Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nestrov Accelerated Gradient Descent #104

Open
DataSenseiAryan opened this issue Feb 19, 2023 · 1 comment
Open

Nestrov Accelerated Gradient Descent #104

DataSenseiAryan opened this issue Feb 19, 2023 · 1 comment

Comments

@DataSenseiAryan
Copy link

class NesterovAcceleratedGradient():
def init(self, learning_rate=0.001, momentum=0.4):
self.learning_rate = learning_rate
self.momentum = momentum
self.w_updt = None#np.array([])

def update(self, w, grad_func):
    # Calculate the gradient of the loss a bit further down the slope from w
    
    if self.w_updt is None:
        self.w_updt = np.zeros(np.shape(w))

    # print("shape og w",w.shape)
    # print("shape og w",self.w_updt.shape)
    approx_future_grad = np.clip((grad_func(w - self.momentum * self.w_updt)), -1, 1)
    #print(approx_future_grad)
    # Initialize on first update
    if not self.w_updt.any():
        self.w_updt = np.zeros(np.shape(w))

    self.w_updt = self.momentum * self.w_updt + self.learning_rate * approx_future_grad
    # Move against the gradient to minimize loss
    return w - self.w_updt

Here grad_func is not implemented!

@MikeMavrok
Copy link

can i contribute?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants