UPDATE a fork of this gist has been used as a starting point for a community-maintained "awesome" list: machine-learning-with-ruby Please look here for the most up-to-date info!
- liblinear-ruby: Ruby interface to LIBLINEAR using SWIG
require 'google_places' | |
api_key = 'key' | |
# Actually executing stubbed-out spec "should request spots by bounds" from client_spec.rb | |
# Supplying a bounding box to a text search query does not seem to work, nor is this feature documented: | |
# https://developers.google.com/places/web-service/search#TextSearchRequests | |
query = 'pizza' | |
# Bounds is around city of Nashville TN |
addParams = (path, params) -> | |
query = objToQuery(params) | |
joinChar = if /\?/.test(path) then '&' else '?' | |
"#{path}#{joinChar}#{query}" | |
objToQuery = (obj) -> | |
pairs = [] | |
for own key, val of obj | |
if val? and val != '' | |
val = encodeURIComponent(val) |
# Simple global PubSub system built around $.Callbacks | |
# Enables PubSub without relying on DOM element bindings | |
# | |
# Usage: | |
# | |
# PubSub.subscribe 'foo', (message) -> console.log("Received: #{message}") | |
# PubSub.publish 'foo', 'bar' | |
# # Outputs: "Received: bar" | |
$(document).on 'ready', () -> | |
window.PubSub = |
require 'nmatrix/nmatrix' | |
class NMatrix | |
def standardize_columns! | |
cols.times do |i| | |
col = self[0..-1,i] | |
self[0..-1,i] = (col - col.mean[0]) / col.std[0] | |
end | |
self | |
end |
require 'nmatrix/nmatrix' | |
NMatrix.class_eval do | |
def row(row_number, get_by = :copy) | |
if row_numbers = get_row_or_col_index_array(row_number) | |
out = NMatrix.new [row_numbers.length, cols], default_value, dtype: dtype, stype: stype | |
row_numbers.each_with_index do |rownum, i| | |
out[i, 0..-1] = self[rownum, 0..-1] |
require 'narray' # gem install narray | |
class LinearRegressor | |
attr_reader :theta, :mean, :std, :cost_history | |
def initialize opts = {} | |
@alpha = opts[:alpha] || 0.01 | |
@iterations = opts[:iterations] || 400 | |
end |
# Ruby implementation of PCA as described in: | |
# | |
# A tutorial on Principal Components Analysis | |
# Lindsay I Smith February 26, 2002 | |
# http://www.cs.otago.ac.nz/cosc453/student_tutorials/principal_components.pdf | |
# | |
# Install: | |
# | |
# brew install gsl | |
# brew install gnuplot --with-x11 |
// BLEPeripheral: https://github.com/sandeepmistry/arduino-BLEPeripheral | |
// TimerOne: https://code.google.com/p/arduino-timerone/ | |
#include <TimerOne.h> | |
#include <SPI.h> | |
#include <BLEPeripheral.h> | |
// Pins used for Adafruit nrf8001 breakout | |
// See https://learn.adafruit.com/getting-started-with-the-nrf8001-bluefruit-le-breakout/hooking-everything-up | |
#define BLE_REQ 10 | |
#define BLE_RDY 2 |
#!/bin/sh | |
# Clear the Bluetooth attributes cache on Mac OS X | |
# From http://expertsoverflow.com/questions/23549859/clearing-corebluetooth-gatt-cache-without-removing-bond | |
sudo defaults write /Library/Preferences/com.apple.Bluetooth CoreBluetoothCache -dict | |
sudo launchctl unload /System/Library/LaunchDaemons/com.apple.blued.plist | |
sudo launchctl load /System/Library/LaunchDaemons/com.apple.blued.plist |