tinycodinglm / math /math-0135.jsonl
winapiadmin's picture
Upload folder using huggingface_hub (part 15)
b27bfb3 verified
|
Raw History Blame Contribute Delete
1.47 kB
opencode trace
System You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing c...

You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing code, identify bugs, security issues, and performance problems. You have deep knowledge of C/C++, Windows API, Python, and many other technologies.

User

Explain the key concepts of optimization in math, with concrete details and common pitfalls. Include a runnable code example with its expected output.

Assistant

Gradient Descent: θ_{n+1} = θ_n − α·∇f(θ_n)

python
import numpy as np

def gradient_descent(f_grad, theta0, lr=0.01, steps=1000):
    theta = theta0
    history = [theta]
    for _ in range(steps):
        theta = theta - lr * f_grad(theta)
        history.append(theta)
    return theta, history

Variants:

  • Momentum: v_t = β·v_{t-1} + ∇f; θ -= α·v_t (smooths oscillations)
  • Adam: Combines momentum + RMSProp (adaptive learning rates)
  • SGD with mini-batches: Gradient estimated on subsets (adds noise, escapes local minima)

Learning rate: Too high → diverges; too low → slow convergence.