|
|
|
@ -13,7 +13,8 @@ import java.util.*;
|
|
|
|
|
* @date 9:36 上午 2019/12/21
|
|
|
|
|
*/
|
|
|
|
|
public abstract class Nerve {
|
|
|
|
|
private List<Nerve> axon = new ArrayList<>();//轴突下一层的连接神经元
|
|
|
|
|
private List<Nerve> son = new ArrayList<>();//轴突下一层的连接神经元
|
|
|
|
|
private List<Nerve> fathor = new ArrayList<>();//树突上一层的连接神经元
|
|
|
|
|
private Map<Integer, Double> dendrites = new HashMap<>();//上一层权重
|
|
|
|
|
private int id;//同级神经元编号,注意在同层编号中ID应有唯一性
|
|
|
|
|
protected int upNub;//上一层神经元数量
|
|
|
|
@ -21,7 +22,8 @@ public abstract class Nerve {
|
|
|
|
|
static final Logger logger = LogManager.getLogger(Nerve.class);
|
|
|
|
|
private double threshold;//此神经元的阈值
|
|
|
|
|
protected ActiveFunction activeFunction = new ActiveFunction();
|
|
|
|
|
protected String name;
|
|
|
|
|
protected String name;//该神经元所属类型
|
|
|
|
|
protected double outNub;//输出数值(ps:只有训练模式的时候才可保存输出过的数值)
|
|
|
|
|
|
|
|
|
|
protected Nerve(int id, int upNub, String name) {//该神经元在同层神经元中的编号
|
|
|
|
|
this.id = id;
|
|
|
|
@ -30,17 +32,32 @@ public abstract class Nerve {
|
|
|
|
|
initPower();//生成随机权重
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void sendMessage(long enevtId, double parameter) throws Exception {
|
|
|
|
|
if (axon.size() > 0) {
|
|
|
|
|
for (Nerve nerve : axon) {
|
|
|
|
|
nerve.input(enevtId, parameter);
|
|
|
|
|
public void sendMessage(long enevtId, double parameter, boolean isStudy) throws Exception {
|
|
|
|
|
if (son.size() > 0) {
|
|
|
|
|
for (Nerve nerve : son) {
|
|
|
|
|
nerve.input(enevtId, parameter, isStudy);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw new Exception("this layer is lastIndex");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void input(long eventId, double parameter) throws Exception {//输入
|
|
|
|
|
public void backSendMessage(double parameter) throws Exception {//反向传播
|
|
|
|
|
if (fathor.size() > 0) {
|
|
|
|
|
for (Nerve nerve : fathor) {
|
|
|
|
|
nerve.backGetMessage(parameter);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw new Exception("this layer is firstIndex");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void input(long eventId, double parameter, boolean isStudy) throws Exception {//输入
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void backGetMessage(double parameter) {//反向传播
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected boolean insertParameter(long eventId, double parameter) {//添加参数
|
|
|
|
@ -93,6 +110,10 @@ public abstract class Nerve {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void connect(List<Nerve> nerveList) {
|
|
|
|
|
axon.addAll(nerveList);
|
|
|
|
|
son.addAll(nerveList);//连接下一层
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void connectFathor(List<Nerve> nerveList) {
|
|
|
|
|
fathor.addAll(nerveList);//连接上一层
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|