Merge branch 'master' into core-updates
[jackhill/guix/guix.git] / gnu / packages / machine-learning.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2015, 2016, 2017, 2018 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 Kei Kebreau <kkebreau@posteo.net>
8 ;;; Copyright © 2018 Mark Meyer <mark@ofosos.org>
9 ;;; Copyright © 2018 Ben Woodcroft <donttrustben@gmail.com>
10 ;;; Copyright © 2018 Fis Trivial <ybbs.daans@hotmail.com>
11 ;;; Copyright © 2018 Julien Lepiller <julien@lepiller.eu>
12 ;;;
13 ;;; This file is part of GNU Guix.
14 ;;;
15 ;;; GNU Guix is free software; you can redistribute it and/or modify it
16 ;;; under the terms of the GNU General Public License as published by
17 ;;; the Free Software Foundation; either version 3 of the License, or (at
18 ;;; your option) any later version.
19 ;;;
20 ;;; GNU Guix is distributed in the hope that it will be useful, but
21 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 ;;; GNU General Public License for more details.
24 ;;;
25 ;;; You should have received a copy of the GNU General Public License
26 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
27
28 (define-module (gnu packages machine-learning)
29 #:use-module ((guix licenses) #:prefix license:)
30 #:use-module (guix packages)
31 #:use-module (guix utils)
32 #:use-module (guix download)
33 #:use-module (guix svn-download)
34 #:use-module (guix build-system cmake)
35 #:use-module (guix build-system gnu)
36 #:use-module (guix build-system ocaml)
37 #:use-module (guix build-system python)
38 #:use-module (guix build-system r)
39 #:use-module (guix git-download)
40 #:use-module (gnu packages)
41 #:use-module (gnu packages algebra)
42 #:use-module (gnu packages autotools)
43 #:use-module (gnu packages boost)
44 #:use-module (gnu packages check)
45 #:use-module (gnu packages compression)
46 #:use-module (gnu packages cran)
47 #:use-module (gnu packages dejagnu)
48 #:use-module (gnu packages gcc)
49 #:use-module (gnu packages image)
50 #:use-module (gnu packages maths)
51 #:use-module (gnu packages mpi)
52 #:use-module (gnu packages ocaml)
53 #:use-module (gnu packages onc-rpc)
54 #:use-module (gnu packages perl)
55 #:use-module (gnu packages pkg-config)
56 #:use-module (gnu packages python)
57 #:use-module (gnu packages statistics)
58 #:use-module (gnu packages swig)
59 #:use-module (gnu packages xml)
60 #:use-module (gnu packages xorg))
61
62 (define-public fann
63 ;; The last release is >100 commits behind, so we package from git.
64 (let ((commit "d71d54788bee56ba4cf7522801270152da5209d7"))
65 (package
66 (name "fann")
67 (version (string-append "2.2.0-1." (string-take commit 8)))
68 (source (origin
69 (method git-fetch)
70 (uri (git-reference
71 (url "https://github.com/libfann/fann.git")
72 (commit commit)))
73 (file-name (string-append name "-" version "-checkout"))
74 (sha256
75 (base32
76 "0ibwpfrjs6q2lijs8slxjgzb2llcl6rk3v2ski4r6215g5jjhg3x"))))
77 (build-system cmake-build-system)
78 (arguments
79 `(#:phases
80 (modify-phases %standard-phases
81 (replace 'check
82 (lambda* (#:key outputs #:allow-other-keys)
83 (let* ((out (assoc-ref outputs "out")))
84 (with-directory-excursion (string-append (getcwd) "/tests")
85 (invoke "./fann_tests"))))))))
86 (home-page "http://leenissen.dk/fann/wp/")
87 (synopsis "Fast Artificial Neural Network")
88 (description
89 "FANN is a free open source neural network library, which implements
90 multilayer artificial neural networks in C with support for both fully
91 connected and sparsely connected networks.")
92 (license license:lgpl2.1))))
93
94 (define-public libsvm
95 (package
96 (name "libsvm")
97 (version "3.22")
98 (source
99 (origin
100 (method url-fetch)
101 (uri (string-append "https://www.csie.ntu.edu.tw/~cjlin/libsvm/"
102 name "-" version ".tar.gz"))
103 (sha256
104 (base32
105 "0zd7s19y5vb7agczl6456bn45cj1y64739sslaskw1qk7dywd0bd"))))
106 (build-system gnu-build-system)
107 (arguments
108 `(#:tests? #f ;no "check" target
109 #:phases (modify-phases %standard-phases
110 (delete 'configure)
111 (replace
112 'install ; no ‘install’ target
113 (lambda* (#:key outputs #:allow-other-keys)
114 (let* ((out (assoc-ref outputs "out"))
115 (bin (string-append out "/bin/")))
116 (mkdir-p bin)
117 (for-each (lambda (file)
118 (copy-file file (string-append bin file)))
119 '("svm-train"
120 "svm-predict"
121 "svm-scale")))
122 #t)))))
123 (home-page "http://www.csie.ntu.edu.tw/~cjlin/libsvm/")
124 (synopsis "Library for Support Vector Machines")
125 (description
126 "LIBSVM is a machine learning library for support vector
127 classification, (C-SVC, nu-SVC), regression (epsilon-SVR, nu-SVR) and
128 distribution estimation (one-class SVM). It supports multi-class
129 classification.")
130 (license license:bsd-3)))
131
132 (define-public python-libsvm
133 (package (inherit libsvm)
134 (name "python-libsvm")
135 (build-system gnu-build-system)
136 (arguments
137 `(#:tests? #f ;no "check" target
138 #:make-flags '("-C" "python")
139 #:phases
140 (modify-phases %standard-phases
141 (delete 'configure)
142 (replace
143 'install ; no ‘install’ target
144 (lambda* (#:key inputs outputs #:allow-other-keys)
145 (let ((site (string-append (assoc-ref outputs "out")
146 "/lib/python"
147 (string-take
148 (string-take-right
149 (assoc-ref inputs "python") 5) 3)
150 "/site-packages/")))
151 (substitute* "python/svm.py"
152 (("../libsvm.so.2") "libsvm.so.2"))
153 (mkdir-p site)
154 (for-each (lambda (file)
155 (copy-file file (string-append site (basename file))))
156 (find-files "python" "\\.py"))
157 (copy-file "libsvm.so.2"
158 (string-append site "libsvm.so.2")))
159 #t)))))
160 (inputs
161 `(("python" ,python)))
162 (synopsis "Python bindings of libSVM")))
163
164 (define-public ghmm
165 ;; The latest release candidate is several years and a couple of fixes have
166 ;; been published since. This is why we download the sources from the SVN
167 ;; repository.
168 (let ((svn-revision 2341))
169 (package
170 (name "ghmm")
171 (version (string-append "0.9-rc3-0." (number->string svn-revision)))
172 (source (origin
173 (method svn-fetch)
174 (uri (svn-reference
175 (url "http://svn.code.sf.net/p/ghmm/code/trunk")
176 (revision svn-revision)))
177 (file-name (string-append name "-" version))
178 (sha256
179 (base32
180 "0qbq1rqp94l530f043qzp8aw5lj7dng9wq0miffd7spd1ff638wq"))))
181 (build-system gnu-build-system)
182 (arguments
183 `(#:imported-modules (,@%gnu-build-system-modules
184 (guix build python-build-system))
185 #:phases
186 (modify-phases %standard-phases
187 (add-after 'unpack 'enter-dir
188 (lambda _ (chdir "ghmm") #t))
189 (delete 'check)
190 (add-after 'install 'check
191 (assoc-ref %standard-phases 'check))
192 (add-before 'check 'fix-PYTHONPATH
193 (lambda* (#:key inputs outputs #:allow-other-keys)
194 (let ((python-version ((@@ (guix build python-build-system)
195 get-python-version)
196 (assoc-ref inputs "python"))))
197 (setenv "PYTHONPATH"
198 (string-append (getenv "PYTHONPATH")
199 ":" (assoc-ref outputs "out")
200 "/lib/python" python-version
201 "/site-packages")))
202 #t))
203 (add-after 'enter-dir 'fix-runpath
204 (lambda* (#:key outputs #:allow-other-keys)
205 (substitute* "ghmmwrapper/setup.py"
206 (("^(.*)extra_compile_args = \\[" line indent)
207 (string-append indent
208 "extra_link_args = [\"-Wl,-rpath="
209 (assoc-ref outputs "out") "/lib\"],\n"
210 line
211 "\"-Wl,-rpath="
212 (assoc-ref outputs "out")
213 "/lib\", ")))
214 #t))
215 (add-after 'enter-dir 'disable-broken-tests
216 (lambda _
217 (substitute* "tests/Makefile.am"
218 ;; GHMM_SILENT_TESTS is assumed to be a command.
219 (("TESTS_ENVIRONMENT.*") "")
220 ;; Do not build broken tests.
221 (("chmm .*") "")
222 (("read_fa .*") "")
223 (("mcmc .*") "")
224 (("label_higher_order_test.*$")
225 "label_higher_order_test\n"))
226
227 ;; These Python unittests are broken as there is no gato.
228 ;; See https://sourceforge.net/p/ghmm/support-requests/3/
229 (substitute* "ghmmwrapper/ghmmunittests.py"
230 (("^(.*)def (testNewXML|testMultipleTransitionClasses|testNewXML)"
231 line indent)
232 (string-append indent
233 "@unittest.skip(\"Disabled by Guix\")\n"
234 line)))
235 #t))
236 (add-after 'disable-broken-tests 'autogen
237 (lambda _
238 (invoke "bash" "autogen.sh"))))))
239 (inputs
240 `(("python" ,python-2) ; only Python 2 is supported
241 ("libxml2" ,libxml2)))
242 (native-inputs
243 `(("pkg-config" ,pkg-config)
244 ("dejagnu" ,dejagnu)
245 ("swig" ,swig)
246 ("autoconf" ,autoconf)
247 ("automake" ,automake)
248 ("libtool" ,libtool)))
249 (home-page "http://ghmm.org")
250 (synopsis "Hidden Markov Model library")
251 (description
252 "The General Hidden Markov Model library (GHMM) is a C library with
253 additional Python bindings implementing a wide range of types of @dfn{Hidden
254 Markov Models} (HMM) and algorithms: discrete, continuous emissions, basic
255 training, HMM clustering, HMM mixtures.")
256 (license license:lgpl2.0+))))
257
258 (define-public mcl
259 (package
260 (name "mcl")
261 (version "14.137")
262 (source (origin
263 (method url-fetch)
264 (uri (string-append
265 "http://micans.org/mcl/src/mcl-"
266 (string-replace-substring version "." "-")
267 ".tar.gz"))
268 (sha256
269 (base32
270 "15xlax3z31lsn62vlg94hkm75nm40q4679amnfg13jm8m2bnhy5m"))))
271 (build-system gnu-build-system)
272 (arguments
273 `(#:configure-flags (list "--enable-blast")))
274 (inputs
275 `(("perl" ,perl)))
276 (home-page "http://micans.org/mcl/")
277 (synopsis "Clustering algorithm for graphs")
278 (description
279 "The MCL algorithm is short for the @dfn{Markov Cluster Algorithm}, a
280 fast and scalable unsupervised cluster algorithm for graphs (also known as
281 networks) based on simulation of (stochastic) flow in graphs.")
282 ;; In the LICENCE file and web page it says "The software is licensed
283 ;; under the GNU General Public License, version 3.", but in several of
284 ;; the source code files it suggests GPL3 or later.
285 ;; http://listserver.ebi.ac.uk/pipermail/mcl-users/2016/000376.html
286 (license license:gpl3)))
287
288 (define-public ocaml-mcl
289 (package
290 (name "ocaml-mcl")
291 (version "12-068oasis4")
292 (source
293 (origin
294 (method url-fetch)
295 (uri (string-append
296 "https://github.com/fhcrc/mcl/archive/"
297 version ".tar.gz"))
298 (file-name (string-append name "-" version ".tar.gz"))
299 (sha256
300 (base32
301 "1l5jbhwjpsj38x8b9698hfpkv75h8hn3kj0gihjhn8ym2cwwv110"))))
302 (build-system ocaml-build-system)
303 (arguments
304 `(#:ocaml ,ocaml-4.02
305 #:findlib ,ocaml4.02-findlib
306 #:phases
307 (modify-phases %standard-phases
308 (add-before 'configure 'patch-paths
309 (lambda _
310 (substitute* "configure"
311 (("SHELL = /bin/sh") (string-append "SHELL = "(which "sh"))))
312 (substitute* "setup.ml"
313 (("LDFLAGS=-fPIC")
314 (string-append "LDFLAGS=-fPIC\"; \"SHELL=" (which "sh"))))
315 #t)))))
316 (home-page "https://github.com/fhcrc/mcl")
317 (synopsis "OCaml wrappers around MCL")
318 (description
319 "This package provides OCaml bindings for the MCL graph clustering
320 algorithm.")
321 (license license:gpl3)))
322
323 (define-public ocaml4.01-mcl
324 (package-with-ocaml4.01 ocaml-mcl))
325
326 (define-public randomjungle
327 (package
328 (name "randomjungle")
329 (version "2.1.0")
330 (source
331 (origin
332 (method url-fetch)
333 (uri (string-append
334 "http://www.imbs-luebeck.de/imbs/sites/default/files/u59/"
335 "randomjungle-" version ".tar_.gz"))
336 (sha256
337 (base32
338 "12c8rf30cla71swx2mf4ww9mfd8jbdw5lnxd7dxhyw1ygrvg6y4w"))))
339 (build-system gnu-build-system)
340 (arguments
341 `(#:configure-flags
342 (list (string-append "--with-boost="
343 (assoc-ref %build-inputs "boost")))
344 #:phases
345 (modify-phases %standard-phases
346 (add-before
347 'configure 'set-CXXFLAGS
348 (lambda _
349 (setenv "CXXFLAGS" "-fpermissive ")
350 #t)))))
351 (inputs
352 `(("boost" ,boost)
353 ("gsl" ,gsl)
354 ("libxml2" ,libxml2)
355 ("zlib" ,zlib)))
356 (native-inputs
357 `(("gfortran" ,gfortran)
358 ("gfortran:lib" ,gfortran "lib")))
359 ;; Non-portable assembly instructions are used so building fails on
360 ;; platforms other than x86_64 or i686.
361 (supported-systems '("x86_64-linux" "i686-linux"))
362 (home-page "http://www.imbs-luebeck.de/imbs/de/node/227/")
363 (synopsis "Implementation of the Random Forests machine learning method")
364 (description
365 "Random Jungle is an implementation of Random Forests. It is supposed to
366 analyse high dimensional data. In genetics, it can be used for analysing big
367 Genome Wide Association (GWA) data. Random Forests is a powerful machine
368 learning method. Most interesting features are variable selection, missing
369 value imputation, classifier creation, generalization error estimation and
370 sample proximities between pairs of cases.")
371 (license license:gpl3+)))
372
373 (define-public shogun
374 (package
375 (name "shogun")
376 (version "6.1.3")
377 (source
378 (origin
379 (method url-fetch)
380 (uri (string-append
381 "ftp://shogun-toolbox.org/shogun/releases/"
382 (version-major+minor version)
383 "/sources/shogun-" version ".tar.bz2"))
384 (sha256
385 (base32
386 "1rn9skm3nw6hr7mr3lgp2gfqhi7ii0lyxck7qmqnf8avq349s5jp"))
387 (modules '((guix build utils)
388 (ice-9 rdelim)))
389 (snippet
390 '(begin
391 ;; Remove non-free sources and files referencing them
392 (for-each delete-file
393 (find-files "src/shogun/classifier/svm/"
394 "SVMLight\\.(cpp|h)"))
395 (for-each delete-file
396 (find-files "examples/undocumented/libshogun/"
397 (string-append
398 "(classifier_.*svmlight.*|"
399 "evaluation_cross_validation_locked_comparison).cpp")))
400 ;; Remove non-free functions.
401 (define (delete-ifdefs file)
402 (with-atomic-file-replacement file
403 (lambda (in out)
404 (let loop ((line (read-line in 'concat))
405 (skipping? #f))
406 (if (eof-object? line)
407 #t
408 (let ((skip-next?
409 (or (and skipping?
410 (not (string-prefix?
411 "#endif //USE_SVMLIGHT" line)))
412 (string-prefix?
413 "#ifdef USE_SVMLIGHT" line))))
414 (when (or (not skipping?)
415 (and skipping? (not skip-next?)))
416 (display line out))
417 (loop (read-line in 'concat) skip-next?)))))))
418 (for-each delete-ifdefs
419 (append
420 (find-files "src/shogun/classifier/mkl"
421 "^MKLClassification\\.cpp")
422 (find-files "src/shogun/classifier/svm"
423 "^SVMLightOneClass\\.(cpp|h)")
424 (find-files "src/shogun/multiclass"
425 "^ScatterSVM\\.(cpp|h)")
426 (find-files "src/shogun/kernel/"
427 "^(Kernel|CombinedKernel|ProductKernel)\\.(cpp|h)")
428 (find-files "src/shogun/regression/svr"
429 "^(MKLRegression|SVRLight)\\.(cpp|h)")
430 (find-files "src/shogun/transfer/domain_adaptation"
431 "^DomainAdaptationSVM\\.(cpp|h)")))
432 #t))))
433 (build-system cmake-build-system)
434 (arguments
435 '(#:tests? #f ;no check target
436 #:phases
437 (modify-phases %standard-phases
438 (add-after 'unpack 'delete-broken-symlinks
439 (lambda _
440 (for-each delete-file '("applications/arts/data"
441 "applications/asp/data"
442 "applications/easysvm/data"
443 "applications/msplicer/data"
444 "applications/ocr/data"
445 "examples/meta/data"
446 "examples/undocumented/data"))
447 #t))
448 (add-after 'unpack 'change-R-target-path
449 (lambda* (#:key outputs #:allow-other-keys)
450 (substitute* '("src/interfaces/r/CMakeLists.txt"
451 "examples/meta/r/CMakeLists.txt")
452 (("\\$\\{R_COMPONENT_LIB_PATH\\}")
453 (string-append (assoc-ref outputs "out")
454 "/lib/R/library/")))
455 #t))
456 (add-after 'unpack 'fix-octave-modules
457 (lambda* (#:key outputs #:allow-other-keys)
458 (substitute* "src/interfaces/octave/CMakeLists.txt"
459 (("^include_directories\\(\\$\\{OCTAVE_INCLUDE_DIRS\\}")
460 "include_directories(${OCTAVE_INCLUDE_DIRS} ${OCTAVE_INCLUDE_DIRS}/octave")
461 ;; change target directory
462 (("\\$\\{OCTAVE_OCT_LOCAL_API_FILE_DIR\\}")
463 (string-append (assoc-ref outputs "out")
464 "/share/octave/packages")))
465 (substitute* '("src/interfaces/octave/swig_typemaps.i"
466 "src/interfaces/octave/sg_print_functions.cpp")
467 ;; "octave/config.h" and "octave/oct-obj.h" deprecated in Octave.
468 (("octave/config\\.h") "octave/octave-config.h")
469 (("octave/oct-obj.h") "octave/ovl.h"))
470 #t))
471 (add-after 'unpack 'move-rxcpp
472 (lambda* (#:key inputs #:allow-other-keys)
473 (let ((rxcpp-dir "shogun/third-party/rxcpp"))
474 (mkdir-p rxcpp-dir)
475 (install-file (assoc-ref inputs "rxcpp") rxcpp-dir)
476 #t)))
477 (add-before 'build 'set-HOME
478 ;; $HOME needs to be set at some point during the build phase
479 (lambda _ (setenv "HOME" "/tmp") #t)))
480 #:configure-flags
481 (list "-DCMAKE_BUILD_WITH_INSTALL_RPATH=TRUE"
482 "-DUSE_SVMLIGHT=OFF" ;disable proprietary SVMLIGHT
483 "-DBUILD_META_EXAMPLES=OFF" ;requires unpackaged ctags
484 ;;"-DINTERFACE_JAVA=ON" ;requires unpackaged jblas
485 ;;"-DINTERFACE_RUBY=ON" ;requires unpackaged ruby-narray
486 ;;"-DINTERFACE_PERL=ON" ;"FindPerlLibs" does not exist
487 ;;"-DINTERFACE_LUA=ON" ;fails because lua doesn't build pkgconfig file
488 "-DINTERFACE_OCTAVE=ON"
489 "-DINTERFACE_PYTHON=ON"
490 "-DINTERFACE_R=ON")))
491 (inputs
492 `(("python" ,python)
493 ("numpy" ,python-numpy)
494 ("r-minimal" ,r-minimal)
495 ("octave" ,octave)
496 ("swig" ,swig)
497 ("eigen" ,eigen)
498 ("hdf5" ,hdf5)
499 ("atlas" ,atlas)
500 ("arpack" ,arpack-ng)
501 ("lapack" ,lapack)
502 ("glpk" ,glpk)
503 ("libxml2" ,libxml2)
504 ("lzo" ,lzo)
505 ("zlib" ,zlib)))
506 (native-inputs
507 `(("pkg-config" ,pkg-config)
508 ("rxcpp" ,rxcpp)))
509 ;; Non-portable SSE instructions are used so building fails on platforms
510 ;; other than x86_64.
511 (supported-systems '("x86_64-linux"))
512 (home-page "http://shogun-toolbox.org/")
513 (synopsis "Machine learning toolbox")
514 (description
515 "The Shogun Machine learning toolbox provides a wide range of unified and
516 efficient Machine Learning (ML) methods. The toolbox seamlessly allows to
517 combine multiple data representations, algorithm classes, and general purpose
518 tools. This enables both rapid prototyping of data pipelines and extensibility
519 in terms of new algorithms.")
520 (license license:gpl3+)))
521
522 (define-public rxcpp
523 (package
524 (name "rxcpp")
525 (version "4.0.0")
526 (source
527 (origin
528 (method url-fetch)
529 (uri (string-append "https://github.com/ReactiveX/RxCpp/archive/v"
530 version ".tar.gz"))
531 (sha256
532 (base32
533 "0y2isr8dy2n1yjr9c5570kpc9lvdlch6jv0jvw000amwn5d3krsh"))
534 (file-name (string-append name "-" version ".tar.gz"))))
535 (build-system cmake-build-system)
536 (arguments
537 `(#:phases
538 (modify-phases %standard-phases
539 (add-after 'unpack 'remove-werror
540 (lambda _
541 (substitute* (find-files ".")
542 (("-Werror") ""))
543 #t))
544 (replace 'check
545 (lambda _
546 (invoke "ctest"))))))
547 (native-inputs
548 `(("catch" ,catch-framework)))
549 (home-page "http://reactivex.io/")
550 (synopsis "Reactive Extensions for C++")
551 (description
552 "The Reactive Extensions for C++ (RxCpp) is a library of algorithms for
553 values-distributed-in-time. ReactiveX is a library for composing asynchronous
554 and event-based programs by using observable sequences.
555
556 It extends the observer pattern to support sequences of data and/or events and
557 adds operators that allow you to compose sequences together declaratively while
558 abstracting away concerns about things like low-level threading,
559 synchronization, thread-safety, concurrent data structures, and non-blocking
560 I/O.")
561 (license license:asl2.0)))
562
563 (define-public r-adaptivesparsity
564 (package
565 (name "r-adaptivesparsity")
566 (version "1.6")
567 (source (origin
568 (method url-fetch)
569 (uri (cran-uri "AdaptiveSparsity" version))
570 (sha256
571 (base32
572 "0imr5m8mll9j6n4icsv6z9rl5kbnwsp9wvzrg7n90nnmcxq2cz91"))))
573 (properties
574 `((upstream-name . "AdaptiveSparsity")))
575 (build-system r-build-system)
576 (arguments
577 `(#:phases
578 (modify-phases %standard-phases
579 (add-after 'unpack 'link-against-armadillo
580 (lambda _
581 (substitute* "src/Makevars"
582 (("PKG_LIBS=" prefix)
583 (string-append prefix "-larmadillo"))))))))
584 (propagated-inputs
585 `(("r-mass" ,r-mass)
586 ("r-matrix" ,r-matrix)
587 ("r-rcpp" ,r-rcpp)
588 ("r-rcpparmadillo" ,r-rcpparmadillo)))
589 (inputs
590 `(("armadillo" ,armadillo)))
591 (home-page "https://cran.r-project.org/web/packages/AdaptiveSparsity")
592 (synopsis "Adaptive sparsity models")
593 (description
594 "This package implements the Figueiredo machine learning algorithm for
595 adaptive sparsity and the Wong algorithm for adaptively sparse gaussian
596 geometric models.")
597 (license license:lgpl3+)))
598
599 (define-public r-kernlab
600 (package
601 (name "r-kernlab")
602 (version "0.9-27")
603 (source
604 (origin
605 (method url-fetch)
606 (uri (cran-uri "kernlab" version))
607 (sha256
608 (base32
609 "1m0xqf6gyvwayz7w3c83y32ayvnlz0jicj8ijk808zq9sh7dbbgn"))))
610 (build-system r-build-system)
611 (home-page "https://cran.r-project.org/web/packages/kernlab")
612 (synopsis "Kernel-based machine learning tools")
613 (description
614 "This package provides kernel-based machine learning methods for
615 classification, regression, clustering, novelty detection, quantile regression
616 and dimensionality reduction. Among other methods @code{kernlab} includes
617 Support Vector Machines, Spectral Clustering, Kernel PCA, Gaussian Processes
618 and a QP solver.")
619 (license license:gpl2)))
620
621 (define-public dlib
622 (package
623 (name "dlib")
624 (version "19.7")
625 (source (origin
626 (method url-fetch)
627 (uri (string-append
628 "http://dlib.net/files/dlib-" version ".tar.bz2"))
629 (sha256
630 (base32
631 "1mljz02kwkrbggyncxv5fpnyjdybw2qihaacb3js8yfkw12vwpc2"))
632 (modules '((guix build utils)))
633 (snippet
634 '(begin
635 ;; Delete ~13MB of bundled dependencies.
636 (delete-file-recursively "dlib/external")
637 (delete-file-recursively "docs/dlib/external")
638 #t))))
639 (build-system cmake-build-system)
640 (arguments
641 `(#:phases
642 (modify-phases %standard-phases
643 (add-after 'unpack 'disable-asserts
644 (lambda _
645 ;; config.h recommends explicitly enabling or disabling asserts
646 ;; when building as a shared library. By default neither is set.
647 (substitute* "dlib/config.h"
648 (("^//#define DLIB_DISABLE_ASSERTS") "#define DLIB_DISABLE_ASSERTS"))
649 #t))
650 (add-after 'disable-asserts 'disable-failing-tests
651 (lambda _
652 ;; One test times out on MIPS, so we need to disable it.
653 ;; Others are flaky on some platforms.
654 (let* ((system ,(or (%current-target-system)
655 (%current-system)))
656 (disabled-tests (cond
657 ((string-prefix? "mips64" system)
658 '("object_detector" ; timeout
659 "data_io"))
660 ((string-prefix? "armhf" system)
661 '("learning_to_track"))
662 ((string-prefix? "i686" system)
663 '("optimization"))
664 (else '()))))
665 (for-each
666 (lambda (test)
667 (substitute* "dlib/test/makefile"
668 (((string-append "SRC \\+= " test "\\.cpp")) "")))
669 disabled-tests)
670 #t)))
671 (replace 'check
672 (lambda _
673 ;; No test target, so we build and run the unit tests here.
674 (let ((test-dir (string-append "../dlib-" ,version "/dlib/test")))
675 (with-directory-excursion test-dir
676 (invoke "make" "-j" (number->string (parallel-job-count)))
677 (invoke "./dtest" "--runall"))
678 #t)))
679 (add-after 'install 'delete-static-library
680 (lambda* (#:key outputs #:allow-other-keys)
681 (delete-file (string-append (assoc-ref outputs "out")
682 "/lib/libdlib.a"))
683 #t)))))
684 (native-inputs
685 `(("pkg-config" ,pkg-config)
686 ;; For tests.
687 ("libnsl" ,libnsl)))
688 (inputs
689 `(("giflib" ,giflib)
690 ("lapack" ,lapack)
691 ("libjpeg" ,libjpeg)
692 ("libpng" ,libpng)
693 ("libx11" ,libx11)
694 ("openblas" ,openblas)
695 ("zlib" ,zlib)))
696 (synopsis
697 "Toolkit for making machine learning and data analysis applications in C++")
698 (description
699 "Dlib is a modern C++ toolkit containing machine learning algorithms and
700 tools. It is used in both industry and academia in a wide range of domains
701 including robotics, embedded devices, mobile phones, and large high performance
702 computing environments.")
703 (home-page "http://dlib.net")
704 (license license:boost1.0)))
705
706 (define-public python-scikit-learn
707 (package
708 (name "python-scikit-learn")
709 (version "0.20.1")
710 (source
711 (origin
712 (method git-fetch)
713 (uri (git-reference
714 (url "https://github.com/scikit-learn/scikit-learn.git")
715 (commit version)))
716 (file-name (git-file-name name version))
717 (sha256
718 (base32
719 "0qv7ir1fy9vjar3llc72yxmfja3gxm5icdf0y3q57vsn3wcdglkz"))))
720 (build-system python-build-system)
721 (arguments
722 `(#:phases
723 (modify-phases %standard-phases
724 (add-after 'build 'build-ext
725 (lambda _ (invoke "python" "setup.py" "build_ext" "--inplace") #t))
726 (replace 'check
727 (lambda _
728 ;; Restrict OpenBLAS threads to prevent segfaults while testing!
729 (setenv "OPENBLAS_NUM_THREADS" "1")
730
731 ;; Some tests require write access to $HOME.
732 (setenv "HOME" "/tmp")
733
734 (invoke "pytest" "sklearn" "-m" "not network")))
735 ;; FIXME: This fails with permission denied
736 (delete 'reset-gzip-timestamps))))
737 (inputs
738 `(("openblas" ,openblas)))
739 (native-inputs
740 `(("python-pytest" ,python-pytest)
741 ("python-pandas" ,python-pandas) ;for tests
742 ("python-cython" ,python-cython)))
743 (propagated-inputs
744 `(("python-numpy" ,python-numpy)
745 ("python-scipy" ,python-scipy)))
746 (home-page "http://scikit-learn.org/")
747 (synopsis "Machine Learning in Python")
748 (description
749 "Scikit-learn provides simple and efficient tools for data mining and
750 data analysis.")
751 (license license:bsd-3)))
752
753 (define-public python2-scikit-learn
754 (package-with-python2 python-scikit-learn))
755
756 (define-public python-autograd
757 (let* ((commit "442205dfefe407beffb33550846434baa90c4de7")
758 (revision "0")
759 (version (git-version "0.0.0" revision commit)))
760 (package
761 (name "python-autograd")
762 (home-page "https://github.com/HIPS/autograd")
763 (source (origin
764 (method git-fetch)
765 (uri (git-reference
766 (url home-page)
767 (commit commit)))
768 (sha256
769 (base32
770 "189sv2xb0mwnjawa9z7mrgdglc1miaq93pnck26r28fi1jdwg0z4"))
771 (file-name (git-file-name name version))))
772 (version version)
773 (build-system python-build-system)
774 (native-inputs
775 `(("python-nose" ,python-nose)
776 ("python-pytest" ,python-pytest)))
777 (propagated-inputs
778 `(("python-future" ,python-future)
779 ("python-numpy" ,python-numpy)))
780 (arguments
781 `(#:phases (modify-phases %standard-phases
782 (replace 'check
783 (lambda _
784 (invoke "py.test" "-v"))))))
785 (synopsis "Efficiently computes derivatives of NumPy code")
786 (description "Autograd can automatically differentiate native Python and
787 NumPy code. It can handle a large subset of Python's features, including loops,
788 ifs, recursion and closures, and it can even take derivatives of derivatives
789 of derivatives. It supports reverse-mode differentiation
790 (a.k.a. backpropagation), which means it can efficiently take gradients of
791 scalar-valued functions with respect to array-valued arguments, as well as
792 forward-mode differentiation, and the two can be composed arbitrarily. The
793 main intended application of Autograd is gradient-based optimization.")
794 (license license:expat))))
795
796 (define-public python2-autograd
797 (package-with-python2 python-autograd))
798
799 (define-public lightgbm
800 (package
801 (name "lightgbm")
802 (version "2.0.12")
803 (source (origin
804 (method url-fetch)
805 (uri (string-append
806 "https://github.com/Microsoft/LightGBM/archive/v"
807 version ".tar.gz"))
808 (sha256
809 (base32
810 "132zf0yk0545mg72hyzxm102g3hpb6ixx9hnf8zd2k55gas6cjj1"))
811 (file-name (string-append name "-" version ".tar.gz"))))
812 (native-inputs
813 `(("python-pytest" ,python-pytest)
814 ("python-nose" ,python-nose)))
815 (inputs
816 `(("openmpi" ,openmpi)))
817 (propagated-inputs
818 `(("python-numpy" ,python-numpy)
819 ("python-scipy" ,python-scipy)))
820 (arguments
821 `(#:configure-flags
822 '("-DUSE_MPI=ON")
823 #:phases
824 (modify-phases %standard-phases
825 (replace 'check
826 (lambda* (#:key outputs #:allow-other-keys)
827 (with-directory-excursion ,(string-append "../LightGBM-" version)
828 (invoke "pytest" "tests/c_api_test/test_.py")))))))
829 (build-system cmake-build-system)
830 (home-page "https://github.com/Microsoft/LightGBM")
831 (synopsis "Gradient boosting framework based on decision tree algorithms")
832 (description "LightGBM is a gradient boosting framework that uses tree
833 based learning algorithms. It is designed to be distributed and efficient with
834 the following advantages:
835
836 @itemize
837 @item Faster training speed and higher efficiency
838 @item Lower memory usage
839 @item Better accuracy
840 @item Parallel and GPU learning supported (not enabled in this package)
841 @item Capable of handling large-scale data
842 @end itemize\n")
843 (license license:expat)))
844
845 (define-public vowpal-wabbit
846 ;; Language bindings not included.
847 (package
848 (name "vowpal-wabbit")
849 (version "8.5.0")
850 (source (origin
851 (method url-fetch)
852 (uri (string-append
853 "https://github.com/JohnLangford/vowpal_wabbit/archive/"
854 version ".tar.gz"))
855 (sha256
856 (base32
857 "0clp2kb7rk5sckhllxjr5a651awf4s8dgzg4659yh4hf5cqnf0gr"))
858 (file-name (string-append name "-" version ".tar.gz"))))
859 (inputs
860 `(("boost" ,boost)
861 ("zlib" ,zlib)))
862 (arguments
863 `(#:configure-flags
864 (list (string-append "--with-boost="
865 (assoc-ref %build-inputs "boost")))))
866 (build-system gnu-build-system)
867 (home-page "https://github.com/JohnLangford/vowpal_wabbit")
868 (synopsis "Fast machine learning library for online learning")
869 (description "Vowpal Wabbit is a machine learning system with techniques
870 such as online, hashing, allreduce, reductions, learning2search, active, and
871 interactive learning.")
872 (license license:bsd-3)))