示例#1
0
 public GeneticKMeansSpeciationStrategy(
     IDistanceMetric <T> distanceMetric,
     int maxKMeansIters,
     IRandomSource rng)
 {
     _distanceMetric  = distanceMetric;
     _maxKMeansIters  = maxKMeansIters;
     _parallelOptions = new ParallelOptions();
     _kmeansInit      = new GeneticKMeansSpeciationInit <T>(distanceMetric, _parallelOptions, rng);
 }
 /// <summary>
 /// Construct a new instance.
 /// </summary>
 /// <param name="distanceMetric">Distance metric.</param>
 /// <param name="maxKMeansIters">Maximum number of k-means iterations.</param>
 /// <param name="parallelOptions">Parallel execution options.</param>
 public GeneticKMeansSpeciationStrategy(
     IDistanceMetric <T> distanceMetric,
     int maxKMeansIters,
     ParallelOptions parallelOptions)
 {
     _distanceMetric  = distanceMetric;
     _maxKMeansIters  = maxKMeansIters;
     _parallelOptions = parallelOptions;
     _kmeansInit      = new GeneticKMeansSpeciationInit <T>(distanceMetric, parallelOptions);
 }
 public RegularizedGeneticKMeansSpeciationStrategy(
     IDistanceMetric <T> distanceMetric,
     int maxKMeansIters,
     double regularizationConstant,
     IRandomSource rng)
 {
     _distanceMetric         = distanceMetric;
     _maxKMeansIters         = maxKMeansIters;
     _regularizationConstant = regularizationConstant;
     _parallelOptions        = new ParallelOptions();
     _kmeansInit             = new GeneticKMeansSpeciationInit <T>(distanceMetric, _parallelOptions, rng);
 }
        /// <summary>
        /// Construct a new instance.
        /// </summary>
        /// <param name="distanceMetric">Distance metric.</param>
        /// <param name="maxKMeansIters">Maximum number of k-means iterations.</param>
        /// <param name="degreeOfParallelism">The number of CPU threads to distribute work to.</param>
        public GeneticKMeansSpeciationStrategy(
            IDistanceMetric <T> distanceMetric,
            int maxKMeansIters,
            int degreeOfParallelism)
        {
            _distanceMetric = distanceMetric;
            _maxKMeansIters = maxKMeansIters;

            // Reject degreeOfParallelism values less than 2. -1 should have been resolved to an actual number by the time
            // this constructor is invoked, and 1 is nonsensical for a parallel strategy.
            if (degreeOfParallelism < 2)
            {
                throw new ArgumentException(nameof(degreeOfParallelism));
            }

            _parallelOptions = new ParallelOptions {
                MaxDegreeOfParallelism = degreeOfParallelism
            };

            _kmeansInit = new GeneticKMeansSpeciationInit <T>(distanceMetric, _parallelOptions);
        }