1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2015, 2016 Ricardo Wurmus <rekado@elephly.net>
3 ;;; Copyright © 2016 Efraim Flashner <efraim@flashner.co.il>
4 ;;; Copyright © 2016 Marius Bakke <mbakke@fastmail.com>
6 ;;; This file is part of GNU Guix.
8 ;;; GNU Guix is free software; you can redistribute it and/or modify it
9 ;;; under the terms of the GNU General Public License as published by
10 ;;; the Free Software Foundation; either version 3 of the License, or (at
11 ;;; your option) any later version.
13 ;;; GNU Guix is distributed in the hope that it will be useful, but
14 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;;; GNU General Public License for more details.
18 ;;; You should have received a copy of the GNU General Public License
19 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
21 (define-module (gnu packages machine-learning)
22 #:use-module ((guix licenses) #:prefix license:)
23 #:use-module (guix packages)
24 #:use-module (guix utils)
25 #:use-module (guix download)
26 #:use-module (guix svn-download)
27 #:use-module (guix build-system cmake)
28 #:use-module (guix build-system gnu)
29 #:use-module (guix build-system ocaml)
30 #:use-module (guix build-system r)
31 #:use-module (gnu packages)
32 #:use-module (gnu packages autotools)
33 #:use-module (gnu packages boost)
34 #:use-module (gnu packages compression)
35 #:use-module (gnu packages cran)
36 #:use-module (gnu packages dejagnu)
37 #:use-module (gnu packages gcc)
38 #:use-module (gnu packages image)
39 #:use-module (gnu packages maths)
40 #:use-module (gnu packages ocaml)
41 #:use-module (gnu packages perl)
42 #:use-module (gnu packages pkg-config)
43 #:use-module (gnu packages python)
44 #:use-module (gnu packages statistics)
45 #:use-module (gnu packages swig)
46 #:use-module (gnu packages xml)
47 #:use-module (gnu packages xorg))
57 "https://github.com/cjlin1/libsvm/archive/v"
58 (string-delete #\. version) ".tar.gz"))
59 (file-name (string-append name "-" version ".tar.gz"))
62 "1jpjlql3frjza7zxzrqqr2firh44fjb8fqsdmvz6bjz7sb47zgp4"))))
63 (build-system gnu-build-system)
65 `(#:tests? #f ;no "check" target
66 #:phases (modify-phases %standard-phases
70 (lambda* (#:key outputs #:allow-other-keys)
71 (let* ((out (assoc-ref outputs "out"))
72 (bin (string-append out "/bin/")))
74 (for-each (lambda (file)
75 (copy-file file (string-append bin file)))
80 (home-page "http://www.csie.ntu.edu.tw/~cjlin/libsvm/")
81 (synopsis "Library for Support Vector Machines")
83 "LIBSVM is a machine learning library for support vector
84 classification, (C-SVC, nu-SVC), regression (epsilon-SVR, nu-SVR) and
85 distribution estimation (one-class SVM). It supports multi-class
87 (license license:bsd-3)))
89 (define-public python-libsvm
90 (package (inherit libsvm)
91 (name "python-libsvm")
92 (build-system gnu-build-system)
94 `(#:tests? #f ;no "check" target
95 #:make-flags '("-C" "python")
97 (modify-phases %standard-phases
101 (lambda* (#:key inputs outputs #:allow-other-keys)
102 (let ((site (string-append (assoc-ref outputs "out")
106 (assoc-ref inputs "python") 5) 3)
108 (substitute* "python/svm.py"
109 (("../libsvm.so.2") "libsvm.so.2"))
111 (for-each (lambda (file)
112 (copy-file file (string-append site (basename file))))
113 (find-files "python" "\\.py"))
114 (copy-file "libsvm.so.2"
115 (string-append site "libsvm.so.2")))
118 `(("python" ,python)))
119 (synopsis "Python bindings of libSVM")))
122 ;; The latest release candidate is several years and a couple of fixes have
123 ;; been published since. This is why we download the sources from the SVN
125 (let ((svn-revision 2341))
128 (version (string-append "0.9-rc3-0." (number->string svn-revision)))
132 (url "http://svn.code.sf.net/p/ghmm/code/trunk")
133 (revision svn-revision)))
134 (file-name (string-append name "-" version))
137 "0qbq1rqp94l530f043qzp8aw5lj7dng9wq0miffd7spd1ff638wq"))))
138 (build-system gnu-build-system)
140 `(#:imported-modules (,@%gnu-build-system-modules
141 (guix build python-build-system))
143 (modify-phases %standard-phases
144 (add-after 'unpack 'enter-dir
145 (lambda _ (chdir "ghmm") #t))
147 (add-after 'install 'check
148 (assoc-ref %standard-phases 'check))
149 (add-before 'check 'fix-PYTHONPATH
150 (lambda* (#:key inputs outputs #:allow-other-keys)
151 (let ((python-version ((@@ (guix build python-build-system)
153 (assoc-ref inputs "python"))))
155 (string-append (getenv "PYTHONPATH")
156 ":" (assoc-ref outputs "out")
157 "/lib/python" python-version
160 (add-after 'enter-dir 'fix-runpath
161 (lambda* (#:key outputs #:allow-other-keys)
162 (substitute* "ghmmwrapper/setup.py"
163 (("^(.*)extra_compile_args = \\[" line indent)
164 (string-append indent
165 "extra_link_args = [\"-Wl,-rpath="
166 (assoc-ref outputs "out") "/lib\"],\n"
169 (assoc-ref outputs "out")
172 (add-after 'enter-dir 'disable-broken-tests
174 (substitute* "tests/Makefile.am"
175 ;; GHMM_SILENT_TESTS is assumed to be a command.
176 (("TESTS_ENVIRONMENT.*") "")
177 ;; Do not build broken tests.
181 (("label_higher_order_test.*$")
182 "label_higher_order_test\n"))
184 ;; These Python unittests are broken as there is no gato.
185 ;; See https://sourceforge.net/p/ghmm/support-requests/3/
186 (substitute* "ghmmwrapper/ghmmunittests.py"
187 (("^(.*)def (testNewXML|testMultipleTransitionClasses|testNewXML)"
189 (string-append indent
190 "@unittest.skip(\"Disabled by Guix\")\n"
193 (add-before 'configure 'autogen
195 (zero? (system* "bash" "./autogen.sh")))))))
197 `(("python" ,python-2) ; only Python 2 is supported
198 ("libxml2" ,libxml2)))
200 `(("pkg-config" ,pkg-config)
203 ("autoconf" ,autoconf)
204 ("automake" ,automake)
205 ("libtool" ,libtool)))
206 (home-page "http://ghmm.org")
207 (synopsis "Hidden Markov Model library")
209 "The General Hidden Markov Model library (GHMM) is a C library with
210 additional Python bindings implementing a wide range of types of @dfn{Hidden
211 Markov Models} (HMM) and algorithms: discrete, continuous emissions, basic
212 training, HMM clustering, HMM mixtures.")
213 (license license:lgpl2.0+))))
222 "http://micans.org/mcl/src/mcl-"
223 (string-replace-substring version "." "-")
227 "15xlax3z31lsn62vlg94hkm75nm40q4679amnfg13jm8m2bnhy5m"))))
228 (build-system gnu-build-system)
230 `(#:configure-flags (list "--enable-blast")))
233 (home-page "http://micans.org/mcl/")
234 (synopsis "Clustering algorithm for graphs")
236 "The MCL algorithm is short for the @dfn{Markov Cluster Algorithm}, a
237 fast and scalable unsupervised cluster algorithm for graphs (also known as
238 networks) based on simulation of (stochastic) flow in graphs.")
239 ;; In the LICENCE file and web page it says "The software is licensed
240 ;; under the GNU General Public License, version 3.", but in several of
241 ;; the source code files it suggests GPL3 or later.
242 ;; http://listserver.ebi.ac.uk/pipermail/mcl-users/2016/000376.html
243 (license license:gpl3)))
245 (define-public ocaml-mcl
248 (version "12-068oasis4")
253 "https://github.com/fhcrc/mcl/archive/"
255 (file-name (string-append name "-" version ".tar.gz"))
258 "1l5jbhwjpsj38x8b9698hfpkv75h8hn3kj0gihjhn8ym2cwwv110"))))
259 (build-system ocaml-build-system)
262 (modify-phases %standard-phases
263 (add-before 'configure 'patch-paths
265 (substitute* "configure"
266 (("SHELL = /bin/sh") (string-append "SHELL = "(which "sh"))))
267 (substitute* "setup.ml"
269 (string-append "LDFLAGS=-fPIC\"; \"SHELL=" (which "sh"))))
271 (home-page "https://github.com/fhcrc/mcl")
272 (synopsis "OCaml wrappers around MCL")
274 "This package provides OCaml bindings for the MCL graph clustering
276 (license license:gpl3)))
278 (define-public ocaml4.01-mcl
279 (package-with-ocaml4.01 ocaml-mcl))
281 (define-public randomjungle
283 (name "randomjungle")
289 "http://www.imbs-luebeck.de/imbs/sites/default/files/u59/"
290 "randomjungle-" version ".tar_.gz"))
293 "12c8rf30cla71swx2mf4ww9mfd8jbdw5lnxd7dxhyw1ygrvg6y4w"))))
294 (build-system gnu-build-system)
297 (list (string-append "--with-boost="
298 (assoc-ref %build-inputs "boost")))
300 (modify-phases %standard-phases
302 'configure 'set-CXXFLAGS
304 (setenv "CXXFLAGS" "-fpermissive ")
312 `(("gfortran" ,gfortran)
313 ("gfortran:lib" ,gfortran "lib")))
314 ;; Non-portable assembly instructions are used so building fails on
315 ;; platforms other than x86_64 or i686.
316 (supported-systems '("x86_64-linux" "i686-linux"))
317 (home-page "http://www.imbs-luebeck.de/imbs/de/node/227/")
318 (synopsis "Implementation of the Random Forests machine learning method")
320 "Random Jungle is an implementation of Random Forests. It is supposed to
321 analyse high dimensional data. In genetics, it can be used for analysing big
322 Genome Wide Association (GWA) data. Random Forests is a powerful machine
323 learning method. Most interesting features are variable selection, missing
324 value imputation, classifier creation, generalization error estimation and
325 sample proximities between pairs of cases.")
326 (license license:gpl3+)))
328 (define-public shogun
336 "ftp://shogun-toolbox.org/shogun/releases/"
337 (version-major+minor version)
338 "/sources/shogun-" version ".tar.bz2"))
341 "159nlijnb7mnrv9za80wnm1shwvy45hgrqzn51hxy7gw4z6d6fdb"))
342 (modules '((guix build utils)
346 ;; Remove non-free sources and files referencing them
347 (for-each delete-file
348 (find-files "src/shogun/classifier/svm/"
349 "SVMLight\\.(cpp|h)"))
350 (for-each delete-file
351 (find-files "examples/undocumented/libshogun/"
353 "(classifier_.*svmlight.*|"
354 "evaluation_cross_validation_locked_comparison).cpp")))
355 ;; Remove non-free functions.
356 (define (delete-ifdefs file)
357 (with-atomic-file-replacement file
359 (let loop ((line (read-line in 'concat))
361 (if (eof-object? line)
366 "#endif //USE_SVMLIGHT" line)))
368 "#ifdef USE_SVMLIGHT" line))))
369 (when (or (not skipping?)
370 (and skipping? (not skip-next?)))
372 (loop (read-line in 'concat) skip-next?)))))))
373 (for-each delete-ifdefs (find-files "src/shogun/kernel/"
374 "^Kernel\\.(cpp|h)"))))))
375 (build-system cmake-build-system)
377 '(#:tests? #f ;no check target
380 'unpack 'delete-broken-symlinks
382 (for-each delete-file '("applications/arts/data"
383 "applications/asp/data"
384 "applications/easysvm/data"
385 "applications/msplicer/data"
386 "applications/ocr/data"
387 "examples/documented/data"
388 "examples/documented/matlab_static"
389 "examples/documented/octave_static"
390 "examples/undocumented/data"
391 "examples/undocumented/matlab_static"
392 "examples/undocumented/octave_static"
393 "tests/integration/data"
394 "tests/integration/matlab_static"
395 "tests/integration/octave_static"
396 "tests/integration/python_modular/tests"))
399 'unpack 'change-R-target-path
400 (lambda* (#:key outputs #:allow-other-keys)
401 (substitute* '("src/interfaces/r_modular/CMakeLists.txt"
402 "src/interfaces/r_static/CMakeLists.txt"
403 "examples/undocumented/r_modular/CMakeLists.txt")
404 (("\\$\\{R_COMPONENT_LIB_PATH\\}")
405 (string-append (assoc-ref outputs "out")
409 'unpack 'fix-octave-modules
410 (lambda* (#:key outputs #:allow-other-keys)
411 (substitute* '("src/interfaces/octave_modular/CMakeLists.txt"
412 "src/interfaces/octave_static/CMakeLists.txt")
413 (("^include_directories\\(\\$\\{OCTAVE_INCLUDE_DIRS\\}")
414 "include_directories(${OCTAVE_INCLUDE_DIRS} ${OCTAVE_INCLUDE_DIRS}/octave"))
416 ;; change target directory
417 (substitute* "src/interfaces/octave_modular/CMakeLists.txt"
418 (("\\$\\{OCTAVE_OCT_LOCAL_API_FILE_DIR\\}")
419 (string-append (assoc-ref outputs "out")
420 "/share/octave/packages")))
424 ;; $HOME needs to be set at some point during the build phase
425 (lambda _ (setenv "HOME" "/tmp") #t)
428 (list "-DCMAKE_BUILD_WITH_INSTALL_RPATH=TRUE"
429 "-DUSE_SVMLIGHT=OFF" ;disable proprietary SVMLIGHT
430 ;;"-DJavaModular=ON" ;requires unpackaged jblas
431 ;;"-DRubyModular=ON" ;requires unpackaged ruby-narray
432 ;;"-DPerlModular=ON" ;"FindPerlLibs" does not exist
433 ;;"-DLuaModular=ON" ;fails because lua doesn't build pkgconfig file
440 "-DCmdLineStatic=ON")))
443 ("numpy" ,python-numpy)
444 ("r-minimal" ,r-minimal)
449 ("arpack" ,arpack-ng)
456 `(("pkg-config" ,pkg-config)))
457 ;; Non-portable SSE instructions are used so building fails on platforms
458 ;; other than x86_64.
459 (supported-systems '("x86_64-linux"))
460 (home-page "http://shogun-toolbox.org/")
461 (synopsis "Machine learning toolbox")
463 "The Shogun Machine learning toolbox provides a wide range of unified and
464 efficient Machine Learning (ML) methods. The toolbox seamlessly allows to
465 combine multiple data representations, algorithm classes, and general purpose
466 tools. This enables both rapid prototyping of data pipelines and extensibility
467 in terms of new algorithms.")
468 (license license:gpl3+)))
470 (define-public r-adaptivesparsity
472 (name "r-adaptivesparsity")
476 (uri (cran-uri "AdaptiveSparsity" version))
479 "1az7isvalf3kmdiycrfl6s9k9xqk22k1mc6rh8v0jmcz402qyq8z"))))
481 `((upstream-name . "AdaptiveSparsity")))
482 (build-system r-build-system)
485 (modify-phases %standard-phases
486 (add-after 'unpack 'link-against-armadillo
488 (substitute* "src/Makevars"
489 (("PKG_LIBS=" prefix)
490 (string-append prefix "-larmadillo"))))))))
493 ("r-rcpparmadillo" ,r-rcpparmadillo)))
494 (home-page "http://cran.r-project.org/web/packages/AdaptiveSparsity")
495 (synopsis "Adaptive sparsity models")
497 "This package implements the Figueiredo machine learning algorithm for
498 adaptive sparsity and the Wong algorithm for adaptively sparse gaussian
500 (license license:lgpl3+)))
502 (define-public r-kernlab
509 (uri (cran-uri "kernlab" version))
512 "0qnaq9x3j2xc6jrmmd98wc6hkzch487s4p3a9lnc00xvahkhgpmr"))))
513 (build-system r-build-system)
514 (home-page "http://cran.r-project.org/web/packages/kernlab")
515 (synopsis "Kernel-based machine learning tools")
517 "This package provides kernel-based machine learning methods for
518 classification, regression, clustering, novelty detection, quantile regression
519 and dimensionality reduction. Among other methods @code{kernlab} includes
520 Support Vector Machines, Spectral Clustering, Kernel PCA, Gaussian Processes
522 (license license:gpl2)))
531 "http://dlib.net/files/dlib-" version ".tar.bz2"))
534 "0gfy83av717qymv53yv7ki6mgh6mdw4xcxxbjk8lrs72f8qvnrcw"))
535 (modules '((guix build utils)))
538 ;; Delete ~13MB of bundled dependencies.
539 (delete-file-recursively "dlib/external")
540 (delete-file-recursively "docs/dlib/external")
542 (build-system cmake-build-system)
545 (modify-phases %standard-phases
546 (add-after 'unpack 'disable-asserts
548 ;; config.h recommends explicitly enabling or disabling asserts
549 ;; when building as a shared library. By default neither is set.
550 (substitute* "dlib/config.h"
551 (("^//#define DLIB_DISABLE_ASSERTS") "#define DLIB_DISABLE_ASSERTS"))
553 (add-after 'disable-asserts 'disable-failing-tests
555 ;; One test times out on MIPS, so we need to disable it.
556 ;; Others are flaky on some platforms.
557 (let* ((system ,(or (%current-target-system)
559 (disabled-tests (cond
560 ((string-prefix? "mips64" system)
561 '("object_detector" ; timeout
563 ((string-prefix? "armhf" system)
564 '("learning_to_track"))
565 ((string-prefix? "i686" system)
570 (substitute* "dlib/test/makefile"
571 (((string-append "SRC \\+= " test "\\.cpp")) "")))
576 ;; No test target, so we build and run the unit tests here.
577 (let ((test-dir (string-append "../dlib-" ,version "/dlib/test")))
578 (with-directory-excursion test-dir
579 (setenv "CXXFLAGS" "-std=gnu++11")
580 (and (zero? (system* "make" "-j" (number->string (parallel-job-count))))
581 (zero? (system* "./dtest" "--runall")))))))
582 (add-after 'install 'delete-static-library
583 (lambda* (#:key outputs #:allow-other-keys)
584 (delete-file (string-append (assoc-ref outputs "out")
588 `(("pkg-config" ,pkg-config)))
595 ("openblas" ,openblas)
598 "Toolkit for making machine learning and data analysis applications in C++")
600 "Dlib is a modern C++ toolkit containing machine learning algorithms and
601 tools. It is used in both industry and academia in a wide range of domains
602 including robotics, embedded devices, mobile phones, and large high performance
603 computing environments.")
604 (home-page "http://dlib.net")
605 (license license:boost1.0)))