0
我正在嘗試使用Boost UBLAS來計算(x-mu)^ T * SigmaInverse *(x-mu),其中x和mu是向量,SigmaInverse是Matrix。代碼如下所示:如何使用Boost UBLAS計算二次形式?
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/matrix.hpp>
#include "matrixhelpers.h"
namespace ublas = boost::numeric::ublas;
class MultivariateNormalLogLikelihood
{
public:
MultivariateNormalLogLikelihood(ublas::vector<double> &mu, ublas::matrix<double> &sigma) : mu(mu)
{
invertMatrix<double>(sigma, sigmaInverse);
constElement = -std::log(2*M_PI)*0.5*mu.size()-0.5*std::log(determinant(sigma));
}
double operator()(ublas::vector<double> &x)
{
auto y = x-mu;
double e = ublas::prod(ublas::prod(ublas::trans(y),sigmaInverse),y);
return constElement-0.5*e;
}
private:
double constElement;
ublas::matrix<double> sigmaInverse;
ublas::vector<double> mu;
};
,我得到這個錯誤:
/home/ga/PhD/cpp/grzesLib/multivariatenormalloglikelihood.h:23:71: error: no matching function for call to ‘prod(boost::numeric::ublas::matrix_vector_binary2_traits<double, boost::numeric::ublas::vector_unary<boost::numeric::ublas::vector_binary<boost::numeric::ublas::vector<double>, boost::numeric::ublas::vector<double>, boost::numeric::ublas::scalar_minus<double, double> >, boost::numeric::ublas::scalar_identity<double> >, double, boost::numeric::ublas::matrix<double> >::result_type, boost::numeric::ublas::vector_binary<boost::numeric::ublas::vector<double>, boost::numeric::ublas::vector<double>, boost::numeric::ublas::scalar_minus<double, double> >&)’
什麼我做錯了,我怎麼能得到它的工作?