NAME

Simulation::Sensitivity - A general-purpose sensitivity analysis tool for user-supplied calculations and parameters

VERSION

version 0.12

SYNOPSIS

use Simulation::Sensitivity;
$sim = Simulation::Sensitiviy->new(
   calculation => sub { my $p = shift; return $p->{alpha} + $p->{beta} }
   parameters  => { alpha => 1.1, beta => 0.2 },
   delta       => 0.1 );
$result = $sim->run;
print $sim->text_report($result);

DESCRIPTION

Simulation::Sensitivity is a general-purpose sensitivity analysis tool. Given a user-written calculating function, a "base-case" of parameters, and a requested input sensitivity delta, this module will carry out a sensitivity analysis, capturing the output of the calculating function while varying each parameter positively and negatively by the specified delta. The module also produces a simple text report showing the percentage impact of each parameter upon the output.

The user-written calculating function must follow a standard form, but may make any type of computations so long as the form is satisfied. It must take a single argument -- a hash reference of parameters for use in the calculation. It must return a single, numerical result.

CONSTRUCTORS

new

my $sim = Simulation::Sensitivity->new(
   calculation => sub { my $p = shift; return $p->{alpha} + $p->{beta} }
   parameters  => { alpha => 1.1, beta => 0.2 },
   delta       => 0.1 );

new takes as its argument a hash with three required parameters. calculation must be a reference to a subroutine and is used for calculation. It must adhere to the usage guidelines above for such functions. parameters must be a reference to a hash that represents the initial starting parameters for the calculation. delta is a percentage that each parameter will be perturbed by during the analysis. Percentages should be expressed as a decimal (0.1 to indicate 10%).

As a constructor, new returns a Simulation::Sensitivity object.

PROPERTIES

calculation, parameters, delta

$sim->calculation()->({alpha=1.0, beta=1.0});
%p = %{$sim->parameters()};
$new_delta = $sim->delta(.15);

The parameter values in a Simulation::Sensitivity object may be retrieved or modified using get/set accessors. With no argument, the accessor returns the value of the parameter. With an argument, the accessor sets the value to the new value and returns the new value.

METHODS

base

$base_case = base();

This method returns the base-case result for the parameter values provided in the constructor.

run

$results = run();

This method returns a hash reference containing the results of the sensitivity analysis. The keys of the hash are the same as the keys of the parameters array. The values of the hash are themselves a hash reference with each key representing a particular case in string form (e.g. "+10%" or "-10%") and the value equal to the result from the calculation. A simple example would be:

{
    alpha => {
        "+25%" => 5.25,
        "-25%" => 4.75
    },
    beta => {
        "+25%" => 6,
        "-25%" => 4
    }
}

text_report

$report = text_report( $results );

This method generates a text string containing a simple, multi-line report. The only parameter is a hash reference containing a set of results produced with run.

SUPPORT

Bugs / Feature Requests

Please report any bugs or feature requests through the issue tracker at https://github.com/dagolden/Simulation-Sensitivity/issues. You will be notified automatically of any progress on your issue.

Source Code

This is open source software. The code repository is available for public review and contribution under the terms of the license.

https://github.com/dagolden/Simulation-Sensitivity

git clone https://github.com/dagolden/Simulation-Sensitivity.git

AUTHOR

David Golden <dagolden@cpan.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2013 by David Golden.

This is free software, licensed under:

The Apache License, Version 2.0, January 2004