File: t_PythonRandomVector_save.py

package info (click to toggle)
openturns 1.24-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 66,204 kB
  • sloc: cpp: 256,662; python: 63,381; ansic: 4,414; javascript: 406; sh: 180; xml: 164; yacc: 123; makefile: 98; lex: 55
file content (38 lines) | stat: -rwxr-xr-x 879 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#! /usr/bin/env python

import openturns as ot

ot.TESTPREAMBLE()


class RVEC(ot.PythonRandomVector):
    def __init__(self):
        # https://github.com/uqfoundation/dill/issues/300
        # super(RVEC, self).__init__(2)
        ot.PythonRandomVector.__init__(self, 2)
        self.setDescription(["R", "S"])

    def getRealization(self):
        X = [ot.RandomGenerator.Generate(), 2 + ot.RandomGenerator.Generate()]
        return X

    def getSample(self, size):
        X = []
        for i in range(size):
            X.append([ot.RandomGenerator.Generate(), 2 + ot.RandomGenerator.Generate()])
        return X

    def getMean(self):
        return [0.5, 2.5]


rv = ot.RandomVector(RVEC())
print(rv)
print(rv.getRealization())
print(rv.getMean())

# save
study = ot.Study()
study.setStorageManager(ot.XMLStorageManager("pyrv.xml"))
study.add("rv", rv)
study.save()