Persalys for data inference: how to wrap Persalys?

Hi,
Maybe this sounds completely stupid, but for a study I need to perform about 87 statistical inference studies on datasets of size (n=2000, d=13).

So I would like to create a kind of wrapper that uses Persalys as a code that produces (i) a data analysis, (ii) inference for marginals, (iii) inference for dependence on some subsets of variables, with common “parameters” for all these analyses (e.g. testing for all parametric marginal types and parametric copulas).

To try this out, I created a kind of “template study” that I would like to repeat over the 87 datasets. After discussing this with @JPelamatti, he advised me to use a Python model within the GUI to loop over these studies…

I’ll probably try that… BUT: has anyone ever tried to do such a silly thing?
(By “silly”, I mean using a GUI to do what pure Python code would do better… Please don’t ask me why!!!)

Thanks for your help,
Vincent

Hello Vincent,

I would try something along the lines of what is done here:

You could use Persalys’ Python API to define/run your DataModel/MarginalInferenceAnalysis in an automated way (e.g by looping over your datasets) and then save/open the resulting study within the GUI to analyse/display the results.

I agree such approach can be cumbersome, mainly due to the fact that you need to run the script in Persalys’ Python environment. It can be done in Persalys’ Python console but it is not very user-friendly. Outside of the Python console, you can also have access to this environment by extracting the Linux AppImage or locating Persalys site-packages installation directory on Windows

You could also compile from source but this requires the compilation of all the required dependencies.

I hope this helps nonetheless
Cheers,

Guillaume

1 Like

Hello Vincent, I have not done such things within a GUI but in Persalys, as Guillaume said it is possible to do it.
It may be useful if you want to create a probabilistic distribution for physical model using inference result ?

Anyway if you want to realize that in Persalys, I provide the python script, which you can obtain directly if you export your study (right click on the study then “export as python script”). The python script does not run the analysis but you can add the corresponding lines. You’ll have the base script, you just need to create the loop. Finally, you can import the python by clicking on the menu button.

#!/usr/bin/env python

import openturns as ot
import persalys

etude_0 = persalys.Study('etude_0')
persalys.Study.Add(etude_0)
inputColumns = [0, 1, 2]
outputColumns = [3]
inputNames = ['Et (MJ/m3)', 'Rm (MPa)', 'R0.2 (MPa)']
outputNames = ['A%']
ModeleDonnees_0 = persalys.DataModel('ModeleDonnees_0', '/home/dumas/projet/Persalys/exemple/data_meca_analysis/data_meca.csv', inputColumns, outputColumns, inputNames, outputNames)
etude_0.add(ModeleDonnees_0)
analyseDonnees_0 = persalys.DataAnalysis('analyseDonnees_0', ModeleDonnees_0)
analyseDonnees_0.run()  # added manually
etude_0.add(analyseDonnees_0)
inferenceMarginales_0 = persalys.InferenceAnalysis('inferenceMarginales_0', ModeleDonnees_0)
interestVariables = ['Et (MJ/m3)', 'Rm (MPa)', 'R0.2 (MPa)', 'A%']
inferenceMarginales_0.setInterestVariables(interestVariables)
factories = [ot.ArcsineFactory(), ot.BetaFactory(), ot.ChiSquareFactory(), ot.ExponentialFactory()]
inferenceMarginales_0.setDistributionsFactories('Et (MJ/m3)', factories)
factories = [ot.NormalFactory()]
inferenceMarginales_0.setDistributionsFactories('Rm (MPa)', factories)
factories = [ot.NormalFactory()]
inferenceMarginales_0.setDistributionsFactories('R0.2 (MPa)', factories)
factories = [ot.NormalFactory()]
inferenceMarginales_0.setDistributionsFactories('A%', factories)
inferenceMarginales_0.setLevel(0.05)
inferenceMarginales_0.run()  # added manually
etude_0.add(inferenceMarginales_0)
inferenceDependance_0 = persalys.CopulaInferenceAnalysis('inferenceDependance_0', ModeleDonnees_0)
variablesSet = ['Et (MJ/m3)', 'Rm (MPa)', 'R0.2 (MPa)', 'A%']
factories = [ot.NormalCopulaFactory()]
inferenceDependance_0.setDistributionsFactories(variablesSet, factories)
inferenceDependance_0.run()  # added manually
etude_0.add(inferenceDependance_0)

Antoine

1 Like