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