diff --git a/src/main/java/org/wlld/function/Tanh.java b/src/main/java/org/wlld/function/Tanh.java index d0add56..13b3cc1 100644 --- a/src/main/java/org/wlld/function/Tanh.java +++ b/src/main/java/org/wlld/function/Tanh.java @@ -6,8 +6,10 @@ import org.wlld.tools.ArithUtil; public class Tanh implements ActiveFunction { @Override public double function(double x) { - double son = ArithUtil.sub(Math.exp(x), Math.exp(-x)); - double mother = ArithUtil.add(Math.exp(x), Math.exp(-x)); + double x1 = Math.exp(x); + double x2 = Math.exp(-x); + double son = ArithUtil.sub(x1, x2); + double mother = ArithUtil.add(x1, x2); return ArithUtil.div(son, mother); } diff --git a/src/main/java/org/wlld/imageRecognition/Operation.java b/src/main/java/org/wlld/imageRecognition/Operation.java index 52595fa..af2e0d9 100644 --- a/src/main/java/org/wlld/imageRecognition/Operation.java +++ b/src/main/java/org/wlld/imageRecognition/Operation.java @@ -281,7 +281,9 @@ public class Operation {//进行计算 Map map = new HashMap<>(); map.put(tagging, 1.0); List feature = getFeature(myMatrix); - //System.out.println(feature); + if (templeConfig.isShowLog()) { + System.out.println(feature); + } intoDnnNetwork(1, feature, templeConfig.getSensoryNerves(), true, map, null); } diff --git a/src/main/java/org/wlld/imageRecognition/TempleConfig.java b/src/main/java/org/wlld/imageRecognition/TempleConfig.java index d77ed5f..848923e 100644 --- a/src/main/java/org/wlld/imageRecognition/TempleConfig.java +++ b/src/main/java/org/wlld/imageRecognition/TempleConfig.java @@ -44,7 +44,7 @@ public class TempleConfig { private boolean boxReady = false;//边框已经学习完毕 private double iouTh = 0.5;//IOU阈值 private int lvqNub = 10;//lvq循环次数,默认30 - private VectorK vectorK; + private VectorK vectorK;//特征向量均值类 private boolean isThreeChannel = false;//是否启用三通道 private int classifier = Classifier.VAvg;//默认分类类别使用的是向量均值分类 private Normalization normalization = new Normalization();//统一归一化 @@ -52,6 +52,8 @@ public class TempleConfig { private int sensoryNerveNub;//输入神经元个数 private boolean isShowLog = false; private ActiveFunction activeFunction = new Tanh(); + private double studyPoint = 0; + public boolean isAccurate() { return isAccurate; } @@ -60,6 +62,10 @@ public class TempleConfig { isAccurate = accurate; } + public void setStudyPoint(double studyPoint) { + this.studyPoint = studyPoint; + } + public void setActiveFunction(ActiveFunction activeFunction) { this.activeFunction = activeFunction; } @@ -131,6 +137,10 @@ public class TempleConfig { this.isShowLog = isShowLog; } + public boolean isShowLog() { + return isShowLog; + } + public void startLvq() throws Exception { switch (classifier) { case Classifier.LVQ: @@ -231,7 +241,7 @@ public class TempleConfig { initConvolutionVision(initPower, width, height); break; case StudyPattern.Cover_Pattern://覆盖学习模式 - initNerveManager(initPower, 9, deep); + initNerveManager(initPower, 9, deep, studyPoint); break; } } @@ -247,13 +257,13 @@ public class TempleConfig { row = 5; column = (int) (d * row); } - initNerveManager(initPower, row * column, deep); + initNerveManager(initPower, row * column, deep,studyPoint); } private void initNerveManager(boolean initPower, int sensoryNerveNub - , int deep) throws Exception { + , int deep, double studyPoint) throws Exception { nerveManager = new NerveManager(sensoryNerveNub, 9, - classificationNub, deep, activeFunction, false, isAccurate); + classificationNub, deep, activeFunction, false, isAccurate, studyPoint); nerveManager.init(initPower, false, isShowLog); } @@ -271,7 +281,7 @@ public class TempleConfig { if (isThreeChannel) { nub = nub * 3; } - initNerveManager(true, nub, this.deep); + initNerveManager(true, nub, this.deep,studyPoint); break; case Classifier.LVQ: lvq = new LVQ(classificationNub, lvqNub); @@ -306,7 +316,7 @@ public class TempleConfig { private NerveManager initNerveManager(Map matrixMap, boolean initPower, int deep) throws Exception { //初始化卷积神经网络 NerveManager convolutionNerveManager = new NerveManager(1, 1, - 1, deep - 1, new ReLu(), true, isAccurate); + 1, deep - 1, new ReLu(), true, isAccurate,studyPoint); convolutionNerveManager.setMatrixMap(matrixMap);//给卷积网络管理器注入期望矩阵 convolutionNerveManager.init(initPower, true, isShowLog); return convolutionNerveManager; @@ -411,10 +421,6 @@ public class TempleConfig { return nerveManager.getSensoryNerves(); } - public void setStudy(double studyPoint) throws Exception {//设置学习率 - nerveManager.setStudyPoint(studyPoint); - } - public void setStudyList(List list) {//设置每一层不同的学习率 if (studyPattern == StudyPattern.Accuracy_Pattern) { //给卷积层设置层学习率 diff --git a/src/main/java/org/wlld/nerveCenter/NerveManager.java b/src/main/java/org/wlld/nerveCenter/NerveManager.java index 4c6bbc4..07eea17 100644 --- a/src/main/java/org/wlld/nerveCenter/NerveManager.java +++ b/src/main/java/org/wlld/nerveCenter/NerveManager.java @@ -44,19 +44,6 @@ public class NerveManager { this.matrixMap = matrixMap; } - public double getStudyPoint() { - return studyPoint; - } - - public void setStudyPoint(double studyPoint) throws Exception { - //设置学习率 - if (studyPoint <= 1 && studyPoint > 0) { - this.studyPoint = studyPoint; - } else { - throw new Exception("studyPoint Values range from 0 to 1"); - } - } - private ModelParameter getDymModelParameter() throws Exception {//获取动态神经元参数 ModelParameter modelParameter = new ModelParameter(); List dymNerveStudies = new ArrayList<>();//动态神经元隐层 @@ -210,7 +197,8 @@ public class NerveManager { * @throws Exception 如果参数错误则抛异常 */ public NerveManager(int sensoryNerveNub, int hiddenNerveNub, int outNerveNub - , int hiddenDepth, ActiveFunction activeFunction, boolean isDynamic, boolean isAccurate) throws Exception { + , int hiddenDepth, ActiveFunction activeFunction, boolean isDynamic, boolean isAccurate, + double studyPoint) throws Exception { if (sensoryNerveNub > 0 && hiddenNerveNub > 0 && outNerveNub > 0 && hiddenDepth > 0 && activeFunction != null) { this.hiddenNerveNub = hiddenNerveNub; this.sensoryNerveNub = sensoryNerveNub; @@ -219,6 +207,9 @@ public class NerveManager { this.activeFunction = activeFunction; this.isDynamic = isDynamic; this.isAccurate = isAccurate; + if (studyPoint > 0 && studyPoint < 1) { + this.studyPoint = studyPoint; + } } else { throw new Exception("param is null"); } diff --git a/src/main/java/org/wlld/nerveEntity/Nerve.java b/src/main/java/org/wlld/nerveEntity/Nerve.java index 0ece1d4..f9b9924 100644 --- a/src/main/java/org/wlld/nerveEntity/Nerve.java +++ b/src/main/java/org/wlld/nerveEntity/Nerve.java @@ -22,7 +22,7 @@ public abstract class Nerve { private int id;//同级神经元编号,注意在同层编号中ID应有唯一性 protected int upNub;//上一层神经元数量 protected int downNub;//下一层神经元的数量 - protected Map> features = new HashMap<>(); + protected Map> features = new HashMap<>();//上一层神经元输入的数值 protected Matrix nerveMatrix = new Matrix(3, 3);//权重矩阵可获取及注入 protected Map matrixMap = new HashMap<>();//参数矩阵 protected double threshold;//此神经元的阈值需要取出 @@ -265,9 +265,7 @@ public abstract class Nerve { double w = dendrites.get(i + 1); //System.out.println("w==" + w + ",value==" + value); sigma = ArithUtil.add(ArithUtil.mul(w, value), sigma); - //logger.debug("name:{},eventId:{},id:{},myId:{},w:{},value:{}", name, eventId, i + 1, id, w, value); } - //logger.debug("当前神经元线性变化已经完成,name:{},id:{}", name, getId()); return ArithUtil.sub(sigma, threshold); } diff --git a/src/main/java/org/wlld/nerveEntity/OutNerve.java b/src/main/java/org/wlld/nerveEntity/OutNerve.java index bdacda9..763a237 100644 --- a/src/main/java/org/wlld/nerveEntity/OutNerve.java +++ b/src/main/java/org/wlld/nerveEntity/OutNerve.java @@ -46,7 +46,7 @@ public class OutNerve extends Nerve { if (E.containsKey(getId())) { this.E = E.get(getId()); } else { - this.E = -1; + this.E = 0; } if (isShowLog) { System.out.println("E==" + this.E + ",out==" + out + ",nerveId==" + getId()); @@ -71,10 +71,6 @@ public class OutNerve extends Nerve { Matrix myMatrix = dynamicNerve(matrix, eventId, isKernelStudy); if (isKernelStudy) {//回传 Matrix matrix1 = matrixMapE.get(E); -// if (isShowLog) { -// System.out.println("E================" + E); -// System.out.println(myMatrix.getString()); -// } if (matrix1.getX() <= myMatrix.getX() && matrix1.getY() <= myMatrix.getY()) { double g = getGradient(myMatrix, matrix1); backMatrix(g, eventId); diff --git a/src/test/java/coverTest/FoodTest.java b/src/test/java/coverTest/FoodTest.java new file mode 100644 index 0000000..4ffa518 --- /dev/null +++ b/src/test/java/coverTest/FoodTest.java @@ -0,0 +1,153 @@ +package coverTest; + +import com.alibaba.fastjson.JSON; +import org.wlld.MatrixTools.Matrix; +import org.wlld.ModelData; +import org.wlld.config.Classifier; +import org.wlld.config.StudyPattern; +import org.wlld.imageRecognition.Operation; +import org.wlld.imageRecognition.Picture; +import org.wlld.imageRecognition.TempleConfig; +import org.wlld.nerveEntity.ModelParameter; +import org.wlld.tools.ArithUtil; + +import java.util.HashMap; +import java.util.Map; + +public class FoodTest { + public static void main(String[] args) throws Exception { + food(); + } + + public static void food() throws Exception { + Picture picture = new Picture(); + TempleConfig templeConfig = new TempleConfig(false, true); + templeConfig.setClassifier(Classifier.DNN); + templeConfig.isShowLog(true); + templeConfig.init(StudyPattern.Accuracy_Pattern, true, 640, 640, 4); + ModelParameter modelParameter2 = JSON.parseObject(ModelData.DATA3, ModelParameter.class); + templeConfig.insertModel(modelParameter2); + Operation operation = new Operation(templeConfig); + // 一阶段 +// for (int j = 0; j < 1; j++) { +// for (int i = 1; i < 1900; i++) {//一阶段 +// System.out.println("study1===================" + i); +// //读取本地URL地址图片,并转化成矩阵 +// Matrix a = picture.getImageMatrixByLocal("D:\\share\\picture/a" + i + ".jpg"); +// Matrix b = picture.getImageMatrixByLocal("D:\\share\\picture/b" + i + ".jpg"); +// Matrix c = picture.getImageMatrixByLocal("D:\\share\\picture/c" + i + ".jpg"); +// Matrix d = picture.getImageMatrixByLocal("D:\\share\\picture/d" + i + ".jpg"); +// //将图像矩阵和标注加入进行学习,Accuracy_Pattern 模式 进行第二次学习 +// //第二次学习的时候,第三个参数必须是 true +// operation.learning(a, 1, false); +// operation.learning(b, 2, false); +// operation.learning(c, 3, false); +// operation.learning(d, 4, false); +// } +// } + + //二阶段 +// for (int i = 1; i < 1900; i++) { +// System.out.println("avg==" + i); +// Matrix a = picture.getImageMatrixByLocal("D:\\share\\picture/a" + i + ".jpg"); +// Matrix b = picture.getImageMatrixByLocal("D:\\share\\picture/b" + i + ".jpg"); +// Matrix c = picture.getImageMatrixByLocal("D:\\share\\picture/c" + i + ".jpg"); +// Matrix d = picture.getImageMatrixByLocal("D:\\share\\picture/d" + i + ".jpg"); +// operation.normalization(a, templeConfig.getConvolutionNerveManager()); +// operation.normalization(b, templeConfig.getConvolutionNerveManager()); +// operation.normalization(c, templeConfig.getConvolutionNerveManager()); +// operation.normalization(d, templeConfig.getConvolutionNerveManager()); +// } +// templeConfig.getNormalization().avg(); + for (int j = 0; j < 1; j++) { + for (int i = 1; i < 1900; i++) { + System.out.println("j==" + j + ",study2==================" + i); + //读取本地URL地址图片,并转化成矩阵 + Matrix a = picture.getImageMatrixByLocal("D:\\share\\picture/a" + i + ".jpg"); + Matrix b = picture.getImageMatrixByLocal("D:\\share\\picture/b" + i + ".jpg"); + Matrix c = picture.getImageMatrixByLocal("D:\\share\\picture/c" + i + ".jpg"); + Matrix d = picture.getImageMatrixByLocal("D:\\share\\picture/d" + i + ".jpg"); + //将图像矩阵和标注加入进行学习,Accuracy_Pattern 模式 进行第二次学习 + //第二次学习的时候,第三个参数必须是 true + operation.learning(a, 1, true); + operation.learning(b, 2, true); + operation.learning(c, 3, true); + operation.learning(d, 4, true); + } + } + + templeConfig.finishStudy();//结束学习 + ModelParameter modelParameter = templeConfig.getModel(); + String model = JSON.toJSONString(modelParameter); + System.out.println(model); +// ModelParameter modelParameter2 = JSON.parseObject(model, ModelParameter.class); +// TempleConfig templeConfig2 = new TempleConfig(false); +// templeConfig2.init(StudyPattern.Accuracy_Pattern, true, 1000, 1000, 2); +// templeConfig2.insertModel(modelParameter2); + + // Operation operation2 = new Operation(templeConfig2); + int wrong = 0; + int allNub = 0; + for (int i = 1900; i <= 1998; i++) { + //读取本地URL地址图片,并转化成矩阵 + Matrix a = picture.getImageMatrixByLocal("D:\\share\\picture/a" + i + ".jpg"); + Matrix b = picture.getImageMatrixByLocal("D:\\share\\picture/b" + i + ".jpg"); + Matrix c = picture.getImageMatrixByLocal("D:\\share\\picture/c" + i + ".jpg"); + Matrix d = picture.getImageMatrixByLocal("D:\\share\\picture/d" + i + ".jpg"); + //将图像矩阵和标注加入进行学习,Accuracy_Pattern 模式 进行第二次学习 + //第二次学习的时候,第三个参数必须是 true + allNub += 4; + int an = operation.toSee(a); + //System.out.println("an============1"); + if (an != 1) { + //System.out.println("a错了"); + wrong++; + } + int bn = operation.toSee(b); + //System.out.println("bn============2"); + if (bn != 2) { + // System.out.println("b错了"); + wrong++; + } + int cn = operation.toSee(c); + // System.out.println("cn============3"); + if (cn != 3) { + //System.out.println("c错了"); + wrong++; + } + int dn = operation.toSee(d); + // System.out.println("dn============4"); + if (dn != 4) { + // System.out.println("d错了"); + wrong++; + } + } + double wrongPoint = ArithUtil.div(wrong, allNub); + System.out.println("错误率1:" + (wrongPoint * 100) + "%"); + } + public static void test1() throws Exception {//覆盖率计算 + Picture picture = new Picture(); + TempleConfig templeConfig = new TempleConfig(false, true); + templeConfig.init(StudyPattern.Cover_Pattern, true, 320, 240, 2); + Operation operation = new Operation(templeConfig); + Map rightTagging = new HashMap<>();//分类标注 + Map wrongTagging = new HashMap<>();//分类标注 + rightTagging.put(1, 1.0); + wrongTagging.put(2, 1.0); + Matrix right = picture.getImageMatrixByLocal("/Users/lidapeng/Desktop/picture/yes1.jpg"); + Matrix wrong = picture.getImageMatrixByLocal("/Users/lidapeng/Desktop/picture/no4.jpg"); + int a = 1; + for (int i = 0; i < a; i++) { + operation.coverStudy(right, rightTagging, wrong, wrongTagging); + } + System.out.println("学习完成"); + long sys = System.currentTimeMillis(); + double point = operation.coverPoint(right, 1); + long sys2 = System.currentTimeMillis(); + long sys3 = sys2 - sys; + double point2 = operation.coverPoint(wrong, 1); + System.out.println("识别耗时:" + sys3); + System.out.println("测试覆盖1:" + point + ",测试覆盖2:" + point2); + + } +} diff --git a/src/test/java/org/wlld/App.java b/src/test/java/org/wlld/App.java deleted file mode 100644 index ec718e9..0000000 --- a/src/test/java/org/wlld/App.java +++ /dev/null @@ -1,108 +0,0 @@ -package org.wlld; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; -import org.wlld.MatrixTools.Matrix; -import org.wlld.config.StudyPattern; -import org.wlld.function.Sigmod; -import org.wlld.imageRecognition.Operation; -import org.wlld.imageRecognition.Picture; -import org.wlld.imageRecognition.TempleConfig; -import org.wlld.imageRecognition.border.Frame; -import org.wlld.imageRecognition.border.FrameBody; -import org.wlld.nerveCenter.NerveManager; -import org.wlld.nerveEntity.ModelParameter; -import org.wlld.nerveEntity.SensoryNerve; - -import java.util.*; - -/** - * Hello world! - */ -public class App { - public static void main(String[] args) throws Exception { - test3(); - } - - public static void test3() throws Exception { - NerveManager nerveManager = new NerveManager(3, 6, 3 - , 3, new Sigmod(), false, true); - nerveManager.init(true, false, false);//初始化 - List> data = new ArrayList<>();//正样本 - List> dataB = new ArrayList<>();//负样本 - List> dataC = new ArrayList<>();//负样本 - Random random = new Random(); - for (int i = 0; i < 4000; i++) { - Map map1 = new HashMap<>(); - Map map2 = new HashMap<>(); - Map map3 = new HashMap<>(); - map1.put(0, 1 + random.nextDouble()); - map1.put(1, 1 + random.nextDouble()); - map1.put(2, 0.0); - //产生鲜明区分 - map2.put(0, random.nextDouble()); - map2.put(1, random.nextDouble()); - map2.put(2, 0.0); - // - map3.put(0, 2 + random.nextDouble()); - map3.put(1, 2 + random.nextDouble()); - map3.put(2, 0.0); - data.add(map1); - dataB.add(map2); - dataC.add(map3); - } - Map right = new HashMap<>(); - Map wrong = new HashMap<>(); - Map other = new HashMap<>(); - right.put(1, 1.0); - - wrong.put(2, 1.0); - - other.put(3, 1.0); - for (int i = 0; i < data.size(); i++) { - Map map1 = data.get(i); - Map map2 = dataB.get(i); - Map map3 = dataC.get(i); - post(nerveManager.getSensoryNerves(), map1, right, null, true); - post(nerveManager.getSensoryNerves(), map2, wrong, null, true); - post(nerveManager.getSensoryNerves(), map3, other, null, true); - } - - List> data2 = new ArrayList<>(); - List> data2B = new ArrayList<>(); - List> data2C = new ArrayList<>();//负样本 - for (int i = 0; i < 20; i++) { - Map map1 = new HashMap<>(); - Map map2 = new HashMap<>(); - Map map3 = new HashMap<>(); - map1.put(0, 1 + random.nextDouble()); - map1.put(1, 1 + random.nextDouble()); - map1.put(2, 0.0); - - map2.put(0, random.nextDouble()); - map2.put(1, random.nextDouble()); - map2.put(2, 0.0); - - map3.put(0, 2 + random.nextDouble()); - map3.put(1, 2 + random.nextDouble()); - map3.put(2, 0.0); - data2.add(map1); - data2B.add(map2); - data2C.add(map3); - } - Back back = new Back(); - for (Map map : data2) { - post(nerveManager.getSensoryNerves(), map, null, back, false); - System.out.println("====================="); - } - } - - public static void post(List sensoryNerveList, Map data - , Map tagging, Back back, boolean isStudy) throws Exception { - int size = sensoryNerveList.size(); - for (int i = 0; i < size; i++) { - sensoryNerveList.get(i).postMessage(1, data.get(i), isStudy, tagging, back); - } - } - -} diff --git a/src/test/java/org/wlld/HelloWorld.java b/src/test/java/org/wlld/HelloWorld.java index 1518adb..26eef72 100644 --- a/src/test/java/org/wlld/HelloWorld.java +++ b/src/test/java/org/wlld/HelloWorld.java @@ -1,194 +1,106 @@ package org.wlld; import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; import org.wlld.MatrixTools.Matrix; import org.wlld.config.Classifier; import org.wlld.config.StudyPattern; import org.wlld.imageRecognition.Operation; import org.wlld.imageRecognition.Picture; import org.wlld.imageRecognition.TempleConfig; -import org.wlld.imageRecognition.ThreeChannelMatrix; -import org.wlld.imageRecognition.border.Frame; -import org.wlld.imageRecognition.border.FrameBody; import org.wlld.nerveEntity.ModelParameter; import org.wlld.tools.ArithUtil; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.io.InputStream; /** * @author lidapeng - * @description 测试入口类 + * @description 图像测试入口类 * @date 11:35 上午 2020/1/18 */ public class HelloWorld { + static TempleConfig templeConfig = new TempleConfig(false, true); + + static {//初始化静态配置模板 + try { + //使用DNN 分类器 + templeConfig.setClassifier(Classifier.DNN); + //初始化 + templeConfig.init(StudyPattern.Accuracy_Pattern, true, 640, 640, 4); + //从数据库里把模型拿出来,并反序列化成模型 + ModelParameter modelParameter2 = JSON.parseObject(ModelData.DATA3, ModelParameter.class); + //模型注入配置模板 + templeConfig.insertModel(modelParameter2); + } catch (Exception e) { + e.printStackTrace(); + } + } + public static void main(String[] args) throws Exception { - //test1(); - food(); + pictureDemo1(); } - public static void test() throws Exception { + public static void pictureDemo1() throws Exception {//图像学习DEMO Picture picture = new Picture(); - TempleConfig templeConfig = new TempleConfig(true, true); + //使用精度计算 + TempleConfig templeConfig = new TempleConfig(false, true); + //使用DNN分类器 templeConfig.setClassifier(Classifier.DNN); - templeConfig.init(StudyPattern.Accuracy_Pattern, true, 1000, 1000, 3); + //打印学习过程中产生的参数 + templeConfig.isShowLog(true); + //初始化配置模板,使用精确模式,第一次学习,640宽度,640高度的训练照片,有四种分类的物体学习 + templeConfig.init(StudyPattern.Accuracy_Pattern, true, 640, 640, 4); + //初始化运算类 Operation operation = new Operation(templeConfig); - for (int i = 1; i < 300; i++) {//一阶段 + // 一阶段学习 + for (int i = 1; i < 1900; i++) {//一阶段 System.out.println("study1===================" + i); //读取本地URL地址图片,并转化成矩阵 - ThreeChannelMatrix a = picture.getThreeMatrix("/Users/lidapeng/Desktop/myDocment/picture/a" + i + ".jpg"); - //Matrix b = picture.getImageMatrixByLocal("/Users/lidapeng/Desktop/myDocment/picture/b" + i + ".jpg"); - ThreeChannelMatrix c = picture.getThreeMatrix("/Users/lidapeng/Desktop/myDocment/picture/c" + i + ".jpg"); - //将图像矩阵和标注加入进行学习,Accuracy_Pattern 模式 进行第二次学习 - //第二次学习的时候,第三个参数必须是 true - // operation.learning(f, 0, false); - operation.threeLearning(a, 1, false); - //operation.learning(b, 2, false); - operation.threeLearning(c, 2, false); + Matrix a = picture.getImageMatrixByLocal("D:\\share\\picture/a" + i + ".jpg"); + Matrix b = picture.getImageMatrixByLocal("D:\\share\\picture/b" + i + ".jpg"); + Matrix c = picture.getImageMatrixByLocal("D:\\share\\picture/c" + i + ".jpg"); + Matrix d = picture.getImageMatrixByLocal("D:\\share\\picture/d" + i + ".jpg"); + operation.learning(a, 1, false); + operation.learning(b, 2, false); + operation.learning(c, 3, false); + operation.learning(d, 4, false); } - for (int i = 1; i < 300; i++) { - ThreeChannelMatrix a = picture.getThreeMatrix("/Users/lidapeng/Desktop/myDocment/picture/a" + i + ".jpg"); - //Matrix b = picture.getImageMatrixByLocal("/Users/lidapeng/Desktop/myDocment/picture/b" + i + ".jpg"); - ThreeChannelMatrix c = picture.getThreeMatrix("/Users/lidapeng/Desktop/myDocment/picture/c" + i + ".jpg"); - operation.threeNormalization(a); - //operation.normalization(b); - operation.threeNormalization(c); + + //二阶段学习 + for (int i = 1; i < 1900; i++) { + System.out.println("avg==" + i); + Matrix a = picture.getImageMatrixByLocal("D:\\share\\picture/a" + i + ".jpg"); + Matrix b = picture.getImageMatrixByLocal("D:\\share\\picture/b" + i + ".jpg"); + Matrix c = picture.getImageMatrixByLocal("D:\\share\\picture/c" + i + ".jpg"); + Matrix d = picture.getImageMatrixByLocal("D:\\share\\picture/d" + i + ".jpg"); + operation.normalization(a, templeConfig.getConvolutionNerveManager()); + operation.normalization(b, templeConfig.getConvolutionNerveManager()); + operation.normalization(c, templeConfig.getConvolutionNerveManager()); + operation.normalization(d, templeConfig.getConvolutionNerveManager()); } templeConfig.getNormalization().avg(); - for (int i = 1; i < 300; i++) { + //三阶段学习 + for (int i = 1; i < 1900; i++) { System.out.println("study2==================" + i); //读取本地URL地址图片,并转化成矩阵 - ThreeChannelMatrix a = picture.getThreeMatrix("/Users/lidapeng/Desktop/myDocment/picture/a" + i + ".jpg"); - // Matrix b = picture.getImageMatrixByLocal("/Users/lidapeng/Desktop/myDocment/picture/b" + i + ".jpg"); - ThreeChannelMatrix c = picture.getThreeMatrix("/Users/lidapeng/Desktop/myDocment/picture/c" + i + ".jpg"); - //Matrix d = picture.getImageMatrixByLocal("/Users/lidapeng/Desktop/myDocment/picture/d" + i + ".jpg"); - operation.threeLearning(a, 1, true); - operation.threeLearning(c, 2, true); - - } - int wrong = 0; - int allNub = 0; - for (int i = 300; i <= 320; i++) { - //读取本地URL地址图片,并转化成矩阵 - ThreeChannelMatrix a = picture.getThreeMatrix("/Users/lidapeng/Desktop/myDocment/picture/a" + i + ".jpg"); - // Matrix b = picture.getImageMatrixByLocal("/Users/lidapeng/Desktop/myDocment/picture/b" + i + ".jpg"); - ThreeChannelMatrix c = picture.getThreeMatrix("/Users/lidapeng/Desktop/myDocment/picture/c" + i + ".jpg"); + Matrix a = picture.getImageMatrixByLocal("D:\\share\\picture/a" + i + ".jpg"); + Matrix b = picture.getImageMatrixByLocal("D:\\share\\picture/b" + i + ".jpg"); + Matrix c = picture.getImageMatrixByLocal("D:\\share\\picture/c" + i + ".jpg"); + Matrix d = picture.getImageMatrixByLocal("D:\\share\\picture/d" + i + ".jpg"); //将图像矩阵和标注加入进行学习,Accuracy_Pattern 模式 进行第二次学习 //第二次学习的时候,第三个参数必须是 true - allNub += 2; - int an = operation.toThreeSee(a); - int cn = operation.toThreeSee(c); - if (an != 1) { - wrong++; - } - if (cn != 2) { - wrong++; - } + operation.learning(a, 1, true); + operation.learning(b, 2, true); + operation.learning(c, 3, true); + operation.learning(d, 4, true); } - double wrongPoint = ArithUtil.div(wrong, allNub); - System.out.println("错误率:" + (wrongPoint * 100) + "%"); - } - public static void food2() throws Exception { - Picture picture = new Picture(); - TempleConfig templeConfig = new TempleConfig(false, true); - templeConfig.init(StudyPattern.Speed_Pattern, true, 1000, 1000, 2); - Operation operation = new Operation(templeConfig); - Map right = new HashMap<>(); - Map wrong = new HashMap<>(); - right.put(1, 1.0); - wrong.put(2, 1.0); - for (int j = 0; j < 20; j++) { - for (int i = 1; i < 1500; i++) {//一阶段 - System.out.println("study1===================" + i); - //读取本地URL地址图片,并转化成矩阵 - Matrix a = picture.getImageMatrixByLocal("/Users/lidapeng/Desktop/myDocment/picture/a" + i + ".jpg"); - Matrix c = picture.getImageMatrixByLocal("/Users/lidapeng/Desktop/myDocment/picture/c" + i + ".jpg"); - operation.study(a, right); - operation.study(c, wrong); - - } - } - - } - - public static void food() throws Exception { - Picture picture = new Picture(); - TempleConfig templeConfig = new TempleConfig(false, true); - //templeConfig.setHavePosition(true); -// Frame frame = new Frame(); -// frame.setWidth(640); -// frame.setHeight(640); -// frame.setLengthHeight(640); -// frame.setLengthWidth(640); -// templeConfig.setFrame(frame); - templeConfig.setClassifier(Classifier.DNN); - templeConfig.isShowLog(true); - templeConfig.init(StudyPattern.Accuracy_Pattern, true, 640, 640, 4); - ModelParameter modelParameter2 = JSON.parseObject(ModelData.DATA3, ModelParameter.class); - templeConfig.insertModel(modelParameter2); - Operation operation = new Operation(templeConfig); - //a b c d 物品 e是背景 - // 一阶段 -// for (int j = 0; j < 1; j++) { -// for (int i = 1; i < 1900; i++) {//一阶段 -// System.out.println("study1===================" + i); -// //读取本地URL地址图片,并转化成矩阵 -// Matrix a = picture.getImageMatrixByLocal("D:\\share\\picture/a" + i + ".jpg"); -// Matrix b = picture.getImageMatrixByLocal("D:\\share\\picture/b" + i + ".jpg"); -// Matrix c = picture.getImageMatrixByLocal("D:\\share\\picture/c" + i + ".jpg"); -// Matrix d = picture.getImageMatrixByLocal("D:\\share\\picture/d" + i + ".jpg"); -// //将图像矩阵和标注加入进行学习,Accuracy_Pattern 模式 进行第二次学习 -// //第二次学习的时候,第三个参数必须是 true -// operation.learning(a, 1, false); -// operation.learning(b, 2, false); -// operation.learning(c, 3, false); -// operation.learning(d, 4, false); -// } -// } - - //二阶段 -// for (int i = 1; i < 1900; i++) { -// System.out.println("avg==" + i); -// Matrix a = picture.getImageMatrixByLocal("D:\\share\\picture/a" + i + ".jpg"); -// Matrix b = picture.getImageMatrixByLocal("D:\\share\\picture/b" + i + ".jpg"); -// Matrix c = picture.getImageMatrixByLocal("D:\\share\\picture/c" + i + ".jpg"); -// Matrix d = picture.getImageMatrixByLocal("D:\\share\\picture/d" + i + ".jpg"); -// operation.normalization(a, templeConfig.getConvolutionNerveManager()); -// operation.normalization(b, templeConfig.getConvolutionNerveManager()); -// operation.normalization(c, templeConfig.getConvolutionNerveManager()); -// operation.normalization(d, templeConfig.getConvolutionNerveManager()); -// } -// templeConfig.getNormalization().avg(); - for (int j = 0; j < 1; j++) { - for (int i = 1; i < 1900; i++) { - System.out.println("j==" + j + ",study2==================" + i); - //读取本地URL地址图片,并转化成矩阵 - Matrix a = picture.getImageMatrixByLocal("D:\\share\\picture/a" + i + ".jpg"); - Matrix b = picture.getImageMatrixByLocal("D:\\share\\picture/b" + i + ".jpg"); - Matrix c = picture.getImageMatrixByLocal("D:\\share\\picture/c" + i + ".jpg"); - Matrix d = picture.getImageMatrixByLocal("D:\\share\\picture/d" + i + ".jpg"); - //将图像矩阵和标注加入进行学习,Accuracy_Pattern 模式 进行第二次学习 - //第二次学习的时候,第三个参数必须是 true - operation.learning(a, 1, true); - operation.learning(b, 2, true); - operation.learning(c, 3, true); - operation.learning(d, 4, true); - } - } templeConfig.finishStudy();//结束学习 ModelParameter modelParameter = templeConfig.getModel(); String model = JSON.toJSONString(modelParameter); - System.out.println(model); -// ModelParameter modelParameter2 = JSON.parseObject(model, ModelParameter.class); -// TempleConfig templeConfig2 = new TempleConfig(false); -// templeConfig2.init(StudyPattern.Accuracy_Pattern, true, 1000, 1000, 2); -// templeConfig2.insertModel(modelParameter2); - - // Operation operation2 = new Operation(templeConfig2); + //我把学到的模型拿出来啦! + System.out.println("my model is:" + model); + //验证一下准确率 int wrong = 0; int allNub = 0; for (int i = 1900; i <= 1998; i++) { @@ -201,90 +113,34 @@ public class HelloWorld { //第二次学习的时候,第三个参数必须是 true allNub += 4; int an = operation.toSee(a); - int bn = operation.toSee(b); - int cn = operation.toSee(c); - int dn = operation.toSee(d); if (an != 1) { wrong++; } + int bn = operation.toSee(b); if (bn != 2) { wrong++; } + int cn = operation.toSee(c); if (cn != 3) { wrong++; } + int dn = operation.toSee(d); if (dn != 4) { wrong++; } } double wrongPoint = ArithUtil.div(wrong, allNub); System.out.println("错误率1:" + (wrongPoint * 100) + "%"); - -// wrong = 0; -// allNub = 0; -// for (int i = 300; i <= 320; i++) { -// //读取本地URL地址图片,并转化成矩阵 -// Matrix a = picture.getImageMatrixByLocal("/Users/lidapeng/Desktop/myDocment/picture/a" + i + ".jpg"); -// //Matrix b = picture.getImageMatrixByLocal("/Users/lidapeng/Desktop/myDocment/picture/b" + i + ".jpg"); -// Matrix c = picture.getImageMatrixByLocal("/Users/lidapeng/Desktop/myDocment/picture/c" + i + ".jpg"); -// //Matrix d = picture.getImageMatrixByLocal("/Users/lidapeng/Desktop/myDocment/picture/d" + i + ".jpg"); -// //将图像矩阵和标注加入进行学习,Accuracy_Pattern 模式 进行第二次学习 -// //第二次学习的时候,第三个参数必须是 true -// allNub += 2; -// int an = operation2.toSee(a); -// int cn = operation2.toSee(c); -// if (an != 1) { -// wrong++; -// } -// if (cn != 2) { -// wrong++; -// } -// } -// wrongPoint = ArithUtil.div(wrong, allNub); -// System.out.println("错误率2:" + (wrongPoint * 100) + "%"); -// ModelParameter modelParameter2 = templeConfig.getModel(); -// String model1 = JSON.toJSONString(modelParameter2); -// System.out.println("完成阶段==" + model1); } - - public static void test1() throws Exception {//覆盖率计算 - Picture picture = new Picture(); - TempleConfig templeConfig = new TempleConfig(false, true); - templeConfig.init(StudyPattern.Cover_Pattern, true, 320, 240, 2); + public static int testPicDemo(InputStream imageStream) throws Exception {//识别图片 + //配置模板塞入运算类 Operation operation = new Operation(templeConfig); - Map rightTagging = new HashMap<>();//分类标注 - Map wrongTagging = new HashMap<>();//分类标注 - rightTagging.put(1, 1.0); - wrongTagging.put(2, 1.0); - Matrix right = picture.getImageMatrixByLocal("/Users/lidapeng/Desktop/picture/yes1.jpg"); - Matrix wrong = picture.getImageMatrixByLocal("/Users/lidapeng/Desktop/picture/no4.jpg"); - int a = 1; - for (int i = 0; i < a; i++) { - operation.coverStudy(right, rightTagging, wrong, wrongTagging); - } - System.out.println("学习完成"); - long sys = System.currentTimeMillis(); - double point = operation.coverPoint(right, 1); - long sys2 = System.currentTimeMillis(); - long sys3 = sys2 - sys; - double point2 = operation.coverPoint(wrong, 1); - System.out.println("识别耗时:" + sys3); - System.out.println("测试覆盖1:" + point + ",测试覆盖2:" + point2); - - } - - private static void compare(List point, List point2) { - int size = point.size(); - int max = 0; - int min = 0; - for (int i = 0; i < size; i++) { - if (point.get(i) >= point2.get(i)) { - max++; - } else { - min++; - } - } - System.out.println("size==" + size + ",max==" + max + ",min==" + min); + //图片解析类 + Picture picture = new Picture(); + //获取矩阵 + Matrix a = picture.getImageMatrixByIo(imageStream); + int type = operation.toSee(a);//返回图片类别 + return type; } } diff --git a/src/test/java/org/wlld/LangTest.java b/src/test/java/org/wlld/LangTest.java index 6d95f77..4480bda 100644 --- a/src/test/java/org/wlld/LangTest.java +++ b/src/test/java/org/wlld/LangTest.java @@ -14,21 +14,6 @@ import java.util.*; */ public class LangTest { public static void main(String[] args) throws Exception { - List listAll = new ArrayList<>(); - List list = new ArrayList<>(); - List list2 = new ArrayList<>(); - List list3 = new ArrayList<>(); - list.add(1.0); - list.add(2.0); - list2.add(3.0); - list2.add(4.0); - list3.add(5.0); - list3.add(6.0); - listAll.addAll(list); - listAll.addAll(list2); - listAll.addAll(list3); - System.out.println(listAll); - //test1(); } public static void test1() throws Exception { diff --git a/src/test/java/org/wlld/MatrixTest.java b/src/test/java/org/wlld/MatrixTest.java deleted file mode 100644 index f301acf..0000000 --- a/src/test/java/org/wlld/MatrixTest.java +++ /dev/null @@ -1,126 +0,0 @@ -package org.wlld; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; -import org.wlld.MatrixTools.Matrix; -import org.wlld.MatrixTools.MatrixOperation; -import org.wlld.randomForest.DataTable; -import org.wlld.randomForest.Node; -import org.wlld.randomForest.Tree; - -import java.awt.*; -import java.util.*; - -/** - * @author lidapeng - * @description - * @date 3:35 下午 2020/1/23 - */ -public class MatrixTest { - public static void main(String[] args) throws Exception { - test4(); - } - - public static void test4() throws Exception { - Set column = new HashSet<>(); - column.add("height"); - column.add("weight"); - column.add("sex"); - column.add("h1"); - column.add("h2"); - DataTable dataTable = new DataTable(column); - dataTable.setKey("sex"); - Random random = new Random(); - int cla = 3; - for (int i = 0; i < 50; i++) { - Food food = new Food(); - food.setHeight(random.nextInt(cla)); - food.setWeight(random.nextInt(cla)); - food.setSex(random.nextInt(cla)); - food.setH1(random.nextInt(cla)); - food.setH2(random.nextInt(cla)); - dataTable.insert(food); - } - Tree tree = new Tree(dataTable); - tree.study(); - Node node = tree.getRootNode(); - String a = JSON.toJSONString(node); - Node node1 = JSONObject.parseObject(a, Node.class); - //// - Tree tree2 = new Tree(dataTable); - tree2.setRootNode(node1); - for (int i = 0; i < 10; i++) { - Food food = new Food(); - food.setHeight(random.nextInt(cla)); - food.setWeight(random.nextInt(cla)); - food.setSex(random.nextInt(cla)); - food.setH1(random.nextInt(cla)); - food.setH2(random.nextInt(cla)); - int type = tree.judge(food).getType(); - int type2 = tree2.judge(food).getType(); - if (type != type2) { - System.out.println("出错,type1==" + type + ",type2==" + type2); - } else { - System.out.println(type); - } - } - System.out.println("结束"); - - } - - - public static void test3() throws Exception { - Matrix matrix = new Matrix(4, 3); - Matrix matrixY = new Matrix(4, 1); - String b = "[7]#" + - "[8]#" + - "[9]#" + - "[19]#"; - matrixY.setAll(b); - String a = "[1,2,17]#" + - "[3,4,18]#" + - "[5,6,10]#" + - "[15,16,13]#"; - matrix.setAll(a); - //将参数矩阵转置 - Matrix matrix1 = MatrixOperation.transPosition(matrix); - //转置的参数矩阵乘以参数矩阵 - Matrix matrix2 = MatrixOperation.mulMatrix(matrix1, matrix); - //求上一步的逆矩阵 - Matrix matrix3 = MatrixOperation.getInverseMatrixs(matrix2); - //逆矩阵乘以转置矩阵 - Matrix matrix4 = MatrixOperation.mulMatrix(matrix3, matrix1); - //最后乘以输出矩阵,生成权重矩阵 - Matrix matrix5 = MatrixOperation.mulMatrix(matrix4, matrixY); - System.out.println(matrix5.getString()); - } - - public static void test1() throws Exception { - Matrix matrix = new Matrix(2, 2); - Matrix matrix2 = new Matrix(1, 5); - String b = "[6,7,8,9,10]#"; - String a = "[1,2]#" + - "[3,4]#"; - matrix.setAll(a); - matrix2.setAll(b); - Matrix matrix1 = MatrixOperation.matrixToVector(matrix, true); - matrix1 = MatrixOperation.push(matrix1, 5, true); - matrix1 = MatrixOperation.pushVector(matrix1, matrix2, true); - System.out.println(matrix1.getString()); - } - - public static void test2() throws Exception { - Matrix matrix = new Matrix(2, 2); - Matrix matrix1 = new Matrix(1, 5); - String a = "[1,2]#" + - "[3,4]#"; - String b = "[6,7,8,9,10]#"; - matrix.setAll(a); - matrix1.setAll(b); - matrix1 = MatrixOperation.matrixToVector(matrix1, false); - matrix = MatrixOperation.matrixToVector(matrix, false); - matrix = MatrixOperation.push(matrix, 5, true); - matrix = MatrixOperation.pushVector(matrix, matrix1, false); - System.out.println(matrix.getString()); - } -} diff --git a/src/test/java/org/wlld/ModelData.java b/src/test/java/org/wlld/ModelData.java index f934841..6bd56f0 100644 --- a/src/test/java/org/wlld/ModelData.java +++ b/src/test/java/org/wlld/ModelData.java @@ -6,12 +6,12 @@ package org.wlld; * @date 9:49 上午 2020/1/31 */ public class ModelData { - //2 1500 0.5 - public static final String DATA = "{\"avg\":0.0,\"borderMap\":{},\"depthNerves\":[[{\"dendrites\":{1:1.213774207111617,2:0.8268137063553612,3:0.6280652124934316,4:0.19376000961255},\"threshold\":0.8165021030427071},{\"dendrites\":{1:0.04460212963683248,2:-0.4654321282143022,3:0.5352699172849223,4:0.5147681165412048},\"threshold\":-0.18748297475744544},{\"dendrites\":{1:1.7535985842788788,2:1.9320990243767278,3:0.7956830581675305,4:0.13115933427855633},\"threshold\":0.3161712461985831},{\"dendrites\":{1:2.005355581058438,2:2.096503235621598,3:1.0255001142294158,4:-0.3415180302752453},\"threshold\":0.4490619825682428},{\"dendrites\":{1:1.426772347120373,2:0.8233726920744929,3:0.2935972267531232,4:0.21994926089778308},\"threshold\":0.5012754479271677},{\"dendrites\":{1:1.4219257622892896,2:1.208652167162009,3:0.2154646249238634,4:0.7689616217564992},\"threshold\":0.11423213519486948},{\"dendrites\":{1:1.3453504287367442,2:1.5823527753464686,3:0.3892803612259637,4:0.23348010533846048},\"threshold\":0.2137214574768484},{\"dendrites\":{1:1.1744309622501712,2:1.5769028429728649,3:0.12504528204127002,4:0.5385503162534262},\"threshold\":0.18342704367141174},{\"dendrites\":{1:1.5123386529784142,2:1.629644262099775,3:0.6632271052431663,4:0.40395695744141197},\"threshold\":0.44957479494089325}],[{\"dendrites\":{1:0.9181531489918668,2:-0.406917512384619,3:1.2053497549981993,4:1.1097370538627105,5:0.5960909111211719,6:0.5482381905194215,7:0.5992388230533979,8:0.5471558038485723,9:0.772686160769771},\"threshold\":1.8083965979087755},{\"dendrites\":{1:0.5720734342199842,2:-0.66219374788196,3:1.170778192540959,4:1.7703214116363217,5:0.7094562409036175,6:0.8343764237781534,7:1.0776347150486234,8:1.2568054571829541,9:0.7129073292222449},\"threshold\":2.2305399654503977},{\"dendrites\":{1:0.42886769596230145,2:0.6503890739474025,3:0.062197388773750736,4:0.7326367865545156,5:0.5182882600861329,6:0.5830544657916861,7:0.03142818626113891,8:0.2444436296475533,9:0.05428996807327451},\"threshold\":0.9429786644578512},{\"dendrites\":{1:1.0584595297854744,2:0.5753994399096104,3:0.7486306476188948,4:0.18658101490261095,5:0.32299632213097235,6:0.8819619370458254,7:0.8157287121085394,8:0.5873266968451736,9:0.671077321094914},\"threshold\":-0.4002435882481297},{\"dendrites\":{1:0.4453969876892543,2:-0.42807530385758324,3:1.3986033236607598,4:0.8056088119411894,5:0.24310182682220613,6:0.5144201381524844,7:0.5124714382542945,8:0.9579821168606611,9:1.0588079911984782},\"threshold\":1.6034263380499667},{\"dendrites\":{1:0.38174161963404435,2:-0.4660018593033016,3:1.4350127432749935,4:1.490474012927967,5:0.4918444499970701,6:0.48433178420118767,7:1.11961980800604,8:0.6829347312399017,9:1.2845509814111973},\"threshold\":2.0993381011160377},{\"dendrites\":{1:0.7491209490985236,2:-0.028934798871836427,3:0.8587106969309863,4:0.3373369854974636,5:0.47667018189088795,6:0.936907842281443,7:0.20137524318756217,8:0.15809206401573406,9:0.5790294073253536},\"threshold\":0.5210228146608656},{\"dendrites\":{1:0.5461207740922938,2:0.5417661742770408,3:0.959010139222777,4:0.7700845566860144,5:0.15787702223512434,6:0.0815071584551707,7:0.7623280667950906,8:0.18611129516254676,9:0.193699887313603},\"threshold\":0.13557648438472322},{\"dendrites\":{1:1.0059126546970962,2:0.5006081353081548,3:0.6925373907156918,4:-0.06950491632348374,5:0.9987857960118185,6:0.6167905999536522,7:0.32149390968078684,8:0.8890591356151473,9:0.1793634508563284},\"threshold\":-0.5351552809709136}]],\"dnnAvg\":7.7029195417,\"dymNerveStudies\":[{\"list\":[0.3630608881688554,0.6112841790078187,0.6791435968753443,0.8953962096424452,0.08979515572520869,0.14208031110000685,0.7360992264475021,0.03316948051929214,0.8680468978155521],\"threshold\":0.3218663238216003},{\"list\":[0.9211057296698194,0.39935420153612167,0.2139196988379325,0.741269427386244,0.5023731407114069,0.35151387263419387,0.44278167943345215,0.5155984562853454,0.5641109390318313],\"threshold\":0.2574630978030212},{\"list\":[0.3001599126878609,0.5688504393895237,0.17787104477273274,0.3259163022256627,0.89845579165752,0.985786273699097,0.5968773072502469,0.6683659722192629,0.45945880255884497],\"threshold\":-0.0942016471516185},{\"list\":[0.44583388735427343,0.4931786829417687,0.33985790076237843,0.3412919671054543,0.6615486187220004,0.6066049282039497,0.3592571461879126,0.18850874781355575,0.6604918620281887],\"threshold\":-0.559251397736928}],\"dymOutNerveStudy\":{\"list\":[0.03381921319051118,0.29810490759417085,0.10630180342187245,0.4154622005182912,0.441593930236595,0.6986331121169781,0.16195374125458062,0.7422191828922098,0.6106824494172568],\"threshold\":-3.558008823587409},\"matrixK\":{},\"outNerves\":[{\"dendrites\":{1:-1.338789681358372,2:-2.1333287741667903,3:0.075373814720555,4:0.8480040581422015,5:-1.2234502988219473,6:-2.1870606087169104,7:-0.42897901117453285,8:0.2423554950067813,9:1.132742647014418},\"threshold\":-1.8203799068059194},{\"dendrites\":{1:1.6507058227468376,2:2.2444002197788055,3:0.32152155738136307,4:-0.5162100352508748,5:1.5591455190683947,6:1.7059786322371064,7:-0.014975986812336597,8:0.030031518421571417,9:-0.44044041246706894},\"threshold\":3.0199365903808237}]}"; + //测试tanh + public static final String DATA = "{\"avg\":0.0,\"borderMap\":{},\"depthNerves\":[[{\"dendrites\":{1:2.781391794071351,2:-0.7093530632219361,3:1.8907939664410403,4:-1.6968930572099914},\"threshold\":-3.286332236515297},{\"dendrites\":{1:0.3027122640649978,2:0.39134936751079513,3:2.4932609207910654,4:3.155411993570755},\"threshold\":-3.4318979471888365},{\"dendrites\":{1:2.4910959214908486,2:-0.5059883585189446,3:1.3848025398524917,4:-1.1097035967064466},\"threshold\":-3.7883826431751975},{\"dendrites\":{1:4.21079808578704,2:-1.5052118694717191,3:1.4344023570142548,4:-2.711764750141483},\"threshold\":-4.5040491753368395},{\"dendrites\":{1:-1.6488332910119838,2:-0.40570845146367146,3:2.170233159716623,4:3.3910347444541267},\"threshold\":-1.241166373815586},{\"dendrites\":{1:3.0329258663540695,2:3.7084662657437883,3:1.5496593946369985,4:2.100412620950156},\"threshold\":0.3054625471271423},{\"dendrites\":{1:1.0495269821180226,2:2.3439222184317736,3:1.5582106334793366,4:2.6321258335239},\"threshold\":1.2975490370745395},{\"dendrites\":{1:2.7233237417345313,2:0.8842354301070787,3:1.702225539133554,4:0.38596825997686396},\"threshold\":-2.223901319415502},{\"dendrites\":{1:-5.6245362452147285,2:-0.7027605071804142,3:1.68335290391799,4:4.726227599898234},\"threshold\":0.5551529159127662}],[{\"dendrites\":{1:1.519771618888756,2:1.1124062739916838,3:1.271723251595258,4:2.2293237158615677,5:0.47102223930531784,6:-0.2179951970616229,7:-0.17221503715206277,8:0.921863512338338,9:-0.825695204378474},\"threshold\":-1.0402466016600722},{\"dendrites\":{1:-0.18554707607768567,2:0.06623648044100013,3:-0.36868032642431303,4:-0.1438220624396441,5:1.771748901001139,6:-2.9437373468448307,7:-0.8000487969534527,8:-0.5247007992850695,9:2.4308313369006678},\"threshold\":0.8879636378001202},{\"dendrites\":{1:1.8694939694529575,2:0.9933842541092538,3:1.8105386356974593,4:2.048005359560365,5:-0.015399682561307923,6:0.6473284981803706,7:-0.16381705467280955,8:0.9002876068821752,9:-0.9154481705448976},\"threshold\":-0.3821570912491198},{\"dendrites\":{1:-0.3003903740269924,2:-0.10756565490505092,3:-0.4368305328404506,4:-0.11676222989227245,5:1.6179601063559292,6:2.0463013865449105,7:1.9329311344092193,8:-0.03784712861869709,9:-0.6648753642127366},\"threshold\":1.2762611214809643},{\"dendrites\":{1:0.3663310032675561,2:0.3234367549482032,3:0.7462463098546954,4:0.49047192148057395,5:2.324145726576901,6:-0.4886542094108692,7:1.2876032501732315,8:0.5048940973589067,9:0.9828772256469841},\"threshold\":-0.017032490001362786},{\"dendrites\":{1:1.3774265844211173,2:0.8007000108988003,3:1.0170984685039495,4:1.7004034556641487,5:0.16681106574762158,6:-2.11360259437321,7:-1.5673819859527398,8:0.507697679573002,9:-0.15813645964340345},\"threshold\":-1.1696558176351128},{\"dendrites\":{1:1.6189129907322557,2:0.9238530697309115,3:1.6847823636420038,4:1.3279475474789944,5:0.2779652545963602,6:0.6748766725411901,7:0.28012488954774956,8:1.2950235265790784,9:0.2792930585044396},\"threshold\":-0.8649997016631853},{\"dendrites\":{1:1.4161233330681369,2:3.2496796113193,3:1.3154466005681649,4:0.7763615526941341,5:0.7594406653279092,6:1.202540794188747,7:0.702769042851161,8:1.2393847184304099,9:1.3558206873454224},\"threshold\":-0.022512688298196665},{\"dendrites\":{1:1.7235370663168648,2:0.9283633956515794,3:1.7358418994360105,4:2.1277110545788447,5:0.06136621876833813,6:1.4541112715492022,7:-0.06486799734940663,8:1.6550774684594396,9:-1.2556174581424993},\"threshold\":-0.8391041383835913}]],\"dnnAvg\":13.3918449779,\"dymNerveStudies\":[{\"list\":[0.3802997191178773,0.8462333264133151,0.3036497890525801,0.6689386465632953,0.9735321423105247,0.03171032455330913,0.9373462916780746,0.09813374876375669,0.6301581389749229],\"threshold\":0.243375767137266},{\"list\":[0.9579864516034587,0.7453204963742909,0.7675279083214079,0.2685283704775936,0.31624489126212485,0.9682768574597324,0.15839748326211833,0.5087439869677978,0.22284068544420677],\"threshold\":-0.0315607192208512},{\"list\":[0.9687831229099197,0.7995117245095982,0.7410761863500637,0.008883753739061362,0.0805261621628518,0.11774125943169367,0.7439291424182288,0.5137881818731225,0.14108782484639681],\"threshold\":-1.655850111381332},{\"list\":[0.8553625742144583,0.6115443829670403,0.4093248404029084,0.9708407229452056,0.3928292015441476,0.5118514829956673,0.2992546905182132,0.7632147750608906,0.7862704478937678],\"threshold\":-2.865071941977669}],\"dymOutNerveStudy\":{\"list\":[0.79718819165002,0.23004903884236327,0.46247637217453164,0.3111780421847602,0.1360181231469869,0.954646485791314,0.2256813071526178,0.13556759374345917,0.9881114501705892],\"threshold\":-5.486450691799499},\"matrixK\":{},\"outNerves\":[{\"dendrites\":{1:0.24719483591031757,2:1.582482543318821,3:0.4632772158998749,4:-0.34080584677363435,5:0.3521224452784588,6:0.9768588456643061,7:0.11258147505372787,8:-0.004733570495282393,9:-0.030087603969750926},\"threshold\":0.18896603266821094},{\"dendrites\":{1:-0.17343165123018459,2:-0.05818193317664359,3:0.5502587580056034,4:-0.06517833739445403,5:-0.8566302369079205,6:-0.08070339079647386,7:0.1744431065662923,8:0.9339665808805032,9:0.200003109805919},\"threshold\":0.7425452049050345},{\"dendrites\":{1:0.739741644307183,2:-0.20090984199829084,3:0.360363860197997,4:1.5036024150490206,5:0.2042385128171256,6:0.12117043070759996,7:0.026267767092597257,8:-0.0023424175767590254,9:0.4907785937995306},\"threshold\":0.23645034514426372},{\"dendrites\":{1:0.22965056581533969,2:0.07238391508994617,3:0.5587683960025985,4:0.0735613710852295,5:-0.07195034183549189,6:0.6199294576447174,7:-0.3472500068405079,8:-1.1228183115323178,9:0.41966879063765256},\"threshold\":0.28189448900814945}]}"; // 2 3000 5 public static final String DATA2 = "{\"avg\":0.0,\"borderMap\":{},\"depthNerves\":[[{\"dendrites\":{1:0.12485417183242148,2:0.2693314713406803,3:0.26519759819414324,4:0.3733550683222323,5:0.6017137271775665,6:0.6287128300768373,7:0.5586253743321579,8:0.6580660952538927,9:0.19467302450828847,10:0.4347560638636916,11:0.6323475606613133,12:0.5917341208621643,13:0.2278902624663791,14:0.04114255428135316,15:0.9811173945047637,16:0.8857864059469929},\"threshold\":1.1259859159502748},{\"dendrites\":{1:0.3409814235153208,2:0.49434780901745484,3:0.5772881442303087,4:0.30394993446890617,5:0.12613969430338848,6:0.7151985147809771,7:0.24928165527471174,8:0.17396645920226206,9:0.024519902129253673,10:0.6074753867742835,11:1.081170437922101,12:0.7073912422713351,13:0.8675077262306066,14:0.8626871371125591,15:0.27372175341956506,16:0.7216871434345027},\"threshold\":1.1040876010913154},{\"dendrites\":{1:0.166182642622306,2:0.780076553988044,3:-0.00983711889627569,4:0.3243195966652157,5:0.35939329830823835,6:0.06456700814244459,7:0.6427635911028485,8:0.779096119253834,9:-0.03013046595571772,10:0.750411854268885,11:0.9323656042718661,12:0.11665684513811314,13:0.6652967958807359,14:0.3845323176734108,15:0.9994537953183966,16:0.687266026029427},\"threshold\":0.15969200570914094},{\"dendrites\":{1:0.9309009489915174,2:0.1195921872303166,3:0.31760835480329264,4:0.2327891218282906,5:0.03543329010271459,6:0.21773484101142962,7:0.9512298054298027,8:0.5519251698675709,9:-0.09726537729209675,10:0.9250260604610594,11:1.1306208530086896,12:0.2429412663415732,13:0.5875067676581073,14:0.20812425364781006,15:0.7839415435299455,16:0.44830460512541437},\"threshold\":0.5443549105653591},{\"dendrites\":{1:0.7986429257948151,2:0.16665267161758926,3:0.3007313394971051,4:0.8113181749911056,5:0.266610737734331,6:0.5603523059750696,7:0.6955112850403667,8:0.772691535264876,9:-0.012933085175800583,10:0.8339403319822001,11:0.5235965022950538,12:0.9250833747823862,13:0.9495487909116774,14:0.9845358194418912,15:0.5040331698085613,16:0.8276749356575563},\"threshold\":0.22710782395651408},{\"dendrites\":{1:0.902060806665231,2:0.2864023420953194,3:-0.1549569406985914,4:0.5583221279688484,5:0.07297786114360912,6:0.48765169812407133,7:0.7263689329458398,8:0.04317768737153216,9:0.12959815077770254,10:0.5040742861461727,11:0.641561216515682,12:0.652794663323882,13:0.23519612826647218,14:0.1836147907788227,15:0.9829913917334306,16:0.9304873904934201},\"threshold\":0.19132633777894864},{\"dendrites\":{1:0.5405476117937533,2:0.07895954873360789,3:-0.04993231190543553,4:0.917573697656973,5:0.0374658081841916,6:0.5597523708254746,7:0.4525776677368508,8:0.14605598562282252,9:0.7346831581703688,10:0.6542562959845876,11:0.3758088721642282,12:0.4072553785189089,13:0.923509193072847,14:0.9605924114522448,15:0.3134260753873115,16:0.14303906480395046},\"threshold\":0.8945348627697984},{\"dendrites\":{1:0.3130537249374775,2:0.07764303420503924,3:0.38748089516329226,4:0.1439215733412097,5:0.19505223221030843,6:0.6991252803627365,7:0.6573021360951571,8:0.6547637303005129,9:-0.07126013674262784,10:0.275486139590227,11:0.9004801322104088,12:0.9775868128346611,13:0.8629026006592977,14:0.562853066060633,15:0.7870606204213427,16:0.8434335064466765},\"threshold\":0.6857427158757302},{\"dendrites\":{1:0.7961793747988476,2:0.21952025248667342,3:0.23728643867055166,4:0.4949116662272057,5:0.6219486392744507,6:0.2332781931104381,7:0.30350529828216577,8:0.27694332134171307,9:-0.1029677996344286,10:0.4710229018871017,11:0.9219430139924784,12:0.9288527518937225,13:0.6991108357014844,14:0.35955010561052836,15:0.31143007932705213,16:0.5906806864596325},\"threshold\":0.9102880451601967}],[{\"dendrites\":{1:0.8280967781763249,2:0.6272599540534387,3:0.6036359038535414,4:0.4166345440676817,5:0.32637964225071137,6:0.05743437246224084,7:0.5213733502049217,8:0.5591052367715301,9:0.17248948199976322},\"threshold\":0.8172845524602762},{\"dendrites\":{1:0.431486151080126,2:0.6048131930925051,3:0.5953680054344688,4:0.8138030365801778,5:0.35024916492836233,6:0.778327622841448,7:0.4415368320347566,8:0.9060199783257531,9:0.042046118746363534},\"threshold\":0.6441215311752696},{\"dendrites\":{1:0.5138539789160997,2:0.8685624628819946,3:0.626539581622421,4:0.5178128230300406,5:0.7968149949417856,6:0.1976806468289684,7:0.6930101821675226,8:0.9686228194863526,9:0.2866428012424087},\"threshold\":0.13358066516105271},{\"dendrites\":{1:0.15627753729409746,2:0.2932177303565192,3:0.564411059046445,4:0.616026210397885,5:0.0414422390878646,6:0.5656641369630686,7:0.8234585897672031,8:0.5214718697006409,9:0.647426583463449},\"threshold\":0.9304331230023964},{\"dendrites\":{1:0.6465854364108188,2:0.3784846707295579,3:0.46793583557458157,4:0.4187880449651361,5:0.5265174029771663,6:0.7942186766342284,7:0.24741891346775463,8:0.3541903753188547,9:0.14595055903909335},\"threshold\":0.23249130287742434},{\"dendrites\":{1:0.14265589503280096,2:0.8297323585454489,3:0.5034880525416884,4:0.8482377871031016,5:0.8174079400887999,6:0.08044604521669356,7:0.37407517973157023,8:0.5957457778792374,9:0.6758986012516098},\"threshold\":1.1000673275784205},{\"dendrites\":{1:0.38999921034308477,2:0.05962683083287554,3:0.7327811823856197,4:0.507940439202757,5:0.7669544293374366,6:0.7326959822991819,7:0.994825447539415,8:0.1380385051719385,9:0.15871299584745321},\"threshold\":-0.16565847081074667},{\"dendrites\":{1:0.7655689427776068,2:0.39264577058405536,3:0.6645600233416393,4:0.46815226678835753,5:0.10080908156844648,6:0.4888814223207846,7:0.15723540004580397,8:0.3609506415394168,9:0.8615630140932222},\"threshold\":1.1384361562147283},{\"dendrites\":{1:0.7095004297975783,2:0.7440253941828625,3:0.5580913474996886,4:0.735734984468657,5:0.26092966042813026,6:0.40786137302210623,7:0.09983960589243748,8:0.6222868501618622,9:0.13515410958926524},\"threshold\":1.1690888542244}]],\"dnnAvg\":8.410168793,\"dymNerveStudies\":[{\"list\":[0.9599154935196191,0.6600873039727762,0.07435370393166163,0.5763137334897183,0.25024701071514444,0.9910313638477233,0.3999336676668027,0.8057045863341429,0.838876890470253],\"threshold\":-0.1183444077258596},{\"list\":[0.18877010831889773,0.7593525130899007,0.21217025257777566,0.729236367056555,0.11961345120290634,0.07394747334226615,0.25452204812547596,0.39606129629279363,0.4596312143391428],\"threshold\":0.514190640891733},{\"list\":[0.21438739838266685,0.4489300019414588,0.6345848609230734,0.5051840864319622,0.07723981416951775,0.6921228443901237,0.9802151395039644,0.5155918456389129,0.6711118378333887],\"threshold\":0.258395875564031},{\"list\":[0.17024093796421025,0.8696083450380061,0.9855989210029061,0.14233413050099863,0.3584284219101771,0.5681799802156358,0.5278951553203215,0.7342440256743761,0.34386885538212975],\"threshold\":-0.4610491292990804}],\"dymOutNerveStudy\":{\"list\":[0.4349034984404513,0.9947606911605519,0.9453179012204015,0.7949381041537922,0.40374878598025077,0.18279170954492419,0.9964544675779774,0.9179506952101003,0.8372584380352703],\"threshold\":-0.894495507129338},\"matrixK\":{},\"outNerves\":[{\"dendrites\":{1:0.1081138981478821,2:-0.0065857627308218755,3:0.4308583785524555,4:0.04226452869033803,5:0.26154090828547827,6:0.8508346454028738,7:-0.08374132452856259,8:0.9163091991020743,9:0.9443008856903765},\"threshold\":1.3521452660588753},{\"dendrites\":{1:-0.4134024519418968,2:-0.38375767374832914,3:0.31306180131594247,4:-0.4974703896552853,5:0.03548882593453909,6:-0.2796330378200446,7:0.6980345279806234,8:-0.11661645711258546,9:-0.471380494903669},\"threshold\":-0.1889355062678561}]}"; //晚上的结果写在这里 - public static final String DATA3 = "{\"avg\":0.0,\"borderMap\":{},\"depthNerves\":[[{\"dendrites\":{1:-0.8852994844132269,2:1.1463551219152373,3:2.516118572027358,4:3.34470981499351},\"threshold\":-0.9326127678194003},{\"dendrites\":{1:-0.10909688320362891,2:1.3795903278956512,3:1.665584430518432,4:2.754810966003403},\"threshold\":-0.7747301501341509},{\"dendrites\":{1:2.764842717040365,2:3.1226107640725447,3:0.6954471921622071,4:0.790333340725011},\"threshold\":0.7751697872240355},{\"dendrites\":{1:-2.4327514658123786,2:-0.6202036968109943,3:1.005936837770415,4:2.2958567995381727},\"threshold\":-2.115014914610206},{\"dendrites\":{1:1.3237932637389405,2:2.3394182955049425,3:1.2264148734347606,4:2.4892524063449404},\"threshold\":1.4553359707509432},{\"dendrites\":{1:1.296305292970723,2:2.1697627914563618,3:1.3829771829542417,4:1.913114015208962},\"threshold\":1.6376272433088972},{\"dendrites\":{1:0.8836310055073291,2:0.4017376440909046,3:3.2655760370209324,4:2.6601016425676085},\"threshold\":-2.6311924384047902},{\"dendrites\":{1:1.0666475888951388,2:1.329983786210766,3:1.3277302185047068,4:1.67039055595536},\"threshold\":0.8945362978104541},{\"dendrites\":{1:-2.027286396663514,2:-0.8814445946256129,3:0.8362371318874575,4:2.0842881806119116},\"threshold\":-1.2112277251393166}],[{\"dendrites\":{1:2.347114876760734,2:2.8276860420140943,3:1.0501761217282741,4:3.16844514429745,5:1.9775092203205247,6:1.0814456213665913,7:5.058147604015127,8:1.479022249102151,9:2.028461294637229},\"threshold\":3.1893275433626442},{\"dendrites\":{1:0.315598350526927,2:1.041865713475249,3:1.246140874898605,4:0.3241652899703311,5:0.8052594319287633,6:0.8046973687988335,7:1.7737470001996167,8:1.1019872616648498,9:0.8962351254978965},\"threshold\":0.8010678665515621},{\"dendrites\":{1:1.2178944534594243,2:1.4712282206245797,3:-0.35301609300168646,4:2.1893610631590934,5:0.88945707481423,6:0.5713910178076996,7:0.8969727543963283,8:0.9540012442260617,9:1.790105371435829},\"threshold\":3.1659369801461863},{\"dendrites\":{1:0.5507104095721601,2:1.189933754494926,3:1.1352393061754793,4:1.0272289629882425,5:1.2527325765079833,6:1.2182544946955536,7:2.0195305242353676,8:1.2901887955600704,9:0.8813473831187199},\"threshold\":1.4241707193139865},{\"dendrites\":{1:0.2638998369370262,2:-0.2921224246671991,3:0.34348266719081655,4:0.9305401766124584,5:0.3397156354284231,6:0.665360276340578,7:-0.3812649231735196,8:-0.14064939230149756,9:0.7936333425644293},\"threshold\":-0.43236341895872754},{\"dendrites\":{1:1.473343641885196,2:1.441001743760637,3:1.0183440330922562,4:-0.6515066527069807,5:1.9150066267503632,6:1.7968548893604561,7:-0.300077817525394,8:0.7854648350450864,9:-1.02917477526627},\"threshold\":3.8948676082125173},{\"dendrites\":{1:2.39330784598304,2:0.986631893555187,3:-2.532619567292439,4:3.0217549101902175,5:-0.6902662044972349,6:-0.34056666383741796,7:-0.3162407892969863,8:-0.5573993029957968,9:2.3363140336441286},\"threshold\":2.118669458520474},{\"dendrites\":{1:3.1499740375022838,2:2.347545373299059,3:-0.6852232768648713,4:1.7614214062267763,5:1.7416500881750616,6:1.2837275268136872,7:0.44307696006666375,8:0.9000746081580508,9:0.9510013658803099},\"threshold\":5.0358232424315315},{\"dendrites\":{1:-0.4006824009390686,2:0.1301677548020116,3:3.507316662607506,4:-2.893225858607386,5:2.317187064029997,6:2.264168752324961,7:1.1735276569142485,8:1.5747116535040597,9:-2.2999879146891353},\"threshold\":1.5140501175154668}]],\"dnnAvg\":13.3918449779,\"dymNerveStudies\":[{\"list\":[0.3802997191178773,0.8462333264133151,0.3036497890525801,0.6689386465632953,0.9735321423105247,0.03171032455330913,0.9373462916780746,0.09813374876375669,0.6301581389749229],\"threshold\":0.243375767137266},{\"list\":[0.9579864516034587,0.7453204963742909,0.7675279083214079,0.2685283704775936,0.31624489126212485,0.9682768574597324,0.15839748326211833,0.5087439869677978,0.22284068544420677],\"threshold\":-0.0315607192208512},{\"list\":[0.9687831229099197,0.7995117245095982,0.7410761863500637,0.008883753739061362,0.0805261621628518,0.11774125943169367,0.7439291424182288,0.5137881818731225,0.14108782484639681],\"threshold\":-1.655850111381332},{\"list\":[0.8553625742144583,0.6115443829670403,0.4093248404029084,0.9708407229452056,0.3928292015441476,0.5118514829956673,0.2992546905182132,0.7632147750608906,0.7862704478937678],\"threshold\":-2.865071941977669}],\"dymOutNerveStudy\":{\"list\":[0.79718819165002,0.23004903884236327,0.46247637217453164,0.3111780421847602,0.1360181231469869,0.954646485791314,0.2256813071526178,0.13556759374345917,0.9881114501705892],\"threshold\":-5.486450691799499},\"matrixK\":{},\"outNerves\":[{\"dendrites\":{1:1.8083025644440953,2:-0.47487598230048766,3:1.7933639445297196,4:-0.4027245173331921,5:-0.10390211819576389,6:-1.834585940998899,7:4.37434100713376,8:1.149699393140979,9:-5.191043476110364},\"threshold\":3.314527557529885},{\"dendrites\":{1:5.874128778567122,2:1.5207232507835766,3:-1.3107601388995365,4:1.7626007219323347,5:-1.6434142770582807,6:-2.8722147381453254,7:-4.136479000635765,8:-4.768236724740191,9:0.43583222488352774},\"threshold\":3.5576904764005275},{\"dendrites\":{1:-1.2131549885828878,2:-1.5315409952049623,3:2.316532529215519,4:-1.3562842659084027,5:-1.0729002543986872,6:3.3301223438313645,7:-1.107555441595785,8:4.547100607654846,9:4.947861007275616},\"threshold\":4.669838826452585},{\"dendrites\":{1:-5.424941949526106,2:-0.2943539157082803,3:-3.681167144646281,4:-1.5160349170484073,5:0.2805198560222738,6:-1.3891353606410695,7:-1.280515715823402,8:-1.3826164393826625,9:-0.5055055648205157},\"threshold\":-4.138376147908407}]}"; + public static final String DATA3 = "{\"avg\":0.0,\"borderMap\":{},\"depthNerves\":[[{\"dendrites\":{1:1.3259385848931655,2:0.47040682776298604,3:0.2626458930710314,4:-0.6931666899516274},\"threshold\":0.1453612348036091},{\"dendrites\":{1:1.1272365640099227,2:-0.7337466876050133,3:1.284322391399613,4:-0.3471114920768559},\"threshold\":-1.0499069028248464},{\"dendrites\":{1:0.016504521661250424,2:-0.10360965006145044,3:1.3652414749205937,4:0.42199222473877945},\"threshold\":-1.4216266119900416},{\"dendrites\":{1:-0.6557724271422759,2:0.5059166113424489,3:0.591672021496659,4:1.5605292204461032},\"threshold\":-1.0324355747309064},{\"dendrites\":{1:0.6802906970222707,2:1.6799412761066854,3:1.3531381462511556,4:1.2615738815960797},\"threshold\":0.7987849092602402},{\"dendrites\":{1:0.558610138859577,2:1.1781048633066742,3:-0.04120451326411118,4:0.8973744836692659},\"threshold\":-0.3364860842210545},{\"dendrites\":{1:1.2201853163931442,2:-0.1319268265505929,3:0.8899349564821847,4:-0.2239436430161853},\"threshold\":-1.4593542524452927},{\"dendrites\":{1:-1.4627108201384893,2:-0.4218087822935181,3:0.8424473913425632,4:1.7381108101943565},\"threshold\":0.009017139220030404},{\"dendrites\":{1:0.21979223862443736,2:-0.09999423845758065,3:1.7493830593593733,4:1.2815060979300226},\"threshold\":-1.2468615252112183}],[{\"dendrites\":{1:-0.06814352458384446,2:0.8654209659798254,3:0.606671878859585,4:0.6690422943293964,5:0.18776993680988208,6:0.4429600106747597,7:0.8007974121988832,8:0.40769292777931043,9:1.089736256954681},\"threshold\":0.11425372893619534},{\"dendrites\":{1:0.4235048601914431,2:0.7301733420440525,3:0.47626065885455093,4:0.20301545827959935,5:-0.14563615295968657,6:0.18938539585886321,7:0.8331177878303199,8:0.08819831079771183,9:1.034007428790719},\"threshold\":0.9035997370956839},{\"dendrites\":{1:-0.0136583263659488,2:1.08540853493493,3:0.6313292218205966,4:0.15616830292219105,5:-0.45257029636590934,6:-0.011821338304250636,7:1.0264664644560217,8:0.09852241171249033,9:0.6153245286623159},\"threshold\":-0.46809655313578014},{\"dendrites\":{1:0.8396468935481934,2:0.24597478533373515,3:0.01709635957889014,4:-0.5157896554506954,5:1.510992017062753,6:0.7053192033802479,7:-0.1301122289133768,8:-1.8114335497652565,9:0.6334010229654464},\"threshold\":0.028096629685495183},{\"dendrites\":{1:0.23731607777021319,2:0.34547711659021174,3:0.5608853822432557,4:-0.09644814573654577,5:0.46901507365465206,6:-0.05164507717178522,7:1.1075376447172733,8:-0.26165687811551763,9:-0.22320027819102847},\"threshold\":-0.5687511270861467},{\"dendrites\":{1:0.10561785365469165,2:0.21097969297409194,3:0.8016626912756442,4:1.0909872287991207,5:0.2527759146699615,6:0.4787114619004488,7:0.9706369146132799,8:-0.061020470316131004,9:1.3341810110225092},\"threshold\":0.4032090222860525},{\"dendrites\":{1:-0.10768669048968336,2:0.30909155387598075,3:0.9041843535141528,4:0.9889376059559655,5:-0.4857743290489738,6:0.7746145317918771,7:1.067237890644749,8:0.9039695592402688,9:0.5859758041389942},\"threshold\":-0.5138621895906719},{\"dendrites\":{1:0.31673036128998944,2:1.2194426935855434,3:0.7450217363929681,4:-0.2915272111515559,5:-0.13306522798783305,6:0.0943981635226951,7:1.0418390678891094,8:0.15647654696126545,9:0.11408175020349469},\"threshold\":-0.1449149617757226},{\"dendrites\":{1:-0.5482449247301743,2:0.8516085836279023,3:1.2361644496454496,4:0.9525331308203848,5:1.4776341546293064,6:-0.6305101936166168,7:0.08278195139673016,8:0.6008344744928618,9:0.537598097839101},\"threshold\":0.7770676119627797}]],\"dnnAvg\":13.3918449779,\"dymNerveStudies\":[{\"list\":[0.3802997191178773,0.8462333264133151,0.3036497890525801,0.6689386465632953,0.9735321423105247,0.03171032455330913,0.9373462916780746,0.09813374876375669,0.6301581389749229],\"threshold\":0.243375767137266},{\"list\":[0.9579864516034587,0.7453204963742909,0.7675279083214079,0.2685283704775936,0.31624489126212485,0.9682768574597324,0.15839748326211833,0.5087439869677978,0.22284068544420677],\"threshold\":-0.0315607192208512},{\"list\":[0.9687831229099197,0.7995117245095982,0.7410761863500637,0.008883753739061362,0.0805261621628518,0.11774125943169367,0.7439291424182288,0.5137881818731225,0.14108782484639681],\"threshold\":-1.655850111381332},{\"list\":[0.8553625742144583,0.6115443829670403,0.4093248404029084,0.9708407229452056,0.3928292015441476,0.5118514829956673,0.2992546905182132,0.7632147750608906,0.7862704478937678],\"threshold\":-2.865071941977669}],\"dymOutNerveStudy\":{\"list\":[0.79718819165002,0.23004903884236327,0.46247637217453164,0.3111780421847602,0.1360181231469869,0.954646485791314,0.2256813071526178,0.13556759374345917,0.9881114501705892],\"threshold\":-5.486450691799499},\"matrixK\":{},\"outNerves\":[{\"dendrites\":{1:0.10434101602614843,2:-0.059927108794489065,3:0.5288563441427986,4:-1.220281452591742,5:0.5268899063519855,6:-0.1668026589215263,7:0.42610522515961735,8:-0.07609330230866232,9:0.04864756427917784},\"threshold\":0.11315114688098979},{\"dendrites\":{1:0.22728893928451854,2:-0.08476513639000224,3:-0.0429026071263658,4:0.013208858828787608,5:0.16212825171355355,6:0.8671316248600842,7:0.1799041204549389,8:-0.3101603786319704,9:-1.0081053128024589},\"threshold\":0.0013061515535431295},{\"dendrites\":{1:0.04346486976885912,2:-0.39896936099929897,3:-0.060456365659088,4:1.156091647487133,5:0.6399013533886204,6:0.09476612730484273,7:-0.32178474625033576,8:0.21539419974348012,9:1.2154708250027648},\"threshold\":0.2294945820642692},{\"dendrites\":{1:-0.4629707929200189,2:0.018844564819924733,3:0.35301506968074037,4:0.0036245591209093874,5:0.322885182539098,6:-0.3589345967034893,7:-0.6644413037745864,8:0.5837702508565968,9:0.14139736823209761},\"threshold\":-0.08772557762708731}]}"; //2 300 10 public static final String DATA4 = "{\"borderMap\":{},\"depthNerves\":[],\"dymNerveStudies\":[{\"list\":[0.7650868673956612,0.41735680484600424,0.772749504058288,0.8384599613367586,0.06718497215232833,0.8850293262766552,0.8851009321760257,0.3377147487002068,0.026600923407615995],\"threshold\":0.4085539955045393},{\"list\":[0.6323922682200495,0.9312225577559277,0.49848962848457745,0.8877566654400643,0.26067491091518213,0.05808389805584624,0.4959719028971741,0.22358587752136916,0.375118935336723],\"threshold\":-0.822655134763225},{\"list\":[0.21616781794077045,0.21359089014595734,0.9866031753826975,0.039237788355860115,0.48405579610217797,0.8457815806254125,0.9692919219180153,0.21887259464434694,0.49735020888413284],\"threshold\":-1.777078438439913},{\"list\":[0.7032405099206009,0.12322216338010372,0.6691753686809487,0.48265272696372263,0.26687076772952245,0.5671989493130618,0.1477514710970167,0.4174529137169356,0.6341882949153155],\"threshold\":-3.916736185074929}],\"dymOutNerveStudy\":{\"list\":[0.29402787308416467,0.23358880323416897,0.8108657396965971,0.8102529215195801,0.41073391427871375,0.13840233568741056,0.5405034618507846,0.12995627329543935,0.7458170503569194],\"threshold\":-8.44190117544671},\"outNerves\":[]}"; public static final String DATA5 = "{\"borderMap\":{},\"depthNerves\":[],\"dymNerveStudies\":[{\"list\":[0.4467703081299109,0.6216350552316628,0.9614933454364657,0.20607668094161646,0.4887977243589058,0.63160869587642,0.5541665393807305,0.6780176493077679,0.311045145099047],\"threshold\":0.806141233738043},{\"list\":[0.16664166723178497,0.6177168961084486,0.5094827323811009,0.8030743749033795,0.2949448909891714,0.5048826684603277,0.29728972921303953,0.5163889826059106,0.31636746120315484],\"threshold\":0.523335756133632},{\"list\":[0.5002599844181366,0.23168031749716456,0.009972722232462483,0.19765661174031213,0.41487704196451936,0.08114152168166133,0.1734755737329785,0.5765370682837576,0.4749258231617214],\"threshold\":0.645293861900744},{\"list\":[0.06267312603488806,0.3148365387915856,0.3261441144961199,0.8599692822928876,0.8794020011762773,0.18877316316816117,0.816967692916158,0.010279303231223502,0.28176395163091383],\"threshold\":1.056555408293605}],\"dymOutNerveStudy\":{\"list\":[0.4493364790159943,0.4464735195422622,0.8194912362912562,0.935208152582449,0.7759469222501951,0.3795323237713125,0.7802158181253224,0.6609269355803631,0.31953583656073115],\"threshold\":0.682843377796887},\"outNerves\":[]}"; diff --git a/src/test/java/org/wlld/NerveDemo1.java b/src/test/java/org/wlld/NerveDemo1.java index 5761919..3672665 100644 --- a/src/test/java/org/wlld/NerveDemo1.java +++ b/src/test/java/org/wlld/NerveDemo1.java @@ -32,7 +32,7 @@ public class NerveDemo1 { * @param activeFunction 激活函数 * @param isDynamic 是否是动态神经元 */ - NerveManager nerveManager = new NerveManager(2, 6, 1, 4, new Sigmod(), false, true); + NerveManager nerveManager = new NerveManager(2, 6, 1, 4, new Sigmod(), false, true, 0); nerveManager.init(true, false, false); @@ -106,6 +106,79 @@ public class NerveDemo1 { } + public static void test3() throws Exception { + NerveManager nerveManager = new NerveManager(3, 6, 3 + , 3, new Sigmod(), false, true, 0); + nerveManager.init(true, false, false);//初始化 + List> data = new ArrayList<>();//正样本 + List> dataB = new ArrayList<>();//负样本 + List> dataC = new ArrayList<>();//负样本 + Random random = new Random(); + for (int i = 0; i < 4000; i++) { + Map map1 = new HashMap<>(); + Map map2 = new HashMap<>(); + Map map3 = new HashMap<>(); + map1.put(0, 1 + random.nextDouble()); + map1.put(1, 1 + random.nextDouble()); + map1.put(2, 0.0); + //产生鲜明区分 + map2.put(0, random.nextDouble()); + map2.put(1, random.nextDouble()); + map2.put(2, 0.0); + // + map3.put(0, 2 + random.nextDouble()); + map3.put(1, 2 + random.nextDouble()); + map3.put(2, 0.0); + data.add(map1); + dataB.add(map2); + dataC.add(map3); + } + Map right = new HashMap<>(); + Map wrong = new HashMap<>(); + Map other = new HashMap<>(); + right.put(1, 1.0); + + wrong.put(2, 1.0); + + other.put(3, 1.0); + for (int i = 0; i < data.size(); i++) { + Map map1 = data.get(i); + Map map2 = dataB.get(i); + Map map3 = dataC.get(i); + post(nerveManager.getSensoryNerves(), map1, right, null, true); + post(nerveManager.getSensoryNerves(), map2, wrong, null, true); + post(nerveManager.getSensoryNerves(), map3, other, null, true); + } + + List> data2 = new ArrayList<>(); + List> data2B = new ArrayList<>(); + List> data2C = new ArrayList<>();//负样本 + for (int i = 0; i < 20; i++) { + Map map1 = new HashMap<>(); + Map map2 = new HashMap<>(); + Map map3 = new HashMap<>(); + map1.put(0, 1 + random.nextDouble()); + map1.put(1, 1 + random.nextDouble()); + map1.put(2, 0.0); + + map2.put(0, random.nextDouble()); + map2.put(1, random.nextDouble()); + map2.put(2, 0.0); + + map3.put(0, 2 + random.nextDouble()); + map3.put(1, 2 + random.nextDouble()); + map3.put(2, 0.0); + data2.add(map1); + data2B.add(map2); + data2C.add(map3); + } + Back back = new Back(); + for (Map map : data2) { + post(nerveManager.getSensoryNerves(), map, null, back, false); + System.out.println("====================="); + } + } + /** * 提交函数 *