
Tune every species and stage the evidence can speak to, in one run
Source:R/tune_run.R
knw_tune_run.RdFor each species in species and each stage in stages: the scoring
population is cut, the rule grid built around link's own thresholds, every
rule scored on held-out groups (knw_tune_score()), and the curve fitted at
the pick (knw_tune_curve()).
Usage
knw_tune_run(
visits,
species_tbl,
walks,
thresholds,
species = knw_species(),
stages = c("rear", "spawn"),
spawner = NULL,
edge_stream = c(1000L, 1100L, 2000L, 2300L),
area_range = c(10, 10000),
seed = 54L,
folds = 5L,
n_boot = 200L,
seeds_more = 55:58,
workers = 1L,
d_floor = 200,
min_wsg = 5L,
power_wsg = 10L,
src = "pick",
grid_args = list(),
cache_dir = NULL,
thresholds_extra = NULL,
previous = NULL,
smoke = TRUE,
smoke_only = FALSE,
smoke_args = list(),
extra = TRUE,
fit = c("fe", "dense"),
prior_sd = 2.5,
evidence_id = NULL,
modelled = NULL,
cols = c(grad = "segment_gradient", width = "cw_deploy", mad = "mad_pick")
)Arguments
- visits
the build's
visits_linktable.- species_tbl
the build's
visits_speciestable.- walks
the build's walks, as
knw_link_walks()returns them.- thresholds
link's
parameters_habitat_thresholds.csv.- species, stages
which to run.
- spawner
NULL, orknw_spawner_evidence()'s table.- edge_stream, area_range
the population's constants.
- seed, folds, n_boot, seeds_more, workers, d_floor, fit, prior_sd
passed to
knw_tune_score()(andfitandprior_sdtoknw_tune_smoke(),prior_sdtoknw_tune_curve()).- min_wsg, power_wsg
integer(1)the floors described above.- src
character(1)the flow source the exception reads.- grid_args
listof arguments passed toknw_tune_grid()for every species × stage (for examplelist(grid_grad = c(0.03, 0.09, 0.15))); empty for its defaults.- cache_dir
NULL, or a directory where each species × stage's scored grid is saved as<sp>_<stage>_score.rdsand read back on a rerun when the population has the same number of visits and the grid the same rows, in the same order (everyknw_tune_grid()column, so a moveddefaultcounts), and the settings the score was made with match (fit,prior_sd,seed,folds,d_floorandextra, recorded asspecbyknw_tune_score(), and the gradient column,grad); a cache whose record lacksgradis rescored, and one written before any record is rescored unlesscols[["grad"]]isfwa_gradient, the gradient every such cache was scored on, when it is read back with a message naming the settings it is taken as.n_boot,seed_bootandseeds_moreare not checked: a cache's bootstrap and extra-seed tables are read back whatever the run asked for, so give a run with different ones its own directory.- thresholds_extra
NULL, or another bundle'sparameters_habitat_thresholds.csv(link'sdefault_tuned): each species' row joins its grid as theis_link_tunedcandidate (knw_tune_grid()).- previous
NULL, or a namedcharactervector of the previous pick's rule string per"<sp>_<stage>", which the smoke run scores where present.- smoke
logical(1)run the smoke run and its checks first.- smoke_only
logical(1)return after the smoke run, scoring nothing.- smoke_args
listof arguments passed toknw_tune_smoke()(tol_null,coef_max).- extra
logical(1)passed toknw_tune_score(): the bootstrap, the nested selection and the extra fold seeds.FALSEis the development setting, which proves a scorer change on every species in a fraction of the time; a run that publishes keepsTRUE.- evidence_id
NULL, orcharacter(1)naming the evidence build the visits and walks came from (scripts/0320passes the md5s of the three derived tables). It joins the cache's settings, so a score made on another build of the same visit count is not read back as this one's.- modelled
NULL, or the species codes link models on the build the visits were placed on (scripts/0320passes those with any access value in the evidence). Every stage of another species isnot_modelled: link draws no access or habitat for it, so a rule could be neither graded nor applied (#145).NULLis every species.- cols
named
character, as inknw_rule_in(): the columns ofvisitscarryinggrad,widthandmad, read by the rules and the curve. The gradient is link's segment gradient (segment_gradient), the one link applies a rule to (#92); the Freshwater Atlas line's (fwa_gradient) is the sensitivity. The gradient column joins the cache's settings.
Value
A list with one element per species × stage ("<sp>_<stage>"): a
list with species_code, stage, response, status (fitted,
underpowered, no_stream_rule, not_modelled, no_response,
too_few_groups, curve_failed; smoke with smoke_only), population, and when scored
smoke (knw_tune_smoke()'s result, with smoke), score
(knw_tune_score()'s result), pick (the recommended rule row) and curve
(knw_tune_curve()'s; NULL with curve_error when its fit failed);
null_heldout (the held-out deviance with no rule over the grid's visits),
null_heldout_curve (the same model scored over the curve's own visits,
those with a size, a gradient and a distance, on the same folds) and
grade_withheld, TRUE when the curve's held-out deviance is no better
than null_heldout_curve: a curve that predicts held-out groups no better
than knowing nothing ranks segments no better either, so its grades are
withheld. The comparison is over one population because a width rule's
curve fits fewer visits than the grid (unmeasured streams have no width),
and each visit it drops would otherwise leave only its own side.
Details
The population follows scripts/0297: visits on the stream branch (FWA edge
types edge_stream, not in a river polygon, a wetland of at least 1 ha or a
lake of at least 100 ha), with a fished area in area_range, in groups where
link's presence rule marks the species present, with no code blocking the
species' absence, and no natural barrier to the species downstream before
observation overrides (barrier_dnstr_<sp> is FALSE). Rearing's response is
detection (U, the species caught); spawning's is spawner evidence (S) from
spawner, which the export carries for char only, so a species × stage with no
response, no stream rule in default, or fewer than min_wsg groups with both
outcomes gets a one-row record saying so and is not fitted. A species × stage
with fewer than power_wsg groups is fitted and labelled underpowered.
Before any grid is scored, every species × stage that would be fitted gets
the smoke run (knw_tune_smoke(); #84): a handful of rules on the main fold
seed, and four checks on the scorer. One failed check on any key stops the
run, with every key's report printed, so a scorer defect costs minutes, not
the hours of the full grid. smoke_only = TRUE returns after the smoke run
(each record carries smoke, and none is scored), which is how
scripts/0320 writes the reports before it decides to score.