Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mistake in numerical differentiation #297

Open
gustavdelius opened this issue Oct 18, 2024 · 0 comments
Open

Mistake in numerical differentiation #297

gustavdelius opened this issue Oct 18, 2024 · 0 comments
Labels
core Issue relates to the mizer core discussion An idea that needs discussion before becoming a proposal major effort Resolving this issue will involve a major effort

Comments

@gustavdelius
Copy link
Member

Mizer is based on the PDE
$$\frac{\partial N}{\partial t} = -\frac{\partial}{\partial w}(g,N)-\mu,N$$
that it solves numerically by approximating the derivatives with first-order finite-difference approximations. In particular it approximates the derivative with respect to $w$ with the backwards difference formula
$$\frac{\partial}{\partial w}f(w_i)\approx \frac{f(w_{i})-f(w_{i-1})}{dw_i}$$
which is correct to first order if
$$w_i = w_{i}-w_{i-1}.$$
Unfortunately mizer is using
$$w_i = w_{i+1}-w_{i}.$$
Given mizer's logarithmically-spaced $w_i$, where $w_{i+1}/w_i=10^{dx}$ is a constant, this means that the derivative in mizer is too small by this factor. Given the way the derivative enters the PDE, this is equivalent to mizer working with a growth rate that is too big by this constant. It also means that the dynamics in mizer currently change as one changes the step size $dx$.

To give a feel for the size of this error: if fish sizes in the model range from 1mg to 10kg then the factor is about 1.18 when using 100 size bins and 1.08 when using 200 size bins.

When we switch to the correct scheme, we should automatically update all old-version params objects in such a way that their growth rates are increased by the factor $10^{dx}$ so that they continue to have the same dynamics as in the past. This would be easiest to do by registering a modified mizerEGrowth() function for them.

Alternatively we could set a flag in the old-version params objects that tells mizer to continue to use the wrong scheme for them.

@gustavdelius gustavdelius added bug discussion An idea that needs discussion before becoming a proposal core Issue relates to the mizer core major effort Resolving this issue will involve a major effort and removed bug labels Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Issue relates to the mizer core discussion An idea that needs discussion before becoming a proposal major effort Resolving this issue will involve a major effort
Projects
None yet
Development

No branches or pull requests

1 participant