1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2015, 2016, 2017 Ricardo Wurmus <rekado@elephly.net>
3 ;;; Copyright © 2016 Efraim Flashner <efraim@flashner.co.il>
4 ;;; Copyright © 2016, 2017 Marius Bakke <mbakke@fastmail.com>
5 ;;; Copyright © 2016 Hartmut Goebel <h.goebel@crazy-compilers.com>
6 ;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
7 ;;; Copyright © 2018 Mark Meyer <mark@ofosos.org>
8 ;;; Copyright © 2018 Ben Woodcroft <donttrustben@gmail.com>
10 ;;; This file is part of GNU Guix.
12 ;;; GNU Guix is free software; you can redistribute it and/or modify it
13 ;;; under the terms of the GNU General Public License as published by
14 ;;; the Free Software Foundation; either version 3 of the License, or (at
15 ;;; your option) any later version.
17 ;;; GNU Guix is distributed in the hope that it will be useful, but
18 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;;; GNU General Public License for more details.
22 ;;; You should have received a copy of the GNU General Public License
23 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
25 (define-module (gnu packages machine-learning)
26 #:use-module ((guix licenses) #:prefix license:)
27 #:use-module (guix packages)
28 #:use-module (guix utils)
29 #:use-module (guix download)
30 #:use-module (guix svn-download)
31 #:use-module (guix build-system cmake)
32 #:use-module (guix build-system gnu)
33 #:use-module (guix build-system ocaml)
34 #:use-module (guix build-system python)
35 #:use-module (guix build-system r)
36 #:use-module (guix git-download)
37 #:use-module (gnu packages)
38 #:use-module (gnu packages autotools)
39 #:use-module (gnu packages boost)
40 #:use-module (gnu packages check)
41 #:use-module (gnu packages compression)
42 #:use-module (gnu packages cran)
43 #:use-module (gnu packages dejagnu)
44 #:use-module (gnu packages gcc)
45 #:use-module (gnu packages image)
46 #:use-module (gnu packages maths)
47 #:use-module (gnu packages ocaml)
48 #:use-module (gnu packages perl)
49 #:use-module (gnu packages pkg-config)
50 #:use-module (gnu packages python)
51 #:use-module (gnu packages statistics)
52 #:use-module (gnu packages swig)
53 #:use-module (gnu packages xml)
54 #:use-module (gnu packages xorg))
57 ;; The last release is >100 commits behind, so we package from git.
58 (let ((commit "d71d54788bee56ba4cf7522801270152da5209d7"))
61 (version (string-append "2.2.0-1." (string-take commit 8)))
65 (url "https://github.com/libfann/fann.git")
67 (file-name (string-append name "-" version "-checkout"))
70 "0ibwpfrjs6q2lijs8slxjgzb2llcl6rk3v2ski4r6215g5jjhg3x"))))
71 (build-system cmake-build-system)
74 (modify-phases %standard-phases
76 (lambda* (#:key outputs #:allow-other-keys)
77 (let* ((out (assoc-ref outputs "out")))
78 (with-directory-excursion (string-append (getcwd) "/tests")
79 (invoke "./fann_tests"))))))))
80 (home-page "http://leenissen.dk/fann/wp/")
81 (synopsis "Fast Artificial Neural Network")
83 "FANN is a free open source neural network library, which implements
84 multilayer artificial neural networks in C with support for both fully
85 connected and sparsely connected networks.")
86 (license license:lgpl2.1))))
95 (uri (string-append "https://www.csie.ntu.edu.tw/~cjlin/libsvm/"
96 name "-" version ".tar.gz"))
99 "0zd7s19y5vb7agczl6456bn45cj1y64739sslaskw1qk7dywd0bd"))))
100 (build-system gnu-build-system)
102 `(#:tests? #f ;no "check" target
103 #:phases (modify-phases %standard-phases
106 'install ; no ‘install’ target
107 (lambda* (#:key outputs #:allow-other-keys)
108 (let* ((out (assoc-ref outputs "out"))
109 (bin (string-append out "/bin/")))
111 (for-each (lambda (file)
112 (copy-file file (string-append bin file)))
117 (home-page "http://www.csie.ntu.edu.tw/~cjlin/libsvm/")
118 (synopsis "Library for Support Vector Machines")
120 "LIBSVM is a machine learning library for support vector
121 classification, (C-SVC, nu-SVC), regression (epsilon-SVR, nu-SVR) and
122 distribution estimation (one-class SVM). It supports multi-class
124 (license license:bsd-3)))
126 (define-public python-libsvm
127 (package (inherit libsvm)
128 (name "python-libsvm")
129 (build-system gnu-build-system)
131 `(#:tests? #f ;no "check" target
132 #:make-flags '("-C" "python")
134 (modify-phases %standard-phases
137 'install ; no ‘install’ target
138 (lambda* (#:key inputs outputs #:allow-other-keys)
139 (let ((site (string-append (assoc-ref outputs "out")
143 (assoc-ref inputs "python") 5) 3)
145 (substitute* "python/svm.py"
146 (("../libsvm.so.2") "libsvm.so.2"))
148 (for-each (lambda (file)
149 (copy-file file (string-append site (basename file))))
150 (find-files "python" "\\.py"))
151 (copy-file "libsvm.so.2"
152 (string-append site "libsvm.so.2")))
155 `(("python" ,python)))
156 (synopsis "Python bindings of libSVM")))
159 ;; The latest release candidate is several years and a couple of fixes have
160 ;; been published since. This is why we download the sources from the SVN
162 (let ((svn-revision 2341))
165 (version (string-append "0.9-rc3-0." (number->string svn-revision)))
169 (url "http://svn.code.sf.net/p/ghmm/code/trunk")
170 (revision svn-revision)))
171 (file-name (string-append name "-" version))
174 "0qbq1rqp94l530f043qzp8aw5lj7dng9wq0miffd7spd1ff638wq"))))
175 (build-system gnu-build-system)
177 `(#:imported-modules (,@%gnu-build-system-modules
178 (guix build python-build-system))
180 (modify-phases %standard-phases
181 (add-after 'unpack 'enter-dir
182 (lambda _ (chdir "ghmm") #t))
184 (add-after 'install 'check
185 (assoc-ref %standard-phases 'check))
186 (add-before 'check 'fix-PYTHONPATH
187 (lambda* (#:key inputs outputs #:allow-other-keys)
188 (let ((python-version ((@@ (guix build python-build-system)
190 (assoc-ref inputs "python"))))
192 (string-append (getenv "PYTHONPATH")
193 ":" (assoc-ref outputs "out")
194 "/lib/python" python-version
197 (add-after 'enter-dir 'fix-runpath
198 (lambda* (#:key outputs #:allow-other-keys)
199 (substitute* "ghmmwrapper/setup.py"
200 (("^(.*)extra_compile_args = \\[" line indent)
201 (string-append indent
202 "extra_link_args = [\"-Wl,-rpath="
203 (assoc-ref outputs "out") "/lib\"],\n"
206 (assoc-ref outputs "out")
209 (add-after 'enter-dir 'disable-broken-tests
211 (substitute* "tests/Makefile.am"
212 ;; GHMM_SILENT_TESTS is assumed to be a command.
213 (("TESTS_ENVIRONMENT.*") "")
214 ;; Do not build broken tests.
218 (("label_higher_order_test.*$")
219 "label_higher_order_test\n"))
221 ;; These Python unittests are broken as there is no gato.
222 ;; See https://sourceforge.net/p/ghmm/support-requests/3/
223 (substitute* "ghmmwrapper/ghmmunittests.py"
224 (("^(.*)def (testNewXML|testMultipleTransitionClasses|testNewXML)"
226 (string-append indent
227 "@unittest.skip(\"Disabled by Guix\")\n"
230 (add-after 'disable-broken-tests 'autogen
232 (zero? (system* "bash" "autogen.sh")))))))
234 `(("python" ,python-2) ; only Python 2 is supported
235 ("libxml2" ,libxml2)))
237 `(("pkg-config" ,pkg-config)
240 ("autoconf" ,autoconf)
241 ("automake" ,automake)
242 ("libtool" ,libtool)))
243 (home-page "http://ghmm.org")
244 (synopsis "Hidden Markov Model library")
246 "The General Hidden Markov Model library (GHMM) is a C library with
247 additional Python bindings implementing a wide range of types of @dfn{Hidden
248 Markov Models} (HMM) and algorithms: discrete, continuous emissions, basic
249 training, HMM clustering, HMM mixtures.")
250 (license license:lgpl2.0+))))
259 "http://micans.org/mcl/src/mcl-"
260 (string-replace-substring version "." "-")
264 "15xlax3z31lsn62vlg94hkm75nm40q4679amnfg13jm8m2bnhy5m"))))
265 (build-system gnu-build-system)
267 `(#:configure-flags (list "--enable-blast")))
270 (home-page "http://micans.org/mcl/")
271 (synopsis "Clustering algorithm for graphs")
273 "The MCL algorithm is short for the @dfn{Markov Cluster Algorithm}, a
274 fast and scalable unsupervised cluster algorithm for graphs (also known as
275 networks) based on simulation of (stochastic) flow in graphs.")
276 ;; In the LICENCE file and web page it says "The software is licensed
277 ;; under the GNU General Public License, version 3.", but in several of
278 ;; the source code files it suggests GPL3 or later.
279 ;; http://listserver.ebi.ac.uk/pipermail/mcl-users/2016/000376.html
280 (license license:gpl3)))
282 (define-public ocaml-mcl
285 (version "12-068oasis4")
290 "https://github.com/fhcrc/mcl/archive/"
292 (file-name (string-append name "-" version ".tar.gz"))
295 "1l5jbhwjpsj38x8b9698hfpkv75h8hn3kj0gihjhn8ym2cwwv110"))))
296 (build-system ocaml-build-system)
299 (modify-phases %standard-phases
300 (add-before 'configure 'patch-paths
302 (substitute* "configure"
303 (("SHELL = /bin/sh") (string-append "SHELL = "(which "sh"))))
304 (substitute* "setup.ml"
306 (string-append "LDFLAGS=-fPIC\"; \"SHELL=" (which "sh"))))
308 (home-page "https://github.com/fhcrc/mcl")
309 (synopsis "OCaml wrappers around MCL")
311 "This package provides OCaml bindings for the MCL graph clustering
313 (license license:gpl3)))
315 (define-public ocaml4.01-mcl
316 (package-with-ocaml4.01 ocaml-mcl))
318 (define-public randomjungle
320 (name "randomjungle")
326 "http://www.imbs-luebeck.de/imbs/sites/default/files/u59/"
327 "randomjungle-" version ".tar_.gz"))
330 "12c8rf30cla71swx2mf4ww9mfd8jbdw5lnxd7dxhyw1ygrvg6y4w"))))
331 (build-system gnu-build-system)
334 (list (string-append "--with-boost="
335 (assoc-ref %build-inputs "boost")))
337 (modify-phases %standard-phases
339 'configure 'set-CXXFLAGS
341 (setenv "CXXFLAGS" "-fpermissive ")
349 `(("gfortran" ,gfortran)
350 ("gfortran:lib" ,gfortran "lib")))
351 ;; Non-portable assembly instructions are used so building fails on
352 ;; platforms other than x86_64 or i686.
353 (supported-systems '("x86_64-linux" "i686-linux"))
354 (home-page "http://www.imbs-luebeck.de/imbs/de/node/227/")
355 (synopsis "Implementation of the Random Forests machine learning method")
357 "Random Jungle is an implementation of Random Forests. It is supposed to
358 analyse high dimensional data. In genetics, it can be used for analysing big
359 Genome Wide Association (GWA) data. Random Forests is a powerful machine
360 learning method. Most interesting features are variable selection, missing
361 value imputation, classifier creation, generalization error estimation and
362 sample proximities between pairs of cases.")
363 (license license:gpl3+)))
365 (define-public shogun
373 "ftp://shogun-toolbox.org/shogun/releases/"
374 (version-major+minor version)
375 "/sources/shogun-" version ".tar.bz2"))
378 "159nlijnb7mnrv9za80wnm1shwvy45hgrqzn51hxy7gw4z6d6fdb"))
379 (modules '((guix build utils)
383 ;; Remove non-free sources and files referencing them
384 (for-each delete-file
385 (find-files "src/shogun/classifier/svm/"
386 "SVMLight\\.(cpp|h)"))
387 (for-each delete-file
388 (find-files "examples/undocumented/libshogun/"
390 "(classifier_.*svmlight.*|"
391 "evaluation_cross_validation_locked_comparison).cpp")))
392 ;; Remove non-free functions.
393 (define (delete-ifdefs file)
394 (with-atomic-file-replacement file
396 (let loop ((line (read-line in 'concat))
398 (if (eof-object? line)
403 "#endif //USE_SVMLIGHT" line)))
405 "#ifdef USE_SVMLIGHT" line))))
406 (when (or (not skipping?)
407 (and skipping? (not skip-next?)))
409 (loop (read-line in 'concat) skip-next?)))))))
410 (for-each delete-ifdefs (find-files "src/shogun/kernel/"
411 "^Kernel\\.(cpp|h)"))))))
412 (build-system cmake-build-system)
414 '(#:tests? #f ;no check target
416 (modify-phases %standard-phases
417 (add-after 'unpack 'delete-broken-symlinks
419 (for-each delete-file '("applications/arts/data"
420 "applications/asp/data"
421 "applications/easysvm/data"
422 "applications/msplicer/data"
423 "applications/ocr/data"
424 "examples/documented/data"
425 "examples/documented/matlab_static"
426 "examples/documented/octave_static"
427 "examples/undocumented/data"
428 "examples/undocumented/matlab_static"
429 "examples/undocumented/octave_static"
430 "tests/integration/data"
431 "tests/integration/matlab_static"
432 "tests/integration/octave_static"
433 "tests/integration/python_modular/tests"))
435 (add-after 'unpack 'change-R-target-path
436 (lambda* (#:key outputs #:allow-other-keys)
437 (substitute* '("src/interfaces/r_modular/CMakeLists.txt"
438 "src/interfaces/r_static/CMakeLists.txt"
439 "examples/undocumented/r_modular/CMakeLists.txt")
440 (("\\$\\{R_COMPONENT_LIB_PATH\\}")
441 (string-append (assoc-ref outputs "out")
444 (add-after 'unpack 'fix-octave-modules
445 (lambda* (#:key outputs #:allow-other-keys)
446 (substitute* '("src/interfaces/octave_modular/CMakeLists.txt"
447 "src/interfaces/octave_static/CMakeLists.txt")
448 (("^include_directories\\(\\$\\{OCTAVE_INCLUDE_DIRS\\}")
449 "include_directories(${OCTAVE_INCLUDE_DIRS} ${OCTAVE_INCLUDE_DIRS}/octave"))
451 ;; change target directory
452 (substitute* "src/interfaces/octave_modular/CMakeLists.txt"
453 (("\\$\\{OCTAVE_OCT_LOCAL_API_FILE_DIR\\}")
454 (string-append (assoc-ref outputs "out")
455 "/share/octave/packages")))
457 (add-before 'build 'set-HOME
458 ;; $HOME needs to be set at some point during the build phase
459 (lambda _ (setenv "HOME" "/tmp") #t)))
461 (list "-DCMAKE_BUILD_WITH_INSTALL_RPATH=TRUE"
462 "-DUSE_SVMLIGHT=OFF" ;disable proprietary SVMLIGHT
463 ;;"-DJavaModular=ON" ;requires unpackaged jblas
464 ;;"-DRubyModular=ON" ;requires unpackaged ruby-narray
465 ;;"-DPerlModular=ON" ;"FindPerlLibs" does not exist
466 ;;"-DLuaModular=ON" ;fails because lua doesn't build pkgconfig file
473 "-DCmdLineStatic=ON")))
476 ("numpy" ,python-numpy)
477 ("r-minimal" ,r-minimal)
482 ("arpack" ,arpack-ng)
489 `(("pkg-config" ,pkg-config)))
490 ;; Non-portable SSE instructions are used so building fails on platforms
491 ;; other than x86_64.
492 (supported-systems '("x86_64-linux"))
493 (home-page "http://shogun-toolbox.org/")
494 (synopsis "Machine learning toolbox")
496 "The Shogun Machine learning toolbox provides a wide range of unified and
497 efficient Machine Learning (ML) methods. The toolbox seamlessly allows to
498 combine multiple data representations, algorithm classes, and general purpose
499 tools. This enables both rapid prototyping of data pipelines and extensibility
500 in terms of new algorithms.")
501 (license license:gpl3+)))
503 (define-public r-adaptivesparsity
505 (name "r-adaptivesparsity")
509 (uri (cran-uri "AdaptiveSparsity" version))
512 "1az7isvalf3kmdiycrfl6s9k9xqk22k1mc6rh8v0jmcz402qyq8z"))))
514 `((upstream-name . "AdaptiveSparsity")))
515 (build-system r-build-system)
518 (modify-phases %standard-phases
519 (add-after 'unpack 'link-against-armadillo
521 (substitute* "src/Makevars"
522 (("PKG_LIBS=" prefix)
523 (string-append prefix "-larmadillo"))))))))
526 ("r-rcpparmadillo" ,r-rcpparmadillo)))
528 `(("armadillo" ,armadillo)))
529 (home-page "https://cran.r-project.org/web/packages/AdaptiveSparsity")
530 (synopsis "Adaptive sparsity models")
532 "This package implements the Figueiredo machine learning algorithm for
533 adaptive sparsity and the Wong algorithm for adaptively sparse gaussian
535 (license license:lgpl3+)))
537 (define-public r-kernlab
544 (uri (cran-uri "kernlab" version))
547 "0qnaq9x3j2xc6jrmmd98wc6hkzch487s4p3a9lnc00xvahkhgpmr"))))
548 (build-system r-build-system)
549 (home-page "https://cran.r-project.org/web/packages/kernlab")
550 (synopsis "Kernel-based machine learning tools")
552 "This package provides kernel-based machine learning methods for
553 classification, regression, clustering, novelty detection, quantile regression
554 and dimensionality reduction. Among other methods @code{kernlab} includes
555 Support Vector Machines, Spectral Clustering, Kernel PCA, Gaussian Processes
557 (license license:gpl2)))
566 "http://dlib.net/files/dlib-" version ".tar.bz2"))
569 "1mljz02kwkrbggyncxv5fpnyjdybw2qihaacb3js8yfkw12vwpc2"))
570 (modules '((guix build utils)))
573 ;; Delete ~13MB of bundled dependencies.
574 (delete-file-recursively "dlib/external")
575 (delete-file-recursively "docs/dlib/external")
577 (build-system cmake-build-system)
580 (modify-phases %standard-phases
581 (add-after 'unpack 'disable-asserts
583 ;; config.h recommends explicitly enabling or disabling asserts
584 ;; when building as a shared library. By default neither is set.
585 (substitute* "dlib/config.h"
586 (("^//#define DLIB_DISABLE_ASSERTS") "#define DLIB_DISABLE_ASSERTS"))
588 (add-after 'disable-asserts 'disable-failing-tests
590 ;; One test times out on MIPS, so we need to disable it.
591 ;; Others are flaky on some platforms.
592 (let* ((system ,(or (%current-target-system)
594 (disabled-tests (cond
595 ((string-prefix? "mips64" system)
596 '("object_detector" ; timeout
598 ((string-prefix? "armhf" system)
599 '("learning_to_track"))
600 ((string-prefix? "i686" system)
605 (substitute* "dlib/test/makefile"
606 (((string-append "SRC \\+= " test "\\.cpp")) "")))
611 ;; No test target, so we build and run the unit tests here.
612 (let ((test-dir (string-append "../dlib-" ,version "/dlib/test")))
613 (with-directory-excursion test-dir
614 (and (zero? (system* "make" "-j" (number->string (parallel-job-count))))
615 (zero? (system* "./dtest" "--runall")))))))
616 (add-after 'install 'delete-static-library
617 (lambda* (#:key outputs #:allow-other-keys)
618 (delete-file (string-append (assoc-ref outputs "out")
622 `(("pkg-config" ,pkg-config)))
629 ("openblas" ,openblas)
632 "Toolkit for making machine learning and data analysis applications in C++")
634 "Dlib is a modern C++ toolkit containing machine learning algorithms and
635 tools. It is used in both industry and academia in a wide range of domains
636 including robotics, embedded devices, mobile phones, and large high performance
637 computing environments.")
638 (home-page "http://dlib.net")
639 (license license:boost1.0)))
641 (define-public python-scikit-learn
643 (name "python-scikit-learn")
649 "https://github.com/scikit-learn/scikit-learn/archive/"
651 (file-name (string-append name "-" version ".tar.gz"))
654 "18n8775kyfwbvcjjjzda9c5sqy4737c0hrmj6qj1ps2jmlqzair9"))
655 (patches (search-patches
656 "python-scikit-learn-fix-test-non-determinism.patch"))))
657 (build-system python-build-system)
660 (modify-phases %standard-phases
662 (add-after 'install 'check
663 ;; Running tests from the source directory requires
664 ;; an "inplace" build with paths relative to CWD.
665 ;; http://scikit-learn.org/stable/developers/advanced_installation.html#testing
666 ;; Use the installed version instead.
667 (lambda* (#:key inputs outputs #:allow-other-keys)
668 (add-installed-pythonpath inputs outputs)
669 ;; some tests require access to "$HOME"
670 (setenv "HOME" "/tmp")
671 ;; Step out of the source directory just to be sure.
673 (zero? (system* "nosetests" "-v" "sklearn")))))))
675 `(("openblas" ,openblas)))
677 `(("python-nose" ,python-nose)
678 ("python-cython" ,python-cython)))
680 `(("python-numpy" ,python-numpy)
681 ("python-scipy" ,python-scipy)))
682 (home-page "http://scikit-learn.org/")
683 (synopsis "Machine Learning in Python")
685 "Scikit-learn provides simple and efficient tools for data
686 mining and data analysis.")
687 (license license:bsd-3)))
689 (define-public python2-scikit-learn
690 (package-with-python2 python-scikit-learn))