You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
I was trying out the MinimumProfit class. The optimization is really slow due to the usages of np.linalg.solve. By changing np.linalg.solve to torch.linalg.solve, I was able to speed it up by ~2x (on CPU) based on observation. Example codes:
import torch
class CustomMinimumProfit(MinimumProfit):
def _mean_passage_time(self, lower: int, upper: int, ar_coeff: float, ar_resid: np.array,
granularity: float) -> pd.Series:
# Build the grid for summation
grid = granularity * np.arange(lower, upper)
# Calculate the gaussian kernel
gaussian = self._gaussian_kernel(ar_coeff, grid, ar_resid)
# Calculate the mean passage time at each grid point
k_dim = gaussian.shape[0]
passage_time = torch.linalg.solve(torch.from_numpy(np.eye(k_dim) - gaussian), torch.from_numpy(np.ones(k_dim)))
# passage_time = np.linalg.solve(np.eye(k_dim) - gaussian, np.ones(k_dim))
# Return a pandas.Series indexed by grid points for easy retrieval
passage_time_df = pd.Series(passage_time, index=grid)
return passage_time_df
Describe the solution you'd like
I am not sure whether this repo wants to take in new dependency on PyTorch, but if the maintainer is willing to do so, using PyTorch to solve the equations would greatly speed to the optimization process.
Describe alternatives you've considered
None.
Additional context
None.
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
I was trying out the MinimumProfit class. The optimization is really slow due to the usages of
np.linalg.solve
. By changingnp.linalg.solve
totorch.linalg.solve
, I was able to speed it up by ~2x (on CPU) based on observation. Example codes:The idea is based on the discussion at https://stackoverflow.com/questions/62099939/solving-linear-equations-on-the-gpu-with-numpy-and-pytorch
Describe the solution you'd like
I am not sure whether this repo wants to take in new dependency on PyTorch, but if the maintainer is willing to do so, using PyTorch to solve the equations would greatly speed to the optimization process.
Describe alternatives you've considered
None.
Additional context
None.
The text was updated successfully, but these errors were encountered: