8
OkCupid's Matching Algorithm
Algorithm

My efforts derive its basic idea from the description of matching algorithm given on OkCupid page. My code can be totally different from the propriety code of OkCupid. OkCupid uses C++ for its development jobs.

To calculate Match percentage for you and someone else OkCupid asks you to give answers to some basic questions. OkCupid collect three values for all users. When you answer a question on Improve Matches page, OkCupid learn:

1)your answer, 2)how you’d like someone else to answer, and 3)how important the question is to you.

Your match percentage with a given person on OkCupid, let’s call him B, is based on the values of (1), (2), and (3) for questions you've both answered.

Example Questions:

-How messy are you?

-very messy -average -very organized

-Your answer: 3 -How you want someone else to answer: 2 -The question’s importance to you: Very Important

-B’s answer: 2 -How B wants someone else to answer: 2 -The question’s importance to B: A Little Important

-Have you ever cheated in a relationship?

-yes -no

-Your answer: 2 -How you want someone else to answer: 2 -The question’s importance to you: A Little Important

-B’s answer: 1 -How B wants someone else to answer: 2 -The question’s importance to B: Somewhat Important

Calculating The Match:

OkCupid assigns numerical values to ideas such as “somewhat important” and “very important.” They chose the following scale:

Level of Importance Point Value

Irrelevant 0

A little important 1

Somewhat important 10

Very important 50

Mandatory 250

When OkCupid look at how each of your answers satisfied the other’s preferences, it’ll use these values to give its calculations the correct weight.

To store preferences of person a structure can be defined as :

define QUE 10
struct person
{
    int ans[QUE];//Array to store your answers
    int sat_ans[QUE];//Array to store your preferred answer
    int imp[QUE];//Array to store Importance level of question
} ;

How much did B’s answer make you happy?

You indicated that B’s answer to the first question was very important to you. And that his answer to the second question was not. So we placed 50 importance points on the first question and 1 point on the second question. Of those 51 possible points, B earned 50 by answering the first question how you wanted. So B’s answers were 50/51 = 98% satisfactory.

How much did your answers make B happy?

Well, B placed 1 importance point on your answer to the first question and 10 on your answer to the second. Of those 11, you earned 10 points. So your answers were 10/11 = 91% satisfactory.

To get a match percentage for you and B, we just multiply your satisfactions, and then take the square root: sqrt(91% * 98%) = 94%.

The resulting code from the description is :

int match(struct person *p, struct person *q)
{
    int p_res=0;
    int q_res=0;
    int i;
    int totp=0;
    int totq=0;
    int res;
    for(i=0;i<QUE;i++)
    {
        if(p->sat_ans[i]==q->ans[i]) 
            p_res+=p->imp[i];
        if(q->sat_ans[i]==p->ans[i])
        q_res+=q->imp[i];

        totp+=p->imp[i];
        totq+=q->imp[i];
     }
     percent_p=p_res/totp;
     percent_q=q_res/totq;
     res=sqrt(percent_p*percent_q);
     return res;
}

This code snippet return a mathematical expression of how happy you’d be with each other… if these questions were the only things that mattered in a relationship!

Disclaimer : My code can be inaccurate in real world scenario as the code is derived by matching percentages illustration on OkCupid Page. okcupid.comMatch Percentages | OkCupid

Any corrections are highly appreciated.

[source: quora, okcupid]

Author

Notifications

?