Java Array Equal equalFreqBinning(double[][] sampleData, int numPredVals, int numRespVals, int divInd)

Here you can find the source of equalFreqBinning(double[][] sampleData, int numPredVals, int numRespVals, int divInd)

Description

Performs a simple binning of the response values.

License

Open Source License

Parameter

Parameter Description
sampleData a parameter
numVals a parameter

Declaration

public static void equalFreqBinning(double[][] sampleData, int numPredVals, int numRespVals, int divInd) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Arrays;

public class Main {
    /**/* ww w.j a va 2 s. c  o m*/
     * Performs a simple binning of the response values. It will result in the
     * values becoming integers in the range [0,numVals-1].
     * 
     * @param sampleData
     * @param numVals
     */
    public static void equalFreqBinning(double[][] sampleData, int numPredVals, int numRespVals, int divInd) {
        if (sampleData.length > 0) {
            double[][] inds = new double[sampleData[0].length][Math.max(numPredVals, numRespVals)];
            int num = numPredVals;
            for (int r = 0; r < sampleData[0].length; r++) {
                if (r == divInd) {
                    num = numRespVals;
                }
                double[] singleData = new double[sampleData.length];
                for (int i = 0; i < sampleData.length; i++) {
                    singleData[i] = sampleData[i][r];

                }
                Arrays.sort(singleData);
                for (int i = 0; i < num; i++) {
                    inds[r][i] = singleData[i * singleData.length / num];
                }
            }
            for (double[] sample : sampleData) {
                for (int i = 0; i < divInd; i++) {
                    int val = 1;
                    while (val < numPredVals && inds[i][val] < sample[i]) {
                        val++;
                    }
                    sample[i] = val - 1.0;
                }
                for (int i = divInd; i < sample.length; i++) {
                    int val = 1;
                    while (val < numRespVals && inds[i][val] < sample[i]) {
                        val++;
                    }
                    sample[i] = val - 1.0;
                }

            }
        }
    }
}

Related

  1. equal(boolean[][] a, boolean[][] b)
  2. equal(byte[] a, byte[] b)
  3. equal(float[][] array1, float[][] array2)
  4. equal(int[] a, int[] b)
  5. equalByRows(boolean[][] a, boolean[][] b)
  6. equalIgnoreOrder(final Object[] array1, final Object[] array2)
  7. equalityCheck(byte[] a, byte[] b)
  8. equalMaps(Map expected, Map actual)
  9. equalOrDie(String testName, Object[] a, Object[] b)