2014-01-07 2 views
1

Java를 사용하여 신경망 백 프로 퍼 게이트를 구현하려고했지만 이미 코드를 작성했지만 그 결과가 만족스럽지 않습니다. 오류가 너무 느리게 감소하고 있습니다. 신경망 BackPropagation 교육에서 너무 느리게 오류 감소

epoch:1 current error:0.5051166876846451 

epoch:2 current error:0.4982484527652138 

epoch:3 current error:0.4965995467118879 

epoch:4 current error:0.49585659139683363 

epoch:5 current error:0.4953426236386938 

epoch:6 current error:0.4948766985413233 

epoch:7 current error:0.49441754405152294 

epoch:8 current error:0.4939551661406868 

epoch:9 current error:0.49348601614718984 

epoch:10 current error:0.4930078119902486 

epoch:11 current error:0.49251846766886453 

는이를 바탕으로 내 코드와 그 알고리즘을 의심하기 시작 : 다음 기차 결과의 예이다. 사용 된 활성화 함수는 시그마 이드입니다. 아래는 트레이닝의 샘플 코드입니다.

public void learning(int epoch,double learningRateTemp,double desiredErrorTemp,DataSet ds,double momentum){ 
    int processEpoch=0; 
    double sumSquaredError=0; 
    DataSetRow dsr; 
    Connector conTemp; 
    double sumError=0; 
    double errorInformation=0; 
    double activationValue; 
    double partialDerivative; 

    do{ 
     processEpoch++; 
     sumSquaredError=0; 
     System.out.println("epoch:"+processEpoch); 
     //data training set 
     for(int a=0;a<ds.countRows();a++){ 
      dsr=ds.getSpecificRow(a); 
      sumError=0; 
      double[]input=dsr.getInput(); 
      double[]output=dsr.getdesiredOutput(); 
      double sumDeltaInput=0; 
      double weightTempValue=0; 
      //forward calculation 
      this.forwardCalculation(input);    
      //backpropagateofError 
      //for output unit 

      for(int k=0;k<NeuralLayers[totalLayer-1].getTotalNode();k++){ 
       activationValue=NeuralLayers[totalLayer-1].getNeuron(k).getValue(); 
       partialDerivative=(activationValue)*(1-activationValue); 
       Neuron Temp=NeuralLayers[totalLayer-1].getNeuron(k); 
       errorInformation=(output[k]-Temp.getValue())*partialDerivative; 
       Temp.SetErrorInformationTerm(errorInformation); 
       sumError+=Math.pow((output[k]-Temp.getValue()),2); 
       NeuralLayers[totalLayer-1].setNeuron(k, Temp); 
      } 
      //end of output unit 
      //for hidden Unit 
      for(int l=totalLayer-2;l>0;l--){ 
       for(int j=1;j<NeuralLayers[l].getTotalNode();j++){ 
        sumDeltaInput=0; 
        for(int k=0;k<NeuralLayers[l+1].getTotalNode();k++){         
         conTemp=NeuralLayers[l+1].getConnector(k, j); 
         if(conTemp.getStatusFrom()==false){ 
           weightTempValue=conTemp.getWeight().getValue(); 
           sumDeltaInput+=(NeuralLayers[l+1].getNeuron(k).GetErrorInformationTerm()*weightTempValue); 
          } 
         } 
        activationValue=NeuralLayers[l].getNeuron(j).getValue(); 
        partialDerivative=(activationValue)*(1-activationValue); 
        errorInformation= sumDeltaInput*partialDerivative;     
        Neuron neuTemp=NeuralLayers[l].getNeuron(j); 
        neuTemp.SetErrorInformationTerm(errorInformation); 
        NeuralLayers[l].setNeuron(j, neuTemp); 
        } 
       } 
      updateWeight(learningRateTemp,momentum); 
      sumSquaredError+=sumError;    
      }  
    sumSquaredError/=(double)(ds.countRows()*NeuralLayers[totalLayer-1].getTotalNode()); 
    sumSquaredError=Math.sqrt(sumSquaredError); 
    System.out.println("current error:"+sumSquaredError); 
    } while(processEpoch<epoch && sumSquaredError>desiredErrorTemp); 
} 

} 전진 계산

private void forwardCalculation(double[] inputValue){ 
     Connector Contemp; 
     double SumNodeWeight=0; 
     int start=1; 
     int count=0; 
     setNodeValue(inputValue,0); 
     do{ 
      count++; 
      if("output".equals(NeuralLayers[count].statusLayer)) 
        start=0; 
       else start=1; 
      //get sum of all input 
      for(int j=start;j<NeuralLayers[count].getTotalNode();j++){ 
       for(int i=0;i<NeuralLayers[count].sizeConnector(j);i++){ 
        Contemp=NeuralLayers[count].getConnector(j, i); 
        SumNodeWeight+=Contemp.getCombinedweightInput(); 
       } 
       SumNodeWeight=(1/(1+Math.exp(-SumNodeWeight))); 
       NeuralLayers[count].setNeuronValue(j, SumNodeWeight); 
       SumNodeWeight=0; 
      } 
    }while(!"output".equals(NeuralLayers[count].statusLayer)); 
} 

오른쪽 트랙에

private void updateWeight(double learningRateTemp,double momentum){ 
    double newWeight; 
    double errorInformation; 
    Connector conTemp; 
    for(int LayerPosition=totalLayer-1;LayerPosition>0;LayerPosition--){ 
     for(int node=1;node<NeuralLayers[LayerPosition].getTotalNode();node++){ 
      errorInformation=NeuralLayers[LayerPosition].getNeuron(node).GetErrorInformationTerm(); 
       //for bias weight 
       newWeight=learningRateTemp*errorInformation; 
       conTemp=NeuralLayers[LayerPosition].getConnector(node, 0); 
       conTemp.updateWeight(newWeight,false,0); 
       NeuralLayers[LayerPosition].updateConnector(conTemp, node, 0); 
       ///////////////////// 
       //for other node weight 
       for(int From=1;From<NeuralLayers[LayerPosition].sizeConnector(node);From++){ 
        conTemp=NeuralLayers[LayerPosition].getConnector(node, From); 
        double weightCorrection=learningRateTemp*errorInformation*NeuralLayers[LayerPosition-1].getNeuron(From).getValue(); 
        conTemp.updateWeight(weightCorrection,true,momentum); 
        NeuralLayers[LayerPosition].updateConnector(conTemp,node,From); 
       } 
     } 
    } 
} 

내가 오전 가중치를 업데이트하기위한

? 나는 이미 며칠 만에 버그를 찾았지만 아직 아무것도 찾지 못했습니다. 오류를 계산할 내 공식이 맞습니까? 대단히 감사합니다! 당신이 다음 다음 출력에서 ​​오류를 추가, 당신은 변수 sumError는 beggining에서 0로 선언 넣고,

+0

학습 속도와 운동량의 가치는 무엇입니까? –

답변

0

그럼 나는 어떤이에 대한 전문가의 종류 나 Java 프로그래밍 아니지만, 그것은 영향을 줄 수 있습니다 다시 숨겨진 레이어의 사이클은 sumSquaredError 변수에 추가되지만, 교육의 오류를 계산할 경우 왜 숨겨진 레이어 cucle에 들어 있습니까?

for(int l=totalLayer-2;l>0;l--){ 
    for(int j=1;j<NeuralLayers[l].getTotalNode();j++){ 

    } 
    updateWeight(learningRateTemp,momentum); 
    sumSquaredError+=sumError; 
} 

외부에 있어야하지 않습니까?

내가 전에 대답 한 사람의 의사 코드를 참조하겠습니다. 이 도움이

link

희망!

관련 문제