Ejemplo n.º 1
0
        sampleX[i] = p

    sampleZ = ot.NumericalSample(size, 1)
    for i in range(size):
        sampleZ[i] = ot.NumericalPoint(1, sampleY[i, 0] * sampleY[i, 0])
    print("LinearModelAdjustedRSquared=",
          ot.LinearModelTest.LinearModelAdjustedRSquared(sampleY, sampleZ))
    print("LinearModelFisher=",
          ot.LinearModelTest.LinearModelFisher(sampleY, sampleZ))
    print("LinearModelResidualMean=",
          ot.LinearModelTest.LinearModelResidualMean(sampleY, sampleZ))
    print("LinearModelRSquared=",
          ot.LinearModelTest.LinearModelRSquared(sampleY, sampleZ))

    # Durbin Watson
    ot.RandomGenerator.SetSeed(5415)
    eps = ot.Normal(0, 20)
    f = ot.NumericalMathFunction('x', '5+2*x+x^2-0.1*x^3')
    N = 15
    x = ot.NumericalSample([[0],[1.42857],[2.85714],[4.28571],[5.71429],[7.14286],
                            [8.57143],[10],[11.4286],[12.8571],[14.2857],[15.7143],
                            [17.1429],[18.5714],[20]])
    y = f(x) + eps.getSample(N)
    linmodel = ot.LinearModelFactory().build(x, y)
    dwTest = ot.LinearModelTest.LinearModelDurbinWatson(x, y)
    print('Durbin Watson = ', dwTest)

except:
    import sys
    print("t_LinearModelTest_std.py", sys.exc_info()[0], sys.exc_info()[1])
import openturns as ot
from openturns.viewer import View

ot.RandomGenerator.SetSeed(0)

dimension = 2
R = ot.CorrelationMatrix(dimension)
R[0, 1] = 0.8
distribution = ot.Normal([3.] * dimension, [2.] * dimension, R)
size = 100
sample = distribution.getSample(size)
firstSample = ot.Sample(size, 1)
secondSample = ot.Sample(size, 1)
for i in range(size):
    firstSample[i] = ot.Point(1, sample[i, 0])
    secondSample[i] = ot.Point(1, sample[i, 1])

lmtest = ot.LinearModelFactory().build(firstSample, secondSample)

drawLinearModelResidual = ot.VisualTest_DrawLinearModelResidual(
    firstSample, secondSample, lmtest)

View(drawLinearModelResidual, figure_kwargs={'figsize': (5, 5)})
Ejemplo n.º 3
0
        graph = ot.Normal().drawPDF()
        fname = 'testDraw.png'
        try:
            graph.draw(fname)
            os.remove(fname)
        except:
            raise
        print('OK')
    except:
        print('no')

    # check that rot package is installed
    print('4: linear model (R.rot)'.ljust(width), end=' ')
    try:
        lm = ot.LinearModelFactory().build(
            ot.Normal(2).getSample(10),
            ot.Normal().getSample(10))
        print('OK')
    except:
        print('no')

    # check XML support
    print('5: serialization (LibXML2)'.ljust(width), end=' ')
    try:
        storageManager = ot.XMLStorageManager('myFile.xml')
        print('OK')
    except:
        print('no')

    # check that analytical function are available
    print('6: analytical function (muParser)'.ljust(width), end=' ')
Ejemplo n.º 4
0
import openturns as ot
from openturns.viewer import View

N = 1000
#create a sample X
dist = ot.Triangular(1.0, 5.0, 10.0)
# create a Y sample : Y = 0.5 + 3 * X + eps
eps = ot.Normal(0.0, 1.0)
sample = ot.ComposedDistribution([dist, eps]).getSample(N)
f = ot.SymbolicFunction(['x', 'eps'], ['0.5+3.0*x+eps'])
sampleY = f(sample)
sampleX = sample.getMarginal(0)
sampleX.setName('X')
# Fit this linear model
factory = ot.LinearModelFactory()
regressionModel = factory.build(sampleX, sampleY, 0.9)
# Test the linear model fitting
graph = ot.VisualTest.DrawLinearModel(sampleX, sampleY, regressionModel)
cloud = graph.getDrawable(0)
cloud.setPointStyle('times')
graph.setDrawable(cloud, 0)
graph.setTitle('')
View(graph)
import openturns as ot
from openturns.viewer import View

N = 1000
#create a sample X
dist = ot.Triangular(1.0, 5.0, 10.0)
# create a Y sample : Y = exp(X/2) + eps
eps = ot.Normal(0.0, 1.0)
sample = ot.ComposedDistribution([dist, eps]).getSample(N)
f = ot.SymbolicFunction(['x', 'eps'], ['exp(0.5*x)+eps'])
sampleY = f(sample)
sampleX = sample.getMarginal(0)
sampleX.setName('X')
# same as good test
regressionModel = ot.LinearModelFactory().build(sampleX, sampleY, 0.9)
graph = ot.VisualTest.DrawLinearModel(sampleX, sampleY, regressionModel)
cloud = graph.getDrawable(0)
cloud.setPointStyle('times')
graph.setDrawable(cloud, 0)
graph.setTitle('')
View(graph)