AForge.Fuzzy.InferenceSystem.NewRule C# (CSharp) Метод

NewRule() публичный Метод

Creates a new Rule and add it to the Rulebase of the InferenceSystem.
public NewRule ( string name, string rule ) : Rule
name string Name of the to create.
rule string A string representing the fuzzy rule.
Результат Rule
        public Rule NewRule( string name, string rule )
        {
            Rule r = new Rule( database, name, rule, normOperator, conormOperator );
            this.rulebase.AddRule( r );
            return r;
        }

Usage Example

        private async Task<InferenceSystem> InitFuzzyEngineDiagnosis(long[] symptomesId, long[] diagnosesId)
        {
            var fuzzyDB = new AForge.Fuzzy.Database();

            LinguisticVariable lv = new LinguisticVariable("Diagnosis", 0, diagnosesId.Count() * 100);

            fuzzyDB.AddVariable(lv);

            var diagnosesRepo = _unitOfWork.RepositoryAsync<Diagnosis>();

            var diagnosis = diagnosesRepo.Query(d => diagnosesId.Any(did => did == d.Id)).Select().Distinct().OrderBy(d => d.Id).ToList();

            var i = 0;
            foreach (var diagnoses in diagnosis)
            {
                i++;

                lv.AddLabel(new FuzzySet("Diagnosis" + i, new TrapezoidalFunction(
                (i-1) * 100, i * 100 - 50, i * 100 - 50, i * 100)));
                
                foreach(var s in diagnoses.Symptoms)
                {
                    LinguisticVariable lvs = new LinguisticVariable(s.Symptom.Name, 0, 100);
                    lvs.AddLabel(SymptomFuzzySet.Common);

                    try
                    {
                        fuzzyDB.AddVariable(lvs);
                    }
                    catch(Exception exc)
                    {

                    }
                }
            }

            var IS = new InferenceSystem(fuzzyDB, new CentroidDefuzzifier(1000));

            i = 0;
            foreach (var diagnoses in diagnosis)
            {
                i++;
                IS.NewRule(diagnoses.RuleName, diagnoses.Rule + i);
            }

            foreach (var diagnoses in diagnosis)
            {
                foreach (var s in diagnoses.Symptoms)
                {
                    if (!symptomesId.Any(sid => sid == s.SymptomId))
                    {
                        IS.SetInput(s.Symptom.Name, 1);
                    }
                }
            }

            return IS;
        }
All Usage Examples Of AForge.Fuzzy.InferenceSystem::NewRule