ProgramMetricValue

Models & Types · AiDotNet.Evolution.Programs.Metrics

One reported metric value, tagged as a number, a boolean flag, or free text.

Implements: IEquatable<ProgramMetricValue>

For Beginners

This is one entry of the score card your evaluation code fills in. Use Number for anything you want the search to optimise, Flag for a yes/no fact such as “the program timed out”, and Text for a message such as the exception that was thrown. Marking them apart means the search will never mistake “it timed out” for “it scored one point”.

How It Works

The reference OpenEvolve evaluator contract is an untyped dictionary, so {"score": 0.8, "timeout": True, "stderr": "ZeroDivisionError"} is a single legal metrics payload. That mixture is the reason metrics_utils.safe_numeric_average exists at all, and the reason it has to special-case bool: Python treats True as the integer 1, so averaging a timeout flag into a score would give a program that crashed a mid-range fitness. This type keeps the same expressiveness while making the distinction explicit at the type level, so nothing has to be guessed from a runtime type test.

Values are immutable and are compared by value. TryGetNumber is the single accessor an aggregation needs: it succeeds for Number and, when allowTextConversion is requested, for text that parses as a finite invariant-culture number. It deliberately fails for a flag, because a flag is not a score.

Properties

Property Summary
ProgramMetricValueKind Kind { get; } Gets which kind of value this instance carries.
bool FlagValue { get; } Gets the flag state, or false when this value is not a flag.
string TextValue { get; } Gets the text, or an empty string when this value is not text.

Methods

Method Summary
ProgramMetricValue Flag(bool value) Creates a boolean flag metric value.
ProgramMetricValue Number(double value) Creates a numeric metric value.
ProgramMetricValue Text(string value) Creates a free-text metric value.
bool Equals(ProgramMetricValue other)
bool Equals(object obj)
bool TryGetNumber(bool allowTextConversion, double value) Attempts to read this value as a number.
int GetHashCode()
string ToString() Returns the kind and a bounded rendering of the value.

Fields

Field Summary
int MaxTextLength The largest text value accepted, in characters.