org.openimaj.feature.SparseFloatFV Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core-feature Show documentation
Show all versions of core-feature Show documentation
Core notion of features, usually denoted as arrays of data.
Definitions of features for all primitive types, features
with location and lists of features (both in memory and on disk).
/*
AUTOMATICALLY GENERATED BY jTemp FROM
/Users/jon/Work/openimaj/target/checkout/core/core-feature/src/main/jtemp/org/openimaj/feature/Sparse#T#FV.jtemp
*/
/**
* Copyright (c) 2011, The University of Southampton and the individual contributors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of the University of Southampton nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.openimaj.feature;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Scanner;
import org.openimaj.util.array.SparseBinSearchFloatArray;
import org.openimaj.util.array.SparseFloatArray;
import org.openimaj.util.array.SparseFloatArray.Entry;
import org.openimaj.util.concatenate.Concatenatable;
/**
* A sparse one-dimensional feature vector of float-valued elements.
*
* @author Jonathon Hare ([email protected])
*
*/
public class SparseFloatFV implements FeatureVector, Concatenatable {
private static final long serialVersionUID = 1L;
/**
* The underlying data backing the feature vector
*/
public SparseFloatArray values;
/**
* Construct an empty FV with zero length
*/
protected SparseFloatFV() {
}
/**
* Construct empty FV with given number of bins
* @param nbins the number of bins in each dimension
*/
public SparseFloatFV(int nbins) {
values = new SparseBinSearchFloatArray(nbins);
}
/**
* Construct from sparse array
* @param values the array of values
*/
public SparseFloatFV(SparseFloatArray values) {
this.values = values;
}
/**
* Construct from native array
* @param values the array of values
*/
public SparseFloatFV(float[] values) {
this.values = new SparseBinSearchFloatArray(values);
}
/* (non-Javadoc)
* @see org.openimaj.io.ReadableASCII#readASCII(java.util.Scanner)
*/
@Override
public void readASCII(Scanner in) throws IOException {
values = new SparseBinSearchFloatArray(0);
values.readASCII(in);
}
/* (non-Javadoc)
* @see org.openimaj.io.ReadableASCII#asciiHeader()
*/
@Override
public String asciiHeader() {
return "SFloatFV";
}
/* (non-Javadoc)
* @see org.openimaj.io.ReadableBinary#readBinary(java.io.DataInput)
*/
@Override
public void readBinary(DataInput in) throws IOException {
values = new SparseBinSearchFloatArray(0);
values.readBinary(in);
}
/* (non-Javadoc)
* @see org.openimaj.io.ReadableBinary#binaryHeader()
*/
@Override
public byte[] binaryHeader() {
return "SFloatFV".getBytes();
}
/* (non-Javadoc)
* @see org.openimaj.io.WriteableASCII#writeASCII(java.io.PrintWriter)
*/
@Override
public void writeASCII(PrintWriter out) throws IOException {
values.writeASCII(out);
}
/* (non-Javadoc)
* @see org.openimaj.io.WriteableBinary#writeBinary(java.io.DataOutput)
*/
@Override
public void writeBinary(DataOutput out) throws IOException {
values.writeBinary(out);
}
/* (non-Javadoc)
* @see org.openimaj.feature.FeatureVector#getVector()
*/
@Override
public SparseFloatArray getVector() {
return values;
}
/* (non-Javadoc)
* @see org.openimaj.feature.FeatureVector#length()
*/
@Override
public int length() {
return values.length;
}
/* (non-Javadoc)
* @see org.openimaj.feature.FeatureVector#normaliseFV(double[], double[])
*/
@Override
public DoubleFV normaliseFV(double [] min, double [] max) {
double [] dvals = asDoubleVector();
for (int i=0; i1) dvals[i] = 1;
}
return new DoubleFV(dvals);
}
/* (non-Javadoc)
* @see org.openimaj.feature.FeatureVector#normaliseFV(double, double)
*/
@Override
public DoubleFV normaliseFV(double min, double max) {
double [] dvals = asDoubleVector();
for (int i=0; i1) dvals[i] = 1;
}
return new DoubleFV(dvals);
}
/* (non-Javadoc)
* @see org.openimaj.feature.FeatureVector#normaliseFV()
*/
@Override
public DoubleFV normaliseFV() {
double [] dvals = asDoubleVector();
double sum = 0;
for (int i=0; i ins) {
SparseFloatArray [] insValues = new SparseFloatArray[ins.size()];
for (int i=0; i
© 2015 - 2024 Weber Informatics LLC | Privacy Policy