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-after 'disable-broken-tests '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
379 (modify-phases %standard-phases
380 (add-after '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"))
398 (add-after 'unpack 'change-R-target-path
399 (lambda* (#:key outputs #:allow-other-keys)
400 (substitute* '("src/interfaces/r_modular/CMakeLists.txt"
401 "src/interfaces/r_static/CMakeLists.txt"
402 "examples/undocumented/r_modular/CMakeLists.txt")
403 (("\\$\\{R_COMPONENT_LIB_PATH\\}")
404 (string-append (assoc-ref outputs "out")
407 (add-after 'unpack 'fix-octave-modules
408 (lambda* (#:key outputs #:allow-other-keys)
409 (substitute* '("src/interfaces/octave_modular/CMakeLists.txt"
410 "src/interfaces/octave_static/CMakeLists.txt")
411 (("^include_directories\\(\\$\\{OCTAVE_INCLUDE_DIRS\\}")
412 "include_directories(${OCTAVE_INCLUDE_DIRS} ${OCTAVE_INCLUDE_DIRS}/octave"))
414 ;; change target directory
415 (substitute* "src/interfaces/octave_modular/CMakeLists.txt"
416 (("\\$\\{OCTAVE_OCT_LOCAL_API_FILE_DIR\\}")
417 (string-append (assoc-ref outputs "out")
418 "/share/octave/packages")))
420 (add-before 'build 'set-HOME
421 ;; $HOME needs to be set at some point during the build phase
422 (lambda _ (setenv "HOME" "/tmp") #t)))
424 (list "-DCMAKE_BUILD_WITH_INSTALL_RPATH=TRUE"
425 "-DUSE_SVMLIGHT=OFF" ;disable proprietary SVMLIGHT
426 ;;"-DJavaModular=ON" ;requires unpackaged jblas
427 ;;"-DRubyModular=ON" ;requires unpackaged ruby-narray
428 ;;"-DPerlModular=ON" ;"FindPerlLibs" does not exist
429 ;;"-DLuaModular=ON" ;fails because lua doesn't build pkgconfig file
436 "-DCmdLineStatic=ON")))
439 ("numpy" ,python-numpy)
440 ("r-minimal" ,r-minimal)
445 ("arpack" ,arpack-ng)
452 `(("pkg-config" ,pkg-config)))
453 ;; Non-portable SSE instructions are used so building fails on platforms
454 ;; other than x86_64.
455 (supported-systems '("x86_64-linux"))
456 (home-page "http://shogun-toolbox.org/")
457 (synopsis "Machine learning toolbox")
459 "The Shogun Machine learning toolbox provides a wide range of unified and
460 efficient Machine Learning (ML) methods. The toolbox seamlessly allows to
461 combine multiple data representations, algorithm classes, and general purpose
462 tools. This enables both rapid prototyping of data pipelines and extensibility
463 in terms of new algorithms.")
464 (license license:gpl3+)))
466 (define-public r-adaptivesparsity
468 (name "r-adaptivesparsity")
472 (uri (cran-uri "AdaptiveSparsity" version))
475 "1az7isvalf3kmdiycrfl6s9k9xqk22k1mc6rh8v0jmcz402qyq8z"))))
477 `((upstream-name . "AdaptiveSparsity")))
478 (build-system r-build-system)
481 (modify-phases %standard-phases
482 (add-after 'unpack 'link-against-armadillo
484 (substitute* "src/Makevars"
485 (("PKG_LIBS=" prefix)
486 (string-append prefix "-larmadillo"))))))))
489 ("r-rcpparmadillo" ,r-rcpparmadillo)))
491 `(("armadillo" ,armadillo)))
492 (home-page "http://cran.r-project.org/web/packages/AdaptiveSparsity")
493 (synopsis "Adaptive sparsity models")
495 "This package implements the Figueiredo machine learning algorithm for
496 adaptive sparsity and the Wong algorithm for adaptively sparse gaussian
498 (license license:lgpl3+)))
500 (define-public r-kernlab
507 (uri (cran-uri "kernlab" version))
510 "0qnaq9x3j2xc6jrmmd98wc6hkzch487s4p3a9lnc00xvahkhgpmr"))))
511 (build-system r-build-system)
512 (home-page "http://cran.r-project.org/web/packages/kernlab")
513 (synopsis "Kernel-based machine learning tools")
515 "This package provides kernel-based machine learning methods for
516 classification, regression, clustering, novelty detection, quantile regression
517 and dimensionality reduction. Among other methods @code{kernlab} includes
518 Support Vector Machines, Spectral Clustering, Kernel PCA, Gaussian Processes
520 (license license:gpl2)))
529 "http://dlib.net/files/dlib-" version ".tar.bz2"))
532 "1mljz02kwkrbggyncxv5fpnyjdybw2qihaacb3js8yfkw12vwpc2"))
533 (modules '((guix build utils)))
536 ;; Delete ~13MB of bundled dependencies.
537 (delete-file-recursively "dlib/external")
538 (delete-file-recursively "docs/dlib/external")
540 (build-system cmake-build-system)
542 ;; Recent releases defaults to "lib64" on 64bit.
543 `(#:configure-flags (list (string-append "-DCMAKE_INSTALL_LIBDIR="
544 (assoc-ref %outputs "out")
547 (modify-phases %standard-phases
548 (add-after 'unpack 'disable-asserts
550 ;; config.h recommends explicitly enabling or disabling asserts
551 ;; when building as a shared library. By default neither is set.
552 (substitute* "dlib/config.h"
553 (("^//#define DLIB_DISABLE_ASSERTS") "#define DLIB_DISABLE_ASSERTS"))
555 (add-after 'disable-asserts 'disable-failing-tests
557 ;; One test times out on MIPS, so we need to disable it.
558 ;; Others are flaky on some platforms.
559 (let* ((system ,(or (%current-target-system)
561 (disabled-tests (cond
562 ((string-prefix? "mips64" system)
563 '("object_detector" ; timeout
565 ((string-prefix? "armhf" system)
566 '("learning_to_track"))
567 ((string-prefix? "i686" system)
572 (substitute* "dlib/test/makefile"
573 (((string-append "SRC \\+= " test "\\.cpp")) "")))
578 ;; No test target, so we build and run the unit tests here.
579 (let ((test-dir (string-append "../dlib-" ,version "/dlib/test")))
580 (with-directory-excursion test-dir
581 (and (zero? (system* "make" "-j" (number->string (parallel-job-count))))
582 (zero? (system* "./dtest" "--runall")))))))
583 (add-after 'install 'delete-static-library
584 (lambda* (#:key outputs #:allow-other-keys)
585 (delete-file (string-append (assoc-ref outputs "out")
589 `(("pkg-config" ,pkg-config)))
596 ("openblas" ,openblas)
599 "Toolkit for making machine learning and data analysis applications in C++")
601 "Dlib is a modern C++ toolkit containing machine learning algorithms and
602 tools. It is used in both industry and academia in a wide range of domains
603 including robotics, embedded devices, mobile phones, and large high performance
604 computing environments.")
605 (home-page "http://dlib.net")
606 (license license:boost1.0)))