Goal-Seeking Decay
A goal-seeking decay simulation modeling exponential approach toward a target.
Level:Beginner
Dynamic Behavior Patterns
Explore common system behaviors: exponential growth, goal-seeking decay, overshoot-and-collapse, and S-curve saturation.
Explore Dynamic Behavior Patternssimulation.py
Chasing a goal with exponential decay
This little demo walks through a feedback loop that nudges a value toward a target. Each step closes a fraction k
of the gap, so the closer we get the slower we move.
from tys import probe, progress
Run the goal-seeking decay simulation.
def simulate(cfg: dict):
import simpy
env = simpy.Environment()
level = cfg["initial_level"]
goal = cfg["goal_level"]
k = cfg["rate_constant"]
steps = cfg["steps"]
done = env.event()
Evolve the level toward the goal each step.
def run():
nonlocal level
for i in range(steps):
change = k * (goal - level)
level += change
probe("level", env.now, level)
probe("approach_rate", env.now, change)
yield env.timeout(1)
progress(100)
done.succeed({"final_level": level})
env.process(run())
env.run(until=done)
return done.value
def requirements():
return {
"builtin": ["micropip", "pyyaml"],
"external": ["simpy==4.1.1"],
}
Default.yaml
initial_level: 100
goal_level: 0
rate_constant: 0.1
steps: 50
Charts (Default)
Final Results (Default)
Metric | Value |
---|---|
final_level | 0.52 |
FAQ
- Why does progress slow near the goal?
- Because each step changes the level by k times the remaining gap, so as the gap shrinks the increments shrink too.
- What does the approach_rate probe show?
- It records the size of each incremental change toward the goal at every step.
- Is SimPy required here?
- The model uses SimPy purely for consistent timing and progress reporting.