-- Nov 8 In-Class Exercise
we have w as a 3x3 matrix,
x = 3x1 matrix,
h = 3x1 matrix,
since k = 2, h can only contain 1 non zero entry.
write the magnitude as a system of equations,
distance = ||x - w*h||
solving for h1, h2, h3
we get h1 = -1/2, h2=3, h3=1
evaluate the arrays for each of these h values with the other entries as 0.
import numpy as np
x = np.matrix([[-1], [3], [-3]])
w = np.matrix([[2, 0, 0], [0, 0, -1], [0, 3, 0]])
print(x)
print(w)
h = np.matrix([[-1 / 2], [0], [0]])
distance = np.linalg.norm(x - w * h)
print(distance)
h = np.matrix([[0], [3], [0]])
distance = np.linalg.norm(x - w * h)
print(distance)
h = np.matrix([[0], [0], [1]])
distance = np.linalg.norm(x - w * h)
print(distance)
4.24264068712
12.409673646
5.09901951359
since h1 = -1/2 had the lowest distance, we can use h = [-1/2,0,0]
(
Edited: 2017-11-08)
we have w as a 3x3 matrix,
x = 3x1 matrix,
h = 3x1 matrix,
since k = 2, h can only contain 1 non zero entry.
write the magnitude as a system of equations,
distance = ||x - w*h||
solving for h1, h2, h3
we get h1 = -1/2, h2=3, h3=1
evaluate the arrays for each of these h values with the other entries as 0.
import numpy as np
x = np.matrix([[-1], [3], [-3]])
w = np.matrix([[2, 0, 0], [0, 0, -1], [0, 3, 0]])
print(x)
print(w)
h = np.matrix([[-1 / 2], [0], [0]])
distance = np.linalg.norm(x - w * h)
print(distance)
h = np.matrix([[0], [3], [0]])
distance = np.linalg.norm(x - w * h)
print(distance)
h = np.matrix([[0], [0], [1]])
distance = np.linalg.norm(x - w * h)
print(distance)
4.24264068712
12.409673646
5.09901951359
since h1 = -1/2 had the lowest distance, we can use h = [-1/2,0,0]