Reputation: 249
I searched and I could not find anything related specifically to my problem (or could not phrase it appropriately), so here's to hoping.
I have 100% to distribute across some variable number of items for UI presentation purposes - that is, I'm not selecting them. I would like the ability to specify a weight suggesting that, for example, item A
is twice as important as item B
. The percentages that would net me if those were the only two items would be 67% and 33%. If I added an item C
that was of equivalent importance to item B
, I would have 50%, 25%, 25%.
The question is language-agnostic but the implementation language is C# if that makes any difference.
Is there some algorithm that is suitable for this purpose? I realize that a discrete distribution may be used for selection, but since I'm only interested in reporting percentage to the associated items for the user's understanding, I'm not doing that. I'm interested in putting in a set of weights and getting out percentages. I'm not familiar with something that allows this.
Upvotes: 0
Views: 2700
Reputation: 137108
You need to have an "importance" factor attached to your items with values like 1, 2, 4 so you can add all the "importances" together and divide that into 100 to get your percentage per importance. Then multiply the percentage for each item to get the proportion for each.
So in your first example you have importances of 1 and 2. Added together they give 3. 100% / 3 is 33.3%. Item A has importance 2 so it's percentage is 2 * 33.3 = 66.7% while item B has importance 1 so it's percentage is 1 * 33.3 = 33.3%
In your second example you have 1 importance of 2 and 2 of 1 giving a total of 4. 100% / 4 = 25%. Giving you the values of 50%, 25% and 25% for items A, B and C.
Upvotes: 2
Reputation: 5758
You can calculate percentage with this formula: percentage = item important /total items important
Upvotes: 1