# Model
X0 = persalys.Input('X0', ot.Normal(1, 1))
X1 = persalys.Input('X1', ot.Normal(1, 1))
Y00 = persalys.Output('fake_Y0')
Y00.setIsSelected(False)
Y0 = persalys.Output('Y0')

formula_Y00 = 'X0'
formula_Y0 = '3*(X0-5)^2 + 8*(X1+8)^2'
model = persalys.SymbolicPhysicalModel('aModelPhys', [X0, X1], [Y00, Y0],
                                       [formula_Y00, formula_Y0])
myStudy.add(model)

# Monte Carlo ##
analysis = persalys.OptimizationAnalysis('optim', model, 'Cobyla')
analysis.setInterestVariables(['Y0'])
analysis.setStartingPoint([0.5, 0.5])
interval = ot.Interval([-5, 0], [5, 0])
analysis.setBounds(interval)
analysis.setVariableInputs(['X0'])
analysis.setMaximumEvaluationNumber(150)
analysis.setMaximumAbsoluteError(1e-6)
analysis.setMaximumRelativeError(1e-6)
analysis.setMaximumResidualError(1e-6)
analysis.setMaximumConstraintError(1e-6)
myStudy.add(analysis)
print(analysis)

analysis.run()
evaluation1 = persalys.ModelEvaluation('evaluation1', symbolicModel)
myStudy.add(evaluation1)

# morris ##
try:
    morris = persalys.MorrisAnalysis('aMorris', symbolicModel)
    morris.setInterestVariables(['y0'])
    morris.setLevel(4)
    morris.setTrajectoriesNumber(10)
    morris.setSeed(2)
    myStudy.add(morris)
except:
    print("No Morris")

# optimization ##
optim = persalys.OptimizationAnalysis('optim', symbolicModel, 'TNC')
optim.setInterestVariables(['y1'])
optim.setVariableInputs(['x1', 'x2'])
optim.setMaximumEvaluationNumber(150)
optim.setMaximumAbsoluteError(1e-6)
optim.setMaximumRelativeError(1e-6)
optim.setMaximumResidualError(1e-6)
optim.setMaximumConstraintError(1e-6)
myStudy.add(optim)

# calibration ##

# a- observations
nbObs = 100
inObs = ot.Uniform(0., 10.).getSample(nbObs)
inObs.setDescription(['x1'])