Преглед изворни кода

v.kernel: stddeviation -> radius

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@54271 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Metz пре 12 година
родитељ
комит
28e75cf821
3 измењених фајлова са 20 додато и 13 уклоњено
  1. 5 3
      vector/v.kernel/function.c
  2. 9 9
      vector/v.kernel/main.c
  3. 6 1
      vector/v.kernel/v.kernel.html

+ 5 - 3
vector/v.kernel/function.c

@@ -103,9 +103,10 @@ double euclidean_distance(double *x, double *y, int n)
 
 
 /*****************kernel density functions******************************/
 /*****************kernel density functions******************************/
 
 
-double gaussianKernel2(double term, double bandwidth, double x)
+double gaussianKernel4(double term, double bandwidth, double x)
 {
 {
     /* term is set by setKernelFunction */
     /* term is set by setKernelFunction */
+    /* bandwidth is here SD */
 
 
     /*
     /*
     double term =
     double term =
@@ -114,7 +115,8 @@ double gaussianKernel2(double term, double bandwidth, double x)
 
 
     x /= bandwidth;
     x /= bandwidth;
 
 
-    return (term * exp(-(x * x) / 2.));
+    /* SD = radius (bandwidth) / 4 */
+    return (term * exp((x * x) / -2.));
 }
 }
 
 
 /* Note: these functions support currently only 1D and 2D, consider this for example 
 /* Note: these functions support currently only 1D and 2D, consider this for example 
@@ -290,7 +292,7 @@ void setKernelFunction(int function, int dimension, double bandwidth, double *te
 	*term *= (35. / 32);
 	*term *= (35. / 32);
 	break;
 	break;
     case KERNEL_GAUSSIAN:
     case KERNEL_GAUSSIAN:
-	kernelfn = gaussianKernel2;
+	kernelfn = gaussianKernel4;
 	*term =
 	*term =
 	    1. / (pow(bandwidth, dimension) * pow((2. * M_PI), dimension / 2.));
 	    1. / (pow(bandwidth, dimension) * pow((2. * M_PI), dimension / 2.));
 	break;
 	break;

+ 9 - 9
vector/v.kernel/main.c

@@ -75,7 +75,7 @@ double L(double smooth)
 int main(int argc, char **argv)
 int main(int argc, char **argv)
 {
 {
     struct Option *in_opt, *net_opt, *out_opt;
     struct Option *in_opt, *net_opt, *out_opt;
-    struct Option *stddev_opt, *dsize_opt, *segmax_opt, *netmax_opt,
+    struct Option *radius_opt, *dsize_opt, *segmax_opt, *netmax_opt,
 	*multip_opt, *node_opt, *kernel_opt;
 	*multip_opt, *node_opt, *kernel_opt;
     struct Flag *flag_o, *flag_q, *flag_normalize, *flag_multiply;
     struct Flag *flag_o, *flag_q, *flag_normalize, *flag_multiply;
     char *desc;
     char *desc;
@@ -125,11 +125,11 @@ int main(int argc, char **argv)
     out_opt->required = YES;
     out_opt->required = YES;
     out_opt->description = _("Output raster/vector map");
     out_opt->description = _("Output raster/vector map");
 
 
-    stddev_opt = G_define_option();
-    stddev_opt->key = "stddeviation";
-    stddev_opt->type = TYPE_DOUBLE;
-    stddev_opt->required = YES;
-    stddev_opt->description = _("Standard deviation in map units");
+    radius_opt = G_define_option();
+    radius_opt->key = "radius";
+    radius_opt->type = TYPE_DOUBLE;
+    radius_opt->required = YES;
+    radius_opt->description = _("Kernel radius in map units");
 
 
     dsize_opt = G_define_option();
     dsize_opt = G_define_option();
     dsize_opt->key = "dsize";
     dsize_opt->key = "dsize";
@@ -206,7 +206,8 @@ int main(int argc, char **argv)
 	exit(EXIT_FAILURE);
 	exit(EXIT_FAILURE);
 
 
     /*read options */
     /*read options */
-    sigma = atof(stddev_opt->answer);
+    dmax = atof(radius_opt->answer);
+    sigma = dmax;
     dsize = atof(dsize_opt->answer);
     dsize = atof(dsize_opt->answer);
     segmax = atof(segmax_opt->answer);
     segmax = atof(segmax_opt->answer);
     netmax = atof(netmax_opt->answer);
     netmax = atof(netmax_opt->answer);
@@ -374,9 +375,8 @@ int main(int argc, char **argv)
 	}
 	}
     }
     }
 
 
-    dmax = sigma;
     if (kernel_function == KERNEL_GAUSSIAN)
     if (kernel_function == KERNEL_GAUSSIAN)
-	dmax = sigma * 4.;  /* should be sigma /= 4.; */
+	sigma /= 4.;
 
 
     if (net_opt->answer) {
     if (net_opt->answer) {
 	setKernelFunction(kernel_function, 1, sigma, &term);
 	setKernelFunction(kernel_function, 1, sigma, &term);

+ 6 - 1
vector/v.kernel/v.kernel.html

@@ -16,7 +16,12 @@ and can be enabled with <em>node=split</em>.
 The <em>mult</em> option is needed to overcome the limitation that
 The <em>mult</em> option is needed to overcome the limitation that
 the resulting density in case of a vector map output is stored as category
 the resulting density in case of a vector map output is stored as category
 (Integer). The density result stored as category may be multiplied by this number.
 (Integer). The density result stored as category may be multiplied by this number.
-<p>With the <em>-o</em> flag (experimental) the command tries to calculate an 
+<p>
+For the <em>gaussian</em> kernel, standard deviation for the 
+<a href="http://en.wikipedia.org/wiki/Kernel_(statistics)#Kernel_functions_in_common_use">gaussian function</a> 
+is set to 1/4 of the radius.
+<p>
+With the <em>-o</em> flag (experimental) the command tries to calculate an 
 optimal standard deviation. The value of <em>stddeviation</em> is taken 
 optimal standard deviation. The value of <em>stddeviation</em> is taken 
 as maximum value. Standard deviation is calculated using ALL points, 
 as maximum value. Standard deviation is calculated using ALL points, 
 not just those in the current region.
 not just those in the current region.