예제 #1
0
        // -------------------------------------------------------------------------------------------------------
        /// <summary>
        /// Creates a new ANN with the specified configuration class
        /// </summary>
        /// <param name="config"></param>
        public AdaptiveNeuralNetwork(NetDescription config)
        {
            this.totalFields           = config.featuresSizes.Length;
            this.vigilancesRaising     = config.adaptiveVigilanceRaising;
            this.fuzzyReadout          = config.fuzzyReadout;
            this.activeFields          = config.activeFields;
            this.featuresSizes         = config.featuresSizes;
            this.temperatureOp         = config.temperatureOp;
            this.learningOp            = config.learningOp;
            this.fieldsClass           = config.fieldsClass;
            this.learningRate          = config.learningRate;
            this.learnVigilances       = config.learningVigilances;
            this.performVigilances     = config.performingVigilances;
            this.gammas                = config.gammas;
            this.alphas                = config.alphas;
            this.adaptiveVigilanceRate = config.adaptiveVigilanceRate;

            activity = new double[totalFields][];
            for (int field = 0; field < totalFields; field++)
            {
                activity[field] = new double[featuresSizes[field]];
            }

            inputFields = new double[totalFields][];
            for (int field = 0; field < totalFields; field++)
            {
                inputFields[field] = new double[featuresSizes[field]];
            }

            predictionFields = new double[totalFields][];
            for (int field = 0; field < totalFields; field++)
            {
                predictionFields[field] = new double[featuresSizes[field]];
            }

            activitySum = new double[totalFields];

            neuronsConfidence = new List <double>();
            neurons           = new List <double[][]>();

            createNeuron();
        }
예제 #2
0
파일: TestBed.cs 프로젝트: Ophien/TCAI
        public void example1_oneField()
        {
            Console.WriteLine("***************************************************************");
            Console.WriteLine("******* TEST 1 - THE ONE FIELD ANN ****************************");
            Console.WriteLine("***************************************************************\n");

            // ---------------------------------------------------------------------
            // ------------ Creating a configuration file --------------------------
            // ---------------------------------------------------------------------
            NetDescription description = new NetDescription();

            // ---------------------------------------------------------------------
            // ------------ Configuring an one field Adaptive Neural Network -------
            // ---------------------------------------------------------------------
            description.activeFields             = new bool[] { true };       // defines which fields are active to perform the categorization
            description.adaptiveVigilanceRaising = new bool[] { true };       // defines which fields will be affected by the adaptive vigilance
            description.fuzzyReadout             = false;                     // defines if the prediction will be performed by the fuzzy ARTI readout

            description.featuresSizes         = new int[] { 4 };              // defines the fields configuration, their size and quantity
            description.alphas                = new double[] { 0.1 };         // defines each field alpha
            description.gammas                = new double[] { 0.5 };         // defines each field gamma
            description.learningRate          = new double[] { 1.0 };         // defines the learning rate for each field
            description.learningVigilances    = new double[] { 1.0 };         // defines the vigilance used for learning for each field
            description.performingVigilances  = new double[] { 0.0 };         // defines the vigilance used to perform predictions for each field
            description.adaptiveVigilanceRate = 0.001;                        // defines how much the vigilance will be added when predicting

            description.fieldsClass   = new int[] { FieldTypes.STATE };       // defines each field type
            description.learningOp    = new int[] { NeuronLearning.ART_I };   // defines which composite operation will be used by the network when learning
            description.temperatureOp = new int[] { NeuronActivation.ART_I }; // defines which composite operation will be used by the network when performing

            // ---------------------------------------------------------------------
            // ---------- Creating the Adaptive Neural Network ---------------------
            // ---------------------------------------------------------------------
            AdaptiveNeuralNetwork network = new AdaptiveNeuralNetwork(description); // creates the network

            network.printNetStructure();
            network.printNetworkParameters();
            network.setDebug(true);

            // ---------------------------------------------------------------------
            // --- Performing learning operations to learn the observed activity ---
            // ---------------------------------------------------------------------

            // Received external stimulus, what the agent is seeing
            double[] externalStimulus = new double[4];
            externalStimulus[0] = 0.3;
            externalStimulus[1] = 0.3;
            externalStimulus[2] = 0.7;
            externalStimulus[3] = 0.1;

            // The field that will receive the observed stimulus
            int fieldToWrite = 0;

            // Inserting the observation into the network's activity vectors
            network.setInputField(fieldToWrite, externalStimulus);

            // Variable that tells to the network if it needs to learn the observed stimulus
            bool learn = true;

            // Performing a learning operation
            network.prediction(learn);

            // Received external stimulus, what the agent is seeing
            externalStimulus[0] = 0.1;
            externalStimulus[1] = 0.3;
            externalStimulus[2] = 0.5;
            externalStimulus[3] = 0.6;

            // Inserting the observation into the network's activity vectors
            network.setInputField(fieldToWrite, externalStimulus);

            // Variable that tells to the network if it needs to learn the observed stimulus
            learn = true;

            // Performing a learning operation
            network.prediction(learn);

            // ---------------------------------------------------------------------
            // --- Performing a prediction operation to read a neuron cluster ------
            // ---------------------------------------------------------------------

            // Received external stimulus, what the agent is seeing
            externalStimulus[0] = 0.1;
            externalStimulus[1] = 0.3;
            externalStimulus[2] = 0.4;
            externalStimulus[3] = 0.6;

            // The field that will receive the observed stimulus
            fieldToWrite = 0;

            // Inserting the observation into the network's activity vectors
            network.setInputField(fieldToWrite, externalStimulus);

            // Variable that tells to the network if it needs to learn the observed stimulus
            learn = false;

            // Performing a learning operation
            network.prediction(learn);

            // ---------------------------------------------------------------------
            // --- Reading a prediction for the field 0 ----------------------------
            // ---------------------------------------------------------------------

            // The field in which the read operation will be performed
            int fieldToRead = 0;

            // The array that will receive the prediction
            double[] prediction = new double[4];

            // Performing the reading operation
            prediction = network.readPrediction(fieldToRead);

            // ---------------------------------------------------------------------
            // --- Printing the observed prediction --------------------------------
            // ---------------------------------------------------------------------

            // Pause
            Console.Write("Press ENTER to continue...");
            Console.ReadLine();
            Console.WriteLine();
        }
예제 #3
0
파일: TestBed.cs 프로젝트: Ophien/TCAI
        public void example2_threeFields()
        {
            Console.WriteLine("***************************************************************");
            Console.WriteLine("******* TEST 2 - THE THREE FIELDS ANN (FALCON) ****************");
            Console.WriteLine("***************************************************************\n");

            // ---------------------------------------------------------------------
            // ------------ Creating a configuration file --------------------------
            // ---------------------------------------------------------------------
            NetDescription description = new NetDescription();

            // ---------------------------------------------------------------------
            // ------------ Configuring an one field Adaptive Neural Network -------
            // ---------------------------------------------------------------------
            description.activeFields             = new bool[] { true, true, false };                                           // defines which fields are active to perform the categorization
            description.adaptiveVigilanceRaising = new bool[] { true, false, false };                                          // defines which fields will be affected by the adaptive vigilance
            description.fuzzyReadout             = true;                                                                       // defines if the prediction will be performed by the fuzzy ARTI readout

            description.featuresSizes         = new int[] { 4, 4, 2 };                                                         // defines the fields configuration, their size and quantity
            description.alphas                = new double[] { 0.1, 0.1, 0.1 };                                                // defines each field alpha
            description.gammas                = new double[] { 0.5, 0.5, 0.0 };                                                // defines each field gamma
            description.learningRate          = new double[] { 1.0, 1.0, 1.0 };                                                // defines the learning rate for each field
            description.learningVigilances    = new double[] { 1.0, 1.0, 1.0 };                                                // defines the vigilance used for learning for each field
            description.performingVigilances  = new double[] { 0.0, 0.0, 0.0 };                                                // defines the vigilance used to perform predictions for each field
            description.adaptiveVigilanceRate = 0.001;                                                                         // defines how much the vigilance will be added when predicting

            description.fieldsClass   = new int[] { FieldTypes.STATE, FieldTypes.ACTION, FieldTypes.REWARD };                  // defines each field type
            description.learningOp    = new int[] { NeuronLearning.ART_I, NeuronLearning.ART_I, NeuronLearning.ART_II };       // defines which composite operation will be used by the network when learning
            description.temperatureOp = new int[] { NeuronActivation.ART_I, NeuronActivation.ART_I, NeuronActivation.ART_II }; // defines which composite operation will be used by the network when performing

            // ---------------------------------------------------------------------
            // ---------- Creating the Adaptive Neural Network ---------------------
            // ---------------------------------------------------------------------
            AdaptiveNeuralNetwork network = new AdaptiveNeuralNetwork(description); // creates the network

            network.printNetStructure();
            network.printNetworkParameters();
            network.setDebug(true);

            // ---------------------------------------------------------------------
            // --- Performing learning operations to learn the observed activity ---
            // ---------------------------------------------------------------------

            // Received external stimulus, what the agent is seeing
            double[] externalStimulusA = new double[2];
            double[] externalStimulusB = new double[2];
            double[] externalStimulusC = new double[1];

            // Define half of the input stimulus, since complement coding will be used for this test
            externalStimulusA[0] = 0.3;
            externalStimulusA[1] = 0.2;

            // Define half of the input stimulus, since complement coding will be used for this test
            externalStimulusB[0] = 0.1;
            externalStimulusB[1] = 0.9;

            // Define half of the input stimulus, since complement coding will be used for this test
            externalStimulusC[0] = 1.0;

            // The field that will receive the observed stimulus
            int fieldToWriteA = 0;
            int fieldToWriteB = 1;
            int fieldToWriteC = 2;

            // Inserting the observation into the network's activity vectors
            network.setInputField(fieldToWriteA, externalStimulusA, ComplementCodingType.MIRRORED);
            network.setInputField(fieldToWriteB, externalStimulusB, ComplementCodingType.MIRRORED);
            network.setInputField(fieldToWriteC, externalStimulusC, ComplementCodingType.MIRRORED);

            // Variable that tells to the network if it needs to learn the observed stimulus
            bool learn = true;

            // Performing a learning operation
            network.prediction(learn);

            // Define half of the input stimulus, since complement coding will be used for this test
            externalStimulusA[0] = 0.1;
            externalStimulusA[1] = 0.6;

            // Define half of the input stimulus, since complement coding will be used for this test
            externalStimulusB[0] = 0.2;
            externalStimulusB[1] = 0.1;

            // Define half of the input stimulus, since complement coding will be used for this test
            externalStimulusC[0] = 0.45;

            // The field that will receive the observed stimulus
            fieldToWriteA = 0;
            fieldToWriteB = 1;
            fieldToWriteC = 2;

            // Inserting the observation into the network's activity vectors
            network.setInputField(fieldToWriteA, externalStimulusA, ComplementCodingType.MIRRORED);
            network.setInputField(fieldToWriteB, externalStimulusB, ComplementCodingType.MIRRORED);
            network.setInputField(fieldToWriteC, externalStimulusC, ComplementCodingType.MIRRORED);

            // Variable that tells to the network if it needs to learn the observed stimulus
            learn = true;

            // Performing a learning operation
            network.prediction(learn);

            // ---------------------------------------------------------------------
            // --- Performing a prediction operation to read a neuron cluster ------
            // ---------------------------------------------------------------------

            // Define half of the input stimulus, since complement coding will be used for this test
            externalStimulusA[0] = 0.3;
            externalStimulusA[1] = 0.2;

            // Define half of the input stimulus, since complement coding will be used for this test
            externalStimulusB[0] = 1.0;
            externalStimulusB[1] = 1.0;

            // Define half of the input stimulus, since complement coding will be used for this test
            externalStimulusC[0] = 1.0;

            // The field that will receive the observed stimulus
            fieldToWriteA = 0;
            fieldToWriteB = 1;
            fieldToWriteC = 2;

            // Inserting the observation into the network's activity vectors
            network.setInputField(fieldToWriteA, externalStimulusA, ComplementCodingType.MIRRORED);
            network.setInputField(fieldToWriteB, externalStimulusB, ComplementCodingType.DIRECT_ACCESS);
            network.setInputField(fieldToWriteC, externalStimulusC, ComplementCodingType.DIRECT_ACCESS);

            // Variable that tells to the network if it needs to learn the observed stimulus
            learn = false;

            // Performing a learning operation
            network.prediction(learn);

            // ---------------------------------------------------------------------
            // --- Reading a prediction for the field 1 ----------------------------
            // ---------------------------------------------------------------------

            // The field in which the read operation will be performed for the ACTION field 1
            int fieldToRead = 1;

            // The array that will receive the prediction
            double[] prediction = new double[4];

            // Performing the reading operation
            prediction = network.readPrediction(fieldToRead);

            // ---------------------------------------------------------------------
            // --- Printing the observed prediction --------------------------------
            // ---------------------------------------------------------------------

            // Pause
            Console.Write("Press ENTER to continue...");
            Console.ReadLine();
            Console.WriteLine();
        }