Debian Codegraph @

dwtools/Distance.cpp

raw symbols SCIP
1 /* Distance.cpp
2 *
3 * Copyright (C) 1993-2019 David Weenink
4 *
5 * This code is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
9 *
10 * This code is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this work. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 /*
20 djmw 20020813 GPL header
21 djmw 20110304 Thing_new
22 */
23
24 #include "Distance.h"
25 #include "NUMselect.h"
26 #include "TableOfReal_extensions.h"
27
28 Thing_implement (Distance, Proximity, 0);
29
30 Thing_implement (DistanceList, ProximityList, 0);
31
32 autoDistance Distance_create (integer numberOfPoints) {
33 try {
34 autoDistance me = Thing_new (Distance);
35 Proximity_init (me.get(), numberOfPoints);
36 return me;
37 } catch (MelderError) {
38 Melder_throw (U"Distance not created.");
39 }
40 }
41
42 autoDistance Configuration_to_Distance (Configuration me) {
43 try {
44 autoDistance thee = Distance_create (my numberOfRows);
45 TableOfReal_copyLabels (me, thee.get(), 1, -1);
46 autoVEC dist = raw_VEC (my numberOfColumns);
47 for (integer i = 1; i <= thy numberOfRows - 1; i ++) {
48 for (integer j = i + 1; j <= thy numberOfColumns; j ++) {
49 dist.all() <<= my data.row (i) - my data.row (j);
50 abs_VEC_inout (dist.get());
51 const double dmax = NUMmax_e (dist.get());
52 double d = 0.0;
53 if (dmax > 0.0) {
54 dist.all() /= dmax; // prevent overflow
55 power_VEC_inout (dist.get(), my metric);
56 d = NUMinner (my w.all(), dist.get());
57 d = dmax * pow (d, 1.0 / my metric); // scale back
58 }
59 thy data [i] [j] = thy data [j] [i] = d;
60 }
61 }
62 return thee;
63 } catch (MelderError) {
64 Melder_throw (me, U": no Distance created.");
65 }
66 }
67
68 void Distance_drawDendrogram (Distance me, Graphics g, int method) {
69 (void) me;
70 (void) g;
71 (void) method;
72 }
73
74 /* End of file Distance.cpp */