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
>
>
>
_______________________________________________
OpenTURNS users mailing list
[email protected]
http://openturns.org/mailman/listinfo/users

Reply via email to