Repository navigation
Expand file tree
/
Copy pathanalyze.js
More file actions
95 lines (76 loc) · 1.73 KB
/
Copy pathanalyze.js
File metadata and controls
95 lines (76 loc) · 1.73 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
//maps a value from one range to another (linear interpolation)
Math.map = function(x, in_min, in_max, out_min, out_max) { return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; };
/*
function analyze(data)
{
var compare = data.slice(0);
var output = new Array2D(data.length, data.length, 0);
for(var i = 0; i < data.length - 1; i++)
{
//rotate the array
var value = compare.pop();
compare.unshift(value);
for(var y = 0; y < data.length; y++)
{
output[y][i] = data[y] === compare[y] ? 1 : 0;
}
}
//normalize(output);
return output;
}
*/
function analyze(data)
{
var output = new Array2D(256, 256, 0);
for(var i = 0; i < data.length - 2; i++)
{
var curr = data[i];
var next = data[i+1];
output[curr][next]++;
}
normalize(output);
return output;
}
/*
function normalize(data)
{
var average = 0;
data.forEach(function(v) {
average += v;
});
average /= data.x * data.y;
//average += 25;
data.forEach(function(v, x, y, a) {
//a[x][y] = Math.ceil(v / max);
var val = (v / average);
if(val > 1) { val = 1; }
a[x][y] = val
});
}
*/
function normalize(data)
{
var max = 0;
data.forEach(function(v) {
if(v > max) { max = v; }
});
points = [0];
data.forEach(function(v, x, y) {
if(v != 0) //vast swaths of nothingness screws up the stats (I care most about the high end)
{
points.push(v);
}
});
points.sort(function(a,b) { return a - b;});
var Q1 = points[Math.round(points.length * 0.1)];
var Q3 = points[Math.round(points.length * 0.9)];
var IQR = Q3 - Q1;
var thresh = 1.5 * IQR;
var high = Q3 + thresh;
high = high > max ? max : high;
data.forEach(function(v, x, y, a) {
var val = Math.map(v, 0, high, 0, 1);
if(val > 1) { val = 1; }
a[x][y] = val;
});
}