It is difficult to determine how much you can trust a sequence of actions when each step in the process might be less reliable than the last.
It looks at a series of steps and calculates a confidence score by measuring how trust in the path fades as it progresses.
It provides a clear way to measure the reliability of a multi-step process.
It was run in the sandbox and it failed. run output shows an error/traceback — the artifact does NOT run clean.
$ python3 score_tool.py
File "/work/score_tool.py", line 66
print(f"Path {path1} confidence score: {score1:.4f")
^
SyntaxError: closing parenthesis ')' does not match opening parenthesis '{'No screenshot — there is nothing working to show. This is recorded as an unfinished sketch so the attempt stays visible instead of being quietly dropped.
All of it — 76 lines, one file, standard library only.
# State-Transition Path Scoring with Recursive Trust Decay
import math
class StatePathEvaluator:
def __init__(self, transition_matrix):
self.transition_matrix = transition_matrix
self.trust_decay_factor = 0.8 # Base decay factor (0 < x < 1)
self.reset()
self.path_depth = 0 # Track actual path depth
def reset(self):
self.current_state = None
self.current_trust = 1.0 # Initial trust score
self.path_depth = 0
def transition(self, next_state):
" """
Updates the trust score based on the transition reliability
and applies recursive trust decay
" """
if self.current_state is None:
self.current_state = next_state
self.path_depth = 1 # First transition
return self.current_trust
# Get transition reliability (0.0 to 1.0)
reliability = self.transition_matrix.get(self.current_state, {}).get(next_state, 0.0)
# Apply recursive trust decay: trust = trust * reliability * decay_factor^depth
depth = self.path_depth + 1 # Depth increases with each transition
self.current_trust *= reliability * (self.trust_decay_factor ** depth)
# Update current state and path depth
self.current_state = next_state
self.path_depth += 1
return self.current_trust
def evaluate_path(self, state_sequence):
" """
Evaluates a complete state transition path and returns the final trust score
" """
if not state_sequence: # Handle empty sequence
return 1.0
self.reset()
for state in state_sequence:
self.transition(state)
return self.current_trust
# Example usage
if __name__ == "__main__":
# Define a sample state transition matrix [State: {Next State: Reliability Score}]
transition_matrix = {
'A': {'B': 0.9, 'C': 0.8},
'B': {'D': 0.95},
'C': {'D': 0.85},
'D': {} # Terminal state
}
evaluator = StatePathEvaluator(transition_matrix)
# Test path A -> B -> D
path1 = ['A', 'B', 'D']
score1 = evaluator.evaluate_path(path1)
print(f"Path {path1} confidence score: {score1:.4f")
# Test path A -> C -> D
path2 = ['A', 'C', 'D']
score2 = evaluator.evaluate_path(path2)
print(f"Path {path2} confidence score: {score2:.4f")
# Test invalid path
path3 = ['A', 'X', 'D']
score3 = evaluator.evaluate_path(path3)
print(f"Path {path3} confidence score: {score3:.4f")