コード例 #1
0
        /// <summary>
        ///     Creates a new <see cref="NonLinearRankFitnessFunction{TProgram}" /> with the given parameters.
        /// </summary>
        /// <param name="programComparer">The object used to compare programs and determine their ranking.</param>
        /// <param name="population">The list of programs whose fitness can be computed by this function.</param>
        /// <param name="selectivePressure">
        ///     The probability of the best individual being selected compared to the average probability of selection of all
        ///     individuals.
        /// </param>
        public NonLinearRankFitnessFunction(
            IComparer <TProgram> programComparer, IPopulation <TProgram> population, double selectivePressure)
            : base(programComparer, population)
        {
            var n = population.Count;

            this.SelectivePressure = Math.Max(1d, Math.Min(n - 2d, selectivePressure));

            // finds the root of the polynomial
            try
            {
                this._root      = Brent.FindRootExpand(this.Polynomial, -n, n, 1E-08, 1000);
                this._rootFound = true;
            }
            catch (NonConvergenceException)
            {
            }

            // stores the exponential sum
            this._rootFactor = 0d;
            var pow = 1d;

            for (var i = 0; i < n; i++)
            {
                this._rootFactor += pow;
                pow *= this._root;
            }

            this._rootFactor = n / this._rootFactor;
        }
コード例 #2
0
ファイル: Aim.cs プロジェクト: tjgtll/osu
        /// <summary>
        /// Find first miss count achievable with at least probability p
        /// </summary>
        private static double getMissCount(double p, double[] missProbabilities)
        {
            var distribution = new PoissonBinomial(missProbabilities);

            Func <double, double> cdfMinusProb = missCount => distribution.Cdf(missCount) - p;

            return(Brent.FindRootExpand(cdfMinusProb, -100, 1000));
        }
コード例 #3
0
ファイル: Aim.cs プロジェクト: HeBuwei/osu
        /// <summary>
        /// Find first miss count achievable with at least probability p
        /// </summary>
        private static double getMissCount(double p, double[] missProbabilities)
        {
            if (missProbabilities.Sum() == 0)
            {
                return(0);
            }

            var distribution = new PoissonBinomial(missProbabilities);

            double cdfMinusProb(double missCount) => distribution.CDF(missCount) - p;

            return(Brent.FindRootExpand(cdfMinusProb, -100, 1000));
        }
コード例 #4
0
        public static double inv_m1_beta_black_brent(double beta, double f, double sigma)
        {
            var guess = inv_m1_beta_black_convexity(beta, f, sigma);
            var shift = 1.5e-8 * (Math.Max(1.0, Math.Abs(guess)));
            var lo    = guess - shift;
            var hi    = guess + shift;
            var rf    = FS.fun((double mu) =>
            {
                var rr = m1_beta_black(beta, mu, sigma);
                return(rr - f);
            });

            return(Brent.FindRootExpand(rf, lo, hi));
        }
コード例 #5
0
        public void BrentMultipleRoots()
        {
            // Roots at -2, 2
            double F1(double x) => x * x - 4;

            Assert.AreEqual(0, F1(Brent.FindRoot(F1, 1, 5, 1e-14)));
            Assert.AreEqual(0, F1(Brent.FindRootExpand(F1, 3, 5, 1e-14)));
            Assert.AreEqual(-2, Brent.FindRoot(F1, -5, -1, 1e-14));
            Assert.AreEqual(2, Brent.FindRoot(F1, 1, 4, 1e-14));
            Assert.AreEqual(0, F1(Brent.FindRoot(x => - F1(x), 1, 5, 1e-14)));
            Assert.AreEqual(-2, Brent.FindRoot(x => - F1(x), -5, -1, 1e-14));
            Assert.AreEqual(2, Brent.FindRoot(x => - F1(x), 1, 4, 1e-14));
            // Roots at 3, 4
            double F2(double x) => (x - 3) * (x - 4);

            Assert.AreEqual(0, F2(Brent.FindRoot(F2, -5, 3.5, 1e-14)));
            Assert.AreEqual(3, Brent.FindRoot(F2, -5, 3.5, 1e-14));
            Assert.AreEqual(4, Brent.FindRoot(F2, 3.2, 5, 1e-14));
            Assert.AreEqual(3, Brent.FindRoot(F2, 2.1, 3.9, 0.001, 50), 0.001);
            Assert.AreEqual(3, Brent.FindRoot(F2, 2.1, 3.4, 0.001, 50), 0.001);
        }
コード例 #6
0
        public void MultipleRoots()
        {
            // Roots at -2, 2
            Func <double, double> f1 = x => x * x - 4;

            Assert.AreEqual(0, f1(Brent.FindRoot(f1, 1, 5, 1e-14, 100)));
            Assert.AreEqual(0, f1(Brent.FindRootExpand(f1, 3, 5, 1e-14, 100)));
            Assert.AreEqual(-2, Brent.FindRoot(f1, -5, -1, 1e-14, 100));
            Assert.AreEqual(2, Brent.FindRoot(f1, 1, 4, 1e-14, 100));
            Assert.AreEqual(0, f1(Brent.FindRoot(x => - f1(x), 1, 5, 1e-14, 100)));
            Assert.AreEqual(-2, Brent.FindRoot(x => - f1(x), -5, -1, 1e-14, 100));
            Assert.AreEqual(2, Brent.FindRoot(x => - f1(x), 1, 4, 1e-14, 100));

            // Roots at 3, 4
            Func <double, double> f2 = x => (x - 3) * (x - 4);

            Assert.AreEqual(0, f2(Brent.FindRoot(f2, -5, 3.5, 1e-14, 100)));
            Assert.AreEqual(3, Brent.FindRoot(f2, -5, 3.5, 1e-14, 100));
            Assert.AreEqual(4, Brent.FindRoot(f2, 3.2, 5, 1e-14, 100));
            Assert.AreEqual(3, Brent.FindRoot(f2, 2.1, 3.9, 0.001, 50), 0.001);
            Assert.AreEqual(3, Brent.FindRoot(f2, 2.1, 3.4, 0.001, 50), 0.001);
        }