Practice
Time limit1sMemory limit128 MB
Given pairs (n, w), fit a logistic regression by maximizing the product of per-observation likelihoods and report the slope and intercept to four decimals.
- Level
Medium7 of 10
- Topics
- Math, Probability, Binary search, Implementation
- Solved
- No attempts yet
Problem
We want to model how a team's chance of winning a programming contest depends on how much it has practiced.
Let be the probability that a given team wins a given contest, and let be the number of practice problems the team solved before the contest. We assume the two are related by the logistic model
for some constants and . Your task is to find the and for which this model best fits a set of observed results.
Each observation is a pair : is the number of practice problems a team solved before a contest, and is if the team won that contest and otherwise.
Given , , and , the model yields , the estimated probability that . The likelihood of a single observation is when and when ; the likelihood of a set of observations is the product of the likelihoods of the individual observations.
Compute the maximum-likelihood estimate of and — the values that maximize the likelihood of the given set of observations.
Input
The input contains several test cases, followed by a line containing a single .
Each test case begins with an integer (), the number of observations that follow. Each of the next lines contains two integers and (, ). Within each test case there are at least two distinct values of and at least two distinct values of .
Output
For each test case, print a single line containing and , each rounded to four digits to the right of the decimal point.