public void StepFunction_Test() { Assert.AreEqual(0, ActivationFunctionHelper.StepFunction(0)); Assert.AreEqual(0, ActivationFunctionHelper.StepFunction(0)); Assert.AreEqual(1, ActivationFunctionHelper.StepFunction(2)); Assert.AreEqual(1, ActivationFunctionHelper.StepFunction(0.1)); }
public void ActivationFunction_Test() { Assert.AreEqual(0.5, ActivationFunctionHelper.ActivationFunction(ActivationFunctionHelper.Function.SIGMOID, 0)); Assert.AreEqual(0.731, ActivationFunctionHelper.ActivationFunction(ActivationFunctionHelper.Function.SIGMOID, 1), 0.0005); Assert.AreEqual(0.2689, ActivationFunctionHelper.ActivationFunction(ActivationFunctionHelper.Function.SIGMOID, -1), 0.0005); Assert.AreEqual(0, ActivationFunctionHelper.ActivationFunction(ActivationFunctionHelper.Function.STEP_FUNC, 0)); Assert.AreEqual(0, ActivationFunctionHelper.ActivationFunction(ActivationFunctionHelper.Function.STEP_FUNC, 0)); Assert.AreEqual(1, ActivationFunctionHelper.ActivationFunction(ActivationFunctionHelper.Function.STEP_FUNC, 2)); Assert.AreEqual(1, ActivationFunctionHelper.ActivationFunction(ActivationFunctionHelper.Function.STEP_FUNC, 0.1)); }
public double CalculateValue(Dictionary <int, NodeGene> nodes, Stack <int> visitedNodes) { //Check if the node is in the stack, if so return the last value if (visitedNodes.Contains(_id)) { return(_lastVal); } //If value already calculated return the value if (_currentValCalculatedFlag) { return(_currentVal); } //Add the node to the stack visitedNodes.Push(_id); //Node is calculated the first time _lastVal = _currentVal; _currentVal = 0; foreach (ConnectionGene connection in _inputs) { //Add only active connections if (connection.Expressed) { //Recursive call of calculate value _currentVal += connection.Weight * nodes[connection.InNode].CalculateValue(nodes, visitedNodes); } } _currentVal = ActivationFunctionHelper.ActivationFunction(_typeOfFunction, _currentVal); _currentValCalculatedFlag = true; //Check if the removed node is really the correct node int poppedNode = visitedNodes.Pop(); if (poppedNode != _id) { throw new System.Exception("The popped node does not match the id! PoppedNode: " + poppedNode + ", ID: " + _id); } return(_currentVal); }
public void SigmoidFunction_Test() { Assert.AreEqual(0.5, ActivationFunctionHelper.SigmoidFunction(0)); Assert.AreEqual(0.731, ActivationFunctionHelper.SigmoidFunction(1), 0.0005); Assert.AreEqual(0.2689, ActivationFunctionHelper.SigmoidFunction(-1), 0.0005); }