示例#1
0
int main(int argc, char **argv) {
	Gfx gfx;
	Model model;
	
	if(argc != 2) {
		printf("Invalid count of arguments!\nUsage %s FILENAME\n", argv[0]);
		return 1;
	}

	if(load_map(argv[1], &model))
		return 1;
	model_static_field(&model);
	gfx_init(&gfx, model.w, model.h);
	double t = SDL_GetTicks()/1000.-0.016;
	while(1) {
		int i;
		int nsteps = 5;

		if(gfx_event(&gfx) < 0)
			break;

		double dt = SDL_GetTicks()/1000.-t;
		dt = 0.06;
		if(nsteps < dt*C/DX*5) {
			nsteps = dt*C/DX*5+0.5;
			printf("nsteps %d\n", nsteps);
			if(nsteps > 30)
				nsteps = 30;
		}

		for(i = 0; i < nsteps; i++)
			model_update(&model, dt/nsteps);
		
		double rho = 0;
		int x, y;
		for(x = 0; x < model.w; x++) {
			for(y = 0; y < model.h; y++) {
				rho += model.rho[y*model.w+x];
			}
		}		
		double tdt = SDL_GetTicks()/1000.-t;
		t = SDL_GetTicks()/1000.;
		printf("%f fps aval = %g\n", 1./tdt, model.phi[model.tp][model.h/2*model.w+model.w*8/10-2]);
		gfx_draw(&gfx, &model);
	}

	gfx_deinit(&gfx);
	model_free(&model);

	return 0;
}
示例#2
0
文件: megahal.c 项目: lp0/sqlhal
static int megahal_learn(brain_t brain, list_t *input) {
	uint_fast32_t i;
	uint32_t size;
	number_t order;
	model_t *model;
	int ret;
	(void)brain;

	/* We only learn from inputs which are long enough */
	ret = db_model_get_order(brain, &order);
	if (ret) return ret;

	ret = list_size(input, &size);
	if (ret) return ret;

	if (size <= order) return OK;

	ret = model_alloc(brain, &model);
	if (ret) return ret;

	/*
	 * Train the model in the forwards direction. Start by initializing
	 * the context of the model.
	 */
	ret = model_init(model, MODEL_FORWARD);
	if (ret) goto fail;

	for (i = 0; i < size; i++) {
		word_t word;

		/* Get word symbol. */
		ret = list_get(input, i, &word);
		if (ret) goto fail;

		/* Update the forward model. */
		ret = model_update(model, word, 1);
		if (ret) goto fail;
	}

	/*
	 * Add the sentence-terminating symbol.
	 */
	ret = model_update(model, 0, 1);
	if (ret) goto fail;

	/*
	 * Train the model in the backwards direction. Start by initializing
	 * the context of the model.
	 */
	ret = model_init(model, MODEL_BACKWARD);
	if (ret) goto fail;

	for (i = 0; i < size; i++) {
		word_t word;

		/* Get word symbol. */
		ret = list_get(input, (size - 1) - i, &word);
		if (ret) goto fail;

		/* Update the backward model. */
		ret = model_update(model, word, 1);
		if (ret) goto fail;
	}

	/*
	 * Add the sentence-terminating symbol.
	 */
	ret = model_update(model, 0, 1);
	if (ret) goto fail;

	model_free(&model);
	return OK;

fail:
	model_free(&model);
	return ret;
}