Merge pull request #2464 from shrit/pre_increment

Pre increment
This commit is contained in:
Ryan Curtin
2020-06-30 10:48:52 -04:00
committed by GitHub
216 changed files with 1244 additions and 1226 deletions
@@ -308,7 +308,7 @@ public:
BOOST_MATH_INSTRUMENT_VARIABLE(tn[1]);
}
for(std::size_t i = std::max<size_t>(2, prev_size); i < m; i++)
for(std::size_t i = std::max<size_t>(2, prev_size); i < m; ++i)
{
bool overflow_check = false;
if(i >= min_overflow_index && (boost::math::tools::max_value<T>() / (i-1) < m_intermediates[1]) )
@@ -317,7 +317,7 @@ public:
break;
}
m_intermediates[1] = m_intermediates[1] * (i-1);
for(std::size_t j = 2; j <= i; j++)
for(std::size_t j = 2; j <= i; ++j)
{
overflow_check =
(i >= min_overflow_index) && (
@@ -360,7 +360,7 @@ public:
T power_two(ldexp(T(1), static_cast<int>(2 * old_size)));
for(std::size_t i = old_size; i < m; i++)
for(std::size_t i = old_size; i < m; ++i)
{
T b(static_cast<T>(i * 2));
//
+1 -1
View File
@@ -76,7 +76,7 @@ bool Load(const std::vector<std::string>& files,
info.Width() * info.Height() * info.Channels(), files.size());
tmpMatrix.col(0) = img;
for (size_t i = 1; i < files.size() ; i++)
for (size_t i = 1; i < files.size() ; ++i)
{
arma::Mat<unsigned char> colImg(tmpMatrix.colptr(i), tmpMatrix.n_rows, 1,
false, true);
+9 -1
View File
@@ -158,10 +158,14 @@ bool Save(const std::string& filename,
{
arma::Mat<eT> tmp = trans(matrix);
#ifdef ARMA_USE_HDF5
// We can't save with streams for HDF5.
const bool success = (saveType == arma::hdf5_binary) ?
tmp.quiet_save(filename, saveType) :
tmp.quiet_save(stream, saveType);
#else
const bool success = tmp.quiet_save(stream, saveType);
#endif
if (!success)
{
Timer::Stop("saving_data");
@@ -175,10 +179,14 @@ bool Save(const std::string& filename,
}
else
{
#ifdef ARMA_USE_HDF5
// We can't save with streams for HDF5.
const bool success = (saveType == arma::hdf5_binary) ?
matrix.quiet_save(filename, saveType) :
matrix.quiet_save(stream, saveType);
#else
const bool success = matrix.quiet_save(stream, saveType);
#endif
if (!success)
{
Timer::Stop("saving_data");
@@ -439,7 +447,7 @@ bool Save(const std::vector<std::string>& files,
arma::Mat<unsigned char> img;
bool status = true;
for (size_t i = 0; i < files.size() ; i++)
for (size_t i = 0; i < files.size() ; ++i)
{
arma::Mat<eT> colImg(matrix.colptr(i), matrix.n_rows, 1,
false, true);
@@ -110,7 +110,7 @@ EncodeHelper(const std::vector<std::string>& input,
policy.Reset();
// The first pass adds the extracted tokens to the dictionary.
for (size_t i = 0; i < input.size(); i++)
for (size_t i = 0; i < input.size(); ++i)
{
boost::string_view strView(input[i]);
auto token = tokenizer(strView);
@@ -141,7 +141,7 @@ EncodeHelper(const std::vector<std::string>& input,
policy.InitMatrix(output, input.size(), numColumns, dictionary.Size());
// The second pass writes the encoded values to the output.
for (size_t i = 0; i < input.size(); i++)
for (size_t i = 0; i < input.size(); ++i)
{
boost::string_view strView(input[i]);
auto token = tokenizer(strView);
@@ -170,7 +170,7 @@ EncodeHelper(const std::vector<std::string>& input,
// The loop below extracts the tokens and writes the encoded values
// at once.
for (size_t i = 0; i < input.size(); i++)
for (size_t i = 0; i < input.size(); ++i)
{
boost::string_view strView(input[i]);
auto token = tokenizer(strView);
@@ -66,7 +66,7 @@ void DiscreteDistribution::Train(const arma::mat& observations)
const size_t dimensions = probabilities.size();
// Clear the old probabilities.
for (size_t i = 0; i < dimensions; i++)
for (size_t i = 0; i < dimensions; ++i)
probabilities[i].zeros();
// Iterate over all the probabilities in each dimension.
@@ -121,13 +121,13 @@ void DiscreteDistribution::Train(const arma::mat& observations,
size_t dimensions = probabilities.size();
// Clear the old probabilities.
for (size_t i = 0; i < dimensions; i++)
for (size_t i = 0; i < dimensions; ++i)
probabilities[i].zeros();
// Ensure that the observation is within the bounds.
for (size_t r = 0; r < observations.n_cols; r++)
{
for (size_t i = 0; i < dimensions; i++)
for (size_t i = 0; i < dimensions; ++i)
{
// Add the probability of each observation. The addition of 0.5
// to the observation is to turn the default flooring operation
@@ -75,7 +75,7 @@ class DiscreteDistribution
*/
DiscreteDistribution(const arma::Col<size_t>& numObservations)
{
for (size_t i = 0; i < numObservations.n_elem; i++)
for (size_t i = 0; i < numObservations.n_elem; ++i)
{
const size_t numObs = size_t(numObservations[i]);
if (numObs <= 0)
@@ -97,7 +97,7 @@ class DiscreteDistribution
*/
DiscreteDistribution(const std::vector<arma::vec>& probabilities)
{
for (size_t i = 0; i < probabilities.size(); i++)
for (size_t i = 0; i < probabilities.size(); ++i)
{
arma::vec temp = probabilities[i];
double sum = accu(temp);
@@ -179,7 +179,7 @@ class DiscreteDistribution
void Probability(const arma::mat& x, arma::vec& probabilities) const
{
probabilities.set_size(x.n_cols);
for (size_t i = 0; i < x.n_cols; i++)
for (size_t i = 0; i < x.n_cols; ++i)
probabilities(i) = Probability(x.unsafe_col(i));
}
@@ -194,7 +194,7 @@ class DiscreteDistribution
void LogProbability(const arma::mat& x, arma::vec& logProbabilities) const
{
logProbabilities.set_size(x.n_cols);
for (size_t i = 0; i < x.n_cols; i++)
for (size_t i = 0; i < x.n_cols; ++i)
logProbabilities(i) = log(Probability(x.unsafe_col(i)));
}
+1 -1
View File
@@ -78,7 +78,7 @@ void GammaDistribution::Train(const arma::mat& rdata,
arma::vec meanxVec(rdata.n_rows, arma::fill::zeros);
arma::vec logMeanxVec(rdata.n_rows, arma::fill::zeros);
for (size_t i = 0; i < rdata.n_cols; i++)
for (size_t i = 0; i < rdata.n_cols; ++i)
{
meanLogxVec += probabilities(i) * arma::log(rdata.col(i));
meanxVec += probabilities(i) * rdata.col(i);
@@ -19,7 +19,7 @@ using namespace mlpack::distribution;
GaussianDistribution::GaussianDistribution(const arma::vec& mean,
const arma::mat& covariance)
: mean(mean)
: mean(mean), logDetCov(0.0)
{
Covariance(covariance);
}
@@ -102,14 +102,14 @@ void GaussianDistribution::Train(const arma::mat& observations)
}
// Calculate the mean.
for (size_t i = 0; i < observations.n_cols; i++)
for (size_t i = 0; i < observations.n_cols; ++i)
mean += observations.col(i);
// Normalize the mean.
mean /= observations.n_cols;
// Now calculate the covariance.
for (size_t i = 0; i < observations.n_cols; i++)
for (size_t i = 0; i < observations.n_cols; ++i)
{
arma::vec obsNoMean = observations.col(i) - mean;
covariance += obsNoMean * trans(obsNoMean);
@@ -150,7 +150,7 @@ void GaussianDistribution::Train(const arma::mat& observations,
// First calculate the mean, and save the sum of all the probabilities for
// later normalization.
for (size_t i = 0; i < observations.n_cols; i++)
for (size_t i = 0; i < observations.n_cols; ++i)
{
mean += probabilities[i] * observations.col(i);
sumProb += probabilities[i];
@@ -170,7 +170,7 @@ void GaussianDistribution::Train(const arma::mat& observations,
mean /= sumProb;
// Now find the covariance.
for (size_t i = 0; i < observations.n_cols; i++)
for (size_t i = 0; i < observations.n_cols; ++i)
{
arma::vec obsNoMean = observations.col(i) - mean;
covariance += probabilities[i] * (obsNoMean * trans(obsNoMean));
@@ -91,7 +91,7 @@ class GaussianDistribution
void Probability(const arma::mat& x, arma::vec& probabilities) const
{
probabilities.set_size(x.n_cols);
for (size_t i = 0; i < x.n_cols; i++)
for (size_t i = 0; i < x.n_cols; ++i)
{
probabilities(i) = Probability(x.unsafe_col(i));
}
@@ -116,7 +116,7 @@ class GaussianDistribution
// so that later we are referencing columns, not rows -- that is faster.
const arma::mat rhs = -0.5 * invCov * diffs;
arma::vec logExponents(diffs.n_cols); // We will now fill this.
for (size_t i = 0; i < diffs.n_cols; i++)
for (size_t i = 0; i < diffs.n_cols; ++i)
logExponents(i) = accu(diffs.unsafe_col(i) % rhs.unsafe_col(i));
logProbabilities = -0.5 * x.n_rows * log2pi - 0.5 * logDetCov +
@@ -37,7 +37,7 @@ void LaplaceDistribution::Probability(const arma::mat& x,
arma::vec& probabilities) const
{
probabilities.set_size(x.n_cols);
for (size_t i = 0; i < x.n_cols; i++)
for (size_t i = 0; i < x.n_cols; ++i)
{
probabilities(i) = Probability(x.unsafe_col(i));
}
@@ -113,7 +113,7 @@ class LaplaceDistribution
void LogProbability(const arma::mat& x, arma::vec& logProbabilities) const
{
logProbabilities.set_size(x.n_cols);
for (size_t i = 0; i < x.n_cols; i++)
for (size_t i = 0; i < x.n_cols; ++i)
{
logProbabilities(i) = LogProbability(x.unsafe_col(i));
}
+8 -8
View File
@@ -23,7 +23,7 @@ using namespace math;
*/
void mlpack::math::VectorPower(arma::vec& vec, const double power)
{
for (size_t i = 0; i < vec.n_elem; i++)
for (size_t i = 0; i < vec.n_elem; ++i)
{
if (std::abs(vec(i)) > 1e-12)
vec(i) = (vec(i) > 0) ? std::pow(vec(i), (double) power) :
@@ -197,9 +197,9 @@ void mlpack::math::Svec(const arma::mat& input, arma::vec& output)
output.zeros(n2bar);
size_t idx = 0;
for (size_t i = 0; i < n; i++)
for (size_t i = 0; i < n; ++i)
{
for (size_t j = i; j < n; j++)
for (size_t j = i; j < n; ++j)
{
if (i == j)
output(idx++) = input(i, j);
@@ -238,9 +238,9 @@ void mlpack::math::Smat(const arma::vec& input, arma::mat& output)
output.zeros(n, n);
size_t idx = 0;
for (size_t i = 0; i < n; i++)
for (size_t i = 0; i < n; ++i)
{
for (size_t j = i; j < n; j++)
for (size_t j = i; j < n; ++j)
{
if (i == j)
output(i, j) = input(idx++);
@@ -259,11 +259,11 @@ void mlpack::math::SymKronId(const arma::mat& A, arma::mat& op)
op.zeros(n2bar, n2bar);
size_t idx = 0;
for (size_t i = 0; i < n; i++)
for (size_t i = 0; i < n; ++i)
{
for (size_t j = i; j < n; j++)
for (size_t j = i; j < n; ++j)
{
for (size_t k = 0; k < n; k++)
for (size_t k = 0; k < n; ++k)
{
op(idx, SvecIndex(k, j, n)) +=
((k == j) ? 1. : M_SQRT1_2) * A(i, k);
+2 -2
View File
@@ -158,7 +158,7 @@ inline void ObtainDistinctSamples(const size_t loInclusive,
samples.zeros(samplesRangeSize);
for (size_t i = 0; i < maxNumSamples; i++)
for (size_t i = 0; i < maxNumSamples; ++i)
samples [ (size_t) math::RandInt(samplesRangeSize) ]++;
distinctSamples = arma::find(samples > 0);
@@ -169,7 +169,7 @@ inline void ObtainDistinctSamples(const size_t loInclusive,
else
{
distinctSamples.set_size(samplesRangeSize);
for (size_t i = 0; i < samplesRangeSize; i++)
for (size_t i = 0; i < samplesRangeSize; ++i)
distinctSamples[i] = loInclusive + i;
}
}
+2 -2
View File
@@ -26,7 +26,7 @@ typename VecTypeA::elem_type LMetric<Power, TakeRoot>::Evaluate(
const VecTypeB& b)
{
typename VecTypeA::elem_type sum = 0;
for (size_t i = 0; i < a.n_elem; i++)
for (size_t i = 0; i < a.n_elem; ++i)
sum += std::pow(fabs(a[i] - b[i]), Power);
if (!TakeRoot) // The compiler should optimize this correctly at compile-time.
@@ -81,7 +81,7 @@ typename VecTypeA::elem_type LMetric<3, true>::Evaluate(
const VecTypeB& b)
{
typename VecTypeA::elem_type sum = 0;
for (size_t i = 0; i < a.n_elem; i++)
for (size_t i = 0; i < a.n_elem; ++i)
sum += std::pow(fabs(a[i] - b[i]), 3.0);
return std::pow(arma::accu(arma::pow(arma::abs(a - b), 3.0)), 1.0 / 3.0);
+7 -7
View File
@@ -79,7 +79,7 @@ void PointToAddress(AddressType& address, const VecType& point)
assert(point.n_elem == address.n_elem);
assert(address.n_elem > 0);
for (size_t i = 0; i < point.n_elem; i++)
for (size_t i = 0; i < point.n_elem; ++i)
{
int e;
VecElemType normalizedVal = std::frexp(point(i), &e);
@@ -128,8 +128,8 @@ void PointToAddress(AddressType& address, const VecType& point)
// Interleave the bits of the new representation across all the elements
// in the address vector.
for (size_t i = 0; i < order; i++)
for (size_t j = 0; j < point.n_elem; j++)
for (size_t i = 0; i < order; ++i)
for (size_t j = 0; j < point.n_elem; ++j)
{
size_t bit = (i * point.n_elem + j) % order;
size_t row = (i * point.n_elem + j) / order;
@@ -176,8 +176,8 @@ void AddressToPoint(VecType& point, const AddressType& address)
// Calculate the number of bits for the mantissa.
const int numMantBits = order - numExpBits - 1;
for (size_t i = 0; i < order; i++)
for (size_t j = 0; j < address.n_elem; j++)
for (size_t i = 0; i < order; ++i)
for (size_t j = 0; j < address.n_elem; ++j)
{
size_t bit = (i * address.n_elem + j) % order;
size_t row = (i * address.n_elem + j) / order;
@@ -186,7 +186,7 @@ void AddressToPoint(VecType& point, const AddressType& address)
(order - 1 - i));
}
for (size_t i = 0; i < rearrangedAddress.n_elem; i++)
for (size_t i = 0; i < rearrangedAddress.n_elem; ++i)
{
bool sgn = rearrangedAddress(i) & ((AddressElemType) 1 << (order - 1));
@@ -238,7 +238,7 @@ int CompareAddresses(const AddressType1& addr1, const AddressType2& addr2)
assert(addr1.n_elem == addr2.n_elem);
for (size_t i = 0; i < addr1.n_elem; i++)
for (size_t i = 0; i < addr1.n_elem; ++i)
{
if (addr1[i] < addr2[i])
return -1;
@@ -72,7 +72,7 @@ BinarySpaceTree(
{
// Initialize oldFromNew correctly.
oldFromNew.resize(data.n_cols);
for (size_t i = 0; i < data.n_cols; i++)
for (size_t i = 0; i < data.n_cols; ++i)
oldFromNew[i] = i; // Fill with unharmed indices.
// Now do the actual splitting.
@@ -106,7 +106,7 @@ BinarySpaceTree(
{
// Initialize the oldFromNew vector correctly.
oldFromNew.resize(data.n_cols);
for (size_t i = 0; i < data.n_cols; i++)
for (size_t i = 0; i < data.n_cols; ++i)
oldFromNew[i] = i; // Fill with unharmed indices.
// Now do the actual splitting.
@@ -118,7 +118,7 @@ BinarySpaceTree(
// Map the newFromOld indices correctly.
newFromOld.resize(data.n_cols);
for (size_t i = 0; i < data.n_cols; i++)
for (size_t i = 0; i < data.n_cols; ++i)
newFromOld[oldFromNew[i]] = i;
}
@@ -169,7 +169,7 @@ BinarySpaceTree(
{
// Initialize oldFromNew correctly.
oldFromNew.resize(dataset->n_cols);
for (size_t i = 0; i < dataset->n_cols; i++)
for (size_t i = 0; i < dataset->n_cols; ++i)
oldFromNew[i] = i; // Fill with unharmed indices.
// Now do the actual splitting.
@@ -203,7 +203,7 @@ BinarySpaceTree(
{
// Initialize the oldFromNew vector correctly.
oldFromNew.resize(dataset->n_cols);
for (size_t i = 0; i < dataset->n_cols; i++)
for (size_t i = 0; i < dataset->n_cols; ++i)
oldFromNew[i] = i; // Fill with unharmed indices.
// Now do the actual splitting.
@@ -215,7 +215,7 @@ BinarySpaceTree(
// Map the newFromOld indices correctly.
newFromOld.resize(dataset->n_cols);
for (size_t i = 0; i < dataset->n_cols; i++)
for (size_t i = 0; i < dataset->n_cols; ++i)
newFromOld[oldFromNew[i]] = i;
}
@@ -315,7 +315,7 @@ BinarySpaceTree(
// Map the newFromOld indices correctly.
newFromOld.resize(dataset->n_cols);
for (size_t i = 0; i < dataset->n_cols; i++)
for (size_t i = 0; i < dataset->n_cols; ++i)
newFromOld[oldFromNew[i]] = i;
}
@@ -54,7 +54,7 @@ bool RPTreeMaxSplit<BoundType, MatType>::GetSplitVal(
arma::Col<ElemType> values(samples.n_elem);
// Find the median of scalar products of the samples and the normal vector.
for (size_t k = 0; k < samples.n_elem; k++)
for (size_t k = 0; k < samples.n_elem; ++k)
values[k] = arma::dot(data.col(samples[k]), direction);
const ElemType maximum = arma::max(values);
@@ -70,8 +70,8 @@ GetAveragePointDistance(
{
ElemType dist = 0;
for (size_t i = 0; i < samples.n_elem; i++)
for (size_t j = i + 1; j < samples.n_elem; j++)
for (size_t i = 0; i < samples.n_elem; ++i)
for (size_t j = i + 1; j < samples.n_elem; ++j)
dist += metric::SquaredEuclideanDistance::Evaluate(data.col(samples[i]),
data.col(samples[j]));
@@ -89,7 +89,7 @@ bool RPTreeMeanSplit<BoundType, MatType>::GetDotMedian(
{
arma::Col<ElemType> values(samples.n_elem);
for (size_t k = 0; k < samples.n_elem; k++)
for (size_t k = 0; k < samples.n_elem; ++k)
values[k] = arma::dot(data.col(samples[k]), direction);
const ElemType maximum = arma::max(values);
@@ -118,7 +118,7 @@ bool RPTreeMeanSplit<BoundType, MatType>::GetMeanMedian(
arma::Col<ElemType> tmp(data.n_rows);
for (size_t k = 0; k < samples.n_elem; k++)
for (size_t k = 0; k < samples.n_elem; ++k)
{
tmp = data.col(samples[k]);
tmp -= mean;
@@ -132,7 +132,7 @@ bool UBTreeSplit<BoundType, MatType>::SplitNode(BoundType& bound,
}
// Set the minimum and the maximum addresses.
for (size_t k = 0; k < bound.Dim(); k++)
for (size_t k = 0; k < bound.Dim(); ++k)
{
bound.LoAddress()[k] = addresses[begin].first[k];
bound.HiAddress()[k] = addresses[begin + count - 1].first[k];
@@ -148,7 +148,7 @@ void UBTreeSplit<BoundType, MatType>::InitializeAddresses(const MatType& data)
addresses.resize(data.n_cols);
// Calculate all addresses.
for (size_t i = 0; i < data.n_cols; i++)
for (size_t i = 0; i < data.n_cols; ++i)
{
addresses[i].first.zeros(data.n_rows);
bound::addr::PointToAddress(addresses[i].first, data.col(i));
@@ -169,13 +169,13 @@ size_t UBTreeSplit<BoundType, MatType>::PerformSplit(
std::vector<size_t> newFromOld(data.n_cols);
std::vector<size_t> oldFromNew(data.n_cols);
for (size_t i = 0; i < splitInfo.addresses->size(); i++)
for (size_t i = 0; i < splitInfo.addresses->size(); ++i)
{
newFromOld[i] = i;
oldFromNew[i] = i;
}
for (size_t i = 0; i < splitInfo.addresses->size(); i++)
for (size_t i = 0; i < splitInfo.addresses->size(); ++i)
{
size_t index = (*splitInfo.addresses)[i].second;
size_t oldI = oldFromNew[i];
@@ -210,10 +210,10 @@ size_t UBTreeSplit<BoundType, MatType>::PerformSplit(
{
std::vector<size_t> newFromOld(data.n_cols);
for (size_t i = 0; i < splitInfo.addresses->size(); i++)
for (size_t i = 0; i < splitInfo.addresses->size(); ++i)
newFromOld[i] = i;
for (size_t i = 0; i < splitInfo.addresses->size(); i++)
for (size_t i = 0; i < splitInfo.addresses->size(); ++i)
{
size_t index = (*splitInfo.addresses)[i].second;
size_t oldI = oldFromNew[i];
@@ -55,7 +55,7 @@ SelectVantagePoint(const MetricType& metric, const MatType& data,
arma::uvec samples;
// Evaluate each candidate
for (size_t i = 0; i < vantagePointCandidates.n_elem; i++)
for (size_t i = 0; i < vantagePointCandidates.n_elem; ++i)
{
// Get no more than min(MaxNumSamples, count) random samples
math::ObtainDistinctSamples(begin, begin + count, MaxNumSamples, samples);
@@ -64,7 +64,7 @@ SelectVantagePoint(const MetricType& metric, const MatType& data,
// candidate using these random samples.
distances.set_size(samples.n_elem);
for (size_t j = 0; j < samples.n_elem; j++)
for (size_t j = 0; j < samples.n_elem; ++j)
distances[j] = metric.Evaluate(data.col(vantagePointCandidates[i]),
data.col(samples[j]));
+31 -27
View File
@@ -51,7 +51,7 @@ inline CellBound<MetricType, ElemType>::CellBound(const size_t dimension) :
hiAddress(dim),
minWidth(0)
{
for (size_t k = 0; k < dim ; k++)
for (size_t k = 0; k < dim ; ++k)
{
loAddress[k] = std::numeric_limits<AddressElemType>::max();
hiAddress[k] = 0;
@@ -74,7 +74,7 @@ inline CellBound<MetricType, ElemType>::CellBound(
minWidth(other.MinWidth())
{
// Copy other bounds over.
for (size_t i = 0; i < dim; i++)
for (size_t i = 0; i < dim; ++i)
bounds[i] = other.bounds[i];
}
@@ -87,9 +87,13 @@ inline CellBound<
ElemType>& CellBound<MetricType, ElemType>::operator=(
const CellBound<MetricType, ElemType>& other)
{
if (dim != other.Dim())
if (this == &other)
return *this;
if (dim != other.Dim())
{
// Reallocation is necessary.
delete[] bounds;
dim = other.Dim();
bounds = new math::RangeType<ElemType>[dim];
@@ -102,7 +106,7 @@ inline CellBound<
hiAddress = other.hiAddress;
// Now copy each of the bound values.
for (size_t i = 0; i < dim; i++)
for (size_t i = 0; i < dim; ++i)
bounds[i] = other.bounds[i];
minWidth = other.MinWidth();
@@ -147,7 +151,7 @@ inline CellBound<MetricType, ElemType>::~CellBound()
template<typename MetricType, typename ElemType>
inline void CellBound<MetricType, ElemType>::Clear()
{
for (size_t k = 0; k < dim; k++)
for (size_t k = 0; k < dim; ++k)
{
bounds[k] = math::RangeType<ElemType>();
@@ -171,7 +175,7 @@ inline void CellBound<MetricType, ElemType>::Center(
if (!(center.n_elem == dim))
center.set_size(dim);
for (size_t i = 0; i < dim; i++)
for (size_t i = 0; i < dim; ++i)
center(i) = bounds[i].Mid();
}
@@ -187,17 +191,17 @@ void CellBound<MetricType, ElemType>::AddBound(
assert(loCorner.n_elem == dim);
assert(hiCorner.n_elem == dim);
for (size_t k = 0; k < dim; k++)
for (size_t k = 0; k < dim; ++k)
{
loBound(k, numBounds) = std::numeric_limits<ElemType>::max();
hiBound(k, numBounds) = std::numeric_limits<ElemType>::lowest();
}
for (size_t i = 0; i < data.n_cols; i++)
for (size_t i = 0; i < data.n_cols; ++i)
{
size_t k = 0;
// Check if the point is contained in the hyperrectangle.
for (k = 0; k < dim; k++)
for (k = 0; k < dim; ++k)
if (data(k, i) < loCorner[k] || data(k, i) > hiCorner[k])
break;
@@ -205,14 +209,14 @@ void CellBound<MetricType, ElemType>::AddBound(
continue; // The point is not contained in the hyperrectangle.
// Shrink the bound.
for (k = 0; k < dim; k++)
for (k = 0; k < dim; ++k)
{
loBound(k, numBounds) = std::min(loBound(k, numBounds), data(k, i));
hiBound(k, numBounds) = std::max(hiBound(k, numBounds), data(k, i));
}
}
for (size_t k = 0; k < dim; k++)
for (size_t k = 0; k < dim; ++k)
if (loBound(k, numBounds) > hiBound(k, numBounds))
return; // The hyperrectangle does not contain points.
@@ -415,7 +419,7 @@ void CellBound<MetricType, ElemType>::UpdateAddressBounds(const MatType& data)
// If the high address is equal to the lower address.
if (row == hiAddress.n_elem)
{
for (size_t i = 0; i < dim; i++)
for (size_t i = 0; i < dim; ++i)
{
loBound(i, 0) = bounds[i].Lo();
hiBound(i, 0) = bounds[i].Hi();
@@ -434,7 +438,7 @@ void CellBound<MetricType, ElemType>::UpdateAddressBounds(const MatType& data)
if ((row == hiAddress.n_elem - 1) && (bit == order - 1))
{
// If the addresses differ in the last bit.
for (size_t i = 0; i < dim; i++)
for (size_t i = 0; i < dim; ++i)
{
loBound(i, 0) = bounds[i].Lo();
hiBound(i, 0) = bounds[i].Hi();
@@ -454,7 +458,7 @@ void CellBound<MetricType, ElemType>::UpdateAddressBounds(const MatType& data)
if (numBounds == 0)
{
// I think this should never happen.
for (size_t i = 0; i < dim; i++)
for (size_t i = 0; i < dim; ++i)
{
loBound(i, 0) = bounds[i].Lo();
hiBound(i, 0) = bounds[i].Hi();
@@ -479,7 +483,7 @@ inline ElemType CellBound<MetricType, ElemType>::MinDistance(
ElemType lower, higher;
for (size_t i = 0; i < numBounds; i++)
for (size_t i = 0; i < numBounds; ++i)
{
ElemType sum = 0;
@@ -549,8 +553,8 @@ ElemType CellBound<MetricType, ElemType>::MinDistance(const CellBound& other)
ElemType lower, higher;
for (size_t i = 0; i < numBounds; i++)
for (size_t j = 0; j < other.numBounds; j++)
for (size_t i = 0; i < numBounds; ++i)
for (size_t j = 0; j < other.numBounds; ++j)
{
ElemType sum = 0;
for (size_t d = 0; d < dim; d++)
@@ -616,7 +620,7 @@ inline ElemType CellBound<MetricType, ElemType>::MaxDistance(
Log::Assert(point.n_elem == dim);
for (size_t i = 0; i < numBounds; i++)
for (size_t i = 0; i < numBounds; ++i)
{
ElemType sum = 0;
for (size_t d = 0; d < dim; d++)
@@ -663,8 +667,8 @@ inline ElemType CellBound<MetricType, ElemType>::MaxDistance(
Log::Assert(dim == other.dim);
ElemType v;
for (size_t i = 0; i < numBounds; i++)
for (size_t j = 0; j < other.numBounds; j++)
for (size_t i = 0; i < numBounds; ++i)
for (size_t j = 0; j < other.numBounds; ++j)
{
ElemType sum = 0;
for (size_t d = 0; d < dim; d++)
@@ -714,8 +718,8 @@ CellBound<MetricType, ElemType>::RangeDistance(
ElemType v1, v2, vLo, vHi;
for (size_t i = 0; i < numBounds; i++)
for (size_t j = 0; j < other.numBounds; j++)
for (size_t i = 0; i < numBounds; ++i)
for (size_t j = 0; j < other.numBounds; ++j)
{
ElemType loSum = 0;
ElemType hiSum = 0;
@@ -793,7 +797,7 @@ CellBound<MetricType, ElemType>::RangeDistance(
Log::Assert(point.n_elem == dim);
ElemType v1, v2, vLo, vHi;
for (size_t i = 0; i < numBounds; i++)
for (size_t i = 0; i < numBounds; ++i)
{
ElemType loSum = 0;
ElemType hiSum = 0;
@@ -876,7 +880,7 @@ CellBound<MetricType, ElemType>::operator|=(const MatType& data)
arma::Col<ElemType> maxs(arma::max(data, 1));
minWidth = std::numeric_limits<ElemType>::max();
for (size_t i = 0; i < dim; i++)
for (size_t i = 0; i < dim; ++i)
{
bounds[i] |= math::RangeType<ElemType>(mins[i], maxs[i]);
const ElemType width = bounds[i].Width();
@@ -902,7 +906,7 @@ CellBound<MetricType, ElemType>::operator|=(const CellBound& other)
assert(other.dim == dim);
minWidth = std::numeric_limits<ElemType>::max();
for (size_t i = 0; i < dim; i++)
for (size_t i = 0; i < dim; ++i)
{
bounds[i] |= other.bounds[i];
const ElemType width = bounds[i].Width();
@@ -918,7 +922,7 @@ CellBound<MetricType, ElemType>::operator|=(const CellBound& other)
if (loAddress[0] > hiAddress[0])
{
for (size_t i = 0; i < dim; i++)
for (size_t i = 0; i < dim; ++i)
{
loBound(i, 0) = bounds[i].Lo();
hiBound(i, 0) = bounds[i].Hi();
@@ -936,7 +940,7 @@ template<typename VecType>
inline bool CellBound<MetricType, ElemType>::Contains(
const VecType& point) const
{
for (size_t i = 0; i < point.n_elem; i++)
for (size_t i = 0; i < point.n_elem; ++i)
{
if (!bounds[i].Contains(point(i)))
return false;
@@ -30,7 +30,7 @@ CosineTree::CosineTree(const arma::mat& dataset) :
l2NormsSquared.zeros(numColumns);
// Set indices and calculate squared norms of the columns.
for (size_t i = 0; i < numColumns; i++)
for (size_t i = 0; i < numColumns; ++i)
{
indices[i] = i;
double l2Norm = arma::norm(dataset.col(i), 2);
@@ -60,7 +60,7 @@ CosineTree::CosineTree(CosineTree& parentNode,
l2NormsSquared.zeros(numColumns);
// Set indices and squared norms of the columns.
for (size_t i = 0; i < numColumns; i++)
for (size_t i = 0; i < numColumns; ++i)
{
indices[i] = parentNode.indices[subIndices[i]];
l2NormsSquared(i) = parentNode.l2NormsSquared(subIndices[i]);
@@ -381,7 +381,7 @@ void CosineTree::ModifiedGramSchmidt(CosineNodeQueue& treeQueue,
// For every vector in the current basis, remove its projection from the
// centroid.
for ( ; i != treeQueue.end(); i++)
for ( ; i != treeQueue.end(); ++i)
{
currentNode = *i;
@@ -430,7 +430,7 @@ double CosineTree::MonteCarloError(CosineTree* node,
projectionSize = treeQueue.size();
// For each sample, calculate the weighted projection onto the current basis.
for (size_t i = 0; i < numSamples; i++)
for (size_t i = 0; i < numSamples; ++i)
{
// Initialize projection as a vector of zeros.
arma::vec projection;
@@ -441,7 +441,7 @@ double CosineTree::MonteCarloError(CosineTree* node,
size_t k = 0;
// Compute the projection of the sampled vector onto the existing subspace.
for ( ; j != treeQueue.end(); j++, k++)
for ( ; j != treeQueue.end(); ++j, ++k)
{
currentNode = *j;
@@ -497,7 +497,7 @@ void CosineTree::ConstructBasis(CosineNodeQueue& treeQueue)
// Transfer basis vectors from the queue to the basis matrix.
size_t j = 0;
for ( ; i != treeQueue.end(); i++, j++)
for ( ; i != treeQueue.end(); ++i, ++j)
{
currentNode = *i;
basis.col(j) = currentNode->BasisVector();
@@ -528,7 +528,7 @@ void CosineTree::CosineNodeSplit()
// We deviate from the paper here and use < instead of <= in order to handle
// the edge case where cosineMax == cosineMin, and force there to be at least
// one point in the right node.
for (size_t i = 0; i < numColumns; i++)
for (size_t i = 0; i < numColumns; ++i)
{
if (cosineMax - cosines(i) < cosines(i) - cosineMin)
leftIndices.push_back(i);
@@ -550,7 +550,7 @@ void CosineTree::ColumnSamplesLS(std::vector<size_t>& sampledIndices,
cDistribution.zeros(numColumns + 1);
// Calculate cumulative length-squared distribution for the node.
for (size_t i = 0; i < numColumns; i++)
for (size_t i = 0; i < numColumns; ++i)
{
cDistribution(i + 1) = cDistribution(i) +
(l2NormsSquared(i) / frobNormSquared);
@@ -560,7 +560,7 @@ void CosineTree::ColumnSamplesLS(std::vector<size_t>& sampledIndices,
sampledIndices.resize(numSamples);
probabilities.zeros(numSamples);
for (size_t i = 0; i < numSamples; i++)
for (size_t i = 0; i < numSamples; ++i)
{
// Generate a random value for sampling.
double randValue = arma::randu();
@@ -586,7 +586,7 @@ size_t CosineTree::ColumnSampleLS()
cDistribution.zeros(numColumns + 1);
// Calculate cumulative length-squared distribution for the node.
for (size_t i = 0; i < numColumns; i++)
for (size_t i = 0; i < numColumns; ++i)
{
cDistribution(i + 1) = cDistribution(i) +
(l2NormsSquared(i) / frobNormSquared);
@@ -633,7 +633,7 @@ void CosineTree::CalculateCosines(arma::vec& cosines)
// Initialize cosine vector as a vector of zeros.
cosines.zeros(numColumns);
for (size_t i = 0; i < numColumns; i++)
for (size_t i = 0; i < numColumns; ++i)
{
// If norm is zero, store cosine value as zero. Else, calculate cosine value
// between two vectors.
@@ -656,7 +656,7 @@ void CosineTree::CalculateCentroid()
centroid.zeros(dataset->n_rows);
// Calculate centroid of columns in the node.
for (size_t i = 0; i < numColumns; i++)
for (size_t i = 0; i < numColumns; ++i)
{
centroid += dataset->col(indices[i]);
}
+14 -11
View File
@@ -52,7 +52,7 @@ inline HRectBound<MetricType, ElemType>::HRectBound(
minWidth(other.MinWidth())
{
// Copy other bounds over.
for (size_t i = 0; i < dim; i++)
for (size_t i = 0; i < dim; ++i)
bounds[i] = other[i];
}
@@ -65,6 +65,9 @@ inline HRectBound<
ElemType>& HRectBound<MetricType,
ElemType>::operator=(const HRectBound<MetricType, ElemType>& other)
{
if (this == &other)
return *this;
if (dim != other.Dim())
{
// Reallocation is necessary.
@@ -76,7 +79,7 @@ inline HRectBound<
}
// Now copy each of the bound values.
for (size_t i = 0; i < dim; i++)
for (size_t i = 0; i < dim; ++i)
bounds[i] = other[i];
minWidth = other.MinWidth();
@@ -116,7 +119,7 @@ inline HRectBound<MetricType, ElemType>::~HRectBound()
template<typename MetricType, typename ElemType>
inline void HRectBound<MetricType, ElemType>::Clear()
{
for (size_t i = 0; i < dim; i++)
for (size_t i = 0; i < dim; ++i)
bounds[i] = math::RangeType<ElemType>();
minWidth = 0;
}
@@ -134,7 +137,7 @@ inline void HRectBound<MetricType, ElemType>::Center(
if (!(center.n_elem == dim))
center.set_size(dim);
for (size_t i = 0; i < dim; i++)
for (size_t i = 0; i < dim; ++i)
center(i) = bounds[i].Mid();
}
@@ -516,7 +519,7 @@ HRectBound<MetricType, ElemType>::operator|=(const MatType& data)
arma::Col<ElemType> maxs(max(data, 1));
minWidth = std::numeric_limits<ElemType>::max();
for (size_t i = 0; i < dim; i++)
for (size_t i = 0; i < dim; ++i)
{
bounds[i] |= math::RangeType<ElemType>(mins[i], maxs[i]);
const ElemType width = bounds[i].Width();
@@ -537,7 +540,7 @@ HRectBound<MetricType, ElemType>::operator|=(const HRectBound& other)
assert(other.dim == dim);
minWidth = std::numeric_limits<ElemType>::max();
for (size_t i = 0; i < dim; i++)
for (size_t i = 0; i < dim; ++i)
{
bounds[i] |= other.bounds[i];
const ElemType width = bounds[i].Width();
@@ -556,7 +559,7 @@ template<typename VecType>
inline bool HRectBound<MetricType, ElemType>::Contains(
const VecType& point) const
{
for (size_t i = 0; i < point.n_elem; i++)
for (size_t i = 0; i < point.n_elem; ++i)
{
if (!bounds[i].Contains(point(i)))
return false;
@@ -572,7 +575,7 @@ template<typename MetricType, typename ElemType>
inline bool HRectBound<MetricType, ElemType>::Contains(
const HRectBound& bound) const
{
for (size_t i = 0; i < dim; i++)
for (size_t i = 0; i < dim; ++i)
{
const math::RangeType<ElemType>& r_a = bounds[i];
const math::RangeType<ElemType>& r_b = bound.bounds[i];
@@ -594,7 +597,7 @@ HRectBound<MetricType, ElemType>::operator&(const HRectBound& bound) const
{
HRectBound<MetricType, ElemType> result(dim);
for (size_t k = 0; k < dim; k++)
for (size_t k = 0; k < dim; ++k)
{
result[k].Lo() = std::max(bounds[k].Lo(), bound.bounds[k].Lo());
result[k].Hi() = std::min(bounds[k].Hi(), bound.bounds[k].Hi());
@@ -609,7 +612,7 @@ template<typename MetricType, typename ElemType>
inline HRectBound<MetricType, ElemType>&
HRectBound<MetricType, ElemType>::operator&=(const HRectBound& bound)
{
for (size_t k = 0; k < dim; k++)
for (size_t k = 0; k < dim; ++k)
{
bounds[k].Lo() = std::max(bounds[k].Lo(), bound.bounds[k].Lo());
bounds[k].Hi() = std::min(bounds[k].Hi(), bound.bounds[k].Hi());
@@ -626,7 +629,7 @@ inline ElemType HRectBound<MetricType, ElemType>::Overlap(
{
ElemType volume = 1.0;
for (size_t k = 0; k < dim; k++)
for (size_t k = 0; k < dim; ++k)
{
ElemType lo = std::max(bounds[k].Lo(), bound.bounds[k].Lo());
ElemType hi = std::min(bounds[k].Hi(), bound.bounds[k].Hi());
+2 -2
View File
@@ -141,7 +141,7 @@ Octree<MetricType, StatisticType, MatType>::Octree(
// Map the newFromOld indices correctly.
newFromOld.resize(this->dataset->n_cols);
for (size_t i = 0; i < this->dataset->n_cols; i++)
for (size_t i = 0; i < this->dataset->n_cols; ++i)
newFromOld[oldFromNew[i]] = i;
}
@@ -267,7 +267,7 @@ Octree<MetricType, StatisticType, MatType>::Octree(
// Map the newFromOld indices correctly.
newFromOld.resize(this->dataset->n_cols);
for (size_t i = 0; i < this->dataset->n_cols; i++)
for (size_t i = 0; i < this->dataset->n_cols; ++i)
newFromOld[oldFromNew[i]] = i;
}
@@ -163,7 +163,7 @@ CalculateValue(const VecType& pt,
// Calculate the number of bits for the mantissa.
const int numMantBits = order - numExpBits - 1;
for (size_t i = 0; i < pt.n_rows; i++)
for (size_t i = 0; i < pt.n_rows; ++i)
{
int e;
VecElemType normalizedVal = std::frexp(pt(i), &e);
@@ -216,7 +216,7 @@ CalculateValue(const VecType& pt,
{
HilbertElemType P = Q - 1;
for (size_t i = 0; i < pt.n_rows; i++)
for (size_t i = 0; i < pt.n_rows; ++i)
{
if (res(i) & Q) // Invert.
res(0) ^= P;
@@ -230,7 +230,7 @@ CalculateValue(const VecType& pt,
}
// Gray encode.
for (size_t i = 1; i < pt.n_rows; i++)
for (size_t i = 1; i < pt.n_rows; ++i)
res(i) ^= res(i - 1);
HilbertElemType t = 0;
@@ -240,14 +240,14 @@ CalculateValue(const VecType& pt,
if (res(pt.n_rows - 1) & Q)
t ^= Q - 1;
for (size_t i = 0; i < pt.n_rows; i++)
for (size_t i = 0; i < pt.n_rows; ++i)
res(i) ^= t;
// We should rearrange bits in order to compare two Hilbert values faster.
arma::Col<HilbertElemType> rearrangedResult(pt.n_rows, arma::fill::zeros);
for (size_t i = 0; i < order; i++)
for (size_t j = 0; j < pt.n_rows; j++)
for (size_t i = 0; i < order; ++i)
for (size_t j = 0; j < pt.n_rows; ++j)
{
size_t bit = (i * pt.n_rows + j) % order;
size_t row = (i * pt.n_rows + j) / order;
@@ -264,7 +264,7 @@ int DiscreteHilbertValue<TreeElemType>::
CompareValues(const arma::Col<HilbertElemType>& value1,
const arma::Col<HilbertElemType>& value2)
{
for (size_t i = 0; i < value1.n_rows; i++)
for (size_t i = 0; i < value1.n_rows; ++i)
{
if (value1(i) > value2(i))
return 1;
@@ -355,7 +355,7 @@ InsertPoint(TreeType *node,
if (node->IsLeaf())
{
// Find an appropriate place.
for (i = 0; i < numValues; i++)
for (i = 0; i < numValues; ++i)
if (CompareValues(localHilbertValues->col(i), *valueToInsert) > 0)
break;
@@ -436,6 +436,12 @@ template<typename TreeElemType>
DiscreteHilbertValue<TreeElemType>& DiscreteHilbertValue<TreeElemType>::
operator=(const DiscreteHilbertValue& val)
{
if (this == &val)
return *this;
if (ownsLocalHilbertValues)
delete localHilbertValues;
localHilbertValues = const_cast<arma::Mat<HilbertElemType>* >
(val.LocalHilbertValues());
ownsLocalHilbertValues = false;
@@ -473,19 +479,19 @@ void DiscreteHilbertValue<TreeElemType>::RedistributeHilbertValues(
{
// We need to update the local dataset if points were redistributed.
size_t numPoints = 0;
for (size_t i = firstSibling; i <= lastSibling; i++)
for (size_t i = firstSibling; i <= lastSibling; ++i)
numPoints += parent->Child(i).NumPoints();
// Copy the local Hilbert values.
arma::Mat<HilbertElemType> tmp(localHilbertValues->n_rows, numPoints);
size_t iPoint = 0;
for (size_t i = firstSibling; i<= lastSibling; i++)
for (size_t i = firstSibling; i<= lastSibling; ++i)
{
DiscreteHilbertValue<TreeElemType> &value =
parent->Child(i).AuxiliaryInfo().HilbertValue();
for (size_t j = 0; j < value.NumValues(); j++)
for (size_t j = 0; j < value.NumValues(); ++j)
{
tmp.col(iPoint) = value.LocalHilbertValues()->col(j);
iPoint++;
@@ -496,12 +502,12 @@ void DiscreteHilbertValue<TreeElemType>::RedistributeHilbertValues(
iPoint = 0;
// Redistribute the Hilbert values.
for (size_t i = firstSibling; i <= lastSibling; i++)
for (size_t i = firstSibling; i <= lastSibling; ++i)
{
DiscreteHilbertValue<TreeElemType> &value =
parent->Child(i).AuxiliaryInfo().HilbertValue();
for (size_t j = 0; j < parent->Child(i).NumPoints(); j++)
for (size_t j = 0; j < parent->Child(i).NumPoints(); ++j)
{
value.LocalHilbertValues()->col(j) = tmp.col(iPoint);
iPoint++;
@@ -105,7 +105,7 @@ DualTreeTraverser<RuleType>::Traverse(RectangleTree& queryNode,
// We sort the children of the reference node by their scores.
std::vector<NodeAndScore> nodesAndScores(referenceNode.NumChildren());
for (size_t i = 0; i < referenceNode.NumChildren(); i++)
for (size_t i = 0; i < referenceNode.NumChildren(); ++i)
{
rule.TraversalInfo() = traversalInfo;
nodesAndScores[i].node = &(referenceNode.Child(i));
@@ -116,7 +116,7 @@ DualTreeTraverser<RuleType>::Traverse(RectangleTree& queryNode,
std::sort(nodesAndScores.begin(), nodesAndScores.end(), nodeComparator);
numScores += nodesAndScores.size();
for (size_t i = 0; i < nodesAndScores.size(); i++)
for (size_t i = 0; i < nodesAndScores.size(); ++i)
{
rule.TraversalInfo() = nodesAndScores[i].travInfo;
if (rule.Rescore(queryNode, *(nodesAndScores[i].node),
@@ -136,11 +136,11 @@ DualTreeTraverser<RuleType>::Traverse(RectangleTree& queryNode,
// We need to traverse down both the reference and the query trees.
// We loop through all of the query nodes, and for each of them, we
// loop through the reference nodes to see where we need to descend.
for (size_t j = 0; j < queryNode.NumChildren(); j++)
for (size_t j = 0; j < queryNode.NumChildren(); ++j)
{
// We sort the children of the reference node by their scores.
std::vector<NodeAndScore> nodesAndScores(referenceNode.NumChildren());
for (size_t i = 0; i < referenceNode.NumChildren(); i++)
for (size_t i = 0; i < referenceNode.NumChildren(); ++i)
{
rule.TraversalInfo() = traversalInfo;
nodesAndScores[i].node = &(referenceNode.Child(i));
@@ -151,7 +151,7 @@ DualTreeTraverser<RuleType>::Traverse(RectangleTree& queryNode,
std::sort(nodesAndScores.begin(), nodesAndScores.end(), nodeComparator);
numScores += nodesAndScores.size();
for (size_t i = 0; i < nodesAndScores.size(); i++)
for (size_t i = 0; i < nodesAndScores.size(); ++i)
{
rule.TraversalInfo() = nodesAndScores[i].travInfo;
if (rule.Rescore(queryNode.Child(j), *(nodesAndScores[i].node),
@@ -128,7 +128,7 @@ HandlePointDeletion(TreeType* node, const size_t localIndex)
// Update the largest Hilbert value.
hilbertValue.DeletePoint(node, localIndex);
for (size_t i = localIndex + 1; localIndex < node->NumPoints(); i++)
for (size_t i = localIndex + 1; localIndex < node->NumPoints(); ++i)
node->Point(i - 1) = node->Point(i);
node->NumPoints()--;
@@ -143,7 +143,7 @@ HandleNodeRemoval(TreeType* node, const size_t nodeIndex)
// Update the largest Hilbert value.
hilbertValue.RemoveNode(node, nodeIndex);
for (size_t i = nodeIndex + 1; nodeIndex < node->NumChildren(); i++)
for (size_t i = nodeIndex + 1; nodeIndex < node->NumChildren(); ++i)
node->children[i - 1] = node->children[i];
node->NumChildren()--;
@@ -76,7 +76,6 @@ void HilbertRTreeSplit<splitOrder>::SplitLeafNode(TreeType* tree,
firstSibling = (lastSibling > splitOrder ? lastSibling - splitOrder : 0);
assert(lastSibling - firstSibling <= splitOrder);
assert(firstSibling >= 0);
assert(lastSibling < parent->NumChildren());
// Redistribute the points among (splitOrder + 1) cooperating siblings evenly.
@@ -141,7 +140,6 @@ SplitNonLeafNode(TreeType* tree, std::vector<bool>& relevels)
lastSibling - splitOrder : 0);
assert(lastSibling - firstSibling <= splitOrder);
assert(firstSibling >= 0);
assert(lastSibling < parent->NumChildren());
// Redistribute children among (splitOrder + 1) cooperating siblings evenly.
@@ -203,7 +201,6 @@ bool HilbertRTreeSplit<splitOrder>::FindCooperatingSiblings(
}
assert(lastSibling - firstSibling <= splitOrder - 1);
assert(firstSibling >= 0);
assert(lastSibling < parent->NumChildren());
return true;
@@ -218,7 +215,7 @@ RedistributeNodesEvenly(const TreeType *parent,
size_t numChildren = 0;
size_t numChildrenPerNode, numRestChildren;
for (size_t i = firstSibling; i <= lastSibling; i++)
for (size_t i = firstSibling; i <= lastSibling; ++i)
numChildren += parent->Child(i).NumChildren();
numChildrenPerNode = numChildren / (lastSibling - firstSibling + 1);
@@ -228,9 +225,9 @@ RedistributeNodesEvenly(const TreeType *parent,
// Copy children's children in order to redistribute them.
size_t iChild = 0;
for (size_t i = firstSibling; i <= lastSibling; i++)
for (size_t i = firstSibling; i <= lastSibling; ++i)
{
for (size_t j = 0; j < parent->Child(i).NumChildren(); j++)
for (size_t j = 0; j < parent->Child(i).NumChildren(); ++j)
{
children[iChild] = parent->Child(i).children[j];
iChild++;
@@ -238,14 +235,14 @@ RedistributeNodesEvenly(const TreeType *parent,
}
iChild = 0;
for (size_t i = firstSibling; i <= lastSibling; i++)
for (size_t i = firstSibling; i <= lastSibling; ++i)
{
// Since we redistribute children of a sibling we should recalculate the
// bound.
parent->Child(i).Bound().Clear();
parent->Child(i).numDescendants = 0;
for (size_t j = 0; j < numChildrenPerNode; j++)
for (size_t j = 0; j < numChildrenPerNode; ++j)
{
parent->Child(i).Bound() |= children[iChild]->Bound();
parent->Child(i).numDescendants += children[iChild]->numDescendants;
@@ -286,7 +283,7 @@ RedistributePointsEvenly(TreeType* parent,
size_t numPoints = 0;
size_t numPointsPerNode, numRestPoints;
for (size_t i = firstSibling; i <= lastSibling; i++)
for (size_t i = firstSibling; i <= lastSibling; ++i)
numPoints += parent->Child(i).NumPoints();
numPointsPerNode = numPoints / (lastSibling - firstSibling + 1);
@@ -296,21 +293,21 @@ RedistributePointsEvenly(TreeType* parent,
// Copy children's points in order to redistribute them.
size_t iPoint = 0;
for (size_t i = firstSibling; i <= lastSibling; i++)
for (size_t i = firstSibling; i <= lastSibling; ++i)
{
for (size_t j = 0; j < parent->Child(i).NumPoints(); j++)
for (size_t j = 0; j < parent->Child(i).NumPoints(); ++j)
points[iPoint++] = parent->Child(i).Point(j);
}
iPoint = 0;
for (size_t i = firstSibling; i <= lastSibling; i++)
for (size_t i = firstSibling; i <= lastSibling; ++i)
{
// Since we redistribute points of a sibling we should recalculate the
// bound.
parent->Child(i).Bound().Clear();
size_t j;
for (j = 0; j < numPointsPerNode; j++)
for (j = 0; j < numPointsPerNode; ++j)
{
parent->Child(i).Bound() |= parent->Dataset().col(points[iPoint]);
parent->Child(i).Point(j) = points[iPoint];
@@ -30,7 +30,7 @@ SweepNonLeafNode(const size_t axis,
std::vector<std::pair<ElemType, size_t>> sorted(node->NumChildren());
for (size_t i = 0; i < node->NumChildren(); i++)
for (size_t i = 0; i < node->NumChildren(); ++i)
{
sorted[i].first = SplitPolicy::Bound(node->Child(i))[axis].Hi();
sorted[i].second = i;
@@ -66,10 +66,10 @@ SweepNonLeafNode(const size_t axis,
BoundType bound2(node->Bound().Dim());
// Find bounds of two resulting nodes.
for (size_t i = 0; i < splitPointer; i++)
for (size_t i = 0; i < splitPointer; ++i)
bound1 |= node->Child(sorted[i].second).Bound();
for (size_t i = splitPointer; i < node->NumChildren(); i++)
for (size_t i = splitPointer; i < node->NumChildren(); ++i)
bound2 |= node->Child(sorted[i].second).Bound();
@@ -96,7 +96,7 @@ SweepLeafNode(const size_t axis,
sorted.resize(node->Count());
for (size_t i = 0; i < node->NumPoints(); i++)
for (size_t i = 0; i < node->NumPoints(); ++i)
{
sorted[i].first = node->Dataset().col(node->Point(i))[axis];
sorted[i].second = i;
@@ -122,10 +122,10 @@ SweepLeafNode(const size_t axis,
BoundType bound2(node->Bound().Dim());
// Find bounds of two resulting nodes.
for (size_t i = 0; i < splitPointer; i++)
for (size_t i = 0; i < splitPointer; ++i)
bound1 |= node->Dataset().col(node->Point(sorted[i].second));
for (size_t i = splitPointer; i < node->NumChildren(); i++)
for (size_t i = splitPointer; i < node->NumChildren(); ++i)
bound2 |= node->Dataset().col(node->Point(sorted[i].second));
// Evaluate the cost of the split i.e. calculate the total coverage
@@ -145,7 +145,7 @@ CheckNonLeafSweep(const TreeType* node,
size_t numTreeTwoChildren = 0;
// Calculate the number of children in the resulting nodes.
for (size_t i = 0; i < node->NumChildren(); i++)
for (size_t i = 0; i < node->NumChildren(); ++i)
{
const TreeType& child = node->Child(i);
int policy = SplitPolicy::GetSplitPolicy(child, cutAxis, cut);
@@ -178,7 +178,7 @@ CheckLeafSweep(const TreeType* node,
size_t numTreeTwoPoints = 0;
// Calculate the number of points in the resulting nodes.
for (size_t i = 0; i < node->NumPoints(); i++)
for (size_t i = 0; i < node->NumPoints(); ++i)
{
if (node->Dataset().col(node->Point(i))[cutAxis] <= cut)
numTreeOnePoints++;
@@ -29,7 +29,7 @@ size_t MinimalSplitsNumberSweep<SplitPolicy>::SweepNonLeafNode(
std::vector<std::pair<ElemType, size_t>> sorted(node->NumChildren());
for (size_t i = 0; i < node->NumChildren(); i++)
for (size_t i = 0; i < node->NumChildren(); ++i)
{
sorted[i].first = SplitPolicy::Bound(node->Child(i))[axis].Hi();
sorted[i].second = i;
@@ -46,14 +46,14 @@ size_t MinimalSplitsNumberSweep<SplitPolicy>::SweepNonLeafNode(
size_t minCost = SIZE_MAX;
// Find a split with the minimal cost.
for (size_t i = 0; i < sorted.size(); i++)
for (size_t i = 0; i < sorted.size(); ++i)
{
size_t numTreeOneChildren = 0;
size_t numTreeTwoChildren = 0;
size_t numSplits = 0;
// Calculate the number of splits.
for (size_t j = 0; j < node->NumChildren(); j++)
for (size_t j = 0; j < node->NumChildren(); ++j)
{
const TreeType& child = node->Child(j);
int policy = SplitPolicy::GetSplitPolicy(child, axis, sorted[i].first);
@@ -35,7 +35,7 @@ RPlusPlusTreeAuxiliaryInformation(const TreeType* tree) :
// Initialize the maximum bounding rectangle if the node is the root
if (!tree->Parent())
{
for (size_t k = 0; k < outerBound.Dim(); k++)
for (size_t k = 0; k < outerBound.Dim(); ++k)
{
outerBound[k].Lo() = std::numeric_limits<ElemType>::lowest();
outerBound[k].Hi() = std::numeric_limits<ElemType>::max();
@@ -45,14 +45,14 @@ size_t RPlusTreeDescentHeuristic::ChooseDescentNode(TreeType* node,
success = true;
for (size_t j = 0; j < node->NumChildren(); j++)
for (size_t j = 0; j < node->NumChildren(); ++j)
{
if (j == bestIndex)
continue;
success = false;
// Two nodes overlap if and only if there are no dimension in which
// they do not overlap each other.
for (size_t k = 0; k < node->Bound().Dim(); k++)
for (size_t k = 0; k < node->Bound().Dim(); ++k)
{
if (bound[k].Lo() >= node->Child(j).Bound()[k].Hi() ||
node->Child(j).Bound()[k].Lo() >= bound[k].Hi())
@@ -100,7 +100,7 @@ SplitLeafNode(TreeType* tree, std::vector<bool>& relevels)
TreeType* parent = tree->Parent();
size_t i = 0;
while (parent->children[i] != tree)
i++;
++i;
assert(i < parent->NumChildren());
@@ -170,7 +170,7 @@ SplitNonLeafNode(TreeType* tree, std::vector<bool>& relevels)
TreeType* parent = tree->Parent();
size_t i = 0;
while (parent->children[i] != tree)
i++;
++i;
assert(i < parent->NumChildren());
@@ -216,7 +216,7 @@ void RPlusTreeSplit<SplitPolicyType, SweepType>::SplitLeafNodeAlongPartition(
}
// Insert points into the corresponding subtree.
for (size_t i = 0; i < tree->NumPoints(); i++)
for (size_t i = 0; i < tree->NumPoints(); ++i)
{
if (tree->Dataset().col(tree->Point(i))[cutAxis] <= cut)
{
@@ -254,7 +254,7 @@ void RPlusTreeSplit<SplitPolicyType, SweepType>::SplitNonLeafNodeAlongPartition(
tree->AuxiliaryInfo().SplitAuxiliaryInfo(treeOne, treeTwo, cutAxis, cut);
// Insert children into the corresponding subtree.
for (size_t i = 0; i < tree->NumChildren(); i++)
for (size_t i = 0; i < tree->NumChildren(); ++i)
{
TreeType* child = tree->children[i];
int policy = SplitPolicyType::GetSplitPolicy(*child, cutAxis, cut);
@@ -313,7 +313,7 @@ AddFakeNodes(const TreeType* tree, TreeType* emptyTree)
size_t numDescendantNodes = tree->TreeDepth() - 1;
TreeType* node = emptyTree;
for (size_t i = 0; i < numDescendantNodes; i++)
for (size_t i = 0; i < numDescendantNodes; ++i)
{
TreeType* child = new TreeType(node);
node->children[node->NumChildren()++] = child;
@@ -342,7 +342,7 @@ PartitionNode(const TreeType* node, size_t& minCutAxis,
minCutAxis = node->Bound().Dim();
// Find the sweep with a minimal cost.
for (size_t k = 0; k < node->Bound().Dim(); k++)
for (size_t k = 0; k < node->Bound().Dim(); ++k)
{
typename TreeType::ElemType cut;
SweepCostType cost;
@@ -35,16 +35,16 @@ inline size_t RStarTreeDescentHeuristic::ChooseDescentNode(
// If its children are leaf nodes, use minimum overlap to choose.
size_t bestIndex = 0;
for (size_t i = 0; i < node->NumChildren(); i++)
for (size_t i = 0; i < node->NumChildren(); ++i)
{
ElemType sc = 0;
for (size_t j = 0; j < node->NumChildren(); j++)
for (size_t j = 0; j < node->NumChildren(); ++j)
{
if (j != i)
{
ElemType overlap = 1.0;
ElemType newOverlap = 1.0;
for (size_t k = 0; k < node->Bound().Dim(); k++)
for (size_t k = 0; k < node->Bound().Dim(); ++k)
{
ElemType newHigh = std::max(node->Dataset().col(point)[k],
node->Child(i).Bound()[k].Hi());
@@ -89,7 +89,7 @@ inline size_t RStarTreeDescentHeuristic::ChooseDescentNode(
if (tiedOne)
{
// If the first heuristic was tied, we need to eliminate garbage values.
for (size_t i = 0; i < scores.size(); i++)
for (size_t i = 0; i < scores.size(); ++i)
scores[i] = std::numeric_limits<ElemType>::max();
}
@@ -98,13 +98,13 @@ inline size_t RStarTreeDescentHeuristic::ChooseDescentNode(
size_t bestIndex = 0;
bool tied = false;
for (size_t i = 0; i < node->NumChildren(); i++)
for (size_t i = 0; i < node->NumChildren(); ++i)
{
if (!tiedOne || originalScores[i] == origMinScore)
{
ElemType v1 = 1.0;
ElemType v2 = 1.0;
for (size_t j = 0; j < node->Bound().Dim(); j++)
for (size_t j = 0; j < node->Bound().Dim(); ++j)
{
v1 *= node->Child(i).Bound()[j].Width();
v2 *= node->Child(i).Bound()[j].Contains(
@@ -136,7 +136,7 @@ inline size_t RStarTreeDescentHeuristic::ChooseDescentNode(
// We break ties by choosing the smallest bound.
ElemType minVol = std::numeric_limits<ElemType>::max();
bestIndex = 0;
for (size_t i = 0; i < scores.size(); i++)
for (size_t i = 0; i < scores.size(); ++i)
{
if (scores[i] == minScore)
{
@@ -173,11 +173,11 @@ inline size_t RStarTreeDescentHeuristic::ChooseDescentNode(
size_t bestIndex = 0;
bool tied = false;
for (size_t i = 0; i < node->NumChildren(); i++)
for (size_t i = 0; i < node->NumChildren(); ++i)
{
ElemType v1 = 1.0;
ElemType v2 = 1.0;
for (size_t j = 0; j < node->Child(i).Bound().Dim(); j++)
for (size_t j = 0; j < node->Child(i).Bound().Dim(); ++j)
{
v1 *= node->Child(i).Bound()[j].Width();
v2 *= node->Child(i).Bound()[j].Contains(insertedNode->Bound()[j]) ?
@@ -209,7 +209,7 @@ inline size_t RStarTreeDescentHeuristic::ChooseDescentNode(
// We break ties by choosing the smallest bound.
ElemType minVol = std::numeric_limits<ElemType>::max();
bestIndex = 0;
for (size_t i = 0; i < scores.size(); i++)
for (size_t i = 0; i < scores.size(); ++i)
{
if (scores[i] == minScore)
{
@@ -50,7 +50,7 @@ size_t RStarTreeSplit::ReinsertPoints(TreeType* tree,
std::vector<std::pair<ElemType, size_t>> sorted(tree->Count());
arma::Col<ElemType> center;
tree->Bound().Center(center);
for (size_t i = 0; i < sorted.size(); i++)
for (size_t i = 0; i < sorted.size(); ++i)
{
sorted[i].first = tree->Metric().Evaluate(center,
tree->Dataset().col(tree->Point(i)));
@@ -60,7 +60,7 @@ size_t RStarTreeSplit::ReinsertPoints(TreeType* tree,
std::sort(sorted.begin(), sorted.end(), PairComp<ElemType, size_t>);
// Remove the points furthest from the center of the node.
for (size_t i = 0; i < p; i++)
for (size_t i = 0; i < p; ++i)
root->DeletePoint(sorted[sorted.size() - 1 - i].second, relevels);
// Now reinsert the points, but reverse the order---insert the closest to
@@ -94,7 +94,7 @@ void RStarTreeSplit::PickLeafSplit(TreeType* tree,
/**
* Check each dimension, to find which dimension is best to split on.
*/
for (size_t j = 0; j < tree->Bound().Dim(); j++)
for (size_t j = 0; j < tree->Bound().Dim(); ++j)
{
ElemType axisScore = 0.0;
@@ -111,7 +111,7 @@ void RStarTreeSplit::PickLeafSplit(TreeType* tree,
arma::Col<ElemType> margins(numPossibleSplits, arma::fill::zeros);
arma::Col<ElemType> overlaps(numPossibleSplits, arma::fill::zeros);
for (size_t i = 0; i < numPossibleSplits; i++)
for (size_t i = 0; i < numPossibleSplits; ++i)
{
// The ith arrangement is obtained by placing the first
// tree->MinLeafSize() + i points in one rectangle and the rest in
@@ -130,7 +130,7 @@ void RStarTreeSplit::PickLeafSplit(TreeType* tree,
areas[i] = bound1.Volume() + bound2.Volume();
overlaps[i] = bound1.Overlap(bound2);
for (size_t k = 0; k < bound1.Dim(); k++)
for (size_t k = 0; k < bound1.Dim(); ++k)
margins[i] += bound1[k].Width() + bound2[k].Width();
axisScore += margins[i];
@@ -145,7 +145,7 @@ void RStarTreeSplit::PickLeafSplit(TreeType* tree,
size_t areaIndex = 0;
bool tiedOnOverlap = false;
for (size_t i = 1; i < areas.n_elem; i++)
for (size_t i = 1; i < areas.n_elem; ++i)
{
if (overlaps[i] < overlaps[overlapIndex])
{
@@ -198,7 +198,7 @@ void RStarTreeSplit::SplitLeafNode(TreeType *tree, std::vector<bool>& relevels)
* dimension to prepare for reinsertion of points into the new nodes.
*/
std::vector<std::pair<ElemType, size_t>> sorted(tree->Count());
for (size_t i = 0; i < sorted.size(); i++)
for (size_t i = 0; i < sorted.size(); ++i)
{
sorted[i].first = tree->Dataset().col(tree->Point(i))[bestAxis];
sorted[i].second = tree->Point(i);
@@ -232,7 +232,7 @@ void RStarTreeSplit::SplitLeafNode(TreeType *tree, std::vector<bool>& relevels)
tree->bound.Clear();
// Insert the points into the appropriate tree.
for (size_t i = 0; i < numPoints; i++)
for (size_t i = 0; i < numPoints; ++i)
{
if (i < bestIndex + tree->MinLeafSize())
treeOne->InsertPoint(sorted[i].second);
@@ -289,7 +289,7 @@ bool RStarTreeSplit::SplitNonLeafNode(
/**
* Check over each dimension to see which is best to use for splitting.
*/
for (size_t j = 0; j < tree->Bound().Dim(); j++)
for (size_t j = 0; j < tree->Bound().Dim(); ++j)
{
ElemType axisLoScore = 0.0;
ElemType axisHiScore = 0.0;
@@ -298,7 +298,7 @@ bool RStarTreeSplit::SplitNonLeafNode(
// bound.
arma::Col<ElemType> loDimValues(tree->NumChildren());
arma::Col<ElemType> hiDimValues(tree->NumChildren());
for (size_t i = 0; i < tree->NumChildren(); i++)
for (size_t i = 0; i < tree->NumChildren(); ++i)
{
loDimValues[i] = tree->Child(i).Bound()[j].Lo();
hiDimValues[i] = tree->Child(i).Bound()[j].Hi();
@@ -347,7 +347,7 @@ bool RStarTreeSplit::SplitNonLeafNode(
overlaps[2 * i + 1] = hb1.Overlap(hb2);
// Now calculate margins for each.
for (size_t k = 0; k < lb1.Dim(); k++)
for (size_t k = 0; k < lb1.Dim(); ++k)
{
margins[2 * i] += lb1[k].Width() + lb2[k].Width();
margins[2 * i + 1] += hb1[k].Width() + hb2[k].Width();
@@ -381,7 +381,7 @@ bool RStarTreeSplit::SplitNonLeafNode(
// Find the best possible split (and whether it is on the low values or
// high values of the bounds).
for (size_t i = 1; i < numPossibleSplits; i++)
for (size_t i = 1; i < numPossibleSplits; ++i)
{
// Check bounds.
if (overlaps[2 * i + indexOffset] < overlaps[overlapIndex])
@@ -458,12 +458,12 @@ bool RStarTreeSplit::SplitNonLeafNode(
// We have to update the children of treeOne so that they record the correct
// parent.
for (size_t i = 0; i < treeOne->NumChildren(); i++)
for (size_t i = 0; i < treeOne->NumChildren(); ++i)
treeOne->children[i]->Parent() = treeOne;
}
// Update the children of treeTwo to have the correct parent.
for (size_t i = 0; i < treeTwo->NumChildren(); i++)
for (size_t i = 0; i < treeTwo->NumChildren(); ++i)
treeTwo->children[i]->Parent() = treeTwo;
// If we have overflowed hte parent's children, then we need to split that
@@ -29,11 +29,11 @@ inline size_t RTreeDescentHeuristic::ChooseDescentNode(const TreeType* node,
int bestIndex = 0;
ElemType bestVol = 0.0;
for (size_t i = 0; i < node->NumChildren(); i++)
for (size_t i = 0; i < node->NumChildren(); ++i)
{
ElemType v1 = 1.0;
ElemType v2 = 1.0;
for (size_t j = 0; j < node->Child(i).Bound().Dim(); j++)
for (size_t j = 0; j < node->Child(i).Bound().Dim(); ++j)
{
v1 *= node->Child(i).Bound()[j].Width();
v2 *= node->Child(i).Bound()[j].Contains(node->Dataset().col(point)[j]) ?
@@ -73,11 +73,11 @@ inline size_t RTreeDescentHeuristic::ChooseDescentNode(
int bestIndex = 0;
ElemType bestVol = 0.0;
for (size_t i = 0; i < node->NumChildren(); i++)
for (size_t i = 0; i < node->NumChildren(); ++i)
{
ElemType v1 = 1.0;
ElemType v2 = 1.0;
for (size_t j = 0; j < node->Child(i).Bound().Dim(); j++)
for (size_t j = 0; j < node->Child(i).Bound().Dim(); ++j)
{
v1 *= node->Child(i).Bound()[j].Width();
v2 *= node->Child(i).Bound()[j].Contains(insertedNode->Bound()[j]) ?
@@ -130,7 +130,7 @@ bool RTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector<bool>& relevels)
par->children[index] = treeOne;
par->children[par->NumChildren()++] = treeTwo;
for (size_t i = 0; i < par->NumChildren(); i++)
for (size_t i = 0; i < par->NumChildren(); ++i)
assert(par->children[i] != tree);
// We only add one at a time, so should only need to test for equality just in
@@ -142,10 +142,10 @@ bool RTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector<bool>& relevels)
// We have to update the children of each of these new nodes so that they
// record the correct parent.
for (size_t i = 0; i < treeOne->NumChildren(); i++)
for (size_t i = 0; i < treeOne->NumChildren(); ++i)
treeOne->children[i]->Parent() = treeOne;
for (size_t i = 0; i < treeTwo->NumChildren(); i++)
for (size_t i = 0; i < treeTwo->NumChildren(); ++i)
treeTwo->children[i]->Parent() = treeTwo;
assert(treeOne->NumChildren() <= treeOne->MaxNumChildren());
@@ -170,9 +170,9 @@ void RTreeSplit::GetPointSeeds(const TreeType *tree, int& iRet, int& jRet)
// same node. Because we are just using points, we will simply choose the two
// that would create the most voluminous hyperrectangle.
typename TreeType::ElemType worstPairScore = -1.0;
for (size_t i = 0; i < tree->Count(); i++)
for (size_t i = 0; i < tree->Count(); ++i)
{
for (size_t j = i + 1; j < tree->Count(); j++)
for (size_t j = i + 1; j < tree->Count(); ++j)
{
const typename TreeType::ElemType score = arma::prod(arma::abs(
tree->Dataset().col(tree->Point(i)) -
@@ -199,12 +199,12 @@ void RTreeSplit::GetBoundSeeds(const TreeType *tree, int& iRet, int& jRet)
typedef typename TreeType::ElemType ElemType;
ElemType worstPairScore = -1.0;
for (size_t i = 0; i < tree->NumChildren(); i++)
for (size_t i = 0; i < tree->NumChildren(); ++i)
{
for (size_t j = i + 1; j < tree->NumChildren(); j++)
for (size_t j = i + 1; j < tree->NumChildren(); ++j)
{
ElemType score = 1.0;
for (size_t k = 0; k < tree->Bound().Dim(); k++)
for (size_t k = 0; k < tree->Bound().Dim(); ++k)
{
const ElemType hiMax = std::max(tree->Child(i).Bound()[k].Hi(),
tree->Child(j).Bound()[k].Hi());
@@ -283,7 +283,7 @@ void RTreeSplit::AssignPointDestNode(TreeType* oldTree,
// First, calculate the starting volume.
ElemType volOne = 1.0;
ElemType volTwo = 1.0;
for (size_t i = 0; i < oldTree->Bound().Dim(); i++)
for (size_t i = 0; i < oldTree->Bound().Dim(); ++i)
{
volOne *= treeOne->Bound()[i].Width();
volTwo *= treeTwo->Bound()[i].Width();
@@ -295,7 +295,7 @@ void RTreeSplit::AssignPointDestNode(TreeType* oldTree,
{
ElemType newVolOne = 1.0;
ElemType newVolTwo = 1.0;
for (size_t i = 0; i < oldTree->Bound().Dim(); i++)
for (size_t i = 0; i < oldTree->Bound().Dim(); ++i)
{
ElemType c = oldTree->Dataset().col(oldTree->Point(index))[i];
newVolOne *= treeOne->Bound()[i].Contains(c) ?
@@ -348,12 +348,12 @@ void RTreeSplit::AssignPointDestNode(TreeType* oldTree,
{
if (numAssignedOne < numAssignedTwo)
{
for (size_t i = 0; i < end; i++)
for (size_t i = 0; i < end; ++i)
treeOne->InsertPoint(oldTree->Point(i));
}
else
{
for (size_t i = 0; i < end; i++)
for (size_t i = 0; i < end; ++i)
treeTwo->InsertPoint(oldTree->Point(i));
}
}
@@ -374,8 +374,8 @@ void RTreeSplit::AssignNodeDestNode(TreeType* oldTree,
assert(intI != intJ);
for (size_t i = 0; i < oldTree->NumChildren(); i++)
for (size_t j = i + 1; j < oldTree->NumChildren(); j++)
for (size_t i = 0; i < oldTree->NumChildren(); ++i)
for (size_t j = i + 1; j < oldTree->NumChildren(); ++j)
assert(oldTree->children[i] != oldTree->children[j]);
InsertNodeIntoTree(treeOne, oldTree->children[intI]);
@@ -397,14 +397,14 @@ void RTreeSplit::AssignNodeDestNode(TreeType* oldTree,
assert(treeOne->NumChildren() == 1);
assert(treeTwo->NumChildren() == 1);
for (size_t i = 0; i < end; i++)
for (size_t j = i + 1; j < end; j++)
for (size_t i = 0; i < end; ++i)
for (size_t j = i + 1; j < end; ++j)
assert(oldTree->children[i] != oldTree->children[j]);
for (size_t i = 0; i < end; i++)
for (size_t i = 0; i < end; ++i)
assert(oldTree->children[i] != treeOne->children[0]);
for (size_t i = 0; i < end; i++)
for (size_t i = 0; i < end; ++i)
assert(oldTree->children[i] != treeTwo->children[0]);
size_t numAssignTreeOne = 1;
@@ -424,7 +424,7 @@ void RTreeSplit::AssignNodeDestNode(TreeType* oldTree,
// new rectangles.
ElemType volOne = 1.0;
ElemType volTwo = 1.0;
for (size_t i = 0; i < oldTree->Bound().Dim(); i++)
for (size_t i = 0; i < oldTree->Bound().Dim(); ++i)
{
volOne *= treeOne->Bound()[i].Width();
volTwo *= treeTwo->Bound()[i].Width();
@@ -434,7 +434,7 @@ void RTreeSplit::AssignNodeDestNode(TreeType* oldTree,
{
ElemType newVolOne = 1.0;
ElemType newVolTwo = 1.0;
for (size_t i = 0; i < oldTree->Bound().Dim(); i++)
for (size_t i = 0; i < oldTree->Bound().Dim(); ++i)
{
// For each of the new rectangles, find the width in this dimension if
// we add the rectangle at index to the new rectangle.
@@ -495,7 +495,7 @@ void RTreeSplit::AssignNodeDestNode(TreeType* oldTree,
{
if (numAssignTreeOne < numAssignTreeTwo)
{
for (size_t i = 0; i < end; i++)
for (size_t i = 0; i < end; ++i)
{
InsertNodeIntoTree(treeOne, oldTree->children[i]);
numAssignTreeOne++;
@@ -503,7 +503,7 @@ void RTreeSplit::AssignNodeDestNode(TreeType* oldTree,
}
else
{
for (size_t i = 0; i < end; i++)
for (size_t i = 0; i < end; ++i)
{
InsertNodeIntoTree(treeTwo, oldTree->children[i]);
numAssignTreeTwo++;
@@ -511,12 +511,12 @@ void RTreeSplit::AssignNodeDestNode(TreeType* oldTree,
}
}
for (size_t i = 0; i < treeOne->NumChildren(); i++)
for (size_t j = i + 1; j < treeOne->NumChildren(); j++)
for (size_t i = 0; i < treeOne->NumChildren(); ++i)
for (size_t j = i + 1; j < treeOne->NumChildren(); ++j)
assert(treeOne->children[i] != treeOne->children[j]);
for (size_t i = 0; i < treeTwo->NumChildren(); i++)
for (size_t j = i + 1; j < treeTwo->NumChildren(); j++)
for (size_t i = 0; i < treeTwo->NumChildren(); ++i)
for (size_t j = i + 1; j < treeTwo->NumChildren(); ++j)
assert(treeTwo->children[i] != treeTwo->children[j]);
}
@@ -74,7 +74,7 @@ RectangleTree(const MatType& data,
// For now, just insert the points in order.
RectangleTree* root = this;
for (size_t i = firstDataIndex; i < data.n_cols; i++)
for (size_t i = firstDataIndex; i < data.n_cols; ++i)
root->InsertPoint(i);
// Initialize statistic recursively after tree construction is complete.
@@ -115,7 +115,7 @@ RectangleTree(MatType&& data,
// For now, just insert the points in order.
RectangleTree* root = this;
for (size_t i = firstDataIndex; i < dataset->n_cols; i++)
for (size_t i = firstDataIndex; i < dataset->n_cols; ++i)
root->InsertPoint(i);
// Initialize statistic recursively after tree construction is complete.
@@ -196,7 +196,7 @@ RectangleTree(
{
if (numChildren > 0)
{
for (size_t i = 0; i < numChildren; i++)
for (size_t i = 0; i < numChildren; ++i)
children[i] = new RectangleTree(other.Child(i), true, this);
}
}
@@ -244,7 +244,7 @@ RectangleTree(RectangleTree&& other) :
}
if (!IsLeaf())
{
for (size_t i = 0; i < numChildren; i++)
for (size_t i = 0; i < numChildren; ++i)
children[i]->parent = this;
}
// Now we are a clone of the other tree. But we must also clear the other
@@ -283,7 +283,7 @@ operator=(const RectangleTree& other)
return *this;
// Freeing memory that will not be used anymore.
for (size_t i = 0; i < numChildren; i++)
for (size_t i = 0; i < numChildren; ++i)
delete children[i];
if (ownsDataset)
@@ -309,7 +309,7 @@ operator=(const RectangleTree& other)
if (numChildren > 0)
{
for (size_t i = 0; i < numChildren; i++)
for (size_t i = 0; i < numChildren; ++i)
children[i] = new RectangleTree(other.Child(i), true, this);
}
@@ -336,7 +336,7 @@ operator=(RectangleTree&& other)
return *this;
// Freeing memory that will not be used anymore.
for (size_t i = 0; i < numChildren; i++)
for (size_t i = 0; i < numChildren; ++i)
delete children[i];
if (ownsDataset)
@@ -414,7 +414,7 @@ RectangleTree<MetricType, StatisticType, MatType, SplitType, DescentType,
AuxiliaryInformationType>::
~RectangleTree()
{
for (size_t i = 0; i < numChildren; i++)
for (size_t i = 0; i < numChildren; ++i)
delete children[i];
if (ownsDataset)
@@ -437,7 +437,7 @@ void RectangleTree<MetricType, StatisticType, MatType, SplitType, DescentType,
{
parent = NULL;
for (size_t i = 0; i < children.size(); i++)
for (size_t i = 0; i < children.size(); ++i)
children[i] = NULL;
numChildren = 0;
@@ -597,7 +597,7 @@ bool RectangleTree<MetricType, StatisticType, MatType, SplitType, DescentType,
if (numChildren == 0)
{
for (size_t i = 0; i < count; i++)
for (size_t i = 0; i < count; ++i)
{
if (points[i] == point)
{
@@ -617,7 +617,7 @@ bool RectangleTree<MetricType, StatisticType, MatType, SplitType, DescentType,
}
}
for (size_t i = 0; i < numChildren; i++)
for (size_t i = 0; i < numChildren; ++i)
if (children[i]->Bound().Contains(dataset->col(point)))
if (children[i]->DeletePoint(point, lvls))
return true;
@@ -641,7 +641,7 @@ bool RectangleTree<MetricType, StatisticType, MatType, SplitType, DescentType,
{
if (numChildren == 0)
{
for (size_t i = 0; i < count; i++)
for (size_t i = 0; i < count; ++i)
{
if (points[i] == point)
{
@@ -661,7 +661,7 @@ bool RectangleTree<MetricType, StatisticType, MatType, SplitType, DescentType,
}
}
for (size_t i = 0; i < numChildren; i++)
for (size_t i = 0; i < numChildren; ++i)
if (children[i]->Bound().Contains(dataset->col(point)))
if (children[i]->DeletePoint(point, relevels))
return true;
@@ -684,7 +684,7 @@ bool RectangleTree<MetricType, StatisticType, MatType, SplitType, DescentType,
AuxiliaryInformationType>::
RemoveNode(const RectangleTree* node, std::vector<bool>& relevels)
{
for (size_t i = 0; i < numChildren; i++)
for (size_t i = 0; i < numChildren; ++i)
{
if (children[i] == node)
{
@@ -703,7 +703,7 @@ bool RectangleTree<MetricType, StatisticType, MatType, SplitType, DescentType,
}
bool contains = true;
for (size_t j = 0; j < node->Bound().Dim(); j++)
for (size_t j = 0; j < node->Bound().Dim(); ++j)
contains &= Child(i).Bound()[j].Contains(node->Bound()[j]);
if (contains)
@@ -724,7 +724,7 @@ size_t RectangleTree<MetricType, StatisticType, MatType, SplitType,
DescentType, AuxiliaryInformationType>::TreeSize() const
{
int n = 0;
for (int i = 0; i < numChildren; i++)
for (int i = 0; i < numChildren; ++i)
n += children[i]->TreeSize();
return n + 1; // Add one for this node.
@@ -1084,7 +1084,7 @@ void RectangleTree<MetricType, StatisticType, MatType, SplitType, DescentType,
if (IsLeaf() && count < minLeafSize && parent != NULL)
{
// We can't delete the root node.
for (size_t i = 0; i < parent->NumChildren(); i++)
for (size_t i = 0; i < parent->NumChildren(); ++i)
{
if (parent->children[i] == this)
{
@@ -1125,7 +1125,7 @@ void RectangleTree<MetricType, StatisticType, MatType, SplitType, DescentType,
root->AuxiliaryInfo().UpdateAuxiliaryInfo(root);
// Reinsert the points at the root node.
for (size_t j = 0; j < count; j++)
for (size_t j = 0; j < count; ++j)
root->InsertPoint(points[j], relevels);
// This will check the minFill of the parent.
@@ -1144,7 +1144,7 @@ void RectangleTree<MetricType, StatisticType, MatType, SplitType, DescentType,
if (parent != NULL)
{
// The normal case. We need to be careful with the root.
for (size_t j = 0; j < parent->NumChildren(); j++)
for (size_t j = 0; j < parent->NumChildren(); ++j)
{
if (parent->children[j] == this)
{
@@ -1186,7 +1186,7 @@ void RectangleTree<MetricType, StatisticType, MatType, SplitType, DescentType,
root->AuxiliaryInfo().UpdateAuxiliaryInfo(root);
// Reinsert the nodes at the root node.
for (size_t i = 0; i < numChildren; i++)
for (size_t i = 0; i < numChildren; ++i)
root->InsertNode(children[i], level, relevels);
// This will check the minFill of the point.
@@ -1210,7 +1210,7 @@ void RectangleTree<MetricType, StatisticType, MatType, SplitType, DescentType,
children.resize(maxNumChildren + 1);
}
for (size_t i = 0; i < child->NumChildren(); i++)
for (size_t i = 0; i < child->NumChildren(); ++i)
{
children[i] = child->children[i];
children[i]->Parent() = this;
@@ -1220,7 +1220,7 @@ void RectangleTree<MetricType, StatisticType, MatType, SplitType, DescentType,
numChildren = child->NumChildren();
child->NumChildren() = 0;
for (size_t i = 0; i < child->Count(); i++)
for (size_t i = 0; i < child->Count(); ++i)
{
// In case the tree has a height of two.
points[i] = child->Point(i);
@@ -1264,12 +1264,12 @@ bool RectangleTree<MetricType, StatisticType, MatType, SplitType, DescentType,
bool shrunk = false;
if (IsLeaf())
{
for (size_t i = 0; i < bound.Dim(); i++)
for (size_t i = 0; i < bound.Dim(); ++i)
{
if (bound[i].Lo() == point[i])
{
ElemType min = std::numeric_limits<ElemType>::max();
for (size_t j = 0; j < count; j++)
for (size_t j = 0; j < count; ++j)
{
if (dataset->col(points[j])[i] < min)
min = dataset->col(points[j])[i];
@@ -1288,7 +1288,7 @@ bool RectangleTree<MetricType, StatisticType, MatType, SplitType, DescentType,
else if (bound[i].Hi() == point[i])
{
ElemType max = std::numeric_limits<ElemType>::lowest();
for (size_t j = 0; j < count; j++)
for (size_t j = 0; j < count; ++j)
{
if (dataset->col(points[j])[i] > max)
max = dataset->col(points[j])[i];
@@ -1308,12 +1308,12 @@ bool RectangleTree<MetricType, StatisticType, MatType, SplitType, DescentType,
}
else
{
for (size_t i = 0; i < bound.Dim(); i++)
for (size_t i = 0; i < bound.Dim(); ++i)
{
if (bound[i].Lo() == point[i])
{
ElemType min = std::numeric_limits<ElemType>::max();
for (size_t j = 0; j < numChildren; j++)
for (size_t j = 0; j < numChildren; ++j)
{
if (children[j]->Bound()[i].Lo() < min)
min = children[j]->Bound()[i].Lo();
@@ -1328,7 +1328,7 @@ bool RectangleTree<MetricType, StatisticType, MatType, SplitType, DescentType,
else if (bound[i].Hi() == point[i])
{
ElemType max = std::numeric_limits<ElemType>::lowest();
for (size_t j = 0; j < numChildren; j++)
for (size_t j = 0; j < numChildren; ++j)
{
if (children[j]->Bound()[i].Hi() > max)
max = children[j]->Bound()[i].Hi();
@@ -1363,20 +1363,20 @@ bool RectangleTree<MetricType, StatisticType, MatType, SplitType, DescentType,
ElemType sum = 0;
// I think it may be faster to just recalculate the whole thing.
for (size_t i = 0; i < bound.Dim(); i++)
for (size_t i = 0; i < bound.Dim(); ++i)
{
sum += bound[i].Width();
bound[i].Lo() = std::numeric_limits<ElemType>::max();
bound[i].Hi() = std::numeric_limits<ElemType>::lowest();
}
for (size_t i = 0; i < numChildren; i++)
for (size_t i = 0; i < numChildren; ++i)
{
bound |= children[i]->Bound();
}
ElemType sum2 = 0;
for (size_t i = 0; i < bound.Dim(); i++)
for (size_t i = 0; i < bound.Dim(); ++i)
sum2 += bound[i].Width();
return sum != sum2;
@@ -1400,7 +1400,7 @@ void RectangleTree<MetricType, StatisticType, MatType, SplitType, DescentType,
// Clean up memory, if necessary.
if (Archive::is_loading::value)
{
for (size_t i = 0; i < numChildren; i++)
for (size_t i = 0; i < numChildren; ++i)
delete children[i];
children.clear();
@@ -52,7 +52,7 @@ SingleTreeTraverser<RuleType>::Traverse(
// If we reach a leaf node, we need to run the base case.
if (referenceNode.IsLeaf())
{
for (size_t i = 0; i < referenceNode.Count(); i++)
for (size_t i = 0; i < referenceNode.Count(); ++i)
rule.BaseCase(queryIndex, referenceNode.Point(i));
return;
@@ -61,7 +61,7 @@ SingleTreeTraverser<RuleType>::Traverse(
// This is not a leaf node so we sort the children of this node by their
// scores.
std::vector<NodeAndScore> nodesAndScores(referenceNode.NumChildren());
for (size_t i = 0; i < referenceNode.NumChildren(); i++)
for (size_t i = 0; i < referenceNode.NumChildren(); ++i)
{
nodesAndScores[i].node = &(referenceNode.Child(i));
nodesAndScores[i].score = rule.Score(queryIndex, *nodesAndScores[i].node);
@@ -71,7 +71,7 @@ SingleTreeTraverser<RuleType>::Traverse(
// Now iterate through them starting with the best and stopping when we reach
// one that isn't good enough.
for (size_t i = 0; i < referenceNode.NumChildren(); i++)
for (size_t i = 0; i < referenceNode.NumChildren(); ++i)
{
if (rule.Rescore(queryIndex, *nodesAndScores[i].node,
nodesAndScores[i].score) != DBL_MAX)
@@ -173,7 +173,7 @@ class XTreeAuxiliaryInformation
SplitHistoryStruct(int dim) : lastDimension(0), history(dim)
{
for (int i = 0; i < dim; i++)
for (int i = 0; i < dim; ++i)
history[i] = false;
}
@@ -49,7 +49,7 @@ void XTreeSplit::SplitLeafNode(TreeType *tree, std::vector<bool>& relevels)
* dimension to prepare for reinsertion of points into the new nodes.
*/
std::vector<std::pair<ElemType, size_t>> sorted(tree->Count());
for (size_t i = 0; i < sorted.size(); i++)
for (size_t i = 0; i < sorted.size(); ++i)
{
sorted[i].first = tree->Dataset().col(tree->Point(i))[bestAxis];
sorted[i].second = tree->Point(i);
@@ -83,7 +83,7 @@ void XTreeSplit::SplitLeafNode(TreeType *tree, std::vector<bool>& relevels)
tree->bound.Clear();
// Insert the points into the appropriate tree.
for (size_t i = 0; i < numPoints; i++)
for (size_t i = 0; i < numPoints; ++i)
{
if (i < bestIndex + tree->MinLeafSize())
treeOne->InsertPoint(sorted[i].second);
@@ -137,7 +137,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector<bool>& relevels)
// Find the next split axis.
std::vector<bool> axes(tree->Bound().Dim(), true);
std::vector<size_t> dimensionsLastUsed(tree->NumChildren());
for (size_t i = 0; i < tree->NumChildren(); i++)
for (size_t i = 0; i < tree->NumChildren(); ++i)
dimensionsLastUsed[i] =
tree->Child(i).AuxiliaryInfo().SplitHistory().lastDimension;
std::sort(dimensionsLastUsed.begin(), dimensionsLastUsed.end());
@@ -146,9 +146,9 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector<bool>& relevels)
size_t minOverlapSplitDimension = tree->Bound().Dim();
// See if we can use a new dimension.
for (size_t i = lastDim + 1; i < axes.size(); i++)
for (size_t i = lastDim + 1; i < axes.size(); ++i)
{
for (size_t j = 0; j < tree->NumChildren(); j++)
for (size_t j = 0; j < tree->NumChildren(); ++j)
axes[i] = axes[i] &
tree->Child(j).AuxiliaryInfo().SplitHistory().history[i];
if (axes[i] == true)
@@ -160,10 +160,10 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector<bool>& relevels)
if (minOverlapSplitDimension == tree->Bound().Dim())
{
for (size_t i = 0; i < lastDim + 1; i++)
for (size_t i = 0; i < lastDim + 1; ++i)
{
axes[i] = true;
for (size_t j = 0; j < tree->NumChildren(); j++)
for (size_t j = 0; j < tree->NumChildren(); ++j)
axes[i] = axes[i] &
tree->Child(j).AuxiliaryInfo().SplitHistory().history[i];
if (axes[i] == true)
@@ -190,13 +190,13 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector<bool>& relevels)
ElemType overlapBestAreaAxis = 0;
ElemType areaBestAreaAxis = 0;
for (size_t j = 0; j < tree->Bound().Dim(); j++)
for (size_t j = 0; j < tree->Bound().Dim(); ++j)
{
ElemType axisScore = 0.0;
// We'll do Bound().Lo() now and use Bound().Hi() later.
std::vector<std::pair<ElemType, TreeType*>> sorted(tree->NumChildren());
for (size_t i = 0; i < sorted.size(); i++)
for (size_t i = 0; i < sorted.size(); ++i)
{
sorted[i].first = tree->Child(i).Bound()[j].Lo();
sorted[i].second = &tree->Child(i);
@@ -211,14 +211,14 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector<bool>& relevels)
2 * tree->MinNumChildren() + 2);
std::vector<ElemType> overlapedAreas(tree->MaxNumChildren() -
2 * tree->MinNumChildren() + 2);
for (size_t i = 0; i < areas.size(); i++)
for (size_t i = 0; i < areas.size(); ++i)
{
areas[i] = 0.0;
margins[i] = 0.0;
overlapedAreas[i] = 0.0;
}
for (size_t i = 0; i < areas.size(); i++)
for (size_t i = 0; i < areas.size(); ++i)
{
// The ith arrangement is obtained by placing the first
// tree->MinNumChildren() + i points in one rectangle and the rest in
@@ -239,7 +239,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector<bool>& relevels)
ElemType area2 = bound2.Volume();
ElemType oArea = bound1.Overlap(bound2);
for (size_t k = 0; k < bound1.Dim(); k++)
for (size_t k = 0; k < bound1.Dim(); ++k)
margins[i] += bound1[k].Width() + bound2[k].Width();
areas[i] += area1 + area2;
@@ -255,7 +255,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector<bool>& relevels)
bestAreaIndexOnBestAxis = 0;
overlapBestOverlapAxis = overlapedAreas[bestOverlapIndexOnBestAxis];
areaBestOverlapAxis = areas[bestAreaIndexOnBestAxis];
for (size_t i = 1; i < areas.size(); i++)
for (size_t i = 1; i < areas.size(); ++i)
{
if (overlapedAreas[i] < overlapedAreas[bestOverlapIndexOnBestAxis])
{
@@ -283,7 +283,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector<bool>& relevels)
if (minOverlapSplitDimension != tree->Bound().Dim() &&
j == minOverlapSplitDimension)
{
for (size_t i = 0; i < overlapedAreas.size(); i++)
for (size_t i = 0; i < overlapedAreas.size(); ++i)
{
if (overlapedAreas[i] < bestScoreMinOverlapSplit)
{
@@ -296,12 +296,12 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector<bool>& relevels)
}
// Now we do the same thing using Bound().Hi() and choose the best of the two.
for (size_t j = 0; j < tree->Bound().Dim(); j++)
for (size_t j = 0; j < tree->Bound().Dim(); ++j)
{
ElemType axisScore = 0.0;
std::vector<std::pair<ElemType, TreeType*>> sorted(tree->NumChildren());
for (size_t i = 0; i < sorted.size(); i++)
for (size_t i = 0; i < sorted.size(); ++i)
{
sorted[i].first = tree->Child(i).Bound()[j].Hi();
sorted[i].second = &tree->Child(i);
@@ -316,14 +316,14 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector<bool>& relevels)
2 * tree->MinNumChildren() + 2);
std::vector<ElemType> overlapedAreas(tree->MaxNumChildren() -
2 * tree->MinNumChildren() + 2);
for (size_t i = 0; i < areas.size(); i++)
for (size_t i = 0; i < areas.size(); ++i)
{
areas[i] = 0.0;
margins[i] = 0.0;
overlapedAreas[i] = 0.0;
}
for (size_t i = 0; i < areas.size(); i++)
for (size_t i = 0; i < areas.size(); ++i)
{
// The ith arrangement is obtained by placing the first
// tree->MinNumChildren() + i points in one rectangle and the rest in
@@ -344,7 +344,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector<bool>& relevels)
ElemType area2 = bound2.Volume();
ElemType oArea = bound1.Overlap(bound2);
for (size_t k = 0; k < bound1.Dim(); k++)
for (size_t k = 0; k < bound1.Dim(); ++k)
margins[i] += bound1[k].Width() + bound2[k].Width();
@@ -362,7 +362,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector<bool>& relevels)
bestAreaIndexOnBestAxis = 0;
overlapBestOverlapAxis = overlapedAreas[bestOverlapIndexOnBestAxis];
areaBestOverlapAxis = areas[bestAreaIndexOnBestAxis];
for (size_t i = 1; i < areas.size(); i++)
for (size_t i = 1; i < areas.size(); ++i)
{
if (overlapedAreas[i] < overlapedAreas[bestOverlapIndexOnBestAxis])
{
@@ -390,7 +390,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector<bool>& relevels)
if (minOverlapSplitDimension != tree->Bound().Dim() &&
j == minOverlapSplitDimension)
{
for (size_t i = 0; i < overlapedAreas.size(); i++)
for (size_t i = 0; i < overlapedAreas.size(); ++i)
{
if (overlapedAreas[i] < bestScoreMinOverlapSplit)
{
@@ -406,7 +406,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector<bool>& relevels)
std::vector<std::pair<ElemType, TreeType*>> sorted(tree->NumChildren());
if (lowIsBest)
{
for (size_t i = 0; i < sorted.size(); i++)
for (size_t i = 0; i < sorted.size(); ++i)
{
sorted[i].first = tree->Child(i).Bound()[bestAxis].Lo();
sorted[i].second = &tree->Child(i);
@@ -414,7 +414,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector<bool>& relevels)
}
else
{
for (size_t i = 0; i < sorted.size(); i++)
for (size_t i = 0; i < sorted.size(); ++i)
{
sorted[i].first = tree->Child(i).Bound()[bestAxis].Hi();
sorted[i].second = &tree->Child(i);
@@ -439,7 +439,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector<bool>& relevels)
{
tree->numDescendants = 0;
tree->bound.Clear();
for (size_t i = 0; i < numChildren; i++)
for (size_t i = 0; i < numChildren; ++i)
{
if (i < bestAreaIndexOnBestAxis + tree->MinNumChildren())
InsertNodeIntoTree(tree, sorted[i].second);
@@ -456,7 +456,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector<bool>& relevels)
{
tree->numDescendants = 0;
tree->bound.Clear();
for (size_t i = 0; i < numChildren; i++)
for (size_t i = 0; i < numChildren; ++i)
{
if (i < bestOverlapIndexOnBestAxis + tree->MinNumChildren())
InsertNodeIntoTree(tree, sorted[i].second);
@@ -480,7 +480,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector<bool>& relevels)
std::vector<std::pair<ElemType, TreeType*>> sorted2(numChildren);
if (minOverlapSplitUsesHi)
{
for (size_t i = 0; i < sorted2.size(); i++)
for (size_t i = 0; i < sorted2.size(); ++i)
{
sorted2[i].first = sorted[i].second->Bound()[bestAxis].Hi();
sorted2[i].second = sorted[i].second;
@@ -488,7 +488,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector<bool>& relevels)
}
else
{
for (size_t i = 0; i < sorted2.size(); i++)
for (size_t i = 0; i < sorted2.size(); ++i)
{
sorted2[i].first = sorted[i].second->Bound()[bestAxis].Lo();
sorted2[i].second = sorted[i].second;
@@ -499,7 +499,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector<bool>& relevels)
tree->numDescendants = 0;
tree->bound.Clear();
for (size_t i = 0; i < numChildren; i++)
for (size_t i = 0; i < numChildren; ++i)
{
if (i < bestIndexMinOverlapSplit + tree->MinNumChildren())
InsertNodeIntoTree(tree, sorted2[i].second);
@@ -544,7 +544,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector<bool>& relevels)
tree->AuxiliaryInfo().NormalNodeMaxNumChildren();
tree->children.resize(tree->MaxNumChildren() + 1);
tree->numChildren = numChildren;
for (size_t i = 0; i < numChildren; i++)
for (size_t i = 0; i < numChildren; ++i)
tree->Child(i).Parent() = tree;
delete treeTwo;
@@ -574,7 +574,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector<bool>& relevels)
// We have to update the children of each of these new nodes so that they
// record the correct parent.
for (size_t i = 0; i < treeTwo->NumChildren(); i++)
for (size_t i = 0; i < treeTwo->NumChildren(); ++i)
treeTwo->Child(i).Parent() = treeTwo;
assert(tree->Parent()->NumChildren() <=
@@ -602,7 +602,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector<bool>& relevels)
{
if (overlapBestAreaAxis/areaBestAreaAxis < MAX_OVERLAP)
{
for (size_t i = 0; i < numChildren; i++)
for (size_t i = 0; i < numChildren; ++i)
{
if (i < bestAreaIndexOnBestAxis + tree->MinNumChildren())
InsertNodeIntoTree(treeOne, sorted[i].second);
@@ -617,7 +617,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector<bool>& relevels)
{
if (overlapBestOverlapAxis/areaBestOverlapAxis < MAX_OVERLAP)
{
for (size_t i = 0; i < numChildren; i++)
for (size_t i = 0; i < numChildren; ++i)
{
if (i < bestOverlapIndexOnBestAxis + tree->MinNumChildren())
InsertNodeIntoTree(treeOne, sorted[i].second);
@@ -641,7 +641,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector<bool>& relevels)
std::vector<std::pair<ElemType, TreeType*>> sorted2(numChildren);
if (minOverlapSplitUsesHi)
{
for (size_t i = 0; i < sorted2.size(); i++)
for (size_t i = 0; i < sorted2.size(); ++i)
{
sorted2[i].first = sorted[i].second->Bound()[bestAxis].Hi();
sorted2[i].second = sorted[i].second;
@@ -649,7 +649,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector<bool>& relevels)
}
else
{
for (size_t i = 0; i < sorted2.size(); i++)
for (size_t i = 0; i < sorted2.size(); ++i)
{
sorted2[i].first = sorted[i].second->Bound()[bestAxis].Lo();
sorted2[i].second = sorted[i].second;
@@ -658,7 +658,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector<bool>& relevels)
std::sort(sorted2.begin(), sorted2.end(),
PairComp<ElemType, TreeType*>);
for (size_t i = 0; i < numChildren; i++)
for (size_t i = 0; i < numChildren; ++i)
{
if (i < bestIndexMinOverlapSplit + tree->MinNumChildren())
InsertNodeIntoTree(treeOne, sorted2[i].second);
@@ -673,7 +673,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector<bool>& relevels)
tree->AuxiliaryInfo().NormalNodeMaxNumChildren();
tree->children.resize(tree->MaxNumChildren() + 1);
tree->numChildren = numChildren;
for (size_t i = 0; i < numChildren; i++)
for (size_t i = 0; i < numChildren; ++i)
tree->Child(i).Parent() = tree;
delete treeOne;
@@ -698,7 +698,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector<bool>& relevels)
// record the correct parent.
for (size_t i = 0; i < treeOne->NumChildren(); ++i)
treeOne->Child(i).Parent() = treeOne;
for (size_t i = 0; i < treeTwo->NumChildren(); i++)
for (size_t i = 0; i < treeTwo->NumChildren(); ++i)
treeTwo->Child(i).Parent() = treeTwo;
return false;
@@ -35,7 +35,7 @@ bool MeanSpaceSplit<MetricType, MatType>::SplitSpace(
return false;
double splitVal = 0.0;
for (size_t i = 0; i < points.n_elem; i++)
for (size_t i = 0; i < points.n_elem; ++i)
splitVal += projVector.Project(data.col(points[i]));
splitVal /= points.n_elem;
@@ -67,7 +67,7 @@ bool SpaceSplit<MetricType, MatType>::GetProjVector(
size_t snd = points[0];
double max = metric.Evaluate(data.col(fst), data.col(snd));
for (size_t i = 1; i < points.n_elem; i++)
for (size_t i = 1; i < points.n_elem; ++i)
{
double dist = metric.Evaluate(data.col(fst), data.col(points[i]));
if (dist > max)
@@ -79,7 +79,7 @@ bool SpaceSplit<MetricType, MatType>::GetProjVector(
std::swap(fst, snd);
for (size_t i = 0; i < points.n_elem; i++)
for (size_t i = 0; i < points.n_elem; ++i)
{
double dist = metric.Evaluate(data.col(fst), data.col(points[i]));
if (dist > max)
@@ -722,7 +722,7 @@ void SpillTree<MetricType, StatisticType, MatType, HyperplaneType, SplitType>::
const double rho)
{
// We need to expand the bounds of this node properly.
for (size_t i = 0; i < points.n_elem; i++)
for (size_t i = 0; i < points.n_elem; ++i)
bound |= dataset->col(points[i]);
// Calculate the furthest descendant distance.
@@ -795,7 +795,7 @@ bool SpillTree<MetricType, StatisticType, MatType, HyperplaneType, SplitType>::
size_t left = 0, right = 0, leftFrontier = 0, rightFrontier = 0;
// Count the number of points to the left/right of the splitting hyperplane.
for (size_t i = 0; i < points.n_elem; i++)
for (size_t i = 0; i < points.n_elem; ++i)
{
// Store projection value for future use.
projections[i] = hyperplane.Project(dataset->col(points[i]));
@@ -824,7 +824,7 @@ bool SpillTree<MetricType, StatisticType, MatType, HyperplaneType, SplitType>::
// leftPoints and rightPoints.
leftPoints.resize(left + rightFrontier);
rightPoints.resize(right + leftFrontier);
for (size_t i = 0, rc = 0, lc = 0; i < points.n_elem; i++)
for (size_t i = 0, rc = 0, lc = 0; i < points.n_elem; ++i)
{
if (projections[i] < tau || projections[i] <= 0)
leftPoints[lc++] = points[i];
@@ -841,7 +841,7 @@ bool SpillTree<MetricType, StatisticType, MatType, HyperplaneType, SplitType>::
// rightPoints.
leftPoints.resize(left);
rightPoints.resize(right);
for (size_t i = 0, rc = 0, lc = 0; i < points.n_elem; i++)
for (size_t i = 0, rc = 0, lc = 0; i < points.n_elem; ++i)
{
if (projections[i] <= 0)
leftPoints[lc++] = points[i];
+2 -2
View File
@@ -84,7 +84,7 @@ void Backtrace::GetAddress(int maxDepth)
int stackDepth = backtrace(trace, maxDepth);
// Skip first stack frame (points to Backtrace::Backtrace).
for (int i = 1; i < stackDepth; i++)
for (int i = 1; i < stackDepth; ++i)
{
Dl_info addressHandler;
@@ -182,7 +182,7 @@ std::string Backtrace::ToString()
return stackStr;
}
for (size_t i = 0; i < stack.size(); i++)
for (size_t i = 0; i < stack.size(); ++i)
{
frame = stack[i];
@@ -106,7 +106,7 @@ double AdaBoost<WeakLearnerType, MatType>::Train(
arma::Row<size_t> finalH(predictedLabels.n_cols);
// Now, start the boosting rounds.
for (size_t i = 0; i < iterations; i++)
for (size_t i = 0; i < iterations; ++i)
{
// Initialized to zero in every round. rt is used for calculation of
// alphat; it is the weighted error.
@@ -127,7 +127,7 @@ double AdaBoost<WeakLearnerType, MatType>::Train(
// buildClassificationMatrix(ht, predictedLabels);
// Now, calculate alpha(t) using ht.
for (size_t j = 0; j < D.n_cols; j++) // instead of D, ht
for (size_t j = 0; j < D.n_cols; ++j) // instead of D, ht
{
if (predictedLabels(j) == labels(j))
rt += arma::accu(D.col(j));
@@ -157,12 +157,12 @@ double AdaBoost<WeakLearnerType, MatType>::Train(
wl.push_back(w);
// Now start modifying the weights.
for (size_t j = 0; j < D.n_cols; j++)
for (size_t j = 0; j < D.n_cols; ++j)
{
const double expo = exp(alphat);
if (predictedLabels(j) == labels(j))
{
for (size_t k = 0; k < D.n_rows; k++)
for (size_t k = 0; k < D.n_rows; ++k)
{
// We calculate zt, the normalization constant.
D(k, j) /= expo;
@@ -178,7 +178,7 @@ double AdaBoost<WeakLearnerType, MatType>::Train(
}
else
{
for (size_t k = 0; k < D.n_rows; k++)
for (size_t k = 0; k < D.n_rows; ++k)
{
// We calculate zt, the normalization constant.
D(k, j) *= expo;
@@ -230,18 +230,18 @@ void AdaBoost<WeakLearnerType, MatType>::Classify(
probabilities.zeros(numClasses, test.n_cols);
predictedLabels.set_size(test.n_cols);
for (size_t i = 0; i < wl.size(); i++)
for (size_t i = 0; i < wl.size(); ++i)
{
wl[i].Classify(test, tempPredictedLabels);
for (size_t j = 0; j < tempPredictedLabels.n_cols; j++)
for (size_t j = 0; j < tempPredictedLabels.n_cols; ++j)
probabilities(tempPredictedLabels(j), j) += alpha[i];
}
arma::colvec pRow;
arma::uword maxIndex = 0;
for (size_t i = 0; i < predictedLabels.n_cols; i++)
for (size_t i = 0; i < predictedLabels.n_cols; ++i)
{
probabilities.col(i) /= arma::accu(probabilities.col(i));
pRow = probabilities.unsafe_col(i);
@@ -78,9 +78,9 @@ class SimpleToleranceTermination
size_t m = V->n_cols;
double sum = 0;
size_t count = 0;
for (size_t i = 0; i < n; i++)
for (size_t i = 0; i < n; ++i)
{
for (size_t j = 0; j < m; j++)
for (size_t j = 0; j < m; ++j)
{
double temp = 0;
if ((temp = (*V)(i, j)) != 0)
@@ -64,7 +64,7 @@ class ValidationRMSETermination
test_points.zeros(num_test_points, 3);
// fill validation set matrix with random chosen entries
for (size_t i = 0; i < num_test_points; i++)
for (size_t i = 0; i < num_test_points; ++i)
{
double t_val;
size_t t_row;
@@ -123,7 +123,7 @@ class ValidationRMSETermination
{
rmseOld = rmse;
rmse = 0;
for (size_t i = 0; i < num_test_points; i++)
for (size_t i = 0; i < num_test_points; ++i)
{
size_t t_row = test_points(i, 0);
size_t t_col = test_points(i, 1);
@@ -78,7 +78,7 @@ class NMFALSUpdate
W = V * H.t() * pinv(H * H.t());
// Set all negative numbers to machine epsilon.
for (size_t i = 0; i < W.n_elem; i++)
for (size_t i = 0; i < W.n_elem; ++i)
{
if (W(i) < 0.0)
{
@@ -109,7 +109,7 @@ class NMFALSUpdate
H = pinv(W.t() * W) * W.t() * V;
// Set all negative numbers to 0.
for (size_t i = 0; i < H.n_elem; i++)
for (size_t i = 0; i < H.n_elem; ++i)
{
if (H(i) < 0.0)
{
@@ -130,9 +130,9 @@ class NMFMultiplicativeDivergenceUpdate
arma::colvec t2;
t1 = W * H;
for (size_t i = 0; i < H.n_rows; i++)
for (size_t i = 0; i < H.n_rows; ++i)
{
for (size_t j = 0; j < H.n_cols; j++)
for (size_t j = 0; j < H.n_cols; ++j)
{
// Writing this as a single expression does not work as of Armadillo
// 3.920. This should be fixed in a future release, and then the code
@@ -100,9 +100,9 @@ class SVDBatchLearning
// Compute the step.
arma::mat deltaW;
deltaW.zeros(n, r);
for (size_t i = 0; i < n; i++)
for (size_t i = 0; i < n; ++i)
{
for (size_t j = 0; j < m; j++)
for (size_t j = 0; j < m; ++j)
{
const double val = V(i, j);
if (val != 0)
@@ -145,9 +145,9 @@ class SVDBatchLearning
// Compute the step.
arma::mat deltaH;
deltaH.zeros(r, m);
for (size_t j = 0; j < m; j++)
for (size_t j = 0; j < m; ++j)
{
for (size_t i = 0; i < n; i++)
for (size_t i = 0; i < n; ++i)
{
const double val = V(i, j);
if (val != 0)
@@ -56,7 +56,7 @@ class HardSigmoidFunction
{
y.set_size(size(x));
for (size_t i = 0; i < x.n_elem; i++)
for (size_t i = 0; i < x.n_elem; ++i)
y(i) = Fn(x(i));
}
@@ -86,7 +86,7 @@ class HardSigmoidFunction
{
x.set_size(size(y));
for (size_t i = 0; i < y.n_elem; i++)
for (size_t i = 0; i < y.n_elem; ++i)
{
x(i) = Deriv(y(i));
}
@@ -104,7 +104,7 @@ class RectifierFunction
{
x.set_size(arma::size(y));
for (size_t i = 0; i < y.n_elem; i++)
for (size_t i = 0; i < y.n_elem; ++i)
x(i) = Deriv(y(i));
}
}; // class RectifierFunction
@@ -68,7 +68,7 @@ class SoftplusFunction
{
y.set_size(arma::size(x));
for (size_t i = 0; i < x.n_elem; i++)
for (size_t i = 0; i < x.n_elem; ++i)
y(i) = Fn(x(i));
}
@@ -120,7 +120,7 @@ class SoftplusFunction
{
x.set_size(arma::size(y));
for (size_t i = 0; i < y.n_elem; i++)
for (size_t i = 0; i < y.n_elem; ++i)
x(i) = Inv(y(i));
}
}; // class SoftplusFunction
@@ -71,7 +71,7 @@ class SoftsignFunction
{
y.set_size(arma::size(x));
for (size_t i = 0; i < x.n_elem; i++)
for (size_t i = 0; i < x.n_elem; ++i)
y(i) = Fn(x(i));
}
@@ -123,7 +123,7 @@ class SoftsignFunction
{
x.set_size(arma::size(y));
for (size_t i = 0; i < y.n_elem; i++)
for (size_t i = 0; i < y.n_elem; ++i)
x(i) = Inv(y(i));
}
}; // class SoftsignFunction
@@ -64,7 +64,7 @@ class SwishFunction
{
y.set_size(arma::size(x));
for (size_t i = 0; i < x.n_elem; i++)
for (size_t i = 0; i < x.n_elem; ++i)
y(i) = Fn(x(i));
}
@@ -38,7 +38,7 @@ double SequencePrecision(arma::field<MatType> trueOutputs,
throw std::invalid_argument(oss.str());
}
for (size_t i = 0; i < testSize; i++)
for (size_t i = 0; i < testSize; ++i)
{
arma::vec delta = arma::vectorise(arma::abs(
trueOutputs.at(i) - predOutputs.at(i)));
@@ -144,7 +144,7 @@ class FFTConvolution
input.n_slices);
output.slice(0) = convOutput;
for (size_t i = 1; i < input.n_slices; i++)
for (size_t i = 1; i < input.n_slices; ++i)
{
FFTConvolution<BorderMode>::Convolution(input.slice(i), filter.slice(i),
output.slice(i));
@@ -175,7 +175,7 @@ class FFTConvolution
filter.n_slices);
output.slice(0) = convOutput;
for (size_t i = 1; i < filter.n_slices; i++)
for (size_t i = 1; i < filter.n_slices; ++i)
{
FFTConvolution<BorderMode>::Convolution(input, filter.slice(i),
output.slice(i));
@@ -203,7 +203,7 @@ class FFTConvolution
input.n_slices);
output.slice(0) = convOutput;
for (size_t i = 1; i < input.n_slices; i++)
for (size_t i = 1; i < input.n_slices; ++i)
{
FFTConvolution<BorderMode>::Convolution(input.slice(i), filter,
output.slice(i));
@@ -108,7 +108,7 @@ class NaiveConvolution
size_t outputCols = (input.n_cols - 1) * dH + 2 * (filter.n_cols - 1)
* dilationH + 1;
for (size_t i = 0; i < dW; i++)
for (size_t i = 0; i < dW; ++i)
{
if (((((i + outputRows - 2 * (filter.n_rows - 1) * dilationW - 1) % dW)
+ dW) % dW) == i){
@@ -116,7 +116,7 @@ class NaiveConvolution
break;
}
}
for (size_t i = 0; i < dH; i++)
for (size_t i = 0; i < dH; ++i)
{
if (((((i + outputCols - 2 * (filter.n_cols - 1) * dilationH - 1) % dH)
+ dH) % dH) == i){
@@ -164,7 +164,7 @@ class NaiveConvolution
input.n_slices);
output.slice(0) = convOutput;
for (size_t i = 1; i < input.n_slices; i++)
for (size_t i = 1; i < input.n_slices; ++i)
{
NaiveConvolution<BorderMode>::Convolution(input.slice(i), filter.slice(i),
output.slice(i), dW, dH, dilationW, dilationH);
@@ -200,7 +200,7 @@ class NaiveConvolution
filter.n_slices);
output.slice(0) = convOutput;
for (size_t i = 1; i < filter.n_slices; i++)
for (size_t i = 1; i < filter.n_slices; ++i)
{
NaiveConvolution<BorderMode>::Convolution(input, filter.slice(i),
output.slice(i), dW, dH, dilationW, dilationH);
@@ -236,7 +236,7 @@ class NaiveConvolution
input.n_slices);
output.slice(0) = convOutput;
for (size_t i = 1; i < input.n_slices; i++)
for (size_t i = 1; i < input.n_slices; ++i)
{
NaiveConvolution<BorderMode>::Convolution(input.slice(i), filter,
output.slice(i), dW, dH, dilationW, dilationH);
@@ -131,7 +131,7 @@ class SVDConvolution
input.n_slices);
output.slice(0) = convOutput;
for (size_t i = 1; i < input.n_slices; i++)
for (size_t i = 1; i < input.n_slices; ++i)
{
SVDConvolution<BorderMode>::Convolution(input.slice(i), filter.slice(i),
output.slice(i));
@@ -160,7 +160,7 @@ class SVDConvolution
filter.n_slices);
output.slice(0) = convOutput;
for (size_t i = 1; i < filter.n_slices; i++)
for (size_t i = 1; i < filter.n_slices; ++i)
{
SVDConvolution<BorderMode>::Convolution(input, filter.slice(i),
output.slice(i));
@@ -189,7 +189,7 @@ class SVDConvolution
input.n_slices);
output.slice(0) = convOutput;
for (size_t i = 1; i < input.n_slices; i++)
for (size_t i = 1; i < input.n_slices; ++i)
{
SVDConvolution<BorderMode>::Convolution(input.slice(i), filter,
output.slice(i));
@@ -52,7 +52,7 @@ DataType BernoulliDistribution<DataType>::Sample() const
DataType sample = arma::randu<DataType>
(probability.n_rows, probability.n_cols);
for (size_t i = 0; i < sample.n_elem; i++)
for (size_t i = 0; i < sample.n_elem; ++i)
sample(i) = sample(i) < probability(i);
return sample;
+1 -1
View File
@@ -242,7 +242,7 @@ void FFN<OutputLayerType, InitializationRuleType, CustomLayers...>::Predict(
results = arma::mat(resultsTemp.n_elem, predictors.n_cols);
results.col(0) = resultsTemp.col(0);
for (size_t i = 1; i < predictors.n_cols; i++)
for (size_t i = 1; i < predictors.n_cols; ++i)
{
Forward(arma::mat(predictors.colptr(i), predictors.n_rows, 1, false, true));
@@ -32,7 +32,7 @@ double InceptionScore(ModelType model,
size_t index = 0;
arma::vec scores = arma::vec(splits);
for (int i = 0; i < splits; i++)
for (int i = 0; i < splits; ++i)
{
size_t curSize = splitSize;
if (remainder)
@@ -75,7 +75,7 @@ class GaussianInitialization
{
W = arma::Cube<eT>(rows, cols, slices);
for (size_t i = 0; i < slices; i++)
for (size_t i = 0; i < slices; ++i)
Initialize(W.slice(i), rows, cols);
}
@@ -131,7 +131,7 @@ inline void GlorotInitializationType<Uniform>::Initialize(arma::Cube<eT>& W,
{
W = arma::cube(rows, cols, slices);
}
for (size_t i = 0; i < slices; i++)
for (size_t i = 0; i < slices; ++i)
Initialize(W.slice(i), rows, cols);
}
@@ -95,7 +95,7 @@ class HeInitialization
if (W.is_empty())
W.set_size(rows, cols, slices);
for (size_t i = 0; i < slices; i++)
for (size_t i = 0; i < slices; ++i)
Initialize(W.slice(i), rows, cols);
}
}; // class HeInitialization
@@ -107,7 +107,7 @@ class KathirvalavakumarSubavathiInitialization
{
W = arma::Cube<eT>(rows, cols, slices);
for (size_t i = 0; i < slices; i++)
for (size_t i = 0; i < slices; ++i)
Initialize(W.slice(i), rows, cols);
}
@@ -101,7 +101,7 @@ class LecunNormalInitialization
if (W.is_empty())
W.set_size(rows, cols, slices);
for (size_t i = 0; i < slices; i++)
for (size_t i = 0; i < slices; ++i)
Initialize(W.slice(i), rows, cols);
}
}; // class LecunNormalInitialization
@@ -99,7 +99,7 @@ class NguyenWidrowInitialization
{
W = arma::Cube<eT>(rows, cols, slices);
for (size_t i = 0; i < slices; i++)
for (size_t i = 0; i < slices; ++i)
Initialize(W.slice(i), rows, cols);
}
@@ -108,7 +108,7 @@ class OivsInitialization
{
W = arma::Cube<eT>(rows, cols, slices);
for (size_t i = 0; i < slices; i++)
for (size_t i = 0; i < slices; ++i)
Initialize(W.slice(i), rows, cols);
}
@@ -66,7 +66,7 @@ class OrthogonalInitialization
{
W = arma::Cube<eT>(rows, cols, slices);
for (size_t i = 0; i < slices; i++)
for (size_t i = 0; i < slices; ++i)
Initialize(W.slice(i), rows, cols);
}
@@ -75,7 +75,7 @@ class RandomInitialization
{
W = arma::Cube<eT>(rows, cols, slices);
for (size_t i = 0; i < slices; i++)
for (size_t i = 0; i < slices; ++i)
Initialize(W.slice(i), rows, cols);
}
@@ -368,13 +368,13 @@ void AtrousConvolution<
if (dilationHeight > 1)
{
for (size_t i = 1; i < output.n_cols; i++){
for (size_t i = 1; i < output.n_cols; ++i){
output.shed_cols(i, i + dilationHeight - 2);
}
}
if (dilationWidth > 1)
{
for (size_t i = 1; i < output.n_rows; i++){
for (size_t i = 1; i < output.n_rows; ++i){
output.shed_rows(i, i + dilationWidth - 2);
}
}
@@ -85,7 +85,7 @@ void BatchNorm<InputDataType, OutputDataType>::Forward(
output.each_col() /= arma::sqrt(variance + eps);
// Use Welford method to compute the sample variance and mean.
for (size_t i = 0; i < input.n_cols; i++)
for (size_t i = 0; i < input.n_cols; ++i)
{
count += 1;
@@ -77,7 +77,7 @@ void BilinearInterpolation<InputDataType, OutputDataType>::Forward(
double scaleCol = (double) inColSize / (double) outColSize;
arma::mat22 coeffs;
for (size_t i = 0; i < outRowSize; i++)
for (size_t i = 0; i < outRowSize; ++i)
{
size_t rOrigin = (size_t) std::floor(i * scaleRow);
if (rOrigin > inRowSize - 2)
@@ -87,7 +87,7 @@ void BilinearInterpolation<InputDataType, OutputDataType>::Forward(
double deltaR = i * scaleRow - rOrigin;
if (deltaR > 1)
deltaR = 1.0;
for (size_t j = 0; j < outColSize; j++)
for (size_t j = 0; j < outColSize; ++j)
{
// Scaled distance of the interpolated point from the leftmost column.
size_t cOrigin = (size_t) std::floor(j * scaleCol);
@@ -102,7 +102,7 @@ void BilinearInterpolation<InputDataType, OutputDataType>::Forward(
coeffs[2] = (1 - deltaR) * deltaC;
coeffs[3] = deltaR * deltaC;
for (size_t k = 0; k < depth * batchSize; k++)
for (size_t k = 0; k < depth * batchSize; ++k)
{
outputAsCube(i, j, k) = arma::accu(inputAsCube.slice(k).submat(
rOrigin, cOrigin, rOrigin + 1, cOrigin + 1) % coeffs);
@@ -144,13 +144,13 @@ void BilinearInterpolation<InputDataType, OutputDataType>::Backward(
double scaleCol = (double)(outColSize) / inColSize;
arma::mat22 coeffs;
for (size_t i = 0; i < inRowSize; i++)
for (size_t i = 0; i < inRowSize; ++i)
{
size_t rOrigin = (size_t) std::floor(i * scaleRow);
if (rOrigin > outRowSize - 2)
rOrigin = outRowSize - 2;
double deltaR = i * scaleRow - rOrigin;
for (size_t j = 0; j < inColSize; j++)
for (size_t j = 0; j < inColSize; ++j)
{
size_t cOrigin = (size_t) std::floor(j * scaleCol);
@@ -163,7 +163,7 @@ void BilinearInterpolation<InputDataType, OutputDataType>::Backward(
coeffs[2] = (1 - deltaR) * deltaC;
coeffs[3] = deltaR * deltaC;
for (size_t k = 0; k < depth * batchSize; k++)
for (size_t k = 0; k < depth * batchSize; ++k)
{
outputAsCube(i, j, k) = arma::accu(gradientAsCube.slice(k).submat(
rOrigin, cOrigin, rOrigin + 1, cOrigin + 1) % coeffs);
+2 -2
View File
@@ -36,7 +36,7 @@ void CELU<InputDataType, OutputDataType>::Forward(
const InputType& input, OutputType& output)
{
output = arma::ones<OutputDataType>(arma::size(input));
for (size_t i = 0; i < input.n_elem; i++)
for (size_t i = 0; i < input.n_elem; ++i)
{
output(i) = (input(i) >= 0) ? input(i) : alpha *
(std::exp(input(i) / alpha) - 1);
@@ -45,7 +45,7 @@ void CELU<InputDataType, OutputDataType>::Forward(
if (!deterministic)
{
derivative.set_size(arma::size(input));
for (size_t i = 0; i < input.n_elem; i++)
for (size_t i = 0; i < input.n_elem; ++i)
{
derivative(i) = (input(i) >= 0) ? 1 :
(output(i) / alpha) + 1;
@@ -83,7 +83,7 @@ void ConcatPerformance<
output = arma::zeros(subOutput.n_elem, inSize);
output.col(0) = subOutput;
for (size_t i = elements, j = 0; i < input.n_elem; i+= elements, j++)
for (size_t i = elements, j = 0; i < input.n_elem; i+= elements, ++j)
{
subInput = input.submat(i, 0, i + elements - 1, 0);
outputLayer.Backward(subInput, target, subOutput);
+2 -2
View File
@@ -52,7 +52,7 @@ void ELU<InputDataType, OutputDataType>::Forward(
const InputType& input, OutputType& output)
{
output = arma::ones<OutputDataType>(arma::size(input));
for (size_t i = 0; i < input.n_elem; i++)
for (size_t i = 0; i < input.n_elem; ++i)
{
if (input(i) < DBL_MAX)
{
@@ -64,7 +64,7 @@ void ELU<InputDataType, OutputDataType>::Forward(
if (!deterministic)
{
derivative.set_size(arma::size(input));
for (size_t i = 0; i < input.n_elem; i++)
for (size_t i = 0; i < input.n_elem; ++i)
{
derivative(i) = (input(i) > 0) ? lambda : output(i) +
lambda * alpha;
+3 -3
View File
@@ -198,9 +198,9 @@ class Glimpse
{
arma::mat t = w;
for (size_t i = 0, k = 0; i < w.n_elem; k++)
for (size_t i = 0, k = 0; i < w.n_elem; ++k)
{
for (size_t j = 0; j < w.n_cols; j++, i++)
for (size_t j = 0; j < w.n_cols; ++j, ++i)
{
w(k, j) = t(i);
}
@@ -214,7 +214,7 @@ class Glimpse
*/
void Transform(arma::cube& w)
{
for (size_t i = 0; i < w.n_slices; i++)
for (size_t i = 0; i < w.n_slices; ++i)
{
arma::mat t = w.slice(i);
Transform(t);
@@ -138,9 +138,9 @@ void Glimpse<InputDataType, OutputDataType>::Backward(
location = locationParameter.back();
locationParameter.pop_back();
for (size_t s = 0, j = 0; s < mappedError.n_slices; s+= gy.n_cols, j++)
for (size_t s = 0, j = 0; s < mappedError.n_slices; s+= gy.n_cols, ++j)
{
for (size_t i = 0; i < gy.n_cols; i++)
for (size_t i = 0; i < gy.n_cols; ++i)
{
mappedError.slice(s + i) = arma::Mat<eT>(gy.memptr(),
outputWidth, outputHeight);
@@ -34,7 +34,7 @@ void HardTanH<InputDataType, OutputDataType>::Forward(
const InputType& input, OutputType& output)
{
output = input;
for (size_t i = 0; i < input.n_elem; i++)
for (size_t i = 0; i < input.n_elem; ++i)
{
output(i) = (output(i) > maxValue ? maxValue :
(output(i) < minValue ? minValue : output(i)));
@@ -47,7 +47,7 @@ void HardTanH<InputDataType, OutputDataType>::Backward(
const DataType& input, const DataType& gy, DataType& g)
{
g = gy;
for (size_t i = 0; i < input.n_elem; i++)
for (size_t i = 0; i < input.n_elem; ++i)
{
if (input(i) < minValue || input(i) > maxValue)
{
@@ -42,7 +42,7 @@ void LeakyReLU<InputDataType, OutputDataType>::Backward(
{
DataType derivative;
derivative.set_size(arma::size(input));
for (size_t i = 0; i < input.n_elem; i++)
for (size_t i = 0; i < input.n_elem; ++i)
derivative(i) = (input(i) >= 0) ? 1 : alpha;
g = gy % derivative;
@@ -60,10 +60,10 @@ void MiniBatchDiscrimination<InputDataType, OutputDataType>::Forward(
distances.set_size(B, batchSize, batchSize);
output.set_size(B, batchSize);
for (size_t i = 0; i < M.n_slices; i++)
for (size_t i = 0; i < M.n_slices; ++i)
{
output.col(i).ones();
for (size_t j = 0; j < M.n_slices; j++)
for (size_t j = 0; j < M.n_slices; ++j)
{
if (j < i)
{
@@ -94,9 +94,9 @@ void MiniBatchDiscrimination<InputDataType, OutputDataType>::Backward(
arma::Mat<eT> gM = gy.tail_rows(B);
deltaM.zeros(B, C, batchSize);
for (size_t i = 0; i < M.n_slices; i++)
for (size_t i = 0; i < M.n_slices; ++i)
{
for (size_t j = 0; j < M.n_slices; j++)
for (size_t j = 0; j < M.n_slices; ++j)
{
if (i == j)
{
@@ -53,7 +53,7 @@ void PReLU<InputDataType, OutputDataType>::Backward(
{
DataType derivative;
derivative.set_size(arma::size(input));
for (size_t i = 0; i < input.n_elem; i++)
for (size_t i = 0; i < input.n_elem; ++i)
{
derivative(i) = (input(i) >= 0) ? 1 : alpha(0);
}
+1 -1
View File
@@ -86,7 +86,7 @@ class Subview
if ((input.n_rows != ((endRow - beginRow + 1) *
(endCol - beginCol + 1))) || (input.n_cols != batchSize))
{
for (size_t i = 0; i < batchSize; i++)
for (size_t i = 0; i < batchSize; ++i)
{
output.col(i) = arma::vectorise(
input.submat(beginRow, batchBegin, endRow, batchEnd));
@@ -49,7 +49,7 @@ double VRClassReward<InputDataType, OutputDataType>::Forward(
reward = 0;
arma::uword index = 0;
for (size_t i = 0; i < input.n_cols - 1; i++)
for (size_t i = 0; i < input.n_cols - 1; ++i)
{
input.unsafe_col(i).max(index);
reward = ((index + 1) == target(i)) * scale;
+4 -4
View File
@@ -169,7 +169,7 @@ RBM<InitializationRuleType, DataType, PolicyType>::SampleHidden(
{
HiddenMean(std::move(input), std::move(output));
for (size_t i = 0; i < output.n_elem; i++)
for (size_t i = 0; i < output.n_elem; ++i)
{
output(i) = math::RandBernoulli(output(i));
}
@@ -188,7 +188,7 @@ RBM<InitializationRuleType, DataType, PolicyType>::SampleVisible(
{
VisibleMean(std::move(input), std::move(output));
for (size_t i = 0; i < output.n_elem; i++)
for (size_t i = 0; i < output.n_elem; ++i)
{
output(i) = math::RandBernoulli(output(i));
}
@@ -247,7 +247,7 @@ void RBM<InitializationRuleType, DataType, PolicyType>::Gibbs(
SampleVisible(std::move(gibbsTemporary), std::move(output));
}
for (size_t j = 1; j < this->steps; j++)
for (size_t j = 1; j < this->steps; ++j)
{
SampleHidden(std::move(output), std::move(gibbsTemporary));
SampleVisible(std::move(gibbsTemporary), std::move(output));
@@ -275,7 +275,7 @@ void RBM<InitializationRuleType, DataType, PolicyType>::Gradient(
Phase(std::move(predictors.cols(i, i + batchSize - 1)),
std::move(positiveGradient));
for (size_t i = 0; i < negSteps; i++)
for (size_t i = 0; i < negSteps; ++i)
{
Gibbs(std::move(predictors.cols(i, i + batchSize - 1)),
std::move(negativeSamples));
@@ -75,7 +75,7 @@ RBM<InitializationRuleType, DataType, PolicyType>::FreeEnergy(
freeEnergy -= 0.5 * hiddenSize * poolSize *
std::log((2.0 * M_PI) / slabPenalty);
for (size_t i = 0; i < hiddenSize; i++)
for (size_t i = 0; i < hiddenSize; ++i)
{
ElemType sum = arma::accu(arma::square(input.t() * weight.slice(i))) /
(2.0 * slabPenalty);
@@ -109,7 +109,7 @@ RBM<InitializationRuleType, DataType, PolicyType>::Phase(
SampleSpike(std::move(spikeMean), std::move(spikeSamples));
SlabMean(std::move(input), std::move(spikeSamples), std::move(slabMean));
for (size_t i = 0 ; i < hiddenSize; i++)
for (size_t i = 0 ; i < hiddenSize; ++i)
{
weightGrad.slice(i) = input * arma::repmat(slabMean.col(i).t(),
input.n_cols, 1) * spikeMean(i);
@@ -161,9 +161,9 @@ RBM<InitializationRuleType, DataType, PolicyType>::SampleVisible(
VisibleMean(std::move(input), std::move(visibleMean));
output.set_size(visibleSize, 1);
for (k = 0; k < numMaxTrials; k++)
for (k = 0; k < numMaxTrials; ++k)
{
for (size_t i = 0; i < visibleSize; i++)
for (size_t i = 0; i < visibleSize; ++i)
{
output(i) = math::RandNormal(visibleMean(i), 1.0 / visiblePenalty(0));
}
@@ -199,7 +199,7 @@ RBM<InitializationRuleType, DataType, PolicyType>::VisibleMean(
DataType slab(input.memptr() + hiddenSize, poolSize, hiddenSize, false,
false);
for (size_t i = 0; i < hiddenSize; i++)
for (size_t i = 0; i < hiddenSize; ++i)
{
output += weight.slice(i) * slab.col(i) * spike(i);
}
@@ -240,7 +240,7 @@ RBM<InitializationRuleType, DataType, PolicyType>::SpikeMean(
DataType&& visible,
DataType&& spikeMean)
{
for (size_t i = 0; i < hiddenSize; i++)
for (size_t i = 0; i < hiddenSize; ++i)
{
spikeMean(i) = LogisticFunction::Fn(0.5 * (1.0 / slabPenalty) * arma::accu(
visible.t() * (weight.slice(i) * weight.slice(i).t()) * visible)
@@ -259,7 +259,7 @@ RBM<InitializationRuleType, DataType, PolicyType>::SampleSpike(
DataType&& spikeMean,
DataType&& spike)
{
for (size_t i = 0; i < hiddenSize; i++)
for (size_t i = 0; i < hiddenSize; ++i)
{
spike(i) = math::RandBernoulli(spikeMean(i));
}
@@ -277,7 +277,7 @@ RBM<InitializationRuleType, DataType, PolicyType>::SlabMean(
DataType&& spike,
DataType&& slabMean)
{
for (size_t i = 0; i < hiddenSize; i++)
for (size_t i = 0; i < hiddenSize; ++i)
{
slabMean.col(i) = arma::mean((1.0 / slabPenalty) * spike(i) *
weight.slice(i).t() * visible, 1);
@@ -295,9 +295,9 @@ RBM<InitializationRuleType, DataType, PolicyType>::SampleSlab(
DataType&& slabMean,
DataType&& slab)
{
for (size_t i = 0; i < hiddenSize; i++)
for (size_t i = 0; i < hiddenSize; ++i)
{
for (size_t j = 0; j < poolSize; j++)
for (size_t j = 0; j < poolSize; ++j)
{
slab(j, i) = math::RandNormal(slabMean(j, i), 1.0 / slabPenalty);
}
@@ -29,9 +29,9 @@ void OrthogonalRegularizer::Evaluate(const MatType& weight, MatType& gradient)
{
arma::mat grad = arma::zeros(arma::size(weight));
for (size_t i = 0; i < weight.n_rows; i++)
for (size_t i = 0; i < weight.n_rows; ++i)
{
for (size_t j = 0; j < weight.n_rows; j++)
for (size_t j = 0; j < weight.n_rows; ++j)
{
if (i == j)
{
@@ -108,7 +108,7 @@ void BiasSVDFunction<MatType>::Gradient(const arma::mat& parameters,
gradient.zeros(rank + 1, numUsers + numItems);
for (size_t i = 0; i < data.n_cols; i++)
for (size_t i = 0; i < data.n_cols; ++i)
{
// Indices for accessing the the correct parameter columns.
const size_t user = data(0, i);
@@ -198,7 +198,7 @@ double StandardSGD::Optimize(
double overallObjective = 0;
// Calculate the first objective function.
for (size_t i = 0; i < numFunctions; i++)
for (size_t i = 0; i < numFunctions; ++i)
overallObjective += function.Evaluate(parameters, i);
const arma::mat data = function.Dataset();
@@ -207,7 +207,7 @@ double StandardSGD::Optimize(
const size_t rank = function.Rank();
// Now iterate!
for (size_t i = 1; i != maxIterations; i++, currentFunction++)
for (size_t i = 1; i != maxIterations; ++i, currentFunction++)
{
// Is this iteration the start of a sequence?
if ((currentFunction % numFunctions) == 0)
+2 -2
View File
@@ -210,7 +210,7 @@ GetRecommendations(const size_t numRecs,
// time and we don't want to repeat the initialization process in each loop.
InterpolationPolicy interpolation(cleanedData);
for (size_t i = 0; i < users.n_elem; i++)
for (size_t i = 0; i < users.n_elem; ++i)
{
// First, calculate the weighted sum of neighborhood values.
arma::vec ratings;
@@ -355,7 +355,7 @@ Predict(const arma::Mat<size_t>& combinations,
// Calculate interpolation weights.
InterpolationPolicy interpolation(cleanedData);
for (size_t i = 0; i < users.n_elem; i++)
for (size_t i = 0; i < users.n_elem; ++i)
{
interpolation.GetWeights(weights.col(i), decomposition, users[i],
neighborhood.col(i), similarities.col(i), cleanedData);
@@ -138,7 +138,7 @@ class BatchSVDPolicy
// Temporarily store feature vector of queried users.
arma::mat query(stretchedH.n_rows, users.n_elem);
// Select feature vectors of queried users.
for (size_t i = 0; i < users.n_elem; i++)
for (size_t i = 0; i < users.n_elem; ++i)
query.col(i) = stretchedH.col(users(i));
NeighborSearchPolicy neighborSearch(stretchedH);
@@ -128,7 +128,7 @@ class BiasSVDPolicy
// Temporarily store feature vector of queried users.
arma::mat query(h.n_rows, users.n_elem);
// Select feature vectors of queried users.
for (size_t i = 0; i < users.n_elem; i++)
for (size_t i = 0; i < users.n_elem; ++i)
query.col(i) = h.col(users(i));
NeighborSearchPolicy neighborSearch(h);
@@ -135,7 +135,7 @@ class NMFPolicy
// Temporarily store feature vector of queried users.
arma::mat query(stretchedH.n_rows, users.n_elem);
// Select feature vectors of queried users.
for (size_t i = 0; i < users.n_elem; i++)
for (size_t i = 0; i < users.n_elem; ++i)
query.col(i) = stretchedH.col(users(i));
NeighborSearchPolicy neighborSearch(stretchedH);
@@ -144,7 +144,7 @@ class RandomizedSVDPolicy
// Temporarily store feature vector of queried users.
arma::mat query(stretchedH.n_rows, users.n_elem);
// Select feature vectors of queried users.
for (size_t i = 0; i < users.n_elem; i++)
for (size_t i = 0; i < users.n_elem; ++i)
query.col(i) = stretchedH.col(users(i));
NeighborSearchPolicy neighborSearch(stretchedH);
@@ -131,7 +131,7 @@ class RegSVDPolicy
// Temporarily store feature vector of queried users.
arma::mat query(stretchedH.n_rows, users.n_elem);
// Select feature vectors of queried users.
for (size_t i = 0; i < users.n_elem; i++)
for (size_t i = 0; i < users.n_elem; ++i)
query.col(i) = stretchedH.col(users(i));
NeighborSearchPolicy neighborSearch(stretchedH);
@@ -141,7 +141,7 @@ class SVDCompletePolicy
// Temporarily store feature vector of queried users.
arma::mat query(stretchedH.n_rows, users.n_elem);
// Select feature vectors of queried users.
for (size_t i = 0; i < users.n_elem; i++)
for (size_t i = 0; i < users.n_elem; ++i)
query.col(i) = stretchedH.col(users(i));
NeighborSearchPolicy neighborSearch(stretchedH);
@@ -140,7 +140,7 @@ class SVDIncompletePolicy
// Temporarily store feature vector of queried users.
arma::mat query(stretchedH.n_rows, users.n_elem);
// Select feature vectors of queried users.
for (size_t i = 0; i < users.n_elem; i++)
for (size_t i = 0; i < users.n_elem; ++i)
query.col(i) = stretchedH.col(users(i));
NeighborSearchPolicy neighborSearch(stretchedH);
@@ -163,7 +163,7 @@ class SVDPlusPlusPolicy
// Temporarily store feature vector of queried users.
arma::mat query(h.n_rows, users.n_elem);
// Select feature vectors of queried users.
for (size_t i = 0; i < users.n_elem; i++)
for (size_t i = 0; i < users.n_elem; ++i)
query.col(i) = h.col(users(i));
NeighborSearchPolicy neighborSearch(h);
@@ -126,11 +126,11 @@ class RegressionInterpolation
return;
}
for (size_t i = 0; i < neighborNum; i++)
for (size_t i = 0; i < neighborNum; ++i)
{
// Calculate coefficient.
arma::vec iPrediction;
for (size_t j = i; j < neighborNum; j++)
for (size_t j = i; j < neighborNum; ++j)
{
if (a(neighbors(i), neighbors(j)) != 0)
{

Some files were not shown because too many files have changed in this diff Show More