using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace BCMToolbox { public static class MathToolbox { static Random r = new Random(); // returns a random gaussian with mean 0 and sigma 1 public static double GetRandomGaussian() { double x1, x2, w, y1, y2; do { x1 = 2.0 * r.NextDouble() - 1.0; x2 = 2.0 * r.NextDouble() - 1.0; w = x1 * x1 + x2 * x2; } while (w >= 1.0); w = Math.Sqrt((-2.0 * Math.Log(w, Math.E)) / w); y1 = x1 * w; y2 = x2 * w; return y1; } public static Func Sigmoid { get { return x => 1 / (1 + Math.Exp(-x)); } } public static Func InverseSigmoid { get { return (y => -Math.Log((1 - y) / y, Math.E)); } } } }