/// <summary>
        /// Initializes a new instance of the <see cref="ContinuizedGenomeSearchPoint"/> class.
        /// </summary>
        /// <param name="values">
        /// The real-valued point to base this on.
        /// This is the internal representation, not the one in the parameter space.
        /// <para>Use <see cref="CreateFromGenome"/> if starting from search space.</para>
        /// </param>
        /// <param name="parameterTree">Specifies the parameters.</param>
        /// <param name="genomeBuilder">Responsible for checking validity and repairing.</param>
        /// <param name="lowerBounds">The lower bounds by dimension.</param>
        /// <param name="upperBounds">The upper bounds by dimension.</param>
        public ContinuizedGenomeSearchPoint(
            Vector <double> values,
            ParameterTree parameterTree,
            GenomeBuilder genomeBuilder,
            double[] lowerBounds,
            double[] upperBounds)
            : base(values, lowerBounds, upperBounds)
        {
            if (parameterTree == null)
            {
                throw new ArgumentNullException(nameof(parameterTree));
            }

            if (genomeBuilder == null)
            {
                throw new ArgumentNullException(nameof(genomeBuilder));
            }

            var transformator = new TolerantGenomeTransformation(parameterTree);
            var geneValues    = transformator.RoundToValidValues(this.MapIntoBounds().ToArray());
            var genome        = transformator.ConvertBack(geneValues);

            // Remember whether there was no direct mapping to a valid genome.
            this.IsRepaired = false;
            if (!genomeBuilder.IsGenomeValid(genome))
            {
                genomeBuilder.MakeGenomeValid(genome);
                this.IsRepaired = true;
            }

            this.Genome = new ImmutableGenome(genome);
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PartialGenomeSearchPoint"/> class.
        /// </summary>
        /// <param name="underlyingGenome">The underlying <see cref="ImmutableGenome"/>.</param>
        /// <param name="values">
        /// The real-valued point to base continuous parameters on.
        /// This is the internal representation, not the one in the parameter space.
        /// <para>Use <see cref="CreateFromGenome"/> if starting from search space.</para>
        /// </param>
        /// <param name="genomeSearchPointConverter">
        /// Responsible for converting between full-fledged <see cref="Genome"/>s and continuous values in
        /// parameter space.
        /// </param>
        /// <param name="genomeBuilder">Responsible for checking validity and repairing.</param>
        /// <param name="lowerBounds">The lower bounds by dimension.</param>
        /// <param name="upperBounds">The upper bounds by dimension.</param>
        public PartialGenomeSearchPoint(
            ImmutableGenome underlyingGenome,
            Vector <double> values,
            GenomeSearchPointConverter genomeSearchPointConverter,
            GenomeBuilder genomeBuilder,
            double[] lowerBounds,
            double[] upperBounds)
            : base(values, lowerBounds, upperBounds)
        {
            if (genomeSearchPointConverter == null)
            {
                throw new ArgumentNullException(nameof(genomeSearchPointConverter));
            }

            if (genomeBuilder == null)
            {
                throw new ArgumentNullException(nameof(genomeBuilder));
            }

            // To create the complete genome, map the continuous values into parameter search space again.
            var genome = genomeSearchPointConverter.MergeIntoGenome(this.MapIntoBounds(), underlyingGenome);

            // Remember whether there was no direct mapping to a valid genome.
            this.IsRepaired = false;
            if (!genomeBuilder.IsGenomeValid(genome))
            {
                genomeBuilder.MakeGenomeValid(genome);
                this.IsRepaired = true;
            }

            this.Genome = new ImmutableGenome(genome);
        }