def test_WeightedProductModel_enwiki_1015567716(): """ Data from: Weighted product model. (n.d.). Retrieved January 07, 2017, from http://en.wikipedia.org/wiki/Weighted_product_model """ dm = skcriteria.mkdm( matrix=[ [25, 20, 15, 30], [10, 30, 20, 30], [30, 10, 30, 10], ], objectives=[max, max, max, max], weights=[20, 15, 40, 25], ) expected = RankResult( "WeightedProductModel", ["A0", "A1", "A2"], [1, 2, 3], {"score": [-0.50128589, -0.50448471, -0.52947246]}, ) transformer = SumScaler(target="both") dm = transformer.transform(dm) ranker = WeightedProductModel() result = ranker.evaluate(dm) assert result.equals(expected) assert result.method == expected.method assert np.allclose(result.e_.score, expected.e_.score)
def test_SumScaler_both(decision_matrix): dm = decision_matrix( seed=42, min_alternatives=10, max_alternatives=10, min_criteria=20, max_criteria=20, min_objectives_proportion=0.5, ) matrix = dm.matrix.to_numpy() expected = skcriteria.mkdm( matrix=matrix / np.sum(matrix, axis=0, keepdims=True, dtype=float), objectives=dm.objectives, weights=dm.weights / np.sum(dm.weights), alternatives=dm.alternatives, criteria=dm.criteria, dtypes=dm.dtypes, ) scaler = SumScaler(target="both") result = scaler.transform(dm) assert result.equals(expected)
def test_ELECTRE2_cebrian2009localizacion(): """ Data From: Cebrián, L. I. G., & Porcar, A. M. (2009). Localización empresarial en Aragón: Una aplicación empírica de la ayuda a la decisión multicriterio tipo ELECTRE I y III. Robustez de los resultados obtenidos. Revista de Métodos Cuantitativos para la Economía y la Empresa, (7), 31-56. """ dm = skcriteria.mkdm( matrix=[ [6, 5, 28, 5, 5], [4, 2, 25, 10, 9], [5, 7, 35, 9, 6], [6, 1, 27, 6, 7], [6, 8, 30, 7, 9], [5, 6, 26, 4, 8], ], objectives=[1, 1, -1, 1, 1], weights=[0.25, 0.25, 0.1, 0.2, 0.2], ) scaler = SumScaler("both") dm = scaler.transform(dm) kselector = ELECTRE2() result = kselector.evaluate(dm) assert np.all(result.rank_ == [3, 2, 1, 3, 1, 3]) np.testing.assert_allclose(result.e_.score, [2.0, 1.5, 1.0, 2.0, 1.0, 2.0])
def test_SumScaler_no_change_original_dm(decision_matrix): dm = decision_matrix( seed=42, min_alternatives=10, max_alternatives=10, min_criteria=20, max_criteria=20, min_objectives_proportion=0.5, ) expected = dm.copy() scaler = SumScaler(target="both") dmt = scaler.transform(dm) assert ( dm.equals(expected) and not dmt.equals(expected) and dm is not expected )
def test_SumScaler_simple_both(): dm = skcriteria.mkdm( matrix=[[1, 2, 3], [4, 5, 6]], objectives=[min, max, min], weights=[1, 2, 3], ) expected = skcriteria.mkdm( matrix=[[1 / 5, 2 / 7, 3 / 9], [4 / 5, 5 / 7, 6 / 9]], objectives=[min, max, min], weights=[1 / 6, 2 / 6, 3 / 6], dtypes=[float, float, float], ) scaler = SumScaler(target="both") result = scaler.transform(dm) assert result.equals(expected)
def test_SumScaler_simple_weights(): dm = skcriteria.mkdm( matrix=[[1, 2, 3], [4, 5, 6]], objectives=[min, max, min], weights=[1, 2, 3], ) expected = skcriteria.mkdm( matrix=[[1, 2, 3], [4, 5, 6]], objectives=[min, max, min], weights=[1 / 6, 2 / 6, 3 / 6], dtypes=[int, int, int], ) scaler = SumScaler(target="weights") result = scaler.transform(dm) assert result.equals(expected)
def test_WeightedSumModel_kracka2010ranking(): """ Data from: KRACKA, M; BRAUERS, W. K. M.; ZAVADSKAS, E. K. Ranking Heating Losses in a Building by Applying the MULTIMOORA. - ISSN 1392 - 2785 Inzinerine Ekonomika-Engineering Economics, 2010, 21(4), 352-359. """ dm = skcriteria.mkdm( matrix=[ [33.95, 23.78, 11.45, 39.97, 29.44, 167.10, 3.852], [38.9, 4.17, 6.32, 0.01, 4.29, 132.52, 25.184], [37.59, 9.36, 8.23, 4.35, 10.22, 136.71, 10.845], [30.44, 37.59, 13.91, 74.08, 45.10, 198.34, 2.186], [36.21, 14.79, 9.17, 17.77, 17.06, 148.3, 6.610], [37.8, 8.55, 7.97, 2.35, 9.25, 134.83, 11.935], ], objectives=[min, min, min, min, max, min, max], weights=[20, 20, 20, 20, 20, 20, 20], ) transformers = [ InvertMinimize(), SumScaler(target="both"), ] for t in transformers: dm = t.transform(dm) expected = RankResult( "WeightedSumModel", ["A0", "A1", "A2", "A3", "A4", "A5"], [6, 1, 3, 4, 5, 2], { "score": [ 0.12040426, 0.3458235, 0.13838192, 0.12841246, 0.12346084, 0.14351701, ] }, ) ranker = WeightedSumModel() result = ranker.evaluate(dm) assert result.equals(expected) assert result.method == expected.method assert np.allclose(result.e_.score, expected.e_.score)
def test_ELECTRE1_kernel_sensibility_barba1997decisiones(): """ Data From: Barba-Romero, S., & Pomerol, J. C. (1997). Decisiones multicriterio: fundamentos teóricos y utilización práctica. P.216 """ dm = skcriteria.mkdm( matrix=[ [0.188, 0.172, 0.168, 0.122, 0.114], [0.125, 0.069, 0.188, 0.244, 0.205], [0.156, 0.241, 0.134, 0.220, 0.136], [0.188, 0.034, 0.174, 0.146, 0.159], [0.188, 0.276, 0.156, 0.171, 0.205], [0.156, 0.207, 0.180, 0.098, 0.182], ], weights=[0.25, 0.25, 0.10, 0.20, 0.20], objectives=[1, 1, 1, 1, 1], alternatives=["A", "B", "D", "E", "G", "H"], ) ps = [0.50, 0.60, 0.70, 0.80, 0.89, 0.89, 0.89, 0.94, 1] qs = [0.50, 0.40, 0.30, 0.20, 0.10, 0.08, 0.05, 0.05, 0] scaler = SumScaler("both") dm = scaler.transform(dm) kernels_len = [] for p, q in zip(ps, qs): kselector = ELECTRE1(p=p, q=q) dec = kselector.evaluate(dm) klen = len(dec.kernel_) if kernels_len and klen < kernels_len[-1]: pytest.fail("less sensitive electre must have more " f"alternatives in kernel. {kernels_len}") kernels_len.append(klen)
def test_SumScaler_weights(decision_matrix): dm = decision_matrix( seed=42, min_alternatives=10, max_alternatives=10, min_criteria=20, max_criteria=20, min_objectives_proportion=0.5, ) expected = skcriteria.mkdm( matrix=dm.matrix, objectives=dm.objectives, weights=dm.weights / np.sum(dm.weights), alternatives=dm.alternatives, criteria=dm.criteria, dtypes=dm.dtypes, ) scaler = SumScaler(target="weights") result = scaler.transform(dm) assert result.equals(expected)