示例#1
0
//display the ori/pos arrays for this animal
void AnimalClass::display()
{
    IOFormat CommaInitFmt(StreamPrecision, DontAlignCols, ", ", ", ", "", "", " << ", ";");
    unsigned numChromosomePair = G.get_num_chrom();
    for(unsigned i=0;i<numChromosomePair;i++){
        cout<<"These are positions on chromosome "<<i<<" for pat"<<endl;
        cout<< GenomePat[i].pos.format(CommaInitFmt)<<endl;
        cout<<"These are origins on chromosome "<<i<<" for pat"<<endl;
        cout<< GenomePat[i].ori.format(CommaInitFmt)<<endl;
        cout<<"These are positions on chromosome "<<i<<" for mat"<<endl;
        cout<< GenomeMat[i].pos.format(CommaInitFmt)<<endl;
        cout<<"These are origins on chromosome "<<i<<" for mat"<<endl;
        cout<< GenomeMat[i].ori.format(CommaInitFmt)<<endl;
    }
};
示例#2
0
void Word2Vec::save_word2vec(string filename, const RMatrixXf& data, bool binary)
{
	IOFormat CommaInitFmt(StreamPrecision, DontAlignCols);

	if(binary)
	{
		std::ofstream out(filename, std::ios::binary);
		char blank = ' ';
		char enter = '\n'; 
		int size = sizeof(char);
		int r_size = data.cols() * sizeof(RMatrixXf::Scalar);

		std::string head = std::string(std::to_string(vocab.size()) + " " + std::to_string(data.cols()) + "\n");
		out.write(head.c_str(),head.length());
		
		RMatrixXf::Index r = data.rows();
		RMatrixXf::Index c = data.cols();
		out.write((char*) &r, sizeof(RMatrixXf::Index));
		out.write(&blank, size);
		out.write((char*) &c, sizeof(RMatrixXf::Index));
		out.write(&enter, size);

		for(auto v: vocab)
		{
			out.write(v->text.c_str(), v->text.size());
			out.write(&blank, size);
			out.write((char*) data.row(v->index).data(), r_size);
			out.write(&enter, size);
		}
		out.close();
	}
	else
	{
		ofstream out(filename);

		out << data.rows() << " " << data.cols() << std::endl;

		for(auto v: vocab)
		{
			out << v->text << " " << data.row(v->index).format(CommaInitFmt) << endl;;
		}
		out.close();
	}
}