//============================================================================ double push(network net, shared_ptr<vector<sample>> dataSet) { vector<double> input; vector<double> expected; vector<double> actual; double correct = 0; int i = 0; vector<sample>::iterator currentSample = dataSet->begin(); //network dnet(data.getTableName(), data.getAttributeCount(), data.getCatagoryCount(), HIDDEN_LAYERS, LAYER_SIZE); while(currentSample != dataSet->end()){ //currentSample->printSample(); input = currentSample->getValues(); expected = m_typeToVector[currentSample->getClassification()]; actual = net.push(input); if (m_data.classVector(m_data.getCatagoryCount(), catagorize(actual)) == expected) correct++; if (i % 10 == 0 && !m_quiet) { cout << "Actual = "; printVector(actual); cout << " "; cout << "Expected = "; printVector(expected); if (m_data.classVector(m_data.getCatagoryCount(), catagorize(actual)) != expected){ cout << " x"; } cout << endl; } i++; currentSample++; } double total = m_data.getSampleCount(); double percent = (correct / total) * 100; cout << correct << "/" << total << " = " << percent << "% correct." << endl; return percent; }
//------------------------------------ // The parse method: Way too long. // Note that flag args are pushed // onto the stack, then the regular // args are appended, sorting them // to the rear the way getopt() does. //------------------------------------ Boolean getoopt::parse( int argc, char** argv) { Optarg o; int cat; const flagspec* fs; Arg_List nonflagargs; enum States {START, ARGEXPECTED}; States state = START; for (unsigned int i = 1; i < (unsigned int)argc; i++) { unsigned int endsize = static_cast<unsigned int>(strlen(argv[i])); switch (state) { case START: cat = catagorize(argv[i]); switch (cat) { case 0: // non-flag command line argument addarg(nonflagargs, "", Optarg::REGULAR, argv[i]); break; case 1: // short (1-character) flag { if(endsize == 1) { MessageLoaderParms parms( "getoopt.getoopt.MISSING_OPTION", "Missing required option for $0", argv[i]); addError(MessageLoader::getMessage(parms)); break; } unsigned int argpos = 1; while (argpos < endsize) { char c = argv[i][argpos]; fs = getFlagspec(c); // Short flag String temp = argv[i]; String name = temp.subString(argpos, 1); // See if we recognize it if (!fs) { MessageLoaderParms parms( "getoopt.getoopt.UNKNOWN_FLAG", "Unknown flag $0$1", "-", name); addError(MessageLoader::getMessage(parms)); argpos++; } else { // Should this flag be bound? if (fs->argtype == NOARG) { // NO addarg(_args, name, Optarg::FLAG, ""); argpos++; } else { // YES -- the value is here or in the next arg optargFromShortOpt(o, &argv[i][argpos]); if (o.Value() == "") { // No value yet state = ARGEXPECTED; } else { addarg(_args, o); } argpos = endsize; } } } break; } // end subcase 1 case 2: // long (--xyz) flag { String arg = &(argv[i][2]); optargFromLongOpt(o, arg); fs = getFlagspec(o.getName()); // see if we recognize this flag if (!fs) { MessageLoaderParms parms( "getoopt.getoopt.UNKNOWN_FLAG", "Unknown flag $0$1", "", o.getName()); addError(MessageLoader::getMessage(parms)); } else { // this is a long flag we know about if (o.optarg() != "" || fs->argtype != MUSTHAVEARG) { addarg(_args, o); state = START; // we have a completed long flag } else { // no value yet, and we expect one if (fs->argtype == MUSTHAVEARG) { state = ARGEXPECTED; } } } break; } // end subcase 2 } // end switch catagorize() break; // end of case START case ARGEXPECTED: if (argv[i][0] == '-') { MessageLoaderParms parms( "getoopt.getoopt.MISSING_VALUE_FOR_FLAG", "Missing required value for flag $0", o.getopt()); addError(MessageLoader::getMessage(parms)); i--; } else { o.setValue(argv[i]); } addarg(_args, o); state = START; break; } // end switch } // end for if (state != START) { MessageLoaderParms parms( "getoopt.getoopt.MISSING_VALUE_FOR_FLAG", "Missing required value for flag $0", o.getName()); addError(MessageLoader::getMessage(parms)); } copyargs(_args, nonflagargs); return !_errorStrings.size(); }