示例#1
0
 double Eval::ComputeOneDocLLH(Document* doc, Row<int32_t>& doc_topic_counter)
 {
     if (doc->Size() == 0) return 0.0;
     double one_doc_llh = LogGamma(Config::num_topics * Config::alpha)
         - Config::num_topics * LogGamma(Config::alpha);
     int32_t nonzero_num = 0;
     doc_topic_counter.Clear();
     doc->GetDocTopicVector(doc_topic_counter);
     Row<int32_t>::iterator iter = doc_topic_counter.Iterator();
     while (iter.HasNext())
     {
         one_doc_llh += LogGamma(iter.Value() + Config::alpha);
         ++nonzero_num;
         iter.Next();
     }
     one_doc_llh += (Config::num_topics - nonzero_num)
         * LogGamma(Config::alpha);
     one_doc_llh -= LogGamma(doc->Size() + 
         Config::alpha * Config::num_topics);
     return one_doc_llh;
 }
示例#2
0
int test_std()
{
	Table *tab1, *tab2;
	ColumnInfo colinfo;
	Row row;

	// create table1
	colinfo.Clear();
	colinfo.AddColumn("col1",1,1);
	colinfo.AddColumn("col2",2,2);
	colinfo.AddColumn("col3",4,5);
	tab1 = Table::CreateTable("table1", &colinfo);
	colinfo.Clear();

	row.AddVal("col1", "1");
	row.AddVal("col2", "12");
	row.AddVal("col3", "432");
	tab1->AddRow( &row );
	row.Clear();
	row.AddVal("col1", "2");
	row.AddVal("col2", "23");
	row.AddVal("col3", "234");
	tab1->AddRow( &row );

	// create table2
	colinfo.AddColumn("col2-1",1,2);
	colinfo.AddColumn("col2-2",4,5);
	tab2 = Table::CreateTable("table2", &colinfo);
	colinfo.Clear();

	row.Clear();
	row.AddVal("col2-1", "1");
	row.AddVal("col2-2", "45");
	tab2->AddRow( &row );
	row.Clear();
	row.AddVal("col2-1", "2");
	row.AddVal("col2-2", "56");
	tab2->AddRow( &row );

	Table::Dump();

	// get row
	assert( !strcmp(tab1->GetRow( "1", "col1" ), "1" ) );
	assert( !strcmp(tab1->GetRow( "1", "col2" ), "12" ) );
	assert( !strcmp(tab1->GetRow( "1", "col3" ), "432" ) );
	assert( !strcmp(tab1->GetRow( "2", "col2" ), "23" ) );
	assert( !strcmp(tab1->GetRow( "2", "col3" ), "234" ) );
	assert( !strcmp(tab2->GetRow( "1", "col2-2" ), "45" ) );
	assert( !strcmp(tab2->GetRow( "2", "col2-2" ), "56" ) );
	
	// update row
	tab1->UpdateRow( "1", "col3", "456" );
	assert( !strcmp(tab1->GetRow( "1", "col3" ), "456" ) );

	// del row
	tab1->DelRow( "2" );

	Table::Dump();

	Table::DeleteTable("table1");
	Table::DeleteTable("table2");
	return 0;
}