venumML.optimization.sgd
class
Nesterov:
A class implementing Nesterov's Accelerated Gradient Descent (NAGD) for encrypted data. This class leverages homomorphic encryption to securely compute model parameters without decrypting sensitive data.
Attributes
- context (EncryptionContext): The encryption context that provides encryption and decryption methods.
- lr (float): Learning rate for gradient descent.
- gamma (float): Momentum factor for Nesterov's accelerated gradient descent.
- epochs (int): Number of epochs to run the optimisation.
Nesterov(ctx, lr=0.3, gamma=0.9, epochs=10)
Initialises the Nesterov optimiser with an encryption context and optimisation hyperparameters.
Parameters
- ctx (EncryptionContext): Encryption context used to encrypt values and perform secure computations.
- lr (float, optional, default=0.3): Learning rate for gradient descent.
- gamma (float, optional, default=0.9): Momentum factor for Nesterov's accelerated gradient descent.
- epochs (int, optional, default=10): Number of epochs to perform the optimisation.
def
venum_nesterov_agd(self, ctx, x, y):
Applies Nesterov's Accelerated Gradient Descent on encrypted data to optimise weights.
Parameters
- ctx (EncryptionContext): The encryption context used to encrypt values.
- x (encrypted array-like, shape (n_samples, n_features)): Encrypted input data.
- y (encrypted array-like, shape (n_samples, 1)): Encrypted target values.
Returns
- encrypted_intercept (encrypted float): The encrypted intercept term after optimisation.
- encrypted_coef (encrypted array-like, shape (n_features,)): The encrypted coefficient(s) after optimisation.
- losses (list of float): List of loss values recorded at each epoch.
Notes
This method initialises the model's parameters with random values, encrypts them, and then iteratively updates them using Nesterov's accelerated gradient descent.