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$
  • $\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 Jun 24 '15 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$ – Adnan Abdul Khaliq Jun 25 '15 at 12:42
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, privacy policy and cookie policy

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