Go to the documentation of this file.00001
00002
00003
00004
00005
00006 #include "pdf1d_compare_samples.h"
00007
00008
00009 double pdf1d_prop_larger(const double* x1, int n1, const double* x2, int n2)
00010 {
00011 int n_larger = 0;
00012 for (int i=0;i<n1;++i)
00013 for (int j=0;j<n2;++j)
00014 if (x1[i]>x2[j]) n_larger++;
00015
00016 return double(n_larger)/(n1*n2);
00017 }
00018
00019
00020
00021
00022 bool pdf1d_larger_samples(const double* x1, int n1, const double* x2, int n2, double p)
00023 {
00024 double prop_larger = pdf1d_prop_larger(x1,n1,x2,n2);
00025 return prop_larger>p;
00026 }
00027
00028
00029
00030
00031 bool pdf1d_smaller_samples(const double* x1, int n1, const double* x2, int n2, double p)
00032 {
00033 double prop_larger = pdf1d_prop_larger(x1,n1,x2,n2);
00034 return prop_larger<(1.0-p);
00035 }
00036
00037
00038
00039 int pdf1d_select_largest_samples(vcl_vector<const double*>& x,
00040 vcl_vector<int>& n, double p)
00041 {
00042 int t = n.size();
00043
00044 int best_i = 0;
00045 int best_n_larger = 0;
00046
00047
00048
00049
00050 for (int i=0;i<t;++i)
00051 {
00052 int n_larger=0;
00053 for (int j=0;j<t;++j)
00054 {
00055 if (i==j) continue;
00056 if (pdf1d_larger_samples(x[i],n[i],x[j],n[j],p))
00057 n_larger++;
00058 }
00059
00060
00061 if (n_larger==(t-1)) return i;
00062
00063 if (i==0 || n_larger>best_n_larger)
00064 {
00065 best_i = i;
00066 best_n_larger = n_larger;
00067 }
00068 }
00069
00070 return best_i;
00071 }