NAME

Logic::Probabilistic::Result - Stores inference results and statistical measures.

SYNOPSIS

my $result = $engine->query(...);
say "Probability: " . $result->probability;
say "95% CI: " . $result->ci_low . " .. " . $result->ci_high;

if ( $result->method eq 'mcmc' ) {
    say "Chains:    " . $result->chains;
    say "R-hat:     " . $result->r_hat;
    say "ESS:       " . $result->ess;
    say "Converged: " . ($result->is_converged ? "yes" : "no");
}

METHODS

probability

Returns the calculated point probability.

gradients

Returns a hashref mapping parameter identifiers (e.g. 'burglary', 'friend(alice,bob)') to their exact partial derivatives dP/dp_i. Empty hashref if inference was run without gradients.

has_gradients

Returns true if analytical gradients were computed and are available on this result.

gradient($target)

Returns the partial derivative of the query probability with respect to the given target parameter. $target can be a Logic::Probabilistic::PFact object, an identifier string, or a predicate name. Returns 0.0 if not found or if gradients were not computed.

ci($level)

Returns the lower and upper bounds of the Wilson score confidence interval (default level 0.95). For MCMC inference, calculates uncertainty based on the Effective Sample Size (ESS) to prevent artificially narrow confidence intervals due to autocorrelation.

r_hat

Potential scale reduction factor (Gelman-Rubin diagnostic). Values close to 1.0 indicate convergence across chains.

ess

Effective Sample Size accounting for autocorrelation and between-chain variance.

is_converged($threshold)

Returns boolean indicating whether R-hat is within threshold (default 1.05).

warnings

List of diagnostic warning messages generated during inference.