Exemplo n.º 1
0
        public void Serialize(StreamWriter writer)
        {
            HtmSerializer2 ser = new HtmSerializer2();

            ser.SerializeBegin(nameof(Synapse), writer);

            if (this.BoxedIndex != null)
            {
                this.BoxedIndex.Serialize(writer);
            }

            if (this.SourceCell != null)
            {
                // We are serializeing the index only to avoid circular references.
                ser.SerializeValue(this.SourceCell.Index, writer);
            }

            ser.SerializeValue(this.SegmentIndex, writer);
            ser.SerializeValue(this.SynapseIndex, writer);
            ser.SerializeValue(this.InputIndex, writer);
            ser.SerializeValue(this.Permanence, writer);
            ser.SerializeValue(this.IsDestroyed, writer);

            ser.SerializeEnd(nameof(Synapse), writer);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Only cell Serialize method should invoke this method!
        /// </summary>
        /// <param name="writer"></param>
        internal void SerializeT(StreamWriter writer)
        {
            HtmSerializer2 ser = new HtmSerializer2();

            ser.SerializeBegin(nameof(Synapse), writer);

            ser.SerializeValue(this.SegmentIndex, writer);
            ser.SerializeValue(this.SynapseIndex, writer);
            ser.SerializeValue(this.InputIndex, writer);
            ser.SerializeValue(this.Permanence, writer);
            ser.SerializeValue(this.IsDestroyed, writer);

            if (this.BoxedIndex != null)
            {
                this.BoxedIndex.Serialize(writer);
            }

            // If we use this, we will get a cirular serialization.
            //if (this.SourceCell != null)
            //{
            //    this.SourceCell.SerializeT(writer);
            //}

            ser.SerializeEnd(nameof(Synapse), writer);
        }
Exemplo n.º 3
0
        public void Serialize(StreamWriter writer)
        {
            HtmSerializer2 ser = new HtmSerializer2();

            ser.SerializeBegin(nameof(Column), writer);

            ser.SerializeValue(this.CellId, writer);
            ser.SerializeValue(this.Index, writer);


            if (this.connectedInputCounter != null)
            {
                this.connectedInputCounter.Serialize(writer);
            }

            if (this.ConnectedInputCounterMatrix != null)
            {
                this.ConnectedInputCounterMatrix.Serialize(writer);
            }

            if (this.ProximalDendrite != null)
            {
                this.ProximalDendrite.Serialize(writer);
            }
            ser.SerializeValue(this.Cells, writer);
            ser.SerializeEnd(nameof(Column), writer);
        }
Exemplo n.º 4
0
        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)) || data.ToCharArray()[0] == HtmSerializer2.ElementsDelimiter || (data.ToCharArray()[0] == HtmSerializer2.ElementsDelimiter && data.ToCharArray()[1] == HtmSerializer2.ParameterDelimiter))
                {
                    continue;
                }
                else if (data == ser.ReadBegin(nameof(DistalDendrite)))
                {
                    cell.DistalDendrites.Add(DistalDendrite.Deserialize(sr));
                }
                else if (data == ser.ReadBegin(nameof(Synapse)))
                {
                    return(cell);
                }
                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;
                        }

                        default:
                        { break; }
                        }
                    }
                }
            }
            return(cell);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        public void Serialize(StreamWriter writer)
        {
            HtmSerializer2 ser = new HtmSerializer2();

            ser.SerializeBegin(nameof(Integer), writer);

            ser.SerializeValue(this.Value, writer);

            ser.SerializeEnd(nameof(Integer), writer);
        }
Exemplo n.º 7
0
        public void Serialize(StreamWriter writer)
        {
            HtmSerializer2 ser = new HtmSerializer2();

            ser.SerializeBegin(nameof(SegmentActivity), writer);

            ser.SerializeValue(this.ActiveSynapses, writer);
            ser.SerializeValue(this.PotentialSynapses, writer);

            ser.SerializeEnd(nameof(SegmentActivity), writer);
        }
        public void Serialize(StreamWriter writer)
        {
            HtmSerializer2 ser = new HtmSerializer2();

            ser.SerializeBegin(nameof(AbstractSparseBinaryMatrix), writer);

            ser.SerializeValue(AbstractSparseBinaryMatrix.serialVersionUID, writer);
            ser.SerializeValue(this.trueCounts, writer);

            ser.SerializeEnd(nameof(AbstractSparseBinaryMatrix), writer);
        }
Exemplo n.º 9
0
        public void Serialize(StreamWriter writer)
        {
            HtmSerializer2 ser = new HtmSerializer2();

            ser.SerializeBegin(nameof(Cell), writer);

            ser.SerializeValue(this.Index, writer);
            //ser.SerializeValue(this.CellId, writer);
            ser.SerializeValue(this.ParentColumnIndex, writer);
            //ser.SerializeValue(this.m_Hashcode, writer);

            ser.SerializeEnd(nameof(Cell), writer);
        }
Exemplo n.º 10
0
        public void Serialize(StreamWriter writer)
        {
            HtmSerializer2 ser = new HtmSerializer2();

            ser.SerializeBegin(nameof(Topology), writer);

            ser.SerializeValue(this.dimensions, writer);
            ser.SerializeValue(this.dimensionMultiples, writer);
            ser.SerializeValue(this.isColumnMajor, writer);
            ser.SerializeValue(this.numDimensions, writer);

            ser.SerializeEnd(nameof(Topology), writer);
        }
Exemplo n.º 11
0
        public void Serialize(StreamWriter writer)
        {
            HtmSerializer2 ser = new HtmSerializer2();

            ser.SerializeBegin(nameof(HtmModuleTopology), writer);

            ser.SerializeValue(this.Dimensions, writer);
            ser.SerializeValue(this.IsMajorOrdering, writer);
            ser.SerializeValue(this.DimensionMultiplies, writer);
            //this.NumDimensions --- It is not serialised since it returns only length of dimensions.

            ser.SerializeEnd(nameof(HtmModuleTopology), writer);
        }
Exemplo n.º 12
0
        public void Serialize(StreamWriter writer)
        {
            HtmSerializer2 ser = new HtmSerializer2();

            ser.SerializeBegin(nameof(Pool), writer);

            ser.SerializeValue(this.size, writer);
            ser.SerializeValue(this.NumInputs, writer);
            ser.SerializeValue(this.m_SynapseConnections, writer);
            ser.SerializeValue(this.m_SynapsesBySourceIndex, writer);

            ser.SerializeEnd(nameof(Pool), writer);
        }
Exemplo n.º 13
0
        public static HtmModuleTopology Deserialize(StreamReader sr)
        {
            HtmModuleTopology htm = new HtmModuleTopology();

            HtmSerializer2 ser = new HtmSerializer2();

            while (sr.Peek() >= 0)
            {
                string data = sr.ReadLine();
                if (data == ser.LineDelimiter || data == ser.ReadBegin(nameof(HtmModuleTopology)) || data == ser.ReadEnd(nameof(SegmentActivity)))
                {
                    continue;
                }
                else if (data == ser.ReadEnd(nameof(HtmModuleTopology)))
                {
                    break;
                }
                else
                {
                    string[] str = data.Split(HtmSerializer2.ParameterDelimiter);
                    for (int i = 0; i < str.Length; i++)
                    {
                        switch (i)
                        {
                        case 0:
                        {
                            htm.Dimensions = ser.ReadArrayInt(str[i]);
                            break;
                        }

                        case 1:
                        {
                            htm.IsMajorOrdering = ser.ReadBoolValue(str[i]);
                            break;
                        }

                        case 2:
                        {
                            htm.DimensionMultiplies = ser.ReadArrayInt(str[i]);
                            break;
                        }

                        default:
                        { break; }
                        }
                    }
                }
            }

            return(htm);
        }
Exemplo n.º 14
0
        public virtual void Serialize(StreamWriter writer)
        {
            HtmSerializer2 ser = new HtmSerializer2();

            ser.SerializeBegin(nameof(HtmConfig), writer);

            ser.SerializeValue(this.SegmentIndex, writer);
            this.boxedIndex.Serialize(writer);
            ser.SerializeValue(this.Synapses, writer);
            ser.SerializeValue(this.SynapsePermConnected, writer);
            ser.SerializeValue(this.NumInputs, writer);

            ser.SerializeEnd(nameof(HtmConfig), writer);
        }
Exemplo n.º 15
0
        public static Topology Deserialize(StreamReader sr)
        {
            Topology       topology = new Topology();
            HtmSerializer2 ser      = new HtmSerializer2();

            while (sr.Peek() >= 0)
            {
                string data = sr.ReadLine();
                if (data == String.Empty || data == ser.ReadBegin(nameof(Topology)))
                {
                    continue;
                }
                else
                {
                    string[] str = data.Split(HtmSerializer2.ParameterDelimiter);
                    for (int i = 0; i < str.Length; i++)
                    {
                        switch (i)
                        {
                        case 0:
                        {
                            topology.dimensions = ser.ReadArrayInt(str[i]);
                            break;
                        }

                        case 1:
                        {
                            topology.dimensionMultiples = ser.ReadArrayInt(str[i]);
                            break;
                        }

                        case 2:
                        {
                            topology.isColumnMajor = ser.ReadBoolValue(str[i]);
                            break;
                        }

                        case 3:
                        {
                            topology.numDimensions = ser.ReadIntValue(str[i]);
                            break;
                        }
                        }
                    }
                }
            }
            return(topology);
        }
Exemplo n.º 16
0
        public void Serialize(StreamWriter writer)
        {
            HtmSerializer2 ser = new HtmSerializer2();

            ser.SerializeBegin(nameof(HtmConfig), writer);

            this.SourceCell.Serialize(writer);
            ser.SerializeValue(this.SegmentIndex, writer);
            ser.SerializeValue(this.SynapseIndex, writer);
            this.BoxedIndex.Serialize(writer);
            ser.SerializeValue(this.InputIndex, writer);
            ser.SerializeValue(this.Permanence, writer);
            ser.SerializeValue(this.IsDestroyed, writer);

            ser.SerializeEnd(nameof(HtmConfig), writer);
        }
Exemplo n.º 17
0
        public static SparseObjectMatrix <T> Deserialize(StreamReader sr)
        {
            SparseObjectMatrix <T> sparse = new SparseObjectMatrix <T>();

            HtmSerializer2 ser = new HtmSerializer2();

            while (sr.Peek() >= 0)
            {
                string data = sr.ReadLine();
                if (data == String.Empty || data == ser.ReadBegin(nameof(SparseObjectMatrix <T>)))
                {
                    continue;
                }
                else if (data == ser.ReadBegin(nameof(HtmModuleTopology)))
                {
                    sparse.ModuleTopology = HtmModuleTopology.Deserialize(sr);
                }
                //else if (data == ser.ReadBegin(nameof(InMemoryDistributedDictionary<TKey, TValue>) <{ nameof(TKey}>))
                //{
                //    sparse.m_SparseMap = InMemoryDistributedDictionary<TKey, TValue>.Deserialize(sr);
                //}
                else if (data == ser.ReadEnd(nameof(SparseObjectMatrix <T>)))
                {
                    break;
                }
                else
                {
                    string[] str = data.Split(HtmSerializer2.ParameterDelimiter);
                    for (int i = 0; i < str.Length; i++)
                    {
                        switch (i)
                        {
                        case 0:
                        {
                            //sparse.IsRemotelyDistributed = ser.ReadBoolValue(str[i]);
                            break;
                        }

                        default:
                        { break; }
                        }
                    }
                }
            }
            return(sparse);
        }
Exemplo n.º 18
0
        public static SparseBinaryMatrix Deserialize(StreamReader sr)
        {
            SparseBinaryMatrix sparse = new SparseBinaryMatrix();
            HtmSerializer2     ser    = new HtmSerializer2();

            while (sr.Peek() >= 0)
            {
                string data = sr.ReadLine();
                if (data == String.Empty || data == ser.ReadBegin(nameof(SparseBinaryMatrix)))
                {
                    continue;
                }
                else if (data == ser.ReadBegin(nameof(InMemoryArray)))
                {
                    sparse.backingArray = InMemoryArray.Deserialize(sr);
                }
                else if (data == ser.ReadBegin(nameof(HtmModuleTopology)))
                {
                    sparse.ModuleTopology = HtmModuleTopology.Deserialize(sr);
                }
                else if (data == ser.ReadEnd(nameof(SparseBinaryMatrix)))
                {
                    break;
                }
                else
                {
                    string[] str = data.Split(HtmSerializer2.ParameterDelimiter);
                    for (int i = 0; i < str.Length; i++)
                    {
                        switch (i)
                        {
                        case 0:
                        {
                            sparse.trueCounts = ser.ReadArrayInt(str[i]);
                            break;
                        }

                        default:
                        { break; }
                        }
                    }
                }
            }
            return(sparse);
        }
Exemplo n.º 19
0
        public static Cell Deserialize(StreamReader sr)
        {
            Cell cell = new Cell();

            HtmSerializer2 ser  = new HtmSerializer2();
            string         data = sr.ReadToEnd();

            string[] str = data.Split('\n');

            foreach (string i in str)
            {
                if (i == "" || i == "  BEGIN 'Cell'  " || i == "  END 'Cell'  ")
                {
                    continue;
                }
                else
                {
                    string[] istr = i.Split('|');
                    int      j;
                    for (j = 0; j < istr.Length; j++)
                    {
                        switch (j)
                        {
                        case 0:
                        {
                            cell.Index = ser.ReadIntValue(istr[j]);
                            break;
                        }

                        case 1:
                        {
                            cell.ParentColumnIndex = ser.ReadIntValue(istr[j]);
                            break;
                        }

                        default:
                        { break; }
                        }
                    }
                }
            }

            return(cell);
        }
Exemplo n.º 20
0
        public override void Serialize(StreamWriter writer)
        {
            HtmSerializer2 ser = new HtmSerializer2();

            ser.SerializeBegin(nameof(SparseBinaryMatrix), writer);

            ser.SerializeValue(this.trueCounts, writer);

            if (this.ModuleTopology != null)
            {
                this.ModuleTopology.Serialize(writer);
            }

            if (this.backingArray != null)
            {
                this.backingArray.Serialize(writer);
            }

            ser.SerializeEnd(nameof(SparseBinaryMatrix), writer);
        }
Exemplo n.º 21
0
        /// <summary>
        /// Serializes the cell to the stream.
        /// </summary>
        /// <param name="writer"></param>
        public void Serialize(StreamWriter writer)
        {
            HtmSerializer2 ser = new HtmSerializer2();

            ser.SerializeBegin(nameof(Cell), writer);

            ser.SerializeValue(this.Index, writer);
            ser.SerializeValue(this.CellId, writer);
            ser.SerializeValue(this.ParentColumnIndex, writer);
            if (this.DistalDendrites != null && this.DistalDendrites.Count > 0)
            {
                ser.SerializeValue(this.DistalDendrites.Select(s => s.Ordinal).ToArray(), writer);
            }

            if (this.ReceptorSynapses != null && this.ReceptorSynapses.Count > 0)
            {
                ser.SerializeValue(this.ReceptorSynapses.Select(s => s.SynapseIndex).ToArray(), writer);
            }

            ser.SerializeEnd(nameof(Cell), writer);
        }
Exemplo n.º 22
0
        public override void Serialize(StreamWriter writer)
        {
            HtmSerializer2 ser = new HtmSerializer2();

            ser.SerializeBegin(nameof(SparseObjectMatrix <T>), writer);

            ser.SerializeValue(this.IsRemotelyDistributed, writer);

            if (this.ModuleTopology != null)
            {
                this.ModuleTopology.Serialize(writer);
            }

            if (this.m_SparseMap != null)
            {
                this.m_SparseMap.Serialize(writer);
            }


            ser.SerializeEnd(nameof(SparseObjectMatrix <T>), writer);
        }
Exemplo n.º 23
0
        public static SegmentActivity Deserialize(StreamReader sr)
        {
            SegmentActivity segment = new SegmentActivity();

            HtmSerializer2 ser = new HtmSerializer2();

            while (sr.Peek() >= 0)
            {
                string data = sr.ReadLine();
                if (data == ser.LineDelimiter || data == ser.ReadBegin(nameof(SegmentActivity)) || data == ser.ReadEnd(nameof(SegmentActivity)))
                {
                }
                else
                {
                    string[] str = data.Split(HtmSerializer2.ParameterDelimiter);
                    for (int i = 0; i < str.Length; i++)
                    {
                        switch (i)
                        {
                        case 0:
                        {
                            segment.ActiveSynapses = ser.ReadDictionaryIIValue(str[i]);
                            break;
                        }

                        case 1:
                        {
                            segment.PotentialSynapses = ser.ReadDictionaryIIValue(str[i]);
                            break;
                        }

                        default:
                        { break; }
                        }
                    }
                }
            }

            return(segment);
        }
Exemplo n.º 24
0
        public static Integer Deserialize(StreamReader sr)
        {
            Integer inte = new Integer();

            HtmSerializer2 ser = new HtmSerializer2();

            while (sr.Peek() >= 0)
            {
                string data = sr.ReadLine();
                if (data == String.Empty || data == ser.ReadBegin(nameof(Integer)))
                {
                    continue;
                }
                else if (data == ser.ReadEnd(nameof(Integer)))
                {
                    break;
                }
                else
                {
                    string[] str = data.Split(HtmSerializer2.ParameterDelimiter);
                    for (int i = 0; i < str.Length; i++)
                    {
                        switch (i)
                        {
                        case 0:
                        {
                            inte.Value = ser.ReadIntValue(str[i]);
                            break;
                        }

                        default:
                        { break; }
                        }
                    }
                }
            }

            return(inte);
        }
Exemplo n.º 25
0
        public static Integer Deserialize(StreamReader sr)
        {
            Integer inte = new Integer();

            HtmSerializer2 ser  = new HtmSerializer2();
            string         data = sr.ReadToEnd();

            string[] str = data.Split('\n');

            foreach (string i in str)
            {
                if (i == "" || i == "  BEGIN 'Integer'  " || i == "  END 'Integer'  ")
                {
                    continue;
                }
                else
                {
                    string[] istr = i.Split('|');
                    int      j;
                    for (j = 0; j < istr.Length; j++)
                    {
                        switch (j)
                        {
                        case 0:
                        {
                            inte.Value = ser.ReadIntValue(istr[j]);
                            break;
                        }

                        default:
                        { break; }
                        }
                    }
                }
            }

            return(inte);
        }
Exemplo n.º 26
0
        public override void Serialize(StreamWriter writer)
        {
            HtmSerializer2 ser = new HtmSerializer2();

            ser.SerializeBegin(nameof(ProximalDendrite), writer);

            ser.SerializeValue(this.SegmentIndex, writer);
            ser.SerializeValue(this.SynapsePermConnected, writer);
            ser.SerializeValue(this.NumInputs, writer);

            if (this.RFPool != null)
            {
                this.RFPool.Serialize(writer);
            }

            //if (this.boxedIndex != null)
            //{
            //    this.boxedIndex.Serialize(writer);
            //}
            ser.SerializeValue(this.Synapses, writer);

            ser.SerializeEnd(nameof(ProximalDendrite), writer);
        }
Exemplo n.º 27
0
        public static Column Deserialize(StreamReader sr)
        {
            Column column = new Column();

            HtmSerializer2 ser = new HtmSerializer2();


            while (!sr.EndOfStream)
            {
                string data = sr.ReadLine();
                if (data == String.Empty || data == ser.ReadBegin(nameof(Column)) || data == ser.ValueDelimiter)
                {
                    continue;
                }
                else if (data == ser.ReadBegin(nameof(SparseBinaryMatrix)))
                {
                    column.connectedInputCounter = SparseBinaryMatrix.Deserialize(sr);
                }
                //else if (data == ser.ReadBegin(nameof(SparseBinaryMatrix)))
                //{
                //    column.ConnectedInputCounterMatrix = SparseBinaryMatrix.Deserialize(sr);
                //}
                else if (data == ser.ReadBegin(nameof(ProximalDendrite)))
                {
                    column.ProximalDendrite = ProximalDendrite.Deserialize(sr);
                }
                else if (data == ser.ReadBegin(nameof(Cell)))
                {
                    column.Cells = ser.DeserializeCellArray(data, sr);
                }
                else if (data == ser.ReadEnd(nameof(Column)))
                {
                    break;
                }
                else
                {
                    string[] str = data.Split(HtmSerializer2.ParameterDelimiter);
                    for (int i = 0; i < str.Length; i++)
                    {
                        switch (i)
                        {
                        case 0:
                        {
                            column.CellId = ser.ReadIntValue(str[i]);
                            break;
                        }

                        case 1:
                        {
                            column.Index = ser.ReadIntValue(str[i]);
                            break;
                        }

                        default:
                        { break; }
                        }
                    }
                }
            }
            return(column);
        }
Exemplo n.º 28
0
        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);
        }
Exemplo n.º 29
0
        /// <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);
        }
Exemplo n.º 30
0
        public static Synapse Deserialize(StreamReader sr)
        {
            Synapse synapse = new Synapse();

            HtmSerializer2 ser = new HtmSerializer2();

            while (sr.Peek() >= 0)
            {
                string data = sr.ReadLine();
                if (data == ser.LineDelimiter || data == ser.ReadBegin(nameof(Synapse)))
                {
                    continue;
                }
                else if (data == ser.ReadBegin(nameof(Integer)))
                {
                    synapse.BoxedIndex = Integer.Deserialize(sr);
                }
                else if (data == ser.ReadEnd(nameof(Synapse)))
                {
                    break;
                }
                else
                {
                    string[] str = data.Split(HtmSerializer2.ParameterDelimiter);
                    for (int i = 0; i < str.Length; i++)
                    {
                        switch (i)
                        {
                        case 0:
                        {
                            synapse.SourceCell       = new Cell();
                            synapse.SourceCell.Index = ser.ReadIntValue(str[i]);

                            break;
                        }

                        case 1:
                        {
                            synapse.SegmentIndex = ser.ReadIntValue(str[i]);
                            break;
                        }

                        case 2:
                        {
                            synapse.SynapseIndex = ser.ReadIntValue(str[i]);
                            break;
                        }

                        case 3:
                        {
                            synapse.InputIndex = ser.ReadIntValue(str[i]);
                            break;
                        }

                        case 4:
                        {
                            synapse.Permanence = ser.ReadDoubleValue(str[i]);
                            break;
                        }

                        case 5:
                        {
                            synapse.IsDestroyed = ser.ReadBoolValue(str[i]);
                            break;
                        }

                        default:
                        { break; }
                        }
                    }
                }
            }

            return(synapse);
        }