Contribution to denominator for GBM's leaf node prediction
@param w weight
@param y response
@param z residual
@param f predicted value (including offset)
@return weighted contribution to denominator
486990
public double gammaDenom(double w, double y, double z, double f) {
    switch (distribution) {
      case gaussian:
      case gamma:
        return w;
      case bernoulli:
      case quasibinomial:
        double ff = y-z;
        return w * ff*(1-ff);
      case multinomial:
        double absz = Math.abs(z);
        return w * (absz*(1-absz));
      case poisson:
        return w * (y-z); //y-z == exp(f)
      case tweedie:
        return w * exp(f*(2- tweediePower));
      case modified_huber:
        double yf = (2*y-1)*f;
        if (yf < -1) return -w*4*yf;
        else if (yf > 1) return 0;
        else return w*(1-yf)*(1-yf);
      default:
        throw H2O.unimpl();
    }
  }
464326
public double regress(DataPoint dp)
    {
        TreeNodeVisitor node = this;
        while(!node.isLeaf())
        {
            int path = node.getPath(dp);
            if(path < 0 )//missing value case
            {
                double sum = 0;
                double resultSum = 0;
                for(int child = 0; child < childrenCount(); child++)
                {
                    if(node.isPathDisabled(child))
                        continue;
                    double child_result = node.getChild(child).regress(dp);
                    sum += node.getPathWeight(child);
                    resultSum += node.getPathWeight(child)*child_result;
                }
                
                if(sum == 0)//all paths disabled?
                    break;//break out and do local classify
                if(sum < 1.0-1e-5)//re-normalize our result
                    resultSum /= (sum+1e-6);
                
                return resultSum;
            }
            if(node.isPathDisabled(path))//if missing value makes path < 0, return local regression dec
                break;
            node = node.getChild(path);
        }
        return node.localRegress(dp);
    }
29582
public static double weightedMovingAverage(FlatDataList flatDataList, int N) {
        double WMA=0;

        double denominator=0.0;
        int counter=0;
        for(int i=flatDataList.size()-1;i>=0;--i) {
            double Yti = flatDataList.getDouble(i);
            
            if(counter>=N) {
                break;
            }

            double weight=(N-counter);
            WMA+=weight*Yti; //possible numeric overflow 

            denominator+=weight;
            ++counter;
        }

        WMA/=denominator;

        return WMA;
    }
287447
static double weightedAverage(double x1, double w1, double x2, double w2) {
        if (x1 <= x2) {
            return weightedAverageSorted(x1, w1, x2, w2);
        } else {
            return weightedAverageSorted(x2, w2, x1, w1);
        }
    }
1363853
public Vector4d set(Vector2dc v, double z, double w) {
        return set(v.x(), v.y(), z, w);
    }
104439
def FZStaeckel(u,v,pot,delta): #pragma: no cover because unused
    
    R,z= bovy_coords.uv_to_Rz(u,v,delta=delta)
    return _evaluatezforces(pot,R,z)
1286134
public void setWeight(int s, int t, double w) {
        DiEdge e = edge(s, t);
        assertEdge(e);
        weights.put(e, w);
    }
1216767
public float rSum(float[] y, float[] w) {
    float tmp1 = (float) 0.0, tmp2 = (float) 0.0;
    for (int i = 0; i < y.length; i++) {
      tmp1 += y[i] * w[i];
      tmp2 += w[i];
    }

    return correctTo01(tmp1 / tmp2);
  }
751879
public static Weighted<Arborescence<Node>> getMaxArborescence(WeightedGraph graph, Node root) {
        // remove all edges incoming to `root`. resulting arborescence is then forced to be rooted at `root`.
        return getMaxArborescence(graph.filterEdges(not(DirectedEdge.hasDestination(root))));
    }
1166228
public Vector4f set(Vector3ic v, float w) {
        return set(v.x(), v.y(), v.z(), w);
    }
615958
private void computeWeights(Node node) {
    int wsum = 0;
    for(Node child : node.children) {
      computeWeights(child);
      wsum += child.weight;
    }
    node.weight = Math.max(1, wsum);
  }
870155
def weighted_median(y, w):
    
    items = sorted(zip(y, w))
    midpoint = sum(w) / 2

    yvals = []
    wsum = 0

    for yy, ww in items:
        wsum += ww
        if wsum > midpoint:
            yvals.append(yy)
            break
        elif wsum == midpoint:
            yvals.append(yy)
    else:
        yvals = y

    return sum(yvals) / len(yvals)
337589
public Vector4d sub(double x, double y, double z, double w, Vector4d dest) {
        dest.x = this.x - x;
        dest.y = this.y - y;
        dest.z = this.z - z;
        dest.w = this.w - w;
        return dest;
    }
289527
public void calcExpectation(double[] expected, double Z, int size)
    {
        double c = Math.exp(lnode.alpha + cost + rnode.beta - Z);
        for (int i = 0; fvector.get(i) != -1; i++)
        {
            int idx = fvector.get(i) + lnode.y * size + rnode.y;
            expected[idx] += c;
        }
    }
771145
@Override protected double score1( Chunk chks[], double weight, double offset, double fs[/*nclass*/], int row ) {
    double sum = 0;
    if (_nclass > 2 || (_nclass == 2 && !_model.binomialOpt())) {
      for (int k = 0; k < _nclass; k++)
        sum += (fs[k+1] = weight * chk_tree(chks, k).atd(row) / chk_oobt(chks).atd(row));
    }
    else if (_nclass==2 && _model.binomialOpt()) {
      fs[1] = weight * chk_tree(chks, 0).atd(row) / chk_oobt(chks).atd(row);
      if (fs[1]>1 && fs[1]<=ONEBOUND)
        fs[1] = 1.0;
      else if (fs[1]<0 && fs[1]>=ZEROBOUND)
        fs[1] = 0.0;
      assert(fs[1] >= 0 && fs[1] <= 1);
      fs[2] = 1. - fs[1];
    }
    else { //regression
      // average per trees voted for this row (only trees which have row in "out-of-bag"
      sum += (fs[0] = weight * chk_tree(chks, 0).atd(row) / chk_oobt(chks).atd(row) );
      fs[1] = 0;
    }
    return sum;
  }


}
75523
def mcc(y, z):
    
    tp, tn, fp, fn = contingency_table(y, z)
    return (tp * tn - fp * fn) / K.sqrt((tp + fp) * (tp + fn) * (tn + fp) * (tn + fn))
33037
public Vector3f reflect(float x, float y, float z) {
        return reflect(x, y, z, thisOrNew());
    }