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