All problems

One Gradient Step for Linear Regression

hardPythonGradient DescentLinear Regression

Off the test rig and onto real deliveries: Kestrel Freight's trainer is fitting a fuel line, and it has two dials to turn rather than one — the line's intercept and its slope. The penalty it is minimising is the same cost as the training tool reports, the mean of the squared residuals, halved, where a residual is the gap between a delivery's real cost and the line's quote. Each dial moves downhill on its own steepness, and both moves are worked out from the line as it stands right now: the intercept does not get to move first and let the slope respond to it.

Task: Apply one gradient-descent step to both dials and print where each lands.

Input

The first line holds three numbers separated by single spaces: b0, the line's current intercept, b1, its current slope, and the learning rate. The second line holds one integer n, the number of deliveries, where 1 <= n <= 1000. Then come n lines, each holding a distance and the real cost, separated by a single space.

Output

Two lines, in this order. First the word b0, a single space, and the updated intercept rounded to 4 decimal places. Then the word b1, a single space, and the updated slope rounded to 4 decimal places. One step only.

Example:

Input:
0 0 0.1
3
1 3
2 5
3 7

Output:
b0 0.5000
b1 1.1333

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…