Esempio n. 1
0
int close_lang_model_wt_cf_lm_nsim(int inst)
{
	long ctype ;

    PRINT_TRACE (2, print_string, "Trace: entering close_lang_model_wt_cf_lm_nsim");

	if ( collstats_info != NULL ) {
		for (ctype = 0; ctype < doc_desc.num_ctypes; ctype++) {
		    if (NULL != collstats_info[ctype].freq)
    			free(collstats_info[ctype].freq);
		}

		free(collstats_info) ;
	}

	if (NULL != conwt_buf)
		free(conwt_buf) ;

	if ( collstats_fd != NULL )
		free(collstats_fd) ;

	if (totalDocFreq)
		free(totalDocFreq);

    PRINT_TRACE (2, print_string, "Trace: leaving close_lang_model_wt_cf_lm_nsim");
    return (1);
}
/*
 * Mount the dump device
 * Return:    0 - ok
 *         != 0 - error
 */
static int mount_dump_device(void)
{
	int pid;
	char dump_part[16];

	PRINT_TRACE("e2fsck\n");
	sprintf(dump_part, "%s%i", DEV_SCSI, atoi(g.parm_part));

	pid = fork();
	if (pid < 0) {
		PRINT_PERR("fork failed\n");
		return -1;
	} else if (pid == 0) {
		execl("/bin/e2fsck", "e2fsck", dump_part, "-y", NULL);
		execl("/sbin/e2fsck", "e2fsck", dump_part, "-y", NULL);
		exit(1);
	} else {
		waitpid(pid, NULL, 0);
	}

	PRINT_TRACE("mount\n");
	if (mount(dump_part, DUMP_DIR, "ext3", 0, NULL) == 0)
		return 0;
	if (mount(dump_part, DUMP_DIR, "ext2", 0, NULL) != 0) {
		PRINT_PERR("mount failed\n");
		return -1;
	}
	return 0;
}
Esempio n. 3
0
/* 	This procedure assignes a score based on the language model.
	score(d) = product over all terms (
			lamda(i). P(d). P(t|d) +
			(1-lambda(i).P(t|Collection))
	where lambda(i) is the chance that the ith term is important in the query.
*/
int lang_model_wt_cf_lm_nsim(VEC* invec, VEC* outvec, int inst)
{
    CON_WT *invec_conwt_ptr, *outvec_conwt_ptr, *startInVec, *startOutVec ;
	float ratio ;
	float docLength ;
	long  ctype ; 

    PRINT_TRACE (2, print_string, "Trace: entering lang_model_wt_cf_lm_nsim");

   /* If no outvec is passed, we'll reweight the invec in place */
    if (outvec == NULL)
    	outvec = invec;
    else {
    	if (invec->num_conwt > num_conwt_buf) {
			if (NULL == (conwt_buf = Realloc( conwt_buf,
                          invec->num_conwt, CON_WT )))
        	return (UNDEF);
        	num_conwt_buf = invec->num_conwt;
		}
    }
    bcopy ((char *) invec->con_wtp,
           (char *) conwt_buf,
           (int) invec->num_conwt * sizeof (CON_WT));

    outvec->id_num = invec->id_num;
    outvec->num_ctype = invec->num_ctype;
    outvec->num_conwt = invec->num_conwt;
    outvec->con_wtp   = conwt_buf;
    outvec->ctype_len = invec->ctype_len ;
                                                                                   
	/* 	ptr->wt is the term frequency of the ith term.
		This number is divided by the total number of words in
		the document to get the probability of occurence of this term
		i.e. P(t|d).
		calculate: summation over ( log (1 + (0.5*tf(i)*totalDocFreq / (0.5*cf(i)*doc_len))) )  
	*/
	for ( 	ctype = 0, startInVec = invec->con_wtp, startOutVec = outvec->con_wtp;
			ctype < invec->num_ctype;
			startInVec += invec->ctype_len[ctype], startOutVec += outvec->ctype_len[ctype], ctype++) {

		docLength = (float)getDocumentLength(invec, ctype);

	    for (	invec_conwt_ptr = startInVec, outvec_conwt_ptr = startOutVec;
				invec_conwt_ptr - startInVec < invec->ctype_len[ctype];
				invec_conwt_ptr++, outvec_conwt_ptr++) {

			ratio = lambda*invec_conwt_ptr->wt/(float)docLength +
					(1-lambda)*collstats_info[ctype].freq[invec_conwt_ptr->con]/(float)totalDocFreq[ctype];
			outvec_conwt_ptr->con = invec_conwt_ptr->con ; 
			outvec_conwt_ptr->wt = log(ratio) ;
    	}
	}

    PRINT_TRACE (2, print_string, "Trace: leaving lang_model_wt_cf_lm_nsim");
    return 1 ;
}
Esempio n. 4
0
int main (int argc, char *argv[])
{
    PRINT_TRACE (1, "Lancement du jeu");
    GameInitializer::init_game();

    MainMenu *menu = new MainMenu();
    delete menu;

    GameInitializer::close_game();
    PRINT_TRACE (1, "Fermeture du jeu");
    return 0;
}
Esempio n. 5
0
/* Input: time value in t which stores the expiry time relative to a fixed reference point.
 * Output: time remaining to expiration as absolute number of sec/usec relative to now.
 */
static void
bcmseclib_translate_expiry_to_absolute(exp_time_t *t)
{
	bcmseclib_time_t now;

	memset(&now, 0, sizeof(now));
	bcmseclib_os_get_time(&now);
	if (bcmseclib_compare_times(&now, t) >= 0) {
		t->sec = t->usec = 0;
		return;
	}

	PRINT_TRACE(("t->sec %ld t->usec %ld now.sec %ld now.usec %ld\n",
		t->sec, t->usec, now.sec, now.usec));


	t->sec -= now.sec;
	t->usec -= now.usec;

	/* Handle underflow. */
	if (t->usec < 0) {
		t->sec -= 1;
		t->usec += 1000000;
	}

	ASSERT(t->sec >= 0);
	ASSERT(t->usec >= 0);

}
/*
 * Get dump parameters from /proc/cmdline
 * Return: 0       - ok
 *         (!= 0)  - error
 */
static int parse_parmline(void)
{
	int fh, i, count, token_cnt;
	char *token;
	char *parms[KERN_PARM_MAX];

	/* setting defaults */

	g.parm_compress = PARM_COMP_DFLT;
	g.parm_dir      = PARM_DIR_DFLT;
	g.parm_part     = PARM_PART_DFLT;
	g.parm_debug    = PARM_DEBUG_DFLT;
	g.parm_mode     = PARM_MODE_NUM_DFLT;
	g.parm_mem      = PARM_MEM_DFLT;

	fh = open(PROC_CMDLINE, O_RDONLY);
	if (fh == -1) {
		PRINT_PERR("open %s failed\n", PROC_CMDLINE);
		return -1;
	}
	count = read(fh, g.parmline, CMDLINE_MAX_LEN);
	if (count == -1) {
		PRINT_PERR("read %s failed\n", PROC_CMDLINE);
		close(fh);
		return -1;
	}
	g.parmline[count-1] = '\0'; /* remove \n */
	token_cnt = 0;
	token = strtok(g.parmline, " \t\n");
	while (token != NULL) {
		parms[token_cnt] = token;
		token = strtok(NULL, " \t\n");
		token_cnt++;
		if (token_cnt >= KERN_PARM_MAX) {
			PRINT_WARN("More than %i kernel parmameters "
				   "specified\n", KERN_PARM_MAX);
			break;
		}
	}
	for (i = 0; i < token_cnt; i++) {
		if (parse_parameter(parms[i])) {
			close(fh);
			return -1;
		}
	}
	PRINT_TRACE("dump dir  : %s\n", g.parm_dir);
	PRINT_TRACE("dump part : %s\n", g.parm_part);
	PRINT_TRACE("dump comp : %s\n", g.parm_compress);
	PRINT_TRACE("dump debug: %d\n", g.parm_debug);
	PRINT_TRACE("dump mem:   %llx\n", (unsigned long long) g.parm_mem);

	if (g.parm_mode == PARM_MODE_AUTO_NUM)
		PRINT_TRACE("dump mode : %s\n", PARM_MODE_AUTO);
	if (g.parm_mode == PARM_MODE_INTERACT_NUM)
		PRINT_TRACE("dump mode : %s\n", PARM_MODE_INTERACT);

	sprintf(g.dump_dir, "%s/%s", DUMP_DIR, g.parm_dir);
	close(fh);
	return 0;
}
Esempio n. 7
0
int close_sentsim_lmtrlm ()
{
    PRINT_TRACE (2, print_string, "Trace: entering close_sentsim_lmtrlm");

    if (UNDEF == vec_vec_ptab->close_proc (vec_vec_inst))
	    return (UNDEF);
   	if (UNDEF == close_lang_model_wt_lm(0))
		return UNDEF;
    if (UNDEF == close_dir_array (collstats_fd))
	    return (UNDEF);
	if ( UNDEF == close_vector(doc_fd) )
		return UNDEF;
	close_lda_est(&ldamodel);
	FREE(p_w_Q);

    PRINT_TRACE (2, print_string, "Trace: leaving close_sentsim_lmtrlm");
    return (0);
}
Esempio n. 8
0
void Babar::double_jump()
{
    m_double_jump = true;
    m_ready_double_jump = false;
    PRINT_TRACE (1, "Double-saut de Babar");
    m_speed.y = -4 * BABAR_SPEED;
    Keyboard::GetInstance()->disable_key (k_jump);

}
// -------------------------------------------------------------------------------------------------
byte TriggerWidget::getValue() const
throw ()
{
    byte ret = 0;

    for (int i = 0; i < NUMBER_OF_BITS_PER_BYTE; i++)
        ret |= (m_checkboxes[i]->checkState() == Qt::Checked) << i;

    PRINT_TRACE("getValue, return %x", ret);
    return ret;
}
Esempio n. 10
0
/* Setup an existing timer with specified parms
 * and add it to the active list
 * If it's already on the active list relocate it
 * to the appropriate position
 */
void
bcmseclib_add_timer(bcmseclib_timer_t *t, uint ms, bool periodic)
{
	bcmseclib_timer_t *plist, *pprev;
	bcmseclib_timer_mgr_t *mgr;
	char *funstr = "bcmseclib_add_timer";

	(void) funstr;
	PRINT_TRACE(("%s(0x%x): duration %d periodic %d\n", funstr, (int)t->mgr, ms, periodic));

	mgr = t->mgr;

	/* If already in active list: remove it! */
	/* this call may fail: ok, just means t was not on list */
	bcm_llist_del_member(&mgr->timerlist, t);

	/* set time value and periodic flag */
	t->ms = ms;
	t->periodic = periodic;
	bcmseclib_set_expiration(ms, &t->expiry_time);

	/* place in correct position (by ascending expiry time) in active list */

	/* if list is NULL, we're the one & only */
	if (mgr->timerlist == NULL) {
		t->next = NULL;
		mgr->timerlist = t;
		goto done;
	}

	/* walk list until we find a time greater than ours, insert before that member */
	pprev = NULL;
	for (plist = mgr->timerlist; plist; ) {
		if (bcmseclib_compare_times(&t->expiry_time, &plist->expiry_time) <= 0) {
			t->next = plist;
			if (pprev == NULL)
				mgr->timerlist = t;
			else
				pprev->next = t;
			break;
		}
		pprev = plist;
		plist = plist->next;
	}

	/* end of list */
	if (plist == NULL) {
		pprev->next = t;
		t->next = NULL;
	}

done:
	return;
}
Esempio n. 11
0
/*
 * Create checksum on SCSI device
 */
static int csum_get(uint64_t off, uint64_t len, uint64_t *result)
{
	char buf[len];

	if (pread_file(DEV_SCSI, (char *)&buf, sizeof(buf), off) < 0) {
		PRINT_ERR("Error reading checksum from disk\n");
		return -1;
	}
	*result = (uint64_t)csum_partial(&buf, len, 0x12345678);
	PRINT_TRACE("Got crc %llx\n", (unsigned long long) *result);
	return 0;
}
Esempio n. 12
0
std::list<Projectile*> *Babar::fire_old (int num_player)
{
    PRINT_TRACE (2, "Tir de Babar");
    /* Calcul de la position de la source du tir */
    Rect fire_pos = position();
    fire_pos.y += SOURCE_Y;
    if ( m_dir == RIGHT )
    {
        fire_pos.x += position().w;
    }
    return m_weapons_armory.get_current_weapon()->fire (fire_pos, m_dir, (dmg_chan) (num_player + 1) );
}
Esempio n. 13
0
/* Removes member pdel from list *head if possible */
int bcm_llist_del_member(void *pplhd, void *plmember)
{
	list_t **head = (list_t **)pplhd;
	list_t *pdel = (list_t *)plmember;
	list_t *pprev, *plist;
	char *funstr = "bcm_llist_del_member";

	PRINT_TRACE(("%s: Requested to delete member %p from list %p\n",
		funstr, pdel, *head));

	if (*head == NULL) {
		PRINT_TRACE(("%s: list empty\n", funstr));
		return -1;
	}
	if (pdel == NULL) {
		PRINT(("%s: can't delete NULL member\n", funstr));
		return -1;
	}

	for (plist = *head, pprev = NULL; plist; ) {
		if (plist == pdel) {
			/* first entry? */
			if (pprev == NULL)
				*head = plist->next;
			else
				pprev->next = plist->next;

			return 0;

		}
		/* advancd */
		pprev = plist;
		plist = plist->next;
	}

	/* not found */
	PRINT_TRACE(("%s: member %p not found in list %p\n",
		funstr, pdel, *head));
	return -1;
}
Esempio n. 14
0
/* Removes member containing "arg" from list *head if possible,
 * If successful returns pointer to that member, otherwise NULL
 */
void * bcm_llist_del_membercmp(void *pplhd, void *arg, bool (*pcmp)(void *, void *))
{
	list_t **head = (list_t **)pplhd;
	list_t *pprev, *plist;
	char *funstr = "bcm_llist_del_member";

	PRINT_TRACE(("%s: Requested to delete member with %p from list %p\n",
		funstr, arg, *head));

	if (*head == NULL) {
		PRINT_TRACE(("%s: list empty\n", funstr));
		return NULL;
	}
	if (pcmp == NULL) {
		PRINT(("%s: comparison fun NULL, bailing \n", funstr));
		return NULL;
	}

	for (plist = *head, pprev = NULL; plist; ) {
		if ((*pcmp)(plist, arg)) {
			/* first entry? */
			if (pprev == NULL)
				*head = plist->next;
			else
				pprev->next = plist->next;

			return plist;

		}
		/* advancd */
		pprev = plist;
		plist = plist->next;
	}

	/* not found */
	PRINT_TRACE(("%s: member %p not found in list %p\n",
		funstr, arg, *head));
	return NULL;
}
Esempio n. 15
0
// -------------------------------------------------------------------------------------------------
double Settings::readDoubleEntry(const QString & key, double def)
    throw ()
{
    bool read = false;
    double number = m_qSettings.readDoubleEntry(key, def, &read);
    if (!read && m_doubleMap.contains(key))
        return m_doubleMap[key];
#ifdef DEBUG
    else if (!read && def == 0.0)
        PRINT_TRACE("Implicit default returned, key = %s", (const char*)key.local8Bit());
#endif
    return number;
}
Esempio n. 16
0
// -------------------------------------------------------------------------------------------------
int Settings::readNumEntry (const QString & key, int def)
    throw ()
{
    bool read = false;
    int number = m_qSettings.readNumEntry(key, def, &read);
    if (!read && m_intMap.contains(key))
        return m_intMap[key];
#ifdef DEBUG
    else if (!read && def == 0)
        PRINT_TRACE("Implicit default returned, key = %s", key.latin1());
#endif
    return number;
}
static int read_file(const char *file, char *buf, int size)
{
	int fh;

	PRINT_TRACE("Read: %s:\n", file);
	fh = open(file, O_RDONLY);
	if (fh == -1) {
		PRINT_PERR("open %s failed\n", file);
		return -1;
	}
	if (read(fh, buf, size) < 0) {
		PRINT_PERR("read %s failed\n", file);
		close(fh);
		return -1;
	}
	if (buf[strlen(buf) - 1] == '\n')
		buf[strlen(buf) - 1] = 0; /* strip newline */
	close(fh);
	PRINT_TRACE("'%s'\n", buf);

	return 0;
}
Esempio n. 18
0
// -------------------------------------------------------------------------------------------------
bool Settings::readBoolEntry(const QString & key, bool def)
    throw ()
{
    bool read = false;
    bool res = m_qSettings.readBoolEntry(key, def, &read);
    if (!read && m_boolMap.contains(key))
        return m_boolMap[key];
#ifdef DEBUG
    else if (!read && !def)
        PRINT_TRACE("Implicit default returned, key = %s", (const char*)key.local8Bit());
#endif
    return res;
}
Esempio n. 19
0
/*
 * Finds the matching partition to a given start and end. If a matching
 * partition is found, the partition number is returned.
 */
int find_part_num(uint64_t start, uint64_t size)
{
	struct hd_geometry geo;
	uint32_t block_size;
	uint64_t part_size;
	char path[11];
	int fd, i;

	PRINT_TRACE("Partiton to dump start: 0x%llx end: 0x%llx\n",
		    (unsigned long long) start, (unsigned long long) size);
	for (i = 1; i < 16; i++) {
		snprintf(path, sizeof(path), DEV_SCSI "%d", i);
		fd = open(path, O_RDONLY);
		if (fd == -1)
			continue;
		if (ioctl(fd, HDIO_GETGEO, &geo) != 0) {
			PRINT_PERR("Could not retrieve partition"
				   " geometry information\n");
			return -1;
		}
		if (ioctl(fd, BLKGETSIZE64, &part_size)) {
			PRINT_PERR("Could not retrieve partition"
				   " size information\n");
			return -1;
		}
		if (ioctl(fd, BLKSSZGET, &block_size)) {
			PRINT_PERR("Could not get blocksize");
			return -1;
		}
		PRINT_TRACE("Partiton %s start: 0x%llx end: 0x%llx\n", path,
			    (unsigned long long) geo.start * block_size,
			    (unsigned long long) part_size);
		if ((start == geo.start * block_size) && (size == part_size))
			return i;
	}
	return -1;
}
static int write_to_file(const char *file, const char *command)
{
	int fh;

	PRINT_TRACE("Write: %s - %s\n", file, command);
	fh = open(file, O_WRONLY);
	if (fh == -1) {
		PRINT_PERR("Could not open %s\n", file);
		return -1;
	}
	if (write(fh, command, strlen(command)) == -1) {
		PRINT_PERR("Write to %s failed\n", file);
		close(fh);
		return -1;
	};
	close(fh);
	return 0;
}
Esempio n. 21
0
/*
 * Read file at given offset
 */
static int pread_file(const char *path, char *buf, int size, uint64_t off)
{
	int fd;

	PRINT_TRACE("Read: %s:\n", path);
	fd = open(path, O_RDONLY);
	if (fd == -1) {
		PRINT_PERR("open %s failed\n", path);
		return -1;
	}
	if (lseek(fd, off, SEEK_SET) < 0) {
		PRINT_PERR("seek %s offset %llu failed\n", path,
			   (unsigned long long) off);
		return -1;
	}
	if (read(fd, buf, size) < 0) {
		PRINT_PERR("read %s failed\n", path);
		close(fd);
		return -1;
	}
	close(fd);
	return 0;
}
Esempio n. 22
0
void Babar::go_down()
{
    m_pos.y += 2 * BOX_SIZE;
    m_speed.y += BOX_SIZE;
    if (binded() )
    {
        while (CollisionsManager::is_down_coll (m_bind->down_collision_type (m_rel_pos) ) )
        {
            if (m_bind->double_collision (m_rel_pos) )
            {
                m_rel_pos.y -= BOX_SIZE;
                break;
            }
            else
            {
                m_rel_pos.y += BOX_SIZE;
            }
        }
    }
    else
    {
        while (CollisionsManager::is_down_coll (gCollision->get_matrix()->down_collision_type (m_pos) ) )
        {
            if (gCollision->get_matrix()->double_collision (m_pos) )
            {
                m_pos.y -= BOX_SIZE;
                break;
            }
            else
            {
                m_pos.y += BOX_SIZE;
            }
        }
    }
    unbind();
    PRINT_TRACE (1, "Descente d'une plateforme");
}
Esempio n. 23
0
void print_backtrace2(void(*stdout_function)(const char*, size_t))
{
  char _symbol_buffer[8192];
  char _btrace_buffer[8192];

  if (Elf::get_strtab() == NULL) {
    int len = snprintf(_btrace_buffer, sizeof(_btrace_buffer),
              "symtab or strtab is empty, indicating image may be stripped\n");
    write(1, _btrace_buffer, len);
  }

#if defined(__ILP32__)
  #define PRINT_TRACE(N, ra) \
    auto symb = Elf::safe_resolve_symbol(                     \
                ra, _symbol_buffer, sizeof(_symbol_buffer));  \
    int len = snprintf(_btrace_buffer, sizeof(_btrace_buffer),\
            "[%d] 0x%08x + 0x%.3x: %s\n",         \
            N, symb.addr, symb.offset, symb.name);\
            stdout_function(_btrace_buffer, len);
#elif defined(__LP64__)
  #define PRINT_TRACE(N, ra) \
    auto symb = Elf::safe_resolve_symbol(                     \
                ra, _symbol_buffer, sizeof(_symbol_buffer));  \
    int len = snprintf(_btrace_buffer, sizeof(_btrace_buffer),\
            "[%d] 0x%016lx + 0x%.3x: %s\n",       \
            N, symb.addr, symb.offset, symb.name);\
            stdout_function(_btrace_buffer, len);
#else
  #error "Implement me"
#endif

  printf("\n");
  void* ra;
  if (frp(0, ra)) {
    PRINT_TRACE(0, ra);
    if (frp(1, ra)) {
      PRINT_TRACE(1, ra);
      if (frp(2, ra)) {
        PRINT_TRACE(2, ra);
        if (frp(3, ra)) {
          PRINT_TRACE(3, ra);
          if (frp(4, ra)) {
            PRINT_TRACE(4, ra);
            if (frp(5, ra)) {
              PRINT_TRACE(5, ra);
              if (frp(6, ra)) {
                PRINT_TRACE(6, ra);
                if (frp(7, ra)) {
                  PRINT_TRACE(7, ra);
                  if (frp(8, ra)) {
                    PRINT_TRACE(8, ra);
                    if (frp(9, ra)) {
                      PRINT_TRACE(9, ra);
                      if (frp(10, ra)) {
                        PRINT_TRACE(10, ra);
                        if (frp(11, ra)) {
                          PRINT_TRACE(11, ra);
                          if (frp(12, ra)) {
                            PRINT_TRACE(12, ra);
                            if (frp(13, ra)) {
                              PRINT_TRACE(13, ra);
                              if (frp(14, ra)) {
                                PRINT_TRACE(14, ra);
  }}}}}}}}}}}}}}}
}
Esempio n. 24
0
// Read from collstat file the collection frequency in the global
// variable collstats_info.
int init_lang_model_wt_cf_lm_nsim(SPEC* spec, char* unused)
{
    DIR_ARRAY dir_array;
	long ctype ;
	char conceptName[256];
	long i;

    PRINT_TRACE (2, print_string, "Trace: entering init_lang_model_wt_cf_lm_nsim");

	// Intialize buffer to copy invec's term weights into outvec's ones
    num_conwt_buf = 8096;

	if ( NULL == (conwt_buf = (CON_WT *)
                 malloc (num_conwt_buf * sizeof (CON_WT))) )
        return (UNDEF);

	// Get the number of concepts
    if (UNDEF == lookup_spec_docdesc (spec, &doc_desc))
        return (UNDEF);

	// Initialize the array of fds for opening the collection files
	collstats_fd = (int*) malloc (sizeof(int) * doc_desc.num_ctypes) ;
	if ( collstats_fd == NULL )
		return UNDEF ;

	collstats_info = (struct coll_info*) malloc (sizeof(struct coll_info) * doc_desc.num_ctypes) ;
	if ( collstats_info == NULL )
		return UNDEF ;

    if (UNDEF == lookup_spec (spec,
                              &spec_args[0],
                              num_spec_args)) {
        return (UNDEF);
    }

	// For each concept, collect the collection frequency
	for (ctype = 0; ctype < doc_desc.num_ctypes; ctype++) {

		snprintf(conceptName, sizeof(conceptName), "ctype.%ld.", ctype) ;
		prefix = conceptName ;
    	if (UNDEF == lookup_spec_prefix (spec, spec_prefix_args, num_spec_prefix_args))
	        return (UNDEF);

	    if (! VALID_FILE (collstat_file)) {
			collstats_info[ctype].freq = NULL ;
        	collstats_info[ctype].num_freq = 0;
	    }
	    else {
   			if (UNDEF == (collstats_fd[ctype] = open_dir_array (collstat_file, collstat_mode)))
				return (UNDEF);

			// Get the frequency mode to use
			dir_array.id_num = 	COLLSTAT_TOTWT ;
 
			// Get the collection frequency list from the file
			if (1 != seek_dir_array (collstats_fd[ctype], &dir_array) ||
			    1 != read_dir_array (collstats_fd[ctype], &dir_array)) {
		    	collstats_info[ctype].freq = NULL;
			    collstats_info[ctype].num_freq = 0;
			}
			else {
				// Read from file successful. Allocate 'freq' array and dump the
				// contents of the file in this list
			    if (NULL == (collstats_info[ctype].freq = (float *)
			                 malloc ((unsigned) dir_array.num_list)))
			        return (UNDEF);
		    	(void) bcopy (dir_array.list,
		                  (char *) collstats_info[ctype].freq,
		                  dir_array.num_list);
			    collstats_info[ctype].num_freq = dir_array.num_list / sizeof (float);
			}

			if (UNDEF == close_dir_array (collstats_fd[ctype]))
				return (UNDEF);
		}
	}

	totalDocFreq = (float*) malloc (sizeof(float) * doc_desc.num_ctypes);

	// Compute the total Document Frequency only once since it is a constant.
	for (i = 0; i < doc_desc.num_ctypes; i++) {
		totalDocFreq[i] = getTotalDocFreq(i);
	}

    PRINT_TRACE (2, print_string, "Trace: leaving init_lang_model_wt_cf_lm_nsim");
    return (1);
}
Esempio n. 25
0
Camera::~Camera()
{
    PRINT_CONSTR (1, "Destruction de la camera");
    PRINT_TRACE (1, "Fermeture de la fenetre");
    delete m_window;
}
Esempio n. 26
0
int init_sentsim_lmtrlm (SPEC* spec, char* prefix)
{
	DIR_ARRAY dir_array;

    PRINT_TRACE (2, print_string, "Trace: entering init_sentsim_lmtrlm");

    /* Lookup the values of the relevant parameters */
    if (UNDEF == lookup_spec (spec, &spec_args[0], num_spec_args))
        return (UNDEF);

   	if (UNDEF == (doc_fd = open_vector (dvec_file, dvec_file_mode)))
       	return (UNDEF);

	// initalize the LM conversion module
	if (UNDEF == init_lang_model_wt_lm(spec, NULL))
		return UNDEF;
    if (UNDEF == (vec_vec_inst = vec_vec_ptab->init_proc (spec, NULL)))
	    return (UNDEF);

	if (! VALID_FILE (collstat_file)) {
		return UNDEF;
    }
    else {
		if (UNDEF == (collstats_fd = open_dir_array (collstat_file, collstat_mode)))
			return (UNDEF);

		// Read the total number of documents
        dir_array.id_num = COLLSTAT_NUMDOC; // Get the collection frequency list from the file
        if (1 != seek_dir_array (collstats_fd, &dir_array) ||
            1 != read_dir_array (collstats_fd, &dir_array)) {
			return UNDEF;
        }
        else {
			memcpy(&collstats_numdocs, dir_array.list, sizeof(long));
        }

		// Read in collection frequencies
        dir_array.id_num = COLLSTAT_TOTWT; // COLLSTAT_COLLFREQ; // ; // Get the collection frequency list from the file
        if (1 != seek_dir_array (collstats_fd, &dir_array) ||
            1 != read_dir_array (collstats_fd, &dir_array)) {
            collstats_freq = NULL;
            collstats_num_freq = 0;
			return UNDEF;
        }
        else {
            // Read from file successful. Allocate 'freq' array and dump the
            // contents of the file in this list
			collstats_freq = (float*) dir_array.list;
            collstats_num_freq = dir_array.num_list / sizeof (float);
			p_w_Q = (float*) malloc (collstats_num_freq * sizeof(float));
			if (p_w_Q == NULL)
				return UNDEF;
        }

    }
	totalDocFreq = getTotalDocumentFreq();

	if (UNDEF == init_lda_est(&ldamodel, spec)) {
		return UNDEF;
	}

    PRINT_TRACE (2, print_string, "Trace: leaving init_sentsim_lmtrlm");
    return 0;
}
Esempio n. 27
0
int sentsim_lmtrlm (Sentence* sentences, int numSentences, VEC* qvec, TR_VEC* tr)
{
	TR_TUP  *tr_tup;
	long    tr_ind, con, i;
	VEC     dvec, *svec, slmvec;
	CON_WT  *conwtp; 
	float   p_w_D, p_D_Q, docLen, totalSim = 0, trlm_comp = 0;
	Sentence* s;
	VEC_PAIR  vec_pair;

    PRINT_TRACE (2, print_string, "Trace: entering sentsim_lmtrlm");

	memset(p_w_Q, 0, collstats_num_freq * sizeof(float));
	/* Call the LDA estimator to estimate P(w|z) and P(z|d)s */
	// For the multi-faceted model the query is considered
	// as a document in the LDA space.
	if (UNDEF == init_lda_est_inst(&ldamodel, doc_fd, tr, qvec, multifaceted)) {
		fprintf(stderr, "LDA reranking failed for query %d\n", qvec->id_num.id);
		return 1;
	}
	lda_est(&ldamodel);

	for (tr_ind = 0; tr_ind < tr->num_tr; tr_ind++) {
		tr_tup = &(tr->tr[tr_ind]);
		totalSim += tr_tup->sim;
	}

	// Estimate P(w|R) for each term in the top ranked passages and then aggregate
	// the scores over sentences...
	for (tr_ind = 0; tr_ind < tr->num_tr; tr_ind++) {
		tr_tup = &(tr->tr[tr_ind]);
		
		/* Open the document vector and search for this given word
		 * in the con_wt array. The number stored in the LM vector
		 * is {tf.sum(df)}/{sum(tf).df}
		 */
	    dvec.id_num.id = tr->tr[tr_ind].did;
	    if (UNDEF == seek_vector (doc_fd, &dvec) ||
    	    UNDEF == read_vector (doc_fd, &dvec)) {
   	    	return UNDEF;
	    }

		docLen = (float)getDocumentLength(&dvec);
		// LM similarity as stored in the LM vec is an approximation of log(P(Q|D))
		// For the multi-faceted model obtain the marginalized probability...
		p_D_Q = !multifaceted? tr_tup->sim : getMarginalizedQueryGenEstimate(&ldamodel, tr_ind, collstats_freq, totalDocFreq);
		p_D_Q /= totalSim;

		// Iterate for every word in this document
		for (conwtp = dvec.con_wtp; conwtp < &dvec.con_wtp[dvec.ctype_len[0]]; conwtp++) {
			 // P(w|Q) = \sum D \in R {P(w|D) * P(D|Q)}
			 // P(w|D) is to be computed as lambda *tf(w,D)/sum(tf, D) + (1-lambda)*df(w)/sum(df)
			 // tr->tr[tr_ind].sim contains the accumulated log P(D|Q )
			if (conwtp->con >= 0 && conwtp->con < collstats_num_freq) { // sanity check of array index access
				p_w_D = compute_marginalized_P_w_D(&ldamodel, conwtp, tr_ind);
				p_w_Q[conwtp->con] += p_w_D * p_D_Q;
			}
		}
	}

	// Aggregate the TRLM term scores over sentences and linearly combine
	// the scores with the LM scores
	
	for (s = sentences; s < &sentences[numSentences]; s++) {
		svec = &(s->svec);
		s->sim = 0;
		docLen = (float)getDocumentLength(svec);

		// Convert the raw term frequency vectors to LM weights
		if (UNDEF == lang_model_wt_lm(svec, &slmvec, 0))
			return UNDEF;

		vec_pair.vec1 = &slmvec;
		vec_pair.vec2 = qvec;
    	if (UNDEF == vec_vec_ptab->proc (&vec_pair, &(s->sim), vec_vec_inst))
        	return (UNDEF);

		s->sim += lm_prior * log(docLen);
		s->sim *= alpha;

		trlm_comp = 0;
		for (conwtp = svec->con_wtp; conwtp < &svec->con_wtp[svec->ctype_len[0]]; conwtp++) {
			if (conwtp->con >= 0 && conwtp->con < collstats_num_freq) { // sanity check of array index access
				if (p_w_Q[conwtp->con] > 0)
					trlm_comp += beta*p_w_Q[conwtp->con] + (1-beta)*collstats_freq[conwtp->con]/(float)totalDocFreq;
			}
		}
		trlm_comp *= (1-alpha);
		s->sim += trlm_comp;  
	}

	close_lda_est_inst(&ldamodel);
    PRINT_TRACE (2, print_string, "Trace: leaving sentsim_lmtrlm");
    return (1);
}