vlab-kaist / NN101_23S

MIT License
6 stars 7 forks source link

[LAB] Week 1_Problem 1_이창섭 #65

Closed Elemorld closed 1 year ago

Elemorld commented 1 year ago

Problem

Week 1_Problem 1

Source Code

import torch
from random import random 
from typing import Callable

##                        Problem 1                           ##
##                                                            ##
##         Arbitrary quadratic function will be given.        ##
## Return the optimal point(global minimum) of given function ##
##          Condition: highest order term is positive         ##
##                  Made by @jangyoujin0917                   ##
##                                                            ##

def solution(func: Callable, start_point: float) -> float: # DO NOT MODIFY FUNCTION NAME
    x = torch.tensor(start_point, requires_grad=True, dtype=torch.float32)
    grad = torch.tensor([1.0]*1)
    lr = 1e-6
    for i in range(10000):

        func(x).backward(grad, retain_graph=True)
        x.data = x.data - lr * x.grad.data

    return x ### IMPLEMENT FROM HERE

if __name__ == "__main__":
    def test_func(x): # function for testing;function for evaluation will be different.
        return x ** 2
    t = torch.tensor([10*random()], requires_grad=True, dtype=torch.float32)
    print(solution(test_func, t))

Description

return x.data

Output (Optional)

No response

github-actions[bot] commented 1 year ago

This is an auto-generated grading output. Your code failed to run. Please check again.

github-actions[bot] commented 1 year ago

This is an auto-generated grading output. Your code failed to run. Please check again.

github-actions[bot] commented 1 year ago

This is an auto-generated grading output. Your code failed to run. Please check again.

github-actions[bot] commented 1 year ago

This is an auto-generated grading output. Your code failed to run. Please check again.

github-actions[bot] commented 1 year ago

This is an auto-generated grading output. Your code failed to run. Please check again.

Dongyeongkim commented 1 year ago

This issue is closed now because of the lack of progress.