Commit b3e9f364 authored by Andrey Filippov's avatar Andrey Filippov

tested LMA converging

parent c3fb4172
...@@ -861,4 +861,21 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{ ...@@ -861,4 +861,21 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{
} }
return true; return true;
} }
public static double [][] combineAffine(
double [][] ref_affine,
double [][] other_affine){
Matrix m_ref = new Matrix(ref_affine);
Matrix m_other = new Matrix(other_affine);
Matrix A1 = m_ref.getMatrix(0,1,0,1);
Matrix A2 =m_other.getMatrix(0,1,0,1);
Matrix B1 = m_ref.getMatrix(0,1,2,2);
Matrix B2 =m_other.getMatrix(0,1,2,2);
Matrix A = A2.times(A1);
Matrix B = A2.times(B1).plus(B2);
double [][] affine = {
{A.get(0,0),A.get(0,1),B.get(0,0)},
{A.get(1,0),A.get(1,1),B.get(1,0)}};
return affine;
}
} }
...@@ -533,6 +533,10 @@ public class OrthoMapsCollection implements Serializable{ ...@@ -533,6 +533,10 @@ public class OrthoMapsCollection implements Serializable{
// uses fixed_size gpu image size // uses fixed_size gpu image size
// TDCorrTile [] td_corr_tiles = // TDCorrTile [] td_corr_tiles =
TpTask [][] tp_tasks = new TpTask [2][]; TpTask [][] tp_tasks = new TpTask [2][];
int num_tries = 5;
double prev_rms = Double.NaN;
double rel_improve = 1E-3;
for (int ntry = 0; ntry < num_tries; ntry++) {
double [][][] vector_field = double [][][] vector_field =
ComboMatch.rectilinearVectorField(//rectilinearCorrelate_TD( // scene0/scene1 ComboMatch.rectilinearVectorField(//rectilinearCorrelate_TD( // scene0/scene1
clt_parameters, // final CLTParameters clt_parameters, clt_parameters, // final CLTParameters clt_parameters,
...@@ -601,7 +605,32 @@ public class OrthoMapsCollection implements Serializable{ ...@@ -601,7 +605,32 @@ public class OrthoMapsCollection implements Serializable{
num_iter, // int num_iter, // 20 num_iter, // int num_iter, // 20
last_run, // boolean last_run, last_run, // boolean last_run,
debugLevel); // int debug_level) debugLevel); // int debug_level)
if (debugLevel > -1) {
System.out.println("LMA result = "+lma_rslt); System.out.println("LMA result = "+lma_rslt);
}
if (lma_rslt < 0) {
System.out.println("LMA failed, result="+lma_rslt);
return null;
}
double rms = orthoPairLMA.getRms();
if (rms > prev_rms) {
if (debugLevel > -3) {
System.out.println("LMA RMSE worsened: new"+rms+" ("+ orthoPairLMA.getInitialRms()+"), prev="+prev_rms);
}
break;
}
affines_gpu[1]=OrthoMap.combineAffine(affines_gpu[1], orthoPairLMA.getAffine());
double [][] jtj = orthoPairLMA.getLastJtJ();
if ((prev_rms - rms)/prev_rms < rel_improve) {
if (debugLevel > -2) {
System.out.println("LMA relative RMSE improvement = "+((prev_rms - rms)/prev_rms)+" < "+rel_improve+", exiting.");
}
break;
}
prev_rms=rms;
} // for (int ntry = 0; ntry < num_tries; ntry++) {
// analyze result, re-run correlation // analyze result, re-run correlation
/* /*
...@@ -637,7 +666,7 @@ public class OrthoMapsCollection implements Serializable{ ...@@ -637,7 +666,7 @@ public class OrthoMapsCollection implements Serializable{
} }
*/ */
if (debugLevel > 1) { if (debugLevel > 1) {// show result here
String [] map_names = {ortho_maps[gpu_pair[0]].getName(),ortho_maps[gpu_pair[1]].getName()}; String [] map_names = {ortho_maps[gpu_pair[0]].getName(),ortho_maps[gpu_pair[1]].getName()};
ShowDoubleFloatArrays.showArrays( ShowDoubleFloatArrays.showArrays(
gpu_pair_img, gpu_pair_img,
......
...@@ -99,6 +99,30 @@ public class OrthoPairLMA { ...@@ -99,6 +99,30 @@ public class OrthoPairLMA {
} }
public double [][] getAffine(){
return new double [][] {
{parameters_vector[0],parameters_vector[1],parameters_vector[4]},
{parameters_vector[2],parameters_vector[3],parameters_vector[5]}};
}
public double getRms() {
return last_rms[0];
}
public double getInitialRms() {
return initial_rms[0];
}
public double getWeight() {
return weight;
}
public double [][] getLastJtJ(){
return getWJtJlambda(
0.0, // lambda, // *10, // temporary
this.last_jt);
}
//getWJtJlambda(
// lambda, // *10, // temporary
// this.last_jt)
private void setSamplesWeightsYCenters( private void setSamplesWeightsYCenters(
final double [][] vector_XYS, final double [][] vector_XYS,
final double [] weights_extra, // null or additional weights (such as elevation-based) final double [] weights_extra, // null or additional weights (such as elevation-based)
......
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