class_docstr: This class enables Greykite based anomaly detection algorithms.
      It takes a ``forecast_config`` and ``ad_config`` (see Parameters) and builds a detector which
      uses the forecast as baseline.
  
      The fit consists of following stages:
  
      - Fit a forecast model using the ``forecast_config`` passed
      - Fit a volatility model using
          `~greykite.algo.uncertainty.conditional.conf_interval.conf_interval`
          to optimize over
  
          -- ``volatility_features_list``
          -- ``coverage_grid``
  
          specified in ``ad_config`` passed.
  
  Parameters
  ----------
  ad_config: `~greykite.detection.detector.config.ADConfig` or None, default None
      Config object for anomaly detection to use.
  forecast_config : `~greykite.framework.templates.model_templates.ForecastConfig` or None, default None
      Config object for forecast to use.
  reward : See docstring for
      `~greykite.detection.detector.detector.Detector`
  
  Attributes
  ----------
  anomaly_percent_dict : `dict` or None,
      See attributes of `~greykite.detection.detector.detector.Detector`
  forecast_result : `~greykite.framework.pipeline.pipeline.ForecastResult` or None
      See class:`~greykite.framework.pipeline.pipeline.ForecastResult`
      for details.
  forecast_estimator : `~greykite.sklearn.estimator.base_forecast_estimator.BaseForecastEstimator` or None
      See class: `~greykite.sklearn.estimator.base_forecast_estimator.BaseForecastEstimator`
      for more details.
  ci_model : `dict`
      This is the fitted volatility model which is the returned dictionary from
      `greykite.algo.uncertainty.conditional.conf_interval`.
  fit_info : `dict` or None
      See attributes of `~greykite.detection.detector.detector.Detector`.
  anomaly_df : `pandas.DataFrame` or None
      A dataframe which includes the start and end times of observed anomalies.
  fit_data : `~greykite.detection.detector.data.DetectorData` or None
      The data used in the `fit` method.
class_docstr_tok: ["This","class","enables","Greykite","based","anomaly","detection","algorithms",".","It","takes","a","``","forecast_config","``","and","``","ad_config","``","(","see","Parameters",")","and","builds","a","detector","which","uses","the","forecast","as","baseline",".","The","fit","consists","of","following","stages",":","-","Fit","a","forecast","model","using","the","``","forecast_config","``","passed","-","Fit","a","volatility","model","using","`","~greykite.algo.uncertainty.conditional.conf_interval.conf_interval","`","to","optimize","over","--","``","volatility_features_list","``","--","``","coverage_grid","``","specified","in","``","ad_config","``","passed",".","Parameters","--","--","--","--","--","ad_config",":","`","~greykite.detection.detector.config.ADConfig","`","or","None",",","default","None","Config","object","for","anomaly","detection","to","use",".","forecast_config",":","`","~greykite.framework.templates.model_templates.ForecastConfig","`","or","None",",","default","None","Config","object","for","forecast","to","use",".","reward",":","See","docstring","for","`","~greykite.detection.detector.detector.Detector","`","Attributes","--","--","--","--","--","anomaly_percent_dict",":","`","dict","`","or","None",",","See","attributes","of","`","~greykite.detection.detector.detector.Detector","`","forecast_result",":","`","~greykite.framework.pipeline.pipeline.ForecastResult","`","or","None","See","class",":","`","~greykite.framework.pipeline.pipeline.ForecastResult","`","for","details",".","forecast_estimator",":","`","~greykite.sklearn.estimator.base_forecast_estimator.BaseForecastEstimator","`","or","None","See","class",":","`","~greykite.sklearn.estimator.base_forecast_estimator.BaseForecastEstimator","`","for","more","details",".","ci_model",":","`","dict","`","This","is","the","fitted","volatility","model","which","is","the","returned","dictionary","from","`","greykite.algo.uncertainty.conditional.conf_interval","`",".","fit_info",":","`","dict","`","or","None","See","attributes","of","`","~greykite.detection.detector.detector.Detector","`",".","anomaly_df",":","`","pandas.DataFrame","`","or","None","A","dataframe","which","includes","the","start","and","end","times","of","observed","anomalies",".","fit_data",":","`","~greykite.detection.detector.data.DetectorData","`","or","None","The","data","used","in","the","`","fit","`","method","."]
docstr: Initializes the GreykiteDetector class.
docstr_tok: ["Initializes","the","GreykiteDetector","class","."]
code: def __init__(self, forecast_config=None, ad_config=None, reward=None):
      """Initializes the GreykiteDetector class."""
      if forecast_config is None:
          forecast_config = ForecastConfig()
      else:
          forecast_config = deepcopy(forecast_config)
      if ad_config is None:
          ad_config = ADConfig()
      else:
          ad_config = deepcopy(ad_config)
  
      # Constructs an object of class `Reward` from `ad_config`.
      reward_from_config = config_to_reward(ad_config)
      if reward is None:
          reward = reward_from_config
      else:
          reward = reward + reward_from_config
  
      param_iterable = None
      if ad_config.coverage_grid is None:
          ad_config.coverage_grid = (
              DEFAULT_COVERAGE_GRID  # coverage grid can not be empty
          )
      param_iterable = add_new_params_to_records(
          new_params={"coverage": ad_config.coverage_grid},
          records=param_iterable,
      )
  
      if ad_config.volatility_features_list is None:
          ad_config.volatility_features_list = [
              []
          ]  # volatility features can be empty
      param_iterable = add_new_params_to_records(
          new_params={
              "volatility_features": ad_config.volatility_features_list
          },
          records=param_iterable,
      )
  
      if ad_config.ape_grid is not None:
          metric = ElementwiseEvaluationMetricEnum.AbsolutePercentError
          param_iterable = add_new_params_to_records(
              new_params={metric.get_metric_name(): ad_config.ape_grid},
              records=param_iterable,
          )
  
      if ad_config.sape_grid is not None:
          metric = (
              ElementwiseEvaluationMetricEnum.SymmetricAbsolutePercentError
          )
          param_iterable = add_new_params_to_records(
              new_params={
                  metric.get_metric_name(): ad_config.sape_grid
              },
              records=param_iterable,
          )
  
      super().__init__(
          reward=reward,
          anomaly_percent_dict=None,
          # In the above, if anomaly percent appears in `ad_config`,
          # it is already baked into `reward` via `config_to_reward` call above.
          param_iterable=param_iterable,
      )
  
      # Attributes
      self.forecast_config = forecast_config
      self.ad_config = ad_config
  
      # These will be set by the `fit` method.
      self.forecast_result = None
      self.forecast_estimator = None
      self.anomaly_df = None
      self.ci_model = None
      self.fit_info = None
      self.fit_data = None
  
imports: from copy import deepcopy
  import numpy
  import pandas
  from greykite.algo.uncertainty.conditional.conf_interval import conf_interval
  from greykite.algo.uncertainty.conditional.conf_interval import predict_ci
  from greykite.common.constants import ACTUAL_COL
  from greykite.common.constants import ANOMALY_COL
  from greykite.common.constants import END_TIME_COL
  from greykite.common.constants import ERR_STD_COL
  from greykite.common.constants import PREDICTED_ANOMALY_COL
  from greykite.common.constants import PREDICTED_COL
  from greykite.common.constants import PREDICTED_LOWER_COL
  from greykite.common.constants import PREDICTED_UPPER_COL
  from greykite.common.constants import QUANTILE_SUMMARY_COL
  from greykite.common.constants import RESIDUAL_COL
  from greykite.common.constants import START_TIME_COL
  from greykite.common.constants import TIME_COL
  from greykite.common.constants import VALUE_COL
  from greykite.common.evaluation import ElementwiseEvaluationMetricEnum
  from greykite.common.features.adjust_anomalous_data import adjust_anomalous_data
  from greykite.common.features.timeseries_features import add_daily_events
  from greykite.common.features.timeseries_features import add_time_features_df
  from greykite.common.logging import LoggingLevelEnum
  from greykite.common.logging import log_message
  from greykite.common.time_properties import describe_timeseries
  from greykite.common.time_properties import get_canonical_data
  from greykite.common.time_properties import infer_freq
  from greykite.detection.detector.ad_utils import add_new_params_to_records
  from greykite.detection.detector.ad_utils import get_anomaly_df
  from greykite.detection.detector.ad_utils import get_anomaly_df_from_outliers
  from greykite.detection.detector.ad_utils import get_canonical_anomaly_df
  from greykite.detection.detector.config import ADConfig
  from greykite.detection.detector.config_to_reward import config_to_reward
  from greykite.detection.detector.constants import DEFAULT_COVERAGE_GRID
  from greykite.detection.detector.constants import PHASE_PREDICT
  from greykite.detection.detector.constants import Z_SCORE_COL
  from greykite.detection.detector.detector import Detector
  from greykite.detection.detector.optimizer import CalcResult
  from greykite.framework.templates.autogen.forecast_config import ForecastConfig
  from greykite.framework.templates.autogen.forecast_config import MetadataParam
  from greykite.framework.templates.forecaster import Forecaster
label_desc: Use image node_id 1 to create a new GreykiteDetector object from inherited base classes: Detector with example: obj = GreykiteDetector(forecast_config, ad_config, reward)