-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.py
More file actions
102 lines (84 loc) · 3.87 KB
/
demo.py
File metadata and controls
102 lines (84 loc) · 3.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
"""
vScore demo — the full pipeline without a real encoder.
Simulates what happens when a fire video is scored:
pixels → encoder → valence scores → trajectory → projection → trigger
Run: python -m vScore.demo
"""
from vScore.core import ValenceVector, ValenceTrajectory, ThresholdTrigger, ScoredDomain
from vScore.core.threshold import ThresholdConfig, Response
from vScore.domains import Fire
def main():
print("=" * 60)
print("vScore — Visual Scoring Intelligence")
print("=" * 60)
print()
# Show all registered domains
print("Registered domains:")
for name in ScoredDomain.list_domains():
domain = ScoredDomain.get_domain(name)
print(f" {domain.describe()}")
print()
# Simulate a fire scenario
# A fire that starts small and accelerates
print("-" * 60)
print("Scenario: Warehouse fire — scoring over time")
print(f"Axes: {Fire.axis_names()}")
print(f"Homeostasis: {Fire.zero_state()}")
print("-" * 60)
print()
trajectory = ValenceTrajectory(domain_name="Fire")
# Simulated scores over time (what a trained encoder would output)
# spread_rate, proximity, intensity, containment, escape_route, structural_risk, smoke_toxicity
frames = [
(0.0, [1.0, 2.0, 1.5, 8.0, 1.0, 0.5, 1.0]), # Small, contained
(1.0, [2.0, 2.0, 2.5, 7.0, 1.5, 1.0, 2.0]), # Growing
(2.0, [3.5, 3.0, 4.0, 5.5, 2.5, 2.0, 3.5]), # Spreading
(3.0, [5.0, 4.0, 5.5, 4.0, 3.5, 3.0, 5.0]), # Losing containment
(4.0, [7.0, 5.5, 7.0, 2.5, 5.0, 5.0, 6.5]), # Accelerating
(5.0, [8.5, 7.0, 8.5, 1.5, 7.0, 7.0, 8.0]), # Critical
]
# Set up threshold trigger
trigger = ThresholdTrigger(
domain_name="Fire",
axis_names=Fire.axis_names(),
configs={
"spread_rate": ThresholdConfig("spread_rate", trigger_level=7.0, attention_level=4.0),
"proximity": ThresholdConfig("proximity", trigger_level=6.0, attention_level=3.5),
"intensity": ThresholdConfig("intensity", trigger_level=7.0, attention_level=4.0),
"containment": ThresholdConfig("containment", trigger_level=6.0, attention_level=4.0),
"escape_route": ThresholdConfig("escape_route", trigger_level=5.0, attention_level=3.0),
"structural_risk": ThresholdConfig("structural_risk", trigger_level=5.0, attention_level=3.0),
"smoke_toxicity": ThresholdConfig("smoke_toxicity", trigger_level=6.0, attention_level=3.5),
},
)
for t, scores in frames:
v = ValenceVector(domain_name="Fire", scores=scores, timestamp=t)
trajectory.append(v)
print(f"t={t:.0f} {v}")
print(f" magnitude: {v.magnitude:.2f} dominant: {Fire.axis_names()[v.dominant_axis]}")
# Show velocity and acceleration for the dominant axis
if trajectory.length >= 2:
dom = v.dominant_axis
vel = trajectory.velocity(dom)
acc = trajectory.acceleration(dom)
proj = trajectory.project(dom, steps_ahead=2.0)
print(f" {Fire.axis_names()[dom]}: vel={vel:+.2f} acc={acc:+.2f} projected(t+2)={proj:.2f}")
# Check triggers
events = trigger.evaluate(trajectory)
for e in events:
marker = "!!!" if e.response == Response.ACT else " ! "
print(f" {marker} {e.response.name}: {e.axis_name} "
f"current={e.current_score:.1f} projected={e.projected_score:.1f}")
print()
# Final state
print("=" * 60)
print("Final projection (all axes, 2 steps ahead):")
projected = trajectory.project_all(steps_ahead=2.0)
for name, val in zip(Fire.axis_names(), projected):
bar = "#" * int(val)
print(f" {name:>18s}: {val:5.1f} {bar}")
print()
print("Zero is safety. Everything above zero is cost.")
print("=" * 60)
if __name__ == "__main__":
main()