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


C++ Strings::at方法代码示例

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


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

示例1: buildTree

void NeighbourJoining::buildTree(Matrix& distMatrix, const Strings& labels, Tree* tree)
{
	// allocation space for temporary variables
  m_separationSums = new double[distMatrix.size()];
  m_separations = new double[distMatrix.size()];
  m_numActiveClusters = distMatrix.size();      
  m_activeClusters = new bool[distMatrix.size()];

	//calculate initial seperation rows
  for(uint i = 0; i < distMatrix.size(); i++)
	{
    double sum = 0;
    for(uint j = 0; j < distMatrix.size(); j++)
      sum += distMatrix[i][j];

    m_separationSums[i] = sum;
    m_separations[i] = sum / (m_numActiveClusters-2); 
    m_activeClusters[i] = true;
  }

	// create initial singleton clusters
	std::vector< Node* > clusters;
	for(uint i = 0; i < labels.size(); ++i)
	{
		Node* node = new Node(labels.at(i));
		clusters.push_back(node);
	}

  while(m_numActiveClusters > 2)
	{
    findNearestClusters(distMatrix);
    updateClusters(distMatrix, clusters);
    updateDistanceMatrix(distMatrix);                       
  }

  // finish by joining the two remaining clusters
  int index1 = -1;
  int index2 = -1;

  // find the last nodes
  for(uint i = 0; i < distMatrix.size(); i++)
	{
    if(m_activeClusters[i])
		{
      if(index1 == -1)
				index1 = i;
      else
			{
				index2 = i;	
				break;
      }            
    }
  }  

	// connect remaining subtrees and define arbitrary root of tree
	clusters.at(index1)->addChild(clusters.at(index2));
	clusters.at(index2)->distanceToParent(distMatrix[index1][index2]);

	tree->root(clusters.at(index1));
}
开发者ID:dparks1134,项目名称:PETs,代码行数:60,代码来源:NeighbourJoining.cpp

示例2: print

void PCoA::print(const std::string& filename, const Strings& labels)
{
	std::ofstream fout(filename.c_str());
	if(!fout.is_open())
	{
		std::cout << "[Error] Unable to create file: " << + filename.c_str() << std::endl;
		return;
	}

	// write projected data
	fout << "Projected data (each column is a point): " << std::endl;
	for(uint i = 0; i < labels.size(); ++i)
	{
		fout << labels.at(i);
		if(i < labels.size()-1)
			fout << '\t';
	}
	fout << std::endl;

	for(uint i = 0; i < m_projectedData.at(0).size(); ++i)
	{
		for(uint ptIndex = 0; ptIndex < m_projectedData.size(); ++ptIndex)
		{
			fout << m_projectedData.at(ptIndex).at(i);
			if(ptIndex < m_projectedData.size()-1)
				fout << '\t';
		}
		fout << std::endl;
	}

	// write captured variance
	fout << std::endl << "Captured variance for each dimension: " << std::endl;
	for(uint i = 0; i < m_variance.size(); ++i)
		fout << m_variance.at(i) << std::endl;

	fout.close();
}
开发者ID:dparks1134,项目名称:PETs,代码行数:37,代码来源:PCoA.cpp


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