7#include "../Branch/BranchRecord.h"
8#include <boost/serialization/export.hpp>
9#include "../Global/SimulationContext.h"
10#include <boost/archive/binary_oarchive.hpp>
11#include <boost/archive/binary_iarchive.hpp>
18 const uint32_t n_sym =
static_cast<uint32_t
>(
symptoms.size());
19 const uint32_t n_evt =
static_cast<uint32_t
>(
events.size());
21 for (
const auto& s :
symptoms) {
const double c = s->getConfidence(); ar << c; }
22 for (
const auto&
e :
events) {
const double c =
e->getConfidence(); ar << c; }
25 uint32_t n_sym = 0, n_evt = 0;
28 throw std::runtime_error(
"EventSymptomMatrix state overlay: unit counts mismatch against the seeded matrix");
30 for (
auto& s :
symptoms) { ar >> c; s->setConfidence(c); }
31 for (
auto&
e :
events) { ar >> c;
e->setConfidence(c); }
68 ifstream fin(_file_name.c_str(), ios::in);
70 cout <<
"File: " << _file_name <<
" cound not be found" << endl;
71 ofstream fout(
"err messages.txt", ios::app);
72 fout <<
r5pars_.timesno <<
" File: " << _file_name <<
" cound not be found\n";
81 auto symptoms_ptr = make_unique<SymptomUnit>();
82 symptoms_ptr->readInfoFromFile(fin);
83 symptoms.push_back(std::move(symptoms_ptr));
87 auto events_ptr = make_unique<DiagnosisEventUnit>();
89 events.push_back(std::move(events_ptr));
102 symptom_name = symptom->getSymptomName();
106 if(symptom_name == (*hwd_itr)->getInfoName()){
109 x = ((*hwd_itr)->getConfidenceLevel());
110 symptom->setConfidence(x);
118 ofstream fout(
"err messages.txt", ios::app);
119 cout <<
"EventSymptomMatrix::updateRationalSymptomConfidence symptom: " << symptom_name <<
" could not be found." << endl;
120 fout <<
r5pars_.timesno <<
" EventSymptomMatrix::updateRationalSymptomConfidence symptom: " << symptom_name <<
" could not be found.\n";
130 int i, j, num_perceived_symptoms, num_symptoms_explained;
131 double x,symptom_confidence, relationship_value, upper, lower, correction;
133 num_perceived_symptoms = 0;
135 if (
symptoms.at(i)->getConfidence() > 0.1) {
136 num_perceived_symptoms = num_perceived_symptoms + 1;
139 for(j = 0; j <
events.size(); j++){
142 num_symptoms_explained = 0;
143 events_pt =
events.at(j).get();
144 for(i = 0; i <
symptoms.size(); i++){
145 symptom_confidence =
symptoms.at(i)->getConfidence();
147 if ((relationship_value * symptom_confidence ) > 0.01) {
148 num_symptoms_explained = num_symptoms_explained + 1;
150 upper = fmin(upper, fmax(0.0, fmin(1.0, symptom_confidence + 1.0 - relationship_value)));
151 if(relationship_value > 0.0001){
158 if (x > symptom_confidence) {
159 lower = fmin(lower, symptom_confidence);
163 correction = num_symptoms_explained / (num_perceived_symptoms + 0.0001);
179 double confidence = 0.0;
180 if (_str ==
"Not_Applicable")
184 auto event_itr = this->
events.begin();
185 while (event_itr != this->
events.end() && ! found) {
186 if ((*event_itr)->getDiagnosisName() == _str) {
188 confidence = (*event_itr)->getConfidence();
196 ofstream fout(
"err messages.txt", ios::app);
197 cout <<
"EventSymptomMatrix::getEventRationalConfidence: " << _str <<
" could not be found." << endl;
198 fout <<
r5pars_.timesno <<
" EventSymptomMatrix::getEventRationalConfidence: " << _str <<
" could not be found.\n";
217 for(i = 0; i <
symptoms.size(); i++){
218 str1 = _str +
symptoms.at(i)->getSymptomName();
219 fout <<
'\t' << str1;
221 for(i = 0; i <
events.size(); i++){
222 str1 = _str +
events.at(i)->getDiagnosisName();
223 fout <<
'\t' << str1;
231 for(i = 0; i <
symptoms.size(); i++){
232 fout <<
"\tConfidence";
234 for(i = 0; i <
events.size(); i++){
236 fout <<
"\tConfidence";
245 auto symptoms_pt = make_unique<SymptomUnit>();
246 symptoms_pt->copySymptomUnit(*src);
247 this->
symptoms.push_back(std::move(symptoms_pt));
249 for(
auto& src : _esm.
events){
250 auto events_pt = make_unique<DiagnosisEventUnit>();
251 events_pt->copyDiagnosisEventUnit(*src);
252 this->
events.push_back(std::move(events_pt));
257 fout <<
"EventSymptomMatrix "
264 symptom->saveSymptomUnitToFile(fout);
266 for(
auto& event :
events){
267 event->saveDiagnosisEventUnitToFile(fout);
272 int tn_symptom, tn_event, i;
280 if (str !=
"EventSymptomMatrix"){
281 ofstream fout(
"err messages.txt", ios::app);
282 cout <<
"EventSymptomMatrix::retrieveEventSymptomMatrixFromFile retrieval error in previous function" << endl;
283 fout <<
r5pars_.timesno <<
" EventSymptomMatrix::retrieveEventSymptomMatrixFromFile error in previous function\n";
290 for(i = 0; i < tn_symptom; i++){
291 auto symptoms_pt = make_unique<SymptomUnit>();
292 symptoms_pt->retrieveSymptomUnitFromFile(fin);
293 this->
symptoms.push_back(std::move(symptoms_pt));
295 for(i = 0; i < tn_event; i++){
296 auto events_pt = make_unique<DiagnosisEventUnit>();
297 events_pt->retrieveDiagnosisEventUnitFromFile(fin);
298 this->
events.push_back(std::move(events_pt));
SimulationContext g_sim
Global simulation context: the single instance, defined in SimulationContext.cpp.
void setTempTypeOfConsequence(Consequence)
Stores the consequence of the end state the running sequence will get.
void setTempESMessage(std::string)
Stores the description of the end state the running sequence will get if it is terminated (set by mod...
void setLowerBound(double)
void setUpperBound(double)
std::vector< double > symptom_event_relationship
void setConfidence(double)
std::string getCategoryName()
void updatePerceivedSymptomConfidence()
void updateRationalEventConfidence()
void copyEventSymptomMatrix(EventSymptomMatrix &)
double getEventRationalConfidence(std::string)
void updateBothRationalConfidence(KB &)
void setAbnormalConfidence(double)
void outputEventSymptomMatrixLabelToFile(std::string, std::ofstream &)
double getAbnormalConfidence()
void updatePerceivedEventConfidence()
void clearEventSymptomMatrix()
void readInfoFromFile(std::string)
void saveEventSymptomMatrixToFile(std::ofstream &)
virtual ~EventSymptomMatrix()
double abnormal_confidence
std::vector< std::unique_ptr< DiagnosisEventUnit > > events
void outputEventSymptomMatrixUnitToFile(std::ofstream &)
void state_save(boost::archive::binary_oarchive &ar) const
void retrieveEventSymptomMatrixFromFile(std::ifstream &)
std::vector< std::unique_ptr< SymptomUnit > > symptoms
void updateRationalSymptomConfidence(KB &)
void state_load(boost::archive::binary_iarchive &ar)
std::vector< std::unique_ptr< KBHardWiredUnit > > hard_wired_diagnosis
BranchRecord Branch_center
Dynamic event tree state.