-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Internal: Move error-scaling (by the error contraction rate) outside …
…of the controller implementations (#795) * Write a test for the controllers to ensure I don't break them * Apply the controller repeatedly to tighten the test * Clean up the source of proportional-integral control * Make the control-inputs keywords to ensure that changing the signature raises erorrs * Assign scaled error norm to a variable to prepare changing the signature * Isolate error**(1/rate) * Move error-power computation out of the controllers to reduce no. function arguments * Merge error-normalisation with existing error normalisation * Rename the error-scale function * Add mypy extensions to the benchmark dependencies
- Loading branch information
Showing
4 changed files
with
52 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"""Test the controllers.""" | ||
|
||
from probdiffeq import ivpsolve | ||
from probdiffeq.backend import numpy as np | ||
|
||
|
||
def test_equivalence_pi_vs_i(dt=0.1428, error_power=3.142, num_applies=4): | ||
ctrl_pi = ivpsolve.control_proportional_integral( | ||
power_integral_unscaled=1.0, power_proportional_unscaled=0.0 | ||
) | ||
ctrl_i = ivpsolve.control_integral() | ||
|
||
x_pi = ctrl_pi.init(dt) | ||
for _ in range(num_applies): | ||
x_pi = ctrl_pi.apply(x_pi, error_power=error_power) | ||
x_pi = ctrl_pi.extract(x_pi) | ||
|
||
x_i = ctrl_i.init(dt) | ||
for _ in range(num_applies): | ||
x_i = ctrl_i.apply(x_i, error_power=error_power) | ||
x_i = ctrl_i.extract(x_i) | ||
assert np.allclose(x_i, x_pi) |