Skip to content

Conversation

@greglucas
Copy link
Owner

More caching and optimization of numpy functions. Testing calling fit and predict multiple times in a row. I go from 5.7s to 0.57 so a 10x speedup here.

import pysecs
import numpy as np
import time

np.random.seed(0)
sec_locs = np.random.rand(1000, 3) * 100
obs_locs = np.random.rand(100, 3) * 100
obs_B = np.random.rand(5000, 100, 3) * 10000
pred_locs = np.random.rand(5000, 3) * 100

t0 = time.perf_counter()
secs = pysecs.SECS(sec_df_loc=sec_locs)

secs.fit(obs_locs, obs_B=obs_B)
secs.fit(obs_locs, obs_B=obs_B)

secs.predict(pred_locs)
secs.predict(pred_locs)

t1 = time.perf_counter()
print(f"Time taken: {t1 - t0:.4f} seconds")

Check for the common case of all equal observation standard
deviations and use numpy broadcasting in that case rather than
a for-loop over all times
@greglucas greglucas force-pushed the optimize-fit-predict branch from dafd3b5 to 172a715 Compare May 9, 2025 15:26
@greglucas greglucas merged commit 1cb6205 into main May 9, 2025
14 checks passed
@greglucas greglucas deleted the optimize-fit-predict branch May 9, 2025 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants