/****************************************************************************************/ /* */ /* Project : 1D-BRNN */ /* Release : 3.3 */ /* */ /* File : Options.cpp */ /* Description : Options to train or retrain a BRNN model */ /* */ /* Author(s) : Christophe Magnan (2013) - New generic version */ /* : Jianlin Cheng (2003) - New custom version for SCRATCH */ /* : Gianluca Pollastri (2001) - Customized version for SCRATCH */ /* : Paolo Frasconi (1997) - Initial generic version */ /* */ /* Copyright : Institute for Genomics and Bioinformatics */ /* University of California, Irvine */ /* */ /* Modified : 2015/07/01 */ /* */ /****************************************************************************************/ #include "Options.h" /*******************************************/ /* Interface */ /*******************************************/ // Constructor Options::Options() : FEATURES(-1),CLASSES(-1),HIDDEN(-1),CONTEXT_FWD(-1), CONTEXT_BWD(-1),OUTPUTS_FWD(-1),OUTPUTS_BWD(-1), HIDDEN_FWD(-1),HIDDEN_BWD(-1),LEARN_RATE(-1.0), NUM_EPOCHS(-1),NUM_BATCHS(-1),ADAP_EPOCHS(-1), ADAP_RELOAD(-1),SHUFFLE(-1),SEED(-1){} // Destructor Options::~Options(){} // Display option values on screen void Options::display() { if(FEATURES!=-1) { cerr << "\n MODEL OPTIONS:\n\n"; cerr << " FEATURES = " << FEATURES << "\n"; cerr << " CLASSES = " << CLASSES << "\n"; cerr << " HIDDEN = " << HIDDEN << "\n"; cerr << " CONTEXT_FWD = " << CONTEXT_FWD << "\n"; cerr << " CONTEXT_BWD = " << CONTEXT_BWD << "\n"; cerr << " OUTPUTS_FWD = " << OUTPUTS_FWD << "\n"; cerr << " OUTPUTS_BWD = " << OUTPUTS_BWD << "\n"; cerr << " HIDDEN_FWD = " << HIDDEN_FWD << "\n"; cerr << " HIDDEN_BWD = " << HIDDEN_BWD << "\n"; } cerr << "\n TRAINING OPTIONS:\n\n"; cerr << " LEARN_RATE = " << LEARN_RATE << "\n"; cerr << " NUM_EPOCHS = " << NUM_EPOCHS << "\n"; cerr << " NUM_BATCHS = " << NUM_BATCHS << "\n"; cerr << " ADAP_EPOCHS = " << ADAP_EPOCHS << "\n"; cerr << " ADAP_RELOAD = " << ADAP_RELOAD << "\n"; cerr << " SHUFFLE = " << SHUFFLE << "\n"; cerr << " SEED = " << SEED << "\n\n"; } // Load option values void Options::load(char* filein,int model) { filebuf in_buffer; if(in_buffer.open(filein,ios::in)!=0) { istream is(&in_buffer); char option[100]; while(is){ is >> option; if(!strcmp(option,"FEATURES")){ is >> FEATURES; } else if(!strcmp(option,"CLASSES")){ is >> CLASSES; } else if(!strcmp(option,"HIDDEN")){ is >> HIDDEN; } else if(!strcmp(option,"CONTEXT_FWD")){ is >> CONTEXT_FWD; } else if(!strcmp(option,"CONTEXT_BWD")){ is >> CONTEXT_BWD; } else if(!strcmp(option,"OUTPUTS_FWD")){ is >> OUTPUTS_FWD; } else if(!strcmp(option,"OUTPUTS_BWD")){ is >> OUTPUTS_BWD; } else if(!strcmp(option,"HIDDEN_FWD")){ is >> HIDDEN_FWD; } else if(!strcmp(option,"HIDDEN_BWD")){ is >> HIDDEN_BWD; } else if(!strcmp(option,"LEARN_RATE")){ is >> LEARN_RATE; } else if(!strcmp(option,"NUM_EPOCHS")){ is >> NUM_EPOCHS; } else if(!strcmp(option,"NUM_BATCHS")){ is >> NUM_BATCHS; } else if(!strcmp(option,"ADAP_EPOCHS")){ is >> ADAP_EPOCHS; } else if(!strcmp(option,"ADAP_RELOAD")){ is >> ADAP_RELOAD; } else if(!strcmp(option,"SHUFFLE")){ is >> SHUFFLE; } else if(!strcmp(option,"SEED")){ is >> SEED; } } in_buffer.close(); } else{ cerr << "Cannot read file \"" << filein << "\"\n"; exit(1); } if((SEED<=0)||(SEED>=10000000)){ SEED=time(NULL)%10000000; } if(model){ check_model_viability(); } else{ FEATURES=-1; } check_training_viability(); } /*******************************************/ /* Methods */ /*******************************************/ // Check the viability of the options to create a new model void Options::check_model_viability() { if(FEATURES<1){ cerr << "ERROR : option FEATURES missing or incorrect.\n"; exit(1); } if(CLASSES<2){ cerr << "ERROR : option CLASSES missing or incorrect.\n"; exit(1); } if(HIDDEN<1){ cerr << "ERROR : option HIDDEN missing or incorrect.\n"; exit(1); } if(CONTEXT_FWD<0){ cerr << "ERROR : option CONTEXT_FWD missing or incorrect.\n"; exit(1); } if(CONTEXT_BWD<0){ cerr << "ERROR : option CONTEXT_BWD missing or incorrect.\n"; exit(1); } if(OUTPUTS_FWD<1){ cerr << "ERROR : option OUTPUTS_FWD missing or incorrect.\n"; exit(1); } if(OUTPUTS_BWD<1){ cerr << "ERROR : option OUTPUTS_BWD missing or incorrect.\n"; exit(1); } if(HIDDEN_FWD<1){ cerr << "ERROR : option HIDDEN_FWD missing or incorrect.\n"; exit(1); } if(HIDDEN_BWD<1){ cerr << "ERROR : option HIDDEN_BWD missing or incorrect.\n"; exit(1); } } // Check the viability of the options to train or retrain a BRNN void Options::check_training_viability() { if((LEARN_RATE<=0)||(LEARN_RATE>1)){ cerr << "ERROR : option LEARN_RATE missing or incorrect.\n"; exit(1); } if(NUM_EPOCHS<1){ cerr << "ERROR : option NUM_EPOCHS missing or incorrect.\n"; exit(1); } if(NUM_BATCHS<1){ cerr << "ERROR : option NUM_BATCHS missing or incorrect.\n"; exit(1); } if(ADAP_EPOCHS<0){ cerr << "ERROR : option ADAP_EPOCHS missing or incorrect.\n"; exit(1); } if(ADAP_RELOAD<0){ cerr << "ERROR : option ADAP_RELOAD missing or incorrect.\n"; exit(1); } if(SHUFFLE<0){ cerr << "ERROR : option SHUFFLE missing or incorrect.\n"; exit(1); } if((SEED<=0)||(SEED>=10000000)){ cerr << "ERROR : option SEED missing or incorrect.\n"; exit(1); } }