Example #1
0
pair<double, MatrixXf> TargetProbEstimatorGivenBG::probify(const MatrixXf& scoremat) {
    // initial guest at lambda
    TargetProbFunction target_func(bgfreq, scoremat);
    double lamb;
    double fx;
    for (lamb = 1. / scoremat.maxCoeff(); lamb < 50.; lamb *= 2.) {
        fx = target_func.fx(lamb);
        if (fx > 0) break;
    }
    // use Newton/Raphson method to find the optimal lambda
    NewtonRaphsonRootFinder solver;
    lamb = solver.find_root(target_func, lamb);
    MatrixXf prob(scoremat.rows(), scoremat.cols());
    prob = (bgfreq * bgfreq.transpose()).cwiseProduct((lamb * scoremat).unaryExpr(&exp));
    return make_pair(lamb, prob);
}