Here are some coding examples
correct
and updateParameters
1 // Specifies how to correct an ensemble given a set of parameters
2 void CorrectorNew::correct(const Parameters& iParameters, Ensemble& iEnsemble) const {
3 float correction = iParameters[0];
4
5 // Correct each ensemble member
6 for(int i = 0; i < iEnsemble.size(); i++) {
7 // ... but only if the member is not missing
8 if(Global::isValid(iEnsemble[i])) {
9 iEnsemble[i] = iEnsemble[i] + correction;
10 }
11 }
12 }
13
14 // Specifies how old parameters should be updated based on new information
15 void CorrectorNew::updateParameters(const Ensemble& iUnCorrected,
16 const std::vector<Obs>& iObs,
17 Parameters& iParameters) const {
18 float ensMean = iUnCorrected.getMoment(1);
19 float error = iObs.getValue() - ensMean;
20 // Weighted average of the old parameter with the new evidence
21 iParameters[0] = combine(iParameters[0], error);
22 }
1 void SelectorClim::selectCore(int iDate,
2 int iInit,
3 float iOffset,
4 const Location& iLocation,
5 const std::string& iVariable,
6 const Parameters& iParameters,
7 std::vector<Slice>& iSlices) const {
8
9 std::vector<int> dates;
10 Input* input = mData.getInput(iVariable,Input::typeObservation);
11 input->getDates(dates);
12
13 std::vector<float> offsets;
14 input->getOffsets(offsets);
15 for(int d = 0; d < (int) dates.size(); d++) {
16 // TODO:
17 // For efficiency reasons the date is checked independently of the offset
18 // This means that some offsets near the edge of the day difference alloweed
19 // will or will not be included properly
20 int date = dates[d];
21 int dayDiff = fabs(Global::getJulianDay(Global::getDate(iDate,iInit,iOffset))
22 - Global::getJulianDay(date));
23 if(dayDiff > 365/2)
24 dayDiff = 365 - dayDiff;
25 assert(dayDiff >= 0);
26 //bool validDate = (dayDiff <= mDayWindow || (365 - dayDiff) <= mDayWindow);
27 bool validDate = (dayDiff <= mDayWindow);
28 if(!mAllowFutureValues) {
29 // Must have occurred in the past
30 validDate = (validDate && iDate > date);
31 }
32 else {
33 // TODO:
34 if(mFutureBlackout) {
35 // Don't allow dates that are close to the forecast date, because this would make the
36 // statistics in sample
37 bool withinBlackout = (Global::getTimeDiff(date, 0, 0, iDate, 0, 0) <= mFutureBlackout) &&
38 (date >= iDate);
39 validDate = (validDate && !withinBlackout);
40 }
41 }
42 }