/// <summary> /// This method updates the permanence matrix with a column's new permanence values. The column is identified by its index, which reflects the row in /// the matrix, and the permanence is given in 'sparse' form, (i.e. an array whose members are associated with specific indexes). It is in charge of /// implementing 'clipping' - ensuring that the permanence values are always between 0 and 1 - and 'trimming' - enforcing sparseness by zeroing out all /// permanence values below 'synPermTrimThreshold'. Every method wishing to modify the permanence matrix should do so through this method. /// </summary> /// <param name="htmConfig"></param> /// <param name="perm">An array of permanence values for a column. The array is "sparse", i.e. it contains an entry for each input bit, even if the permanence value is 0.</param> /// <param name="maskPotential">Indexes of potential connections to input neurons.</param> /// <param name="raisePerm">a boolean value indicating whether the permanence values</param> public void UpdatePermanencesForColumnSparse(HtmConfig htmConfig, double[] perm, int[] maskPotential, bool raisePerm) { if (raisePerm) { HtmCompute.RaisePermanenceToThresholdSparse(htmConfig, perm); } ArrayUtils.LessOrEqualXThanSetToY(perm, htmConfig.SynPermTrimThreshold, 0); ArrayUtils.EnsureBetweenMinAndMax(perm, htmConfig.SynPermMin, htmConfig.SynPermMax); SetProximalPermanencesSparse(htmConfig, perm, maskPotential); }
/// <summary> /// Sets the permanences for each <see cref="Synapse"/>. The number of synapses is set by the potentialPct variable which determines the number of input /// bits a given column will be "attached" to which is the same number as the number of <see cref="Synapse"/>s /// </summary> /// <param name="htmConfig">the <see cref="Connections"/> memory</param> /// <param name="perms">the floating point degree of connectedness</param> public void SetPermanences(HtmConfig htmConfig, double[] perms) { this.ProximalDendrite.RFPool.ResetConnections(); // Every column contians a single row at index 0. this.ConnectedInputCounterMatrix.ClearStatistics(0); foreach (Synapse synapse in this.ProximalDendrite.Synapses) { this.SetPermanence(synapse, htmConfig.SynPermConnected, perms[synapse.InputIndex]); if (perms[synapse.InputIndex] >= htmConfig.SynPermConnected) { this.ConnectedInputCounterMatrix.set(1, 0 /*this.Index*/, synapse.InputIndex); } } }
/// <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); } } }
/// <summary> /// Creates connections between mini-columns and input neurons. /// </summary> /// <param name="htmConfig"></param> /// <param name="inputVectorIndexes">Sensory cells providing spatial input that will be learned by SP.</param> /// <param name="startSynapseIndex">Starting index.</param> /// <returns></returns> public Pool CreatePotentialPool(HtmConfig htmConfig, int[] inputVectorIndexes, int startSynapseIndex) { this.ProximalDendrite.Synapses.Clear(); var pool = new Pool(inputVectorIndexes.Length, htmConfig.NumInputs); this.ProximalDendrite.RFPool = pool; for (int i = 0; i < inputVectorIndexes.Length; i++) { var synapse = this.ProximalDendrite.CreateSynapse(startSynapseIndex + i, inputVectorIndexes[i]); // All permanences are at the begining set to 0. this.SetPermanence(synapse, htmConfig.SynPermConnected, 0); } return(pool); }
/// <summary> /// Gets the min,max and avg permanence of all connected synapses. /// </summary> /// <returns></returns> public HtmStatistics GetStatistics(HtmConfig config) { double permSum = 0.0; double max = 0.0; double min = 2.0; int connectedSynapses = 0; foreach (var syn in this.ProximalDendrite.Synapses.Where(s => s.Permanence > config.SynPermConnected)) { permSum += syn.Permanence; if (syn.Permanence < min) { min = syn.Permanence; } if (syn.Permanence > max) { max = syn.Permanence; } connectedSynapses++; } return(new HtmStatistics { SynapticActivity = (double)connectedSynapses / (double)this.ProximalDendrite.Synapses.Count, AvgPermanence = permSum / connectedSynapses, MinPermanence = min, MaxPermanence = max, ConnectedSynapses = connectedSynapses, Synapses = this.ProximalDendrite.Synapses.Count }); }
/// <summary> /// Sets the permanences on the <see cref="ProximalDendrite"/> <see cref="Synapse"/>s /// </summary> /// <param name="htmConfig"></param> /// <param name="permanences">floating point degree of connectedness</param> /// <param name="inputVectorIndexes"></param> public void SetProximalPermanencesSparse(HtmConfig htmConfig, double[] permanences, int[] inputVectorIndexes) { this.ProximalDendrite.SetPermanences(this.ConnectedInputCounterMatrix, htmConfig, permanences, inputVectorIndexes); }