Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create custom "Probability Distribution Object" in MATLAB

I would like to include in MATLAB (using the Statistics toolbox) some simple ways to create new probability distributions from existing ones. For example: finite mixtures or compound distributions. My goal is to achieve seamless integration with the existing probability distributions and the environment around them. Is there some documentation or examples how this should be done?

The documentation contains only descriptions of the pre-defined distributions. I could find nothing about the class structure of "Probability Distribution Object" or how to write a custom "makedist" function.

like image 745
g g Avatar asked Mar 30 '16 12:03

g g


1 Answers

Note: As indicated by Mathworks, the ProbDist superclass seems to be on its way out and in the future will be handled entirely via makedist

I'm aware this is an old question, but I needed to implement some distributions that are missing in the statistics toolbox and worked my way through to a solution that worked for my purposes and decided to share that here.

What works:

You can define a class that inherits from the ProbDist or TruncatableDistribution and implement the methods these require.

These objects, for example one modeling the Skew Normal distribution or what have you, can then be instantiated like any other object and fed into the matlab function that accept probDist objects as parameters

pd=SkewNormal('xi',0,'omega',1.0,'alpha',4)
pdf(pd,linspace(0,2,20))
cdf(pd,1)

And given the truncate() method is also implemented even

truncate(pd,[0,2])

What doesn't work

Even after playing around with it for a while, I did not manage to get these custom distribution classes to appear in the list of distributions for makedist although it allows to have the path searched for other classes implementing ProbDist with

makedist -reset

While I did not test it, I would assume it won't appear in the list of the distribution fitter GUI either. Given that your class implements the fit function, it should be able to fit the distribution programmatically.

like image 74
deemel Avatar answered Oct 01 '22 05:10

deemel