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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
#!/usr/bin/env python
import openturns as ot
import os
ot.TESTPREAMBLE()
process = ot.DiscreteMarkovChain()
print("Default constructor : process = ")
print(process)
process = ot.DiscreteMarkovChain(0, ot.SquareMatrix([[1.0, 0.0], [0.0, 1.0]]))
print("Constructor from int and SquareMatrix: process = ")
print(process)
transitionMatrix = ot.SquareMatrix([[0.0, 0.5, 0.5], [0.7, 0.0, 0.3], [0.8, 0.0, 0.2]])
print("transition matrix =")
print(transitionMatrix)
origin = 1
print("origin =")
print(origin)
process.setTransitionMatrix(transitionMatrix)
print("Transition matrix accessor : process = ")
print(process)
process.setOrigin(origin)
print("Origin accessor : process = ")
print(process)
process.setTimeGrid(ot.RegularGrid(0, 1, 20))
print("Time grid accessor : process = ")
print(process)
real = process.getRealization()
print("Realization :")
print(real)
future = process.getFuture(20)
print("One future :")
print(future)
futures = process.getFuture(20, 3)
print("3 different futures :")
print(futures)
dist = process.computeStationaryDistribution()
print("Distribution: ", dist)
process.exportToDOTFile("markov.dot")
with open("markov.dot") as f:
print(f.read())
if 0:
from graphviz import Source
path = "markov.dot"
s = Source.from_file(path)
s.view()
os.remove("markov.dot")
|