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