//goalX.printInfor();
//=== entropy
//--normalize
SignedValue entropyFactor = goalK.getR().getEntropy().duplicate();
entropyFactor.multiLogNumber(-logZ);
this.entropy = logZ - entropyFactor.convertToRealValue();//logZ - \bar{r}/Z
//System.out.print("Entropy is" + entropy);
//=== risk
//--normalize
SignedValue riskFactor = goalK.getR().getRisk().duplicate();
riskFactor.multiLogNumber(-logZ);
this.risk = riskFactor.convertToRealValue();
//System.out.print("Risk is" + risk);
this.functionValue = this.risk - this.temperature*this.entropy;
//=== gradients
//System.out.print("Gradients are: ");
HashMap<Integer, Double> gradient = new HashMap<Integer, Double>();
for(Integer featID : goalX.getT().getValue().getIds()){
//delta(r)*Z/Z^2=delta(r)/Z
//--normalize
SignedValue resT = goalX.getT().getValue().getValueAt(featID).duplicate();
resT.multiLogNumber(-logZ);
//-delta(Z)*r/Z^2
SignedValue resRS = SignedValue.multi(
goalX.getS().getValue().getValueAt(featID),
goalK.getR().getValue()
);
resRS.negate();
resRS.multiLogNumber(-2*logZ);
//-T*delta(Z)/Z
SignedValue resS = goalX.getS().getValue().getValueAt(featID).duplicate();
resS.multiLogNumber(Math.log(this.getTemperature()));
resS.negate();
resS.multiLogNumber(-logZ);
//add them together
resT.add(resRS);
resT.add(resS);
double finalVal = resT.convertToRealValue();