Verify if a given argument is a probability distribution
Show older comments
I would like a class to have as property a probability distribution (of any kind) built using makedist().
The class of a variable a = makedist('normal',0,1) would be prob.NormalDistribution, so I guess I would either:
- Check that the parent class of the input is prob (unsuccessful so far)
- Match the class name in a similar way to: startsWith(class(a),'prob.')
Could it be done using Property Validation in classes with the "mustBe*" syntax?
Accepted Answer
More Answers (1)
Interesting puzzle...I dunno, but let's see what we can find...
The class is the fully-qualified distribution name; in your above example 'prob.NormalDistribution'; not just the parent class.
Well, let's see -- some testing shows that mustBeA is case sensitive as well and must be eggzackly the matching name -- so, the following seems to work with the builtin distributions -- fortunately, makedist without arguments returns the list of allowed/known distributions.
>> plist=strcat('prob.',capitalize(makedist),'Distribution')
plist =
27×1 cell array
{'prob.BetaDistribution' }
{'prob.BinomialDistribution' }
{'prob.BirnbaumsaundersDistribution' }
{'prob.BurrDistribution' }
{'prob.ExponentialDistribution' }
{'prob.ExtremevalueDistribution' }
{'prob.GammaDistribution' }
{'prob.GeneralizedextremevalueDistribution'}
{'prob.GeneralizedparetoDistribution' }
{'prob.HalfnormalDistribution' }
{'prob.InversegaussianDistribution' }
{'prob.LogisticDistribution' }
{'prob.LoglogisticDistribution' }
{'prob.LognormalDistribution' }
{'prob.MultinomialDistribution' }
{'prob.NakagamiDistribution' }
{'prob.NegativebinomialDistribution' }
{'prob.NormalDistribution' }
{'prob.PiecewiselinearDistribution' }
{'prob.PoissonDistribution' }
{'prob.RayleighDistribution' }
{'prob.RicianDistribution' }
{'prob.StableDistribution' }
{'prob.TlocationscaleDistribution' }
{'prob.TriangularDistribution' }
{'prob.UniformDistribution' }
{'prob.WeibullDistribution' }
>> d=makedist('Normal');
>> mustBeA(d,plist)
>>
The above serves to make sure only it is one of the possible; you'd have to shorten the list to specific values to find out about a particular distribution in which case it's probably still just a simple as to do a string search.
I dunno what you do about added distributions; didn't 'spearmint with one of them...
1 Comment
Loïc Reymond
on 26 Jul 2022
Categories
Find more on Perform Sensitivity Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!