code: def get_changes_from_beta(
      beta, seasonality_components_df, magnitude_only=False
  ):
      """Gets the seasonality magnitude change arrays for each seasonality component from the
      estimated regression coefficients.
  
      In total there are::
  
          {sum_{i=1}^{number of components}(2 * order of component i)} * {number of changepoints + 1}
  
      coefficients in ``beta``, where the + 1 counts the overall seasonality. These coefficients
      indicate the change in magnitude for each term in each component at each change point.
      We can't work on these directly, since the values are positive or negative.
  
      Two options are available to calcumated the change metric, controlled by the parameter
      ``magnitude_only``.
  
      If ``magnitude_only`` == True, the cumulative sum is taken for every single cos or sin term
      (from all components) along the change points. The results are the magnitudes for each cos
      or sin term (from all components) at each change point. An L2 norm is taken over the cos and sin
      terms' magnitudes within the same component at the same change point. Now for each component
      at every change point, we have one L2 norm value that represents the magnitude (no longer
      cos or sin level). Then the magnitude changes for the same component between consecutive
      change points are computed. This option captures total magnitude changes only.
  
      If ``magnitude_only`` == False, an L2 norm is taken over the cos or sin magnitude changes
      in the same component directly. This option captures shape changes as well.
  
      A dictionary is returned with keys equal to the component names, and values are the corresponding
      arrays of changes.
  
      Parameters
      ----------
      beta : `np.array`
          The estimated regression coefficients.
      seasonality_components_df : `pandas.DataFrame`
          The df to generate seasonality design matrix, which is compatible with
          ``seasonality_components_df`` in
          `~greykite.algo.changepoint.adalasso.changepoint_detector.ChangepointDetector.find_seasonality_changepoints`
      magnitude_only : `bool`, default False
          Set to True to compute the L2 norms on the seasonality magnitudes, and set to False to compute the
          L2 norms on the seasonailty changes.
  
      Returns
      -------
      seasonality_magnitude : `dict`
          Keys are seasonality components, and values are the arrays of changes at each changepoint for the
          components.
  
      Examples
      --------
      # 1 change point, 2 seasonality components: "weekly" has order 1, and "yearly" has order 2.
      # so (1 + 2) * 2 * (1 + 1) = 12 coefficients in total.
      # the terms above are
      # [(weekly_order + yearly_order) * 2_terms_sin_cos] * (overall_seasonality + num_changepoints)
      >>> # the initial coefficients are [1, 1, 1, 1, 1, 1], and changes to [2, 0, 2, 2, 2, 0] at the change point
      >>> # the change is [1, -1, 1, 1, 1, -1].
      >>> beta = np.array([1, 1,     1, 1, 1, 1,          # initial coefficients
      ...                  1, -1,    1, 1, 1, -1])        # changes to [2, 0,     2, 2, 2, 0]
      >>> seasonality_components_df = pd.DataFrame({
      ...     "name": ["tow", "conti_year"],
      ...     "period": [7.0, 1.0],
      ...     "order": [1, 2],
      ...     "seas_names": ["weekly", "yearly"]})
      >>> result = get_changes_from_beta(beta, seasonality_components_df, True)
      >>> # when ``magnitude_only`` is set to True, the norm is calculated on the magnitude coefficients
      >>> # we have norms = [[sqrt(2), 2], [2, 2 * sqrt(3)]]
      >>> # hence the changes at the change point are [2 - sqrt(2), 2 * sqrt(3) - 2]
      >>> # the first coefficients is always prepended.
      >>> for key, value in result.items():
      >>>     print(key, value)
      weekly [1.41421356 0.58578644]
      yearly [2.         1.46410162]
  
      >>> # when ``magnitude_only`` is set to False, the norm is calculated directly on the change coefficients
      >>> # we have changes [sqrt(2), 2] at the change point
      >>> result = get_changes_from_beta(beta, seasonality_components_df, False)
      >>> for key, value in result.items():
      >>>     print(key, value)
      weekly [1.41421356 1.41421356]
      yearly [2. 2.]
      """
      # gets the number of terms in each component
      num_terms = (seasonality_components_df["order"] * 2).tolist()
      # gets the names of components
      components = seasonality_components_df["seas_names"].tolist()
      # reshapes the regression coefficients and computes the magnitude coefficients
      # the columns are the terms of different orders for each component
      # each row is one change point
      beta_mat = beta.reshape(-1, sum(num_terms))
      if magnitude_only:
          # cumsum gets the coefficient for the term between this changepoint and the next one.
          coef_mat = np.cumsum(beta_mat, axis=0)
      # computes the change magnitudes of each component at each time point, metric is l2 norm
      result = {}
      for i in range(len(num_terms)):
          start = np.sum(num_terms[:i]).astype(int)
          end = np.sum(num_terms[: (i + 1)]).astype(int)
          if magnitude_only:
              result[components[i]] = np.diff(
                  np.linalg.norm(coef_mat[:, start:end], axis=1),
                  prepend=0,
              )
          else:
              result[components[i]] = np.linalg.norm(
                  beta_mat[:, start:end], axis=1
              )
      return result
  
imports: import warnings
  from datetime import timedelta
  import numpy
  import pandas
  import plotly.graph_objects
  from pandas.plotting import register_matplotlib_converters
  from pandas.tseries.frequencies import to_offset
  from sklearn.linear_model import Lasso
  from sklearn.linear_model import LassoCV
  from sklearn.linear_model import LinearRegression
  from sklearn.linear_model import RidgeCV
  from greykite.common.constants import CHANGEPOINT_COL_PREFIX
  from greykite.common.constants import TimeFeaturesEnum
  from greykite.common.features.timeseries_features import add_time_features_df
  from greykite.common.features.timeseries_features import build_time_features_df
  from greykite.common.features.timeseries_features import fourier_series_multi_fcn
  from greykite.common.features.timeseries_features import get_changepoint_dates_from_changepoints_dict
  from greykite.common.features.timeseries_features import get_changepoint_features
  from greykite.common.features.timeseries_features import get_changepoint_features_and_values_from_config
  from greykite.common.features.timeseries_features import get_default_origin_for_time_vars
  from greykite.common.python_utils import get_pattern_cols
  from greykite.common.python_utils import unique_elements_in_list
label_desc: Use image node_id 12 for calling a global function with example usage: get_changes_from_beta(beta, seasonality_components_df, magnitude_only) and returns: result