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)); }
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); }
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); }
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); }
/// <summary> /// Evaluates the fuzzy condition. /// </summary> /// <param name="data"> /// The data. /// </param> /// <param name="evaluator"> /// The evaluator. /// </param> /// <returns> /// A <see cref="double"/>. /// </returns> /// <exception cref="ArgumentException"> /// Throws if provided data does not contain all subjects. /// </exception> public Evaluation Evaluate( IReadOnlyDictionary <Label, DataPoint> data, FuzzyEvaluator evaluator) { Validate.NotNull(data, nameof(data)); Validate.NotNull(evaluator, nameof(evaluator)); var evaluations = new List <Evaluation>(); foreach (var premise in this.Premises) { if (data.ContainsKey(premise.Subject)) { var input = data[premise.Subject]; evaluations.Add(premise.Evaluate(input)); } else { throw new InvalidOperationException( $"Evaluation Failed (cannot evaluate premise '{premise.Subject}' with provided data)."); } } return(new Evaluation(this.Connective, UnitInterval.Create(evaluator.Evaluate(evaluations) * this.Weight))); }
internal void Evaluate_WithTwoEvaluationsOrConnective_ReturnsExpectedResult() { // Arrange var evaluator = new FuzzyEvaluator(); var evaluations = new List <Evaluation> { new Evaluation(LogicOperators.If(), UnitInterval.Create(0.25)), new Evaluation(LogicOperators.Or(), UnitInterval.Create(1)) }; // Act var result = evaluator.Evaluate(evaluations); // Assert Assert.Equal(UnitInterval.Create(1), result); }