/// <summary>
        /// Implements <see cref="ICompensatedSum.Clone()"/>.
        /// </summary>
        public ICompensatedSum Clone()
        {
            var clone = new KahanSum();

            clone._sum = _sum;
            clone._kc  = _kc;
            return(clone);
        }
Esempio n. 2
0
 public TrainingSample(TSample s, int index, float weight, float actual)
 {
     Sample       = s;
     Weight       = weight;
     Actual       = actual;
     Index        = index;
     _confidenceP = new KahanSum();
     _confidenceN = new KahanSum();
 }
        public void ZeroSumTest()
        {
            KahanSum sum = new KahanSum();

            for (int i = 0; i < 10; i++)
            {
                sum.Add(0.0);
            }

            Assert.Equal(0.0, sum.Sum);
        }
        public void SumTest()
        {
            KahanSum sum = new KahanSum();

            for (int i = 0; i < 100; i++)
            {
                sum.Add(i);
            }

            Assert.Equal(4950.0, sum.Sum);
        }
Esempio n. 5
0
        /// <summary>
        /// Create the object which uses custom implementation for random generators.
        /// </summary>
        /// <param name="UniformGen"> Object, which implements <see cref="IContUniformGen"/> interface. </param>
        /// <param name="NormalGen">  Object, which implements <see cref="INormalGen"/> interface. </param>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="NormalGen"/> or <paramref name="UniformGen"/> is null.
        /// </exception>
        public BBBCOptimizer(IContUniformGen UniformGen, INormalGen NormalGen)
        {
            if (NormalGen == null)
            {
                throw new ArgumentNullException(nameof(NormalGen));
            }

            _uniformRand = UniformGen ?? throw new ArgumentNullException(nameof(UniformGen));

            _normalRand = NormalGen;

            _denumKahanSum = new KahanSum();
        }
        public void SumResetTest()
        {
            KahanSum sum = new KahanSum();

            sum.Add(-1);
            sum.Add(-2);
            sum.Add(-3);

            sum.SumResest();

            sum.Add(1);
            sum.Add(2);

            Assert.Equal(3.0, sum.Sum);
        }
Esempio n. 7
0
        /// <summary>
        /// Create the object which uses custom implementation for random generators.
        /// </summary>
        /// <param name="UniformGen">
        /// Object, which implements <see cref="IContUniformGen"/> interface.
        /// </param>
        /// <param name="NormalGen">  Object, which implements <see cref="INormalGen"/> interface. </param>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="NormalGen"/> or <paramref name="UniformGen"/> is null.
        /// </exception>
        public BaseFW(IContUniformGen UniformGen, INormalGen NormalGen)
        {
            if (UniformGen == null)
            {
                throw new ArgumentNullException(nameof(UniformGen));
            }

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

            _uniformRand = UniformGen;

            _normalRand = NormalGen;

            _distKahanSum         = new KahanSum();
            _denumForProbKahanSum = new KahanSum();
        }
Esempio n. 8
0
        public MOControlTask(int N, double LowerBound, double UpperBound, double TMax, double x10, double x20, double lambda1, double lambda2, double lambda3, double lambad4)
        {
            if (N < 2)
            {
                throw new ArgumentException($"{nameof(N)} must be greater than 1.", nameof(N));
            }

            if (LowerBound >= UpperBound)
            {
                throw new ArgumentException($"{nameof(LowerBound)} must be less than {nameof(UpperBound)}");
            }

            if (TMax <= 0)
            {
                throw new ArgumentException($"{nameof(TMax)} must be greater than 0.");
            }

            _lowerBounds = Enumerable.Repeat(LowerBound, N * 2).ToArray();
            _upperBounds = Enumerable.Repeat(UpperBound, N * 2).ToArray();

            _lambda1 = lambda1;
            _lambda2 = lambda2;
            _lambda3 = lambda3;
            _lambda4 = lambad4;

            _nSwitch = N;

            _step = (double)TMax / _nSwitch;

            _Tmax     = TMax;
            _valueofT = new double[_nSwitch + 1];

            for (int i = 0; i < _valueofT.Length; i++)
            {
                _valueofT[i] = i * _step;
            }

            _ode          = new TargetODE(x10, x20, _Tmax, _valueofT);
            _targetValues = new double[OBJ_COUNT];

            _sum = new KahanSum();
        }
Esempio n. 9
0
 public void Sub(KahanSum sum)
 {
     Add(sum.m_carry);
     Sub(sum.m_sum);
 }
Esempio n. 10
0
 public void Add(KahanSum sum)
 {
     Sub(sum.m_carry);
     Add(sum.m_sum);
 }
Esempio n. 11
0
 public ControlTaskI2(int N, double LowerBound, double UpperBound, double TMax, double x10, double x20, double LambdaLower, double LambdaUpper) : base(N, LowerBound, UpperBound, TMax, x10, x20, LambdaLower, LambdaUpper)
 {
     _sum = new KahanSum();
 }