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