//########################clustering################################################# /*create partitions of 2 clusters. The partition returned is determinated by "cluster" * 0<=cluster <50 */ public IDataView get2clustered(int cluster) { if (cluster >= 50) { System.Console.WriteLine("More than 50 calls (2-clustered)"); } float clusters_split = (sorted_data.Count / 51.0f) * (cluster + 1); MinutiaData[] in_memory = new MinutiaData[sorted_data.Count]; for (int i = 0; i < sorted_data.Count; ++i) { sorted_data[i][269] = (i < clusters_split)? 0:1; in_memory[i] = fromRow2Data(sorted_data[i]); } return(new MLContext().Data.LoadFromEnumerable <MinutiaData>(in_memory)); }
public IDataView get3clustered() { if (++calls3 > 50) { System.Console.WriteLine("More than 50 calls without reset (3-clustered)"); } float segs = cnt_seg(50); float seg_lenght = sorted_data.Count / segs; if (clusters3idx_2 == segs) { clusters3idx_2 = ++clusters3idx_1 + 1; } int end_1 = (int)(seg_lenght * clusters3idx_1); int end_2 = (int)(seg_lenght * clusters3idx_2); MinutiaData[] in_memory = new MinutiaData[sorted_data.Count]; for (int i = 0; i < sorted_data.Count; ++i) { if (i < end_1) { sorted_data[i][269] = 0; } else if (i < end_2) { sorted_data[i][269] = 1; } else { sorted_data[i][269] = 2; } in_memory[i] = fromRow2Data(sorted_data[i]); } clusters3idx_2 += 1; return(new MLContext().Data.LoadFromEnumerable <MinutiaData>(in_memory)); }
/*create partitions of 3 clusters. The partition returned is determinated by "cluster" * 0<=cluster <50 */ public IDataView get3clustered(int cluster) { if (cluster >= 50) { System.Console.WriteLine("More than 50 calls (3-clustered)"); } float segs = cnt_seg(50); float seg_lenght = sorted_data.Count / segs; int[] idxs = find_idx(cluster, (int)segs); int clusters3idx_2 = idxs[1]; int clusters3idx_1 = idxs[0]; int end_1 = (int)(seg_lenght * clusters3idx_1); int end_2 = (int)(seg_lenght * clusters3idx_2); MinutiaData[] in_memory = new MinutiaData[sorted_data.Count]; for (int i = 0; i < sorted_data.Count; ++i) { //labels for the clusters are are int (0,1,2) if (i < end_1) { sorted_data[i][269] = 0; } else if (i < end_2) { sorted_data[i][269] = 1; } else { sorted_data[i][269] = 2; } in_memory[i] = fromRow2Data(sorted_data[i]); } return(new MLContext().Data.LoadFromEnumerable <MinutiaData>(in_memory)); }