/// <summary> /// ns 记录从输入层开始,每层的节点个数。 /// withBias 为真,表示所有的节点均带有偏置。 /// fp 激活函数及其导数 /// u 训练步长 /// ranndomOrNull 初始化权值的方法 /// </summary> public Network(List <int> ns, bool withBias, Function_Pair fp, double u, bool RandomOrNull) { Layers = new List <Layer>(); this.withBias = withBias; for (int i = 0; i < ns.Count; i++) { int n = ns[i]; bool IsInput = false; bool IsOutput = false; if (i == 0) { IsInput = true; } if (i == ns.Count - 1) { IsOutput = true; withBias = false;//输出层不会有偏置。 } Layer layer = new Layer(withBias, n, IsInput, IsOutput, this, i, fp); Layers.Add(layer); } this.u = u; GodFunctions = new List <GodFunction>(); InitializeWeight(RandomOrNull); }
public Node(bool IsBias, Layer layer, Function_Pair fp) { this.IsBias = IsBias; this.layer = layer; if (!this.IsInput) { this.FP = fp; // 输入层无需激活函数。 Inputs = new List <Node>(); weights = new List <double>(); } }
/// <summary> /// 是否带偏置,该层的节点个数(不包含偏置在内) /// 是否为输入层,是否为输出层。 /// 网络,该层的层数。激活函数。 /// </summary> public Layer(bool withBias, int N_nodes, bool IsInput, bool IsOutput, Network net, int Nth_layer, Function_Pair fp) { nodes = new List <Node>(); this.IsInput = IsInput; this.IsOutput = IsOutput; this.net = net; this.Nth_layer = Nth_layer; if (withBias) { nodes.Add(new Node(true, this, fp)); } for (int i = 0; i < N_nodes; i++) { Node node = new Node(false, this, fp); nodes.Add(node); if (!node.IsInput) { foreach (Node pnode in this.PreviousLayer.nodes) { node.Inputs.Add(pnode); node.weights.Add(new double()); } } } }