diff --git a/scripts/release-mlpack.sh b/scripts/release-mlpack.sh new file mode 100755 index 0000000000..5997ace895 --- /dev/null +++ b/scripts/release-mlpack.sh @@ -0,0 +1,221 @@ +#!/usr/bin/env bash +# +# Release a new version of mlpack. +# +# Usage: release-mlpack.sh X Y Z +# +# where X is the major version, Y is the minor version, and Z is the patch +# version. Run this from the root of the repository. +# +# Make sure HISTORY.md is updated first! +set +e + +if [ "$#" -ne "4" ]; +then + echo "Usage: mlpack-release.sh "; + exit 1; +fi + +# First, check for any unlicensed files. +output=$( + for i in $(find src/ -iname '*.[hc]pp'); + do + echo -n $i": "; + cat $i | grep 'mlpack is free software;' | wc -l; + done |\ + grep -v ': 1' |\ + grep -v 'arma_extend' |\ + grep -v 'boost_backport' |\ + grep -v 'arma_config.hpp' |\ + grep -v 'gitversion.hpp' |\ + grep -v 'CLI11.hpp' |\ + grep -v 'bindings/R/mlpack/src/boost/serialization' |\ + grep -v 'tests/catch.hpp'); +lines=`echo $output | grep -v '^[ ]*$' | wc -l`; + +if [ "0$lines" -gt "0" ]; +then + echo "Unlicensed files found! Aborting release."; + echo "$output"; + exit 1; +fi + +# Now, check that there are no local changes. +lines=`git diff | wc -l | sed -e 's/^\s*//g'`; +if [ "$lines" != "0" ]; then + echo "git diff returned a nonzero result!"; + echo ""; + git diff; + exit 1; +fi + +# Next, make sure the origin is right. +dest_remote_name=`git remote -v |\ + grep "mlpack/mlpack (fetch)" |\ + head -1 |\ + awk -F' ' '{ print $1 }'`; + +if [ "a$dest_remote_name" == "a" ]; then + echo "No git remote found for https://github.com/mlpack/mlpack!"; + echo "Make sure that you've got the ensmallen repository as a remote, and" \ + "that the master branch from that remote is checked out."; + echo "You can do this with a fresh repository via \`git clone" \ + "https://github.com/mlpack/mlpack\`."; + exit 1; +fi + +# Also check that we're on the master branch, from the correct origin. +current_branch=`git branch --no-color | grep '^\* ' | awk -F' ' '{ print $2 }'`; +current_origin=`git rev-parse --abbrev-ref --symbolic-full-name @{u} |\ + awk -F'/' '{ print $1 }'`; +if [ "a$current_branch" != "amaster" ]; then + echo "Current branch is $current_branch."; + echo "This script has to be run from the master branch."; + exit 1; +elif [ "a$current_origin" != "a$dest_remote_name" ]; then + echo "Current branch does not track from remote mlpack repository!"; + echo "Instead, it tracks from $current_origin/master."; + echo "Make sure to check out a branch that tracks $dest_remote_name/master."; + exit 1; +fi + +# Make sure `hub` is installed. +hub_output="`which hub`" || true; +if [ "a$hub_output" == "a" ]; then + echo "The Hub command-line tool must be installed for this script to run" \ + "successfully."; + echo "See https://hub.github.com for more details and installation" \ + "instructions."; + echo ""; + echo "(apt-get install hub on Debian and Ubuntu)"; + echo "(brew install hub via Homebrew)"; + exit 1; +fi + +# Check git remotes: we need to make sure we have a fork to push to. +github_user=$1; +remote_name`git remote -v |\ + grep "$github_user/mlpack (push)" |\ + head -1 |\ + awk -F' ' '{ print $1 }'`; +if [ "a$remote_name" == "a" ]; then + echo "No git remote found for $github_user/mlpack!"; + echo "Adding remote '$github_user'."; + git remote add $github_user https://github.com/$github_user/mlpack; + remote_name="$github_user"; +fi +git fetch $github_user; + +# Make sure everything is up to date. +git pull; + +# Make updates to files that will be needed for the release. +MAJOR="$2"; +MINOR="$3"; +PATCH="$4"; + +# Update version. +sed --in-place -E 's/PROJECT_NUMBER([ \t]*)= .*$/PROJECT_NUMBER\1= '$MAJOR'.'$MINOR'.'$PATCH'/' \ + Doxyfile; +sed --in-place 's/MLPACK_VERSION_MAJOR [0-9]*$/MLPACK_VERSION_MAJOR '$MAJOR'/' \ + src/mlpack/core/util/version.hpp; +sed --in-place 's/MLPACK_VERSION_MINOR [0-9]*$/MLPACK_VERSION_MINOR '$MINOR'/' \ + src/mlpack/core/util/version.hpp; +sed --in-place 's/MLPACK_VERSION_PATCH [0-9]*$/MLPACK_VERSION_PATCH '$PATCH'/' \ + src/mlpack/core/util/version.hpp; +sed --in-place 's/ VERSION [0-9]*\.[0-9]*/ VERSION '$MAJOR'.'$MINOR'/' \ + src/mlpack/CMakeLists.txt; + +sed --in-place 's/mlpack-[0-9]\.[0-9]\.[0-9]/mlpack-'$MAJOR'.'$MINOR'.'$PATCH'/g' \ + doc/guide/build.hpp; +sed --in-place 's/mlpack-[0-9]\.[0-9]\.[0-9]/mlpack-'$MAJOR'.'$MINOR'.'$PATCH'/g' \ + doc/guide/python_quickstart.hpp; +sed --in-place 's/mlpack-[0-9]\.[0-9]\.[0-9]/mlpack-'$MAJOR'.'$MINOR'.'$PATCH'/g' \ + doc/guide/sample_ml_app.hpp; +sed --in-place 's/mlpack-[0-9]\.[0-9]\.[0-9]/mlpack-'$MAJOR'.'$MINOR'.'$PATCH'/g' \ + doc/examples/sample-ml-app/sample-ml-app/sample-ml-app.vcxproj; + +sed --in-place 's/mlpack-[0-9]\.[0-9]\.[0-9]/mlpack-'$MAJOR'.'$MINOR'.'$PATCH'/g' \ + README.md; +sed --in-place 's/([0-9]\.[0-9]\.[0-9])/('$MAJOR'.'$MINOR'.'$PATCH')/g' \ + README.md; +sed --in-place 's/mlpack [0-9]\.[0-9]\.[0-9]/mlpack '$MAJOR'.'$MINOR'.'$PATCH'/g' \ + README.md; + +sed --in-place 's/### mlpack ?[.]?[.]?/### mlpack '$MAJOR'.'$MINOR'.'$PATCH'/g' HISTORY.md; +year=`date +%Y`; +month=`date +%m`; +day=`date +%d`; +sed --in-place 's/###### ????-??-??/###### '$year'-'$month'-'$day'/g' \ + HISTORY.md; + +# Get the latest release of ensmallen. +git clone https://github.com/mlpack/ensmallen /tmp/ensmallen; +cd /tmp/ensmallen; +ens_ver=`git describe --tags $(git rev-list --tags --max-count=1)`; +echo "Latest version of ensmallen: $ens_ver" +cd -; +sed --in-place "s/ensmallen-latest.tar.gz/ensmallen-$ens_ver.tar.gz/" CMakeLists.txt; +rm -rf /tmp/ensmallen; + +# Make these changes on a release branch. +git checkout -b release-$MAJOR.$MINOR.$PATCH; + +git add Doxyfile src/mlpack/core/util/version.hpp src/mlpack/CMakeLists.txt \ + doc/guide/build.hpp doc/guide/python_quickstart.hpp \ + doc/guide/sample_ml_app.hpp \ + doc/examples/sample-ml-app/sample-ml-app/sample-ml-app.vcxproj \ + CMakeLists.txt \ + README.md \ + HISTORY.md; + +git commit -m "Update and release version $MAJOR.$MINOR.$PATCH."; + +changelog_str=`cat HISTORY.md |\ + awk '/^### /{f=0} /^### mlpack '"$MAJOR"'.'"$MINOR"'.'"$PATCH"'/{f=1} f{print}' |\ + grep -v '^#' |\ + tr '\n' '!' |\ + sed -e 's/! [ ]*/ /g' |\ + tr '!' '\n'`; +echo "Changelog string:" +echo "$changelog_str" + +# Update version again and add a new block for HISTORY.md. +sed --in-place 's/MLPACK_VERSION_PATCH [0-9]*$/MLPACK_VERSION_PATCH '$(($PATCH + 1))'/' \ + src/mlpack/core/util/version.hpp; +sed --in-place 's/ensmallen-'$ens_ver'.tar.gz/ensmallen-latest.tar.gz/' CMakeLists.txt; + +echo "### mlpack ?.?.?" > HISTORY.md.new; +echo "###### ????-??-??" >> HISTORY.md.new; +echo "" >> HISTORY.md.new; +cat HISTORY.md >> HISTORY.md.new; +mv HISTORY.md.new HISTORY.md; + +git add HISTORY.md; +git add src/mlpack/core/util/version.hpp CMakeLists.txt; + +git commit -m "Add new block for next release to HISTORY.md."; + +# Push to new branch. +git push --set-upstream $github_user release-$MAJOR.$MINOR.$PATCH; + +# Next, we have to actually open the PR for the release. +hub pull-request \ + -b mlpack:master \ + -h $github_user:release-$MAJOR.$MINOR.$PATCH \ + -m "Release version $MAJOR.$MINOR.$PATCH" \ + -m "This automatically-generated pull request adds the commits necessary to +make the $MAJOR.$MINOR.$PATCH release." \ + -m "Once the PR is merged, mlpack-bot will tag the release as HEAD~1 (so +that it doesn't include the new HISTORY block) and publish it." \ + -m "Or, well, hopefully that will happen someday." \ + -m "When you merge this PR, be sure to merge it using a *rebase*." \ + -m "### Changelog" \ + -m "$changelog_str" \ + -l "t: release" + +echo ""; +echo "Switching back to 'master' branch."; +echo "If you want to access the release branch again, use \`git checkout " \ + "release-$MAJOR.$MINOR.$PATCH\`."; +echo 0; diff --git a/scripts/update-website-after-release.sh b/scripts/update-website-after-release.sh new file mode 100755 index 0000000000..e80ad8694f --- /dev/null +++ b/scripts/update-website-after-release.sh @@ -0,0 +1,65 @@ +#!/usr/bin/env bash +# +# This script is used to update the website after an mlpack release is made. +# Push access to the mlpack.org website repository is needed. Generally, this +# script will be run by mlpack-bot, so it never needs to be run by hand. +# +# Usage: update-website-after-release.sh + +MAJOR=$1; +MINOR=$2; +PATCH=$3; + +# Make sure that the mlpack repository exists. +dest_remote_name=`git remote -v |\ + grep "mlpack/mlpack (fetch)" |\ + head -1 |\ + awk -F' ' '{ print $1 }'`; + +if [ "a$dest_remote_name" == "a" ]; then + echo "No git remote found for mlpack/mlpack!"; + echo "Make sure that you've got the mlpack repository as a remote, and" \ + "that the master branch from that remote is checked out."; + echo "You can do this with a fresh repository via \`git clone" \ + "https://github.com/mlpack/mlpack\`."; + exit 1; +fi + +# Update the checked out repository, so that we can get the tags. +git fetch $dest_remote_name; + +# Check out a copy of the ensmallen.org repository. +git clone git@github.com:mlpack/mlpack.org /tmp/mlpack.org/; + +# Create the release file. +git archive --prefix=mlpack-$MAJOR.$MINOR.$PATCH/ $MAJOR.$MINOR.$PATCH |\ + gzip > /tmp/mlpack.org/files/mlpack-$MAJOR.$MINOR.$PATCH.tar.gz; + +# Now update the website. +wd=`pwd`; +cd /tmp/mlpack.org/; + +# These may be specific to the old website. +sed --in-place 's/[0-9]\.[0-9]\.[0-9]/'$MAJOR'.'$MINOR'.'$PATCH'/g' index.md; +sed --in-place 's/[0-9]\.[0-9]\.[0-9]/'$MAJOR'.'$MINOR'.'$PATCH'/g' docs.md; +sed --in-place 's/[0-9]\.[0-9]\.[0-9]/'$MAJOR'.'$MINOR'.'$PATCH'/g' getstarted.md; +sed --in-place 's/[0-9]\.[0-9]\.[0-9]/'$MAJOR'.'$MINOR'.'$PATCH'/g' community.md; +git add index.md docs.md getstarted.md community.md; + +# These may be specific to the new website. +sed --in-place 's/mlpack-[0-9]\.[0-9]\.[0-9]/mlpack-'$MAJOR'.'$MINOR'.'$PATCH'/g' html/index.html; +sed --in-place 's/Version [0-9]\.[0-9]\.[0-9]/Version '$MAJOR'.'$MINOR'.'$PATCH'/g' html/index.html; +sed --in-place 's/[0-9]\.[0-9]\.[0-9]/'$MAJOR'.'$MINOR'.'$PATCH'/g' html/getstarted.html; +sed --in-place 's/[0-9]\.[0-9]\.[0-9]/'$MAJOR'.'$MINOR'.'$PATCH'/g' html/config/install.md; +git add html/index.html html/getstarted.html html/config/install.md; + +git commit -m "Update links to latest stable version."; + +git add files/mlpack-$MAJOR.$MINOR.$PATCH.tar.gz; +git commit -m "Release version $MAJOR.$MINOR.$PATCH."; + +# Finally, push, and we're done. +git push origin; +cd $wd; + +rm -rf /tmp/mlpack.org; diff --git a/src/mlpack/bindings/markdown/print_docs.cpp b/src/mlpack/bindings/markdown/print_docs.cpp index 10805e8209..45b9807afa 100644 --- a/src/mlpack/bindings/markdown/print_docs.cpp +++ b/src/mlpack/bindings/markdown/print_docs.cpp @@ -180,7 +180,7 @@ void PrintDocs(const std::string& bindingName, } if (hasOutputOptions) - { + { // Next, iterate through the list of output options. cout << "### Output options" << endl; cout << endl; diff --git a/src/mlpack/core/cereal/array_wrapper.hpp b/src/mlpack/core/cereal/array_wrapper.hpp index 05a675277f..c696f5b727 100644 --- a/src/mlpack/core/cereal/array_wrapper.hpp +++ b/src/mlpack/core/cereal/array_wrapper.hpp @@ -21,7 +21,7 @@ namespace cereal { -/** +/** * This class is used as a shim for cereal to be able to serialize a raw pointer array. */ template @@ -84,7 +84,7 @@ ArrayWrapper make_array(T*& t, S& s) * @param T C Style array. * @param S Size of the array. */ -#define CEREAL_POINTER_ARRAY(T,S) cereal::make_array(T, S) +#define CEREAL_POINTER_ARRAY(T, S) cereal::make_array(T, S) } // namespace cereal diff --git a/src/mlpack/core/cereal/is_loading.hpp b/src/mlpack/core/cereal/is_loading.hpp index d075c3d303..085358b2f4 100644 --- a/src/mlpack/core/cereal/is_loading.hpp +++ b/src/mlpack/core/cereal/is_loading.hpp @@ -5,7 +5,7 @@ * Implementation of is_loading function. * * This implementation provides backward compatibilty with older - * version of cereal that does not have Archive::is_loading struct. + * version of cereal that does not have Archive::is_loading struct. * * 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 @@ -28,11 +28,12 @@ struct is_cereal_archive { // Archive::is_loading is not implemented yet, so we can use std::is_same<> // to check if it is a loading archive. - constexpr static bool value = std::is_same::value || -//#if (BINDING_TYPE != BINDING_TYPE_R) - std::is_same::value || -//#endif - std::is_same::value; + constexpr static bool value = std::is_same::value || +// #if (BINDING_TYPE != BINDING_TYPE_R) + std::is_same::value || +// #endif + std::is_same::value; }; template @@ -40,7 +41,7 @@ bool is_loading( const typename std::enable_if< is_cereal_archive::value, Archive>::type* = 0) { - return true; + return true; } template diff --git a/src/mlpack/core/cereal/is_saving.hpp b/src/mlpack/core/cereal/is_saving.hpp index 147668853f..e54362913f 100644 --- a/src/mlpack/core/cereal/is_saving.hpp +++ b/src/mlpack/core/cereal/is_saving.hpp @@ -6,7 +6,7 @@ * Implementation of is_saving function. * * This implementation provides backward compatibilty with older - * version of cereal that does not have Archive::is_saving struct. + * version of cereal that does not have Archive::is_saving struct. * * 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 @@ -29,11 +29,12 @@ struct is_cereal_archive_saving { // Archive::is_saving is not implemented yet, so we can use std::is_same<> // to check if it is a loading archive. - constexpr static bool value = std::is_same::value || -//#if (BINDING_TYPE != BINDING_TYPE_R) - std::is_same::value || -//#endif - std::is_same::value; + constexpr static bool value = std::is_same::value || +// #if (BINDING_TYPE != BINDING_TYPE_R) + std::is_same::value || +// #endif + std::is_same::value; }; template @@ -41,7 +42,7 @@ bool is_saving( const typename std::enable_if< is_cereal_archive_saving::value, Archive>::type* = 0) { - return true; + return true; } template diff --git a/src/mlpack/core/data/has_serialize.hpp b/src/mlpack/core/data/has_serialize.hpp index 0c3b92c73b..7c2c3d114a 100644 --- a/src/mlpack/core/data/has_serialize.hpp +++ b/src/mlpack/core/data/has_serialize.hpp @@ -32,9 +32,12 @@ template struct HasSerializeFunction { template - using NonStaticSerialize = void(C::*)(cereal::XMLOutputArchive&, const uint32_t version); + using NonStaticSerialize = void(C::*)(cereal::XMLOutputArchive&, + const uint32_t version); + template - using StaticSerialize = void(*)(cereal::XMLOutputArchive&, const uint32_t version); + using StaticSerialize = void(*)(cereal::XMLOutputArchive&, + const uint32_t version); static const bool value = HasSerializeCheck::value || HasSerializeCheck::value; diff --git a/src/mlpack/core/metrics/bleu_impl.hpp b/src/mlpack/core/metrics/bleu_impl.hpp index 66fdd626a5..38e9b29437 100644 --- a/src/mlpack/core/metrics/bleu_impl.hpp +++ b/src/mlpack/core/metrics/bleu_impl.hpp @@ -187,7 +187,7 @@ ElemType BLEU::Evaluate( template template -void BLEU::serialize(Archive& ar, +void BLEU::serialize(Archive& ar, const uint32_t version) { ar(CEREAL_NVP(maxOrder)); diff --git a/src/mlpack/core/tree/binary_space_tree/binary_space_tree_impl.hpp b/src/mlpack/core/tree/binary_space_tree/binary_space_tree_impl.hpp index cc1b86be18..6e2a934004 100644 --- a/src/mlpack/core/tree/binary_space_tree/binary_space_tree_impl.hpp +++ b/src/mlpack/core/tree/binary_space_tree/binary_space_tree_impl.hpp @@ -1131,7 +1131,7 @@ void BinarySpaceTree:: if (node->left) stack.push(node->left); if (node->right) - stack.push(node->right); + stack.push(node->right); } } } diff --git a/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp b/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp index 30d09c1300..03acfb0e74 100644 --- a/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp @@ -1431,7 +1431,7 @@ void RectangleTree(dataset); ar(CEREAL_POINTER(datasetTemp)); - } + } ar(CEREAL_NVP(points)); ar(CEREAL_NVP(auxiliaryInfo)); diff --git a/src/mlpack/methods/ann/layer/add_impl.hpp b/src/mlpack/methods/ann/layer/add_impl.hpp index e9903981f6..a268956fe8 100644 --- a/src/mlpack/methods/ann/layer/add_impl.hpp +++ b/src/mlpack/methods/ann/layer/add_impl.hpp @@ -23,7 +23,7 @@ template Add::Add(const size_t outSize) : outSize(outSize) { - weights.set_size(outSize, 1); + weights.set_size(WeightSize(), 1); } template diff --git a/src/mlpack/methods/ann/layer/atrous_convolution_impl.hpp b/src/mlpack/methods/ann/layer/atrous_convolution_impl.hpp index e71bb2cf5e..cfb200e3ec 100644 --- a/src/mlpack/methods/ann/layer/atrous_convolution_impl.hpp +++ b/src/mlpack/methods/ann/layer/atrous_convolution_impl.hpp @@ -122,8 +122,7 @@ AtrousConvolution< dilationWidth(dilationWidth), dilationHeight(dilationHeight) { - weights.set_size((outSize * inSize * kernelWidth * kernelHeight) + outSize, - 1); + weights.set_size(WeightSize(), 1); // Transform paddingType to lowercase. std::string paddingTypeLow = paddingType; diff --git a/src/mlpack/methods/ann/layer/concat.hpp b/src/mlpack/methods/ann/layer/concat.hpp index 81df70a1b2..13d29458cb 100644 --- a/src/mlpack/methods/ann/layer/concat.hpp +++ b/src/mlpack/methods/ann/layer/concat.hpp @@ -165,9 +165,9 @@ class Concat } //! Return the initial point for the optimization. - const arma::mat& Parameters() const { return parameters; } + const arma::mat& Parameters() const { return weights; } //! Modify the initial point for the optimization. - arma::mat& Parameters() { return parameters; } + arma::mat& Parameters() { return weights; } //! Get the value of run parameter. bool Run() const { return run; } @@ -196,6 +196,9 @@ class Concat //! Get the axis of concatenation. size_t const& ConcatAxis() const { return axis; } + //! Get the size of the weight matrix. + size_t WeightSize() const { return 0; } + /** * Serialize the layer */ @@ -225,8 +228,8 @@ class Concat //! Locally-stored network modules. std::vector > network; - //! Locally-stored model parameters. - arma::mat parameters; + //! Locally-stored model weights. + OutputDataType weights; //! Locally-stored delta visitor. DeltaVisitor deltaVisitor; diff --git a/src/mlpack/methods/ann/layer/concat_impl.hpp b/src/mlpack/methods/ann/layer/concat_impl.hpp index 694784c7a5..b410361295 100644 --- a/src/mlpack/methods/ann/layer/concat_impl.hpp +++ b/src/mlpack/methods/ann/layer/concat_impl.hpp @@ -33,7 +33,7 @@ Concat::Concat( run(run), channels(1) { - parameters.set_size(0, 0); + weights.set_size(0, 0); } template::Concat( model(model), run(run) { - parameters.set_size(0, 0); + weights.set_size(0, 0); // Parameters to help calculate the number of channels. size_t oldColSize = 1, newColSize = 1; diff --git a/src/mlpack/methods/ann/layer/dropconnect.hpp b/src/mlpack/methods/ann/layer/dropconnect.hpp index 7451705974..db8d76aa4b 100644 --- a/src/mlpack/methods/ann/layer/dropconnect.hpp +++ b/src/mlpack/methods/ann/layer/dropconnect.hpp @@ -115,9 +115,9 @@ class DropConnect std::vector >& Model() { return network; } //! Get the parameters. - OutputDataType const& Parameters() const { return parameters; } + OutputDataType const& Parameters() const { return weights; } //! Modify the parameters. - OutputDataType& Parameters() { return parameters; } + OutputDataType& Parameters() { return weights; } //! Get the output parameter. OutputDataType const& OutputParameter() const { return outputParameter; } @@ -150,6 +150,9 @@ class DropConnect scale = 1.0 / (1.0 - ratio); } + //! Return the size of the weight matrix. + size_t WeightSize() const { return 0; } + /** * Serialize the layer. */ @@ -164,7 +167,7 @@ class DropConnect double scale; //! Locally-stored weight object. - OutputDataType parameters; + OutputDataType weights; //! Locally-stored delta object. OutputDataType delta; diff --git a/src/mlpack/methods/ann/layer/dropconnect_impl.hpp b/src/mlpack/methods/ann/layer/dropconnect_impl.hpp index ccbda1c888..9b22c91951 100644 --- a/src/mlpack/methods/ann/layer/dropconnect_impl.hpp +++ b/src/mlpack/methods/ann/layer/dropconnect_impl.hpp @@ -108,7 +108,7 @@ template void DropConnect::serialize( Archive& ar, const uint32_t /* version */) { - // Delete the old network first, if needed. + // Delete the old network first, if needed. if (cereal::is_loading()) { boost::apply_visitor(DeleteVisitor(), baseLayer); diff --git a/src/mlpack/methods/ann/layer/fast_lstm.hpp b/src/mlpack/methods/ann/layer/fast_lstm.hpp index a0400772fd..121c97e176 100644 --- a/src/mlpack/methods/ann/layer/fast_lstm.hpp +++ b/src/mlpack/methods/ann/layer/fast_lstm.hpp @@ -164,6 +164,12 @@ class FastLSTM //! Get the number of output units. size_t OutSize() const { return outSize; } + //! Get the size of the weight matrix. + size_t WeightSize() const + { + return 4 * outSize * inSize + 4 * outSize + 4 * outSize * outSize; + } + /** * Serialize the layer */ diff --git a/src/mlpack/methods/ann/layer/fast_lstm_impl.hpp b/src/mlpack/methods/ann/layer/fast_lstm_impl.hpp index b283dbc5ad..5f5502cf9a 100644 --- a/src/mlpack/methods/ann/layer/fast_lstm_impl.hpp +++ b/src/mlpack/methods/ann/layer/fast_lstm_impl.hpp @@ -42,8 +42,7 @@ FastLSTM::FastLSTM( { // Weights for: input to gate layer (4 * outsize * inSize + 4 * outsize) // and output to gate (4 * outSize). - weights.set_size( - 4 * outSize * inSize + 4 * outSize + 4 * outSize * outSize, 1); + weights.set_size(WeightSize(), 1); } template diff --git a/src/mlpack/methods/ann/layer/linear_impl.hpp b/src/mlpack/methods/ann/layer/linear_impl.hpp index 83a7b1f157..2edfb4802c 100644 --- a/src/mlpack/methods/ann/layer/linear_impl.hpp +++ b/src/mlpack/methods/ann/layer/linear_impl.hpp @@ -38,7 +38,7 @@ Linear::Linear( outSize(outSize), regularizer(regularizer) { - weights.set_size(outSize * inSize + outSize, 1); + weights.set_size(WeightSize(), 1); } template& Linear:: operator=(const Linear& layer) -{ +{ if (this != &layer) { inSize = layer.inSize; @@ -86,7 +86,7 @@ template& Linear:: operator=(Linear&& layer) -{ +{ if (this != &layer) { inSize = layer.inSize; diff --git a/src/mlpack/methods/ann/layer/softmin_impl.hpp b/src/mlpack/methods/ann/layer/softmin_impl.hpp index e2389f5856..6945256b44 100644 --- a/src/mlpack/methods/ann/layer/softmin_impl.hpp +++ b/src/mlpack/methods/ann/layer/softmin_impl.hpp @@ -29,7 +29,7 @@ template void Softmin::Forward( const InputType& input, OutputType& output) -{ +{ InputType softminInput = arma::exp(-(input.each_row() - arma::min(input, 0))); output = softminInput.each_row() / sum(softminInput, 0); @@ -53,7 +53,7 @@ void Softmin::serialize( { // Nothing to do here. } - + } // namespace ann } // namespace mlpack diff --git a/src/mlpack/methods/ann/loss_functions/mean_absolute_percentage_error_impl.hpp b/src/mlpack/methods/ann/loss_functions/mean_absolute_percentage_error_impl.hpp index c17badf733..52b6281a18 100644 --- a/src/mlpack/methods/ann/loss_functions/mean_absolute_percentage_error_impl.hpp +++ b/src/mlpack/methods/ann/loss_functions/mean_absolute_percentage_error_impl.hpp @@ -32,7 +32,7 @@ MeanAbsolutePercentageError::Forward( const InputType& input, const TargetType& target) { - InputType loss = arma::abs((input - target) / target); + InputType loss = arma::abs((input - target) / target); return arma::accu(loss) * (100 / target.n_cols); } @@ -43,9 +43,9 @@ void MeanAbsolutePercentageError::Backward( const TargetType& target, OutputType& output) -{ +{ output = (((arma::conv_to::from(input < target) * -2) + 1) / - target) * (100 / target.n_cols) ; + target) * (100 / target.n_cols); } template diff --git a/src/mlpack/methods/bayesian_linear_regression/bayesian_linear_regression_impl.hpp b/src/mlpack/methods/bayesian_linear_regression/bayesian_linear_regression_impl.hpp index 8842cc82e5..d0881dd06a 100644 --- a/src/mlpack/methods/bayesian_linear_regression/bayesian_linear_regression_impl.hpp +++ b/src/mlpack/methods/bayesian_linear_regression/bayesian_linear_regression_impl.hpp @@ -21,7 +21,8 @@ namespace regression { * Serialize the Bayesian linear regression model. */ template -void BayesianLinearRegression::serialize(Archive& ar, const uint32_t /* version */) +void BayesianLinearRegression::serialize(Archive& ar, + const uint32_t /* version */) { ar(CEREAL_NVP(centerData)); ar(CEREAL_NVP(scaleData)); diff --git a/src/mlpack/methods/hmm/hmm_util_impl.hpp b/src/mlpack/methods/hmm/hmm_util_impl.hpp index 24ee4adc6b..017cc65bcd 100644 --- a/src/mlpack/methods/hmm/hmm_util_impl.hpp +++ b/src/mlpack/methods/hmm/hmm_util_impl.hpp @@ -41,14 +41,25 @@ void LoadHMMAndPerformAction(const std::string& modelFile, { const std::string extension = data::Extension(modelFile); if (extension == "xml") - LoadHMMAndPerformActionHelper(modelFile, x); + { + LoadHMMAndPerformActionHelper( + modelFile, x); + } else if (extension == "bin") - LoadHMMAndPerformActionHelper(modelFile, x); + { + LoadHMMAndPerformActionHelper( + modelFile, x); + } else if (extension == "json") - LoadHMMAndPerformActionHelper(modelFile, x); + { + LoadHMMAndPerformActionHelper( + modelFile, x); + } else + { Log::Fatal << "Unknown extension '" << extension << "' for HMM model file " << "(known: 'xml', 'json', 'bin')." << std::endl; + } } template linear = new Linear<>(randomSize, randomSize); + LayerTypes<> linearLayer = new Linear<>(randomInSize, randomOutSize); - CheckCorrectnessOfWeightSize(linear); + size_t weightSize = boost::apply_visitor(WeightSizeVisitor(), linearLayer); + + CheckCorrectnessOfWeightSize(linearLayer); +} + +/** + * Test that WeightSizeVisitor works properly for concat layer. + */ +TEST_CASE("WeightSizeVisitorTestForConcatLayer", "[ANNVisitorTest]") +{ + LayerTypes<> concatLayer = new Concat<>(); + + size_t weightSize = boost::apply_visitor(WeightSizeVisitor(), concatLayer); + + CheckCorrectnessOfWeightSize(concatLayer); +} + +/** + * Test that WeightSizeVisitor works properly for fast lstm layer. + */ +TEST_CASE("WeightSizeVisitorTestForFastLSTMLayer", "[ANNVisitorTest]") +{ + size_t randomInSize = arma::randi(arma::distr_param(1, 100)); + size_t randomOutSize = arma::randi(arma::distr_param(1, 100)); + + LayerTypes<> fastLSTMLayer = new FastLSTM<>(randomInSize, randomOutSize); + + size_t weightSize = boost::apply_visitor(WeightSizeVisitor(), fastLSTMLayer); + + CheckCorrectnessOfWeightSize(fastLSTMLayer); +} + +/** + * Test that WeightSizeVisitor works properly for Add layer. + */ +TEST_CASE("WeightSizeVisitorTestForAddLayer", "[ANNVisitorTest]") +{ + size_t randomOutSize = arma::randi(arma::distr_param(1, 100)); + + LayerTypes<> addLayer = new Add<>(randomOutSize); + + size_t weightSize = boost::apply_visitor(WeightSizeVisitor(), addLayer); + + CheckCorrectnessOfWeightSize(addLayer); +} + +/** + * Test that WeightSizeVisitor works properly for Atrous Convolution Layer. + */ +TEST_CASE("WeightSizeVisitorTestForAtrousConvolutionLayer", "[ANNVisitorTest]") +{ + size_t randomInSize = arma::randi(arma::distr_param(1, 100)); + size_t randomOutSize = arma::randi(arma::distr_param(1, 100)); + size_t randomKernelWidth = arma::randi(arma::distr_param(1, 100)); + size_t randomKernelHeight = arma::randi(arma::distr_param(1, 100)); + + LayerTypes<> atrousConvLayer = new AtrousConvolution<>(randomInSize, + randomOutSize, randomKernelWidth, randomKernelHeight); + + size_t weightSize = boost::apply_visitor(WeightSizeVisitor(), + atrousConvLayer); + + CheckCorrectnessOfWeightSize(atrousConvLayer); } diff --git a/src/mlpack/tests/distribution_test.cpp b/src/mlpack/tests/distribution_test.cpp index 0ec7fd3cb6..7346098d43 100644 --- a/src/mlpack/tests/distribution_test.cpp +++ b/src/mlpack/tests/distribution_test.cpp @@ -1518,7 +1518,8 @@ TEST_CASE("DiagonalGaussianUnbiasedEstimatorTest", "[DistributionTest]") * the weighted mean and covariance reduce to the unweighted sample mean and * covariance. */ -TEST_CASE("DiagonalGaussianWeightedParametersReductionTest", "[DistributionTest]") +TEST_CASE("DiagonalGaussianWeightedParametersReductionTest", + "[DistributionTest]") { arma::vec mean("2.5 1.5 8.2 3.1"); arma::vec cov("1.2 3.1 8.3 4.3"); diff --git a/src/mlpack/tests/hoeffding_tree_test.cpp b/src/mlpack/tests/hoeffding_tree_test.cpp index 8787dfe28f..49c60b0cea 100644 --- a/src/mlpack/tests/hoeffding_tree_test.cpp +++ b/src/mlpack/tests/hoeffding_tree_test.cpp @@ -173,7 +173,8 @@ TEST_CASE("HoeffdingInformationGainBadSplitTest", "[HoeffdingTreeTest]") counts(1, 0) = 5; counts(1, 1) = 5; - REQUIRE(HoeffdingInformationGain::Evaluate(counts) == Approx(0.0).margin(1e-10)); + REQUIRE(HoeffdingInformationGain::Evaluate(counts) == + Approx(0.0).margin(1e-10)); } /** @@ -216,7 +217,8 @@ TEST_CASE("HoeffdingInformationGainZeroTest", "[HoeffdingTreeTest]") // When nothing has been seen, the information gain should be zero. arma::Mat counts = arma::zeros>(10, 10); - REQUIRE(HoeffdingInformationGain::Evaluate(counts) == Approx(0.0).margin(1e-10)); + REQUIRE(HoeffdingInformationGain::Evaluate(counts) == + Approx(0.0).margin(1e-10)); } /** @@ -225,14 +227,22 @@ TEST_CASE("HoeffdingInformationGainZeroTest", "[HoeffdingTreeTest]") */ TEST_CASE("HoeffdingInformationGainRangeTest", "[HoeffdingTreeTest]") { - REQUIRE(HoeffdingInformationGain::Range(1) == Approx(0).epsilon(1e-7)); - REQUIRE(HoeffdingInformationGain::Range(2) == Approx(1.0).epsilon(1e-7)); - REQUIRE(HoeffdingInformationGain::Range(3) == Approx(1.5849625).epsilon(1e-7)); - REQUIRE(HoeffdingInformationGain::Range(4) == Approx(2).epsilon(1e-7)); - REQUIRE(HoeffdingInformationGain::Range(5) == Approx(2.32192809).epsilon(1e-7)); - REQUIRE(HoeffdingInformationGain::Range(10) == Approx(3.32192809).epsilon(1e-7)); - REQUIRE(HoeffdingInformationGain::Range(100) == Approx(6.64385619).epsilon(1e-7)); - REQUIRE(HoeffdingInformationGain::Range(1000) == Approx(9.96578428).epsilon(1e-7)); + REQUIRE(HoeffdingInformationGain::Range(1) == + Approx(0).epsilon(1e-7)); + REQUIRE(HoeffdingInformationGain::Range(2) == + Approx(1.0).epsilon(1e-7)); + REQUIRE(HoeffdingInformationGain::Range(3) == + Approx(1.5849625).epsilon(1e-7)); + REQUIRE(HoeffdingInformationGain::Range(4) == + Approx(2).epsilon(1e-7)); + REQUIRE(HoeffdingInformationGain::Range(5) == + Approx(2.32192809).epsilon(1e-7)); + REQUIRE(HoeffdingInformationGain::Range(10) == + Approx(3.32192809).epsilon(1e-7)); + REQUIRE(HoeffdingInformationGain::Range(100) == + Approx(6.64385619).epsilon(1e-7)); + REQUIRE(HoeffdingInformationGain::Range(1000) == + Approx(9.96578428).epsilon(1e-7)); } /** diff --git a/src/mlpack/tests/io_test.cpp b/src/mlpack/tests/io_test.cpp index d09b7e97a0..fa363face9 100644 --- a/src/mlpack/tests/io_test.cpp +++ b/src/mlpack/tests/io_test.cpp @@ -795,7 +795,8 @@ TEST_CASE_METHOD(IOTestDestroyer, "OutputMatrixParamTest", remove("test.csv"); } -TEST_CASE_METHOD(IOTestDestroyer, "OutputMatrixNoTransposeParamTest", "[IOTest]") +TEST_CASE_METHOD(IOTestDestroyer, "OutputMatrixNoTransposeParamTest", + "[IOTest]") { AddRequiredCLIOptions(); diff --git a/src/mlpack/tests/lin_alg_test.cpp b/src/mlpack/tests/lin_alg_test.cpp index 7454564c20..a43821d75d 100644 --- a/src/mlpack/tests/lin_alg_test.cpp +++ b/src/mlpack/tests/lin_alg_test.cpp @@ -190,7 +190,6 @@ TEST_CASE("TestSvecSmat", "[LinAlgTest]") for (size_t i = 0; i < 3; ++i) for (size_t j = 0; j < 3; ++j) REQUIRE(X(i, j) == Approx(Xtest(i, j)).epsilon(1e-9)); - } TEST_CASE("TestSparseSvec", "[LinAlgTest]") diff --git a/src/mlpack/tests/lmnn_test.cpp b/src/mlpack/tests/lmnn_test.cpp index 52d014c9aa..b767f4a940 100644 --- a/src/mlpack/tests/lmnn_test.cpp +++ b/src/mlpack/tests/lmnn_test.cpp @@ -120,7 +120,7 @@ TEST_CASE("LMNNInitialPointTest", "[LMNNTest]") for (int col = 0; col < 5; col++) { if (row == col) - REQUIRE(initialPoint(row, col) == Approx( 1.0).epsilon(1e-7)); + REQUIRE(initialPoint(row, col) == Approx(1.0).epsilon(1e-7)); else REQUIRE(initialPoint(row, col) == Approx(0.0).margin(1e-5)); } @@ -207,8 +207,8 @@ TEST_CASE("LMNNSeparableObjectiveTest", "[LMNNTest]") // Result calculated by hand. arma::mat coordinates = arma::eye(2, 2); - REQUIRE(lmnnfn.Evaluate(coordinates, 0, 1) == Approx( 1.576).epsilon(1e-7)); - REQUIRE(lmnnfn.Evaluate(coordinates, 1, 1) == Approx( 1.576).epsilon(1e-7)); + REQUIRE(lmnnfn.Evaluate(coordinates, 0, 1) == Approx(1.576).epsilon(1e-7)); + REQUIRE(lmnnfn.Evaluate(coordinates, 1, 1) == Approx(1.576).epsilon(1e-7)); REQUIRE(lmnnfn.Evaluate(coordinates, 2, 1) == Approx(1.576).epsilon(1e-7)); REQUIRE(lmnnfn.Evaluate(coordinates, 3, 1) == Approx(1.576).epsilon(1e-7)); REQUIRE(lmnnfn.Evaluate(coordinates, 4, 1) == Approx(1.576).epsilon(1e-7)); @@ -326,21 +326,21 @@ TEST_CASE("LMNNSeparableEvaluateWithGradientTest", "[LMNNTest]") objective = lmnnfn.EvaluateWithGradient(coordinates, 4, gradient, 1); - REQUIRE(objective == Approx( 1.576).epsilon(1e-7)); + REQUIRE(objective == Approx(1.576).epsilon(1e-7)); - REQUIRE(gradient(0, 0) == Approx( -0.048).epsilon(1e-7)); - REQUIRE(gradient(0, 1) == Approx( 0.0).epsilon(1e-7)); - REQUIRE(gradient(1, 0) == Approx( 0.0).epsilon(1e-7)); - REQUIRE(gradient(1, 1) == Approx( 2.0).epsilon(1e-7)); + REQUIRE(gradient(0, 0) == Approx(-0.048).epsilon(1e-7)); + REQUIRE(gradient(0, 1) == Approx(0.0).epsilon(1e-7)); + REQUIRE(gradient(1, 0) == Approx(0.0).epsilon(1e-7)); + REQUIRE(gradient(1, 1) == Approx(2.0).epsilon(1e-7)); objective = lmnnfn.EvaluateWithGradient(coordinates, 5, gradient, 1); - REQUIRE(objective == Approx( 1.576).epsilon(1e-7)); + REQUIRE(objective == Approx(1.576).epsilon(1e-7)); - REQUIRE(gradient(0, 0) == Approx( -0.048).epsilon(1e-7)); - REQUIRE(gradient(0, 1) == Approx( 0.0).epsilon(1e-7)); - REQUIRE(gradient(1, 0) == Approx( 0.0).epsilon(1e-7)); - REQUIRE(gradient(1, 1) == Approx( 2.0).epsilon(1e-7)); + REQUIRE(gradient(0, 0) == Approx(-0.048).epsilon(1e-7)); + REQUIRE(gradient(0, 1) == Approx(0.0).epsilon(1e-7)); + REQUIRE(gradient(1, 0) == Approx(0.0).epsilon(1e-7)); + REQUIRE(gradient(1, 1) == Approx(2.0).epsilon(1e-7)); } // Check that final objective value using SGD optimizer is optimal. @@ -450,7 +450,7 @@ TEST_CASE("LMNNAccuracyTest", "[LMNNTest]") REQUIRE(initAccuracy < finalAccuracy); // Since this is a very simple dataset final accuracy should be around 100%. - REQUIRE(finalAccuracy == Approx( 100.0).epsilon(1e-7)); + REQUIRE(finalAccuracy == Approx(100.0).epsilon(1e-7)); } // Check that accuracy while learning square distance matrix is the same as when diff --git a/src/mlpack/tests/loss_functions_test.cpp b/src/mlpack/tests/loss_functions_test.cpp index cb814d021e..42762bd96d 100644 --- a/src/mlpack/tests/loss_functions_test.cpp +++ b/src/mlpack/tests/loss_functions_test.cpp @@ -201,7 +201,7 @@ TEST_CASE("KLDivergenceMeanTest", "[LossFunctionsTest]") target = arma::exp(arma::mat("2 1 1 1 1 1 1 1 1 1")); loss = module.Forward(input, target); - REQUIRE(loss == Approx(-1.1 ).epsilon(1e-5)); + REQUIRE(loss == Approx(-1.1).epsilon(1e-5)); // Test the Backward function. module.Backward(input, target, output); @@ -846,7 +846,8 @@ TEST_CASE("SoftMarginLossTest", "[LossFunctionsTest]") // Test the Backward function. module1.Backward(input, target, output); - REQUIRE(arma::as_scalar(arma::accu(output)) == Approx(-1.48227).epsilon(1e-3)); + REQUIRE(arma::as_scalar(arma::accu(output)) == + Approx(-1.48227).epsilon(1e-3)); REQUIRE(output.n_rows == input.n_rows); REQUIRE(output.n_cols == input.n_cols); CheckMatrices(output, expectedOutput, 0.1); @@ -865,7 +866,8 @@ TEST_CASE("SoftMarginLossTest", "[LossFunctionsTest]") // Test the Backward function. module2.Backward(input, target, output); - REQUIRE(arma::as_scalar(arma::accu(output)) == Approx(-0.164697).epsilon(1e-3)); + REQUIRE(arma::as_scalar(arma::accu(output)) == + Approx(-0.164697).epsilon(1e-3)); REQUIRE(output.n_rows == input.n_rows); REQUIRE(output.n_cols == input.n_cols); CheckMatrices(output, expectedOutput, 0.1); @@ -884,12 +886,13 @@ TEST_CASE("MeanAbsolutePercentageErrorTest", "[LossFunctionsTest]") // Test the Forward function. Loss should be 95.625. // Loss value calculated manually. - double loss = module.Forward(input,target); - REQUIRE(loss == Approx(95.625).epsilon(1e-1)); + double loss = module.Forward(input, target); + REQUIRE(loss == Approx(95.625).epsilon(1e-1)); // Test the Backward function. module.Backward(input, target, output); - REQUIRE(arma::as_scalar(arma::accu(output)) == Approx(-105.625).epsilon(1e-3)); + REQUIRE(arma::as_scalar(arma::accu(output)) == + Approx(-105.625).epsilon(1e-3)); REQUIRE(output.n_rows == input.n_rows); REQUIRE(output.n_cols == input.n_cols); CheckMatrices(output, expectedOutput, 0.1); diff --git a/src/mlpack/tests/main_tests/kde_test.cpp b/src/mlpack/tests/main_tests/kde_test.cpp index f4604f9475..325130c928 100644 --- a/src/mlpack/tests/main_tests/kde_test.cpp +++ b/src/mlpack/tests/main_tests/kde_test.cpp @@ -87,7 +87,7 @@ TEST_CASE_METHOD(KDETestFixture, "KDEGaussianRTreeResultsMain", // Check whether results are equal. for (size_t i = 0; i < query.n_cols; ++i) - REQUIRE(kdeEstimations[i] == Approx( mainEstimations[i]).epsilon(relError)); + REQUIRE(kdeEstimations[i] == Approx(mainEstimations[i]).epsilon(relError)); } /** @@ -128,7 +128,7 @@ TEST_CASE_METHOD(KDETestFixture, "KDETriangularBallTreeResultsMain", // Check whether results are equal. for (size_t i = 0; i < query.n_cols; ++i) - REQUIRE(kdeEstimations[i] == Approx( mainEstimations[i]).epsilon(relError)); + REQUIRE(kdeEstimations[i] == Approx(mainEstimations[i]).epsilon(relError)); } /** @@ -170,7 +170,7 @@ TEST_CASE_METHOD(KDETestFixture, "KDEMonoResultsMain", // Check whether results are equal. for (size_t i = 0; i < reference.n_cols; ++i) - REQUIRE(kdeEstimations[i] == Approx( mainEstimations[i]).epsilon(relError)); + REQUIRE(kdeEstimations[i] == Approx(mainEstimations[i]).epsilon(relError)); } /** @@ -239,7 +239,7 @@ TEST_CASE_METHOD(KDETestFixture, "KDEModelReuse", // Check estimations are the same. for (size_t i = 0; i < samples; ++i) - REQUIRE(oldEstimations[i] == Approx( newEstimations[i]).epsilon(relError)); + REQUIRE(oldEstimations[i] == Approx(newEstimations[i]).epsilon(relError)); } /** @@ -282,7 +282,7 @@ TEST_CASE_METHOD(KDETestFixture, "KDEGaussianSingleKDTreeResultsMain", // Check whether results are equal. for (size_t i = 0; i < query.n_cols; ++i) - REQUIRE(kdeEstimations[i] == Approx( mainEstimations[i]).epsilon(relError)); + REQUIRE(kdeEstimations[i] == Approx(mainEstimations[i]).epsilon(relError)); } /** diff --git a/src/mlpack/tests/main_tests/krann_test.cpp b/src/mlpack/tests/main_tests/krann_test.cpp index 244b88c8c5..b61044f104 100644 --- a/src/mlpack/tests/main_tests/krann_test.cpp +++ b/src/mlpack/tests/main_tests/krann_test.cpp @@ -453,7 +453,8 @@ TEST_CASE_METHOD(KRANNTestFixture, "KRANNDifferentTreeType", // Check that initial output matrices and the output matrices using // saved model are equal - CHECK(output_model->TreeType() == 0); + const bool check = output_model->TreeType() == 0; + CHECK(check == true); CHECK(IO::GetParam("output_model")->TreeType() == 8); delete output_model; @@ -491,7 +492,8 @@ TEST_CASE_METHOD(KRANNTestFixture, "KRANNDifferentSingleSampleLimit", // Check that initial output matrices and the output matrices using // saved model are equal. - CHECK( IO::GetParam("output_model")->SingleSampleLimit() == (int) 15); + CHECK(IO::GetParam("output_model")->SingleSampleLimit() == + (int) 15); CHECK(output_model->SingleSampleLimit() == (int) 20); delete output_model; } diff --git a/src/mlpack/tests/nbc_test.cpp b/src/mlpack/tests/nbc_test.cpp index f487060db4..ddc0487315 100644 --- a/src/mlpack/tests/nbc_test.cpp +++ b/src/mlpack/tests/nbc_test.cpp @@ -81,7 +81,6 @@ TEST_CASE("NaiveBayesClassifierTest", "[NBCTest]") { for (size_t j = 0; j < testResProbs.n_rows; ++j) { - REQUIRE(testResProbs(j, i) + 0.0001 == Approx(calcProbs(j, i) + 0.0001).epsilon(0.0001)); } diff --git a/src/mlpack/tests/pca_test.cpp b/src/mlpack/tests/pca_test.cpp index fff63d0024..6ccefbbaeb 100644 --- a/src/mlpack/tests/pca_test.cpp +++ b/src/mlpack/tests/pca_test.cpp @@ -316,7 +316,8 @@ TEST_CASE("PCAScalingTest", "[PCATest]") // zero. There is noise, of course... REQUIRE(std::abs(eigvec(0, 0)) == Approx(sqrt(2) / 2).epsilon(0.0035)); REQUIRE(std::abs(eigvec(1, 0)) == Approx(sqrt(2) / 2).epsilon(0.0035)); - REQUIRE(eigvec(2, 0) == Approx(0.0).margin(0.1)); // Large tolerance for noise. + // Large tolerance for noise. + REQUIRE(eigvec(2, 0) == Approx(0.0).margin(0.1)); // The second component should be focused almost entirely in the third // dimension. @@ -328,7 +329,8 @@ TEST_CASE("PCAScalingTest", "[PCATest]") // the first (plus tolerance). REQUIRE(std::abs(eigvec(0, 0)) == Approx(sqrt(2) / 2).epsilon(0.0035)); REQUIRE(std::abs(eigvec(1, 0)) == Approx(sqrt(2) / 2).epsilon(0.0035)); - REQUIRE(eigvec(2, 0) == Approx(0.0).margin(0.1)); // Large tolerance for noise. + // Large tolerance for noise. + REQUIRE(eigvec(2, 0) == Approx(0.0).margin(0.1)); // The eigenvalues should sum to three. REQUIRE(accu(eigval) == Approx(3.0).epsilon(0.001)); diff --git a/src/mlpack/tests/range_search_test.cpp b/src/mlpack/tests/range_search_test.cpp index 3df0247a6b..8e6e79da17 100644 --- a/src/mlpack/tests/range_search_test.cpp +++ b/src/mlpack/tests/range_search_test.cpp @@ -206,13 +206,20 @@ TEST_CASE("ExhaustiveSyntheticTest", "[RangeSearchTest]") // Neighbors of point 10. REQUIRE(sortedOutput[newFromOld[10]].size() == 4); REQUIRE(sortedOutput[newFromOld[10]][0].second == newFromOld[9]); - REQUIRE(sortedOutput[newFromOld[10]][0].first == Approx(0.10).epsilon(1e-7)); - REQUIRE(sortedOutput[newFromOld[10]][1].second == newFromOld[3]); - REQUIRE(sortedOutput[newFromOld[10]][1].first == Approx(0.25).epsilon(1e-7)); - REQUIRE(sortedOutput[newFromOld[10]][2].second == newFromOld[8]); - REQUIRE(sortedOutput[newFromOld[10]][2].first == Approx(0.55).epsilon(1e-7)); - REQUIRE(sortedOutput[newFromOld[10]][3].second == newFromOld[1]); - REQUIRE(sortedOutput[newFromOld[10]][3].first == Approx(0.65).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[10]][0].first == + Approx(0.10).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[10]][1].second == + newFromOld[3]); + REQUIRE(sortedOutput[newFromOld[10]][1].first == + Approx(0.25).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[10]][2].second == + newFromOld[8]); + REQUIRE(sortedOutput[newFromOld[10]][2].first == + Approx(0.55).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[10]][3].second == + newFromOld[1]); + REQUIRE(sortedOutput[newFromOld[10]][3].first == + Approx(0.65).epsilon(1e-7)); // Now do it again with a different range: [sqrt(0.5) 1.0]. if (rs->ReferenceTree()) @@ -273,9 +280,11 @@ TEST_CASE("ExhaustiveSyntheticTest", "[RangeSearchTest]") // Neighbors of point 10. REQUIRE(sortedOutput[newFromOld[10]].size() == 2); REQUIRE(sortedOutput[newFromOld[10]][0].second == newFromOld[2]); - REQUIRE(sortedOutput[newFromOld[10]][0].first == Approx(0.85).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[10]][0].first == + Approx(0.85).epsilon(1e-7)); REQUIRE(sortedOutput[newFromOld[10]][1].second == newFromOld[0]); - REQUIRE(sortedOutput[newFromOld[10]][1].first == Approx(0.95).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[10]][1].first == + Approx(0.95).epsilon(1e-7)); // Now do it again with a different range: [1.0 inf]. if (rs->ReferenceTree()) @@ -433,13 +442,20 @@ TEST_CASE("ExhaustiveSyntheticTest", "[RangeSearchTest]") // Neighbors of point 10. REQUIRE(sortedOutput[newFromOld[10]].size() == 4); REQUIRE(sortedOutput[newFromOld[10]][0].second == newFromOld[5]); - REQUIRE(sortedOutput[newFromOld[10]][0].first == Approx(1.22).epsilon(1e-7)); - REQUIRE(sortedOutput[newFromOld[10]][1].second == newFromOld[7]); - REQUIRE(sortedOutput[newFromOld[10]][1].first == Approx(2.30).epsilon(1e-7)); - REQUIRE(sortedOutput[newFromOld[10]][2].second == newFromOld[6]); - REQUIRE(sortedOutput[newFromOld[10]][2].first == Approx(3.00).epsilon(1e-7)); - REQUIRE(sortedOutput[newFromOld[10]][3].second == newFromOld[4]); - REQUIRE(sortedOutput[newFromOld[10]][3].first == Approx(4.05).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[10]][0].first == + Approx(1.22).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[10]][1].second == + newFromOld[7]); + REQUIRE(sortedOutput[newFromOld[10]][1].first == + Approx(2.30).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[10]][2].second == + newFromOld[6]); + REQUIRE(sortedOutput[newFromOld[10]][2].first == + Approx(3.00).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[10]][3].second == + newFromOld[4]); + REQUIRE(sortedOutput[newFromOld[10]][3].first == + Approx(4.05).epsilon(1e-7)); // Clean the memory. delete rs; @@ -1042,7 +1058,7 @@ TEST_CASE("DualBallTreeTest2", "[RangeSearchTest]") { REQUIRE(kdSorted[i][j].second == ballSorted[i][j].second); REQUIRE(kdSorted[i][j].first == - Approx(ballSorted[i][j].first).epsilon (1e-7)); + Approx(ballSorted[i][j].first).epsilon(1e-7)); } } } diff --git a/src/mlpack/tests/rl_components_test.cpp b/src/mlpack/tests/rl_components_test.cpp index 7eb69cb003..8ce209903e 100644 --- a/src/mlpack/tests/rl_components_test.cpp +++ b/src/mlpack/tests/rl_components_test.cpp @@ -196,7 +196,7 @@ TEST_CASE("DoublePoleCartTest", "[RLComponentsTest]") } /** - * Constructs a ContinuousDoublePoleCart instance and check if the main + * Constructs a ContinuousDoublePoleCart instance and check if the main * routine works as it should be. */ TEST_CASE("ContinuousDoublePoleCartTest", "[RLComponentsTest]") @@ -285,5 +285,4 @@ TEST_CASE("GreedyPolicyTest", "[RLComponentsTest]") CartPole::Action action = policy.Sample(actionValue); REQUIRE(actionValue[action.action] == Approx(actionValue.max()).epsilon(1e-7)); - } diff --git a/src/mlpack/tests/sort_policy_test.cpp b/src/mlpack/tests/sort_policy_test.cpp index 6418135f8e..cb73f96cad 100644 --- a/src/mlpack/tests/sort_policy_test.cpp +++ b/src/mlpack/tests/sort_policy_test.cpp @@ -107,7 +107,7 @@ TEST_CASE("NnsNodeToNodeDistance", "[SortPolicyTest]") utility[0] = 0.5; nodeTwo.Bound() |= utility; - REQUIRE(NearestNeighborSort::BestNodeToNodeDistance(&nodeOne, &nodeTwo) == + REQUIRE(NearestNeighborSort::BestNodeToNodeDistance(&nodeOne, &nodeTwo) == Approx(0.0).margin(1e-5)); } @@ -146,7 +146,7 @@ TEST_CASE("NnsPointToNodeDistance", "[SortPolicyTest]") // And now when the point is inside the bound. point[0] = 0.5; - REQUIRE(NearestNeighborSort::BestPointToNodeDistance(point, &node) == + REQUIRE(NearestNeighborSort::BestPointToNodeDistance(point, &node) == Approx(0.0).margin(1e-5)); } diff --git a/src/mlpack/tests/string_encoding_test.cpp b/src/mlpack/tests/string_encoding_test.cpp index 23c72da3a4..8793981fce 100644 --- a/src/mlpack/tests/string_encoding_test.cpp +++ b/src/mlpack/tests/string_encoding_test.cpp @@ -268,7 +268,8 @@ TEST_CASE("DictionaryEncodingIndividualCharactersTest", "[StringEncodingTest]") * Test the one pass modification of the dictionary encoding algorithm * in case of individual character encoding. */ -TEST_CASE("OnePassDictionaryEncodingIndividualCharactersTest", "[StringEncodingTest]") +TEST_CASE("OnePassDictionaryEncodingIndividualCharactersTest", + "[StringEncodingTest]") { std::vector input = { "GACCA", @@ -541,7 +542,7 @@ TEST_CASE("CharExtractDictionaryEncodingSerialization", "[StringEncodingTest]") /** * Test the Bag of Words encoding algorithm. - */ + */ TEST_CASE("BagOfWordsEncodingTest", "[StringEncodingTest]") { using DictionaryType = StringEncodingDictionary; @@ -616,7 +617,7 @@ TEST_CASE("BagOfWordsEncodingTest", "[StringEncodingTest]") /** * Test the Bag of Words encoding algorithm. The output is saved into a vector. - */ + */ TEST_CASE("VectorBagOfWordsEncodingTest", "[StringEncodingTest]") { using DictionaryType = StringEncodingDictionary; @@ -683,7 +684,8 @@ TEST_CASE("BagOfWordsEncodingIndividualCharactersTest", "[StringEncodingTest]") * Test the Bag of Words encoding algorithm in case of individual * characters encoding. The output type is vector>. */ -TEST_CASE("VectorBagOfWordsEncodingIndividualCharactersTest", "[StringEncodingTest]") +TEST_CASE("VectorBagOfWordsEncodingIndividualCharactersTest", + "[StringEncodingTest]") { std::vector input = { "GACCA", @@ -860,7 +862,8 @@ TEST_CASE("VectorRawCountSmoothIdfEncodingTest", "[StringEncodingTest]") * raw count term frequency type and the smooth inverse document frequency type. * These parameters are the default ones. */ -TEST_CASE("RawCountSmoothIdfEncodingIndividualCharactersTest", "[StringEncodingTest]") +TEST_CASE("RawCountSmoothIdfEncodingIndividualCharactersTest", + "[StringEncodingTest]") { vector input = { "GACCA", @@ -941,7 +944,8 @@ TEST_CASE("RawCountSmoothIdfEncodingIndividualCharactersTest", "[StringEncodingT * These parameters are the default ones. The output type is * vector>. */ -TEST_CASE("VectorRawCountSmoothIdfEncodingIndividualCharactersTest", "[StringEncodingTest]") +TEST_CASE("VectorRawCountSmoothIdfEncodingIndividualCharactersTest", + "[StringEncodingTest]") { std::vector input = { "GACCA", @@ -1067,7 +1071,8 @@ TEST_CASE("VectorTfIdfRawCountEncodingTest", "[StringEncodingTest]") * raw count term frequency type and the non-smooth inverse document frequency * type. */ -TEST_CASE("RawCountTfIdfEncodingIndividualCharactersTest", "[StringEncodingTest]") +TEST_CASE("RawCountTfIdfEncodingIndividualCharactersTest", + "[StringEncodingTest]") { vector input = { "GACCA", @@ -1098,7 +1103,8 @@ TEST_CASE("RawCountTfIdfEncodingIndividualCharactersTest", "[StringEncodingTest] * raw count term frequency type and the non-smooth inverse document frequency * type. The output type is vector>. */ -TEST_CASE("VectorRawCountTfIdfEncodingIndividualCharactersTest", "[StringEncodingTest]") +TEST_CASE("VectorRawCountTfIdfEncodingIndividualCharactersTest", + "[StringEncodingTest]") { std::vector input = { "GACCA", @@ -1128,7 +1134,8 @@ TEST_CASE("VectorRawCountTfIdfEncodingIndividualCharactersTest", "[StringEncodin * Test the Tf-Idf encoding algorithm for individual characters with the * binary term frequency type and the smooth inverse document frequency type. */ -TEST_CASE("BinarySmoothIdfEncodingIndividualCharactersTest", "[StringEncodingTest]") +TEST_CASE("BinarySmoothIdfEncodingIndividualCharactersTest", + "[StringEncodingTest]") { vector input = { "GACCA", @@ -1159,7 +1166,8 @@ TEST_CASE("BinarySmoothIdfEncodingIndividualCharactersTest", "[StringEncodingTes * binary term frequency type and the smooth inverse document frequency type. * The output type is vector>. */ -TEST_CASE("VectorBinarySmoothIdfEncodingIndividualCharactersTest", "[StringEncodingTest]") +TEST_CASE("VectorBinarySmoothIdfEncodingIndividualCharactersTest", + "[StringEncodingTest]") { std::vector input = { "GACCA", @@ -1221,7 +1229,8 @@ TEST_CASE("BinaryTfIdfEncodingIndividualCharactersTest", "[StringEncodingTest]") * sublinear term frequency type and the smooth inverse document frequency * type. */ -TEST_CASE("SublinearSmoothIdfEncodingIndividualCharactersTest", "[StringEncodingTest]") +TEST_CASE("SublinearSmoothIdfEncodingIndividualCharactersTest", + "[StringEncodingTest]") { vector input = { "GACCA", @@ -1253,7 +1262,8 @@ TEST_CASE("SublinearSmoothIdfEncodingIndividualCharactersTest", "[StringEncoding * sublinear term frequency type and the non-smooth inverse document frequency * type. */ -TEST_CASE("SublinearTfIdfEncodingIndividualCharactersTest", "[StringEncodingTest]") +TEST_CASE("SublinearTfIdfEncodingIndividualCharactersTest", + "[StringEncodingTest]") { vector input = { "GACCA", @@ -1285,7 +1295,8 @@ TEST_CASE("SublinearTfIdfEncodingIndividualCharactersTest", "[StringEncodingTest * standard term frequency type and the smooth inverse document frequency * type. */ -TEST_CASE("TermFrequencySmoothIdfEncodingIndividualCharactersTest", "[StringEncodingTest]") +TEST_CASE("TermFrequencySmoothIdfEncodingIndividualCharactersTest", + "[StringEncodingTest]") { vector input = { "GACCA", @@ -1366,7 +1377,8 @@ TEST_CASE("TermFrequencySmoothIdfEncodingIndividualCharactersTest", "[StringEnco * standard term frequency type and the non-smooth inverse document frequency * type. */ -TEST_CASE("TermFrequencyTfIdfEncodingIndividualCharactersTest", "[StringEncodingTest]") +TEST_CASE("TermFrequencyTfIdfEncodingIndividualCharactersTest", + "[StringEncodingTest]") { vector input = { "GACCA",