def computeBoxCox(factors, valuesInit, shift): # if no affine trend is considered graph = ot.Graph() myBoxCoxFactory = ot.BoxCoxFactory() myModelTransform = myBoxCoxFactory.build(valuesInit, [shift], graph) lambdaBoxCox = myModelTransform.getLambda()[0] # if an affine trend is considered (more computing time required) # works only in 1D # myBoxCoxFactory = LinearBoxCoxFactory() # myModelTransform, graph = myBoxCoxFactory.build(factors, valuesInit) # lambdaBoxCox = myModelTransform.getLambda()[0] return lambdaBoxCox, graph
# Transform myXproc to make its variance depend on the vertex (s,t) # and to get a positive process # thanks to the spatial function g # myXtProcess R --> R g = ot.SymbolicFunction(['x1'], ['exp(x1)']) myDynTransform = ot.ValueFunction(g, 2) myXtProcess = ot.CompositeProcess(myDynTransform, myXproc) myField = myXtProcess.getRealization() graphMarginal1 = ot.KernelSmoothing().build(myField.getValues()).drawPDF() graphMarginal1.setTitle("") graphMarginal1.setXTitle("X") graphMarginal1.setLegendPosition("") # Initiate a BoxCoxFactory myBoxCoxFactory = ot.BoxCoxFactory() graph = ot.Graph() shift = [0.0] # We estimate the lambda parameter from the field myField # All values of the field are positive myModelTransform = myBoxCoxFactory.build(myField, shift, graph) graphMarginal2 = ot.KernelSmoothing().build( myModelTransform(myField).getValues()).drawPDF() graphMarginal2.setTitle("") graphMarginal2.setXTitle("T_lambda(X)") graphMarginal2.setLegendPosition("") graph.setLegendPosition("bottomright")
scale = [0.2, 0.2] myCovModel = ot.ExponentialModel(scale, amplitude) myXproc = ot.GaussianProcess(myCovModel, myMesh) g = ot.SymbolicFunction(['x1'], ['exp(x1)']) myDynTransform = ot.ValueFunction(g, myMesh) myXtProcess = ot.CompositeProcess(myDynTransform, myXproc) # %% # Draw a field field = myXtProcess.getRealization() graph = field.drawMarginal(0) view = viewer.View(graph) # %% # Draw values marginal = ot.HistogramFactory().build(field.getValues()) graph = marginal.drawPDF() view = viewer.View(graph) # %% # Build the transformed field through Box-Cox myModelTransform = ot.BoxCoxFactory().build(field) myStabilizedField = myModelTransform(field) # %% # Draw values marginal = ot.HistogramFactory().build(myStabilizedField.getValues()) graph = marginal.drawPDF() view = viewer.View(graph) plt.show()