Exemple #1
0
void unfix_tableidtopic(int d, int t) {
  int val;
  ddS.Tdt[d][t]--;
  assert(ddS.Tdt[d][t]>=0);
  assert(ddS.Tdt[d][t]>0 || ddS.Ndt[d][t]==0);
  val = atomic_decr(ddS.TDt[t]);
  atomic_decr(ddS.TDT);
  if ( val==0 ) {
    atomic_decr(ddS.TDTnz);
    ddS.Tlife[t] = 0;
  }
}
Exemple #2
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);
  }
}
Exemple #3
0
/*
 *    remove affects of document from stats
 */
int remove_doc(int d, enum GibbsType fix) {
  int i, t;
  for (t=0; t<ddN.T; t++) 
    ddS.Ndt[d][t] = 0;
  ddS.NdT[d] = 0;
  if ( ddP.PYalpha ) {
    for (t=0; t<ddN.T; t++) 
      if ( ddS.Tdt[d][t]>0 ) {
        int val;
	val = atomic_sub(ddS.TDt[t],ddS.Tdt[d][t]);
	atomic_sub(ddS.TDT,ddS.Tdt[d][t]);
	if ( val==0 ) {
          atomic_decr(ddS.TDTnz);
          ddS.Tlife[t] = 0;
        }
	ddS.Tdt[d][t] = 0;
      }
  }
  for (i=ddD.NdTcum[d]; i<ddD.NdTcum[d+1]; i++) {
    if ( fix!=GibbsHold || !pctl_hold(i) ) {
      /*
       *   these words are for training
       */
      if ( (ddP.bdk==NULL) || Z_issetr(ddS.z[i]) ) {
	t = Z_t(ddS.z[i]);
	if ( ddP.phi==NULL ) {
          int val;
	  int w = ddD.w[i];
	  atomic_decr(ddS.NWt[t]);
	  // assert(ddS.Nwt[w][t]>0);
	  val = atomic_decr(ddS.Nwt[w][t]);
	  if (  ddP.PYbeta ) 
	    if ( val==0 || ddS.Twt[w][t]>ddS.Nwt[w][t] ) 
	      unfix_tableidword(w,t);  // ???? WRONG ??
	}
      }
    }
  }
  return 0;
}
Exemple #4
0
int bc_put(bc_hash_t *h, bc_item_t *i)
{
    uint use = atomic_decr(i->in_use);
    if (!use && i->purge)
    {
		i->offset = 0;
		if (i - h->bucket >= h->num_hash)
		{
			i->queue_next = h->queue_head;
			h->queue_head = i - h->bucket;
		}
    }
    return 0;
}
Exemple #5
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
}
Exemple #6
0
/*
 *   remove topic, so update all statistics;
 *   return non-zero if fails due to constraints
 *
 *   JINJING:   you need to fix this
 */
int remove_topic(int i, int did, int wid, int t, int mi, D_MiSi_t *dD) {
  int  rw = 0;           /*  indicator for docXwords's */
  int  rd;           /*  indicator for docXtopic's */
  int  e = ddD.e[did];
  /*
   *    this doc contributes data to TM (not just doc PYP)
   */
  // check_n_dt(did);

  if ( PCTL_BURSTY() && misi_blocked(dD, i, mi, t) )
    return 1;

  if ( resample_doc_side_ind(did, t, &rd) )
    return 1;
  assert(rd>=-1 && rd<=e+1);

  if (wid>=0 && resample_word_side_ind(e, wid, t, &rw) )
    return 1;
  assert(wid<0 || (rw>=0 && rw<=e+1));
  
  /*
   *  OK to change this topic.
   *  NB.  all misi stats are local document so unaffected
   *       by other threads
   */
  if ( PCTL_BURSTY() )
    misi_decr(dD, i, mi, t, wid);

  /*
   *    remove from doc stats ...
   */
  if ( rd>=0 ) {
    /* 
     *   subtract affect of table indicator for topic PYP;
     *   when multicore, need to maintain consistency of constraints
     */
    int n = ddS.n_dt[did][t];
    assert(n>0);
    if ( n==1 ) {
      /*  chains going to zero, work up  */
      // ??????????  wrong ... its ddS.c_dt[d][t] we should worry about!
      ddS.n_dt[did][t] = 0;
      ddS.N_dT[did]--;
      unfix_tableidtopic(did,t,rd);
    } else {
     /*  chains not going to zero, work down  */
      unfix_tableidtopic(did,t,rd);
      ddS.n_dt[did][t] = n-1;
      ddS.N_dT[did]--;
    }
  } else {
    ddS.n_dt[did][t]--;
    ddS.N_dT[did]--;
  }
  
  /*
   *  remove from topicXword stats;
   *  note wid<0 means burstiness caught case
   */
  if ( wid>=0 ) {
    if ( rw>=1 ) {
      int decr = 0; 
      /*
       *  need to safely catch with atomic ops if it goes to zero
       */
      if ( e==ddN.E-1 || ddS.s_vte[wid][t][e+1]==0 ) {
        int one = 1;
        /*  no data inherited from later epoch */
        if ( atomic_decr_val(ddS.m_vte[wid][t][e],one) ) {
          /*   m_vte[wid][t][e] was decremented to zero */
          atomic_decr(ddS.M_Vte[t][e]);
          decr = 1;
        }
      }
      /*
       *    subtract affect of table indicator for word PYP
       */
#ifdef PHI_CACHE
      {
        int elast = unfix_tableidword(e,wid,t,rw);
        phi_norm_change(wid,t,elast);
        phi_sum_change(t,elast,i);
      }
#else
      unfix_tableidword(e,wid,t,rw);
#endif
      if ( decr==0 ) {
        /*  not decremented to zero above */
#ifndef H_THREADS
        assert(ddS.m_vte[wid][t][e]>0);
#endif
        /*  safe because the count is uniquely associated with this word */
        atomic_decr(ddS.m_vte[wid][t][e]);
        atomic_decr(ddS.M_Vte[t][e]);
      }
    } else {
      /*  safe because the count is uniquely associated with this word */
      atomic_decr(ddS.m_vte[wid][t][e]);
      atomic_decr(ddS.M_Vte[t][e]);
#ifdef PHI_CACHE
      phi_norm_change(wid,t,e);
      phi_sum_change(t,e,i);
#endif
    }
  }
  return 0;
}