# Ublas :

Subject: [ublas] How can I calculate a quadratic form using Boost UBLAS?
From: Grze¶ Andruszkiewicz (gandrusz_at_[hidden])
Date: 2013-01-23 10:26:33

Hi,

I am completely new to uBlas, so probably my question will be rather basic.

I am trying to calculate (x-mu)^T*SigmaInverse*(x-mu) using Boost UBLAS,
where x and mu are vectors and SigmaInverse is a Matrix. The code looks
like this:

#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;
};

and I get this error:

/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> >&)’

What am I doing wrong and how can I get it to work?

Cheers,
Grzegorz