Verify if a given argument is a probability distribution

4 Ansichten (letzte 30 Tage)
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:
  1. Check that the parent class of the input is prob (unsuccessful so far)
  2. 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?

Akzeptierte Antwort

Loïc Reymond
Loïc Reymond am 26 Jul. 2022
An existing thread had already answered this question 5 years ago, sorry for the duplicate... https://www.mathworks.com/matlabcentral/answers/364545-isa-probability-distribution?s_tid=answers_rc1-1_p1_MLT
In order to verify that an input argument is a distribution, the following statment would work:
mustBeA(Distribution, 'prob.ToolboxFittableParametricDistribution')

Weitere Antworten (1)

dpb
dpb am 26 Jul. 2022
Bearbeitet: dpb am 26 Jul. 2022
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 Kommentar
Loïc Reymond
Loïc Reymond am 26 Jul. 2022
Thanks for your input !
I tried this approach, but had some issues with the distributions having names that contain more than one word (such as GeneralizedExtremeValueDistribution, that becomes GeneralizedextremevalueDistribution) eventually endding up not matching the case-sensitivity of mustBeA.
Furthermore, I am unsure about how to initialize the equivalent of your plist variable so that it is available during the property validation step (see below). Would you have a workaround?
Also, what do you mean by "added distributions"?
classdef DummyClass
properties
Distribution {mustBeA(Distribution, plist)} %plist has to be initialized
end
methods
%...
end
end

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by