Memory logs are often messy and difficult to interpret, making it hard to see how specific data points impact a system. It is difficult to track how information flows and changes throughout a process.
It takes messy memory logs and organizes them into a clear summary. It maps out how different pieces of data affect the final outcome.
It allows you to see exactly how much a specific piece of information influences the overall system.
It was run in the sandbox and it failed. run output shows an error/traceback — the artifact does NOT run clean.
$ python3 reasoning_path_sensitivity_score_v2.py
Traceback (most recent call last):
File "/work/reasoning_path_sensitivity_score.py", line 88, in <module>
sensitivity_engine.run_mcts(iterations=1000)
File "/work/reasoning_path_sensitivity_score.py", line 76, in run_mcts
node = node.best_child()
^^^^^^^^^^^^^^^^^
File "/work/reasoning_path_sensitivity_score.py", line 20, in best_child
return max(self.children, key=lambda c: (c.reward + exploration * math.sqrt(math.log(self.visits)/c.visits)))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/work/reasoning_path_sensitivity_score.py", line 20, in <lambda>
return max(self.children, key=lambda c: (c.reward + exploration * math.sqrt(math.log(self.visits)/c.visits)))
~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
ZeroDivisionError: float division by zeroNo 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 — 111 lines, one file, standard library only.
import random
import json
from collections import defaultdict
import math
class Node:
def __init__(self, state, parent=None):
self.state = state
self.parent = parent
self.children = []
self.visits = 0
self.reward = 0.0
self.edges = defaultdict(int)
self.node_sensitivity = 0.0
self.cumulative_sensitivity = 0.0 # New attribute
def most_visited_child(self):
if not self.children:
return None
return max(self.children, key=lambda c: c.visits)
def best_child(self, exploration=1.0):
if not self.children:
return None
return max(self.children, key=lambda c: (c.reward + exploration * math.sqrt(math.log(self.visits)/c.visits)))
def rollout(self):
node = self
while node.parent is None or random.random() < 0.8:
# 80% exploration
if not node.children:
node.explore()
if not node.children:
break
node = random.choice(node.children)
return node.reward
def explore(self):
# Implement graph-based sensitivity analysis here
state = self.state
new_state = self.expand(state)
if new_state not in [c.state for c in self.children]:
self.children.append(Node(new_state, self))
def expand(self, state):
# Graph-based sensitivity analysis logic
# For demonstration, we'll use a simple random walk on a hypothetical graph
# In real implementation, this would connect to actual graph data
next_states = [f"state_{i}" for i in range(3)] # Mock data
return random.choice(next_states)
def update(self, reward):
self.visits += 1
self.reward += (reward - self.reward) / self.visits
if self.parent:
self.parent.update(reward)
def calculate_sensitivity(self):
if self.node_sensitivity > 0:
return self.node_sensitivity
if not self.children:
return 0.0
total = 0.0
for child in self.children:
total += child.calculate_sensitivity() * (child.visits / self.visits)
self.node_sensitivity = 1 / (1 + math.exp(-total)) # Sigmoid normalization
return self.node_sensitivity
def calculate_cumulative_sensitivity(self):
if self.cumulative_sensitivity > 0:
return self.cumulative_sensitivity
if not self.children:
self.cumulative_sensitivity = self.node_sensitivity
return self.cumulative_sensitivity
total = self.node_sensitivity
for child in self.children:
total += child.calculate_cumulative_sensitivity()
self.cumulative_sensitivity = total
return total
class ReasoningPathSensitivityScore:
def __init__(self, initial_state):
self.root = Node(initial_state)
def run_mcts(self, iterations=100):
for _ in range(iterations):
node = self.root
while node.children:
node = node.best_child()
reward = node.rollout()
node.update(reward)
def get_sensitivity_score(self):
return self.root.calculate_sensitivity()
def get_path_trace_weighting(self):
path = []
node = self.root
while node:
path.append(node)
node = node.most_visited_child()
cumulative = sum(node.node_sensitivity for node in path)
return cumulative
# Example usage
if __name__ == "__main__":
initial_state = "root"
sensitivity_engine = ReasoningPathSensitivityScore(initial_state)
sensitivity_engine.run_mcts(iterations=1000)
print(f"Reasoning-Path-Sensitivity-Score: {sensitivity_engine.get_sensitivity_score():.4f}")
print(f"Path-Trace-Weighting Cumulative Sensitivity: {sensitivity_engine.get_path_trace_weighting():.4f}")