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); }
public NetworkUnit(Func <double, double> actFunc, int unitId, NetworkUnit biasUnit = null) { UnitId = unitId; ID_COUNTER = Math.Max(unitId, ID_COUNTER) + 1; Connections = new Dictionary <NetworkUnit, double>(); BiasUnit = biasUnit; ActFunc = actFunc; }
public static NetworkUnit Get(this Dictionary <int, NetworkUnit> dict, int key, Func <double, double> actFunc = null, NetworkUnit biasUnit = null, bool isBias = false) { if (!dict.ContainsKey(key)) { dict[key] = isBias ? NetworkUnit.CreateBias(key) : new NetworkUnit(actFunc, key, biasUnit); } return(dict[key]); }
public NetworkUnit(Func <double, double> actFunc, NetworkUnit biasUnit = null) { UnitId = ID_COUNTER; ID_COUNTER++; Connections = new Dictionary <NetworkUnit, double>(); ActFunc = actFunc; BiasUnit = biasUnit; if (BiasUnit != null) { Connections[BiasUnit] = 0; } }
public void AddUnit(NetworkUnit unit) { Units.Add(unit); }