Exemple #1
0
        public double Defuzzificate( Rule[] rule )
        {
            double numerator = 0.0;
            double denominator = 0.0;

            for ( int i = 0; i < rule.Length; i++ )
            {
                numerator += GetOutputValue( rule[i].GetConclusion().Identifier ).CrispValue * rule[i].GetConclusion().Fulfillment;
                denominator += rule[i].GetConclusion().Fulfillment;
            }
            return ( denominator != 0.0 )? ( numerator / denominator ) : 0.0;
        }
        public Rule[] Infer( FuzzifiedValueContainer fuzzyContainer )
        {
            Rule[] result = new Rule[m_RuleBase.RuleCount()];
            m_RuleBase.ResetFulfillmentValues();

            for ( int i = 0; i < m_RuleBase.RuleCount(); i++ )
            {
                Rule currentRule = m_RuleBase.GetRule( i );
                for ( int j = 0; j < currentRule.ConditionCount(); j++ )
                {
                    RuleCondition currentCondition = currentRule.GetCondition( j );
                    FuzzifiedValue fuzzyVal = null;
                    if ( ( fuzzyVal = fuzzyContainer.Get( currentCondition.VariableName, currentCondition.TermName ) ) != null )
                        currentCondition.Fulfillment = fuzzyVal.FuzzyValue;
                    else
                        LogWriter.Write( "Error in rule " + i + " condition " + j );
                }
                currentRule.CalculateConclusionFulfillments();
                result[i] = currentRule;
            }
            return result;
        }
 public Rule RemoveRule( Rule rule )
 {
     for ( int i = 0; i < RuleCount(); i++ )
         if ( ( ( Rule )m_Rules[i] ).Equals( rule ) )
             return RemoveRule( i );
     return null;
 }
        public void AddRule( Rule rule )
        {
            for ( int i = 0; i < RuleCount(); i++ )
                if ( GetRule( i ).Equals( rule ) )
                    return;

            m_Rules.Add( rule );
        }
        public static void MakeReady( RuleBase ruleBase )
        {
            ruleBase.m_Rules.Clear();

            string line;
            char[] separator = {' ', '\t', '\n'};
            string[] tokens;
            string[] s = Rules.GetRules();
            for ( int i = 0; i < s.Length; i++ )
            {
                line = s[i].Trim();
                if ( line.Length > 0 && line[0] != ';' )
                {
                    Rule rule = new Rule();

                    tokens = line.Split( separator );
                    int idx = 0;
                    while ( !tokens[idx].Equals( "then" ) )
                    {
                        RuleCondition ruleCondition = new RuleCondition( tokens[idx+1], tokens[idx+3] );
                        rule.AddCondition( ruleCondition );
                        idx += 4;
                    }
                    RuleConclusion ruleConclusion = new RuleConclusion( tokens[idx+2] );
                    rule.SetConclusion( ruleConclusion );

                    ruleBase.AddRule( rule );
                }
            }
        }
 public void AddRule( Rule rule )
 {
     m_InferenceEngine.GetRuleBase().AddRule( rule );
 }
 public Rule RemoveRule( Rule rule )
 {
     return m_InferenceEngine.GetRuleBase().RemoveRule( rule );
 }