Skip to main content

fuzlog

Fuzzy logic for Python: membership functions, linguistic variables, Mamdani and Sugeno inference. Built on NumPy, typed, Python 3.12+.

pip install fuzlog            # NumPy is the only dependency
pip install "fuzlog[plot]"    # adds matplotlib for the plots

Example

How much to tip, given the service and the food:

import fuzlog as fz

service = fz.partition("service", (0, 10), ["poor", "good", "excellent"])
food = fz.Variable("food", (0, 10), rancid=fz.z_shape(1, 4), tasty=fz.s_shape(6, 9))
tip = fz.partition("tip", (0, 30), cheap=5, average=15, generous=25)

tipper = fz.Mamdani(
    service.poor | food.rancid >> tip.cheap,
    service.good >> tip.average,
    service.excellent | food.tasty >> tip.generous,
)
print(round(tipper(service=3, food=8), 2))  # 17.03
print(tipper(service=[1, 5, 9], food=[2, 5, 8]).round(2).tolist())  # [8.2, 15.0, 21.8]
print(*tipper.rules, sep="\n")
# if service is poor or food is rancid then tip is cheap
# if service is good then tip is average
# if service is excellent or food is tasty then tip is generous

tipper.plot(service=3, food=8) and tipper.surface("service", "food") draw:

The output set inferred for service 3 and food 8, and the tip over both inputs

What is inside

  • Sets. 16 shapes: triangle, trapezoid, rising, falling, rectangle, singleton, piecewise, gauss, gauss2, bell, sigmoid, dsigmoid, psigmoid, s_shape, z_shape, pi_shape; any function of your own through MF. Sets combine with &, |, ~ and **.
  • Variables. Variable names the terms of a quantity; partition builds terms that always sum to 1, also on periodic universes such as angles.
  • Rules. temp.hot & ~humid.dry >> fan.fast, with weights and the hedges very, extremely, somewhat.
  • Inference. Mamdani with any t-norm, s-norm, implication and aggregation and the defuzzifiers centroid, bisector, mom, som, lom; Sugeno with constant or functional conclusions.
  • Arrays. A scalar gives a float, arrays give arrays, and inputs broadcast against each other.
  • Labels. Labels describes inputs in words, such as hot_wet.
  • Tables. compile turns a system, Labels or any function into a lookup table, also over transformed inputs; table.save(path) and load(path) keep it on disk.
  • Plots. variable.plot(), system.plot(...), system.surface(x, y).

Documentation

Development

uv sync                 # environment with the dev tools
uv run pytest           # tests, including every example in the documentation
uv run ruff check       # lint; `uv run ruff format` formats
uv run ty check         # types

MIT license.

Metadata

Release files for fuzlog 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fuzlog 0.2.0
File Size Uploaded Provenance Actions
fuzlog-0.2.0.tar.gz 25.5 kB Without provenance Details for fuzlog-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fuzlog 0.2.0
File Interpreter ABI Platform Actions
fuzlog-0.2.0-py3-none-any.whl Python 3 none any Details for fuzlog-0.2.0-py3-none-any.whl

Total release size: 54.7 kB

Release files / fuzlog-0.2.0.tar.gz

Download URL fuzlog-0.2.0.tar.gz
Size 25.5 kB
Tags Source
SHA-256 checksum
How to use checksums
29e20766c6acb5745ec4065ce9601047c64d28840df89a85b49bd5b673864b16
BLAKE2b-256 checksum
How to use checksums
57bbe5adfd0fcf9d582a5e751ec0f847063036769493ccdc5ad173e21b45460c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / fuzlog-0.2.0-py3-none-any.whl

Download URL fuzlog-0.2.0-py3-none-any.whl
Size 29.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1e6e510110ff492e128c3753f05c610157b5c4d8dae613fb0ffe0aab4bd8b308
BLAKE2b-256 checksum
How to use checksums
c7503e3965c6fcea37d6009d77b9cc146890add448e4d1e57c308f4e068c82e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for fuzlog 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page