docstr: FréchetSort is a softer version of descending sort which samples all possible
  orderings of items favoring orderings which resemble descending sort. This can
  be used to convert descending sort by rank score into a differentiable,
  stochastic policy amenable to policy gradient algorithms.
  
  :param shape: parameter of Frechet Distribution. Lower values correspond to
  aggressive deviations from descending sort.
  :param topk: If specified, only the first topk actions are specified.
  :param equiv_len: Orders are considered equivalent if the top equiv_len match. Used
      in probability computations.
      Essentially specifies the action space.
  :param log_scores Scores passed in are already log-transformed. In this case, we would
  simply add Gumbel noise.
  For LearnVM, we set this to be True because we expect input and output scores
  to be in the log space.
  
  Example:
  
  Consider the sampler:
  
  sampler = FrechetSort(shape=3, topk=5, equiv_len=3)
  
  Given a set of scores, this sampler will produce indices of items roughly
  resembling a argsort by scores in descending order. The higher the shape,
  the more it would resemble a descending argsort. `topk=5` means only the top
  5 ranks will be output. The `equiv_len` determines what orders are considered
  equivalent for probability computation. In this example, the sampler will
  produce probability for the top 3 items appearing in a given order for the
  `log_prob` call.
docstr_tok: ["Fr\u00e9chetSort","is","a","softer","version","of","descending","sort","which","samples","all","possible","orderings","of","items","favoring","orderings","which","resemble","descending","sort",".","This","can","be","used","to","convert","descending","sort","by","rank","score","into","a","differentiable",",","stochastic","policy","amenable","to","policy","gradient","algorithms",".",":","param","shape",":","parameter","of","Frechet","Distribution",".","Lower","values","correspond","to","aggressive","deviations","from","descending","sort",".",":","param","topk",":","If","specified",",","only","the","first","topk","actions","are","specified",".",":","param","equiv_len",":","Orders","are","considered","equivalent","if","the","top","equiv_len","match",".","Used","in","probability","computations",".","Essentially","specifies","the","action","space",".",":","param","log_scores","Scores","passed","in","are","already","log-transformed",".","In","this","case",",","we","would","simply","add","Gumbel","noise",".","For","LearnVM",",","we","set","this","to","be","True","because","we","expect","input","and","output","scores","to","be","in","the","log","space",".","Example",":","Consider","the","sampler",":","sampler","=","FrechetSort","(","shape=3",",","topk=5",",","equiv_len=3",")","Given","a","set","of","scores",",","this","sampler","will","produce","indices","of","items","roughly","resembling","a","argsort","by","scores","in","descending","order",".","The","higher","the","shape",",","the","more","it","would","resemble","a","descending","argsort",".","`","topk=5","`","means","only","the","top","5","ranks","will","be","output",".","The","`","equiv_len","`","determines","what","orders","are","considered","equivalent","for","probability","computation",".","In","this","example",",","the","sampler","will","produce","probability","for","the","top","3","items","appearing","in","a","given","order","for","the","`","log_prob","`","call","."]
code: def __init__(
      self,
      shape: float = 1.0,
      topk: Optional[int] = None,
      equiv_len: Optional[int] = None,
      log_scores: bool = False,
  ):
      """FréchetSort is a softer version of descending sort which samples all possible
      orderings of items favoring orderings which resemble descending sort. This can
      be used to convert descending sort by rank score into a differentiable,
      stochastic policy amenable to policy gradient algorithms.
  
      :param shape: parameter of Frechet Distribution. Lower values correspond to
      aggressive deviations from descending sort.
      :param topk: If specified, only the first topk actions are specified.
      :param equiv_len: Orders are considered equivalent if the top equiv_len match. Used
          in probability computations.
          Essentially specifies the action space.
      :param log_scores Scores passed in are already log-transformed. In this case, we would
      simply add Gumbel noise.
      For LearnVM, we set this to be True because we expect input and output scores
      to be in the log space.
  
      Example:
  
      Consider the sampler:
  
      sampler = FrechetSort(shape=3, topk=5, equiv_len=3)
  
      Given a set of scores, this sampler will produce indices of items roughly
      resembling a argsort by scores in descending order. The higher the shape,
      the more it would resemble a descending argsort. `topk=5` means only the top
      5 ranks will be output. The `equiv_len` determines what orders are considered
      equivalent for probability computation. In this example, the sampler will
      produce probability for the top 3 items appearing in a given order for the
      `log_prob` call.
      """
      self.shape = shape
      self.topk = topk
      self.upto = equiv_len
      if topk is not None:
          if equiv_len is None:
              self.upto = topk
          # pyre-fixme[58]: `>` is not supported for operand types `Optional[int]`
          #  and `Optional[int]`.
          if self.upto > self.topk:
              raise ValueError(
                  f"Equiv length {equiv_len} cannot exceed topk={topk}."
              )
      self.gumbel_noise = Gumbel(0, 1.0 / shape)
      self.log_scores = log_scores
  
file_path: ReAgent/reagent/samplers/frechet.py
imports: import logging
  import math
  from typing import Optional
  import reagent.core.types
  import torch
  import torch.nn.functional
  from reagent.core.configuration import resolve_defaults
  from reagent.gym.types import Sampler
  from torch.distributions import Gumbel
label_desc: Use image node_id 1 to create a new FrechetSort object from inherited base classes: Sampler with example: obj = FrechetSort(shape, topk, equiv_len, log_scores)