link-grammar-5.8.0/link-grammar/parse/count.c
/**
 * Provide data for insights on the effectively of the connector pair table.
 * Hits, misses, chain length, number of elements with zero/nonzero counts.
 */
Provide data for insights on the effectively of the connector pair table.
Hits, misses, chain length, number of elements with zero/nonzero counts.
Provide data for insights on the effectively of the connector pair table . Hits misses chain length number of elements with zero / nonzero counts .
static void table_stat(count_context_t *ctxt, Sentence sent)
{
	int z = 0, nz = 0;  
	int c, total_c = 0; 
	int N = 0;          
	int null_count[256] = { 0 };   
	int chain_length[64] = { 0 };  
	bool table_stat_entries = test_enabled("count-table-entries");
	int n;              
	for (unsigned int i = 0; i < ctxt->table_size; i++)
	{
		c = 0;
		Table_connector *t = ctxt->table[i];
		if (t == NULL) N++;
		for (; t != NULL; t = t->next)
		{
			c++;
			if (hist_total(&t->count) == 0)
				z++;
			else
				nz++;
			null_count[t->null_count]++;
		}
		if (c > 0) 
		{
			chain_length[c >= (int)ARRAY_SIZE(chain_length) ? 0 : c]++;
			total_c += c;
		}
	}
#if __GNUC__
#define msb(x) ((int)(CHAR_BIT*sizeof(int)-1)-__builtin_clz(x))
#else
#define msb(x) 0
#endif
	int used_slots = ctxt->table_size-N;
	printf("Connector table: msb=%d slots=%6d/%6u (%5.2f%%) avg-chain=%4.2f "
	       "values=%6d (z=%5d nz=%5d N=%5d) used=%5.2f%% "
	       "acc=%zu (hit=%zu miss=%zu) (sent_len=%zu)\n",
	       msb(ctxt->table_size), used_slots, ctxt->table_size,
			 100.0f*used_slots/ctxt->table_size, 1.0f*total_c/used_slots,
	       z+nz, z, nz, N, 100.0f*(z+nz)/ctxt->table_size,
	       hit+miss, hit, miss, sent->length);
	printf("Chain length:\n");
	for (size_t i = 1; i < ARRAY_SIZE(chain_length); i++)
		if (chain_length[i] > 0) printf("%zu: %d\n", i, chain_length[i]);
	if (chain_length[0] > 0) printf(">63: %d\n", chain_length[0]);
	if (!((null_count[1] == 1) && (null_count[2] == 0)))
	{
		printf("Null count:\n");
		for (unsigned int nc = 0; nc < ARRAY_SIZE(null_count); nc++)
		{
			if (0 != null_count[nc])
				printf("%u: %d\n", nc, null_count[nc]);
		}
	}
	if (table_stat_entries)
	{
		for (unsigned int nc = 0; nc < ARRAY_SIZE(null_count); nc++)
		{
			if (0 == null_count[nc]) continue;
			printf("Null count %u:\n", nc);
			for (unsigned int i = 0; i < ctxt->table_size; i++)
			{
				for (Table_connector *t = ctxt->table[i]; t != NULL; t = t->next)
				{
					if (t->null_count != nc) continue;
					printf("[%u]%n", i, &n);
					printf("%*d %5d c=%lld\n",  15-n, t->l_id, t->r_id, t->count);
				}
			}
		}
	}
	hit = miss = 0;
}
static void table_stat ( count_context_t * ctxt , Sentence sent ) { int z = 0 , nz = 0 ; int c , total_c = 0 ; int N = 0 ; int null_count [ 256 ] = { 0 } ; int chain_length [ 64 ] = { 0 } ; bool table_stat_entries = test_enabled ( " " ) ; int n ; for ( unsigned int i = 0 ; i < ctxt -> table_size ; i ++ ) { c = 0 ; Table_connector * t = ctxt -> table [ i ] ; if ( t == NULL ) N ++ ; for ( ; t != NULL ; t = t -> next ) { c ++ ; if ( hist_total ( & t -> count ) == 0 ) z ++ ; else nz ++ ; null_count [ t -> null_count ] ++ ; } if ( c > 0 ) { chain_length [ c >= ( int ) ARRAY_SIZE ( chain_length ) ? 0 : c ] ++ ; total_c += c ; } } #if __GNUC__ #define msb ( x )  ((int)(CHAR_BIT*sizeof(int)-1)-__builtin_clz(x)) #else #define msb ( x )  0 #endif int used_slots = ctxt -> table_size - N ; printf ( " " " " " \n " , msb ( ctxt -> table_size ) , used_slots , ctxt -> table_size , 100.0f * used_slots / ctxt -> table_size , 1.0f * total_c / used_slots , z + nz , z , nz , N , 100.0f * ( z + nz ) / ctxt -> table_size , hit + miss , hit , miss , sent -> length ) ; printf ( " \n " ) ; for ( size_t i = 1 ; i < ARRAY_SIZE ( chain_length ) ; i ++ ) if ( chain_length [ i ] > 0 ) printf ( " \n " , i , chain_length [ i ] ) ; if ( chain_length [ 0 ] > 0 ) printf ( " \n " , chain_length [ 0 ] ) ; if ( ! ( ( null_count [ 1 ] == 1 ) && ( null_count [ 2 ] == 0 ) ) ) { printf ( " \n " ) ; for ( unsigned int nc = 0 ; nc < ARRAY_SIZE ( null_count ) ; nc ++ ) { if ( 0 != null_count [ nc ] ) printf ( " \n " , nc , null_count [ nc ] ) ; } } if ( table_stat_entries ) { for ( unsigned int nc = 0 ; nc < ARRAY_SIZE ( null_count ) ; nc ++ ) { if ( 0 == null_count [ nc ] ) continue ; printf ( " \n " , nc ) ; for ( unsigned int i = 0 ; i < ctxt -> table_size ; i ++ ) { for ( Table_connector * t = ctxt -> table [ i ] ; t != NULL ; t = t -> next ) { if ( t -> null_count != nc ) continue ; printf ( " " , i , & n ) ; printf ( " \n " , 15 - n , t -> l_id , t -> r_id , t -> count ) ; } } } } hit = miss = 0 ; }
Provide data for insights on the effectively of the connector pair table.
Provide data for insights on the effectively of the connector pair table .
/* Number of entries with zero and non-zero counts */ /* Chain length */ /* NULL table slots */ /* null_count histogram */ /* Chain length histogram */ /* For printf() pretty printing */ /* Slot 0 used for length overflow */ //if (c != 0) printf("Connector table [%d] c=%d\n", i, c); /* The used= value is TotalValues/TableSize (not UsedSlots/TableSize). */