pyfuzzymind


Namepyfuzzymind JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://github.com/fadedreams/pycircuitbreaker
SummaryA Python library for implementing fuzzy logic systems, including fuzzy sets, fuzzy rules, inference engines, and various defuzzification methods.
upload_time2024-08-08 16:07:59
maintainerNone
docs_urlNone
authorfadedreams7
requires_python<4.0,>=3.8
licenseMIT
keywords fuzzy logic fuzzy logic fuzzy set fuzzy rule inference engine
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ### pyFuzzyMind
This library provides a set of classes for implementing fuzzy logic systems in Python. It includes support for defining fuzzy sets, fuzzy rules, and performing inference using an inference engine. It also provides methods for defuzzification using different techniques. For example, you can use this library to build a fuzzy logic-based risk assessment system for financial investments. In this system, fuzzy sets could represent risk levels (such as "Low Risk", "Medium Risk", "High Risk"), and rules could determine investment strategies based on market indicators. The inference engine would evaluate these rules to suggest an appropriate investment strategy, and defuzzification methods like the Mean of Maximum (MOM) could be used to provide a precise risk score for decision-making.

#### FuzzySet
Represents a fuzzy set with a membership function. Provides methods for operations on fuzzy sets.

```python
FuzzySet(name, membership_function)
# name: The name of the fuzzy set.
# membership_function: A function that defines the membership degree of the set.
```
##### Methods
- membership_degree(x): Returns the membership degree of x.
- union(other_set): Returns a new fuzzy set representing the union of this set and other_set.
- intersection(other_set): Returns a new fuzzy set representing the intersection of this set and other_set.
- complement(): Returns a new fuzzy set representing the complement of this set.
- normalize(): Returns a new fuzzy set with a normalized membership function.
- centroid(min, max, step): Performs defuzzification using the centroid method.

#### FuzzyRule
Represents a fuzzy rule consisting of a condition and a consequence.

```python
FuzzyRule(condition, consequence, weight=1)
# condition: A function that takes inputs and returns a boolean indicating if the rule condition is satisfied.
# consequence: The result of the rule if the condition is true. Can be a fuzzy set or a function.
# weight: An optional weight for the rule (default is 1).
```
##### Methods
- evaluate(inputs): Evaluates the rule against the given inputs and returns the result and weight if the condition is satisfied.
#### InferenceEngine
Uses a set of fuzzy rules to perform inference and defuzzification.
```python
InferenceEngine(rules)
# rules: A list of FuzzyRule instances.
```
##### Methods
- infer(inputs): Performs inference based on the input values and returns the aggregated result.
- aggregate_results(results): Aggregates results from the fuzzy rules.
- defuzzify_centroid(min, max, step): Performs defuzzification using the centroid method.
- defuzzify_mom(min, max, step): Performs defuzzification using the Mean of Maxima (MOM) method.
- defuzzify_bisector(min, max, step): Performs defuzzification using the Bisector method.
- get_fuzzy_set_consequences(): Returns a list of fuzzy sets as consequences of the rules.

##### Example Usage
```python
from pyfuzzymind import FuzzySet, FuzzyRule, InferenceEngine
InferenceEngine(rules)

# Define fuzzy sets for urgency and complexity
urgency_set = FuzzySet('Urgency', lambda urgency: 0 if urgency < 3 else (urgency - 3) / 4 if urgency < 7 else 1)
complexity_set = FuzzySet('Complexity', lambda complexity: 0 if complexity < 2 else (complexity - 2) / 3 if complexity < 5 else 1)

# Define fuzzy rules
rules = [
    FuzzyRule(
        lambda inputs: urgency_set.membership_degree(inputs['urgency']) > 0.7 and complexity_set.membership_degree(inputs['complexity']) > 0.7,
        FuzzySet('Urgent', lambda x: 1 if x >= 7 else x / 7)
    ),
    FuzzyRule(
        lambda inputs: urgency_set.membership_degree(inputs['urgency']) > 0.5,
        lambda inputs: 'High Priority'
    ),
    FuzzyRule(
        lambda inputs: complexity_set.membership_degree(inputs['complexity']) > 0.5,
        lambda inputs: 'Medium Priority'
    ),
    FuzzyRule(
        lambda inputs: urgency_set.membership_degree(inputs['urgency']) <= 0.5 and complexity_set.membership_degree(inputs['complexity']) <= 0.5,
        lambda inputs: 'Low Priority'
    )
]

engine = InferenceEngine(rules)

# Example ticket
ticket = {'urgency': 8, 'complexity': 6}
priority = engine.infer(ticket)
print(f'Ticket Priority: {priority}')

# Defuzzification examples
centroid = urgency_set.centroid(0, 10)
print(f'Centroid defuzzification: {centroid}')

defuzzified_centroid = engine.defuzzify_centroid(0, 10)
print(f'Defuzzified Centroid: {defuzzified_centroid}')

defuzzified_mom = engine.defuzzify_mom(0, 10)
print(f'Defuzzified MOM: {defuzzified_mom}')

defuzzified_bisector = engine.defuzzify_bisector(0, 10)
print(f'Defuzzified Bisector: {defuzzified_bisector}')

```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/fadedreams/pycircuitbreaker",
    "name": "pyfuzzymind",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": null,
    "keywords": "fuzzy, logic, fuzzy logic, fuzzy set, fuzzy rule, inference engine",
    "author": "fadedreams7",
    "author_email": "fadedreams7@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/80/b9/913eb4a2ad706d449f62f80ef45fa1a3171701aac4a3e9e477c6715c7876/pyfuzzymind-0.1.1.tar.gz",
    "platform": null,
    "description": "### pyFuzzyMind\nThis library provides a set of classes for implementing fuzzy logic systems in Python. It includes support for defining fuzzy sets, fuzzy rules, and performing inference using an inference engine. It also provides methods for defuzzification using different techniques. For example, you can use this library to build a fuzzy logic-based risk assessment system for financial investments. In this system, fuzzy sets could represent risk levels (such as \"Low Risk\", \"Medium Risk\", \"High Risk\"), and rules could determine investment strategies based on market indicators. The inference engine would evaluate these rules to suggest an appropriate investment strategy, and defuzzification methods like the Mean of Maximum (MOM) could be used to provide a precise risk score for decision-making.\n\n#### FuzzySet\nRepresents a fuzzy set with a membership function. Provides methods for operations on fuzzy sets.\n\n```python\nFuzzySet(name, membership_function)\n# name: The name of the fuzzy set.\n# membership_function: A function that defines the membership degree of the set.\n```\n##### Methods\n- membership_degree(x): Returns the membership degree of x.\n- union(other_set): Returns a new fuzzy set representing the union of this set and other_set.\n- intersection(other_set): Returns a new fuzzy set representing the intersection of this set and other_set.\n- complement(): Returns a new fuzzy set representing the complement of this set.\n- normalize(): Returns a new fuzzy set with a normalized membership function.\n- centroid(min, max, step): Performs defuzzification using the centroid method.\n\n#### FuzzyRule\nRepresents a fuzzy rule consisting of a condition and a consequence.\n\n```python\nFuzzyRule(condition, consequence, weight=1)\n# condition: A function that takes inputs and returns a boolean indicating if the rule condition is satisfied.\n# consequence: The result of the rule if the condition is true. Can be a fuzzy set or a function.\n# weight: An optional weight for the rule (default is 1).\n```\n##### Methods\n- evaluate(inputs): Evaluates the rule against the given inputs and returns the result and weight if the condition is satisfied.\n#### InferenceEngine\nUses a set of fuzzy rules to perform inference and defuzzification.\n```python\nInferenceEngine(rules)\n# rules: A list of FuzzyRule instances.\n```\n##### Methods\n- infer(inputs): Performs inference based on the input values and returns the aggregated result.\n- aggregate_results(results): Aggregates results from the fuzzy rules.\n- defuzzify_centroid(min, max, step): Performs defuzzification using the centroid method.\n- defuzzify_mom(min, max, step): Performs defuzzification using the Mean of Maxima (MOM) method.\n- defuzzify_bisector(min, max, step): Performs defuzzification using the Bisector method.\n- get_fuzzy_set_consequences(): Returns a list of fuzzy sets as consequences of the rules.\n\n##### Example Usage\n```python\nfrom pyfuzzymind import FuzzySet, FuzzyRule, InferenceEngine\nInferenceEngine(rules)\n\n# Define fuzzy sets for urgency and complexity\nurgency_set = FuzzySet('Urgency', lambda urgency: 0 if urgency < 3 else (urgency - 3) / 4 if urgency < 7 else 1)\ncomplexity_set = FuzzySet('Complexity', lambda complexity: 0 if complexity < 2 else (complexity - 2) / 3 if complexity < 5 else 1)\n\n# Define fuzzy rules\nrules = [\n    FuzzyRule(\n        lambda inputs: urgency_set.membership_degree(inputs['urgency']) > 0.7 and complexity_set.membership_degree(inputs['complexity']) > 0.7,\n        FuzzySet('Urgent', lambda x: 1 if x >= 7 else x / 7)\n    ),\n    FuzzyRule(\n        lambda inputs: urgency_set.membership_degree(inputs['urgency']) > 0.5,\n        lambda inputs: 'High Priority'\n    ),\n    FuzzyRule(\n        lambda inputs: complexity_set.membership_degree(inputs['complexity']) > 0.5,\n        lambda inputs: 'Medium Priority'\n    ),\n    FuzzyRule(\n        lambda inputs: urgency_set.membership_degree(inputs['urgency']) <= 0.5 and complexity_set.membership_degree(inputs['complexity']) <= 0.5,\n        lambda inputs: 'Low Priority'\n    )\n]\n\nengine = InferenceEngine(rules)\n\n# Example ticket\nticket = {'urgency': 8, 'complexity': 6}\npriority = engine.infer(ticket)\nprint(f'Ticket Priority: {priority}')\n\n# Defuzzification examples\ncentroid = urgency_set.centroid(0, 10)\nprint(f'Centroid defuzzification: {centroid}')\n\ndefuzzified_centroid = engine.defuzzify_centroid(0, 10)\nprint(f'Defuzzified Centroid: {defuzzified_centroid}')\n\ndefuzzified_mom = engine.defuzzify_mom(0, 10)\nprint(f'Defuzzified MOM: {defuzzified_mom}')\n\ndefuzzified_bisector = engine.defuzzify_bisector(0, 10)\nprint(f'Defuzzified Bisector: {defuzzified_bisector}')\n\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Python library for implementing fuzzy logic systems, including fuzzy sets, fuzzy rules, inference engines, and various defuzzification methods.",
    "version": "0.1.1",
    "project_urls": {
        "Homepage": "https://github.com/fadedreams/pycircuitbreaker",
        "Repository": "https://github.com/fadedreams/pycircuitbreaker"
    },
    "split_keywords": [
        "fuzzy",
        " logic",
        " fuzzy logic",
        " fuzzy set",
        " fuzzy rule",
        " inference engine"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "141f03c0da3a00e6311aca7d2995cde64d0deac65e40c5c7a370dd8d8ecd10c0",
                "md5": "c1b5610b404e132e07ea6472791ff8e7",
                "sha256": "077a97300aaa491efb8071808292952ff10b63cb02ab2f64ca06ece475e6ee98"
            },
            "downloads": -1,
            "filename": "pyfuzzymind-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c1b5610b404e132e07ea6472791ff8e7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 7120,
            "upload_time": "2024-08-08T16:07:57",
            "upload_time_iso_8601": "2024-08-08T16:07:57.809893Z",
            "url": "https://files.pythonhosted.org/packages/14/1f/03c0da3a00e6311aca7d2995cde64d0deac65e40c5c7a370dd8d8ecd10c0/pyfuzzymind-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "80b9913eb4a2ad706d449f62f80ef45fa1a3171701aac4a3e9e477c6715c7876",
                "md5": "59450d3513069dfa6d6e8eaaa0a25554",
                "sha256": "459fc911eb139128df3930cc14a757eee15dae01f8ee2917e0d809b3b883c603"
            },
            "downloads": -1,
            "filename": "pyfuzzymind-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "59450d3513069dfa6d6e8eaaa0a25554",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 4142,
            "upload_time": "2024-08-08T16:07:59",
            "upload_time_iso_8601": "2024-08-08T16:07:59.933344Z",
            "url": "https://files.pythonhosted.org/packages/80/b9/913eb4a2ad706d449f62f80ef45fa1a3171701aac4a3e9e477c6715c7876/pyfuzzymind-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-08 16:07:59",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "fadedreams",
    "github_project": "pycircuitbreaker",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pyfuzzymind"
}
        
Elapsed time: 0.74788s