private static unsafe double[][] SolveKMeans(PocketData[] pockets) { Kml.Init(null); Kml.Parameters kmParams = new Kml.Parameters(); kmParams.SetDefaultTerm(); kmParams.dim = _cmdLine.Dim; kmParams.term_st_a = _cmdLine.Stages; kmParams.term_st_b = kmParams.term_st_c = kmParams.term_st_d = 0; kmParams.seed = 1; kmParams.k = _cmdLine.K; kmParams.n = _cmdLine.UsePocketCounts ? 1326: 169; kmParams.Allocate(); Console.WriteLine("Data passed to kml:"); int p = 0; for (int pocket = 0; pocket < pockets.Length; ++pocket) { int count = _cmdLine.UsePocketCounts ? HePocket.KindToRange((HePocketKind)pocket).Length : 1; for (int i = 0; i < count; ++i) { for (int d = 0; d < _cmdLine.Dim; ++d) { double value = pockets[pocket].Value[d]; *kmParams.GetPoint(p, d) = value; Console.Write(value.ToString(CultureInfo.InvariantCulture) + " "); } Console.WriteLine(); ++p; } } Console.WriteLine(); Debug.Assert(!_cmdLine.UsePocketCounts || p == 1326); Kml.KML_Hybrid(&kmParams); double[][] centers = new double[_cmdLine.K][].Fill(i => new double[_cmdLine.Dim]); for (int c = 0; c < kmParams.k; ++c) { for (int d = 0; d < kmParams.dim; ++d) { centers[c][d] = *kmParams.GetCenter(c, d); } } kmParams.Free(); return(centers); }
public void Test_Hybrid() { Kml.Init(Path.GetDirectoryName(CodeBase.Get(Assembly.GetExecutingAssembly()))); Kml.Parameters p = new Kml.Parameters(); try { p.n = 20; p.k = 4; p.dim = 2; p.term_st_a = 50; p.term_st_b = p.term_st_c = p.term_st_d = 0; p.term_minConsecRDL = 0.2; p.term_minAccumRDL = 0.1; p.term_maxRunStage = 100; p.term_initProbAccept = 0.50; p.term_tempRunLength = 10; p.term_tempReducFact = 0.75; p.seed = 4; p.Allocate(); for (int i = 0; i < p.n; ++i) { for (int d = 0; d < p.dim; ++d) { *p.GetPoint(i, d) = _data1[i * p.dim + d]; } } Kml.KML_Hybrid(&p); p.PrintCenters(Console.Out); VerifyResult(p, _data1, _data1_expCenters, _data1_expCenterAssignments); } finally { p.Free(); } }