-
Notifications
You must be signed in to change notification settings - Fork 141
Expand file tree
/
Copy pathJenksBreaks.h
More file actions
104 lines (95 loc) · 3.06 KB
/
JenksBreaks.h
File metadata and controls
104 lines (95 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**************************************************************************************
* File name: JenksBreaks.h
*
* Project: MapWindow Open Source (MapWinGis ActiveX control)
* Description: Declaration of JenksBreaks.h
*
**************************************************************************************
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at http://www.mozilla.org/mpl/
* See the License for the specific language governing rights and limitations
* under the License.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
**************************************************************************************
* Contributor(s):
* (Open source contributors should list themselves and their modifications here). */
// Sergei Leschinski (lsu) 25 june 2010 - created the file
#pragma once
#include <algorithm>
#include "float.h"
#ifndef MAX
# define MIN(a,b) ((a<b) ? a : b)
# define MAX(a,b) ((a>b) ? a : b)
#endif
class CJenksBreaks
{
public:
// Constructor
CJenksBreaks(std::vector<double>* values, int numClasses);
~CJenksBreaks(){}
// data structures
struct JenksData
{
public:
double value;
double square;
int classId; // number of break to which a value belongs
};
struct JenksBreak
{
public:
double value;
double square;
int count;
double SDev;
int startId;
int endId;
JenksBreak()
{
value = 0.0;
square = 0.0;
count = 0;
SDev = 0.0;
startId = -1;
endId = -1;
}
// the formula for every class is: sum((a[k])^2) - sum(a[k])^2/n
void RefreshStandardDeviations()
{
SDev = square - pow(value, 2.0)/(double)(endId - startId + 1);
}
};
private:
// data members
std::vector<JenksData> _values;
std::vector<JenksBreak> _classes;
int _numClasses;
int _numValues;
int _previousMaxId; // to prevent stalling in the local optimum
int _previousTargetId;
int _leftBound; // the id of classes between which optimization takes place
int _rightBound; // initially it's all classes, then it's reducing
bool _init;
// functions
public:
std::vector<long>* get_Results();
void Optimize();
std::vector<int>* SolveAsDP(std::vector<double>& data, int numClasses);
bool Initialized()
{
return _init;
}
private:
double get_SumStandardDeviations();
bool FindShift();
void MakeShift(int maxId, int targetId, int valueId);
std::vector<int>* BuildEqualBreaks(std::vector<double>& data, int numClasses);
};