Search code examples
pythonmcdm

How to set weights with pyDecision


I'm trying to figure out how to set weights in a MAUT excercise in which I follow this pyDecision example. In my evaluation matrix I have 68 measurement criteria and they belong to 7 different main criteria. It is on these 7 main criteria I want to set the weights to, and absolutely not onto every one of the 68 measurement criteria. You can assume, that in the dataset

the first 5 values belong to the first main criteria;

the next 4 to the second main criteria;

the next 14 to the third main criteria;

the next 11 to the fourth main criteria;

the next 20 to the fifth main criteria;

the next 11 to the sixth main criteria;

and the last 3 the seventh main criteria

How could this be done?

Here's my code

# Required Libraries
import pyDecision
import numpy as np

from pyDecision.algorithm import maut_method

weights = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0] #This is the tricky part. It should sum up to 1

#Here I have 68 criterion types, one for every measurement criteria
criterion_type    = ['min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'min', 'max', 'max', 'max', 'max', 'max', 'max', 'max', 'max', 'max', 'max', 'min', 'max', 'min']

# Load Utility Functions: 'exp'; 'ln'; 'log'; 'quad' or 'step' 
# Possibly the amount of utility functions defined here should be 68 as well?
utility_functions = ['exp', 'exp', 'exp', 'exp', 'exp', 'exp', 'exp', 'exp', 'exp', 'exp']

# In this dataset, every value is a measurement criteria, and every row belongs to one of the five decision alternatives
dataset = np.array([
                    [1, 1, 1, 1, 1, 2, 2, 2, 3, 59.4, 4.13, 4, 4, 2, 3, 4, 1, 1, 1, 1, 1, 1, 1, 1550, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.43, 187, 1.87e-05, 0.0698, 0.149, 1, 0.0398, 1, 1, 1, 1, 1, 1, 315, 6030, 1, 2910, 0.00134, 1, 183, 27.2, 30.6, 3, 48, 3, 23, 14, 3.3, 1, 3.65, 0.025, 2, 0.0], #A1
[1, 1, 1, 1, 1, 2, 2, 2, 3, 57.5, 5.04, 3, 3, 1, 3, 3, 1, 1, 1, 1, 1, 1, 1, 198, 1, 1, 1, 1, 1, 1, 1, 1, 1, 11, 357, 4.13e-05, 0.551, 1.47, 1, 0.12, 1, 1, 1, 1, 1, 1, 768, 8760, 1, 5770, 0.0214, 1, 218, 28, 32, 3.4, 22.1, 3, 27, 17, 13, 5, 8.936, 0.304, 2, 0.0], #A2
[1, 1, 1, 1, 1, 2, 2, 2, 3, 57.5, 5.04, 3, 3, 1, 3, 3, 1, 1, 1, 1, 1, 1, 1, 198, 1, 1, 1, 1, 1, 1, 1, 1, 1, 11, 357, 4.13e-05, 0.551, 1.47, 1, 0.12, 1, 1, 1, 1, 1, 1, 768, 8760, 1, 5770, 0.0214, 1, 218, 20, 30, 6.2, 26.1, 3, 27, 17, 13, 5, 8.936, 0.304, 2, 0.0], #A3
[1, 1, 1, 1, 1, 2, 2, 2, 3, 54.9, 2.58, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 8.7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.53, 216, 1.78e-05, 0.0706, 0.199, 1, 0.0364, 1, 1, 1, 1, 1, 1, 312, 5830, 1, 3400, 0.00133, 1, 227, 15, 19, 5.4, 20.8, 2, 21.5, 18.5, 8.6, 2.1, 1.125, 0.41, 2, 0.0], #A4
[1, 1, 1, 1, 1, 2, 2, 2, 3, 54.9, 2.58, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 8.7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.53, 216, 1.78e-05, 0.0706, 0.199, 1, 0.0364, 1, 1, 1, 1, 1, 1, 312, 5830, 1, 3400, 0.00133, 1, 227, 16, 22, 9.1, 41.2, 2, 21.5, 18.5, 8.6, 2.1, 1.125, 0.41, 2, 0.0] #A5
                   ])

# Call MAUT Function
rank = maut_method(dataset, weights, criterion_type, utility_functions, step_size, graph = True)

Solution

  • You can break it down to seven criteria and then pass it to maut_method():

    import pyDecision
    import numpy as np
    from pyDecision.algorithm import maut_method
    
    
    def get_ranks(D):
        Ws, Ds = [0.2, 0.1, 0.25, 0.15, 0.2, 0.05, 0.05], [5, 4, 14, 11, 20, 11, 3]
        weights = []
        for w, d in zip(Ws, Ds):
            weights.extend([w / d] * d)
    
        return maut_method(D, weights, ['min'] * 67 + ['max'], ['exp'] * 68, 0.01, graph=True)
    
    
    dataset = np.array([
        [1, 1, 1, 1, 1, 2, 2, 2, 3, 59.4, 4.13, 4, 4, 2, 3, 4, 1, 1, 1, 1, 1, 1, 1, 1550, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.43, 187, 1.87e-05, 0.0698,
            0.149, 1, 0.0398, 1, 1, 1, 1, 1, 1, 315, 6030, 1, 2910, 0.00134, 1, 183, 27.2, 30.6, 3, 48, 3, 23, 14, 3.3, 1, 3.65, 0.025, 2, 0.0],
        [1, 1, 1, 1, 1, 2, 2, 2, 3, 57.5, 5.04, 3, 3, 1, 3, 3, 1, 1, 1, 1, 1, 1, 1, 198, 1, 1, 1, 1, 1, 1, 1, 1, 1, 11, 357, 4.13e-05, 0.551,
            1.47, 1, 0.12, 1, 1, 1, 1, 1, 1, 768, 8760, 1, 5770, 0.0214, 1, 218, 28, 32, 3.4, 22.1, 3, 27, 17, 13, 5, 8.936, 0.304, 2, 0.0],
        [1, 1, 1, 1, 1, 2, 2, 2, 3, 57.5, 5.04, 3, 3, 1, 3, 3, 1, 1, 1, 1, 1, 1, 1, 198, 1, 1, 1, 1, 1, 1, 1, 1, 1, 11, 357, 4.13e-05, 0.551,
            1.47, 1, 0.12, 1, 1, 1, 1, 1, 1, 768, 8760, 1, 5770, 0.0214, 1, 218, 20, 30, 6.2, 26.1, 3, 27, 17, 13, 5, 8.936, 0.304, 2, 0.0],
        [1, 1, 1, 1, 1, 2, 2, 2, 3, 54.9, 2.58, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 8.7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.53, 216, 1.78e-05, 0.0706, 0.199,
            1, 0.0364, 1, 1, 1, 1, 1, 1, 312, 5830, 1, 3400, 0.00133, 1, 227, 15, 19, 5.4, 20.8, 2, 21.5, 18.5, 8.6, 2.1, 1.125, 0.41, 2, 0.0],
        [1, 1, 1, 1, 1, 2, 2, 2, 3, 54.9, 2.58, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 8.7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.53, 216, 1.78e-05, 0.0706, 0.199,
            1, 0.0364, 1, 1, 1, 1, 1, 1, 312, 5830, 1, 3400, 0.00133, 1, 227, 16, 22, 9.1, 41.2, 2, 21.5, 18.5, 8.6, 2.1, 1.125, 0.41, 2, 0.0]
    ])
    
    
    print(get_ranks(dataset))
    
    

    Prints

    The maut_method() prints a matrix where each row contains an alternative number and its corresponding utility value.

    a1: 0.813
    a2: 0.717
    a3: 0.715
    a4: 0.926
    a5: 0.916
    [[4.         0.92649844]
     [5.         0.91637153]
     [1.         0.81277224]
     [2.         0.71718458]
     [3.         0.71541932]]