double BayesianClassifier::calculate_recognition_error(const math::matrix<double> & x,
                                                       const QVector<Distribution> & distributions,
                                                       const math::matrix<double> & regretMatrix)
{
    double R = 0.0;

    bool first = true;
    for (size_t i = 0; i < regretMatrix.RowNo(); ++i)
    {
        double tR = 0.0;

        for (int j = 0; j < distributions.size(); ++j)
            tR += regretMatrix(i, j)*g(x, distributions[j]);

        if (first)
        {
            R = tR;
            first = false;
        }

        if (R > tR)
            R = tR;
    }

    return -R;
}
/** Joins to matrices by multiplying the A[i,j] with B[i,j].
  * Warning! Both Matrices must be squares with the same size!
  */
const math::matrix<double> Convolution::join(math::matrix<double> A, math::matrix<double> B)
{
    int size = A.RowNo();
    math::matrix<double> C(size, size);

    for(int i = 0; i < size; i++)
        for(int j = 0; j < size; j++)
        {
            C(i, j) = A(i, j) * B(i, j);
        }

    return C;
}
/** Sums all of the matrixes elements */
const double Convolution::sum(const math::matrix<double> A)
{
    double sum = 0.0;

    int size = A.RowNo();

    for(int i = 0; i < size; i++)
        for(int j = 0; j < size; j++)
        {
            sum += A(i, j);
        }

    return sum;

}