'How can I retrieve the value at which the error occured in Python?
I'm using a package in Python and it often throws up an error. The error is from the Cholesky decomposition (specifically from the function torch.linalg_cholesky). By the time the error arises, my input data to the original function has gone through several steps, so that I don't have immediate access to the input to torch.linalg_cholesky, without performing those many intermediate steps myself. Is there a way I can retrieve the values that were used as an input to the torch.linalg_cholesky function?
More details: I'm using the MOGPTK package in Python. As part of this, I run the function
model_BNSE.init_parameters('BNSE')
Often I get the following error:
File "C:\Users\simon\AppData\Local\Temp\ipykernel_37540\2931476796.py", line 1, in <module>
model_BNSE.init_parameters('BNSE')
File "c:\users\simon\documents\project\python packages\mogptk\mogptk\models\mosm.py", line 85, in init_parameters
amplitudes, means, variances = self.dataset.get_bnse_estimation(self.Q)
File "c:\users\simon\documents\project\python packages\mogptk\mogptk\dataset.py", line 615, in get_bnse_estimation
channel_amplitudes, channel_means, channel_variances = channel.get_bnse_estimation(Q, n)
File "c:\users\simon\documents\project\python packages\mogptk\mogptk\data.py", line 955, in get_bnse_estimation
w, psd = BNSE(x[:,i], y, max_freq=nyquist[i], n=n)
File "c:\users\simon\documents\project\python packages\mogptk\mogptk\bnse.py", line 35, in BNSE
loss = optimizer.step(model.loss)
File "C:\Users\simon\Anaconda3\envs\myenv\lib\site-packages\torch\optim\optimizer.py", line 88, in wrapper
return func(*args, **kwargs)
File "C:\Users\simon\Anaconda3\envs\myenv\lib\site-packages\torch\autograd\grad_mode.py", line 27, in decorate_context
return func(*args, **kwargs)
File "C:\Users\simon\Anaconda3\envs\myenv\lib\site-packages\torch\optim\lbfgs.py", line 437, in step
loss = float(closure())
File "C:\Users\simon\Anaconda3\envs\myenv\lib\site-packages\torch\autograd\grad_mode.py", line 27, in decorate_context
return func(*args, **kwargs)
File "c:\users\simon\documents\project\python packages\mogptk\mogptk\gpr\model.py", line 219, in loss
loss = -self.log_marginal_likelihood() - self.log_prior()
File "c:\users\simon\documents\project\python packages\mogptk\mogptk\gpr\model.py", line 277, in log_marginal_likelihood
L = self._cholesky(Kff, add_jitter=self.variance_per_data) # NxN
File "c:\users\simon\documents\project\python packages\mogptk\mogptk\gpr\model.py", line 209, in _cholesky
raise CholeskyException(e.args[0], K, self)
CholeskyException: torch.linalg_cholesky: The factorization could not be completed because the input is not positive-definite (the leading minor of order 13 is not positive-definite).`
I would like to be able to retrieve the matrix Kff that went into the function at the point the error occured.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
