-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
74 lines (61 loc) · 2.31 KB
/
Program.cs
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
using Cluster;
using DataSet;
using Utility;
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace AffinityPropagationClusteringt
{
class Program
{
static void Main(string[] args)
{
//This is a simple driver program
Console.WriteLine("Testing:Driver program for Affinity Propagation clustering algorithm.");
var rnd = new ToyDataset();
Stopwatch s = new Stopwatch();
var data1 = rnd.DataSet();
var sim = SimilarityMatrix.SparseSimilarityMatrix(data1);
Console.WriteLine($"Data size:{data1.Length} ; SimilarityMatrix size:{sim.Length}");
Console.WriteLine($"Start at:{DateTime.Now}");
s.Start();
try
{
AffinityPropagation model = new AffinityPropagation(data1.Length);
var centers = model.Fit(sim);
Print(centers);
ClusterUtility.AssignClusterCenters(data1, centers);
int[] centers_index = new int[model.Centers.Count];
model.Centers.CopyTo(centers_index);
var t = ClusterUtility.GroupClusters(data1, centers, centers_index);
//print the clusters (grouped)
Print(t);
}
catch (Exception e)
{
Console.WriteLine($"\a{e.Message}");
}
s.Stop();
Console.WriteLine($"\nEnding at:{DateTime.Now}");
Console.WriteLine($"Ellapsed time: {s.ElapsedMilliseconds} ms | {s.Elapsed.TotalSeconds} s | {s.Elapsed.TotalMinutes} m");
}
public static void Print(int[] clusteredData)
{
Console.WriteLine();
foreach (var s in clusteredData)
Console.Write($"{s} ");
Console.WriteLine();
}
public static void Print(List<Point>[] clusters)
{
for(int i = 0; i < clusters.Length; ++i) {
Console.Write($"[{i}]->");
foreach (var b in clusters[i])
{
Console.Write($"[({b.Coordinates(0).ToString("n2")},{b.Coordinates(1).ToString("n2")})] ");
}
Console.WriteLine("\n");
}
}
}
}