Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function fit_discrete_mc #678

Closed
jstac opened this issue Dec 30, 2022 · 6 comments
Closed

Add function fit_discrete_mc #678

jstac opened this issue Dec 30, 2022 · 6 comments

Comments

@jstac
Copy link
Contributor

jstac commented Dec 30, 2022

As discussed in #640, we should add a function called fit_discrete_mc that takes a time series $X_0, \ldots, X_{T-1}$ taking values in $\mathbb R^n$ (each $X_t$ is a vector in continuous state space $\mathbb R^n$) and fits a finite Markov chain to it using the following steps:

  1. Set up a one-dimensional grid in each dimension of $\mathbb R^n$ (e.g., if $n=2$ then set up a grid on the $x$ axis and the $y$ axis)
  2. Take the cartesian product of these 1D grids to get a set of grid points in $\mathbb R^n$
  3. Produce a new time series $\hat X_0, \ldots, \hat X_{T-1}$ by mapping each $X_t$ to the nearest grid point in $\mathbb R^n$.
  4. Fit a finite Markov chain to the new time series and return as a MarkovChain object.

This function just combines existing tools, since

#. for step 3, we can use cartesian_nearest_index
#. for step 4, we can use estimate_mc (see #658)

@oyamad Could you please confirm that you agree?
@Smit-create @HumphreyYang might you be willing to collaborate on this issue?

@oyamad
Copy link
Member

oyamad commented Dec 31, 2022

One thing I am concerned with is that it is less general than what the general name fit_discrete_mc would suggest, in that the state space of the finite MC will be just a Cartesian product. I would like to have an implementation that would warrant future extendability. Suppose that the function will be called with fit_discrete_mc(X, S).

  • For now, as S it accepts an array_like (typically tuple) of array_like's of 1D grid points.
  • In a future extension, add a cartesian option (with default True), where with cartesian=False, S will be a 2D array_like of n-dimensional points (which will be the state space of mc).

If this works, we can proceed for now as you propose.

@jstac
Copy link
Contributor Author

jstac commented Dec 31, 2022

Thanks for your comments @oyamad .

The extension you suggest sounds like a good idea. My understanding is that someone can proceed now in line with my suggestion and your bullet point one. We can then open as issue to add the enhancement that you suggested.

@Smit-create
Copy link
Member

Thanks @jstac and @oyamad ,
So are we trying to implement something like this?

def fit_discrete_mc(X, S):
    X_new = cartesian_nearest_index(X, S)
    return estimate_mc(X_new)

@jstac
Copy link
Contributor Author

jstac commented Jan 1, 2023

Hi @Smit-create , yes, that's all we need. The same lines appear in 745c0d4.

Notice that there's also an order keyword argument, which determines whether the cartesian product is counted in row major or column major. The default should be 'C', which is row major.

Many thanks!

@oyamad
Copy link
Member

oyamad commented Jan 1, 2023

See this part:

# Estimate the Markov chain
X_indices = cartesian_nearest_index(X.T, V, order=order)
mc = estimate_mc(X_indices)
# Assign the visited states in the cartesian product as the state values
prod = cartesian(V, order=order)
mc.state_values = prod[mc.state_values]
return mc

@oyamad
Copy link
Member

oyamad commented Jan 6, 2023

Done by #681

@oyamad oyamad closed this as completed Jan 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants