{"id":16345839,"url":"https://github.com/yalishanda42/fuzzykit","last_synced_at":"2025-10-26T01:31:43.035Z","repository":{"id":98613656,"uuid":"438776238","full_name":"yalishanda42/FuzzyKit","owner":"yalishanda42","description":"Fuzzy sets and fuzzy logic theory implementations in Swift.","archived":false,"fork":false,"pushed_at":"2023-08-30T09:53:51.000Z","size":668,"stargazers_count":4,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-07T13:11:37.285Z","etag":null,"topics":["dsl","dsl-syntax","fuzzy","fuzzy-inference-system","fuzzy-logic","fuzzy-logic-control","fuzzy-sets","fuzzy-systems","hacktoberfest","spm","swift-package-manager"],"latest_commit_sha":null,"homepage":"https://yalishanda42.github.io/FuzzyKit","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yalishanda42.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"ko_fi":"yalishanda42","github":"yalishanda42"}},"created_at":"2021-12-15T21:20:48.000Z","updated_at":"2023-10-01T20:27:49.000Z","dependencies_parsed_at":null,"dependency_job_id":"93ba36bf-de94-4433-9b09-b0aa0b7f4115","html_url":"https://github.com/yalishanda42/FuzzyKit","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/yalishanda42/FuzzyKit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yalishanda42%2FFuzzyKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yalishanda42%2FFuzzyKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yalishanda42%2FFuzzyKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yalishanda42%2FFuzzyKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yalishanda42","download_url":"https://codeload.github.com/yalishanda42/FuzzyKit/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yalishanda42%2FFuzzyKit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281047804,"owners_count":26435124,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-25T02:00:06.499Z","response_time":81,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dsl","dsl-syntax","fuzzy","fuzzy-inference-system","fuzzy-logic","fuzzy-logic-control","fuzzy-sets","fuzzy-systems","hacktoberfest","spm","swift-package-manager"],"created_at":"2024-10-11T00:33:40.299Z","updated_at":"2025-10-26T01:31:43.027Z","avatar_url":"https://github.com/yalishanda42.png","language":"Swift","funding_links":["https://ko-fi.com/yalishanda42","https://github.com/sponsors/yalishanda42"],"categories":[],"sub_categories":[],"readme":"![Cover photo](Resources/cover.png)\n\n# FuzzyKit\n\nFuzzy sets and fuzzy logic theory implementations.\n\n![Made for Swift](https://img.shields.io/badge/MADE%20FOR-SWIFT-orange?style=for-the-badge\u0026logo=swift)\n![Swift Package Manager supported](https://img.shields.io/badge/SWIFT%20PACKAGE%20MANAGER-SUPPORTED-green?style=for-the-badge\u0026logo=SWIFT)\n\n[![Build \u0026 Test](https://github.com/allexks/FuzzyKit/actions/workflows/build-and-test.yml/badge.svg)](https://github.com/allexks/FuzzyKit/actions/workflows/build-and-test.yml)\n![License](https://img.shields.io/github/license/allexks/FuzzyKit)\n\n## Example Usage\n\n```swift\nimport FuzzyKit\n\nenum Funding { case adequate, marginal, inadequate }\nenum Staffing { case small, large }\nenum Risk { case low, normal, high }\n\nlet funding: SimpleLinguisticVariable\u003cFunding, AnyFuzzySet\u003e = [\n    .inadequate: .init(membershipFunction: .leftOpen(slopeStart: 15, slopeEnd: 35)),\n    .marginal: .init(membershipFunction: .triangular(minimum: 21, peak: 41, maximum: 61)),\n    .adequate: .init(membershipFunction: .rightOpen(slopeStart: 55, slopeEnd: 75)),\n]\n\nlet staffing: SimpleLinguisticVariable\u003cStaffing, AnyFuzzySet\u003e = [\n    .small: .init(membershipFunction: .leftOpen(slopeStart: 29, slopeEnd: 69)),\n    .large: .init(membershipFunction: .rightOpen(slopeStart: 37, slopeEnd: 77)),\n]\n\nlet risk: SimpleLinguisticVariable\u003cRisk, AnyFuzzySet\u003e = [\n    .low: .init(membershipFunction: .leftOpen(slopeStart: 20, slopeEnd: 40)),\n    .normal: .init(membershipFunction: .triangular(minimum: 20, peak: 50, maximum: 80)),\n    .high: .init(membershipFunction: .rightOpen(slopeStart: 60, slopeEnd: 80)),\n]\n\nlet Ø = AnyFuzzySet\u003cDouble\u003e.empty\n\nlet ruleBase = FuzzyRuleBase {\n    funding.is(.adequate) || staffing.is(.small) --\u003e risk.is(.low)\n    funding.is(.marginal) \u0026\u0026 staffing.is(.large) --\u003e risk.is(.normal)\n    funding.is(.inadequate) || Ø --\u003e risk.is(.high)\n}\n\nlet flc = FuzzyLogicController(rules: ruleBase, settings: .init(implication: .mamdani))\n\nflc.consequenceGrade(for: 50, usingSingletonFact: (8.8, 42))  // result is 0.675\n```\n\n## Modules\n\nUsing the Swift Package Manager, don't forget to add the package as a dependency to your `Package.swift` file:\n\n```diff\ndependencies: [\n+   .package(url: \"https://github.com/allexks/FuzzyKit\", .upToNextMajor(from: \"0.1.0\")),\n],\n```\n\nTo be able to use everything from this package, you can import everything at once using this helper module:\n\n```diff\n.target(\n    name: \"...\",\n    dependencies: [\n+       .product(name: \"FuzzyKit\", package: \"FuzzyKit\"),\n    ]\n),\n```\n\n```swift\nimport FuzzyKit\n```\n\nOr alternatively, import only the specific modules needed:\n\n```diff\n.target(\n    name: \"...\",\n    dependencies: [\n+       .product(name: \"FuzzySets\", package: \"FuzzyKit\"),\n+       .product(name: \"FuzzyNumbers\", package: \"FuzzyKit\"),\n+       .product(name: \"FuzzyRelations\", package: \"FuzzyKit\"),\n+       .product(name: \"FuzzyLogic\", package: \"FuzzyKit\"),\n    ]\n),\n```\n\n```swift\nimport FuzzySets\nimport FuzzyNumbers\nimport FuzzyRelations\nimport FuzzyLogic\n```\n\n## API Reference\n\nAPI Reference automatically collected with `jazzy` is published [here](https://allexks.github.io/FuzzyKit) with each new release.\n\n## `FuzzySets` Module\n\n### `protocol FuzzySet`\nThis abstraction requires a fuzzy set to provide a `grade(forElement:)` method which accepts a parameter of an `associatedtype Universe` and returns its membership `Grade` in the set. There are 3 provided concrete implementations in this module:\n\n1. `struct AnyFuzzySet` - allows type erasure. It only stores a `MembershipFunction` and has non-mutable methods.\n\n2. `struct IterableFuzzySet` - stores a `MembershipFunction` as well as a `Sequence` of elements of the associated type `Universe`. Implements `Sequence` so that it can easily be iterated over them. The elements of the iteration over an `IterableFuzzySet` are `struct`s containing `grade` and `element` properties. It has non-mutable methods only. Includes `support`, `core` and `height` computed properties.\n\n3. `struct DiscreteMutableFuzzySet` - it is \"discrete\" because it doesn't stores a `MembershipFunction` but instead keeps its elements and their grade in a `Dictionary`, and it is \"mutable\" because it contains mutable equivalents of all other methods that operate over the set (including `subscript`). A default value of `0` is returned for the grade of an element that is not in the dictionary (a different default value can be provided as well). Includes `support`, `core` and `height` computed properties. A bonus feature is its debug print using Zadeh's notation.\n\nConvertions between the 3 types are easy and possible using the `eraseToAnyFuzzySet`, `makeIterable` and `makeDiscreteMutable` methods defined on them.\n\n### `protocol FuzzySetOperations`\nAll 3 concrete types implement it. It requires the following methods that operate on fuzzy sets:\n\n* `alphaCut(_:alpha:)`\n\n* `complement(method:)`\n\n* `intersection(_:method:)`\n\n* `union(_:method:)`\n\n* `difference(_:method:)`\n\n* `symmetricDifference(_:method:)`\n\n* `power(_:n:)`\n\n* `appliedCustomFunction(_:function:)`\n\n## License\n\n[MIT](LICENSE)\n\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fallexks%2FFuzzyKit.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fallexks%2FFuzzyKit?ref=badge_large)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyalishanda42%2Ffuzzykit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyalishanda42%2Ffuzzykit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyalishanda42%2Ffuzzykit/lists"}