A library for String Grammar Possibilistic Fuzzy C-Medians
Project description
What is String Grammar Fuzzy Clustering?
String Grammar Fuzzy Clustering is a clustering framework designed for syntactic or structural pattern recognition, where each data instance is represented not as a numeric vector but as a string that encodes structural information.
Unlike conventional numerical clustering method (e.g., Fuzzy C-Means), which assume that data have a fixed-length feature vector whereas structural clustering method operates directly on string data whose lengths and internal structures may vary.
In this approach, each pattern is described by a sequence of primitives (symbols) defined by grammatical rules. This is similar to how a sentence is formed from characters following syntax rules.
To measure similarity between strings, the method employs the Levenshtein distance[1], which counts the minimum number of edit operations (insertions, deletions, substitutions) required to transform on string into another.
The "fuzzy" aspect of this framework allows each string to belong to multiple clusters, with a membership degree that reflects how strongly it is associated with each cluster. This provides a more flexible and realistic clustering behavior compared to traditional "hard" clustering, which forces each sample to belong to only one group.
About This Library
This Python library introduces an algorithm belonging to the String Grammar Fuzzy Clustering framework, namely the String Grammar Possibilistic Fuzzy C-Medians (sgPFCMed).
String Grammar Possibilistic Fuzzy C-Medians (sgPFCMed)[2]
The sgPFCMed algorithm enhances the sgFCMed [3] algorithm by integrating possibilistic clustering theory, with both membership and typicality values (as in [4]) for each string. While membership reflects relative association of a string across clusters, typicality value represent a string within a single cluster. This combination allows sgPFCMed to produce more reliable and stable clustering results, especially in datasets with uncertain or overlapping string patterns.
Key Features:
- Integrates membership (U) and typicality (T) for dual uncertainty modeling
- Automatically updates γ (gamma) parameters per cluster
- Better resilience to noisy or ambiguous strings
- Parallelized medoid and modified median updates
- Suitable for real-world or imperfect string data where overlap and noise occur
**Please be noted that this sgPFCMed can be used for academic and research purposes only. Please also cite this paper [2].**
Reference
[1] S. K. Fu, Syntactic Pattern Recognition and Applications, 1982, Prentice-Hall, Zbl0521.68091.
[2] Atcharin Klomsae, Sansanee Auephanwiriyakul, and Nipon Theera-Umpon, “A string grammar possibilistic-fuzzy C-medians”, Soft Computing , vol. 23, no. 17, pp. 7637 – 7653, 2019: http://doi.org/10.1007/s00500-018-3392-6.
[3] Atcharin Klomsae, Sansanee Auephanwiriyakul, and Nipon Theera-Umpon, “A Novel String Grammar Fuzzy C-Medians,” Proceedings of the 2015 IEEE International Conference on Fuzzy Systems, Istanbul, Turkey, August 2015.
[4] N. R. Pal, K. Pal, J. M. Keller and J. C. Bezdek, "A possibilistic fuzzy c-means clustering algorithm," in IEEE Transactions on Fuzzy Systems, vol. 13, no. 4, pp. 517-530, Aug. 2005
Installation
You can install the library using pip:
pip install sgPFCMed
USAGE
Example Code
import random
from sgPFCMed import SGPFCMed # Import the clustering class
if __name__ == "__main__":
# Set random seed for reproducibility
random.seed(42)
# Define a list of strings to cluster
data = ["book", "back", "boon", "cook", "look", "cool", "kick", "lack", "rack", "tack"]
# Create the model with 2 clusters and fuzzifier m=2.0
model = SGPFCMed(C=2, m=2.0)
# Fit the model on the data
model.fit(data)
# Print the final prototype strings representing each cluster
print("Prototypes:", model.prototypes())
# Print the fuzzy membership matrix for each input string
print("\nMembership Matrix (U):")
for s, u in zip(data, model.membership()):
print(f"{s:>6} → {[round(val, 3) for val in u]}")
# Print the typicality matrix for each input string
print("\nTypicality Matrix (T):")
for s, t in zip(data, model.typicality()):
print(f"{s:>6} → {[round(val, 3) for val in t]}")
# Define new strings to classify using the trained model
new_data = ["hack", "rook", "cook"]
# Predict the cluster index (0 or 1) for each new string
preds = model.predict(new_data, model.prototypes())
print("\nPredictions:")
for s, c in zip(new_data, preds):
print(f"{s} → Cluster {c+1}")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sgpfcmed-0.0.2.tar.gz.
File metadata
- Download URL: sgpfcmed-0.0.2.tar.gz
- Upload date:
- Size: 3.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4417d2c5b175a8ea3cd6a7061e1f921224787f78be5511ddd2c0a9e0dd15bb0e
|
|
| MD5 |
eb6a0c4acbd8ab96c32d61558617fc1b
|
|
| BLAKE2b-256 |
6dc6f5ae9192419fc7b1af9d89457f5a2354706ec320f711f6b6daec36d7cf92
|
File details
Details for the file sgpfcmed-0.0.2-py3-none-any.whl.
File metadata
- Download URL: sgpfcmed-0.0.2-py3-none-any.whl
- Upload date:
- Size: 4.1 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6449812b0ceabe0dc82c3b2950417506677ed78bf37dad725a0fbd7c2eba0daa
|
|
| MD5 |
be2508e1a372a6eeb4e22f7db0c7ea8b
|
|
| BLAKE2b-256 |
06baf6a4e90300e4edc0bd72b4c9c08027039460ffd24866bce9015e6a5deec3
|