/************************************************************************* Copyright (c) 2008, Sergey Bochkanov (ALGLIB project). >>> SOURCE LICENSE >>> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation (www.fsf.org); either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. A copy of the GNU General Public License is available at http://www.fsf.org/licensing/licenses >>> END OF LICENSE >>> *************************************************************************/ using System; namespace alglib { public class kmeans { /************************************************************************* k-means++ clusterization INPUT PARAMETERS: XY - dataset, array [0..NPoints-1,0..NVars-1]. NPoints - dataset size, NPoints>=K NVars - number of variables, NVars>=1 K - desired number of clusters, K>=1 Restarts - number of restarts, Restarts>=1 OUTPUT PARAMETERS: Info - return code: * -3, if taskis degenerate (number of distinct points is less than K) * -1, if incorrect NPoints/NFeatures/K/Restarts was passed * 1, if subroutine finished successfully C - array[0..NVars-1,0..K-1].matrix whose columns store cluster's centers XYC - array which contains number of clusters dataset points belong to. -- ALGLIB -- Copyright 21.03.2009 by Bochkanov Sergey *************************************************************************/ public static void kmeansgenerate(ref double[,] xy, int npoints, int nvars, int k, int restarts, ref int info, ref double[,] c, ref int[] xyc) { int i = 0; int j = 0; double[,] ct = new double[0,0]; double[,] ctbest = new double[0,0]; double e = 0; double ebest = 0; double[] x = new double[0]; double[] tmp = new double[0]; double[] d2 = new double[0]; double[] p = new double[0]; int[] csizes = new int[0]; bool[] cbusy = new bool[0]; double v = 0; int cclosest = 0; double dclosest = 0; double[] work = new double[0]; bool waschanges = new bool(); bool zerosizeclusters = new bool(); int pass = 0; int i_ = 0; // // Test parameters // if( npoints