00001 package commandline.Distributions;
00002
00003 import junit.framework.Assert;
00004
00005 import commandline.Algorithms.ArrayHandler;
00006 import commandline.ImageStuff.GeometricObjects.GenericEdge;
00007
00008
00009
00010 public class NormalIndicesDistribution_1A_Power_Law extends NormalIndicesDistribution{
00011 VerticalDistribution_Power_Law distribution_Power_Law;
00012
00013
00014 public NormalIndicesDistribution_1A_Power_Law(VerticalDistribution_Power_Law distribution_Power_Law){
00015 this.distribution_Power_Law=distribution_Power_Law;
00016 }
00017
00018
00019
00020
00021 public double[] getPMF_disc(GenericEdge e){
00022 int H=e.getHoogte();
00023 int L=e.getLengte();
00024 double[] PMF=makePMF(H,L);
00025 return normalize(PMF);
00026 }
00027
00028
00034 private double[] makePMF(int H, int L){
00035 double[] pmf=new double[L];
00036 float[] left=makeLeft(H,L);
00037 float[] right=ArrayHandler.Flip(left);
00038 if(2*left.length==L){
00039 for (int i = 0; i < left.length; i++) {
00040 pmf[i]=left[i];
00041 }
00042 for (int i = left.length; i != pmf.length; i++) {
00043 pmf[i]=right[i-left.length];
00044 }
00045 }else{
00046 if(2*left.length==L+1){
00047 for (int i = 0; i < left.length; i++) {
00048 pmf[i]=left[i];
00049 }
00050 for (int i = left.length; i != pmf.length; i++) {
00051
00052 pmf[i]=right[i-left.length+1];
00053 }
00054 }
00055 else{
00056 System.err.println("Length of the edge does not allow for a symmetric distribution");
00057 System.exit(-1);
00058 }
00059
00060 }
00061 return pmf;
00062 }
00063
00064
00071 private float[] makeLeft(int H,int L){
00072
00073 float[] helft=new float[(int)Math.ceil(L/2f)];
00074
00075 for (int index = 0; index != helft.length; index++) {
00076 addProbabilityForVertikalOffset(helft,index,H,L);
00077 }
00078 return helft;
00079 }
00080
00088 private void addProbabilityForVertikalOffset(float[] helft,int index,int H,int L){
00089 double v=(0.5f-index)*L*L/(float)H-H/2f;
00090 float f_v=(float)this.distribution_Power_Law.getPMF_at(v,-1f,-1d);
00091 Assert.assertTrue(f_v>=0);
00092
00093 float p_peak= 1f/2f-(float)index/(float)L;
00094 Assert.assertTrue(p_peak>=0);
00095 helft[index]+=f_v*p_peak;
00096
00097 float other_p = (1f/2f- p_peak)/(helft.length-1);
00098 Assert.assertTrue((helft.length-1)>=1);
00099 float other_p_times_f_v=other_p*f_v;
00100 if(other_p_times_f_v<0){
00101 System.err.println("probability must be >= 0");
00102 }
00103
00104 for (int inbetween = helft.length-1; inbetween !=index ; inbetween--) {
00105 helft[inbetween]+=other_p_times_f_v;
00106 }
00107 }
00108
00109 protected double evaluatePDF(double x,float A_0,float A_1,GenericEdge edge){
00110 System.err.println("should not use evaluatePDF(double x,float A_0,float A_1,GenericEdge edge) in class " + this.getClass().getName());
00111 System.exit(-1);
00112 return 0;
00113 }
00114
00115
00116 }