00001 package commandline.Distributions;
00002
00003 import junit.framework.Assert;
00004
00005 import commandline.CodingUtils.DataStructure;
00006 import commandline.ImageStuff.GeometricObjects.GenericEdge;
00007 import commandline.NormalMeshAlgorithm.Configuration;
00008 import commandline.NormalMeshAlgorithm.SnijPixelStrategy;
00009 import commandline.debuggingCode.Debug;
00010 import commandline.factories.SnijPixelStrategyBuilder;
00011
00012 public class VerticalDistribution_discr extends VerticalDistribution {
00013 public final static int UNUSED = -1;
00014 public final static float PROB = 0.4f;
00015 public final static float LAMBDA = 0.05f;
00016
00017
00018
00019
00020
00021
00022 public VerticalDistribution_discr(Configuration configuration, DataStructure breathFirstDatastructure) {
00023 super( configuration, breathFirstDatastructure);
00024
00025 this.lambda_streep=getLambdaEstimator(configuration, breathFirstDatastructure);
00026 this.p= this.getPEstimate(breathFirstDatastructure);
00027 System.out.println("p=" + this.p + " lambdastreep= " + lambda_streep);
00028 if (Debug.APPLE_TEST) {
00029 this.lambda_streep = 0.05f;
00030 this.p = 0.1f;
00031 Debug.print("APPLE_TEST: p=" + this.p + " lambda_streep "
00032 + this.lambda_streep);
00033 }
00034 if (Debug.HORIZON_TEST) {
00035
00036
00037 this.lambda_streep = 0.0005f;
00038 this.p = 0.0f;
00039 Debug.print("HORIZON_TEST: p=" + this.p + " lambda_streep "
00040 + this.lambda_streep);
00041 }
00042 }
00043
00044
00045
00051 public VerticalDistribution_discr(float lambda, float p) {
00052 this.p=p;
00053 this.lambda_streep=lambda;
00054 }
00055
00059 public double getPMF_at(double v, float normalizingFactor,
00060 double width) {
00061 float lambda = NormalIndicesDistribution.scaleLambaEstimator(this.lambda_streep,
00062 normalizingFactor);
00063 v = Math.abs(v);
00064 if (Debug.DEBUG)
00065 Assert.assertTrue(v >= 0);
00066 double p_v = (1 - p) * 0.5 * lambda * Math.pow((1 - lambda), v);
00067 if (v == 0) {
00068 p_v += p;
00069 }
00070 return p_v;
00071 }
00072
00078 protected float getLambdaEstimator(Configuration configuration,DataStructure breathFirstDatastructure){
00079 SnijPixelStrategy snij= SnijPixelStrategyBuilder.makeSnijPixelStrategy(configuration.getSnijPixelStrategyTYPE(),configuration);
00080 int N=0;
00081 float sum_abs_values=0;
00082 float normalisedVerticalOffset=0;
00083 for(GenericEdge e: breathFirstDatastructure.getParentCommitOrderedList()){
00084 normalisedVerticalOffset=(int)e.getVerticalOffset();
00085 if(e.isFlat() && e.getLengte()>2){
00086
00087 normalisedVerticalOffset=snij.calculateVerticalOffset(snij.berekenMiddenHoogte(e),commandline.ImageStuff.Image.getInstance().getPuntOpEnty(e.getMidLoc()).getZ());
00088 }
00089 normalisedVerticalOffset=normalisedVerticalOffset*e.getNormalisationFactor();
00090 sum_abs_values+=Math.abs(normalisedVerticalOffset);
00091 N++;
00092 }
00093 float schatter=N/sum_abs_values;
00094 if(!Debug.DISTIBUTION) Debug.print("schatter voor lambda = "+ schatter);
00095 return schatter;
00096 }
00097
00098
00102 protected float getPEstimate(DataStructure breathFirstDatastructure){
00103 int zero_count=0;
00104 for(GenericEdge e: breathFirstDatastructure.getParentCommitOrderedList()){
00105 if(e.getVerticalOffset()==0){zero_count++;}
00106 }
00107 float p=(float)zero_count/(float)breathFirstDatastructure.getParentCommitOrderedList().size();
00108 return p;
00109 }
00110
00111
00112
00113
00114 public NormalIndicesDistribution getNormalIndicesDistribution_1A() {
00115
00116 return new NormalIndicesDistribution_1A_discr(this);
00117 }
00118
00119
00120
00121
00122 public NormalIndicesDistribution getNormalIndicesDistribution_1B() {
00123 return new NormalIndicesDistribution_1B_discr();
00124 }
00125
00126
00127
00128
00129 public NormalIndicesDistribution getNormalIndicesDistribution_2A() {
00130 return new NormalIndicesDistribution_2A_discr(this);
00131 }
00132
00133
00134
00135
00136 public NormalIndicesDistribution getNormalIndicesDistribution_2B() {
00137 return new NormalIndicesDistribution_2B_discr();
00138 }
00139
00140 }