All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fuzzylite.term.SigmoidDifference Maven / Gradle / Ivy

Go to download

jfuzzylite(TM) is a free and open-source fuzzy logic control library programmed in Java. The goal of jfuzzylite is to easily design and efficiently operate fuzzy logic controllers following an object-oriented model without relying on external libraries. jfuzzylite is the Java equivalent of the fuzzylite(R) library. jfuzzylite is a trademark of FuzzyLite Limited. fuzzylite is a registered trademark of FuzzyLite Limited.

The newest version!
/*
 jfuzzylite (TM), a fuzzy logic control library in Java.
 Copyright (C) 2010-2017 FuzzyLite Limited. All rights reserved.
 Author: Juan Rada-Vilela, Ph.D. 

 This file is part of jfuzzylite.

 jfuzzylite is free software: you can redistribute it and/or modify it under
 the terms of the FuzzyLite License included with the software.

 You should have received a copy of the FuzzyLite License along with
 jfuzzylite. If not, see .

 jfuzzylite is a trademark of FuzzyLite Limited.
 fuzzylite (R) is a registered trademark of FuzzyLite Limited.
 */
package com.fuzzylite.term;

import com.fuzzylite.Op;

import java.util.Iterator;
import java.util.List;

/**
 The SigmoidDifference class is an extended Term that represents the difference
 between two sigmoidal membership functions.

 @image html sigmoidDifference.svg

 @author Juan Rada-Vilela, Ph.D.
 @see Term
 @see Variable
 @since 4.0
 */
public class SigmoidDifference extends Term {

    private double left, rising;
    private double falling, right;

    public SigmoidDifference() {
        this("");
    }

    public SigmoidDifference(String name) {
        this(name, Double.NaN, Double.NaN, Double.NaN, Double.NaN);
    }

    public SigmoidDifference(String name, double left, double rising,
            double falling, double right) {
        this(name, left, rising, falling, right, 1.0);

    }

    public SigmoidDifference(String name, double left, double rising,
            double falling, double right, double height) {
        super(name, height);
        this.left = left;
        this.rising = rising;
        this.falling = falling;
        this.right = right;
    }

    /**
     Returns the parameters of the term

     @return `"left rising falling right [height]"`
     */
    @Override
    public String parameters() {
        return Op.join(" ", left, rising, falling, right)
                + (!Op.isEq(height, 1.0) ? " " + Op.str(height) : "");
    }

    /**
     Configures the term with the parameters

     @param parameters as `"left rising falling right [height]"`
     */
    @Override
    public void configure(String parameters) {
        if (parameters.isEmpty()) {
            return;
        }
        List values = Op.split(parameters, " ");
        int required = 4;
        if (values.size() < required) {
            throw new RuntimeException(String.format(
                    "[configuration error] term <%s> requires <%d> parameters",
                    this.getClass().getSimpleName(), required));
        }
        Iterator it = values.iterator();
        setLeft(Op.toDouble(it.next()));
        setRising(Op.toDouble(it.next()));
        setFalling(Op.toDouble(it.next()));
        setRight(Op.toDouble(it.next()));
        if (values.size() > required) {
            setHeight(Op.toDouble(it.next()));
        }
    }

    /**
     Computes the membership function evaluated at `x`

     @param x
     @return ` h (a-b)`

     where `h` is the height of the Term,
     `a= 1 / (1 + \exp(-s_l \times (x - i_l))) `,
     `b = 1 / (1 + \exp(-s_r \times (x - i_r)))`,
     `i_l` is the left inflection of the SigmoidDifference,
     `s_l` is the left slope of the SigmoidDifference,
     `i_r` is the right inflection of the SigmoidDifference,
     `s_r` is the right slope of the SigmoidDifference
     */
    @Override
    public double membership(double x) {
        if (Double.isNaN(x)) {
            return Double.NaN;
        }
        double a = 1.0 / (1.0 + Math.exp(-rising * (x - left)));
        double b = 1.0 / (1.0 + Math.exp(-falling * (x - right)));
        return height * Math.abs(a - b);
    }

    /**
     Gets the inflection of the left sigmoidal curve

     @return the inflection of the left sigmoidal curve
     */
    public double getLeft() {
        return left;
    }

    /**
     Sets the inflection of the left sigmoidal curve

     @param leftInflection is the inflection of the left sigmoidal curve
     */
    public void setLeft(double leftInflection) {
        this.left = leftInflection;
    }

    /**
     Gets the slope of the left sigmoidal curve

     @return the slope of the left sigmoidal curve
     */
    public double getRising() {
        return rising;
    }

    /**
     Sets the slope of the left sigmoidal curve

     @param risingSlope is the slope of the left sigmoidal curve
     */
    public void setRising(double risingSlope) {
        this.rising = risingSlope;
    }

    /**
     Gets the slope of the right sigmoidal curve

     @return the slope of the right sigmoidal curve
     */
    public double getFalling() {
        return falling;
    }

    /**
     Sets the slope of the right sigmoidal curve

     @param fallingSlope is the slope of the right sigmoidal curve
     */
    public void setFalling(double fallingSlope) {
        this.falling = fallingSlope;
    }

    /**
     Gets the inflection of the right sigmoidal curve

     @return the inflection of the right sigmoidal curve
     */
    public double getRight() {
        return right;
    }

    /**
     Sets the inflection of the right sigmoidal curve

     @param rightInflection is the inflection of the right sigmoidal curve
     */
    public void setRight(double rightInflection) {
        this.right = rightInflection;
    }

    @Override
    public SigmoidDifference clone() throws CloneNotSupportedException {
        return (SigmoidDifference) super.clone();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy