/// <summary> /// Creates and returns a newly created synapse with the specified source cell, permanence, and index. /// </summary> /// <param name="sourceCell">This value is typically set to NULL in a case of proximal segment. This is because, proximal segments /// build synaptic connections from column to the sensory input. They do not cobbect a specific cell inside of the column.</param> /// <param name="index">Sequence within gthe pool.</param> /// <param name="inputIndex">The index of the sensory neuron connected by this synapse.</param> /// <remarks> /// <b>This method is only called for Proximal Synapses.</b> For ProximalDendrites, there are many synapses within a pool, and in that case, the index /// specifies the synapse's sequence order within the pool object, and may be referenced by that index</remarks> /// <returns>Instance of the new synapse.</returns> /// <seealso cref="Synapse"/> public Synapse CreateSynapse(int index, int inputIndex) { Synapse synapse = new Synapse(this.SegmentIndex, index, inputIndex); this.Synapses.Add(synapse); return(synapse); }
/// <summary> /// Creates and returns a newly created synapse with the specified source cell, permanence, and index. /// </summary> /// <param name="sourceCell"></param> /// <param name="index">Sequence within gthe pool.</param> /// <param name="inputIndex"></param> /// <remarks> /// <b>This method is only called for Proximal Synapses.</b> For ProximalDendrites, there are many synapses within a pool, and in that case, the index /// specifies the synapse's sequence order within the pool object, and may be referenced by that index</remarks> /// <returns>Instance of the new synapse.</returns> /// <seealso cref="Synapse"/> public Synapse CreateSynapse(Cell sourceCell, int index, int inputIndex) { Synapse synapse = new Synapse(sourceCell, this.SegmentIndex, index, inputIndex); this.Synapses.Add(synapse); return(synapse); }
/// <summary> /// Deserializes from text file to DistalDendrite /// </summary> /// <param name="sr"></param> /// <returns>DistalDendrite</returns> public Synapse DeserializeSynapse(StreamReader sr) { while (sr.Peek() >= 0) { string data = sr.ReadLine(); if (data == ReadBegin(nameof(Synapse))) { Synapse synapseT1 = Synapse.Deserialize(sr); Cell cell1 = synapseT1.SourceCell; DistalDendrite distSegment1 = synapseT1.SourceCell.DistalDendrites[0]; DistalDendrite distSegment2 = synapseT1.SourceCell.DistalDendrites[1]; distSegment1.ParentCell = cell1; distSegment2.ParentCell = cell1; synapseT1.SourceCell = cell1; return(synapseT1); } } return(null); }
public static Pool Deserialize(StreamReader sr) { Pool pool = new Pool(); HtmSerializer2 ser = new HtmSerializer2(); while (sr.Peek() >= 0) { string data = sr.ReadLine(); if (data == String.Empty || data == ser.ReadBegin(nameof(Pool)) || (data.ToCharArray()[0] == HtmSerializer2.ElementsDelimiter && data.ToCharArray()[1] == HtmSerializer2.ParameterDelimiter)) { continue; } else if (data == ser.ReadEnd(nameof(Pool))) { break; } else if (data.Contains(HtmSerializer2.KeyValueDelimiter)) { int val = ser.ReadKeyISValue(data); data = sr.ReadLine(); pool.m_SynapsesBySourceIndex.Add(val, Synapse.Deserialize(sr)); } else { string[] str = data.Split(HtmSerializer2.ParameterDelimiter); for (int i = 0; i < str.Length; i++) { switch (i) { case 0: { pool.size = ser.ReadIntValue(str[i]); break; } case 1: { pool.NumInputs = ser.ReadIntValue(str[i]); break; } case 2: { pool.m_SynapseConnections = ser.ReadListInt(str[i]); break; } default: { break; } } } } } return(pool); }
/** * Destroys any references this {@code Pool} maintains on behalf * of the specified {@link Synapse} * * @param synapse */ public void destroySynapse(Synapse synapse) { synapseConnections.Remove(synapse.getInputIndex()); synapsesBySourceIndex.Remove(synapse.getInputIndex()); if (synapse.getSegment() is DistalDendrite) { destroy(); } }
/// <summary> /// Used by SpatialPooler when learning spatial patterns. Spatial patterns are learned by synapses between /// proximal dendrite segment and input neurons. /// </summary> /// <param name="synapse"></param> /// <param name="synPermConnected">The synapse is the connected oneif its permanence value is greather than this threshold.</param> /// <param name="perm">The permanence value of the synapse.</param> private void SetPermanence(Synapse synapse, double synPermConnected, double perm) { synapse.Permanence = perm; // // On proximal dendrite which has no presynaptic cell if (synapse.SourceCell == null) { this.ProximalDendrite.RFPool.UpdatePool(synPermConnected, synapse, perm); } }
/** * Returns the permanence value for the {@link Synapse} specified. * * @param s the Synapse * @return the permanence */ //public double getPermanence(Synapse s) //{ // return synapsesBySourceIndex[s.getInputIndex()].getPermanence(); //} /** * Sets the specified permanence value for the specified {@link Synapse} * @param s * @param permanence */ //public void setPermanence(Connections c, Synapse s, double permanence) //{ // s.setPermanence(c, permanence); //} /// <summary> /// Updates this <see cref="Pool"/>'s store of permanences for the specified <see cref="Synapse"/> /// </summary> /// <param name="synPermConnected"></param> /// <param name="synapse">the synapse who's permanence is recorded</param> /// <param name="permanence">the permanence value to record</param> public void UpdatePool(double synPermConnected, Synapse synapse, double permanence) { int inputIndex = synapse.InputIndex; if (m_SynapsesBySourceIndex.ContainsKey(inputIndex) == false) { m_SynapsesBySourceIndex.Add(inputIndex, synapse); } if (permanence >= synPermConnected) { m_SynapseConnections.Add(inputIndex); } else { m_SynapseConnections.Remove(inputIndex); } }
public static ProximalDendrite Deserialize(StreamReader sr) { ProximalDendrite proximal = new ProximalDendrite(); HtmSerializer2 ser = new HtmSerializer2(); while (sr.Peek() >= 0) { string data = sr.ReadLine(); if (data == String.Empty || data == ser.ReadBegin(nameof(ProximalDendrite)) || (data.ToCharArray()[0] == HtmSerializer2.ElementsDelimiter && data.ToCharArray()[1] == HtmSerializer2.ParameterDelimiter) || data.ToCharArray()[1] == HtmSerializer2.ParameterDelimiter) { continue; } else if (data == ser.ReadBegin(nameof(Pool))) { proximal.RFPool = Pool.Deserialize(sr); } //else if (data == ser.ReadBegin(nameof(Integer))) //{ // proximal.boxedIndex = Integer.Deserialize(sr); //} else if (data == ser.ReadBegin(nameof(Synapse))) { proximal.Synapses.Add(Synapse.Deserialize(sr)); } else if (data == ser.ReadEnd(nameof(ProximalDendrite))) { break; } else { string[] str = data.Split(HtmSerializer2.ParameterDelimiter); for (int i = 0; i < str.Length; i++) { switch (i) { case 0: { proximal.SegmentIndex = ser.ReadIntValue(str[i]); break; } case 1: { proximal.SynapsePermConnected = ser.ReadDoubleValue(str[i]); break; } case 2: { proximal.NumInputs = ser.ReadIntValue(str[i]); break; } default: { break; } } } } } return(proximal); }
/// <summary> /// Deserializes the cell from the stream. /// </summary> /// <param name="sr"></param> /// <returns></returns> public static Cell Deserialize(StreamReader sr) { Cell cell = new Cell(); HtmSerializer2 ser = new HtmSerializer2(); while (sr.Peek() >= 0) { string data = sr.ReadLine(); if (data == String.Empty || data == ser.ReadBegin(nameof(Cell))) { continue; } else if (data == ser.ReadEnd(nameof(Cell))) { break; } else { string[] str = data.Split(HtmSerializer2.ParameterDelimiter); for (int i = 0; i < str.Length; i++) { switch (i) { case 0: { cell.Index = ser.ReadIntValue(str[i]); break; } case 1: { cell.CellId = ser.ReadIntValue(str[i]); break; } case 2: { cell.ParentColumnIndex = ser.ReadIntValue(str[i]); break; } case 3: { int[] vs = ser.ReadArrayInt(str[i]); cell.DistalDendrites = new List <DistalDendrite>(); for (int j = 0; j < vs.Count(); j++) { cell.DistalDendrites.Add(new DistalDendrite()); cell.DistalDendrites[j].Ordinal = vs[j]; using (StreamReader swLD = new StreamReader($"ser_SerializeDistalDendrite_{cell.DistalDendrites[j].Ordinal}.txt")) { cell.DistalDendrites[j] = DistalDendrite.Deserialize(swLD); } } break; } case 4: { int[] vs = ser.ReadArrayInt(str[i]); cell.ReceptorSynapses = new List <Synapse>(); for (int j = 0; j < vs.Count(); j++) { cell.ReceptorSynapses.Add(new Synapse()); cell.ReceptorSynapses[j].SynapseIndex = vs[j]; using (StreamReader swLS = new StreamReader($"ser_SerializeSynapseTest_{cell.ReceptorSynapses[j].SynapseIndex}.txt")) { cell.ReceptorSynapses[j] = Synapse.Deserialize(swLS); } } break; } default: { break; } } } } } return(cell); }