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