public Randomize ( double d ) : double | ||
d | double | The range randomizer ignores this value. |
Résultat | double |
/// <summary> /// Randomize the connections between two layers. /// </summary> /// <param name="network">The network to randomize.</param> /// <param name="fromLayer">The starting layer.</param> private void RandomizeSynapse(BasicNetwork network, int fromLayer) { int toLayer = fromLayer + 1; int toCount = network.GetLayerNeuronCount(toLayer); int fromCount = network.GetLayerNeuronCount(fromLayer); int fromCountTotalCount = network.GetLayerTotalNeuronCount(fromLayer); IActivationFunction af = network.GetActivation(toLayer); double low = CalculateRange(af, Double.NegativeInfinity); double high = CalculateRange(af, Double.PositiveInfinity); double b = 0.7d * Math.Pow(toCount, (1d / fromCount)) / (high - low); for (int toNeuron = 0; toNeuron < toCount; toNeuron++) { if (fromCount != fromCountTotalCount) { double w = RangeRandomizer.Randomize(-b, b); network.SetWeight(fromLayer, fromCount, toNeuron, w); } for (int fromNeuron = 0; fromNeuron < fromCount; fromNeuron++) { double w = RangeRandomizer.Randomize(0, b); network.SetWeight(fromLayer, fromNeuron, toNeuron, w); } } }
/// <summary> /// Makes random inputs by randomizing with encog randomize , the normal random from net framework library. /// a quick and easy way to test data and and train networks. /// </summary> /// <param name="number">The number.</param> /// <returns></returns> public static double[] MakeRandomInputs(int number) { var rdn = new Random(); var encogRnd = new RangeRandomizer(-1, 1); var x = new double[number]; for (int i = 0; i < number; i++) { x[i] = encogRnd.Randomize((rdn.NextDouble())); } return x; }