SetInput() public method

Sets a numerical input for one of the linguistic variables of the Database.
The variable indicated in /// was not found in the database.
public SetInput ( string variableName, float value ) : void
variableName string Name of the .
value float Numeric value to be used as input.
return void
Ejemplo n.º 1
0
        private byte Modify(InferenceSystem system, int[] windowData, byte center)
        {
            for (int i = 0; i < windowSize*windowSize - 1; i++)
            {
                system.SetInput(String.Format("IN{0}", i), windowData[i]);
            }

            int x = center + (byte) system.Evaluate("OUT");
            if (x < 0)
            {
                return 0;
            }

            if (x > 255)
            {
                return 255;
            }

            return (byte) x;
        }
        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;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List <double>             NumInputs  = new List <double>();
            List <LinguisticVariable> InputVars  = new List <LinguisticVariable>();
            List <LinguisticVariable> OutputVars = new List <LinguisticVariable>();
            List <string>             Rules      = new List <string>();

            if (!DA.GetDataList(0, NumInputs))
            {
                return;
            }
            if (!DA.GetDataList(1, InputVars))
            {
                return;
            }
            if (!DA.GetDataList(2, OutputVars))
            {
                return;
            }
            if (!DA.GetDataList(3, Rules))
            {
                return;
            }

            // creating the database
            Database fuzzyDB = new Database();

            foreach (object x in InputVars)
            {
                LinguisticVariable LV = (LinguisticVariable)x;
                fuzzyDB.AddVariable(LV);
            }
            foreach (object y in OutputVars)
            {
                LinguisticVariable LV = (LinguisticVariable)y;
                fuzzyDB.AddVariable(LV);
            }


            // creating the inference system
            AForge.Fuzzy.InferenceSystem InfrSys = new AForge.Fuzzy.InferenceSystem(fuzzyDB, new AForge.Fuzzy.CentroidDefuzzifier(1000));

            int C = Rules.Count;

            for (int i = 0; i <= C - 1; i++)
            {
                string ruleName = "Rule" + i;
                InfrSys.NewRule(ruleName, Rules[i]);
            }

            // Setting inputs
            int D = InputVars.Count;

            for (int j = 0; j <= D - 1; j++)
            {
                LinguisticVariable LV  = (LinguisticVariable)InputVars[j];
                double             val = NumInputs[j];
                InfrSys.SetInput(LV.Name, Convert.ToSingle(val));
            }

            DA.SetData(0, InfrSys);
        }