Skip to content

Instantly share code, notes, and snippets.

@lspector
lspector / gaussian.clj
Last active April 5, 2022 21:13
Demo of perturbation with Gaussian noise
;; gorilla-repl.fileformat = 1
;; **
;;; # Gaussian
;; **
;; @@
(ns gaussian
(:require [gorilla-plot.core :as plot]))
@lspector
lspector / maria.clj
Last active September 24, 2018 13:07
A gist to experiment with maria.cloud
(defn maria
[]
(+ 1 3))
@lspector
lspector / palindrome.clj
Last active February 14, 2018 16:37
A simple genetic algorithm for evolving a palindrome, in Clojure in a Gorilla REPL worksheet; view at http://viewer.gorilla-repl.org/view.html?source=gist&id=e0afea6bba84c1317a765b4da55ae0c6
;; gorilla-repl.fileformat = 1
;; **
;;; # Palindrome
;;;
;;; Lee Spector, lspector@hampshire.edu, 20180213
;;;
;;; Here's another simple genetic algorithm demonstration, this one for evolving a palindrome -- a word that's the same backwards as forwards.
;;;
;;; We could represent words as strings of characters, but some things are a little simpler to do with vectors, so here we'll represent words as vectors of single-letter symbols.
@lspector
lspector / primes.clj
Last active February 8, 2018 17:28
Some Clojure code from class, for testing primality, in a Gorilla REPL worksheet. View: http://viewer.gorilla-repl.org/view.html?source=gist&id=766a20c30fb54f009e4e8a38173a4910
;; gorilla-repl.fileformat = 1
;; **
;;; # Primes
;; **
;; @@
(ns primes)
;; @@
;; =>
@lspector
lspector / self-eval-music.clj
Last active November 28, 2017 05:03
Turning a self-eval map into music for AI at Hampshire College: http://viewer.gorilla-repl.org/view.html?source=gist&id=249adaf7d066406cbcdefbac3a534ae4
;; gorilla-repl.fileformat = 1
;; **
;;; # Self-eval music
;;;
;;; Lee Spector, 2017
;;;
;;; This is code for turning self-evaluations into music, for CS263: Artificial Intelligence at Hampshire College. The output can be played via [Klangmeister](http://ctford.github.io/klangmeister/).
;;;
;; **
@lspector
lspector / self-eval-scramble.clj
Last active October 31, 2017 02:38
Scrambling a self-eval map with a Markov chain for AI at Hampshire College: http://viewer.gorilla-repl.org/view.html?source=gist&id=a038002d2c32eee3a1d5680b69446cd6
;; gorilla-repl.fileformat = 1
;; **
;;; # Self-eval scramble
;;;
;;; Lee Spector, 2017
;;;
;;; This is code for Markov chain scrambling of self-evaluations for CS263: Artificial Intelligence at Hampshire College.
;;;
;;; In this text scrambler, we start with a random word and then follow it by some word that follows that word in the original text, with the probabilities for the following words derived from the numbers of times that they follow the first word in the original text. Then we repeat the process to choose a word to follow the second word, and so on. While it's possible to do this by computing the probabilities of all word pairs in the input, we can do it more simply, and achieve the same results, with random rotations.
;; gorilla-repl.fileformat = 1
;; **
;;; # A Simple Genetic Algorithm to Solve a Silly, Made-Up Problem
;;;
;;; Here we'll demonstrate the core concepts of genetic algorithms, in Clojure, by writing code to evolve a sequence of 5 integers between 1 and 100 (inclusive) that, when divided in sequence, produce 5.
;;;
;;; That is, we want numbers a, b, c, d, e such that `a / b / c / d / e = 5`
;;;
;;; It's a silly, made-up problem, but it will nonetheless allow us to see how genetic algorithms work, and how to implement them in Clojure.
;; gorilla-repl.fileformat = 1
;; **
;;; # Search
;;;
;;; Lecture notes on AI search algorithms, with Clojure code.
;;;
;;; Lee Spector, lspector@hampshire.edu, 20141015-20170930
;;;
;;; Some of the code here was adapted from the [search.lisp](https://norvig.com/paip/search.lisp) Common Lisp code in Peter Norvig's Paradigms of AI Programming (1991), but with substantial modifications.
@lspector
lspector / search.clj
Last active August 29, 2015 14:07
AI search code
(ns search.core)
;; Lecture notes on AI search algorithms.
;; Lee Spector, lspector@hampshire.edu, 20141015
#_(defn is-5 [n]
(= n 5))
#_(filter is-5 [1 2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 1])
@lspector
lspector / vp2d.clj
Created April 10, 2014 01:48
Initial sketches toward a 2d swarm-like alife system in Clojure/Quil
;; Initial sketches toward a 2d swarm-like alife system in Clojure/Quil
;; Lee Spector, lspector@hampshire.edu, 20140409
(ns vp2d.core
(:use quil.core)
(:gen-class))
(def all-pods (atom []))
(def iteration (atom 0))