Skip to main content

fuzzy-anova

One-Way Analysis of Variance (ANOVA) for Triangular Fuzzy Data

A complete Python implementation of the fuzzy ANOVA framework based on:

Hsien-Chung Wu (2007), "Analysis of variance for fuzzy data", International Journal of Systems Science, 38(3), 235-246.

PyPI version Python 3.8+ License: MIT Type Checked

Developed by Harshit Trivedi and Dr. Masum Raj (Mathematics Professor).


Overview

In traditional ANOVA, observations are crisp real numbers. In many real-world experiments—such as sensory evaluation, customer satisfaction surveys, and engineering tolerances—observations are inherently imprecise and naturally expressed as Triangular Fuzzy Numbers (TFN):

$$y_{ij} = (L_{ij}, \text{Core}{ij}, U{ij})$$

where:

  • $L_{ij}$ is the lower bound of support (membership degree = 0)
  • $\text{Core}_{ij}$ is the modal / core value (membership degree = 1)
  • $U_{ij}$ is the upper bound of support (membership degree = 0)
  • Condition: $L_{ij} \le \text{Core}{ij} \le U{ij}$

fuzzy-anova implements the complete Wu (2007) methodology, providing:

  1. Alpha-Cut ($h$-level set) Method: Converts fuzzy numbers into real intervals at any membership degree $h \in [0, 1]$.
  2. Lower & Upper Bound ANOVA Tables: Full ANOVA tables (SS, df, MS, F-statistic, P-value) calculated at any level-cut (Wu Table 2 & Table 3).
  3. Quadratic Boundary Analysis: Computes exact quadratic coefficients $A \cdot h^2 + B \cdot h + C$ for both fuzzy boundaries.
  4. Interval Sets $K_{H0}$ and $K_{H1}$: Determines the valid parameter ranges for accepting $H_0$ or $H_1$ via quadratic constraint optimization.
  5. Degree of Belief Metrics:
    • Optimistic Degree $\lambda(K)$: Total interval measure / length of the supporting parameter set.
    • Pessimistic Degree $h_H$: Supremum of the opposing parameter set.
    • Confidence Degree: Overall balanced decision confidence $\min(\text{optimistic}, 1 - \text{pessimistic})$.
  6. Zero Mandatory Heavy Dependencies: Fast pure-Python Snedecor's F-distribution fallback included, with automatic SciPy acceleration if SciPy is installed.

Installation

pip install fuzzy-anova

Optional Dependencies

For faster F-distribution calculation using SciPy:

pip install "fuzzy-anova[scipy]"

For development and running tests:

pip install "fuzzy-anova[dev]"

Quickstart

from fuzzy_anova import fuzzy_anova

# 1. Define groups with triangular fuzzy numbers (Lower, Core, Upper)
data = {
    "Design_1": [(9, 11, 13), (14, 16, 18)],
    "Design_2": [(11, 15, 19), (10, 15, 21), (11, 13, 15)],
    "Design_3": [(15, 18, 21), (14, 17, 20), (17, 20, 23)],
    "Design_4": [(15, 19, 23), (21, 24, 27)],
}

# 2. Run Fuzzy ANOVA at significance level alpha = 0.05
result = fuzzy_anova(data, alpha_sig=0.05)

# 3. Print the comprehensive formatted summary report
print(result.summary())

Accessing Result Quantities

# Decision and confidence metrics
print("Decision:           ", result.decision)            # 'H0' or 'H1'
print("Null Rejected:      ", result.is_null_rejected)     # True or False
print("Optimistic Degree:  ", result.optimistic_degree)   # e.g. 0.8808
print("Pessimistic Degree: ", result.pessimistic_degree)  # e.g. 0.0031
print("Confidence Degree:  ", result.confidence_degree)   # e.g. 0.8808

# Classical ANOVA core values (at h = 1)
print("SSTR:               ", result.sstr)
print("SSE:                ", result.sse)
print("F-Statistic:        ", result.f_stat)
print("Critical F-Value:   ", result.f_crit)
print("P-Value:            ", result.p_value)

# Boundary quadratic coefficients (A, B, C)
print("Lower Coeffs (A,B,C):", result.lower_coeffs.as_tuple())
print("Upper Coeffs (A,B,C):", result.upper_coeffs.as_tuple())

# Convert full results to a Python dictionary (ready for JSON serialization)
data_dict = result.to_dict()

Alpha-Cut and Boundary Tables

You can evaluate explicit alpha-cuts or compute the lower/upper bound ANOVA tables at any specific cut level $h$:

from fuzzy_anova import get_alpha_cut, alpha_cut_anova

# 1. Get explicit interval endpoints [lower, upper] at h = 0.5
cuts = get_alpha_cut(data, h=0.5)
print(cuts["Design_1"])  # [(10.0, 12.0), (15.0, 17.0)]

# 2. Generate Table 2 (Lower Bound) & Table 3 (Upper Bound) at h = 0.0 (full support)
tables = alpha_cut_anova(data, h=0.0, alpha_sig=0.05)
print(tables.summary())

Command-Line Interface (CLI)

fuzzy-anova provides a built-in CLI:

# Run the benchmark demonstration problem from Wu (2007)
fuzzy-anova --demo

# View version
fuzzy-anova --version

# Run ANOVA on your own dataset stored in a JSON file
fuzzy-anova data.json --alpha 0.05 --json

API Reference

fuzzy_anova(groups, alpha_sig=0.05, alpha_cut_level=0.0, f_crit=None) -> FuzzyANOVAResult

Main function to perform One-Way Fuzzy ANOVA.

Parameter Type Default Description
groups Mapping or Sequence required Dictionary of {group_name: [(L, C, U), ...]} or list of lists [[(L, C, U), ...], ...].
alpha_sig float 0.05 Statistical significance level $\alpha \in (0, 1)$.
alpha_cut_level float 0.0 Cut level $h \in [0, 1]$ used for generating bound ANOVA tables.
f_crit float or None None Optional critical value override (e.g. for matching textbook values).

get_alpha_cut(groups, h: float) -> Dict[str, List[Tuple[float, float]]]

Returns interval endpoints (lower_h, upper_h) for each observation at membership cut $h \in [0, 1]$.

alpha_cut_anova(groups, h=0.0, alpha_sig=0.05) -> AlphaCutANOVAResult

Computes the classical ANOVA table for both lower and upper bounds at level $h$.


Verification & Testing

The package includes an extensive test suite verifying:

  • Numerical accuracy against Wu (2007) published benchmarks to 4 decimal places
  • Degenerate crisp numbers ($L = \text{Core} = U$) collapsing to classical ANOVA
  • Identical groups accepting $H_0$ with confidence 1.0
  • Widely separated groups rejecting $H_0$ with confidence 1.0
  • Unequal sample sizes across treatments
  • Asymmetric and overlapping fuzzy numbers
  • Comprehensive input validation (types, shapes, NaN/Inf, ordering violations)

To run the automated tests:

python test_fuzzy_anova.py

or with pytest:

pytest


Authors & Maintainers

  • Harshit Trivedi — Software Architect & Core Implementation (GitHub)
  • Dr. Masum Raj — Professor of Mathematics, Academic Mentorship & Theoretical Mathematical Verification

Acknowledgements

Special gratitude to Dr. Masum Raj for mathematics mentorship, guiding the research on fuzzy hypothesis testing, and validating the numerical proofs and formulations from Wu (2007).

We also thank the peers and students who assisted with reviewing documentation, testing edge cases, and validating the outputs.


References

  1. Wu, Hsien-Chung (2007). "Analysis of variance for fuzzy data", International Journal of Systems Science, 38(3), pp. 235–246. DOI: 10.1080/00207720601157997.

Citation

If you use fuzzy-anova in academic research, please cite both the foundational paper and this implementation:

@article{wu2007analysis,
  title   = {Analysis of variance for fuzzy data},
  author  = {Wu, Hsien-Chung},
  journal = {International Journal of Systems Science},
  volume  = {38},
  number  = {3},
  pages   = {235--246},
  year    = {2007},
  doi     = {10.1080/00207720601160822}
}

@software{fuzzy_anova_2026,
  author  = {Harshit Trivedi and Dr. Masum Raj},
  title   = {fuzzy-anova: One-Way Analysis of Variance (ANOVA) for Triangular Fuzzy Data},
  year    = {2026},
  url     = {https://github.com/AquillaRival/fuzzy-anova},
  version = {1.0.0}
}

License

This project is licensed under the terms of the MIT License. Copyright (c) 2026 Harshit Trivedi, Dr. Masum Raj.

Metadata

Release files for fuzzy-anova 1.0.1

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

Source distribution (sdist)

Source distribution for fuzzy-anova 1.0.1
File Size Uploaded Provenance Actions
fuzzy_anova-1.0.1.tar.gz 34.8 kB With provenance Details for fuzzy_anova-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fuzzy-anova 1.0.1
File Interpreter ABI Platform Actions
fuzzy_anova-1.0.1-py3-none-any.whl Python 3 none any Details for fuzzy_anova-1.0.1-py3-none-any.whl

Total release size: 51.4 kB

Release files / fuzzy_anova-1.0.1.tar.gz

Download URL fuzzy_anova-1.0.1.tar.gz
Size 34.8 kB
Tags Source
SHA-256 checksum
How to use checksums
d9d759fc589ac64749808112390ba6becafd49d8b7f69e02e28fff0ec83d94ed
BLAKE2b-256 checksum
How to use checksums
d570e330eaed1be301c331953f21563593d956579d6b87ab54adface7022b1e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.

Transparency log

Release files / fuzzy_anova-1.0.1-py3-none-any.whl

Download URL fuzzy_anova-1.0.1-py3-none-any.whl
Size 16.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
599763766035a2d1ea320198f4b9c0e5a10588fe4c685c7a0999362976bffb07
BLAKE2b-256 checksum
How to use checksums
a8e789c7b0827c1381cb8f435e32bce7b44b3458c62791ef25840bc5d700777f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.

Transparency log

Security for fuzzy-anova 1.0.1

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for fuzzy_anova-1.0.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.

Transparency log

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