0

I have the following data:

  • Number of views (n)
  • Mean position in search (m)
  • Possible values for position: 1 to 8

I need to calculate the possible variations of values.

Ex: n = 4442, m = 1.1. So, the variations would be:

(1*x + 2*y + ... + 8*z) / 4442 = 1.1

Or, given that the mean almost equals 1, it makes sense to find variations for 1, 2 and 3 positions in search. I want to get tuples (x1, y1, z1) etc.

I have rewritten the equation as:

(1*x + 2*y + 3*z) / 4442 - 1.1 = 0

I have tried to use SymPy's Diophantine equation solver for 2 unknowns. But if I understand correctly, it only works with integer coefficients, while I have a floating coefficient (mean values), so it didn't work. How should I approach this?

from sympy import *

x, y = symbols('x, y', integer=True)

eq = (1*x + 2*y)/4442 - 1.1
conds = [(0 < x), (x <= 4442), (0 <= y), (y < 4442)]

#Solve the diophantine equation for solutions in parameter t_0
t, t_0 = symbols('t, t_0', integers = True)
gensol = diophantine(eq, t, [x, y])
((xs, ys),) = gensol

#"Solve" the inequalities for constraints on t_0
conds_t = [cond.subs(x, xs).subs(y, ys) for cond in conds]
conds_t_sol = solve(conds_t, t_0)

#Find the finite set of values for t_0 and sub in to general solution
set_t0 = (conds_t_sol.as_set() & Integers)
sol_set = [(xs.subs(t_0, ti), ys.subs(t_0, ti)) for ti in set_t0]

print(sol_set)
CrazyChucky
  • 3,263
  • 4
  • 11
  • 25
Alina
  • 11
  • 2
  • What do you mean by "Or, given that the mean almost equals 1, it makes sense to find variations for 1, 2 and 3 positions in search. I want to get tuples `(x1, y1, z1)` etc."? It might help if you gave a little more context about what this data represents. – CrazyChucky Oct 15 '22 at 14:53
  • 1
    The data represents the position of an ad-campaign in search results (1 to 8). I need to calculate how many times the webpage was in Top-1/Top-3 position, but I only have aggregated data (mean position, wich equals 1.1 in this case, and number of shows). The mean (1.1) says us, that most of values for the position were 1, some were 2 or 3. And it's very unlikely there were many 4,5,6,7,8, so I could ignore such variations, and only calculate the ratio for 1s, 2s and maybe 3s. – Alina Oct 16 '22 at 09:37

0 Answers0