All problems

One Training Step Over a Batch

hardPythonLogistic RegressionGradient Descent

Kestrel Freight's late-delivery model has two dials — one weight on the job's single number, and one starting amount — and the trainer is ready to move them. It works over a batch of past jobs, each with its outcome known. Each job has an opinion about which way the dials should go, and the trainer moves on the average of those opinions rather than on any single job's, so a batch of two and a batch of two hundred move the dials by comparable amounts. Both opinions and both moves are worked out from the dials as they stand: the weight does not get to move first and let the starting amount respond to it. One move only.

Task: Apply one training step to both dials and print where each lands.

Input

The first line holds three numbers separated by single spaces: the weight's current value, the starting amount's current value, and the learning rate, which fixes how far one move travels. The second line holds one integer n, the number of jobs in the batch. Then come n lines, each holding two numbers separated by a single space: the job's number first, then its outcome — 1 if the delivery was late and 0 if it was not.

Output

Two lines, in this order. First the letter-and-digit label w1, a single space, and the weight after the step, rounded to 4 decimal places. Then b1, a single space, and the starting amount after the step, rounded to 4 decimal places.

Example:

Input:
0 0 1
2
2 1
3 0

Output:
w1 -0.2500
b1 0.0000

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…