This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# See also: https://stackoverflow.com/questions/10982911/creating-temporary-files-in-bash | |
# Create temporary directory. | |
mydir=$(mktemp -d "${TMPDIR:-/tmp/}$(basename $0).XXXXXXXXXXXX") | |
# Remove on exit. | |
trap "rm -rf $mydir" EXIT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns pca | |
(:require [clojure.core.matrix :as m] | |
[clojure.core.matrix.linear :as ml] | |
[clojure.core.matrix.utils :as mu] | |
[clojure.core.matrix.stats :as ms])) | |
;; dependency: [net.mikera/core.matrix "0.57.0"] | |
(defn fit! [m & {:keys [num-components transform?]}] | |
(let [mean (ms/mean m) ;; per-column mean |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns k-means | |
(:import [org.apache.commons.math3.ml.clustering | |
Clusterable KMeansPlusPlusClusterer] | |
[org.apache.commons.math3.ml.distance EuclideanDistance])) | |
;; dependency: [org.apache.commons/commons-math3 "3.6.1"] | |
(defrecord ClusterableWrapper [x] | |
Clusterable | |
(getPoint [this] x)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns learn-mallet.core | |
(:import [cc.mallet.optimize Optimizable$ByGradientValue | |
ConjugateGradient GradientAscent LimitedMemoryBFGS | |
OptimizerEvaluator$ByGradient])) | |
;; add dependency [cc.mallet/mallet "2.0.8"] | |
(defprotocol IProblem | |
;; returns map of problem's current state | |
(problem-state [this])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns hdf5 | |
(:import [org.bytedeco.javacpp | |
DoublePointer FloatPointer | |
LongPointer IntPointer | |
ShortPointer BytePointer] | |
[org.bytedeco.javacpp hdf5 hdf5$H5File])) | |
;; Using maven dependency: | |
;; [org.bytedeco.javacpp-presets/hdf5-platform "1.10.0-patch1-1.3"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns read-excel-stream | |
(:import [com.monitorjbl.xlsx StreamingReader])) | |
;; Remember to add the following maven dependency: | |
;; [com.monitorjbl/xlsx-streamer "1.0.1"] | |
;; More info here: | |
;; https://github.com/monitorjbl/excel-streaming-reader | |
(defn workbook | |
"Open an Excel workbook, for example in a with-open form. This is lazy, and |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Port of https://github.com/bytedeco/javacpp-presets/tree/master/openblas | |
;; Requires openblas dependency: | |
;; [org.bytedeco.javacpp-presets/openblas-platform "0.2.19-1.3"] | |
(ns ExampleDGELSrowmajor | |
(:import [org.bytedeco.javacpp openblas])) | |
(defn print-matrix-rowmajor [desc m n mat ldm] | |
(println "\n " desc) | |
(doseq [i (range m)] | |
(doseq [j (range n)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "lbfgs.h" // see https://github.com/stephenbeckr/L-BFGS-B-C/blob/master/src/lbfgsb.h | |
#include <stdio.h> | |
int test_setulb(integer *n, integer *m, double *x, double *l, | |
double *u, integer *nbd, double *f, | |
double *g, double *factr, double *pgtol, double *wa, | |
integer *iwa, integer *task, | |
integer *iprint, integer *csave, | |
logical *lsave, integer *isave, double *dsave) { | |
printf("test_setulb()\n"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns getpid | |
(:import [jnr.ffi.types pid_t] | |
[jnr.ffi LibraryLoader])) | |
;; see https://github.com/jnr/jnr-ffi-examples/blob/master/getpid/src/main/java/getpid/Getpid.java | |
;; using dependency: [com.github.jnr/jnr-ffi "2.0.9"] | |
;; public interface LibC { | |
;; public @pid_t long getpid(); | |
;; public @pid_t long getppid(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns fuzzy-diff | |
"Approximate comparison of floating-point numbers for clojure.data/diff." | |
(:require [clojure.data :refer [Diff]])) | |
(def ^:dynamic *fuzz* 0) | |
(defn fuzzy-float-diff [a b] | |
(if (< (Math/abs (- a b)) *fuzz*) [nil nil a] [a b nil])) | |
(extend java.lang.Double |
NewerOlder