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?
The
UserDefinedFactoryclass creates aUserDefineddistribution by estimating thepointsandweightsfrom the sample. Thebuildmethod takes the sample as input and returns theot.UserDefinedobject that fits the data.