Skip to content

Conversation

@timmens
Copy link
Member

@timmens timmens commented Aug 19, 2025

There seems to be something wrong about the stochastics in PyLCM.

In this PR, I want to validate and potentially fix the parts in PyLCM that work with stochastics. This will most likely close #39 and #63.

In particular, we have to answer the following questions:

  • Mathematically, what do the state transition probabilities represent (joint probabilities or conditional probabilities)
  • Given that we assume that stochastic state transitions can depend on other stochastic variables, does this interfere with our assumption that in a given period, the stochastic states are independent?

I believe here we must start form the mathematics again, and then work ourselves down to the implementation.

What we (most likely) need

  • We need to improve the error handling of the transition matrices as well (BUG: Transition matrices with incorrect shapes do not throw error #63)
    Ideally, we check that the transition matrices and the model are consistent as early as possible; i.e., inside the solve(params) or simulate(params) call, but before any computation
  • We absolutely need to refactor the stochastics related code; it is very hard to understand!
  • Move computation of node weights from Q_and_F.py to solve_brute.py (helps in modularization, cleans up Q_and_F code)

@timmens timmens self-assigned this Aug 19, 2025
@hmgaudecker
Copy link
Member

hmgaudecker commented Aug 19, 2025

I was going to write a quick reply because I do think these should be pretty clear, but without formulas it is really hard to grasp what you are after precisely. Could you maybe give an example in math?

In general, I guess a transition for some element $k$ of the state vector $s$ is always:

$$ s^k_{t+1} = g(\mu(s_t) + \varepsilon_t) $$

There might be cases where you scale $\varepsilon_t$ with $\sigma(s_t)$, but typically not when we are concerned with discrete states. The form of $g(\cdot)$ does not matter much here, for discrete states it will be that its index is above and/or below some cutoff.

When talking about independence etc, we are usually thinking about $\varepsilon$.

When we say "the next state depends on current state $m$", we are typically talking about the case that $\mu(\cdot)$ takes the form $\mu(s^m_t)$. In #39, we have the issue that we do not support the case where $\mu$ is a constant.

@timmens timmens linked an issue Aug 20, 2025 that may be closed by this pull request
Base automatically changed from improvement to main August 24, 2025 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Transition matrices with incorrect shapes do not throw error BUG: Stochastic next functions need to depend on at least one argument

3 participants