Пример #1
0
 flScalar ShoulderTerm::membership(flScalar crisp) const {
     if (isLeft()) {
         if (crisp < minimum())
             return flScalar(1.0);
         if (crisp > maximum())
             return flScalar(0.0);
         return FuzzyOperation::Scale(minimum(), maximum(), crisp, 1, 0);
     } else {
         if (crisp < minimum())
             return flScalar(0.0);
         if (crisp > maximum())
             return flScalar(1.0);
         return FuzzyOperation::Scale(minimum(), maximum(), crisp, 0, 1);
     }
 }
 flScalar CompoundTerm::membership(flScalar crisp) const {
     flScalar max = flScalar(0);
     for (size_t i = 0; i < _terms.size(); ++i) {
         max = fuzzyOperator().aggregation().execute(max, _terms[i]->membership(crisp));
     }
     return fuzzyOperator().modulation().execute(modulation(), max);
 }
flScalar TrapezoidalTerm::membership(flScalar crisp) const {
    if (crisp < minimum() || crisp > maximum()) {
        return flScalar(0);
    }
    if (crisp < b()) {
        return fuzzyOperator().modulation().execute(modulation(),
                FuzzyOperation::Scale(a(), b(), crisp, 0, 1));
    }
    if (crisp < c()) {
        return fuzzyOperator().modulation().execute(modulation(), flScalar(1.0));
    }
    if (crisp < d()) {
        return fuzzyOperator().modulation().execute(modulation(),
                FuzzyOperation::Scale(c(), d(), crisp, 1, 0));
    }
    return flScalar(0.0);
}
Пример #4
0
 flScalar TriangularTerm::membership(flScalar crisp) const {
     if (crisp > maximum() || crisp < minimum()) {
         return flScalar(0.0);
     }
     flScalar result = crisp < b() ? FuzzyOperation::Scale(a(), b(), crisp, 0, 1)
             : FuzzyOperation::Scale(b(), c(), crisp, 1, 0);
     return fuzzyOperator().modulation().execute(result, modulation());
 }
    void FuzzyRule::fire(flScalar strength) {
        if (!FuzzyOperation::IsEq(strength, flScalar(0.0))) {
//            FL_LOG("DoT: " << strength << " - Fired: " << toString());
            for (int i = 0; i < numberOfConsequents(); ++i) {
                consequent(i)->execute(strength);
            }
        }
    }
 std::string MamdaniConsequent::toString() const {
     std::stringstream ss;
     ss << outputLVar()->name() << " " << FuzzyRule::FR_IS;
     for (int i = 0; i < numberOfHedges(); ++i) {
         ss << " " << hedge(i)->name();
     }
     ss << " " << term()->name();
     if (weight() < flScalar(1.0)) {
         ss << " " + FuzzyRule::FR_WITH + " " << weight();
     }
     return ss.str();
 }
flScalar TriangulationAlgorithm::areaAndCentroid(
    const LinguisticTerm* term, flScalar& centroid_x,
    flScalar& centroid_y, int samples) const {
    centroid_x = flScalar(0);
    centroid_y = flScalar(0);

    flScalar sum_area = flScalar(0.0);
    flScalar sum_a_x = flScalar(0.0);
    flScalar sum_a_y = flScalar(0.0);
    flScalar tmp_area = flScalar(0.0);

    flScalar range = term->maximum() - term->minimum();
    flScalar step_size = range / samples;

    int pi = 0;
    flScalar x[3];
    flScalar y[3];
    /*******
     * first triangle should include (minimum, 0)
     * fix requires y_is_0 to start false & pi to start at 1
     * updated by rctaylor 02/08/11
     ********/
    bool y_is_0 = false;
    x[0] = term->minimum();
    y[0] = term->membership(x[0]);
    x[1] = term->minimum();
    y[1] = 0;

    pi = 1;
    // end update 02/08/11

    int i = 1;
    //Triangulation:
    // rctaylor 02/08/11 - updated to <= because that is the only way x will ever equal
    // term->maximum (ie. term->maximum = term->minimum + samples * step_size)
    while (pi <= samples) {
        ++i;
        if (y_is_0) {
            x[i % 3] = x[(i - 1) % 3];
            y[i % 3] = 0;
            ++pi; // rctaylor 02/08/11 - since y_is_0 starts false, this moves here
        } else {
            x[i % 3] = term->minimum() + pi * step_size;
            y[i % 3] = term->membership(x[i % 3]);
        }

        y_is_0 = !y_is_0;

        //Area of triangle:
        // |Ax(By - Cy) + Bx(Cy - Ay) + Cx(Ay - By)| / 2
        // |x0(y1 - y2) + x1(y2 - y0) + x2(y0 - y1)| / 2
        tmp_area = FuzzyOperation::Absolute(x[0] * (y[1] - y[2]) + x[1]
                                            * (y[2] - y[0]) + x[2] * (y[0] - y[1])) / 2;
        //Centroid of a triangle:
        // x = (x0 + x1 + x2)/3; y = (y0 + y1 + y2)/3;
        sum_a_x += tmp_area * (x[0] + x[1] + x[2]) / 3;
        sum_a_y += tmp_area * (y[0] + y[1] + y[2]) / 3;

        sum_area += tmp_area;
    }
    centroid_x = sum_a_x / sum_area;
    centroid_y = sum_a_y / sum_area;
    return sum_area;
}
    LinguisticTerm::LinguisticTerm(const FuzzyOperator& fuzzy_op,
            const std::string& name, flScalar minimum, flScalar maximum) :
    _fuzzy_operator(&fuzzy_op), _name(name), _minimum(minimum), _maximum(maximum),
    _modulation(flScalar(1.0)) {

    }
 LinguisticTerm::LinguisticTerm(const std::string& name, flScalar minimum,
         flScalar maximum) :
 _fuzzy_operator(NULL), _name(name), _minimum(minimum), _maximum(maximum),
 _modulation(flScalar(1.0)) {
     setFuzzyOperator(FuzzyOperator::DefaultFuzzyOperator());
 }
 LinguisticTerm::LinguisticTerm() :
 _fuzzy_operator(NULL), _name(""), _minimum(-(log (0.0))), _maximum((log (0.0))),
 _modulation(flScalar(1.0)) {
     setFuzzyOperator(FuzzyOperator::DefaultFuzzyOperator());
 }
Пример #11
0
 flScalar SingletonTerm::membership(flScalar crisp) const {
     return fuzzyOperator().modulation().execute(modulation(), FuzzyOperation::IsEq(crisp, value())
             ? flScalar(1.0) : flScalar(0.0));
 }
Пример #12
0
 flScalar RectangularTerm::membership(flScalar crisp) const {
     if (crisp > maximum() || crisp < minimum()) {
         return flScalar(0.0);
     }
     return fuzzyOperator().modulation().execute(1.0, modulation());
 }