CorrelationCalculator¶
- class torch_sim.properties.correlations.CorrelationCalculator(*, window_size, properties, device, normalize=True)[source]¶
Bases:
object
Efficient on-the-fly correlation function calculator.
Manage the calculation of time correlation functions during simulation, with support for both autocorrelation and cross-correlation of arbitrary properties. It maintains a sliding window of historical data and performs efficient updates.
- Variables:
window_size – Number of steps to keep in memory
properties – Map of property names to their calculators
buffers – Circular buffers for storing historical data
correlations – Current correlation results
device – Device where calculations are performed
- Parameters:
Example: Computing correlation function in loop:
corr_calc = CorrelationCalculator( window_size=100, properties={"velocity": lambda state: state.velocities}, ) for step in range(n_steps): state = integrator.step(state) # Call update at desired frequency if step % 10 == 0: # Sample every 10 steps corr_calc.update(state) # Periodically retrieve correlation functions if step % 1000 == 0: acfs = corr_calc.get_auto_correlations() # Process or save acfs...
- update(state)[source]¶
Update correlation calculations with new state data.
- Parameters:
state (SimState) – Current simulation state
- Return type:
None