Skip to content

Commit

Permalink
feat : Braun-Blanquet-similarity added #349
Browse files Browse the repository at this point in the history
  • Loading branch information
sepandhaghighi committed Aug 10, 2022
1 parent db48191 commit 5328cd5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
19 changes: 19 additions & 0 deletions pycm/pycm_class_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,24 @@ def OC_calc(TP, TOP, P):
except (ZeroDivisionError, TypeError):
return "None"

def BB_calc(TP, TOP, P):
"""
Calculate Braun-Blanquet similarity (BB).
:param TP: true positive
:type TP: int
:param TOP: number of positives in predict vector
:type TOP: int
:param P: number of actual positives
:type P: int
:return: BB as float
"""
try:
BB = TP / max(TOP, P)
return BB
except (ZeroDivisionError, TypeError):
return "None"


def AGF_calc(TP, FP, FN, TN):
"""
Expand Down Expand Up @@ -790,6 +808,7 @@ def class_statistics(TP, TN, FP, FN, classes, table):
result["MCCI"][i] = MCC_analysis(result["MCC"][i])
result["AGF"][i] = AGF_calc(TP[i], FP[i], FN[i], TN[i])
result["OC"][i] = OC_calc(TP[i], result["TOP"][i], result["P"][i])
result["BB"][i] = BB_calc(TP[i], result["TOP"][i], result["P"][i])
result["OOC"][i] = OOC_calc(TP[i], result["TOP"][i], result["P"][i])
result["AUPR"][i] = AUC_calc(result["PPV"][i], result["TPR"][i])
result["ICSI"][i] = MK_BM_calc(result["PPV"][i], result["TPR"][i])
Expand Down
2 changes: 1 addition & 1 deletion pycm/pycm_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __class_stat_init__(cm):
cm.AUPR = cm.class_stat["AUPR"]
cm.ICSI = cm.class_stat["ICSI"]
cm.HD = cm.class_stat["HD"]

cm.BB = cm.class_stat["BB"]

def __overall_stat_init__(cm):
"""
Expand Down
9 changes: 6 additions & 3 deletions pycm/pycm_param.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@
"AUPR",
"ICSI",
"QI",
"HD"]
"HD",
"BB"]

SUMMARY_OVERALL = [
"ACC Macro",
Expand Down Expand Up @@ -455,7 +456,8 @@
"OOC": "Otsuka-Ochiai coefficient",
"AUPR": "Area under the PR curve",
"ICSI": "Individual classification success index",
"HD": "Hamming distance"}
"HD": "Hamming distance",
"BB": "Braun-Blanquet similarity"}

PARAMS_LINK = {
"TPR": "TPR-(True-positive-rate)",
Expand Down Expand Up @@ -582,7 +584,8 @@
"ARI": "ARI-(Adjusted-Rand-index)",
"Bangdiwala B": "Bangdiwala's-B",
"Krippendorff Alpha": "Krippendorff's-alpha",
"HD": "HD-(Hamming-distance)"}
"HD": "HD-(Hamming-distance)",
"BB": "BB-(Braun-Blanquet-similarity)"}

CAPITALIZE_FILTER = ["BCD", "AUCI", "Q", "AGF", "OOC", "AUPR", "AUC", "QI"]

Expand Down

0 comments on commit 5328cd5

Please sign in to comment.