Ejemplo n.º 1
0
        public MLP(int[] counts, int input)
        {
            mlp = new List<List<INeuron>>();

            //bemeneti reteg
            List<INeuron> inputlayer = new List<INeuron>();
            for (int i = 0; i < input; ++i)
            {
                InputNeuron n = new InputNeuron();
                inputlayer.Add(n);
            }
            mlp.Add(inputlayer);

            //rejtett retegek
            int layernum = 0;
            foreach (int count in counts)
            {
                List<INeuron> layer = new List<INeuron>();
                for (int i = 0; i < count; ++i)
                {
                    Neuron n = new Neuron((layernum < counts.Length - 1));
                    //elozo reteg osszes neuronja bemenet
                    foreach (INeuron n2 in mlp[mlp.Count-1])
                    {
                        n.AddInputNeuron(n2);
                    }
                    layer.Add(n);
                }
                mlp.Add(layer);
                layernum++;
            }
        }
Ejemplo n.º 2
0
        public MLP(MLP copyInstance)
        {
            mlp = new List<List<INeuron>>();
            List<INeuron> inputlayer = new List<INeuron>();
            for (int i = 0; i < copyInstance.mlp[0].Count; ++i)
            {
                InputNeuron n = new InputNeuron();
                inputlayer.Add(n);                
            }
            mlp.Add(inputlayer);

            int layernum = 0;
            for (int i = 1; i < copyInstance.mlp.Count; ++i)
            {
                List<INeuron> layer = new List<INeuron>();
                for (int i2 = 0; i2 < copyInstance.mlp[i].Count; ++i2)
                {
                    Neuron n = new Neuron(((Neuron)copyInstance.mlp[i][i2]).nonlinear);
                    layer.Add(n);
                    //elozo reteg osszes neuronja bemenet
                    foreach (INeuron n2 in mlp[i - 1])
                    {
                        n.AddInputNeuron(n2);                        
                    }                    
                    //sulyok atmasolasa
                    int i3=0;
                    foreach (NeuronInput ni in n.inputs)
                    {
                        ni.w = ((Neuron)copyInstance.mlp[i][i2]).inputs[i3].w;
                        ++i3;
                    }                    
                }
                mlp.Add(layer);
                layernum++;
            }
        }
Ejemplo n.º 3
0
 public void LoadNN(string filename)
 {
     TextReader tr = new StreamReader(filename);
     string line = tr.ReadLine();
     List<INeuron> layer = null;
     Neuron n = null;
     int ni_counter = 0;
     while (line != "E")
     {
         if (line == "M") mlp = new List<List<INeuron>>();
         if (line == "L")
         {
             layer = new List<INeuron>();
             mlp.Add(layer);
         }
         if (line == "I") layer.Add(new InputNeuron());
         if ((line == "Pn")||(line == "P"))
         {
             n = new Neuron(true);
             ni_counter = 0;
             layer.Add(n);
         }
         if (line == "Pl")
         {
             n = new Neuron(false);
             ni_counter = 0;
             layer.Add(n);
         }
         if (line == "b")
         {
             string w = tr.ReadLine();
             n.inputs[0].w = double.Parse(w, CultureInfo.InvariantCulture);                    
         }
         if (line == "w")
         {
             string w = tr.ReadLine();
             NeuronInput ni = new NeuronInput();
             ni.w = double.Parse(w, CultureInfo.InvariantCulture);
             ni.n = mlp[mlp.Count - 2][ni_counter];                    
             n.inputs.Add(ni);
             ni_counter++;                        
         }
         line = tr.ReadLine();
     }
     tr.Close();
 }
Ejemplo n.º 4
0
 public void AddNeuron(int layer)
 {
     Neuron n = new Neuron(true);
     foreach (INeuron n2 in mlp[layer - 1])
     {
         n.AddInputNeuron(n2);
     }
     mlp[layer].Add(n);
     foreach (INeuron n2 in mlp[layer + 1])
     {
         ((Neuron)n2).AddInputNeuron(n);
     }
 }