Verify if a given argument is a probability distribution

조회 수: 5 (최근 30일)
Loïc Reymond
Loïc Reymond 2022년 7월 26일
답변: Loïc Reymond 2022년 7월 26일
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?

채택된 답변

Loïc Reymond
Loïc Reymond 2022년 7월 26일
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')

추가 답변 (1개)

dpb
dpb 2022년 7월 26일
편집: dpb 2022년 7월 26일
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
Loïc Reymond
Loïc Reymond 2022년 7월 26일
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

댓글을 달려면 로그인하십시오.

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by