Created
March 13, 2016 11:51
-
-
Save geffy/3b6008d574103a1886a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
%pylab inline | |
def generate_raw_weights(n, a, b, p): | |
res = np.zeros((n, n)) | |
for i in range(n): | |
for j in range(n): | |
sq_dist = ((i - a)**2 + (j - b)**2) *1.0/ n**2 | |
res[i,j] = exp(-sq_dist*p) | |
return res | |
n = 100 | |
k = 3 | |
A = np.random.rand(n, k).dot(np.random.rand(n, k).T) | |
B = np.random.rand(n, k).dot(np.random.rand(n, k).T) | |
raw_mask1 = generate_raw_weights(n, 10, 10, 2) | |
raw_mask2 = generate_raw_weights(n, n-10, n-10, 5) | |
# normalization | |
mask1 = raw_mask1 / (raw_mask1 + raw_mask2) | |
mask2 = raw_mask2 / (raw_mask1 + raw_mask2) | |
# plot | |
figsize(10, 4) | |
subplot(121) | |
title('w_a') | |
imshow(mask1, interpolation='None') | |
colorbar() | |
subplot(122) | |
title('w_b') | |
imshow(mask2, interpolation='None') | |
colorbar() | |
print 'shape(A)={}, shape(B)={}'.format(A.shape, B.shape) | |
print 'rank(A) = {}, rank(B) = {}'.format(np.linalg.matrix_rank(A), np.linalg.matrix_rank(B)) | |
print 'rank(A+B) = {}'.format(np.linalg.matrix_rank(A + B)) | |
print 'rank(w_a*A + w_b*B) = {}'.format(np.linalg.matrix_rank(mask1*A + mask2*B)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment