示例#1
0
        public void InterConnectionWeightRenewal(double learningRate, double decayRate)
        {
            InterConnectionMatrix += LayerActivationMatrix.Transpose() * LayerErrorMatrix * learningRate;
            Parallel.For(0, InterConnectionMatrix.RowCount, index =>
            {
                InterConnectionMatrix[index, index] = 0;
            });
            if (decayRate > 0)
            {
                Parallel.For(0, InterConnectionMatrix.RowCount, rowIndex =>
                {
                    for (int columnIndex = 0; columnIndex < InterConnectionMatrix.ColumnCount; columnIndex++)
                    {
                        if (InterConnectionMatrix[rowIndex, columnIndex] > 0)
                        {
                            InterConnectionMatrix[rowIndex, columnIndex] -= decayRate;
                        }
                        else if (InterConnectionMatrix[rowIndex, columnIndex] < 0)
                        {
                            InterConnectionMatrix[rowIndex, columnIndex] += decayRate;
                        }
                    }
                });

                InterConnectionMatrix.CoerceZero(decayRate);
            }
        }
示例#2
0
 public virtual void Duplicate(Layer cloneLayer)
 {
     cloneLayer.LayerStroageMatrix    = LayerStroageMatrix.Clone();
     cloneLayer.LayerActivationMatrix = LayerActivationMatrix.Clone();
     cloneLayer.LayerErrorMatrix      = LayerErrorMatrix.Clone();
     cloneLayer.BiasMatrix            = BiasMatrix.Clone();
     cloneLayer.InterConnectionMatrix = InterConnectionMatrix.Clone();
 }
示例#3
0
        public void CleanUpBackwordProcess(double momentum, double learningRate, double decayRate)
        {
            CleanupLayerErrorMatrix = (LayerErrorMatrix * CleanupToLayerWeightMatrix.Transpose())
                                      .PointwiseMultiply(CleanupLayerActivationMatrix.PointwiseMultiply(1 - CleanupLayerActivationMatrix));

            CleanupBiasMatrix += CleanupLayerErrorMatrix.ColumnSums().ToRowMatrix() * learningRate;

            CleanupToLayerWeightMatrix += CleanupLayerActivationMatrix.Transpose() * LayerErrorMatrix * learningRate;
            LayerToCleanupWeightMatrix += LayerActivationMatrix.Transpose() * CleanupLayerErrorMatrix * learningRate;

            if (decayRate > 0)
            {
                Parallel.For(0, CleanupBiasMatrix.ColumnCount, columnIndex =>
                {
                    if (CleanupBiasMatrix[0, columnIndex] > 0)
                    {
                        CleanupBiasMatrix[0, columnIndex] -= decayRate;
                    }
                    else if (CleanupBiasMatrix[0, columnIndex] < 0)
                    {
                        CleanupBiasMatrix[0, columnIndex] += decayRate;
                    }
                });
                CleanupBiasMatrix.CoerceZero(decayRate);

                Parallel.For(0, CleanupToLayerWeightMatrix.RowCount, rowIndex =>
                {
                    for (int columnIndex = 0; columnIndex < CleanupToLayerWeightMatrix.ColumnCount; columnIndex++)
                    {
                        if (CleanupToLayerWeightMatrix[rowIndex, columnIndex] > 0)
                        {
                            CleanupToLayerWeightMatrix[rowIndex, columnIndex] -= decayRate;
                        }
                        else if (CleanupToLayerWeightMatrix[rowIndex, columnIndex] < 0)
                        {
                            CleanupToLayerWeightMatrix[rowIndex, columnIndex] += decayRate;
                        }
                    }
                });
                CleanupToLayerWeightMatrix.CoerceZero(decayRate);

                Parallel.For(0, LayerToCleanupWeightMatrix.RowCount, rowIndex =>
                {
                    for (int columnIndex = 0; columnIndex < LayerToCleanupWeightMatrix.ColumnCount; columnIndex++)
                    {
                        if (LayerToCleanupWeightMatrix[rowIndex, columnIndex] > 0)
                        {
                            LayerToCleanupWeightMatrix[rowIndex, columnIndex] -= decayRate;
                        }
                        else if (LayerToCleanupWeightMatrix[rowIndex, columnIndex] < 0)
                        {
                            LayerToCleanupWeightMatrix[rowIndex, columnIndex] += decayRate;
                        }
                    }
                });
                LayerToCleanupWeightMatrix.CoerceZero(decayRate);
            }
        }
示例#4
0
        public void Test(Matrix <double> targetPattern, double activationCriterion, double inactivationCriterion, out List <double> meanSEList, out List <double> meanSSList, out List <double> meanCEList, out List <bool> correctnessList, out List <double> meanActivationList, out List <double> meanAUActivationList, out List <double> meanIUActivationList)
        {
            meanSEList         = ((targetPattern - LayerActivationMatrix).PointwisePower(2).RowSums() / 2.0 / UnitCount).ToList();
            meanSSList         = ((((LayerActivationMatrix.PointwiseMultiply(LayerActivationMatrix.PointwiseLog()) + ((1 - LayerActivationMatrix).PointwiseMultiply((1 - LayerActivationMatrix).PointwiseLog()))) / Math.Log(2)) + 1).RowSums() / UnitCount).ToList();
            meanCEList         = (((targetPattern.PointwiseMultiply(LayerActivationMatrix.PointwiseLog()) + (1 - targetPattern).PointwiseMultiply((1 - LayerActivationMatrix).PointwiseLog())) / Math.Log(Math.E)).RowSums() * -1 / UnitCount).ToList();
            meanActivationList = (LayerActivationMatrix.RowSums() / UnitCount).ToList();

            correctnessList      = new List <bool>(LayerActivationMatrix.RowCount);
            meanAUActivationList = new List <double>(LayerActivationMatrix.RowCount);
            meanIUActivationList = new List <double>(LayerActivationMatrix.RowCount);
            for (int index = 0; index < LayerActivationMatrix.RowCount; index++)
            {
                correctnessList.Add(true);
                meanAUActivationList.Add(0);
                meanIUActivationList.Add(0);
            }

            Matrix <double> activeUnitMatrix   = DenseMatrix.Create(LayerActivationMatrix.RowCount, LayerActivationMatrix.ColumnCount, 0);
            Matrix <double> inactiveUnitMatrix = DenseMatrix.Create(LayerActivationMatrix.RowCount, LayerActivationMatrix.ColumnCount, 0);
            Matrix <double> countActive        = DenseMatrix.Create(LayerActivationMatrix.RowCount, 1, 0);
            Matrix <double> countInactive      = DenseMatrix.Create(LayerActivationMatrix.RowCount, 1, 0);

            for (int rowIndex = 0; rowIndex < LayerActivationMatrix.RowCount; rowIndex++)
            {
                for (int columnIndex = 0; columnIndex < LayerActivationMatrix.ColumnCount; columnIndex++)
                {
                    if (targetPattern[rowIndex, columnIndex] > activationCriterion)
                    {
                        if (LayerActivationMatrix[rowIndex, columnIndex] < activationCriterion)
                        {
                            correctnessList[rowIndex] = false;
                        }
                        activeUnitMatrix[rowIndex, columnIndex] = 1;
                        countActive[rowIndex, 0]++;
                    }
                    if (targetPattern[rowIndex, columnIndex] < inactivationCriterion)
                    {
                        if (LayerActivationMatrix[rowIndex, columnIndex] > activationCriterion)
                        {
                            correctnessList[rowIndex] = false;
                        }
                        inactiveUnitMatrix[rowIndex, columnIndex] = 1;
                        countInactive[rowIndex, 0]++;
                    }
                }
            }
            meanAUActivationList = LayerActivationMatrix.PointwiseMultiply(activeUnitMatrix).RowSums().ToList();
            meanIUActivationList = LayerActivationMatrix.PointwiseMultiply(inactiveUnitMatrix).RowSums().ToList();
            for (int rowIndex = 0; rowIndex < LayerActivationMatrix.RowCount; rowIndex++)
            {
                if (countActive[rowIndex, 0] > 0)
                {
                    meanAUActivationList[rowIndex] = meanAUActivationList[rowIndex] / countActive[rowIndex, 0];
                }
                else
                {
                    meanAUActivationList[rowIndex] = double.NaN;
                }
                if (countInactive[rowIndex, 0] > 0)
                {
                    meanIUActivationList[rowIndex] = meanIUActivationList[rowIndex] / countInactive[rowIndex, 0];
                }
                else
                {
                    meanIUActivationList[rowIndex] = double.NaN;
                }
            }
        }