Skip to content

Commit

Permalink
add descriptive statistics to product distribution op
Browse files Browse the repository at this point in the history
  • Loading branch information
jmhorcas committed May 20, 2024
1 parent bb45395 commit 80e377a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import math
from collections import defaultdict
from typing import cast

from dd.autoref import Function
from typing import cast, Any
import statistics

from flamapy.core.models import VariabilityModel
from flamapy.metamodels.bdd_metamodel.models import BDDModel
Expand All @@ -24,6 +23,29 @@ def get_result(self) -> list[int]:

def product_distribution(self) -> list[int]:
return self.get_result()

def descriptive_statistics(self) -> dict[str, Any]:
if not self._result:
return {}
else:
return descriptive_statistics(self._result)


def descriptive_statistics(prod_dist: list[int]) -> dict[str, Any]:
values = [i for i in range(len(prod_dist)) for _ in range(prod_dist[i])]
min_dist = min(values)
max_dist = max(values)
median = statistics.median(values)
result = {'Mean': statistics.mean(values),
'Standard deviation': statistics.stdev(values),
'Median': median,
'Median absolute deviation': statistics.median([abs(n - median) for n in values]),
'Mode': statistics.mode(values),
'Min': min_dist,
'Max': max_dist,
'Range': max_dist - min_dist}
return result



def product_distribution(bdd_model: BDDModel) -> list[int]:
Expand Down Expand Up @@ -58,7 +80,7 @@ def product_distribution(bdd_model: BDDModel) -> list[int]:


def get_prod_dist(bdd_model: BDDModel,
node: Function,
node: Any,
dist: dict[int, list[int]],
mark: dict[int, bool],
complemented: bool) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class FeatureInclusionProbability(Operation):
The other two core metrics are the number of features the SPL manages,
and the number of valid product that can be derived.
Ref.: [Heradio et al. 2019. Supporting the Statistical Analysis of Variability Models. SPLC.
Ref.: [Heradio et al. 2019. Supporting the Statistical Analysis of Variability Models.
(https://doi.org/10.1109/ICSE.2019.00091)]
"""

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from abc import abstractmethod
from typing import Any

from flamapy.core.operations import Operation

Expand All @@ -10,6 +11,11 @@ class ProductDistribution(Operation):
It accounts for how many products have no features, one features,
two features, ..., all features.
This operation also provides a descriptive statistics summarizing the product distribution of
a variability model. Concretely, it provides:
Mean, Standard deviation, Median, Median absolute deviation, Mode, Min, Max, and Range, of the
product distribution of the variability model.
This operation in combination with the Feature Inclusion Probability (FIP) operation
provides a clear picture of the products' homogeneity (i.e., how much does one product
differ from the others).
Expand All @@ -18,7 +24,7 @@ class ProductDistribution(Operation):
The other two core metrics are the number of features the SPL manages,
and the number of valid product that can be derived.
Ref.: [Heradio et al. 2019. Supporting the Statistical Analysis of Variability Models. SPLC.
Ref.: [Heradio et al. 2019. Supporting the Statistical Analysis of Variability Models.
(https://doi.org/10.1109/ICSE.2019.00091)]
"""

Expand All @@ -29,3 +35,7 @@ def __init__(self) -> None:
@abstractmethod
def product_distribution(self) -> list[int]:
pass

@abstractmethod
def descriptive_statistics(self) -> dict[str, Any]:
pass
6 changes: 5 additions & 1 deletion tests/test_bdd_metamodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,13 @@ def analyze_bdd(bdd_model: BDDModel) -> None:
# print(f'Config {i}: {config.get_selected_elements()}')

# BDD product distribution
dist = BDDProductDistribution().execute(bdd_model).get_result()
dist_op = BDDProductDistribution().execute(bdd_model)
dist = dist_op.get_result()
ds_dist = dist_op.descriptive_statistics()
print(f'Product Distribution: {dist}')
print(f'#Products: {sum(dist)}')
for ds, v in ds_dist.items():
print(f'{ds}: {v}')

# BDD feature inclusion probabilities
probabilities = BDDFeatureInclusionProbability().execute(bdd_model).get_result()
Expand Down

0 comments on commit 80e377a

Please sign in to comment.