Beispiel #1
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);
        }
        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);
        }
Beispiel #3
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);
        }
Beispiel #4
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);
        }
Beispiel #5
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);
        }
Beispiel #6
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);
        }
        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);
        }
Beispiel #8
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);
        }
        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);
        }
Beispiel #10
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);
        }
Beispiel #11
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);
        }
Beispiel #12
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);
        }