Code Monkey home page Code Monkey logo

rcppmlpack2's People

Contributors

eddelbuettel avatar mhenderson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rcppmlpack2's Issues

Install fail - cannot find mlpack header files

Hi,

I am having an issue installing rcppmlpack2 on rhel 7. The default gcc is v4.8.5 but this is not sufficient for openmp which I require. So I have installed the devtoolset-6 which I enable using the command .

The install seems to choke on the source install of rcppMLPACK. Incidentally, I am able to install rcppMLPACK manually from CRAN successfully.

It seems the rcppMLPACK source is unable to find the mlpack headers in /usr/local/include? I did find that g++6 does not by default check /usr/local/include. Is there a variable I need to set that will solve this. I have tried CFLAGS, CPLUS_FLAGS, MLPACK_CFLAGS, MLPACK_CPPFLAGS. I have even tried setting gcc, g++, cpp aliases to include the library path like -I/usr/local/include. However, I am unable to get the build/install to work. Any help appreciated.

My sessionInfo:

> sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux

Matrix products: default
BLAS/LAPACK: /usr/lib64/R/lib/libRblas.so

locale:
 [1] LC_CTYPE=en_AU.UTF-8       LC_NUMERIC=C               LC_TIME=en_AU.UTF-8        LC_COLLATE=en_AU.UTF-8     LC_MONETARY=en_AU.UTF-8    LC_MESSAGES=en_AU.UTF-8   
 [7] LC_PAPER=en_AU.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_AU.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.0        rstudioapi_0.8    magrittr_1.5      usethis_1.4.0     devtools_2.0.1    pkgload_1.0.2     R6_2.3.0          rlang_0.3.0.1     tools_3.5.1      
[10] pkCould yougbuild_1.0.2    sessioninfo_1.1.1 cli_1.0.1         withr_2.1.2       remotes_2.0.2     assertthat_0.2.0  digest_0.6.18     rprojroot_1.3-2   crayon_1.3.4     
[19] processx_3.2.0    callr_3.0.0       base64enc_0.1-3   fs_1.2.6          ps_1.2.1          curl_3.2          memoise_1.1.0     glue_1.3.0        compiler_3.5.1   
[28] desc_1.2.0        backports_1.1.2   prettyunits_1.0.2

The output from the install is below:

> devtools::install_github("rcppmlpack/rcppmlpack2")
Downloading GitHub repo rcppmlpack/rcppmlpack2@master
✔  checking for file ‘/tmp/RtmpTGbarz/remotes691f797e3951/rcppmlpack-rcppmlpack2-4af4b01/DESCRIPTION’ ...
─  preparing ‘RcppMLPACK’:
✔  checking DESCRIPTION meta-information ...
─  cleaning src
─  running ‘cleanup’
─  checking for LF line-endings in source and make files and shell scripts
─  checking for empty or unneeded directories
─  looking to see if a ‘data/datalist’ file should be added
─  building ‘RcppMLPACK_3.0.1-0.0.tar.gz’
   
Installing package into ‘/root/R/x86_64-pc-linux-gnu-library/3.5.1’
(as ‘lib’ is unspecified)
* installing *source* package ‘RcppMLPACK’ ...
checking whether the C++ compiler works... yes
checking for C++ compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking how to run the C++ preprocessor... g++ -E
checking for gcc... gcc
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether we are using the GNU C++ compiler... (cached) yes
checking whether g++ accepts -g... (cached) yes
checking whether g++ supports C++11 features by default... yes
checking for pkg-config... yes
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking mlpack/core.hpp usability... no
checking mlpack/core.hpp presence... no
checking for mlpack/core.hpp... no
configure: error: Cannot find MLPACK headers.
ERROR: configuration failed for package ‘RcppMLPACK’
* removing ‘/root/R/x86_64-pc-linux-gnu-library/3.5.1/RcppMLPACK’
* restoring previous ‘/root/R/x86_64-pc-linux-gnu-library/3.5.1/RcppMLPACK’
Error in i.p(...) : 
  (converted from warning) installation of package ‘/tmp/RtmpTGbarz/file691f4fd5f752/RcppMLPACK_3.0.1-0.0.tar.gz’ had non-zero exit status

Rcpp Gallery write-up draft

Poking @thirdwing @coatless @MHenderson : if you have a moment, can you read across this before I post this to the Rcpp Gallery. I have a two-day streak going on new posts, and the day off so I figured I may as well :) In all seriousness, I think it is time to beat the drum a bit more for RcppMLPACK{1,2} and to sort out where we go with RcppMLPACK2.


title: "RcppMLPACK2 and the MLPACK Machine Learning Library"
author: "Dirk Eddelbuettel"
license: GPL (>= 2)
tags: machine_learning armadillo mlpack
summary: "RcppMLPACK2 bring access to MLPACK to R"

mlpack

mlpack is, to quote, a scalable machine learning library, written in C++,
that aims to provide fast, extensible implementations of cutting-edge machine learning
algorithms
. It has been written by Ryan Curtin and others, and is
described in two papers in BigLearning (2011) and
JMLR (2013). mlpack uses
Armadillo as the underlying linear algebra library, which, thanks to
RcppArmadillo, is already a rather
well-known library in the R ecosystem.

RcppMLPACK1

Qiang Kou has created the
RcppMLPACK package on CRAN for easy-to-use
integration of mlpack with R. It integrates the
mlpack sources, and is, as a CRAN package, widely available on all
platforms.

However, this RcppMLPACK package is also based on a
by-now dated version of mlpack. Quoting again: mlpack provides these
algorithms as simple command-line programs and C++ classes which can then be integrated into
larger-scale machine learning solutions.
Version 2 of the mlpack sources
switched to a slightly more encompassing build also requiring the Boost
libraries 'program_options', 'unit_test_framework' and 'serialization'. Within the context of an R
package, we could condition out the first two as R provides both the direct interface (hence no need
to parse command-line options) and also the testing framework. However, it would be both difficult
and potentially undesirable to condition out the serialization which allows
mlpack to store and resume machine learning tasks.

We refer to this version now as RcppMLPACK1.

RcppMLPACK2

As of February 2017, the current version of mlpack is 2.1.1. As it
requires external linking with (some) Boost libraries as well as with
Armadillo, we have created a new package
RcppMLPACK2 inside a new
GitHub organization RcppMLPACK.

Linux

This package works fine on Linux provided mlpack,
Armadillo and Boost are installed.

OS X / macOS

For maxOS / OS X, James Balamuta has tried to set up a homebrew
recipe but there are some tricky interaction with the compiler suites used by both brew and R on
macOS.

Windows

For Windows, one could do what Jeroen Ooms has done and build
(external) libraries. Volunteers are encouraged to get in touch via the issue tickets at GitHub.

Example: Logistic Regression

To illustrate mlpack we show a first simple example also included in the
package. As the rest of the Rcpp Gallery, these are "live" code examples.


#include <RcppMLPACK.h>				// MLPACK, Rcpp and RcppArmadillo

#include <mlpack/methods/logistic_regression/logistic_regression.hpp> 	// particular algorithm used here

// [[Rcpp::depends(RcppMLPACK)]]

// [[Rcpp::export]]
Rcpp::List logisticRegression(const arma::mat& train,
                              const arma::irowvec& labels,
                              const Rcpp::Nullable<Rcpp::NumericMatrix>& test = R_NilValue) {
    
    // MLPACK wants Row<size_t> which is an unsigned representation
    // that R does not have
    arma::Row<size_t> labelsur, resultsur;

    // TODO: check that all values are non-negative
    labelsur = arma::conv_to<arma::Row<size_t>>::from(labels);

    // Initialize with the default arguments.
    // TODO: support more arguments>
    mlpack::regression::LogisticRegression<> lrc(train, labelsur);
    
    arma::vec parameters = lrc.Parameters();

    Rcpp::List return_val;
    
    if (test.isNotNull()) {
        arma::mat test2 = Rcpp::as<arma::mat>(test);
        lrc.Classify(test2, resultsur);
        arma::vec results = arma::conv_to<arma::vec>::from(resultsur);
        return_val = Rcpp::List::create(Rcpp::Named("parameters") = parameters,
                                        Rcpp::Named("results") = results);
    } else {
        return_val = Rcpp::List::create(Rcpp::Named("parameters") = parameters);
    }

    return return_val;

}

We can then call this function with the same (trivial) data set as used in the first unit test for
it:

logisticRegression(matrix(c(1, 2, 3, 1, 2, 3), nrow=2, byrow=TRUE), c(1L, 1L, 0L))

Example: Naive Bayes Classifier

A second examples shows the NaiveBayesClassifier class.

#include <RcppMLPACK.h>				// MLPACK, Rcpp and RcppArmadillo

#include <mlpack/methods/naive_bayes/naive_bayes_classifier.hpp> 	// particular algorithm used here

// [[Rcpp::depends(RcppMLPACK)]]

// [[Rcpp::export]]
arma::irowvec naiveBayesClassifier(const arma::mat& train,
                                   const arma::mat& test,
                                   const arma::irowvec& labels,
                                   const int& classes) {
    
    // MLPACK wants Row<size_t> which is an unsigned representation
    // that R does not have
    arma::Row<size_t> labelsur, resultsur;

    // TODO: check that all values are non-negative
    labelsur = arma::conv_to<arma::Row<size_t>>::from(labels);

    // Initialize with the default arguments.
    // TODO: support more arguments>
    mlpack::naive_bayes::NaiveBayesClassifier<> nbc(train, labelsur, classes);
    
    nbc.Classify(test, resultsur);
    
    arma::irowvec results = arma::conv_to<arma::irowvec>::from(resultsur);
    
    return results;
}

I also placed the (locally rendered) version here for now

Support plugins

Under this version:

R> sourceCpp("/tmp/mlpackError.cpp")
Error in tools::file_path_as_absolute(base::system.file(..., package = "RcppMLPACK")) : 
  file '' does not exist
R> 

Examples need roxygen docs

We currently only export mlKmeans which is the only function with a (short) manual page.

I'll work on extending this.

Binaries for macOS + Windows

So, it looks like a binary approach is going to be used for both of the methods.

Before, we were opting to just hook into the homebrew version of MLPACK. However, that is compiled under libstd++ vs. libc++, which is how R is compiled on macOS.

Target: Next weekend.

Compiling of dependancies on Mac OS

As mentioned in the README there is an issue with compiling of the dependancy "RcppArmadillo" on Mac OS (for R versions 3.0 and above). This is due to a mismatch in gfortran versions for the package and used to compile R itself. The solution is well described here: https://thecoatlessprofessor.com/programming/rcpp-rcpparmadillo-and-os-x-mavericks--lgfortran-and--lquadmath-error/

While this ultimately a dependency issue, it would help those encountering this issue to direct them to this. Perhaps in the README?

While I've managed to install RcppArmadillo on my system, I worry that it is such an inconvenience to R users on Mac OS that I am reconsidering to include functions dependent on it in my package.

Can't install rcppmlpack2

When I try to install and load the package I get the following message.

devtools::install_github("rcppmlpack/rcppmlpack2")
#>Error: package or namespace load failed for ‘RcppMLPACK’ in dyn.load(file, DLLpath = DLLpath, ...):
#>unable to load shared object #>'/Users/jakobjulelben/Library/R/3.4/library/RcppMLPACK/libs/RcppMLPACK.so':
#>dlopen(/Users/jakobjulelben/Library/R/3.4/library/RcppMLPACK/libs/RcppMLPACK.so, 6): Library not #>loaded: libmlpack.2.dylib
#> Referenced from: /Users/jakobjulelben/Library/R/3.4/library/RcppMLPACK/libs/RcppMLPACK.so
#> Reason: image not found
#>Error: loading failed
#>Execution halted
Session info
devtools::session_info()
#> Session info -------------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.4.0 (2017-04-21)
#>  system   x86_64, darwin15.6.0        
#>  ui       X11                         
#>  language (EN)                        
#>  collate  en_US.UTF-8                 
#>  tz       Europe/Copenhagen           
#>  date     2017-08-15
#> Packages -----------------------------------------------------------------
#>  package   * version date       source         
#>  backports   1.0.5   2017-01-18 cran (@1.0.5)  
#>  base      * 3.4.0   2017-04-21 local          
#>  compiler    3.4.0   2017-04-21 local          
#>  curl        2.8.1   2017-07-21 cran (@2.8.1)  
#>  datasets  * 3.4.0   2017-04-21 local          
#>  devtools    1.13.0  2017-05-08 CRAN (R 3.4.0) 
#>  digest      0.6.12  2017-01-27 CRAN (R 3.4.0) 
#>  evaluate    0.10    2016-10-11 cran (@0.10)   
#>  git2r       0.18.0  2017-01-01 CRAN (R 3.4.0) 
#>  graphics  * 3.4.0   2017-04-21 local          
#>  grDevices * 3.4.0   2017-04-21 local          
#>  htmltools   0.3.6   2017-04-28 cran (@0.3.6)  
#>  httr        1.2.1   2016-07-03 CRAN (R 3.4.0) 
#>  knitr       1.16    2017-05-18 cran (@1.16)   
#>  magrittr    1.5     2014-11-22 CRAN (R 3.4.0) 
#>  memoise     1.1.0   2017-04-21 CRAN (R 3.4.0) 
#>  methods   * 3.4.0   2017-04-21 local          
#>  R6          2.2.2   2017-06-17 cran (@2.2.2)  
#>  Rcpp        0.12.12 2017-07-15 cran (@0.12.12)
#>  rmarkdown   1.6     2017-06-15 cran (@1.6)    
#>  rprojroot   1.2     2017-01-16 cran (@1.2)    
#>  stats     * 3.4.0   2017-04-21 local          
#>  stringi     1.1.5   2017-04-07 cran (@1.1.5)  
#>  stringr     1.2.0   2017-02-18 CRAN (R 3.4.0) 
#>  tools       3.4.0   2017-04-21 local          
#>  utils     * 3.4.0   2017-04-21 local          
#>  withr       1.0.2   2016-06-20 CRAN (R 3.4.0) 
#>  yaml        2.1.14  2016-11-12 cran (@2.1.14)

Best regards,
Jakob

API commonalities ?

How do we want the top-level functions?

Even in the two uses case in the gallery we have one with test data (the naive Bayes classifier) and one without. Should be always have a Rcpp::Nullable<> test set?

can't install from source

My operating system is Ubuntu. When I tried to install rcppmlpack2 from source, after I ran ./configure, I ran make. However, it told me there is no file to be make. Could you please give me some advice? Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.