View pi.clj
; Calculate Pi in Clojure | |
; https://rosettacode.org/wiki/Pi | |
; https://en.wikipedia.org/wiki/Spigot_algorithm | |
(defn pi-digits [& {:keys [q r t k n l]}] | |
(if (< (- (+ (* 4 q) r) t) (* n t)) | |
(cons n | |
(lazy-seq | |
(pi-digits :q (* q 10) | |
:r (* 10 (- r (* n t))) | |
:t t |
View eratosthenes.clj
; This one is really nice and compact but it quickly runs out of stack space: | |
(defn primes [i] (cons i (lazy-seq (filter #(not (zero? (mod % i))) (primes (inc i)))))) | |
(take 100 (primes 2)) | |
; (2 3 5 7 ...) | |
(take 1000 (primes 2)) | |
; Error printing return value (StackOverflowError) at user/primes (NO_SOURCE_FILE:1). | |
; This one is slightly less elegant but works for large numbers: | |
(defn primes [i p] | |
(if (some #(zero? (mod i %)) p) |
View imageio.clj
(import '[magick MagickImage ImageInfo ColorspaceType]) | |
(defn spit-image [file-name width height data] | |
"Save an RGB image" | |
(let [info (ImageInfo.) | |
image (MagickImage.)] | |
(.constituteImage image width height "RGB" data) | |
(.setSize info (str width \x height)) | |
(.setDepth info 8) | |
(.setColorspace info ColorspaceType/RGBColorspace) |
View mnist.scm
(use-modules (oop goops) (ice-9 binary-ports) (rnrs bytevectors) (aiscm core) (system foreign) (aiscm xorg) (ice-9 format) | |
; http://yann.lecun.com/exdb/mnist/ | |
(define f (open-file "train-labels-idx1-ubyte" "rb")) | |
(define magic (bytevector-u32-ref (get-bytevector-n f 4) 0 (endianness big))) | |
(define n (bytevector-u32-ref (get-bytevector-n f 4) 0 (endianness big))) | |
(define bv (get-bytevector-n f n)) | |
(define labels (make (multiarray <ubyte> 1) #:memory (bytevector->pointer bv) #:shape (list n))) | |
(define f (open-file "train-images-idx3-ubyte" "rb")) | |
(define magic (bytevector-u32-ref (get-bytevector-n f 4) 0 (endianness big))) |
View raw-opengl.c
// Minimal OpenGL shader example using OpenGL directly | |
#include <math.h> | |
#include <stdio.h> | |
#include <GL/glew.h> | |
#include <GL/glut.h> | |
const char *vertexSource = "#version 130\n\ | |
in mediump vec3 point;\n\ | |
in mediump vec2 texcoord;\n\ |
View lstm-predict.py
#!/usr/bin/env python3 | |
import sys | |
import numpy as np | |
import tensorflow as tf | |
class CharVec: | |
def __init__(self, text): | |
self.chars = np.array([ord(c) for c in sorted(set(text))]) |
View rnn-predict.py
#!/usr/bin/env python3 | |
import sys | |
import numpy as np | |
import tensorflow as tf | |
class CharVec: | |
def __init__(self, text): | |
self.chars = np.array([ord(c) for c in sorted(set(text))]) |
View autoencoder-run.py
#!/usr/bin/env python3 | |
# http://blog.aloni.org/posts/backprop-with-tensorflow/ | |
import random | |
import numpy as np | |
import tensorflow as tf | |
import pickle | |
import gzip | |
import cv2 |
View mnist-dream.py
#!/usr/bin/env python3 | |
# http://blog.aloni.org/posts/backprop-with-tensorflow/ | |
import random | |
import pickle | |
import gzip | |
import numpy as np | |
import tensorflow as tf | |
import cv2 |
View grid.pov
// calibration grid |
NewerOlder