Example 02: Linguistic scales and expert aggregation¶
Three experts rate two suppliers on two criteria with words from a linguistic scale; the words become intuitionistic numbers and are aggregated.
Source¶
examples/02_scale_and_experts.py
"""Linguistic scales: three experts rate two suppliers on two criteria."""
from bulanik.aggregate import aggregate_experts
from bulanik.scales import EXAMPLE_IFN_5
scale = EXAMPLE_IFN_5
# ratings[expert][supplier][criterion], written as scale terms
words = [
[["H", "M"], ["VH", "L"]], # expert 1
[["M", "M"], ["H", "VL"]], # expert 2
[["VH", "L"], ["M", "L"]], # expert 3
]
ratings = scale.convert(words)
weights = [0.4, 0.35, 0.25] # expert importance
matrix = aggregate_experts(ratings, weights, method="wa")
for s, row in enumerate(matrix):
for c, agg in enumerate(row):
mus = [r[s][c].mu for r in ratings]
nus = [r[s][c].nu for r in ratings]
assert 0.0 <= agg.mu and 0.0 <= agg.nu and agg.mu + agg.nu <= 1.0
# mu and nu are weighted geometric means of (1 - mu) and nu, so each stays
# inside the range of the opinions it mixes (the score mu - nu need not)
assert min(mus) - 1e-9 <= agg.mu <= max(mus) + 1e-9
assert min(nus) - 1e-9 <= agg.nu <= max(nus) + 1e-9
print(f"aggregated: supplier {s + 1}, criterion {c + 1}: {agg} score {agg.score():.3f}")
Output¶
Run when this page is built:
aggregated: supplier 1, criterion 1: IFN(mu=0.7274237556337286, nu=0.18025009252216603) score 0.547
aggregated: supplier 1, criterion 2: IFN(mu=0.45612134703136137, nu=0.4426727678801286) score 0.013
aggregated: supplier 2, criterion 1: IFN(mu=0.7803481121641287, nu=0.13660402567543956) score 0.644
aggregated: supplier 2, criterion 2: IFN(mu=0.23563885149583932, nu=0.6635594036922036) score -0.428
What to notice¶
convertturns nested lists of words into numbers without a loop of your own.aggregate_expertstakes[expert][alternative][criterion]and returns[alternative][criterion].- Supplier 2 / criterion 2 ends with a negative difference score: the experts' non-membership outweighs membership.
Go further¶
- Guide: Sets and scales
- Guide: Aggregation
- API:
bulanik.scales - API:
bulanik.aggregate
Run it yourself: python examples/02_scale_and_experts.py.