Example #1
0
        private double ComputeVigilance(double[] input, double[] category)
        {
            double vigilance = FuzzyLogicUtil.Norm(FuzzyLogicUtil.Intersect(input, category, 2 * inputSize))
                               / FuzzyLogicUtil.Norm(input);

            return(vigilance);
        }
Example #2
0
        public void AdjustWeight()
        {
            Neuron winnerNeuron = F2.Neurons(winningNeuronPos);

            double[] intersect = FuzzyLogicUtil.
                                 Intersect(InputData, winnerNeuron.Weights.ToArray(), InputSize);
            // Modify new art a weight.
            for (int i = 0; i < this.InputSize; ++i)
            {
                winnerNeuron.Weights[i] = (Beta * intersect[i]) + ((1 - Beta) * winnerNeuron.Weights[i]);
            }
        }
Example #3
0
 private double[] ComputeChoicingValues(double[] input, double[][] categories,
                                        int numberOfCategories, double choicingParam)
 {
     double[] choicingValues = new double[numberOfCategories];
     for (int i = 0; i < numberOfCategories; ++i)
     {
         choicingValues[i] =
             FuzzyLogicUtil.Norm(FuzzyLogicUtil.Intersect(input, categories[i], 2 * inputSize)) /
             (choicingParam + FuzzyLogicUtil.Norm(categories[i]));
     }
     return(choicingValues);
 }
Example #4
0
        private void Process()
        {
            bool isSuccess = false;

            while (!isSuccess)
            {
                int    max = FuzzyLogicUtil.FindMax(ChoiceValues.ToArray());
                double normOfSimilarity = 0;

                if (max != -1)
                {
                    normOfSimilarity = F2.Neurons(max).Output();
                }
                else
                {
                    // Indicate that there is no eligible neuron
                    // as winner, so create a dummy neuron in F2 layer.
                    max = F2.AddNeuron(FuzzyLogicUtil.MakeDummyNeuron(InputSize));
                    ChoiceValues.Add(
                        FuzzyLogicUtil.ChoicingValue(normOfInputs, 1.0 * InputSize, Choice));
                    normOfSimilarity = normOfInputs;
                }

                // Calculate and compare with vigilance
                winningVigilance = normOfSimilarity / normOfInputs;
                if (winningVigilance >= Vigilance)
                {
                    winningNeuronPos = max;
                    isSuccess        = true;
                }
                else
                {
                    ChoiceValues[max] = 0;
                }
            }

            // Adjust neuron weight automatically. if it is set.
            if (AutoAdjustWeight)
            {
                AdjustWeight();
            }

            // Calculate output.
            output = FuzzyLogicUtil.Intersect(F2.Neurons(WinningNeuronPos).Weights.ToArray(),
                                              InputData, InputSize);
        }
Example #5
0
        public void Run(double[] data)
        {
            input = data;
            // Compute norm of input values.
            normOfInputs = FuzzyLogicUtil.Norm(data);

            // Transfer input values.
            f1.Input(data);

            // Calculate initial choicing value
            ChoiceValues.Clear();
            for (int i = 0; i < f2.Count; ++i)
            {
                double normOfWeight = FuzzyLogicUtil.Norm(F2.Neurons(i).Weights.ToArray());
                ChoiceValues.Add(FuzzyLogicUtil.ChoicingValue(F2.Neurons(i).Output(), normOfWeight, Choice));
            }

            Process();
        }
Example #6
0
        private void Process()
        {
            bool isSuccess = false;

            while (!isSuccess)
            {
                // Select target weight
                int winnerNeuronIndex = ArtA.WinningNeuronPos;

                Neuron weightNeuron = null;
                if (winnerNeuronIndex >= Map.Count)
                {
                    // Create new weight neuron in mapfield.
                    weightNeuron = Map.Neurons(
                        Map.AddNeuron(FuzzyLogicUtil.MakeDummyNeuron(ArtB.InputSize)));
                }
                else
                {
                    weightNeuron = Map.Neurons(winnerNeuronIndex);
                }

                if (training)
                {
                    // Check vigilance condition
                    double[] artBValues = artB.Output;
                    weightNeuron.Input(artBValues);
                    double normOfSimilarity = weightNeuron.Output();
                    double testVigilance    = normOfSimilarity / FuzzyLogicUtil.Norm(artBValues);
                    if (testVigilance >= Vigilance)
                    {
                        output = FuzzyLogicUtil.Intersect(weightNeuron.Weights.ToArray(), artBValues, ArtB.InputSize);

                        // Modify new mapfield weight.
                        for (int i = 0; i < weightNeuron.Weights.Count; ++i)
                        {
                            weightNeuron.Weights[i] = (Beta * output[i]) + ((1 - Beta) * weightNeuron.Weights[i]);
                        }

                        // Call ArtA to adjust its winner neuron weight.
                        bool isWeightAdjusted = false;
                        if (FastCommitedSlowLearningOption)
                        {
                            if (IsUnCommited(ArtA.F2.Neurons(ArtA.WinningNeuronPos)))
                            {
                                double beta = ArtA.Beta;
                                ArtA.Beta = 1.0;
                                artA.AdjustWeight();
                                ArtA.Beta        = beta;
                                isWeightAdjusted = true;
                            }
                        }
                        if (!isWeightAdjusted)
                        {
                            ArtA.AdjustWeight();
                        }

                        // Call ArtB to adjust its winner neuron weight.
                        ArtB.AdjustWeight();

                        isSuccess = true;
                    }
                    else
                    {
                        double newVigilance = ArtA.WinningVigilance + ArtA.Choice;
                        ArtA.Vigilance = newVigilance > 1 ? 1.0 : newVigilance;
                        ArtA.Reset(winnerNeuronIndex);
                    }
                }
                else
                {
                    output    = weightNeuron.Weights.ToArray();
                    isSuccess = true;
                }
            }
            training = false;
        }