本文整理汇总了C++中TreeType::Centroid方法的典型用法代码示例。如果您正苦于以下问题:C++ TreeType::Centroid方法的具体用法?C++ TreeType::Centroid怎么用?C++ TreeType::Centroid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TreeType
的用法示例。
在下文中一共展示了TreeType::Centroid方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FastMKSStat
FastMKSStat(const TreeType& node) :
bound(-DBL_MAX),
lastKernel(0.0),
lastKernelNode(NULL)
{
// Do we have to calculate the centroid?
if (tree::TreeTraits<TreeType>::FirstPointIsCentroid)
{
// If this type of tree has self-children, then maybe the evaluation is
// already done. These statistics are built bottom-up, so the child stat
// should already be done.
if ((tree::TreeTraits<TreeType>::HasSelfChildren) &&
(node.NumChildren() > 0) &&
(node.Point(0) == node.Child(0).Point(0)))
{
selfKernel = node.Child(0).Stat().SelfKernel();
}
else
{
selfKernel = sqrt(node.Metric().Kernel().Evaluate(
node.Dataset().col(node.Point(0)),
node.Dataset().col(node.Point(0))));
}
}
else
{
// Calculate the centroid.
arma::vec centroid;
node.Centroid(centroid);
selfKernel = sqrt(node.Metric().Kernel().Evaluate(centroid, centroid));
}
}
示例2: CalculateBound
//.........这里部分代码省略.........
else
{
// The reference parent could be NULL, which does weird things and we have
// to consider.
if (traversalInfo.LastQueryNode() != NULL)
{
adjustedScore += refDescDist *
traversalInfo.LastQueryNode()->Stat().SelfKernel();
dualRefTerm = refDescDist;
}
else
{
// This makes it so a child-parent (or parent-parent) prune is not
// possible.
dualRefTerm = 0.0;
adjustedScore = bestKernel;
}
}
// Now add the dual term.
adjustedScore += (dualQueryTerm * dualRefTerm);
if (adjustedScore < bestKernel)
{
// It is not possible that this node combination can contain a point
// combination with kernel value better than the minimum kernel value to
// improve any of the results, so we can prune it.
return DBL_MAX;
}
// We were unable to perform a parent-child or parent-parent prune, so now we
// must calculate kernel evaluation, if necessary.
double kernelEval = 0.0;
if (tree::TreeTraits<TreeType>::FirstPointIsCentroid)
{
// For this type of tree, we may have already calculated the base case in
// the parents.
if ((traversalInfo.LastQueryNode() != NULL) &&
(traversalInfo.LastReferenceNode() != NULL) &&
(traversalInfo.LastQueryNode()->Point(0) == queryNode.Point(0)) &&
(traversalInfo.LastReferenceNode()->Point(0) == referenceNode.Point(0)))
{
// Base case already done.
kernelEval = traversalInfo.LastBaseCase();
// When BaseCase() is called after Score(), these must be correct so that
// another kernel evaluation is not performed.
lastQueryIndex = queryNode.Point(0);
lastReferenceIndex = referenceNode.Point(0);
}
else
{
// The kernel must be evaluated, but it is between points in the dataset,
// so we can call BaseCase(). BaseCase() will set lastQueryIndex and
// lastReferenceIndex correctly.
kernelEval = BaseCase(queryNode.Point(0), referenceNode.Point(0));
}
traversalInfo.LastBaseCase() = kernelEval;
}
else
{
// Calculate the maximum possible kernel value.
arma::vec queryCentroid;
arma::vec refCentroid;
queryNode.Centroid(queryCentroid);
示例3: products
double FastMKSRules<KernelType, TreeType>::Score(const size_t queryIndex,
TreeType& referenceNode)
{
// Compare with the current best.
const double bestKernel = products(products.n_rows - 1, queryIndex);
// See if we can perform a parent-child prune.
const double furthestDist = referenceNode.FurthestDescendantDistance();
if (referenceNode.Parent() != NULL)
{
double maxKernelBound;
const double parentDist = referenceNode.ParentDistance();
const double combinedDistBound = parentDist + furthestDist;
const double lastKernel = referenceNode.Parent()->Stat().LastKernel();
if (kernel::KernelTraits<KernelType>::IsNormalized)
{
const double squaredDist = std::pow(combinedDistBound, 2.0);
const double delta = (1 - 0.5 * squaredDist);
if (lastKernel <= delta)
{
const double gamma = combinedDistBound * sqrt(1 - 0.25 * squaredDist);
maxKernelBound = lastKernel * delta +
gamma * sqrt(1 - std::pow(lastKernel, 2.0));
}
else
{
maxKernelBound = 1.0;
}
}
else
{
maxKernelBound = lastKernel +
combinedDistBound * queryKernels[queryIndex];
}
if (maxKernelBound < bestKernel)
return DBL_MAX;
}
// Calculate the maximum possible kernel value, either by calculating the
// centroid or, if the centroid is a point, use that.
++scores;
double kernelEval;
if (tree::TreeTraits<TreeType>::FirstPointIsCentroid)
{
// Could it be that this kernel evaluation has already been calculated?
if (tree::TreeTraits<TreeType>::HasSelfChildren &&
referenceNode.Parent() != NULL &&
referenceNode.Point(0) == referenceNode.Parent()->Point(0))
{
kernelEval = referenceNode.Parent()->Stat().LastKernel();
}
else
{
kernelEval = BaseCase(queryIndex, referenceNode.Point(0));
}
}
else
{
const arma::vec queryPoint = querySet.unsafe_col(queryIndex);
arma::vec refCentroid;
referenceNode.Centroid(refCentroid);
kernelEval = kernel.Evaluate(queryPoint, refCentroid);
}
referenceNode.Stat().LastKernel() = kernelEval;
double maxKernel;
if (kernel::KernelTraits<KernelType>::IsNormalized)
{
const double squaredDist = std::pow(furthestDist, 2.0);
const double delta = (1 - 0.5 * squaredDist);
if (kernelEval <= delta)
{
const double gamma = furthestDist * sqrt(1 - 0.25 * squaredDist);
maxKernel = kernelEval * delta +
gamma * sqrt(1 - std::pow(kernelEval, 2.0));
}
else
{
maxKernel = 1.0;
}
}
else
{
maxKernel = kernelEval + furthestDist * queryKernels[queryIndex];
}
// We return the inverse of the maximum kernel so that larger kernels are
// recursed into first.
return (maxKernel > bestKernel) ? (1.0 / maxKernel) : DBL_MAX;
}