Ejemplo n.º 1
0
        /// <summary>
        /// Applies the rulset in <see cref="FuzzyLogic.InferenceEngine.fuzzyRules"/> to <paramref name="fuzzyInput"/> and produces a new <see cref="FuzzyLogic.FuzzyOutputData"/> based on these rules
        /// </summary>
        /// <param name="fuzzyInput">The fussified input given by <see cref="FuzzyLogic.Fuzzifier.Fuzzify(CrispInput)"/> on which the rules will be applied</param>
        /// <returns>A new <see cref="FuzzyLogic.FuzzyOutputData"/> based on these rules</returns>
        public FuzzyOutputData ApplyRulset(FuzzyInputData fuzzyInput)
        {
            List <FuzzyOutputData> unaggragatedFuzzyOuputs = new List <FuzzyOutputData>();

            ApplySimpleRules(fuzzyInput, unaggragatedFuzzyOuputs);
            ApplyLogicalRules(fuzzyInput, unaggragatedFuzzyOuputs);

            FuzzyOutputData outputData = AgragateFuzzyOutputs(unaggragatedFuzzyOuputs);

            return(outputData);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Takes <see cref="FuzzyLogic.CrispInput"/> and turns it into <see cref="FuzzyLogic.FuzzyInputData"/> based on the evaluated value at <see cref="FuzzyLogic.Fuzzifier.inputFunction"/>
        /// </summary>
        /// <param name="crispInput">Crisp data from sensors</param>
        /// <returns>Fuzzified data</returns>
        public FuzzyInputData Fuzzify(CrispInput crispInput)
        {
            FuzzyInputData fuzzy = new FuzzyInputData();

            foreach (CrispInput.Inputs variable in System.Enum.GetValues(typeof(CrispInput.Inputs)))
            {
                foreach (FuzzyUtility.FuzzyStates state in System.Enum.GetValues(typeof(FuzzyUtility.FuzzyStates)))
                {
                    fuzzy[variable][state] = inputFunction[state].Evaluate(crispInput[variable]);
                }
            }

            return(fuzzy);
        }
Ejemplo n.º 3
0
        private void ApplySimpleRules(FuzzyInputData fuzzyInput, List <FuzzyOutputData> unaggragatedFuzzyOuputs)
        {
            foreach (FuzzyRulesList.SimpleFuzzyRule rule in fuzzyRules.simpleRules)
            {
                FuzzyOutputData fuzzyOutput = new FuzzyOutputData();


                float value = GetValueOfAnticedent(fuzzyInput, rule.anticedent);

                fuzzyOutput[rule.consequent.output][rule.consequent.state] = value;


                unaggragatedFuzzyOuputs.Add(fuzzyOutput);
            }
        }
Ejemplo n.º 4
0
        private static float GetValueOfAnticedent(FuzzyInputData fuzzyInput, FuzzyRulesList.FuzzyAnticedent anticedent)
        {
            float value = 0;

            switch (anticedent.isOrIsNot)
            {
            case FuzzyRulesList.FuzzyAnticedent.IsOrIsNot.Is:
                value = ValueIsRule(fuzzyInput, anticedent);
                break;

            case FuzzyRulesList.FuzzyAnticedent.IsOrIsNot.IsNot:
                value = ValueIsNotRule(fuzzyInput, anticedent);
                break;
            }

            return(value);
        }
Ejemplo n.º 5
0
        private void ApplyLogicalRules(FuzzyInputData fuzzyInput, List <FuzzyOutputData> unaggragatedFuzzyOuputs)
        {
            foreach (FuzzyRulesList.LogicalFuzzyRule rule in fuzzyRules.logicRules)
            {
                FuzzyOutputData fuzzyOutput = new FuzzyOutputData();

                float anticedent1 = GetValueOfAnticedent(fuzzyInput, rule.anticedent1);
                float anticedent2 = GetValueOfAnticedent(fuzzyInput, rule.anticedent2);

                float value = ApplyLogicalRelationshipToAnticedent1Values(anticedent1, anticedent2, rule.logicalRelationship);

                fuzzyOutput[rule.consequent.output][rule.consequent.state] = value;


                unaggragatedFuzzyOuputs.Add(fuzzyOutput);
            }
        }
Ejemplo n.º 6
0
        private static float GetValueOfPredicate(FuzzyInputData fuzzyInput, FuzzyPredicate predicate)
        {
            float value = 0;

            switch (predicate.isOrIsNot)
            {
            case FuzzyPredicate.IsOrIsNot.Is:
                value = ValueIsRule(fuzzyInput, predicate);
                break;

            case FuzzyPredicate.IsOrIsNot.IsNot:
                value = ValueIsNotRule(fuzzyInput, predicate);
                break;
            }

            return(value);
        }
Ejemplo n.º 7
0
        private void ApplyLogicalRules(FuzzyInputData fuzzyInput, List <FuzzyOutputData> unaggragatedFuzzyOuputs)
        {
            foreach (LogicalFuzzyRule rule in fuzzyRules.logicRules)
            {
                FuzzyOutputData fuzzyOutput = new FuzzyOutputData();

                float predicate1 = GetValueOfPredicate(fuzzyInput, rule.predicate1);
                float predicate2 = GetValueOfPredicate(fuzzyInput, rule.predicate2);

                float value = ApplyLogicalRelationshipToPredicateValues(predicate1, predicate2, rule.logicalRelationship);

                fuzzyOutput[rule.consequent.output][rule.consequent.state] = value;


                unaggragatedFuzzyOuputs.Add(fuzzyOutput);
            }
        }
Ejemplo n.º 8
0
 private static float ValueIsNotRule(FuzzyInputData fuzzyInput, FuzzyRulesList.FuzzyAnticedent anticedent) => (!fuzzyInput[anticedent.input])[anticedent.state];
Ejemplo n.º 9
0
 private static float ValueIsNotRule(FuzzyInputData fuzzyInput, FuzzyPredicate predicate) => (!fuzzyInput[predicate.input])[predicate.state];