import torch
from random import random
from typing import Callable
## Problem 2 ##
## ##
## Arbitrary quartic function will be given. ##
## Return the optimal point(global minimum) of given function ##
## Condition: highest order term is positive ##
## Made by @jangyoujin0917 ##
## ##
alpha = 0.001
beta = 0.9
def solution(func: Callable, start_point: float) -> float: # DO NOT MODIFY FUNCTION NAME
x = torch.tensor([start_point], requires_grad=True)
v = 0
for i in range (50000):
y = func(x + beta * v)
y.backward()
v = beta * v - alpha * x.grad
x.data += v
x.grad.zero_()
return x.item()
if __name__ == "__main__":
def test_func(x): # function for testing;function for evaluation will be different.
return x ** 4
t = 10 * random()
print(solution(test_func, t))
Problem
Week 1_Problem 2
Source Code
Description
.
Output (Optional)
No response