Exemple #1
0
 internal static BetaSimilarity[] GetVector(int x)
 {
     BetaSimilarity[] vector = new BetaSimilarity[x];
     for (int i = 0; i < x; i++)
     {
         vector[i] = new BetaSimilarity();
     }
     return vector;
 }
Exemple #2
0
 internal static BetaSimilarity[][] GetTensor2(int x, int y)
 {
     BetaSimilarity[][] tensor = new BetaSimilarity[x][];
     for (int i = 0; i < x; i++)
     {
         tensor[i] = GetVector(y);
     }
     return tensor;
 }
Exemple #3
0
 internal static BetaSimilarity[] GetVector(int x)
 {
     BetaSimilarity[] vector = new BetaSimilarity[x];
     for (int i = 0; i < x; i++)
     {
         vector[i] = new BetaSimilarity();
     }
     return(vector);
 }
Exemple #4
0
 internal static BetaSimilarity[][] GetTensor2(int x, int y)
 {
     BetaSimilarity[][] tensor = new BetaSimilarity[x][];
     for (int i = 0; i < x; i++)
     {
         tensor[i] = GetVector(y);
     }
     return(tensor);
 }
Exemple #5
0
        //Implementation of focusing by content (Page 8, Unit 3.3.1 Focusing by Content)
        internal ContentAddressing(BetaSimilarity[] betaSimilarities)
        {
            BetaSimilarities = betaSimilarities;
            ContentVector = UnitFactory.GetVector(betaSimilarities.Length);

            //Subtracting max increase numerical stability
            double max = BetaSimilarities.Max(similarity => similarity.BetaSimilarityMeasure.Value);
            double sum = 0;

            for (int i = 0; i < BetaSimilarities.Length; i++)
            {
                BetaSimilarity unit = BetaSimilarities[i];
                double weight = Math.Exp(unit.BetaSimilarityMeasure.Value - max);
                ContentVector[i].Value = weight;
                sum += weight;
            }

            foreach (Unit unit in ContentVector)
            {
                unit.Value = unit.Value/sum;
            }
        }
        //Implementation of focusing by content (Page 8, Unit 3.3.1 Focusing by Content)
        internal ContentAddressing(BetaSimilarity[] betaSimilarities)
        {
            BetaSimilarities = betaSimilarities;
            ContentVector    = UnitFactory.GetVector(betaSimilarities.Length);

            //Subtracting max increase numerical stability
            double max = BetaSimilarities.Max(similarity => similarity.BetaSimilarityMeasure.Value);
            double sum = 0;

            for (int i = 0; i < BetaSimilarities.Length; i++)
            {
                BetaSimilarity unit   = BetaSimilarities[i];
                double         weight = Math.Exp(unit.BetaSimilarityMeasure.Value - max);
                ContentVector[i].Value = weight;
                sum += weight;
            }

            foreach (Unit unit in ContentVector)
            {
                unit.Value = unit.Value / sum;
            }
        }
Exemple #7
0
        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);
        }