Rev | Line | |
---|
[171] | 1 | using System; |
---|
| 2 | using System.Collections.Generic; |
---|
| 3 | using System.Linq; |
---|
| 4 | using System.Text; |
---|
| 5 | |
---|
| 6 | namespace BCMToolbox |
---|
| 7 | { |
---|
| 8 | public static class MathToolbox |
---|
| 9 | { |
---|
| 10 | static Random r = new Random(); |
---|
| 11 | // returns a random gaussian with mean 0 and sigma 1 |
---|
| 12 | public static double GetRandomGaussian() |
---|
| 13 | { |
---|
| 14 | double x1, x2, w, y1, y2; |
---|
| 15 | |
---|
| 16 | do |
---|
| 17 | { |
---|
| 18 | x1 = 2.0 * r.NextDouble() - 1.0; |
---|
| 19 | x2 = 2.0 * r.NextDouble() - 1.0; |
---|
| 20 | w = x1 * x1 + x2 * x2; |
---|
| 21 | } while (w >= 1.0); |
---|
| 22 | |
---|
| 23 | w = Math.Sqrt((-2.0 * Math.Log(w, Math.E)) / w); |
---|
| 24 | y1 = x1 * w; |
---|
| 25 | y2 = x2 * w; |
---|
| 26 | return y1; |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | public static Func<double, double> Sigmoid |
---|
| 30 | { |
---|
| 31 | get |
---|
| 32 | { |
---|
| 33 | return x => 1 / (1 + Math.Exp(-x)); |
---|
| 34 | } |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | public static Func<double, double> InverseSigmoid |
---|
| 38 | { |
---|
| 39 | get |
---|
| 40 | { |
---|
| 41 | return (y => -Math.Log((1 - y) / y, Math.E)); |
---|
| 42 | } |
---|
| 43 | } |
---|
| 44 | } |
---|
| 45 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.