Second-order power weighting in plotSpectra/plotCDF (#383)#397
Open
gustavdelius wants to merge 1 commit into
Open
Second-order power weighting in plotSpectra/plotCDF (#383)#397gustavdelius wants to merge 1 commit into
gustavdelius wants to merge 1 commit into
Conversation
Refines the plotting placement of #382 for the `power` argument. For a cell average N_j the transformed density N(w) w^power is represented at the geometric bin centre w* = w sqrt(beta) by N_j (w*)^power, so using the node for both the w^power weight and the x-location is doubly off -- the location error is the half-bin shift, and the w^power error is O(power*Δx), largest for the common power = 2 Sheldon plot. plot_spectra() now evaluates both the w^power weight and the plotted location at the bin centre (species, resource, total, background) under second_order_w[["bin_average"]]; the default auto wlim follows the plotted grid so the shift does not clip the end bins. animate.MizerSim() gets the same treatment. plotlySpectra/plotlyCDF/plotSpectraRelative inherit it (the latter's w^power factor cancels in the relative ratio, so only its x-location shifts). plotCDF is the opposite case: a CDF value is cumulative up to a size, a boundary quantity, so plot_cdf() maps the density back to the bin edges (w = w*/sqrt(beta)) -- keeping the cumulative on the nodes -- while the increments stay centre-weighted, so each value*dw_k is the second-order bin integral of N w^power. getFlux() (a face/point quantity) is deliberately left untouched. Default (first-order) plots, return_data and vdiffr snapshots are unchanged. Tests cover power = 0/1/2 placement and weighting, the CDF staying on edges, and the relative-plot cancellation. Full suite: 2842 pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #383. Refines the plotting placement of #382 for the
powerargument ofthe
plotSpectra…/plotCDF…families.The problem
plotSpectra()forms the plotted value with the weight and the location both atthe node:
N_j · w_j^poweratw = w_j. For a cell averageN_jthetransformed density
N(w) w^poweris represented at the geometric bin centrew*_j = w_j sqrt(β)byN_j (w*_j)^power, so the node is doubly off:w^powerweighting error —O(power·Δx), largest for the most commonpower = 2(Sheldon/biomass-per-log-size) plot, wherew_j^powerundershoots(w*_j)^powerby a full factorβ.Fix
plot_spectra()(density): undersecond_order_w[["bin_average"]],evaluate both the
w^powerweight and the plotted location at the bincentre
w* = w sqrt(β)(species, resource, total, background), reusingbin_midpoints()from Second-order plotting: locate bin-averaged values at geometric bin centres + Array representation tag #382. The default autowlimfollows the plotted gridso the centre shift does not clip the end bins.
animate.MizerSim()gets the same treatment;plotlySpectra()/plotlyCDF()inherit it (thindo.callwrappers);plotSpectraRelative()is the special case where thew^powerfactorcancels in
2(N2−N1)/(N1+N2), so only its x-location shifts — which itinherits automatically.
plotCDF()is the opposite case: a CDF value is cumulative up to a size,a boundary quantity, so
plot_cdf()maps the density back to the binedges (
w = w*/sqrt(β)) — keeping the cumulative on the nodes — while theincrements stay centre-weighted, so each
value·Δw_k = N_k (w*_k)^power Δw_kis the second-order bin integral of
N w^power.Explicitly out of scope
getFlux()also has apowerargument but is a flux at the boundary → apoint value at the face, correctly weighted at the node; it is left untouched.
Tests
test-plots.R: forpower = 0/1/2the spectrum x shifts bysqrt(β)and thevalue scales by
β^(power/2)(weight evaluated at the centre); the default pathkeeps x on the nodes;
plotCDFx stays on the node/edge grid (never thecentres) and is monotonic;
plotSpectraRelativeshifts x to centres but itsvalue is power-independent (cancellation). Default vdiffr snapshots unchanged.
Full suite: 2842 pass.
Docs
NEWS entry; the numerical-details vignette's plotting note extended to cover the
w^power-at-centre weighting and the CDF's edge placement.🤖 Generated with Claude Code