greta-dev / greta.dynamics

a greta extension for modelling dynamical systems
https://greta-dev.github.io/greta.dynamics/
Other
6 stars 2 forks source link

Tf while loop #11

Closed goldingn closed 5 years ago

goldingn commented 5 years ago

Switch to doing iterate_matrix() in a TF while_loop construct. This also enables setting a numerical convergence tolerance (in addition to maximum number of iterations), and reports whether or not that convergence has been reached.

Two planned additional features that are possible now we are using a while loop:

codecov[bot] commented 5 years ago

Codecov Report

Merging #11 into master will decrease coverage by 0.97%. The diff coverage is 93.57%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #11      +/-   ##
==========================================
- Coverage   93.42%   92.44%   -0.98%     
==========================================
  Files           3        3              
  Lines         152      225      +73     
==========================================
+ Hits          142      208      +66     
- Misses         10       17       +7
Impacted Files Coverage Δ
R/iterate_matrix.R 94.21% <93.57%> (-2.69%) :arrow_down:
R/ode_solve.R 95.74% <0%> (-0.26%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update dfbb4aa...4708cc9. Read the comment docs.

goldingn commented 5 years ago

@jdyen I just merged this, but should point out that it changes the behaviour somewhat. It will now stop early if a convergence tolerance is met. So all_states will be padded with 0s after the convergence is reached.

Might this may break some of your code? To reimplement the old behaviour, you can set tol to 0 or a negative value, and it then will never stop early.

jdyen commented 5 years ago

It'll probably break some of it but I need to update it anyway. What's the main application of the while loop? Is this for finding equilibrium states?

goldingn commented 5 years ago

Yes exactly. Stops early if a convergence criterion (all ratios between new and old states the same, to within a tolerance) is met. So just turn off the early stopping and it'll revert to previous behaviour.