Skip to content

Add evaluate(): Evaluate a policy (without improving it) - #18

Merged
areenberg merged 1 commit into
masterfrom
policy_evaluation
Nov 15, 2026
Merged

areenberg merged 1 commit into
masterfrom
policy_evaluation

Conversation

@areenberg

Copy link
Copy Markdown
Owner

Adds model.evaluate(), which evaluates a given policy (by default the one from the last run) without improving it. It returns the policy's value vector, and under criterion="average" its gain and bias, through the existing output methods.

Changes

  • evaluate(policy, tolerance, update, criterion, SORrelaxation, initValueVector, verbose, postProcessing, makeFinalCheck, parallel) runs the evaluation sweeps of policy iteration until the tolerance is reached. Under the discounted criterion with standard updates and post-processing, the values lie less than the tolerance below the policy's values. getIterations() returns 0 after evaluate(), since no policy improvement step is made.
  • The evaluation sweeps of PI/MPI are moved into their own routines, which both solve() and evaluate() use. The results of solve() are bit-identical, and PI/MPI speed is unchanged.
  • solve()'s initPolicy/initValueVector and evaluate()'s policy go to C++ as NumPy arrays without a copy, and are checked in a single C++ pass. With 5×10⁶ states, solve(initPolicy=array) drops from 7.6 s to 0.17 s. Results and error messages are unchanged.
  • The final value vector is swapped into place instead of copied. ConvergenceWarnings now point at the user's line.

Tests
New test_evaluate.py (added to CI) checks evaluate() against the results of solve() and against exact values from linear equations, under both criteria. test_order.py now counts evaluate() as a step method. All 14 tests pass locally.

Documentation is on the wiki (Classes-and-methods, Contribution-guidelines, Validating-MDPSolver).

@areenberg
areenberg merged commit 35ec5cb into master Nov 15, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant