Commit d24659c3 authored by Andrey Filippov's avatar Andrey Filippov

testing different cost functions

parent 1183ecd4
......@@ -32,7 +32,9 @@ public class ConnectionCosts {
double orthoWeight;
double diagonalWeight;
double starPwr; // Divide cost by number of connections to this power
double starWeightPwr; // Use this power of tile weight when calculating connection cost
double starValPwr; // Raise value of each tile before averaging
int steps;
int [][][] neibs_init;
int [] mod_tiles;
......@@ -48,6 +50,7 @@ public class ConnectionCosts {
double orthoWeight,
double diagonalWeight,
double starPwr, // Divide cost by number of connections to this power
double starWeightPwr, // Use this power of tile weight when calculating connection cost
double starValPwr, // Raise value of each tile before averaging
int steps,
TilePlanes.PlaneData [][] planes,
......@@ -60,6 +63,7 @@ public class ConnectionCosts {
this.orthoWeight = orthoWeight;
this.diagonalWeight = diagonalWeight;
this.starPwr = starPwr; // Divide cost by number of connections to this power
this.starWeightPwr = starWeightPwr;
this.starValPwr = starValPwr; // Raise value of each tile before averaging
this.steps = steps;
}
......@@ -203,7 +207,7 @@ public class ConnectionCosts {
orthoWeight,
diagonalWeight,
starPwr, // double starPwr, // Divide cost by number of connections to this power
// starValPwr, //double starValPwr, // Raise value of each tile before averaging
starWeightPwr,
tnSurface,
preferDisparity,
-1); // debugLevel);
......@@ -268,7 +272,7 @@ public class ConnectionCosts {
}
if (neibs_changed){
vw[isTile][nl] = getStarValueWeight(
vw[isTile][nl] = getStarValueWeight2(
nsTile,
nl,
neibs0,
......@@ -276,7 +280,7 @@ public class ConnectionCosts {
orthoWeight,
diagonalWeight,
starPwr, // double starPwr, // Divide cost by number of connections to this power
// starValPwr, //double starValPwr, // Raise value of each tile before averaging
starWeightPwr, //
tnSurface,
preferDisparity,
-1); // debugLevel);
......@@ -348,7 +352,7 @@ public class ConnectionCosts {
* @param neibs array of 8 neighbors layers (N,NE,...NW), -1 - not connected
* @param orthoWeight multiply contribution of ortho neighbors
* @param diagonalWeight multiply contribution of diagonal neighbors
* @param diagonalWeight divide value by number of connections to this power (if !=0)
* @param starPwr, // Divide cost by number of connections to this power
* @param tnSurface TileNeibs instance to navigate tile index and control array borders
* @param preferDisparity - the first eigenvalue/vector is the most disparity-like
* (false - smallest eigenvalue)
......@@ -362,7 +366,7 @@ public class ConnectionCosts {
double orthoWeight,
double diagonalWeight,
double starPwr, // Divide cost by number of connections to this power
// double starValPwr, // Raise value of each tile before averaging
double starWeightPwr, // Use this power of tile weight when calculating connection cost
TileSurface.TileNeibs tnSurface,
boolean preferDisparity,
int debugLevel)
......@@ -377,6 +381,7 @@ public class ConnectionCosts {
merged_plane = merged_plane.mergePlaneToThis(
other_plane, // PlaneData otherPd,
other_weight, // double scale_other,
starWeightPwr, //
false, // boolean ignore_weights,
true, // boolean sum_weights,
preferDisparity,
......@@ -409,7 +414,7 @@ public class ConnectionCosts {
*/
public double [] getStarValueWeight(
public double [] getStarValueWeight2(
int nsTile,
int nl,
int [] neibs,
......@@ -417,7 +422,7 @@ public class ConnectionCosts {
double orthoWeight,
double diagonalWeight,
double starPwr, // Divide cost by number of connections to this power
// double starValPwr, // Raise value of each tile before averaging
double starWeightPwr, // Use this power of tile weight when calculating connection cost
TileSurface.TileNeibs tnSurface,
boolean preferDisparity,
int debugLevel)
......@@ -453,6 +458,7 @@ public class ConnectionCosts {
merged_plane = merged_plane.mergePlaneToThis(
other_plane, // PlaneData otherPd,
entry.getValue(), // double scale_other,
starPwr, // Divide cost by number of connections to this power
false, // boolean ignore_weights,
true, // boolean sum_weights,
preferDisparity,
......
......@@ -2172,6 +2172,8 @@ public class EyesisCorrectionParameters {
public boolean plDbgMerge = true; // Combine 'other' plane with current
public double plWorstWorsening = 2.0; // Worst case worsening after merge
public double plWorstWorsening2 = 5.0; // Worst case worsening for thin planes
public double plWorstEq = 1.0; // Worst case worsening after merge with equal weights
public double plWorstEq2 = 2.0; // Worst case worsening for thin planes with equal weights
public double plOKMergeEigen = 0.03; // If result of the merged planes is below, OK to use thin planes (higher) threshold
public double plMaxWorldSin2 = 0.1; // Maximal sine squared of the world angle between planes to merge. Set to >= 1.0 to disable
public double plWeakWorsening = 1.0; // Relax merge requirements for weaker planes
......@@ -2185,6 +2187,7 @@ public class EyesisCorrectionParameters {
public double plStarOrtho = 0.5; // When calculating cost for the connections scale 4 ortho neighbors
public double plStarDiag = 0.25; // When calculating cost for the connections scale 4 diagonal neighbors
public double plStarPwr = 0.5; // Divide cost by number of connections to this power
public double plStarWeightPwr = 0.5; // use this power of tile weight when calculating connection cost
public double plStarValPwr = 1.0; // Raise value of each tile before averaging
public double plDblTriLoss = 0.0001; // When resolving double triangles allow minor degradation (0.0 - strict)
public boolean plNewConfl = false; // Allow more conflicts if overall cost is reduced
......@@ -2535,6 +2538,8 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"plDbgMerge", this.plDbgMerge+"");
properties.setProperty(prefix+"plWorstWorsening", this.plWorstWorsening +"");
properties.setProperty(prefix+"plWorstWorsening2",this.plWorstWorsening2 +"");
properties.setProperty(prefix+"plWorstEq", this.plWorstEq +"");
properties.setProperty(prefix+"plWorstEq2", this.plWorstEq2 +"");
properties.setProperty(prefix+"plOKMergeEigen", this.plOKMergeEigen +"");
properties.setProperty(prefix+"plMaxWorldSin2", this.plMaxWorldSin2 +"");
properties.setProperty(prefix+"plWeakWorsening", this.plWeakWorsening +"");
......@@ -2547,6 +2552,7 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"plStarOrtho", this.plStarOrtho +"");
properties.setProperty(prefix+"plStarDiag", this.plStarDiag +"");
properties.setProperty(prefix+"plStarPwr", this.plStarPwr +"");
properties.setProperty(prefix+"plStarWeightPwr", this.plStarWeightPwr +"");
properties.setProperty(prefix+"plStarValPwr", this.plStarValPwr +"");
properties.setProperty(prefix+"plDblTriLoss", this.plDblTriLoss +"");
properties.setProperty(prefix+"plNewConfl", this.plNewConfl+"");
......@@ -2877,6 +2883,8 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"plDbgMerge")!=null) this.plDbgMerge=Boolean.parseBoolean(properties.getProperty(prefix+"plDbgMerge"));
if (properties.getProperty(prefix+"plWorstWorsening")!=null) this.plWorstWorsening=Double.parseDouble(properties.getProperty(prefix+"plWorstWorsening"));
if (properties.getProperty(prefix+"plWorstWorsening2")!=null) this.plWorstWorsening2=Double.parseDouble(properties.getProperty(prefix+"plWorstWorsening2"));
if (properties.getProperty(prefix+"plWorstEq")!=null) this.plWorstEq=Double.parseDouble(properties.getProperty(prefix+"plWorstEq"));
if (properties.getProperty(prefix+"plWorstEq2")!=null) this.plWorstEq2=Double.parseDouble(properties.getProperty(prefix+"plWorstEq2"));
if (properties.getProperty(prefix+"plOKMergeEigen")!=null) this.plOKMergeEigen=Double.parseDouble(properties.getProperty(prefix+"plOKMergeEigen"));
if (properties.getProperty(prefix+"plMaxWorldSin2")!=null) this.plMaxWorldSin2=Double.parseDouble(properties.getProperty(prefix+"plMaxWorldSin2"));
if (properties.getProperty(prefix+"plWeakWorsening")!=null) this.plWeakWorsening=Double.parseDouble(properties.getProperty(prefix+"plWeakWorsening"));
......@@ -2889,6 +2897,7 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"plStarOrtho")!=null) this.plStarOrtho=Double.parseDouble(properties.getProperty(prefix+"plStarOrtho"));
if (properties.getProperty(prefix+"plStarDiag")!=null) this.plStarDiag=Double.parseDouble(properties.getProperty(prefix+"plStarDiag"));
if (properties.getProperty(prefix+"plStarPwr")!=null) this.plStarPwr=Double.parseDouble(properties.getProperty(prefix+"plStarPwr"));
if (properties.getProperty(prefix+"plStarWeightPwr")!=null) this.plStarWeightPwr=Double.parseDouble(properties.getProperty(prefix+"plStarWeightPwr"));
if (properties.getProperty(prefix+"plStarValPwr")!=null) this.plStarValPwr=Double.parseDouble(properties.getProperty(prefix+"plStarValPwr"));
if (properties.getProperty(prefix+"plDblTriLoss")!=null) this.plDblTriLoss=Double.parseDouble(properties.getProperty(prefix+"plDblTriLoss"));
if (properties.getProperty(prefix+"plNewConfl")!=null) this.plNewConfl=Boolean.parseBoolean(properties.getProperty(prefix+"plNewConfl"));
......@@ -3247,6 +3256,8 @@ public class EyesisCorrectionParameters {
gd.addCheckbox ("Combine 'other' plane with the current (unused)", this.plDbgMerge);
gd.addNumericField("Worst case worsening after merge", this.plWorstWorsening, 6);
gd.addNumericField("Worst case worsening for thin planes", this.plWorstWorsening2, 6);
gd.addNumericField("Worst case worsening after merge with equal weights", this.plWorstEq, 6);
gd.addNumericField("Worst case worsening for thin planes with equal weights", this.plWorstEq2, 6);
gd.addNumericField("If result of the merged planes is below, OK to use thin planes (higher) threshold ",this.plOKMergeEigen, 6);
gd.addNumericField("Maximal sine squared of the world angle between planes to merge. Set to >= 1.0 to disable", this.plMaxWorldSin2, 6);
gd.addNumericField("Relax merge requirements for weaker planes", this.plWeakWorsening, 6);
......@@ -3259,6 +3270,7 @@ public class EyesisCorrectionParameters {
gd.addNumericField("When calculating cost for the connections scale 4 ortho neighbors", this.plStarOrtho, 6);
gd.addNumericField("When calculating cost for the connections scale 4 diagonal neighbors", this.plStarDiag, 6);
gd.addNumericField("Divide cost by number of connections to this power", this.plStarPwr, 6);
gd.addNumericField("Use this power of tile weight when calculating connection cost", this.plStarWeightPwr, 6);
gd.addNumericField("Raise value of each tile before averaging", this.plStarValPwr, 6);
gd.addNumericField("When resolving double triangles allow minor degradation (0.0 - strict)", this.plDblTriLoss, 6);
gd.addCheckbox ("Allow more conflicts if overall cost is reduced", this.plNewConfl);
......@@ -3602,6 +3614,8 @@ public class EyesisCorrectionParameters {
this.plDbgMerge= gd.getNextBoolean();
this.plWorstWorsening= gd.getNextNumber();
this.plWorstWorsening2= gd.getNextNumber();
this.plWorstEq= gd.getNextNumber();
this.plWorstEq2= gd.getNextNumber();
this.plOKMergeEigen= gd.getNextNumber();
this.plMaxWorldSin2= gd.getNextNumber();
this.plWeakWorsening= gd.getNextNumber();
......@@ -3614,6 +3628,7 @@ public class EyesisCorrectionParameters {
this.plStarOrtho= gd.getNextNumber();
this.plStarDiag= gd.getNextNumber();
this.plStarPwr= gd.getNextNumber();
this.plStarWeightPwr= gd.getNextNumber();
this.plStarValPwr= gd.getNextNumber();
this.plDblTriLoss= gd.getNextNumber();
this.plNewConfl= gd.getNextBoolean();
......
This diff is collapsed.
......@@ -2033,9 +2033,27 @@ public class TilePlanes {
* @return PlaneData object representing merged planes with combined weight (scale_other*otherPd.weight + this.weight),
* recalculated center, eigenvalues and eigenvectors
*/
public PlaneData mergePlaneToThis1(
PlaneData otherPd,
double scale_other,
boolean ignore_weights,
boolean sum_weights,
boolean preferDisparity, // Always start with disparity-most axis (false - lowest eigenvalue)
int debugLevel)
{
return mergePlaneToThis(
otherPd,
scale_other,
1.0, // double starWeightPwr, // Use this power of tile weight when calculating connection cost
ignore_weights,
sum_weights,
preferDisparity, // Always start with disparity-most axis (false - lowest eigenvalue)
debugLevel);
}
public PlaneData mergePlaneToThis(
PlaneData otherPd,
double scale_other,
double starWeightPwr, // Use this power of tile weight when calculating connection cost
boolean ignore_weights,
boolean sum_weights,
boolean preferDisparity, // Always start with disparity-most axis (false - lowest eigenvalue)
......@@ -2058,8 +2076,17 @@ public class TilePlanes {
Matrix this_eig_vectors = new Matrix(this.vectors).transpose(); // vectors are saved as rows
Matrix this_center = new Matrix(this.getZxy(),3);
Matrix other_center = new Matrix(otherPd.getZxy(),3); // should already be relative to this supertile center
double sum_weight = scale_other * otherPd.weight + this.weight;
double other_fraction = ignore_weights? (scale_other/(scale_other + 1.0)): ((scale_other * otherPd.weight) / sum_weight);
double this_weight = this.weight;
double other_weight = otherPd.weight;
if (starWeightPwr == 0){
ignore_weights = true;
} else if (starWeightPwr != 1.0){
this_weight = Math.pow(this_weight, starWeightPwr);
other_weight = Math.pow(other_weight,starWeightPwr);
}
double sum_weight = scale_other * other_weight + this_weight;// should be the same for
double other_fraction = ignore_weights? (scale_other/(scale_other + 1.0)): ((scale_other * other_weight) / sum_weight);
Matrix common_center = this_center.times(1.0 - other_fraction).plus(other_center.times(other_fraction));
Matrix other_offset = other_center.minus(this_center); // other center from this center
if ((this.values[0] == 0.0) || (otherPd.values[0] == 0.0)) {
......@@ -2189,12 +2216,23 @@ public class TilePlanes {
pd.setZxy(common_center.getColumnPackedCopy()); // set new center
// what weight to use? cloned is original weight for this supertile
// or use weighted average like below?
double new_weight;
if (sum_weights) {
new_weight = sum_weight; // normalize while averaging by the caller
} else { // how it was before
new_weight = other_fraction * other_weight + (1.0 - other_fraction) * this_weight;
}
if (!ignore_weights && ((starWeightPwr != 1.0))){
new_weight = Math.pow(new_weight,1.0/starWeightPwr);
}
pd.setWeight(new_weight);
/*
if (sum_weights) {
pd.setWeight(sum_weight); // normalize while averaging by the caller
} else { // how it was before
pd.setWeight(other_fraction * otherPd.weight + (1.0 - other_fraction) * this.weight);
pd.setWeight(other_fraction * other_weight + (1.0 - other_fraction) * this_weight);
}
*/
return pd;
}
......
......@@ -3419,6 +3419,8 @@ public class TileProcessor {
st.filterNeighborPlanes(
clt_parameters.plWorstWorsening, // final double worst_worsening,
clt_parameters.plWorstWorsening2,// final double worst_worsening2 Worst case worsening for thin planes,
clt_parameters.plWorstEq, // final double worstEq, // Worst case worsening after merge with equal weights
clt_parameters.plWorstEq2, // final double worstEq2, // Worst case worsening for thin planes with equal weights
clt_parameters.plWeakWorsening, // final double worst_worsening,
clt_parameters.plOKMergeEigen, // final double okMergeEigen, f result of the merged planes is below, OK to use thin planes (higher) threshold
clt_parameters.plMaxWorldSin2, // final double maxWorldSin2,
......@@ -3458,6 +3460,7 @@ public class TileProcessor {
clt_parameters.plStarOrtho, // double orthoWeight,
clt_parameters.plStarDiag, // double diagonalWeight,
clt_parameters.plStarPwr, // double starPwr, // Divide cost by number of connections to this power
clt_parameters.plStarWeightPwr,// double starWeightPwr, // Use this power of tile weight when calculating connection cost
clt_parameters.plStarValPwr, // double starValPwr, // Raise value of each tile before averaging
clt_parameters.plDblTriLoss, // double diagonalWeight,
clt_parameters.plNewConfl, // boolean preferDisparity, // Allow more conflicts if overall cost is reduced
......@@ -3568,6 +3571,8 @@ public class TileProcessor {
st.filterNeighborPlanes(
clt_parameters.plWorstWorsening, // final double worst_worsening,
clt_parameters.plWorstWorsening2,// final double worst_worsening2 Worst case worsening for thin planes,
clt_parameters.plWorstEq, // ffinal double worstEq, // Worst case worsening after merge with equal weights
clt_parameters.plWorstEq2, // ffinal double worstEq2, // Worst case worsening for thin planes with equal weights
clt_parameters.plWeakWorsening, // final double worst_worsening,
clt_parameters.plOKMergeEigen, // final double okMergeEigen,
clt_parameters.plMaxWorldSin2, // final double maxWorldSin2,
......@@ -3586,23 +3591,23 @@ public class TileProcessor {
st.resolveConflicts(
clt_parameters.plMaxEigen,
clt_parameters.plConflDualTri, // boolean conflDualTri, // Resolve dual triangles conflict (odoodo)
clt_parameters.plConflMulti, // boolean conflMulti, // Resolve multiple odo triangles conflicts
clt_parameters.plConflDiag, // boolean conflDiag, // Resolve diagonal (ood) conflicts
clt_parameters.plConflStar, // boolean conflStar, // Resolve all conflicts around a supertile
clt_parameters.plStarSteps, // int starSteps, // How far to look around when calculationg connection cost
clt_parameters.plStarOrtho, // double orthoWeight,
clt_parameters.plStarDiag, // double diagonalWeight,
clt_parameters.plStarPwr, // double starPwr, // Divide cost by number of connections to this power
clt_parameters.plStarValPwr, // double starValPwr, // Raise value of each tile before averaging
clt_parameters.plDblTriLoss, // double diagonalWeight,
clt_parameters.plNewConfl, // boolean preferDisparity, // Allow more conflicts if overall cost is reduced
clt_parameters.plMaxChanges, // int maxChanges, // Maximal number of simultaneous connection changes around one tile (0 - any)
clt_parameters.plConflDualTri, // boolean conflDualTri, // Resolve dual triangles conflict (odoodo)
clt_parameters.plConflMulti, // boolean conflMulti, // Resolve multiple odo triangles conflicts
clt_parameters.plConflDiag, // boolean conflDiag, // Resolve diagonal (ood) conflicts
clt_parameters.plConflStar, // boolean conflStar, // Resolve all conflicts around a supertile
clt_parameters.plStarSteps, // int starSteps, // How far to look around when calculationg connection cost
clt_parameters.plStarOrtho, // double orthoWeight,
clt_parameters.plStarDiag, // double diagonalWeight,
clt_parameters.plStarPwr, // double starPwr, // Divide cost by number of connections to this power
clt_parameters.plStarWeightPwr, // double starWeightPwr, // Use this power of tile weight when calculating connection cost
clt_parameters.plStarValPwr, // double starValPwr, // Raise value of each tile before averaging
clt_parameters.plDblTriLoss, // double diagonalWeight,
clt_parameters.plNewConfl, // boolean preferDisparity, // Allow more conflicts if overall cost is reduced
clt_parameters.plMaxChanges, // int maxChanges, // Maximal number of simultaneous connection changes around one tile (0 - any)
clt_parameters.plPreferDisparity,
1, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
}
while (true) {
......
......@@ -399,6 +399,17 @@ public class TwoLayerNeighbors {
{
ArrayList<NeibVariant> variant_list = new ArrayList<NeibVariant>();
while (nextSelection()){
if (debugLevel > 0) {
System.out.print("trying variant: [");
for (int i = 0; i < selection_star.length; i++){
System.out.print(selection_star[i]);
}
System.out.print("] [");
for (int i = 0; i < selection_conns.length; i++){
System.out.print(selection_conns[i]);
}
System.out.print("]: ");
}
NeibVariant variant = generateVariant(debugLevel);
if (variant != null){
int num_changes = variant.diffToOther(neibs_init, 0);
......
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