Skip to content

Instantly share code, notes, and snippets.

View mathias-brandewinder's full-sized avatar

Mathias Brandewinder mathias-brandewinder

View GitHub Profile
#I @"c:\users\mathias\documents\visual studio 2013\Projects\Chapter3\packages\"
#r @"R.NET.1.5.5\lib\net40\RDotNet.dll"
#r @"RDotNet.FSharp.0.1.2.1\lib\net40\RDotNet.FSharp.dll"
#r @"R.NET.1.5.5\lib\net40\RDotNet.NativeLibrary.dll"
#r @"RProvider.1.0.5\lib\RProvider.dll"
open RDotNet
open RProvider
open RProvider.``base``
#r @"Deedle.0.9.12\lib\net40\Deedle.dll"
#r @"Deedle.RPlugin.0.9.12\lib\net40\Deedle.RProvider.Plugin.dll"
open Deedle
open Deedle.RPlugin
let codesSeries =
Series(
countries |> Seq.map (fun c -> c.Code) |> Seq.toList,
countries |> Seq.map (fun c -> c.Code) |> Seq.toList)
#r "/home/you/src/thisthing/lib/JSONNet/Newtonsoft.Json.dll"
open System
open System.Collections.Generic // for dictionary
open Newtonsoft.Json
// Identifier type
type Id = System.Guid
module EventStore =
@mathias-brandewinder
mathias-brandewinder / logistic.fsx
Created July 16, 2014 21:08
Logistic regression
type Vec = float []
let f (X:Vec) (W:Vec) =
(X,W) ||> Array.map2 (fun x w -> x * w)
let g z = 1. / (1. + exp (-z))
let dg z = g(z) * (1. - g(z))
let h (X:Vec) (W:Vec) = g (f X W |> Seq.sum)
@mathias-brandewinder
mathias-brandewinder / gist:07a94a584973f5155cf1
Created October 28, 2014 05:01
Digits & Streams (experimenting)
#r @"../packages/Streams.0.2.0/lib/Streams.Core.dll"
open Nessos.Streams.Core
open System.IO
(*
Original file here: 50,000 scans of digits
Col 1 is the actual number, rest is 28x28 pixels, grayscale encoded
http://1drv.ms/ZWkcX6
*)
open System.Drawing
let brightness (c:Color) = c.GetBrightness ()
let pixels (bmp:Bitmap) =
seq { for x in 0 .. bmp.Width - 1 do
for y in 0 .. bmp.Height - 1 ->
(x,y) |> bmp.GetPixel }
let breakpoint (bmp:Bitmap) =
// blog post: http://clear-lines.com/blog/post/Fun-with-L-system.aspx
type Symbol = | Sym of char
type State = Symbol list
type Rules = Map<Symbol,State>
type LSystem =
{ Axiom:State
@mathias-brandewinder
mathias-brandewinder / example.fsx
Created January 31, 2015 04:13
Accord.NET multi class SVM on digit recognizer problem
// Uses Accord.NET version 2.14.0
#r @"..\packages\Accord.2.14.0\lib\net40\Accord.dll"
#r @"..\packages\Accord.Math.2.14.0\lib\net40\Accord.Math.dll"
#r @"..\packages\Accord.Statistics.2.14.0\lib\net40\Accord.Statistics.dll"
#r @"..\packages\Accord.MachineLearning.2.14.0\lib\net40\Accord.MachineLearning.dll"
open System
open System.IO
@mathias-brandewinder
mathias-brandewinder / gist:8f081f3c1fae03133bba
Created March 7, 2015 16:31
Bubbles from Fractal Forest
// just a tiny tweak on the Fractal Forest dojo:
// https://github.com/c4fsharp/Dojo-Fractal-Forest
open System
open System.Drawing
open System.Windows.Forms
let width, height = 500, 500
let form = new Form(Width = width, Height = height)
let box = new PictureBox(BackColor = Color.White, Dock = DockStyle.Fill)
let rec minimum data mini =
match data with
| first::second::tail ->
let min = abs (first - second) |> minimumBetweenTwoNumbers mini
match tail with
| [] -> min
| _ -> minimum second::tail min