基本上我试图backpropogation在网络中实现。我知道反向传播算法是硬编码的,但我试图首先使其发挥作用。
它适用于一组输入和输出,但超出一个训练集,网络收敛于一个解决方案,而另一输出收敛于 0.5。
即一次试验的输出是:
[0.9969527919933012, 0.003043774988797313]
[0.5000438200377985, 0.49995612243030635]
Network.java
private ArrayList<ArrayList<ArrayList<Double>>> weights;
private ArrayList<ArrayList<Double>> nodes;
private final double LEARNING_RATE = -0.25;
private final double DEFAULT_NODE_VALUE = 0.0;
private double momentum = 1.0;
public Network() {
weights = new ArrayList<ArrayList<ArrayList<Double>>>();
nodes = new ArrayList<ArrayList<Double>>();
}
/**
* This method is used to add a layer with {@link n} nodes to the network.
* @param n number of nodes for the layer
*/
public void addLayer(int n) {
nodes.add(new ArrayList<Double>()); …Run Code Online (Sandbox Code Playgroud)