5 #include <xercesc/dom/DOM.hpp>
16 XERCES_CPP_NAMESPACE_USE
18 using namespace PhysicsTools;
28 virtual ~ProcLinear();
30 virtual void configure(DOMElement *
elem)
override;
33 virtual void trainBegin()
override;
34 virtual void trainData(
const std::vector<double> *
values,
36 virtual void trainEnd()
override;
38 virtual bool load()
override;
39 virtual void save()
override;
50 std::auto_ptr<LeastSquares>
ls;
51 std::vector<double> vars;
52 std::vector<double> coefficients;
58 ProcLinear::ProcLinear(
const char *
name,
const AtomicId *
id,
65 ProcLinear::~ProcLinear()
69 void ProcLinear::configure(DOMElement *
elem)
73 DOMNode *
node = elem->getFirstChild();
74 while(node && node->getNodeType() != DOMNode::ELEMENT_NODE)
75 node = node->getNextSibling();
80 if (std::strcmp(
XMLSimpleStr(node->getNodeName()),
"coefficients") != 0)
82 <<
"Expected coefficients tag in config section."
85 elem =
static_cast<DOMElement*
>(
node);
88 theoffset= XMLDocument::readAttribute<double>(
elem,
"offset", 0.0);
90 coefficients.push_back(XMLDocument::readAttribute<double>(elem,
"coeff1", 1.0));
92 coefficients.push_back(XMLDocument::readAttribute<double>(elem,
"coeff2", 1.0));
105 calib->
coeffs = coefficients;
106 calib->
offset = theoffset;
113 void ProcLinear::trainBegin()
116 vars.resize(
ls->getSize());
119 void ProcLinear::trainData(
const std::vector<double> *
values,
125 for(
unsigned int i = 0;
i <
ls->getSize();
i++, values++)
126 vars[
i] = values->front();
128 ls->add(vars, target, weight);
131 void ProcLinear::trainEnd()
148 if (name ==
"linearAnalyzer")
149 return static_cast<void*
>(
ls.get());
157 if (!exists(filename))
161 DOMElement *elem = xml.getRootNode();
162 if (std::strcmp(
XMLSimpleStr(elem->getNodeName()),
"ProcLinear") != 0)
164 <<
"XML training data file has bad root node."
167 DOMNode *node = elem->getFirstChild();
168 while(node && node->getNodeType() != DOMNode::ELEMENT_NODE)
169 node = node->getNextSibling();
173 <<
"Train data file empty." << std::endl;
175 ls->load(static_cast<DOMElement*>(node));
177 node = elem->getNextSibling();
178 while(node && node->getNodeType() != DOMNode::ELEMENT_NODE)
179 node = node->getNextSibling();
183 <<
"Train data file contains superfluous tags."
193 XMLDocument xml(trainer->trainFileName(
this,
"xml"),
true);
194 DOMDocument *
doc = xml.createDocument(
"ProcLinear");
196 xml.getRootNode()->appendChild(
ls->save(doc));
MVATrainerComputer * calib
static bool hasAttribute(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *elem, const char *name)
tuple size
Write out results.