package data;

import com.google.common.primitives.Ints;
import data.core.Label;
import data.core.AMatrix;
import gnu.trove.list.TIntList;
import gnu.trove.list.array.TIntArrayList;
import gnu.trove.set.TIntSet;
import gnu.trove.set.hash.TIntHashSet;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
 * Created by hanxuan on 9/17/15.
 */

public class DataSet {

    private AMatrix featureMatrix = null;

    private Label labels = null;

    public DataSet(AMatrix m, Label l) {

        this.featureMatrix = m;
        this.labels = l;
    }

    public DataSet subDataSetByRow(int[] rowIndexes) {
        AMatrix subMatrix = featureMatrix.subMatrixByRow(rowIndexes);
        Label subLabels = labels.subLableByRow(rowIndexes);
        return new DataSet(subMatrix, subLabels);
    }

    public void shiftCompressNorm(float[] min, float[] max) {
        featureMatrix.shiftCompressNormalize(min, max);
    }

    public void shiftCompressNorm() {
        featureMatrix.shiftCompressNormalize();
    }

    public void meanVarianceNorm(float[] mean, float[] sd) {
        featureMatrix.meanVarianceNormalize(mean, sd);
    }

    public void meanVarianceNorm() {
        featureMatrix.meanVarianceNormalize();
    }

    public double getEntry(int i, int j){

        return featureMatrix.getEntry(i, j);
    }

    public double[] getInstance(int i) {

        return featureMatrix.getRow(i);
    }

    public double getLabel(int i) {

        return labels.getRow(i);
    }

    public AMatrix getFeatureMatrix() {

        return featureMatrix;
    }

    public int getInstanceLength() {

        return featureMatrix.getInstanceLength();
    }

    public int getFeatureLength() {

        return featureMatrix.getFeatureLength();
    }

    public Label getLabels() {

        return labels;
    }

    public float[] getMeanOrMin() {
        return featureMatrix.getMeanOrMin();
    }

    public float[] getSdOrMax() {
        return featureMatrix.getSdOrMax();
    }

}

@@ -12,50 +12,8 @@
 a;%0A%0A
-import com.google.common.primitives.Ints;%0A
 impo
@@ -84,333 +84,53 @@
 ist.
-TIntList;%0Aimport gnu.trove.list.array.TIntArrayList;%0Aimport gnu.trove.set.TIntSet;%0Aimport gnu.trove.set.hash.TIntHashSet;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Arrays;%0Aimport java.util.List;%0Aimport java.util.Random;%0Aimport java.util.stream.Collectors;%0Aimport java.util.stream.IntStream;%0Aimport java.util.stream.Stream
+array.TDoubleArrayList;%0A%0Aimport java.util.Set
 ;%0A%0A/
@@ -542,18 +542,18 @@
 s.subLab
-l
 e
+l
 ByRow(ro
@@ -1257,58 +1257,686 @@
 uble
- getLabel(int i) %7B%0A%0A        return labels.getRow(i
+%5B%5D getFeatureCol(int featureIndex) %7B%0A        return featureMatrix.getCol(featureIndex);%0A    %7D%0A%0A    public double%5B%5D getFeatureColFilteredByLabel(int col, Set%3CInteger%3E ls) %7B%0A%0A        TDoubleArrayList filterFeature = new TDoubleArrayList(getInstanceLength());%0A        double%5B%5D feature = featureMatrix.getCol(col);%0A        for (int i = 0; i %3C feature.length; i++) %7B%0A            if (ls.contains((int) getLabel(i))) filterFeature.add(feature%5Bi%5D);%0A        %7D%0A        return filterFeature.toArray();%0A    %7D%0A%0A    public double getLabel(int i) %7B%0A%0A        return labels.getRow(i);%0A    %7D%0A%0A    public double getCategoryProportion(int category) %7B%0A        return labels.getLabelQuotient(category
 );%0A 

add get col filtered by category logic