[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [labplot] src/backend/nsl: small improvements on line simplification error calculation
From: Stefan Gerlach <stefan.gerlach () uni-konstanz ! de>
Date: 2016-08-31 20:40:04
Message-ID: E1bfCIm-0002xK-RI () code ! kde ! org
[Download RAW message or body]
Git commit 50e20cdcb3b01cb6107f20c1afed65967b27a767 by Stefan Gerlach.
Committed on 31/08/2016 at 20:39.
Pushed by sgerlach into branch 'master'.
small improvements on line simplification error calculation
M +14 -4 src/backend/nsl/nsl_geom_linesim.c
M +3 -3 src/backend/nsl/nsl_geom_linesim.h
M +7 -7 src/backend/nsl/nsl_geom_linesim_test.c
http://commits.kde.org/labplot/50e20cdcb3b01cb6107f20c1afed65967b27a767
diff --git a/src/backend/nsl/nsl_geom_linesim.c b/src/backend/nsl/nsl_geom_linesim.c
index 3658c0e..68cedc3 100644
--- a/src/backend/nsl/nsl_geom_linesim.c
+++ b/src/backend/nsl/nsl_geom_linesim.c
@@ -26,27 +26,37 @@
* *
***************************************************************************/
+/*
+ TODO:
+ * struct of algorithm and names
+ * extern nsl_compare
+ * non-parametric functions (calculate eps from data)
+ * more algorithm
+ * error calculation by area
+ * error statistics
+*/
+
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "nsl_geom.h"
#include "nsl_geom_linesim.h"
-double nsl_geom_linesim_positional_error(const double xdata[], const double ydata[], \
const size_t n, const size_t index[]) { +double \
nsl_geom_linesim_positional_squared_error(const double xdata[], const double ydata[], \
const size_t n, const size_t index[]) { double dist=0;
- size_t i=0, j; /* index of index[] */
+ size_t i=0, j; /* i: index of index[] */
do {
/*for every point not in index[] calculate distance to line*/
/*printf("i=%d (index[i]-index[i+1]=%d-%d)\n", i , index[i], index[i+1]);*/
for(j=1;j<index[i+1]-index[i];j++) {
/*printf("i=%d: j=%d\n", i, j);*/
- dist += nsl_geom_point_line_dist(xdata[index[i]], ydata[index[i]], \
xdata[index[i+1]], ydata[index[i+1]], xdata[index[i]+j], ydata[index[i]+j]); + dist \
+= pow(nsl_geom_point_line_dist(xdata[index[i]], ydata[index[i]], xdata[index[i+1]], \
ydata[index[i+1]], xdata[index[i]+j], ydata[index[i]+j]), 2); /*printf("dist = \
%g\n", dist);*/ }
i++;
} while(index[i] != n-1);
- return dist;
+ return dist/(double)n;
}
size_t nsl_geom_linesim_nthpoint(const size_t n, const size_t step, size_t index[]) \
{
diff --git a/src/backend/nsl/nsl_geom_linesim.h b/src/backend/nsl/nsl_geom_linesim.h
index d6d14ec..1b6ae54 100644
--- a/src/backend/nsl/nsl_geom_linesim.h
+++ b/src/backend/nsl/nsl_geom_linesim.h
@@ -31,10 +31,10 @@
#include <stdlib.h>
-/* calculates positional error (summed perpendicular distance)
- from simplified set (given by index[])
+/* calculates positional error (sum of squared perpendicular distance)
+ of simplified set (given by index[])
*/
-double nsl_geom_linesim_positional_error(const double xdata[], const double ydata[], \
const size_t n, const size_t index[]); +double \
nsl_geom_linesim_positional_squared_error(const double xdata[], const double ydata[], \
const size_t n, const size_t index[]);
/* simple n-th point line simplification
n: number of points
diff --git a/src/backend/nsl/nsl_geom_linesim_test.c \
b/src/backend/nsl/nsl_geom_linesim_test.c index 89c4fea..3701430 100644
--- a/src/backend/nsl/nsl_geom_linesim_test.c
+++ b/src/backend/nsl/nsl_geom_linesim_test.c
@@ -37,7 +37,7 @@ double main() {
printf("* n-th point\n");
size_t nout = nsl_geom_linesim_nthpoint(n, np, index);
- printf("nout = %d (error = %g)\n", nout, nsl_geom_linesim_positional_error(xdata, \
ydata, n, index)); + printf("nout = %d (error = %g)\n", nout, \
nsl_geom_linesim_positional_squared_error(xdata, ydata, n, index));
size_t i;
for(i=0; i<nout; i++)
@@ -46,7 +46,7 @@ double main() {
const double eps=1.5;
printf("* radial distance\n");
nout = nsl_geom_linesim_raddist(xdata, ydata, n, eps, index);
- printf("nout = %d (error = %g)\n", nout, nsl_geom_linesim_positional_error(xdata, \
ydata, n, index)); + printf("nout = %d (error = %g)\n", nout, \
nsl_geom_linesim_positional_squared_error(xdata, ydata, n, index));
for(i=0; i<nout; i++)
printf("%d: %d\n", i, index[i]);
@@ -55,7 +55,7 @@ double main() {
const size_t repeat = 3;
printf("* perpendicular distance (repeat = %d)\n", repeat);
nout = nsl_geom_linesim_perpdist_repeat(xdata, ydata, n, eps2, repeat, index);
- printf("nout = %d (error = %g)\n", nout, nsl_geom_linesim_positional_error(xdata, \
ydata, n, index)); + printf("nout = %d (error = %g)\n", nout, \
nsl_geom_linesim_positional_squared_error(xdata, ydata, n, index));
for(i=0; i<nout; i++)
printf("%d: %d\n", i, index[i]);
@@ -63,7 +63,7 @@ double main() {
const double eps3=0.7;
printf("* perp. distance (Reumann-Witkam)\n");
nout = nsl_geom_linesim_reumann_witkam(xdata, ydata, n, eps3, index);
- printf("nout = %d (error = %g)\n", nout, nsl_geom_linesim_positional_error(xdata, \
ydata, n, index)); + printf("nout = %d (error = %g)\n", nout, \
nsl_geom_linesim_positional_squared_error(xdata, ydata, n, index));
for(i=0; i<nout; i++)
printf("%d: %d\n", i, index[i]);
@@ -72,7 +72,7 @@ double main() {
const double maxeps=7.0;
printf("* perp. distance (Opheim)\n");
nout = nsl_geom_linesim_opheim(xdata, ydata, n, mineps, maxeps, index);
- printf("nout = %d (error = %g)\n", nout, nsl_geom_linesim_positional_error(xdata, \
ydata, n, index)); + printf("nout = %d (error = %g)\n", nout, \
nsl_geom_linesim_positional_squared_error(xdata, ydata, n, index));
for(i=0; i<nout; i++)
printf("%d: %d\n", i, index[i]);
@@ -81,7 +81,7 @@ double main() {
const size_t region=5;
printf("* simplification (Lang)\n");
nout = nsl_geom_linesim_lang(xdata, ydata, n, eps4, region, index);
- printf("nout = %d (error = %g)\n", nout, nsl_geom_linesim_positional_error(xdata, \
ydata, n, index)); + printf("nout = %d (error = %g)\n", nout, \
nsl_geom_linesim_positional_squared_error(xdata, ydata, n, index));
for(i=0; i<nout; i++)
printf("%d: %d\n", i, index[i]);
@@ -89,7 +89,7 @@ double main() {
const double eps5=0.6;
printf("* simplification (Douglas Peucker)\n");
nout = nsl_geom_linesim_douglas_peucker(xdata, ydata, n, eps5, index);
- printf("nout = %d (error = %g)\n", nout, nsl_geom_linesim_positional_error(xdata, \
ydata, n, index)); + printf("nout = %d (error = %g)\n", nout, \
nsl_geom_linesim_positional_squared_error(xdata, ydata, n, index));
for(i=0; i<nout; i++)
printf("%d: %d\n", i, index[i]);
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic