1 # -*- coding: utf-8 -*-
4 import matplotlib.pyplot as plt
5 np.random.seed(123456789)
9 print("Defining a set of artificial physical fields")
10 from Models.TwoDimensionalInverseDistanceCS2010 \
11 import TwoDimensionalInverseDistanceCS2010 as Equation
12 Eq = Equation(dimension, dimension)
15 print("Search for optimal measurement positions")
16 from adao import adaoBuilder
17 case = adaoBuilder.New()
18 case.setAlgorithmParameters(
19 Algorithm = 'MeasurementsOptimalPositioningTask',
22 "SampleAsnUplet":Eq.get_sample_of_mu(15, 15),
23 "MaximumNumberOfLocations":50,
25 "ErrorNormTolerance":0.,
26 "StoreSupplementaryCalculations":[
29 "EnsembleOfSimulations",
33 case.setBackground(Vector = [1,1] )
34 case.setObservationOperator(OneFunction = Eq.OneRealisation)
38 print("Graphical display of the results")
40 sp = case.get("EnsembleOfSimulations")[-1]
42 x1, x2 = np.meshgrid(x1, x2)
43 name = "Representation of a few snapshots of G out of a total of %i"%sp.shape[1]
45 fig, ax = plt.subplots(subplot_kw={"projection": "3d"}, figsize=(6, 6))
47 ax.set_xlabel("Position x1", fontweight='bold', color='red')
48 ax.set_ylabel("Position x2", fontweight='bold', color='red')
49 ax.set_zlabel("Magnitude of G", fontweight='bold', color='red')
50 for i in range(sp.shape[1]):
51 if i % 44 != 0: continue
52 ax.plot_surface(x1, x2, sp[:,i].reshape((dimension, dimension)), cmap='coolwarm')
53 fig.savefig("simple_MeasurementsOptimalPositioningTask31.png")
56 sv = case.get("SingularValues")[-1]
57 name = "Singular values of the set of G simulations"
59 fig, ax = plt.subplots(figsize=(6, 6))
61 ax.set_xlabel("Index of singular values, numbered from 1")
62 ax.set_ylabel("Magnitude of singular values")
63 ax.set_xlim(1, len(sv))
66 ax.plot(range(1, 1 + len(sv)), sv)
67 fig.savefig("simple_MeasurementsOptimalPositioningTask32.png")
72 op = case.get("OptimalPoints")[-1]
73 posx1 = [x1.reshape((-1,))[ip] for ip in op[:nbmax]]
74 posx2 = [x2.reshape((-1,))[ip] for ip in op[:nbmax]]
75 name = "Set of %i first optimal points of measurement"%nbmax
76 Omega = Eq.get_bounds_on_space()
78 fig, ax = plt.subplots(figsize=(6, 6))
80 ax.set_xlabel("Position x1", fontweight='bold', color='red')
81 ax.set_ylabel("Position x2", fontweight='bold', color='red')
82 ax.set_xlim(Omega[0][0] - 0.05, Omega[0][1] + 0.05)
83 ax.set_ylim(Omega[1][0] - 0.05, Omega[1][1] + 0.05)
84 ax.grid(True, which='both', linestyle=(0, (1, 5)), linewidth=0.5)
85 ax.plot(posx1, posx2, markersize=6, marker="o", linestyle='')
86 for i in range(len(posx1)):
87 ax.text(posx1[i] + 0.005, posx2[i] + 0.01, str(i + 1), fontweight='bold')
88 fig.savefig("simple_MeasurementsOptimalPositioningTask33.png")