Exemplo n.º 1
0
        public static Layer Load(StreamReader reader, Dictionary <int, NetworkUnit> netUnits)
        {
            Layer layer = new Layer();
            int   units = int.Parse(reader.ReadLine());

            for (int j = 0; j < units; j++)
            {
                int[] unitInfo   = IOUtils.ReadInts(reader);
                int[] extraUnits = IOUtils.ReadInts(reader);
                Func <double, double> actFunc = ActFuncs.ById(unitInfo[1]);
                NetworkUnit           bias    = extraUnits[0] > 0 ? netUnits.Get(extraUnits[0], isBias: true) : null;
                NetworkUnit           memory  = extraUnits[1] > 0 ? netUnits.Get(extraUnits[1]) : null;
                NetworkUnit           unit    = netUnits.Get(unitInfo[0], actFunc, bias);
                unit.MemoryUnit = memory;
                int connections = int.Parse(reader.ReadLine());
                for (int k = 0; k < connections; k++)
                {
                    double[] connTokens = IOUtils.ReadDoubles(reader);
                    int      connUnitId = (int)connTokens[0];
                    double   connWeight = connTokens[1];
                    unit.Connections[netUnits.Get(connUnitId)] = connWeight;
                }
                layer.AddUnit(unit);
            }
            return(layer);
        }
Exemplo n.º 2
0
        public override string ToString()
        {
            StringBuilder result = new StringBuilder();

            result.Append(UnitId).Append(" ");
            result.Append(ActFuncs.GetId(ActFunc)).AppendLine();
            result.Append(BiasUnit == null ? -1 : BiasUnit.UnitId).Append(" ");
            result.Append(MemoryUnit == null ? -1 : MemoryUnit.UnitId).AppendLine();
            result.Append(Connections.Count).AppendLine();
            foreach (NetworkUnit connUnit in Connections.Keys.ToList())
            {
                result.Append(connUnit.UnitId).Append(" ").Append(Connections[connUnit]).AppendLine();
            }
            return(result.ToString());
        }