예제 #1
0
        private void calculateOverlap(CalculateOverlapMsg msg)
        {
            Console.WriteLine($"{Self.Path} - Received message: '{msg.GetType().Name}'");

            ConcurrentDictionary <int, int> overlaps = new ConcurrentDictionary <int, int>();

            ParallelOptions opts = new ParallelOptions();

            opts.MaxDegreeOfParallelism = Environment.ProcessorCount;

            Parallel.ForEach(this.dict, opts, (keyPair) =>
            {
                Column col = keyPair.Value as Column;

                var overlap = col.GetColumnOverlapp(msg.InputVector, this.config.StimulusThreshold);

                overlaps.TryAdd((int)keyPair.Key, overlap);
            });

            List <KeyPair> result = new List <KeyPair>();

            foreach (var item in overlaps)
            {
                result.Add(new KeyPair {
                    Key = item.Key, Value = item.Value
                });
            }

            var sortedRes = result.OrderBy(k => k.Key).ToList();

            //Console.Write($"o = {sortedRes.Count(p => (int)p.Value > 0)}");

            Sender.Tell(sortedRes, Self);
        }
예제 #2
0
        private List <KeyPair> CalculateOverlap(CalculateOverlapMsg msg)
        {
            Console.WriteLine($"Received message: '{msg.GetType().Name}'");

            ConcurrentDictionary <int, int> overlaps = new ConcurrentDictionary <int, int>();

            ParallelOptions opts = new ParallelOptions
            {
                MaxDegreeOfParallelism = Environment.ProcessorCount
            };

            Parallel.ForEach(this.Dict, opts, (keyPair) =>
            {
                Column col = keyPair.Value as Column;

                var overlap = col.CalcMiniColumnOverlap(msg.InputVector, this.HtmConfig.StimulusThreshold);

                overlaps.TryAdd(keyPair.Key is string?int.Parse(keyPair.Key as string) : (int)keyPair.Key, overlap);
            });

            List <KeyPair> result = new List <KeyPair>();

            foreach (var item in overlaps)
            {
                result.Add(new KeyPair {
                    Key = item.Key, Value = item.Value
                });
            }

            var sortedRes = result.OrderBy(k => k.Key).ToList();

            //Console.Write($"o = {sortedRes.Count(p => (int)p.Value > 0)}");
            if (sortedRes.Count < this.Dict.Count)
            {
            }

            return(sortedRes);
        }