bool SelfOrganizingMap::load( std::fstream &file ){ //Clear any previous model clear(); std::string word; file >> word; if( word != "GRT_SELF_ORGANIZING_MAP_MODEL_FILE_V1.0" ){ errorLog << "load(fstream &file) - Failed to load file header!" << std::endl; return false; } if( !loadClustererSettingsFromFile( file ) ){ errorLog << "load(fstream &file) - Failed to load cluster settings from file!" << std::endl; return false; } file >> word; if( word != "NetworkTypology:" ){ errorLog << "load(fstream &file) - Failed to load NetworkTypology header!" << std::endl; return false; } file >> networkTypology; file >> word; if( word != "AlphaStart:" ){ errorLog << "load(fstream &file) - Failed to load AlphaStart header!" << std::endl; return false; } file >> alphaStart; file >> word; if( word != "AlphaEnd:" ){ errorLog << "load(fstream &file) - Failed to load alphaEnd header!" << std::endl; return false; } file >> alphaEnd; //Load the model if it has been trained if( trained ){ file >> word; if( word != "Neurons:" ){ errorLog << "load(fstream &file) - Failed to load Neurons header!" << std::endl; return false; } neurons.resize(numClusters,numClusters); for(UINT i=0; i<neurons.getNumRows(); i++){ for(UINT j=0; j<neurons.getNumCols(); j++){ if( !neurons[i][j].load( file ) ){ errorLog << "load(fstream &file) - Failed to save neuron to file!" << std::endl; return false; } } } } return true; }
bool HierarchicalClustering::loadModelFromFile( std::fstream &file ){ std::string word; //Clear any previous model clear(); file >> word; if( word != "GRT_HIERARCHICAL_CLUSTERING_FILE_V1.0" ){ return false; } if( !loadClustererSettingsFromFile( file ) ){ errorLog << "loadModelFromFile(fstream &file) - Failed to load cluster settings from file!" << std::endl; return false; } return true; }
bool KMeans::loadModelFromFile( std::fstream &file ){ //Clear any previous model clear(); if(!file.is_open()){ errorLog << "loadModelFromFile(string filename) - Failed to open file!" << std::endl; return false; } std::string word; file >> word; if( word != "GRT_KMEANS_MODEL_FILE_V1.0" ){ return false; } if( !loadClustererSettingsFromFile( file ) ){ errorLog << "loadModelFromFile(string filename) - Failed to open file!" << std::endl; return false; } if( trained ){ file >> word; if( word != "Clusters:" ){ return false; } //Resize the buffers clusters.resize(numClusters,numInputDimensions); //Load the data for(UINT k=0; k<numClusters; k++){ for(UINT n=0; n<numInputDimensions; n++){ file >> clusters[k][n]; } } } return true; }
bool GaussianMixtureModels::loadModelFromFile( std::fstream &file ){ //Clear any previous model clear(); std::string word; file >> word; if( word != "GRT_GAUSSIAN_MIXTURE_MODELS_FILE_V1.0" ){ return false; } if( !loadClustererSettingsFromFile( file ) ){ errorLog << "loadModelFromFile(fstream &file) - Failed to load cluster settings from file!" << std::endl; return false; } //Load the model if( trained ){ //Setup the memory mu.resize(numClusters, numInputDimensions); sigma.resize(numClusters); invSigma.resize(numClusters); det.resize(numClusters); //Load mu file >> word; if( word != "Mu:" ){ clear(); errorLog << "loadModelFromFile(fstream &file) - Failed to load Mu!" << std::endl; return false; } for(UINT k=0; k<numClusters; k++){ for(UINT n=0; n<numInputDimensions; n++){ file >> mu[k][n]; } } //Load Sigma file >> word; if( word != "Sigma:" ){ clear(); errorLog << "loadModelFromFile(fstream &file) - Failed to load Sigma!" << std::endl; return false; } for(UINT k=0; k<numClusters; k++){ sigma[k].resize(numInputDimensions, numInputDimensions); for(UINT i=0; i<numInputDimensions; i++){ for(UINT j=0; j<numInputDimensions; j++){ file >> sigma[k][i][j]; } } } //Load InvSigma file >> word; if( word != "InvSigma:" ){ clear(); errorLog << "loadModelFromFile(fstream &file) - Failed to load InvSigma!" << std::endl; return false; } for(UINT k=0; k<numClusters; k++){ invSigma[k].resize(numInputDimensions, numInputDimensions); for(UINT i=0; i<numInputDimensions; i++){ for(UINT j=0; j<numInputDimensions; j++){ file >> invSigma[k][i][j]; } } } //Load Det file >> word; if( word != "Det:" ){ clear(); errorLog << "loadModelFromFile(fstream &file) - Failed to load Det!" << std::endl; return false; } for(UINT k=0; k<numClusters; k++){ file >> det[k]; } //Setup the cluster labels clusterLabels.resize(numClusters); for(UINT i=0; i<numClusters; i++){ clusterLabels[i] = i+1; } clusterLikelihoods.resize(numClusters,0); clusterDistances.resize(numClusters,0); } return true; }