Blealtan / efficient-kan

An efficient pure-PyTorch implementation of Kolmogorov-Arnold Network (KAN).
MIT License
4.11k stars 361 forks source link

torch._C._LinAlgError: torch.linalg.lstsq: (Batch element 1): The least squares solution could not be computed because the input matrix does not have full rank (error code: 4). #50

Open black-yt opened 2 months ago

black-yt commented 2 months ago

when update grid:

torch._C._LinAlgError: torch.linalg.lstsq: (Batch element 1): The least squares solution could not be computed because the input matrix does not have full rank (error code: 4).

how to solve this problem? thanks!

wanide commented 2 months ago

+1

hoangthangta commented 2 months ago

You can use torch.linalg.matrix_rank(A) to check the matrix's rank. In this case, we need a full-rank matrix. If not, use a regularization, may be:

# Tikhonov regularization 
lambda_value = 1e-3
A_reg = A + lambda_value * torch.eye(A.size(-1))
solution, _ = torch.linalg.lstsq(A_reg, B)