Java Code Examples for gnu.trove.list.TDoubleList#addAll()

The following examples show how to use gnu.trove.list.TDoubleList#addAll() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Encoder.java    From htm.java with GNU Affero General Public License v3.0 5 votes vote down vote up
public TDoubleList closenessScores(TDoubleList expValues, TDoubleList actValues, boolean fractional) {
	TDoubleList retVal = new TDoubleArrayList();

	//Fallback closenss is a percentage match
	List<EncoderTuple> encoders = getEncoders(this);
	if(encoders == null || encoders.size() < 1) {
		double err = Math.abs(expValues.get(0) - actValues.get(0));
		double closeness = -1;
		if(fractional) {
			double denom = Math.max(expValues.get(0), actValues.get(0));
			if(denom == 0) {
				denom = 1.0;
			}

			closeness = 1.0 - err/denom;
			if(closeness < 0) {
				closeness = 0;
			}
		}else{
			closeness = err;
		}

		retVal.add(closeness);
		return retVal;
	}

	int scalarIdx = 0;
	for(EncoderTuple res : getEncoders(this)) {
		TDoubleList values = res.getEncoder().closenessScores(
			expValues.subList(scalarIdx, expValues.size()), actValues.subList(scalarIdx, actValues.size()), fractional);

		scalarIdx += values.size();
		retVal.addAll(values);
	}

	return retVal;
}
 
Example 2
Source File: Encoder.java    From htm.java with GNU Affero General Public License v3.0 3 votes vote down vote up
/**
 * Returns an {@link TDoubleList} containing the sub-field scalar value(s) for
    * each sub-field of the inputData. To get the associated field names for each of
    * the scalar values, call getScalarNames().
 *
    * For a simple scalar encoder, the scalar value is simply the input unmodified.
    * For category encoders, it is the scalar representing the category string
    * that is passed in.
    *
    * TODO This is not correct for DateEncoder:
    *
    * For the datetime encoder, the scalar value is the
    * the number of seconds since epoch.
 *
    * The intent of the scalar representation of a sub-field is to provide a
    * baseline for measuring error differences. You can compare the scalar value
    * of the inputData with the scalar value returned from topDownCompute() on a
    * top-down representation to evaluate prediction accuracy, for example.
    *
    * @param <S>  the specifically typed input object
    *
 * @return
 */
public <S> TDoubleList getScalars(S d) {
	TDoubleList retVals = new TDoubleArrayList();
	double inputData = (Double)d;
	List<EncoderTuple> encoders = getEncoders(this);
	if(encoders != null) {
		for(EncoderTuple t : encoders) {
			TDoubleList values = t.getEncoder().getScalars(inputData);
			retVals.addAll(values);
		}
	}
	return retVals;
}