The Fib multimedia system
Fib is a system for storing multimedia data (like images or films).
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cClusterFunArea.h
Go to the documentation of this file.
1 /**
2  * @class cClusterFunArea
3  * file name: cClusterFunArea.h
4  * @author Betti Oesterholz
5  * @date 17.03.2011
6  * @mail webmaster@BioKom.info
7  *
8  * System: C++
9  *
10  * This file contains the implementation for evaluing a cluster value for
11  * two data points.
12  * Copyright (C) @c LGPL3 2011 Betti Oesterholz
13  *
14  * This program is free software: you can redistribute it and/or modify
15  * it under the terms of the GNU Lesser General Public License (LGPL) as
16  * published by the Free Software Foundation, either version 3 of the
17  * License, or any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public License
25  * along with this program. If not, see <http://www.gnu.org/licenses/>.
26  *
27  *
28  * This file contains the implementation for evaluing a cluster value for
29  * two data points.
30  *
31  * An data point D can be in the cluster to an other data point C, if:
32  * The distance is lower an maximal distance (@see dMaxDistance).
33  * If C has more elements than D.
34  */
35 /*
36 History:
37 17.03.2011 Oesterholz created
38 */
39 
40 #ifndef ___C_CLUSTER_FUN_AREA__
41 #define ___C_CLUSTER_FUN_AREA__
42 
43 #include "version.h"
44 
45 #include <vector>
46 #include <cmath>
47 
48 
49 namespace fib{
50 
51 namespace algorithms{
52 
53 namespace nCluster{
54 
55 template< class tValue >
56 class cClusterFunArea: public iClusterFunction< vector< tValue > >{
57 
58  /**
59  * The maximum distance of two points in an cluster.
60  */
61  const tValue dMaxDistance;
62 
63 public:
64 
65  /**
66  * constructor
67  *
68  * @param dInMaxDistance The maximum distance of two points in an cluster.
69  * (@see dMaxDistance)
70  */
71  cClusterFunArea( const tValue dInMaxDistance ):dMaxDistance( dInMaxDistance ){
72  //nothing to do
73  }
74 
75  /**
76  * destructor
77  */
78  virtual ~cClusterFunArea(){
79  //nothing to do
80  }
81 
82 
83  /**
84  * This operator should evalue a cluster value for two data points.
85  * The value should indicate how good it is to cluster the secound data
86  * point dataPoint to the first dataClusterCenter.
87  * An data point D can be in the cluster to an other data point C, if:
88  * The distance is lower an maximal distance (@see dMaxDistance).
89  * If C has more elements than D.
90  *
91  * @param dataClusterCenter the data point, to which to evalue the
92  * value that dataPoint is clustered to it
93  * @param dataPoint the data point to cluster/subsume by dataClusterCenter
94  * @return the cluster value for dataClusterCenter and dataPoint
95  */
96  virtual double operator() ( const pair< vector< tValue >, unsigned long > & dataClusterCenter,
97  const pair< vector< tValue >, unsigned long > & dataPoint ) const{
98 
99  const vector< tValue > & vecDataPointCluster = dataClusterCenter.first;
100  const vector< tValue > & vecDataPoint = dataPoint.first;
101  const unsigned int uiDimensions = min( vecDataPointCluster.size(),
102  vecDataPoint.size() );
103 
104  tValue dDistance = 0;
105  for ( unsigned int uiActualDimension = 0;
106  uiActualDimension < uiDimensions; uiActualDimension++ ){
107 
108  dDistance += abs( ((int)(vecDataPoint[ uiActualDimension ])) -
109  ((int)(vecDataPointCluster[ uiActualDimension ])) );
110  }
111 
112  if ( dMaxDistance < dDistance ){
113  /*distance of data points greater than the maximum distance
114  -> don't cluster them*/
115  return -1.0;
116  }
117  /*evalue:
118  (dataClusterCenter.second - dataPoint.second) * dim * dMaxDistance / 2 +
119  + dim * dMaxDistance / 2 - sum( vecDataPoint[ uiActualDimension ] mod (dMaxDistance / 2) )
120  with:
121  dim = dataClusterCenter.first.size()
122 
123  explanation:
124  With the part ((dataClusterCenter.second - dataPoint.second) *
125  * dim * dMaxDistance / 2) any datapoint with the most elements will
126  be the center of the cluster.
127  If two data point have an equal number of data points the part
128  (dim * dMaxDistance / 2 - sum( vecDataPoint[ uiActualDimension ]
129  mod (dMaxDistance / 2) )) will arrange that, in any neighbourhood
130  just one point is choosen as the cluster center
131  */
132 
133  const unsigned int uiHalfDimMaxDistance = ( 2 < dMaxDistance ) ?
134  (dMaxDistance / 2) : 1;
135 
136  tValue dDistanceFactor = 0;
137  for ( unsigned int uiActualDimension = 0;
138  uiActualDimension < uiDimensions; uiActualDimension++ ){
139 
140  dDistanceFactor += vecDataPoint[ uiActualDimension ] % uiHalfDimMaxDistance;
141  }
142  return (dataClusterCenter.second - dataPoint.second + 1) *
143  ((double)( uiDimensions )) * dMaxDistance / 2.0 + dDistanceFactor;
144  }
145 
146 
147 };//class cClusterFunArea
148 
149 
150 };//end namespace nCluster
151 };//end namespace algorithms
152 };//end namespace fib
153 
154 
155 #endif //___C_CLUSTER_FUN_AREA__
156 
157 
158 
159