/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package sim.app.socialsystem; import sim.util.MutableDouble3D; import sim.util.MutableInt3D; /** * * @author epokh * This class only compute the output generated by the distal error */ public class IcoLearner { private boolean noLearning=false; private double output; private MutableDouble3D derivReflex; private MutableDouble3D reflex; private MutableDouble3D Wdistal; private MutableDouble3D Wtemp; //this define the learning rate private double mu=0.01; //private MutableDouble3D Wreflex; //initialize with initial weights public IcoLearner() { Wdistal=new MutableDouble3D(1.0, 1.0, 1.0); Wtemp=new MutableDouble3D(); reflex=new MutableDouble3D(); derivReflex=new MutableDouble3D(); derivReflex.zero(); reflex.zero(); Wtemp.zero(); } //input is the distal error public double calculate(MutableInt3D reflex_int,MutableInt3D distal_int) { /*! decrease the energy of the robot */ MutableDouble3D reflex_double=new MutableDouble3D(reflex_int); MutableDouble3D distal_double=new MutableDouble3D(distal_int); // if there's no learning the agent is only reactive if(noLearning) { /*! compute the next output */ output=Wdistal.dot(distal_double); } else { //compute output output =Wdistal.dot(distal_double); //compute derivative of reflex dr=r(t)-r(t-1) derivReflex=reflex_double.subtract(reflex_double, reflex); //update r(t-1) reflex.setTo(reflex_int); // Learn and update the distal synaptic weights Wtemp.zero(); Wtemp=derivReflex.multiply(derivReflex, mu); Wtemp.multiplyDot(Wtemp, distal_double); Wdistal.addIn(Wtemp); } return output; } public double getWeight(int type) { switch(type) { case DecisionMaker.B_AGENT: return Wdistal.x; case DecisionMaker.B_FOOD: return Wdistal.y; case DecisionMaker.B_AGENTFOOD: return Wdistal.z; default: return 0; } } }