discount_cumsum

    0

    0

    def discount_cumsum(x, discount): return discount_cumsum(x, discount, axis=1)

    import scipy.signal
    
    def discount_cumsum(x, discount):
      """
      magic from rllab for computing discounted cumulative sums of vectors.
    
      input: 
        vector x, 
        [x0, 
          x1, 
          x2]
    
      output:
        [x0 + discount * x1 + discount^2 * x2,  
          x1 + discount * x2,
          x2]
      """
      return scipy.signal.lfilter([1], [1, float(-discount)], x[::-1], axis=0)[::-1]
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.