Goal-Seeking Decay

A goal-seeking decay simulation modeling exponential approach toward a target.

Level:Beginner

decaygoalbalancing-loopexponentialcontrolfirst-order-dynamicstime-delay

  • Stocks:level
  • Flows:approach_rate
  • Feedback Loops:goal-seeking (balancing)
  • Probes:level, approach_rate

Dynamic Behavior Patterns

Explore common system behaviors: exponential growth, goal-seeking decay, overshoot-and-collapse, and S-curve saturation.

Explore Dynamic Behavior Patterns
simulation.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)

level

level chartCSV
Samples50 @ 0.00–49.00
Valuesmin 0.52, mean 17.91, median 6.82, max 90.00, σ 23.06

approach_rate

approach_rate chartCSV
Samples50 @ 0.00–49.00
Valuesmin -10.00, mean -1.99, median -0.76, max -0.06, σ 2.56
Final Results (Default)
MetricValue
final_level0.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.