AO
Size: a a a
AO
AO
AO
АГ
AO
K
АГ
AO
АГ
B
d
def squared_error2(x, y, w0, w1):
diff = y - (w0 + w1 * x)
return np.sum(np.square(diff))
def squared_error3(x, y, w0, w1):
x = np.array(x)
x = x.reshape(1, x.size)
y = np.array(y)
y = y.reshape(1, y.size)
w1 = np.array(w1)
w1 = w1.reshape(w1.size, 1)
m = w0 + w1.dot(x) - y
m = np.square(m)
result = m.sum(axis=1)
if result.size == 1:
return result[0]
return result
Вызываем вот так:w0 = 50Вот какой вариант должен быть самым быстрым, а какой самым медленным?
w1 = np.linspace(-5, 5, 10001)
a1 = np.array([squared_error2(x, y, w0, wi) for wi in w1])
a2 = np.array([squared_error3(x, y, w0, wi) for wi in w1])
a3 = squared_error3(x, y, w0, w1)
А
def squared_error2(x, y, w0, w1):
diff = y - (w0 + w1 * x)
return np.sum(np.square(diff))
def squared_error3(x, y, w0, w1):
x = np.array(x)
x = x.reshape(1, x.size)
y = np.array(y)
y = y.reshape(1, y.size)
w1 = np.array(w1)
w1 = w1.reshape(w1.size, 1)
m = w0 + w1.dot(x) - y
m = np.square(m)
result = m.sum(axis=1)
if result.size == 1:
return result[0]
return result
Вызываем вот так:w0 = 50Вот какой вариант должен быть самым быстрым, а какой самым медленным?
w1 = np.linspace(-5, 5, 10001)
a1 = np.array([squared_error2(x, y, w0, wi) for wi in w1])
a2 = np.array([squared_error3(x, y, w0, wi) for wi in w1])
a3 = squared_error3(x, y, w0, w1)
d
А
d
А
🐙
d
SA
n🐈
def squared_error2(x, y, w0, w1):
diff = y - (w0 + w1 * x)
return np.sum(np.square(diff))
def squared_error3(x, y, w0, w1):
x = np.array(x)
x = x.reshape(1, x.size)
y = np.array(y)
y = y.reshape(1, y.size)
w1 = np.array(w1)
w1 = w1.reshape(w1.size, 1)
m = w0 + w1.dot(x) - y
m = np.square(m)
result = m.sum(axis=1)
if result.size == 1:
return result[0]
return result
Вызываем вот так:w0 = 50Вот какой вариант должен быть самым быстрым, а какой самым медленным?
w1 = np.linspace(-5, 5, 10001)
a1 = np.array([squared_error2(x, y, w0, wi) for wi in w1])
a2 = np.array([squared_error3(x, y, w0, wi) for wi in w1])
a3 = squared_error3(x, y, w0, w1)