tapios / risk-networks

Code for risk networks: a blend of compartmental models, graphs, data assimilation and semi-supervised learning
Other
2 stars 2 forks source link

Refactor flatten in MasterEquationsModelEnsemble "simulate" and "simulate_backwards" #123

Closed dburov190 closed 4 years ago

dburov190 commented 4 years ago

Here https://github.com/dburov190/risk-networks/blob/839d2a02518290180fc863183e36973b12a03c26/epiforecast/risk_simulator.py#L239-L240 and here https://github.com/dburov190/risk-networks/blob/839d2a02518290180fc863183e36973b12a03c26/epiforecast/risk_simulator.py#L278-L279 in the first line, self.y0.size should be written instead of len(...) because

  1. it's clearer and easier to read
  2. it doesn't create a temporary variable, so saves one unnecessary memory allocation

In the second line, np.copy can be removed for clarity, since flatten returns a copy anyway.

odunbar commented 4 years ago

I can see why this was originally coded, as you make a container of size y0.flatten() and then use it to store y0.flatten(). But I also prefer size here.