Commit d0f3ff06 authored by Andrey Filippov's avatar Andrey Filippov

changed parameters for automatic LMA run

parent 41015a35
...@@ -3018,15 +3018,15 @@ d_s2/d_x0= 2*delta_x*delta_y^2/r2^2 ...@@ -3018,15 +3018,15 @@ d_s2/d_x0= 2*delta_x*delta_y^2/r2^2
String msg="initial Jacobian matrix calculation. Points:"+this.dataValues.length+" Parameters:"+this.currentVector.length; String msg="initial Jacobian matrix calculation. Points:"+this.dataValues.length+" Parameters:"+this.currentVector.length;
if (debugLevel>1) System.out.println(msg); if (debugLevel>1) System.out.println(msg);
if (this.updateStatus) IJ.showStatus(msg); if (this.updateStatus) IJ.showStatus(msg);
System.out.println("*** 1 @ "+ IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),5)); if (debugLevel>1) System.out.println("*** 1 @ "+ IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),5));
this.currentfX=createFXandJacobian(this.currentVector, true); // is it always true here (this.jacobian==null) this.currentfX=createFXandJacobian(this.currentVector, true); // is it always true here (this.jacobian==null)
System.out.println("*** 2 @ "+ IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),5)); if (debugLevel>1) System.out.println("*** 2 @ "+ IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),5));
this.lMAArrays=calculateJacobianArrays(this.currentfX); this.lMAArrays=calculateJacobianArrays(this.currentfX);
System.out.println("*** 3 @ "+ IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),5)); if (debugLevel>1) System.out.println("*** 3 @ "+ IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),5));
this.currentRMS= calcErrorDiffY(this.currentfX,false); this.currentRMS= calcErrorDiffY(this.currentfX,false);
System.out.println("*** 4 @ "+ IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),5)); if (debugLevel>1) System.out.println("*** 4 @ "+ IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),5));
this.currentRMSPure=calcErrorDiffY(this.currentfX, true); this.currentRMSPure=calcErrorDiffY(this.currentfX, true);
System.out.println("*** 5 @ "+ IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),5)); if (debugLevel>1) System.out.println("*** 5 @ "+ IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),5));
msg=this.currentStrategyStep+": initial RMS="+IJ.d2s(this.currentRMS,8)+" (pure RMS="+IJ.d2s(this.currentRMSPure,8)+")"+ msg=this.currentStrategyStep+": initial RMS="+IJ.d2s(this.currentRMS,8)+" (pure RMS="+IJ.d2s(this.currentRMSPure,8)+")"+
". Calculating next Jacobian. Points:"+this.dataValues.length+" Parameters:"+this.currentVector.length; ". Calculating next Jacobian. Points:"+this.dataValues.length+" Parameters:"+this.currentVector.length;
if (debugLevel>1) System.out.println(msg); if (debugLevel>1) System.out.println(msg);
...@@ -3164,97 +3164,97 @@ public void stepLevenbergMarquardtAction(int debugLevel){// ...@@ -3164,97 +3164,97 @@ public void stepLevenbergMarquardtAction(int debugLevel){//
* *
*/ */
public boolean selectLMAParameters(boolean autoSel){ public boolean selectLMAParameters(boolean autoSel){
// int numSeries=fittingStrategy.getNumSeries(); // int numSeries=fittingStrategy.getNumSeries();
// boolean resetCorrections=false; // boolean resetCorrections=false;
GenericDialog gd = new GenericDialog("Levenberg-Marquardt algorithm parameters lens aberrations approxiamtion"); GenericDialog gd = new GenericDialog("Levenberg-Marquardt algorithm parameters lens aberrations approxiamtion");
//TODO: change to selection using series comments //TODO: change to selection using series comments
// gd.addNumericField("Fitting series number", this.currentStrategyStep, 0, 3," (-1 - current)"); // gd.addNumericField("Fitting series number", this.currentStrategyStep, 0, 3," (-1 - current)");
int suggestStep=this.currentStrategyStep; int suggestStep=this.currentStrategyStep;
boolean suggestStopEachStep=this.stopEachStep; boolean suggestStopEachStep=this.stopEachStep;
if (autoSel){ if (autoSel){
suggestStep=0; suggestStep=0;
suggestStopEachStep=false; suggestStopEachStep=false;
} }
FieldStrategies fs=fieldFitting.fieldStrategies; FieldStrategies fs=fieldFitting.fieldStrategies;
String [] indices=new String[fs.getNumStrategies()+1]; String [] indices=new String[fs.getNumStrategies()+1];
indices[0]="current strategy"; indices[0]="current strategy";
for (int i=0;i<fs.getNumStrategies();i++) { for (int i=0;i<fs.getNumStrategies();i++) {
indices[i+1]=i+": "+fs.getComment(i)+" ("+(fs.isStopAfterThis(i)?"STOP":"CONTINUE")+")"; indices[i+1]=i+": "+fs.getComment(i)+" ("+(fs.isStopAfterThis(i)?"STOP":"CONTINUE")+")";
} }
if (suggestStep>=(indices.length-1)) suggestStep=indices.length-2; // last one if (suggestStep>=(indices.length-1)) suggestStep=indices.length-2; // last one
gd.addChoice("Fitting series", indices,indices[suggestStep+1]); gd.addChoice("Fitting series", indices,indices[suggestStep+1]);
gd.addCheckbox("Debug df/dX0, df/dY0", false); gd.addCheckbox("Debug df/dX0, df/dY0", false);
gd.addNumericField("Debug Jacobian for point number", this.debugPoint, 0, 5,"(-1 - none)"); gd.addNumericField("Debug Jacobian for point number", this.debugPoint, 0, 5,"(-1 - none)");
gd.addNumericField("Debug Jacobian for parameter number", this.debugParameter, 0, 5,"(-1 - none)"); gd.addNumericField("Debug Jacobian for parameter number", this.debugParameter, 0, 5,"(-1 - none)");
// gd.addCheckbox("Keep current correction parameters (do not reset)", this.keepCorrectionParameters); // gd.addCheckbox("Keep current correction parameters (do not reset)", this.keepCorrectionParameters);
gd.addNumericField("Initial LMA Lambda ", 0.0, 5, 8, "0 - keep, last was "+this.lambda); gd.addNumericField("Initial LMA Lambda ", 0.0, 5, 8, "0 - keep, last was "+this.lambda);
gd.addNumericField("Multiply lambda on success", this.lambdaStepDown, 5); gd.addNumericField("Multiply lambda on success", this.lambdaStepDown, 5);
gd.addNumericField("Threshold RMS to exit LMA", this.thresholdFinish, 7,9,"pix"); gd.addNumericField("Threshold RMS to exit LMA", this.thresholdFinish, 7,9,"pix");
gd.addNumericField("Multiply lambda on failure", this.lambdaStepUp, 5); gd.addNumericField("Multiply lambda on failure", this.lambdaStepUp, 5);
gd.addNumericField("Threshold lambda to fail", this.maxLambda, 5); gd.addNumericField("Threshold lambda to fail", this.maxLambda, 5);
gd.addNumericField("Maximal number of iterations", this.numIterations, 0); gd.addNumericField("Maximal number of iterations", this.numIterations, 0);
gd.addCheckbox("Dialog after each iteration step", suggestStopEachStep); //this.stopEachStep); gd.addCheckbox("Dialog after each iteration step", suggestStopEachStep); //this.stopEachStep);
gd.addCheckbox("Dialog after each iteration series", this.stopEachSeries); gd.addCheckbox("Dialog after each iteration series", this.stopEachSeries);
gd.addCheckbox("Dialog after each failure", this.stopOnFailure); gd.addCheckbox("Dialog after each failure", this.stopOnFailure);
gd.addCheckbox("Show modified parameters", this.showParams); gd.addCheckbox("Show modified parameters", this.showParams);
gd.addCheckbox("Show disabled parameters", this.showDisabledParams); gd.addCheckbox("Show disabled parameters", this.showDisabledParams);
gd.addCheckbox("Show per-sample correction parameters", this.showCorrectionParams); gd.addCheckbox("Show per-sample correction parameters", this.showCorrectionParams);
gd.addNumericField("Maximal number of threads (0 - old code)", this.threadsMax, 0); gd.addNumericField("Maximal number of threads (0 - old code)", this.threadsMax, 0);
//threadsMax //threadsMax
// gd.addCheckbox("Reset all per-sample corrections to zero", resetCorrections); // gd.addCheckbox("Reset all per-sample corrections to zero", resetCorrections);
// gd.addCheckbox("Show debug images before correction",this.showThisImages); // gd.addCheckbox("Show debug images before correction",this.showThisImages);
// gd.addCheckbox("Show debug images after correction", this.showNextImages); // gd.addCheckbox("Show debug images after correction", this.showNextImages);
// gd.addNumericField("Maximal number of threads", this.threadsMax, 0); // gd.addNumericField("Maximal number of threads", this.threadsMax, 0);
// gd.addCheckbox("Use memory-saving/multithreaded version", this.threadedLMA); // gd.addCheckbox("Use memory-saving/multithreaded version", this.threadedLMA);
gd.showDialog(); gd.showDialog();
if (gd.wasCanceled()) return false; if (gd.wasCanceled()) return false;
this.currentStrategyStep= gd.getNextChoiceIndex()-1; //(int) gd.getNextNumber(); this.currentStrategyStep= gd.getNextChoiceIndex()-1; //(int) gd.getNextNumber();
if (this.currentStrategyStep>=0){ if (this.currentStrategyStep>=0){
getStrategy(this.currentStrategyStep); getStrategy(this.currentStrategyStep);
} }
this.debugDerivativesFxDxDy=gd.getNextBoolean(); this.debugDerivativesFxDxDy=gd.getNextBoolean();
debugPoint= (int) gd.getNextNumber(); debugPoint= (int) gd.getNextNumber();
debugParameter= (int) gd.getNextNumber(); debugParameter= (int) gd.getNextNumber();
// this.keepCorrectionParameters = gd.getNextBoolean(); // this.keepCorrectionParameters = gd.getNextBoolean();
double preLambda=gd.getNextNumber(); double preLambda=gd.getNextNumber();
if (preLambda>0.0) this.lambda= preLambda; if (preLambda>0.0) this.lambda= preLambda;
this.lambdaStepDown= gd.getNextNumber(); this.lambdaStepDown= gd.getNextNumber();
this.thresholdFinish= gd.getNextNumber(); this.thresholdFinish= gd.getNextNumber();
this.lambdaStepUp= gd.getNextNumber(); this.lambdaStepUp= gd.getNextNumber();
this.maxLambda= gd.getNextNumber(); this.maxLambda= gd.getNextNumber();
this.numIterations= (int) gd.getNextNumber(); this.numIterations= (int) gd.getNextNumber();
this.stopEachStep= gd.getNextBoolean(); this.stopEachStep= gd.getNextBoolean();
this.stopEachSeries= gd.getNextBoolean(); this.stopEachSeries= gd.getNextBoolean();
this.stopOnFailure= gd.getNextBoolean(); this.stopOnFailure= gd.getNextBoolean();
this.showParams= gd.getNextBoolean(); this.showParams= gd.getNextBoolean();
this.showDisabledParams= gd.getNextBoolean(); this.showDisabledParams= gd.getNextBoolean();
this.showCorrectionParams= gd.getNextBoolean(); this.showCorrectionParams= gd.getNextBoolean();
this.threadsMax= (int) gd.getNextNumber(); this.threadsMax= (int) gd.getNextNumber();
// if (!keepCorrectionParameters) fieldFitting.resetSampleCorr(); // if (!keepCorrectionParameters) fieldFitting.resetSampleCorr();
return true; return true;
} }
public void listParameters(String title, String path){ public void listParameters(String title, String path){
String header="State\tDescription\tValue\tUnits"; String header="State\tDescription\tValue\tUnits";
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
for (String s:this.fieldFitting.getParameterValueStrings(true,true)){ //this.showDisabledParams)){ // for (String s:this.fieldFitting.getParameterValueStrings(true,true)){ //this.showDisabledParams)){ //
sb.append(s+"\n"); sb.append(s+"\n");
} }
if (path!=null) { if (path!=null) {
CalibrationFileManagement.saveStringToFile ( CalibrationFileManagement.saveStringToFile (
path, path,
header+"\n"+sb.toString()); header+"\n"+sb.toString());
} else { } else {
new TextWindow(title, header, sb.toString(), 800,1000); new TextWindow(title, header, sb.toString(), 800,1000);
} }
} }
public void listData(String title, String path){ public void listData(String title, String path){
...@@ -4282,6 +4282,12 @@ public boolean LevenbergMarquardt( ...@@ -4282,6 +4282,12 @@ public boolean LevenbergMarquardt(
double savedLambda=this.lambda; double savedLambda=this.lambda;
this.debugLevel=debugLevel; this.debugLevel=debugLevel;
if (openDialog && !selectLMAParameters(autoSel)) return false; if (openDialog && !selectLMAParameters(autoSel)) return false;
if (!openDialog && autoSel) {
this.stopEachStep= false;
this.stopEachSeries= false;
this.currentStrategyStep=0;
}
this.startTime=System.nanoTime(); this.startTime=System.nanoTime();
// create savedVector (it depends on parameter masks), restore from it if aborted // create savedVector (it depends on parameter masks), restore from it if aborted
// fieldFitting.initSampleCorrVector( // fieldFitting.initSampleCorrVector(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment