@Override
public void execute() throws AlgorithmError {
for (int i = 0; i < obs.size() && !interrupted; i++) {
ValidObservation ob = obs.get(i);
fitter.addObservedPoint(1.0,
ob.getJD() - zeroPoint, ob.getMag());
}
if (!interrupted) {
try {
function = fitter.fit();
fit = new ArrayList<ValidObservation>();
residuals = new ArrayList<ValidObservation>();
double sumSqResiduals = 0;
String comment = LocaleProps
.get("MODEL_INFO_POLYNOMIAL_DEGREE_DESC")
+ degree;
// Create fit and residual observations and
// compute the sum of squares of residuals for
// Akaike and Bayesean Information Criteria.
for (int i = 0; i < obs.size() && !interrupted; i++) {
ValidObservation ob = obs.get(i);
double y = function.value(ob.getJD()
- zeroPoint);
ValidObservation fitOb = new ValidObservation();
fitOb.setDateInfo(new DateInfo(ob.getJD()));
fitOb.setMagnitude(new Magnitude(y, 0));
fitOb.setBand(SeriesType.Model);
fitOb.setComments(comment);
fit.add(fitOb);
ValidObservation resOb = new ValidObservation();
resOb.setDateInfo(new DateInfo(ob.getJD()));
double residual = ob.getMag() - y;
resOb.setMagnitude(new Magnitude(residual,
0));
resOb.setBand(SeriesType.Residuals);
resOb.setComments(comment);
residuals.add(resOb);
sumSqResiduals += (residual * residual);
}