double StochasticThresholdForInitiationOfBedloadMotion::calculateNotConst (const RegularRiverReachProperties& regularRiverReachProperties) { double result = std::numeric_limits<double>::quiet_NaN(); std::map<double,std::vector<double> >::iterator currentValues = mapFromWidthToValues.find(regularRiverReachProperties.activeWidth); if(currentValues == mapFromWidthToValues.end()) { double currentMiu (miu); double currentBeta (beta); std::map<double,std::pair<double,double> >::iterator currentSpecialValues = mapFromWidthToSpecialValues.find(regularRiverReachProperties.activeWidth); if(currentSpecialValues != mapFromWidthToSpecialValues.end()) { currentMiu = currentSpecialValues->second.first; currentBeta = currentSpecialValues->second.second; } std::vector<double> tmpValues (6,currentMiu); //miu, currentValue, previousValue, prePreviousValue tmpValues.at(0) = std::numeric_limits<double>::quiet_NaN(); //discharge tmpValues.at(2) = currentBeta; //beta mapFromWidthToValues[regularRiverReachProperties.activeWidth] = tmpValues; currentValues = mapFromWidthToValues.find(regularRiverReachProperties.activeWidth); } /* if(regularRiverReachProperties.discharge == currentValues->second.at(0)) { result = currentValues->second.at(3); } else*/ { currentValues->second.at(0) = regularRiverReachProperties.discharge; currentValues->second.at(5) = currentValues->second.at(4); // prePreviousValue = previousValue currentValues->second.at(4) = currentValues->second.at(3); // previousValue = currentValue double randomNumber = (1.0+rand()) / (2.0+RAND_MAX); //Uniform Distribution randomNumber = currentValues->second.at(1) - (currentValues->second.at(2) * log( (-1.0) * log(randomNumber) ) ); //Gumbel Distribution result = (randomNumber * weightForCurrent) + (currentValues->second.at(4) * weightForPrevious) + (currentValues->second.at(5) * weightForPrePrevious); result = std::max(result,minimumThresholdValue); if(correctionForBedloadWeightAtSteepCounterSlopes && regularRiverReachProperties.bedslope < 0.0) { result = CorrectionForBedloadWeightAtSteepSlopes::calculateCorrectedDimensionlessCriticalShearStressAtSteepCounterSlopes(result,(regularRiverReachProperties.getOverallParameters())->getAngleOfReposeInRadians(),regularRiverReachProperties.bedslope); } currentValues->second.at(3) = result; } return result; }
// format = {Virtual place, Loop closure, level1, level2, l3, l4...} void BayesFilter::setPredictionLC(const std::string & prediction) { std::list<std::string> strValues = uSplit(prediction, ' '); if(strValues.size() < 2) { UERROR("The number of values < 2 (prediction=\"%s\")", prediction.c_str()); } else { std::vector<double> tmpValues(strValues.size()); int i=0; bool valid = true; for(std::list<std::string>::iterator iter = strValues.begin(); iter!=strValues.end(); ++iter) { tmpValues[i] = std::atof((*iter).c_str()); //UINFO("%d=%e", i, tmpValues[i]); if(tmpValues[i] < 0.0 || tmpValues[i]>1.0) { valid = false; break; } ++i; } if(!valid) { UERROR("The prediction is not valid (values must be between >0 && <=1) prediction=\"%s\"", prediction.c_str()); } else { _predictionLC = tmpValues; } } _totalPredictionLCValues = 0.0f; for(unsigned int j=0; j<_predictionLC.size(); ++j) { _totalPredictionLCValues += _predictionLC[j]; } }
void merge(std::vector<ValueType> &values, Comparator<ValueType> &comparator, int left, int mid, int right) { // Assumption: left, mid and right are valid indices std::vector<ValueType> tmpValues(values.begin() + left, values.begin() + right + 1); int i = left; int j = mid + 1; int k = left; while ((i <= mid) && (j <= right)) { if (comparator(tmpValues[i - left], tmpValues[j - left])) { values[k++] = tmpValues[(i++) - left]; } else { values[k++] = tmpValues[(j++) - left]; } } while (i <= mid) { values[k++] = tmpValues[(i++) - left]; } // There is no need to copy values from positions j to right, if any, // because the values are already in the correct position }