예제 #1
0
        public Result Compress(int[,] imgArray)
        {
            int    totalFrames      = (imgArray.GetLength(0) * imgArray.GetLength(1)) / (FrameSize * FrameSize);
            int    numOfFramesInrow = imgArray.GetLength(0) / FrameSize;
            int    counter          = 0;
            Result result           = new Result(totalFrames);

            result.FrameSize = FrameSize;
            for (int i = 0; i < numOfFramesInrow; i++)
            {
                for (int j = 0; j < numOfFramesInrow; j++)
                {
                    int[]    frameBeginning    = { FrameSize *i, FrameSize *j };
                    int[]    frame             = FrameHelper.GetFrame(frameBeginning, imgArray, FrameSize);
                    double   squareOfVectorSum = FrameHelper.CountSquareOfVectorSum(frame);
                    double[] normalizedFrame   = FrameHelper.Normalize(frame, squareOfVectorSum);
                    int      bestNeuronIndex   = FindBestNeuron(normalizedFrame);
                    result.NeuronIndexes[counter] = bestNeuronIndex;
                    result.Lenghts[counter]       = squareOfVectorSum;
                    counter++;
                }
            }
            if (counter != totalFrames)
            {
                throw new Exception("Counter must be equal to total frames");
            }
            for (int i = 0; i < Neurons.Length; i++)
            {
                result.IndexToWeights.Add(i, Neurons[i].Weights);
            }
            return(result);
        }
예제 #2
0
 public void Train(int numberOfEpochs, int[,] imgArray)
 {
     for (int i = 0; i < numberOfEpochs; i++)
     {
         int[]    frameBeginning  = FrameHelper.SelectRandomFrameBeginning(imgArray.GetLength(0), FrameSize, random);
         int[]    frame           = FrameHelper.GetFrame(frameBeginning, imgArray, FrameSize);
         double[] normalizedFrame = FrameHelper.Normalize(frame, FrameHelper.CountSquareOfVectorSum(frame));
         Train(normalizedFrame);
     }
 }
예제 #3
0
        private double[] NormalizeWeights(double[] weights)
        {
            double[] normalizedWeights = new double[weights.Length];
            double   squareOfVectorSum = FrameHelper.CountSquareOfVectorSum(weights);

            for (int i = 0; i < weights.Length; i++)
            {
                if (squareOfVectorSum == 0)
                {
                    normalizedWeights[i] = 0;
                }
                else
                {
                    normalizedWeights[i] = weights[i] / squareOfVectorSum;
                }
            }
            return(normalizedWeights);
        }