Example #1
0
ScalarType eigentools::cosineMeasure(DenseMat &a,DenseMat &b)
{
    if (a.cols()!=b.cols() || a.rows()!=b.rows())
        return (ScalarType)0;
    if (a.cols()==1 || a.rows() == 1)
    {
        eigentools::ScalarType rval = a.cwiseProduct(b).array().sum();
        if (!a.norm() || !b.norm())
        {
            std::cerr<<"Norm of vector is 0\n";
            return 0;
        }
        rval /= a.norm();
        rval /= b.norm();
        return rval;
    }
    else
        return 0;
}
Example #2
0
static
void calculate_energy(DenseMat& cluster_dist_mat,
	std::vector< std::vector<CoordType> >& center_coord,
	double& curr_energy)
{
	using namespace std;
	curr_energy = 0;

	vector<CoordType> u(2);
	vector<CoordType> v(2);
	for (int i=0; i<cluster_dist_mat.rows(); ++i)
	{
		u.at(0) = center_coord.at(i).at(0);
		u.at(1) = center_coord.at(i).at(1);
		for (int j=i+1; j<cluster_dist_mat.rows(); ++j)
		{
			v.at(0) = center_coord.at(j).at(0);
			v.at(0) = center_coord.at(j).at(1);
			curr_energy += pow(norm(u, v) - cluster_dist_mat(i, j) , 2);
		}
	}
}