I
I
Ilya Lesnykh2012-06-18 17:43:36
Algorithms
Ilya Lesnykh, 2012-06-18 17:43:36

Random rotation of banners depending on cost?

Let's say we have a banner display system. Each display of banners costs its owner some money, the amount of which he exposes himself. For example, the average price is 1 ruble, and someone put 2 rubles. I would like the banners of those who are ready to spend more money to spin more often, but at the same time give the opportunity for cheaper banners to also be displayed in the ad block (let's say that the block is a page with 5 random banners). My math memories tell me to use logarithms/exponentials to calculate the probability of showing a banner in a particular block depending on its cost, but I can't figure out the equation completely. Prompt the algorithm.

Answer the question

In order to leave comments, you need to log in

9 answer(s)
@
@ksurent, 2012-06-18
@Aliance

A segment is taken (for example, [0, 1]), divided into N parts, where N is the number of banners. The size of each part is proportional to the cost. A random number is guessed in the range from 0 to the size of the segment. In which sub-segment the number fell, that banner is shown. In principle, it is very similar to what has already been described above.
Example: there are three banners costing 50, 30 and 10 rubles. We take the segment [0, 1] and divide it into parts:
1. [0, 0.5] — the first banner
2. (0.5, 0.8] — the second
3. (0.8, 1] — the third (up to one, because there are more banners no)
We guess the number rand(0, 1), show the banner of the subsegment where it fell.
Because the first banner has the highest cost, then its subsegment is also the largest, which means that the probability of a random number falling into this subsegment also becomes higher (provided that rand() produces numbers with a uniform distribution).

G
Georg, 2012-06-18
@Georg

x = random() //x from 0 to 1
sum = s1+s2+s3 //sum of costs
if (x<s1/sum) then banner1 //if x falls within the first banner display interval, then show it
elseif (x <s2/sum) then banner2
elseif (x<s3/sum) then banner3
the algorithm is

S
Salavat Sitdikov, 2012-06-18
@zona7o

Hmm, sort of price is a priority. Then you can use the following algorithm.
We have n priorities. (1, 2, 3… n). We create an array of data - where we drive banners according to the following rule:
Each banner will be driven k times, where k is the priority. And then from this array we will randomly select a banner to display.
Banner 1 = $1
Banner 2 = $2
Banner 3 = $3
Array = (Banner 1, Banner 2, Banner 2, Banner 3, Banner 3, Banner 3)
By choosing randomly from this array, you will solve your problem.

L
leventov, 2012-06-18
@leventov

This is a weighted random sampling problem .
Further in Google there are many many links, the basic algorithms are somewhat more complicated than the above approaches.

M
merlin-vrn, 2012-06-19
@merlin-vrn

You make a list of all options, and those that should be twice as often appear in the list twice, respectively, those that should be displayed 9 times out of 10 will fill 90% of the list. And then choose an arbitrary random element from this list.
The list is recalculated only when the weights or the item set itself change.
Example:
[1, 2, 2, 3, 4, 4, 4, 4, 2]
With a random choice, we get:
1 - with a probability of 1/9
2 - with a probability of 3/9 = 1/3
3 - with a probability of 1 /9
4 - with probability 4/9

A
Andrey Kravchuk, 2012-06-18
@WhiteD

openx.com/

C
ComodoHacker, 2012-06-18
@ComodoHacker

You should read about task scheduling algorithms in operating systems. You can turn away from them.
On the other hand, you don't have the same hard constraints as task scheduling (scheduling time, discrete priorities) so other approaches can be considered.

L
Lev Lybin, 2012-06-18
@lybin

plate:
link, image, cost per impression, number of impressions
link | img | cost | count
SELECT link, img FROM banners ORDER BY (count / cost) ASC LIMIT 1 I'm
writing an idea, I could make a mistake, but it seems to work

I
Ivan B, 2012-09-20
@hexes

Try this:
ORDER BY -LOG(1.0 - RAND()) / weight

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question