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; }
public void BackwardErrorPropagation(double[] input, ReadData[] reads) { double[] hiddenLayerGradients = CalculateHiddenLayerGradinets(); UpdateReadDataGradient(hiddenLayerGradients, reads); UpdateInputToHiddenWeightsGradients(hiddenLayerGradients, input); UpdateHiddenLayerThresholdsGradients(hiddenLayerGradients); }
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); }
//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); } }
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; } } } }
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; }
public void Process(double[] input, ReadData[] readDatas) { HiddenLayer.ForwardPropagation(input, readDatas); OutputLayer.ForwardPropagation(HiddenLayer); }
public void BackwardErrorPropagation(double[] knownOutput, double[] input, ReadData[] reads) { OutputLayer.BackwardErrorPropagation(knownOutput, HiddenLayer); HiddenLayer.BackwardErrorPropagation(input, reads); }
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); }
internal MemoryState(NTMMemory memory, HeadSetting[] headSettings, ReadData[] readDatas) { _memory = memory; _headSettings = headSettings; ReadData = readDatas; }