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

com.github.TKnudsen.ComplexDataObject.data.features.numericalData.NumericalFeatureVector 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.

There is a newer version: 0.2.13
Show newest version
package com.github.TKnudsen.ComplexDataObject.data.features.numericalData;

import java.util.ArrayList;
import java.util.List;
import java.util.SortedMap;

import com.github.TKnudsen.ComplexDataObject.data.features.AbstractFeatureVector;
import com.github.TKnudsen.ComplexDataObject.data.features.FeatureType;

import de.javagl.nd.tuples.d.DoubleTuple;

/**
 * 

* Title: NumericalFeatureVector *

* *

* Description: Numerical representation of a high-dimensional object. Can be * used for algorithmic models applied in data mining, machine learning, * information retrieval, etc. *

* *

* Copyright: Copyright (c) 2015-2017 *

* * @author Juergen Bernard * @version 1.02 */ public class NumericalFeatureVector extends AbstractFeatureVector implements DoubleTuple { public NumericalFeatureVector(List features) { super(features); } public NumericalFeatureVector(NumericalFeature[] features) { super(features); } public NumericalFeatureVector(SortedMap featuresMap) { super(featuresMap); } @Override public NumericalFeatureVector subTuple(int fromIndex, int toIndex) { return new NumericalFeatureVector(featuresList.subList(fromIndex, toIndex)); } @Override public int getSize() { return sizeOfFeatures(); } @Override public double get(int arg0) { return getFeature(arg0).doubleValue(); } /** * Conversion to primitive double format. Algorithms require the * (traditional) version of double vectors. * * @return */ public double[] getVector() { return toPrimitive(featuresList); } public void setVector(double vector[]) { featuresList = new ArrayList<>(); featuresMap = null; if (vector != null) for (int i = 0; i < vector.length; i++) featuresList.add(new NumericalFeature("Dim " + i + 1, vector[i])); } public double[] getVectorClone() { return this.getVector().clone(); } @Override public NumericalFeatureVector clone() { List features = new ArrayList<>(); for (NumericalFeature f : featuresList) features.add(f.clone()); NumericalFeatureVector clone = new NumericalFeatureVector(features); // attributes and meta information clone.setMaster(getMaster()); for (String s : attributes.keySet()) clone.add(s, getAttribute(s)); return clone; } private static double[] toPrimitive(List features) { if (features == null) return null; else if (features.size() == 0) return new double[0]; final double[] result = new double[features.size()]; for (int i = 0; i < features.size(); i++) if (features.get(i) instanceof NumericalFeature) result[i] = ((NumericalFeature) features.get(i)).doubleValue(); else if (features.get(i).getFeatureType().equals(FeatureType.DOUBLE)) result[i] = ((Double) features.get(i).getFeatureValue()).doubleValue(); return result; } @Override public void addFeature(String featureName, Double value, FeatureType type) { addFeature(new NumericalFeature(featureName, value)); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy