membership: Membership Functions for Fuzzy Logic

membershipR Documentation

Membership Functions for Fuzzy Logic

Description

A collection of functions to compute membership values for various fuzzy sets, including triangular, trapezoidal, Gaussian, generalized bell, two-parameter Gaussian, sigmoid, difference of sigmoids, product of sigmoids, Z-shaped, PI-shaped, and S-shaped membership functions. Includes a function to visualize membership functions using ggplot2. These are designed for evaluation models in mathematical modeling, compatible with fuzzy_eval in the mathmodels package.

Usage

tri_mf(x, params)

trap_mf(x, params)

gauss_mf(x, params)

gbell_mf(x, params)

gauss2mf(x, params)

sigmoid_mf(x, params)

dsigmoid_mf(x, params)

psigmoid_mf(x, params)

z_mf(x, params)

pi_mf(x, params)

s_mf(x, params)

plot_mf(mf, xlim = c(0, 10), main = NULL)

Arguments

x

Numeric vector, input values for which to compute membership.

params

Numeric vector, parameters defining the membership function:

  • For tri_mf: c(a, b, c), where a <= b <= c (left base, peak, right base).

  • For trap_mf: c(a, b, c, d), where a <= b <= c <= d (left base, left top, right top, right base).

  • For gauss_mf: c(sigma, c), where sigma > 0 (spread, center).

  • For gbell_mf: c(a, b, c), where a > 0, b > 0 (width, shape, center).

  • For gauss2mf: c(s1, c1, s2, c2), where s1 > 0, s2 > 0 (left spread, left center, right spread, right center).

  • For sigmoid_mf: c(a, b), where a > 0 (slope, inflection point).

  • For dsigmoid_mf: c(a1, c1, a2, c2), where a1 > 0, a2 > 0 (slopes and inflection points for two sigmoids).

  • For psigmoid_mf: c(a1, c1, a2, c2), where a1 > 0, a2 > 0 (slopes and inflection points for two sigmoids).

  • For z_mf: c(a, b), where a < b (left base, right base).

  • For pi_mf: c(a, b, c, d), where a < b < c < d (left base, left shoulder, right shoulder, right base).

  • For s_mf: c(a, b), where a < b (left base, right base).

mf

Function, a membership function with fixed parameters (e.g., function(x) tri_mf(x, c(2, 5, 8))).

xlim

Numeric vector of length 2, x-axis limits for plotting (default c(0, 10)).

main

Character, plot title (default NULL, no title).

Details

These functions support evaluation models in mathematical modeling:

  • tri_mf: Triangular membership, linear rise from a to b (peak) and fall to c.

  • trap_mf: Trapezoidal membership, linear rise from a to b, plateau from b to c, fall to d.

  • gauss_mf: Gaussian membership, bell-shaped curve centered at c with spread sigma.

  • gbell_mf: Generalized bell membership, bell-shaped curve with width a, shape b, and center c.

  • gauss2mf: Two-parameter Gaussian membership, combining two Gaussians with spreads s1, s2 and centers c1, c2.

  • sigmoid_mf: Sigmoid membership, S-shaped curve with slope a and inflection point b.

  • dsigmoid_mf: Difference of two sigmoids, combining slopes a1, a2 and inflection points c1, c2.

  • psigmoid_mf: Product of two sigmoids, combining slopes a1, a2 and inflection points c1, c2.

  • z_mf: Z-shaped membership, decreasing from 1 at a to 0 at b.

  • pi_mf: PI-shaped membership, rising from a to b, plateau from b to c, falling to d.

  • s_mf: S-shaped membership, increasing from 0 at a to 1 at b.

  • plot_mf: Plots a membership function over xlim using ggplot2, suitable for tidyverse workflows.

Membership values can be used to construct fuzzy evaluation matrices for fuzzy_eval. Implemented in base R, except plot_mf, which requires ggplot2.

Value

  • For membership functions (tri_mf, trap_mf, gauss_mf, gbell_mf, gauss2mf, sigmoid_mf, dsigmoid_mf, psigmoid_mf, z_mf, pi_mf, s_mf): A numeric vector of membership values in 0, 1, same length as x.

  • For plot_mf: A ggplot2 object, plotting the membership function.

Examples

# Define input values
x = 0:10

# Triangular membership
tri_mf(x, params = c(3, 6, 8))

# Trapezoidal membership
trap_mf(x, params = c(1, 5, 7, 8))

# Gaussian membership
gauss_mf(x, params = c(2, 5))

# Generalized bell membership
gbell_mf(x, params = c(2, 4, 6))

# Two-parameter Gaussian membership
gauss2mf(x, params = c(1, 3, 3, 4))

# Sigmoid membership
sigmoid_mf(x, params = c(2, 4))

# Difference of sigmoids membership
dsigmoid_y = dsigmoid_mf(x, params = c(5, 2, 5, 7))

# Product of sigmoids membership
psigmoid_mf(x, params = c(2, 3, -5, 8))

# Z-shaped membership
z_mf(x, params = c(3, 7))

# PI-shaped membership
pi_mf(x, params = c(1, 4, 5, 10))

# S-shaped membership
s_mf(x, params = c(1, 8))

## Not run: 
# Visualize membership functions
plot_mf(\(x) tri_mf(x, c(3, 6, 8)), main = "Triangular MF")
plot_mf(\(x) trap_mf(x, c(1, 5, 7, 8)), main = "Trapezoidal MF")
plot_mf(\(x) gauss_mf(x, c(2, 5)), main = "Gaussian MF")
plot_mf(\(x) gbell_mf(x, c(2, 4, 6)), main = "Generalized Bell MF")
plot_mf(\(x) gauss2mf(x, c(1, 3, 3, 4)), main = "Two-Parameter Gaussian MF")
plot_mf(\(x) sigmoid_mf(x, c(2, 4)), main = "Sigmoid MF")
plot_mf(\(x) dsigmoid_mf(x, c(5, 2, 5, 7)), main = "Difference of Sigmoids MF")
plot_mf(\(x) psigmoid_mf(x, c(2, 3, -5, 8)), main = "Product of Sigmoids MF")
plot_mf(\(x) z_mf(x, c(3, 7)), main = "Z-Shaped MF")
plot_mf(\(x) pi_mf(x, c(1, 4, 5, 10)), main = "PI-Shaped MF")
plot_mf(\(x) s_mf(x, c(1, 8)), main = "S-Shaped MF")

## End(Not run)


zhjx19/mathmodels documentation built on June 2, 2025, 12:18 a.m.