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 r)
30 #:use-module (gnu packages)
31 #:use-module (gnu packages autotools)
32 #:use-module (gnu packages boost)
33 #:use-module (gnu packages compression)
34 #:use-module (gnu packages dejagnu)
35 #:use-module (gnu packages gcc)
36 #:use-module (gnu packages image)
37 #:use-module (gnu packages maths)
38 #:use-module (gnu packages perl)
39 #:use-module (gnu packages pkg-config)
40 #:use-module (gnu packages python)
41 #:use-module (gnu packages statistics)
42 #:use-module (gnu packages swig)
43 #:use-module (gnu packages xml)
44 #:use-module (gnu packages xorg))
54 "https://github.com/cjlin1/libsvm/archive/v"
55 (string-delete #\. version) ".tar.gz"))
56 (file-name (string-append name "-" version ".tar.gz"))
59 "1jpjlql3frjza7zxzrqqr2firh44fjb8fqsdmvz6bjz7sb47zgp4"))))
60 (build-system gnu-build-system)
62 `(#:tests? #f ;no "check" target
63 #:phases (modify-phases %standard-phases
67 (lambda* (#:key outputs #:allow-other-keys)
68 (let* ((out (assoc-ref outputs "out"))
69 (bin (string-append out "/bin/")))
71 (for-each (lambda (file)
72 (copy-file file (string-append bin file)))
77 (home-page "http://www.csie.ntu.edu.tw/~cjlin/libsvm/")
78 (synopsis "Library for Support Vector Machines")
80 "LIBSVM is a machine learning library for support vector
81 classification, (C-SVC, nu-SVC), regression (epsilon-SVR, nu-SVR) and
82 distribution estimation (one-class SVM). It supports multi-class
84 (license license:bsd-3)))
86 (define-public python-libsvm
87 (package (inherit libsvm)
88 (name "python-libsvm")
89 (build-system gnu-build-system)
91 `(#:tests? #f ;no "check" target
92 #:make-flags '("-C" "python")
94 (modify-phases %standard-phases
98 (lambda* (#:key inputs outputs #:allow-other-keys)
99 (let ((site (string-append (assoc-ref outputs "out")
103 (assoc-ref inputs "python") 5) 3)
105 (substitute* "python/svm.py"
106 (("../libsvm.so.2") "libsvm.so.2"))
108 (for-each (lambda (file)
109 (copy-file file (string-append site (basename file))))
110 (find-files "python" "\\.py"))
111 (copy-file "libsvm.so.2"
112 (string-append site "libsvm.so.2")))
115 `(("python" ,python)))
116 (synopsis "Python bindings of libSVM")))
119 ;; The latest release candidate is several years and a couple of fixes have
120 ;; been published since. This is why we download the sources from the SVN
122 (let ((svn-revision 2341))
125 (version (string-append "0.9-rc3-0." (number->string svn-revision)))
129 (url "http://svn.code.sf.net/p/ghmm/code/trunk")
130 (revision svn-revision)))
131 (file-name (string-append name "-" version))
134 "0qbq1rqp94l530f043qzp8aw5lj7dng9wq0miffd7spd1ff638wq"))))
135 (build-system gnu-build-system)
137 `(#:imported-modules (,@%gnu-build-system-modules
138 (guix build python-build-system))
140 (modify-phases %standard-phases
141 (add-after 'unpack 'enter-dir
142 (lambda _ (chdir "ghmm") #t))
144 (add-after 'install 'check
145 (assoc-ref %standard-phases 'check))
146 (add-before 'check 'fix-PYTHONPATH
147 (lambda* (#:key inputs outputs #:allow-other-keys)
148 (let ((python-version ((@@ (guix build python-build-system)
150 (assoc-ref inputs "python"))))
152 (string-append (getenv "PYTHONPATH")
153 ":" (assoc-ref outputs "out")
154 "/lib/python" python-version
157 (add-after 'enter-dir 'fix-runpath
158 (lambda* (#:key outputs #:allow-other-keys)
159 (substitute* "ghmmwrapper/setup.py"
160 (("^(.*)extra_compile_args = \\[" line indent)
161 (string-append indent
162 "extra_link_args = [\"-Wl,-rpath="
163 (assoc-ref outputs "out") "/lib\"],\n"
166 (assoc-ref outputs "out")
169 (add-after 'enter-dir 'disable-broken-tests
171 (substitute* "tests/Makefile.am"
172 ;; GHMM_SILENT_TESTS is assumed to be a command.
173 (("TESTS_ENVIRONMENT.*") "")
174 ;; Do not build broken tests.
178 (("label_higher_order_test.*$")
179 "label_higher_order_test\n"))
181 ;; These Python unittests are broken as there is no gato.
182 ;; See https://sourceforge.net/p/ghmm/support-requests/3/
183 (substitute* "ghmmwrapper/ghmmunittests.py"
184 (("^(.*)def (testNewXML|testMultipleTransitionClasses|testNewXML)"
186 (string-append indent
187 "@unittest.skip(\"Disabled by Guix\")\n"
190 (add-before 'configure 'autogen
192 (zero? (system* "bash" "./autogen.sh")))))))
194 `(("python" ,python-2) ; only Python 2 is supported
195 ("libxml2" ,libxml2)))
197 `(("pkg-config" ,pkg-config)
200 ("autoconf" ,autoconf)
201 ("automake" ,automake)
202 ("libtool" ,libtool)))
203 (home-page "http://ghmm.org")
204 (synopsis "Hidden Markov Model library")
206 "The General Hidden Markov Model library (GHMM) is a C library with
207 additional Python bindings implementing a wide range of types of @dfn{Hidden
208 Markov Models} (HMM) and algorithms: discrete, continous emissions, basic
209 training, HMM clustering, HMM mixtures.")
210 (license license:lgpl2.0+))))
219 "http://micans.org/mcl/src/mcl-"
220 (string-replace-substring version "." "-")
224 "15xlax3z31lsn62vlg94hkm75nm40q4679amnfg13jm8m2bnhy5m"))))
225 (build-system gnu-build-system)
227 `(#:configure-flags (list "--enable-blast")))
230 (home-page "http://micans.org/mcl/")
231 (synopsis "Clustering algorithm for graphs")
233 "The MCL algorithm is short for the @dfn{Markov Cluster Algorithm}, a
234 fast and scalable unsupervised cluster algorithm for graphs (also known as
235 networks) based on simulation of (stochastic) flow in graphs.")
236 ;; In the LICENCE file and web page it says "The software is licensed
237 ;; under the GNU General Public License, version 3.", but in several of
238 ;; the source code files it suggests GPL3 or later.
239 ;; http://listserver.ebi.ac.uk/pipermail/mcl-users/2016/000376.html
240 (license license:gpl3)))
242 (define-public randomjungle
244 (name "randomjungle")
250 "http://www.imbs-luebeck.de/imbs/sites/default/files/u59/"
251 "randomjungle-" version ".tar_.gz"))
254 "12c8rf30cla71swx2mf4ww9mfd8jbdw5lnxd7dxhyw1ygrvg6y4w"))))
255 (build-system gnu-build-system)
258 (list (string-append "--with-boost="
259 (assoc-ref %build-inputs "boost")))
261 (modify-phases %standard-phases
263 'configure 'set-CXXFLAGS
265 (setenv "CXXFLAGS" "-fpermissive ")
273 `(("gfortran" ,gfortran)
274 ("gfortran:lib" ,gfortran "lib")))
275 ;; Non-portable assembly instructions are used so building fails on
276 ;; platforms other than x86_64 or i686.
277 (supported-systems '("x86_64-linux" "i686-linux"))
278 (home-page "http://www.imbs-luebeck.de/imbs/de/node/227/")
279 (synopsis "Implementation of the Random Forests machine learning method")
281 "Random Jungle is an implementation of Random Forests. It is supposed to
282 analyse high dimensional data. In genetics, it can be used for analysing big
283 Genome Wide Association (GWA) data. Random Forests is a powerful machine
284 learning method. Most interesting features are variable selection, missing
285 value imputation, classifier creation, generalization error estimation and
286 sample proximities between pairs of cases.")
287 (license license:gpl3+)))
289 (define-public shogun
297 "ftp://shogun-toolbox.org/shogun/releases/"
298 (version-major+minor version)
299 "/sources/shogun-" version ".tar.bz2"))
302 "159nlijnb7mnrv9za80wnm1shwvy45hgrqzn51hxy7gw4z6d6fdb"))
303 (modules '((guix build utils)
307 ;; Remove non-free sources and files referencing them
308 (for-each delete-file
309 (find-files "src/shogun/classifier/svm/"
310 "SVMLight\\.(cpp|h)"))
311 (for-each delete-file
312 (find-files "examples/undocumented/libshogun/"
314 "(classifier_.*svmlight.*|"
315 "evaluation_cross_validation_locked_comparison).cpp")))
316 ;; Remove non-free functions.
317 (define (delete-ifdefs file)
318 (with-atomic-file-replacement file
320 (let loop ((line (read-line in 'concat))
322 (if (eof-object? line)
327 "#endif //USE_SVMLIGHT" line)))
329 "#ifdef USE_SVMLIGHT" line))))
330 (when (or (not skipping?)
331 (and skipping? (not skip-next?)))
333 (loop (read-line in 'concat) skip-next?)))))))
334 (for-each delete-ifdefs (find-files "src/shogun/kernel/"
335 "^Kernel\\.(cpp|h)"))))))
336 (build-system cmake-build-system)
338 '(#:tests? #f ;no check target
341 'unpack 'delete-broken-symlinks
343 (for-each delete-file '("applications/arts/data"
344 "applications/asp/data"
345 "applications/easysvm/data"
346 "applications/msplicer/data"
347 "applications/ocr/data"
348 "examples/documented/data"
349 "examples/documented/matlab_static"
350 "examples/documented/octave_static"
351 "examples/undocumented/data"
352 "examples/undocumented/matlab_static"
353 "examples/undocumented/octave_static"
354 "tests/integration/data"
355 "tests/integration/matlab_static"
356 "tests/integration/octave_static"
357 "tests/integration/python_modular/tests"))
360 'unpack 'change-R-target-path
361 (lambda* (#:key outputs #:allow-other-keys)
362 (substitute* '("src/interfaces/r_modular/CMakeLists.txt"
363 "src/interfaces/r_static/CMakeLists.txt"
364 "examples/undocumented/r_modular/CMakeLists.txt")
365 (("\\$\\{R_COMPONENT_LIB_PATH\\}")
366 (string-append (assoc-ref outputs "out")
370 'unpack 'fix-octave-modules
371 (lambda* (#:key outputs #:allow-other-keys)
372 (substitute* '("src/interfaces/octave_modular/CMakeLists.txt"
373 "src/interfaces/octave_static/CMakeLists.txt")
374 (("^include_directories\\(\\$\\{OCTAVE_INCLUDE_DIRS\\}")
375 "include_directories(${OCTAVE_INCLUDE_DIRS} ${OCTAVE_INCLUDE_DIRS}/octave"))
377 ;; change target directory
378 (substitute* "src/interfaces/octave_modular/CMakeLists.txt"
379 (("\\$\\{OCTAVE_OCT_LOCAL_API_FILE_DIR\\}")
380 (string-append (assoc-ref outputs "out")
381 "/share/octave/packages")))
385 ;; $HOME needs to be set at some point during the build phase
386 (lambda _ (setenv "HOME" "/tmp") #t)
389 (list "-DCMAKE_BUILD_WITH_INSTALL_RPATH=TRUE"
390 "-DUSE_SVMLIGHT=OFF" ;disable proprietary SVMLIGHT
391 ;;"-DJavaModular=ON" ;requires unpackaged jblas
392 ;;"-DRubyModular=ON" ;requires unpackaged ruby-narray
393 ;;"-DPerlModular=ON" ;"FindPerlLibs" does not exist
394 ;;"-DLuaModular=ON" ;fails because lua doesn't build pkgconfig file
401 "-DCmdLineStatic=ON")))
404 ("numpy" ,python-numpy)
410 ("arpack" ,arpack-ng)
417 `(("pkg-config" ,pkg-config)))
418 ;; Non-portable SSE instructions are used so building fails on platforms
419 ;; other than x86_64.
420 (supported-systems '("x86_64-linux"))
421 (home-page "http://shogun-toolbox.org/")
422 (synopsis "Machine learning toolbox")
424 "The Shogun Machine learning toolbox provides a wide range of unified and
425 efficient Machine Learning (ML) methods. The toolbox seamlessly allows to
426 combine multiple data representations, algorithm classes, and general purpose
427 tools. This enables both rapid prototyping of data pipelines and extensibility
428 in terms of new algorithms.")
429 (license license:gpl3+)))
431 (define-public r-adaptivesparsity
433 (name "r-adaptivesparsity")
437 (uri (cran-uri "AdaptiveSparsity" version))
440 "1az7isvalf3kmdiycrfl6s9k9xqk22k1mc6rh8v0jmcz402qyq8z"))))
442 `((upstream-name . "AdaptiveSparsity")))
443 (build-system r-build-system)
446 (modify-phases %standard-phases
447 (add-after 'unpack 'link-against-armadillo
449 (substitute* "src/Makevars"
450 (("PKG_LIBS=" prefix)
451 (string-append prefix "-larmadillo"))))))))
454 ("r-rcpparmadillo" ,r-rcpparmadillo)))
455 (home-page "http://cran.r-project.org/web/packages/AdaptiveSparsity")
456 (synopsis "Adaptive sparsity models")
458 "This package implements the Figueiredo machine learning algorithm for
459 adaptive sparsity and the Wong algorithm for adaptively sparse gaussian
461 (license license:lgpl3+)))
463 (define-public r-nnet
470 (uri (cran-uri "nnet" version))
473 "17amqnw9dpap2w8ivx53hxha2xrm0drwfnj32li0xk41hlz548r7"))))
474 (build-system r-build-system)
475 (home-page "http://www.stats.ox.ac.uk/pub/MASS4/")
476 (synopsis "Feed-forward neural networks and multinomial log-linear models")
478 "This package provides functions for feed-forward neural networks with a
479 single hidden layer, and for multinomial log-linear models.")
480 (license (list license:gpl2+ license:gpl3+))))
482 (define-public r-kernlab
489 (uri (cran-uri "kernlab" version))
492 "0qnaq9x3j2xc6jrmmd98wc6hkzch487s4p3a9lnc00xvahkhgpmr"))))
493 (build-system r-build-system)
494 (home-page "http://cran.r-project.org/web/packages/kernlab")
495 (synopsis "Kernel-based machine learning tools")
497 "This package provides kernel-based machine learning methods for
498 classification, regression, clustering, novelty detection, quantile regression
499 and dimensionality reduction. Among other methods @code{kernlab} includes
500 Support Vector Machines, Spectral Clustering, Kernel PCA, Gaussian Processes
502 (license license:gpl2)))
511 "http://dlib.net/files/dlib-" version ".tar.bz2"))
514 "0p2pvcdalc6jhb6r99ybvjd9x74sclr0ngswdg9j2xl5pj7knbr4"))
515 (modules '((guix build utils)))
518 ;; Delete ~13MB of bundled dependencies.
519 (delete-file-recursively "dlib/external")
520 (delete-file-recursively "docs/dlib/external")))))
521 (build-system cmake-build-system)
524 (modify-phases %standard-phases
525 (add-after 'unpack 'disable-asserts
527 ;; config.h recommends explicitly enabling or disabling asserts
528 ;; when building as a shared library. By default neither is set.
529 (substitute* "dlib/config.h"
530 (("^//#define DLIB_DISABLE_ASSERTS") "#define DLIB_DISABLE_ASSERTS"))
532 (add-after 'disable-asserts 'disable-failing-tests
534 ;; One test times out on MIPS, so we need to disable it.
535 ;; The rest is known to fail on non-x86_64 platforms in the current release.
536 ;; Some have been fixed in git; this list should be readjusted next update.
537 (let* ((system ,(or (%current-target-system)
539 (disabled-tests (cond
540 ((string-prefix? "mips64" system)
541 '("object_detector" ; timeout
543 ((string-prefix? "armhf" system)
544 '("learning_to_track" "max_cost_assignment"))
545 ((string-prefix? "i686" system)
546 '("optimization" "matrix2" "mpc"))
548 ;; The following test fails due a bug in openblas < 0.2.18.
549 (append! disabled-tests '("empirical_map"))
552 (substitute* "dlib/test/makefile"
553 (((string-append "SRC \\+= " test "\\.cpp")) "")) #t)
557 ;; No test target, so we build and run the unit tests here.
558 (let ((test-dir (string-append "../dlib-" ,version "/dlib/test")))
559 (with-directory-excursion test-dir
560 (setenv "CXXFLAGS" "-std=gnu++11")
561 (and (zero? (system* "make" "-j" (number->string (parallel-job-count))))
562 (zero? (system* "./dtest" "--runall")))))))
563 (add-after 'install 'delete-static-library
564 (lambda* (#:key outputs #:allow-other-keys)
565 (delete-file (string-append (assoc-ref outputs "out") "/lib/libdlib.a")))))))
567 `(("pkg-config" ,pkg-config)))
574 ("openblas" ,openblas)
577 "Toolkit for making machine learning and data analysis applications in C++")
579 "Dlib is a modern C++ toolkit containing machine learning algorithms and
580 tools. It is used in both industry and academia in a wide range of domains
581 including robotics, embedded devices, mobile phones, and large high performance
582 computing environments.")
583 (home-page "http://dlib.net")
584 (license license:boost1.0)))