code: def build_effects_to_residuals_matrix(num_seasons, dtype):
      """Build change-of-basis matrices for constrained seasonal effects.
  
      This method builds the matrix that transforms seasonal effects into
      effect residuals (differences from the mean effect), and additionally
      projects these residuals onto the subspace where the mean effect is zero.
  
      See `ConstrainedSeasonalStateSpaceModel` for mathematical details.
  
      Args:
        num_seasons: scalar `int` number of seasons.
        dtype: TensorFlow `dtype` for the returned values.
      Returns:
        effects_to_residuals: `Tensor` of shape
          `[num_seasons-1, num_seasons]`, such that `differences_from_mean_effect =
          matmul(effects_to_residuals, seasonal_effects)`.  In the
          notation of `ConstrainedSeasonalStateSpaceModel`, this is
          `effects_to_residuals = P * R`.
        residuals_to_effects: the (pseudo)-inverse of the above; a
          `Tensor` of shape `[num_seasons, num_seasons-1]`. In the
          notation of `ConstrainedSeasonalStateSpaceModel`, this is
          `residuals_to_effects = R^{-1} * P'`.
      """
  
      # Build the matrix that converts effects `e_i` into differences from the mean
      # effect `(e_i - sum(e_i)) / num_seasons`, with the mean effect in the last
      # row so that the transformation is invertible.
      effects_to_residuals_fullrank = (
          np.eye(num_seasons) - 1.0 / num_seasons
      )
      effects_to_residuals_fullrank[-1, :] = (
          1.0 / num_seasons
      )  # compute mean effect
      residuals_to_effects_fullrank = np.linalg.inv(
          effects_to_residuals_fullrank
      )
  
      # Drop the final dimension, effectively setting the mean effect to zero.
      effects_to_residuals = effects_to_residuals_fullrank[:-1, :]
      residuals_to_effects = residuals_to_effects_fullrank[:, :-1]
  
      # Return Tensor values of the specified dtype.
      effects_to_residuals = tf.cast(
          effects_to_residuals, dtype=dtype, name="effects_to_residuals"
      )
      residuals_to_effects = tf.cast(
          residuals_to_effects, dtype=dtype, name="residuals_to_effects"
      )
  
      return effects_to_residuals, residuals_to_effects
  
imports: import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.bijectors import chain
  from tensorflow_probability.python.bijectors import invert
  from tensorflow_probability.python.bijectors import scale
  from tensorflow_probability.python.bijectors import softplus
  from tensorflow_probability.python.bijectors import square
  from tensorflow_probability.python.distributions import inverse_gamma
  from tensorflow_probability.python.distributions import linear_gaussian_ssm
  from tensorflow_probability.python.distributions import lognormal
  from tensorflow_probability.python.distributions import mvn_diag
  from tensorflow_probability.python.distributions import mvn_tril
  from tensorflow_probability.python.distributions import normal
  from tensorflow_probability.python.distributions import transformed_distribution
  from tensorflow_probability.python.experimental.sts_gibbs import sample_parameters
  from tensorflow_probability.python.internal import distribution_util
  from tensorflow_probability.python.internal import docstring_util
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.sts.internal import util
  from tensorflow_probability.python.sts.structural_time_series import Parameter
  from tensorflow_probability.python.sts.structural_time_series import StructuralTimeSeries
label_desc: Use image node_id 2 for calling a global function with example usage: build_effects_to_residuals_matrix(num_seasons, dtype) and returns: effects_to_residuals,  residuals_to_effects