Exemplo n.º 1
0
        void step()
        {
            //-----------------
            //Fixate somewhere
            int startX = rnd.Next(0, world.Width - retinaSize);
            int startY = rnd.Next(0, world.Height - retinaSize);

            //-----------------
            //Get the perceptive information
            //2-Vision
            for (int i = 0; i < retinaSize; i++)
            {
                for (int j = 0; j < retinaSize; j++)
                {
                    Cell   startPx = world.cells[startX + i, startY + j];
                    Signal signal  = LEC_Color[i, j];
                    for (int compo = 0; compo < 4; compo++)
                    {
                        signal.reality[compo, 0] = startPx.colorCode[compo];
                    }
                }
            }

            //-----------------
            //Run a cycle on CA3
            CA3.Converge();
            CA3.Diverge();
        }
Exemplo n.º 2
0
        void step(StreamWriter logFile, int steps, int worldCnt)
        {
            //-----------------
            //Fixate somewhere
            int startX = rnd.Next(0, world.Width - retinaSize);
            int startY = rnd.Next(0, world.Height - retinaSize);

            //-----------------
            //Saccade
            int endX = -1; int dX = 0;
            int endY = -1; int dY = 0;

            while (endX < 0 || endY < 0 || endX >= world.Width - retinaSize || endY >= world.Width - retinaSize)
            {
                dX   = rnd.Next(-saccadeSize, saccadeSize + 1);
                dY   = rnd.Next(-saccadeSize, saccadeSize + 1);
                endX = startX + dX;
                endY = startY + dY;
            }

            //-----------------
            //Get the perceptive information
            //1-Proprioception
            //dX dY
            //Right = 0 1 0 0
            //Left  = 1 0 0 0
            //Up    = 0 0 0 1
            //Down  = 0 0 1 0
            if (dX == -saccadeSize)
            {
                MEC.reality[0, 0] = 1;
                MEC.reality[1, 0] = 0;
            }
            else if (dX == saccadeSize)
            {
                MEC.reality[0, 0] = 0;
                MEC.reality[1, 0] = 1;
            }
            else
            {
                MEC.reality[0, 0] = 0;
                MEC.reality[1, 0] = 0;
            }


            if (dY == -saccadeSize)
            {
                MEC.reality[2, 0] = 1;
                MEC.reality[3, 0] = 0;
            }
            else if (dY == saccadeSize)
            {
                MEC.reality[2, 0] = 0;
                MEC.reality[3, 0] = 1;
            }
            else
            {
                MEC.reality[2, 0] = 0;
                MEC.reality[3, 0] = 0;
            }

            //2-Vision
            for (int i = 0; i < retinaSize; i++)
            {
                for (int j = 0; j < retinaSize; j++)
                {
                    Cell startPx = world.cells[startX + i, startY + j];
                    Cell endPx   = world.cells[endX + i, endY + j];

                    for (int compo = 0; compo < 4; compo++)
                    {
                        LEC_ColorT0.reality[i * 4 + compo, j] = startPx.colorCode[compo];
                        LEC_ColorT1.reality[i * 4 + compo, j] = endPx.colorCode[compo];
                    }
                }
            }

            //-----------------
            //Run a cycle on CA3
            CA3.Converge();
            CA3.Diverge();
            log(logFile, steps, !CA3.learningLocked, worldCnt);
        }
Exemplo n.º 3
0
        public void learnAndLog()
        {
            Random rnd = new Random();

            if (checkBoxPretrainMotor.Checked)
            {
                //We train only the motor map
                foreach (Signal s in CA3.modalities)
                {
                    if (s != MEC)
                    {
                        CA3.modalitiesInfluence[s] = 0.0;
                    }
                }

                //Pretrain the motor modality
                int pretrainSteps = 1000;
                progressBarCurrentOp.Value   = 0;
                progressBarCurrentOp.Minimum = 0;
                progressBarCurrentOp.Maximum = pretrainSteps;
                progressBarCurrentOp.Step    = 1;

                for (int i = 0; i < pretrainSteps; i++)
                {
                    Array.Clear(MEC.reality, 0, MEC.reality.Length);
                    MEC.reality[rnd.Next(0, world.Width), 0]  = 1.0;
                    MEC.reality[rnd.Next(0, world.Height), 0] = 1.0;
                    CA3.Converge();
                    CA3.Diverge();
                    progressBarCurrentOp.PerformStep();
                }

                //Put all influences back to 1
                foreach (Signal s in CA3.modalities)
                {
                    CA3.modalitiesInfluence[s] = 1.0;
                }
            }

            //Explore the world
            StreamWriter logFile = new StreamWriter("errorLog.csv");

            //logFile.WriteLine("t,realColor0,realColor1,realColor2,realColor3,realOrientation, predColor0,predColor1,predColor2,predColor3, predOrientation,orientation->color0,orientation->color1,orientation->color2,orientation->color3, color->orientation, Ecolor,Eorientation");
            logHeadings(logFile);
            //int explorationSteps = 1000;
            //for (int step = 0; step < explorationSteps; step++)
            int steps = 0;

            while (steps < trainSteps /*&& mainLoopThread.IsAlive*/)
            {
                //-----------------
                //Saccade somewhere
                int nextX = rnd.Next(0, world.Width - retinaSize);
                int nextY = rnd.Next(0, world.Height - retinaSize);
                drawFixationPoint(nextX, nextY);

                //-----------------
                //Get the perceptive information
                //1-Proprioception
                Array.Clear(MEC.reality, 0, MEC.reality.Length);
                MEC.reality[nextX, 0] = 1.0;
                MEC.reality[world.Width + nextY, 0] = 1.0;

                //2-Vision
                for (int i = 0; i < retinaSize; i++)
                {
                    for (int j = 0; j < retinaSize; j++)
                    {
                        Cell px = world.cells[nextX + i, nextY + j];

                        for (int compo = 0; compo < 4; compo++)
                        {
                            LEC_Color.reality[i * 4 + compo, j] = px.colorCode[compo];
                        }

                        //Other features
                        //LEC_Orientation.reality[retinaSize / 2 + i, retinaSize / 2 + j] = Math.Abs(px.orientation % 180.0) / 180.0;
                        double[] orientationCode = px.orientationCode;
                        LEC_Orientation.reality[i * 2 + 0, j] = orientationCode[0];
                        LEC_Orientation.reality[i * 2 + 1, j] = orientationCode[1];

                        LEC_Shape.reality[i, j] = px.shape / (double)shapeCount; //  !!! This encoding is bad because it defines intrinsic shape distance
                    }
                }

                //-----------------
                //Run a cycle on CA3
                CA3.Converge();
                CA3.Diverge();

                //TO REMOVE
                if (CA3 is MMNodeMWSOM)
                {
                    (CA3 as MMNodeMWSOM).HandleEpoch(steps, trainSteps, null, 0);
                }

                log(logFile, steps);
                if (checkBoxEgosphere.Checked)
                {
                    predictEgosphere();
                    //MessageBox.Show("top");
                }
                steps++;
            }


            //-------------------------------------------------------------------------------------------------------------------
            //Test Phase
            //1--Make sure we do not modify the network
            //if (CA3 is MMNodeLookupTable)
            //{
            //    (CA3 as MMNodeLookupTable).allowTemplateCreation = false;
            //    (CA3 as MMNodeLookupTable).learningRate = 0.0;
            //}
            //if (CA3 is MMNodeSOM)
            //{
            //    (CA3 as MMNodeSOM).learningRate = 0.0;
            //}
            CA3.learningLocked = true;

            //2-- Use a never encountered equidistant color (i.e (0 0 0 0) )
            for (int i = 0; i < retinaSize; i++)
            {
                for (int j = 0; j < retinaSize; j++)
                {
                    for (int compo = 0; compo < 4; compo++)
                    {
                        LEC_Color.reality[i * 4 + compo, j] = 0.0;
                    }
                }
            }

            //Test with different orientations
            for (double orientation = 0; orientation <= 1.0; orientation += 0.025)
            {
                for (int i = 0; i < retinaSize; i++)
                {
                    for (int j = 0; j < retinaSize; j++)
                    {
                        double[] orientationCode = Cell.getOrientationCode(orientation * 180.0);
                        LEC_Orientation.reality[i * 2 + 0, j] = orientationCode[0];
                        LEC_Orientation.reality[i * 2 + 1, j] = orientationCode[1];
                    }
                }

                CA3.Converge();
                CA3.Diverge();
                log(logFile, -1);
            }

            predictEgosphere();

            MessageBox.Show("Testing done.");
            //-------------------------------------------------------------------------------------------------------------------

            logFile.Close();
        }