public void CPD_to_lambda_ukf(EDBUnit ret, EDBUnit node, DiscreteNodesCombination dc, EDBUnit lambda, int indexLambda, EDBUnit parentNext, EDBUnit pi_from_parents){
//lambda.print("");
if( lambda.get("PRECISION").getMatrix() != null )
if( lambda.get("PRECISION").getMatrixData() == 0){
ret.get("PRECISION").setMatrix(new Matrix(1,1,0));
ret.get("INFO_STATE").setMatrix(new Matrix(1,1,0));
ret.get("WEIGHT").setMatrix(new Matrix(1,1,1));
ret.get("RATIO").setMatrix(new Matrix(1,1,1));
return;
}
//pi_from_parents.print("");
EDBUnit cpd = node.get("CPD");
double Q = 0.0;
double Mean = 0.0;
EDBUnit f;
if( dc != null ){
Mean = cpd.get("MEAN").getMatrix(dc.getMap()).get();
Q = cpd.get("COV").getMatrix(dc.getMap()).get();
f = dc.getEquation();
}
else{
Mean = cpd.get("MEAN").getMatrixData();
Q = cpd.get("COV").getMatrixData();
f = node.get("EQUATION");
}
// %% find the coefficient of the independent variable in the original linear
// %% equation - the final ratio will be the reciprocal of this number.
// %% -wsun, 12/14/10.
double r = 0;
int j = 0;
Map<String, Integer> mapName1 = new HashMap<String, Integer>();
Matrix mValue = new Matrix(pi_from_parents.getSize());
for( String str: pi_from_parents.getRel("ISA").getMap().keySet() ){
if( !str.equalsIgnoreCase(parentNext.getName())) {
mapName1.put(str,j);
}else{
mapName1.put(str,j);
mValue.set(j, 0, 1);
}
j++;
}
//f.print(" f ");
r = substitution(0, f, mValue, mapName1);
r = Math.abs(r);
// invert function
//f.print(" f ");
//System.out.println("");
EDBUnit invF = convert( f, parentNext.getName(), node.getName() );
//invF.print(" invF ");
//lambda.print("lambda ");
// % transform the lambda message of the current node.
double Sigma_lambda = 0;
double mu_lambda = 0;
if( lambda.get("PRECISION").getData().equalsIgnoreCase("INFINITY")){
Sigma_lambda = 0;
mu_lambda = lambda.get("MU").getMatrix().get(0, indexLambda);
}else{
Sigma_lambda = 1/lambda.get("PRECISION").getMatrix().get(0, indexLambda);
mu_lambda = Sigma_lambda * lambda.get("INFO_STATE").getMatrix().get(0, indexLambda);
}
Matrix augSigma = new Matrix(pi_from_parents.getSize()+1, pi_from_parents.getSize()+1);
Matrix augMu = new Matrix(pi_from_parents.getSize()+1);
int i = 0;
Map<String, Integer> mapName = new HashMap<String, Integer>();
//pi_from_parents.print("pi_from_parents: ");
//parentNext.print("parentNext: ");
for( String str: pi_from_parents.getRel("ISA").getMap().keySet() ){
if( !str.equalsIgnoreCase(parentNext.getName())) {
mapName.put(str,i);
EDBUnit parent = pi_from_parents.get(str);
augMu.set(i,0, parent.get("MU").getMatrixData());
augSigma.set(i,i, parent.get("SIGMA").getMatrixData());
i++;
}
}
augMu.set(i, 0, Mean );
augSigma.set(i, i, Q);
mapName.put("NormalDist",i);
i++;
augMu.set(i, 0, mu_lambda);
augSigma.set(i, i, Sigma_lambda);
mapName.put(node.getName(),i);
//invF.print(" invF ");
Matrix rM = mysut_wgn( invF, augMu, augSigma, 0, mapName );
ret.get("WEIGHT").setMatrixData(1);
EDBUnit nonlinear = node.get("INFO.NONLINEAR");
if (nonlinear != null &&
nonlinear.getData().equalsIgnoreCase("TRUE")){
double d = Math.sqrt(rM.get(1))/Math.sqrt(Q+Sigma_lambda);
ret.get("RATIO").setMatrixData(d);
}else{
ret.get("RATIO").setMatrixData(1/r);
}
ret.get("PRECISION").setMatrixData( 1/rM.get(1));
ret.get("INFO_STATE").setMatrixData( rM.get(0)*ret.get("PRECISION").getMatrixData() );
//ret.print("Ret");
}