Skip to content

Instantly share code, notes, and snippets.

@rakasaka
rakasaka / sound.pde
Created September 6, 2011 23:18
Arduino piano stair Processing script
import processing.serial.*;
import ddf.minim.signals.*; // Minim sound library
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
int prevent = 0; // Double ring prevention
Serial myPort; // The serial port
Minim minim;
AudioPlayer a;
@rakasaka
rakasaka / sensor.pde
Created September 6, 2011 23:12
Musical stairs sensor code for Arduino
#include <HashMap.h>
int mini = 0;
int maxi = 16;
const byte HASH_SIZE = 16;
HashType<int,int> hashRawArray[HASH_SIZE];
HashMap<int,int> hashMap = HashMap<int,int>( hashRawArray , HASH_SIZE );
void setup(){
Serial.print("reset");
@rakasaka
rakasaka / gist:1169341
Created August 24, 2011 21:45
Unsupervised topic modeling in Ruby using LDA
require 'lda-ruby'
corpus = Lda::Corpus.new
corpus.add_document(Lda::TextDocument.new(corpus, "a lion is a wild feline animal", []))
corpus.add_document(Lda::TextDocument.new(corpus, "a dog is a friendly animal", []))
corpus.add_document(Lda::TextDocument.new(corpus, "a cat is a feline animal", []))
lda = Lda::Lda.new(corpus)
lda.verbose = false
lda.num_topics = (2)
lda.em('random')
@rakasaka
rakasaka / gist:1169338
Created August 24, 2011 21:44
Classification using Latent Semantic Indexing
require 'classifier'
require 'stemmer'
classifier_lsi = Classifier::LSI.new
classifier_lsi.add_item "a lion is a wild feline animal", :cat
classifier_lsi.add_item "a dog is a friendly animal", :dog
classifier_lsi.classify "a cat is a feline animal"
# Results
@rakasaka
rakasaka / gist:1169334
Created August 24, 2011 21:41
Clustering in Ruby using cluster
require 'clusterer'
include Clusterer
@idf = InverseDocumentFrequency.new()
a = Document.new("a lion is a wild feline animal", :idf => @idf).normalize!(@idf)
b = Document.new("a dog is a friendly animal", :idf => @idf).normalize!(@idf)
c = Document.new("a cat is a feline animal", :idf => @idf).normalize!(@idf)
clus = Algorithms.bisecting_kmeans([a,b,c], 2, :maximum_iterations => 5)
# Results