gnu: nss, nss-certs: Update to 3.27.2.
[jackhill/guix/guix.git] / gnu / packages / machine-learning.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2015, 2016 Ricardo Wurmus <rekado@elephly.net>
3 ;;; Copyright © 2016 Efraim Flashner <efraim@flashner.co.il>
4 ;;; Copyright © 2016 Marius Bakke <mbakke@fastmail.com>
5 ;;;
6 ;;; This file is part of GNU Guix.
7 ;;;
8 ;;; GNU Guix is free software; you can redistribute it and/or modify it
9 ;;; under the terms of the GNU General Public License as published by
10 ;;; the Free Software Foundation; either version 3 of the License, or (at
11 ;;; your option) any later version.
12 ;;;
13 ;;; GNU Guix is distributed in the hope that it will be useful, but
14 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;;; GNU General Public License for more details.
17 ;;;
18 ;;; You should have received a copy of the GNU General Public License
19 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20
21 (define-module (gnu packages machine-learning)
22 #:use-module ((guix licenses) #:prefix license:)
23 #:use-module (guix packages)
24 #:use-module (guix utils)
25 #:use-module (guix download)
26 #:use-module (guix svn-download)
27 #:use-module (guix build-system cmake)
28 #:use-module (guix build-system gnu)
29 #:use-module (guix build-system r)
30 #:use-module (gnu packages)
31 #:use-module (gnu packages autotools)
32 #:use-module (gnu packages boost)
33 #:use-module (gnu packages compression)
34 #:use-module (gnu packages dejagnu)
35 #:use-module (gnu packages gcc)
36 #:use-module (gnu packages image)
37 #:use-module (gnu packages maths)
38 #:use-module (gnu packages perl)
39 #:use-module (gnu packages pkg-config)
40 #:use-module (gnu packages python)
41 #:use-module (gnu packages statistics)
42 #:use-module (gnu packages swig)
43 #:use-module (gnu packages xml)
44 #:use-module (gnu packages xorg))
45
46 (define-public libsvm
47 (package
48 (name "libsvm")
49 (version "3.20")
50 (source
51 (origin
52 (method url-fetch)
53 (uri (string-append
54 "https://github.com/cjlin1/libsvm/archive/v"
55 (string-delete #\. version) ".tar.gz"))
56 (file-name (string-append name "-" version ".tar.gz"))
57 (sha256
58 (base32
59 "1jpjlql3frjza7zxzrqqr2firh44fjb8fqsdmvz6bjz7sb47zgp4"))))
60 (build-system gnu-build-system)
61 (arguments
62 `(#:tests? #f ;no "check" target
63 #:phases (modify-phases %standard-phases
64 (delete 'configure)
65 (replace
66 'install
67 (lambda* (#:key outputs #:allow-other-keys)
68 (let* ((out (assoc-ref outputs "out"))
69 (bin (string-append out "/bin/")))
70 (mkdir-p bin)
71 (for-each (lambda (file)
72 (copy-file file (string-append bin file)))
73 '("svm-train"
74 "svm-predict"
75 "svm-scale")))
76 #t)))))
77 (home-page "http://www.csie.ntu.edu.tw/~cjlin/libsvm/")
78 (synopsis "Library for Support Vector Machines")
79 (description
80 "LIBSVM is a machine learning library for support vector
81 classification, (C-SVC, nu-SVC), regression (epsilon-SVR, nu-SVR) and
82 distribution estimation (one-class SVM). It supports multi-class
83 classification.")
84 (license license:bsd-3)))
85
86 (define-public python-libsvm
87 (package (inherit libsvm)
88 (name "python-libsvm")
89 (build-system gnu-build-system)
90 (arguments
91 `(#:tests? #f ;no "check" target
92 #:make-flags '("-C" "python")
93 #:phases
94 (modify-phases %standard-phases
95 (delete 'configure)
96 (replace
97 'install
98 (lambda* (#:key inputs outputs #:allow-other-keys)
99 (let ((site (string-append (assoc-ref outputs "out")
100 "/lib/python"
101 (string-take
102 (string-take-right
103 (assoc-ref inputs "python") 5) 3)
104 "/site-packages/")))
105 (substitute* "python/svm.py"
106 (("../libsvm.so.2") "libsvm.so.2"))
107 (mkdir-p site)
108 (for-each (lambda (file)
109 (copy-file file (string-append site (basename file))))
110 (find-files "python" "\\.py"))
111 (copy-file "libsvm.so.2"
112 (string-append site "libsvm.so.2")))
113 #t)))))
114 (inputs
115 `(("python" ,python)))
116 (synopsis "Python bindings of libSVM")))
117
118 (define-public ghmm
119 ;; The latest release candidate is several years and a couple of fixes have
120 ;; been published since. This is why we download the sources from the SVN
121 ;; repository.
122 (let ((svn-revision 2341))
123 (package
124 (name "ghmm")
125 (version (string-append "0.9-rc3-0." (number->string svn-revision)))
126 (source (origin
127 (method svn-fetch)
128 (uri (svn-reference
129 (url "http://svn.code.sf.net/p/ghmm/code/trunk")
130 (revision svn-revision)))
131 (file-name (string-append name "-" version))
132 (sha256
133 (base32
134 "0qbq1rqp94l530f043qzp8aw5lj7dng9wq0miffd7spd1ff638wq"))))
135 (build-system gnu-build-system)
136 (arguments
137 `(#:imported-modules (,@%gnu-build-system-modules
138 (guix build python-build-system))
139 #:phases
140 (modify-phases %standard-phases
141 (add-after 'unpack 'enter-dir
142 (lambda _ (chdir "ghmm") #t))
143 (delete 'check)
144 (add-after 'install 'check
145 (assoc-ref %standard-phases 'check))
146 (add-before 'check 'fix-PYTHONPATH
147 (lambda* (#:key inputs outputs #:allow-other-keys)
148 (let ((python-version ((@@ (guix build python-build-system)
149 get-python-version)
150 (assoc-ref inputs "python"))))
151 (setenv "PYTHONPATH"
152 (string-append (getenv "PYTHONPATH")
153 ":" (assoc-ref outputs "out")
154 "/lib/python" python-version
155 "/site-packages")))
156 #t))
157 (add-after 'enter-dir 'fix-runpath
158 (lambda* (#:key outputs #:allow-other-keys)
159 (substitute* "ghmmwrapper/setup.py"
160 (("^(.*)extra_compile_args = \\[" line indent)
161 (string-append indent
162 "extra_link_args = [\"-Wl,-rpath="
163 (assoc-ref outputs "out") "/lib\"],\n"
164 line
165 "\"-Wl,-rpath="
166 (assoc-ref outputs "out")
167 "/lib\", ")))
168 #t))
169 (add-after 'enter-dir 'disable-broken-tests
170 (lambda _
171 (substitute* "tests/Makefile.am"
172 ;; GHMM_SILENT_TESTS is assumed to be a command.
173 (("TESTS_ENVIRONMENT.*") "")
174 ;; Do not build broken tests.
175 (("chmm .*") "")
176 (("read_fa .*") "")
177 (("mcmc .*") "")
178 (("label_higher_order_test.*$")
179 "label_higher_order_test\n"))
180
181 ;; These Python unittests are broken as there is no gato.
182 ;; See https://sourceforge.net/p/ghmm/support-requests/3/
183 (substitute* "ghmmwrapper/ghmmunittests.py"
184 (("^(.*)def (testNewXML|testMultipleTransitionClasses|testNewXML)"
185 line indent)
186 (string-append indent
187 "@unittest.skip(\"Disabled by Guix\")\n"
188 line)))
189 #t))
190 (add-before 'configure 'autogen
191 (lambda _
192 (zero? (system* "bash" "./autogen.sh")))))))
193 (inputs
194 `(("python" ,python-2) ; only Python 2 is supported
195 ("libxml2" ,libxml2)))
196 (native-inputs
197 `(("pkg-config" ,pkg-config)
198 ("dejagnu" ,dejagnu)
199 ("swig" ,swig)
200 ("autoconf" ,autoconf)
201 ("automake" ,automake)
202 ("libtool" ,libtool)))
203 (home-page "http://ghmm.org")
204 (synopsis "Hidden Markov Model library")
205 (description
206 "The General Hidden Markov Model library (GHMM) is a C library with
207 additional Python bindings implementing a wide range of types of @dfn{Hidden
208 Markov Models} (HMM) and algorithms: discrete, continous emissions, basic
209 training, HMM clustering, HMM mixtures.")
210 (license license:lgpl2.0+))))
211
212 (define-public mcl
213 (package
214 (name "mcl")
215 (version "14.137")
216 (source (origin
217 (method url-fetch)
218 (uri (string-append
219 "http://micans.org/mcl/src/mcl-"
220 (string-replace-substring version "." "-")
221 ".tar.gz"))
222 (sha256
223 (base32
224 "15xlax3z31lsn62vlg94hkm75nm40q4679amnfg13jm8m2bnhy5m"))))
225 (build-system gnu-build-system)
226 (arguments
227 `(#:configure-flags (list "--enable-blast")))
228 (inputs
229 `(("perl" ,perl)))
230 (home-page "http://micans.org/mcl/")
231 (synopsis "Clustering algorithm for graphs")
232 (description
233 "The MCL algorithm is short for the @dfn{Markov Cluster Algorithm}, a
234 fast and scalable unsupervised cluster algorithm for graphs (also known as
235 networks) based on simulation of (stochastic) flow in graphs.")
236 ;; In the LICENCE file and web page it says "The software is licensed
237 ;; under the GNU General Public License, version 3.", but in several of
238 ;; the source code files it suggests GPL3 or later.
239 ;; http://listserver.ebi.ac.uk/pipermail/mcl-users/2016/000376.html
240 (license license:gpl3)))
241
242 (define-public randomjungle
243 (package
244 (name "randomjungle")
245 (version "2.1.0")
246 (source
247 (origin
248 (method url-fetch)
249 (uri (string-append
250 "http://www.imbs-luebeck.de/imbs/sites/default/files/u59/"
251 "randomjungle-" version ".tar_.gz"))
252 (sha256
253 (base32
254 "12c8rf30cla71swx2mf4ww9mfd8jbdw5lnxd7dxhyw1ygrvg6y4w"))))
255 (build-system gnu-build-system)
256 (arguments
257 `(#:configure-flags
258 (list (string-append "--with-boost="
259 (assoc-ref %build-inputs "boost")))
260 #:phases
261 (modify-phases %standard-phases
262 (add-before
263 'configure 'set-CXXFLAGS
264 (lambda _
265 (setenv "CXXFLAGS" "-fpermissive ")
266 #t)))))
267 (inputs
268 `(("boost" ,boost)
269 ("gsl" ,gsl)
270 ("libxml2" ,libxml2)
271 ("zlib" ,zlib)))
272 (native-inputs
273 `(("gfortran" ,gfortran)
274 ("gfortran:lib" ,gfortran "lib")))
275 ;; Non-portable assembly instructions are used so building fails on
276 ;; platforms other than x86_64 or i686.
277 (supported-systems '("x86_64-linux" "i686-linux"))
278 (home-page "http://www.imbs-luebeck.de/imbs/de/node/227/")
279 (synopsis "Implementation of the Random Forests machine learning method")
280 (description
281 "Random Jungle is an implementation of Random Forests. It is supposed to
282 analyse high dimensional data. In genetics, it can be used for analysing big
283 Genome Wide Association (GWA) data. Random Forests is a powerful machine
284 learning method. Most interesting features are variable selection, missing
285 value imputation, classifier creation, generalization error estimation and
286 sample proximities between pairs of cases.")
287 (license license:gpl3+)))
288
289 (define-public shogun
290 (package
291 (name "shogun")
292 (version "4.0.0")
293 (source
294 (origin
295 (method url-fetch)
296 (uri (string-append
297 "ftp://shogun-toolbox.org/shogun/releases/"
298 (version-major+minor version)
299 "/sources/shogun-" version ".tar.bz2"))
300 (sha256
301 (base32
302 "159nlijnb7mnrv9za80wnm1shwvy45hgrqzn51hxy7gw4z6d6fdb"))
303 (modules '((guix build utils)
304 (ice-9 rdelim)))
305 (snippet
306 '(begin
307 ;; Remove non-free sources and files referencing them
308 (for-each delete-file
309 (find-files "src/shogun/classifier/svm/"
310 "SVMLight\\.(cpp|h)"))
311 (for-each delete-file
312 (find-files "examples/undocumented/libshogun/"
313 (string-append
314 "(classifier_.*svmlight.*|"
315 "evaluation_cross_validation_locked_comparison).cpp")))
316 ;; Remove non-free functions.
317 (define (delete-ifdefs file)
318 (with-atomic-file-replacement file
319 (lambda (in out)
320 (let loop ((line (read-line in 'concat))
321 (skipping? #f))
322 (if (eof-object? line)
323 #t
324 (let ((skip-next?
325 (or (and skipping?
326 (not (string-prefix?
327 "#endif //USE_SVMLIGHT" line)))
328 (string-prefix?
329 "#ifdef USE_SVMLIGHT" line))))
330 (when (or (not skipping?)
331 (and skipping? (not skip-next?)))
332 (display line out))
333 (loop (read-line in 'concat) skip-next?)))))))
334 (for-each delete-ifdefs (find-files "src/shogun/kernel/"
335 "^Kernel\\.(cpp|h)"))))))
336 (build-system cmake-build-system)
337 (arguments
338 '(#:tests? #f ;no check target
339 #:phases
340 (alist-cons-after
341 'unpack 'delete-broken-symlinks
342 (lambda _
343 (for-each delete-file '("applications/arts/data"
344 "applications/asp/data"
345 "applications/easysvm/data"
346 "applications/msplicer/data"
347 "applications/ocr/data"
348 "examples/documented/data"
349 "examples/documented/matlab_static"
350 "examples/documented/octave_static"
351 "examples/undocumented/data"
352 "examples/undocumented/matlab_static"
353 "examples/undocumented/octave_static"
354 "tests/integration/data"
355 "tests/integration/matlab_static"
356 "tests/integration/octave_static"
357 "tests/integration/python_modular/tests"))
358 #t)
359 (alist-cons-after
360 'unpack 'change-R-target-path
361 (lambda* (#:key outputs #:allow-other-keys)
362 (substitute* '("src/interfaces/r_modular/CMakeLists.txt"
363 "src/interfaces/r_static/CMakeLists.txt"
364 "examples/undocumented/r_modular/CMakeLists.txt")
365 (("\\$\\{R_COMPONENT_LIB_PATH\\}")
366 (string-append (assoc-ref outputs "out")
367 "/lib/R/library/")))
368 #t)
369 (alist-cons-after
370 'unpack 'fix-octave-modules
371 (lambda* (#:key outputs #:allow-other-keys)
372 (substitute* '("src/interfaces/octave_modular/CMakeLists.txt"
373 "src/interfaces/octave_static/CMakeLists.txt")
374 (("^include_directories\\(\\$\\{OCTAVE_INCLUDE_DIRS\\}")
375 "include_directories(${OCTAVE_INCLUDE_DIRS} ${OCTAVE_INCLUDE_DIRS}/octave"))
376
377 ;; change target directory
378 (substitute* "src/interfaces/octave_modular/CMakeLists.txt"
379 (("\\$\\{OCTAVE_OCT_LOCAL_API_FILE_DIR\\}")
380 (string-append (assoc-ref outputs "out")
381 "/share/octave/packages")))
382 #t)
383 (alist-cons-before
384 'build 'set-HOME
385 ;; $HOME needs to be set at some point during the build phase
386 (lambda _ (setenv "HOME" "/tmp") #t)
387 %standard-phases))))
388 #:configure-flags
389 (list "-DCMAKE_BUILD_WITH_INSTALL_RPATH=TRUE"
390 "-DUSE_SVMLIGHT=OFF" ;disable proprietary SVMLIGHT
391 ;;"-DJavaModular=ON" ;requires unpackaged jblas
392 ;;"-DRubyModular=ON" ;requires unpackaged ruby-narray
393 ;;"-DPerlModular=ON" ;"FindPerlLibs" does not exist
394 ;;"-DLuaModular=ON" ;fails because lua doesn't build pkgconfig file
395 "-DOctaveModular=ON"
396 "-DOctaveStatic=ON"
397 "-DPythonModular=ON"
398 "-DPythonStatic=ON"
399 "-DRModular=ON"
400 "-DRStatic=ON"
401 "-DCmdLineStatic=ON")))
402 (inputs
403 `(("python" ,python)
404 ("numpy" ,python-numpy)
405 ("r" ,r)
406 ("octave" ,octave)
407 ("swig" ,swig)
408 ("hdf5" ,hdf5)
409 ("atlas" ,atlas)
410 ("arpack" ,arpack-ng)
411 ("lapack" ,lapack)
412 ("glpk" ,glpk)
413 ("libxml2" ,libxml2)
414 ("lzo" ,lzo)
415 ("zlib" ,zlib)))
416 (native-inputs
417 `(("pkg-config" ,pkg-config)))
418 ;; Non-portable SSE instructions are used so building fails on platforms
419 ;; other than x86_64.
420 (supported-systems '("x86_64-linux"))
421 (home-page "http://shogun-toolbox.org/")
422 (synopsis "Machine learning toolbox")
423 (description
424 "The Shogun Machine learning toolbox provides a wide range of unified and
425 efficient Machine Learning (ML) methods. The toolbox seamlessly allows to
426 combine multiple data representations, algorithm classes, and general purpose
427 tools. This enables both rapid prototyping of data pipelines and extensibility
428 in terms of new algorithms.")
429 (license license:gpl3+)))
430
431 (define-public r-adaptivesparsity
432 (package
433 (name "r-adaptivesparsity")
434 (version "1.4")
435 (source (origin
436 (method url-fetch)
437 (uri (cran-uri "AdaptiveSparsity" version))
438 (sha256
439 (base32
440 "1az7isvalf3kmdiycrfl6s9k9xqk22k1mc6rh8v0jmcz402qyq8z"))))
441 (properties
442 `((upstream-name . "AdaptiveSparsity")))
443 (build-system r-build-system)
444 (arguments
445 `(#:phases
446 (modify-phases %standard-phases
447 (add-after 'unpack 'link-against-armadillo
448 (lambda _
449 (substitute* "src/Makevars"
450 (("PKG_LIBS=" prefix)
451 (string-append prefix "-larmadillo"))))))))
452 (propagated-inputs
453 `(("r-rcpp" ,r-rcpp)
454 ("r-rcpparmadillo" ,r-rcpparmadillo)))
455 (home-page "http://cran.r-project.org/web/packages/AdaptiveSparsity")
456 (synopsis "Adaptive sparsity models")
457 (description
458 "This package implements the Figueiredo machine learning algorithm for
459 adaptive sparsity and the Wong algorithm for adaptively sparse gaussian
460 geometric models.")
461 (license license:lgpl3+)))
462
463 (define-public r-nnet
464 (package
465 (name "r-nnet")
466 (version "7.3-12")
467 (source
468 (origin
469 (method url-fetch)
470 (uri (cran-uri "nnet" version))
471 (sha256
472 (base32
473 "17amqnw9dpap2w8ivx53hxha2xrm0drwfnj32li0xk41hlz548r7"))))
474 (build-system r-build-system)
475 (home-page "http://www.stats.ox.ac.uk/pub/MASS4/")
476 (synopsis "Feed-forward neural networks and multinomial log-linear models")
477 (description
478 "This package provides functions for feed-forward neural networks with a
479 single hidden layer, and for multinomial log-linear models.")
480 (license (list license:gpl2+ license:gpl3+))))
481
482 (define-public r-kernlab
483 (package
484 (name "r-kernlab")
485 (version "0.9-25")
486 (source
487 (origin
488 (method url-fetch)
489 (uri (cran-uri "kernlab" version))
490 (sha256
491 (base32
492 "0qnaq9x3j2xc6jrmmd98wc6hkzch487s4p3a9lnc00xvahkhgpmr"))))
493 (build-system r-build-system)
494 (home-page "http://cran.r-project.org/web/packages/kernlab")
495 (synopsis "Kernel-based machine learning tools")
496 (description
497 "This package provides kernel-based machine learning methods for
498 classification, regression, clustering, novelty detection, quantile regression
499 and dimensionality reduction. Among other methods @code{kernlab} includes
500 Support Vector Machines, Spectral Clustering, Kernel PCA, Gaussian Processes
501 and a QP solver.")
502 (license license:gpl2)))
503
504 (define-public dlib
505 (package
506 (name "dlib")
507 (version "19.1")
508 (source (origin
509 (method url-fetch)
510 (uri (string-append
511 "http://dlib.net/files/dlib-" version ".tar.bz2"))
512 (sha256
513 (base32
514 "0p2pvcdalc6jhb6r99ybvjd9x74sclr0ngswdg9j2xl5pj7knbr4"))
515 (modules '((guix build utils)))
516 (snippet
517 '(begin
518 ;; Delete ~13MB of bundled dependencies.
519 (delete-file-recursively "dlib/external")
520 (delete-file-recursively "docs/dlib/external")))))
521 (build-system cmake-build-system)
522 (arguments
523 `(#:phases
524 (modify-phases %standard-phases
525 (add-after 'unpack 'disable-asserts
526 (lambda _
527 ;; config.h recommends explicitly enabling or disabling asserts
528 ;; when building as a shared library. By default neither is set.
529 (substitute* "dlib/config.h"
530 (("^//#define DLIB_DISABLE_ASSERTS") "#define DLIB_DISABLE_ASSERTS"))
531 #t))
532 (add-after 'disable-asserts 'disable-failing-tests
533 (lambda _
534 ;; One test times out on MIPS, so we need to disable it.
535 ;; The rest is known to fail on non-x86_64 platforms in the current release.
536 ;; Some have been fixed in git; this list should be readjusted next update.
537 (let* ((system ,(or (%current-target-system)
538 (%current-system)))
539 (disabled-tests (cond
540 ((string-prefix? "mips64" system)
541 '("object_detector" ; timeout
542 "data_io"))
543 ((string-prefix? "armhf" system)
544 '("learning_to_track" "max_cost_assignment"))
545 ((string-prefix? "i686" system)
546 '("optimization" "matrix2" "mpc"))
547 (else '()))))
548 ;; The following test fails due a bug in openblas < 0.2.18.
549 (append! disabled-tests '("empirical_map"))
550 (for-each
551 (lambda (test)
552 (substitute* "dlib/test/makefile"
553 (((string-append "SRC \\+= " test "\\.cpp")) "")) #t)
554 disabled-tests))))
555 (replace 'check
556 (lambda _
557 ;; No test target, so we build and run the unit tests here.
558 (let ((test-dir (string-append "../dlib-" ,version "/dlib/test")))
559 (with-directory-excursion test-dir
560 (setenv "CXXFLAGS" "-std=gnu++11")
561 (and (zero? (system* "make" "-j" (number->string (parallel-job-count))))
562 (zero? (system* "./dtest" "--runall")))))))
563 (add-after 'install 'delete-static-library
564 (lambda* (#:key outputs #:allow-other-keys)
565 (delete-file (string-append (assoc-ref outputs "out") "/lib/libdlib.a")))))))
566 (native-inputs
567 `(("pkg-config" ,pkg-config)))
568 (inputs
569 `(("giflib" ,giflib)
570 ("lapack" ,lapack)
571 ("libjpeg" ,libjpeg)
572 ("libpng" ,libpng)
573 ("libx11" ,libx11)
574 ("openblas" ,openblas)
575 ("zlib" ,zlib)))
576 (synopsis
577 "Toolkit for making machine learning and data analysis applications in C++")
578 (description
579 "Dlib is a modern C++ toolkit containing machine learning algorithms and
580 tools. It is used in both industry and academia in a wide range of domains
581 including robotics, embedded devices, mobile phones, and large high performance
582 computing environments.")
583 (home-page "http://dlib.net")
584 (license license:boost1.0)))