PhilipGriffith / AHPy

A Python implementation of the Analytic Hierarchy Process
MIT License
129 stars 29 forks source link

Document the difference between "local" and "global" weights? #6

Closed dfrankow closed 3 years ago

dfrankow commented 3 years ago

I am not sure of the precise definition of local and global weights. In particular, when they would be different.

It has something to do with this code in _apply_weights:

    def _apply_weight(self):
        """
        Updates the 'global_weights' dictionary of the Compare object, given the global weight of the node.
        """
        for key in self.global_weights:
            self.global_weights[key] = np.round(self.weight * self.local_weights[key], self.precision)

The "Choosing a leader" example in the docs shows different local and global weights:

>>> print(experience.local_weights)
{'Nell': 0.717, 'Moll': 0.217, 'Sue': 0.066}
>>> print(experience.consistency_ratio)
0.035
>>> print(experience.weight)
0.548

>>> print(education.global_weights)
{'Sue': 0.093, 'Moll': 0.024, 'Nell': 0.01}
>>> print(education.consistency_ratio)
0.062
>>> print(education.weight)
0.127

Although this example uses different nodes (experience and education) to look at local and global, I think local weights sum to 1.0 at that level of the tree, while global weights sum to 1 over all the nodes in a tree (maybe not counting the leaves?).

A more precise statement would be helpful to me. Thanks.

dfrankow commented 3 years ago

Actually, documenting the difference between "local" and "target" weights would also help me. Here is the difference in the vehicle example:

Target weights:

    {'Odyssey': 0.219, 'Accord Sedan': 0.215, 'CR-V': 0.167,
     'Accord Hybrid': 0.15, 'Element': 0.144, 'Pilot': 0.106},

Local weights:

    {'Odyssey': 0.273, 'Accord Sedan': 0.136, 'CR-V': 0.136,
     'Accord Hybrid': 0.136, 'Element': 0.045, 'Pilot': 0.273},

Both add to 1.0. How to interpret each?

Perhaps the local weights just depend on the rankings at that level of the tree, and target weights include multiplication from above? But then how is that different from global weights?

dfrankow commented 3 years ago

Ah, I see at least for the internal nodes. Global weights add to 1 along the leaves (or close, due to rounding).

 {'Capacity': 0.215, 'Cost': 0.51, 'Safety': 0.234, 'Style': 0.041,
  'Cargo': 0.036, 'Passenger': 0.179,
  'Price': 0.249, 'Fuel': 0.129, 'Maintenance': 0.051, 'Resale': 0.082}

$ python -c "print(0.036+0.179+  0.249+0.129+0.051+0.082 + 0.234 + 0.041)"
1.001

While for the non-leaves (internal nodes), the weights add up:

Capacity = Cargo + Passenger Cost = Price + Fuel + Maintenance + Resale

PhilipGriffith commented 3 years ago

Hi Dan,

Thanks for drawing my attention to this. I wanted the lexicon of the API to be as general as possible, so I tried my best to stay away from terms like "goal", "priorities", "criteria" and "alternatives" that (at least in my experience) carry a certain amount of semantic baggage when attempting to build a hierarchy. As a rule of thumb, I replaced "priorities" with "weights", "criteria" with "elements" and "alternatives" with "target". Of course, the terms "weights" and "target" have implications of their own, but I think they're broad enough for present purposes.

That being said, I should have better defined the alternatives I chose! I've added this text to the README:

Compare objects compute up to three kinds of weights for their elements: local weights, global weights and target weights. Compare objects also compute their own global weight, given their parent.

  • Local weights display the computed weights of a Compare object's elements independent of that object's global weight within a hierarchy
    • For this reason, the local weights of the elements within a Compare object will always (approximately) sum to 1.0
  • Global weights display the computed weights of a Compare object's elements dependent on that object's global weight within a hierarchy
    • Global weights are derived by multiplying the local weights of the elements within a Compare object by that object's own global weight in the hierarchy
  • Target weights display the synthesized weights of the problem elements described in the lowest level of a hierarchy
    • Target weights are only computed by the Compare object at the highest level of the hierarchy (i.e. the only Compare object without a parent)

A Compare object that does not have a parent will have identical local and global weights; a Compare object that has neither a parent nor children will have identical local, global and target weights.

Hopefully this makes the meaning of the terms clearer. Please let me know if it doesn't!

All the best, Philip

dfrankow commented 3 years ago

Yes, this is good. Thanks! I'll close this.

On a different topic, I don't understand this: "I wanted the lexicon of the API to be as general as possible, so I tried my best to stay away from terms like "goal", "priorities", "criteria" and "alternatives" that (at least in my experience) carry a certain amount of semantic baggage when attempting to build a hierarchy."

I think you're right there is "semantic baggage" with those words, but that seems useful. What are you modeling, if not priorities among alternatives using criteria? But, this is not a blocking issue.

PhilipGriffith commented 3 years ago

Thank you for contacting Florida State University. The following person(s) you are trying to contact directly or through a distribution list are no longer with the university. Philip Griffith @.***) For further assistance, please contact the ITS Service Desk at 850-644-HELP (4357) or help.fsu.edu. This is an automated notification. Replies to this mailbox are not monitored.