Python scipy.linalg.lu() Examples
The following are 5
code examples of scipy.linalg.lu().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
scipy.linalg
, or try the search function
.
Example #1
Source File: blow.py From blow with Apache License 2.0 | 6 votes |
def __init__(self,in_channel): super(InvConv,self).__init__() weight=np.random.randn(in_channel,in_channel) q,_=linalg.qr(weight) w_p,w_l,w_u=linalg.lu(q.astype(np.float32)) w_s=np.diag(w_u) w_u=np.triu(w_u,1) u_mask=np.triu(np.ones_like(w_u),1) l_mask=u_mask.T self.register_buffer('w_p',torch.from_numpy(w_p)) self.register_buffer('u_mask',torch.from_numpy(u_mask)) self.register_buffer('l_mask',torch.from_numpy(l_mask)) self.register_buffer('l_eye',torch.eye(l_mask.shape[0])) self.register_buffer('s_sign',torch.sign(torch.from_numpy(w_s))) self.w_l=torch.nn.Parameter(torch.from_numpy(w_l)) self.w_s=torch.nn.Parameter(torch.log(1e-7+torch.abs(torch.from_numpy(w_s)))) self.w_u=torch.nn.Parameter(torch.from_numpy(w_u)) self.weight=None self.invweight=None return
Example #2
Source File: model.py From glow-pytorch with MIT License | 6 votes |
def __init__(self, in_channel): super().__init__() weight = np.random.randn(in_channel, in_channel) q, _ = la.qr(weight) w_p, w_l, w_u = la.lu(q.astype(np.float32)) w_s = np.diag(w_u) w_u = np.triu(w_u, 1) u_mask = np.triu(np.ones_like(w_u), 1) l_mask = u_mask.T w_p = torch.from_numpy(w_p) w_l = torch.from_numpy(w_l) w_s = torch.from_numpy(w_s) w_u = torch.from_numpy(w_u) self.register_buffer('w_p', w_p) self.register_buffer('u_mask', torch.from_numpy(u_mask)) self.register_buffer('l_mask', torch.from_numpy(l_mask)) self.register_buffer('s_sign', torch.sign(w_s)) self.register_buffer('l_eye', torch.eye(l_mask.shape[0])) self.w_l = nn.Parameter(w_l) self.w_s = nn.Parameter(logabs(w_s)) self.w_u = nn.Parameter(w_u)
Example #3
Source File: FDImplicitEu.py From Mastering-Python-for-Finance-source-codes with MIT License | 5 votes |
def _traverse_grid_(self): """ Solve using linear systems of equations """ P, L, U = linalg.lu(self.coeffs) aux = np.zeros(self.M-1) for j in reversed(range(self.N)): aux[0] = np.dot(-self.a[1], self.grid[0, j]) x1 = linalg.solve(L, self.grid[1:self.M, j+1]+aux) x2 = linalg.solve(U, x1) self.grid[1:self.M, j] = x2
Example #4
Source File: FDCnEu.py From Mastering-Python-for-Finance-source-codes with MIT License | 5 votes |
def _traverse_grid_(self): """ Solve using linear systems of equations """ P, L, U = linalg.lu(self.M1) for j in reversed(range(self.N)): x1 = linalg.solve(L, np.dot(self.M2, self.grid[1:self.M, j+1])) x2 = linalg.solve(U, x1) self.grid[1:self.M, j] = x2
Example #5
Source File: randomized_pca.py From neupy with MIT License | 5 votes |
def randomized_range_finder(A, size, n_iter): """ Computes an orthonormal matrix whose range approximates the range of A. Parameters ---------- A: 2D array The input data matrix size: integer Size of the return array n_iter: integer Number of power iterations used to stabilize the result Returns ------- Q: 2D array A (size x size) projection matrix, the range of which approximates well the range of the input matrix A. Notes ----- scikit-learn implementation """ # Generating normal random vectors with shape: (A.shape[1], size) Q = np.random.normal(size=(A.shape[1], size)) # Perform power iterations with Q to further 'imprint' the top # singular vectors of A in Q for i in range(n_iter): Q, _ = linalg.lu(np.dot(A, Q), permute_l=True) Q, _ = linalg.lu(np.dot(A.T, Q), permute_l=True) # Sample the range of A using by linear projection of Q # Extract an orthonormal basis Q, _ = linalg.qr(np.dot(A, Q), mode='economic') return Q