in lib/model/CAnomalyDetectorModelConfig.cc [757:986]
bool CAnomalyDetectorModelConfig::processStanza(const boost::property_tree::ptree& propertyTree) {
bool result = true;
for (const auto& property : propertyTree) {
std::string propName = property.first;
std::string propValue = property.second.data();
core::CStringUtils::trimWhitespace(propValue);
if (propName == ONLINE_LEARN_RATE_PROPERTY) {
double learnRate = DEFAULT_LEARN_RATE;
if (core::CStringUtils::stringToType(propValue, learnRate) == false ||
learnRate <= 0.0) {
LOG_ERROR(<< "Invalid value for property " << propName << " : " << propValue);
result = false;
continue;
}
learnRate *= bucketNormalizationFactor(this->bucketLength());
for (auto& factory : m_Factories) {
factory.second->learnRate(learnRate);
}
} else if (propName == DECAY_RATE_PROPERTY) {
double decayRate = DEFAULT_DECAY_RATE;
if (core::CStringUtils::stringToType(propValue, decayRate) == false ||
decayRate <= 0.0) {
LOG_ERROR(<< "Invalid value for property " << propName << " : " << propValue);
result = false;
continue;
}
decayRate *= bucketNormalizationFactor(this->bucketLength());
for (auto& factory : m_Factories) {
factory.second->decayRate(decayRate);
}
} else if (propName == INITIAL_DECAY_RATE_MULTIPLIER_PROPERTY) {
double multiplier = DEFAULT_INITIAL_DECAY_RATE_MULTIPLIER;
if (core::CStringUtils::stringToType(propValue, multiplier) == false ||
multiplier < 1.0) {
LOG_ERROR(<< "Invalid value for property " << propName << " : " << propValue);
result = false;
continue;
}
for (auto& factory : m_Factories) {
factory.second->initialDecayRateMultiplier(multiplier);
}
} else if (propName == MAXIMUM_UPDATES_PER_BUCKET_PROPERTY) {
double maximumUpdatesPerBucket;
if (core::CStringUtils::stringToType(propValue, maximumUpdatesPerBucket) == false ||
maximumUpdatesPerBucket < 0.0) {
LOG_ERROR(<< "Invalid value for property " << propName << " : " << propValue);
result = false;
continue;
}
for (auto& factory : m_Factories) {
factory.second->maximumUpdatesPerBucket(maximumUpdatesPerBucket);
}
} else if (propName == INDIVIDUAL_MODE_FRACTION_PROPERTY) {
double fraction;
if (core::CStringUtils::stringToType(propValue, fraction) == false ||
fraction < 0.0 || fraction > 1.0) {
LOG_ERROR(<< "Invalid value for property " << propName << " : " << propValue);
result = false;
continue;
}
if (m_Factories.count(E_EventRateFactory) > 0) {
m_Factories[E_EventRateFactory]->minimumModeFraction(fraction);
}
if (m_Factories.count(E_MetricFactory) > 0) {
m_Factories[E_MetricFactory]->minimumModeFraction(fraction);
}
} else if (propName == POPULATION_MODE_FRACTION_PROPERTY) {
double fraction;
if (core::CStringUtils::stringToType(propValue, fraction) == false ||
fraction < 0.0 || fraction > 1.0) {
LOG_ERROR(<< "Invalid value for property " << propName << " : " << propValue);
result = false;
continue;
}
if (m_Factories.count(E_EventRatePopulationFactory) > 0) {
m_Factories[E_EventRatePopulationFactory]->minimumModeFraction(fraction);
}
if (m_Factories.count(E_MetricPopulationFactory) > 0) {
m_Factories[E_MetricPopulationFactory]->minimumModeFraction(fraction);
}
} else if (propName == COMPONENT_SIZE_PROPERTY) {
int componentSize;
if (core::CStringUtils::stringToType(propValue, componentSize) == false ||
componentSize < 0) {
LOG_ERROR(<< "Invalid value of property " << propName << " : " << propValue);
result = false;
continue;
}
for (auto& factory : m_Factories) {
factory.second->componentSize(componentSize);
}
} else if (propName == SAMPLE_COUNT_FACTOR_PROPERTY) {
int factor;
if (core::CStringUtils::stringToType(propValue, factor) == false || factor < 0) {
LOG_ERROR(<< "Invalid value for property " << propName << " : " << propValue);
result = false;
continue;
}
for (auto& factory : m_Factories) {
factory.second->sampleCountFactor(factor);
}
} else if (propName == PRUNE_WINDOW_SCALE_MINIMUM) {
double factor;
if (core::CStringUtils::stringToType(propValue, factor) == false) {
LOG_ERROR(<< "Invalid value for property " << propName << " : " << propValue);
result = false;
continue;
}
for (auto& factory : m_Factories) {
factory.second->pruneWindowScaleMinimum(factor);
}
} else if (propName == PRUNE_WINDOW_SCALE_MAXIMUM) {
double factor;
if (core::CStringUtils::stringToType(propValue, factor) == false) {
LOG_ERROR(<< "Invalid value for property " << propName << " : " << propValue);
result = false;
continue;
}
for (auto& factory : m_Factories) {
factory.second->pruneWindowScaleMaximum(factor);
}
} else if (propName == AGGREGATION_STYLE_PARAMS) {
core::CStringUtils::trimWhitespace(propValue);
propValue = core::CStringUtils::normaliseWhitespace(propValue);
TStrVec strings;
std::string remainder;
core::CStringUtils::tokenise(" ", propValue, strings, remainder);
if (!remainder.empty()) {
strings.push_back(remainder);
}
std::size_t n = model_t::NUMBER_AGGREGATION_STYLES * model_t::NUMBER_AGGREGATION_PARAMS;
if (strings.size() != n) {
LOG_ERROR(<< "Expected " << n << " values for " << propName);
result = false;
continue;
}
for (std::size_t j = 0, l = 0; j < model_t::NUMBER_AGGREGATION_STYLES; ++j) {
for (std::size_t k = 0; k < model_t::NUMBER_AGGREGATION_PARAMS; ++k, ++l) {
double value;
if (core::CStringUtils::stringToType(strings[l], value) == false) {
LOG_ERROR(<< "Unexpected value " << strings[l]
<< " in property " << propName);
result = false;
continue;
}
this->aggregationStyleParams(
static_cast<model_t::EAggregationStyle>(j),
static_cast<model_t::EAggregationParam>(k), value);
}
}
} else if (propName == MAXIMUM_ANOMALOUS_PROBABILITY_PROPERTY) {
double probability;
if (core::CStringUtils::stringToType(propValue, probability) == false) {
LOG_ERROR(<< "Invalid value for property " << propName << " : " << propValue);
result = false;
continue;
}
this->maximumAnomalousProbability(probability);
} else if (propName == NOISE_PERCENTILE_PROPERTY) {
double percentile;
if (core::CStringUtils::stringToType(propValue, percentile) == false ||
this->noisePercentile(percentile) == false) {
LOG_ERROR(<< "Invalid value for property " << propName << " : " << propValue);
result = false;
continue;
}
} else if (propName == NOISE_MULTIPLIER_PROPERTY) {
double multiplier;
if (core::CStringUtils::stringToType(propValue, multiplier) == false ||
this->noiseMultiplier(multiplier) == false) {
LOG_ERROR(<< "Invalid value for property " << propName << " : " << propValue);
result = false;
continue;
}
} else if (propName == NORMALIZED_SCORE_KNOT_POINTS) {
core::CStringUtils::trimWhitespace(propValue);
propValue = core::CStringUtils::normaliseWhitespace(propValue);
TStrVec strings;
std::string remainder;
core::CStringUtils::tokenise(" ", propValue, strings, remainder);
if (!remainder.empty()) {
strings.push_back(remainder);
}
if (strings.empty() || (strings.size() % 2) != 0) {
LOG_ERROR(<< "Expected even number of values for property "
<< propName << " " << strings);
result = false;
continue;
}
TDoubleDoublePrVec points;
points.reserve(strings.size() / 2 + 2);
points.emplace_back(0.0, 0.0);
for (std::size_t j = 0; j < strings.size(); j += 2) {
double rate;
double score;
if (core::CStringUtils::stringToType(strings[j], rate) == false) {
LOG_ERROR(<< "Unexpected value " << strings[j]
<< " for rate in property " << propName);
result = false;
continue;
}
if (core::CStringUtils::stringToType(strings[j + 1], score) == false) {
LOG_ERROR(<< "Unexpected value " << strings[j + 1]
<< " for score in property " << propName);
result = false;
continue;
}
points.emplace_back(rate, score);
}
points.emplace_back(100.0, 100.0);
this->normalizedScoreKnotPoints(points);
} else {
LOG_WARN(<< "Ignoring unknown property " << propName);
}
}
return result;
}