Understanding probability distributions and the Belief type in Styx
In Styx, node liveness is represented as a probability distribution over three mutually exclusive states: ALIVE, DEAD, and UNKNOWN. This is captured in the Belief type.
A Belief represents a probability distribution where the three components always sum to 1.0:
source/types/belief.go
// Belief represents a probability distribution over node liveness.//// This represents the probability distribution over three mutually// exclusive states: ALIVE, DEAD, and UNKNOWN.//// Invariant: alive + dead + unknown = 1.0 (within floating-point tolerance)type Belief struct { alive Confidence dead Confidence unknown Confidence}
The sum of alive + dead + unknown must always equal 1.0 within a tolerance of 1e-9 (BeliefSumEpsilon).
Each component is represented as a Confidence type, which enforces the range [0.0, 1.0]:
source/types/confidence.go
type Confidence struct { value float64}// NewConfidence creates a new Confidence from a raw value.// Returns an error if the value is outside [0.0, 1.0] or is NaN.func NewConfidence(value float64) (Confidence, error) { if math.IsNaN(value) { return Confidence{}, ErrConfidenceNaN } if value < 0.0 { return Confidence{}, fmt.Errorf("%w: %f", ErrConfidenceBelowMinimum, value) } if value > 1.0 { return Confidence{}, fmt.Errorf("%w: %f", ErrConfidenceAboveMaximum, value) } return Confidence{value: value}, nil}
Confidence values are bounds-checked at construction time. Invalid values will return an error rather than silently clamping.
Styx uses thresholds to determine when a belief is “certain” enough:
source/types/belief.go
const CertaintyThreshold = 0.95const DominantMargin = 0.1// IsCertainAlive checks if the node is certainly alive.// Returns true only if alive confidence exceeds the certainty threshold.func (b Belief) IsCertainAlive() bool { return b.alive.Value() >= CertaintyThreshold}// IsCertainDead checks if the node is certainly dead.// Returns true only if dead confidence exceeds the certainty threshold.// This triggers irreversible death semantics.func (b Belief) IsCertainDead() bool { return b.dead.Value() >= CertaintyThreshold}
CertaintyThreshold = 0.95
A node is considered “certainly alive” or “certainly dead” only when the corresponding confidence exceeds 95%. This high bar prevents premature decisions.
DominantMargin = 0.1
For a state to be considered dominant, it must exceed the other states by at least 10%. This prevents flapping between states when probabilities are close.
The BeliefState enum represents the three possible dominant states:
source/types/belief.go
type BeliefState intconst ( // StateUnknown indicates the liveness state is unknown. StateUnknown BeliefState = iota // StateAlive indicates the node is believed to be alive. StateAlive // StateDead indicates the node is believed to be dead. StateDead)
StateUnknown is returned both when uncertainty is high AND when no state clearly dominates (due to insufficient margin).