Improvements and Speedups
This commit is contained in:
@@ -51,7 +51,8 @@ LRSDPFunction<SDPType>::LRSDPFunction(const size_t numSparseConstraints,
|
||||
}
|
||||
|
||||
template <typename SDPType>
|
||||
double LRSDPFunction<SDPType>::Evaluate(const arma::mat& coordinates) const
|
||||
double LRSDPFunction<SDPType>::Evaluate(const arma::mat& /* coordinates */)
|
||||
const
|
||||
{
|
||||
// Note: We don't require to update the R*R^T matrix here as the current
|
||||
// function is only used by AugLagrangian, which do not update the coordinates
|
||||
|
||||
@@ -21,8 +21,8 @@ namespace ann /** Artificial Neural Network. */ {
|
||||
|
||||
/**
|
||||
* Computes the two-dimensional convolution through fft. This class allows
|
||||
* specification of the type of the border type. The convolution can be compute
|
||||
* with the valid border type of the full border type (default).
|
||||
* specification of the type of the border type. The convolution can be
|
||||
* computed with the valid border type of the full border type (default).
|
||||
*
|
||||
* FullConvolution: returns the full two-dimensional convolution.
|
||||
* ValidConvolution: returns only those parts of the convolution that are
|
||||
@@ -40,12 +40,12 @@ class FFTConvolution
|
||||
/*
|
||||
* Perform a convolution through fft (valid mode). This method only supports
|
||||
* input which is even on the last dimension. In case of an odd input width, a
|
||||
* user can manually pad the imput or specify the padLastDim parameter which
|
||||
* user can manually pad the input or specify the padLastDim parameter which
|
||||
* takes care of the padding. The filter instead can have any size. When using
|
||||
* the valid mode the filters has to be smaller than the input.
|
||||
* the valid mode the filter has to be smaller than the input.
|
||||
*
|
||||
* @param input Input used to perform the convolution.
|
||||
* @param filter Filter used to perform the conolution.
|
||||
* @param filter Filter used to perform the convolution.
|
||||
* @param output Output data that contains the results of the convolution.
|
||||
*/
|
||||
template<typename eT, typename Border = BorderMode>
|
||||
@@ -64,23 +64,23 @@ class FFTConvolution
|
||||
// Pad filter and input to the output shape.
|
||||
filterPadded.resize(inputPadded.n_rows, inputPadded.n_cols);
|
||||
|
||||
output = arma::real(ifft2(arma::fft2(inputPadded) % arma::fft2(
|
||||
arma::Mat<eT> temp = arma::real(ifft2(arma::fft2(inputPadded) % arma::fft2(
|
||||
filterPadded)));
|
||||
|
||||
// Extract the region of interest. We don't need to handle the padLastDim in
|
||||
// a special way we just cut it out from the output matrix.
|
||||
output = output.submat(filter.n_rows - 1, filter.n_cols - 1,
|
||||
output = temp.submat(filter.n_rows - 1, filter.n_cols - 1,
|
||||
input.n_rows - 1, input.n_cols - 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Perform a convolution through fft (full mode). This method only supports
|
||||
* input which is even on the last dimension. In case of an odd input width, a
|
||||
* user can manually pad the imput or specify the padLastDim parameter which
|
||||
* user can manually pad the input or specify the padLastDim parameter which
|
||||
* takes care of the padding. The filter instead can have any size.
|
||||
*
|
||||
* @param input Input used to perform the convolution.
|
||||
* @param filter Filter used to perform the conolution.
|
||||
* @param filter Filter used to perform the convolution.
|
||||
* @param output Output data that contains the results of the convolution.
|
||||
*/
|
||||
template<typename eT, typename Border = BorderMode>
|
||||
@@ -110,12 +110,12 @@ class FFTConvolution
|
||||
filterPadded.resize(outputRows, outputCols);
|
||||
|
||||
// Perform FFT and IFFT
|
||||
output = arma::real(ifft2(arma::fft2(inputPadded) % arma::fft2(
|
||||
arma::Mat<eT> temp = arma::real(ifft2(arma::fft2(inputPadded) % arma::fft2(
|
||||
filterPadded)));
|
||||
|
||||
// Extract the region of interest. We don't need to handle the padLastDim
|
||||
// parameter in a special way we just cut it out from the output matrix.
|
||||
output = output.submat(filter.n_rows - 1, filter.n_cols - 1,
|
||||
output = temp.submat(filter.n_rows - 1, filter.n_cols - 1,
|
||||
2 * (filter.n_rows - 1) + input.n_rows - 1,
|
||||
2 * (filter.n_cols - 1) + input.n_cols - 1);
|
||||
}
|
||||
@@ -123,12 +123,12 @@ class FFTConvolution
|
||||
/*
|
||||
* Perform a convolution through fft using 3rd order tensors. This method only
|
||||
* supports input which is even on the last dimension. In case of an odd input
|
||||
* width, a user can manually pad the imput or specify the padLastDim
|
||||
* width, a user can manually pad the input or specify the padLastDim
|
||||
* parameter which takes care of the padding. The filter instead can have any
|
||||
* size.
|
||||
*
|
||||
* @param input Input used to perform the convolution.
|
||||
* @param filter Filter used to perform the conolution.
|
||||
* @param filter Filter used to perform the convolution.
|
||||
* @param output Output data that contains the results of the convolution.
|
||||
*/
|
||||
template<typename eT>
|
||||
@@ -147,8 +147,7 @@ class FFTConvolution
|
||||
for (size_t i = 1; i < input.n_slices; i++)
|
||||
{
|
||||
FFTConvolution<BorderMode>::Convolution(input.slice(i), filter.slice(i),
|
||||
convOutput);
|
||||
output.slice(i) = convOutput;
|
||||
output.slice(i));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,11 +155,11 @@ class FFTConvolution
|
||||
* Perform a convolution through fft using dense matrix as input and a 3rd
|
||||
* order tensors as filter and output. This method only supports input which
|
||||
* is even on the last dimension. In case of an odd input width, a user can
|
||||
* manually pad the imput or specify the padLastDim parameter which takes care
|
||||
* manually pad the input or specify the padLastDim parameter which takes care
|
||||
* of the padding. The filter instead can have any size.
|
||||
*
|
||||
* @param input Input used to perform the convolution.
|
||||
* @param filter Filter used to perform the conolution.
|
||||
* @param filter Filter used to perform the convolution.
|
||||
* @param output Output data that contains the results of the convolution.
|
||||
*/
|
||||
template<typename eT>
|
||||
@@ -179,8 +178,7 @@ class FFTConvolution
|
||||
for (size_t i = 1; i < filter.n_slices; i++)
|
||||
{
|
||||
FFTConvolution<BorderMode>::Convolution(input, filter.slice(i),
|
||||
convOutput);
|
||||
output.slice(i) = convOutput;
|
||||
output.slice(i));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,7 +187,7 @@ class FFTConvolution
|
||||
* dense matrix as filter.
|
||||
*
|
||||
* @param input Input used to perform the convolution.
|
||||
* @param filter Filter used to perform the conolution.
|
||||
* @param filter Filter used to perform the convolution.
|
||||
* @param output Output data that contains the results of the convolution.
|
||||
*/
|
||||
template<typename eT>
|
||||
@@ -208,8 +206,7 @@ class FFTConvolution
|
||||
for (size_t i = 1; i < input.n_slices; i++)
|
||||
{
|
||||
FFTConvolution<BorderMode>::Convolution(input.slice(i), filter,
|
||||
convOutput);
|
||||
output.slice(i) = convOutput;
|
||||
output.slice(i));
|
||||
}
|
||||
}
|
||||
}; // class FFTConvolution
|
||||
|
||||
@@ -39,7 +39,7 @@ class NaiveConvolution
|
||||
* Perform a convolution (valid mode).
|
||||
*
|
||||
* @param input Input used to perform the convolution.
|
||||
* @param filter Filter used to perform the conolution.
|
||||
* @param filter Filter used to perform the convolution.
|
||||
* @param output Output data that contains the results of the convolution.
|
||||
* @param dW Stride of filter application in the x direction.
|
||||
* @param dH Stride of filter application in the y direction.
|
||||
@@ -79,7 +79,7 @@ class NaiveConvolution
|
||||
* Perform a convolution (full mode).
|
||||
*
|
||||
* @param input Input used to perform the convolution.
|
||||
* @param filter Filter used to perform the conolution.
|
||||
* @param filter Filter used to perform the convolution.
|
||||
* @param output Output data that contains the results of the convolution.
|
||||
* @param dW Stride of filter application in the x direction.
|
||||
* @param dH Stride of filter application in the y direction.
|
||||
@@ -111,7 +111,7 @@ class NaiveConvolution
|
||||
* Perform a convolution using 3rd order tensors.
|
||||
*
|
||||
* @param input Input used to perform the convolution.
|
||||
* @param filter Filter used to perform the conolution.
|
||||
* @param filter Filter used to perform the convolution.
|
||||
* @param output Output data that contains the results of the convolution.
|
||||
* @param dW Stride of filter application in the x direction.
|
||||
* @param dH Stride of filter application in the y direction.
|
||||
@@ -143,7 +143,7 @@ class NaiveConvolution
|
||||
* as filter and output.
|
||||
*
|
||||
* @param input Input used to perform the convolution.
|
||||
* @param filter Filter used to perform the conolution.
|
||||
* @param filter Filter used to perform the convolution.
|
||||
* @param output Output data that contains the results of the convolution.
|
||||
* @param dW Stride of filter application in the x direction.
|
||||
* @param dH Stride of filter application in the y direction.
|
||||
@@ -175,7 +175,7 @@ class NaiveConvolution
|
||||
* dense matrix as filter.
|
||||
*
|
||||
* @param input Input used to perform the convolution.
|
||||
* @param filter Filter used to perform the conolution.
|
||||
* @param filter Filter used to perform the convolution.
|
||||
* @param output Output data that contains the results of the convolution.
|
||||
* @param dW Stride of filter application in the x direction.
|
||||
* @param dH Stride of filter application in the y direction.
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* @author Marcus Edel
|
||||
*
|
||||
* Implementation of the convolution using the singular value decomposition to
|
||||
* speeded up the computation.
|
||||
* speed up the computation.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
@@ -24,7 +24,7 @@ namespace ann /** Artificial Neural Network. */ {
|
||||
/**
|
||||
* Computes the two-dimensional convolution using singular value decomposition.
|
||||
* This class allows specification of the type of the border type. The
|
||||
* convolution can be compute with the valid border type of the full border
|
||||
* convolution can be computed with the valid border type of the full border
|
||||
* type (default).
|
||||
*
|
||||
* FullConvolution: returns the full two-dimensional convolution.
|
||||
@@ -87,13 +87,13 @@ class SVDConvolution
|
||||
NaiveConvolution<BorderMode>::Convolution(subOutput, U.unsafe_col(0),
|
||||
output);
|
||||
|
||||
arma::Mat<eT> temp;
|
||||
for (size_t r = 1; r < rank; r++)
|
||||
{
|
||||
subFilter = V.unsafe_col(r) * s(r);
|
||||
NaiveConvolution<BorderMode>::Convolution(input, subFilter,
|
||||
subOutput);
|
||||
|
||||
arma::Mat<eT> temp;
|
||||
subOutput = subOutput.t();
|
||||
NaiveConvolution<BorderMode>::Convolution(subOutput, U.unsafe_col(r),
|
||||
temp);
|
||||
@@ -134,8 +134,7 @@ class SVDConvolution
|
||||
for (size_t i = 1; i < input.n_slices; i++)
|
||||
{
|
||||
SVDConvolution<BorderMode>::Convolution(input.slice(i), filter.slice(i),
|
||||
convOutput);
|
||||
output.slice(i) = convOutput;
|
||||
output.slice(i));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,8 +163,7 @@ class SVDConvolution
|
||||
for (size_t i = 1; i < filter.n_slices; i++)
|
||||
{
|
||||
SVDConvolution<BorderMode>::Convolution(input, filter.slice(i),
|
||||
convOutput);
|
||||
output.slice(i) = convOutput;
|
||||
output.slice(i));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,8 +192,7 @@ class SVDConvolution
|
||||
for (size_t i = 1; i < input.n_slices; i++)
|
||||
{
|
||||
SVDConvolution<BorderMode>::Convolution(input.slice(i), filter,
|
||||
convOutput);
|
||||
output.slice(i) = convOutput;
|
||||
output.slice(i));
|
||||
}
|
||||
}
|
||||
}; // class SVDConvolution
|
||||
|
||||
@@ -171,8 +171,8 @@ void Convolution<
|
||||
>::Backward(
|
||||
const arma::Mat<eT>&& /* input */, arma::Mat<eT>&& gy, arma::Mat<eT>&& g)
|
||||
{
|
||||
arma::cube mappedError = arma::cube(gy.memptr(),
|
||||
outputWidth, outputHeight, outSize);
|
||||
arma::cube mappedError(gy.memptr(), outputWidth, outputHeight, outSize,
|
||||
false, false);
|
||||
gTemp = arma::zeros<arma::Cube<eT> >(inputTemp.n_rows,
|
||||
inputTemp.n_cols, inputTemp.n_slices);
|
||||
|
||||
@@ -265,12 +265,10 @@ void Convolution<
|
||||
{
|
||||
for (size_t i = 0; i < output.n_slices; i++)
|
||||
{
|
||||
arma::mat subOutput = output.slice(i);
|
||||
|
||||
gradientTemp.slice(s) += subOutput.submat(subOutput.n_rows / 2,
|
||||
subOutput.n_cols / 2,
|
||||
subOutput.n_rows / 2 + gradientTemp.n_rows - 1,
|
||||
subOutput.n_cols / 2 + gradientTemp.n_cols - 1);
|
||||
gradientTemp.slice(s) += output.slice(i).submat(output.n_rows / 2,
|
||||
output.n_cols / 2,
|
||||
output.n_rows / 2 + gradientTemp.n_rows - 1,
|
||||
output.n_cols / 2 + gradientTemp.n_cols - 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -414,7 +414,7 @@ void DecisionTree<FitnessFunction,
|
||||
// Pass off work to the Train() method.
|
||||
arma::rowvec weights; // Fake weights, not used.
|
||||
Train<false>(tmpData, 0, tmpData.n_cols, tmpLabels, numClasses, weights,
|
||||
minimumLeafSize);
|
||||
minimumLeafSize, minimumGainSplit);
|
||||
}
|
||||
|
||||
//! Train on the given weighted data.
|
||||
|
||||
@@ -29,7 +29,7 @@ BOOST_AUTO_TEST_SUITE(ConvolutionTest);
|
||||
* Implementation of the convolution function test.
|
||||
*
|
||||
* @param input Input used to perform the convolution.
|
||||
* @param filter Filter used to perform the conolution.
|
||||
* @param filter Filter used to perform the convolution.
|
||||
* @param output The reference output data that contains the results of the
|
||||
* convolution.
|
||||
*
|
||||
@@ -43,7 +43,7 @@ void Convolution2DMethodTest(const arma::mat input,
|
||||
arma::mat convOutput;
|
||||
ConvolutionFunction::Convolution(input, filter, convOutput);
|
||||
|
||||
// Check the outut dimension.
|
||||
// Check the output dimension.
|
||||
bool b = (convOutput.n_rows == output.n_rows) &&
|
||||
(convOutput.n_cols == output.n_cols);
|
||||
BOOST_REQUIRE_EQUAL(b, 1);
|
||||
@@ -59,7 +59,7 @@ void Convolution2DMethodTest(const arma::mat input,
|
||||
* Implementation of the convolution function test using 3rd order tensors.
|
||||
*
|
||||
* @param input Input used to perform the convolution.
|
||||
* @param filter Filter used to perform the conolution.
|
||||
* @param filter Filter used to perform the convolution.
|
||||
* @param output The reference output data that contains the results of the
|
||||
* convolution.
|
||||
*
|
||||
@@ -91,7 +91,7 @@ void Convolution3DMethodTest(const arma::cube input,
|
||||
* and a 3rd order tensors as filter and output (batch modus).
|
||||
*
|
||||
* @param input Input used to perform the convolution.
|
||||
* @param filter Filter used to perform the conolution.
|
||||
* @param filter Filter used to perform the convolution.
|
||||
* @param output The reference output data that contains the results of the
|
||||
* convolution.
|
||||
*
|
||||
@@ -146,7 +146,7 @@ BOOST_AUTO_TEST_CASE(ValidConvolution2DTest)
|
||||
output);
|
||||
|
||||
// Perform the convolution using singular value decomposition to
|
||||
// speeded up the computation.
|
||||
// speed up the computation.
|
||||
Convolution2DMethodTest<SVDConvolution<ValidConvolution> >(input, filter,
|
||||
output);
|
||||
}
|
||||
@@ -183,7 +183,7 @@ BOOST_AUTO_TEST_CASE(FullConvolution2DTest)
|
||||
output);
|
||||
|
||||
// Perform the convolution using singular value decomposition to
|
||||
// speeded up the computation.
|
||||
// speed up the computation.
|
||||
Convolution2DMethodTest<SVDConvolution<FullConvolution> >(input, filter,
|
||||
output);
|
||||
}
|
||||
@@ -228,7 +228,7 @@ BOOST_AUTO_TEST_CASE(ValidConvolution3DTest)
|
||||
filterCube, outputCube);
|
||||
|
||||
// Perform the convolution using using the singular value decomposition to
|
||||
// speeded up the computation.
|
||||
// speed up the computation.
|
||||
Convolution3DMethodTest<SVDConvolution<ValidConvolution> >(inputCube,
|
||||
filterCube, outputCube);
|
||||
}
|
||||
@@ -277,7 +277,7 @@ BOOST_AUTO_TEST_CASE(FullConvolution3DTest)
|
||||
filterCube, outputCube);
|
||||
|
||||
// Perform the convolution using using the singular value decomposition to
|
||||
// speeded up the computation.
|
||||
// speed up the computation.
|
||||
Convolution3DMethodTest<SVDConvolution<FullConvolution> >(inputCube,
|
||||
filterCube, outputCube);
|
||||
}
|
||||
@@ -319,7 +319,7 @@ BOOST_AUTO_TEST_CASE(ValidConvolutionBatchTest)
|
||||
filterCube, outputCube);
|
||||
|
||||
// Perform the convolution using using the singular value decomposition to
|
||||
// speeded up the computation.
|
||||
// speed up the computation.
|
||||
ConvolutionMethodBatchTest<SVDConvolution<ValidConvolution> >(input,
|
||||
filterCube, outputCube);
|
||||
}
|
||||
@@ -365,7 +365,7 @@ BOOST_AUTO_TEST_CASE(FullConvolutionBatchTest)
|
||||
filterCube, outputCube);
|
||||
|
||||
// Perform the convolution using using the singular value decomposition to
|
||||
// speeded up the computation.
|
||||
// speed up the computation.
|
||||
ConvolutionMethodBatchTest<SVDConvolution<FullConvolution> >(input,
|
||||
filterCube, outputCube);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user