Пример #1
0
void fix_tableidtopic(int d, int t) {
  int val;
  assert(ddS.Tdt);
  ddS.Tdt[d][t]++;
  val = atomic_incr(ddS.TDt[t]);
  if ( val==1 )
    atomic_incr(ddS.TDTnz);
  atomic_incr(ddS.TDT);
}
Пример #2
0
void fix_tableidword(int w, int t) {
  int val;
  val = atomic_incr(ddS.Twt[w][t]);
  atomic_incr(ddS.TWt[t]);
  val = atomic_incr(ddS.TwT[w]);
  if ( val==1 ) {
    atomic_incr( ddS.TWTnz);
  }
  atomic_incr(ddS.TWT);
}
Пример #3
0
/*
 *    add affects of document to stats
 *
 *    when using multis, reset ddM.Mi[] to be totals
 *    for training words only, ignore test words in hold
 */
int add_doc(int d, enum GibbsType fix) {
  int i, t, w, nd=0;
  int mi = 0;
  if ( ddP.bdk!=NULL )
    mi = ddM.MI[d];

  for (i=ddD.NdTcum[d]; i<ddD.NdTcum[d+1]; i++) {
    if ( fix!=GibbsHold || pctl_hold(i) ) {
       /*
       *   these words are for perp. calcs
       */     
      nd++;
    }
    if ( fix!=GibbsHold || !pctl_hold(i) ) {
      t = Z_t(ddS.z[i]);
      /*
       *   these words are for training
       */
      ddS.Ndt[d][t]++;
      ddS.NdT[d]++;	
      if ( (ddP.bdk==NULL) || Z_issetr(ddS.z[i]) ) {
	if ( ddP.phi==NULL ) {
          int val;
	  w = ddD.w[i];
	  atomic_incr(ddS.NWt[t]);
	  val = atomic_incr(ddS.Nwt[w][t]);
	  if (  ddP.PYbeta && val==1 ) 
	    fix_tableidword(w,t);
	}
      }
    }
    if ( (ddP.bdk!=NULL) && M_multi(i) ) mi++;
  }
  if ( ddP.PYalpha ) {
    /*  initialise ddS.Tdt[d][*]  */ 
    /*
     *   adjust table count stats based on Ndt[d]
     */
    for (t=0; t<ddN.T; t++) {
      if ( ddS.Ndt[d][t]>0 ) {
        int val;
	ddS.Tdt[d][t] = 1;
        val = atomic_incr(ddS.TDt[t]);
        if ( val==1 )
          atomic_incr(ddS.TDTnz);
        atomic_incr(ddS.TDT);
      } else
	ddS.Tdt[d][t] = 0;
    }
  }
  // yap_message("add_doc(%d):  %d\n", d, nd);
  return nd;
}
Пример #4
0
void *sampling_p(void *pargs)
{
  int i;
  float *p = fvec(ddN.T * 4);
  D_MiSi_t dD;
  D_pargs_p *par =(D_pargs_p *) pargs;
  clock_t t1 = clock();
  
  if ( PCTL_BURSTY() )
    misi_init(&ddM,&dD);
  /*
   *  sampling
   */
  par->thislp = 0;
  par->thisNd = 0;
  while ( (i=atomic_incr(*par->doc)-1)<ddN.DT ) {
    if ( PCTL_BURSTY() )
      misi_build(&dD,i,0);
    par->thislp += gibbs_lda(GibbsNone, i, ddD.N_dT[i], p, &dD);
    par->thisNd += ddD.N_dT[i];
    if ( par->dots>0 && i>0 && (i%par->dots==0) ) 
      yap_message(".");
    if ( PCTL_BURSTY() )
      misi_unbuild(&dD,i,0);
  }
  free(p);
  if ( PCTL_BURSTY() )
    misi_free(&dD);
  par->tot_time = (double)(clock() - t1) / CLOCKS_PER_SEC;
  return NULL;
}
Пример #5
0
struct sockbase *getlistener (const char *addr) {
	int refed = false;
	struct str_rbe *entry;
	struct sockbase *sb = 0;

	mutex_lock (&xgb.lock);
	if ((entry = str_rb_find (&xgb.inproc_listeners, addr, strlen (addr)))) {
		sb = & (cont_of (entry, struct inproc_sock, lhentry))->base;
		mutex_lock (&sb->lock);
		if (!sb->flagset.epipe) {
			refed = true;
			atomic_incr (&sb->ref);
		}
		mutex_unlock (&sb->lock);
		if (!refed)
			sb = 0;
	}
Пример #6
0
void unfix_tableidword(int w, int t) {
  int val;
  assert(ddS.Twt[w][t]);
  val = atomic_decr(ddS.Twt[w][t]);
  if ( val>UINT16_MAX-5 ) {
    /*
     *  whoops
     */
    atomic_incr(ddS.Twt[w][t]);
    return;
  }
  val = atomic_decr(ddS.TwT[w]);
  atomic_decr(ddS.TWt[t]);
  atomic_decr(ddS.TWT);
  if ( val==0 ) {
    atomic_decr(ddS.TWTnz);
  }
}
Пример #7
0
/*
 *   got a new topic, so update all statistics;
 *
 */
void update_topic(int i, int did, int wid, int t, int mi, 
                  float dtip, D_MiSi_t *dD) {
  int e = ddD.e[did];
  int rd;
  int rw=0;
  /*
   *   fix up doc side
   */
  rd = doc_side_ind(did, t);
  assert(rd>=-1 && rd<=e+1);
  
  if ( PCTL_BURSTY() ) 
    // set wid negative if the word is bursty
    wid = misi_incr(dD, i, mi, t, wid, dtip);

  if ( rd>=0 ) {
    /*
     *    increment affect of table indicator for topic PYP;
     *    when multicore, need to maintain consistency of constraints
     */
    int n = ddS.n_dt[did][t];
    if ( 0 && n==0 ) {
      /*  ripple to one, so go down chain */
      fix_tableidtopic(did, t, rd);
      ddS.N_dT[did]++;
      ddS.n_dt[did][t] = 1;
    } else {
      /*  increment up chain */
      ddS.N_dT[did]++;
      ddS.n_dt[did][t] = n+1;
      fix_tableidtopic(did, t, rd);
    }
  } else {
    ddS.N_dT[did]++;
    ddS.n_dt[did][t]++;
  }

  /*
   *   fix up topicXword side
   */
  if ( wid>=0 ) {
    if ( ddP.phi )
      rw = 0;
    else
      rw = word_side_ind(e, wid, t);
    assert(rw>=0 && rw<=e+1);
    if ( rw>0 ) {
      /*
       *    subtract affect of table indicator for word PYP;
       *    when multicore, need to maintain consistency of constraints
       */
      int zero = 0;
      int incr = 0;
      if ( atomic_incr_val(ddS.m_vte[wid][t][e],zero) ) {
        if ( 1 ) {
          atomic_incr(ddS.M_Vte[t][e]);
          incr = 1;
        } else {
          atomic_decr(ddS.m_vte[wid][t][e]);
        }
        /*  cancel increment and do afterwards */
      } else {
        atomic_incr(ddS.M_Vte[t][e]);
        atomic_incr(ddS.m_vte[wid][t][e]);
        incr = 1;
      }
      /*
       *  we have a new table for the word matrix
       */
#ifdef PHI_CACHE
      {
        int laste = fix_tableidword(e,wid,t,rw);
        phi_sum_change(t,laste,i+1);  
        phi_norm_change(wid,t,laste);
      }
#else
      fix_tableidword(e,wid,t,rw);
#endif
      if ( !incr ) {
        atomic_incr(ddS.M_Vte[t][e]);
        atomic_incr(ddS.m_vte[wid][t][e]);
      }
    } else {
      /*  simple case, order doesn't matter  */
      atomic_incr(ddS.M_Vte[t][e]);
      atomic_incr(ddS.m_vte[wid][t][e]);
#ifdef PHI_CACHE
      phi_norm_change(wid,t,e);
      phi_sum_change(t,e,i+1);
#endif
    }
  }
#ifdef IND_STATS
  if ( did < ddN.DT ) {
    if ( rd>=0 && rd<=e )
      atomic_incr(ddP.doc_ind_stats[t][e][rd]);
    if ( wid>=0 && rw<=e )
      atomic_incr(ddP.word_ind_stats[t][e][rw]);
  } 
#endif
}