Second-moment decay rate like Adam, subsuming the correction factor.

  Args:
    beta2: a float between 0 and 1
  Returns:
    a scalar
489988
def adafactor_decay_rate_adam(beta2):
  
  t = tf.cast(tf.train.get_or_create_global_step(), tf.float32) + 1.0
  decay = beta2 * (1.0 - tf.pow(beta2, t - 1.0)) / (1.0 - tf.pow(beta2, t))
  return decay
1316581
def reg_incomplete_beta(a, b, x):
  

  if (x == 0):
    return 0
  elif (x == 1):
    return 1
  else:
    lbeta = (math.lgamma(a + b) - math.lgamma(a) - math.lgamma(b) +
             a * math.log(x) + b * math.log(1 - x))
    if (x < (a + 1) / (a + b + 2)):
      return math.exp(lbeta) * __contfractbeta(a, b, x) / a
    else:
      return 1 - math.exp(lbeta) * __contfractbeta(b, a, 1 - x) / b
1192468
def eval_objfn(self):
        

        if self.opt['fEvalX']:
            rnn = np.sum(self.ss)
        else:
            rnn = sp.norm_nuclear(self.obfn_fvar())
        rl1 = np.sum(np.abs(self.obfn_gvar()))
        cns = np.linalg.norm(self.X + self.Y - self.S)
        obj = rnn + self.lmbda*rl1
        return (obj, rnn, rl1, cns)
126757
def adafactor_optimizer_from_hparams(hparams, lr):
  
  if hparams.optimizer_adafactor_decay_type == "Adam":
    decay_rate = adafactor_decay_rate_adam(
        hparams.optimizer_adafactor_beta2)
  elif hparams.optimizer_adafactor_decay_type == "pow":
    decay_rate = adafactor_decay_rate_pow(
        hparams.optimizer_adafactor_memory_exponent)
  else:
    raise ValueError("unknown optimizer_adafactor_decay_type")
  return AdafactorOptimizer(
      multiply_by_parameter_scale=(
          hparams.optimizer_adafactor_multiply_by_parameter_scale),
      learning_rate=lr,
      decay_rate=decay_rate,
      beta1=hparams.optimizer_adafactor_beta1,
      clipping_threshold=hparams.optimizer_adafactor_clipping_threshold,
      factored=hparams.optimizer_adafactor_factored)
1149865
def smooth_l1_loss(input, target, beta=1. / 9, size_average=True):
    
    n = torch.abs(input - target)
    cond = n < beta
    loss = torch.where(cond, 0.5 * n ** 2 / beta, n - 0.5 * beta)
    if size_average:
        return loss.mean()
    return loss.sum()
857973
def normalized(beta, beta_list):
    
    if len(beta_list) <= 2:
        # beta_list元素小于等于2时，根据jiaccard相似度公式进行判定
        return 1
    try:
        result = (beta - min(beta_list)) / (max(beta_list) - min(beta_list))
    except ZeroDivisionError:
        result = 1
    return result
784751
def beta_r(self, r, kwargs):
        
        if self._type == 'const':
            return self.const_beta(kwargs)
        elif self._type == 'OsipkovMerritt':
            return self.ospikov_meritt(r, kwargs)
        elif self._type == 'Colin':
            return self.colin(r, kwargs)
        elif self._type == 'isotropic':
            return self.isotropic()
        elif self._type == 'radial':
            return self.radial()
        else:
            raise ValueError('anisotropy type %s not supported!' % self._type)
552652
def MarginalBeta(self, i):
        
        alpha0 = self.params.sum()
        alpha = self.params[i]
        return Beta(alpha, alpha0 - alpha)
581273
def beta_schedule(schedule, global_step, final_beta, decay_start, decay_end):
  """"""
  if decay_start > decay_end:
    raise ValueError("decay_end is smaller than decay_end.")

  # Since some of the TF schedules do not support incrementing a value,
  # in all of the schedules, we anneal the beta from final_beta to zero
  # and then reverse it at the bottom.
  if schedule == "constant":
    decayed_value = 0.0
  elif schedule == "linear":
    decayed_value = tf.train.polynomial_decay(
        learning_rate=final_beta,
        global_step=global_step - decay_start,
        decay_steps=decay_end - decay_start,
        end_learning_rate=0.0)
  elif schedule == "noisy_linear_cosine_decay":
    decayed_value = tf.train.noisy_linear_cosine_decay(
        learning_rate=final_beta,
        global_step=global_step - decay_start,
        decay_steps=decay_end - decay_start)
  # TODO(mechcoder): Add log_annealing schedule.
  else:
    raise ValueError("Unknown beta schedule.")

  increased_value = final_beta - decayed_value
  increased_value = tf.maximum(0.0, increased_value)

  beta = tf.case(
      pred_fn_pairs={
          tf.less(global_step, decay_start): lambda: 0.0,
          tf.greater(global_step, decay_end): lambda: final_beta},
      default=lambda: increased_value)
  return beta
323191
def beta(self):
        '''
        
'''
        t = self.X.transpose()
        XX = dot(t,self.X)
        XY = dot(t,self.y)
        return linalg.solve(XX,XY)
459173
def _get_a2(bbar, dbar, slip_moment, mmax):
        
        return ((dbar - bbar) / bbar) * (slip_moment / _scale_moment(mmax))
1104536
protected static double rawQuantile(double p, double alpha, double beta, final double logbeta) {
    // Initial estimate for x
    double x;
    {
      // Very fast approximation of y.
      double tmp = FastMath.sqrt(-2 * FastMath.log(p));
      double y = tmp - (2.30753 + 0.27061 * tmp) / (1. + (0.99229 + 0.04481 * tmp) * tmp);

      if(alpha > 1 && beta > 1) {
        double r = (y * y - 3.) / 6.;
        double s = 1. / (alpha + alpha - 1.);
        double t = 1. / (beta + beta - 1.);
        double h = 2. / (s + t);
        double w = y * FastMath.sqrt(h + r) / h - (t - s) * (r + 5. / 6. - 2. / (3. * h));
        x = alpha / (alpha + beta * FastMath.exp(w + w));
      }
      else {
        double r = beta + beta;
        double t = 1. / (9. * beta);
        final double a = 1. - t + y * FastMath.sqrt(t);
        t = r * a * a * a;
        if(t <= 0.) {
          x = 1. - FastMath.exp((FastMath.log1p(-p) + FastMath.log(beta) + logbeta) / beta);
        }
        else {
          t = (4. * alpha + r - 2.) / t;
          if(t <= 1.) {
            x = FastMath.exp((FastMath.log(p * alpha) + logbeta) / alpha);
          }
          else {
            x = 1. - 2. / (t + 1.);
          }
        }
      }
      // Degenerate initial approximations
      if(x < 3e-308 || x > 1 - 2.22e-16) {
        x = 0.5;
      }
    }

    // Newon-Raphson method using the CDF
    {
      final double ialpha = 1 - alpha;
      final double ibeta = 1 - beta;

      // Desired accuracy, as from GNU R adoption of AS 109
      final double acu = Math.max(1e-300, FastMath.pow(10., -13 - 2.5 / (alpha * alpha) - .5 / (p * p)));
      double prevstep = 0., y = 0., stepsize = 1;

      for(int outer = 0; outer < 1000; outer++) {
        // Current CDF value
        double ynew = cdf(x, alpha, beta);
        if(Double.isInfinite(ynew)) { // Degenerated.
          return Double.NaN;
        }
        // Error gradient
        ynew = (ynew - p) * FastMath.exp(logbeta + ialpha * FastMath.log(x) + ibeta * FastMath.log1p(-x));
        if(ynew * y <= 0.) {
          prevstep = Math.max(Math.abs(stepsize), 3e-308);
        }
        // Inner loop: try different step sizes: y * 3^-i
        double g = 1, xnew = 0.;
        for(int inner = 0; inner < 1000; inner++) {
          stepsize = g * ynew;
          if(Math.abs(stepsize) < prevstep) {
            xnew = x - stepsize; // Candidate x
            if(xnew >= 0. && xnew <= 1.) {
              // Close enough
              if(prevstep <= acu || Math.abs(ynew) <= acu) {
                return x;
              }
              if(xnew != 0. && xnew != 1.) {
                break;
              }
            }
          }
          g /= 3.;
        }
        // Convergence
        if(Math.abs(xnew - x) < 1e-15 * x) {
          return x;
        }
        // Iterate with new values
        x = xnew;
        y = ynew;
      }
    }
    // Not converged in Newton-Raphson
    throw new ArithmeticException("Beta quantile computation did not converge.");
  }
917708
def beta(self, val:float)->None:
        ""
        if val is None: return
        if 'betas' in self.opt_keys:    self.set_val('betas', (self._mom, listify(val, self._beta)))
        elif 'alpha' in self.opt_keys:  self.set_val('alpha', listify(val, self._beta))
        self._beta = listify(val, self._beta)
1021872
def afx_adam():
  """"""
  hparams = transformer.transformer_base_v2()
  hparams.optimizer_adam_beta1 = 0.9
  hparams.optimizer_adam_beta2 = 0.999
  hparams.symbol_modality_num_shards = 1
  hparams.batch_size = 2048
  hparams.optimizer = "adam"
  hparams.learning_rate_schedule = (
      "constant*rsqrt_decay*linear_warmup*rsqrt_hidden_size")
  hparams.learning_rate_constant = 2.0
  return hparams
282080
def _compute_delta_beta(self, df, events, start, stop, weights):
        

        score_residuals = self._compute_residuals(df, events, start, stop, weights) * weights[:, None]

        naive_var = inv(self._hessian_)
        delta_betas = -score_residuals.dot(naive_var) / self._norm_std.values

        return delta_betas
360673
def betacf(a, b, x):
    
    ITMAX = 200
    EPS = 3.0e-7

    bm = az = am = 1.0
    qab = a + b
    qap = a + 1.0
    qam = a - 1.0
    bz = 1.0 - qab * x / qap
    for i in range(ITMAX + 1):
        em = float(i + 1)
        tem = em + em
        d = em * (b - em) * x / ((qam + tem) * (a + tem))
        ap = az + d * am
        bp = bz + d * bm
        d = -(a + em) * (qab + em) * x / ((qap + tem) * (a + tem))
        app = ap + d * az
        bpp = bp + d * bz
        aold = az
        am = ap / bpp
        bm = bp / bpp
        az = app / bpp
        bz = 1.0
        if (abs(az - aold) < (EPS * abs(az))):
            return az
    print('a or b too big, or ITMAX too small in Betacf.')
815514
def adam(grad, x, callback=None, num_iters=100,
         step_size=0.001, b1=0.9, b2=0.999, eps=10**-8):
    """"""
    m = np.zeros(len(x))
    v = np.zeros(len(x))
    for i in range(num_iters):
        g = grad(x, i)
        if callback: callback(x, i, g)
        m = (1 - b1) * g      + b1 * m  # First  moment estimate.
        v = (1 - b2) * (g**2) + b2 * v  # Second moment estimate.
        mhat = m / (1 - b1**(i + 1))    # Bias correction.
        vhat = v / (1 - b2**(i + 1))
        x = x - step_size*mhat/(np.sqrt(vhat) + eps)
    return x