All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.TKnudsen.ComplexDataObject.data.features.numericalData.NumericalFeatureVectorTools Maven / Gradle / Ivy

Go to download

A library that models real-world objects in Java, referred to as ComplexDataObjects. Other features: IO and preprocessing of ComplexDataObjects.

The newest version!
package com.github.TKnudsen.ComplexDataObject.data.features.numericalData;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * 

* Copyright: Copyright (c) 2016-2018 *

* * @author Juergen Bernard * @deprecated use NumericalFeatureVectors * @version 1.02 */ public class NumericalFeatureVectorTools { /** * retrieves the minimum value. * * @param featureVector * @deprecated use NumericalFeatureVectors * @return */ public static Double getMin(NumericalFeatureVector featureVector) { if (featureVector == null) return Double.NaN; Double d = Double.MAX_VALUE - 1; for (NumericalFeature feature : featureVector.getVectorRepresentation()) d = Math.min(d, feature.doubleValue()); return d; } /** * retrieves the maximum value. * * @param featureVector * @deprecated use NumericalFeatureVectors * @return */ public static Double getMax(NumericalFeatureVector featureVector) { if (featureVector == null) return Double.NaN; Double d = Double.MIN_VALUE + 1; for (NumericalFeature feature : featureVector.getVectorRepresentation()) d = Math.max(d, feature.doubleValue()); return d; } /** * calculates the min value for a dimension * * @param features * @param dim * @deprecated use NumericalFeatureVectors * @return */ public static double getMin(List features, int dim) { if (features == null || features.size() == 0) throw new IllegalArgumentException(); double min = Double.MAX_VALUE - 1; for (int n = 0; n < features.size(); n++) { if (!Double.isNaN(features.get(n).get(dim))) { min = Math.min(min, features.get(n).get(dim)); } } return min; } /** * calculates the max value for a dimension * * @param features * @param dim * @deprecated use NumericalFeatureVectors * @return */ public static double getMax(List features, int dim) { if (features == null || features.size() == 0) throw new IllegalArgumentException(); double max = Double.MIN_VALUE + 1; for (int n = 0; n < features.size(); n++) { if (!Double.isNaN(features.get(n).get(dim))) { max = Math.max(max, features.get(n).get(dim)); } } return max; } /** * calculates the mean value * * @param features * @param dim * @deprecated use NumericalFeatureVectors * @return */ public static double getMean(List features, int dim) { double sum = 0; double count = 0; for (int n = 0; n < features.size(); n++) { if (!Double.isNaN(features.get(n).get(dim))) { sum += features.get(n).get(dim); count += 1; } } return sum / count; } /** * * @param featureVectors * @deprecated use NumericalFeatureVectors * @return */ public static List toPrimitives(Set featureVectors) { List returnValues = new ArrayList<>(); for (NumericalFeatureVector fv : featureVectors) returnValues.add(fv.getVectorClone()); return returnValues; } /** * * @param featureVectors * @deprecated use NumericalFeatureVectors * @return */ public static List toPrimitives(List featureVectors) { List returnValues = new ArrayList<>(); for (int i = 0; i < featureVectors.size(); i++) returnValues.add(featureVectors.get(i).getVectorClone()); return returnValues; } /** * * @param featureVectors * @param labels * @param classAttribute * @deprecated use NumericalFeatureVectors */ public static void addClassAttribute(List featureVectors, List labels, String classAttribute) { for (int i = 0; i < featureVectors.size(); i++) featureVectors.get(i).add(classAttribute, labels.get(i)); } public static void addNumericAttribute(List features, List labels, String attributeName) { for (int i = 0; i < features.size(); i++) features.get(i).add(attributeName, labels.get(i)); } /** * creates a matrix-like representation with the number of feature vectors in * the first dimension and the dimensionality of the feature vectors in the * second dimension. * * @param fvs * @deprecated use NumericalFeatureVectors * @return */ public static double[][] createMatrixRepresentation(List fvs) { if (fvs == null) throw new NullPointerException("NumericalFeatureVectorTools: feature vectors must not be null"); if (fvs.size() == 0) throw new IllegalArgumentException("NumericalFeatureVectorTools: feature vectors size was 0"); double[][] values = new double[fvs.size()][fvs.get(0).getDimensions()]; for (int i = 0; i < fvs.size(); i++) values[i] = fvs.get(i).getVectorClone(); return values; } /** * creates a vector with the information of one feature from the FeatureVectors, * addressed by the index. * * @param fvs * @param index * @deprecated use NumericalFeatureVectors * @return */ public static double[] retrieveVariable(List fvs, int index) { if (fvs == null) throw new NullPointerException("NumericalFeatureVectorTools: feature vectors must not be null"); if (fvs.size() == 0) throw new IllegalArgumentException("NumericalFeatureVectorTools: feature vectors size was 0"); double[] values = new double[fvs.size()]; for (int i = 0; i < fvs.size(); i++) values[i] = fvs.get(i).get(index); return values; } /** * * @param fvs * @param classAttribute * @deprecated use NumericalFeatureVectors * @return */ public static double[] retrieveNumericalAttribute(List fvs, String classAttribute) { if (fvs == null) throw new NullPointerException("LDA: feature vectors must not be null"); if (fvs.size() == 0) throw new IllegalArgumentException("LDA: feature vectors size was 0"); double[] values = new double[fvs.size()]; for (int i = 0; i < fvs.size(); i++) { if (fvs.get(i).getAttribute(classAttribute) != null) if (fvs.get(i).getAttribute(classAttribute) instanceof Number) { values[i] = ((Number) fvs.get(i).getAttribute(classAttribute)).doubleValue(); continue; } values[i] = Double.NaN; } return values; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy