Skip to content

Commit

Permalink
Use scipy lstsq instad of numpy
Browse files Browse the repository at this point in the history
  • Loading branch information
harskish committed Sep 2, 2020
1 parent 0609e82 commit ceb4f2a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
8 changes: 6 additions & 2 deletions decomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import torch
import json
from types import SimpleNamespace
import scipy
from scipy.cluster.vq import kmeans
from tqdm import trange
from netdissect.nethook import InstrumentedModel
Expand Down Expand Up @@ -125,8 +126,11 @@ def project(X, comp):
Z[i*B:(i+1)*B] = z.detach().cpu().numpy().reshape(B, -1)

# Solve least squares fit
print('Performing least squares fit')
M_t = np.linalg.lstsq(A, Z, rcond=None)[0] # torch.lstsq(Z, A)[0][:n_comp, :]

# gelsd = divide-and-conquer SVD; good default
# gelsy = complete orthogonal factorization; sometimes faster
# gelss = SVD; slow but less memory hungry
M_t = scipy.linalg.lstsq(A, Z, lapack_driver='gelsd')[0] # torch.lstsq(Z, A)[0][:n_comp, :]

# Solution given by rows of M_t
Z_comp = M_t[:n_comp, :]
Expand Down
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies:
- pillow=6.2
- ffmpeg
- tqdm
- scipy
- scikit-learn
- scikit-image
- boto3
Expand Down

0 comments on commit ceb4f2a

Please sign in to comment.