/// <summary> /// Calculate the derivative. /// </summary> /// <param name="a">The activation function.</param> /// <param name="d">The value to calculate for.</param> /// <returns>The derivative.</returns> private double CalcDerivative2(IActivationFunction a, double d) { double[] temp = new double[1]; temp[0] = d; a.ActivationFunction(temp, 0, 1); a.ActivationFunction(temp, 0, 1); return(temp[0]); }
/// <inheritdoc /> public INormalizationStrategy SuggestNormalizationStrategy(VersatileMLDataSet dataset, String architecture) { double inputLow = -1; double inputHigh = 1; double outputLow = -1; double outputHigh = 1; // Create a basic neural network, just to examine activation functions. var methodFactory = new MLMethodFactory(); var network = (BasicNetwork)methodFactory.Create(MethodName, architecture, 1, 1); if (network.LayerCount < 1) { throw new EncogError("Neural network does not have an output layer."); } IActivationFunction outputFunction = network.GetActivation(network.LayerCount - 1); double[] d = { -1000, -100, -50 }; outputFunction.ActivationFunction(d, 0, d.Length); if (d[0] > 0 && d[1] > 0 && d[2] > 0) { inputLow = 0; } INormalizationStrategy result = new BasicNormalizationStrategy( inputLow, inputHigh, outputLow, outputHigh); return(result); }
/// <summary> /// Calculate the derivative. /// </summary> /// /// <param name="a">The activation function.</param> /// <param name="d">The value to calculate for.</param> /// <returns>The derivative.</returns> private static double CalcDerivative2(IActivationFunction a, double d) { var temp = new double[1]; temp[0] = d; a.ActivationFunction(temp, 0, temp.Length); temp[0] = a.DerivativeFunction(temp[0], temp[0]); return(temp[0]); }
/// <summary> /// Calculate the derivative. /// </summary> /// <param name="a">The activation function.</param> /// <param name="d">The value to calculate for.</param> /// <returns>The derivative.</returns> private double CalcDerivative2(IActivationFunction a, double d) { double[] temp = new double[1]; temp[0] = d; a.ActivationFunction(temp, 0, 1); a.ActivationFunction(temp, 0, 1); return temp[0]; }
/// <summary> /// Calculate the range of an activation function. /// </summary> /// <param name="af">The actionvation function to calculate for.</param> /// <param name="r">The value to collect the range at.</param> /// <returns>The range.</returns> private double CalculateRange(IActivationFunction af, double r) { double[] d = { r }; af.ActivationFunction(d, 0, 1); return d[0]; }
/// <summary> /// Compute the output from this synapse. /// </summary> /// /// <param name="input">The input to this synapse.</param> /// <returns>The output from this synapse.</returns> public virtual IMLData Compute(IMLData input) { IMLData result = new BasicMLData(_outputCount); if (_neurons.Count == 0) { throw new NeuralNetworkError( "This network has not been evolved yet, it has no neurons in the NEAT synapse."); } int flushCount = 1; if (_snapshot) { flushCount = _networkDepth; } // iterate through the network FlushCount times for (int i = 0; i < flushCount; ++i) { int outputIndex = 0; int index = 0; result.Clear(); // populate the input neurons while (_neurons[index].NeuronType == NEATNeuronType.Input) { _neurons[index].Output = input[index]; index++; } // set the bias neuron _neurons[index++].Output = 1; while (index < _neurons.Count) { NEATNeuron currentNeuron = _neurons[index]; double sum = 0; foreach (NEATLink link in currentNeuron.InboundLinks) { double weight = link.Weight; double neuronOutput = link.FromNeuron.Output; sum += weight * neuronOutput; } var d = new double[1]; d[0] = sum / currentNeuron.ActivationResponse; _activationFunction.ActivationFunction(d, 0, d.Length); _neurons[index].Output = d[0]; if (currentNeuron.NeuronType == NEATNeuronType.Output) { result[outputIndex++] = currentNeuron.Output; } index++; } } _outputActivationFunction.ActivationFunction(result.Data, 0, result.Count); return(result); }
/// <summary> /// Calculate the range of an activation function. /// </summary> /// <param name="af">The actionvation function to calculate for.</param> /// <param name="r">The value to collect the range at.</param> /// <returns>The range.</returns> private double CalculateRange(IActivationFunction af, double r) { double[] d = { r }; af.ActivationFunction(d, 0, 1); return(d[0]); }
private static double xbc17cb206c45d25e(IActivationFunction x19218ffab70283ef, double x73f821c71fe1e676) { double[] d = new double[] { x73f821c71fe1e676 }; x19218ffab70283ef.ActivationFunction(d, 0, d.Length); d[0] = x19218ffab70283ef.DerivativeFunction(d[0], d[0]); return d[0]; }
/// <summary> /// Calculate the derivative. /// </summary> /// /// <param name="a">The activation function.</param> /// <param name="d">The value to calculate for.</param> /// <returns>The derivative.</returns> private static double CalcDerivative2(IActivationFunction a, double d) { var temp = new double[1]; temp[0] = d; a.ActivationFunction(temp, 0, temp.Length); temp[0] = a.DerivativeFunction(temp[0],temp[0]); return temp[0]; }