Пример #1
0
int generate_sparse_rectangular_problem(MatrixType& A, DenseMat& dA, int maxRows = 300)
{
  typedef typename MatrixType::Scalar Scalar;
  int rows = internal::random<int>(1,maxRows);
  int cols = internal::random<int>(1,rows);
  double density = (std::max)(8./(rows*cols), 0.01);
  
  A.resize(rows,cols);
  dA.resize(rows,cols);
  initSparse<Scalar>(density, dA, A,ForceNonZeroDiag);
  A.makeCompressed();
  int nop = internal::random<int>(0, internal::random<double>(0,1) > 0.5 ? cols/2 : 0);
  for(int k=0; k<nop; ++k)
  {
    int j0 = internal::random<int>(0,cols-1);
    int j1 = internal::random<int>(0,cols-1);
    Scalar s = internal::random<Scalar>();
    A.col(j0)  = s * A.col(j1);
    dA.col(j0) = s * dA.col(j1);
  }
  
//   if(rows<cols) {
//     A.conservativeResize(cols,cols);
//     dA.conservativeResize(cols,cols);
//     dA.bottomRows(cols-rows).setZero();
//   }
  
  return rows;
}
Пример #2
0
int main()
{
    GPUHandle::Init(0);
    DenseMat<mode, Dtype> a(3, 5);
    
    a.SetRandN(0, 1);
    a.Print2Screen();
    
    DenseMat<mode, Dtype> d;
    
    d.GetColsFrom(a, 1, 2);
    d.Print2Screen();
    
    GPUHandle::Destroy();
    return 0;
}
Пример #3
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);
		}
	}
}
Пример #4
0
static
void create_cluster_dist_mat(
    DenseMat& distMat,
    int cls,
    std::vector<int>& cluster_nodes,
    std::vector<WgtType>& nodes_radii,
    DenseMat& clusterDistMat)
{
    // Steps
    // 1. resize cluster distance matrix
    // 2. match the distance from distMat to clusterDistMat
    // 3. add central node influence

    // Step 1
    clusterDistMat.resize(cluster_nodes.size()+1, cluster_nodes.size()+1);
    clusterDistMat.fill(0);

    // Step 2
    int rowIdx;
    int colIdx;
    for (int c=0; c<cluster_nodes.size(); ++c)
    {
        for (int r=0; r<cluster_nodes.size(); ++r)
        {
            rowIdx = cluster_nodes.at(r);
            colIdx = cluster_nodes.at(c);
            clusterDistMat(r+1, c+1) = distMat(rowIdx, colIdx);
        }
    }

    // Step 3
    for (int i=0; i<nodes_radii.size(); ++i)
    {
        clusterDistMat(0, i+1) = nodes_radii.at(i);
        clusterDistMat(i+1, 0) = nodes_radii.at(i);

    }
}
Пример #5
0
int generate_sparse_rectangular_problem(MatrixType& A, DenseMat& dA, int maxRows = 300, int maxCols = 300)
{
  eigen_assert(maxRows >= maxCols);
  typedef typename MatrixType::Scalar Scalar;
  int rows = internal::random<int>(1,maxRows);
  int cols = internal::random<int>(1,rows);
  double density = (std::max)(8./(rows*cols), 0.01);
  
  A.resize(rows,rows);
  dA.resize(rows,rows);
  initSparse<Scalar>(density, dA, A,ForceNonZeroDiag);
  A.makeCompressed();
  return rows;
}
Пример #6
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;
}