TensorTonicTensorTonic
Problems
Study PlansProjectsInterviewPricingFeedback
Study Plan
Apply a Gradient-Descent Step
Optimization
Medium

Apply one gradient-descent update to the Python lists values and gradients:

θi′=θi−ηgi.\theta'_i=\theta_i-\eta g_i.θi′​=θi​−ηgi​.

Here iii indexes coordinates, θi\theta_iθi​ is the original value, gig_igi​ is its gradient, η\etaη is learning_rate, and θi′\theta'_iθi′​ is the updated value. The predicted first-order objective change is

ΔLpred=∑igi(θi′−θi).\Delta L_{\mathrm{pred}}=\sum_i g_i(\theta'_i-\theta_i).ΔLpred​=i∑​gi​(θi′​−θi​).

Here ΔLpred\Delta L_{\mathrm{pred}}ΔLpred​ is a local prediction, not a measured change in loss. Empty input lists produce an empty updated list and 0.0. Return a two-item tuple: a fresh list of updated Python floats, followed by the predicted change as a Python float.

Loading visualization...

Examples

Input: values=[2.0,-3.0,10.0], gradients=[-3.0,2.0,1.0], learning_rate=0.1

Output: ([2.3,-3.2,9.9],-1.4)

Explanation: Each value moves opposite its gradient, and the local prediction is -0.1 times the squared gradient norm.

Input: values=[1.0,-2.0], gradients=[0.0,0.0], learning_rate=0.5

Output: ([1.0,-2.0],0.0)

Input: values=[1.5,-4.0], gradients=[2.0,-3.0], learning_rate=0.0

Output: ([1.5,-4.0],0.0)

Hint 1

np.asarray with dtype=np.float64 prepares vectors for elementwise arithmetic.

Hint 2

np.dot reduces the gradient and update vector to a scalar.

Requirements

  • Use 64-bit floating-point arithmetic; NumPy is available.
  • Compute the predicted change from the actual updated values.
  • Leave both input lists unchanged.

Constraints

  • values and gradients are equal-length Python lists, possibly empty, of finite numbers.
  • learning_rate is a finite nonnegative number.
  • Updated values and the predicted change must be finite.
Try Similar Problems
Check a Product-Chain GradientMediumTrain a Tiny Micrograd MLPHardApply One Full SGD Training StepHardLogistic Regression Training LoopMediumImplement AdaDelta Update StepMediumGradient Clipping (Global Norm)MediumLearning Rate Scheduler (Linear Decay)MediumSynchronize Data-Parallel GradientsMediumNesterov MomentumMediumBatch vs Stochastic vs Mini-Batch GDMediumBradley-Terry Reward Model LossMediumRLOO (REINFORCE Leave-One-Out)Medium

Accepts: array

Accepts: array

Accepts: number

You must run your code first.

Apply a Gradient-Descent Step

Optimization
Medium

Apply one gradient-descent update to the Python lists values and gradients:

θi′=θi−ηgi.\theta'_i=\theta_i-\eta g_i.θi′​=θi​−ηgi​.

Here iii indexes coordinates, θi\theta_iθi​ is the original value, gig_igi​ is its gradient, η\etaη is learning_rate, and θi′\theta'_iθi′​ is the updated value. The predicted first-order objective change is

ΔLpred=∑igi(θi′−θi).\Delta L_{\mathrm{pred}}=\sum_i g_i(\theta'_i-\theta_i).ΔLpred​=i∑​gi​(θi′​−θi​).

Here ΔLpred\Delta L_{\mathrm{pred}}ΔLpred​ is a local prediction, not a measured change in loss. Empty input lists produce an empty updated list and 0.0. Return a two-item tuple: a fresh list of updated Python floats, followed by the predicted change as a Python float.

Loading visualization...

Examples

Input: values=[2.0,-3.0,10.0], gradients=[-3.0,2.0,1.0], learning_rate=0.1

Output: ([2.3,-3.2,9.9],-1.4)

Explanation: Each value moves opposite its gradient, and the local prediction is -0.1 times the squared gradient norm.

Input: values=[1.0,-2.0], gradients=[0.0,0.0], learning_rate=0.5

Output: ([1.0,-2.0],0.0)

Input: values=[1.5,-4.0], gradients=[2.0,-3.0], learning_rate=0.0

Output: ([1.5,-4.0],0.0)

Hint 1

np.asarray with dtype=np.float64 prepares vectors for elementwise arithmetic.

Hint 2

np.dot reduces the gradient and update vector to a scalar.

Requirements

  • Use 64-bit floating-point arithmetic; NumPy is available.
  • Compute the predicted change from the actual updated values.
  • Leave both input lists unchanged.

Constraints

  • values and gradients are equal-length Python lists, possibly empty, of finite numbers.
  • learning_rate is a finite nonnegative number.
  • Updated values and the predicted change must be finite.
Try Similar Problems
Check a Product-Chain GradientMediumTrain a Tiny Micrograd MLPHardApply One Full SGD Training StepHardLogistic Regression Training LoopMediumImplement AdaDelta Update StepMediumGradient Clipping (Global Norm)MediumLearning Rate Scheduler (Linear Decay)MediumSynchronize Data-Parallel GradientsMediumNesterov MomentumMediumBatch vs Stochastic vs Mini-Batch GDMediumBradley-Terry Reward Model LossMediumRLOO (REINFORCE Leave-One-Out)Medium

Accepts: array

Accepts: array

Accepts: number

You must run your code first.