1 |
44467
|
claudio.at
|
package eu.dnetlib.data.mapreduce;
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* Created by claudio on 14/11/2016.
|
5 |
|
|
*/
|
6 |
|
|
public class Algorithms {
|
7 |
|
|
|
8 |
|
|
public static double BASE_MIN = 0;
|
9 |
|
|
|
10 |
|
|
public static double BASE_MAX = 1;
|
11 |
|
|
|
12 |
|
|
public static double LIMIT_MIN = 0;
|
13 |
|
|
|
14 |
52802
|
claudio.at
|
/**
|
15 |
|
|
|
16 |
|
|
Source: https://stackoverflow.com/questions/5294955/how-to-scale-down-a-range-of-numbers-with-a-known-min-and-max-value
|
17 |
|
|
|
18 |
|
|
f(min) = a
|
19 |
|
|
f(max) = b
|
20 |
|
|
|
21 |
|
|
f(x) = x - min ===> f(min) = min - min = 0
|
22 |
|
|
|
23 |
|
|
|
24 |
|
|
x - min max - min
|
25 |
|
|
f(x) = --------- ===> f(min) = 0; f(max) = --------- = 1
|
26 |
|
|
max - min max - min
|
27 |
|
|
|
28 |
|
|
|
29 |
|
|
(b-a)(x - min)
|
30 |
|
|
f(x) = -------------- + a
|
31 |
|
|
max - min
|
32 |
|
|
*/
|
33 |
44467
|
claudio.at
|
public static double scale(final double valueIn, final double baseMin, final double baseMax, final double limitMin, final double limitMax) {
|
34 |
|
|
return ((limitMax - limitMin) * (valueIn - baseMin) / (baseMax - baseMin)) + limitMin;
|
35 |
|
|
}
|
36 |
|
|
|
37 |
|
|
public static double scale(final double valueIn, final double limitMin, final double limitMax) {
|
38 |
|
|
return scale(valueIn, BASE_MIN, BASE_MAX, limitMin, limitMax);
|
39 |
|
|
}
|
40 |
|
|
|
41 |
|
|
public static double scale(final double valueIn, final double limitMax) {
|
42 |
|
|
return scale(valueIn, BASE_MIN, BASE_MAX, LIMIT_MIN, limitMax);
|
43 |
|
|
}
|
44 |
|
|
|
45 |
|
|
}
|