bool drwnConditionalGaussian::load(drwnXMLNode& xml) { DRWN_ASSERT(drwnGetXMLAttribute(xml, "n") != NULL); _n = atoi(drwnGetXMLAttribute(xml, "n")); DRWN_ASSERT(drwnGetXMLAttribute(xml, "m") != NULL); _m = atoi(drwnGetXMLAttribute(xml, "m")); drwnXMLNode *node = xml.first_node("mu"); DRWN_ASSERT((node != NULL) && (node->next_sibling("mu") == NULL)); drwnXMLUtils::deserialize(*node, _mu); DRWN_ASSERT(_mu.rows() == _n); node = xml.first_node("sigma"); DRWN_ASSERT((node != NULL) && (node->next_sibling("sigma") == NULL)); drwnXMLUtils::deserialize(*node, _mSigma); DRWN_ASSERT((_mSigma.rows() == _n) && (_mSigma.cols() == _n)); node = xml.first_node("gain"); DRWN_ASSERT((node != NULL) && (node->next_sibling("gain") == NULL)); drwnXMLUtils::deserialize(*node, _mSigmaGain); DRWN_ASSERT((_mSigmaGain.rows() == _n) && (_mSigmaGain.cols() == _m)); return true; }
bool drwnCompositeClassifier::load(drwnXMLNode& xml) { drwnClassifier::load(xml); // load meta-parameters if (drwnGetXMLAttribute(xml, "baseClassifier") == NULL) { DRWN_LOG_WARNING("XML is missing baseClassifier attribute"); } else { _baseClassifier = string(drwnGetXMLAttribute(xml, "baseClassifier")); } if (drwnGetXMLAttribute(xml, "method") == NULL) { DRWN_LOG_WARNING("XML is missing method attribute"); } else { _method = (drwnCompositeClassifierMethod)atoi(drwnGetXMLAttribute(xml, "method")); } // load binary classifiers drwnXMLNode *node = xml.first_node("binaryClassifiers"); for (drwnXMLNode *child = node->first_node(); child != NULL; child = child->next_sibling()) { _binaryClassifiers.push_back(drwnClassifierFactory::get().createFromXML(*child)); } // load feature whitener and calibration weights node = xml.first_node("featureWhitener"); _featureWhitener.load(*node); node = xml.first_node("calibrationWeights"); _calibrationWeights.load(*node); return true; }
bool drwnSuffStats::load(drwnXMLNode& xml) { DRWN_ASSERT(drwnGetXMLAttribute(xml, "n") != NULL); clear(atoi(drwnGetXMLAttribute(xml, "n"))); DRWN_ASSERT(drwnGetXMLAttribute(xml, "count") != NULL); _count = atof(drwnGetXMLAttribute(xml, "count")); drwnXMLNode *node = xml.first_node("sum"); DRWN_ASSERT(node != NULL); drwnXMLUtils::deserialize(*node, _sum); DRWN_ASSERT(_sum.rows() == _n); MatrixXd tmp(_n, _n); node = xml.first_node("sumSq"); DRWN_ASSERT(node != NULL); drwnXMLUtils::deserialize(*node, tmp); switch (_pairStats) { case DRWN_PSS_FULL: _sum2 = tmp; break; case DRWN_PSS_DIAG: _sum2 = tmp.diagonal(); break; default: // do nothing break; } return true; }
bool drwnFeatureWhitener::load(drwnXMLNode& node) { drwnUnsupervisedTransform::load(node); drwnXMLNode *child = node.first_node("mu"); DRWN_ASSERT(child != NULL); drwnXMLUtils::deserialize(*child, _mu); child = node.first_node("beta"); DRWN_ASSERT(child != NULL); drwnXMLUtils::deserialize(*child, _beta); return true; }
void drwnMultiSegRegionDefinitions::read(drwnXMLNode& root) { DRWN_ASSERT(!drwnIsXMLEmpty(root)); clear(); unsigned char red, green, blue; for (drwnXMLNode *node = root.first_node("region"); node != NULL; node = node->next_sibling("region")) { _keys[atoi(drwnGetXMLAttribute(*node, "id"))] = (int)_names.size(); _names.push_back(string(drwnGetXMLAttribute(*node, "name"))); #if defined(_WIN32) int ir, ig, ib; if (sscanf(drwnGetXMLAttribute(*node, "color"), "%d %d %d", &ir, &ig, &ib) != 3) { DRWN_LOG_FATAL("could not parse color for \"" << _names.back() << "\""); } if ((ir < 0) || (ir > 255) || (ig < 0) || (ig > 255) || (ib < 0) || (ib > 255)) { DRWN_LOG_FATAL("could not parse color for \"" << _names.back() << "\""); } red = (unsigned char)ir; green = (unsigned char)ig; blue = (unsigned char)ib; #else if (sscanf(drwnGetXMLAttribute(*node, "color"), "%hhu %hhu %hhu", &red, &green, &blue) != 3) { DRWN_LOG_FATAL("could not parse color for \"" << _names.back() << "\""); } #endif _colors.push_back((red << 16) | (green << 8) | blue); } }
bool drwnTableFactor::load(drwnXMLNode& xml) { // free existing storage if ((_storage == NULL) && (_data != NULL)) { delete[] _data; _data = NULL; #ifdef DRWN_FACTOR_DEBUG_STATISTICS drwnFactor::_dbStatsCurrentMem -= _nSize; #endif } // load and add variables drwnFactor::load(xml); // read table data drwnXMLNode *node = xml.first_node("data"); if ((node == NULL) || drwnIsXMLEmpty(*node)) { initialize(); } else { VectorXd v; drwnXMLUtils::deserialize(*node, v); DRWN_ASSERT_MSG(v.size() == _nSize, v.size() << " != " << _nSize); Eigen::Map<VectorXd>(_data, _nSize) = v; } return true; }
bool drwnGaussian::load(drwnXMLNode& xml) { DRWN_ASSERT(drwnGetXMLAttribute(xml, "n") != NULL); initialize(atoi(drwnGetXMLAttribute(xml, "n"))); drwnXMLNode *node = xml.first_node("mu"); DRWN_ASSERT((node != NULL) && (node->next_sibling("mu") == NULL)); drwnXMLUtils::deserialize(*node, _mu); DRWN_ASSERT(_mu.rows() == _n); node = xml.first_node("sigma"); DRWN_ASSERT((node != NULL) && (node->next_sibling("sigma") == NULL)); drwnXMLUtils::deserialize(*node, _mSigma); DRWN_ASSERT((_mSigma.rows() == _n) && (_mSigma.cols() == _n)); updateCachedParameters(); return true; }
bool drwnBoostedClassifierNode::load(drwnXMLNode& xml) { drwnNode::load(xml); drwnXMLNode *node = xml.first_node("drwnClassifier"); if (node != NULL) { return _classifier.load(*node); } return false; }
// options i/o void drwnMultiSegConfig::readConfiguration(drwnXMLNode& node) { // read options drwnProperties::readProperties(node, "option"); // read region definitions drwnXMLNode *childNode = node.first_node("regionDefinitions"); if (childNode != NULL) { gMultiSegRegionDefs.read(*childNode); } else { DRWN_LOG_WARNING("drwnMultiSegConfig is missing regionDefinitions"); } }
bool drwnBoostedClassifier::load(drwnXMLNode& xml) { drwnClassifier::load(xml); for (drwnXMLNode *node = xml.first_node("weakLearner"); node != NULL; node = node->next_sibling("weakLearner")) { _alphas.push_back(atof(drwnGetXMLAttribute(*node, "weight"))); _weakLearners.push_back(new drwnDecisionTree()); _weakLearners.back()->load(*node); } return true; }
bool drwnDecisionTree::load(drwnXMLNode& xml) { drwnClassifier::load(xml); if (_leftChild != NULL) delete _leftChild; if (_rightChild != NULL) delete _rightChild; DRWN_ASSERT(drwnGetXMLAttribute(xml, "splitIndx") != NULL); DRWN_ASSERT(drwnGetXMLAttribute(xml, "splitValue") != NULL); _splitIndx = atoi(drwnGetXMLAttribute(xml, "splitIndx")); _splitValue = atof(drwnGetXMLAttribute(xml, "splitValue")); drwnXMLUtils::deserialize(xml, _scores); if (_scores.size() == 0) { _predictedClass = -1; } else { _scores.maxCoeff(&_predictedClass); } // create and load children if (_splitIndx != -1) { _leftChild = new drwnDecisionTree(); drwnXMLNode *childNode = xml.first_node("drwnDecisionTree"); DRWN_ASSERT(childNode != NULL); _leftChild->load(*childNode); _rightChild = new drwnDecisionTree(); childNode = childNode->next_sibling("drwnDecisionTree"); DRWN_ASSERT(childNode != NULL); _rightChild->load(*childNode); DRWN_ASSERT(childNode->next_sibling("drwnDecisionTree") == NULL); } else { DRWN_ASSERT(xml.first_node("drwnDecisionTree") == NULL); _leftChild = NULL; _rightChild = NULL; } return true; }
bool drwnObjectList::load(drwnXMLNode& xml) { clear(); const int numObjects = drwnCountXMLChildren(xml, "drwnObject"); reserve(numObjects); for (drwnXMLNode *node = xml.first_node("drwnObject"); node != NULL; node = node->next_sibling("drwnObject")) { DRWN_ASSERT(!drwnIsXMLEmpty(*node)); push_back(drwnObject()); back().load(*node); } return true; }
bool drwnFactor::load(drwnXMLNode& xml) { // clear existing variables _variables.clear(); _varIndex.clear(); // read variables vector<int> vars; drwnXMLNode *node = xml.first_node("vars"); DRWN_ASSERT(node != NULL); drwn::parseString<int>(string(drwnGetXMLText(*node)), vars); addVariables(vars); return true; }
bool drwnObjectSequence::load(drwnXMLNode& xml) { clear(); for (drwnXMLNode *node = xml.first_node("drwnObjectList"); node != NULL; node = node->next_sibling("drwnObjectList")) { DRWN_ASSERT(!drwnIsXMLEmpty(*node) && (node->first_attribute("id") != NULL)); string id = string(node->first_attribute("id")->value()); if (this->find(id) != this->end()) { DRWN_LOG_ERROR("duplicate id \"" << id << "\" in drwnObjectSequence"); continue; } drwnObjectSequence::iterator it = this->insert(make_pair(id, drwnObjectList())).first; it->second.load(*node); } return true; }
bool drwnCondSuffStats::load(drwnXMLNode& xml) { DRWN_ASSERT(drwnGetXMLAttribute(xml, "n") != NULL); int n = atoi(drwnGetXMLAttribute(xml, "n")); DRWN_ASSERT(drwnGetXMLAttribute(xml, "k") != NULL); int k = atoi(drwnGetXMLAttribute(xml, "k")); DRWN_ASSERT(drwnCountXMLChildren(xml, "drwnSuffStats") == k); clear(n, k); bool bSuccess = true; drwnXMLNode *node = NULL; for (int i = 0; i < k; i++) { node = (i == 0) ? xml.first_node("drwnSuffStats") : node->next_sibling("drwnSuffStats"); bSuccess = bSuccess && _stats[i].load(*node); } return bSuccess; }
bool drwnKMeans::load(drwnXMLNode& node) { drwnUnsupervisedTransform::load(node); DRWN_ASSERT(drwnGetXMLAttribute(node, "k") != NULL); _numClusters = atoi(drwnGetXMLAttribute(node, "k")); drwnXMLNode *child = node.first_node("centroids"); DRWN_ASSERT(child != NULL); drwnXMLUtils::deserialize(*child, _centroids); DRWN_ASSERT((_centroids.rows() == (int)_numClusters) || (_centroids.rows() == 0)); DRWN_ASSERT((_centroids.cols() == _nFeatures) || (_centroids.cols() == 0)); // compute centroid norms _cSqNorm = VectorXd::Zero(_numClusters); for (int k = 0; k < (int)_numClusters; k++) { _cSqNorm[k] = _centroids.row(k).squaredNorm(); } return true; }