Skip to content

Instantly share code, notes, and snippets.

Avatar

Mathias Brandewinder mathias-brandewinder

View GitHub Profile
@mathias-brandewinder
mathias-brandewinder / graph.fsx
Created Apr 11, 2017
Visualize Azure Function App with F# and GraphViz
View graph.fsx
(*
Reading out bindings
*)
type Direction =
| Trigger
| In
| Out
type Properties = Map<string,string>
@mathias-brandewinder
mathias-brandewinder / gist:d3daebd687f2095de1b1
Created Mar 31, 2015
Conversion to F# of "Gradient Descent Training Using C#"
View gist:d3daebd687f2095de1b1
// This is a conversion to F# of the C# code presented in
// MSDN Magazine, March 2015, by James McCaffrey:
// https://msdn.microsoft.com/en-us/magazine/dn913188.aspx
open System
let sumprod (v1:float[]) (v2:float[]) =
Seq.zip v1 v2 |> Seq.sumBy (fun (x,y) -> x * y)
let sigmoid z = 1.0 / (1.0 + exp (- z))
@mathias-brandewinder
mathias-brandewinder / App.fs
Last active Jul 11, 2020
Lorentz attractor in Fable-Elmish
View App.fs
(*
Simulation of the Lorentz attractor, using Fable.
If you want to see this code in action, just copy this code into the Fable REPL:
https://fable.io/repl/
*)
module App
open Elmish
open Elmish.React
@mathias-brandewinder
mathias-brandewinder / version-0.fsx
Last active May 17, 2020
On-the-fly code with FParsec
View version-0.fsx
type Program () =
let f (x:float) = 2.0 * x + 1.0
member this.Run (x:float) =
let result = f x
printfn "Result: %.2f" result
let program = Program()
program.Run(10.0)
@mathias-brandewinder
mathias-brandewinder / day.csv
Last active Dec 6, 2019
ML.NET in FSI / dotnetcore
View day.csv
instant dteday season yr mnth holiday weekday workingday weathersit temp atemp hum windspeed casual registered cnt
1 2011-01-01 1 0 1 0 6 0 2 0.344167 0.363625 0.805833 0.160446 331 654 985
2 2011-01-02 1 0 1 0 0 0 2 0.363478 0.353739 0.696087 0.248539 131 670 801
3 2011-01-03 1 0 1 0 1 1 1 0.196364 0.189405 0.437273 0.248309 120 1229 1349
4 2011-01-04 1 0 1 0 2 1 1 0.2 0.212122 0.590435 0.160296 108 1454 1562
5 2011-01-05 1 0 1 0 3 1 1 0.226957 0.22927 0.436957 0.1869 82 1518 1600
6 2011-01-06 1 0 1 0 4 1 1 0.204348 0.233209 0.518261 0.0895652 88 1518 1606
7 2011-01-07 1 0 1 0 5 1 2 0.196522 0.208839 0.498696 0.168726 148 1362 1510
8 2011-01-08 1 0 1 0 6 0 2 0.165 0.162254 0.535833 0.266804 68 891 959
9 2011-01-09 1 0 1 0 0 0 1 0.138333 0.116175 0.434167 0.36195 54 768 822
View santa.fsx
// This is the code sample for my #fsAdvent 2019 contribution.
// Check the corresponding blog post for some explanations :)
// https://brandewinder.com/2019/12/04/santas-mailbox/
open System
open System.Threading.Tasks
open System.Diagnostics
open System.Collections.Generic
let factorize x =
@mathias-brandewinder
mathias-brandewinder / MDL.fs
Last active Nov 20, 2019
Recursive minimal entropy partitioning, based on Fayyad & Irani: break a continuous variable into discrete intervals top-down, maximizing the entropy gained at each step, with a stopping rule using the Minimum Description Length principle.
View MDL.fs
namespace Discretization
// Recursive minimal entropy partitioning,
// based on Fayyad & Irani 1993.
// See the following article, section 3.3,
// for a description of the algorithm:
// http://www.math.unipd.it/~dulli/corso04/disc.pdf
// Note: this can certainly be optimized.
module MDL =
@mathias-brandewinder
mathias-brandewinder / gist:5558573
Last active Oct 7, 2019
Stub for F# Machine Learning Dojo
View gist:5558573
// This F# dojo is directly inspired by the
// Digit Recognizer competition from Kaggle.com:
// http://www.kaggle.com/c/digit-recognizer
// The datasets below are simply shorter versions of
// the training dataset from Kaggle.
// The goal of the dojo will be to
// create a classifier that uses training data
// to recognize hand-written digits, and
// evaluate the quality of our classifier
@mathias-brandewinder
mathias-brandewinder / gist:6443302
Last active Oct 7, 2019
Experimenting with Accord SVM
View gist:6443302
#r @"..\packages\Accord.2.8.1.0\lib\Accord.dll"
#r @"..\packages\Accord.Math.2.8.1.0\lib\Accord.Math.dll"
#r @"..\packages\Accord.Statistics.2.8.1.0\lib\Accord.Statistics.dll"
#r @"..\packages\Accord.MachineLearning.2.8.1.0\lib\Accord.MachineLearning.dll"
open System
open System.IO
open Accord.MachineLearning
open Accord.MachineLearning.VectorMachines