예제 #1
0
파일: FC_cv.cpp 프로젝트: jfahren/BayesX
double FC_cv::compute_logscore(void)
  {

  unsigned s,i;

//  ofstream out("c:\\bayesx\\testh\\results\\sampled_likelihood.res");
//  sampled_likelihood.prettyPrint(out);

  unsigned S = sampled_likelihood.cols();       // S = number of samples
  unsigned I = sampled_likelihood.rows();       // I = number of observations
                                                // i-th row, s-th column contains
                                                // log-likelihood of i-th
                                                // observation in sample s

  if (log_score.rows() != nrcat)
    log_score = datamatrix(nrcat,1,0);

  datamatrix lhelp(nrcat,S,0);

  unsigned in;

  for (i=0;i<I;i++)
    {

    in = ind(i,0);

    for (s=0;s<S;s++)
      {
      lhelp(in,s) += sampled_likelihood(i,s);
      }



//    log_score(in,0) = log(S) - log(log_score(in,0));
    }


  for (i=0;i<nrcat;i++)
    {
    log_score(i,0) = 0;
    for (s=0;s<S;s++)
      log_score(i,0) +=  exp(lhelp(i,s));

    log_score(i,0) = log(static_cast<double>(S)) - log(log_score(i,0));
    }

  return log_score.mean(0);

  }
예제 #2
0
void
loser(const PLANE *p, const char *s)
{
    int			c;
    struct itimerval	itv;

    /* disable timer */
    itv.it_value.tv_sec = 0;
    itv.it_value.tv_usec = 0;
    setitimer(ITIMER_REAL, &itv, NULL);

    wmove(input, 0, 0);
    wclrtobot(input);
    wprintw(input, "Plane '%c' %s\n\nHit space for top players list...",
            name(p), s);
    wrefresh(input);
    fflush(stdout);
    while ((c = getchar()) != EOF && c != ' ')
        ;
    clear();	/* move to top of screen */
    refresh();
    endwin();
    log_score(0);
    exit(0);
}
예제 #3
0
void
quit(void)
{
    int			c, y, x;
    struct itimerval	itv;

    getyx(input, y, x);
    wmove(input, 2, 0);
    waddstr(input, "Really quit? (y/n) ");
    wclrtobot(input);
    wrefresh(input);
    fflush(stdout);

    c = getchar();
    if (c == EOF || c == 'y') {
        /* disable timer */
        itv.it_value.tv_sec = 0;
        itv.it_value.tv_usec = 0;
        setitimer(ITIMER_REAL, &itv, NULL);
        fflush(stdout);
        clear();
        refresh();
        endwin();
        log_score(0);
        exit(0);
    }
    wmove(input, 2, 0);
    wclrtobot(input);
    wmove(input, y, x);
    wrefresh(input);
    fflush(stdout);
}
static int mate_score_child(int infileno, int outfileno)
{
	struct command cmd;
	gchar* level;
	gchar* realname;
	gint retval;

	#ifdef HAVE_SETFSGID
	   gid_t gid;

	   gid = getegid();
	   setgid(getgid());
	   setfsgid(gid);
	#endif

	realname = g_strdup(g_get_real_name());

	if (strcmp(realname, "Unknown") == 0)
	{
		g_free(realname);
		realname = g_strdup(g_get_user_name());
	}

	while (read(infileno, &cmd, sizeof cmd) == sizeof(cmd))
	{
		level = g_new (char, cmd.level);

		if (read(infileno, level, cmd.level) != cmd.level)
		{
			g_free(realname);

			return EXIT_FAILURE;
		}

		if (!*level)
		{
			g_free(level);
			level = NULL;
		}

		retval = log_score(defgamename, level, realname, cmd.score, cmd.ordering);

		if (write(outfileno, &retval, sizeof retval) != sizeof retval)
		{
			g_free(realname);
			return EXIT_FAILURE;
		}

		g_free(level);
	}

	g_free(realname);

	return EXIT_SUCCESS;
}
예제 #5
0
void game (void)
{
  int lives = MAX_LIVES;
  int score = 0;
  long int level_score;
  int level = START_LEVEL;
  int result;

  do {
    result = play_level (level, &level_score, lives, score);
    /* The level has been played, now we must check to see what happened, display an appropriate
       message to the terminal if necessary, add up points, etc */
    
    switch (result)
      {	
      case MSG_WINLEVEL:
	score+= level_score;
	level++;
	display_message (result, lives, level, score);
	break;
      case MSG_WINGAME:
	score+= level_score;
	level++; /* This is for the log_score function */
	game_win ();
	
	lives = 0; /* This lets us get out of this function */
	
	/* Display ending message, then go back to menu */
	ansi_PutString (1, 25, "Done.");
	wait_for_select ();
	break;
      case MSG_QUIT: return;
      default: /* We know the users aircraft has crashed in some way, so deduct one life and display a message */
	lives--;
	display_message (result, lives, level, score);
	break;
      }
  } while (lives > 0);

#ifndef __ANDROID__
  log_score (score, level); /* This records the score of anyone who finishes or runs out of lives */
#endif // __ANDROID__
}
예제 #6
0
void log_score_quit(int dummy UNUSED)
{
    log_score(0);
    exit(0);
}
예제 #7
0
파일: log.c 프로젝트: ilyak/openbsd
void
log_score_quit(int dummy)
{
	(void)log_score(0);
	exit(0);
}
예제 #8
0
파일: main.c 프로젝트: jyin0813/OpenBSD-src
int
main(int ac, char *av[])
{
	int			f_usage = 0, f_list = 0, f_showscore = 0;
	int			f_printpath = 0;
	const char		*file = NULL;
	char			*name, *ptr, *seed;
	struct sigaction	sa;
	gid_t			gid;
#ifdef BSD
	struct itimerval	itv;
#endif

	open_score_file();

	/* revoke privs */
	gid = getgid();
	setresgid(gid, gid, gid);

	start_time = time(0);
	makenoise = 1;
	seed = NULL;

	name = *av++;
	while (*av) {
#ifndef SAVEDASH
		if (**av == '-') 
			++*av;
		else
			break;
#endif
		ptr = *av++;
		while (*ptr) {
			switch (*ptr) {
			case '?':
			case 'u':
				f_usage++;
				break;
			case 'l':
				f_list++;
				break;
			case 's':
			case 't':
				f_showscore++;
				break;
			case 'p':
				f_printpath++;
				break;
			case 'q':
				makenoise = 0;
				break;
			case 'r':
				seed = *av;
				av++;
				break;
			case 'f':
			case 'g':
				file = *av;
				av++;
				break;
			default: 
				warnx("unknown option '%c'", *ptr);
				f_usage++;
				break;
			}
			ptr++;
		}
	}
	if (seed != NULL)
		srandom(atol(seed));
	else
		srandomdev();

	if (f_usage)
		fprintf(stderr, 
		    "usage: %s [-lpqstu?] [-f game] [-g game] [-r seed]\n",
		    name);
	if (f_showscore)
		log_score(1);
	if (f_list)
		list_games();
	if (f_printpath) {
		size_t	len;
		char	buf[256];

		strlcpy(buf, _PATH_GAMES, sizeof buf);
		len = strlen(buf);
		if (len != 0 && buf[len - 1] == '/')
			buf[len - 1] = '\0';
		puts(buf);
	}
		
	if (f_usage || f_showscore || f_list || f_printpath)
		exit(0);

	if (file == NULL)
		file = default_game();
	else
		file = okay_game(file);

	if (file == NULL || read_file(file) < 0)
		exit(1);

	setup_screen(sp);

	addplane();

	signal(SIGINT, quit);
	signal(SIGQUIT, quit);
#ifdef BSD
	signal(SIGTSTP, SIG_IGN);
	signal(SIGSTOP, SIG_IGN);
#endif
	signal(SIGHUP, log_score_quit);
	signal(SIGTERM, log_score_quit);

	tcgetattr(fileno(stdin), &tty_start);
	tty_new = tty_start;
	tty_new.c_lflag &= ~(ICANON|ECHO);
	tty_new.c_iflag |= ICRNL;
	tty_new.c_cc[VMIN] = 1;
	tty_new.c_cc[VTIME] = 0;
	tcsetattr(fileno(stdin), TCSADRAIN, &tty_new);

	memset(&sa, 0, sizeof sa);
	sa.sa_handler = update;
	sigemptyset(&sa.sa_mask);
	sigaddset(&sa.sa_mask, SIGALRM);
	sigaddset(&sa.sa_mask, SIGINT);
	sa.sa_flags = 0;
	sigaction(SIGALRM, &sa, (struct sigaction *)0);

#ifdef BSD
	itv.it_value.tv_sec = 0;
	itv.it_value.tv_usec = 1;
	itv.it_interval.tv_sec = sp->update_secs;
	itv.it_interval.tv_usec = 0;
	setitimer(ITIMER_REAL, &itv, NULL);
#endif
#ifdef SYSV
	alarm(sp->update_secs);
#endif

	for (;;) {
		if (getcommand() != 1)
			planewin();
		else {
#ifdef BSD
			itv.it_value.tv_sec = 0;
			itv.it_value.tv_usec = 0;
			setitimer(ITIMER_REAL, &itv, NULL);
#endif
#ifdef SYSV
			alarm(0);
#endif

			update(0);

#ifdef BSD
			itv.it_value.tv_sec = sp->update_secs;
			itv.it_value.tv_usec = 0;
			itv.it_interval.tv_sec = sp->update_secs;
			itv.it_interval.tv_usec = 0;
			setitimer(ITIMER_REAL, &itv, NULL);
#endif
#ifdef SYSV
			alarm(sp->update_secs);
#endif
		}
	}
}
예제 #9
0
파일: FC_cv.cpp 프로젝트: jfahren/BayesX
void FC_cv::outresults(ofstream & out_stata, ofstream & out_R,
                            const ST::string & pathresults)
  {


  if (pathresults.isvalidfile() != 1)
    {

    FC::outresults(out_stata,out_R,pathresults);

    optionsp->out("  Marshall-Spiegelhalter Cross Validation: \n",true);
    optionsp->out("\n");

    optionsp->out("    Estimated individual observation samples are stored in\n");
    optionsp->out("    " +  pathresults + "\n");
    optionsp->out("\n");


    ST::string pathresults_like = pathresults.substr(0,pathresults.length()-4)+
                                  "_like.res";

    FC_sampled_l.outresults(out_stata,out_R,pathresults_like);

    optionsp->out("    Estimated individual observation likelihoods are stored in\n");
    optionsp->out("    " +  pathresults_like + "\n");
    optionsp->out("\n");



//    unsigned nrobs = sampled_etas.rows();
    unsigned i;

    /*
    ofstream outres(pathresults.strtochar());

    for(j=0;j<sampled_etas.cols();j++)
      outres << "s_eta_" << (j+1) << "  ";

    for(j=0;j<sampled_etas.cols();j++)
      outres << "s_resp_" << (j+1) << "  ";

    outres << endl;

    for (i=0;i<nrobs;i++)
      {

      for(j=0;j<sampled_etas.cols();j++)
        outres << sampled_etas(i,j) << "  ";

      for(j=0;j<sampled_responses.cols();j++)
        outres << sampled_responses(i,j) << "  ";

      outres << endl;

      }
     */

    // Energy score

    double es = compute_energyscore();


    ST::string pathresults_e = pathresults.substr(0,pathresults.length()-4)+
                               "_energy.res";


    ofstream out2(pathresults_e.strtochar());
    out2 << "id   score" << endl;

    for (i=0;i<e_score.rows();i++)
      out2 << effectvalues[i] << "  " << e_score(i,0) << endl;

    // Log-score


    double ls = compute_logscore();

    ST::string pathresults_l = pathresults.substr(0,pathresults.length()-4)+
                               "_logscore.res";

    ofstream out3(pathresults_l.strtochar());
    out3 << "id   score" << endl;

    for (i=0;i<e_score.rows();i++)
      out3 << effectvalues[i] << "  " << log_score(i,0) << endl;

    optionsp->out("    Estimated energy scores are stored in\n");
    optionsp->out("    " +  pathresults_e + "\n");
    optionsp->out("\n");

    optionsp->out("    Estimated log-scores are stored in\n");
    optionsp->out("    " +  pathresults_l + "\n");
    optionsp->out("\n");

    optionsp->out("    Mean energy score: " + ST::doubletostring(es,8) + "\n");
    optionsp->out("    Mean log score: " + ST::doubletostring(ls,8) + "\n");


    }   // end if (pathresults.isvalidfile() != 1)


  }
예제 #10
0
파일: main.c 프로젝트: Gwenio/DragonFlyBSD
int
main(int argc __unused, char *argv[])
{
	int                     seed = 0;
	int			f_usage = 0, f_list = 0, f_showscore = 0;
	int			f_printpath = 0;
	const char		*file = NULL;
	char			*p_name, *ptr;
	struct itimerval	itv;

	/* Open the score file then revoke setgid privileges */
	open_score_file();
	setregid(getgid(), getgid());

	start_time = time(0);

	p_name = *argv++;
	while (*argv) {
#ifndef SAVEDASH
		if (**argv == '-')
			++*argv;
		else
			break;
#endif
		ptr = *argv++;
		while (*ptr) {
			switch (*ptr) {
			case '?':
			case 'u':
				f_usage++;
				break;
			case 'l':
				f_list++;
				break;
			case 's':
			case 't':
				f_showscore++;
				break;
			case 'p':
				f_printpath++;
				break;
			case 'r':
				srandom(atoi(*argv));
				seed = 1;
				argv++;
				break;
			case 'f':
			case 'g':
				file = *argv;
				argv++;
				break;
			default:
				fprintf(stderr, "Unknown option '%c'\n", *ptr);
				f_usage++;
				break;
			}
			ptr++;
		}
	}
	if (!seed)
		srandomdev();

	if (f_usage)
		fprintf(stderr,
		    "Usage: %s -[u?lstp] [-[gf] game_name] [-r random seed]\n",
			p_name);
	if (f_showscore)
		log_score(1);
	if (f_list)
		list_games();
	if (f_printpath) {
		char	buf[100];

		strcpy(buf, _PATH_GAMES);
		buf[strlen(buf) - 1] = '\0';
		puts(buf);
	}

	if (f_usage || f_showscore || f_list || f_printpath)
		exit(0);

	if (file == NULL)
		file = default_game();
	else
		file = okay_game(file);

	if (file == NULL || read_file(file) < 0)
		exit(1);

	init_gr();
	setup_screen(sp);

	addplane();

	signal(SIGINT, (sig_t)quit);
	signal(SIGQUIT, (sig_t)quit);
	signal(SIGTSTP, SIG_IGN);
	signal(SIGSTOP, SIG_IGN);
	signal(SIGHUP, (sig_t)log_score);
	signal(SIGTERM, (sig_t)log_score);

	tcgetattr(fileno(stdin), &tty_start);
	bcopy(&tty_start, &tty_new, sizeof(tty_new));
	tty_new.c_lflag &= ~(ICANON|ECHO);
	tty_new.c_cc[VMIN] = 1;
	tty_new.c_cc[VTIME] = 0;
	tcsetattr(fileno(stdin), TCSANOW, &tty_new);
	signal(SIGALRM, (sig_t)update);

	itv.it_value.tv_sec = 0;
	itv.it_value.tv_usec = 1;
	itv.it_interval.tv_sec = sp->update_secs;
	itv.it_interval.tv_usec = 0;
	setitimer(ITIMER_REAL, &itv, NULL);

	for (;;) {
		if (getcommand() != 1)
			planewin();
		else {
			itv.it_value.tv_sec = 0;
			itv.it_value.tv_usec = 0;
			setitimer(ITIMER_REAL, &itv, NULL);

			update();

			itv.it_value.tv_sec = sp->update_secs;
			itv.it_value.tv_usec = 0;
			itv.it_interval.tv_sec = sp->update_secs;
			itv.it_interval.tv_usec = 0;
			setitimer(ITIMER_REAL, &itv, NULL);
		}
	}
}