This may seem a trivial question but I am coming to Mathematica from object oriented programming languages.
The results of many analyses are composite datatype. I want to access part of the result. For example:
dist = MixtureDistribution[{2, 1}, {NormalDistribution[], NormalDistribution[2, 1/2]}];
weights = dist.getWeights() -- result is {2,1}
Another example:
hmm = HiddenMarkovProcess[{0.5, 0.5}, {{0.7, 0.3}, {0.25, 0.75}}, {{0.2, 0.6, 0.2}, {0.4, 0.2, 0.4}}];
initial = hmm.getInitialProbabilities() -- result is {0.5,0.5}
transition = hmm.getTransitionProbabilities() -- result is {{0.7, 0.3}, {0.25, 0.75}}
I searched Mathematica Documentation and could not find a direct answer. In all the examples, the result is passed to other functions for further plotting/processing.
MixtureDistribution, so you extract them by getting the firstPart:Part[dist, 1],dist[[1]]orFirst[dist]. – 2012rcampion Apr 06 '15 at 02:32weights /: dist[weights] := dist[[1]]and nowdist[weights]will return{2,1}– k_v Apr 06 '15 at 06:55dist[] = MixtureDistribution[{2, 1}, {NormalDistribution[], NormalDistribution[2, 1/2]}];dist["weights"] := dist[][[1]]– k_v Apr 06 '15 at 07:22{1,2,3}is just shorthand forList[1,2,3]so it is really no different from any otherhead[args]expression. – Simon Woods Apr 06 '15 at 19:34