تصغير دالة يدويًا باستخدام Python
برمج الانحدار المتدرج على منحنى بسيط
تصغير دالة يدويًا باستخدام Python درس مجاني في Deep Learning Academy على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Deep Learning Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Deep Learning Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
A Tiny Practice Problem
Let's run gradient descent ourselves on one simple curve. We will minimize a basic function in plain Python before trusting any framework to do it.
Pick a Function
We use a single-dip parabola. Its lowest point sits at x equal to 3, so that is the minimum our code should discover on its own.
def f(x):
return (x - 3) ** 2Know the Gradient
For this curve the slope, or gradient, is two times x minus three. In real models autograd computes this for you, but here we write it directly.
def grad(x):
return 2 * (x - 3)Start Somewhere
Descent needs a starting point. We pick an arbitrary initial value far from the answer so we can watch the steps march toward it.
x = 0.0Choose a Learning Rate
We set a modest learning rate so steps are big enough to make progress but small enough to avoid overshooting the dip.
lr = 0.1The Update Step
Each iteration applies the same rule from before: subtract the scaled gradient from x. One line does all the downhill work.
x = x - lr * grad(x)Loop It
One step is not enough, so we wrap the update in a loop. Twenty or so iterations let x slide steadily toward the minimum.
for i in range(20):
x = x - lr * grad(x)Watch It Converge
Print x and f(x) each pass and you will see them converge: x creeps toward 3 and the function value shrinks toward zero.
print(round(x, 4), round(f(x), 6))Steps Get Smaller
Notice the moves shrink as you approach the bottom. Near the minimum the gradient is tiny, so each step naturally slows down without any extra code.
Try a Bad Rate
Set the learning rate to something like 1.1 and rerun. x bounces away instead of settling, showing live how a too-big step diverges.
lr = 1.1Same Idea, Bigger Scale
This handful of lines is exactly what deep learning does, just with millions of weights and an automatic gradient. The core loop never changes.
Quick Check
What signals that descent is converging?
Recap
You coded gradient descent by hand: define a function and its gradient, start somewhere, then loop the update rule until x converges on the minimum. ✅
تعلم Python مع معلم ذكاء اصطناعي — مجانًا
اكتب وقم بتشغيل أكوادك الفعلية في المتصفح، واحصل على مساعدة فورية من معلم ذكاء اصطناعي متاح 24/7، واستمر من حيث توقفت على الويب أو في التطبيق.
- الدورات
- 30
- الدروس
- 120
الأسئلة الشائعة
هل درس «تصغير دالة يدويًا باستخدام Python» مجاني؟
نعم — نص درس «تصغير دالة يدويًا باستخدام Python» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Deep Learning Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Deep Learning Academy 4 دروس في المجموع.
ماذا ستتعلم في «تصغير دالة يدويًا باستخدام Python»؟
برمج الانحدار المتدرج على منحنى بسيط تتمرن على Deep Learning Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Deep Learning Academy؟
لا تُشترط خبرة سابقة. Deep Learning Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «تصغير دالة يدويًا باستخدام Python»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Deep Learning Academy هذا؟
نعم. كل درس في Deep Learning Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- الخسارة كسطح نهبط عليه
- تشير التدرجات إلى الأعلى — لذا تحرّك في الاتجاه المعاكس
- معدل التعلّم: كبير جدًا، صغير جدًا، أو مناسب تمامًا
- تصغير دالة يدويًا باستخدام Python