예제 #1
0
        internal void Evaluate_WithThreeGroupCompoundStatementAndEinsteinFunctions_ReturnsExpectedResult()
        {
            // Arrange
            var tnorm   = TriangularNormFactory.EinsteinProduct();
            var tconorm = TriangularConormFactory.EinsteinSum();

            var evaluator = new FuzzyEvaluator(tnorm, tconorm);

            var evaluations = new List <Evaluation>
            {
                // Statement group 1
                new Evaluation(LogicOperators.If(), UnitInterval.Create(0.25)),
                new Evaluation(LogicOperators.And(), UnitInterval.Create(0.0)),
                new Evaluation(LogicOperators.And(), UnitInterval.Create(0.2)),

                // Statement group 2
                new Evaluation(LogicOperators.Or(), UnitInterval.Create(1)),
                new Evaluation(LogicOperators.And(), UnitInterval.Create(0.9)),
                new Evaluation(LogicOperators.And(), UnitInterval.Create(0.8)),

                // Statement group 3
                new Evaluation(LogicOperators.Or(), UnitInterval.Create(0.5)),
                new Evaluation(LogicOperators.And(), UnitInterval.Create(1)),
                new Evaluation(LogicOperators.And(), UnitInterval.Create(1))
            };

            // Act
            var result = evaluator.Evaluate(evaluations);

            // Assert
            Assert.Equal(0.891304347826087, result.Value);
        }
예제 #2
0
        internal void Evaluate_WithThreeGroupCompoundStatementAndOtherFunctions_ReturnsExpectedResult()
        {
            // Arrange
            var tnorm   = TriangularNormFactory.Lukasiewicz();
            var tconorm = TriangularConormFactory.ProbabilisticSum();

            var evaluator = new FuzzyEvaluator(tnorm, tconorm);

            var evaluations = new List <Evaluation>
            {
                // Statement group 1
                new Evaluation(LogicOperators.If(), UnitInterval.Create(0.25)),
                new Evaluation(LogicOperators.And(), UnitInterval.Create(0.0)),
                new Evaluation(LogicOperators.And(), UnitInterval.Create(0.2)),

                // Statement group 2
                new Evaluation(LogicOperators.Or(), UnitInterval.Create(1)),
                new Evaluation(LogicOperators.And(), UnitInterval.Create(0.9)),
                new Evaluation(LogicOperators.And(), UnitInterval.Create(0.8)),

                // Statement group 3
                new Evaluation(LogicOperators.Or(), UnitInterval.Create(0.5)),
                new Evaluation(LogicOperators.And(), UnitInterval.Create(1)),
                new Evaluation(LogicOperators.And(), UnitInterval.Create(1))
            };

            // Act
            var result = evaluator.Evaluate(evaluations);

            // Assert
            Assert.Equal(0.85, Math.Round(result.Value, 2));
        }
예제 #3
0
        internal void Evaluate_WithFourGroupCompoundStatementThenConnectedByMultipleOrs_ReturnsExpectedResult()
        {
            // Arrange
            var evaluator = new FuzzyEvaluator();

            var evaluations = new List <Evaluation>
            {
                // Statement group 1 (assumed to evaluate to 0.9).
                new Evaluation(LogicOperators.If(), UnitInterval.Create(1)),
                new Evaluation(LogicOperators.And(), UnitInterval.Create(1)),
                new Evaluation(LogicOperators.And(), UnitInterval.Create(0.9)),

                // Statement group 2 (assumed to evaluate to 0.8).
                new Evaluation(LogicOperators.Or(), UnitInterval.Create(1)),
                new Evaluation(LogicOperators.And(), UnitInterval.Create(0.9)),
                new Evaluation(LogicOperators.And(), UnitInterval.Create(0.8)),

                // Statement group 3 (assumed to evaluate to 0.7).
                new Evaluation(LogicOperators.Or(), UnitInterval.Create(0.7)),
                new Evaluation(LogicOperators.And(), UnitInterval.Create(0.7)),
                new Evaluation(LogicOperators.And(), UnitInterval.Create(0.7)),

                // Then multiple or connectives (assumed to evaluate to 1).
                new Evaluation(LogicOperators.Or(), UnitInterval.Create(0.8)),
                new Evaluation(LogicOperators.Or(), UnitInterval.Create(0.9)),
                new Evaluation(LogicOperators.Or(), UnitInterval.Create(1))
            };

            // Act
            var result = evaluator.Evaluate(evaluations);

            // Assert
            Assert.Equal(UnitInterval.Create(1), result);
        }
예제 #4
0
        internal void Evaluate_WithThreeGroupCompoundStatement_ReturnsExpectedResult()
        {
            // Arrange
            var evaluator = new FuzzyEvaluator();

            var evaluations = new List <Evaluation>
            {
                // Statement group 1 (assumed to evaluate to 0).
                new Evaluation(LogicOperators.If(), UnitInterval.Create(0.25)),
                new Evaluation(LogicOperators.And(), UnitInterval.Create(0.0)),
                new Evaluation(LogicOperators.And(), UnitInterval.Create(0.2)),

                // Statement group 2 (assumed to evaluate to 0.8).
                new Evaluation(LogicOperators.Or(), UnitInterval.Create(1)),
                new Evaluation(LogicOperators.And(), UnitInterval.Create(0.9)),
                new Evaluation(LogicOperators.And(), UnitInterval.Create(0.8)),

                // Statement group 3 (assumed to evaluate to 0.9).
                new Evaluation(LogicOperators.Or(), UnitInterval.Create(0.9)),
                new Evaluation(LogicOperators.And(), UnitInterval.Create(1)),
                new Evaluation(LogicOperators.And(), UnitInterval.Create(1))
            };

            // Act
            var result = evaluator.Evaluate(evaluations);

            // Assert
            Assert.Equal(UnitInterval.Create(0.9), result);
        }
예제 #5
0
        /// <summary>
        /// Adds a <see cref="Condition"/> to the <see cref="FuzzyRule"/> to be built.
        /// </summary>
        /// <param name="condition">
        /// The condition.
        /// </param>
        /// <returns>
        /// The <see cref="FuzzyRuleBuilder"/>.
        /// </returns>
        public FuzzyRuleBuilder And(ConditionBuilder condition)
        {
            Validate.NotNull(condition, nameof(condition));

            condition.Connective = LogicOperators.And();
            this.conditions.Add(condition.Build());

            return(this);
        }
예제 #6
0
        /// <summary>
        /// Adds an 'And' premise to the condition builder.
        /// </summary>
        /// <param name="proposition">
        /// The proposition.
        /// </param>
        /// <returns>
        /// A <see cref="Condition"/>.
        /// </returns>
        public ConditionBuilder And(Proposition proposition)
        {
            Utility.Validate.NotNull(proposition, nameof(proposition));

            this.Premises.Add(new Premise(
                                  LogicOperators.And(),
                                  proposition.Variable,
                                  proposition.Evaluator,
                                  proposition.State));

            return(this);
        }
예제 #7
0
        internal void Evaluate_WithTwoEvaluationsAndConnective_ReturnsExpectedResult()
        {
            // Arrange
            var evaluator = new FuzzyEvaluator();

            var evaluations = new List <Evaluation>
            {
                new Evaluation(LogicOperators.If(), UnitInterval.Create(0.25)),
                new Evaluation(LogicOperators.And(), UnitInterval.Create(0.1))
            };

            // Act
            var result = evaluator.Evaluate(evaluations);

            // Assert
            Assert.Equal(UnitInterval.Create(0.1), result);
        }
예제 #8
0
        /// <summary>
        /// Returns the final evaluation result of the aggregated collection of evaluations.
        /// </summary>
        /// <param name="evaluations">
        /// The evaluations.
        /// </param>
        /// <returns>
        /// A <see cref="UnitInterval"/>.
        /// </returns>
        public UnitInterval Evaluate(IEnumerable <Evaluation> evaluations)
        {
            var result = UnitInterval.One();

            foreach (var evaluation in evaluations)
            {
                if (evaluation.Connective.Equals(LogicOperators.And()) ||
                    evaluation.Connective.Equals(LogicOperators.If()))
                {
                    result = this.And(result, evaluation.Result);
                }

                if (evaluation.Connective.Equals(LogicOperators.Or()))
                {
                    result = this.Or(result, evaluation.Result);
                }
            }

            return(result);
        }