예제 #1
0
 /// <summary>
 /// This <see cref="SparseBinaryMatrix"/> will contain the operation of or-ing the inputMatrix with the contents of this matrix; returning this matrix as the result.
 /// </summary>
 /// <param name="inputMatrix">the matrix containing the "on" bits to or</param>
 /// <returns>this matrix</returns>
 public AbstractSparseBinaryMatrix Or(AbstractSparseBinaryMatrix inputMatrix)
 {
     int[] mask = inputMatrix.GetSparseIndices();
     int[] ones = new int[mask.Length];
     ArrayUtils.Fill(ones, 1);
     return(set(mask, ones));
 }
예제 #2
0
        /// <summary>
        /// Returns true if the on bits of the specified matrix are matched by the on bits of this matrix. It is allowed that this matrix have more on bits than the specified matrix.
        /// </summary>
        /// <param name="matrix"></param>
        /// <returns></returns>
        public bool All(AbstractSparseBinaryMatrix matrix)
        {
            var  sparseSet = GetSparseSet();
            bool hasAll    = matrix.GetSparseIndices().All(itm2 => sparseSet.Contains(itm2));

            return(hasAll);
            //return getSparseSet().Contains(
            //    containsAll(matrix.getSparseIndices());
        }
예제 #3
0
        /// <summary>
        /// Returns true if any of the on bits of the specified matrix are matched by the on bits of this matrix. It is allowed that this matrix have more on bits than the specified matrix.
        /// </summary>
        /// <param name="matrix"></param>
        /// <returns></returns>
        public bool Any(AbstractSparseBinaryMatrix matrix)
        {
            var keySet = GetSparseSet();

            foreach (int i in matrix.GetSparseIndices())
            {
                if (keySet.Contains(i))
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #4
0
        /// <summary>
        /// Sets the permanences for each {@link Synapse} specified by the indexes passed in which identify the input vector indexes associated with the
        /// <see cref="Synapse"/>. The permanences passed in are understood to be in "sparse" format and therefore require the int array identify their
        /// corresponding indexes.
        /// </summary>
        /// <param name="connectedCounts"></param>
        /// <param name="htmConfig"></param>
        /// <param name="perms">the floating point degree of connectedness</param>
        /// <param name="inputIndexes"></param>
        /// <remarks>
        /// Note: This is the "sparse" version of this method.
        /// </remarks>
        public void SetPermanences(AbstractSparseBinaryMatrix connectedCounts, HtmConfig htmConfig, double[] perms, int[] inputIndexes)
        {
            var permConnThreshold = htmConfig.SynPermConnected;

            RFPool.ResetConnections();
            // c.getConnectedCounts().clearStatistics(ParentColumnIndex);
            connectedCounts.ClearStatistics(0 /*this.ParentColumnIndex*/);
            for (int i = 0; i < inputIndexes.Length; i++)
            {
                var synapse = RFPool.GetSynapseForInput(inputIndexes[i]);
                synapse.Permanence = perms[i];

                if (perms[i] >= permConnThreshold)
                {
                    connectedCounts.set(1, 0 /*ParentColumnIndex*/, i);
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Creates a new collumn with specified number of cells and a single proximal dendtrite segment.
        /// </summary>
        /// <param name="numCells">Number of cells in the column.</param>
        /// <param name="colIndx">Column index.</param>
        /// <param name="synapsePermConnected">Permanence threshold value to declare synapse as connected.</param>
        /// <param name="numInputs">Number of input neorn cells.</param>
        public Column(int numCells, int colIndx, double synapsePermConnected, int numInputs)
        {
            this.Index = colIndx;

            this.hashcode = GetHashCode();

            Cells = new Cell[numCells];

            for (int i = 0; i < numCells; i++)
            {
                Cells[i] = new Cell(this.Index, i, this.GetNumCellsPerColumn(), this.CellId, CellActivity.ActiveCell);
            }

            // We keep tracking of this column only
            this.connectedInputCounter = new SparseBinaryMatrix(new int[] { 1, numInputs });

            ProximalDendrite = new ProximalDendrite(colIndx, synapsePermConnected, numInputs);

            this.ConnectedInputCounterMatrix = new SparseBinaryMatrix(new int[] { 1, numInputs });
        }
예제 #6
0
        public bool Equals(AbstractSparseBinaryMatrix obj)
        {
            if (this == obj)
            {
                return(true);
            }
            if (!base.Equals(obj))
            {
                return(false);
            }
            if ((obj.GetType() != this.GetType()))
            {
                return(false);
            }

            AbstractSparseBinaryMatrix other = (AbstractSparseBinaryMatrix)obj;

            if (other.trueCounts != null && trueCounts != null)
            {
                if (!other.trueCounts.SequenceEqual(trueCounts))
                {
                    return(false);
                }
            }

            if (ModuleTopology == null)
            {
                if (obj.ModuleTopology != null)
                {
                    return(false);
                }
            }
            else if (!ModuleTopology.Equals(obj.ModuleTopology))
            {
                return(false);
            }

            return(true);
        }
        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            if (!base.Equals(obj))
            {
                return(false);
            }
            if ((obj.GetType() != this.GetType()))
            {
                return(false);
            }
            AbstractSparseBinaryMatrix other = (AbstractSparseBinaryMatrix)obj;

            if (!Array.Equals(trueCounts, other.trueCounts))
            {
                return(false);
            }
            return(true);
        }