void Outputs::create_test_outputs 
		(stringvec const& words, Outputs& old, double smooth, int seed) 
{
	
	srand(seed);
	outmap::const_iterator it = old.f.begin();
	int c (it->second.size());

	for (stringvec::const_iterator it (words.begin()); it != words.end(); ++it) 
	{
		// if the word isn't already in the old maps...
		if (old.f.find(*it) == old.f.end()) {
		
			update_f(old.f, smooth);
			
			// fill f and g
			double sum (0);
			for (int i (0); i < c; ++i) {
				f[*it].push_back(smooth);
				double grand ((double)rand() / RAND_MAX);
				g[*it].push_back(grand);
				sum += grand;
			}
			
			normalize(g[*it], sum);
			
		}
	}
	
	f.insert(old.f.begin(), old.f.end());
	g.insert(old.g.begin(), old.g.end());
	
}
Example #2
0
// Draws multple lines of text on screen given the pixel location of the top left corner
void DrawText2Pix(stringvec lines, int x, int y) {
	int add = 0;
	for (stringvec::iterator it = lines.begin(); it != lines.end(); ++it) {
		DrawText2Pix(*it, x, y + add);
		add += fontSize + fontSep;
	}
}
// fill f and g with random doubles
void Outputs::initialize (stringvec const& words, int c, int seed) {

	srand(seed);
	double* fsum = new double[c];
	
	for (stringvec::const_iterator it (words.begin()); it != words.end(); ++it) 
	{
	
		double gsum (0);
		
		for (int i (0); i < c; ++i) {
		
			double frand = ((double)rand() / RAND_MAX);
			double grand = ((double)rand() / RAND_MAX);
			
			f[*it].push_back(frand);
			g[*it].push_back(grand);
			
			fsum[i] += frand;
			gsum += grand;
			
		}
		
		normalize(g[*it], gsum);
		
	}
	
	//normalize f
	for (int i (0); i < c; ++i) {
		for (outmap::iterator it = f.begin(); it != f.end(); ++it) {
			it->second[i] /= fsum[i];
		}
	}
	
}
Example #4
0
int es3::do_cat(context_ptr context, const stringvec& params,
		 agenda_ptr ag, bool help)
{
	if (help)
	{
		std::cout << "Cat syntax: es3 cat <PATHS>\n"
				  << "where <PATHS> are:\n"
				  << "\t - Amazon S3 storage (in s3://<bucket>/path/fl format)"
				  << std::endl << std::endl;
		return 0;
	}
	if (params.empty())
	{
		std::cerr << "ERR: at least one <PATH> must be specified.\n";
		return 2;
	}

	for(auto iter=params.begin();iter!=params.end();++iter)
	{
		bf::path tmp_nm = context->scratch_dir_ /
				bf::unique_path("scratchy-cat-%%%%-%%%%-%%%%-%%%%-dl");
		ON_BLOCK_EXIT(unlink, tmp_nm.c_str());
		
		s3_path remote=parse_path(*iter);
		s3_connection conn(context);
		std::string region=conn.find_region(remote.bucket_);
		remote.zone_=region;
				
		sync_task_ptr task(new file_downloader(context, tmp_nm, remote, false));	
		ag->schedule(task);
		size_t failed=ag->run();
		if (failed)
			return 6;
		
		if (ag->tasks_count())
		{
			ag->print_epilog(); //Print stats, so they're at least visible
			std::cerr << "ERR: ";
			ag->print_queue();
			return 4;
		}
		
		handle_t fl(open(tmp_nm.c_str(), O_RDWR) 
					| libc_die2("Failed to open "+tmp_nm.string()));
		
		fflush(stdout);
		while(true)
		{
			char buf[16385];
			int res=read(fl.get(), buf, 16384);
			if (res<0)
				res | libc_die;
			if (res==0)
				break;
			
			int written=write(1, buf, res);
			if (written!=res)
			{
				std::cerr << "ERR: failed to write "<<res<<" bytes to stdout";
				return 5;
			}
		}
	}
	
	return 0;
}