reflame

reflame: Revolutionizing Functional Link Neural Network by Metaheuristic Optimization

https://github.com/thieu1995/reflame

Science Score: 77.0%

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

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 13 DOI reference(s) in README
  • Academic publication links
    Links to: zenodo.org
  • Committers with academic emails
    1 of 2 committers (50.0%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (14.7%) to scientific vocabulary

Keywords

classification evolutionary-algorithms feed-forward-neural-networks flnn functional-link-artificial-neural-network functional-link-neural-network genetic-algorithm higher-order-functions higher-order-neural-network machine-learning metaheuristic-algorithms nature-inspired-algorithms neural-network optimization-algorithms particle-swarm-optimization pytorch-model regression scikit-learn shade whale-optimization-algorithm
Last synced: 4 months ago · JSON representation ·

Repository

reflame: Revolutionizing Functional Link Neural Network by Metaheuristic Optimization

Basic Info
Statistics
  • Stars: 9
  • Watchers: 3
  • Forks: 0
  • Open Issues: 0
  • Releases: 2
Topics
classification evolutionary-algorithms feed-forward-neural-networks flnn functional-link-artificial-neural-network functional-link-neural-network genetic-algorithm higher-order-functions higher-order-neural-network machine-learning metaheuristic-algorithms nature-inspired-algorithms neural-network optimization-algorithms particle-swarm-optimization pytorch-model regression scikit-learn shade whale-optimization-algorithm
Created over 2 years ago · Last pushed about 2 years ago
Metadata Files
Readme Changelog License Code of conduct Citation

README.md

Reflame


GitHub release Wheel PyPI version PyPI - Python Version PyPI - Status PyPI - Downloads Downloads Tests & Publishes to PyPI GitHub Release Date Documentation Status Chat GitHub contributors GitTutorial DOI License: GPL v3

Reflame (REvolutionizing Functional Link Artificial neural networks by MEtaheuristic algorithms) is a Python library that implements a framework for training Functional Link Neural Network (FLNN) networks using Metaheuristic Algorithms. It provides a comparable alternative to the traditional FLNN network and is compatible with the Scikit-Learn library. With Reflame, you can perform searches and hyperparameter tuning using the functionalities provided by the Scikit-Learn library.

  • Free software: GNU General Public License (GPL) V3 license
  • Provided Estimator: FlnnRegressor, FlnnClassifier, MhaFlnnRegressor, MhaFlnnClassifier
  • Total Official Metaheuristic-based Flnn Regression: > 200 Models
  • Total Official Metaheuristic-based Flnn Classification: > 200 Models
  • Supported performance metrics: >= 67 (47 regressions and 20 classifications)
  • Supported objective functions (as fitness functions or loss functions): >= 67 (47 regressions and 20 classifications)
  • Documentation: https://reflame.readthedocs.io
  • Python versions: >= 3.8.x
  • Dependencies: numpy, scipy, scikit-learn, pandas, mealpy, permetrics, torch, skorch

Citation Request

If you want to understand how Metaheuristic is applied to Functional Link Neural Network, you need to read the paper titled "A resource usage prediction system using functional-link and genetic algorithm neural network for multivariate cloud metrics". The paper can be accessed at the following this link

Please include these citations if you plan to use this library:

```code @software{nguyenvanthieu20238249046, author = {Nguyen Van Thieu}, title = {Revolutionizing Functional Link Neural Network by Metaheuristic Algorithms: reflame - A Python Library}, month = 11, year = 2023, publisher = {Zenodo}, doi = {10.5281/zenodo.8249045}, url = {https://github.com/thieu1995/reflame} }

@article{van2023mealpy, title={MEALPY: An open-source library for latest meta-heuristic algorithms in Python}, author={Van Thieu, Nguyen and Mirjalili, Seyedali}, journal={Journal of Systems Architecture}, year={2023}, publisher={Elsevier}, doi={10.1016/j.sysarc.2023.102871} }

@inproceedings{nguyen2019building, author = {Thieu Nguyen and Binh Minh Nguyen and Giang Nguyen}, booktitle = {International Conference on Theory and Applications of Models of Computation}, organization = {Springer}, pages = {501--517}, title = {Building Resource Auto-scaler with Functional-Link Neural Network and Adaptive Bacterial Foraging Optimization}, year = {2019}, url={https://doi.org/10.1007/978-3-030-14812-631}, doi={10.1007/978-3-030-14812-631} }

@inproceedings{nguyen2018resource, author = {Thieu Nguyen and Nhuan Tran and Binh Minh Nguyen and Giang Nguyen}, booktitle = {2018 IEEE 11th Conference on Service-Oriented Computing and Applications (SOCA)}, organization = {IEEE}, pages = {49--56}, title = {A Resource Usage Prediction System Using Functional-Link and Genetic Algorithm Neural Network for Multivariate Cloud Metrics}, year = {2018}, url={https://doi.org/10.1109/SOCA.2018.00014}, doi={10.1109/SOCA.2018.00014} }

```

Installation

  • Install the current PyPI release: sh $ pip install reflame==1.0.1

  • Install directly from source code sh $ git clone https://github.com/thieu1995/reflame.git $ cd reflame $ python setup.py install

  • In case, you want to install the development version from Github: sh $ pip install git+https://github.com/thieu1995/reflame

After installation, you can import Reflame as any other Python module:

```sh $ python

import reflame reflame.version ```

Examples

In this section, we will explore the usage of the Reflame model with the assistance of a dataset. While all the preprocessing steps mentioned below can be replicated using Scikit-Learn, we have implemented some utility functions to provide users with convenience and faster usage.

Combine Reflame library like a normal library with scikit-learn.

```python

Step 1: Importing the libraries

import pandas as pd from sklearn.modelselection import traintest_split from sklearn.preprocessing import MinMaxScaler, LabelEncoder from reflame import FlnnRegressor, FlnnClassifier, MhaFlnnRegressor, MhaFlnnClassifier

Step 2: Reading the dataset

dataset = pd.readcsv('PositionSalaries.csv') X = dataset.iloc[:, 1:2].values y = dataset.iloc[:, 2].values

Step 3: Next, split dataset into train and test set

Xtrain, Xtest, ytrain, ytest = traintestsplit(X, y, testsize=0.2, shuffle=True, randomstate=100)

Step 4: Feature Scaling

scalerX = MinMaxScaler() scalerX.fit(Xtrain) Xtrain = scalerX.transform(Xtrain) Xtest = scalerX.transform(X_test)

ley = LabelEncoder() # This is for classification problem only ley.fit(y) ytrain = ley.transform(ytrain) ytest = ley.transform(ytest)

Step 5: Fitting FLNN-based model to the dataset

5.1: Use standard FLNN model for regression problem

regressor = FlnnRegressor(expandname="chebyshev", nfuncs=4, actname="elu", objname="MSE", maxepochs=100, batchsize=32, optimizer="SGD", verbose=True) regressor.fit(Xtrain, ytrain)

5.2: Use standard FLNN model for classification problem

classifer = FlnnClassifier(expandname="chebyshev", nfuncs=4, actname="sigmoid", objname="BCEL", maxepochs=100, batchsize=32, optimizer="SGD", verbose=True) classifer.fit(Xtrain, ytrain)

5.3: Use Metaheuristic-based FLNN model for regression problem

print(MhaFlnnClassifier.SUPPORTEDOPTIMIZERS) print(MhaFlnnClassifier.SUPPORTEDREGOBJECTIVES) optparas = {"name": "GA", "epoch": 10, "popsize": 30} model = MhaFlnnRegressor(expandname="chebyshev", nfuncs=3, actname="elu", objname="RMSE", optimizer="BaseGA", optimizerparas=optparas, verbose=True) regressor.fit(Xtrain, y_train)

5.4: Use Metaheuristic-based FLNN model for classification problem

print(MhaFlnnClassifier.SUPPORTEDOPTIMIZERS) print(MhaFlnnClassifier.SUPPORTEDCLSOBJECTIVES) optparas = {"name": "GA", "epoch": 10, "popsize": 30} classifier = MhaFlnnClassifier(expandname="chebyshev", nfuncs=4, actname="sigmoid", objname="NPV", optimizer="BaseGA", optimizerparas=optparas, verbose=True) classifier.fit(Xtrain, y_train)

Step 6: Predicting a new result

ypred = regressor.predict(Xtest)

ypredcls = classifier.predict(Xtest) ypredlabel = ley.inversetransform(ypred_cls)

Step 7: Calculate metrics using score or scores functions.

print("Try my AS metric with score function") print(regressor.score(Xtest, ytest, method="AS"))

print("Try my multiple metrics with scores function") print(classifier.scores(Xtest, ytest, list_methods=["AS", "PS", "F1S", "CEL", "BSL"])) ```

Utilities everything that Reflame provided

```python

Step 1: Importing the libraries

from reflame import Data, FlnnRegressor, FlnnClassifier, MhaFlnnRegressor, MhaFlnnClassifier from sklearn.datasets import load_digits

Step 2: Reading the dataset

X, y = loaddigits(returnX_y=True) data = Data(X, y)

Step 3: Next, split dataset into train and test set

data.splittraintest(testsize=0.2, shuffle=True, randomstate=100)

Step 4: Feature Scaling

data.Xtrain, scalerX = data.scale(data.Xtrain, scalingmethods=("minmax")) data.Xtest = scalerX.transform(data.X_test)

data.ytrain, scalery = data.encodelabel(data.ytrain) # This is for classification problem only data.ytest = scalery.transform(data.y_test)

Step 5: Fitting FLNN-based model to the dataset

5.1: Use standard FLNN model for regression problem

regressor = FlnnRegressor(expandname="chebyshev", nfuncs=4, actname="tanh", objname="MSE", maxepochs=100, batchsize=32, optimizer="SGD", verbose=True) regressor.fit(data.Xtrain, data.ytrain)

5.2: Use standard FLNN model for classification problem

classifer = FlnnClassifier(expandname="chebyshev", nfuncs=4, actname="tanh", objname="BCEL", maxepochs=100, batchsize=32, optimizer="SGD", verbose=True) classifer.fit(data.Xtrain, data.ytrain)

5.3: Use Metaheuristic-based FLNN model for regression problem

print(MhaFlnnClassifier.SUPPORTEDOPTIMIZERS) print(MhaFlnnClassifier.SUPPORTEDREGOBJECTIVES) optparas = {"name": "GA", "epoch": 10, "popsize": 30} model = MhaFlnnRegressor(expandname="chebyshev", nfuncs=3, actname="elu", objname="RMSE", optimizer="BaseGA", optimizerparas=optparas, verbose=True) regressor.fit(data.Xtrain, data.y_train)

5.4: Use Metaheuristic-based FLNN model for classification problem

print(MhaFlnnClassifier.SUPPORTEDOPTIMIZERS) print(MhaFlnnClassifier.SUPPORTEDCLSOBJECTIVES) optparas = {"name": "GA", "epoch": 10, "popsize": 30} classifier = MhaFlnnClassifier(expandname="chebyshev", nfuncs=4, actname="sigmoid", objname="NPV", optimizer="BaseGA", optimizerparas=optparas, verbose=True) classifier.fit(data.Xtrain, data.y_train)

Step 6: Predicting a new result

ypred = regressor.predict(data.Xtest)

ypredcls = classifier.predict(data.Xtest) ypredlabel = scalery.inversetransform(ypred_cls)

Step 7: Calculate metrics using score or scores functions.

print("Try my AS metric with score function") print(regressor.score(data.Xtest, data.ytest, method="AS"))

print("Try my multiple metrics with scores function") print(classifier.scores(data.Xtest, data.ytest, list_methods=["AS", "PS", "F1S", "CEL", "BSL"])) ```

A real-world dataset contains features that vary in magnitudes, units, and range. We would suggest performing normalization when the scale of a feature is irrelevant or misleading. Feature Scaling basically helps to normalize the data within a particular range.

1) Where do I find the supported metrics like above ["AS", "PS", "RS"]. What is that? You can find it here: https://github.com/thieu1995/permetrics or use this

```python from reflame import MhaFlnnClassifier, MhaFlnnRegressor

print(MhaFlnnRegressor.SUPPORTEDREGOBJECTIVES) print(MhaFlnnClassifier.SUPPORTEDCLSOBJECTIVES) ```

2) I got this type of error python raise ValueError("Existed at least one new label in y_pred.") ValueError: Existed at least one new label in y_pred. How to solve this?

  • This occurs only when you are working on a classification problem with a small dataset that has many classes. For instance, the "Zoo" dataset contains only 101 samples, but it has 7 classes. If you split the dataset into a training and testing set with a ratio of around 80% - 20%, there is a chance that one or more classes may appear in the testing set but not in the training set. As a result, when you calculate the performance metrics, you may encounter this error. You cannot predict or assign new data to a new label because you have no knowledge about the new label. There are several solutions to this problem.

  • 1st: Use the SMOTE method to address imbalanced data and ensure that all classes have the same number of samples.

```python import pandas as pd from imblearn.over_sampling import SMOTE from reflame import Data

dataset = pd.readcsv('examples/dataset.csv', indexcol=0).values X, y = dataset[:, 0:-1], dataset[:, -1]

Xnew, ynew = SMOTE().fitresample(X, y) data = Data(Xnew, y_new) ```

  • 2nd: Use different randomstate numbers in splittrain_test() function.

```python import pandas as pd from reflame import Data

dataset = pd.readcsv('examples/dataset.csv', indexcol=0).values X, y = dataset[:, 0:-1], dataset[:, -1] data = Data(X, y) data.splittraintest(testsize=0.2, randomstate=10) # Try different random_state value ```

Support (questions, problems)

Official Links

  • Official source code repo: https://github.com/thieu1995/reflame
  • Official document: https://reflame.readthedocs.io/
  • Download releases: https://pypi.org/project/reflame/
  • Issue tracker: https://github.com/thieu1995/reflame/issues
  • Notable changes log: https://github.com/thieu1995/reflame/blob/master/ChangeLog.md
  • Official chat group: https://t.me/+fRVCJGuGJg1mNDg1

  • This project also related to our another projects which are "optimization" and "machine learning", check it here:

    • https://github.com/thieu1995/mealpy
    • https://github.com/thieu1995/metaheuristics
    • https://github.com/thieu1995/opfunu
    • https://github.com/thieu1995/enoppy
    • https://github.com/thieu1995/permetrics
    • https://github.com/thieu1995/MetaCluster
    • https://github.com/thieu1995/pfevaluator
    • https://github.com/thieu1995/intelelm
    • https://github.com/aiir-team

Owner

  • Name: Nguyen Van Thieu
  • Login: thieu1995
  • Kind: user
  • Location: Earth
  • Company: AIIR Group

Knowledge is power, sharing it is the premise of progress in life. It seems like a burden to someone, but it is the only way to achieve immortality.

Citation (CITATION.cff)

cff-version: 1.1.0
message: "If you use this software, please cite it as below."
authors:
  - family-names: "Van Thieu"
    given-names: "Nguyen"
    orcid: "https://orcid.org/0000-0001-9994-8747"
title: "Revolutionizing Functional Link Neural Network by Metaheuristic Algorithms: reflame - A Python Library"
version: 1.0.1
doi: 10.5281/zenodo.10067995
date-released: 2023-11-26
url: "https://github.com/thieu1995/reflame"

GitHub Events

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

Committers

Last synced: over 1 year ago

All Time
  • Total Commits: 55
  • Total Committers: 2
  • Avg Commits per committer: 27.5
  • Development Distribution Score (DDS): 0.218
Past Year
  • Commits: 44
  • Committers: 2
  • Avg Commits per committer: 22.0
  • Development Distribution Score (DDS): 0.273
Top Committers
Name Email Commits
Thieu Nguyen n****2@g****m 43
Thieu t****n@p****n 12
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 5 months ago

All Time
  • Total issues: 0
  • Total pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 0
  • Total 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
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
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 16 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 2
  • Total maintainers: 1
pypi.org: reflame

Revolutionizing Functional Link Neural Network by Metaheuristic Algorithms: reflame - A Python Library

  • Versions: 2
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 16 Last month
Rankings
Dependent packages count: 9.6%
Forks count: 29.9%
Stargazers count: 32.0%
Average: 34.9%
Dependent repos count: 68.0%
Maintainers (1)
Last synced: 5 months ago