//###############semiring parsing
parserEntropyP.insideEstimationOverHG(testHG);
parserEntropyQ.insideEstimationOverHG(testHG);
parserCrossentropyPQ.insideEstimationOverHG(testHG);
ExpectationSemiring pGoalSemiring = (ExpectationSemiring) parserEntropyP.getGoalSemiringMember(testHG);
ExpectationSemiring qGoalSemiring = (ExpectationSemiring) parserEntropyQ.getGoalSemiringMember(testHG);
ExpectationSemiring pqGoalSemiring = (ExpectationSemiring) parserCrossentropyPQ.getGoalSemiringMember(testHG);
pGoalSemiring.normalizeFactors();
pGoalSemiring.printInfor();
qGoalSemiring.normalizeFactors();
qGoalSemiring.printInfor();
pqGoalSemiring.normalizeFactors();
pqGoalSemiring.printInfor();
double entropyP = pGoalSemiring.getLogProb() - pGoalSemiring.getFactor1().convertRealValue();//logZ-E(s)??????????
double entropyQ = qGoalSemiring.getLogProb() - qGoalSemiring.getFactor1().convertRealValue();//logZ-E(s)?????
double crossEntropyPQ = qGoalSemiring.getLogProb()- pqGoalSemiring.getFactor1().convertRealValue();//logZ(q)-E(s)?????????
double klPQ = -entropyP + crossEntropyPQ;
if(klPQ<0){System.out.println("kl divergence is negative, must be wrong"); System.exit(1);}
System.out.println("p_entropy=" + entropyP +"; "+"q_entropy=" + entropyQ +"; "+"pq_entropy=" + crossEntropyPQ +"; "+"pq_kl=" + klPQ);
}
}