Пример #1
0
double BayesNet::query( const DataPoint& dpt ) const
{
	for( int dvi = 0; dvi < dpt.getNumValues(); ++dvi )
		// Can classify only nominal values
		mlAssert( dpt.getValueType(dvi) == AT_Enum );

	int attrc = dpt.getNumValues() - 1;
	Node* qnode = getNode(attrc);
	DataPoint qdpt = dpt;
	std::vector<double> vlogp = std::vector<double>( qnode->getNumValues(), 0 );

	// Compute probability for every possible value
	double sump = 0;
	double maxlogp = -DBL_MAX;
	int maxv = 0;
	for( int vi = 0; vi < qnode->getNumValues(); ++vi )
	{
		qdpt.setEnumValue( attrc, vi );
		vlogp[vi] = queryLog(qdpt);
		sump += exp( vlogp[vi] );

		if( vlogp[vi] > maxlogp )
		{
			maxlogp = vlogp[vi];
			maxv = vi;
		}
	}

	// Compute scaled probability of this instance
	sump -= exp( vlogp[maxv] );
	double logp = vlogp[ dpt.getEnumValue(attrc) ] - maxlogp - log( 1 + sump/exp( vlogp[maxv] ) );
	double prob = exp(logp);

	return prob;
}
Пример #2
0
void selectAlignments(std::vector<std::vector<Chain*>>& dst, DbAlignment*** alignments,
    int32_t* alignments_lengths, Chain** queries, int32_t queries_length,
    float threshold) {

    dst.resize(queries_length);

    fprintf(stderr, "** Selecting alignments with median threshold: %.2f **\n", threshold);

    std::vector<ThreadPoolTask*> thread_tasks(queries_length, nullptr);

    for (int32_t i = 0; i < queries_length; ++i) {

        if (alignments_lengths[i] == 0) {
            continue;
        }

        auto thread_data = new ThreadSelectionData(dst[i], alignments[i],
            alignments_lengths[i], queries[i], threshold);

        thread_tasks[i] = threadPoolSubmit(threadSelectAlignments, (void*) thread_data);
    }

    for (int32_t i = 0; i < queries_length; ++i) {
        threadPoolTaskWait(thread_tasks[i]);
        threadPoolTaskDelete(thread_tasks[i]);
        queryLog(i + 1, queries_length);
    }

    fprintf(stderr, "\n\n");
}