Skip to main content
LearnMLAcademy
Advanced10 min read

State-Space Models

Understand linear State-Space Models (SSMs) and selective Mamba scan layers, with sequence diagrams, attention calculations, and model-code exercises.

What you will master in this lesson
Intuitive core mechanisms & practical real-world intuition
Step-by-step mathematical breakdown & visual diagrams
Runnable Python implementation & practical trade-offs

Advanced Deep Learning Topic

State-space models maintain a compact internal state while processing an ordered sequence. This optional lesson preserves the state-space material outside the 24-lesson core path.

The Basic State Update

In a simplified discrete linear model, A carries information from the previous state, B writes the current input, C reads the state, and D can pass the current input directly to the output. In practical models these symbols usually represent learned or structured matrices.

st = A st−1 + B xt

yt = C st + D xt

A compact state carries selected information through a long sequence

input x₁

↓

state s1

produces y1

→

input x₂

↓

state s2

produces y2

→

input x₃

↓

state s3

produces y3

→

input x₄

↓

state s4

produces y4

The state is updated rather than storing every earlier input separately. Structured and selective SSMs make this idea efficient and input-aware in different ways.

A One-Dimensional Teaching Example

Choose A=0.9 and B=0.2 only to make the arithmetic visible. Let the previous state be 0.5 and the current data value be 1.

st=(0.9×0.5)+(0.2×1)=0.45+0.20=0.65

The first product retains part of the old state; the second writes current evidence; addition combines them. A real model learns or constrains these transformations during training.

From Classical to Selective SSMs

Structured SSMs parameterize the state update so long sequences can be processed efficiently. Selective variants make parts of the update depend on the current input, allowing the model to preserve or suppress information conditionally. These architectures need task-specific evidence: compare quality, latency, memory, tooling and long-context behavior with recurrent and attention baselines.

Related Learning

Apply this concept in a real hands-on project

You have studied the idea. Now use it in working Python code, see the calculation and output, and explain what changed. Each project includes step-by-step instructions, full source and tests.

Practice challenge: predict an outcome first, run the code, and explain the difference.

Track Your Progress0% curriculum done

Finished "State-Space Models"?

Mark this lesson as completed to update your progress bar and track your milestones across the full curriculum.

Overall Progress0 / 167 lessons

Was this tutorial helpful?

Your feedback helps us continuously refine and improve our open-access tutorials.

Summary / Key Takeaways

  • An SSM updates a compact state while reading an ordered sequence.
  • A state transition retains history and an input transform writes new evidence.
  • An output transform reads state, optionally with a direct input path.
  • Structured updates make long-sequence computation efficient.
  • Selective variants condition retention on the current input.
  • Compare quality, memory, latency, tooling, and long-context behavior with alternatives.

Knowledge Check

Progress: 0/5

Test your active recall. Choose one answer for each question, then check it to reveal the step-by-step reasoning.

Question 1 of 5conceptual
What is the purpose of the state s_t?
Question 2 of 5numerical/formula
For s_t=0.9s_{t-1}+0.2x_t, s_{t-1}=0.5, and x_t=1, what is s_t?
Question 3 of 5interpretation
What does a direct D x_t output term provide?
Question 4 of 5conceptual
How do selective SSMs extend a fixed structured update?
Question 5 of 5practical selection
What is a fair evaluation against attention models?

Knowledge Check Review & Explanations

Review the questions, verified correct answers, and conceptual explanations for this lesson.

1What is the purpose of the state s_t?▼

Correct Answer: Carry a compact summary through the sequence

The updated state combines retained history with current input evidence.

2For s_t=0.9s_{t-1}+0.2x_t, s_{t-1}=0.5, and x_t=1, what is s_t?▼

Correct Answer: 0.65

Compute 0.9×0.5 + 0.2×1 = 0.45+0.20 = 0.65.

3What does a direct D x_t output term provide?▼

Correct Answer: A path from current input directly to output

The output can use current evidence without requiring it to pass only through stored state.

4How do selective SSMs extend a fixed structured update?▼

Correct Answer: Current input can influence what is retained or suppressed

Input-dependent selection makes state handling conditional on the token or reading.

5What is a fair evaluation against attention models?▼

Correct Answer: Compare quality, latency, memory, and long-context behavior

SSM value depends on both task quality and the efficiency constraints it is intended to improve.

Keep moving through the path

Continue Learning

Free Download: ML Interview Cheatsheet

100 essential Machine Learning interview questions and answers covering foundations, algorithms, evaluation, deep learning, Python, system design and interview strategy. Enter your email to download it instantly.

Optional Learning Resources

These resources may complement the lesson. They are optional and are not required to use ML Academy.

As an Amazon Associate I earn from qualifying purchases. Other links are identified separately when they are not affiliate links.

Next