Skip to content

Extract the per-level search from speed_hierarchical() #136

Description

@rogerssam

speed_hierarchical() (R/speed.R) has grown to the point where its per-level
body is around 130 lines, and each feature added to it makes the next extraction
harder. feature/keep-with added three more concerns: swappable-group discovery,
the unequal-replication warning, and stop_reason bookkeeping.

What the function is actually doing is a fold over levels. The body of that fold
is a self-contained simulated-annealing run, and it should be a helper:

.optimise_level <- function(design, opt, level, grid_idx, quiet, ...) {
  # random_initialise has already run; this is one level's SA loop
  return(list(
    design         = best_design,
    scores         = scores,
    temperatures   = temperatures,
    stop_reason    = stop_reason,
    optimal_score  = optimal_score,
    best_score_obj = best_score_obj
  ))
}

That would leave speed_hierarchical() as the loop over hierarchy_levels
plus the metadata assembly it already does in a second pass, and would make the
per-level state (scores, temperatures, n_kept, last_improvement_iter,
temp) local to the run that owns it rather than reassigned in an outer scope.

Worth doing as its own change rather than inside a feature branch - it is a pure
refactor with no behavioural component, and the test suite is a good net for it.

Not urgent. Filing so it is not rediscovered on every review of this area.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions