Reputation: 4041
Using Tensorflow, I am trying to optimize the shape parameter of Weillbull distribution. The shape parameter should be always more than zero.
What is a nice way to define a positive variable in TensorFlow?
Upvotes: 2
Views: 1066
Reputation: 10474
I see two ways of doing this:
tf.Variable
, you can use the constraint
parameter (get_variable
has it as well). This needs to be a function that basically projects the variable into the allowed space. E.g. you could pass tf.nn.relu
here, which would map any negative values to 0 should they occur.tf.exp
. E.g. if your variable is x
, you pass tf.exp(x)
as the parameter to the Weibull distribution. Then x
represents the log of the parameter.Upvotes: 1