Efficiently reconstruct state variable from event times in R
I have a discrete-time stochastic model where individuals enter in state 0, can step up/down in their state value, and then exit. The numbers of individuals and time-steps are very large so I only save the times of entry, state-transitions (up, down), and exit. From these logs, I want to reconstruct the mean state value among active individuals (after entry & before exit) for all time.
Efficiently reconstruct state variable from event times in R
I have a discrete-time stochastic model where individuals enter in state 0, can step up/down in their state value, and then exit. The numbers of individuals and time-steps are very large so I only save the times of entry, state-transitions (up, down), and exit. From these logs, I want to reconstruct the mean state value among active individuals (after entry & before exit) for all time.
R code: Speed up function: Cross product of all row permutations of an array
I have written a function to that uses a numerical 2D-array (dimension n x m) as input and calculates the cross product of all row permutations of this input array. The output is a 2D-array (dimension n x n). This function becomes increasingly slow as I scale n and m.