本文整理汇总了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));
}
示例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();
}