class_docstr: Reward class which is to support very flexible set of rewards
  used in optimization where an objective is to be optimized.
  
  The main method for this class is `apply` which
  is used when the reward is to be applied to data.
  No assumption is made on the arguments of `apply` to keep this class very
  generic.
  
  This class enables two powerful mechanisms:
  
  - taking a simple `reward_func` and construct a penalized version of that
  - starting from existing objectives building more complex ones by adding /
  multiplying / dividing them or use same operations with numbers.
  
  Using these two mechanisms can enable use to support multi-objective problems.
  For examples, in the context of anomaly detection if recall is to be optimized
  subject to precision being at least 80 percent, then use can enable that by
  
  def recall(y_true, y_pred):
      # recall function implementation
      ...
  
  def precision(y_true, y_pred):
      # precision function implementation
      ...
  
  reward =
      Reward(reward_func=recall) +
      Reward(
          reward_func=precision,
          min_unpenalized_metric=0.8,
          max_unpenalized_metric=None,
          penalty=-inf)
  
  where the second part will cause the total sum of the objectives to be -inf
  whenever precision is not in the desired range.
  Also note that the "+" operation is defined in this class using the dunder
  method `__add__`.
  
  One can also combine objectives to achieve more complex objectives from existing ones. For example F1 can be easily expressed in terms of
  precision and recall:
  
      rec_obj = Reward(reward_func=recall)
      prec_obj =Reward(reward_func=precision)
      f1_obj = (2 * rec_obj * prec_obj) / (rec_obj + prec_obj)
  
  The penalize mechanism on its own is useful for example in the context of
  anomaly detection without labels, where we only have an idea about the
  expected anomaly percentage in the data. In such a case an objective can be
  constructed for optimization. See
      `~greykite.detection.detector.detector.Detector`
  init to see a construction of such an objective.
  
  
  Parameters
  ----------
  reward_func : callable
      The reward function which will be used as the staring point and augmented
      with extra logic depending on other input.
  min_unpenalized : `float`, default `float("-inf")`
      The minimum value of the reward function (`reward_func`) which will
      remain un-penalized.
  max_unpenalized : `float`, default `float("inf")`
      The maximum value of the reward function (`reward_func`) which will
      remain un-penalized.
  penalize_method : `str`, default `PenalizeMethod.ADDITIVE.value`
      The logic of using the penalty. The possibilities are given in
      `~greykite.detection.detector.constants.PenalizeMethod`
  penalty : `float` or None, default None
      The penalty amount. If None, it will be mapped to 0 for additive and
      1 for multiplicative.
  
  Attributes
  ----------
  None
class_docstr_tok: ["Reward","class","which","is","to","support","very","flexible","set","of","rewards","used","in","optimization","where","an","objective","is","to","be","optimized",".","The","main","method","for","this","class","is","`","apply","`","which","is","used","when","the","reward","is","to","be","applied","to","data",".","No","assumption","is","made","on","the","arguments","of","`","apply","`","to","keep","this","class","very","generic",".","This","class","enables","two","powerful","mechanisms",":","-","taking","a","simple","`","reward_func","`","and","construct","a","penalized","version","of","that","-","starting","from","existing","objectives","building","more","complex","ones","by","adding","\/","multiplying","\/","dividing","them","or","use","same","operations","with","numbers",".","Using","these","two","mechanisms","can","enable","use","to","support","multi-objective","problems",".","For","examples",",","in","the","context","of","anomaly","detection","if","recall","is","to","be","optimized","subject","to","precision","being","at","least","80","percent",",","then","use","can","enable","that","by","def","recall","(","y_true",",","y_pred",")",":","#","recall","function","implementation","...","def","precision","(","y_true",",","y_pred",")",":","#","precision","function","implementation","...","reward","=","Reward","(","reward_func=recall",")","+","Reward","(","reward_func=precision",",","min_unpenalized_metric=0.8",",","max_unpenalized_metric=None",",","penalty=-inf",")","where","the","second","part","will","cause","the","total","sum","of","the","objectives","to","be","-inf","whenever","precision","is","not","in","the","desired","range",".","Also","note","that","the","``","+","''","operation","is","defined","in","this","class","using","the","dunder","method","`","__add__","`",".","One","can","also","combine","objectives","to","achieve","more","complex","objectives","from","existing","ones",".","For","example","F1","can","be","easily","expressed","in","terms","of","precision","and","recall",":","rec_obj","=","Reward","(","reward_func=recall",")","prec_obj","=Reward","(","reward_func=precision",")","f1_obj","=","(","2","*","rec_obj","*","prec_obj",")","\/","(","rec_obj","+","prec_obj",")","The","penalize","mechanism","on","its","own","is","useful","for","example","in","the","context","of","anomaly","detection","without","labels",",","where","we","only","have","an","idea","about","the","expected","anomaly","percentage","in","the","data",".","In","such","a","case","an","objective","can","be","constructed","for","optimization",".","See","`","~greykite.detection.detector.detector.Detector","`","init","to","see","a","construction","of","such","an","objective",".","Parameters","--","--","--","--","--","reward_func",":","callable","The","reward","function","which","will","be","used","as","the","staring","point","and","augmented","with","extra","logic","depending","on","other","input",".","min_unpenalized",":","`","float","`",",","default","`","float","(","``","-inf","''",")","`","The","minimum","value","of","the","reward","function","(","`","reward_func","`",")","which","will","remain","un-penalized",".","max_unpenalized",":","`","float","`",",","default","`","float","(","``","inf","''",")","`","The","maximum","value","of","the","reward","function","(","`","reward_func","`",")","which","will","remain","un-penalized",".","penalize_method",":","`","str","`",",","default","`","PenalizeMethod.ADDITIVE.value","`","The","logic","of","using","the","penalty",".","The","possibilities","are","given","in","`","~greykite.detection.detector.constants.PenalizeMethod","`","penalty",":","`","float","`","or","None",",","default","None","The","penalty","amount",".","If","None",",","it","will","be","mapped","to","0","for","additive","and","1","for","multiplicative",".","Attributes","--","--","--","--","--","None"]
docstr: Multiplication of objects or an object with a number.
docstr_tok: ["Multiplication","of","objects","or","an","object","with","a","number","."]
code: def __mul__(self, other):
      """Multiplication of objects or an object with a number."""
      if isinstance(other, numbers.Number):
  
          def reward_func(*args, **kwargs):
              return self.apply(*args, **kwargs) * other
  
      else:
  
          def reward_func(*args, **kwargs):
              return self.apply(*args, **kwargs) * other.apply(
                  *args, **kwargs
              )
  
      return Reward(reward_func=reward_func)
  
file_path: greykite/greykite/detection/detector/reward.py
imports: import inspect
  import numbers
  from greykite.detection.detector.constants import PenalizeMethod
label_desc: Use image node_id 4 for calling the Reward obj's underlying member method code with example usage: obj.__mul__(other) and returns: Reward, unknown, unknown