1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
|
/***********************************************/
/**
* @file parametrizationTemporalSplines.cpp
*
* @brief Splines expansion.
* @see ParametrizationTemporal
*
* @author Torsten Mayer-Guerr
* @date 2011-12-28
*
*/
/***********************************************/
#include "base/import.h"
#include "base/basisSplines.h"
#include "config/config.h"
#include "inputOutput/logging.h"
#include "classes/timeSeries/timeSeries.h"
#include "classes/parametrizationTemporal/parametrizationTemporal.h"
#include "parametrizationTemporalSplines.h"
/***********************************************/
ParametrizationTemporalSplines::ParametrizationTemporalSplines(Config &config)
{
try
{
TimeSeriesPtr timeSeriesPtr, timesIntervalPtr;
readConfig(config, "degree", degree, Config::MUSTSET, "", "degree of splines");
readConfig(config, "timeSeries", timeSeriesPtr, Config::MUSTSET, "", "nodal points in time domain");
readConfig(config, "intervals", timesIntervalPtr, Config::DEFAULT, "", "");
readConfig(config, "includeLastTime", includeLastTime, Config::DEFAULT, "0", "");
if(isCreateSchema(config)) return;
times = timeSeriesPtr->times();
// init time intervals
// -------------------
std::vector<Time> timesInterval = timesIntervalPtr->times();
isInterval = (timesInterval.size() != 0);
if(!isInterval)
timesInterval = {times.at(0), times.back()};
computeIntervals(timesInterval);
idxStart = 0;
idxEnd = idEpochStart.size();
}
catch(std::exception &e)
{
GROOPS_RETHROW(e)
}
}
/***********************************************/
void ParametrizationTemporalSplines::computeIntervals(const std::vector<Time> ×Interval)
{
try
{
idEpochStart.clear();
idEpochEnd.clear();
for(UInt idInterval=0; idInterval<timesInterval.size()-1; idInterval++)
{
UInt start = 0;
while((start+1<times.size()) && (times.at(start+1)<=timesInterval.at(idInterval)))
start++;
UInt count = 0;
while((start+count<times.size()) && (times.at(start+count)<=timesInterval.at(idInterval+1)))
count++;
if(count==0)
continue;
for(UInt n=0; n<degree; n++)
idEpochStart.push_back(start);
for(UInt i=0; i<count-1; i++)
{
idEpochStart.push_back(start+i);
idEpochEnd.push_back(start+i+1);
}
for(UInt n=0; n<degree; n++)
idEpochEnd.push_back(start+count-1);
}
}
catch(std::exception &e)
{
GROOPS_RETHROW(e)
}
}
/***********************************************/
Bool ParametrizationTemporalSplines::setInterval(const Time &timeStart, const Time &timeEnd, Bool estimatePerArc)
{
try
{
const UInt idxStartOld = idxStart;
const UInt idxEndOld = idxEnd;
if((timeEnd<=times.at(0)) || (timeStart>=times.back()))
{
idxStart = idxEnd = 0; // time interval outside spline nodal points
return (idxStartOld != idxStart) || (idxEndOld != idxEnd);
}
if(estimatePerArc && !isInterval)
computeIntervals({timeStart, timeEnd});
idxStart = 0;
while((idxStart<idEpochEnd.size()) && (times.at(idEpochEnd.at(idxStart))<=timeStart))
idxStart++;
idxEnd = idxStart;
while((idxEnd<idEpochStart.size()) && (times.at(idEpochStart.at(idxEnd))<timeEnd))
idxEnd++;
return (idxStartOld != idxStart) || (idxEndOld != idxEnd);
}
catch(std::exception &e)
{
GROOPS_RETHROW(e)
}
}
/***********************************************/
void ParametrizationTemporalSplines::parameterName(std::vector<ParameterName> &name) const
{
try
{
for(UInt i=idxStart; i<idxEnd; i++)
name.push_back(ParameterName("", "", "spline.n"+degree%"%i"s, times.at(idEpochStart.at(i)), times.at(idEpochEnd.at(i))));
}
catch(std::exception &e)
{
GROOPS_RETHROW(e)
}
}
/***********************************************/
void ParametrizationTemporalSplines::factors(const Time &time, UInt startIndex, std::vector<UInt> &index, std::vector<Double> &factor) const
{
try
{
if(idxEnd == idxStart)
return;
if((time < times.at(idEpochStart.at(idxStart))) || (time > times.at(idEpochEnd.at(idxEnd-1))) || (!includeLastTime && (time == times.at(idEpochEnd.at(idxEnd-1)))))
return;
// find first used parameter
UInt idx = idxStart;
while((idx+1+degree < idxEnd) && (time >= times.at(idEpochEnd.at(idx))))
idx++;
const UInt idEpoch = idEpochEnd.at(idx)-1;
const Double t = (time-times.at(idEpoch)).mjd()/(times.at(idEpoch+1)-times.at(idEpoch)).mjd();
const Vector f = BasisSplines::compute(t, degree);
for(UInt i=0; i<=degree; i++)
if(std::fabs(f(i)) > 1e-8)
{
index.push_back( i+idx-idxStart+startIndex );
factor.push_back( f(i) );
}
}
catch(std::exception &e)
{
GROOPS_RETHROW(e)
}
}
/***********************************************/
|