org.tensorics.core.reduction.AbstractLinearDoubleInterpolationStrategy Maven / Gradle / Ivy
Show all versions of tensorics-core Show documentation
/**
* Copyright (c) 2015 European Organisation for Nuclear Research (CERN), All Rights Reserved.
*/
package org.tensorics.core.reduction;
import java.util.List;
import org.tensorics.core.tensor.Tensor;
/**
* An abstract implementation for the linear interpolation of the {@link Double} {@link Tensor}.
*
* It returns a value based on the ratio in the comparable (ie. time) domain, between the reference point(t_i) and the
* pair of the one before(t_1) and after(t_2) like:
*
* ratio = (t_i - t_1)/(t_2 - t_1)
*
* The final interpolated value is: v_i = v(t_1)+(v(t_2)-v(t_1))*ratio.
*
* @author agorzaws
* @param type of the coordinate, must be the {@link Comparable}
*/
public abstract class AbstractLinearDoubleInterpolationStrategy> extends
AbstractInterpolationStrategy {
@Override
public Double getInterpolatedValue(Tensor tensorWithTheOnlyOneCoordinateOfC, C coordineteToInterpolate) {
List orderedList = getOrderedListOfComparableCoodrinate(tensorWithTheOnlyOneCoordinateOfC,
coordineteToInterpolate);
C thePreviousComparable = findIndex(orderedList, coordineteToInterpolate, 0);
C theNextComparable = findIndex(orderedList, coordineteToInterpolate, 1);
Double firstPoint = tensorWithTheOnlyOneCoordinateOfC.get(thePreviousComparable);
return firstPoint + (tensorWithTheOnlyOneCoordinateOfC.get(theNextComparable) - firstPoint)
* ratio(thePreviousComparable, theNextComparable, coordineteToInterpolate);
}
public abstract double ratio(C previousComparable, C nextComparable, C value);
}