Re: [ot-users] Kriging with confidence bounds

2019-04-24 Thread regis lebrun
 Hi!
The scripts producing the images in the carrousel are 
here:https://github.com/openturns/www/tree/master/_images/scripts
Warning! The scripts are not executed at each new release, so they may need a 
little bit of effort to make them work with the last release. Here is an 
updated version of the script you are looking for. 

The two changes are:1) ot.Function->ot.SymbolicFunction2) no more output 
description in the definition of a symbolic function

The figure will NOT be created into the current directory, but rather into the 
upper level directory.
Cheers
Régis

from __future__ import print_function
from openturns.viewer import View
import openturns as ot

sampleSize = 4
dimension = 1

f = ot.SymbolicFunction(['x'], ['0.5*x^2 + sin(2.5*x)'])

# Database
xMin = -0.9
xMax = 1.9
X = ot.LHSExperiment(ot.Uniform(xMin, xMax), sampleSize, False, 
False).generate()
Y = f(X)

# create algorithm
basis = ot.ConstantBasisFactory(dimension).build()
covarianceModel = ot.MaternModel([1.0], 1.5)

ot.Log.Show(ot.Log.INFO)
algo = ot.KrigingAlgorithm(X, Y, covarianceModel, basis)
algo.run()

# perform an evaluation
result = algo.getResult()
meta = result.getMetaModel()
graph_meta = meta.draw(xMin, xMax)
data = graph_meta.getDrawable(0).getData()
xGrid = data.getMarginal(0)
covGrid = result.getConditionalCovariance(xGrid)
a = ot.DistFunc.qNormal(0.975)
c = ot.Cloud([data[2]])
c.setPointStyle("square")
c.setColor("green")
c.setLegend("95% confidence bound")
dataLower = [[data[i, 0], data[i, 1] - a * covGrid[i, i]] for i in 
range(len(data))]
dataUpper = [[data[i, 0], data[i, 1] + a * covGrid[i, i]] for i in 
range(len(data))]
bounds = ot.PolygonArray([ot.Polygon([dataLower[i], dataLower[i+1], 
dataUpper[i+1], dataUpper[i]], "green", "green") for i in 
range(len(dataLower)-1)])
graph = ot.Graph()
graph.setLegendPosition("bottomright")
graph.setAxes(True)
graph.setGrid(True)
graph.add(c)
graph.add(bounds)

d = f.draw(xMin, xMax).getDrawable(0)
d.setLineStyle("dashed")
d.setColor("magenta")
d.setLineWidth(2)
graph.add(d)
graph.add(graph_meta)
cloud = ot.Cloud(X, Y)
cloud.setPointStyle("circle")
cloud.setColor("red")
graph.add(cloud)
graph.setTitle("Kriging meta-modeling")
graph.setXTitle(r"$x$")
graph.setYTitle(r"$f$")
graph.setLegends(["95% conf. bounds", "true function", "meta-model", "data"])
view = View(graph, (800, 600))
view.save("../plot_kriging.png")
view.close()




Le mercredi 24 avril 2019 à 15:26:37 UTC+2, BAUDIN Michael 
 a écrit :  
 
  
Hi !
 
  
 
I am currently working on kriging and try to reproduce the graphics which is 
printed in the carrousel of openturns.org (see attachement). More precisely, I 
would like to compute the 95% confidence bounds of the kriging predictions. 
However, I could not find the script corresponding to the figure neither on 
openturns.org nor in the doc (nor in the Slides of the User’s days, nor in the 
Use Cases Guide). Is this Python script available ?
 
  
 
I also tried to produce the script by myself, and failed In attachment, I 
put a Python script which tries to reproduce the figure. Notice however, that 
the confidence bounds are extremely tight compared to what I expected. My guess 
is that the issue is related to the estimate of the covariance model : in 
OpenTURNS, the SquaredExponential is anisotropic while the figure might be 
produced with an isotropic covariance. I also tried to prevent the optimization 
algorithm from tuning the theta parameter with the setOptimizeParameters 
method, but I wasn’t able to use correctly (the parameters still change, 
however with a different value). What is the explanation for these tight bounds 
?
 
  
 
Best regards,
 
  
 
Michaël
 
  
 
Michaël BAUDIN
Ingénieur - Chercheur
EDF – R
Département Management des Risques Industriels
6, quai Watier
78401 CHATOU
michael.bau...@edf.fr
Tél. : 01 30 87 81 82
Fax : 01 30 87 82 13
 
  
 



Ce message et toutes les pièces jointes (ci-après le 'Message') sont établis à 
l'intention exclusive des destinataires et les informations qui y figurent sont 
strictement confidentielles. Toute utilisation de ce Message non conforme à sa 
destination, toute diffusion ou toute publication totale ou partielle, est 
interdite sauf autorisation expresse.

Si vous n'êtes pas le destinataire de ce Message, il vous est interdit de le 
copier, de le faire suivre, de le divulguer ou d'en utiliser tout ou partie. Si 
vous avez reçu ce Message par erreur, merci de le supprimer de votre système, 
ainsi que toutes ses copies, et de n'en garder aucune trace sur quelque support 
que ce soit. Nous vous remercions également d'en avertir immédiatement 
l'expéditeur par retour du message.

Il est impossible de garantir que les communications par messagerie 
électronique arrivent en temps utile, sont sécurisées ou dénuées de toute 
erreur ou virus.


This message and any attachments (the 'Message') are intended solely for the 
addressees. The information 

Re: [ot-users] Error creating a PCE model from a design experiment

2019-04-24 Thread BAUDIN Michael
Hi Armando,

I cannot reproduce the problem : your script works fine on my computer, both 
with OT 1.11 and 1.12 in Windows.

I might be wrong, but it may happen that invisible characters were present in 
the string of the formula. These invisible characters appear when we copy/paste 
from a PDF.

Best regards,

Michaël

Michaël BAUDIN
Ingénieur - Chercheur
EDF – R
Département PRISME
6, quai Watier
78401 CHATOU
michael.bau...@edf.fr
Tél. : 01 30 87 81 82
Fax : 01 30 87 82 13

De : users-boun...@openturns.org [mailto:users-boun...@openturns.org] De la 
part de armando.alexan...@gmail.com
Envoyé : vendredi 14 décembre 2018 17:36
À : users@openturns.org
Objet : [ot-users] Error creating a PCE model from a design experiment

Hello,

I've been trying to recreate the example in the user cases  manual on creating 
a PCE model from  a design experiment ( section 4.3.4)  but I am getting an 
error:

return _metamodel.FunctionalChaosAlgorithm_run(self)
TypeError: InvalidArgumentException : Error: the left gradient and the right 
function have incompatible input or output dimensions.

The code I am using is given below and I am using OT   1.11. Does anyone have 
any idea what can be the problem?

Many thanks for the help,
Armando

from math import sin, pi
import openturns as ot

# Definition of the Ishigami function
dimension = 3
a = 7.0
b = 0.1
input_variables = ['xi1', 'xi2', 'xi3', 'a', 'b']
formula = ['sin(xi1) + a * (sin(xi2)) ^ 2 + b * xi3^4 * sin(xi1)']
full = ot.SymbolicFunction(input_variables, formula)
ishigami_model = ot.ParametricFunction(full, [3, 4], [a, b])



distribution = ot.ComposedDistribution([ot.Uniform(-pi, pi)] * dimension)
lhs_validation = ot.MonteCarloExperiment(distribution, 100)
input_validation = lhs_validation.generate()
X = input_validation
Y =  ishigami_model(input_validation)
coll = [ ]
for i in range ( dimension):
coll.append(ot.StandardDistributionPolynomialFactory( 
distribution.getMarginal(i)))

enumerateFunction = ot.LinearEnumerateFunction( dimension )
productBasis = ot.OrthogonalProductPolynomialFactory( coll , enumerateFunction )
# c r e a t e the algor i thm
degree = 6
adaptiveStrategy = ot.FixedStrategy (productBasis , enumerateFunction . 
getStrataCumulatedCardinal ( degree ) )
projection_strategy = ot.LeastSquaresStrategy ()
algo = ot.FunctionalChaosAlgorithm( X, Y, distribution , adaptiveStrategy 
,projection_strategy )
algo.run()






Ce message et toutes les pièces jointes (ci-après le 'Message') sont établis à 
l'intention exclusive des destinataires et les informations qui y figurent sont 
strictement confidentielles. Toute utilisation de ce Message non conforme à sa 
destination, toute diffusion ou toute publication totale ou partielle, est 
interdite sauf autorisation expresse.

Si vous n'êtes pas le destinataire de ce Message, il vous est interdit de le 
copier, de le faire suivre, de le divulguer ou d'en utiliser tout ou partie. Si 
vous avez reçu ce Message par erreur, merci de le supprimer de votre système, 
ainsi que toutes ses copies, et de n'en garder aucune trace sur quelque support 
que ce soit. Nous vous remercions également d'en avertir immédiatement 
l'expéditeur par retour du message.

Il est impossible de garantir que les communications par messagerie 
électronique arrivent en temps utile, sont sécurisées ou dénuées de toute 
erreur ou virus.


This message and any attachments (the 'Message') are intended solely for the 
addressees. The information contained in this Message is confidential. Any use 
of information contained in this Message not in accord with its purpose, any 
dissemination or disclosure, either whole or partial, is prohibited except 
formal approval.

If you are not the addressee, you may not copy, forward, disclose or use any 
part of it. If you have received this message in error, please delete it and 
all copies from your system and notify the sender immediately by return message.

E-mail communication cannot be guaranteed to be timely secure, error or 
virus-free.
___
OpenTURNS users mailing list
users@openturns.org
http://openturns.org/mailman/listinfo/users


[ot-users] Error creating a PCE model from a design experiment

2019-04-24 Thread armando alexandre
Hello,

I've been trying to recreate the example in the user cases  manual on
creating a PCE model from  a design experiment ( section 4.3.4)  but I am
getting an error:

return _metamodel.FunctionalChaosAlgorithm_run(self)
TypeError: InvalidArgumentException : Error: the left gradient and the
right function have incompatible input or output dimensions.

The code I am using is given below and I am using OT   1.11. Does anyone
have any idea what can be the problem?

Many thanks for the help,
Armando

from math import sin, pi
import openturns as ot

# Definition of the Ishigami function
dimension = 3
a = 7.0
b = 0.1
input_variables = ['xi1', 'xi2', 'xi3', 'a', 'b']
formula = ['sin(xi1) + a * (sin(xi2)) ^ 2 + b * xi3^4 * sin(xi1)']
full = ot.SymbolicFunction(input_variables, formula)
ishigami_model = ot.ParametricFunction(full, [3, 4], [a, b])



distribution = ot.ComposedDistribution([ot.Uniform(-pi, pi)] * dimension)
lhs_validation = ot.MonteCarloExperiment(distribution, 100)
input_validation = lhs_validation.generate()
X = input_validation
Y =  ishigami_model(input_validation)
coll = [ ]
for i in range ( dimension):
coll.append(ot.StandardDistributionPolynomialFactory(
distribution.getMarginal(i)))

enumerateFunction = ot.LinearEnumerateFunction( dimension )
productBasis = ot.OrthogonalProductPolynomialFactory( coll ,
enumerateFunction )
# c r e a t e the algor i thm
degree = 6
adaptiveStrategy = ot.FixedStrategy (productBasis , enumerateFunction .
getStrataCumulatedCardinal ( degree ) )
projection_strategy = ot.LeastSquaresStrategy ()
algo = ot.FunctionalChaosAlgorithm( X, Y, distribution , adaptiveStrategy
,projection_strategy )
algo.run()
___
OpenTURNS users mailing list
users@openturns.org
http://openturns.org/mailman/listinfo/users


[ot-users] AttributeError: 'module' object has no attribute 'SobolIndicesExperiment'

2019-04-24 Thread Rajeev Das
Hi,

I have installed OpenTurns on a Windows machine (Win7). While running a
piece of code I am getting an error message as '*AttributeError: 'module'
object has no attribute 'SobolIndicesExperiment*''

I used the package 'OpenTURNS1.12rc1 ' from the path provided below
Download the installer matching your python version and architecture from
GitHub

I used the following lines, which throws the error from
ot.SobolIndicesExperiment

import pandas as pd
import openturns as ot
import xlrd
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import interactive
import shutil
import os

N = 4
distribution = ot.ComposedDistribution([ot.Uniform(25000.06, 35000.09),
ot.Uniform(35, 50), ot.Uniform(5, 20), ot.Uniform(0.95 , 1.05),
ot.Uniform(0.3135, 0.3465), ot.Uniform(21.375, 23.625)])
design = ot.SobolIndicesExperiment(distribution, N, True).generate()
dataMatrix = np.array(design)


Just to cross very few more things, I tried the following lines too just
for the sequence and they work, *but not SobolIndicesExperiment*

sequence = ot.SobolSequence(6)
experiment = sequence.generate(5)
sample = np.array(experiment)

Am I missing any dependencies? and is there a way to avoid this issue? Any
help would be greatly appreciated.

Thank you,

Raj
___
OpenTURNS users mailing list
users@openturns.org
http://openturns.org/mailman/listinfo/users


[ot-users] Kriging with confidence bounds

2019-04-24 Thread BAUDIN Michael
Hi !

I am currently working on kriging and try to reproduce the graphics which is 
printed in the carrousel of openturns.org (see attachement). More precisely, I 
would like to compute the 95% confidence bounds of the kriging predictions. 
However, I could not find the script corresponding to the figure neither on 
openturns.org nor in the doc (nor in the Slides of the User's days, nor in the 
Use Cases Guide). Is this Python script available ?

I also tried to produce the script by myself, and failed In attachment, I 
put a Python script which tries to reproduce the figure. Notice however, that 
the confidence bounds are extremely tight compared to what I expected. My guess 
is that the issue is related to the estimate of the covariance model : in 
OpenTURNS, the SquaredExponential is anisotropic while the figure might be 
produced with an isotropic covariance. I also tried to prevent the optimization 
algorithm from tuning the theta parameter with the setOptimizeParameters 
method, but I wasn't able to use correctly (the parameters still change, 
however with a different value). What is the explanation for these tight bounds 
?

Best regards,

Michaël

Michaël BAUDIN
Ingénieur - Chercheur
EDF - R
Département Management des Risques Industriels
6, quai Watier
78401 CHATOU
michael.bau...@edf.fr
Tél. : 01 30 87 81 82
Fax : 01 30 87 82 13




Ce message et toutes les pièces jointes (ci-après le 'Message') sont établis à 
l'intention exclusive des destinataires et les informations qui y figurent sont 
strictement confidentielles. Toute utilisation de ce Message non conforme à sa 
destination, toute diffusion ou toute publication totale ou partielle, est 
interdite sauf autorisation expresse.

Si vous n'êtes pas le destinataire de ce Message, il vous est interdit de le 
copier, de le faire suivre, de le divulguer ou d'en utiliser tout ou partie. Si 
vous avez reçu ce Message par erreur, merci de le supprimer de votre système, 
ainsi que toutes ses copies, et de n'en garder aucune trace sur quelque support 
que ce soit. Nous vous remercions également d'en avertir immédiatement 
l'expéditeur par retour du message.

Il est impossible de garantir que les communications par messagerie 
électronique arrivent en temps utile, sont sécurisées ou dénuées de toute 
erreur ou virus.


This message and any attachments (the 'Message') are intended solely for the 
addressees. The information contained in this Message is confidential. Any use 
of information contained in this Message not in accord with its purpose, any 
dissemination or disclosure, either whole or partial, is prohibited except 
formal approval.

If you are not the addressee, you may not copy, forward, disclose or use any 
part of it. If you have received this message in error, please delete it and 
all copies from your system and notify the sender immediately by return message.

E-mail communication cannot be guaranteed to be timely secure, error or 
virus-free.


kriging-sin-function.py
Description: kriging-sin-function.py
___
OpenTURNS users mailing list
users@openturns.org
http://openturns.org/mailman/listinfo/users


Re: [ot-users] Simplified symbolic functions

2019-04-24 Thread BAUDIN Michael
Hi Régis,

It works : thank you very much !

Best regards,

Michaël

Michaël BAUDIN
Ingénieur - Chercheur
EDF – R
Département Management des Risques Industriels
6, quai Watier
78401 CHATOU
michael.bau...@edf.fr
Tél. : 01 30 87 81 82
Fax : 01 30 87 82 13

De : regis_anne.lebrun_dut...@yahoo.fr 
[mailto:regis_anne.lebrun_dut...@yahoo.fr]
Envoyé : vendredi 3 août 2018 18:40
À : bou...@gmail.com; BAUDIN Michael 
Cc : users@openturns.org
Objet : Re: [ot-users] Simplified symbolic functions

Hi Michael,

Try this:

import openturns as ot

Q = 1013.
Ks = 30.
Zv = 50.
Zm = 55.
Hd = 8
Zb = 55.5
L = 5000
B = 300
X = [Q,Ks,Zv,Zm,Hd,Zb,L,B]

inputs = ['Q', 'Ks', 'Zv', 'Zm', 'Hd', 'Zb', 'L', 'B']
formula = 'var alpha := (Zm - Zv)/L; H := (Q/(Ks*B*sqrt(alpha)))^(3.0/5.0); var 
Zc := H + Zv; var Zd := Zb + Hd; S := Zc - Zd'
outputs = ['H', 'S']
myFunction = ot.SymbolicFunction(inputs, outputs, formula)
print(myFunction(X))

In the case of multiple outputs defined using a unique formula, you have to:
1) provide the formula as a single string
2) declare the intermediate results you want to reuse but not to output using 
the 'var' qualifier
3) provide the list of outputs as a sequence of strings

Cheers

Régis

Le vendredi 3 août 2018 à 18:10:15 UTC+2, BAUDIN Michael 
mailto:michael.bau...@edf.fr>> a écrit :


Hi,

I tried the feature you showed with the following script :

Q = 1013.
Ks = 30.
Zv = 50.
Zm = 55.
Hd = 8
Zb = 55.5
L = 5000
B = 300
X = [Q,Ks,Zv,Zm,Hd,Zb,L,B]

inputs = ['Q', 'Ks', 'Zv', 'Zm', 'Hd', 'Zb', 'L', 'B']
formula = ['var alpha := (Zm - Zv)/L; H := (Q/(Ks*B*sqrt(alpha)))^(3.0/5.0); 
var Zc := H + Zv; var Zd := Zb + Hd; S := Zc - Zd']
outputs = ['H', 'S']
myFunction = ot.SymbolicFunction(inputs, outputs, formula)
print(myFunction(X))

But the following exception is generated :

NotImplementedError: Wrong number or type of arguments for overloaded function 
'new_SymbolicFunction'.
  Possible C/C++ prototypes are:
OT::SymbolicFunction::SymbolicFunction()
OT::SymbolicFunction::SymbolicFunction(OT::String const &,OT::String const 
&)
OT::SymbolicFunction::SymbolicFunction(OT::Description const 
&,OT::Description const &)
OT::SymbolicFunction::SymbolicFunction(OT::Description const 
&,OT::Description const &,OT::String const &)
OT::SymbolicFunction::SymbolicFunction(OT::SymbolicFunction const &)

I also tried a simpler version :

inputs = ['Q', 'Ks', 'Zv', 'Zm', 'Hd', 'Zb', 'L', 'B']
formula = ['alpha := (Zm - Zv)/L; H := (Q/(Ks*B*sqrt(alpha)))^(3.0/5.0); Zc := 
H + Zv; Zd := Zb + Hd; S := Zc - Zd']
myFunction = ot.SymbolicFunction(inputs, formula)
print(myFunction(X))

TypeError: InvalidArgumentException : Errors found when parsing expression 
'alpha := (Zm - Zv)/L; H := (Q/(Ks*B*sqrt(alpha)))^(3.0/5.0); Zc := H + Zv; Zd 
:= Zb + Hd; S := Zc - Zd': ERR189 - Undefined symbol: 'alpha'

What is the trick you used to make it work ?
(This is with OT 1.11).

Best regards,

Michaël

Michaël BAUDIN
Ingénieur - Chercheur
EDF – R
Département Management des Risques Industriels
6, quai Watier
78401 CHATOU
michael.bau...@edf.fr
Tél. : 01 30 87 81 82
Fax : 01 30 87 82 13

-Message d'origine-
De : bou...@gmail.com 
[mailto:bou...@gmail.com]
Envoyé : lundi 12 mars 2018 21:26
À : BAUDIN Michael mailto:michael.bau...@edf.fr>>
Cc : users@openturns.org
Objet : Re: [ot-users] Simplified symbolic functions

Hello Michael,

We investigated using ExprTk to parse analytical formulas instead of muParser, 
it is known to be faster.
Almost all muParser formulas can be parsed by ExprTk without changes, but it 
also provides many more features.  And multiple outputs are trivial with this 
backend.
This has been implemented on current master, your example can be written:

inputs = ['Q', 'Ks', 'Zv', 'Zm', 'Hd', 'Zb', 'L', 'B'] outputs = ['H', 'S'] 
formula = """var alpha := (Zm - Zv)/L; H := (Q/(Ks*B*sqrt(alpha)))^(3.0/5.0); 
var Zc := H + Zv; var Zd := Zb + Hd; S := Zc - Zd;"""
myFunction = SymbolicFunction(inputs, outputs, formula)

This is almost straightforward; input and output variables are declared, all 
other variables must be prefixed by the keyword 'var', assignment is ':=', and 
statements must be separated by semicolons.

But Python can be as fast as SymbolicFunction; pull request #699 avoids copies 
between OT and Python, your code could be rewritten as

import numpy as np
def functionCrueSample(X) :
Q, Ks, Zv, Zm, Hd, Zb, L, B = np.array(X, copy=False).T
alpha = (Zm - Zv)/L
H = (Q/(Ks*B*np.sqrt(alpha)))**(3.0/5.0)
Zc = H + Zv
Zd = Zb + Hd
S = Zc - Zd;
Y = np.zeros((len(H), 2))
Y[:,0] = H
Y[:,1] = S
return Y

myFunction = PythonFunction(8, 2, func_sample=functionCrueSample)

Denis

2018-02-14 12:30 GMT+01:00 BAUDIN Michael 
mailto:michael.bau...@edf.fr>>:
> Hi,
>
>
>
> I have a symbolic function that I would like to simplify 

Re: [ot-users] Linear least squares always insert a constant

2019-04-24 Thread BAUDIN Michael
Hi Sofiane,

Thanks for the trick : I did not know this constructor.

However, my particular need was really to get over the linear model. My 
particular applications are the calibration of a model based on the BLUE or 
ridge regression. In these cases, we really need to solve the basic linear 
least squares problem, without any link to a functional basis.

How would you do that ?

Best regards,

Michaël


Michaël BAUDIN
Ingénieur - Chercheur
EDF – R
Département PRISME
6, quai Watier
78401 CHATOU
michael.bau...@edf.fr
Tél. : 01 30 87 81 82
Fax : 01 30 87 82 13

De : sofiane_had...@yahoo.fr [mailto:sofiane_had...@yahoo.fr]
Envoyé : mardi 2 avril 2019 09:00
À : users@openturns.org; BAUDIN Michael 
Objet : Re: [ot-users] Linear least squares always insert a constant

Hi Michael,

The LinearModelAlgorithm indeed relies on a linear basis (if no one is 
provided).

However you can define your own basis and provide it to the algorithm class :

"""
import openturns as ot

ot.RandomGenerator.SetSeed(0)
g = ot.SymbolicFunction(['x', 'y'], ['0.5+sin(x)-2*y'])

npoints = 50

x = ot.Uniform(-2,2).getSample(npoints)
x.stack(ot.Normal(0, 3).getSample(npoints))
x.setDescription(["x", "y"])
y = g(x)

 # Create basis B = ( [x,y]-->x, [x,y]-->y )
input_description = x.getDescription()
basis = ot.Basis([ot.SymbolicFunction(input_description, [description_i])  for 
description_i in input_description])

algo = ot.LinearModelAlgorithm(x, basis, y)
algo.run()
...
"""

The trend coefficients's size is 2 corresponding to the basis size

Sofiane

Le jeudi 28 mars 2019 à 20:09:52 UTC+1, BAUDIN Michael 
mailto:michael.bau...@edf.fr>> a écrit :



Dear all !



The LinearLeastSquares class in OT 1.12 always inserts a constant in the model, 
be it wanted by the user or not:



https://github.com/openturns/openturns/blob/d0802a1b17b60bd86afa234662a047bc4f04492f/lib/src/Base/MetaModel/LinearLeastSquares.cxx#L105



In the API, this term corresponds to the getConstant() method.



The same is true for LinearModelFactory.



In the demo script in PS, I use linear least squares to approximate the sine 
function with the polynomial basis 1, x, x^2, x^3. The linear model involves 4 
coefficients. An intercept is always added leading to 5 estimated coefficients, 
that I do not want.



g = ot.SymbolicFunction(['x'], ['0.5+sin(x)'])

npoints = 50

x=ot.Uniform(-2,2).getSample(npoints).sort()

y = g(x)



# Create input

basis = ot.SymbolicFunction(['x'], ['1','x','x^2','x^3'])

inputData = basis(x)



With LinearLeastSquares, I get a constant:



myLeastSquares = ot.LinearLeastSquares(inputData, y)

myLeastSquares.run()

beta0 = myLeastSquares.getConstant()[0]



With LinearModelFactory, I get 5 coefficicents instead of 4:



LMF = ot.LinearModelFactory()

linearModel = LMF.build(inputData, y)

beta = linearModel.getRegression()



As far as I can see, the LinearModelAlgorithm in OT 1.13 has the same behaviour:



https://github.com/openturns/openturns/blob/ce1bc890a907faeecde495f5528ed42e401153c7/lib/src/Uncertainty/Algorithm/MetaModel/LinearModel/LinearModelAlgorithm.cxx#L65



I assume that the constant is always there, so that the method prevents from 
having a bias in the estimate. But in cases where you want really to perform 
linear least squares, then there is an issue.



As far as I can see, the LeastSquaresMethod is the right tool. Unfortunately, 
this cannot be used from the Python API.



Am I correct ?



Best regards,



Michaël



PS



import openturns as ot

from openturns.viewer import View



g = ot.SymbolicFunction(['x'], ['0.5+sin(x)'])

npoints = 50

x=ot.Uniform(-2,2).getSample(npoints).sort()

y = g(x)



# Create input

basis = ot.SymbolicFunction(['x'], ['1','x','x^2','x^3'])

inputData = basis(x)



# Solve

myLeastSquares = ot.LinearLeastSquares(inputData, y)

myLeastSquares.run()

beta0 = myLeastSquares.getConstant()[0]

print("beta0=%s" % (beta0))

beta = myLeastSquares.getLinear()

print("beta=%s" % (beta))

# Check

responseSurface = myLeastSquares.getResponseSurface()

ypredicted = responseSurface(inputData)

#

graph = ot.Graph("Linear Model","x","y",True,"topleft")

curve = ot.Curve(x,ypredicted)

curve.setLegend("Linear Model")

graph.add(curve)

cloud = ot.Cloud(x,y)

cloud.setColor("red")

cloud.setLegend("Data")

graph.add(cloud)

View(graph)



#

ot.ResourceMap.SetAsString('R-executable-command','bla\\bla\\R.exe')

LMF = ot.LinearModelFactory()

linearModel = LMF.build(inputData, y)

beta = linearModel.getRegression()

print(beta)



Ce message et toutes les pièces jointes (ci-après le 'Message') sont établis à 
l'intention exclusive des destinataires et les informations qui y figurent sont 
strictement confidentielles. Toute utilisation de ce Message non conforme à sa 
destination, toute diffusion ou toute publication totale ou partielle, est 
interdite sauf autorisation expresse.

Si vous n'êtes pas le destinataire de ce Message, il vous est interdit de le 
copier, de le 

Re: [ot-users] Linear least squares always insert a constant

2019-04-24 Thread HADDAD Sofiane
Hi,
Sorry I missed the msg
You can: 1 - Wait for the next release ;-) 2 - Implement easily your own class 
that solve the linear problem without the ìntercept` 3 - Might rely on python 
modules (statsmodels, scikit...)
Regards,Sofiane 

Le mardi 2 avril 2019 à 17:03:33 UTC+2, BAUDIN Michael 
 a écrit :  
 
 #yiv3869854319 #yiv3869854319 -- _filtered #yiv3869854319 
{font-family:Helvetica;panose-1:2 11 6 4 2 2 2 2 2 4;} _filtered #yiv3869854319 
{panose-1:2 4 5 3 5 4 6 3 2 4;} _filtered #yiv3869854319 
{font-family:Calibri;panose-1:2 15 5 2 2 2 4 3 2 4;}#yiv3869854319 
#yiv3869854319 p.yiv3869854319MsoNormal, #yiv3869854319 
li.yiv3869854319MsoNormal, #yiv3869854319 div.yiv3869854319MsoNormal 
{margin:0cm;margin-bottom:.0001pt;font-size:12.0pt;font-family:New 
serif;}#yiv3869854319 a:link, #yiv3869854319 span.yiv3869854319MsoHyperlink 
{color:blue;text-decoration:underline;}#yiv3869854319 a:visited, #yiv3869854319 
span.yiv3869854319MsoHyperlinkFollowed 
{color:purple;text-decoration:underline;}#yiv3869854319 p 
{margin-right:0cm;margin-left:0cm;font-size:12.0pt;font-family:New 
serif;}#yiv3869854319 p.yiv3869854319msonormal, #yiv3869854319 
li.yiv3869854319msonormal, #yiv3869854319 div.yiv3869854319msonormal 
{margin-right:0cm;margin-left:0cm;font-size:12.0pt;font-family:New 
serif;}#yiv3869854319 p.yiv3869854319msochpdefault, #yiv3869854319 
li.yiv3869854319msochpdefault, #yiv3869854319 div.yiv3869854319msochpdefault 
{margin-right:0cm;margin-left:0cm;font-size:12.0pt;font-family:New 
serif;}#yiv3869854319 span.yiv3869854319msohyperlink {}#yiv3869854319 
span.yiv3869854319msohyperlinkfollowed {}#yiv3869854319 
span.yiv3869854319emailstyle17 {}#yiv3869854319 p.yiv3869854319msonormal1, 
#yiv3869854319 li.yiv3869854319msonormal1, #yiv3869854319 
div.yiv3869854319msonormal1 
{margin:0cm;margin-bottom:.0001pt;font-size:11.0pt;font-family:sans-serif;}#yiv3869854319
 span.yiv3869854319msohyperlink1 
{color:#0563C1;text-decoration:underline;}#yiv3869854319 
span.yiv3869854319msohyperlinkfollowed1 
{color:#954F72;text-decoration:underline;}#yiv3869854319 
span.yiv3869854319emailstyle171 
{font-family:sans-serif;color:windowtext;}#yiv3869854319 
p.yiv3869854319msochpdefault1, #yiv3869854319 li.yiv3869854319msochpdefault1, 
#yiv3869854319 div.yiv3869854319msochpdefault1 
{margin-right:0cm;margin-left:0cm;font-size:12.0pt;font-family:sans-serif;}#yiv3869854319
 span.yiv3869854319EmailStyle28 
{font-family:sans-serif;color:#1F497D;}#yiv3869854319 
.yiv3869854319MsoChpDefault {font-size:10.0pt;} _filtered #yiv3869854319 
{margin:70.85pt 70.85pt 70.85pt 70.85pt;}#yiv3869854319 
div.yiv3869854319WordSection1 {}#yiv3869854319 
Hi Sofiane,
 
  
 
Thanks for the trick : I did not know this constructor.
 
  
 
However, my particular need was really to get over the linear model. My 
particular applications are the calibration of a model based on the BLUE or 
ridge regression. In these cases, we really need to solve the basic linear 
least squares problem, without any link to a functional basis.
 
  
 
How would you do that ?
 
  
 
Best regards,
 
  
 
Michaël
 
  
 
  
 
Michaël BAUDIN
Ingénieur - Chercheur
EDF – R
Département PRISME
 
6, quai Watier
78401 CHATOU
michael.bau...@edf.fr
Tél. : 01 30 87 81 82
Fax : 01 30 87 82 13
 
  
 
De : sofiane_had...@yahoo.fr [mailto:sofiane_had...@yahoo.fr]
Envoyé : mardi 2 avril 2019 09:00
À : users@openturns.org; BAUDIN Michael 
Objet : Re: [ot-users] Linear least squares always insert a constant
 
  
 
Hi Michael,
 
  
 
The LinearModelAlgorithm indeed relies on a linear basis (if no one is 
provided).
 
  
 
However you can define your own basis and provide it to the algorithm class :
 
  
 
"""
 
import openturns as ot
 
  
 
ot.RandomGenerator.SetSeed(0)
 
g = ot.SymbolicFunction(['x', 'y'], ['0.5+sin(x)-2*y'])
 
  
 
npoints = 50
 
  
 
x = ot.Uniform(-2,2).getSample(npoints)
 
x.stack(ot.Normal(0, 3).getSample(npoints))
 
x.setDescription(["x", "y"])
 
y = g(x)
 
  
 
 # Create basis B = ( [x,y]-->x, [x,y]-->y )
 
input_description = x.getDescription()
 
basis = ot.Basis([ot.SymbolicFunction(input_description, [description_i])  for 
description_i in input_description])
 
  
 
algo = ot.LinearModelAlgorithm(x, basis, y)
 
algo.run()
 
...
 
"""
 
  
 
The trend coefficients's size is 2 corresponding to the basis size
 
 
 
Sofiane
 
  
 
Le jeudi 28 mars 2019 à 20:09:52 UTC+1, BAUDIN Michael  
a écrit :
 
  
 
  
 
Dear all !
 
 
 
The LinearLeastSquares class in OT 1.12 always inserts a constant in the model, 
be it wanted by the user or not:
 
 
 
https://github.com/openturns/openturns/blob/d0802a1b17b60bd86afa234662a047bc4f04492f/lib/src/Base/MetaModel/LinearLeastSquares.cxx#L105
 
 
 
In the API, this term corresponds to the getConstant() method.
 
 
 
The same is true for LinearModelFactory.
 
 
 
In the demo script in PS, I use linear least squares to approximate the sine 
function with the polynomial basis 1, x, x^2, x^3. The linear model involves 4 
coefficients. An 

[ot-users] Error creating a PCE model from two samples

2019-04-24 Thread armando alexandre
Hello,

I've been trying to recreate the example in the user cases  manual on
creating a PCE model from  a design experiment ( section 4.3.4)  but I am
getting an error:

return _metamodel.FunctionalChaosAlgorithm_run(self)
*TypeError: InvalidArgumentException : Error: the left gradient and the
right function have incompatible input or output dimensions.*

The code I am using is given below and I am using OT   1.11. Does anyone
have any idea what can be the problem?

Many thanks for the help,
Armando

from math import sin, pi
import openturns as ot

# Definition of the Ishigami function
dimension = 3
a = 7.0
b = 0.1
input_variables = ['xi1', 'xi2', 'xi3', 'a', 'b']
formula = ['sin(xi1) + a * (sin(xi2)) ^ 2 + b * xi3^4 * sin(xi1)']
full = ot.SymbolicFunction(input_variables, formula)
ishigami_model = ot.ParametricFunction(full, [3, 4], [a, b])



distribution = ot.ComposedDistribution([ot.Uniform(-pi, pi)] * dimension)
lhs_validation = ot.MonteCarloExperiment(distribution, 100)
input_validation = lhs_validation.generate()
X = input_validation
Y =  ishigami_model(input_validation)
coll = [ ]
for i in range ( dimension):
coll.append(ot.StandardDistributionPolynomialFactory(
distribution.getMarginal(i)))

enumerateFunction = ot.LinearEnumerateFunction( dimension )
productBasis = ot.OrthogonalProductPolynomialFactory( coll ,
enumerateFunction )
# c r e a t e the algor i thm
degree = 6
adaptiveStrategy = ot.FixedStrategy (productBasis , enumerateFunction .
getStrataCumulatedCardinal ( degree ) )
projection_strategy = ot.LeastSquaresStrategy ()
algo = ot.FunctionalChaosAlgorithm( X, Y, distribution , adaptiveStrategy
,projection_strategy )
algo.run()
___
OpenTURNS users mailing list
users@openturns.org
http://openturns.org/mailman/listinfo/users


[ot-users] Computation of leave-one-out residuals from a FunctionalChaosAlgorithm

2019-04-24 Thread COUPLET Mathieu
Hello everyone.

I would like to know whether there is an simple/cheap way to get the 
leave-one-out residuals from the result of a FunctionalChaosAlgorithm (using 
FixedStrategy + LARS + KFold or CorrectedLeaveOneOut) applied over the complete 
data set (formula (3) of 
http://openturns.github.io/openturns/latest/theory/meta_modeling/cross_validation.html),
 that is without rebuilding a DesignProxy, computing the "hat matrix", and so 
on.

I prefer these residuals to the least-square ones because I want a fair 
comparison with other techniques, in particular "interpolation" by kriging. 
Moreover, I don't want to use a "big" test/validation set so as to save as much 
data as possible for the regression.

Thank you,
Mathieu Couplet.




Ce message et toutes les pièces jointes (ci-après le 'Message') sont établis à 
l'intention exclusive des destinataires et les informations qui y figurent sont 
strictement confidentielles. Toute utilisation de ce Message non conforme à sa 
destination, toute diffusion ou toute publication totale ou partielle, est 
interdite sauf autorisation expresse.

Si vous n'êtes pas le destinataire de ce Message, il vous est interdit de le 
copier, de le faire suivre, de le divulguer ou d'en utiliser tout ou partie. Si 
vous avez reçu ce Message par erreur, merci de le supprimer de votre système, 
ainsi que toutes ses copies, et de n'en garder aucune trace sur quelque support 
que ce soit. Nous vous remercions également d'en avertir immédiatement 
l'expéditeur par retour du message.

Il est impossible de garantir que les communications par messagerie 
électronique arrivent en temps utile, sont sécurisées ou dénuées de toute 
erreur ou virus.


This message and any attachments (the 'Message') are intended solely for the 
addressees. The information contained in this Message is confidential. Any use 
of information contained in this Message not in accord with its purpose, any 
dissemination or disclosure, either whole or partial, is prohibited except 
formal approval.

If you are not the addressee, you may not copy, forward, disclose or use any 
part of it. If you have received this message in error, please delete it and 
all copies from your system and notify the sender immediately by return message.

E-mail communication cannot be guaranteed to be timely secure, error or 
virus-free.
___
OpenTURNS users mailing list
users@openturns.org
http://openturns.org/mailman/listinfo/users