-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fb6e810
commit 8569af5
Showing
11 changed files
with
629 additions
and
116 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
::: leaguedata.data | ||
options: | ||
show_root_heading: True | ||
show_root_toc_entry: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
::: leaguedata.inference | ||
options: | ||
show_root_heading: True | ||
show_root_toc_entry: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
::: leaguedata.model | ||
options: | ||
show_root_heading: True | ||
show_root_toc_entry: false |
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import numpyro | ||
import numpyro.distributions as dist | ||
import jax.numpy as jnp | ||
import numpy as np | ||
import tensorflow_probability.substrates.jax.distributions as tfd | ||
|
||
|
||
def numpyro_model(markov_model, observed_data): | ||
""" | ||
Function that is used as a model in NumPyro to perform inference on the Discrete Markov Chain model. | ||
Parameters: | ||
markov_model (DMCModel): The Discrete Markov Chain model to use. | ||
observed_data (jnp.array): The observed data to use for inference. | ||
""" | ||
|
||
if not markov_model.is_bernoulli: | ||
proba = numpyro.sample('proba', | ||
dist.Uniform(low=jnp.zeros(2 ** markov_model.n), high=jnp.ones(2 ** markov_model.n))) | ||
else: | ||
proba = numpyro.sample('proba', dist.Uniform(low=0, high=1)) * jnp.ones(2 ** markov_model.n) | ||
|
||
transition_matrix = markov_model.build_transition_matrix(proba) | ||
|
||
def transition_fn(_, x): | ||
return tfd.Categorical(probs=transition_matrix[x]) | ||
|
||
encoded_history = np.apply_along_axis(markov_model.binary_serie_to_categorical, 1, observed_data) | ||
|
||
likelihood_dist = tfd.MarkovChain( | ||
initial_state_prior=tfd.Categorical(probs=markov_model.uniform_prior), | ||
transition_fn=transition_fn, | ||
num_steps=encoded_history.shape[1] | ||
) | ||
|
||
numpyro.sample('likelihood', likelihood_dist, obs=encoded_history) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters