Esempio n. 1
0
        public void addHidden(int a)
        {
            layer hidden  = new layer();
            node  NewNode = new node();
            int   flag    = 0;

            //number of nodes in each layer
            for (int i = 0; i < numberOfNodes[a]; i++)
            {
                NewNode.Layernum = a + 1;
                NewNode.Nodenum  = i;
                //A loop for all inputs &weights
                for (int j = 0; j < tree[a].nodes.Count; j++)
                {
                    if (a == 0)
                    {
                        NewNode.inputs.Add(tree[a].nodes[j].value);
                    }
                    //generating weights
                    if (tree.Count < numberOfHiddenLayers + 2)
                    {
                        RandomNumber = (float)rand2.NextDouble();
                        NewNode.weights.Add(RandomNumber);
                        RandomNumber = 0;
                    }
                    else
                    {
                        //get weights from old tree
                        flag = 1;
                    }
                }
                if (flag == 1)
                {
                    for (int q = 0; q < tree[a + 1].nodes[i].weights.Count; q++)
                    {
                        NewNode.weights.Add(tree[a + 1].nodes[i].weights[q]);
                    }
                    flag = 0;
                }
                hidden.nodes.Add(NewNode);
                NewNode = new node();
            }
            hidden.Layernum = a + 1;
            if (tree.Count < numberOfHiddenLayers + 2)
            {
                tree.Add(hidden);
                treeBest.Add(hidden);
            }
            else
            {
                try
                {
                    tree[a + 1] = hidden;
                }
                catch (Exception er)
                {
                }
            }
        }
Esempio n. 2
0
        void initialize_nodes(int len1)
        {
            layer ly = new layer();

            for (int i = 0; i < len1; i++)
            {
                node nd = new node();
                ly.nl.Add(nd);
            }
            nk.ly.Add(ly);
        }
Esempio n. 3
0
        public void splitBySpace(string x)
        {
            layer input = new layer();

            node NewNode = new node();

            string[] allInputs = new string[7];
            allInputs = x.Split(' ');

            for (int j = 0; j < 6; j++)
            {
                NewNode.value = float.Parse(allInputs[j]);

                NewNode.Layernum = 0;
                NewNode.Nodenum  = j;
                input.nodes.Add(NewNode);
                NewNode = new node();
            }
            input.Layernum = 0;

            //makes sure here it's tree[0]=input after first time
            if (tree.Count <= 0)
            {
                tree.Add(input);
                treeBest.Add(input);
            }
            else
            {
                tree[0] = input;
            }
            desired = allInputs[6];
            if (desired == "DH")
            {
                desired1 = 0; desired2 = 0;
            }
            else if (desired == "SL")
            {
                desired1 = 0; desired2 = 1;
            }
            else if (desired == "NO")
            {
                desired1 = 1; desired2 = 0;
            }
        }
Esempio n. 4
0
        void initialize_weights(int len1, int len2, int n1)
        {
            Random r  = new Random();
            layer  ly = new layer();

            for (int i = 0; i < len2; i++)                 // i = dest
            {
                for (int k = 0; k < len1; k++)             // k = scr
                {
                    weight w = new weight();
                    w.val   = 0;//r.NextDouble();
                    w.lscr  = n1;
                    w.ldest = n1 + 1;
                    w.nscr  = k;
                    w.ndest = i;
                    nk.ly[n1 + 1].nl[i].w.Add(w);
                }
            }
        }
Esempio n. 5
0
        public void addOutput()
        {
            layer output  = new layer();
            node  NewNode = new node();
            int   flag2   = 0;

            //number of nodes in each layer
            for (int i = 0; i < 2; i++)
            {
                NewNode.Layernum = numberOfHiddenLayers + 1;
                NewNode.Nodenum  = i;
                //A loop for all inputs &weights
                try
                {
                    for (int j = 0; j < tree[NewNode.Layernum - 1].nodes.Count; j++)
                    {
                        //generating weights
                        if (tree.Count < numberOfHiddenLayers + 2)
                        {
                            RandomNumber = (float)rand2.NextDouble();
                            NewNode.weights.Add(RandomNumber);
                            RandomNumber = 0;
                        }
                        else
                        {
                            flag2 = 1;
                        }
                    }
                    if (flag2 == 1)
                    {
                        for (int q = 0; q < tree[numberOfHiddenLayers + 1].nodes[i].weights.Count; q++)
                        {
                            NewNode.weights.Add(tree[numberOfHiddenLayers + 1].nodes[i].weights[q]);
                        }
                        flag2 = 0;
                    }
                    output.nodes.Add(NewNode);
                    NewNode = new node();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception: " + e.Message);
                }
            }
            output.Layernum = numberOfHiddenLayers + 1;
            if (tree.Count < numberOfHiddenLayers + 2)
            {
                tree.Add(output);
                treeBest.Add(output);
            }
            else
            {
                try
                {
                    tree[numberOfHiddenLayers + 1] = output;
                }
                catch (Exception er)
                {
                }
            }
        }