package data.core;

import java.util.Arrays;
import java.util.EnumMap;
import java.util.HashSet;
import java.util.stream.IntStream;

/**
 * Created by hanxuan on 9/17/15.
 */
public class Label {

    private float[] vector = null;

    private HashSet<String> categories = null;

    private boolean isCategory = false;

//    public Label (float[] data) {
//
//        this.vector = data;
//    }

    public Label(float[] data, HashSet<String> categories) {

        this.vector = data;
        this.categories = categories;
    }

    public boolean isCategoryLabel() {

        return isCategory;
    }

    public double getRow(int rowNum) {

        return vector[rowNum];
    }

    public float[] getVector() {

        return vector;
    }

    public HashSet<String> getCategories() {
        return categories;
    }

    public Label subLableByRow (int[] subIndexes) {
        float[] suVector = new float[subIndexes.length];
        IntStream.range(0, subIndexes.length).forEach(i -> suVector[i] = vector[subIndexes[i]]);
        return new Label(suVector, this.categories);
    }

    public static void main(String[] args) {

    }
}

@@ -34,66 +34,15 @@
 til.
-Arrays;%0Aimport java.util.EnumMap;%0Aimport java.util.HashSet
+HashMap
 ;%0Aim
@@ -191,38 +191,112 @@
 ate Hash
-Set%3CString%3E categories
+Map%3CInteger, Integer%3E classIndexMap = null;%0A%0A    private HashMap%3CInteger, Integer%3E indexClassMap
  = null;
@@ -289,32 +289,34 @@
 assMap = null;%0A%0A
+//
     private bool
@@ -340,18 +340,16 @@
 false;%0A%0A
-//
     publ
@@ -356,17 +356,16 @@
 ic Label
- 
 (float%5B%5D
@@ -373,17 +373,51 @@
 data
-) %7B%0A//%0A//
+, HashMap%3CInteger, Integer%3E categories) %7B%0A%0A
     
@@ -444,143 +444,496 @@
 ta;%0A
-//
     
-%7D%0A%0A
     
-public Label(float%5B%5D data, HashSet%3CString%3E categories) %7B%0A%0A        this.vector = data;%0A        this.categories = categories
+this.classIndexMap = categories;%0A        if (classIndexMap != null) %7B%0A            indexClassMap = new HashMap%3C%3E();%0A            for (int k : classIndexMap.keySet()) %7B%0A                indexClassMap.put(classIndexMap.get(k), k);%0A            %7D%0A        %7D%0A    %7D%0A%0A    public double getLabelQuotient(int category) %7B%0A%0A        float l = (float) (category * 1.0);%0A        int counter = 0;%0A        for (float e : vector) if (e == l) ++ counter;%0A        return counter / (double) vector.length
 ;%0A  
@@ -929,32 +929,34 @@
 .length;%0A    %7D%0A%0A
+//
     public boole
@@ -974,25 +974,29 @@
 ryLabel() %7B%0A
-%0A
+//%0A//
         retu
@@ -1010,16 +1010,18 @@
 tegory;%0A
+//
     %7D%0A%0A 
@@ -1180,63 +1180,174 @@
 Hash
-Set%3CString%3E getCategories() %7B%0A        return categories
+Map%3CInteger, Integer%3E getClassIndexMap() %7B%0A        return classIndexMap;%0A    %7D%0A%0A    public HashMap%3CInteger, Integer%3E getIndexClassMap() %7B%0A        return indexClassMap
 ;%0A  
@@ -1378,16 +1378,15 @@
 bLab
-l
 e
+l
 ByRow
- 
 (int
@@ -1597,25 +1597,28 @@
 , this.c
-ategories
+lassIndexMap
 );%0A    %7D

add classIndex map and indexClass map