Exemplo n.º 1
0
 def setUpClass(cls):
     # attributes to compare a one-dimensional InverseWishart to the
     # equivalent InverseGamma distribution
     U = ot.Uniform(0., 1.)
     scale = 10. * U.getRealization()[0]
     DoF = 3. + U.getRealization()[0]  # Degrees of Freedom
     cls.k, cls.beta = 0.5 * DoF, 0.5 * scale
     cls.one_dimensional_inverse_wishart \
         = ot.InverseWishart(ot.CovarianceMatrix([[scale]]), DoF)
     cls.inverse_gamma = ot.InverseGamma(cls.k, 1. / cls.beta)
     # attributes to test a multi-dimensional InverseWishart
     cls.dimension = 5
     cls.DoF = cls.dimension + 3 + U.getRealization()[0]
     cls.L = ot.TriangularMatrix(cls.dimension)
     diagL = ot.Uniform(0.5, 1.).getSample(cls.dimension)
     cls.determinant = 1.
     for i in range(cls.dimension):
         cls.determinant *= diagL[i, 0]
         cls.L[i, i] = diagL[i, 0]
         for j in range(i):
             cls.L[i, j] = U.getRealization()[0]
     cls.determinant *= cls.determinant
     cls.Scale = ot.CovarianceMatrix(cls.L * cls.L.transpose())
Exemplo n.º 2
0
#! /usr/bin/env python

import openturns as ot

ref_values = [[1.0, 0.0], [0.0, 0.5]]

mats = [ot.Matrix(ref_values),
        ot.SquareMatrix(ref_values),
        ot.TriangularMatrix(ref_values),
        ot.SymmetricMatrix(ref_values),
        ot.CovarianceMatrix(ref_values),
        ot.CorrelationMatrix(ref_values)]
mats.extend([
    ot.ComplexMatrix(ref_values),
    ot.HermitianMatrix(ref_values),
    ot.TriangularComplexMatrix(ref_values),
    ot.SquareComplexMatrix(ref_values)])

for a in mats:

    # try conversion
    ref = ot.Matrix([[1.0, 0.0], [0.0, 0.5]])
    iname = a.__class__.__name__
    print('a=', a)

    # try scalar mul
    try:
        s = 5.
        ats = a * s
        print('a*s=', ats)
        sta = s * a
Exemplo n.º 3
0
a0 = np.array(((1., 2.), (3., 4.), (5., 6.)))
m0 = ot.Matrix(a0)
print("array", a0, "=> Matrix", m0)
a1 = np.array(m0)
print("Matrix", m0, "=> array", a1)
m0 = ot.Matrix(a0.transpose())
print("with transpose, array", a0.transpose(), "=> Matrix", m0)

a0 = np.array(((1., 2.), (3., 4.)))
m0 = ot.SquareMatrix(a0)
print("array", a0, "=> SquareMatrix", m0)
a1 = np.array(m0)
print("SquareMatrix", m0, "=> array", a1)

a0 = np.array(((1., 2.), (0., 4.)))
m0 = ot.TriangularMatrix(a0)
print("array", a0, "=> TriangularMatrix", m0)
a1 = np.array(m0)
print("TriangularMatrix", m0, "=> array", a1)

a0 = np.array(((1., 2.), (2., 4.)))
m0 = ot.SymmetricMatrix(a0)
print("array", a0, "=> SymmetricMatrix", m0)
m0[1, 0] = 3.0
a1 = np.array(m0)
print("SymmetricMatrix", m0, "=> array", a1)

a0 = np.array(
    (((1., 2.), (3., 4.), (5., 6.)), ((7., 8.), (9., 10.), (11., 12.)),
     ((13., 14.), (15., 16.), (17., 18.)), ((19., 20.), (21., 22.), (23.,
                                                                     24.))))