Beispiel #1
0
        /// <summary>
        /// Gets a random kown activation function excluding the given activation function.
        /// </summary>
        /// <param name="excluding_activationFunction">The activation function to exclude from the search.</param>
        /// <returns>The random known activation function.</returns>
        public Node.ActivationFunction GetRandomActivationFunction(Node.ActivationFunction excluding_activationFunction)
        {
            if (known_activationFunctions.Count == 0)
            {
                return(null);
            }
            else if (known_activationFunctions.Count == 1)
            {
                return(known_activationFunctions[0]);
            }

            int choice = -1;

            int index = known_activationFunctions.IndexOf(excluding_activationFunction);

            if (index == -1)
            {
                choice = Random.Next(known_activationFunctions.Count);
            }
            else
            {
                choice = Random.Next(known_activationFunctions.Count - 1);

                if (choice >= index)
                {
                    ++choice;
                }
            }

            return(known_activationFunctions[choice]);
        }
Beispiel #2
0
        /// <summary>
        /// Constructs a node gene with the given node gene pattern and activation function.
        /// </summary>
        /// <param name="nodeGenePattern">The node gene pattern that this node gene implements.</param>
        /// <param name="activationFunction">The activation function of the node.</param>
        /// <exception cref="ArgumentNullException">When the node gene pattern or activation function is null.</exception>
        protected internal NodeGene(NodeGenePattern nodeGenePattern, Node.ActivationFunction activationFunction)
        {
            Helpers.ThrowOnNull(nodeGenePattern, "nodeGenePattern");
            Helpers.ThrowOnNull(activationFunction, "activationFunction");


            NodeGenePattern = nodeGenePattern;

            ActivationFunction = activationFunction;
        }
Beispiel #3
0
        /// <summary>
        /// Adds the given activation function to the known activation functions.
        /// </summary>
        /// <param name="activationFunction">The activation function to add.</param>
        /// <returns>False if activation function is already added. True otherwise.</returns>
        public bool Add_KnownActivationFunction(Node.ActivationFunction activationFunction)
        {
            if (known_activationFunctions.Contains(activationFunction))
            {
                return(false);
            }

            known_activationFunctions.Add(activationFunction);

            return(true);
        }
Beispiel #4
0
 /// <summary>
 /// Creates a node gene with the given pattern and activation function.
 /// </summary>
 /// <param name="nodeGenePattern">The node gene pattern of the node gene.</param>
 /// <param name="activationFunction">The activation function of the node gene.</param>
 /// <returns>The created node gene.</returns>
 /// <exception cref="ArgumentNullException">When the node gene pattern or activation function is null.</exception>
 public NodeGene Create_NodeGene(NodeGenePattern nodeGenePattern, Node.ActivationFunction activationFunction)
 {
     return(new NodeGene(nodeGenePattern, activationFunction));
 }