﻿PHASE 4 - DETECTIVE MAP: HOW DOES AN AI PREDICT?  |  TEACHER NOTES
=====================================================================
(English, then Arabic, then Hebrew)

THE QUESTION THIS ANSWERS
"We train a model on pictures of apples, bananas, cats or dogs. Then in the test, how does it know
what a NEW picture is?"

THE ANSWER IN FOUR SENTENCES (the simulation lets students see each one)
1. A computer cannot "see". Every picture is turned into numbers - measured clues such as colour,
   roundness, ear shape.
2. Training = the AI looks at many labelled pictures and remembers where each one lands on a map of clues.
   Pictures of the same thing land close together.
3. Testing = a new picture is measured, lands somewhere on the map, and the AI asks: which remembered pictures
   are closest? The k nearest neighbours vote, and the winner is the prediction (the votes show the confidence).
4. The coloured "decision map" is the model. Where the colours change, the AI changes its mind.

WHAT STUDENTS DO (30-40 minutes, five numbered steps on the page)
1. Pictures become numbers: pick a picture, see its clue numbers. Fruit: zoom into the pixels (each pixel =
   three numbers). Cats & dogs: build your own animal with sliders - the picture is DRAWN from the numbers.
2. Train: press the button and watch every training picture fly onto the map as a coloured dot.
3. Test: pick a test picture (or "Surprise me", or "Test my own animal"). The star lands, the neighbours light up,
   they vote. Drag the star around to ask "what if?".
4. See the AI's brain: switch on the coloured decision map. Try k = 1 versus k = 15.
5. Score: test all easy and tricky pictures, read accuracy, and compare every pair of clues in the table.

WHAT TO LOOK FOR
- Fruit: colour + roundness and colour + leafiness get about 100% on the easy test; roundness + leafiness
  makes mistakes. Which clues you give the AI matters.
- Cats & dogs: ears + snout work well. Fur darkness + eye size are useless clues by design: about 60% accuracy,
  close to guessing. More clues are not better; useful clues are.
- Tricky pictures (a chihuahua with pointy ears, a green apple, a pale orange...) fool the AI. Use the map to
  explain why: they land in the wrong neighbourhood.
- k = 1 gives jagged borders (it trusts one neighbour), a large k gives smooth borders.

LINK TO TEACHABLE MACHINE
Teachable Machine does the same job, but instead of two clues chosen by a person, a neural network discovers
thousands of clues by itself from the pixels. The idea is the same: numbers -> where it lands -> closest
training examples -> prediction.

HONEST SIMPLIFICATIONS
- The "AI" here is k-nearest-neighbours on two clues at a time. Teachable Machine uses a neural network.
- The cat and dog pictures are generated from the clue numbers (so students can see the link); the fruit
  pictures are the real ones from the lesson.

TECHNICAL: works offline in Chrome/Edge/Firefox. Open OPEN_DETECTIVE_MAP.html, or use the class server
http://YOUR-IP:8000/sim/  Languages: English, Arabic, Hebrew (buttons at the top).


ملاحظات للمعلم - المرحلة 4: خريطة المحقق، كيف يتنبأ الذكاء الاصطناعي؟
السؤال: «ندرّب نموذجًا على صور تفاح وموز وقطط وكلاب. ثم في الاختبار كيف يعرف ما هي صورة جديدة؟»
الجواب في أربع جمل: 1) الحاسوب لا «يرى». تتحول كل صورة إلى أرقام: أدلة تُقاس مثل اللون والاستدارة وشكل الأذن. 2) التدريب = ينظر الذكاء الاصطناعي إلى صور كثيرة معنونة ويتذكّر أين تقع كل واحدة على خريطة الأدلة. الصور المتشابهة تقع قريبة من بعضها. 3) الاختبار = تُقاس صورة جديدة فتقع في مكان على الخريطة ويسأل: أي الصور المتذكَّرة هي الأقرب؟ يصوّت أقرب k جيران والفائز هو التنبؤ (وتدل الأصوات على الثقة). 4) الخريطة الملونة هي النموذج نفسه، وحيث تتغير الألوان يغيّر الذكاء الاصطناعي رأيه.
ماذا يفعل الطلاب (30-40 دقيقة، خمس خطوات): 1) الصور إلى أرقام (للفاكهة: التقريب إلى البكسلات؛ للقطط والكلاب: اصنع حيوانك بالمؤشرات فالصورة تُرسم من الأرقام). 2) درّب: شاهد كل صور التدريب تطير إلى الخريطة نقاطًا ملونة. 3) اختبر: اختر صورة اختبار فتسقط النجمة وتضيء الجيران ويصوّتون؛ اسحب النجمة لتسأل «ماذا لو؟». 4) شاهد دماغ الذكاء الاصطناعي: خريطة القرار الملونة، وجرّب k = 1 مقابل k = 15. 5) الدرجة: اختبر الصور السهلة والصعبة وقارن كل زوج من الأدلة في الجدول.
ما الذي نلاحظه: في الفاكهة اللون + الاستدارة واللون + الورقية يعطيان نحو 100% بينما الاستدارة + الورقية تخطئ. في القطط والكلاب: الأذنان + الأنف جيدان، أما غمق الفراء وحجم العينين فعديما الفائدة عمدًا (نحو 60% أي شبه تخمين): الأدلة المفيدة أهم من الأكثر. الصور الصعبة تخدع الذكاء الاصطناعي وتفسّرها الخريطة: تقع في الحي الخطأ.
الرابط مع Teachable Machine: يفعل الشيء نفسه لكن بدل دليلين يختارهما إنسان تكتشف شبكة عصبية آلاف الأدلة بنفسها من البكسلات.
تبسيط صادق: «الذكاء الاصطناعي» هنا هو أقرب الجيران على دليلين، وصور القطط والكلاب مولَّدة من أرقام الأدلة، أما صور الفاكهة فحقيقية.
تقني: يعمل بدون إنترنت. افتحوا OPEN_DETECTIVE_MAP.html أو http://YOUR-IP:8000/sim/ .


הערות למורה - שלב 4: מפת הבלש, איך בינה מלאכותית מנבאת?
השאלה: "מאמנים מודל על תמונות של תפוחים, בננות, חתולים וכלבים. ובבדיקה, איך הוא יודע מה תמונה חדשה?"
התשובה בארבעה משפטים: 1) מחשב לא "רואה". כל תמונה הופכת למספרים: רמזים שנמדדים כמו צבע, עגלגלות, צורת אוזן. 2) אימון = הבינה המלאכותית מסתכלת על הרבה תמונות מתויגות וזוכרת איפה כל אחת נוחתת על מפת הרמזים. תמונות דומות נוחתות קרוב. 3) בדיקה = תמונה חדשה נמדדת, נוחתת במקום כלשהו על המפה, והיא שואלת: אילו תמונות שזכרה הכי קרובות? k השכנים הקרובים מצביעים והמנצח הוא הניבוי (ההצבעות מראות ביטחון). 4) מפת ההחלטה הצבעונית היא המודל עצמו, ובמקום שבו הצבעים מתחלפים הבינה המלאכותית משנה את דעתה.
מה התלמידים עושים (30-40 דקות, חמישה שלבים): 1) תמונות הופכות למספרים (פירות: התקרבות לפיקסלים; חתולים וכלבים: יוצרים חיה עם מחוונים והתמונה מצוירת מהמספרים). 2) אימון: רואים את כל תמונות האימון עפות למפה כנקודות צבעוניות. 3) בדיקה: בוחרים תמונת בדיקה, הכוכב נוחת, השכנים נדלקים ומצביעים; גוררים את הכוכב ושואלים "מה אם?". 4) המוח של הבינה המלאכותית: מפת ההחלטה הצבעונית, ומנסים k = 1 מול k = 15. 5) ציון: בודקים את כל התמונות הקלות והמתעתעות ומשווים כל זוג רמזים בטבלה.
למה לשים לב: בפירות צבע + עגלגלות וצבע + עליוּת נותנים כ-100%, ואילו עגלגלות + עליוּת טועה. בחתולים וכלבים: אוזניים + חוטם עובדים טוב; כהות פרווה וגודל עיניים חסרי תועלת בכוונה (כ-60%, כמעט ניחוש): רמזים מועילים חשובים יותר מהרבה רמזים. התמונות המתעתעות מטעות את הבינה המלאכותית והמפה מסבירה: הן נוחתות בשכונה הלא נכונה.
קשר ל-Teachable Machine: היא עושה את אותו הדבר, אבל במקום שני רמזים שבחר אדם, רשת עצבית מגלה אלפי רמזים בעצמה מהפיקסלים.
פישוט כן: "הבינה המלאכותית" כאן היא השכנים הקרובים על שני רמזים, תמונות החתולים והכלבים נוצרות ממספרי הרמזים, ותמונות הפירות אמיתיות.
טכני: עובד בלי אינטרנט. פותחים את OPEN_DETECTIVE_MAP.html או http://YOUR-IP:8000/sim/ .
