Skip to content

Instantly share code, notes, and snippets.

View mthomure's full-sized avatar

Mick Thomure mthomure

  • Sony AI
  • Portland, Oregon
View GitHub Profile
@mthomure
mthomure / apply-trained-classifier.py
Created December 29, 2013 23:18
This script illustrates the application of a trained image classifier to a new set of images in Glimpse.
# This script illustrates how to apply a trained image classifier to a new set
# of images.
# Author: Mick Thomure
# Date: 12/29/2013
from glimpse.experiment import *
from glimpse.pools import *
def PredictImageClasses(exp, images, pool):
"""Apply existing model to a new set of images.
@mthomure
mthomure / evaluate-classifier-for-protos.py
Created January 13, 2014 01:41
This script illustrates the use of an existing set of prototypes to compute image features. This data is then used to evaluate classifier performance.
from glimpse.experiment import *
def make_model_for_protos(protos):
"""Create a model for an existing set of prototypes."""
model = Model()
# Here, we assume that all prototypes have the same spatial extent.
model.s2_kernels = [protos]
return model
def train_classifier(model, pool, images, labels):
@mthomure
mthomure / load_activity.py
Last active August 29, 2015 14:16
Glimpse as Feature Extraction (for Kendall) -- load activity from a glimpse experiment as features for a classifier
from cPickle import load as load_pickle
from glimpse.experiment import Layer, ExtractFeatures, GetTrainingSet
# load an experiment object from disk, as saved by the 'glab' command.
def load_experiment(path):
with open(path) as f:
# load saved experiment. return type is described here:
# https://github.com/mthomure/glimpse-project/blob/master/glimpse/experiment/experiment.py#L77
return load_pickle(f)
@mthomure
mthomure / noisy_spirals.clj
Created February 15, 2016 19:45
drive processing (simple drawing) with leap motion and midi controllers
(ns hello-quil.noisy-spirals
(:require [quil.core :as q]
[hello-quil.noisy-spirals-dynamic :as d]
[clojure.core.async :as a]
[overtone.midi :as midi]
[mojion.leap :as leap]))
(q/defsketch gen-art-14
:title "100 Noisy Spirals"
:size [d/SIZE d/SIZE]
@mthomure
mthomure / fuzzy_diff.clj
Created June 14, 2016 16:38
Approximate comparison of floating-point numbers for clojure.data/diff.
(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
(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();
@mthomure
mthomure / test_setulb.c
Last active May 25, 2017 18:13
LBFGS via JNR
#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");
@mthomure
mthomure / ExampleDGELSrowmajor.clj
Created December 30, 2016 22:48
Using OpenBLAS from Clojure
;; 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)]
@mthomure
mthomure / read-excel-stream.clj
Created January 7, 2017 01:21
Read large excel files from clojure without killing the JVM
(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
@mthomure
mthomure / hdf5.clj
Last active May 9, 2017 15:40
Simple HDF5 reader in clojure
(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"]