Skip to content

Commit

Permalink
topsis tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leliel12 committed Jan 7, 2017
1 parent 058268d commit 53e8b33
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
61 changes: 61 additions & 0 deletions skcriteria/tests/test_topsis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# License: 3 Clause BSD
# http://scikit-criteria.org/


# =============================================================================
# FUTURE
# =============================================================================

from __future__ import unicode_literals


# =============================================================================
# DOC
# =============================================================================

__doc__ = """test topsis methods"""


# =============================================================================
# IMPORTS
# =============================================================================

from . import core

from .. import topsis
from ..common import util


# =============================================================================
# BASE CLASS
# =============================================================================

class TopsisTest(core.SKCriteriaTestCase):

def setUp(self):
# Data From:
# Tzeng, G. H., & Huang, J. J. (2011).
# Multiple attribute decision making: methods and applications.
# CRC press.
self.mtx = [
[5, 8, 4],
[7, 6, 8],
[8, 8, 6],
[7, 4, 6],
]
self.criteria = [util.MAX, util.MAX, util.MAX]

def test_topsis(self):
weights = [.3, .4, .3]

result = [3, 2, 1, 4]
points = [0.5037, 0.6581, 0.7482, 0.3340]

rank_result, points_result = topsis.topsis(
self.mtx, self.criteria, weights)

self.assertAllClose(points_result, points, atol=1.e-4)
self.assertAllClose(rank_result, result)
2 changes: 1 addition & 1 deletion skcriteria/topsis.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def topsis(mtx, criteria, weights=1):
nmtx = norm.vector(mtx, axis=0)

# apply weights
nweights = norm.vector(weights) if weights is not None else 1
nweights = norm.sum(weights) if weights is not None else 1
wmtx = np.multiply(nmtx, nweights)

# extract mins and maxes
Expand Down

0 comments on commit 53e8b33

Please sign in to comment.