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 HeadSetting(Unit gamma, ShiftedAddressing shiftedVector) { _gamma = gamma; ShiftedVector = shiftedVector; _shiftedVector = ShiftedVector.ShiftedVector; _cellCount = _shiftedVector.Length; AddressingVector = UnitFactory.GetVector(_cellCount); //NO CLUE IN PAPER HOW TO IMPLEMENT - ONLY RESTRICTION IS THAT IT HAS TO BE LARGER THAN 1 //(Page 9, Part 3.3.2. Focusing by location) _gammaIndex = Math.Log(Math.Exp(gamma.Value) + 1) + 1; double sum = 0; for (int i = 0; i < _cellCount; i++) { Unit unit = AddressingVector[i]; unit.Value = Math.Pow(_shiftedVector[i].Value, _gammaIndex); sum += unit.Value; } foreach (Unit unit in AddressingVector) { unit.Value = unit.Value / sum; if (double.IsNaN(unit.Value)) { throw new Exception("Should not be NaN - Error"); } } }