Beispiel #1
0
        public Network(Network n)
        {
            this.actionList = new List<IAction>();
            foreach(IAction ac in n.actionList){
                if (ac.GetType() == typeof(Layer))
                {
                    Layer acLayer = (Layer)ac;
                    Layer aux = new Layer(acLayer);
                    this.actionList.Add(aux);

                    if (acLayer == n.input)
                    {
                        this.input = aux;

                    }
                    else if (acLayer == n.output)
                    {

                        this.output = aux;
                    }
                }
                else
                {
                    this.actionList.Add(ac);
                }

            }
        }
Beispiel #2
0
        /// <summary>
        /// Gets the number of the connection
        /// </summary>
        /// <param name="n1">Number of neurons of the input layer</param>
        /// <param name="n2">Number of neurons of the output layer</param>
        public Connections(int n1, int n2)
        {
            this.n1 = n1;
            this.n2 = n2;

            this.weights = new double[n2,n1];
            this.source = null;
            this.dest = null;
        }
Beispiel #3
0
        /// <summary>
        /// Gets two layers and generate the all_to_all weigth matrix
        /// </summary>
        /// <param name="input">The source layer</param>
        /// <param name="output">The otuput layer</param>
        public Connections(Layer input, Layer output)
        {
            // Una neurona más por el bias
            this.n1 = input.nNeurons+1;
            this.n2 = output.nNeurons;

            this.weights = new double[n2, n1];
            this.source = input;
            this.dest = output;
        }
Beispiel #4
0
 public Layer(Layer L)
 {
     this.nNeurons = L.nNeurons;
     weights = new double[L.nNeurons];
     act_func = L.act_func;
 }
Beispiel #5
0
        public static Network fromDescription(string description)
        {
            Network network = new Network();

            string[] desc = description.Split();

            int idx = 0;
            Layer ant = null;

            while (idx < desc.Length)
            {
                int nNeurons = Int32.Parse(desc[idx++]);
                string sAct = desc[idx++];
                ActivationFunction fAct = Layer.stringToActivation(sAct);

                if (ant == null)
                {
                    network.input = new Layer(nNeurons, fAct);
                    ant = network.input;
                    continue;
                }

                Layer newLayer = new Layer(nNeurons, fAct);

                Connections newConnection = new Connections(ant, newLayer);
                network.actionList.Add(newConnection);

                network.actionList.Add(newLayer);

                ant = newLayer;

            }

            network.output = ant;
            return network;
        }
Beispiel #6
0
 //public List<Connections> connections;
 /// <summary>
 /// Creates a empty network
 /// </summary>
 public Network()
 {
     actionList = new List<IAction>();
     input = output = null;
 }
Beispiel #7
0
        /// <summary>
        /// Parser of the lua format
        /// </summary>
        /// <param name="reader">Correctly open stream file reader</param>
        public void readfromFile(StreamReader reader)
        {
            /* return {
               "256 inputs 1024 tanh 10 softmax",
               matrix.fromString[[273418
                ascii
            */
            string line;

            //Avoid comments and lua lines
            do
            {
                line = reader.ReadLine().Trim();

            } while (line.StartsWith("#") || line.StartsWith("return"));

            string description = line;

            description = description.Replace("\"", "");

            string[] camps = description.Split();
            int ncamps = camps.Length;
            // Read the Network info
            // Nneurons0 tipe0 .. NneuronsN tipeN

            Layer ant = null;

            //Avoid lua code
            do
            {

                line = reader.ReadLine().Trim();

            } while (line.StartsWith("#") || line.StartsWith("matrix"));

            for (int i = 0; i < ncamps; i+=2) {
                int nNeurons = int.Parse(camps[i]);
                string type = camps[i + 1];

                if (ant == null)
                {
                    // Is the first layer
                    this.input = addLayer(nNeurons, Layer.stringToActivation(type));
                    ant = this.input;
                    continue;
                }

                Layer newLayer = new Layer(nNeurons, Layer.stringToActivation(type));

                Connections newConnection = new Connections(ant, newLayer);
                this.actionList.Add(newConnection);

                this.actionList.Add(newLayer);

                newConnection.readWeightsfromStream(reader);

                ant = newLayer;

                //Console.WriteLine(newConnection.ToString());

            }

            if (ant != null) this.output = ant;
        }
Beispiel #8
0
        /// <summary>
        /// Add a layer with a given input neurons
        /// </summary>
        /// <param name="nNeurons">Number of neurons of the function</param>
        /// <param name="activate">Activation Function</param>
        /// <returns></returns>
        public Layer addLayer(int nNeurons, ActivationFunction activate)
        {
            Layer layer = new Layer(nNeurons, activate);

            actionList.Add(layer);

            return layer;
        }
Beispiel #9
0
        /// <summary>
        /// Add a layer from a determined vector
        /// </summary>
        /// <param name="v">Vector with the values of the layer</param>
        /// <param name="activate">The activation function</param>
        /// <returns></returns>
        public Layer addLayer(double[] v, ActivationFunction activate)
        {
            Layer layer = new Layer(v, activate);

            actionList.Add(layer);

            return layer;
        }