use of org.ojalgo.type.CalendarDate in project ojAlgo by optimatika.
the class ImplicitTimeSeries method keys.
@Override
public final long[] keys() {
final long[] retVal = new long[this.size()];
CalendarDate tmpKey = myFirst;
retVal[0] = tmpKey.millis;
for (int t = 1; t < retVal.length; t++) {
tmpKey = tmpKey.step(myResolution);
retVal[t] = tmpKey.millis;
}
return retVal;
}
use of org.ojalgo.type.CalendarDate in project ojAlgo by optimatika.
the class CalendarDateSeries method getPrimitiveKeys.
public long[] getPrimitiveKeys() {
final long[] retVal = new long[this.size()];
int i = 0;
for (final CalendarDate tmpKey : this.keySet()) {
retVal[i] = tmpKey.millis;
i++;
}
return retVal;
}
use of org.ojalgo.type.CalendarDate in project ojAlgo by optimatika.
the class CoordinationSet method prune.
/**
* Will prune and resample the data
*/
public CoordinationSet<N> prune(final CalendarDateUnit resolution) {
final CoordinationSet<N> retVal = new CoordinationSet<>(resolution);
final CalendarDate tmpLatestFirstKey = this.getLatestFirstKey();
final CalendarDate tmpEarliestLastKey = this.getEarliestLastKey();
for (final Map.Entry<String, CalendarDateSeries<N>> tmpEntry : this.entrySet()) {
retVal.put(tmpEntry.getKey(), tmpEntry.getValue().resample(tmpLatestFirstKey, tmpEarliestLastKey, resolution));
}
return retVal;
}
use of org.ojalgo.type.CalendarDate in project ojAlgo by optimatika.
the class SeriesInterpolator method getCombination.
public CalendarDateSeries<Double> getCombination(final Number inputKey) {
final BigDecimal tmpInputKey = TypeUtils.toBigDecimal(inputKey, myContext);
if (myCoordinatedSet == null) {
myCoordinatedSet = myOriginalSet.prune();
myCoordinatedSet.complete();
}
final CalendarDateSeries<Double> retVal = new CalendarDateSeries<>(myCoordinatedSet.getResolution());
BigDecimal tmpLowerKey = null;
BigDecimal tmpUpperKey = null;
for (final BigDecimal tmpIterKey : myKeys.keySet()) {
if (tmpIterKey.compareTo(tmpInputKey) != 1) {
if ((tmpLowerKey == null) || (tmpIterKey.compareTo(tmpLowerKey) == 1)) {
tmpLowerKey = tmpIterKey;
}
}
if (tmpIterKey.compareTo(tmpInputKey) != -1) {
if ((tmpUpperKey == null) || (tmpIterKey.compareTo(tmpInputKey) != -1)) {
tmpUpperKey = tmpIterKey;
}
}
}
@SuppressWarnings("unchecked") final long[] tmpSeriesKeys = ((CalendarDateSeries<Double>) myCoordinatedSet.values().toArray()[0]).getPrimitiveKeys();
double tmpFactor;
double[] tmpSeriesValues;
if ((tmpLowerKey == null) && (tmpUpperKey != null)) {
tmpFactor = tmpInputKey.doubleValue() / tmpUpperKey.doubleValue();
tmpSeriesValues = myCoordinatedSet.get(myKeys.get(tmpUpperKey)).asPrimitive().toRawCopy1D();
for (int i = 0; i < tmpSeriesValues.length; i++) {
tmpSeriesValues[i] *= tmpFactor;
}
} else if ((tmpLowerKey != null) && (tmpUpperKey == null)) {
tmpFactor = tmpInputKey.doubleValue() / tmpLowerKey.doubleValue();
tmpSeriesValues = myCoordinatedSet.get(myKeys.get(tmpLowerKey)).asPrimitive().toRawCopy1D();
for (int i = 0; i < tmpSeriesValues.length; i++) {
tmpSeriesValues[i] *= tmpFactor;
}
} else if ((tmpLowerKey != null) && (tmpUpperKey != null)) {
if (tmpLowerKey.equals(tmpUpperKey)) {
tmpSeriesValues = myCoordinatedSet.get(myKeys.get(tmpLowerKey)).asPrimitive().toRawCopy1D();
} else {
final double[] tmpLowerValues = myCoordinatedSet.get(myKeys.get(tmpLowerKey)).asPrimitive().toRawCopy1D();
final double[] tmpUpperValues = myCoordinatedSet.get(myKeys.get(tmpUpperKey)).asPrimitive().toRawCopy1D();
tmpFactor = (tmpInputKey.doubleValue() - tmpLowerKey.doubleValue()) / (tmpUpperKey.doubleValue() - tmpLowerKey.doubleValue());
tmpSeriesValues = new double[tmpSeriesKeys.length];
for (int i = 0; i < tmpSeriesValues.length; i++) {
tmpSeriesValues[i] = (tmpFactor * tmpUpperValues[i]) + ((PrimitiveMath.ONE - tmpFactor) * tmpLowerValues[i]);
}
}
} else {
tmpSeriesValues = new double[tmpSeriesKeys.length];
}
for (int i = 0; i < tmpSeriesKeys.length; i++) {
retVal.put(new CalendarDate(tmpSeriesKeys[i]), tmpSeriesValues[i]);
}
return retVal;
}
use of org.ojalgo.type.CalendarDate in project ojAlgo by optimatika.
the class CoordinationSet method prune.
/**
* @return A new CoordinationSet where all series have the same first and last keys.
*/
public CoordinationSet<N> prune() {
final CoordinationSet<N> retVal = new CoordinationSet<>(this.getResolution());
final CalendarDate tmpFirstKey = this.getLatestFirstKey();
final CalendarDate tmpLastKey = this.getEarliestLastKey();
if (tmpLastKey.compareTo(tmpFirstKey) != -1) {
for (final CalendarDateSeries<N> tmpSeries : this.values()) {
final CalendarDateSeries<N> tmpSubMap = tmpSeries.subMap(tmpFirstKey, true, tmpLastKey, true);
retVal.put(tmpSubMap);
}
}
final CalendarDate tmpEarliestFirstKey = retVal.getEarliestFirstKey();
final CalendarDate tmpLatestFirstKey = retVal.getLatestFirstKey();
final CalendarDate tmpEarliestLastKey = retVal.getEarliestLastKey();
final CalendarDate tmpLatestLastKey = retVal.getLatestLastKey();
if ((tmpEarliestFirstKey == null) || !tmpEarliestFirstKey.equals(tmpFirstKey)) {
throw new ProgrammingError("Something went wrong!");
}
if ((tmpLatestFirstKey == null) || !tmpLatestFirstKey.equals(tmpFirstKey)) {
throw new ProgrammingError("Something went wrong!");
}
if ((tmpEarliestLastKey == null) || !tmpEarliestLastKey.equals(tmpLastKey)) {
throw new ProgrammingError("Something went wrong!");
}
if ((tmpLatestLastKey == null) || !tmpLatestLastKey.equals(tmpLastKey)) {
throw new ProgrammingError("Something went wrong!");
}
return retVal;
}
Aggregations