Reputation: 1151
I have a sample of real values which contains independent realizations of a discrete random variable and I want to create the distribution which fits this data.
sample = [2.0, 2.0, 1.0, 1.0, 2.0, 3.0, 1.0, 2.0, 2.0, 1.0]
The UserDefined
distribution seems to be designed for this purpose, but requires to compute the weights of each point, depending on its frequency in the sample:
import openturns as ot
distribution = ot.UserDefined(points, weights)
But we have to compute the points
and weights
first. To do this, I computed the points and weights using the Numpy unique
function. However, this sounds like a limitation of the UserDefined
class. How may I do this more simply?
Upvotes: 0
Views: 246
Reputation: 1151
The UserDefinedFactory
class creates a UserDefined
distribution by estimating the points
and weights
from the sample. The build
method takes the sample as input and returns the ot.UserDefined
object that fits the data.
import openturns as ot
sample = ot.Sample([[2.0], [2.0], [1.0], [1.0], [2.0], [3.0], [1.0], [2.0], [2.0], [1.0]])
factory = ot.UserDefinedFactory()
distribution = factory.build(sample)
Upvotes: 0