示例#1
0
 public void AddLevel(IntervalD level, double alpha)
 {
     if (_alphaLevels.ContainsKey(alpha))
         _alphaLevels[alpha] = level;
     else
         _alphaLevels.Add(alpha, level);
 }
示例#2
0
        public void PropagateSignal()
        {
            var levelsRight = new Dictionary<double, IntervalD>
                {
                    {0.0, new IntervalD(1.0, 3.0)},
                    {0.5, new IntervalD(1.5, 2.5)},
                    {1.0, new IntervalD(2.0, 2.0)},
                };
            var weight = new DiscreteFuzzyNumber(levelsRight);
            var input = new Link(weight);
            var output = new Link();
            var f = new Func<double, double>(x => 1.0 / (1.0 + Math.Pow(Math.E, -x)));

            var neuron = new FuzzyNeuron(f, () => DiscreteFuzzyNumber.GenerateLittleNumber(levelsCount: 3));
            neuron.AddInput(input, weight);
            neuron.SetOutput(output);

            neuron.Propagate();

            var expectedLevel00 = new IntervalD(f(1), f(9));
            var expectedLevel05 = new IntervalD(f(2.25), f(6.25));
            var expectedLevel10 = new IntervalD(f(4.0), f(4.0));

            Assert.NotNull(output.Signal);
            Assert.That(output.Signal.GetAlphaLevel(0.0), Is.EqualTo(expectedLevel00));
            Assert.That(output.Signal.GetAlphaLevel(0.5), Is.EqualTo(expectedLevel05));
            Assert.That(output.Signal.GetAlphaLevel(1.0), Is.EqualTo(expectedLevel10));
        }
示例#3
0
        public void ContainSameValuesAfterConstructionFromIntervalD()
        {
            var source = new IntervalD(0.0, 0.0);

            var result = new IntervalD(source);

            Assert.That(result, Is.EqualTo(source));
        }
示例#4
0
        public void BeAnotherObjectAfterConstructionFromIntervalD()
        {
            var source = new IntervalD(0.0, 0.0);

            var result = new IntervalD(source);

            Assert.AreNotSame(result, source, "New point should be another object");
        }
示例#5
0
        public void CorrectlySubstractIntervals()
        {
            const double a1 = -3.0;
            const double b1 = 0.5;
            var x = new IntervalD(a1, b1);

            const double a2 = 0.5;
            const double b2 = 2.0;
            var y = new IntervalD(a2, b2);

            var result = x - y;

            Assert.That(result, Is.EqualTo(new IntervalD(a1 - a2, b1 - b2)));
        }
示例#6
0
        public void CorrectlyMultiplyIntervals()
        {
            const double a1 = -3.0;
            const double b1 = 0.5;
            var x = new IntervalD(a1, b1);

            const double a2 = 0.5;
            const double b2 = 2.0;
            var y = new IntervalD(a2, b2);

            var result = x*y;

            Assert.That(result, Is.EqualTo(new IntervalD(a1*a2, b1*b2)));
        }
示例#7
0
        public void CorrectlyDivideIntervals()
        {
            const double a1 = -3.0;
            const double b1 = 0.5;
            var x = new IntervalD(a1, b1);

            const double a2 = 0.5;
            const double b2 = 2.0;
            var y = new IntervalD(a2, b2);

            var result = x / y;

            Assert.That(result, Is.EqualTo(new IntervalD(a1 / a2, b1 / b2)));
        }
示例#8
0
        public void ThrowArgumentExceptionOnZeroDivision()
        {
            const double a1 = -3.0;
            const double b1 = 0.5;
            var x = new IntervalD(a1, b1);

            const double a2 = 0.5;
            const double b2 = 0.0;
            var y = new IntervalD(a2, b2);

            Assert.Throws<DivideByZeroException>(() => { var result = x / y; });
        }
示例#9
0
        public void SwapValuesToMakeCorrectInterval()
        {
            const double min = -1.0;
            const double max = 3.0;
            var result = new IntervalD(max, min);

            Assert.That(result.X, Is.EqualTo(min));
            Assert.That(result.Y, Is.EqualTo(max));
        }
示例#10
0
文件: IntervalD.cs 项目: Diover/nets
 public bool Equals(IntervalD value)
 {
     return Math.Abs(X - value.X) < Epsilon &&
            Math.Abs(Y - value.Y) < Epsilon;
 }
示例#11
0
        public void ReturnTrueComparingValuesSmallerEpsilon()
        {
            const double epsilon = IntervalD.Epsilon;
            const double x = 1.0;
            var a = new IntervalD(x + epsilon / 2.0, x);
            var b = new IntervalD(x, x);

            Assert.That(a == b, Is.True);
        }
示例#12
0
        public void ReturnTrueComparingSameValues()
        {
            const double x = 1.0001;
            var a = new IntervalD(x, x);
            var b = new IntervalD(x, x);

            Assert.That(a == b, Is.True);
        }
示例#13
0
        public void ReturnFalseIfNotContainsValue()
        {
            const double x = -1.001;
            const double left = -1.0;
            const double right = 100.0;
            var interval = new IntervalD(left, right);

            var result = interval.Contains(x);

            Assert.That(result, Is.False);
        }
示例#14
0
        public void CorrectlyApplyActivationFunction()
        {
            var f = new Func<double, double>(value => 1.0/(1.0 + Math.Pow(Math.E, -value)));
            var levelsLeft = new Dictionary<double, IntervalD>
                {
                    {0.0, new IntervalD(-2.0, 2.0)},
                    {0.5, new IntervalD(-1.0, 1.0)},
                    {1.0, new IntervalD(0.0, 0.0)},
                };
            var x = new DiscreteFuzzyNumber(levelsLeft);

            var activation = x.Apply(f);

            var expectedValueOnLevel00 = new IntervalD(f(-2.0), f(2.0));
            var expectedValueOnLevel05 = new IntervalD(f(-1.0), f(1.0));
            var expectedValueOnLevel10 = new IntervalD(f(0.0), f(0.0));

            Assert.That(activation.GetAlphaLevel(0.0), Is.EqualTo(expectedValueOnLevel00));
            Assert.That(activation.GetAlphaLevel(0.5), Is.EqualTo(expectedValueOnLevel05));
            Assert.That(activation.GetAlphaLevel(1.0), Is.EqualTo(expectedValueOnLevel10));
        }
示例#15
0
        public void ReturnFalseComparingDifferentValues()
        {
            var a = new IntervalD(1, 1);
            var b = new IntervalD(1, 2);

            Assert.That(a == b, Is.False);
        }
示例#16
0
        public void ReturnTrueIfContainsValue()
        {
            const double x = 99.99;
            const double left = -1.0;
            const double right = 100.0;
            var interval = new IntervalD(left, right);

            var result = interval.Contains(x);

            Assert.That(result, Is.True);
        }
示例#17
0
文件: IntervalD.cs 项目: Diover/nets
 public IntervalD(IntervalD interval)
     : this(interval.X, interval.Y)
 {
 }