/** * Creates a FuzzySet with a gaussian-shape such that the membership value is 1 at the leftX value * and 0 at the rightX value. The number of points in the generated FuzzySet is determined by the * the paramter numberOfPoints if it is acceptable (>= 5) or it is set to 5. The right point is * actually 4 standard deviations from the left (centre) point of the gaussian curve. The right * point and all point to its right are assumed to be zero. <br> * The equation for the gaussian curve is: <br> * * <pre><code> * * f(x) = e ** ((-(x-c)**2)/(2*sigma)) * * where c is the mean (centre) value and sigma is the standard deviation * * <br></pre></code> * * @param leftX the upper left x value of the gaussian-shaped curve. * @param rightX the bottom right x value of the gaussian-shaped curve. * @param numberOfPoints the number of points to be used when generating the gaussian-shaped * curve. */ public FuzzySet generateFuzzySet(double leftX, double rightX, int numberOfPoints) { double deltaX, x; double sigma = (rightX - leftX) / 4.0; double twoSigmaSquared = 2.0 * sigma * sigma; int numPoints = returnCorrectedNumPoints(numberOfPoints); FuzzySet fs = new FuzzySet(numPoints); fs.numPoints = numPoints; fs.set[0] = new SetPoint(leftX, 1.0); deltaX = (rightX - leftX) / (numPoints - 1); x = leftX; for (int i = 1; i < numPoints - 1; i++) { double membershipValue; x += deltaX; membershipValue = Math.pow(Math.E, -((x - leftX) * (x - leftX)) / twoSigmaSquared); fs.set[i] = new SetPoint(x, membershipValue); } fs.set[numPoints - 1] = new SetPoint(rightX, 0.0); fs.simplifySet(); return (fs); }
/** * Generates a FuzzySet that is a straight line (linear) from with membership value 0 on the left * to 1 on the right. * * @param leftX the left most X value of the FuzzySet (where membership value is 0) * @param rightX the right most X value of the FuzzySet (where membership value is 1) * @param numPoints the number of points to generate for the set (if < 2 then it will be set to 2) */ public FuzzySet generateFuzzySet(double leftX, double rightX, int numPoints) { if (numPoints < 2) numPoints = 2; FuzzySet fs = new FuzzySet(numPoints); fs.numPoints = numPoints; if (numPoints == 2) { fs.set[0] = new SetPoint(leftX, 0.0); fs.set[1] = new SetPoint(rightX, 1.0); return (fs); } else { double deltaX, X; double deltaY, Y; X = deltaX = (rightX - leftX) / (numPoints - 1); Y = deltaY = 1.0 / (numPoints - 1); fs.set[0] = new SetPoint(leftX, 0.0); for (int i = 1; i < numPoints - 2; i++) { fs.set[i] = new SetPoint(leftX + X, Y); X += deltaX; Y += deltaY; } fs.set[numPoints - 1] = new SetPoint(rightX, 1.0); fs.simplifySet(); return (fs); } }