Compute the sample L-Moments using probability weighted moments.

@param sorted <b>Presorted</b> data array.
@param adapter Array adapter.
@param nmom Number of moments to compute
@return Array containing Lambda1, Lambda2, Tau3 ... TauN
160981
public static <A> double[] samLMR(A sorted, NumberArrayAdapter<?, A> adapter, int nmom) {
    final int n = adapter.size(sorted);
    final double[] sum = new double[nmom];
    nmom = n < nmom ? n : nmom;
    // Estimate probability weighted moments (unbiased)
    for(int i = 0; i < n; i++) {
      double term = adapter.getDouble(sorted, i);
      // Robustness: skip bad values
      if(Double.isInfinite(term) || Double.isNaN(term)) {
        continue;
      }
      sum[0] += term;
      for(int j = 1, z = i; j < nmom; j++, z--) {
        term *= z;
        sum[j] += term;
      }
    }
    // Normalize by "n choose (j + 1)"
    sum[0] /= n;
    double z = n;
    for(int j = 1; j < nmom; j++) {
      z *= n - j;
      sum[j] /= z;
    }
    normalizeLMR(sum, nmom);
    // Handle case when lambda2 == 0, by setting tau3...tauN = 0:
    if(sum[1] == 0) {
      for(int i = 2; i < nmom; i++) {
        sum[i] = 0.; // tau3...tauN = 0.
      }
      return sum;
    }
    // Map lambda3...lambdaN to tau3...tauN
    for(int i = 2; i < nmom; i++) {
      sum[i] /= sum[1];
    }
    return sum;
  }
1230254
public double getSampleExcessKurtosis() {
    if(!(m2 > 0) || !(n > 3)) {
      throw new ArithmeticException("Kurtosis not defined when variance is 0 or weight <= 3.0!");
    }
    final double nm1 = n - 1.;
    return (nm1 / ((n - 2.) * (n - 3.))) * (n * (n + 1) * m4 / (m2 * m2) - 3 * nm1);
  }
350373
@Override
    public void shuffle(INDArray array, Random rnd, int... dimension) {
        shuffle(Collections.singletonList(array), rnd, dimension);
    }
1259032
public static AssociativeArray normalDistributionGetParams(FlatDataCollection flatDataCollection) {
        AssociativeArray params = new AssociativeArray();
        params.put("mean", Descriptives.mean(flatDataCollection));
        params.put("variance", Descriptives.variance(flatDataCollection, true));
        return params;
    }
637401
def _get_moment_tensor_from_ndk_string(self, ndk_string):
        
        moment_tensor = GCMTMomentTensor('USE')
        tensor_data = _read_moment_tensor_from_ndk_string(ndk_string, 'USE')
        moment_tensor.tensor = tensor_data[0]
        moment_tensor.tensor_sigma = tensor_data[1]
        moment_tensor.exponent = tensor_data[2]
        return moment_tensor
1103252
public int guessOrderFromAngle(double threshold, int maxOrder) {
		double bestDelta = threshold;
		int bestOrder = 1;
		for (int order = 2; order < maxOrder; order++) {
			double delta = Math.abs(2 * Math.PI / order - theta);
			if (delta < bestDelta) {
				bestOrder = order;
				bestDelta = delta;
			}
		}
		return bestOrder;
	}
702441
public ArrayOfDoublesCompactSketch getResult(final WritableMemory dstMem) {
    if (sketch_.getRetainedEntries() > sketch_.getNominalEntries()) {
      theta_ = Math.min(theta_, sketch_.getNewTheta());
    }
    if (dstMem == null) {
      return new HeapArrayOfDoublesCompactSketch(sketch_, theta_);
    }
    return new DirectArrayOfDoublesCompactSketch(sketch_, theta_, dstMem);
  }
444580
public static void sort(DenseMatrix64F matrix, RowComparator comparator)
    {
        int len = matrix.numCols;
        quickSort(matrix.data, 0, matrix.numRows-1, len, comparator, new double[len], new double[len]);
    }
504033
@Override
    public INDArray rand(int[] shape, float min, float max, org.nd4j.linalg.api.rng.Random rng) {
        //ensure shapes that wind up being scalar end up with the write shape
        if (shape.length == 1 && shape[0] == 0) {
            shape = new int[] {1, 1};
        }
        return Nd4j.getDistributions().createUniform(min, max).sample(shape);
    }
1015803
private List<double[]> calculateStdMeasurementsForParam(
            int            numEntriesPerPreview,
            int            numParamValues,
            int            paramValue,
            List<double[]> meanParamMeasurements)
    {
        List<double[]> paramMeasurementsSquaredDiffSum = 
                new ArrayList<double[]>(numEntriesPerPreview);
        List<double[]> paramMeasurementsStd            = 
                new ArrayList<double[]>(numEntriesPerPreview);
        
        int numCompleteFolds = 0;
        
        // sum up squared differences between measurements and mean values
        for (PreviewCollection<Preview> foldPreview : 
             this.origMultiRunPreviews.subPreviews) 
        {
            // check if there is a preview for each parameter value
            if (foldPreview.getPreviews().size() == numParamValues) {
                numCompleteFolds++;
                
                Preview foldParamPreview = 
                        foldPreview.getPreviews().get(paramValue);
                
                // add this Preview's standardDeviations to the overall sum
                this.addPreviewMeasurementSquaredDiffsToSum(
                        meanParamMeasurements, 
                        paramMeasurementsSquaredDiffSum,
                        foldParamPreview, 
                        numEntriesPerPreview);
            }
        }
        
        // divide sum by number of folds and take square root 
        for (int entryIdx = 0; entryIdx < numEntriesPerPreview; entryIdx++) {
            double[] sumEntry = paramMeasurementsSquaredDiffSum.get(entryIdx);
            double[] stdEntry = new double[sumEntry.length];
            
            // first measurement is used for indexing -> simply copy
            stdEntry[0] = sumEntry[0];
            
            // calculate standard deviation for remaining measurements
            for (int m = 1; m < sumEntry.length; m++) {
                if (numCompleteFolds > 1) {
                    stdEntry[m] = Math.sqrt(sumEntry[m]/(numCompleteFolds-1));
                }
                else {
                    stdEntry[m] = Math.sqrt(sumEntry[m]);
                }
            }
            
            paramMeasurementsStd.add(stdEntry);
        }
        
        return paramMeasurementsStd;
    }
216854
public void shuffle(long seed) {
        // just skip shuffle if there's only 1 example
        if (numExamples() < 2)
            return;

        //note here we use the same seed with different random objects guaranteeing same order

        List<INDArray> arrays = new ArrayList<>();
        List<int[]> dimensions = new ArrayList<>();

        arrays.add(getFeatures());
        dimensions.add(ArrayUtil.range(1, getFeatures().rank()));

        arrays.add(getLabels());
        dimensions.add(ArrayUtil.range(1, getLabels().rank()));

        if (featuresMask != null) {
            arrays.add(getFeaturesMaskArray());
            dimensions.add(ArrayUtil.range(1, getFeaturesMaskArray().rank()));
        }

        if (labelsMask != null) {
            arrays.add(getLabelsMaskArray());
            dimensions.add(ArrayUtil.range(1, getLabelsMaskArray().rank()));
        }

        Nd4j.shuffle(arrays, new Random(seed), dimensions);

        //As per CpuNDArrayFactory.shuffle(List<INDArray> arrays, Random rnd, List<int[]> dimensions) and libnd4j transforms.h shuffleKernelGeneric
        if (exampleMetaData != null) {
            int[] map = ArrayUtil.buildInterleavedVector(new Random(seed), numExamples());
            ArrayUtil.shuffleWithMap(exampleMetaData, map);
        }
    }
298128
def _mom(self, k, dist, cache):
        """"""
        return (-1)**numpy.sum(k)*evaluation.evaluate_moment(
            dist, k, cache=cache)
1337206
public static double kurtosisSE(FlatDataCollection flatDataCollection) {
	    int n = count(flatDataCollection);
        if(n<=3) {
            throw new IllegalArgumentException("The provided collection must have more than 3 elements.");
        }
        
        double kurtosisSE = Math.sqrt(24.0/n);
        
        return kurtosisSE;
    }
230537
public static <T> void shuffle(T[] array, Random rnd) {
        //Implementing Fisher-Yates shuffle
        T tmp;
        for (int i = array.length - 1; i > 0; --i) {
            int index = rnd.nextInt(i + 1);
            
            tmp = array[index];
            array[index] = array[i];
            array[i] = tmp;
        }
    }
487954
def _get_moment_from_ndk_string(self, ndk_string, exponent):
        
        moment = float(ndk_string[49:56]) * (10. ** exponent)
        version = ndk_string[:3]
        magnitude = utils.moment_magnitude_scalar(moment)
        return moment, version, magnitude
1017538
private SortedClassProbability[] sortByDescendingClassProbability(String[] domainValues, double[] classProbabilities) {
    assert (classProbabilities.length == domainValues.length);
    SortedClassProbability[] arr = new SortedClassProbability[domainValues.length];
    for (int i = 0; i < domainValues.length; i++) {
      arr[i] = new SortedClassProbability();
      arr[i].name = domainValues[i];
      arr[i].probability = classProbabilities[i];
    }
    Arrays.sort(arr, Collections.reverseOrder());
    return arr;
  }
222110
@SuppressWarnings("WeakerAccess")
    public static void sort(int[] order, double[] values, int start, int n) {
        for (int i = start; i < start + n; i++) {
            order[i] = i;
        }
        quickSort(order, values, start, start + n, 64);
        insertionSort(order, values, start, start + n, 64);
    }