Example #1
0
Spectrum RegUnfolder::unfold_nouncertainty(const Spectrum & r) const{
    if(tau < 0.0 || L.get_n_rows() != p.gen().dim()) throw invalid_argument("unfold called, but regularization not set up!");
    const size_t ngen = p.gen().dim();
    
    // calculate delta1 := R * t - r for the first term:
    auto delta1 = p.R() * t - poly_matrix(r.get_values());
    
    // calculate delta2 := L * (t - gen) for the second term
    //auto delta2 = L * (t - poly_matrix(p.gen().get_values()));

    // chi2 = delta1^T C^{-1} delta1 + tau * delta2^T * delta2,
    // where C is the covariance matrix of r:
    Matrix r_cov_inverse = r.cov();
    r_cov_inverse.invert_cholesky();
    auto chi2 = delta1.transpose() * r_cov_inverse * delta1 + tau * delta2.transpose() * delta2;
    
    auto solution = chi2(0,0).argmin();
    
    Spectrum result(ngen);
    for(size_t i=0; i<ngen; ++i){
        result[i] = solution[t(i,0)];
    }
    return result;
}