/// <summary>
        /// Initiates a NeuralNetwork from a Topology and a Seed.
        /// </summary>
        /// <param name="Topology">The Topology of the Neural Network.</param>
        /// <param name="Seed">The Seed of the Neural Network.
        /// Set to 'null' to use a Timed Seed.</param>
        public NeuralNetwork(UInt32[] Topology, Int32?Seed = 0)
        {
            // Validation check
            if (Topology.Length < 2)
            {
                throw new ArgumentOutOfRangeException("A neural network cannot contain less than 2 layers.",
                                                      "Topology");
            }
            for (int i = 0; i < Topology.Length; i++)
            {
                if (Topology[i] < 1)
                {
                    throw new ArgumentOutOfRangeException("Topology", "A single layer of neurons must contain," +
                                                          "at least, one neuron");
                }
            }
            TheRandomizer = Seed.HasValue ? new Random(Seed.Value) : new Random();

            TheTopology = new List <uint>(Topology).AsReadOnly();

            Sections = new NeuralSection[TheTopology.Count - 1];

            for (int i = 0; i < Sections.Length; i++)
            {
                Sections[i] = new NeuralSection(TheTopology[i], TheTopology[i + 1], TheRandomizer);
            }
        }
예제 #2
0
    public NeuralNetwork(int[] topology)
    {
        if (topology.Length < 2)
        {
            throw new ArgumentException("A Neural Network cannot contain less than 2 Layers.", "Topology");
        }

        for (int i = 0; i < topology.Length; i++)
        {
            if (topology[i] < 1)
            {
                throw new ArgumentException("A single layer of neurons must contain, at least, one neuron.", "Topology");
            }
        }


        _topology = new List <int>(topology);


        _sections = new NeuralSection[_topology.Count - 1];


        for (int i = 0; i < _sections.Length; i++)
        {
            _sections[i] = new NeuralSection(_topology[i], _topology[i + 1]);
        }
    }
예제 #3
0
    public NeuralNetwork(NeuralNetwork main)
    {
        _topology = main._topology;


        _sections = new NeuralSection[_topology.Count - 1];


        for (int i = 0; i < _sections.Length; i++)
        {
            _sections[i] = new NeuralSection(main._sections[i]);
        }
    }
예제 #4
0
    /// <summary>
    /// Initiate an independent deep copy of the nerual network (maybe call this copy?)
    /// </summary>
    /// <param name="Main"></param>
    public NeuralNetwork(NeuralNetwork Main)
    {
        // Initialise randomiser
        TheRandomiser = new System.Random(Main.TheRandomiser.Next());

        // Set topology
        TheTopology = Main.TheTopology;

        Sections = new NeuralSection[TheTopology.Count - 1];

        // Initialise Sections
        for (int i = 0; i < Sections.Length; i++)
        {
            Sections[i] = new NeuralSection(Main.Sections[i]);
        }
    }
        /// <summary>
        /// Initiates an independent Deep-Copy of the Neural Network provided.
        /// </summary>
        /// <param name="Main">The Neural Network that should be cloned.</param>
        public NeuralNetwork(NeuralNetwork Main)
        {
            // Init Random
            TheRandomizer = new Random(Main.TheRandomizer.Next());

            // Set Topology
            TheTopology = Main.TheTopology;

            // Initialize Sections
            Sections = new NeuralSection[TheTopology.Count - 1];

            // Set the Sections
            for (int i = 0; i < Sections.Length; i++)
            {
                Sections[i] = new NeuralSection(Main.Sections[i]);
            }
        }
예제 #6
0
        public NeuralSection(NeuralSection main)
        {
            _weights = new double[main._weights.Length][];

            for (int i = 0; i < _weights.Length; i++)
            {
                _weights[i] = new double[main._weights[0].Length];
            }

            for (int i = 0; i < _weights.Length; i++)
            {
                for (int j = 0; j < _weights[i].Length; j++)
                {
                    _weights[i][j] = main._weights[i][j];
                }
            }
        }
예제 #7
0
 public void Crossover(NeuralSection other)
 {
     if (_weights.Length != other._weights.Length || _weights[0].Length != other._weights[0].Length)
     {
         throw new ArgumentException("Neural Sections must be of equal size");
     }
     for (int i = 0; i < _weights.Length; i++)
     {
         for (int j = 0; j < _weights[i].Length; j++)
         {
             if (UnityEngine.Random.value < 0.5f)
             {
                 _weights[i][j] = other._weights[i][j];
             }
         }
     }
 }
예제 #8
0
    /// <summary>
    /// Initiates a NeuralNetwork from a Topology and a Seed.
    /// </summary>
    /// <param name="Topology">The Topology of the Neural Network.</param>
    /// <param name="Seed">The Seed of the Neural Network.
    /// Set to 'null' to use a Timed Seed.</param>
    public NeuralNetwork(UInt32[] Topology, Int32?Seed = 0)
    {
        // Validation Checks
        if (Topology.Length < 2)
        {
            throw new ArgumentException
                      ("A Neural Network cannot contain less than 2 Layers.", "Topology");
        }

        for (int i = 0; i < Topology.Length; i++)
        {
            if (Topology[i] < 1)
            {
                throw new ArgumentException
                          ("A single layer of neurons must contain, at least, one neuron.", "Topology");
            }
        }

        // Initialize Randomizer
        if (Seed.HasValue)
        {
            TheRandomizer = new Random(Seed.Value);
        }
        else
        {
            TheRandomizer = new Random();
        }

        // Set Topology
        TheTopology = new List <uint>(Topology).AsReadOnly();

        // Initialize Sections
        Sections = new NeuralSection[TheTopology.Count - 1];

        // Set the Sections
        for (int i = 0; i < Sections.Length; i++)
        {
            Sections[i] = new NeuralSection(TheTopology[i], TheTopology[i + 1], TheRandomizer);
        }
    }
예제 #9
0
            /// <summary>
            /// Initiates an independent Deep-Copy of the NeuralSection provided.
            /// </summary>
            /// <param name="Main"></param>
            public NeuralSection(NeuralSection Main)
            {
                //Set Randomizer
                TheRandomizer = Main.TheRandomizer;

                // Initialize Weights
                Weights = new double[Main.Weights.Length][];

                for (int i = 0; i < Weights.Length; i++)
                {
                    Weights[i] = new double[Main.Weights[0].Length];
                }

                // Set Weights
                for (int i = 0; i < Weights.Length; i++)
                {
                    for (int j = 0; j < Weights[i].Length; j++)
                    {
                        Weights[i][j] = Main.Weights[i][j];
                    }
                }
            }