Update to BAEL-1425 (#4399)
* added example code for Java mail * added examp code for BAEL-1425 * updated example code for BAEL-1425 * updated example code for BAEL-1425
This commit is contained in:
parent
fb8224d8d4
commit
5ef5e539e4
|
@ -10,8 +10,13 @@ import java.util.*;
|
||||||
|
|
||||||
public class Histogram {
|
public class Histogram {
|
||||||
|
|
||||||
|
private Map distributionMap;
|
||||||
|
private int classWidth;
|
||||||
|
|
||||||
public Histogram() {
|
public Histogram() {
|
||||||
|
|
||||||
|
distributionMap = new TreeMap();
|
||||||
|
classWidth = 10;
|
||||||
Map distributionMap = processRawData();
|
Map distributionMap = processRawData();
|
||||||
List yData = new ArrayList();
|
List yData = new ArrayList();
|
||||||
yData.addAll(distributionMap.values());
|
yData.addAll(distributionMap.values());
|
||||||
|
@ -46,43 +51,43 @@ public class Histogram {
|
||||||
Frequency frequency = new Frequency();
|
Frequency frequency = new Frequency();
|
||||||
datasetList.forEach(d -> frequency.addValue(Double.parseDouble(d.toString())));
|
datasetList.forEach(d -> frequency.addValue(Double.parseDouble(d.toString())));
|
||||||
|
|
||||||
int classWidth = 10;
|
|
||||||
|
|
||||||
Map distributionMap = new TreeMap();
|
|
||||||
List processed = new ArrayList();
|
List processed = new ArrayList();
|
||||||
datasetList.forEach(d -> {
|
datasetList.forEach(d -> {
|
||||||
|
double observation = Double.parseDouble(d.toString());
|
||||||
|
|
||||||
double observation = Double.parseDouble(d.toString());
|
if(processed.contains(observation))
|
||||||
|
return;
|
||||||
|
|
||||||
if(processed.contains(observation))
|
long observationFrequency = frequency.getCount(observation);
|
||||||
return;
|
int upperBoundary = (observation > classWidth) ? Math.multiplyExact( (int) Math.ceil(observation / classWidth), classWidth) : classWidth;
|
||||||
|
int lowerBoundary = (upperBoundary > classWidth) ? Math.subtractExact(upperBoundary, classWidth) : 0;
|
||||||
|
String bin = lowerBoundary + "-" + upperBoundary;
|
||||||
|
|
||||||
long observationFrequency = frequency.getCount(observation);
|
updateDistributionMap(lowerBoundary, bin, observationFrequency);
|
||||||
int upperBoundary = (observation > classWidth) ? Math.multiplyExact( (int) Math.ceil(observation / classWidth), classWidth) : classWidth;
|
|
||||||
int lowerBoundary = (upperBoundary > classWidth) ? Math.subtractExact(upperBoundary, classWidth) : 0;
|
|
||||||
String bin = lowerBoundary + "-" + upperBoundary;
|
|
||||||
|
|
||||||
int prevUpperBoundary = lowerBoundary;
|
processed.add(observation);
|
||||||
int prevLowerBoundary = (lowerBoundary > classWidth) ? lowerBoundary - classWidth : 0;
|
|
||||||
String prevBin = prevLowerBoundary + "-" + prevUpperBoundary;
|
|
||||||
if(!distributionMap.containsKey(prevBin))
|
|
||||||
distributionMap.put(prevBin, 0);
|
|
||||||
|
|
||||||
if(!distributionMap.containsKey(bin)) {
|
|
||||||
distributionMap.put(bin, observationFrequency);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
long oldFrequency = Long.parseLong(distributionMap.get(bin).toString());
|
|
||||||
distributionMap.replace(bin, oldFrequency + observationFrequency);
|
|
||||||
}
|
|
||||||
|
|
||||||
processed.add(observation);
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return distributionMap;
|
return distributionMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateDistributionMap(int lowerBoundary, String bin, long observationFrequency) {
|
||||||
|
|
||||||
|
int prevLowerBoundary = (lowerBoundary > classWidth) ? lowerBoundary - classWidth : 0;
|
||||||
|
String prevBin = prevLowerBoundary + "-" + lowerBoundary;
|
||||||
|
if(!distributionMap.containsKey(prevBin))
|
||||||
|
distributionMap.put(prevBin, 0);
|
||||||
|
|
||||||
|
if(!distributionMap.containsKey(bin)) {
|
||||||
|
distributionMap.put(bin, observationFrequency);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
long oldFrequency = Long.parseLong(distributionMap.get(bin).toString());
|
||||||
|
distributionMap.replace(bin, oldFrequency + observationFrequency);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
new Histogram();
|
new Histogram();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue