public double likelihood(String[] doc,String tag){
  double likelihood=0;
  if (ntw.rowSum(tag) == 0) {
    return likelihood;
  }
  Counter<String> nwd=new Counter<String>();
  for (  String w : doc) {
    nwd.inc(w,1);
  }
  double norm=0;
  Map<String,Double> prwd=new Hashtable<String,Double>();
  for (  Entry<String,Long> e : nwd) {
    double prw=prw(e.getKey());
    norm+=prw;
    prwd.put(e.getKey(),prw);
  }
  for (  Entry<String,Double> e : prwd.entrySet()) {
    double prw=e.getValue() / norm;
    likelihood+=ptr(tag,e.getKey()) * prw * (1.0 - pcm());
  }
  likelihood+=ptr(tag,NOISE) * pcm();
  return likelihood;
}

public double likelihood ( String [ ] doc , String tag ) { double likelihood = 0 ; if ( ntw . rowSum ( tag ) == 0 ) { return likelihood ; } Counter < String > nwd = new Counter < String > ( ) ; for ( String w : doc ) { nwd . inc ( w , 1 ) ; } double norm = 0 ; Map < String , Double > prwd = new Hashtable < String , Double > ( ) ; for ( Entry < String , Long > e : nwd ) { double prw = prw ( e . getKey ( ) ) ; norm += prw ; prwd . put ( e . getKey ( ) , prw ) ; } for ( Entry < String , Double > e : prwd . entrySet ( ) ) { double prw = e . getValue ( ) / norm ; likelihood += ptr ( tag , e . getKey ( ) ) * prw * ( 1.0 - pcm ( ) ) ; } likelihood += ptr ( tag , NOISE ) * pcm ( ) ; return likelihood ; }
the likelihood of a tag in given document .
