public LingVar(string name, int numTerms, float min, float max, float cross) { this.min = min; this.max = max; range = Math.Abs(max - min); float left, right, center; terms = new FuzzySet[numTerms]; lv = new LinguisticVariable(name, min, max); center = min + 0 * range / (numTerms - 1) * (1 / cross); right = min + (0 + 1) * range / (numTerms - 1) * (1 / cross); terms[0] = new FuzzySet(name + "-0", new TrapezoidalFunction(center, right, TrapezoidalFunction.EdgeType.Right)); lv.AddLabel(terms[0]); for (int i = 1; i < numTerms - 1; i++) { left = min + (i - 1) * range / (numTerms - 1) * (1 / cross); center = min + i * range / (numTerms - 1) * (1 / cross); right = min + (i + 1) * range / (numTerms - 1) * (1 / cross); terms[i] = new FuzzySet(name + "-" + i.ToString(), new TrapezoidalFunction(left, center, right)); lv.AddLabel(terms[i]); } left = min + (numTerms - 1 - 1) * range / (numTerms - 1) * (1 / cross); center = min + (numTerms - 1) * range / (numTerms - 1) * (1 / cross); terms[numTerms - 1] = new FuzzySet(name + "-" + (numTerms - 1).ToString(), new TrapezoidalFunction(left, center, TrapezoidalFunction.EdgeType.Left)); lv.AddLabel(terms[numTerms - 1]); }
public InferenceSystem SetupInferenceSystem(int width) { var mp = new TrapezoidalFunction(centerPoint - width / 2, centerPoint, centerPoint + width / 2); var mn = new TrapezoidalFunction(-centerPoint - width / 2, -centerPoint, -centerPoint + width / 2); var sp = new TrapezoidalFunction(-centerPoint / 2 + width / 4, (double)centerPoint / 2, centerPoint / 2 + width / 3); var sn = new TrapezoidalFunction(-centerPoint / 2 - width / 3, (double)-centerPoint / 2, centerPoint / 2 - width / 4); var ze = new TrapezoidalFunction(-(double)centerPoint / 4, 0, (double)centerPoint / 4); var mpSet = new FuzzySet("MP", mp); var mnSet = new FuzzySet("MN", mn); var spSet = new FuzzySet("SP", sp); var snSet = new FuzzySet("SN", sn); var zeSet = new FuzzySet("ZE", ze); var ruleDatabase = new Database(); for (int i = 0; i < windowSize * windowSize - 1; i++) { var variable = new LinguisticVariable(String.Format("IN{0}", i), -255, 255); variable.AddLabel(mpSet); variable.AddLabel(mnSet); ruleDatabase.AddVariable(variable); } var outVariable = new LinguisticVariable("OUT", -centerPoint - width / 2, centerPoint + width / 2); outVariable.AddLabel(spSet); outVariable.AddLabel(snSet); outVariable.AddLabel(zeSet); ruleDatabase.AddVariable(outVariable); var inferenceSystem = new InferenceSystem(ruleDatabase, new CentroidDefuzzifier(100)); string rule1 = "IF "; string rule2 = "IF "; string rule3 = "IF "; for (int i = 0; i < windowSize * windowSize - 1; i++) { rule1 += String.Format("IN{0} is MP and ", i); rule2 += String.Format("IN{0} is MN and ", i); rule3 += String.Format("IN{0} is not MP and IN{0} is not MN AND ", i); } rule1 = rule1.Remove(rule1.Length - 4, 4); rule2 = rule2.Remove(rule2.Length - 4, 4); rule3 = "IF NOT (" + rule1.Replace("IF", "") + ") AND NOT(" + rule2.Replace("IF", "") + ")"; rule1 += " then OUT is SN"; rule2 += " then OUT is SP"; rule3 += " then OUT is ZE"; inferenceSystem.NewRule("Rule1", rule1); inferenceSystem.NewRule("Rule2", rule2); inferenceSystem.NewRule("Rule3", rule3); return(inferenceSystem); }
// Testing basic funcionality of linguistic variables private void runLingVarTestButton_Click(object sender, EventArgs e) { ClearDataSeries( ); // create a linguistic variable to represent temperature LinguisticVariable lvTemperature = new LinguisticVariable("Temperature", 0, 80); // create the linguistic labels (fuzzy sets) that compose the temperature TrapezoidalFunction function1 = new TrapezoidalFunction(10, 15, TrapezoidalFunction.EdgeType.Right); FuzzySet fsCold = new FuzzySet("Cold", function1); TrapezoidalFunction function2 = new TrapezoidalFunction(10, 15, 20, 25); FuzzySet fsCool = new FuzzySet("Cool", function2); TrapezoidalFunction function3 = new TrapezoidalFunction(20, 25, 30, 35); FuzzySet fsWarm = new FuzzySet("Warm", function3); TrapezoidalFunction function4 = new TrapezoidalFunction(30, 35, TrapezoidalFunction.EdgeType.Left); FuzzySet fsHot = new FuzzySet("Hot", function4); // adding labels to the variable lvTemperature.AddLabel(fsCold); lvTemperature.AddLabel(fsCool); lvTemperature.AddLabel(fsWarm); lvTemperature.AddLabel(fsHot); // get membership of some points to the cool fuzzy set double[][,] chartValues = new double[4][, ]; for (int i = 0; i < 4; i++) { chartValues[i] = new double[160, 2]; } // showing the shape of the linguistic variable - the shape of its labels memberships from start to end int j = 0; for (float x = 0; x < 80; x += 0.5f, j++) { double y1 = lvTemperature.GetLabelMembership("Cold", x); double y2 = lvTemperature.GetLabelMembership("Cool", x); double y3 = lvTemperature.GetLabelMembership("Warm", x); double y4 = lvTemperature.GetLabelMembership("Hot", x); chartValues[0][j, 0] = x; chartValues[0][j, 1] = y1; chartValues[1][j, 0] = x; chartValues[1][j, 1] = y2; chartValues[2][j, 0] = x; chartValues[2][j, 1] = y3; chartValues[3][j, 0] = x; chartValues[3][j, 1] = y4; } // plot membership to a chart chart.UpdateDataSeries("COLD", chartValues[0]); chart.UpdateDataSeries("COOL", chartValues[1]); chart.UpdateDataSeries("WARM", chartValues[2]); chart.UpdateDataSeries("HOT", chartValues[3]); }
private void SetSpeedFuzzySets() { fsSlow = new FuzzySet("Slow", new TrapezoidalFunction(30, 50, TrapezoidalFunction.EdgeType.Right)); fsMedium = new FuzzySet("Medium", new TrapezoidalFunction(30, 50, 80, 100)); fsFast = new FuzzySet("Fast", new TrapezoidalFunction(80, 100, TrapezoidalFunction.EdgeType.Left)); lvSpeed = new LinguisticVariable("Speed", 0, 100); lvSpeed.AddLabel(fsSlow); lvSpeed.AddLabel(fsMedium); lvSpeed.AddLabel(fsFast); }
private void SetDistanceFuzzySets() { fsNear = new FuzzySet("Near", new TrapezoidalFunction(20, 40, TrapezoidalFunction.EdgeType.Right)); fsMedi = new FuzzySet("Medi", new TrapezoidalFunction(20, 40, 50, 70)); fsFar = new FuzzySet("Far", new TrapezoidalFunction(50, 70, TrapezoidalFunction.EdgeType.Left)); lvDistance = new LinguisticVariable("Distance", 0, 100); lvDistance.AddLabel(fsNear); lvDistance.AddLabel(fsMedi); lvDistance.AddLabel(fsFar); }
private void SpeedFuzzySets() { fsSlow = new FuzzySet("Slow", new TrapezoidalFunction(5, 7, TrapezoidalFunction.EdgeType.Right)); fsMedium = new FuzzySet("Medium", new TrapezoidalFunction(5, 7, 10, 15)); fsFast = new FuzzySet("Fast", new TrapezoidalFunction(15, 20, TrapezoidalFunction.EdgeType.Left)); linSpeed = new LinguisticVariable("Speed", 0, 120); linSpeed.AddLabel(fsSlow); linSpeed.AddLabel(fsMedium); linSpeed.AddLabel(fsFast); }
private void DistanceFuzzySets() { fsNear = new FuzzySet("Near", new TrapezoidalFunction(0, 10, TrapezoidalFunction.EdgeType.Right)); fsMed = new FuzzySet("Med", new TrapezoidalFunction(0, 10, 15, 20)); fsFar = new FuzzySet("Far", new TrapezoidalFunction(20, 30, TrapezoidalFunction.EdgeType.Left)); linDistance = new LinguisticVariable("Distance", 0, 100); linDistance.AddLabel(fsNear); linDistance.AddLabel(fsMed); linDistance.AddLabel(fsFar); }
private void SetDistanceFuzzySets() { fsNear = new FuzzySet("Near", new TrapezoidalFunction(1, 3, TrapezoidalFunction.EdgeType.Right)); fsMed = new FuzzySet("Med", new TrapezoidalFunction(1, 3, 5, 7)); fsFar = new FuzzySet("Far", new TrapezoidalFunction(5, 7, TrapezoidalFunction.EdgeType.Left)); lvDistance = new LinguisticVariable("Distance", 0, 10); lvDistance.AddLabel(fsNear); lvDistance.AddLabel(fsMed); lvDistance.AddLabel(fsFar); }
private void SetDistanceFuzzySets() { Near = new FuzzySet("Near", new TrapezoidalFunction(5, 6, TrapezoidalFunction.EdgeType.Right)); Med = new FuzzySet("Med", new TrapezoidalFunction(6, 7, 8, 10)); Far = new FuzzySet("Far", new TrapezoidalFunction(13, 50, TrapezoidalFunction.EdgeType.Left)); lv_Distance = new LinguisticVariable("Distance", 0, 50); lv_Distance.AddLabel(Near); lv_Distance.AddLabel(Med); lv_Distance.AddLabel(Far); }
private void SetSpeedFuzzySets() { fsSlow = new FuzzySet("Slow", new TrapezoidalFunction(slowAC.keys[0].time, slowAC.keys[1].time, TrapezoidalFunction.EdgeType.Right)); fsMedium = new FuzzySet("Medium", new TrapezoidalFunction(mediumAC.keys[0].time, mediumAC.keys[1].time, mediumAC.keys[2].time, mediumAC.keys[3].time)); fsFast = new FuzzySet("Fast", new TrapezoidalFunction(fastAC.keys[0].time, fastAC.keys[1].time, TrapezoidalFunction.EdgeType.Left)); lvSpeed = new LinguisticVariable("Speed", 0, 120); lvSpeed.AddLabel(fsSlow); lvSpeed.AddLabel(fsMedium); lvSpeed.AddLabel(fsFast); }
private void SetSpeedFuzzySets() { Slow = new FuzzySet("Slow", new TrapezoidalFunction(4, 5, TrapezoidalFunction.EdgeType.Right)); Medium = new FuzzySet("Medium", new TrapezoidalFunction(4, 5, 8, 10)); Fast = new FuzzySet("Fast", new TrapezoidalFunction(8, 10, TrapezoidalFunction.EdgeType.Left)); lvSpeed = new LinguisticVariable("Speed", 0, 10); lvSpeed.AddLabel(Slow); lvSpeed.AddLabel(Medium); lvSpeed.AddLabel(Fast); }
private void SetDistanceFuzzySets() { fsNear = new FuzzySet("Near", new TrapezoidalFunction(nearAC.keys[0].time, nearAC.keys[1].time, TrapezoidalFunction.EdgeType.Right)); fsMed = new FuzzySet("Med", new TrapezoidalFunction(medAC.keys[0].time, medAC.keys[1].time, medAC.keys[2].time, medAC.keys[3].time)); fsFar = new FuzzySet("Far", new TrapezoidalFunction(farAC.keys[0].time, farAC.keys[1].time, TrapezoidalFunction.EdgeType.Left)); lvDistance = new LinguisticVariable("Distance", 0, 100); lvDistance.AddLabel(fsNear); lvDistance.AddLabel(fsMed); lvDistance.AddLabel(fsFar); }
private LinguisticVariable GetDistanceVariable() { FuzzySet distanceNear = new FuzzySet("Near", new TrapezoidalFunction(0, 0, 15, 22)); FuzzySet distanceFair = new FuzzySet("Fair", new TrapezoidalFunction(20, 30, 40)); LinguisticVariable lvDistance = new LinguisticVariable("Distance", 0, 40); lvDistance.AddLabel(distanceNear); lvDistance.AddLabel(distanceFair); return(lvDistance); }
public LinguisticVariable LinguistictDistance() { LinguisticVariable lDistance = new LinguisticVariable("Distance", 0, 500000); FuzzySet fsFaible = new FuzzySet("Faible", new TrapezoidalFunction(30, 50, 500000, 0, TrapezoidalFunction.EdgeType.Right)); FuzzySet fsMoyenne = new FuzzySet("Moyenne", new TrapezoidalFunction(40, 50, 100, 150)); FuzzySet fsGrande = new FuzzySet("Grande", new TrapezoidalFunction(100, 150, 500000, 0, TrapezoidalFunction.EdgeType.Left)); lDistance.AddLabel(fsFaible); lDistance.AddLabel(fsMoyenne); lDistance.AddLabel(fsGrande); return(lDistance); }
private LinguisticVariable LinguisticZoom() { LinguisticVariable lZ = new LinguisticVariable("Zoom", 1, 5); FuzzySet fsPetit = new FuzzySet("Petit", new TrapezoidalFunction(1, 2, TrapezoidalFunction.EdgeType.Right)); FuzzySet fsNormal = new FuzzySet("Normal", new TrapezoidalFunction(1, 2, 3, 4)); FuzzySet fsGros = new FuzzySet("Gros", new TrapezoidalFunction(3, 4, TrapezoidalFunction.EdgeType.Left)); lZ.AddLabel(fsPetit); lZ.AddLabel(fsNormal); lZ.AddLabel(fsGros); return(lZ); }
public LinguisticVariable LinguisticVitesse() { LinguisticVariable lV = new LinguisticVariable("Vitesse", 0, 200); FuzzySet fsLente = new FuzzySet("Lente", new TrapezoidalFunction(20, 30, 200, 0, TrapezoidalFunction.EdgeType.Right)); FuzzySet fsPeuRapide = new FuzzySet("PeuRapide", new TrapezoidalFunction(20, 30, 70, 80)); FuzzySet fsRapide = new FuzzySet("Rapide", new TrapezoidalFunction(70, 80, 90, 110)); FuzzySet fsTresRapide = new FuzzySet("TresRapide", new TrapezoidalFunction(90, 110, 200, 0, TrapezoidalFunction.EdgeType.Left)); lV.AddLabel(fsLente); lV.AddLabel(fsPeuRapide); lV.AddLabel(fsRapide); lV.AddLabel(fsTresRapide); return(lV); }
private LinguisticVariable GetDepthVariable(string depthType) { FuzzySet shallowDepth = new FuzzySet("Shallow", new TrapezoidalFunction(0, 2, 8, 10.5f)); FuzzySet fairlyDepth = new FuzzySet("Fairly", new TrapezoidalFunction(9.5f, 12, 18, 20.5f)); FuzzySet deepDepth = new FuzzySet("Deep", new TrapezoidalFunction(19.5f, 25, 35, 40.5f)); FuzzySet veryDeepDepth = new FuzzySet("VeryDeep", new TrapezoidalFunction(35, 40, float.MaxValue, float.MaxValue)); LinguisticVariable lvDepth = new LinguisticVariable(depthType, 0, float.MaxValue); lvDepth.AddLabel(shallowDepth); lvDepth.AddLabel(fairlyDepth); lvDepth.AddLabel(deepDepth); lvDepth.AddLabel(veryDeepDepth); return(lvDepth); }
private void SetUpFisII() { //Input var impact = new LinguisticVariable("Impact", 0, 100); new List <FuzzySet>() { new FuzzySet("Low", new TrapezoidalFunction(0, 5, 25, 30)), new FuzzySet("Medium", new TrapezoidalFunction(20, 25, 55, 60)), new FuzzySet("High", new TrapezoidalFunction(50, 55, 95, 100)) }.ForEach(x => impact.AddLabel(x)); var onGround = new LinguisticVariable("On_ground", -0.5f, 1.5f); new List <FuzzySet>() { new FuzzySet("Low", new TrapezoidalFunction(-0.5f, -0.2f, 0.2f, 0.5f)), new FuzzySet("Medium", new TrapezoidalFunction(0.1f, 0.5f, 0.5f, 0.9f)), new FuzzySet("High", new TrapezoidalFunction(0.5f, 0.8f, 1.2f, 1.5f)) }.ForEach(x => onGround.AddLabel(x)); var timeOnGround = new LinguisticVariable("Time_on_ground", -1, 901); new List <FuzzySet>() { new FuzzySet("Brief", new TrapezoidalFunction(-1, 1, 1, 2)), new FuzzySet("Short", new TrapezoidalFunction(1, 5, 10, 15)), new FuzzySet("Moderate", new TrapezoidalFunction(10, 120, 480, 720)), new FuzzySet("Long", new TrapezoidalFunction(480, 900, 900, 901)) }.ForEach(x => timeOnGround.AddLabel(x)); //Output var fallWearable = new LinguisticVariable("Fall_wearable", -0.5f, 1.5f); new List <FuzzySet>() { new FuzzySet("Low", new TrapezoidalFunction(-0.5f, -0.2f, 0.2f, 0.5f)), new FuzzySet("Medium", new TrapezoidalFunction(0.1f, 0.5f, 0.5f, 0.9f)), new FuzzySet("High", new TrapezoidalFunction(0.5f, 0.8f, 1.2f, 1.5f)) }.ForEach(x => fallWearable.AddLabel(x)); var db = new Database(); db.AddVariable(impact); db.AddVariable(onGround); db.AddVariable(timeOnGround); db.AddVariable(fallWearable); fisII = new InferenceSystem(db, new CentroidDefuzzifier(1000)); fisII.NewRule("Rule 1", "IF Impact IS High AND On_ground IS High AND Time_on_ground IS Long THEN Fall_wearable IS High"); fisII.NewRule("Rule 2", "IF Impact IS Medium AND On_ground IS High AND Time_on_ground IS Long THEN Fall_wearable IS High"); fisII.NewRule("Rule 3", "IF Impact IS Low AND On_ground IS Low AND (Time_on_ground IS Short OR Time_on_ground IS Brief) THEN Fall_wearable IS Low"); fisII.NewRule("Rule 4", "IF Impact IS Medium AND On_ground IS Medium AND Time_on_ground IS Moderate THEN Fall_wearable IS Medium"); fisII.NewRule("Rule 5", "IF Impact IS High AND On_ground IS Medium AND (Time_on_ground IS Short OR Time_on_ground IS Brief) THEN Fall_wearable IS Medium"); }
private void SetUpFisI() { //Input var treshhold = new LinguisticVariable("Threshold", 0, 100); new List <FuzzySet>() { new FuzzySet("Low", new TrapezoidalFunction(0, 5, 25, 30)), new FuzzySet("Medium", new TrapezoidalFunction(20, 25, 55, 60)), new FuzzySet("High", new TrapezoidalFunction(50, 55, 95, 100)) }.ForEach(x => treshhold.AddLabel(x)); //Output var impact = new LinguisticVariable("Impact", 0, 100); new List <FuzzySet>() { new FuzzySet("Low", new TrapezoidalFunction(0, 5, 25, 30)), new FuzzySet("Medium", new TrapezoidalFunction(20, 25, 55, 60)), new FuzzySet("High", new TrapezoidalFunction(50, 55, 95, 100)) }.ForEach(x => impact.AddLabel(x)); var db = new Database(); db.AddVariable(treshhold); db.AddVariable(impact); fisI = new InferenceSystem(db, new CentroidDefuzzifier(1000)); fisI.NewRule("Rule 1", "IF Threshold IS Low THEN Impact IS Low"); fisI.NewRule("Rule 2", "IF Threshold IS Medium THEN Impact IS Medium"); fisI.NewRule("Rule 3", "IF Threshold IS High THEN Impact IS High"); }
private LinguisticVariable GetSeismicityVariable(string seismicityType) { FuzzySet lowEnv = new FuzzySet("Low", new TrapezoidalFunction(1, 2.5f, 2.5f, 4.2f)); FuzzySet mediumEnv = new FuzzySet("Medium", new TrapezoidalFunction(3.8f, 4.5f, 4.5f, 5.2f)); FuzzySet strongEnv = new FuzzySet("Strong", new TrapezoidalFunction(4.8f, 6.5f, 6.5f, 9.2f)); FuzzySet greatEnv = new FuzzySet("Great", new TrapezoidalFunction(8.8f, 10.5f, 12, 12)); LinguisticVariable lvSeismicEnv = new LinguisticVariable(seismicityType, 1, 12); lvSeismicEnv.AddLabel(lowEnv); lvSeismicEnv.AddLabel(mediumEnv); lvSeismicEnv.AddLabel(strongEnv); lvSeismicEnv.AddLabel(greatEnv); return(lvSeismicEnv); }
private void Initialize() { _fVariable = new LinguisticVariable(Name, _range.Min, _range.Max); foreach (FuzzySet label in _sets) { _fVariable.AddLabel(label); } _chartArea = _chart.ChartAreas[0]; _chartArea.AxisY.Maximum = 1; _chartArea.AxisY.Minimum = 0; _chartArea.AxisX.LabelStyle.Format = "{0}"; _chartArea.AxisX.LabelStyle.Interval = 2; _chartArea.AxisY.LabelStyle.Format = "{0.0}"; _chartArea.AxisY.LabelStyle.Interval = 0.5; //_chart = System.Windows.Forms.DockStyle.Bottom; _chart.Legends.ToList().ForEach(x => x.Docking = Docking.Bottom); if (Type == VariableType.Input) { InitialSelectLine(); } }
/// <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) { string Name = null; Interval Interval = new Interval(); List <FuzzySet> fSets = new List <FuzzySet>(); if (!DA.GetData(0, ref Name)) { return; } if (!DA.GetData(1, ref Interval)) { return; } if (!DA.GetDataList(2, fSets)) { return; } LinguisticVariable lingVar = new LinguisticVariable(Name, (float)Interval.Min, (float)Interval.Max); foreach (object x in fSets) { FuzzySet func = (FuzzySet)x; lingVar.AddLabel(func); } DA.SetData(0, lingVar); }
public void SetFuzzyValues(float f1_1, float f2_1, float f1_X, float f2_X, float f3_X, float f4_X, float f1_2, float f2_2) { _lvlProbabilidad.ClearLabels(); _fsUno = new FuzzySet("UNO", new TrapezoidalFunction(f1_1, f2_1, TrapezoidalFunction.EdgeType.Left)); _fsEquis = new FuzzySet("EQUIS", new TrapezoidalFunction(f1_X, f2_X, f3_X, f4_X)); _fsDos = new FuzzySet("DOS", new TrapezoidalFunction(f1_2, f2_2, TrapezoidalFunction.EdgeType.Right)); Log.Info($"Setting Function for '2' with values 0 - {f1_2} - {f2_2}"); Log.Info($"Setting Function for 'X' with values {f1_X} - {f2_X} - {f3_X} - {f4_X}"); Log.Info($"Setting Function for '1' with values {f1_1} - {f2_1} - 100"); _lvlProbabilidad.AddLabel(_fsUno); _lvlProbabilidad.AddLabel(_fsDos); _lvlProbabilidad.AddLabel(_fsEquis); IsSet = true; }
private InferenceSystem SetupInferenceSystem(byte minLuma, byte maxLuma, byte meanLuma) { var lumaIn = new LinguisticVariable("LumaIn", minLuma, maxLuma); var lumaOut = new LinguisticVariable("LumaOut", 0, 255); var darkFunction = new TrapezoidalFunction(minLuma, meanLuma, TrapezoidalFunction.EdgeType.Right); var darkSet = new FuzzySet("Dark", darkFunction); var mediumFunction = new TrapezoidalFunction(minLuma, meanLuma, maxLuma); var mediumSet = new FuzzySet("Medium", mediumFunction); var lightFunction = new TrapezoidalFunction(meanLuma, maxLuma, TrapezoidalFunction.EdgeType.Left); var lightSet = new FuzzySet("Light", lightFunction); lumaIn.AddLabel(darkSet); lumaIn.AddLabel(mediumSet); lumaIn.AddLabel(lightSet); var whiteFunction = new SingletonFunction(255); var whiteSet = new FuzzySet("White", whiteFunction); var blackFunction = new SingletonFunction(0); var blackSet = new FuzzySet("Black", blackFunction); var grayFunction = new SingletonFunction(128); var graySet = new FuzzySet("Gray", grayFunction); lumaOut.AddLabel(blackSet); lumaOut.AddLabel(graySet); lumaOut.AddLabel(whiteSet); var database = new Database(); database.AddVariable(lumaIn); database.AddVariable(lumaOut); var inferenceSystem = new InferenceSystem(database, new CogDefuzzifier()); inferenceSystem.NewRule("Rule 1", "IF LumaIn IS Dark THEN LumaOut is Black"); inferenceSystem.NewRule("Rule 2", "IF LumaIn IS Medium THEN LumaOut is Gray"); inferenceSystem.NewRule("Rule 3", "IF LumaIn IS Light THEN LumaOut is White"); return(inferenceSystem); }
public static LinguisticVariable CreateVariable(string name, float start, float end, params FuzzySet[] labels) { LinguisticVariable lv = new LinguisticVariable(name, start, end); for (int i = 0; i < labels.Length; i++) { lv.AddLabel(labels[i]); } return(lv); }
private LinguisticVariable GetConcentrationVariable(string period, DateTime dateFrom, DateTime dateTo) { var offset = dateTo - dateFrom; int days = offset.Days; float bigPercent = 0.04f; float mediumPercent = 0.02f; float smallPercent = 0.01f; FuzzySet smallConcentration = new FuzzySet("Small", new TrapezoidalFunction(0, 0, smallPercent * days, mediumPercent * days)); FuzzySet mediumConcentration = new FuzzySet("Medium", new TrapezoidalFunction(smallPercent * days, mediumPercent * days, bigPercent * days)); FuzzySet bigConcentration = new FuzzySet("Big", new TrapezoidalFunction(mediumPercent * days, bigPercent * days, TrapezoidalFunction.EdgeType.Left)); LinguisticVariable lvConcentration = new LinguisticVariable(period, 0, float.MaxValue); lvConcentration.AddLabel(smallConcentration); lvConcentration.AddLabel(mediumConcentration); lvConcentration.AddLabel(bigConcentration); return(lvConcentration); }
private void SetLinguisticVariable() //ustawia zmienne lingwistyczne { airOutTemperature = new LinguisticVariable("AirOutTemperature", -20, 40); airOutTemperature.AddLabel(tmpColdOut); airOutTemperature.AddLabel(tmpHotOut); airTemperature = new LinguisticVariable("AirTemperature", 0, 40); airTemperature.AddLabel(tmpVeryCold); airTemperature.AddLabel(tmpCold); airTemperature.AddLabel(tmpMedium); airTemperature.AddLabel(tmpHot); airTemperature.AddLabel(tmpVeryHot); Humidity = new LinguisticVariable("Humidity", 0, 100); Humidity.AddLabel(smallHumidity); Humidity.AddLabel(goodHumidity); Humidity.AddLabel(bigHumidity); HumidityOut = new LinguisticVariable("HumidityOut", 0, 100); HumidityOut.AddLabel(smallHumidity); HumidityOut.AddLabel(goodHumidity); HumidityOut.AddLabel(bigHumidity); desiredTemperature = new LinguisticVariable("DesiredTemperature", 0, 40); desiredTemperature.AddLabel(tmpVeryCold); desiredTemperature.AddLabel(tmpCold); desiredTemperature.AddLabel(tmpMedium); desiredTemperature.AddLabel(tmpHot); desiredTemperature.AddLabel(tmpVeryHot); FunTemperature = new LinguisticVariable("FunTemperature", 0, 40); FunTemperature.AddLabel(tmpVeryCold); FunTemperature.AddLabel(tmpCold); FunTemperature.AddLabel(tmpMedium); FunTemperature.AddLabel(tmpHot); FunTemperature.AddLabel(tmpVeryHot); FunStrenght = new LinguisticVariable("FunStrenght", 0, 100); FunStrenght.AddLabel(veryLowStrenght); FunStrenght.AddLabel(lowStrenght); FunStrenght.AddLabel(mediumStrenght); FunStrenght.AddLabel(hightStrenght); FunStrenght.AddLabel(veryHightStrenght); }
public LingVar(int number, string name, float min, float max, Scope[] scopes, int[] d) { this.min = min; this.max = max; range = Math.Abs(max - min); terms = new FuzzySet[d.Length]; lv = new LinguisticVariable(name, min, max); for (int i = 0; i < terms.Length; i++) { terms[i] = new FuzzySet(name + d[i].ToString(), new TrapezoidalFunction( (float)scopes[d[i]].min[number], (float)scopes[d[i]].center[number], (float)scopes[d[i]].max[number]) ); lv.AddLabel(terms[i]); } }
private LinguisticVariable GetMagnitudeVariable(string magType) { FuzzySet microMagnitude = new FuzzySet("Micro", new TrapezoidalFunction(0, 1, 1, 2.2f)); FuzzySet minorMagnitude = new FuzzySet("Minor", new TrapezoidalFunction(1.8f, 3, 3, 4.2f)); FuzzySet lightMagnitude = new FuzzySet("Light", new TrapezoidalFunction(3.8f, 4.5f, 4.5f, 5.2f)); FuzzySet moderateMagnitude = new FuzzySet("Moderate", new TrapezoidalFunction(4.8f, 5.5f, 5.5f, 6.2f)); FuzzySet strongMagnitude = new FuzzySet("Strong", new TrapezoidalFunction(5.8f, 6.5f, 6.5f, 7.2f)); FuzzySet majorMagnitude = new FuzzySet("Major", new TrapezoidalFunction(6.8f, 7.5f, 7.5f, 8.2f)); FuzzySet greatMagnitude = new FuzzySet("Great", new TrapezoidalFunction(7.8f, 8, 12, 12)); LinguisticVariable lvMagnitude = new LinguisticVariable(magType, 0, 12); lvMagnitude.AddLabel(microMagnitude); lvMagnitude.AddLabel(minorMagnitude); lvMagnitude.AddLabel(lightMagnitude); lvMagnitude.AddLabel(moderateMagnitude); lvMagnitude.AddLabel(strongMagnitude); lvMagnitude.AddLabel(majorMagnitude); lvMagnitude.AddLabel(greatMagnitude); return(lvMagnitude); }
// Hardcode initializing the Fuzzy Inference System void InitFuzzyEngine( ) { // Linguistic labels (fuzzy sets) that compose the distances FuzzySet fsNear = new FuzzySet("Near", new TrapezoidalFunction(15, 50, TrapezoidalFunction.EdgeType.Right)); FuzzySet fsMedium = new FuzzySet("Medium", new TrapezoidalFunction(15, 50, 60, 100)); FuzzySet fsFar = new FuzzySet("Far", new TrapezoidalFunction(60, 100, TrapezoidalFunction.EdgeType.Left)); // Right Distance (Input) LinguisticVariable lvRight = new LinguisticVariable("RightDistance", 0, 120); lvRight.AddLabel(fsNear); lvRight.AddLabel(fsMedium); lvRight.AddLabel(fsFar); // Left Distance (Input) LinguisticVariable lvLeft = new LinguisticVariable("LeftDistance", 0, 120); lvLeft.AddLabel(fsNear); lvLeft.AddLabel(fsMedium); lvLeft.AddLabel(fsFar); // Front Distance (Input) LinguisticVariable lvFront = new LinguisticVariable("FrontalDistance", 0, 120); lvFront.AddLabel(fsNear); lvFront.AddLabel(fsMedium); lvFront.AddLabel(fsFar); // Linguistic labels (fuzzy sets) that compose the angle FuzzySet fsVN = new FuzzySet("VeryNegative", new TrapezoidalFunction(-40, -35, TrapezoidalFunction.EdgeType.Right)); FuzzySet fsN = new FuzzySet("Negative", new TrapezoidalFunction(-40, -35, -25, -20)); FuzzySet fsLN = new FuzzySet("LittleNegative", new TrapezoidalFunction(-25, -20, -10, -5)); FuzzySet fsZero = new FuzzySet("Zero", new TrapezoidalFunction(-10, 5, 5, 10)); FuzzySet fsLP = new FuzzySet("LittlePositive", new TrapezoidalFunction(5, 10, 20, 25)); FuzzySet fsP = new FuzzySet("Positive", new TrapezoidalFunction(20, 25, 35, 40)); FuzzySet fsVP = new FuzzySet("VeryPositive", new TrapezoidalFunction(35, 40, TrapezoidalFunction.EdgeType.Left)); // Angle LinguisticVariable lvAngle = new LinguisticVariable("Angle", -50, 50); lvAngle.AddLabel(fsVN); lvAngle.AddLabel(fsN); lvAngle.AddLabel(fsLN); lvAngle.AddLabel(fsZero); lvAngle.AddLabel(fsLP); lvAngle.AddLabel(fsP); lvAngle.AddLabel(fsVP); // The database Database fuzzyDB = new Database( ); fuzzyDB.AddVariable(lvFront); fuzzyDB.AddVariable(lvLeft); fuzzyDB.AddVariable(lvRight); fuzzyDB.AddVariable(lvAngle); // Creating the inference system IS = new InferenceSystem(fuzzyDB, new CentroidDefuzzifier(1000)); // Going Straight IS.NewRule("Rule 1", "IF FrontalDistance IS Far THEN Angle IS Zero"); // Going Straight (if can go anywhere) IS.NewRule("Rule 2", "IF FrontalDistance IS Far AND RightDistance IS Far AND LeftDistance IS Far THEN Angle IS Zero"); // Near right wall IS.NewRule("Rule 3", "IF RightDistance IS Near AND LeftDistance IS Not Near THEN Angle IS LittleNegative"); // Near left wall IS.NewRule("Rule 4", "IF RightDistance IS Not Near AND LeftDistance IS Near THEN Angle IS LittlePositive"); // Near front wall - room at right IS.NewRule("Rule 5", "IF RightDistance IS Far AND FrontalDistance IS Near THEN Angle IS Positive"); // Near front wall - room at left IS.NewRule("Rule 6", "IF LeftDistance IS Far AND FrontalDistance IS Near THEN Angle IS Negative"); // Near front wall - room at both sides - go right IS.NewRule("Rule 7", "IF RightDistance IS Far AND LeftDistance IS Far AND FrontalDistance IS Near THEN Angle IS Positive"); }