Skip to content

Commit fe77336

Browse files
committed
the
2 parents 207da95 + 7410c17 commit fe77336

1 file changed

Lines changed: 70 additions & 0 deletions

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import os
2+
import numpy as np
3+
import matplotlib.pyplot as plt
4+
import numpy.matlib
5+
#the least_square
6+
a = np.array([1, -1.5, 0.7]); b = np.array([1, 0.5]);d = 3 #
7+
8+
len_a = len(a) -1; len_b = len(b) - 1 ; L = 1500
9+
10+
Input_init = np.zeros(d + len_b) #the init_value of input
11+
Output_init = np.zeros(len_a) # the init_value of ouput
12+
13+
white_noise = np.random.normal(0, 1, L) # the white_noise
14+
15+
theta = np.append(a[1: len_a + 1], b)
16+
17+
theta_1 = np.zeros(len_a + len_b + 1)
18+
19+
alpha = 1
20+
c = 0.1
21+
22+
phi = np.array([]) # the
23+
thetae_1 = []
24+
thetae_2 = []
25+
thetae_3 = []
26+
thetae_4 = []
27+
28+
29+
for i in range(L):
30+
31+
temp = np.append(-Output_init, Input_init[d - 1: d + len_b])
32+
33+
temp_y = np.dot(temp, theta.transpose())# Y
34+
35+
thetae_temp = theta_1 + alpha * temp * (temp_y - temp * theta_1)/(np.dot(temp, temp) + c)
36+
37+
#print("the size of thetae: ", thetae_temp.shape)
38+
thetae_1.append(thetae_temp[0,0])
39+
thetae_2.append(thetae_temp[1,1])
40+
thetae_3.append(thetae_temp[2,2])
41+
thetae_4.append(thetae_temp[3,3])
42+
43+
#update the data
44+
theta_1 = thetae_temp
45+
46+
for k in range(d + len_b - 1, 0, -1):
47+
Input_init[k] = Input_init[k - 1]
48+
Input_init[0] = white_noise[i]
49+
50+
for j in range(len_a - 1, 0, -1):
51+
Output_init[j] = Output_init[j - 1]
52+
Output_init[0] = temp_y
53+
54+
55+
plt.figure(1)
56+
ax = plt.subplot(1, 1, 1)
57+
58+
plt.sca(ax)
59+
ax.plot(thetae_1, 'Red', label = 'thetae_1')
60+
ax.plot(thetae_2, 'Blue', label = 'thetae_2')
61+
ax.plot(thetae_3, 'Green', label = 'thetae_3')
62+
ax.plot(thetae_4, 'Yellow', label = 'thetae_4')
63+
#ax.plot(theta_real_3, 'burlywood', label = 'theta_real_3', linestyle="-" )
64+
#ax.plot(theta_real_4, 'coral', label = 'theta_real_4', linestyle="-" )
65+
plt.title('thetae')
66+
plt.xlabel("k")
67+
plt.ylabel("value")
68+
69+
ax.legend()
70+
plt.show()

0 commit comments

Comments
 (0)