コード例 #1
0
        private List <LabelVector> findCenterCandidates(object arg)
        {
            Job job = arg as Job;
            List <LabelVector> result = new List <LabelVector>();
            double             norm   = OversampleRate / _phi;

            for (int i = job.StartIndex; i < job.EndIndex; i++)
            {
                LabelVector x      = _data[i];
                double      sample = x.FeatureValue * norm;
                if (ThreadsafeRandom.Test(sample))
                {
                    LabelVector center = x.Clone() as LabelVector;
                    result.Add(center);
                }
            }
            return(result);
        }
コード例 #2
0
        private void seedCenters()
        {
            UpdateManager.WriteLine("Performing K-Means++ initialization...");
            LabelVector center = _data.SelectRandom().Clone() as LabelVector;

            center.Label = 0;
            _centers.Add(center);

            Stopwatch sw = new Stopwatch();

            for (int i = 1; i < _k; i++)
            {
                sw.Reset();
                UpdateManager.Write("Recalculating phi...");
                sw.Start();
                runJobs(o => calculatePhi(o));
                sw.Stop();
                UpdateManager.WriteLine("Done [{0}ms]", sw.ElapsedMilliseconds);

                float[]     dist = _data.Select(o => o.FeatureValue).ToArray().Normalize();
                LabelVector x    = _data[dist.Sample()];
                _centers.Add(x.Clone() as LabelVector);
            }
        }