/// <summary> /// Creates a new Trapezoid fuzzy set. /// </summary> /// <param name="parentVar">the ContinuousFuzzyRuleVariable object that is the parent</param> /// <param name="name">the String object that contains the name</param> /// <param name="alphaCut">the double value for the alpha cut</param> /// <param name="ptLeft">the double value of the beginning point of the fuzzy set</param> /// <param name="ptLeftCore">the double value of the beginning point of the plateau</param> /// <param name="ptLeftCore">the double value of the end point of the plateau</param> /// <param name="ptRight">the double value of the end point of the fuzzy set</param> internal TrapezoidFuzzySet(ContinuousFuzzyRuleVariable parentVar, string name, double alphaCut, double ptLeft, double ptLeftCore, double ptRightCore, double ptRight) : base(EnumFuzzySetType.Trapezoid, name, parentVar, alphaCut) { // Save the original parameters this.mdPointLeft = ptLeft; this.mdPointLeftCore = ptLeftCore; this.mdPointRightCore = ptRightCore; this.mdPointRight = ptRight; // Set the domain values in the base class! mdDomainLo = parentVar.DiscourseLo; mdDomainHi = parentVar.DiscourseHi; // Working variables int numberOfValues = 6; double[] lclScalarVector = new double[7]; double[] lclTruthVector = new double[7]; // Set up the vectors for a trapezoid: lclScalarVector[0] = mdDomainLo; lclTruthVector[0] = 0.0; lclScalarVector[1] = ptLeft; lclTruthVector[1] = 0.0; lclScalarVector[2] = ptLeftCore; lclTruthVector[2] = 1.0; lclScalarVector[3] = ptRightCore; lclTruthVector[3] = 1.0; lclScalarVector[4] = ptRight; lclTruthVector[4] = 0.0; lclScalarVector[5] = mdDomainHi; lclTruthVector[5] = 0.0; // Fill in the truth vector for this set: SegmentCurve(numberOfValues, lclScalarVector, lclTruthVector); }
protected internal string msSetName; // Set name #endregion Fields #region Constructors /// <summary> /// Create a new Fuzzy Set /// </summary> /// <param name="setType"></param> /// <param name="setName"></param> /// <param name="parentVar"></param> /// <param name="alphaCut"></param> /// <param name="domainLo"></param> /// <param name="domainHi"></param> protected internal FuzzySet(EnumFuzzySetType setType, string setName, ContinuousFuzzyRuleVariable parentVar, double alphaCut, double domainLo, double domainHi) { meSetType = setType; msSetName = setName; moParentVar = parentVar; mdAlphaCut = alphaCut; mdDomainLo = domainLo; mdDomainHi = domainHi; mdTruthVector = new double[Constants.FUZZY_MAXVALUES]; for (int i = 0; i < Constants.FUZZY_MAXVALUES; i++) { mdTruthVector[i] = 0.0; } }
private EnumFuzzySetDirection meSetDir; // Left or Right #endregion Fields #region Constructors /// <summary> /// Creates a new Shoulder fuzzy set. /// </summary> /// <param name="parentVar">the ContinuousFuzzyRuleVariable object that is the parent</param> /// <param name="name">the String object that contains the name</param> /// <param name="alphaCut">the double value for the alpha cut</param> /// <param name="ptBeg">the double value of the beginning point of the fuzzy set</param> /// <param name="ptEnd">the double value of the end point of the fuzzy set</param> /// <param name="setDirection">the integer that represents the direction of the shoulder</param> internal ShoulderFuzzySet(ContinuousFuzzyRuleVariable parentVar, string name, double alphaCut, double ptBeg, double ptEnd, EnumFuzzySetDirection setDirection) : base(EnumFuzzySetType.Shoulder, name, parentVar, alphaCut) { // Save the original parameters this.mdPointBegin = ptBeg; this.mdPointEnd = ptEnd; this.meSetDir = setDirection; // Set the domain values in the base class! mdDomainLo = parentVar.DiscourseLo; mdDomainHi = parentVar.DiscourseHi; // Working variables int numberOfValues = 4; double[] lclScalarVector = new double[5]; double[] lclTruthVector = new double[5]; // Set up the vectors for a shoulder if (setDirection == EnumFuzzySetDirection.Left) { lclScalarVector[0] = mdDomainLo; lclTruthVector[0] = 1.0; lclScalarVector[1] = ptBeg; lclTruthVector[1] = 1.0; lclScalarVector[2] = ptEnd; lclTruthVector[2] = 0.0; lclScalarVector[3] = mdDomainHi; lclTruthVector[3] = 0.0; } else { lclScalarVector[0] = mdDomainLo; lclTruthVector[0] = 0.0; lclScalarVector[1] = ptBeg; lclTruthVector[1] = 0.0; lclScalarVector[2] = ptEnd; lclTruthVector[2] = 1.0; lclScalarVector[3] = mdDomainHi; lclTruthVector[3] = 1.0; } // Fill in the truth vector for this set: SegmentCurve(numberOfValues, lclScalarVector, lclTruthVector); }
/// <summary> /// Get the FuzzySet based on the hedges /// </summary> /// <param name="lhs">Left Hand Side</param> /// <param name="setName">The Set Name that contains the Right Hand Side</param> /// <param name="hedges">The Hedge Name that contains the list of hedges</param> /// <returns></returns> private FuzzySet GetFuzzySet(ContinuousFuzzyRuleVariable lhs, string setName, string hedges) { FuzzySet rhs = null; string sValue = setName.Trim(); string tmpHedges = hedges.Trim(); // The value on the Rhs represents a fuzzy set name; // The named set must exist. if (lhs.SetExist(sValue)) { if (tmpHedges.Length == 0) { rhs = lhs.GetSet(sValue); } else { rhs = lhs.GetOrAddHedgedSet(sValue, tmpHedges); } } else { Console.Out.WriteLine("Error: Invalid fuzzy set name " + sValue); } return rhs; }
/// <summary> /// Crate the Clause /// </summary> /// <param name="lhs">Left Hand Side</param> /// <param name="oper">Operator</param> /// <param name="hedges">Hedges</param> /// <param name="setName">Set Name</param> /// <returns>FuzzyClause</returns> public FuzzyClause CreateClause(ContinuousFuzzyRuleVariable lhs, EnumFuzzyOperator oper, string hedges, string setName) { // Retrieve the fuzzy set object based on hedges and setName FuzzySet rhs = GetFuzzySet(lhs, setName, hedges); // Create a clause to place into a rule. FuzzyClause clause = new FuzzyClause(lhs, oper, rhs); return clause; }
/// <summary> /// Creates a fuzzy work set with the given parameters. /// </summary> /// <param name="parentVar">the ContinuousFuzzyRuleVariable object that is the parent /// of this fuzzy set</param> /// <param name="setName">the String object that contains the set name</param> /// <param name="alphaCut">the double value for the alphacut threshold</param> /// <param name="discourseLo">the double value for the low end of the discourse</param> /// <param name="discourseHi">the double value for the high end of the discourse</param> internal WorkingFuzzySet(ContinuousFuzzyRuleVariable parentVar, string setName, double alphaCut, double discourseLo, double discourseHi) : base(EnumFuzzySetType.Work, setName, parentVar, alphaCut, discourseLo, discourseHi) { mbSetEmpty = true; }
/// <summary> /// Create a ContinuousRuleVariable /// </summary> /// <param name="vsXml"></param> private void CreateContinuousRuleVariable(string vsXml) { XmlTextReader reader = new XmlTextReader(new StringReader(vsXml)); reader.Read(); string sName = reader.GetAttribute("name"); float fStart = float.Parse(reader.GetAttribute("start")); float fEnd = float.Parse(reader.GetAttribute("end")); ContinuousFuzzyRuleVariable fuzzyVariable = new ContinuousFuzzyRuleVariable(rb, sName, fStart, fEnd); while (reader.Read()) { switch (reader.Name) { case "Shoulder": CreateShoulder(fuzzyVariable, reader.ReadOuterXml()); break; case "Triangle": CreateTriangle(fuzzyVariable, reader.ReadOuterXml()); break; case "Trapezoid": CreateTrapezoid(fuzzyVariable, reader.ReadOuterXml()); break; } } reader.Close(); }
/// <summary> /// Create a Triangle /// </summary> /// <param name="vFuzzyVar"></param> /// <param name="vsXml"></param> private void CreateTriangle(ContinuousFuzzyRuleVariable vFuzzyVar, string vsXml) { XmlTextReader reader = new XmlTextReader(new StringReader(vsXml)); reader.Read(); string sName = reader.GetAttribute("name"); float fAlpha = float.Parse(reader.GetAttribute("alpha")); float fLeft = float.Parse(reader.GetAttribute("left")); float fCenter = float.Parse(reader.GetAttribute("center")); float fRight = float.Parse(reader.GetAttribute("right")); vFuzzyVar.AddSetTriangle(sName, fAlpha, fLeft, fCenter, fRight); reader.Close(); }
/// <summary> /// Create a Shoulder /// </summary> /// <param name="vFuzzyVar"></param> /// <param name="vsXml"></param> private void CreateShoulder(ContinuousFuzzyRuleVariable vFuzzyVar, string vsXml) { XmlTextReader reader = new XmlTextReader(new StringReader(vsXml)); reader.Read(); string sName = reader.GetAttribute("name"); float fAlpha = float.Parse(reader.GetAttribute("alpha")); float fStart = float.Parse(reader.GetAttribute("start")); float fEnd = float.Parse(reader.GetAttribute("end")); //left = 1, right = 2 EnumFuzzySetDirection eType = (EnumFuzzySetDirection)int.Parse(reader.GetAttribute("type")); vFuzzyVar.AddSetShoulder(sName, fAlpha, fStart, fEnd, eType); reader.Close(); }
/// <summary> /// Create a new Fuzzy Set /// </summary> /// <param name="setType"></param> /// <param name="setName"></param> /// <param name="parentVar"></param> /// <param name="alphaCut"></param> protected internal FuzzySet(EnumFuzzySetType setType, string setName, ContinuousFuzzyRuleVariable parentVar, double alphaCut) : this(setType, setName, parentVar, alphaCut, 0.0, 0.0) { }