当前位置: 首页>>代码示例>>C++>>正文


C++ VectorXf::resize方法代码示例

本文整理汇总了C++中VectorXf::resize方法的典型用法代码示例。如果您正苦于以下问题:C++ VectorXf::resize方法的具体用法?C++ VectorXf::resize怎么用?C++ VectorXf::resize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在VectorXf的用法示例。


在下文中一共展示了VectorXf::resize方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getChildrenRadius

void LayoutSetting::getChildrenRadius( const QList<SymbolNode::Ptr>& childList, VectorXf& radiusVec )
{
	radiusVec.resize(childList.size());

	for (int ithChild = 0; ithChild < childList.size(); ++ithChild)
	{
		const SymbolNode::Ptr& child = childList[ithChild];
		getNodeRadius(child, radiusVec[ithChild]);
	}
}
开发者ID:league1991,项目名称:CodeView,代码行数:10,代码来源:Layouter.cpp

示例2: layoutByWord

void ComponentLayouter::layoutByWord( QVector<Component>& compInfo, float& finalRadius )
{
	//	qDebug()<< "by word";
	int nComp = compInfo.size();
	if (nComp == 1)
	{
		Component& comp = compInfo[0];
		comp.m_compPos2D.resize(2);
		comp.m_compPos2D[0] = comp.m_compPos2D[1] = 0.f;
		finalRadius = comp.m_radius;
		return;
	}
	MatrixXd distMat(nComp, nComp);
	for (int i = 0; i < nComp; ++i)
	{
		distMat(i,i) = 0.f;
		for (int j = i+1; j < nComp; ++j)
		{
			Component& compI = compInfo[i];
			Component& compJ = compInfo[j];
			double cosVal = compI.m_wordAttr.cosSimilarity(compJ.m_wordAttr);
			distMat(i,j) = distMat(j,i) = 1.0 - cosVal;
		}
	}

	VectorXf rVec;
	VectorXi hashVec;
	rVec.resize(nComp);
	hashVec.resize(nComp);
	for (int ithComp = 0; ithComp < nComp; ++ithComp)
	{
		rVec[ithComp] = compInfo[ithComp].m_radius;
		hashVec[ithComp] = compInfo[ithComp].m_compHash;
	}

	MatrixXf finalPos2D;
	Layouter::mds(distMat, rVec, hashVec, finalPos2D, finalRadius, m_wordSparseFactor, 0.01f);

	for (int ithComp = 0; ithComp < nComp; ++ithComp)
		compInfo[ithComp].m_compPos2D = finalPos2D.row(ithComp);
} 
开发者ID:league1991,项目名称:CodeView,代码行数:41,代码来源:ComponentLayouter.cpp

示例3: compute

bool ComponentLayouter::compute(   const SparseMatrix*	vtxEdgeMatrix, 
								   const VectorXd*		edgeWeight,
								   const QList<SymbolNode::Ptr>& childList,
								   MatrixXf& childPos,
								   VectorXf& childRadius,
								   float& totalRadius)
{
	CHECK_ERRORS_RETURN_BOOL(m_status);

	// check edge data
	int nVtx1 = childList.size();
	bool hasEdgeData = (vtxEdgeMatrix != NULL && edgeWeight != NULL );
	if (hasEdgeData)
	{
		int nVtx0 = vtxEdgeMatrix->rows();
		int nEdge0= vtxEdgeMatrix->cols();
		int nEdge1 = edgeWeight->size();
		if (!(nVtx0 == nVtx1 && nEdge0 == nEdge1 && nVtx0 > 0 && nEdge0 > 0))
			m_status |= WARNING_INVALID_EDGE_DATA;
	}
	else
		m_status |= WARNING_NO_EDGE;
	bool isVtxEdgeMatValid = (m_status & (WARNING_NO_EDGE | WARNING_INVALID_EDGE_DATA)) == 0;

	// fill child radius
	LayoutSetting::getChildrenRadius(childList, childRadius);

	QVector<Component>     compInfo;
	VectorXi	  vtxCompIdx, vtxIdx, edgeCompIdx, edgeIdx;
	QList<SparseMatrix> compVEMat;
	int nComp = 0; 
	if (isVtxEdgeMatValid)
	{
		GraphUtility::splitConnectedComponents(*vtxEdgeMatrix, vtxCompIdx, vtxIdx, edgeCompIdx, edgeIdx, compVEMat);
		nComp = compVEMat.size();
	}
	else
	{
		vtxCompIdx.resize(nVtx1);
		vtxIdx.resize(nVtx1);
		for (int ithVtx = 0; ithVtx < nVtx1; ++ithVtx)
		{
			vtxCompIdx[ithVtx] = ithVtx;
			vtxIdx[ithVtx]  = 0;
			compVEMat.push_back(SparseMatrix());
		}
		nComp = nVtx1;
	}

	// fill component information array
	compInfo.resize(nComp);
	for (int ithComp = 0; ithComp < nComp; ++ithComp)
	{
		Component& comp = compInfo[ithComp];
		comp.m_vtxRadius.resize(childRadius.size());
		comp.m_hashID.resize(childRadius.size());
		comp.m_pVEIncidenceMat = &compVEMat[ithComp];
		comp.m_edgeWeight.resize(compVEMat[ithComp].cols());
	}
	for (int ithVtx = 0; ithVtx < vtxCompIdx.size(); ++ithVtx)
	{
		Component& comp = compInfo[vtxCompIdx[ithVtx]];
		comp.m_vtxRadius[vtxIdx[ithVtx]] = childRadius[ithVtx];
		unsigned vtxHash = childList[ithVtx]->getSymInfo().hash();
		comp.m_hashID[vtxIdx[ithVtx]]    = vtxHash;
		comp.m_compHash                  = comp.m_compHash ^ vtxHash;
	}
	if (edgeWeight)
	{
		for (int ithEdge = 0; ithEdge < edgeCompIdx.size(); ++ithEdge)
		{
			compInfo[edgeCompIdx[ithEdge]].m_edgeWeight[edgeIdx[ithEdge]] = (*edgeWeight)[ithEdge];
		}
	}

	// layout within each components
	if (isVtxEdgeMatValid)
		layoutByGraph(compInfo);
	else
	{
		// set component result directly
		for (int ithComp = 0; ithComp < nComp; ++ithComp)
		{
			Component& comp = compInfo[ithComp];
			float r = childRadius[ithComp];
			comp.m_vtxRadius.setConstant(1, r);
			comp.m_radius    = r;
			comp.m_localPos2D.setZero(1,2);
		}
	}

	// layout by word, first fill word attributes
	for (int ithChild = 0; ithChild < childList.size(); ++ithChild)
	{
		const SymbolNode::Ptr& child = childList[ithChild]; 
		if (SymbolWordAttr::Ptr wordAttr = child->getAttr<SymbolWordAttr>())
		{
			int ithComp = vtxCompIdx[ithChild];
			Component& comp = compInfo[ithComp];	
			comp.m_wordAttr.unite(*wordAttr);
//.........这里部分代码省略.........
开发者ID:league1991,项目名称:CodeView,代码行数:101,代码来源:ComponentLayouter.cpp

示例4: fwd_load_eeg_sphere_models

//*************************************************************************************************************
//fwd_eeg_sphere_models.c
FwdEegSphereModelSet* FwdEegSphereModelSet::fwd_load_eeg_sphere_models(const QString& filename, FwdEegSphereModelSet* now)
{
    char line[MAXLINE];
    FILE *fp = NULL;
    char  *name   = NULL;
    VectorXf rads;
    VectorXf sigmas;
    int   nlayer  = 0;
    char  *one,*two;
    char  *tag = NULL;

    if (!now)
        now = fwd_add_default_eeg_sphere_model(now);

    if (filename.isEmpty())
        return now;

#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
    if (_access(filename.toLatin1().data(),R_OK) != OK)	/* Never mind about an unaccesible file */
        return now;
#else
    if (access(filename.toLatin1().data(),R_OK) != OK)	/* Never mind about an unaccesible file */
        return now;
#endif

    if ((fp = fopen(filename.toLatin1().data(),"r")) == NULL) {
        printf(filename.toLatin1().data());
        goto bad;
    }
    while (fgets(line,MAXLINE,fp) != NULL) {
        if (line[0] == '#')
            continue;
        one = strtok(line,SEP);
        if (one != NULL) {
            if (!tag || strlen(tag) == 0)
                name = mne_strdup_2(one);
            else {
                name = MALLOC_2(strlen(one)+strlen(tag)+10,char);
                sprintf(name,"%s %s",one,tag);
            }
            while (1) {
                one = strtok(NULL,SEP);
                if (one == NULL)
                    break;
                two = strtok(NULL,SEP);
                if (two == NULL)
                    break;
                rads.resize(nlayer+1);
                sigmas.resize(nlayer+1);
                if (sscanf(one,"%g",rads[nlayer]) != 1) {
                    nlayer = 0;
                    break;
                }
                if (sscanf(two,"%g",sigmas[nlayer]) != 1) {
                    nlayer = 0;
                    break;
                }
                nlayer++;
            }
            if (nlayer > 0)
                now = fwd_add_to_eeg_sphere_model_set(now,FwdEegSphereModel::fwd_create_eeg_sphere_model(name,nlayer,rads,sigmas));
            nlayer = 0;
        }
    }
    if (ferror(fp)) {
        printf(filename.toLatin1().data());
        goto bad;
    }
    fclose(fp);
    return now;

bad : {
        if (fp)
            fclose(fp);
        delete now;
        return NULL;
    }
}
开发者ID:louiseichhorst,项目名称:mne-cpp,代码行数:80,代码来源:fwd_eeg_sphere_model_set.cpp

示例5: Calculate

int Pca::Calculate(vector<float> &x, 
              const unsigned int &nrows, 
              const unsigned int &ncols, 
              const bool is_corr, 
              const bool is_center, 
              const bool is_scale) {
  _ncols = ncols;
  _nrows = nrows;
  _is_corr = is_corr;
  _is_center = is_center;
  _is_scale = is_scale;
  if (x.size()!= _nrows*_ncols) {
    return -1;
  }
  if ((1 == _ncols) || (1 == nrows)) {
    return -1;
  }
  // Convert vector to Eigen 2-dimensional matrix
  //Map<MatrixXf> _xXf(x.data(), _nrows, _ncols);
  _xXf.resize(_nrows, _ncols);
  for (unsigned int i = 0; i < _nrows; ++i) {
    for (unsigned int j = 0; j < _ncols; ++j) {
      _xXf(i, j) = x[j + i*_ncols];
    }
  }
  // Mean and standard deviation for each column
  VectorXf mean_vector(_ncols);
  mean_vector = _xXf.colwise().mean();
  VectorXf sd_vector(_ncols);
  unsigned int zero_sd_num = 0;
  float denom = static_cast<float>((_nrows > 1)? _nrows - 1: 1);
  for (unsigned int i = 0; i < _ncols; ++i) {
     VectorXf curr_col  = VectorXf::Constant(_nrows, mean_vector(i)); // mean(x) for column x
     curr_col = _xXf.col(i) - curr_col; // x - mean(x)
     curr_col = curr_col.array().square(); // (x-mean(x))^2  
     sd_vector(i) = sqrt((curr_col.sum())/denom);
     if (0 == sd_vector(i)) {
      zero_sd_num++;
     }
  }
  // If colums with sd == 0 are too many,
  // don't continue calculations
  if (1 > _ncols-zero_sd_num) {
    return -1;
  }
  // Delete columns where sd == 0
  MatrixXf tmp(_nrows, _ncols-zero_sd_num);
  VectorXf tmp_mean_vector(_ncols-zero_sd_num);
  unsigned int curr_col_num = 0;
  for (unsigned int i = 0; i < _ncols; ++i) {
    if (0 != sd_vector(i)) {
      tmp.col(curr_col_num) = _xXf.col(i);
      tmp_mean_vector(curr_col_num) = mean_vector(i);
      curr_col_num++;
    } else {
      _eliminated_columns.push_back(i);
    }
  }
  _ncols -= zero_sd_num;
  _xXf = tmp;
  mean_vector = tmp_mean_vector;
  tmp.resize(0, 0); tmp_mean_vector.resize(0);
  // Shift to zero
  if (true == _is_center) {
    for (unsigned int i = 0; i < _ncols; ++i) {
      _xXf.col(i) -= VectorXf::Constant(_nrows, mean_vector(i));
    }
  }
  // Scale to unit variance
  if ( (false == _is_corr) || (true == _is_scale)) {
    for (unsigned int i = 0; i < _ncols; ++i) {
     _xXf.col(i) /= sqrt(_xXf.col(i).array().square().sum()/denom);
    }
  }
  #ifdef DEBUG
    cout << "\nScaled matrix:\n";
    cout << _xXf << endl;
    cout << "\nMean before scaling:\n" << mean_vector.transpose();
    cout << "\nStandard deviation before scaling:\n" << sd_vector.transpose();
  #endif
  // When _nrows < _ncols then svd will be used.
  // If corr is true and _nrows > _ncols then will be used correlation matrix
  // (TODO): What about covariance?
  if ( (_nrows < _ncols) || (false == _is_corr)) { // Singular Value Decomposition is on
    _method = "svd";
    JacobiSVD<MatrixXf> svd(_xXf, ComputeThinV);
    VectorXf eigen_singular_values = svd.singularValues();
    VectorXf tmp_vec = eigen_singular_values.array().square();
    float tmp_sum = tmp_vec.sum();
    tmp_vec /= tmp_sum;
    // PC's standard deviation and
    // PC's proportion of variance
    _kaiser = 0;
    unsigned int lim = (_nrows < _ncols)? _nrows : _ncols;
    for (unsigned int i = 0; i < lim; ++i) {
      _sd.push_back(eigen_singular_values(i)/sqrt(denom));
      if (_sd[i] >= 1) {
        _kaiser = i + 1;
      }
      _prop_of_var.push_back(tmp_vec(i));
//.........这里部分代码省略.........
开发者ID:ihar,项目名称:EigenPCA,代码行数:101,代码来源:pca.cpp

示例6: fwd_load_eeg_sphere_models

//*************************************************************************************************************
//fwd_eeg_sphere_models.c
FwdEegSphereModelSet* FwdEegSphereModelSet::fwd_load_eeg_sphere_models(const QString& filename, FwdEegSphereModelSet* now)
{
    char line[MAXLINE];
    FILE *fp = NULL;
    QString name;
    VectorXf rads;
    VectorXf sigmas;
    int   nlayer  = 0;
    char *one, *two;
    QString tag;

    if (!now)
        now = fwd_add_default_eeg_sphere_model(now);

    if (filename.isEmpty())
        return now;

    QFile t_file(filename);
    if (!t_file.isReadable())	/* Never mind about an unaccesible file */
        return now;


    if ((fp = fopen(filename.toUtf8().data(),"r")) == NULL) {
        printf(filename.toUtf8().data());
        goto bad;
    }
    while (fgets(line,MAXLINE,fp) != NULL) {
        if (line[0] == '#')
            continue;
        one = strtok(line,SEP);
        if (one != NULL) {
            if (tag.isEmpty() || tag.size() == 0)
                name = one;
            else {
                name = QString("%1 %2").arg(one).arg(tag);
            }
            while (1) {
                one = strtok(NULL,SEP);
                if (one == NULL)
                    break;
                two = strtok(NULL,SEP);
                if (two == NULL)
                    break;
                rads.resize(nlayer+1);
                sigmas.resize(nlayer+1);
                if (sscanf(one,"%g",rads[nlayer]) != 1) {
                    nlayer = 0;
                    break;
                }
                if (sscanf(two,"%g",sigmas[nlayer]) != 1) {
                    nlayer = 0;
                    break;
                }
                nlayer++;
            }
            if (nlayer > 0)
                now = fwd_add_to_eeg_sphere_model_set(now,FwdEegSphereModel::fwd_create_eeg_sphere_model(name,nlayer,rads,sigmas));
            nlayer = 0;
        }
    }
    if (ferror(fp)) {
        printf(filename.toUtf8().data());
        goto bad;
    }
    fclose(fp);
    return now;

bad : {
        if (fp)
            fclose(fp);
        delete now;
        return NULL;
    }
}
开发者ID:GBeret,项目名称:mne-cpp,代码行数:76,代码来源:fwd_eeg_sphere_model_set.cpp


注:本文中的VectorXf::resize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。