vlab-kaist / NN101_23S

MIT License
6 stars 7 forks source link

[LAB] Week 1_Problem 2_이정우 #53

Closed james1147 closed 1 year ago

james1147 commented 1 year ago

Problem

Week 1_Problem 2

Source Code

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.005

def solution(func: Callable, start_point: float) -> float: # DO NOT MODIFY FUNCTION NAME    
    x = start_point
    v=0
    for i in range(1500):
        momentum=0.9
        v=momentum*v - alpha * (func(x+0.0000001)-func(x-0.0000001))/0.0000002
        x=x+v
    return x

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))

Description

.

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. Checking code of james1147 {'james1147': 99.0}