File: BoxCoxFactory.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 (63 lines) | stat: -rw-r--r-- 1,940 bytes parent folder | download
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
61
62
63
import openturns as ot
from matplotlib import pyplot as plt
from openturns.viewer import View

# Create a process X: R^2 --> R^2

# Define a bi dimensional mesh as a box
indices = ot.Indices([40, 20])
mesher = ot.IntervalMesher(indices)
lowerBound = [0.0, 0.0]
upperBound = [2.0, 1.0]
interval = ot.Interval(lowerBound, upperBound)
mesh = mesher.build(interval)


# Define a scalar temporal Gaussian process on the mesh
# this process is stationary
# xProc R^2 --> R
amplitude = [1.0]
scale = [0.2, 0.2]
covModel = ot.ExponentialModel(scale, amplitude)
xProc = ot.GaussianProcess(covModel, mesh)


# Transform xProc to make its variance depend on the vertex (s,t)
# and to get a positive process
# thanks to the spatial function g
# xtProcess R --> R
g = ot.SymbolicFunction(["x1"], ["exp(x1)"])
dynTransform = ot.ValueFunction(g, mesh)
xtProcess = ot.CompositeProcess(dynTransform, xProc)

field = xtProcess.getRealization()
graphMarginal1 = ot.KernelSmoothing().build(field.getValues()).drawPDF()
graphMarginal1.setTitle("")
graphMarginal1.setXTitle("X")
graphMarginal1.setLegendPosition("")

# Initiate a BoxCoxFactory
factory = ot.BoxCoxFactory()

shift = [0.0]

# We estimate the lambda parameter from the field field
# All values of the field are positive
transform, graph = factory.buildWithGraph(field, shift)
graphMarginal2 = ot.KernelSmoothing().build(transform(field).getValues()).drawPDF()
graphMarginal2.setXTitle("T_lambda(X)")
graphMarginal2.setLegendPosition("")

graph.setLegendPosition("lower right")

fig = plt.figure(figsize=(12, 4))
axis = fig.add_subplot(131)
axis.set_xlim(auto=True)
View(graphMarginal1, figure=fig, axes=[axis], add_legend=True)
axis = fig.add_subplot(132)
axis.set_xlim(auto=True)
View(graph, figure=fig, axes=[axis], add_legend=True)
axis = fig.add_subplot(133)
axis.set_xlim(auto=True)
View(graphMarginal2, figure=fig, axes=[axis], add_legend=True)
fig.suptitle("Box Cox log-likelihood example")