1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2015 Ricardo Wurmus <rekado@elephly.net>
4 ;;; This file is part of GNU Guix.
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (gnu packages machine-learning)
20 #:use-module ((guix licenses) #:prefix license:)
21 #:use-module (guix packages)
22 #:use-module (guix utils)
23 #:use-module (guix download)
24 #:use-module (guix build-system cmake)
25 #:use-module (guix build-system gnu)
26 #:use-module (guix build-system r)
27 #:use-module (gnu packages)
28 #:use-module (gnu packages boost)
29 #:use-module (gnu packages compression)
30 #:use-module (gnu packages gcc)
31 #:use-module (gnu packages maths)
32 #:use-module (gnu packages pkg-config)
33 #:use-module (gnu packages python)
34 #:use-module (gnu packages statistics)
35 #:use-module (gnu packages swig)
36 #:use-module (gnu packages xml))
46 "https://github.com/cjlin1/libsvm/archive/v"
47 (string-delete #\. version) ".tar.gz"))
48 (file-name (string-append name "-" version ".tar.gz"))
51 "1jpjlql3frjza7zxzrqqr2firh44fjb8fqsdmvz6bjz7sb47zgp4"))))
52 (build-system gnu-build-system)
54 `(#:tests? #f ;no "check" target
55 #:phases (modify-phases %standard-phases
59 (lambda* (#:key outputs #:allow-other-keys)
60 (let* ((out (assoc-ref outputs "out"))
61 (bin (string-append out "/bin/")))
63 (for-each (lambda (file)
64 (copy-file file (string-append bin file)))
69 (home-page "http://www.csie.ntu.edu.tw/~cjlin/libsvm/")
70 (synopsis "Library for Support Vector Machines")
72 "LIBSVM is a machine learning library for support vector
73 classification, (C-SVC, nu-SVC), regression (epsilon-SVR, nu-SVR) and
74 distribution estimation (one-class SVM). It supports multi-class
76 (license license:bsd-3)))
78 (define-public python-libsvm
79 (package (inherit libsvm)
80 (name "python-libsvm")
81 (build-system gnu-build-system)
83 `(#:tests? #f ;no "check" target
84 #:make-flags '("-C" "python")
86 (modify-phases %standard-phases
90 (lambda* (#:key inputs outputs #:allow-other-keys)
91 (let ((site (string-append (assoc-ref outputs "out")
95 (assoc-ref inputs "python") 5) 3)
97 (substitute* "python/svm.py"
98 (("../libsvm.so.2") "libsvm.so.2"))
100 (for-each (lambda (file)
101 (copy-file file (string-append site (basename file))))
102 (find-files "python" "\\.py"))
103 (copy-file "libsvm.so.2"
104 (string-append site "libsvm.so.2")))
107 `(("python" ,python)))
108 (synopsis "Python bindings of libSVM")))
110 (define-public randomjungle
112 (name "randomjungle")
118 "http://www.imbs-luebeck.de/imbs/sites/default/files/u59/"
119 "randomjungle-" version ".tar_.gz"))
122 "12c8rf30cla71swx2mf4ww9mfd8jbdw5lnxd7dxhyw1ygrvg6y4w"))))
123 (build-system gnu-build-system)
126 (list (string-append "--with-boost="
127 (assoc-ref %build-inputs "boost")))
129 (modify-phases %standard-phases
131 'configure 'set-CXXFLAGS
133 (setenv "CXXFLAGS" "-fpermissive ")
141 `(("gfortran" ,gfortran)))
142 (home-page "http://www.imbs-luebeck.de/imbs/de/node/227/")
143 (synopsis "Implementation of the Random Forests machine learning method")
145 "Random Jungle is an implementation of Random Forests. It is supposed to
146 analyse high dimensional data. In genetics, it can be used for analysing big
147 Genome Wide Association (GWA) data. Random Forests is a powerful machine
148 learning method. Most interesting features are variable selection, missing
149 value imputation, classifier creation, generalization error estimation and
150 sample proximities between pairs of cases.")
151 (license license:gpl3+)))
153 (define-public shogun
161 "ftp://shogun-toolbox.org/shogun/releases/"
162 (version-major+minor version)
163 "/sources/shogun-" version ".tar.bz2"))
166 "159nlijnb7mnrv9za80wnm1shwvy45hgrqzn51hxy7gw4z6d6fdb"))
167 (modules '((guix build utils)
171 ;; Remove non-free sources and files referencing them
172 (for-each delete-file
173 (find-files "src/shogun/classifier/svm/"
174 "SVMLight\\.(cpp|h)"))
175 (for-each delete-file
176 (find-files "examples/undocumented/libshogun/"
178 "(classifier_.*svmlight.*|"
179 "evaluation_cross_validation_locked_comparison).cpp")))
180 ;; Remove non-free functions.
181 (define (delete-ifdefs file)
182 (with-atomic-file-replacement file
184 (let loop ((line (read-line in 'concat))
186 (if (eof-object? line)
191 "#endif //USE_SVMLIGHT" line)))
193 "#ifdef USE_SVMLIGHT" line))))
194 (when (or (not skipping?)
195 (and skipping? (not skip-next?)))
197 (loop (read-line in 'concat) skip-next?)))))))
198 (for-each delete-ifdefs (find-files "src/shogun/kernel/"
199 "^Kernel\\.(cpp|h)"))))))
200 (build-system cmake-build-system)
202 '(#:tests? #f ;no check target
205 'unpack 'delete-broken-symlinks
207 (for-each delete-file '("applications/arts/data"
208 "applications/asp/data"
209 "applications/easysvm/data"
210 "applications/msplicer/data"
211 "applications/ocr/data"
212 "examples/documented/data"
213 "examples/documented/matlab_static"
214 "examples/documented/octave_static"
215 "examples/undocumented/data"
216 "examples/undocumented/matlab_static"
217 "examples/undocumented/octave_static"
218 "tests/integration/data"
219 "tests/integration/matlab_static"
220 "tests/integration/octave_static"
221 "tests/integration/python_modular/tests"))
224 'unpack 'change-R-target-path
225 (lambda* (#:key outputs #:allow-other-keys)
226 (substitute* '("src/interfaces/r_modular/CMakeLists.txt"
227 "src/interfaces/r_static/CMakeLists.txt"
228 "examples/undocumented/r_modular/CMakeLists.txt")
229 (("\\$\\{R_COMPONENT_LIB_PATH\\}")
230 (string-append (assoc-ref outputs "out")
234 'unpack 'fix-octave-modules
235 (lambda* (#:key outputs #:allow-other-keys)
236 (substitute* '("src/interfaces/octave_modular/CMakeLists.txt"
237 "src/interfaces/octave_static/CMakeLists.txt")
238 (("^include_directories\\(\\$\\{OCTAVE_INCLUDE_DIRS\\}")
239 "include_directories(${OCTAVE_INCLUDE_DIRS} ${OCTAVE_INCLUDE_DIRS}/octave"))
241 ;; change target directory
242 (substitute* "src/interfaces/octave_modular/CMakeLists.txt"
243 (("\\$\\{OCTAVE_OCT_LOCAL_API_FILE_DIR\\}")
244 (string-append (assoc-ref outputs "out")
245 "/share/octave/packages")))
249 ;; $HOME needs to be set at some point during the build phase
250 (lambda _ (setenv "HOME" "/tmp") #t)
253 (list "-DCMAKE_BUILD_WITH_INSTALL_RPATH=TRUE"
254 "-DUSE_SVMLIGHT=OFF" ;disable proprietary SVMLIGHT
255 ;;"-DJavaModular=ON" ;requires unpackaged jblas
256 ;;"-DRubyModular=ON" ;requires unpackaged ruby-narray
257 ;;"-DPerlModular=ON" ;"FindPerlLibs" does not exist
258 ;;"-DLuaModular=ON" ;fails because lua doesn't build pkgconfig file
265 "-DCmdLineStatic=ON")))
268 ("numpy" ,python-numpy)
274 ("arpack" ,arpack-ng)
281 `(("pkg-config" ,pkg-config)))
282 ;; Non-portable SSE instructions are used so building fails on platforms
283 ;; other than x86_64.
284 (supported-systems '("x86_64-linux"))
285 (home-page "http://shogun-toolbox.org/")
286 (synopsis "Machine learning toolbox")
288 "The Shogun Machine learning toolbox provides a wide range of unified and
289 efficient Machine Learning (ML) methods. The toolbox seamlessly allows to
290 combine multiple data representations, algorithm classes, and general purpose
291 tools. This enables both rapid prototyping of data pipelines and extensibility
292 in terms of new algorithms.")
293 (license license:gpl3+)))
295 (define-public r-adaptivesparsity
297 (name "r-adaptivesparsity")
301 (uri (cran-uri "AdaptiveSparsity" version))
304 "1az7isvalf3kmdiycrfl6s9k9xqk22k1mc6rh8v0jmcz402qyq8z"))))
306 `((upstream-name . "AdaptiveSparsity")))
307 (build-system r-build-system)
310 (modify-phases %standard-phases
311 (add-after 'unpack 'link-against-armadillo
313 (substitute* "src/Makevars"
314 (("PKG_LIBS=" prefix)
315 (string-append prefix "-larmadillo"))))))))
318 ("r-rcpparmadillo" ,r-rcpparmadillo)))
319 (home-page "http://cran.r-project.org/web/packages/AdaptiveSparsity")
320 (synopsis "Adaptive sparsity models")
322 "This package implements the Figueiredo machine learning algorithm for
323 adaptive sparsity and the Wong algorithm for adaptively sparse gaussian
325 (license license:lgpl3+)))