コード例 #1
0
ファイル: ReadData.cs プロジェクト: weizh/NTM-1
 public static ReadData[] GetVector(int x, Func<int, Tuple<HeadSetting, NTMMemory>> paramGetters)
 {
     ReadData[] vector = new ReadData[x];
     for (int i = 0; i < x; i++)
     {
         Tuple<HeadSetting, NTMMemory> parameters = paramGetters(i);
         vector[i] = new ReadData(parameters.Item1, parameters.Item2);
     }
     return vector;
 }
コード例 #2
0
ファイル: HiddenLayer.cs プロジェクト: weizh/NTM-1
        public void BackwardErrorPropagation(double[] input, ReadData[] reads)
        {
            double[] hiddenLayerGradients = CalculateHiddenLayerGradinets();

            UpdateReadDataGradient(hiddenLayerGradients, reads);

            UpdateInputToHiddenWeightsGradients(hiddenLayerGradients, input);

            UpdateHiddenLayerThresholdsGradients(hiddenLayerGradients);
        }
コード例 #3
0
ファイル: ReadData.cs プロジェクト: zaharPonimash/NTM
 public static ReadData[] GetVector(int x, Func <int, Tuple <HeadSetting, NTMMemory> > paramGetters)
 {
     ReadData[] vector = new ReadData[x];
     for (int i = 0; i < x; i++)
     {
         Tuple <HeadSetting, NTMMemory> parameters = paramGetters(i);
         vector[i] = new ReadData(parameters.Item1, parameters.Item2);
     }
     return(vector);
 }
コード例 #4
0
ファイル: HiddenLayer.cs プロジェクト: weizh/NTM-1
        //TODO refactor - do not use tempsum - but beware of rounding issues
        public void ForwardPropagation(double[] input, ReadData[] readData)
        {
            //Foreach neuron in hidden layer
            for (int neuronIndex = 0; neuronIndex < _controllerSize; neuronIndex++)
            {
                double sum = 0;
                sum = GetReadDataContributionToHiddenLayer(neuronIndex, readData, sum);
                sum = GetInputContributionToHiddenLayer(neuronIndex, input, sum);
                sum = GetThresholdContributionToHiddenLayer(neuronIndex, sum);

                //Set new controller unit value
                HiddenLayerNeurons[neuronIndex].Value = _activationFunction.Value(sum);
            }
        }
コード例 #5
0
ファイル: HiddenLayer.cs プロジェクト: weizh/NTM-1
        private void UpdateReadDataGradient(double[] hiddenLayerGradients, ReadData[] reads)
        {
            for (int neuronIndex = 0; neuronIndex < _controllerSize; neuronIndex++)
            {
                Unit[][] neuronToReadDataWeights = _readDataToHiddenLayerWeights[neuronIndex];
                double hiddenLayerGradient = hiddenLayerGradients[neuronIndex];

                for (int headIndex = 0; headIndex < _headCount; headIndex++)
                {
                    ReadData readData = reads[headIndex];
                    Unit[] neuronToHeadReadDataWeights = neuronToReadDataWeights[headIndex];
                    for (int memoryCellIndex = 0; memoryCellIndex < _memoryUnitSizeM; memoryCellIndex++)
                    {
                        readData.ReadVector[memoryCellIndex].Gradient += hiddenLayerGradient * neuronToHeadReadDataWeights[memoryCellIndex].Value;

                        neuronToHeadReadDataWeights[memoryCellIndex].Gradient += hiddenLayerGradient * readData.ReadVector[memoryCellIndex].Value;
                    }
                }
            }
        }
コード例 #6
0
ファイル: HiddenLayer.cs プロジェクト: weizh/NTM-1
        private double GetReadDataContributionToHiddenLayer(int neuronIndex, ReadData[] readData, double tempSum)
        {
            Unit[][] readWeightsForEachHead = _readDataToHiddenLayerWeights[neuronIndex];
            for (int headIndex = 0; headIndex < _headCount; headIndex++)
            {
                Unit[] headWeights = readWeightsForEachHead[headIndex];
                ReadData read = readData[headIndex];

                for (int memoryCellIndex = 0; memoryCellIndex < _memoryUnitSizeM; memoryCellIndex++)
                {
                    tempSum += headWeights[memoryCellIndex].Value * read.ReadVector[memoryCellIndex].Value;
                }
            }
            return tempSum;
        }
コード例 #7
0
ファイル: FeedForwardController.cs プロジェクト: weizh/NTM-1
 public void Process(double[] input, ReadData[] readDatas)
 {
     HiddenLayer.ForwardPropagation(input, readDatas);
     OutputLayer.ForwardPropagation(HiddenLayer);
 }
コード例 #8
0
ファイル: FeedForwardController.cs プロジェクト: weizh/NTM-1
 public void BackwardErrorPropagation(double[] knownOutput, double[] input, ReadData[] reads)
 {
     OutputLayer.BackwardErrorPropagation(knownOutput, HiddenLayer);
     HiddenLayer.BackwardErrorPropagation(input, reads);
 }
コード例 #9
0
ファイル: MemoryState.cs プロジェクト: weizh/NTM-1
        internal MemoryState Process(Head[] heads)
        {
            int headCount = heads.Length;
            int memoryColumnsN = _memory.CellCountN;

            ReadData[] newReadDatas = new ReadData[headCount];
            HeadSetting[] newHeadSettings = new HeadSetting[headCount];
            for (int i = 0; i < headCount; i++)
            {
                Head head = heads[i];
                BetaSimilarity[] similarities = new BetaSimilarity[_memory.CellCountN];

                for (int j = 0; j < memoryColumnsN; j++)
                {
                    Unit[] memoryColumn = _memory.Data[j];
                    SimilarityMeasure similarity = new SimilarityMeasure(new CosineSimilarityFunction(), head.KeyVector, memoryColumn);
                    similarities[j] = new BetaSimilarity(head.Beta, similarity);
                }

                ContentAddressing ca = new ContentAddressing(similarities);
                GatedAddressing ga = new GatedAddressing(head.Gate, ca, _headSettings[i]);
                ShiftedAddressing sa = new ShiftedAddressing(head.Shift, ga);

                newHeadSettings[i] = new HeadSetting(head.Gamma, sa);
                newReadDatas[i] = new ReadData(newHeadSettings[i], _memory);
            }

            NTMMemory newMemory = new NTMMemory(newHeadSettings, heads, _memory);

            return new MemoryState(newMemory, newHeadSettings, newReadDatas);
        }
コード例 #10
0
ファイル: MemoryState.cs プロジェクト: weizh/NTM-1
 internal MemoryState(NTMMemory memory, HeadSetting[] headSettings, ReadData[] readDatas)
 {
     _memory = memory;
     _headSettings = headSettings;
     ReadData = readDatas;
 }