Skip to content

Nestrov Accelerated Gradient Descent  #104

Open
@DataSenseiAryan

Description

@DataSenseiAryan

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions