Simulate¤
compute_loss(loss_fn, observed_outputs, simulated_outputs)
¤
Compute the loss between observed and simulated outputs.
Arguments:
- loss_fn : loss function
- observed_outputs : list of data tensors to calibrate to
- simulated_outputs: list of simulated outputs
Example
loss_fn = torch.nn.MSELoss()
observed_outputs = [torch.tensor([1, 2, 3]), torch.tensor([4, 5, 6])]
simulated_outputs = [torch.tensor([1, 2, 3]), torch.tensor([4, 5, 6])]
compute_loss(loss_fn, observed_outputs, simulated_outputs) # tensor(0.)
Source code in blackbirds/simulate.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
simulate_and_observe_model(model, params, gradient_horizon=None)
¤
Runs the simulator for the given parameters and calls the model's observe method.
To avoid gradient instabilities, the gradient_horizon
argument limits the number of past time-steps
that are taken into account for the gradient's calculation. That is, if gradient_horizon
is 10, then
only the last 10 time-steps are used to calculate the gradient.
Arguments:
model
: A torch.nn.Module implemnting theinitialize
,forward
andobserve
methods.params
: The parameters taken by the model'sforward
method.n_timesteps
: Number of timesteps to simulate.gradient_horizon
: Gradient window, if None then all time-steps are used to calculate the gradient.
Source code in blackbirds/simulate.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
|