package trust.jfcm.learning.supervised;
import trust.jfcm.learning.LearningConcept;
import trust.jfcm.learning.LearningWeightedConnection;
import trust.jfcm.learning.TrainingFunction;
/**
* This class implements the linear the Back Propagation rule for error calculation.
* @author Matteo
*
*/
public class LinearBP extends TrainingFunction{
/** Learning rate */
double learn = 0.4;
/** Momentum */
double momentum = 0.1;
@Override
public void update(LearningWeightedConnection wconn) {
double cWeight = wconn.getChangeInWeight();
double weight = wconn.getWeight();
double weightUncertainty = wconn.getWeightUncertainty();
LearningConcept from = (LearningConcept) wconn.getFrom();
double learnTimesError = learn * from.getError();
/* Rule */
//double delta = (learnTimesError * from.getOutput()) + (momentum * cWeight);
double delta = 0;
if(weight == weightUncertainty)
delta = (learnTimesError * from.getOutput()) + (momentum * cWeight);
else
delta = (learnTimesError * weightUncertainty * from.getOutput()) + (momentum * cWeight);
/*
System.out.println("Connection: "+wconn);
System.out.println(" learnTimesError: "+learnTimesError);
System.out.println(" weightUncertainty: "+weightUncertainty);
System.out.println(" cWeight: "+cWeight);
System.out.println(" delta: "+delta);
*/
weight = weight + delta;
if(weight>1)
weight=1;
/*
if(weight<-1)
weight=-1;
*/
wconn.setChangeInWeight(delta);
wconn.setWeight(weight);
}
public String toString(){
return "LinearBP";
}
@Override
public Object clone() {
// TODO Auto-generated method stub
return new LinearBP();
}
}