Calculate the optimal size for the next Runge-Kutta step.
(last_step,
error_ratio,
safety=0.9,
ifactor=10.0,
dfactor=0.2,
order=5,
name=None)
| 214 | |
| 215 | |
| 216 | def _optimal_step_size(last_step, |
| 217 | error_ratio, |
| 218 | safety=0.9, |
| 219 | ifactor=10.0, |
| 220 | dfactor=0.2, |
| 221 | order=5, |
| 222 | name=None): |
| 223 | """Calculate the optimal size for the next Runge-Kutta step.""" |
| 224 | with ops.name_scope(name, 'optimal_step_size', [last_step, |
| 225 | error_ratio]) as scope: |
| 226 | error_ratio = math_ops.cast(error_ratio, last_step.dtype) |
| 227 | exponent = math_ops.cast(1 / order, last_step.dtype) |
| 228 | # this looks more complex than necessary, but importantly it keeps |
| 229 | # error_ratio in the numerator so we can't divide by zero: |
| 230 | factor = math_ops.maximum(1 / ifactor, |
| 231 | math_ops.minimum(error_ratio**exponent / safety, |
| 232 | 1 / dfactor)) |
| 233 | return math_ops.div(last_step, factor, name=scope) |
| 234 | |
| 235 | |
| 236 | def _abs_square(x): |
no test coverage detected