Exemple #1
0
#! /usr/bin/env python

from __future__ import print_function
import openturns as ot
import numpy as np
import os

ot.TESTPREAMBLE()

sample = ot.Normal(3).getSample(1000)
tree = ot.KDTree(sample)
print('tree=', tree)

test = ot.Normal(3).getSample(100)

sample_np = np.array(sample)
test_np = np.array(test)


def nearest_debug(x):
    global sample_np
    a = np.sum(np.square(sample_np - x), axis=1)
    return int(np.argmin(a))


def nearest_debug_indices(x):
    global sample_np
    a = np.sum(np.square(sample_np - x), axis=1)
    return a.argsort()

Exemple #2
0
print('ts1=', ts1)

# We get the values of the second element of the ts
values1 = ts1.getValueAtIndex(1)
print('values of the second element=', values1)

# We set new values for the second element of the ts
newValues = values1 * 2.
ts1.setValueAtIndex(1, newValues)
values2 = ts1.getValueAtIndex(1)
print('ts1=', ts1)
print('modified values of the second element=', values2, ' should be ',
      newValues)

# We get the values of the second element of the ts
tree = ot.KDTree(ts1.getMesh().getVertices())
values3 = ts1.getValueAtIndex(tree.query([-1.0]))
print('values at t=-1.0 =', values3)
values4 = ts1.getValueAtIndex(tree.query([1.45]))
print('values at t=1.45 =', values4)
values5 = ts1.getValueAtIndex(tree.query([1.54]))
print('values at t=1.54 =', values5)
values6 = ts1.getValueAtIndex(tree.query([14.5]))
print('values at t=14.5 =', values6)

# We set new values for the third element of the ts
ts1.setValueAtIndex(tree.query([1.54]), values6 * -1.0)
print('ts1=', ts1)

ts2 = ot.TimeSeries(10, dim)
print('ts2=', ts2)
    myStudy.add('sormResult', sormResult)

    # Create a RandomGeneratorState
    ot.RandomGenerator.SetSeed(0)
    randomGeneratorState = ot.RandomGeneratorState(
        ot.RandomGenerator.GetState())
    myStudy.add('randomGeneratorState', randomGeneratorState)

    # Create a GeneralLinearModelResult
    generalizedLinearModelResult = ot.GeneralLinearModelResult()
    generalizedLinearModelResult.setName('generalizedLinearModelResult')
    myStudy.add('generalizedLinearModelResult', generalizedLinearModelResult)

    # KDTree
    sample = ot.Normal(3).getSample(10)
    kDTree = ot.KDTree(sample)
    myStudy.add('kDTree', kDTree)

    # TensorApproximationAlgorithm/Result
    dim = 1
    model = ot.SymbolicFunction(['x'], ['x*sin(x)'])
    distribution = ot.ComposedDistribution([ot.Uniform()] * dim)
    factoryCollection = [ot.FourierSeriesFactory()] * dim
    functionFactory = ot.OrthogonalProductFunctionFactory(factoryCollection)
    size = 10
    X = distribution.getSample(size)
    Y = model(X)
    nk = [5] * dim
    rank = 1
    algo = ot.TensorApproximationAlgorithm(X, Y, distribution, functionFactory,
                                           nk, rank)
Exemple #4
0
ot.PlatformInfo.SetNumericalPrecision(6)
# 1D example
mesh1D = ot.Mesh()
print("Default 1D mesh=", mesh1D)
vertices = ot.Sample(0, 1)
vertices.add([0.5])
vertices.add([1.5])
vertices.add([2.1])
vertices.add([2.7])
simplicies = [[]] * 3
simplicies[0] = [0, 1]
simplicies[1] = [1, 2]
simplicies[2] = [2, 3]
mesh1D = ot.Mesh(vertices, simplicies)
mesh1Ddomain = ot.MeshDomain(mesh1D)
tree = ot.KDTree(vertices)
enclosingSimplex = ot.EnclosingSimplexAlgorithm(vertices, simplicies)
print("1D mesh=", mesh1D)
print("Is empty? ", mesh1D.isEmpty())
print("vertices=", mesh1D.getVertices())
print("simplices=", mesh1D.getSimplices())
print("volume=", "%.3f" % mesh1D.getVolume())
print("simplices volume=", mesh1D.computeSimplicesVolume())
p = [1.3]
print("is p=", p, " in mesh? ", mesh1Ddomain.contains(p))
point = [1.8]
print("Nearest index(", point, ")=", tree.query(point))
simplex = enclosingSimplex.query(point)
found, coordinates = mesh1D.checkPointInSimplexWithCoordinates(point, simplex)
print("Nearest index(", point, "), found=", found, "simplex=", int(simplex),
      "coordinates=", coordinates)