use of org.activityinfo.shared.report.content.Point in project activityinfo by bedatadriven.
the class KMeans method computeCenters.
/**
* Computes the centers of the assigned clusters
*
* @param nodes
* The list of nodes
* @param membership
* An array containing the cluster membership for each node
* @param centers
* Array of center points to update
*/
private static void computeCenters(List<MarkerGraph.Node> nodes, int[] membership, Point[] centers) {
int[] sumX = new int[centers.length];
int[] sumY = new int[centers.length];
int[] counts = new int[centers.length];
for (int i = 0; i != nodes.size(); ++i) {
Point point = nodes.get(i).getPoint();
sumX[membership[i]] += point.getX();
sumY[membership[i]] += point.getY();
counts[membership[i]]++;
}
for (int i = 0; i != centers.length; ++i) {
if (counts[i] > 0) {
centers[i] = new Point(sumX[i] / counts[i], sumY[i] / counts[i]);
}
}
}
use of org.activityinfo.shared.report.content.Point in project activityinfo by bedatadriven.
the class CircleMathTest method testTangentIntersection.
@Test
public void testTangentIntersection() {
Point a = new Point(0, 0);
Point b = new Point(2, 0);
Assert.assertEquals(0.0, CircleMath.intersectionArea(a, b, 1, 1), DELTA);
}
use of org.activityinfo.shared.report.content.Point in project activityinfo by bedatadriven.
the class CoincidentPointsClusterTest method testSimpleData.
@Test
public void testSimpleData() throws Exception {
List<PointValue> points = new ArrayList<PointValue>();
points.add(new PointValue(new SiteDTO(), new MapSymbol(), 7.0, new Point(0, 0)));
points.add(new PointValue(new SiteDTO(), new MapSymbol(), 2.0, new Point(0, 0)));
points.add(new PointValue(new SiteDTO(), new MapSymbol(), 41.0, new Point(100, 100)));
points.add(new PointValue(new SiteDTO(), new MapSymbol(), 9.0, new Point(0, 0)));
points.add(new PointValue(new SiteDTO(), new MapSymbol(), 39.0, new Point(100, 100)));
double originalSum = 7 + 2 + 9 + 41 + 39;
// Now build the graph
MarkerGraph graph = new MarkerGraph(points, new BubbleIntersectionCalculator(15));
GeneticSolver solver = new GeneticSolver();
List<Cluster> clusters = solver.solve(graph, new GsLogCalculator(5, 15), new BubbleFitnessFunctor(), UpperBoundsCalculator.calculate(graph, new FixedRadiiCalculator(5)));
// check to make sure all values were included
double sumAfterClustering = 0;
for (Cluster cluster : clusters) {
sumAfterClustering += cluster.sumValues();
}
Assert.assertEquals(originalSum, sumAfterClustering, 0.0001);
Assert.assertEquals(2, clusters.size());
saveClusters(graph, "clusterTest-solution", clusters);
}
use of org.activityinfo.shared.report.content.Point in project activityinfo by bedatadriven.
the class GraphTest method testGraph.
@Test
public void testGraph() throws Exception {
List<PointValue> points = new ArrayList<PointValue>();
points.add(new PointValue(null, null, 100, new Point(380, 530)));
points.add(new PointValue(null, null, 200, new Point(500, 500)));
points.add(new PointValue(null, null, 50, new Point(650, 550)));
points.add(new PointValue(null, null, 300, new Point(600, 600)));
points.add(new PointValue(null, null, 200, new Point(650, 650)));
points.add(new PointValue(null, null, 30, new Point(500, 1300)));
points.add(new PointValue(null, null, 150, new Point(200, 200)));
points.add(new PointValue(null, null, 200, new Point(350, 200)));
points.add(new PointValue(null, null, 150, new Point(500, 200)));
points.add(new PointValue(null, null, 30, new Point(700, 200)));
// MarkerGraph graph = new MarkerGraph(points, new
// GraduatedLogCalculator(50, 100), 100);
}
use of org.activityinfo.shared.report.content.Point in project activityinfo by bedatadriven.
the class GraphTest method saveClusters.
protected void saveClusters(MarkerGraph graph, String fileName, List<Cluster> clusters) throws IOException {
File outputDir = new File("target/report-tests");
outputDir.mkdirs();
File outputFile = new File("target/report-tests/" + fileName + ".svg");
FileWriter svg = new FileWriter(outputFile);
svg.write("<svg width='100%' height='100%' transform='scale(500)' version='1.1' " + "xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' >\n");
for (MarkerGraph.Edge edge : graph.getEdges()) {
svg.write(String.format("<path d='M%d %d L%d %d' " + "style='stroke:rgb(92,92,92);stroke-width:0.25'/>\n", edge.getA().getPoint().getX(), edge.getA().getPoint().getY(), edge.getB().getPoint().getX(), edge.getB().getPoint().getY()));
}
String[] colors = new String[] { "antiquewhite", "blue", "brown", "chartreuse", "cornflowerblue", "crimson", "darkkhaki", "darkorange", "darkorchid", "lightpink", "lightseagreen", "lightskyblue", "lime", "limegreen", "magenta", "mediumaqua" };
int colorIndex = 0;
for (int i = 0; i != clusters.size(); ++i) {
Cluster cluster = clusters.get(i);
svg.write(String.format("<circle cx='%d' cy='%d' r='%f' " + "style='fill: %s; fill-opacity: 0.5; stroke:none'/>\n", cluster.getPoint().getX(), cluster.getPoint().getY(), cluster.getRadius(), colors[colorIndex]));
for (PointValue pointValue : cluster.getPointValues()) {
svg.write(String.format("<circle cx='%d' cy='%d' r='1.5' " + "style='stroke:rgb(92,92,92); stroke-width:0.1; fill: %s' title='%f'/>\n", pointValue.getPx().getX(), pointValue.getPx().getY(), colors[colorIndex], pointValue.getValue()));
}
colorIndex++;
if (colorIndex == colors.length) {
colorIndex = 0;
}
}
// label subgraphs
List<List<MarkerGraph.Node>> subgraphs = graph.getSubgraphs();
for (int i = 0; i != subgraphs.size(); ++i) {
Point p = findLR(subgraphs.get(i));
svg.write(String.format("<text x='%d' y='%d'>%d</text>\n", p.getX() + 5, p.getY(), i));
}
svg.write("</svg>\n");
svg.close();
}
Aggregations