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

Fix typos across multiple files #13

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions sts_jax/causal_impact/causal_impact.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def plot(self) -> None:
x = jnp.arange(self.time_series.shape[0])
fig, (ax1, ax2, ax3) = plt.subplots(3, 1, figsize=(9, 6), sharex=True, layout="constrained")

# Plot the original obvervation and the counterfactual predict
# Plot the original observation and the counterfactual predict
ax1.plot(x, self.time_series, color="black", lw=2, label="Observation")
ax1.plot(x, self.predict_point, linestyle="dashed", color="blue", lw=2, label="Prediction")
ax1.fill_between(x, self.predict_interval[0], self.predict_interval[1], color="blue", alpha=0.2)
Expand Down Expand Up @@ -90,7 +90,7 @@ def print_summary(self) -> None:
f'{f"[{pred_l.cumulative:.2f}, {pred_r.cumulative:.2f}]": ^{ncol3}}'
)

# Summary statistics of the absolute post-invervention effect
# Summary statistics of the absolute post-intervention effect
abs_e = self.summary["abs_effect"]
abs_sd = self.summary["abs_effect_sd"]
abs_l = self.summary["abs_effect_lower"]
Expand Down Expand Up @@ -202,7 +202,7 @@ def causal_impact(
# Fit the STS model, sample from the past and forecast.
# Model fitting
params_posterior_samples, _ = sts_model.fit_hmc(num_samples, time_series_pre, covariates=covariates_pre, key=key1)
# Sample observations from the posterior predictive sample given paramters of the STS model.
# Sample observations from the posterior predictive sample given parameters of the STS model.
posterior_sample_means, posterior_samples = sts_model.posterior_sample(
params_posterior_samples, time_series_pre, covariates_pre, key=key2
)
Expand Down Expand Up @@ -266,7 +266,7 @@ def causal_impact(
average=jnp.std(forecast_samples.mean(axis=1)), cumulative=jnp.std(forecast_samples.sum(axis=1))
)

# Summary statistics of the absolute post-invervention effect
# Summary statistics of the absolute post-intervention effect
effect_means = time_series_pos - forecast_means
effects = time_series_pos - forecast_samples
summary["abs_effect"] = Stats(average=effect_means.mean(axis=0).mean(), cumulative=effect_means.mean(axis=0).sum())
Expand Down
4 changes: 2 additions & 2 deletions sts_jax/structural_time_series/learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ def fit_vi(
which is achieved by written KL(q || p) as expectation over standard normal distribution
so a sample from q is obstained by
s = z * exp(log_sigma_k) + mu_k,
where z is a sample from the standard multivarate normal distribtion.
where z is a sample from the standard multivariate normal distribution.

Args:
sample_size (int): number of samples to be returned from the fitted approxiamtion q.
sample_size (int): number of samples to be returned from the fitted approximation q.
M (int): number of fixed samples from q used in evaluation of ELBO.

Returns:
Expand Down
28 changes: 14 additions & 14 deletions sts_jax/structural_time_series/sts_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,27 @@


class ParamsSTSComponent(OrderedDict):
"""A :class: 'OrderdedDict' with each item being an instance of :class: 'jax.DeviceArray'."""
"""A :class: 'OrderedDict' with each item being an instance of :class: 'jax.DeviceArray'."""

pass


class ParamsSTS(OrderedDict):
"""A :class: 'OrderdedDict' with each item being an instance of :class: 'OrderedDict'."""
"""A :class: 'OrderedDict' with each item being an instance of :class: 'OrderedDict'."""

pass


class ParamPropertiesSTS(OrderedDict):
"""A :class: 'OrderdedDict' with each item being an instance of :class: 'OrderedDict',
"""A :class: 'OrderedDict' with each item being an instance of :class: 'OrderedDict',
having the same pytree structure with 'ParamsSTS'.
"""

pass


class ParamPriorsSTS(OrderedDict):
"""A :class: 'OrderdedDict' with each item being an instance of :class: 'OrderedDict',
"""A :class: 'OrderedDict' with each item being an instance of :class: 'OrderedDict',
having the same pytree structure with 'ParamsSTS'.
"""

Expand Down Expand Up @@ -81,7 +81,7 @@ class STSComponent(ABC):
component at time step $t$.
* :attr: 'obs_mat' returns the observation (emission) matrix $H$ for the latent component.
* :attr: 'cov_select_mat' returns the selecting matrix $R$ that expands the nonsingular
covariance matrix $Q[t]$ in each time step into a (possibly singular) convarince
covariance matrix $Q[t]$ in each time step into a (possibly singular) covariance
matrix of shape (dim_state, dim_state).
* :attr: 'name' returns the unique name of the latent component.
* :attr: 'dim_obs' returns the dimension of the observation in each step of the observed
Expand Down Expand Up @@ -130,7 +130,7 @@ def get_trans_mat(self, params: ParamsSTSComponent, t: int) -> Float[Array, "dim
Args:
params: parameters of the latent component, having the same tree structure with
self.params.
t: time point at which the transition matrix is to be evaluted.
t: time point at which the transition matrix is to be evaluated.

Returns:
transition matrix, $F[t]$, of the latent component at time step $t$
Expand All @@ -145,7 +145,7 @@ def get_trans_cov(self, params: ParamsSTSComponent, t: int) -> Float[Array, "ran
Args:
params: parameters of the latent component, having the same tree structure with
self.params.
t: time point at which the transition matrix is to be evaluted.
t: time point at which the transition matrix is to be evaluated.

Returns:
nonsingular covariance matrix, $Q[t]$, of the latent component at time step $t$
Expand All @@ -162,7 +162,7 @@ def obs_mat(self) -> Float[Array, "dim_obs dim_state"]:
@abstractmethod
def cov_select_mat(self) -> Float[Array, "dim_state rank_state"]:
r"""Returns the selecting matrix $R$ that expands the nonsingular covariance matrix
$Q[t]$ in each time step into a (possibly singular) convarince matrix of shape
$Q[t]$ in each time step into a (possibly singular) covariance matrix of shape
(dim_state, dim_state).

Returns:
Expand Down Expand Up @@ -230,11 +230,11 @@ def initialize_params(
def get_reg_value(
self, params: ParamsSTSComponent, covariates: Float[Array, "num_timesteps dim_covariates"]
) -> Float[Array, "num_timesteps dim_obs"]:
r"""Returns the sequence of values of the regression model evaluted at the
r"""Returns the sequence of values of the regression model evaluated at the
given parameters and the sequence of covariates.

Args:
params: parameters on which the regression model is to be evalueated.
params: parameters on which the regression model is to be evaluated.
covariates: sequence of covariates at which the regression model is to be evaluated.

Raises:
Expand All @@ -249,7 +249,7 @@ def get_reg_value(


class LocalLinearTrend(STSComponent):
r"""The local linear trend component of the structual time series (STS) model
r"""The local linear trend component of the structural time series (STS) model

The latent state has two parts $[level, slope]$, having dimension 2 * dim_obs.
The dynamics is:
Expand Down Expand Up @@ -451,7 +451,7 @@ def cov_select_mat(self) -> Float[Array, "order*dim_obs dim_obs"]:
class SeasonalDummy(STSComponent):
r"""The (dummy) seasonal component of the structual time series (STS) model

Since at any step $t$ the seasonal effect has following constraint
Since at any step $t$ the seasonal effect has the following constraint

$$sum_{j=1}^{num_seasons} s_{t-j} = 0 $$,

Expand Down Expand Up @@ -571,7 +571,7 @@ def cov_select_mat(self) -> Float[Array, "(num_seasons-1)*dim_obs dim_obs"]:


class SeasonalTrig(STSComponent):
r"""The trigonometric seasonal component of the structual time series (STS) model.
r"""The trigonometric seasonal component of the structural time series (STS) model.

The seasonal effect (random) of next time step takes the form:

Expand All @@ -589,7 +589,7 @@ class SeasonalTrig(STSComponent):
distribution with mean zeros and a common covariance $drift_cov$ for all $j$ and $t$.

The latent state corresponding to the seasonal component has dimension $(s-1) * dim_obs$.
If $s$ is odd, then $s-1 = 2 * (s-1)/2$, which means thare are $j = 1,...,(s-1)/2$ blocks.
If $s$ is odd, then $s-1 = 2 * (s-1)/2$, which means there are $j = 1,...,(s-1)/2$ blocks.
If $s$ is even, then $s-1 = 2 * (s/2) - 1$, which means there are $j = 1,...(s/2)$ blocks,
but we remove the last dimension in this case since this part does not play role in the
observation.
Expand Down
6 changes: 3 additions & 3 deletions sts_jax/structural_time_series/sts_ssm.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@


class StructuralTimeSeriesSSM(SSM):
"""Formulate the structual time series(STS) model into a LinearSSM model,
"""Formulate the structural time series(STS) model into a LinearSSM model,
which always have block-diagonal dynamics covariance matrix and fixed transition matrices.
"""

Expand All @@ -67,7 +67,7 @@ def __init__(
parameters of one component.
param_props: properties of parameters of the STS model, having same tree structure
with 'params', each leaf node is a instance of 'ParameterProperties' for the
parameter in the conrresponding leaf node of 'params'.
parameter in the corresponding leaf node of 'params'.
param_priors: priors of parameters of the STS model, having same tree structure
with 'params', each leaf node is a prior distribution for the parameter in the
corresponding leaf node of 'params'.
Expand Down Expand Up @@ -143,7 +143,7 @@ def initial_distribution(self):
def transition_distribution(self, state):
"""This is a must-have method of SSM.
Not implemented here because tfp.distribution does not support multivariate normal
distribution with singular convariance matrix.
distribution with singular covariance matrix.
"""
raise NotImplementedError

Expand Down