0
$\begingroup$

I would like to export the following mixture distribution mathematica found for my dataset to .json file

dis = FindDistribution[selection]

MixtureDistribution[
  {0.874492,0.125508},
  {LogisticDistribution[19.2103, 0.155169],
   CauchyDistribution[23.5492, 2.24062]
  }
]

I tried to look into the documentation available on Mathematica on Export .json here what I did:

Export["distribution.json", 
  {"MixtureDistribution" -> {"Weight"-> {0.8744, 0.1255}},
   "LogisticDistribution"-> {"Parameter"-> 19.2103,0.1551}},
    "CauchyDistribution" -> {"Parameter"-> {23.5492, 2.2406}}
  }
]

It created .json file, but what i need is not to write manually the distribution and parameters, instead i would like to have these parameters and distribution to be automatically found in .json file.

I hope I am clear. Will be looking forward for the answers.

$\endgroup$
2
  • $\begingroup$ Start by reading through this: reference.wolfram.com/language/tutorial/PatternsOverview.html You'll need to define a separate function to handle each type of distribution and convert them to the rule form you showed. $\endgroup$
    – Szabolcs
    Commented Jun 24, 2015 at 14:34
  • $\begingroup$ Can you please elaborate on defining a seperate funcion for each type of distribution? Will be looking for your answer. $\endgroup$ Commented Jun 25, 2015 at 12:42

1 Answer 1

2
$\begingroup$

Perhaps this is what you're looking for:

fun[MixtureDistribution[w_, dists_]] :=
  Prepend[
    Cases[dists, d_[p___] :> ToString[d] -> {"Parameter" -> {p}}], 
    "MixtureDistribution" -> {"Weight" -> w}
  ]

md = MixtureDistribution[
      {0.874492,0.125508},
      {LogisticDistribution[19.2103, 0.155169],
       CauchyDistribution[23.5492, 2.24062]}
     ]

fun[md] --> 
        {"MixtureDistribution" -> {"Weight" -> {0.874492, 0.125508}}, 
         "LogisticDistribution" -> {"Parameter" -> {19.2103, 0.155169}}, 
         "CauchyDistribution" -> {"Parameter" -> {23.5492, 2.24062}}}

You can then export this result.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.