NAME

Sim::OPT::CalcMarginals - calculate marginal and level-specific response distributions

SYNOPSIS

use Sim::OPT::CalcMarginals qw(run_config);

run_config('marginals_config.pl');

Or call it directly with a configuration hash reference:

use Sim::OPT::CalcMarginals qw(run);

my $result = run({
    file      => 'amtry-0_totres.csv',
    levels    => { 1 => 5, 2 => 5, 3 => 5, 4 => 3 },
    column    => 2,
    divisions => 100,
    best      => 60,
    worst     => 80,
}, '.');

DESCRIPTION

The module calculates two related kinds of distributions from a Sim::OPT-style CSV results file.

First, it calculates the empirical marginal distribution of each discrete variable encoded in CSV field 0 as variable-level tokens separated by underscores.

Second, for every level of every requested variable, it calculates a histogram of the numerical response selected by column. The histogram is written both as raw counts and as percentages normalized independently within each level.

The optimization direction is inferred from best and worst: best < worst means minimization; best worst> means maximization.

CONFIGURATION

A configuration file is an ordinary Perl file that returns a hash reference. Recognized keys are:

  • file

    Input CSV filename.

  • levels

    Hash reference mapping variable numbers to their declared number of levels.

  • column

    Zero-based CSV column containing the numerical response.

  • divisions

    Number of histogram bins.

  • best, worst

    Response values defining the optimization direction and histogram interval.

  • output_dir

    Optional output directory. Relative paths are resolved relative to the configuration file. By default, outputs are written next to that file.

OUTPUT FILES

For an input named name.csv, the module writes:

marginals_name.csv
distributions_counts_name.csv
distributions_percentages_name.csv

FUNCTIONS

run_config($path)

Loads a configuration file and runs the calculation. Returns a hash reference containing summary information and the three generated output paths.

run($config, $base_directory)

Runs the calculation from a configuration hash reference. Relative paths are resolved from $base_directory, or from the current directory if omitted.

load_config($path)

Loads and validates the configuration container itself. In list context it returns the configuration hash reference and the directory containing the file.