[0, 2]) anOTStudy.add(aDesign2) aDesign2.run() print('outs=', aDesign2.getResult().getDesignOfExperiment().getOutputSample()) # Design of Experiment ## aDesign3 = persalys.ProbabilisticDesignOfExperiment('aDesign_3', model, 10, 'QUASI_MONTE_CARLO') anOTStudy.add(aDesign3) aDesign3.run() print('outs=', aDesign3.getResult().getDesignOfExperiment().getOutputSample()) # Design of Experiment ## aDesign4 = persalys.FixedDesignOfExperiment('aDesign_4', model) inputSample = ot.LHSExperiment(model.getDistribution(), 10).generate() #inputSample.stack(ot.Sample(10, [0.5, 1.3])) aDesign4.setOriginalInputSample(inputSample) anOTStudy.add(aDesign4) aDesign4.run() print('outs=', aDesign4.getResult().getDesignOfExperiment().getOutputSample()) # 3D Model to test Space filling algos X0 = persalys.Input('X0', 1, ot.Normal()) X1 = persalys.Input('X1', 2, ot.Normal()) X2 = persalys.Input('X2', 3, ot.Normal()) Y0 = persalys.Output('Y0')
xi2 = persalys.Input('xi2', ot.Uniform(0., 10.)) xi3 = persalys.Input('xi3', 0.5) y00 = persalys.Output('fake_y0') y00.setIsSelected(False) y0 = persalys.Output('y0') y1 = persalys.Output('y1') formula_y00 = "xi1" formula_y0 = "cos(0.5*xi1) + sin(xi2)" formula_y1 = "cos(0.5*xi1) + sin(xi2) + xi3" model = persalys.SymbolicPhysicalModel('model', [xi1, xi2, xi3], [y00, y0, y1], [ formula_y00, formula_y0, formula_y1]) myStudy.add(model) # Design of Experiment ## aDesign = persalys.FixedDesignOfExperiment('design', model) inputSample = ot.LHSExperiment(model.getDistribution(), 50).generate() inputSample.stack(ot.Sample(50, [0.5])) aDesign.setOriginalInputSample(inputSample) myStudy.add(aDesign) aDesign.run() # Chaos 1 ## analysis = persalys.FunctionalChaosAnalysis('chaos_0', aDesign) analysis.setChaosDegree(4) analysis.setSparseChaos(True) myStudy.add(analysis) print(analysis) analysis.run()
# python model ## code = 'from math import cos, sin, sqrt\n\ndef _exec(x1, x2, x3):\n y0 = cos(0.5*x1) + sin(x2) + sqrt(x3)\n return y0\n' pythonModel = persalys.PythonPhysicalModel('pythonModel', [x1, x2, x3], [y0], code) myStudy.add(pythonModel) filename = 'data.csv' cDist = ot.ComposedDistribution([ot.Normal(), ot.Gumbel(), ot.Normal(), ot.Uniform()], ot.ComposedCopula([ot.IndependentCopula(2), ot.GumbelCopula()])) sample = cDist.getSample(200) sample.exportToCSVFile(filename, ' ') # Designs of Experiment ## # fixed design ## ot.RandomGenerator.SetSeed(0) fixedDesign = persalys.FixedDesignOfExperiment('fixedDesign', symbolicModel) inputSample = ot.LHSExperiment(ot.ComposedDistribution([ot.Uniform(0., 10.), ot.Uniform(0., 10.)]), 10).generate() inputSample.stack(ot.Sample(10, [0.5])) fixedDesign.setOriginalInputSample(inputSample) fixedDesign.run() myStudy.add(fixedDesign) # grid ## values = [[0.5+i*1.5 for i in range(7)], [0.5+i*1.5 for i in range(7)], [1]] grid = persalys.GridDesignOfExperiment('grid', symbolicModel, values) myStudy.add(grid) # importDesign ## importDesign = persalys.ImportedDesignOfExperiment('importDesign', symbolicModel, 'data.csv', [0, 2, 3]) importDesign.run() myStudy.add(importDesign)
'from math import pi\n\ndef _exec(R, F):\n G = 6*F\n H = 42.0\n return G, H\n') f = model.getFunction() print(f([300., 75000.])) # test operator() (sample) model.setCode( 'from math import pi\n\ndef _exec(R, F):\n G = 2*R-F/(pi*100.0)\n return G\n') f = model.getFunction() print(f([[300., 75000.]])) print(f([[300., 75000.], [400., 74000.]])) # test operator() (sample) model.setCode( 'from math import pi\nimport time\ndef _exec(R, F):\n if R == 300.:\n time.sleep(0.5)\n G = 2*R-F/(pi*100.0)\n return G\n') plan_0 = persalys.FixedDesignOfExperiment('plan_0', model, [[300., 75000.], [400., 74000.]]) plan_0.setBlockSize(2) myStudy.add(plan_0) plan_0.run() print("Sample :\n %s" % plan_0.getResult().getDesignOfExperiment().getSample()) # model with an error model.setCode( 'from math import pi\n\ndef _exec(R, F):\n G = 2*R-F/(pi*100.0)/0.\n return G\n') f = model.getFunction() try: print(f([[300., 75000.]])) except Exception as e: print("ZeroDivisionError occured: %s" % ("ZeroDivisionError: float division by zero" in str(e))) print("Error on the line 4 : %s" % ("line 4" in str(e)))
#! /usr/bin/env python import openturns as ot import persalys import os # Model with error X0 = persalys.Input('X0', 1, ot.Normal()) X1 = persalys.Input('X1', 2) Y0 = persalys.Output('Y0') Y1 = persalys.Output('Y1') model2 = persalys.PythonPhysicalModel('model2', [X0, X1], [Y0], 'from math import pi\n\ndef _exec(X0, X1):\n Y0 = 2*X1 - 1/X0\n return Y0\n') model2.setParallel(True) design5 = persalys.FixedDesignOfExperiment('design5', model2) design5.setOriginalInputSample([[0.9, 1.1], [1.8, 2.2], [0, 2.2]]) design5.setBlockSize(3) design5.run() assert design5.getResult().getDesignOfExperiment().getOutputSample().getSize() == 2, "whole block must no fail" model3 = persalys.PythonPhysicalModel('model3', [X0, X1], [Y0, Y1], 'from math import pi\n\ndef _exec(X0, X1):\n Y0 = 2*X1 - 1/X0\n Y1=5\n return Y0, Y1\n') model3.setParallel(True) # same with multiple outputs design6 = persalys.FixedDesignOfExperiment('design6', model3) design6.setInterestVariables(['Y0']) design6.setOriginalInputSample([[0.9, 1.1], [1.8, 2.2], [0, 2.2]]) design6.setBlockSize(3) design6.run() assert design6.getResult().getDesignOfExperiment().getOutputSample().getSize() == 2, "whole block must no fail"