Pysens Tutorial

PySens  Tutorial / Basic Test==================

In [1]:
import json
import pysens
%pylab inline
Populating the interactive namespace from numpy and matplotlib

First let's define our parameter space in json format. You should describe each parameter variations with a probability distributions.

As a test we will use the Ishigami function implemented as a basic test in the library.

In [2]:
%%writefile ishigami.json
{
 "model": "test",
 "parameters": [
   {
     "name": "X1",
     "distrib": {
       "max": 3.14,
       "min": -3.14,
       "type": "uniform"
     },
     "unit": "mm"
   },
   {
     "name": "X2",
     "distrib": {
       "min": -3.14,
       "max": 3.14,
       "type": "uniform"
     },
     "unit": "V"
   },
   {
     "name": "X3",
     "distrib": {
       "min": -3.14,
       "max": 3.14,
       "type": "uniform"
     },
     "unit": "V"
   }
 ]
}
Overwriting ishigami.json

Now we can sample this space using one of the available methods in pysens.sample

In [3]:
smpl=pysens.sample.Sobol('ishigami.json')
smpl.build()

Let's visualise our DOE and print its statistical properties:

In [4]:
smpl.plot_plan()
pysens.tools.print_stat(smpl.mat)
Statistics for DOE
Euclidean maximin distance: 0.0857099128711
Maximum pairwise correlation: 0.041104110411
Condition number: 1.09694361664
ML2 discrepency: 0.000370740566756

Now we can evaluate the model at each of the point described by the DOE plan:

In [5]:
ev=pysens.evaluate.TestIshigami('ishigami-Sobol.csv')
ev.simulate()
Number of threads to be used: 8/8
Number of simulations to run: 100

Total time elapsed: 0.12s 

This generated a hundred npy files each containing the results of one evaluation of the model. They have been stored in a new subdirectory named by the time and date of the analysis.

(In the following lines, we use the name of the subdirectory stored in ev.subdir. You can run the post-processing and analysis without the evaluator object, just by giving the directory name instead.)

In [6]:
prcss=pysens.process.TestModels(ev.subdir)

Now we have both the DOE plan in ishigami-Sobol.csv and the features in Out.csv. Both files are in the subdirectory. For the test models, there's only one feature, the scalar output of the model.

Let's compute the linear correclations of the inputs / output:

In [7]:
anls=pysens.analyse.CorrelationsSA(ev.subdir+'ishigami-Sobol.csv',ev.subdir+'Out.csv')
anls.analyse()
anls.save_results()
anls.plot_results()
In [ ]:
 

Comments