Esempio n. 1
0
        /**
         * Convenience method to compute a metric over an indices trace, excluding
         * resets.
         *
         * @param trace     Trace of indices
         * @return
         */
        public virtual Metric <int> mmGetMetricFromTrace(IndicesTrace trace)
        {
            List <HashSet <int> > data          = null;
            BoolsTrace            excludeResets = mmGetTraceResets();

            if (excludeResets != null)
            {
                int[] i = { 0 };
                data = trace.items.Where(t => !excludeResets.items[i[0]++]).ToList();
            }

            trace.items = data;
            CountsTrace iTrace = trace.makeCountsTrace();

            return(Metric <int> .createFromTrace(iTrace, mmGetTraceResets()));
        }
Esempio n. 2
0
        public virtual void mmComputeTransitionTraces()
        {
            if (!transitionTracesStale())
            {
                return;
            }

            Map <string, HashSet <int> > predActCells = (Map <string, HashSet <int> >)getDataMap().Get("predictedActiveCellsForSequence");

            if (predActCells == null)
            {
                getDataMap().Add("predictedActiveCellsForSequence", predActCells = new Map <string, HashSet <int> >());
            }

            getTraceMap().Add("predictedActiveCells", new IndicesTrace(this, "predicted => active cells (correct)"));
            getTraceMap().Add("predictedInactiveCells", new IndicesTrace(this, "predicted => inactive cells (extra)"));
            getTraceMap().Add("predictedActiveColumns", new IndicesTrace(this, "predicted => active columns (correct)"));
            getTraceMap().Add("predictedInactiveColumns", new IndicesTrace(this, "predicted => inactive columns (extra)"));
            getTraceMap().Add("unpredictedActiveColumns", new IndicesTrace(this, "unpredicted => active columns (bursting)"));

            IndicesTrace predictedCellsTrace = (IndicesTrace)getTraceMap().Get("predictedCells");

            int           i = 0;
            HashSet <int> predictedActiveColumns = null;

            foreach (HashSet <int> activeColumns in mmGetTraceActiveColumns().items)
            {
                HashSet <int> predictedActiveCells   = new HashSet <int>();
                HashSet <int> predictedInactiveCells = new HashSet <int>();
                predictedActiveColumns = new HashSet <int>();
                HashSet <int> predictedInactiveColumns = new HashSet <int>();

                foreach (int predictedCell in predictedCellsTrace.items[i])
                {
                    int predictedColumn = getConnections().GetCell(predictedCell).GetColumn().GetIndex();

                    if (activeColumns.Contains(predictedColumn))
                    {
                        predictedActiveCells.Add(predictedCell);
                        predictedActiveColumns.Add(predictedColumn);

                        string sequenceLabel = (string)mmGetTraceSequenceLabels().items[i];
                        if (sequenceLabel != null && !string.IsNullOrWhiteSpace(sequenceLabel))
                        {
                            HashSet <int> sequencePredictedCells = null;
                            if ((sequencePredictedCells = (HashSet <int>)predActCells.Get(sequenceLabel)) == null)
                            {
                                ((Map <string, HashSet <int> >)predActCells).Add(
                                    sequenceLabel, sequencePredictedCells = new HashSet <int>());
                            }

                            sequencePredictedCells.Add(predictedCell);
                        }
                    }
                    else
                    {
                        predictedInactiveCells.Add(predictedCell);
                        predictedInactiveColumns.Add(predictedColumn);
                    }
                }

                HashSet <int> unpredictedActiveColumns = new HashSet <int>(activeColumns);
                unpredictedActiveColumns.ExceptWith(predictedActiveColumns);

                ((IndicesTrace)getTraceMap().Get("predictedActiveCells")).items.Add(predictedActiveCells);
                ((IndicesTrace)getTraceMap().Get("predictedInactiveCells")).items.Add(predictedInactiveCells);
                ((IndicesTrace)getTraceMap().Get("predictedActiveColumns")).items.Add(predictedActiveColumns);
                ((IndicesTrace)getTraceMap().Get("predictedInactiveColumns")).items.Add(predictedInactiveColumns);
                ((IndicesTrace)getTraceMap().Get("unpredictedActiveColumns")).items.Add(unpredictedActiveColumns);

                i++;
            }

            setTransitionTracesStale(false);
        }