If you sample a 4-D Normal distribution, you get a 4-D sample ;-)! If you 
replace sample1 = myDistribution.getSample(10) by output.getSample(10), then 
you get all the zeros you want.

A++

Régis LEBRUN



>________________________________
> De : Douglas Long <[email protected]>
>À : regis lebrun <[email protected]> 
>Cc : "[email protected]" <[email protected]>
>Envoyé le : Vendredi 7 octobre 2016 19h10
>Objet : Re: [ot-users] Python Function
> 
>
>
>Thanks for your response.
>
>
>here is the modified code. In theory if Y = 0 this code should return zero for 
>each dimension in the sample, but for some reason it is returning numbers <> 0
>import openturns as ot
>
>
>def a_function(X):
>return [(X[0] + X[1] +X[2] + X[3]) * Y]
>
>if __name__ == "__main__":
>ot.RandomGenerator.SetSeed(0)
>Y = 0
>
>myFunction = ot.PythonFunction(4,1, a_function)
>myDistribution = ot.Normal([50.0, 1.0, 10.0, 5.0], [1.0]*4, 
>ot.IdentityMatrix(4))
>
>vect = ot.RandomVector(myDistribution)
>output = ot.RandomVector(myFunction, vect)
>
>sample1 = myDistribution.getSample(10)
>print(sample1)
>
>
>On Fri, Oct 7, 2016 at 11:02 AM, regis lebrun 
><[email protected]> wrote:
>
>Hi,
>>
>>
>>I don't understand your construction: the formula defining your Python 
>>function does not involve Y, so what is the meaning of a_function(Y=cov)? 
>>What you can do:
>>+ make the formula defining a_function depends on Y
>>+ be sure that Y is defined before to call. A simplified version of your 
>>example could be:
>>
>>
>>def a_function(X):
>>return [Y * X[0]]
>>
>>f = PythonFunction(1, 1, a_function)
>>Y = 0.5
>>print f([1.0])
>>
>>For more complexe situations, you may have a look at the 
>>OpenTURNSPythonFunction class here:
>>http://openturns.github.io/ user_manual/_generated/ openturns. 
>>OpenTURNSPythonFunction.html? highlight=openturnspython# openturns. 
>>OpenTURNSPythonFunction
>>
>>You can also define a first function of dimension d+1, one of the input being 
>>Y, then construct a parametric function based on this first function to fix 
>>the value of Y, see the following constructor:
>>NumericalMathFunction( function, indices, referencePoint, parametersSet=True)
>>
>>here:
>>
>>http://openturns.github.io/ user_manual/_generated/ openturns. 
>>NumericalMathFunction.html? highlight= numericalmathfunction
>>Best regards,
>>
>>Régis LEBRUN
>>
>>>_____________________________ ___
>>> De : Douglas Long <[email protected]>
>>>À : [email protected]
>>>Envoyé le : Vendredi 7 octobre 2016 18h42
>>>Objet : [ot-users] Python Function
>>
>>>
>>>
>>>
>>>Hi Folks,
>>>
>>>
>>>anyone know how to submit constants or coefficients into a python function.
>>>example. I am trying to submit the coefficient as Y below.
>>>
>>>
>>>I have tried other methods as well with a composite, composed distribution, 
>>>and several others. any help would be appreciated
>>>
>>>
>>>import openturns as ot
>>>
>>>
>>>def a_function(X):
>>>return [(X[0] + X[1] +X[2] + X[3]) * X[4]]
>>>
>>>if __name__ == "__main__":
>>>ot.RandomGenerator.SetSeed(0)
>>>cov = 0.0017
>>>
>>>myFunction = ot.PythonFunction(5,1, a_function(Y=cov))
>>>myDistribution = ot.Normal([50.0, 1.0, 10.0, 5.0], [1.0]*4, 
>>>ot.IdentityMatrix(4))
>>>
>>>vect = ot.RandomVector( myDistribution)
>>>
>>>output = ot.RandomVector(myFunction, vect)
>>>
>>>sample1 = myDistribution.getSample(10)
>>>print(sample1)
>>>_____________________________ __________________
>>>OpenTURNS users mailing list
>>>[email protected]
>>>http://openturns.org/mailman/ listinfo/users
>>>
>>>
>>>
>>
>
>
>
>-- 
>
>Douglas Long
>[email protected]
>
>_______________________________________________
>OpenTURNS users mailing list
>[email protected]
>http://openturns.org/mailman/listinfo/users
>
>
>
_______________________________________________
OpenTURNS users mailing list
[email protected]
http://openturns.org/mailman/listinfo/users

Reply via email to