Commit db2f5570 authored by Adrien Dorsaz's avatar Adrien Dorsaz

Fix storage and restore data.

parent 6e82069c
......@@ -77,31 +77,39 @@ QMap<double, double>& NaiveBayesClassifier::getTotalFeatureOccurences() const{
}
QDataStream &operator<<(QDataStream &out, const NaiveBayesClassifier &naiveBayes){
QMap<QString, QMap<double,double>*>* trainedClasses =
new QMap<QString, QMap<double,double>*>(naiveBayes.getTrainedClasses());
qDebug()<<"size : "<<naiveBayes.getTrainedClasses().size();
out<<naiveBayes.getTrainedClasses().size();
qDebug()<<"size : "<<naiveBayes._trainedClasses->size();
foreach(QString klass, trainedClasses->keys()){
out<<naiveBayes._trainedClasses->size();
foreach(QString klass, naiveBayes._trainedClasses->keys()){
out<<klass;
out<<*(trainedClasses->value(klass));
out<<naiveBayes._trainedClasses->value(klass)->keys().size();
foreach(double feature, (naiveBayes._trainedClasses->value(klass)->keys())){
out<<feature<<naiveBayes._trainedClasses->value(klass)->value(feature);
}
}
out << naiveBayes.getTotalFeatureOccurences();
out << *(naiveBayes._totalFeatureOccurrences);
return out;
}
QDataStream &operator>>(QDataStream &in, NaiveBayesClassifier &naiveBayes){
int sizeMap;
naiveBayes._trainedClasses=new QMap<QString,QMap<double, double>*>();
QMap<double, double> totalFeatureOccurences;
in >> sizeMap;
for(int i=0;i<sizeMap;++i){
QMap<double, double> trainedValue;
QString trainedKey;
in >> trainedKey >> trainedValue;
naiveBayes._trainedClasses->insert(trainedKey, &trainedValue);
int nbTrainedClasses;
in >> nbTrainedClasses;
for(int i=0;i<nbTrainedClasses;++i){
QString klass;
QMap<double,double>* features = new QMap<double,double>();
int nbFeatures;
in >> klass;
in>>nbFeatures;
naiveBayes._trainedClasses->insert(klass, features);
for(int j=0;j<nbFeatures;++j){
double feature;
double occFeature;
in >> feature >> occFeature;
features->insert(feature, occFeature);
}
}
in >> *(naiveBayes._totalFeatureOccurrences);
return in;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment