Verify if a given argument is a probability distribution

4 visualizaciones (últimos 30 días)
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?

Respuesta aceptada

Loïc Reymond
Loïc Reymond el 26 de Jul. de 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')

Más respuestas (1)

dpb
dpb el 26 de Jul. de 2022
Editada: dpb el 26 de Jul. de 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 comentario
Loïc Reymond
Loïc Reymond el 26 de Jul. de 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

Iniciar sesión para comentar.

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by