1 # -*- coding: utf-8 -*-
3 from numpy import array, ravel
4 def QuadFunction( coefficients ):
6 Simulation : y = a x^2 + b x + c
8 a, b, c = list(ravel(coefficients))
9 x_points = (-5, 0, 1, 3, 10)
12 y_points.append( a*x*x + b*x + c )
13 return array(y_points)
15 Xb = array([1., 1., 1.])
16 Yobs = array([57, 2, 3, 17, 192])
18 print("Iterative resolution of the calibration problem")
19 print("-----------------------------------------------")
21 from adao import adaoBuilder
22 case = adaoBuilder.New('')
23 case.setBackground( Vector = Xb, Stored=True )
24 case.setBackgroundError( ScalarSparseMatrix = 1.e6 )
25 case.setObservation( Vector = Yobs, Stored=True )
26 case.setObservationError( ScalarSparseMatrix = 1. )
27 case.setObservationOperator( OneFunction = QuadFunction )
28 case.setAlgorithmParameters(
31 'StoreSupplementaryCalculations': [
37 Info=" Intermediate state at the current iteration:",
38 Template='ValuePrinter',
39 Variable='CurrentState',
44 #-------------------------------------------------------------------------------
46 print("Calibration of %i coefficients in a 1D quadratic function on %i measures"%(
47 len(case.get('Background')),
48 len(case.get('Observation')),
50 print("----------------------------------------------------------------------")
52 print("Observation vector.................:", ravel(case.get('Observation')))
53 print("A priori background state..........:", ravel(case.get('Background')))
55 print("Expected theoretical coefficients..:", ravel((2,-1,2)))
57 print("Calibration resulting coefficients.:", ravel(case.get('Analysis')[-1]))