From 7cd17e72ad997ecae4ef74e4f21aec9f15168296 Mon Sep 17 00:00:00 2001 From: Raul Peralta Date: Sun, 21 Jan 2024 17:34:19 -0600 Subject: [PATCH] Fix typos across multiple files --- sts_jax/causal_impact/causal_impact.py | 8 +++--- sts_jax/structural_time_series/learning.py | 4 +-- .../structural_time_series/sts_components.py | 28 +++++++++---------- sts_jax/structural_time_series/sts_ssm.py | 6 ++-- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/sts_jax/causal_impact/causal_impact.py b/sts_jax/causal_impact/causal_impact.py index be814c0..052cc2b 100644 --- a/sts_jax/causal_impact/causal_impact.py +++ b/sts_jax/causal_impact/causal_impact.py @@ -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) @@ -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"] @@ -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 ) @@ -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()) diff --git a/sts_jax/structural_time_series/learning.py b/sts_jax/structural_time_series/learning.py index 45e18a9..f98d971 100644 --- a/sts_jax/structural_time_series/learning.py +++ b/sts_jax/structural_time_series/learning.py @@ -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: diff --git a/sts_jax/structural_time_series/sts_components.py b/sts_jax/structural_time_series/sts_components.py index 17b34e5..5e82a7f 100644 --- a/sts_jax/structural_time_series/sts_components.py +++ b/sts_jax/structural_time_series/sts_components.py @@ -21,19 +21,19 @@ 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'. """ @@ -41,7 +41,7 @@ class ParamPropertiesSTS(OrderedDict): 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'. """ @@ -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 @@ -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$ @@ -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$ @@ -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: @@ -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: @@ -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: @@ -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 $$, @@ -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: @@ -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. diff --git a/sts_jax/structural_time_series/sts_ssm.py b/sts_jax/structural_time_series/sts_ssm.py index e011117..aa03069 100644 --- a/sts_jax/structural_time_series/sts_ssm.py +++ b/sts_jax/structural_time_series/sts_ssm.py @@ -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. """ @@ -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'. @@ -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