Ejemplo n.º 1
0
        public double Compute(InputValues inputs)
        {
            if (!KB.CheckIntegrity(out var outputvarname))
            {
                throw new ArgumentException("Invalid KnowledgeBase");
            }

            var aggregation = KB.First().Eval(inputs, Method);
            var rules       = KB.Skip(1);

            foreach (var rule in rules)
            {
                var ruleSet = rule.Eval(inputs, Method);
                aggregation = new FuzzySet(
                    AggregationMethod.Combine(
                        Method.AggregationOper,
                        aggregation.Membership,
                        ruleSet.Membership));
            }

            return(Defuzzification(aggregation, KB.GetVar(outputvarname).Universe));
        }
Ejemplo n.º 2
0
        public void Fire(List <Rule> rules)
        {
            Dictionary <string, List <double> > degrees = new Dictionary <string, List <double> >();

            for (int i = 0; i < mValues.Count; ++i)
            {
                degrees[mValues[i]] = new List <double>();
            }

            for (int i = 0; i < rules.Count; ++i)
            {
                Rule   rule       = rules[i];
                Clause consequent = rule.Consequent;
                if (consequent.Variable == this)
                {
                    double y = 1;

                    for (int j = 0; j < rule.AntecedentCount; ++j)
                    {
                        Clause     antecedent = rule.getAntecedent(j);
                        FuzzySet   variable   = antecedent.Variable;
                        string     value      = antecedent.Value;
                        Membership ms         = variable.GetMembership(value);
                        double     degree     = ms.degree(variable.X);
                        if (y > degree)
                        {
                            y = degree;
                        }
                    }
                    degrees[consequent.Value].Add(y);
                }
            }

            Dictionary <string, double> consequent_degrees = getRootSumSquare(degrees);

            mValX = getAreaCentroid(consequent_degrees);
        }
Ejemplo n.º 3
0
 internal SimplePredicate(string varName, FuzzySet fs)
 {
     this.varName = varName;
     this.fs      = fs;
 }
Ejemplo n.º 4
0
 public Clause(FuzzySet variable, String condition, String value)
 {
     mVariable  = variable;
     mValue     = value;
     mCondition = condition;
 }
Ejemplo n.º 5
0
 public void Infer(FuzzySet output)
 {
     output.Fire(mRules);
 }
Ejemplo n.º 6
0
 public void AddFuzzySet(string variable, FuzzySet set)
 {
     mVariables.Add(variable);
     mWorkingMemory[variable] = set;
 }