Skip to content

TLC for fuzzy_logic/: restore disabled demo dependency-free + add README - #15166

Merged
cclauss merged 3 commits into
TheAlgorithms:masterfrom
priya-sundaram-dev:tlc-fuzzy-logic
Sep 3, 2026
Merged

TLC for fuzzy_logic/: restore disabled demo dependency-free + add README#15166
cclauss merged 3 commits into
TheAlgorithms:masterfrom
priya-sundaram-dev:tlc-fuzzy-logic

Conversation

@priya-sundaram-dev

Copy link
Copy Markdown
Contributor

Describe your change:

TLC pass on fuzzy_logic/ — the first directory from the shortlist in #15081 (last new contribution 2024-09, 2 files, no README). Starting here since it has the same "restore a disabled file + add tests/README/URLs" shape as the audio_filters/ exercise (#15087).

What this does:

  • Restores fuzzy_operations.py.DISABLED.txt dependency-free. It was disabled because it imported the third-party scikit-fuzzy (import skfuzzy). I rewrote it as fuzzy_set_operations.py using NumPy only (already in pyproject.toml). It implements the classic Zadeh operators on sampled membership vectors — union, intersection, complement, difference, algebraic sum/product, bounded sum/difference — plus a triangular_membership helper.
  • Adds doctests to every function instead of the old __main__-only matplotlib demo. The __main__ block still reproduces the original "young vs. middle-aged" figure and degrades gracefully (prints a summary) when matplotlib isn't installed.
  • Adds fuzzy_logic/README.md covering both modules, with Wikipedia links and a runnable example, and explaining how the two files complement each other (fuzzy_operations.py keeps the parametric triangular representation; fuzzy_set_operations.py works on arbitrary sampled membership shapes).
  • Removes the obsolete .DISABLED.txt now that its intent lives in a working, tested module.

Credit kept to Jigyasa Gandhi (original scikit-fuzzy demo) and @Shreya123714 (the FuzzySet class).

Verified locally: pytest --doctest-modules fuzzy_logic/ (15 passed), ruff check, ruff format --check all pass.

Relates to #15081.

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Add or change doctests? -- Note: Please avoid changing both code and tests in a single pull request.
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.

- Restore fuzzy_operations.py.DISABLED.txt as fuzzy_set_operations.py,
  rewritten to drop the scikit-fuzzy dependency (NumPy only). Implements the
  Zadeh operators on sampled membership vectors: union, intersection,
  complement, difference, algebraic sum/product, bounded sum/difference, plus a
  triangular_membership helper. Every function has doctests; the __main__ block
  reproduces the original 'young vs. middle-aged' demo and degrades gracefully
  when matplotlib is absent.
- Add fuzzy_logic/README.md covering both modules with Wikipedia links and a
  runnable example.
- Remove the obsolete .DISABLED.txt (its intent is now the working module).

Credit to Jigyasa Gandhi (original scikit-fuzzy demo) and @Shreya123714
(FuzzySet). Passes pytest --doctest-modules, ruff check, ruff format --check.
@algorithms-keeper algorithms-keeper Bot added documentation This PR modified documentation files require descriptive names This PR needs descriptive function and/or variable names labels Sep 2, 2026

@algorithms-keeper algorithms-keeper Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

Comment thread fuzzy_logic/fuzzy_set_operations.py Outdated
Comment thread fuzzy_logic/fuzzy_set_operations.py Outdated
Comment thread fuzzy_logic/fuzzy_set_operations.py Outdated
Comment thread fuzzy_logic/fuzzy_set_operations.py Outdated
Comment thread fuzzy_logic/fuzzy_set_operations.py Outdated
Comment thread fuzzy_logic/fuzzy_set_operations.py Outdated
Comment thread fuzzy_logic/fuzzy_set_operations.py Outdated
Comment thread fuzzy_logic/fuzzy_set_operations.py Outdated
Comment thread fuzzy_logic/fuzzy_set_operations.py Outdated
@algorithms-keeper algorithms-keeper Bot added the awaiting reviews This PR is ready to be reviewed label Sep 2, 2026
@cclauss

cclauss commented Sep 2, 2026

Copy link
Copy Markdown
Member

I agree with @algorithms-keeper that single-letter names for function parameters are not self-documenting for the caller.

Comment thread fuzzy_logic/fuzzy_set_operations.py Outdated
Address review on TheAlgorithms#15166:
- rename single-letter params (x->grid, a/b->membership_a/membership_b,
  fuzzy_complement arg -> membership) per algorithms-keeper + cclauss
- drop 'from __future__ import annotations' (repo is Python 3.14t-only)
@algorithms-keeper algorithms-keeper Bot removed the require descriptive names This PR needs descriptive function and/or variable names label Sep 2, 2026
Address review on TheAlgorithms#15166:
- rename single-letter params (x->grid, a/b->membership_a/membership_b,
  fuzzy_complement arg -> membership) per algorithms-keeper + cclauss
- drop 'from __future__ import annotations' (repo is Python 3.14t-only)
@priya-sundaram-dev

Copy link
Copy Markdown
Contributor Author

Done — pushed in bbef392:

  • Descriptive parameter names (agreeing with @algorithms-keeper and @cclauss): xgrid, the two operands → membership_a/membership_b, and fuzzy_complement's single operand → membership. Doctests call positionally so results are unchanged; all still pass.
  • Dropped from __future__ import annotations — not needed in a Python 3.14t-only repo.

ruff and pre-commit.ci are green; the NDArray[np.float64] hints evaluate fine at runtime without the future import. Thanks for the review!

@cclauss
cclauss enabled auto-merge (squash) September 3, 2026 04:46
@algorithms-keeper algorithms-keeper Bot removed the awaiting reviews This PR is ready to be reviewed label Sep 3, 2026
@cclauss
cclauss merged commit c1ad752 into TheAlgorithms:master Sep 3, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation This PR modified documentation files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants