Data.java [src/java/utils] Revision: default Date:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package utils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
*
* @author sidereus
*/
public class Data {
String[] names;
Boolean[] norm;
double[] norm_min;
double[] norm_max;
String[] types;
Map<Integer, double[]> dataPerRow;
List<List<Double>> dataPerCol;
List<Integer> outIndices;
double[] outMin;
double[] outMax;
double[] min;
double[] max;
Integer[] outMinIndices;
Integer[] outMaxIndices;
int datalength = 0;
Data(String[] names, Boolean[] norm, double[] norm_min, double[] norm_max, String[] types) {
this.names = names;
this.norm = norm;
this.norm_min = norm_min;
this.norm_max = norm_max;
this.types = types;
dataPerRow = new HashMap();
dataPerCol = new ArrayList();
outIndices = new ArrayList();
checkOutIndices();
}
private void checkOutIndices() {
int index = 0;
for (String type : types) {
if (type.contains(MongoAccess.OUT)) {
outIndices.add(index);
index++;
}
}
outMin = new double[outIndices.size()];
outMax = new double[outIndices.size()];
outMinIndices = new Integer[outIndices.size()];
outMaxIndices = new Integer[outIndices.size()];
Arrays.fill(outMin, Double.MAX_VALUE);
Arrays.fill(outMax, Double.MIN_VALUE);
}
private void checkOutMinMax(int rowIndex, double[] row) {
int mmindex = 0;
for (int outColumn : outIndices) {
double val = row[outColumn];
if (val > outMax[mmindex]) {
outMax[mmindex] = val;
outMaxIndices[mmindex] = rowIndex;
} else if (val < outMin[mmindex]) {
outMin[mmindex] = val;
outMinIndices[mmindex] = rowIndex;
}
mmindex++;
}
for(int col = 0; col < row.length; col++) {
double val = row[col];
if (val > max[col]) {
max[col] = val;
} else if (val < min[col]) {
min[col] = val;
}
}
}
public void put(int index, double[] row) {
if (!dataPerRow.containsKey(index)) {
dataPerRow.put(index, row);
addDataPerCol(row);
datalength++;
checkOutMinMax(index, row);
} else {
String msg = "Index " + index + " already in hashmap";
throw new IllegalArgumentException(msg);
}
}
private void addDataPerCol(double[] row) {
if (dataPerCol.isEmpty()) {
min = new double[row.length];
max = new double[row.length];
for (int col = 0; col < row.length; col++) {
dataPerCol.add(new ArrayList<>());
min[col] = Double.MAX_VALUE;
max[col] = Double.MIN_VALUE;
}
}
for (int col = 0; col < row.length; col++) {
double val = row[col];
dataPerCol.get(col).add(val);
}
}
public Integer[] getMinIndices() {
return outMinIndices;
}
public Integer[] getMaxIndices() {
return outMaxIndices;
}
public int getDatalength() {
return datalength;
}
public List<List<Double>> getDataPerCol() {
return dataPerCol;
}
public double[] getDataPerRow(int rowIndex) {
return dataPerRow.get(rowIndex);
}
public String getName(int colIndex) {
return names[colIndex];
}
public boolean getNorm(int colIndex) {
return norm[colIndex];
}
public double getNormMin(int colIndex) {
return norm_min[colIndex];
}
public double getNormMax(int colIndex) {
return norm_max[colIndex];
}
public String getType(int colIndex) {
return types[colIndex];
}
public double getMin(int colIndex) {
return min[colIndex];
}
public double getMax(int colIndex) {
return max[colIndex];
}
}