}
public DblMatrix getValueAt(DblMatrix factors)
{
BufferSolution sol;
DblMatrix fact;
this.Params.show("Parameters");
// for (int j=0;j<this.bufferSolutions.size();j++)
// {
// sol = (BufferSolution)this.bufferSolutions.get(j);
//
// if (j==0)
// {
// fact = new DblMatrix(0.0);
// }
// else
// {
// fact = this.getParam(new String("Factor"+j));
// }
//
// //We're optimizing the log of the mixture coefficients.
// factors.setDblAt(DblMatrix.pow(10,fact),j);
// }
BufferSolution mixture = null;
//mixture = BufferSolution.createMixture(this.repos,this.bufferSolutions,factors);
mixture = BufferSolution.createMixture(this.bufferSolutions,factors);
mixture.show("Mixture");
DblMatrix concMatrix = new DblMatrix(this.BVector.getN());
HashMap spec_conc = null;
spec_conc = (HashMap)mixture.species(this.pH);
//Get the predicted ionic strength too!
HashMap ionicStr = null;
ionicStr = mixture.ionicStr(this.pH);
DblMatrix iStrength = (DblMatrix)ionicStr.get("total");
Set buffers = spec_conc.keySet();
Set ions;
Iterator iter = buffers.iterator();
Iterator iterIon;
String ionComp=null;
int row=0;
HashMap abuff=null;
String buffer;
int k=0;
while (iter.hasNext())
{
buffer = (String)iter.next();
abuff = (HashMap)spec_conc.get(buffer);
ions = abuff.keySet();
iterIon = ions.iterator();
while (iterIon.hasNext())
{
ionComp=(String)iterIon.next();
concMatrix.setDblAt((DblMatrix)abuff.get(ionComp),k);
k++;
}
}
//Need to remove constraints for which BVector is NaN
this.AMatrix.show("AMatrix");
concMatrix.show("concMatrix");
this.BVector.show("BVector");
DblMatrix ionicStrPenalty = iStrength.minus(this.desiredIonicStr);
ionicStrPenalty = ionicStrPenalty.pow(2);
DblMatrix resids = (this.AMatrix.dot(concMatrix)).minus(this.BVector);
DblMatrix ONE = new DblMatrix(1.0);
resids = resids.getMap(ONE.minus(DblMatrix.isNaN(resids)));
resids = DblMatrix.sum(resids.pow(2),1);
resids = resids.plus(ionicStrPenalty);
resids = DblMatrix.sqrt(resids);
//resids.show("resids2");