Skip to content

random_initialisation semantics are undocumented and partly undecided #144

Description

@rogerssam

The only user-facing description of random_initialisation is one sentence in ?optim_params:

Number of times to randomly shuffle items within swap_within; the design with the best score is used as an initial design (default: 0).

Checked against the behaviour, that sentence is either silent on or wrong about every non-obvious thing the argument does.

Undecided: is the input a candidate?

random_initialise() starts with best_score <- Inf, so the first shuffle always replaces the input and the input never competes. With a 4x4 Latin square input (score 0, optimal) and random_initialisation = 3, the search is handed a design scoring 6.67 and ends at 2.67 — worse than what the user supplied, where with no random initialisation speed() recognises the optimum at iteration 1.

"the design with the best score is used" reads as though the input competes. Either randomisation is the point and the exclusion is deliberate — in which case say so — or it should be best-of-(N+1) and best_score should start at the input's score. This is the same question #89 has to answer before it can auto-trigger anything, and it points the opposite way from #139, where the search privileges the starting design among tied-scoring ones. Worth deciding the rule once for both.

Undocumented

Validation tidy

.verify_optim_params() tests random_initialisation %in% c(TRUE, FALSE). %in% coerces both sides to character, so the strings "TRUE" and "FALSE" match and skip verify_non_negative_whole(), then fail later with NAs introduced by coercion. optim_params(random_initialisation = NULL) gives a bare argument is of length zero rather than the package's own message. Neither input is realistic, but isTRUE(x) || isFALSE(x) is the correct test and costs nothing.

Test coverage

No test calls random_initialise() or shuffle_items() directly, and none combines random_initialisation with swap_all = TRUE. Of the seven tests that set it, only one (test-speed.R:2395) asserts anything about the shuffle itself, and only that the starting score improved. That is why every defect in #141, #142 and #143 went unnoticed.

Worth adding, alongside whichever fixes land: the multiset per group is preserved at each level; units stay intact under swap_all; missing plots do not move; a fresh session with no seed works; a partial optimise_params works.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

documentationImprovements or additions to documentation

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions