示例#1
0
void NeighbourJoining::configure(const MatrixXf& D, MatrixXf& currentD, MatrixXi& rowsID, int numOccupiedNodes) {
	numObservableNodes = rowsID.rows();
	numCurrentNodes = numObservableNodes;

	//allocates memory for the latent nodes
	rowsID.conservativeResize((2 * numObservableNodes - 2), 1);

	//gives latent nodes IDs
	for (int i = numObservableNodes; i < 2 * numObservableNodes - 2; ++i) {
		rowsID(i) = i + numOccupiedNodes;
	}
	sort(rowsID.data(), rowsID.data() + rowsID.size());
	//cout << "rowsID after sort:" << rowsID.transpose();	cout << endl;

	//copies distances of selected Nodes
	int offseti = 0;	int offsetj = 0;
	for (int i = 0; i < numObservableNodes; ++i) {
		while (rowsID(i) != i + offseti)
			++offseti;
		offsetj = 0;
		for (int j = 0; j < numObservableNodes; ++j) {
			while (rowsID(j) != j + offsetj)
				++offsetj;
			currentD(i, j) = D(i + offseti, j + offsetj);
			currentD(j, i) = currentD(i, j);
		}
	}
	//cout << "copied matrix: " << endl;		printMatrix(currentD);
}
MatrixXf CharacterController::GenerateXapv(const std::vector<int> &activeParts)
{
	// pvDim without
	auto& allClipinfo = m_cpxClipinfo;
	auto& pvFacade = allClipinfo.PvFacade;
	int pvDim = pvFacade.GetAllPartDimension();
	assert(pvDim > 0);


	MatrixXf Xabpv(allClipinfo.ClipFrames(), size(activeParts) * pvDim);

	ArrayXi incX(pvDim);
	incX.setLinSpaced(0, pvDim - 1);

	MatrixXi apMask = VectorXi::Map(activeParts.data(), activeParts.size()).replicate(1, pvDim).transpose();


	apMask.array() = apMask.array() * pvDim + incX.replicate(1, apMask.cols());

	auto maskVec = VectorXi::Map(apMask.data(), apMask.size());
	selectCols(pvFacade.GetAllPartsSequence(), maskVec, &Xabpv);

	Pca<MatrixXf> pcaXabpv(Xabpv);
	int dXabpv = pcaXabpv.reducedRank(g_CharacterPcaCutoff);
	Xabpv = pcaXabpv.coordinates(dXabpv);
	XabpvT = pcaXabpv.components(dXabpv);
	uXabpv = pcaXabpv.mean();

	if (g_EnableDebugLogging)
	{
		ofstream fout(g_CharacterAnalyzeDir / (m_pCharacter->Name + "_Xabpv.pd.csv"));
		fout << Xabpv.format(CSVFormat);

		fout.close();
	}


	return Xabpv;
}
示例#3
0
void read_SparseMatrix(SparseMatrix<double,0,int>& M, string path,string name){

	FILE * pFile;
	pFile = fopen((path + name+"i.bin").c_str(), "rb");
	if (pFile==NULL) {fputs ("File error",stderr); exit (1);}

	int n,m,ni;
	if(1 != fread(&n,sizeof(int),1,pFile)){
		fputs ("Read error\n",stderr); exit (1);
	}
	if(1 != fread(&m,sizeof(int),1,pFile)){
		fputs ("Read error\n",stderr); exit (1);
	}

	if(1 != fread(&ni,sizeof(int),1,pFile)){
		fputs ("Read error\n",stderr); exit (1);
	}
	M.resize(n,m);
	MatrixXi ij;
	ij.setZero(ni,2);
	if(ni*2 != fread(ij.data(),sizeof(int),ni*2,pFile)){
		fputs ("Read error\n",stderr); exit (1);
	}
	fclose(pFile);
	VectorXd v;
	v.setZero(ni);
	pFile = fopen((path + name+"v.bin").c_str(), "rb");
	if (pFile==NULL) {fputs ("File error",stderr); exit (1);}
	if(ni != fread(v.data(),sizeof(double),ni,pFile)){
		fputs ("Read error\n",stderr); exit (1);
	}
	fclose(pFile);
	vector<T> coef;
	for(int i=0;i<ni;i++){
		coef.push_back(T(ij(i,0),ij(i,1),v(i)));
	}
	M.setFromTriplets(coef.begin(), coef.end());
}
示例#4
0
void Mesh::CreateSimpleMesh() {

    int c = 0;
    MatrixXi g(n_node_x, n_node_y);
    for (size_t i=0; i<n_node_x; i++) {
        for (size_t j=0; j<n_node_y; j++) {
            g(i,j) = c;
            c++;
        }
    }

    MatrixXi gg(n_node_p_elem, n_elem);
    size_t xi = 0;
    size_t xj = 0;
    for (size_t i=0; i<n_elem; i++) {

        size_t xi_min = xi;
        size_t xj_min = xj;
        size_t xi_max = xi + n_node_p_dim;
        size_t xj_max = xj + n_node_p_dim;

        MatrixXi block =
            g.block(xi_min, xj_min, n_node_p_dim, n_node_p_dim);
        Map<VectorXi> gv(block.data(), block.size());
        gg.col(i) = gv;

        if (xi_max == n_node_x) {
            xi = 0;
            xj = xj_max - 1;
        } else {
            xi = xi_max - 1;
        }

    }

    c = 0;
    MatrixXi nf(eqn_p_node, n_node);
    for (size_t i=0; i<n_node; i++) {
        nf(0,i) = c;
        nf(1,i) = c+1;
        c += 2;
    }

    imap.resize(n_dof_p_elem, n_elem);
    for (size_t i=0; i<n_elem; i++) {
        c = 0;
        while (c+eqn_p_node <= n_dof_p_elem) {
            imap.block(c, i, eqn_p_node, 1) =
                nf.block(
                    0, gg(c/eqn_p_node, i), eqn_p_node, 1);
            c += eqn_p_node;
        }
    }

    valen.resize(n_dof_p_elem, n_elem);
    valen.setZero();
    for (size_t i=0; i<n_elem; i++) {
        for (size_t j=0; j<n_dof_p_elem; j++) {
            valen(j, i) += 1;
        }
    }

    size_t k = 0;
    size_t e = 0;
    size_t n_node_x_vis {n_elem_x + 1};
    connec.resize(4*n_elem);
    for (size_t j=0; j<n_elem_y; j++) {
        for (size_t i=0; i<n_elem_x; i++) {
            connec(k+0) = (i+0) + (j+0) * n_node_x_vis;
            connec(k+1) = (i+1) + (j+0) * n_node_x_vis;
            connec(k+2) = (i+1) + (j+1) * n_node_x_vis;
            connec(k+3) = (i+0) + (j+1) * n_node_x_vis;
            k+=4;
            e++;
        }
    }
    connec = connec.array() + 1;
    n_vis_node = connec.maxCoeff();

    k = 0;
    ex.resize(n_vis_node);
    ey.resize(n_vis_node);
    m_node_n.resize(n_vis_node);
    for (size_t j=0; j<=n_elem_y; j++) {
        for (size_t i=0; i<=n_elem_x; i++) {
            ex(k) = i * s_elem_x;
            ey(k) = j * s_elem_y;
            m_node_n(k) = k;
            k++;
        }
    }
    m_node_n = m_node_n.array() + 1;

    ctr_elem_x.resize(n_elem);
    ctr_elem_y.resize(n_elem);
    k = 0;
    for (size_t j=0; j<n_elem_y; j++) {
        for (size_t i=0; i<n_elem_x; i++) {
            ctr_elem_x(k) = (1/2.) * (ex(k) + ex(k+1));
            ctr_elem_y(k) = (1/2.) * (ey(k) + ey(k+1));
            k++;
        }
    }

}