gnu: Add Pfff.
[jackhill/guix/guix.git] / gnu / packages / machine-learning.scm
CommitLineData
741115b6
RW
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2015 Ricardo Wurmus <rekado@elephly.net>
3;;;
4;;; This file is part of GNU Guix.
5;;;
6;;; GNU Guix is free software; you can redistribute it and/or modify it
7;;; under the terms of the GNU General Public License as published by
8;;; the Free Software Foundation; either version 3 of the License, or (at
9;;; your option) any later version.
10;;;
11;;; GNU Guix is distributed in the hope that it will be useful, but
12;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19(define-module (gnu packages machine-learning)
20 #:use-module ((guix licenses) #:prefix license:)
21 #:use-module (guix packages)
22 #:use-module (guix utils)
23 #:use-module (guix download)
c1670a81 24 #:use-module (guix build-system cmake)
741115b6 25 #:use-module (guix build-system gnu)
8406138b 26 #:use-module (guix build-system r)
71f80f54 27 #:use-module (gnu packages)
0931c609
RW
28 #:use-module (gnu packages boost)
29 #:use-module (gnu packages compression)
30 #:use-module (gnu packages gcc)
31 #:use-module (gnu packages maths)
c1670a81 32 #:use-module (gnu packages pkg-config)
0931c609 33 #:use-module (gnu packages python)
c1670a81
RW
34 #:use-module (gnu packages statistics)
35 #:use-module (gnu packages swig)
0931c609 36 #:use-module (gnu packages xml))
741115b6
RW
37
38(define-public libsvm
39 (package
40 (name "libsvm")
41 (version "3.20")
42 (source
43 (origin
44 (method url-fetch)
45 (uri (string-append
46 "https://github.com/cjlin1/libsvm/archive/v"
47 (string-delete #\. version) ".tar.gz"))
48 (file-name (string-append name "-" version ".tar.gz"))
49 (sha256
50 (base32
51 "1jpjlql3frjza7zxzrqqr2firh44fjb8fqsdmvz6bjz7sb47zgp4"))))
52 (build-system gnu-build-system)
53 (arguments
54 `(#:tests? #f ;no "check" target
55 #:phases (modify-phases %standard-phases
56 (delete 'configure)
57 (replace
58 'install
59 (lambda* (#:key outputs #:allow-other-keys)
60 (let* ((out (assoc-ref outputs "out"))
61 (bin (string-append out "/bin/")))
62 (mkdir-p bin)
63 (for-each (lambda (file)
64 (copy-file file (string-append bin file)))
65 '("svm-train"
66 "svm-predict"
67 "svm-scale")))
68 #t)))))
69 (home-page "http://www.csie.ntu.edu.tw/~cjlin/libsvm/")
70 (synopsis "Library for Support Vector Machines")
71 (description
72 "LIBSVM is a machine learning library for support vector
73classification, (C-SVC, nu-SVC), regression (epsilon-SVR, nu-SVR) and
74distribution estimation (one-class SVM). It supports multi-class
75classification.")
76 (license license:bsd-3)))
71f80f54
RW
77
78(define-public python-libsvm
79 (package (inherit libsvm)
80 (name "python-libsvm")
81 (build-system gnu-build-system)
82 (arguments
83 `(#:tests? #f ;no "check" target
84 #:make-flags '("-C" "python")
85 #:phases
86 (modify-phases %standard-phases
87 (delete 'configure)
88 (replace
89 'install
90 (lambda* (#:key inputs outputs #:allow-other-keys)
91 (let ((site (string-append (assoc-ref outputs "out")
92 "/lib/python"
93 (string-take
94 (string-take-right
95 (assoc-ref inputs "python") 5) 3)
96 "/site-packages/")))
97 (substitute* "python/svm.py"
98 (("../libsvm.so.2") "libsvm.so.2"))
99 (mkdir-p site)
100 (for-each (lambda (file)
101 (copy-file file (string-append site (basename file))))
102 (find-files "python" "\\.py"))
103 (copy-file "libsvm.so.2"
104 (string-append site "libsvm.so.2")))
105 #t)))))
106 (inputs
107 `(("python" ,python)))
108 (synopsis "Python bindings of libSVM")))
0931c609
RW
109
110(define-public randomjungle
111 (package
112 (name "randomjungle")
113 (version "2.1.0")
114 (source
115 (origin
116 (method url-fetch)
117 (uri (string-append
118 "http://www.imbs-luebeck.de/imbs/sites/default/files/u59/"
119 "randomjungle-" version ".tar_.gz"))
120 (sha256
121 (base32
122 "12c8rf30cla71swx2mf4ww9mfd8jbdw5lnxd7dxhyw1ygrvg6y4w"))))
123 (build-system gnu-build-system)
124 (arguments
125 `(#:configure-flags
126 (list (string-append "--with-boost="
127 (assoc-ref %build-inputs "boost")))
128 #:phases
129 (modify-phases %standard-phases
130 (add-before
131 'configure 'set-CXXFLAGS
132 (lambda _
133 (setenv "CXXFLAGS" "-fpermissive ")
134 #t)))))
135 (inputs
136 `(("boost" ,boost)
137 ("gsl" ,gsl)
138 ("libxml2" ,libxml2)
139 ("zlib" ,zlib)))
140 (native-inputs
19afbea1 141 `(("gfortran" ,gfortran)))
0931c609
RW
142 (home-page "http://www.imbs-luebeck.de/imbs/de/node/227/")
143 (synopsis "Implementation of the Random Forests machine learning method")
144 (description
145 "Random Jungle is an implementation of Random Forests. It is supposed to
146analyse high dimensional data. In genetics, it can be used for analysing big
147Genome Wide Association (GWA) data. Random Forests is a powerful machine
148learning method. Most interesting features are variable selection, missing
149value imputation, classifier creation, generalization error estimation and
150sample proximities between pairs of cases.")
151 (license license:gpl3+)))
c1670a81
RW
152
153(define-public shogun
154 (package
155 (name "shogun")
156 (version "4.0.0")
157 (source
158 (origin
159 (method url-fetch)
160 (uri (string-append
161 "ftp://shogun-toolbox.org/shogun/releases/"
162 (version-major+minor version)
163 "/sources/shogun-" version ".tar.bz2"))
164 (sha256
165 (base32
166 "159nlijnb7mnrv9za80wnm1shwvy45hgrqzn51hxy7gw4z6d6fdb"))
167 (modules '((guix build utils)
168 (ice-9 rdelim)))
169 (snippet
170 '(begin
171 ;; Remove non-free sources and files referencing them
172 (for-each delete-file
173 (find-files "src/shogun/classifier/svm/"
174 "SVMLight\\.(cpp|h)"))
175 (for-each delete-file
176 (find-files "examples/undocumented/libshogun/"
177 (string-append
178 "(classifier_.*svmlight.*|"
179 "evaluation_cross_validation_locked_comparison).cpp")))
180 ;; Remove non-free functions.
181 (define (delete-ifdefs file)
182 (with-atomic-file-replacement file
183 (lambda (in out)
184 (let loop ((line (read-line in 'concat))
185 (skipping? #f))
186 (if (eof-object? line)
187 #t
188 (let ((skip-next?
189 (or (and skipping?
190 (not (string-prefix?
191 "#endif //USE_SVMLIGHT" line)))
192 (string-prefix?
193 "#ifdef USE_SVMLIGHT" line))))
194 (when (or (not skipping?)
195 (and skipping? (not skip-next?)))
196 (display line out))
197 (loop (read-line in 'concat) skip-next?)))))))
198 (for-each delete-ifdefs (find-files "src/shogun/kernel/"
199 "^Kernel\\.(cpp|h)"))))))
200 (build-system cmake-build-system)
201 (arguments
202 '(#:tests? #f ;no check target
203 #:phases
204 (alist-cons-after
205 'unpack 'delete-broken-symlinks
206 (lambda _
207 (for-each delete-file '("applications/arts/data"
208 "applications/asp/data"
209 "applications/easysvm/data"
210 "applications/msplicer/data"
211 "applications/ocr/data"
212 "examples/documented/data"
213 "examples/documented/matlab_static"
214 "examples/documented/octave_static"
215 "examples/undocumented/data"
216 "examples/undocumented/matlab_static"
217 "examples/undocumented/octave_static"
218 "tests/integration/data"
219 "tests/integration/matlab_static"
220 "tests/integration/octave_static"
221 "tests/integration/python_modular/tests"))
222 #t)
223 (alist-cons-after
224 'unpack 'change-R-target-path
225 (lambda* (#:key outputs #:allow-other-keys)
226 (substitute* '("src/interfaces/r_modular/CMakeLists.txt"
227 "src/interfaces/r_static/CMakeLists.txt"
228 "examples/undocumented/r_modular/CMakeLists.txt")
229 (("\\$\\{R_COMPONENT_LIB_PATH\\}")
230 (string-append (assoc-ref outputs "out")
231 "/lib/R/library/")))
232 #t)
233 (alist-cons-after
234 'unpack 'fix-octave-modules
235 (lambda* (#:key outputs #:allow-other-keys)
236 (substitute* '("src/interfaces/octave_modular/CMakeLists.txt"
237 "src/interfaces/octave_static/CMakeLists.txt")
238 (("^include_directories\\(\\$\\{OCTAVE_INCLUDE_DIRS\\}")
239 "include_directories(${OCTAVE_INCLUDE_DIRS} ${OCTAVE_INCLUDE_DIRS}/octave"))
240
241 ;; change target directory
242 (substitute* "src/interfaces/octave_modular/CMakeLists.txt"
243 (("\\$\\{OCTAVE_OCT_LOCAL_API_FILE_DIR\\}")
244 (string-append (assoc-ref outputs "out")
245 "/share/octave/packages")))
246 #t)
247 (alist-cons-before
248 'build 'set-HOME
249 ;; $HOME needs to be set at some point during the build phase
250 (lambda _ (setenv "HOME" "/tmp") #t)
251 %standard-phases))))
252 #:configure-flags
253 (list "-DCMAKE_BUILD_WITH_INSTALL_RPATH=TRUE"
254 "-DUSE_SVMLIGHT=OFF" ;disable proprietary SVMLIGHT
255 ;;"-DJavaModular=ON" ;requires unpackaged jblas
256 ;;"-DRubyModular=ON" ;requires unpackaged ruby-narray
257 ;;"-DPerlModular=ON" ;"FindPerlLibs" does not exist
258 ;;"-DLuaModular=ON" ;fails because lua doesn't build pkgconfig file
259 "-DOctaveModular=ON"
260 "-DOctaveStatic=ON"
261 "-DPythonModular=ON"
262 "-DPythonStatic=ON"
263 "-DRModular=ON"
264 "-DRStatic=ON"
265 "-DCmdLineStatic=ON")))
266 (inputs
267 `(("python" ,python)
268 ("numpy" ,python-numpy)
269 ("r" ,r)
270 ("octave" ,octave)
271 ("swig" ,swig)
272 ("hdf5" ,hdf5)
273 ("atlas" ,atlas)
274 ("arpack" ,arpack-ng)
275 ("lapack" ,lapack)
276 ("glpk" ,glpk)
277 ("libxml2" ,libxml2)
278 ("lzo" ,lzo)
279 ("zlib" ,zlib)))
280 (native-inputs
281 `(("pkg-config" ,pkg-config)))
6b5b656f
RW
282 ;; Non-portable SSE instructions are used so building fails on platforms
283 ;; other than x86_64.
284 (supported-systems '("x86_64-linux"))
c1670a81
RW
285 (home-page "http://shogun-toolbox.org/")
286 (synopsis "Machine learning toolbox")
287 (description
288 "The Shogun Machine learning toolbox provides a wide range of unified and
289efficient Machine Learning (ML) methods. The toolbox seamlessly allows to
290combine multiple data representations, algorithm classes, and general purpose
291tools. This enables both rapid prototyping of data pipelines and extensibility
292in terms of new algorithms.")
293 (license license:gpl3+)))
8406138b
RW
294
295(define-public r-adaptivesparsity
296 (package
297 (name "r-adaptivesparsity")
298 (version "1.4")
299 (source (origin
300 (method url-fetch)
301 (uri (cran-uri "AdaptiveSparsity" version))
302 (sha256
303 (base32
304 "1az7isvalf3kmdiycrfl6s9k9xqk22k1mc6rh8v0jmcz402qyq8z"))))
305 (properties
306 `((upstream-name . "AdaptiveSparsity")))
307 (build-system r-build-system)
308 (arguments
309 `(#:phases
310 (modify-phases %standard-phases
311 (add-after 'unpack 'link-against-armadillo
312 (lambda _
313 (substitute* "src/Makevars"
314 (("PKG_LIBS=" prefix)
315 (string-append prefix "-larmadillo"))))))))
316 (propagated-inputs
317 `(("r-rcpp" ,r-rcpp)
318 ("r-rcpparmadillo" ,r-rcpparmadillo)))
319 (home-page "http://cran.r-project.org/web/packages/AdaptiveSparsity")
320 (synopsis "Adaptive sparsity models")
321 (description
322 "This package implements the Figueiredo machine learning algorithm for
323adaptive sparsity and the Wong algorithm for adaptively sparse gaussian
324geometric models.")
325 (license license:lgpl3+)))