packagecom.violet.VerticalSystem.MathSystem.NetWork.bash;importjava.util.ArrayList;importjava.util.HashMap;importjava.util.Iterator;importjava.util.Map.Entry;/***神经网络模型**@authortaoyo**/publicclassBPNet{//模型应用号privateStringapp_no;//层privateArrayListLayerlayerList=newArrayListLayer();//权重1.2-2.1,0.232privateHashMapString,DoubleweightMap=newHashMapString,Double();//模型结构privateint[]layerNodes;//学习率privatedoubleleanRate=0.02;//期望误差privatedoubletargetError=1E-6;privatedoublemaxCount=Math.pow(10,3);publicstaticvoidmain(String[]args){BPNetbpNet=newBPNet();int[]temp=newint[]{3,10,2};double[][]variables=newdouble[][]{{184.1470985,168.9824306,477.4399204},{190.9297427,180,2.031951694},{114.1120008,168.9824306,134.0550122},{24.31975047,138.6272075,1142.788171},{4.107572534,96.36634815,8.468460342},{72.05845018,52.54678471,75.94215866},{165.6986599,17.8970746,4623.607587},{198.9358247,0.900675306,20.45894558},{141.2118485,5.718898144,42.03717626},{45.59788891,31.17207412,5105378.501},{0.000979345,71.02837805,40.43178489},{46.3427082,115.5295967,21.43885695},{142.0167037,153.7802797,5248.432502},{199.0607356,176.4153258,73.27247024},{165.028784,177.8928863,9.037974494},{71.20966833,157.8512029,1220.744654},{3.860250812,121.1971786,129.348248},{24.90127532,76.90499696,2.29793676},{114.987721,35.81892876,500.488909},{191.2945251,7.99827643,233.3251752},{183.6655639,0.254505942,0.007835181},{99.11486907,14.48356238,252.2230216},{15.37795958,47.20167648,455.778391}};double[][]target=newdouble[][]{{830.5694495,93.30299985},{372.9616944,35.26519536},{417.1494436,34.46418834},{1305.735129,97.26945124},{108.942381,0.608856105},{200.5473936,84.92111439},{4807.203322,21.83472509},{220.2954455,8.663900816},{188.9679229,98.70692273},{5105455.271,31.00534646},{111.4611423,15.4701039},{183.3111618,23.84495835},{5544.229486,73.15620083},{448.7485316,71.59022759},{351.9596448,79.41333997},{1449.805525,78.84224476},{254.4056774,61.18001822},{104.104209,55.93676926},{651.2955588,7.374459696},{432.6179767,15.51971834},{183.927905,88.83228348},{365.8214531,15.58275208},{518.3580271,3.063853679}};double[]forcast=newdouble[]{9.442163799,90.39831282,1.782930137};bpNet.setLayerNodes(temp);bpNet.initNet(temp);bpNet.iniBias();bpNet.initWeight();bpNet.initError();bpNet.forward();//bpNet.dl_SelfCoding(variables,target);//bpNet.forward();//System.out.println(----coding---\n+bpNet.toJson());doublesumTemp=0;for(inti=0;itarget[0].length;i++){doublesum=0;for(intj=0;jtarget.length-1;j++){sum+=(bpNet.normalization(target[j][i])-bpNet.normalization(target[j+1][i]));}sum=sum/(target.length-1);sumTemp+=Math.pow(sum,2);}sumTemp=sumTemp/2;bpNet.targetError=sumTemp;System.out.println(sumTemp);bpNet.train(variables,target);//,,{101.6234068,1.060103061},,double[]result=bpNet.forcast(forcast);System.out.println(bpNet.toJson());for(doubled:result){System.out.println(result:+d);}}/***预测**@paramvariables*@return*/publicdouble[]forcast(double[]variables){forward();Layerlayer=layerList.get(layerList.size()-1);returngetLayerNodesOutPut(layer,true);}/****@paramlayer*@return*/publicdouble[]getLayerNodesOutPut(Layerlayer,booleanisNorma){double[]result=newdouble[layer.getNodeList().size()];for(intindex=0;indexlayer.getNodeList().size();index++){Nodenode=layer.getNodeList().get(index);if(isNorma)result[index]=normalizationBack(node.getOutput());elseresult[index]=(node.getOutput());}returnresult;}publicvoidsetLayerNodeOutPut(Layerlayer,double[]values,booleanisNorma){for(intindex=0;indexlayer.getNodeList().size();index++){Nodenode=layer.getNodeList().get(index);if(isNorma)node.setOutput(normalization(values[index]));elsenode.setOutput((values[index]));}}/****@paramvariables*@paramtarget*/publicvoidtrain(double[][]variables,double[][]target){for(inti=0;ivariables.length;i++){initInput(variables[i]);trainBP(target[i]);//trainDL(variables[i],target[i]);}}/***深度学习训练**@paramvariables*@paramtarget*/publicvoidtrainDL(double[]variables,double[]target){intcount=0;doubletemp=0;while(countmaxCount){forward();doubleep=error(target);if(temp!=ep){System.out.println(count+error:+ep);temp=ep;}if(ep-targetError0)break;outNet();System.out.println('''''''''''''''''''''''''''''''''''''''''''''''''''''''''');wake(target);sleep(variables);outNet();count++;}}publicvoidwake(double[]target){LayeroutputLayer=layerList.get(layerList.size()-1);setLayerNodeOutPut(outputLayer,target,true);for(intindex=layerList.size()-2;index0;index--){forward(index,false);forward(index,true);tranTreeLayer(layerList.get(index+1),layerList.get(index),layerList.get(index-1));}}publicvoidsleep(double[]variables){initInput(variables);for(intindex=1;indexlayerList.size()-1;index++){forward(index,false);forward(index,true);tranTreeLayer(layerList.get(index-1),layerList.get(index),layerList.get(index+1));}}/****@paramvariables*@paramtarget*/publicvoiddl_SelfCoding(double[][]variables,double[][]target){//上行正向训练SparseAutoEncoderautoEncoder=newSparseAutoEncoder();autoEncoder.setWeightMap(weightMap);for(inti=0;i1;