Skip to content

Commit

Permalink
Merge pull request #8 from mlpack/master
Browse files Browse the repository at this point in the history
updating master
  • Loading branch information
Aakash-kaushik committed Oct 6, 2020
2 parents 871fde3 + d1af492 commit ca26c75
Show file tree
Hide file tree
Showing 25 changed files with 1,571 additions and 1,213 deletions.
1 change: 1 addition & 0 deletions .ci/windows-steps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ steps:
msbuildVersion: $(MSBuildVersion)
configuration: 'Release'
msbuildArchitecture: 'x64'
platform: 'x64'
msbuildArguments: /m /p:BuildInParallel=true
maximumCpuCount: false
clean: false
Expand Down
66 changes: 59 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,31 @@ on:
- master
release:
types: [published, created, edited]
name: R CMD check mlpack

jobs:
cancel:
name: 'Cancel Previous Builds'
if: ${{ github.event_name == 'pull_request' && github.repository == 'mlpack/mlpack' }}
runs-on: ubuntu-latest
timeout-minutes: 3
steps:
- name: Get all workflow ids and set to env variable
run: echo ::set-env name=WORKFLOW_IDS_TO_CANCEL::$(curl https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/workflows -s | jq -r '.workflows | map(.id|tostring) | join(",")')

- uses: styfle/cancel-workflow-action@0.5.0
with:
workflow_id: ${{ env.WORKFLOW_IDS_TO_CANCEL }}
access_token: ${{ secrets.GITHUB_TOKEN }}

jobR:
name: mlpack-R
name: Build mlpack_r_tarball
if: ${{ github.repository == 'mlpack/mlpack' }}
runs-on: ubuntu-20.04

outputs:
r_bindings: ${{ steps.mlpack_version.outputs.mlpack_r_package }}

steps:
- uses: actions/checkout@v2

Expand All @@ -27,16 +45,35 @@ jobs:
MLPACK_VERSION_VALUE=${MLPACK_VERSION_MAJOR}.${MLPACK_VERSION_MINOR}.${MLPACK_VERSION_PATCH}
echo ::set-output name=mlpack_r_package::$(echo mlpack_"$MLPACK_VERSION_VALUE".tar.gz)
- uses: r-lib/actions/setup-r@master
with:
r-version: release

- name: Query dependencies
run: |
cp src/mlpack/bindings/R/mlpack/DESCRIPTION.in DESCRIPTION
Rscript -e "install.packages('remotes')" -e "saveRDS(remotes::dev_package_deps(dependencies = TRUE), 'depends.Rds')"
- name: Cache R packages
if: runner.os != 'Windows'
uses: actions/cache@v1
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-r-release-${{ hashFiles('depends.Rds') }}
restore-keys: ${{ runner.os }}-r-release-

- name: Install Build Dependencies
run: |
sudo apt-get update
sudo apt-get install -y --allow-unauthenticated libopenblas-dev liblapack-dev g++ libboost-all-dev
curl https://data.kurg.org/armadillo-8.400.0.tar.xz | tar -xvJ && cd armadillo*
cmake . && make && sudo make install && cd ..
sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu xenial-cran40/'
sudo apt-get -y update
sudo apt-get install -y r-base-core
sudo Rscript -e "install.packages(c('Rcpp', 'RcppArmadillo', 'RcppEnsmallen', 'BH', 'roxygen2', 'testthat'))"
- name: Install R-bindings dependencies
run: |
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("roxygen2")
shell: Rscript {0}

- name: CMake
run: |
Expand All @@ -58,6 +95,7 @@ jobs:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})
if: ${{ github.repository == 'mlpack/mlpack' }}

strategy:
fail-fast: false
Expand All @@ -74,6 +112,8 @@ jobs:
R_CHECK_ARGS: "--no-build-vignettes"
_R_CHECK_FORCE_SUGGESTS: 0
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: ${{ matrix.config.rspm }}
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/download-artifact@v2
Expand All @@ -86,10 +126,22 @@ jobs:

- uses: r-lib/actions/setup-pandoc@master

- name: Query dependencies
run: Rscript -e "install.packages('remotes')" -e "saveRDS(remotes::dev_package_deps('${{ needs.jobR.outputs.r_bindings }}', dependencies = TRUE), 'depends.Rds')"

- name: Cache R packages
if: runner.os != 'Windows'
uses: actions/cache@v1
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-r-${{ matrix.config.r }}-${{ hashFiles('depends.Rds') }}
restore-keys: ${{ runner.os }}-r-${{ matrix.config.r }}-

- name: Install dependencies
run: |
Rscript -e "install.packages('remotes')" -e "remotes::install_cran('rcmdcheck')"
Rscript -e "install.packages(c('Rcpp', 'RcppArmadillo', 'RcppEnsmallen', 'BH', 'roxygen2', 'testthat'))"
remotes::install_deps('${{ needs.jobR.outputs.r_bindings }}', dependencies = TRUE)
remotes::install_cran("rcmdcheck")
shell: Rscript {0}

- name: Check
run: Rscript -e "rcmdcheck::rcmdcheck('${{ needs.jobR.outputs.r_bindings }}', args = c('--no-manual','--as-cran'), error_on = 'warning', check_dir = 'check')"
Expand Down
2 changes: 2 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
###### ????-??-??
* Added Mean Absolute Percentage Error.

* Added Softmin activation function as layer in ann/layer.

### mlpack 3.4.1
###### 2020-09-07
* Fix incorrect parsing of required matrix/model parameters for command-line
Expand Down
2 changes: 2 additions & 0 deletions src/mlpack/methods/ann/layer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ set(SOURCES
celu_impl.hpp
softshrink.hpp
softshrink_impl.hpp
softmin.hpp
softmin_impl.hpp
)

# Add directory name to sources.
Expand Down
3 changes: 3 additions & 0 deletions src/mlpack/methods/ann/layer/add.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ class Add
//! Get the output size.
size_t OutputSize() const { return outSize; }

//! Get the size of weights.
size_t WeightSize() const { return outSize; }

/**
* Serialize the layer
*/
Expand Down
6 changes: 6 additions & 0 deletions src/mlpack/methods/ann/layer/atrous_convolution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@ class AtrousConvolution
//! Modify the internal Padding layer.
ann::Padding<>& Padding() { return padding; }

//! Get size of the weight matrix.
size_t WeightSize() const
{
return (outSize * inSize * kernelWidth * kernelHeight) + outSize;
}

/**
* Serialize the layer.
*/
Expand Down
1 change: 1 addition & 0 deletions src/mlpack/methods/ann/layer/layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
#include "sequential.hpp"
#include "softshrink.hpp"
#include "softmax.hpp"
#include "softmin.hpp"
#include "spatial_dropout.hpp"
#include "subview.hpp"
#include "transposed_convolution.hpp"
Expand Down
6 changes: 6 additions & 0 deletions src/mlpack/methods/ann/layer/linear.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ class Linear
//! Modify the bias weights of the layer.
OutputDataType& Bias() { return bias; }

//! Get the size of the weights.
size_t WeightSize() const
{
return (inSize * outSize) + outSize;
}

/**
* Serialize the layer
*/
Expand Down
97 changes: 97 additions & 0 deletions src/mlpack/methods/ann/layer/softmin.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/**
* @file methods/ann/layer/softmin.hpp
* @author Aakash Kaushik
*
* Definition of the Softmin class.
*
* 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
* 3-clause BSD license along with mlpack. If not, see
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
*/

#ifndef MLPACK_METHODS_ANN_LAYER_SOFTMIN_HPP
#define MLPACK_METHODS_ANN_LAYER_SOFTMIN_HPP

#include <mlpack/prereqs.hpp>

namespace mlpack {
namespace ann /** Artificial Neural Network. */ {

/**
* Implementation of the Softmin layer. The Softmin function takes as a input
* a vector of K real numbers, rescaling them so that the elements of the
* K-dimensional output vector lie in the range [0, 1] and sum to 1.
*
* @tparam InputDataType Type of the input data (arma::colvec, arma::mat,
* arma::sp_mat or arma::cube).
* @tparam OutputDataType Type of the output data (arma::colvec, arma::mat,
* arma::sp_mat or arma::cube).
*/
template <
typename InputDataType = arma::mat,
typename OutputDataType = arma::mat
>
class Softmin
{
public:
/**
* Create the Softmin object.
*/
Softmin();

/**
* Ordinary feed forward pass of a neural network, evaluating the function
* f(x) by propagating the activity forward through f.
*
* @param input Input data used for evaluating the specified function.
* @param output Resulting output activation.
*/
template<typename InputType, typename OutputType>
void Forward(const InputType& input, OutputType& output);

/**
* Ordinary feed backward pass of a neural network, calculating the function
* f(x) by propagating x backwards through f. Using the results from the feed
* forward pass.
*
* @param input The propagated input activation.
* @param gy The backpropagated error.
* @param g The calculated gradient.
*/
template<typename eT>
void Backward(const arma::Mat<eT>& input,
const arma::Mat<eT>& gy,
arma::Mat<eT>& g);

//! Get the output parameter.
OutputDataType& OutputParameter() const { return outputParameter; }
//! Modify the output parameter.
OutputDataType& OutputParameter() { return outputParameter; }

//! Get the delta.
InputDataType& Delta() const { return delta; }
//! Modify the delta.
InputDataType& Delta() { return delta; }

/**
* Serialize the layer.
*/
template<typename Archive>
void serialize(Archive& /* ar */, const unsigned int /* version */);

private:
//! Locally-stored delta object.
OutputDataType delta;

//! Locally stored output parameter object.
OutputDataType outputParameter;
}; // class Softmin

} // namespace ann
} // namespace mlpack

// Include implementation.
#include "softmin_impl.hpp"

#endif
61 changes: 61 additions & 0 deletions src/mlpack/methods/ann/layer/softmin_impl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* @file methods/ann/layer/softmin_impl.hpp
* @author Aakash Kaushik
*
* Implementation of the Softmin class.
*
* 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
* 3-clause BSD license along with mlpack. If not, see
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
*/
#ifndef MLPACK_METHODS_ANN_LAYER_SOFTMIN_IMPL_HPP
#define MLPACK_METHODS_ANN_LAYER_SOFTMIN_IMPL_HPP

// In case it hasn't yet been included.
#include "softmin.hpp"

namespace mlpack {
namespace ann /** Artificial Neural Network. */ {

template<typename InputDataType, typename OutputDataType>
Softmin<InputDataType, OutputDataType>::Softmin()
{
// Nothing to do here.
}

template<typename InputDataType, typename OutputDataType>
template<typename InputType, typename OutputType>
void Softmin<InputDataType, OutputDataType>::Forward(
const InputType& input,
OutputType& output)
{
InputType inputMin = arma::repmat(arma::min(input,0), input.n_rows, 1);
output = arma::repmat(arma::log(arma::sum(
arma::exp(-(input - inputMin)),0)), input.n_rows, 1);
output = arma::exp(-(input - inputMin) - output);
}

template<typename InputDataType, typename OutputDataType>
template<typename eT>
void Softmin<InputDataType, OutputDataType>::Backward(
const arma::Mat<eT>& input,
const arma::Mat<eT>& gy,
arma::Mat<eT>& g)
{
g = input % (gy - arma::repmat(arma::sum(gy % input), input.n_rows, 1));
}

template<typename InputDataType, typename OutputDataType>
template<typename Archive>
void Softmin<InputDataType, OutputDataType>::serialize(
Archive& /* ar */,
const unsigned int /* version */)
{
// Nothing to do here.
}

} // namespace ann
} // namespace mlpack

#endif
Loading

0 comments on commit ca26c75

Please sign in to comment.