pyfume

Software to estimate fuzzy models from data using the Simpful library.

https://github.com/carofuchs/pyfume

Science Score: 23.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
    3 of 5 committers (60.0%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (14.4%) to scientific vocabulary

Keywords from Contributors

fuzzy-logic mamdani sugeno
Last synced: 10 months ago · JSON representation

Repository

Software to estimate fuzzy models from data using the Simpful library.

Basic Info
  • Host: GitHub
  • Owner: CaroFuchs
  • License: gpl-3.0
  • Language: Python
  • Default Branch: master
  • Homepage:
  • Size: 5.89 MB
Statistics
  • Stars: 19
  • Watchers: 4
  • Forks: 6
  • Open Issues: 3
  • Releases: 3
Created over 6 years ago · Last pushed about 2 years ago
Metadata Files
Readme License

README.md

pyFUME

pyFUME is a Python package for automatic Fuzzy Models Estimation from data [1]. pyFUME contains functions to estimate the antecedent sets and the consequent parameters of a Takagi-Sugeno fuzzy model directly from data. This information is then used to create an executable fuzzy model using the Simpful library. pyFUME also provides facilities for the evaluation of performance. For more information about pyFUME's functionalities, please check the online documentation.

Usage

For the following example, we use the Concrete Compressive Strength data set [2] as can be found in the UCI repository. The code in Example 1 is simple and easy to use, making it ideal to use for practitioners who wish to use the default settings or only wish to use few non-default settings using additional input arguments (Example 2). Users that wish to deviate from the default settings can use the code as shown in Example 3. The code of the Simpful model that is generated is automatically saved (in the same location as the pyFUME script is ran from) under the name 'Simpful_code.py'

Note

Please be aware that pyFUME's feature selection functionality makes use of multiprocessing. When feature selection is used, the main script should always be guarded by including "if __name__ == '__main__':" in the header the script. When the Spyder IDE is used, one should include "if __name__ == '__main__' and '__file__' in globals():".

Example 1

``` from pyfume import pyFUME

Set the path to the data and choose the number of clusters

path='./Concrete_data.csv' nc=3

Generate the Takagi-Sugeno FIS

FIS = pyFUME(datapath=path, nr_clus=nc)

Calculate and print the accuracy of the generated model

MAE=FIS.calculate_error(method="MAE") print ("The estimated error of the developed model is:", MAE)

Use the FIS to predict the compressive strength of a new concrete sample

Extract the model from the FIS object

model=FIS.get_model()

Set the values for each variable

model.setvariable('Cement', 300.0) model.setvariable('BlastFurnaceSlag', 50.0) model.setvariable('FlyAsh', 0.0) model.setvariable('Water', 175.0) model.setvariable('Superplasticizer',0.7) model.setvariable('CoarseAggregate', 900.0) model.setvariable('FineAggregate', 600.0) model.setvariable('Age', 45.0)

Perform inference and print predicted value

print(model.Sugeno_inference(['OUTPUT'])) ```

Example 2

``` from pyfume import pyFUME

Set the path to the data and choose the number of clusters

path='./Concrete_data.csv' nc=3

Generate the Takagi-Sugeno FIS

FIS = pyFUME(datapath=path, nrclus=nc, featureselection='fst-pso')

Calculate and print the accuracy of the generated model

MAE=FIS.calculate_error(method="MAE") print ("The estimated error of the developed model is:", MAE)

Use the FIS to predict the compressive strength of a new concrete sample

Extract the model from the FIS object

model=FIS.get_model()

Set the values for each variable

model.setvariable('Cement', 300.0) model.setvariable('BlastFurnaceSlag', 50.0) model.setvariable('FlyAsh', 0.0) model.setvariable('Water', 175.0) model.setvariable('Superplasticizer',0.7) model.setvariable('CoarseAggregate', 900.0) model.setvariable('FineAggregate', 600.0) model.setvariable('Age', 45.0)

Perform inference and print predicted value

print(model.Sugeno_inference(['OUTPUT'])) ```

Example 3

``` from pyfume import *

Set the path to the data and choose the number of clusters

path='./Concretedata.csv' nrclus=3

Load and normalize the data using min-max normalization

dl=DataLoader(path,normalize='minmax') variablenames=dl.variablenames dataX=dl.dataX dataY=dl.dataY

Split the data using the hold-out method in a training (default: 75%)

and test set (default: 25%).

ds = DataSplitter() xtrain, ytrain, xtest, ytest = ds.holdout(dataX=dl.dataX, dataY=dl.dataY)

Select features relevant to the problem

fs=FeatureSelector(dataX=xtrain, dataY=ytrain, nrclus=nrclus, variablenames=variablenames) selectedfeatureindices, variable_names=fs.wrapper()

Adapt the training and test input data after feature selection

xtrain = xtrain[:, selectedfeatureindices] xtest = xtest[:, selectedfeatureindices]

Cluster the training data (in input-output space) using FCM with default settings

cl = Clusterer(xtrain=xtrain, ytrain=ytrain, nrclus=nrclus) clustercenters, partitionmatrix, _ = cl.cluster(method="fcm")

Estimate the membership funtions of the system (default: mf_shape = gaussian)

ae = AntecedentEstimator(xtrain=xtrain, partitionmatrix=partitionmatrix) antecedent_parameters = ae.determineMF()

Calculate the firing strength of each rule for each data instance

fsc=FireStrengthCalculator(antecedentparameters=antecedentparameters, nrclus=nrclus, variablenames=variablenames) firingstrengths = fsc.calculatefirestrength(data=xtrain)

Estimate the parameters of the consequent functions

ce = ConsequentEstimator(xtrain=xtrain, ytrain=ytrain, firingstrengths=firingstrengths) consequent_parameters = ce.suglms()

Build a first-order Takagi-Sugeno model using Simpful. Specify the optional

'extreme_values' argument to specify the universe of discourse of the input

variables if you which to use Simpful's membership function plot functionalities.

simpbuilder = SugenoFISBuilder(antecedentsets=antecedentparameters, consequentparameters=consequentparameters, variablenames=variablenames) model = simpbuilder.get_model()

Calculate the mean squared error (MSE) of the model using the test data set

test=SugenoFISTester(model=model, testdata=xtest, variablenames=variablenames, goldenstandard=ytest) MSE = test.calculate_MSE()

print('The mean squared error of the created model is', MSE) ```

Example 4

``` from pyfume import pyFUME import pandas as pd import numpy as np

Read a Pandas dataframe (using the Pandas library)

df = pd.readcsv('.\Concretedata.csv')

Generate the Takagi-Sugeno FIS

FIS = pyFUME(dataframe=df, nr_clus=2)

Calculate and print the accuracy of the generated model

MAE=FIS.calculate_error(method="MAE") print ("The estimated error of the developed model is:", MAE)

Use the FIS to predict the compressive strength of a new concrete samples

Using Simpful's syntax (NOTE: This approach ONLY works for models built using non-normalized data!)

Extract the model from the FIS object

model=FIS.get_model()

Set the values for each variable

model.setvariable('Cement', 300.0) model.setvariable('BlastFurnaceSlag', 50.0) model.setvariable('FlyAsh', 0.0) model.setvariable('Water', 175.0) model.setvariable('Superplasticizer',0.7) model.setvariable('CoarseAggregate', 900.0) model.setvariable('FineAggregate', 600.0) model.setvariable('Age', 45.0)

Perform inference and print predicted value

print('The output using Simpfuls "setvariable" functionality is:', model.Sugenoinference(['OUTPUT']))

Using pyFUME's syntax (NOTE: This approach DOES work for models built using normalized data!)

Create numpy array (matrix) in which each row is a data instance to be processed

newdataoneinstance=np.array([[300, 50,0,175,0.7,900,600,45]]) predictionlabelsoneinstance=FIS.predictlabel(newdataoneinstance) print('The output using pyFUMEs "predictlabel" functionality is:', predictionlabelsoneinstance)

Example in which output for multiple data instances is computed

newdatamultipleinstances=np.array([[300, 50,0,175,0.7,900,600,45],[500, 75,30,200,0.9,600,760,39],[250, 40,10,175,0.3,840,360,51]]) predictionlabelsmultipleinstance=FIS.predictlabel(newdatamultipleinstances) print('The output using pyFUMEs "predictlabel" functionality is:', predictionlabelsmultipleinstance)

Plot the actual values vs the predicted values of the test data using the matplotlib library

Predict the labels of the test data

pred = FIS.predicttestdata()

Get the actual labels of the test data

, actual = FIS.getdata(data_set='test')

Create scatterplot

import matplotlib.pyplot as plt plt.scatter(actual, pred) plt.xlabel('Actual value') plt.ylabel('Predicted value') plt.plot([0,85],[0,85],'r') # Add a reference line plt.show()

```

Installation

pip install pyfume

Further information

If you need further information, please write an e-mail to Caro Fuchs: c.e.m.fuchs(at)tue.nl.

References

[1] Fuchs, C., Spolaor, S., Nobile, M. S., & Kaymak, U. (2020) "pyFUME: a Python package for fuzzy model estimation". In 2020 IEEE International Conference on Fuzzy Systems (FUZZ-IEEE) (pp. 1-8). IEEE.

[2] I-Cheng Yeh, "Modeling of strength of high performance concrete using artificial neural networks," Cement and Concrete Research, Vol. 28, No. 12, pp. 1797-1808 (1998). http://archive.ics.uci.edu/ml/datasets/Concrete+Compressive+Strength

GitHub Events

Total
  • Watch event: 1
Last Year
  • Watch event: 1

Committers

Last synced: over 2 years ago

All Time
  • Total Commits: 153
  • Total Committers: 5
  • Avg Commits per committer: 30.6
  • Development Distribution Score (DDS): 0.229
Past Year
  • Commits: 3
  • Committers: 1
  • Avg Commits per committer: 3.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Fuchs c****s@t****l 118
MSN m****e@t****l 24
Simone Spolaor s****r@c****t 5
Marco S. Nobile m****e@u****t 3
Marco S. Nobile n****e@d****t 3
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: about 1 year ago

All Time
  • Total issues: 5
  • Total pull requests: 3
  • Average time to close issues: about 20 hours
  • Average time to close pull requests: over 1 year
  • Total issue authors: 3
  • Total pull request authors: 2
  • Average comments per issue: 1.4
  • Average comments per pull request: 0.33
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • tdhooghe (3)
  • YawarGuguma (1)
  • spacecream (1)
  • LeoneBacciu (1)
Pull Request Authors
  • mandjevant (3)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 59,046 last-month
  • Total dependent packages: 1
  • Total dependent repositories: 3
  • Total versions: 61
  • Total maintainers: 3
pypi.org: pyfume

A Python package for fuzzy model estimation

  • Versions: 61
  • Dependent Packages: 1
  • Dependent Repositories: 3
  • Downloads: 59,046 Last month
Rankings
Downloads: 1.2%
Dependent packages count: 4.7%
Average: 8.7%
Dependent repos count: 9.0%
Forks count: 14.2%
Stargazers count: 14.5%
Maintainers (3)
Last synced: 11 months ago

Dependencies

docs/requirements.txt pypi
  • Sphinx ==3.3.1
  • fst-pso *
  • numpy *
  • scipy *
  • simpful *
  • sphinx-rtd-theme ==0.5.0
  • sphinxcontrib-napoleon ==0.7
setup.py pypi
  • fst-pso *
  • numpy *
  • scipy *
  • simpful *