-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathfonctions_regression_1.py
More file actions
87 lines (57 loc) · 1.45 KB
/
fonctions_regression_1.py
File metadata and controls
87 lines (57 loc) · 1.45 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
N = 100
VX = np.linspace(0.1, 1.5, N)
VY = np.linspace(0.1, 5.0, N)
X,Y = np.meshgrid(VX, VY)
def f(a,b):
# objectifs du genre y = 0.5x+1.5
points = [(2,3),(3,5),(4,4),(5,6),(6,6)]
z = 0
for P in points:
z = z + (a*P[0]-P[1]+b)**2
return z/(1+a**2)
Z = f(X,Y)
def affiche_surface():
fig = plt.figure()
ax = plt.axes(projection='3d')
# Tweaking display region and labels
# ax.set_xlim(-3.0, 3.0)
# ax.set_ylim(-3.0, 3.0)
# ax.set_zlim(-0.6, 0.6)
ax.set_xlabel('axe x')
ax.set_ylabel('axe y')
ax.set_zlabel('axe z')
ax.view_init(40, -30)
ax.plot_surface(X, Y, Z)
plt.tight_layout()
# plt.savefig('fonctions-surface-3a.png')
# trouver une séquence de vues
plt.show()
return
def affiche_niveaux():
fig = plt.figure()
mes_niveaux = np.linspace(0,5,20)
plt.contour(X, Y, Z, mes_niveaux, colors='black')
plt.scatter(0.79,1.61,color='blue')
plt.xlabel('axe a')
plt.ylabel('axe b')
plt.tight_layout()
# plt.savefig('fonctions-regression.png')
plt.show()
return
def cherche_minimum():
# Minimum sur la grille
imin, jmin = np.unravel_index(np.argmin(Z, axis=None), Z.shape)
print("--- Minimum sur la grille ---")
print("Taille de la grille :",N,"x",N)
print("Nombre de points :",N**2)
print(X[imin,jmin],Y[imin,jmin],Z[imin,jmin])
return
# affiche_surface()
affiche_niveaux()
cherche_minimum()
# a = 0.79
# b = 1.61
# f = 1.219