rajeshrinet / pyross

PyRoss: inference, forecasts, and optimised control of epidemiological models in Python. github.com/rajeshrinet/pyross
https://pyross.readthedocs.io
MIT License
169 stars 57 forks source link

Unnecessarily convoluted code #48

Open yairdaon opened 5 months ago

yairdaon commented 5 months ago

In examples/inference/ex08-optimal_design.ipynb in the fifth code cell the following lines appear:

make a fltr to get Is for each age class

fltr1=np.kron([[0, 0, 0, 1]], np.identity(M)) obs1=np.einsum('ij,kj->ki', fltr1, x)

This is a very interesting way of writing obs1 = x[:,-2:]

Verify:

import numpy as np M = 2 x = np.random.randn(200, 4*M)

fltr1=np.kron([[0, 0, 0, 1]], np.identity(M)) np.all(np.einsum('ij,kj->ki', fltr1, x) == x[:,-2:])