vlab-kaist / NN101_23S

MIT License
6 stars 7 forks source link

[LAB] Week1_Problem1_이성준 #28

Closed E-pak-sa closed 1 year ago

E-pak-sa 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 test_func(x): # function for testing;function for evaluation will be different.
    return 3 * x ** 2 - 3.14 * x + 7

def solution(func: Callable, start_point: float): # DO NOT MODIFY FUNCTION NAME    
    x0 = start_point
    while True:
        x1 = x0 - 0.01 * (((func(x0+1e-9) - func(x0))) / (1e-9))
        if abs(func(x0)-func(x1)) < 1e-6:
            return x0
        else:
            x0 = x1
    ### IMPLEMENT FROM HERE

if __name__ == "__main__":
    print(solution(test_func, 10*random()))

Description

numeral differentiation

Output (Optional)

No response

Dongyeongkim commented 1 year ago

Set For-loop not While-loop

jangyoujin0917 commented 1 year ago

In addition, this code do not get good performance on re-scoring. (50/100) I also recommend you to use for-loop.

github-actions[bot] commented 1 year ago

This is an auto-generated grading output. Checking code of E-pak-sa {'E-pak-sa': 35.0}

Dongyeongkim commented 1 year ago

Resolved from #68