Stephen
Stephen

Reputation: 18964

How can I modify this (simple) equation to produce my desired result?

I have a database of 817 items, each given a "rank" of 1 to 817 (the smaller the number, the "better" the item). This rank is based off of many factors that indicate quality.

Now, I need to assign a "value" to these items, with the item at rank 1 being valued the most, and the value decreasing with rank (non-linear).

The easiest first attempt was to simply choose an arbitrary base (100,000) and divide by the rank:

$value = 100000 / $rank;

/**
 * Rank : Value
 * 1    : 100,000
 * 2    : 50,000
 * 3    : 33,333
 * etc.
 */

This produces exponential decay, as shown in the red line in this image:

graph

However, I wish to value these items in a manner that looks more like the blue line above. How can I change my formula to achieve this?

Upvotes: 0

Views: 112

Answers (3)

Kamahire
Kamahire

Reputation: 2209

I haven't tried but use exponent instead of dividing by 1000 of a base 2.

UPDATES

value = 2 pow (n-rank)

Upvotes: 0

user149341
user149341

Reputation:

Try 1/sqrt(x) (i.e, pow(x, -1/2)) for starters. If that's still not slow enough, try a smaller fractional power.

Upvotes: 2

svick
svick

Reputation: 244948

Why don't you go with linear?

value = n - rank

where n is the count of your items, i.e. 817.

Upvotes: 0

Related Questions