Returns the index for the median, adjusted incase multiple features have the same value.
@param data the dataset to get the median index of
@param pivot the dimension to pivot on, and ensure the median index has a different value on the left side
@return
763075
public int getMedianIndex(final List<Integer> data, int pivot)
    {
        int medianIndex = data.size()/2;
        //What if more than one point have the samve value? Keep incrementing until that dosn't happen
        while(medianIndex < data.size()-1 && allVecs.get(data.get(medianIndex)).get(pivot) == allVecs.get(data.get(medianIndex+1)).get(pivot))
            medianIndex++;
        return medianIndex;
    }
994304
function(datasetIndex) {
		var ringWeightOffset = 0;

		for (var i = 0; i < datasetIndex; ++i) {
			if (this.chart.isDatasetVisible(i)) {
				ringWeightOffset += this._getRingWeight(i);
			}
		}

		return ringWeightOffset;
	}
582111
public double[] toWraparoundOrder(double data[], int i0, int stride) {
    if ((i0==0)&&(stride==2)) return data;
    double newdata[] = new double[2*n];
    for(int i=0; i<n; i++){
      newdata[2*i]   = data[i0+stride*i];
      newdata[2*i+1] = data[i0+stride*i+1]; }
    return newdata; }
121842
@Nonnull
  public int [] getPivot ()
  {
    final int [] p = new int [m_nRows];
    for (int i = 0; i < m_nRows; i++)
      p[i] = m_aPivot[i];
    return p;
  }
1047425
public MultinomialModelPrediction predictMultinomial(RowData data, double offset) throws PredictException {
    double[] preds = preamble(ModelCategory.Multinomial, data, offset);

    MultinomialModelPrediction p = new MultinomialModelPrediction();
    if (enableLeafAssignment) { // only get leaf node assignment if enabled
      SharedTreeMojoModel.LeafNodeAssignments assignments = leafNodeAssignmentExtended(data);
      p.leafNodeAssignments = assignments._paths;
      p.leafNodeAssignmentIds = assignments._nodeIds;
    }
    p.classProbabilities = new double[m.getNumResponseClasses()];
    p.labelIndex = (int) preds[0];
    String[] domainValues = m.getDomainValues(m.getResponseIdx());
    p.label = domainValues[p.labelIndex];
    System.arraycopy(preds, 1, p.classProbabilities, 0, p.classProbabilities.length);
    if (enableStagedProbabilities) {
        double[] rawData = nanArray(m.nfeatures());
        rawData = fillRawData(data, rawData);
        p.stageProbabilities = ((SharedTreeMojoModel) m).scoreStagedPredictions(rawData, preds.length);
    }
    return p;
  }
604232
public SDVariable get(SDIndex... indices) {
        int ndims = indices.length;
        long[] begin = new long[ndims];
        long[] end = new long[ndims];
        long[] strides = new long[ndims];
        int[] begin_mask_arr = new int[ndims];
        int[] end_mask_arr = new int[ndims];
        int[] shrink_axis_mask_arr = new int[ndims];
        for (int i = 0; i < ndims; i++) {
            strides[i] = 1;
            SDIndex index = indices[i];
            SDIndex.IndexType indexType = index.getIndexType();
            if (indexType == SDIndex.IndexType.ALL) {
                begin_mask_arr[i] = 1;
                end_mask_arr[i] = 1;
            } else if (indexType == SDIndex.IndexType.POINT) {
                long pointIndex = index.getPointIndex();
                begin[i] = pointIndex;
                end[i] = pointIndex + 1;
                if(!index.isPointKeepDim()) {
                    shrink_axis_mask_arr[i] = 1;
                }
            } else if (indexType == SDIndex.IndexType.INTERVAL) {
                if (index.getIntervalBegin() == null) {
                    begin_mask_arr[i] = 1;
                } else {
                    begin[i] = index.getIntervalBegin();
                }
                if (index.getIntervalEnd() == null) {
                    end_mask_arr[i] = 1;
                } else {
                    end[i] = index.getIntervalEnd();
                }
                if (index.getIntervalStrides() == null) {
                    strides[i] = 1;
                } else {
                    strides[i] = index.getIntervalStrides();
                }
            }
        }

        // convert binary int[] to int
        int begin_mask = binArrToInt(begin_mask_arr);
        int end_mask = binArrToInt(end_mask_arr);
        int shrink_axis = binArrToInt(shrink_axis_mask_arr);

        return this.sameDiff.stridedSlice(this, begin, end, strides,
                begin_mask, end_mask, 0, 0, shrink_axis);
    }
1359199
public static Matrix calculateCovarianceMatrixOfCenteredData(Matrix data){
		Assume.assume(data.getRowDimension()>1, "Number of data samples is "+
				data.getRowDimension()+", but it has to be >1 to compute "+
				"covariances");
		int dimsNo = data.getColumnDimension();
		int samplesNo = data.getRowDimension();
		Matrix m = new Matrix(dimsNo, dimsNo);
		for(int r = 0; r < dimsNo; r++)
			for(int c = r; c < dimsNo; c++){
				double sum = 0;
				for(int i = 0; i < samplesNo; i++)
					 sum += data.get(i, r)*data.get(i, c);
				m.set(r, c, sum/(samplesNo-1));
			}
		for(int r = 0; r < dimsNo; r++)
			for(int c = 0; c < r; c++) m.set(r, c, m.get(c, r));
		return m;		
	}
}
769971
public java.lang.String getPivotForPredName() {
    java.lang.Object ref = pivotForPredName_;
    if (ref instanceof java.lang.String) {
      return (java.lang.String) ref;
    } else {
      com.google.protobuf.ByteString bs = 
          (com.google.protobuf.ByteString) ref;
      java.lang.String s = bs.toStringUtf8();
      pivotForPredName_ = s;
      return s;
    }
  }
902786
public static double getPvalue(FlatDataCollection flatDataCollection, double median) {
        int n=flatDataCollection.size();
        if(n<=0) {
            throw new IllegalArgumentException("The provided collection can't be empty.");
        }
        
        int Tplus=0;
        Iterator<Double> it = flatDataCollection.iteratorDouble();
        while(it.hasNext()) {
            double v = it.next();
            if(Math.abs(v-median) < 0.0000001) {
                continue; //don't count it at all
            }
            if(v>median) {
                ++Tplus;
            }
        }


        double pvalue= scoreToPvalue(Tplus, n);

        return pvalue;
    }
333802
private Type.Field[] determinePivotFields(Tuple<Type.Field> lhsFields, Tuple<Type.Field> rhsFields,
			LifetimeRelation lifetimes, LinkageStack stack) {
		Type.Field[] pivots = new Type.Field[lhsFields.size()];
		//
		for (int i = 0; i != lhsFields.size(); ++i) {
			Type.Field lhsField = lhsFields.get(i);
			Identifier lhsFieldName = lhsField.getName();
			for (int j = 0; j != rhsFields.size(); ++j) {
				Type.Field rhsField = rhsFields.get(j);
				Identifier rhsFieldName = rhsField.getName();
				if (lhsFieldName.equals(rhsFieldName)) {
					// Matched field, now compute its type.
					Type type = apply(lhsField.getType(), rhsField.getType(), lifetimes, stack);
					// Check whether is a pivot or not
					if (!(type instanceof Type.Void)) {
						// Yes, is a pivot
						pivots[i] = new Type.Field(lhsFieldName, type);
					}
					break;
				}
			}
		}
		return pivots;
	}
367867
public double median(double[] series) {
    double[] clonedSeries = series.clone();
    Arrays.sort(clonedSeries);

    double median;
    if (clonedSeries.length % 2 == 0) {
      median = (clonedSeries[clonedSeries.length / 2]
          + (double) clonedSeries[clonedSeries.length / 2 - 1]) / 2;
    }
    else {
      median = clonedSeries[clonedSeries.length / 2];
    }
    return median;
  }
465968
private static final int bestPivot(int rank, int m1, int m2, int m3, int m4, int m5) {
    if(rank < m1) {
      return m1;
    }
    if(rank > m5) {
      return m5;
    }
    if(rank < m2) {
      return m2;
    }
    if(rank > m4) {
      return m4;
    }
    return m3;
  }
278421
public static <T extends ImageGray<T>> void median(Planar<T> input, T output) {
		median(input, output, 0, input.getNumBands() - 1);
	}
550452
def get_median(data_np):
    """"""
    i = np.isfinite(data_np)
    if not np.any(i):
        return np.nan
    return np.median(data_np[i])
524166
def median(data):
    
    data = sorted(data)
    n = len(data)
    if n == 0:
        raise StatisticsError("no median for empty data")
    if n % 2 == 1:
        return data[n // 2]
    else:
        i = n // 2
        return (data[i - 1] + data[i]) / 2
1156085
def pivot(args={})
      args = {
        column: nil,
        row: nil,
        value: nil,
        fill_value: Float::NAN
      }.merge(args)

      raise ArgumentError unless [:column, :row, :value].all?{|sym| args[sym].is_a?(Symbol)}

      column = self[args[:column]].factors
      index = self[args[:row]].factors

      source = column.reduce({}) do |memo, label|
        arr = []
        df = self.select{|row| row[args[:column]] == label}
        index.each do |i|
          unless df.any?{|row| row[args[:row]] == i}
            arr.push(args[:fill_value])
          else
            column = df.select{|row| row[args[:row]] == i}[args[:value]]
            arr.push(column.to_a[0])
          end
        end
        memo[label] = arr
        memo
      end

      Mikon::DataFrame.new(source, index: index)
    end
397160
public OrdinalModelPrediction predictOrdinal(RowData data, double offset) throws PredictException {
    double[] preds = preamble(ModelCategory.Ordinal, data, offset);

    OrdinalModelPrediction p = new OrdinalModelPrediction();
    p.classProbabilities = new double[m.getNumResponseClasses()];
    p.labelIndex = (int) preds[0];
    String[] domainValues = m.getDomainValues(m.getResponseIdx());
    p.label = domainValues[p.labelIndex];
    System.arraycopy(preds, 1, p.classProbabilities, 0, p.classProbabilities.length);

    return p;
  }