int main(int argc, char* argv[])
{
    cout << "starting ..." << endl;
    string xmlPath = "./main.xml";
    XmlConfigurator xmlconf;
    xmlconf.Load(xmlPath, "main");

    int flaredepth;
    int machdepth;
    int machtimeout;
    double flareangle;
    double machangle;
    string flarename = "";

    xmlconf.GetVar("missions.flare.vars@flaredepth",flaredepth);
    xmlconf.GetVar("missions.flare.vars@flareangle",flareangle);
    xmlconf.GetVar("missions.flare.vars@missionname",flarename);

    xmlconf.GetVar("missions.machinegunnest.vars@machdepth",machdepth);
    xmlconf.GetVar("missions.machinegunnest.vars@machtimeout",machtimeout);
    xmlconf.GetVar("missions.machinegunnest.vars@machangle",machangle);

    cout << "Flare Angle: " << flareangle << endl;
    cout << "Flare Depth: " << flaredepth << endl;
    cout << "Mission Name: " << flarename << endl;
    cout << "Machine Gun Depth: " << machdepth << endl;
    cout << "Machine Gun Time Out: " << machtimeout << endl;
    cout << "Machine Gun Angle: " << machangle << endl;


    cout.flush();

    return 0;
}
Example #2
0
int main(int argc, char** argv) {

    string filename;
    string outfile = "";
	string type = "";
	string xmlpath = "";
    int numIn,numHid,numOut, numTrain, numVal, numTest, numRuns;
	bool useValidation = true;
	XmlConfigurator params;

#ifdef USE_NEW_CMDLINE

	vector<string> allowedTypes;
	allowedTypes.push_back("CC");
	allowedTypes.push_back("BP");
	ValuesConstraint<string> allowedType (allowedTypes);
	vector<string> validationOptions;
	validationOptions.push_back("T");
	validationOptions.push_back("F");
	ValuesConstraint<string> boolOptions (validationOptions);

	try {
		CmdLine cmd("JRNN_test: Single run experimental executable.", ' ', "0.87");
		UnlabeledValueArg<string> inFilename("filename", "The datafile path", true, "", "string", cmd);
		UnlabeledValueArg<int> inNumTrain("numTrain", "Number of training points", true, 0, "int", cmd);
		UnlabeledValueArg<int> inNumVal("numVal", "Number of validation points", true, 0, "int", cmd);
		UnlabeledValueArg<int> inNumTest("numTest", "Number of testing points", true, 0, "int", cmd);
		UnlabeledValueArg<int> inNumIn("numIn", "Number of in nodes", true, 0, "int", cmd);
		UnlabeledValueArg<int> inNumHid("numHid", "Number of hidden nodes", true, 0, "int", cmd);
		UnlabeledValueArg<int> inNumOut("numOut", "Number of out nodes", true, 0, "int", cmd);
		UnlabeledValueArg<string> inType("type", "Type of neural network CC or BP", true, "CC", &allowedType, cmd);
		UnlabeledValueArg<string> inUseValidation("inValidation", "Use validation T or F", true, "T", &boolOptions, cmd);
		UnlabeledValueArg<string> inOutfile("outfile", "The outfile path", true, "", "string", cmd);
		UnlabeledValueArg<int> inNumRuns("numRuns", "Number runs", true, 2, "int", cmd);
		UnlabeledValueArg<string> inXmlPath("xmlpath", "The xml parameters file path", true, "", "string", cmd);

		cmd.parse(argc,argv);

		filename = inFilename.getValue();
		numTrain = inNumTrain.getValue();
		numVal = inNumVal.getValue();
		numTest = inNumTest.getValue();
		numIn = inNumIn.getValue();
		numHid = inNumHid.getValue();
		numOut = inNumOut.getValue();
		type = inType.getValue();
		useValidation = (inUseValidation.getValue() == "T") ? true : false;
		outfile = inOutfile.getValue();
		numRuns = inNumRuns.getValue();
		xmlpath = inXmlPath.getValue();

	}
	catch (TCLAP::ArgException &e) {
		cout << "error: " << e.error() << " for arg " << e.argId() << endl;
	}

#else
    if (argc != 13){
        cout << "Incorrect Arguments" << endl;
		cout << "Proper Syntax: JRNN_test <filename> <numTrain> <numVal> <numTest> <numIn> <numHid> <numOut> <type = 'BP' or 'CC'> <validate = 'T' or 'F'> <outfilename> <numRuns> <xmlconfigpath>" << endl;
		cout << "The number of training, validation, and testing points must be less than the number of points in the test set." << endl;
        return -1;
    }
    else {
        filename = argv[1];
        numTrain = lexical_cast<int>(argv[2]);
        numVal = lexical_cast<int>(argv[3]);
        numTest = lexical_cast<int>(argv[4]);
		numIn = lexical_cast<int>(argv[5]);
		numHid = lexical_cast<int>(argv[6]);
		numOut = lexical_cast<int>(argv[7]);
		type = string(argv[8]);
		if (type != "CC" && type != "BP"){
			cout << "Type must be 'CC' or 'BP'" << endl;
			return -1;
		}

		useValidation = (string(argv[9]) == "T") ? true : false;

		outfile = string(argv[10]);
		
		numRuns = lexical_cast<int>(argv[11]);

		xmlpath	= string(argv[12]);

        /*outfile = filename;
		outfile.replace(outfile.end()-4,outfile.end()," ");
		outfile += type;
        outfile += " results.txt";*/
    }

#endif

    fstream myfile;
    myfile.open(outfile.c_str(),fstream::out);
	if (myfile.is_open() == false){
		cout << "Output file Not open: " << outfile.c_str() << endl;
		return -1;
	}
    DatasetPtr ds(new Dataset());
	//FFMLPNetwork netBuilder(numIn, numHid, numOut);
    ds->LoadFromFile(filename, numIn,numOut);
	if (ds->GetSize(Dataset::ALL) == 0){
		cout << "input file not loaded" << endl;
		return -1;
	}
    ds->DistData(numTrain,numVal,numTest);
    //NetworkPtr net = Network::CreateFFMLPNetwork(numIn,numHid,numOut);

	double rPropEtaPlus = 1.2;
	double rPropEtaMinus = 0.5;
	int rPropMaxEpochs = 3000;
	double rPropMinError = 0.04;

	int ccMaxEpochs = 3000;
	int ccNumCands = 8;
	bool xmlLoaded = false;
	bool parmsOptional = true;

#ifdef DEBUG
	parmsOptional = false;
#endif

	if (params.Load(xmlpath,"params")){
#ifdef DEBUG
		cout << "Loading parameters from xml" << endl;
#endif
		params.GetVar("rProp.params@etaPlus",rPropEtaPlus, parmsOptional);
		params.GetVar("rProp.params@etaMinus",rPropEtaMinus, parmsOptional);
		params.GetVar("rProp.params@maxEpochs",rPropMaxEpochs, parmsOptional);
		params.GetVar("rProp.params@minError",rPropMinError, parmsOptional);

		params.GetVar("CC.params@maxEpochs", ccMaxEpochs, parmsOptional);
		params.GetVar("CC.params@numCands", ccNumCands, parmsOptional);
		xmlLoaded = true;
	}




	if (type == "BP")
	{
		FFMLPNetPtr net = FFMLPNetwork::Create();
		net->Build(numIn,numHid,numOut);
		//net.printConnections();
	//    BackPropTrainer bp(net, ds, 0.01);
		RPropTrainer bp(net, ds, rPropEtaPlus, rPropEtaMinus);
	//    cout << bp.trainEpoch() << endl;
		int skips = 0;
		for (int i = 0; i < numRuns;){
			//bp.trainToConvergence(0.1, 1000);
			double time = 0.0;
			clock_t startTime = clock();
			if (useValidation){
				bp.TrainToValConv(rPropMaxEpochs);
			}
			else {
				bp.TrainToConvergence(rPropMinError, rPropMaxEpochs);
			}
			time = (clock() - startTime)/(double)CLOCKS_PER_SEC;
			int epochs = bp.GetEpochs();
			myfile << epochs << "\t";
			myfile << time << "\t";
			//cout << epochs << "\t";
			myfile << numHid << "\t";
			//cout << numHid << "\t";
			hashedDoubleMap testresults = bp.TestWiClass(Dataset::TEST);
			std::pair<string,double> p;
			BOOST_FOREACH(p, testresults){
				myfile << p.first << ":" << p.second << "\t";
				//cout << p.first << ":" << p.second << "\t";
			}
			myfile << "|\t";
			printDoubles(bp.GetMSERec(),myfile);
			myfile << endl;
			//cout << endl;
			i++;
			bp.Reset();
		}
	}