Пример #1
0
bool SMDTable::open( FILE* file,int offset,unsigned short pageSize/*=4096*/,bool exists /*= true*/ )
{
    this->file = file;
    this->offset = offset;

    if(exists && !checkFlag())
    {
        return false;
    }

    if(!exists)
    {
        saveFlag(pageSize);
    }

    if(pageMgr != NULL) delete pageMgr;

    pageMgr = new SMDPageManagement(this,exists,pageSize);
    if(pageMgr == NULL)
    {
        return false;
    }

    // 初始化各个段结构
    segMeta = new SMDMetaSegment(pageMgr);
    segTable = new SMDTableSegment(pageMgr);
    segData = new SMDDataSegment(segTable,pageMgr);
    segIndex = new SMDIndexSegment(pageMgr);
    return true;
}
Пример #2
0
int main(int argc, char* argv[])
{
	if (argc != 2 && argc != 3)
	{
		cout << "usage rnnlib [-s | --save] config_file" << endl;
		exit(0);
	}
	bool autosave = false;
	string configFilename;
	if (argc == 3)
	{
		string saveFlag(argv[1]);
		autosave = (saveFlag == "-s" || saveFlag == "--save");
		configFilename = argv[2];
	}
	else
	{
		configFilename = argv[1];
	}
	ConfigFile conf(configFilename);
#ifdef FAST_LOGISTIC
	Logistic::fill_lookup();
#endif
	string task = conf.get<string>("task");
	if (task == "transcription" && conf.has("dictionary"))
	{
		task = conf.set<string>("task", "dictionary_transcription");
	}
	bool display = conf.get<bool>("display", false);
	vector<int> jacobianCoords = conf.get_list<int>("jacobianCoords");
	bool gradCheck = conf.get<bool>("gradCheck", false);
	verbose = conf.get<bool>("verbose", false);
	int displaySequence = conf.get<int>("sequence", 0);
	string dataset = conf.get<string>("dataset", "train");
	check(in(validDatasets, dataset), 
		  dataset + " given as 'dataset' parameter in config file '" 
		  + configFilename + "'\nmust be one of '" + str(validDatasets) + "'");
	string dataFileString = dataset + "File";
	string saveName = "";
	ofstream* logout = 0;
	TeeDev* tdev = 0;
	TeeStream* tout = 0;
	string displayPath = "";
	string logname = "";
	if (display || jacobianCoords.size())
	{
		displayPath = conf.get<string>("displayPath");
		logname = displayPath + "log";
	} 
	else if (autosave)
	{
		if (in (conf.filename, '@'))
		{
			saveName = conf.filename.substr(0, conf.filename.find('@'));
		}
		else
		{
			saveName = conf.filename.substr(0, conf.filename.rfind('.'));
		}
		saveName += "@" + time_stamp();
		logname = saveName + ".log";
	}
	if (autosave || display || jacobianCoords.size())
	{
		logout = new ofstream(logname.c_str());
		check(logout->is_open(), "can't open log file " + logname);
		tdev = new TeeDev(cout, *logout);
		tout = new TeeStream(*tdev);
		cout << "writing to log file " << logname << endl;
	}
	ostream& out = tout ? *tout : cout;
	vector<string> dataFiles = conf.get_list<string>(dataFileString);
	int dataFileNum = conf.get<int>("dataFileNum", 0);
	check(dataFiles.size() > dataFileNum, "no " + ordinal(dataFileNum) + " file in size " + str(dataFiles.size()) + " file list " + dataFileString + " in " + configFilename);
	DataHeader header(dataFiles[dataFileNum], task, 1);
	DataSequence* testSeq = 0;
	if (display || gradCheck || jacobianCoords.size())
	{
		NetcdfDataset* data = new NetcdfDataset(dataFiles[dataFileNum], task, displaySequence);
		testSeq = new DataSequence((*data)[0]);
		delete data;
	}
	Mdrnn *net;
	if (task == "code")
	{
		net = new CodeNet(out, conf, header);
	}
	else if (task == "memory")
	{
		net = new MemoryNet(out, conf, header);
	}
	else if (task == "pm")
	{
		net = new PmNet(out, conf, header);
	}
	else
	{
		net = new MultilayerNet(out, conf, header);
	}
	out << endl << "network:" << endl;
	PRINT(task, out);
	out << *net;
	
	//build weight container after net is created
	WeightContainer::instance().build();
	int numWeights = WeightContainer::instance().weights.size();
	out << numWeights << " weights" << endl << endl;
	
	//build the network after the weight container
	net->build();
	
	//only construct optimiser after weight container is built
	Optimiser* opt;
	if (conf.get<string>("optimiser", "steepest") == "rprop")
	{
		opt = new Rprop(out);
	}
	else
	{
		opt = new SteepestDescent(out, conf.get<double>("learnRate", 1e-4), conf.get<double>("momentum", 0.9));
	}
	Trainer trainer(out, net, opt, conf);
	out << "setting random seed to " << Random::set_seed(conf.get<unsigned long int>("randSeed", 0)) << endl << endl;
	if (conf.get<bool>("loadWeights", false))
	{
		out << "loading dynamic data from "  << conf.filename << endl;
		DataExportHandler::instance().load(conf, out);
		out << "epoch = " << trainer.epoch << endl << endl;
	}
	double initWeightRange = conf.get<double>("initWeightRange", 0.1);
	out << "randomising uninitialised weights with mean 0 std. dev. " << initWeightRange << endl << endl;
	WeightContainer::instance().randomise(initWeightRange);	
	out << "optimiser:" << endl << *opt << endl;
	if (gradCheck)
 	{
		out << "data header:" << endl << header << endl;
		out << "running gradient check for sequence " << displaySequence << endl;
		out << *testSeq; 
		prt_line(out);
 		GradientCheck(out, net, *testSeq, conf.get<int>("sigFigs", 6), 
			conf.get<double>("pert", 1e-5), conf.get<bool>("verbose", false));
 	}
	else if (jacobianCoords.size())
	{
		out << "data header:" << endl << header << endl;
		out << "calculating Jacobian for sequence " << displaySequence << " at coords " << jacobianCoords << endl;
		out << *testSeq; 
		out << "output path: " << endl << displayPath << endl;
		net->feed_forward(*testSeq);
		net->print_output_shape(out);
		net->outputLayer->outputErrors.get(jacobianCoords) = net->outputLayer->outputActivations.get(jacobianCoords);
		net->feed_back();
		DataExportHandler::instance().display(displayPath);
	}
	else if (display)
	{
		out << "data header:" << endl << header << endl;
		out << "displaying sequence " << displaySequence << endl;
		out << *testSeq; 
		out << "output path: " << endl << displayPath << endl;
		net->train(*testSeq);
		net->print_output_shape(out);
		out << "errors:" << endl << net->outputLayer->errorMap;
		DataExportHandler::instance().display(displayPath);
	}
	else if (conf.get<bool>("errorTest", false))
	{
		trainer.calculate_all_errors();
	}
	else
	{
		out << "trainer:" << endl;
		trainer.train(saveName);
	}
	if (logout)
	{
		delete logout;
	}
	if (tdev)
	{
		delete tdev;
	}
//	if (tout)
//	{
//		delete tout;
//	}
	delete net;
	delete opt;
}
Пример #3
0
void ofApp::onButtonEvent(ofxDatGuiButtonEvent e)
{
	if (e.target->is("SAVE FLAG")) {
		saveFlag();
	}
}