Skip to content

Commit

Permalink
v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Fuminides committed Feb 10, 2025
1 parent ad7a013 commit 1ea9061
Show file tree
Hide file tree
Showing 94 changed files with 2,286 additions and 2,676 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@
All rights reserved
@author: Javier Fumanal Idocin - University of Essex
@author: Javier Andreu-Perez - University of Essex
This is a the source file that contains a demo for a tip computation example, where a diferent set of T1-FS are used to compute
a t1 reasoning approach.
We also show the GA to optimize the rules obtained in classification.
This is a the source file that contains a demo for an Iris classification example using a FRBC where we will also show different possible ways to print the rules, precompute the partitions, etc.
"""

Expand All @@ -22,14 +17,10 @@
import sys




# In case you run this without installing the package, you need to add the path to the package

# This is for launching from root folder path
sys.path.append('./ex_fuzzy/')
sys.path.append('./ex_fuzzy/ex_fuzzy/')

# This is for launching from Demos folder
sys.path.append('../ex_fuzzy/')
sys.path.append('../ex_fuzzy/ex_fuzzy/')
Expand All @@ -43,45 +34,47 @@

runner = 1 # 1: single thread, 2+: corresponding multi-thread

# GA parameters
n_gen = 5
n_pop = 30

nRules = 15
nAnts = 3
tolerance = 0.001

# FRBC parameters
nRules = 15 # Number of maximum rules
nAnts = 3 # Number of maximum antecedents per rule
vl = 3 # Number of linguistic variables
tolerance = 0.001 # Minimum dominance score to accept a rule
fz_type_studied = fs.FUZZY_SETS.t1 # Fuzzy set type


iris = datasets.load_iris()
X = pd.DataFrame(iris.data, columns=iris.feature_names)
y = pd.Series(iris.target)
class_names = iris.target_names
class_names = np.unique(y)
fz_type_studied = fs.FUZZY_SETS.t1
vl = 3



# Compute the fuzzy partitions using n linguistic variables
precomputed_partitions_vl = utils.construct_partitions(X, fz_type_studied, n_partitions=vl)

# Split the data into a training set and a test set
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=0)


# We create a FRBC with the precomputed partitions and the specified fuzzy set type,
# We create a FRBC with the precomputed partitions or None (will optimize them as well in that case) and the specified fuzzy set type
fl_classifier = GA.BaseFuzzyRulesClassifier(nRules=nRules, linguistic_variables=None, nAnts=nAnts, class_names=class_names, n_linguistic_variables=vl, fuzzy_type=fz_type_studied, verbose=True, tolerance=tolerance, runner=runner, allow_unknown=True, ds_mode=0)

# fl_classifier.customized_loss(utils.mcc_loss) Use this to change the loss function, but be sure to look at the API first
fl_classifier.fit(X_train, y_train, n_gen=n_gen, pop_size=n_pop, checkpoints=0, random_state=0, p_value_compute=True)

# print(vis_rules.rules_to_latex(fl_classifier.rule_base))
# We evaluate the fuzzy model, this will print the rules, the accuracy, the Matthew's correlation coefficient, etc.
fuzzy_evaluator = eval_tools.FuzzyEvaluator(fl_classifier)
str_rules = fuzzy_evaluator.eval_fuzzy_model(X_train, y_train, X_test, y_test,
plot_rules=False, print_rules=True, plot_partitions=False, return_rules=True)
rule_matrix = fl_classifier.rule_base.get_rulebase_matrix()
plot_rules=False, print_rules=True, plot_partitions=False, return_rules=True, bootstrap_results_print=True)

# print(vis_rules.rules_to_latex(fl_classifier.rule_base)) # Do this to print the rules in latex format

# Save the rules as a plain text file
with open('rules_iris_t2.txt', 'w') as f:
f.write(str_rules)
#with open('rules_iris_t2.txt', 'w') as f:
# f.write(str_rules)

# Compute the explainable predictions
# Compute the explainable predictions: this will return the predictions, the winning rules, the winning association degrees, and the confidence interval of the certainty of the predictions
y_pred, winning_rules, winning_association_degrees, conf_interval_certainty = fl_classifier.explainable_predict(X_test, out_class_names=True)
print('Done')

print('Done!')
Binary file modified docs/build/doctrees/api.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/classifiers.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/build/doctrees/extending.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/function_resume/centroid.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/function_resume/classifiers.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/function_resume/cognitive_maps.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/function_resume/eval_rules.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/function_resume/eval_tools.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/function_resume/evolutionary_fit.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/function_resume/fuzzy_sets.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/function_resume/pattern_stability.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/function_resume/persistence.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/function_resume/rule_mining.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/function_resume/rules.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/function_resume/temporal.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/function_resume/utils.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/function_resume/vis_rules.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/gt2.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/index.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/optimize.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/pattern_stats.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/persistence.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/precom.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/step1.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/step2.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/step3.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/step4.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/tmpfs.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/usage.doctree
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/build/html/.buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: bbbf35d0940a0dcfa2922ad1d1125950
config: 7184ad333879fb5e4f199b3de50a2caf
tags: 645f666f9bcd5a90fca523b33c5a78b7
1 change: 1 addition & 0 deletions docs/build/html/_modules/ex_fuzzy/classifiers.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<li class="toctree-l1"><a class="reference internal" href="../../extending.html">Extending Ex-Fuzzy</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../persistence.html">Persistence</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../classifiers.html">Advanced classifiers</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../pattern_stats.html">Bootstrapping and rule robustness</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../api.html">API</a></li>
</ul>

Expand Down
Loading

0 comments on commit 1ea9061

Please sign in to comment.