1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2015, 2016, 2017, 2018, 2019 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, 2019 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 ;;; Copyright © 2019 Nicolas Goaziou <mail@nicolasgoaziou.fr>
14 ;;; Copyright © 2019 Guillaume Le Vaillant <glv@posteo.net>
16 ;;; This file is part of GNU Guix.
18 ;;; GNU Guix is free software; you can redistribute it and/or modify it
19 ;;; under the terms of the GNU General Public License as published by
20 ;;; the Free Software Foundation; either version 3 of the License, or (at
21 ;;; your option) any later version.
23 ;;; GNU Guix is distributed in the hope that it will be useful, but
24 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
25 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 ;;; GNU General Public License for more details.
28 ;;; You should have received a copy of the GNU General Public License
29 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
31 (define-module (gnu packages machine-learning)
32 #:use-module ((guix licenses) #:prefix license:)
33 #:use-module (guix packages)
34 #:use-module (guix utils)
35 #:use-module (guix download)
36 #:use-module (guix svn-download)
37 #:use-module (guix build-system asdf)
38 #:use-module (guix build-system cmake)
39 #:use-module (guix build-system gnu)
40 #:use-module (guix build-system ocaml)
41 #:use-module (guix build-system python)
42 #:use-module (guix build-system r)
43 #:use-module (guix git-download)
44 #:use-module (gnu packages)
45 #:use-module (gnu packages adns)
46 #:use-module (gnu packages algebra)
47 #:use-module (gnu packages audio)
48 #:use-module (gnu packages autotools)
49 #:use-module (gnu packages base)
50 #:use-module (gnu packages bash)
51 #:use-module (gnu packages boost)
52 #:use-module (gnu packages check)
53 #:use-module (gnu packages compression)
54 #:use-module (gnu packages cran)
55 #:use-module (gnu packages databases)
56 #:use-module (gnu packages dejagnu)
57 #:use-module (gnu packages gcc)
58 #:use-module (gnu packages glib)
59 #:use-module (gnu packages graphviz)
60 #:use-module (gnu packages gstreamer)
61 #:use-module (gnu packages image)
62 #:use-module (gnu packages linux)
63 #:use-module (gnu packages lisp)
64 #:use-module (gnu packages maths)
65 #:use-module (gnu packages mpi)
66 #:use-module (gnu packages ocaml)
67 #:use-module (gnu packages onc-rpc)
68 #:use-module (gnu packages perl)
69 #:use-module (gnu packages pkg-config)
70 #:use-module (gnu packages protobuf)
71 #:use-module (gnu packages python)
72 #:use-module (gnu packages python-web)
73 #:use-module (gnu packages python-xyz)
74 #:use-module (gnu packages serialization)
75 #:use-module (gnu packages sphinx)
76 #:use-module (gnu packages statistics)
77 #:use-module (gnu packages sqlite)
78 #:use-module (gnu packages swig)
79 #:use-module (gnu packages tls)
80 #:use-module (gnu packages web)
81 #:use-module (gnu packages xml)
82 #:use-module (gnu packages xorg)
83 #:use-module (ice-9 match))
86 ;; The last release is >100 commits behind, so we package from git.
87 (let ((commit "d71d54788bee56ba4cf7522801270152da5209d7"))
90 (version (string-append "2.2.0-1." (string-take commit 8)))
94 (url "https://github.com/libfann/fann.git")
96 (file-name (string-append name "-" version "-checkout"))
99 "0ibwpfrjs6q2lijs8slxjgzb2llcl6rk3v2ski4r6215g5jjhg3x"))))
100 (build-system cmake-build-system)
103 (modify-phases %standard-phases
105 (lambda* (#:key outputs #:allow-other-keys)
106 (let* ((out (assoc-ref outputs "out")))
107 (with-directory-excursion (string-append (getcwd) "/tests")
108 (invoke "./fann_tests"))))))))
109 (home-page "http://leenissen.dk/fann/wp/")
110 (synopsis "Fast Artificial Neural Network")
112 "FANN is a free open source neural network library, which implements
113 multilayer artificial neural networks in C with support for both fully
114 connected and sparsely connected networks.")
115 (license license:lgpl2.1))))
117 (define-public libsvm
124 (uri (string-append "https://www.csie.ntu.edu.tw/~cjlin/libsvm/"
125 name "-" version ".tar.gz"))
127 (base32 "0jpaq0rr92x38p4nk3gjan79ip67m6p80anb28z1d8601miysyi5"))))
128 (build-system gnu-build-system)
130 `(#:tests? #f ; no "check" target
131 #:phases (modify-phases %standard-phases
134 'install ; no ‘install’ target
135 (lambda* (#:key outputs #:allow-other-keys)
136 (let* ((out (assoc-ref outputs "out"))
137 (bin (string-append out "/bin/")))
139 (for-each (lambda (file)
140 (copy-file file (string-append bin file)))
145 (home-page "http://www.csie.ntu.edu.tw/~cjlin/libsvm/")
146 (synopsis "Library for Support Vector Machines")
148 "LIBSVM is a machine learning library for support vector
149 classification, (C-SVC, nu-SVC), regression (epsilon-SVR, nu-SVR) and
150 distribution estimation (one-class SVM). It supports multi-class
152 (license license:bsd-3)))
154 (define-public python-libsvm
155 (package (inherit libsvm)
156 (name "python-libsvm")
157 (build-system gnu-build-system)
159 `(#:tests? #f ; no "check" target
160 #:make-flags '("-C" "python")
162 (modify-phases %standard-phases
165 'install ; no ‘install’ target
166 (lambda* (#:key inputs outputs #:allow-other-keys)
167 (let ((site (string-append (assoc-ref outputs "out")
171 (assoc-ref inputs "python") 5) 3)
173 (substitute* "python/svm.py"
174 (("../libsvm.so.2") "libsvm.so.2"))
176 (for-each (lambda (file)
177 (copy-file file (string-append site (basename file))))
178 (find-files "python" "\\.py"))
179 (copy-file "libsvm.so.2"
180 (string-append site "libsvm.so.2")))
183 `(("python" ,python)))
184 (synopsis "Python bindings of libSVM")))
187 ;; The latest release candidate is several years and a couple of fixes have
188 ;; been published since. This is why we download the sources from the SVN
190 (let ((svn-revision 2341))
193 (version (string-append "0.9-rc3-0." (number->string svn-revision)))
197 (url "http://svn.code.sf.net/p/ghmm/code/trunk")
198 (revision svn-revision)))
199 (file-name (string-append name "-" version "-checkout"))
202 "0qbq1rqp94l530f043qzp8aw5lj7dng9wq0miffd7spd1ff638wq"))))
203 (build-system gnu-build-system)
205 `(#:imported-modules (,@%gnu-build-system-modules
206 (guix build python-build-system))
208 (modify-phases %standard-phases
209 (add-after 'unpack 'enter-dir
210 (lambda _ (chdir "ghmm") #t))
212 (add-after 'install 'check
213 (assoc-ref %standard-phases 'check))
214 (add-before 'check 'fix-PYTHONPATH
215 (lambda* (#:key inputs outputs #:allow-other-keys)
216 (let ((python-version (python-version
217 (assoc-ref inputs "python"))))
219 (string-append (getenv "PYTHONPATH")
220 ":" (assoc-ref outputs "out")
221 "/lib/python" python-version
224 (add-after 'enter-dir 'fix-runpath
225 (lambda* (#:key outputs #:allow-other-keys)
226 (substitute* "ghmmwrapper/setup.py"
227 (("^(.*)extra_compile_args = \\[" line indent)
228 (string-append indent
229 "extra_link_args = [\"-Wl,-rpath="
230 (assoc-ref outputs "out") "/lib\"],\n"
233 (assoc-ref outputs "out")
236 (add-after 'enter-dir 'disable-broken-tests
238 (substitute* "tests/Makefile.am"
239 ;; GHMM_SILENT_TESTS is assumed to be a command.
240 (("TESTS_ENVIRONMENT.*") "")
241 ;; Do not build broken tests.
245 (("label_higher_order_test.*$")
246 "label_higher_order_test\n"))
248 ;; These Python unittests are broken as there is no gato.
249 ;; See https://sourceforge.net/p/ghmm/support-requests/3/
250 (substitute* "ghmmwrapper/ghmmunittests.py"
251 (("^(.*)def (testNewXML|testMultipleTransitionClasses|testNewXML)"
253 (string-append indent
254 "@unittest.skip(\"Disabled by Guix\")\n"
258 `(("python" ,python-2) ; only Python 2 is supported
259 ("libxml2" ,libxml2)))
261 `(("pkg-config" ,pkg-config)
264 ("autoconf" ,autoconf)
265 ("automake" ,automake)
266 ("libtool" ,libtool)))
267 (home-page "http://ghmm.org")
268 (synopsis "Hidden Markov Model library")
270 "The General Hidden Markov Model library (GHMM) is a C library with
271 additional Python bindings implementing a wide range of types of @dfn{Hidden
272 Markov Models} (HMM) and algorithms: discrete, continuous emissions, basic
273 training, HMM clustering, HMM mixtures.")
274 (license license:lgpl2.0+))))
283 "http://micans.org/mcl/src/mcl-"
284 (string-replace-substring version "." "-")
288 "15xlax3z31lsn62vlg94hkm75nm40q4679amnfg13jm8m2bnhy5m"))))
289 (build-system gnu-build-system)
291 `(#:configure-flags (list "--enable-blast")))
294 (home-page "http://micans.org/mcl/")
295 (synopsis "Clustering algorithm for graphs")
297 "The MCL algorithm is short for the @dfn{Markov Cluster Algorithm}, a
298 fast and scalable unsupervised cluster algorithm for graphs (also known as
299 networks) based on simulation of (stochastic) flow in graphs.")
300 ;; In the LICENCE file and web page it says "The software is licensed
301 ;; under the GNU General Public License, version 3.", but in several of
302 ;; the source code files it suggests GPL3 or later.
303 ;; http://listserver.ebi.ac.uk/pipermail/mcl-users/2016/000376.html
304 (license license:gpl3)))
306 (define-public ocaml-mcl
309 (version "12-068oasis4")
314 (url "https://github.com/fhcrc/mcl.git")
316 (file-name (git-file-name name version))
319 "0009dc3h2jp3qg5val452wngpqnbfyhbcxylghq0mrjqxx0jdq5p"))))
320 (build-system ocaml-build-system)
323 (modify-phases %standard-phases
324 (add-before 'configure 'patch-paths
326 (substitute* "configure"
327 (("/bin/sh") (which "sh")))
328 (substitute* "setup.ml"
330 (string-append "LDFLAGS=-fPIC\"; \"SHELL=" (which "sh")))
331 (("-std=c89") "-std=gnu99")
333 ;; This is a mutable string, which is no longer supported. Use
334 ;; a byte buffer instead.
335 (("String.make \\(String.length s\\)")
336 "Bytes.make (String.length s)")
338 ;; These two belong together.
339 (("OASISString.replace_chars")
340 "Bytes.to_string (OASISString.replace_chars")
343 (substitute* "myocamlbuild.ml"
344 (("std=c89") "std=gnu99"))
345 ;; Since we build with a more recent OCaml, we have to use C99 or
346 ;; later. This causes problems with the old C code.
347 (substitute* "src/impala/matrix.c"
348 (("restrict") "restrict_"))
351 `(("ocamlbuild" ,ocamlbuild)))
352 (home-page "https://github.com/fhcrc/mcl")
353 (synopsis "OCaml wrappers around MCL")
355 "This package provides OCaml bindings for the MCL graph clustering
357 (license license:gpl3)))
359 (define-public randomjungle
361 (name "randomjungle")
367 "https://www.imbs.uni-luebeck.de/fileadmin/files/Software"
368 "/randomjungle/randomjungle-" version ".tar_.gz"))
369 (patches (search-patches "randomjungle-disable-static-build.patch"))
372 "12c8rf30cla71swx2mf4ww9mfd8jbdw5lnxd7dxhyw1ygrvg6y4w"))))
373 (build-system gnu-build-system)
376 (list "--disable-static"
377 (string-append "--with-boost="
378 (assoc-ref %build-inputs "boost")))
380 (modify-phases %standard-phases
382 'configure 'set-CXXFLAGS
384 (setenv "CXXFLAGS" "-fpermissive ")
392 `(("gfortran" ,gfortran)
393 ("gfortran:lib" ,gfortran "lib")))
394 ;; Non-portable assembly instructions are used so building fails on
395 ;; platforms other than x86_64 or i686.
396 (supported-systems '("x86_64-linux" "i686-linux"))
397 (home-page "https://www.imbs.uni-luebeck.de/forschung/software/details.html#c224")
398 (synopsis "Implementation of the Random Forests machine learning method")
400 "Random Jungle is an implementation of Random Forests. It is supposed to
401 analyse high dimensional data. In genetics, it can be used for analysing big
402 Genome Wide Association (GWA) data. Random Forests is a powerful machine
403 learning method. Most interesting features are variable selection, missing
404 value imputation, classifier creation, generalization error estimation and
405 sample proximities between pairs of cases.")
406 (license license:gpl3+)))
408 (define-public openfst
414 (uri (string-append "http://www.openfst.org/twiki/pub/FST/"
415 "FstDownload/openfst-" version ".tar.gz"))
418 "0fqgk8195kz21is09gwzwnrg7fr9526bi9mh4apyskapz27pbhr1"))))
419 (build-system gnu-build-system)
420 (home-page "http://www.openfst.org")
421 (synopsis "Library for weighted finite-state transducers")
422 (description "OpenFst is a library for constructing, combining,
423 optimizing, and searching weighted finite-state transducers (FSTs).")
424 (license license:asl2.0)))
426 (define-public shogun
434 "ftp://shogun-toolbox.org/shogun/releases/"
435 (version-major+minor version)
436 "/sources/shogun-" version ".tar.bz2"))
439 "1rn9skm3nw6hr7mr3lgp2gfqhi7ii0lyxck7qmqnf8avq349s5jp"))
440 (modules '((guix build utils)
444 ;; Remove non-free sources and files referencing them
445 (for-each delete-file
446 (find-files "src/shogun/classifier/svm/"
447 "SVMLight\\.(cpp|h)"))
448 (for-each delete-file
449 (find-files "examples/undocumented/libshogun/"
451 "(classifier_.*svmlight.*|"
452 "evaluation_cross_validation_locked_comparison).cpp")))
453 ;; Remove non-free functions.
454 (define (delete-ifdefs file)
455 (with-atomic-file-replacement file
457 (let loop ((line (read-line in 'concat))
459 (if (eof-object? line)
464 "#endif //USE_SVMLIGHT" line)))
466 "#ifdef USE_SVMLIGHT" line))))
467 (when (or (not skipping?)
468 (and skipping? (not skip-next?)))
470 (loop (read-line in 'concat) skip-next?)))))))
471 (for-each delete-ifdefs
473 (find-files "src/shogun/classifier/mkl"
474 "^MKLClassification\\.cpp")
475 (find-files "src/shogun/classifier/svm"
476 "^SVMLightOneClass\\.(cpp|h)")
477 (find-files "src/shogun/multiclass"
478 "^ScatterSVM\\.(cpp|h)")
479 (find-files "src/shogun/kernel/"
480 "^(Kernel|CombinedKernel|ProductKernel)\\.(cpp|h)")
481 (find-files "src/shogun/regression/svr"
482 "^(MKLRegression|SVRLight)\\.(cpp|h)")
483 (find-files "src/shogun/transfer/domain_adaptation"
484 "^DomainAdaptationSVM\\.(cpp|h)")))
486 (build-system cmake-build-system)
488 '(#:tests? #f ;no check target
490 (modify-phases %standard-phases
491 (add-after 'unpack 'delete-broken-symlinks
493 (for-each delete-file '("applications/arts/data"
494 "applications/asp/data"
495 "applications/easysvm/data"
496 "applications/msplicer/data"
497 "applications/ocr/data"
499 "examples/undocumented/data"))
501 (add-after 'unpack 'change-R-target-path
502 (lambda* (#:key outputs #:allow-other-keys)
503 (substitute* '("src/interfaces/r/CMakeLists.txt"
504 "examples/meta/r/CMakeLists.txt")
505 (("\\$\\{R_COMPONENT_LIB_PATH\\}")
506 (string-append (assoc-ref outputs "out")
509 (add-after 'unpack 'fix-octave-modules
510 (lambda* (#:key outputs #:allow-other-keys)
511 (substitute* "src/interfaces/octave/CMakeLists.txt"
512 (("^include_directories\\(\\$\\{OCTAVE_INCLUDE_DIRS\\}")
513 "include_directories(${OCTAVE_INCLUDE_DIRS} ${OCTAVE_INCLUDE_DIRS}/octave")
514 ;; change target directory
515 (("\\$\\{OCTAVE_OCT_LOCAL_API_FILE_DIR\\}")
516 (string-append (assoc-ref outputs "out")
517 "/share/octave/packages")))
518 (substitute* '("src/interfaces/octave/swig_typemaps.i"
519 "src/interfaces/octave/sg_print_functions.cpp")
520 ;; "octave/config.h" and "octave/oct-obj.h" deprecated in Octave.
521 (("octave/config\\.h") "octave/octave-config.h")
522 (("octave/oct-obj.h") "octave/ovl.h"))
524 (add-after 'unpack 'move-rxcpp
525 (lambda* (#:key inputs #:allow-other-keys)
526 (let ((rxcpp-dir "shogun/third-party/rxcpp"))
528 (install-file (assoc-ref inputs "rxcpp") rxcpp-dir)
530 (add-before 'build 'set-HOME
531 ;; $HOME needs to be set at some point during the build phase
532 (lambda _ (setenv "HOME" "/tmp") #t)))
534 (list "-DCMAKE_BUILD_WITH_INSTALL_RPATH=TRUE"
535 "-DUSE_SVMLIGHT=OFF" ;disable proprietary SVMLIGHT
536 "-DBUILD_META_EXAMPLES=OFF" ;requires unpackaged ctags
537 ;;"-DINTERFACE_JAVA=ON" ;requires unpackaged jblas
538 ;;"-DINTERFACE_RUBY=ON" ;requires unpackaged ruby-narray
539 ;;"-DINTERFACE_PERL=ON" ;"FindPerlLibs" does not exist
540 ;;"-DINTERFACE_LUA=ON" ;fails because lua doesn't build pkgconfig file
541 "-DINTERFACE_OCTAVE=ON"
542 "-DINTERFACE_PYTHON=ON"
543 "-DINTERFACE_R=ON")))
546 ("numpy" ,python-numpy)
547 ("r-minimal" ,r-minimal)
548 ("octave" ,octave-cli)
553 ("arpack" ,arpack-ng)
560 `(("pkg-config" ,pkg-config)
562 ;; Non-portable SSE instructions are used so building fails on platforms
563 ;; other than x86_64.
564 (supported-systems '("x86_64-linux"))
565 (home-page "http://shogun-toolbox.org/")
566 (synopsis "Machine learning toolbox")
568 "The Shogun Machine learning toolbox provides a wide range of unified and
569 efficient Machine Learning (ML) methods. The toolbox seamlessly allows to
570 combine multiple data representations, algorithm classes, and general purpose
571 tools. This enables both rapid prototyping of data pipelines and extensibility
572 in terms of new algorithms.")
573 (license license:gpl3+)))
583 (url "https://github.com/ReactiveX/RxCpp.git")
584 (commit (string-append "v" version))))
586 (base32 "1rdpa3jlc181jd08nk437aar085h28i45s6nzrv65apb3xyyz0ij"))
587 (file-name (git-file-name name version))))
588 (build-system cmake-build-system)
591 (modify-phases %standard-phases
592 (add-after 'unpack 'remove-werror
594 (substitute* (find-files ".")
599 (invoke "ctest"))))))
601 `(("catch" ,catch-framework)))
602 (home-page "http://reactivex.io/")
603 (synopsis "Reactive Extensions for C++")
605 "The Reactive Extensions for C++ (RxCpp) is a library of algorithms for
606 values-distributed-in-time. ReactiveX is a library for composing asynchronous
607 and event-based programs by using observable sequences.
609 It extends the observer pattern to support sequences of data and/or events and
610 adds operators that allow you to compose sequences together declaratively while
611 abstracting away concerns about things like low-level threading,
612 synchronization, thread-safety, concurrent data structures, and non-blocking
614 (license license:asl2.0)))
616 (define-public r-adaptivesparsity
618 (name "r-adaptivesparsity")
622 (uri (cran-uri "AdaptiveSparsity" version))
625 "0imr5m8mll9j6n4icsv6z9rl5kbnwsp9wvzrg7n90nnmcxq2cz91"))))
627 `((upstream-name . "AdaptiveSparsity")))
628 (build-system r-build-system)
631 (modify-phases %standard-phases
632 (add-after 'unpack 'link-against-armadillo
634 (substitute* "src/Makevars"
635 (("PKG_LIBS=" prefix)
636 (string-append prefix "-larmadillo"))))))))
639 ("r-matrix" ,r-matrix)
641 ("r-rcpparmadillo" ,r-rcpparmadillo)))
643 `(("armadillo" ,armadillo)))
644 (home-page "https://cran.r-project.org/web/packages/AdaptiveSparsity")
645 (synopsis "Adaptive sparsity models")
647 "This package implements the Figueiredo machine learning algorithm for
648 adaptive sparsity and the Wong algorithm for adaptively sparse gaussian
650 (license license:lgpl3+)))
652 (define-public gemmlowp-for-tensorflow
653 ;; The commit hash is taken from "tensorflow/workspace.bzl".
654 (let ((commit "38ebac7b059e84692f53e5938f97a9943c120d98")
658 (version (git-version "0" revision commit))
661 (uri (string-append "https://mirror.bazel.build/"
662 "github.com/google/gemmlowp/archive/"
664 (file-name (string-append "gemmlowp-" version ".zip"))
667 "0n56s2g8hrssm4w8qj1v58gfm56a04n9v992ixkmvk6zjiralzxq"))))
668 (build-system cmake-build-system)
671 (list ,@(match (%current-system)
672 ((or "x86_64-linux" "i686-linux")
673 '("-DCMAKE_CXX_FLAGS=-msse2"))
676 (modify-phases %standard-phases
677 ;; This directory contains the CMakeLists.txt.
678 (add-after 'unpack 'chdir
679 (lambda _ (chdir "contrib") #t))
680 ;; There is no install target
682 (lambda* (#:key outputs #:allow-other-keys)
683 (let* ((out (assoc-ref outputs "out"))
684 (lib (string-append out "/lib/"))
685 (inc (string-append out "/include/")))
686 (install-file "../build/libeight_bit_int_gemm.so" lib)
687 (for-each (lambda (dir)
688 (let ((target (string-append inc "/" dir)))
690 (for-each (lambda (h)
691 (install-file h target))
692 (find-files (string-append "../" dir)
694 '("meta" "profiling" "public" "fixedpoint"
695 "eight_bit_int_gemm" "internal"))
699 (home-page "https://github.com/google/gemmlowp")
700 (synopsis "Small self-contained low-precision GEMM library")
702 "This is a small self-contained low-precision @dfn{general matrix
703 multiplication} (GEMM) library. It is not a full linear algebra library.
704 Low-precision means that the input and output matrix entries are integers on
705 at most 8 bits. To avoid overflow, results are internally accumulated on more
706 than 8 bits, and at the end only some significant 8 bits are kept.")
707 (license license:asl2.0))))
716 "http://dlib.net/files/dlib-" version ".tar.bz2"))
719 "1mljz02kwkrbggyncxv5fpnyjdybw2qihaacb3js8yfkw12vwpc2"))
720 (modules '((guix build utils)))
723 ;; Delete ~13MB of bundled dependencies.
724 (delete-file-recursively "dlib/external")
725 (delete-file-recursively "docs/dlib/external")
727 (build-system cmake-build-system)
730 (modify-phases %standard-phases
731 (add-after 'unpack 'disable-asserts
733 ;; config.h recommends explicitly enabling or disabling asserts
734 ;; when building as a shared library. By default neither is set.
735 (substitute* "dlib/config.h"
736 (("^//#define DLIB_DISABLE_ASSERTS") "#define DLIB_DISABLE_ASSERTS"))
738 (add-after 'disable-asserts 'disable-failing-tests
740 ;; One test times out on MIPS, so we need to disable it.
741 ;; Others are flaky on some platforms.
742 (let* ((system ,(or (%current-target-system)
744 (disabled-tests (cond
745 ((string-prefix? "mips64" system)
746 '("object_detector" ; timeout
748 ((string-prefix? "armhf" system)
749 '("learning_to_track"))
750 ((string-prefix? "i686" system)
755 (substitute* "dlib/test/makefile"
756 (((string-append "SRC \\+= " test "\\.cpp")) "")))
761 ;; No test target, so we build and run the unit tests here.
762 (let ((test-dir (string-append "../dlib-" ,version "/dlib/test")))
763 (with-directory-excursion test-dir
764 (invoke "make" "-j" (number->string (parallel-job-count)))
765 (invoke "./dtest" "--runall"))
767 (add-after 'install 'delete-static-library
768 (lambda* (#:key outputs #:allow-other-keys)
769 (delete-file (string-append (assoc-ref outputs "out")
773 `(("pkg-config" ,pkg-config)
782 ("openblas" ,openblas)
785 "Toolkit for making machine learning and data analysis applications in C++")
787 "Dlib is a modern C++ toolkit containing machine learning algorithms and
788 tools. It is used in both industry and academia in a wide range of domains
789 including robotics, embedded devices, mobile phones, and large high performance
790 computing environments.")
791 (home-page "http://dlib.net")
792 (license license:boost1.0)))
794 (define-public python-scikit-learn
796 (name "python-scikit-learn")
802 (url "https://github.com/scikit-learn/scikit-learn.git")
804 (file-name (git-file-name name version))
807 "08aaby5zphfxy83mggg35bwyka7wk91l2qijh8kk0bl08dikq8dl"))))
808 (build-system python-build-system)
811 (modify-phases %standard-phases
812 (add-after 'build 'build-ext
813 (lambda _ (invoke "python" "setup.py" "build_ext" "--inplace") #t))
816 ;; Restrict OpenBLAS threads to prevent segfaults while testing!
817 (setenv "OPENBLAS_NUM_THREADS" "1")
819 ;; Some tests require write access to $HOME.
820 (setenv "HOME" "/tmp")
822 (invoke "pytest" "sklearn" "-m" "not network")))
823 (add-before 'reset-gzip-timestamps 'make-files-writable
824 (lambda* (#:key outputs #:allow-other-keys)
825 ;; Make sure .gz files are writable so that the
826 ;; 'reset-gzip-timestamps' phase can do its work.
827 (let ((out (assoc-ref outputs "out")))
828 (for-each make-file-writable
829 (find-files out "\\.gz$"))
832 `(("openblas" ,openblas)))
834 `(("python-pytest" ,python-pytest)
835 ("python-pandas" ,python-pandas) ;for tests
836 ("python-cython" ,python-cython)))
838 `(("python-numpy" ,python-numpy)
839 ("python-scipy" ,python-scipy)))
840 (home-page "http://scikit-learn.org/")
841 (synopsis "Machine Learning in Python")
843 "Scikit-learn provides simple and efficient tools for data mining and
845 (license license:bsd-3)))
847 (define-public python2-scikit-learn
848 (package-with-python2 python-scikit-learn))
850 (define-public python-autograd
851 (let* ((commit "442205dfefe407beffb33550846434baa90c4de7")
853 (version (git-version "0.0.0" revision commit)))
855 (name "python-autograd")
856 (home-page "https://github.com/HIPS/autograd")
864 "189sv2xb0mwnjawa9z7mrgdglc1miaq93pnck26r28fi1jdwg0z4"))
865 (file-name (git-file-name name version))))
867 (build-system python-build-system)
869 `(("python-nose" ,python-nose)
870 ("python-pytest" ,python-pytest)))
872 `(("python-future" ,python-future)
873 ("python-numpy" ,python-numpy)))
875 `(#:phases (modify-phases %standard-phases
878 (invoke "py.test" "-v"))))))
879 (synopsis "Efficiently computes derivatives of NumPy code")
880 (description "Autograd can automatically differentiate native Python and
881 NumPy code. It can handle a large subset of Python's features, including loops,
882 ifs, recursion and closures, and it can even take derivatives of derivatives
883 of derivatives. It supports reverse-mode differentiation
884 (a.k.a. backpropagation), which means it can efficiently take gradients of
885 scalar-valued functions with respect to array-valued arguments, as well as
886 forward-mode differentiation, and the two can be composed arbitrarily. The
887 main intended application of Autograd is gradient-based optimization.")
888 (license license:expat))))
890 (define-public python2-autograd
891 (package-with-python2 python-autograd))
893 (define-public lightgbm
900 "https://github.com/Microsoft/LightGBM/archive/v"
904 "132zf0yk0545mg72hyzxm102g3hpb6ixx9hnf8zd2k55gas6cjj1"))
905 (file-name (string-append name "-" version ".tar.gz"))))
907 `(("python-pytest" ,python-pytest)
908 ("python-nose" ,python-nose)))
910 `(("openmpi" ,openmpi)))
912 `(("python-numpy" ,python-numpy)
913 ("python-scipy" ,python-scipy)))
918 (modify-phases %standard-phases
920 (lambda* (#:key outputs #:allow-other-keys)
921 (with-directory-excursion ,(string-append "../LightGBM-" version)
922 (invoke "pytest" "tests/c_api_test/test_.py")))))))
923 (build-system cmake-build-system)
924 (home-page "https://github.com/Microsoft/LightGBM")
925 (synopsis "Gradient boosting framework based on decision tree algorithms")
926 (description "LightGBM is a gradient boosting framework that uses tree
927 based learning algorithms. It is designed to be distributed and efficient with
928 the following advantages:
931 @item Faster training speed and higher efficiency
932 @item Lower memory usage
933 @item Better accuracy
934 @item Parallel and GPU learning supported (not enabled in this package)
935 @item Capable of handling large-scale data
937 (license license:expat)))
939 (define-public vowpal-wabbit
940 ;; Language bindings not included.
942 (name "vowpal-wabbit")
947 "https://github.com/JohnLangford/vowpal_wabbit/archive/"
951 "0clp2kb7rk5sckhllxjr5a651awf4s8dgzg4659yh4hf5cqnf0gr"))
952 (file-name (string-append name "-" version ".tar.gz"))))
958 (list (string-append "--with-boost="
959 (assoc-ref %build-inputs "boost")))))
960 (build-system gnu-build-system)
961 (home-page "https://github.com/JohnLangford/vowpal_wabbit")
962 (synopsis "Fast machine learning library for online learning")
963 (description "Vowpal Wabbit is a machine learning system with techniques
964 such as online, hashing, allreduce, reductions, learning2search, active, and
965 interactive learning.")
966 (license license:bsd-3)))
968 (define-public python2-fastlmm
970 (name "python2-fastlmm")
975 (uri (pypi-uri "fastlmm" version ".zip"))
978 "1q8c34rpmwkfy3r4d5172pzdkpfryj561897z9r3x22gq7813x1m"))))
979 (build-system python-build-system)
981 `(#:tests? #f ; some test files are missing
982 #:python ,python-2)) ; only Python 2.7 is supported
984 `(("python2-numpy" ,python2-numpy)
985 ("python2-scipy" ,python2-scipy)
986 ("python2-matplotlib" ,python2-matplotlib)
987 ("python2-pandas" ,python2-pandas)
988 ("python2-scikit-learn" ,python2-scikit-learn)
989 ("python2-pysnptools" ,python2-pysnptools)))
992 ("python2-cython" ,python2-cython)
993 ("python2-mock" ,python2-mock)
994 ("python2-nose" ,python2-nose)))
995 (home-page "http://research.microsoft.com/en-us/um/redmond/projects/mscompbio/fastlmm/")
996 (synopsis "Perform genome-wide association studies on large data sets")
998 "FaST-LMM, which stands for Factored Spectrally Transformed Linear Mixed
999 Models, is a program for performing both single-SNP and SNP-set genome-wide
1000 association studies (GWAS) on extremely large data sets.")
1001 (license license:asl2.0)))
1003 ;; There have been no proper releases yet.
1004 (define-public kaldi
1005 (let ((commit "2f95609f0bb085bd3a1dc5eb0a39f3edea59e606")
1009 (version (git-version "0" revision commit))
1013 (url "https://github.com/kaldi-asr/kaldi.git")
1015 (file-name (git-file-name name version))
1018 "082qh3pfi7hvncylp4xsmkfahbd7gb0whdfa4rwrx7fxk9rdh3kz"))))
1019 (build-system gnu-build-system)
1021 `(#:test-target "test"
1023 (modify-phases %standard-phases
1024 (add-after 'unpack 'chdir
1025 (lambda _ (chdir "src") #t))
1027 (lambda* (#:key build system inputs outputs #:allow-other-keys)
1028 (when (not (or (string-prefix? "x86_64" system)
1029 (string-prefix? "i686" system)))
1030 (substitute* "makefiles/linux_openblas.mk"
1031 (("-msse -msse2") "")))
1032 (substitute* "makefiles/default_rules.mk"
1033 (("/bin/bash") (which "bash")))
1034 (substitute* "Makefile"
1035 (("ext_depend: check_portaudio")
1037 (substitute* '("online/Makefile"
1038 "onlinebin/Makefile"
1039 "gst-plugin/Makefile")
1040 (("../../tools/portaudio/install")
1041 (assoc-ref inputs "portaudio")))
1043 ;; This `configure' script doesn't support variables passed as
1044 ;; arguments, nor does it support "prefix".
1045 (let ((out (assoc-ref outputs "out"))
1046 (openblas (assoc-ref inputs "openblas"))
1047 (openfst (assoc-ref inputs "openfst")))
1048 (substitute* "configure"
1049 (("check_for_slow_expf;") "")
1050 ;; This affects the RPATH and also serves as the installation
1052 (("KALDILIBDIR=`pwd`/lib")
1053 (string-append "KALDILIBDIR=" out "/lib")))
1054 (mkdir-p out) ; must exist
1055 (setenv "CONFIG_SHELL" (which "bash"))
1056 (setenv "OPENFST_VER" ,(package-version openfst))
1057 (invoke "./configure"
1060 (string-append "--openblas-root=" openblas)
1061 (string-append "--fst-root=" openfst)))))
1062 (add-after 'build 'build-ext-and-gstreamer-plugin
1064 (invoke "make" "-C" "online" "depend")
1065 (invoke "make" "-C" "online")
1066 (invoke "make" "-C" "onlinebin" "depend")
1067 (invoke "make" "-C" "onlinebin")
1068 (invoke "make" "-C" "gst-plugin" "depend")
1069 (invoke "make" "-C" "gst-plugin")
1071 ;; TODO: also install the executables.
1073 (lambda* (#:key outputs #:allow-other-keys)
1074 (let* ((out (assoc-ref outputs "out"))
1075 (inc (string-append out "/include"))
1076 (lib (string-append out "/lib")))
1078 ;; The build phase installed symlinks to the actual
1079 ;; libraries. Install the actual targets.
1080 (for-each (lambda (file)
1081 (let ((target (readlink file)))
1083 (install-file target lib)))
1084 (find-files lib "\\.so"))
1086 (for-each (lambda (file)
1087 (let ((target-dir (string-append inc "/" (dirname file))))
1088 (install-file file target-dir)))
1089 (find-files "." "\\.h"))
1090 (install-file "gst-plugin/libgstonlinegmmdecodefaster.so"
1091 (string-append lib "/gstreamer-1.0"))
1094 `(("alsa-lib" ,alsa-lib)
1095 ("gfortran" ,gfortran "lib")
1097 ("gstreamer" ,gstreamer)
1099 ("openblas" ,openblas)
1100 ("openfst" ,openfst)
1101 ("portaudio" ,portaudio)
1102 ("python" ,python)))
1104 `(("glib" ,glib "bin") ; glib-genmarshal
1107 ("pkg-config" ,pkg-config)
1109 (home-page "https://kaldi-asr.org/")
1110 (synopsis "Speech recognition toolkit")
1111 (description "Kaldi is an extensible toolkit for speech recognition
1113 (license license:asl2.0))))
1115 (define-public gst-kaldi-nnet2-online
1116 (let ((commit "617e43e73c7cc45eb9119028c02bd4178f738c4a")
1119 (name "gst-kaldi-nnet2-online")
1120 (version (git-version "0" revision commit))
1124 (url "https://github.com/alumae/gst-kaldi-nnet2-online.git")
1126 (file-name (git-file-name name version))
1129 "0xh3w67b69818s6ib02ara4lw7wamjdmh4jznvkpzrs4skbs9jx9"))))
1130 (build-system gnu-build-system)
1132 `(#:tests? #f ; there are none
1134 (list (string-append "SHELL="
1135 (assoc-ref %build-inputs "bash") "/bin/bash")
1136 (string-append "KALDI_ROOT="
1137 (assoc-ref %build-inputs "kaldi-src"))
1138 (string-append "KALDILIBDIR="
1139 (assoc-ref %build-inputs "kaldi") "/lib")
1140 "KALDI_FLAVOR=dynamic")
1142 (modify-phases %standard-phases
1143 (add-after 'unpack 'chdir
1144 (lambda _ (chdir "src") #t))
1146 (lambda* (#:key inputs #:allow-other-keys)
1147 (let ((glib (assoc-ref inputs "glib")))
1148 (setenv "CXXFLAGS" "-fPIC")
1149 (setenv "CPLUS_INCLUDE_PATH"
1150 (string-append glib "/include/glib-2.0:"
1151 glib "/lib/glib-2.0/include:"
1152 (assoc-ref inputs "gstreamer")
1153 "/include/gstreamer-1.0")))
1154 (substitute* "Makefile"
1155 (("include \\$\\(KALDI_ROOT\\)/src/kaldi.mk") "")
1156 (("\\$\\(error Cannot find") "#"))
1158 (add-before 'build 'build-depend
1159 (lambda* (#:key make-flags #:allow-other-keys)
1160 (apply invoke "make" "depend" make-flags)))
1162 (lambda* (#:key outputs #:allow-other-keys)
1163 (let* ((out (assoc-ref outputs "out"))
1164 (lib (string-append out "/lib/gstreamer-1.0")))
1165 (install-file "libgstkaldinnet2onlinedecoder.so" lib)
1169 ("gstreamer" ,gstreamer)
1170 ("jansson" ,jansson)
1171 ("openfst" ,openfst)
1175 ("glib:bin" ,glib "bin") ; glib-genmarshal
1176 ("kaldi-src" ,(package-source kaldi))
1177 ("pkg-config" ,pkg-config)))
1178 (home-page "https://kaldi-asr.org/")
1179 (synopsis "Gstreamer plugin for decoding speech")
1180 (description "This package provides a GStreamer plugin that wraps
1181 Kaldi's @code{SingleUtteranceNnet2Decoder}. It requires iVector-adapted DNN
1182 acoustic models. The iVectors are adapted to the current audio stream
1184 (license license:asl2.0))))
1186 (define-public kaldi-gstreamer-server
1187 (let ((commit "1735ba49c5dc0ebfc184e45105fc600cd9f1f508")
1190 (name "kaldi-gstreamer-server")
1191 (version (git-version "0" revision commit))
1195 (url "https://github.com/alumae/kaldi-gstreamer-server.git")
1197 (file-name (git-file-name name version))
1200 "0j701m7lbwmzqxsfanj882v7881hrbmpqybbczbxqpcbg8q34w0k"))))
1201 (build-system gnu-build-system)
1203 `(#:tests? #f ; there are no tests that can be run automatically
1204 #:modules ((guix build utils)
1205 (guix build gnu-build-system)
1208 (modify-phases %standard-phases
1211 (lambda* (#:key outputs #:allow-other-keys)
1212 ;; Disable hash randomization to ensure the generated .pycs
1213 ;; are reproducible.
1214 (setenv "PYTHONHASHSEED" "0")
1215 (with-directory-excursion "kaldigstserver"
1216 (for-each (lambda (file)
1220 "-f" ; force rebuild
1222 (find-files "." "\\.py$")))
1225 (lambda* (#:key inputs outputs #:allow-other-keys)
1226 (let* ((out (assoc-ref outputs "out"))
1227 (bin (string-append out "/bin"))
1228 (share (string-append out "/share/kaldi-gstreamer-server/")))
1229 ;; Install Python files
1230 (with-directory-excursion "kaldigstserver"
1231 (for-each (cut install-file <> share)
1232 (find-files "." ".*")))
1234 ;; Install sample configuration files
1235 (for-each (cut install-file <> share)
1236 (find-files "." "\\.yaml"))
1238 ;; Install executables
1240 (let* ((server (string-append bin "/kaldi-gst-server"))
1241 (client (string-append bin "/kaldi-gst-client"))
1242 (worker (string-append bin "/kaldi-gst-worker"))
1243 (PYTHONPATH (getenv "PYTHONPATH"))
1244 (GST_PLUGIN_PATH (string-append
1245 (assoc-ref inputs "gst-kaldi-nnet2-online")
1246 "/lib/gstreamer-1.0:${GST_PLUGIN_PATH}"))
1247 (wrap (lambda (wrapper what)
1248 (with-output-to-file wrapper
1252 export PYTHONPATH=~a
1253 export GST_PLUGIN_PATH=~a
1254 exec ~a ~a/~a \"$@\"~%"
1255 (which "bash") PYTHONPATH GST_PLUGIN_PATH
1256 (which "python") share what)))
1257 (chmod wrapper #o555))))
1259 (list server client worker)
1260 (list "master_server.py"
1265 `(("gst-kaldi-nnet2-online" ,gst-kaldi-nnet2-online)
1266 ("python2" ,python-2)
1267 ("python2-futures" ,python2-futures)
1268 ("python2-pygobject" ,python2-pygobject)
1269 ("python2-pyyaml" ,python2-pyyaml)
1270 ("python2-tornado" ,python2-tornado)
1271 ("python2-ws4py" ,python2-ws4py-for-kaldi-gstreamer-server)))
1272 (home-page "https://github.com/alumae/kaldi-gstreamer-server")
1273 (synopsis "Real-time full-duplex speech recognition server")
1274 (description "This is a real-time full-duplex speech recognition server,
1275 based on the Kaldi toolkit and the GStreamer framework and implemented in
1277 (license license:bsd-2))))
1286 (url "https://github.com/grpc/grpc.git")
1287 (commit (string-append "v" version))))
1288 (file-name (git-file-name name version))
1291 "1jimqz3115f9pli5w6ik9wi7mjc7ix6y7yrq4a1ab9fc3dalj7p2"))))
1292 (build-system cmake-build-system)
1294 `(#:tests? #f ; no test target
1296 (list "-DgRPC_ZLIB_PROVIDER=package"
1297 "-DgRPC_CARES_PROVIDER=package"
1298 "-DgRPC_SSL_PROVIDER=package"
1299 "-DgRPC_PROTOBUF_PROVIDER=package")))
1301 `(("c-ares" ,c-ares/cmake)
1302 ("openssl" ,openssl)
1305 `(("protobuf" ,protobuf-next)
1306 ("python" ,python-wrapper)))
1307 (home-page "https://grpc.io")
1308 (synopsis "High performance universal RPC framework")
1309 (description "gRPC is a modern open source high performance @dfn{Remote
1310 Procedure Call} (RPC) framework that can run in any environment. It can
1311 efficiently connect services in and across data centers with pluggable support
1312 for load balancing, tracing, health checking and authentication. It is also
1313 applicable in last mile of distributed computing to connect devices, mobile
1314 applications and browsers to backend services.")
1315 (license license:asl2.0)))
1317 ;; Note that Tensorflow includes a "third_party" directory, which seems to not
1318 ;; only contain modified subsets of upstream library source code, but also
1319 ;; adapter headers provided by Google (such as the fft.h header, which is not
1320 ;; part of the upstream project code). The Tensorflow code includes headers
1321 ;; from the "third_party" directory. It does not look like we can replace
1322 ;; these headers with unmodified upstream files, so we keep them.
1323 (define-public tensorflow
1331 (url "https://github.com/tensorflow/tensorflow.git")
1332 (commit (string-append "v" version))))
1333 (file-name (string-append "tensorflow-" version "-checkout"))
1336 "0a9kwha395g3wgxfwln5j8vn9nkspmd75xldrlqdq540w996g8xa"))))
1337 (build-system cmake-build-system)
1339 `(#:tests? #f ; no "check" target
1340 #:build-type "Release"
1342 (let ((protobuf (assoc-ref %build-inputs "protobuf"))
1343 (protobuf:native (assoc-ref %build-inputs "protobuf:native"))
1344 (jsoncpp (assoc-ref %build-inputs "jsoncpp"))
1345 (snappy (assoc-ref %build-inputs "snappy"))
1346 (sqlite (assoc-ref %build-inputs "sqlite")))
1348 ;; Use protobuf from Guix
1349 (string-append "-Dprotobuf_STATIC_LIBRARIES="
1350 protobuf "/lib/libprotobuf.so")
1351 (string-append "-DPROTOBUF_PROTOC_EXECUTABLE="
1352 protobuf:native "/bin/protoc")
1354 ;; Use snappy from Guix
1355 (string-append "-Dsnappy_STATIC_LIBRARIES="
1356 snappy "/lib/libsnappy.so")
1357 ;; Yes, this is not actually the include directory but a prefix...
1358 (string-append "-Dsnappy_INCLUDE_DIR=" snappy)
1360 ;; Use jsoncpp from Guix
1361 (string-append "-Djsoncpp_STATIC_LIBRARIES="
1362 jsoncpp "/lib/libjsoncpp.so")
1363 ;; Yes, this is not actually the include directory but a prefix...
1364 (string-append "-Djsoncpp_INCLUDE_DIR=" jsoncpp)
1366 ;; Use sqlite from Guix
1367 (string-append "-Dsqlite_STATIC_LIBRARIES="
1368 sqlite "/lib/libsqlite.a")
1370 ;; Use system libraries wherever possible. Currently, this
1371 ;; only affects zlib.
1372 "-Dsystemlib_ALL=ON"
1373 "-Dtensorflow_ENABLE_POSITION_INDEPENDENT_CODE=ON"
1374 "-Dtensorflow_BUILD_SHARED_LIB=ON"
1375 "-Dtensorflow_OPTIMIZE_FOR_NATIVE_ARCH=OFF"
1376 "-Dtensorflow_ENABLE_SSL_SUPPORT=OFF"
1377 "-Dtensorflow_BUILD_CONTRIB_KERNELS=OFF"))
1380 #:modules ((ice-9 ftw)
1382 (guix build cmake-build-system))
1384 (modify-phases %standard-phases
1385 (add-after 'unpack 'set-source-file-times-to-1980
1386 ;; At the end of the tf_python_build_pip_package target, a ZIP
1387 ;; archive should be generated via bdist_wheel, but it fails with
1388 ;; "ZIP does not support timestamps before 1980". Luckily,
1389 ;; SOURCE_DATE_EPOCH is respected, which we set to some time in
1391 (lambda _ (setenv "SOURCE_DATE_EPOCH" "315532800") #t))
1392 ;; See https://github.com/tensorflow/tensorflow/issues/20517#issuecomment-406373913
1393 (add-after 'unpack 'python3.7-compatibility
1395 (substitute* '("tensorflow/python/eager/pywrap_tfe_src.cc"
1396 "tensorflow/python/lib/core/ndarray_tensor.cc"
1397 "tensorflow/python/lib/core/py_func.cc")
1398 (("PyUnicode_AsUTF8") "(char *)PyUnicode_AsUTF8"))
1399 (substitute* "tensorflow/c/eager/c_api.h"
1400 (("unsigned char async")
1401 "unsigned char is_async"))
1403 ;; Remove dependency on tensorboard, a complicated but probably
1404 ;; optional package.
1405 (substitute* "tensorflow/tools/pip_package/setup.py"
1406 ((".*'tensorboard >.*") ""))
1408 (add-after 'python3.7-compatibility 'chdir
1409 (lambda _ (chdir "tensorflow/contrib/cmake") #t))
1410 (add-after 'chdir 'disable-downloads
1411 (lambda* (#:key inputs #:allow-other-keys)
1412 (substitute* (find-files "external" "\\.cmake$")
1413 (("GIT_REPOSITORY.*") "")
1416 "DOWNLOAD_COMMAND \"\"\nPREFIX "))
1418 ;; Use packages from Guix
1419 (let ((grpc (assoc-ref inputs "grpc")))
1420 (substitute* "CMakeLists.txt"
1422 (("include\\(sqlite\\)") "")
1423 (("\\$\\{sqlite_STATIC_LIBRARIES\\}")
1424 (string-append (assoc-ref inputs "sqlite")
1425 "/lib/libsqlite3.so"))
1426 (("sqlite_copy_headers_to_destination") "")
1429 (("include\\(png\\)") "")
1430 (("\\$\\{png_STATIC_LIBRARIES\\}")
1431 (string-append (assoc-ref inputs "libpng")
1432 "/lib/libpng16.so"))
1433 (("png_copy_headers_to_destination") "")
1436 (("include\\(jpeg\\)") "")
1437 (("\\$\\{jpeg_STATIC_LIBRARIES\\}")
1438 (string-append (assoc-ref inputs "libjpeg")
1440 (("jpeg_copy_headers_to_destination") "")
1443 (("include\\(gif\\)") "")
1444 (("\\$\\{gif_STATIC_LIBRARIES\\}")
1445 (string-append (assoc-ref inputs "giflib")
1447 (("gif_copy_headers_to_destination") "")
1450 (("include\\(lmdb\\)") "")
1451 (("\\$\\{lmdb_STATIC_LIBRARIES\\}")
1452 (string-append (assoc-ref inputs "lmdb")
1454 (("lmdb_copy_headers_to_destination") "")
1457 (("include\\(protobuf\\)") "")
1458 (("protobuf_copy_headers_to_destination") "")
1459 (("^ +protobuf") "")
1462 (("include\\(grpc\\)")
1463 "find_package(grpc REQUIRED NAMES gRPC)")
1464 (("list\\(APPEND tensorflow_EXTERNAL_DEPENDENCIES grpc\\)") "")
1467 (("include\\(eigen\\)")
1468 (string-append "find_package(eigen REQUIRED NAMES Eigen3)
1469 set(eigen_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/external/eigen_archive "
1470 (assoc-ref inputs "eigen") "/include/eigen3)"))
1474 (("include\\(snappy\\)")
1475 "add_definitions(-DTF_USE_SNAPPY)")
1476 (("list\\(APPEND tensorflow_EXTERNAL_DEPENDENCIES snappy\\)") "")
1479 (("include\\(jsoncpp\\)") "")
1480 (("^ +jsoncpp") ""))
1482 (substitute* "tf_core_framework.cmake"
1484 (("\\$\\{GRPC_BUILD\\}/grpc_cpp_plugin")
1485 (which "grpc_cpp_plugin"))
1486 ;; Link with gRPC libraries
1487 (("add_library\\(tf_protos_cc.*" m)
1489 (format #f "\ntarget_link_libraries(tf_protos_cc PRIVATE \
1490 ~a/lib/libgrpc++_unsecure.a \
1491 ~a/lib/libgrpc_unsecure.a \
1492 ~a/lib/libaddress_sorting.a \
1497 (assoc-ref inputs "c-ares"))))))
1498 (substitute* "tf_tools.cmake"
1499 (("add_dependencies\\(\\$\\{proto_text.*") ""))
1500 ;; Remove dependency on bundled grpc
1501 (substitute* "tf_core_distributed_runtime.cmake"
1502 (("tf_core_cpu grpc") "tf_core_cpu"))
1504 ;; This directory is a dependency of many targets.
1505 (mkdir-p "protobuf")
1507 (add-after 'configure 'unpack-third-party-sources
1508 (lambda* (#:key inputs #:allow-other-keys)
1509 ;; This is needed to configure bundled packages properly.
1510 (setenv "CONFIG_SHELL" (which "bash"))
1513 (let* ((what (assoc-ref inputs (string-append name "-src")))
1514 (name* (string-map (lambda (c)
1517 (where (string-append "../build/" name* "/src/" name*)))
1519 ((string-suffix? ".zip" what)
1521 (with-directory-excursion where
1522 (invoke "unzip" what)))
1523 ((string-suffix? ".tar.gz" what)
1525 (invoke "tar" "xf" what
1526 "-C" where "--strip-components=1"))
1528 (let ((parent (dirname where)))
1530 (with-directory-excursion parent
1531 (when (file-exists? name*)
1532 (delete-file-recursively name*))
1533 (copy-recursively what name*)
1534 (map make-file-writable
1535 (find-files name* ".*"))))))))
1545 (rename-file "../build/cub/src/cub/cub-1.8.0/"
1546 "../build/cub/src/cub/cub/")
1548 (add-after 'unpack 'fix-python-build
1549 (lambda* (#:key inputs outputs #:allow-other-keys)
1550 (mkdir-p "protobuf-src")
1551 (invoke "tar" "xf" (assoc-ref inputs "protobuf:src")
1552 "-C" "protobuf-src" "--strip-components=1")
1553 (mkdir-p "eigen-src")
1554 (invoke "tar" "xf" (assoc-ref inputs "eigen:src")
1555 "-C" "eigen-src" "--strip-components=1")
1557 (substitute* "tensorflow/contrib/cmake/tf_python.cmake"
1558 ;; Ensure that all Python dependencies can be found at build time.
1559 (("PYTHONPATH=\\$\\{CMAKE_CURRENT_BINARY_DIR\\}/tf_python" m)
1560 (string-append m ":" (getenv "PYTHONPATH")))
1561 ;; Take protobuf source files from our source package.
1562 (("\\$\\{CMAKE_CURRENT_BINARY_DIR\\}/protobuf/src/protobuf/src/google")
1563 (string-append (getcwd) "/protobuf-src/src/google")))
1565 (substitute* '("tensorflow/contrib/cmake/tf_shared_lib.cmake"
1566 "tensorflow/contrib/cmake/tf_python.cmake")
1567 ;; Take Eigen source files from our source package.
1568 (("\\$\\{CMAKE_CURRENT_BINARY_DIR\\}/eigen/src/eigen/")
1569 (string-append (getcwd) "/eigen-src/"))
1570 ;; Take Eigen headers from our own package.
1571 (("\\$\\{CMAKE_CURRENT_BINARY_DIR\\}/external/eigen_archive")
1572 (string-append (assoc-ref inputs "eigen") "/include/eigen3")))
1574 ;; Correct the RUNPATH of ops libraries generated for Python.
1575 ;; TODO: this doesn't work :(
1576 ;; /gnu/store/...-tensorflow-1.9.0/lib/python3.7/site-packages/tensorflow/contrib/seq2seq/python/ops/lib_beam_search_ops.so:
1577 ;; warning: RUNPATH contains bogus entries: ("/tmp/guix-build-tensorflow-1.9.0.drv-0/source/tensorflow/contrib/build")
1578 ;; /gnu/store/...-tensorflow-1.9.0/lib/python3.7/site-packages/tensorflow/contrib/seq2seq/python/ops/lib_beam_search_ops.so:
1579 ;; error: depends on 'libpywrap_tensorflow_internal.so', which
1580 ;; cannot be found in RUNPATH ...
1581 (substitute* "tensorflow/contrib/cmake/tf_cc_ops.cmake"
1582 (("set_target_properties.*")
1583 (string-append "set_target_properties(${_AT_TARGET} PROPERTIES \
1584 COMPILE_FLAGS ${target_compile_flags} \
1585 INSTALL_RPATH_USE_LINK_PATH TRUE \
1586 INSTALL_RPATH " (assoc-ref outputs "out") "/lib)\n")))
1588 (add-after 'build 'build-pip-package
1589 (lambda* (#:key outputs #:allow-other-keys)
1591 (string-append "-Wl,-rpath="
1592 (assoc-ref outputs "out") "/lib"))
1593 (invoke "make" "tf_python_build_pip_package")
1595 (add-after 'build-pip-package 'install-python
1596 (lambda* (#:key outputs #:allow-other-keys)
1597 (let ((out (assoc-ref outputs "out"))
1598 (wheel (car (find-files "../build/tf_python/dist/" "\\.whl$"))))
1599 (invoke "python" "-m" "pip" "install" wheel
1600 (string-append "--prefix=" out))
1602 ;; XXX: broken RUNPATH, see fix-python-build phase.
1605 out "/lib/python3.7/site-packages/tensorflow/contrib/"
1606 "seq2seq/python/ops/lib_beam_search_ops.so"))
1609 `(("pkg-config" ,pkg-config)
1610 ("protobuf:native" ,protobuf-next) ; protoc
1611 ("protobuf:src" ,(package-source protobuf-next))
1612 ("eigen:src" ,(package-source eigen-for-tensorflow))
1613 ;; install_pip_packages.sh wants setuptools 39.1.0 specifically.
1614 ("python-setuptools" ,python-setuptools-for-tensorflow)
1616 ;; The commit hashes and URLs for third-party source code are taken
1617 ;; from "tensorflow/workspace.bzl".
1619 ,(let ((commit "ee7aa02")
1624 (url "https://boringssl.googlesource.com/boringssl")
1626 (file-name (string-append "boringssl-0-" revision
1627 (string-take commit 7)
1631 "1jf693q0nw0adsic6cgmbdx6g7wr4rj4vxa8j1hpn792fqhd8wgw")))))
1633 ,(let ((version "1.8.0"))
1636 (uri (string-append "https://mirror.bazel.build/github.com/NVlabs/"
1637 "cub/archive/" version ".zip"))
1638 (file-name (string-append "cub-" version ".zip"))
1641 "1hsqikqridb90dkxkjr2918dcry6pfh46ccnwrzawl56aamhdykb")))))
1642 ("double-conversion-src"
1643 ,(let ((commit "5664746")
1648 (url "https://github.com/google/double-conversion.git")
1651 (git-file-name "double-conversion"
1652 (string-append "0-" revision "."
1653 (string-take commit 7))))
1656 "1h5lppqqxcvdg5jq42i5msgwx20ryij3apvmndflngrgdpc04gn1")))))
1658 ,(let ((commit "816a4ae622e964763ca0862d9dbd19324a1eaf45"))
1662 "https://mirror.bazel.build/github.com/google/farmhash/archive/"
1664 (file-name (string-append "farmhash-0-" (string-take commit 7)
1668 "185b2xdxl4d4cnsnv6abg8s22gxvx8673jq2yaq85bz4cdy58q35")))))
1669 ;; The license notice on the home page at
1670 ;; http://www.kurims.kyoto-u.ac.jp/~ooura/fft.html says:
1671 ;; Copyright Takuya OOURA, 1996-2001
1673 ;; You may use, copy, modify and distribute this code for any purpose
1674 ;; (include commercial use) and without fee. Please refer to this
1675 ;; package when you modify this code.
1677 ;; We take the identical tarball from the Bazel mirror, because the URL
1678 ;; at the home page is not versioned and might change.
1682 (uri "https://mirror.bazel.build/www.kurims.kyoto-u.ac.jp/~ooura/fft.tgz")
1683 (file-name "fft2d.tar.gz")
1686 "15jjkfvhqvl2c0753d2di8hz0pyzn598g74wqy79awdrf1y67fsj"))))
1688 ,(let ((commit "be5edafc2e1a455768e260ccd68ae7317b6690ee")
1693 (url "https://github.com/google/highwayhash.git")
1695 (file-name (string-append "highwayhash-0-" revision
1696 (string-take commit 7)
1700 "154jwf98cyy54hldr94pgjn85zynly3abpnc1avmb8a18lzwjyb6")))))
1702 ,(let ((version "0559ce013feac8db639ee1bf776aca0325d28777")
1706 (uri (string-append "https://mirror.bazel.build/"
1707 "github.com/google/nsync/archive/"
1709 (file-name (string-append "nsync-0." revision
1710 "-" (string-take version 7)
1714 "0qdkyqym34x739mmzv97ah5r7ph462v5xkxqxvidmcfqbi64b132")))))
1716 ,(let ((commit "e7efc48")
1721 (url "https://github.com/google/re2")
1723 (file-name (string-append "re2-0-" revision
1724 (string-take commit 7)
1728 "161g9841rjfsy5pn52fcis0s9hdr7rxvb06pad38j5rppfihvign")))))
1729 ("googletest" ,googletest)
1733 `(("python-absl-py" ,python-absl-py)
1734 ("python-astor" ,python-astor)
1735 ("python-gast" ,python-gast)
1736 ("python-grpcio" ,python-grpcio)
1737 ("python-numpy" ,python-numpy)
1738 ("python-protobuf" ,python-protobuf-next)
1739 ("python-six" ,python-six)
1740 ("python-termcolo" ,python-termcolor)
1741 ("python-wheel" ,python-wheel)))
1743 `(("c-ares" ,c-ares)
1744 ("eigen" ,eigen-for-tensorflow)
1745 ("gemmlowp" ,gemmlowp-for-tensorflow)
1747 ("libjpeg" ,libjpeg)
1751 ("jsoncpp" ,jsoncpp-for-tensorflow)
1754 ("protobuf" ,protobuf-next)
1755 ("python" ,python-wrapper)
1757 (home-page "https://tensorflow.org")
1758 (synopsis "Machine learning framework")
1760 "TensorFlow is a flexible platform for building and training machine
1761 learning models. It provides a library for high performance numerical
1762 computation and includes high level Python APIs, including both a sequential
1763 API for beginners that allows users to build models quickly by plugging
1764 together building blocks and a subclassing API with an imperative style for
1765 advanced research.")
1766 (license license:asl2.0)))
1768 (define-public python-iml
1775 (uri (pypi-uri "iml" version))
1778 "1k8szlpm19rcwcxdny9qdm3gmaqq8akb4xlvrzyz8c2d679aak6l"))))
1779 (build-system python-build-system)
1781 `(("ipython" ,python-ipython)
1782 ("nose" ,python-nose)
1783 ("numpy" ,python-numpy)
1784 ("pandas" ,python-pandas)
1785 ("scipy" ,python-scipy)))
1786 (home-page "http://github.com/interpretable-ml/iml")
1787 (synopsis "Interpretable Machine Learning (iML) package")
1788 (description "Interpretable ML (iML) is a set of data type objects,
1789 visualizations, and interfaces that can be used by any method designed to
1790 explain the predictions of machine learning models (or really the output of
1791 any function). It currently contains the interface and IO code from the Shap
1792 project, and it will potentially also do the same for the Lime project.")
1793 (license license:expat)))
1795 (define-public python-keras-applications
1797 (name "python-keras-applications")
1802 (uri (pypi-uri "Keras_Applications" version))
1805 "1rcz31ca4axa6kzhjx4lwqxbg4wvlljkj8qj9a7p9sfd5fhzjyam"))))
1806 (build-system python-build-system)
1807 ;; The tests require Keras, but this package is needed to build Keras.
1808 (arguments '(#:tests? #f))
1810 `(("python-h5py" ,python-h5py)
1811 ("python-numpy" ,python-numpy)))
1813 `(("python-pytest" ,python-pytest)
1814 ("python-pytest-cov" ,python-pytest-cov)
1815 ("python-pytest-pep8" ,python-pytest-pep8)
1816 ("python-pytest-xdist" ,python-pytest-xdist)))
1817 (home-page "https://github.com/keras-team/keras-applications")
1818 (synopsis "Reference implementations of popular deep learning models")
1820 "This package provides reference implementations of popular deep learning
1821 models for use with the Keras deep learning framework.")
1822 (license license:expat)))
1824 (define-public python-keras-preprocessing
1826 (name "python-keras-preprocessing")
1831 (uri (pypi-uri "Keras_Preprocessing" version))
1834 "1r98nm4k1svsqjyaqkfk23i31bl1kcfcyp7094yyj3c43phfp3as"))))
1835 (build-system python-build-system)
1837 `(("python-numpy" ,python-numpy)
1838 ("python-six" ,python-six)))
1840 `(("python-pandas" ,python-pandas)
1841 ("python-pillow" ,python-pillow)
1842 ("python-pytest" ,python-pytest)
1843 ("python-pytest-cov" ,python-pytest-cov)
1844 ("python-pytest-xdist" ,python-pytest-xdist)
1845 ("tensorflow" ,tensorflow)))
1846 (home-page "https://github.com/keras-team/keras-preprocessing/")
1847 (synopsis "Data preprocessing and augmentation for deep learning models")
1849 "Keras Preprocessing is the data preprocessing and data augmentation
1850 module of the Keras deep learning library. It provides utilities for working
1851 with image data, text data, and sequence data.")
1852 (license license:expat)))
1854 (define-public python-keras
1856 (name "python-keras")
1861 (uri (pypi-uri "Keras" version))
1862 (patches (search-patches "python-keras-integration-test.patch"))
1865 "1j8bsqzh49vjdxy6l1k4iwax5vpjzniynyd041xjavdzvfii1dlh"))))
1866 (build-system python-build-system)
1869 (modify-phases %standard-phases
1870 (add-after 'unpack 'remove-tests-for-unavailable-features
1872 (delete-file "keras/backend/theano_backend.py")
1873 (delete-file "keras/backend/cntk_backend.py")
1874 (delete-file "tests/keras/backend/backend_test.py")
1876 ;; FIXME: This doesn't work because Tensorflow is missing the
1877 ;; coder ops library.
1878 (delete-file "tests/keras/test_callbacks.py")
1882 ;; These tests attempt to download data files from the internet.
1883 (delete-file "tests/integration_tests/test_datasets.py")
1884 (delete-file "tests/integration_tests/imagenet_utils_test.py")
1886 (setenv "PYTHONPATH"
1887 (string-append (getcwd) "/build/lib:"
1888 (getenv "PYTHONPATH")))
1889 (invoke "py.test" "-v"
1890 "-p" "no:cacheprovider"
1891 "--ignore" "keras/utils"))))))
1893 `(("python-h5py" ,python-h5py)
1894 ("python-keras-applications" ,python-keras-applications)
1895 ("python-keras-preprocessing" ,python-keras-preprocessing)
1896 ("python-numpy" ,python-numpy)
1897 ("python-pydot" ,python-pydot)
1898 ("python-pyyaml" ,python-pyyaml)
1899 ("python-scipy" ,python-scipy)
1900 ("python-six" ,python-six)
1901 ("tensorflow" ,tensorflow)
1902 ("graphviz" ,graphviz)))
1904 `(("python-pandas" ,python-pandas)
1905 ("python-pytest" ,python-pytest)
1906 ("python-pytest-cov" ,python-pytest-cov)
1907 ("python-pytest-pep8" ,python-pytest-pep8)
1908 ("python-pytest-timeout" ,python-pytest-timeout)
1909 ("python-pytest-xdist" ,python-pytest-xdist)
1910 ("python-sphinx" ,python-sphinx)
1911 ("python-requests" ,python-requests)))
1912 (home-page "https://github.com/keras-team/keras")
1913 (synopsis "High-level deep learning framework")
1914 (description "Keras is a high-level neural networks API, written in Python
1915 and capable of running on top of TensorFlow. It was developed with a focus on
1916 enabling fast experimentation. Use Keras if you need a deep learning library
1920 @item Allows for easy and fast prototyping (through user friendliness,
1921 modularity, and extensibility).
1922 @item Supports both convolutional networks and recurrent networks, as well as
1923 combinations of the two.
1924 @item Runs seamlessly on CPU and GPU.
1926 (license license:expat)))
1928 (define-public sbcl-cl-libsvm-format
1929 (let ((commit "3300f84fd8d9f5beafc114f543f9d83417c742fb")
1932 (name "sbcl-cl-libsvm-format")
1933 (version (git-version "0.1.0" revision commit))
1938 (url "https://github.com/masatoi/cl-libsvm-format.git")
1940 (file-name (git-file-name name version))
1943 "0284aj84xszhkhlivaigf9qj855fxad3mzmv3zfr0qzb5k0nzwrg"))))
1944 (build-system asdf-build-system/sbcl)
1946 `(("prove" ,sbcl-prove)
1947 ("prove-asdf" ,sbcl-prove-asdf)))
1949 `(("alexandria" ,sbcl-alexandria)))
1950 (synopsis "LibSVM data format reader for Common Lisp")
1952 "This Common Lisp library provides a fast reader for data in LibSVM
1954 (home-page "https://github.com/masatoi/cl-libsvm-format")
1955 (license license:expat))))
1957 (define-public cl-libsvm-format
1958 (sbcl-package->cl-source-package sbcl-cl-libsvm-format))
1960 (define-public ecl-cl-libsvm-format
1961 (sbcl-package->ecl-package sbcl-cl-libsvm-format))
1963 (define-public sbcl-cl-online-learning
1964 (let ((commit "fc7a34f4f161cd1c7dd747d2ed8f698947781423")
1967 (name "sbcl-cl-online-learning")
1968 (version (git-version "0.5" revision commit))
1973 (url "https://github.com/masatoi/cl-online-learning.git")
1975 (file-name (git-file-name name version))
1978 "14x95rlg80ay5hv645ki57pqvy12v28hz4k1w0f6bsfi2rmpxchq"))))
1979 (build-system asdf-build-system/sbcl)
1981 `(("prove" ,sbcl-prove)
1982 ("prove-asdf" ,sbcl-prove-asdf)))
1984 `(("cl-libsvm-format" ,sbcl-cl-libsvm-format)
1985 ("cl-store" ,sbcl-cl-store)))
1987 `(;; FIXME: Tests pass but then the check phase crashes
1989 (synopsis "Online Machine Learning for Common Lisp")
1991 "This library contains a collection of machine learning algorithms for
1992 online linear classification written in Common Lisp.")
1993 (home-page "https://github.com/masatoi/cl-online-learning")
1994 (license license:expat))))
1996 (define-public cl-online-learning
1997 (sbcl-package->cl-source-package sbcl-cl-online-learning))
1999 (define-public ecl-cl-online-learning
2000 (sbcl-package->ecl-package sbcl-cl-online-learning))
2002 (define-public sbcl-cl-random-forest
2003 (let ((commit "85fbdd4596d40e824f70f1b7cf239cf544e49d51")
2006 (name "sbcl-cl-random-forest")
2007 (version (git-version "0.1" revision commit))
2012 (url "https://github.com/masatoi/cl-random-forest.git")
2014 (file-name (git-file-name name version))
2017 "097xv60i1ndz68sg9p4pc7c5gvyp9i1xgw966b4wwfq3x6hbz421"))))
2018 (build-system asdf-build-system/sbcl)
2020 `(("prove" ,sbcl-prove)
2021 ("prove-asdf" ,sbcl-prove-asdf)
2022 ("trivial-garbage" ,sbcl-trivial-garbage)))
2024 `(("alexandria" ,sbcl-alexandria)
2025 ("cl-libsvm-format" ,sbcl-cl-libsvm-format)
2026 ("cl-online-learning" ,sbcl-cl-online-learning)
2027 ("lparallel" ,sbcl-lparallel)))
2029 `(;; The tests download data from the Internet
2032 (modify-phases %standard-phases
2033 (add-after 'unpack 'add-sb-cltl2-dependency
2035 ;; sb-cltl2 is required by lparallel when using sbcl, but it is
2036 ;; not loaded automatically.
2037 (substitute* "cl-random-forest.asd"
2038 (("\\(in-package :cl-user\\)")
2039 "(in-package :cl-user) #+sbcl (require :sb-cltl2)"))
2041 (synopsis "Random Forest and Global Refinement for Common Lisp")
2043 "CL-random-forest is an implementation of Random Forest for multiclass
2044 classification and univariate regression written in Common Lisp. It also
2045 includes an implementation of Global Refinement of Random Forest.")
2046 (home-page "https://github.com/masatoi/cl-random-forest")
2047 (license license:expat))))
2049 (define-public cl-random-forest
2050 (sbcl-package->cl-source-package sbcl-cl-random-forest))
2052 (define-public ecl-cl-random-forest
2053 (sbcl-package->ecl-package sbcl-cl-random-forest))