AI - Artificial Intelligence PDF

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Document Details

VersatileEarthArt

Uploaded by VersatileEarthArt

Marwa Eddakhli

Tags

artificial intelligence machine learning learning models AI

Summary

This document gives an overview of different types of learning models in Artificial intelligence, focusing on logical, geometric, and probabilistic models, as well as grouping and grading methods. It also discusses probabilistic models in more detail, including predictive and generative models.

Full Transcript

6/2/2024 AI - ARTIFICIAL INTELLIGENCE Marwa Eddakhli 1...

6/2/2024 AI - ARTIFICIAL INTELLIGENCE Marwa Eddakhli 1 TYPES OF LEARNING MODELS Machine learning focuses on using appropriate features to build models that accomplish specific tasks. Learning models are generally categorized into three main types based on their approach to the instance space: Logical Models: Geometric Models: Probabilistic Models: Grouping and Grading: Definition: Models that use Definition: Models that use the Definition: Models that use Definition: Methods for logical expressions. geometry of the instance space. probability theory to classify clustering similar instances and Characteristics: Constructs Characteristics: the instance space. grading them based on their decision rules based on logical Characteristics: Calculate characteristics. Represent data instances as conditions. points in a multidimensional probabilities of different Characteristics: Identifies Simple to interpret and space. outcomes. groups of similar instances. understand. Use geometric relationships for Suitable for uncertain or Provides a grading scale based classification. incomplete data. on predefined criteria. 2 6/2/2024 PROBABILISTIC MODELS Probabilistic models view features and target variables as random variables. They model and manipulate the level of uncertainty associated with these variables. This approach differs from k-nearest neighbors (using distances) and logical models (using rules) for classification. 3 TWO TYPES OF PROBABILISTIC MODELS Predictive models: Focus on conditional probability distribution P(Y|X). They aim to predict Y (target variable) given X (features). Generative models: Estimate the joint probability distribution P(Y, X). They can derive any conditional or marginal distribution involving Y and X. 4 6/2/2024 The world of probabilistic models offers two main categories: predictive and generative. Predictive models, as the name suggests, focus on the conditional probability distribution P(Y|X). This distribution allows them to predict the target variable Y based on the features X. For instance, if we're trying to predict whether an email is spam or not, a predictive model would use the words in the email (features) to estimate the probability of it being spam (target variable). On the other hand, generative models take a more comprehensive approach. They estimate the joint probability distribution P(Y, X), representing the relationship between both variables. This powerful capability allows generative models to not just predict but also create new data points and their corresponding labels, all thanks to the knowledge of the joint probability distribution. Imagine generating entirely new email samples with their corresponding spam labels, all based on the power of probability. 5 UNVEILING THE JOINT DISTRIBUTION The joint probability distribution P(Y, X) captures the relationship between two variables. By inferring this relationship, we can predict new data points. Generative models excel at this task, leveraging the joint distribution. 6 6/2/2024 Naïve Bayes is a popular example of a probabilistic classifier. It leverages Bayes' rule, a powerful tool for conditional probability calculations. The algorithm analyzes evidence (features) to determine the likelihood of a specific class and assigns a label accordingly. THE NAÏVE BAYES ALGORITHM 7 GROUPING AND GRADING Grading vs grouping is an orthogonal categorization to geometric-probabilistic- logical-compositional.  Grouping models break the instance space up into groups or segments and in each segment apply a very simple method (such as majority class). o E.g. decision tree, KNN.  Grading models form one global model over the instance space. o E.g. Linear classifiers – Neural networks 8 6/2/2024 DESIGNING A LEARNING SYSTEM 9 For any learning system, we must be knowing the three elements — T (Task), P (Performance Measure), and E (Training Experience). At a high level, the process of learning system looks as below. 10 6/2/2024 he learning process starts with task T, performance measure P and training experience E and objective are to find an unknown target function. The target function is an exact knowledge to be learned from the training experience and its unknown. For example, in a case of credit approval, the learning system will have customer application records as experience and task would be to classify whether the given customer application is eligible for a loan. So in this case, the training examples can be represented as 8 (x1,y1)(x2,y2)..(xn,yn) where X represents customer application details and y represents the status of credit approval. With these details, what is that exact knowledge to be learned from the training experience? So the target function to be learned in the credit approval learning system is a mapping function f:X →y. This function represents the exact knowledge defining the relationship between input variable X and output variable y 11 Type of Training Experience Choosing the Target Function DESIGN OF A Choosing a Representation for the LEARNING Target Function SYSTEM Choosing an Approximation Algorithm for the Target Function The Final Design 12 6/2/2024 TYPE OF TRAINING EXPERIENCE The type of training experience significantly affects the success of the learning system. Direct vs. Indirect Training Experience: Direct Experience: Each board state and the correct move for each state are provided. Indirect Experience: Sequences of moves and final results (win, loss, draw) are given. The credit assignment problem arises here, determining how to assign credit or blame to individual moves. Teacher or Not: Supervised Learning: The training experience is labeled, meaning each board state is associated with the correct move. Unsupervised Learning: The training experience is unlabeled, meaning the system plays random games against itself without supervision. Semi-supervised Learning: The system generates game states and occasionally asks a teacher for help with confusing states. Quality of Training Experience: Ensure the training examples represent the distribution of examples over which the final performance will be measured. Example: In the checkers problem, the player learns by playing against itself, encountering indirect experiences and possibly missing common human expert moves. 13 CHOOSING THE TARGET FUNCTION When playing checkers, a player must decide the best move. This decision process needs to be translated into a target function. Direct Experience: ChooseMove Function: ChooseMove:𝐵→𝑀ChooseMove:B→M, where 𝐵B is the set of board states and 𝑀M is the set of legal moves. Indirect Experience: Value Function (V): 𝑉:𝐵→𝑅V:B→R, where 𝐵B is the set of board states and 𝑅R is a real number score indicating the board state quality. 14 6/2/2024 CHOOSING A REPRESENTATION FOR THE TARGET FUNCTION The representation should be expressive yet manageable with available training data, Options include large tables, rule collections, polynomial functions, neural networks. 15 Large Tables: The objective function values for each possible game board state can be stored in a large table.But this approach is ineffective, especially with large or complex game boards. Rule Sets: Specific rules can be written to determine the best move for each game board situation.But this approach is difficult to maintain and expand as the game becomes more complex. Polynomials: Mathematical equations can be used to represent the objective function.For example, in a simple game, the objective function could be a linear combination of features of the playing board, such as the number of pieces per player (as in the example shown). Neural Networks: Neural networks are one of the most powerful tools for representing an objective function.Neural networks can learn from data and determine the best possible representation of the objective function even with large and complex game boards. 16 6/2/2024 CHOOSING AN APPROXIMATION ALGORITHM FOR THE TARGET FUNCTION Training data needs to be generated, and the system should learn to minimize the error between the predicted and actual values. Temporal Difference (TD) Learning: Used for indirect training experiences to iteratively correct the estimated returns. Example: Adjust weights to minimize the squared error using the LMS (Least Mean Square) algorithm. 17 As mentioned earlier, choosing an objective function approximation algorithm is an important step in designing a learning system. This algorithm helps the system learn the relationship between inputs and outputs through training experience. Need for approximation: The true objective function we want to learn may be very complex or difficult to calculate directly. Therefore, we need an algorithm that helps us approximate this function through the training experiment. Error Reduction: During the learning process, it is expected that there will be a difference between the values predicted by the system and the actual values found in the training data.The approximation algorithm reduces this difference (known as error) over time. Types of Approximation Algorithms: There are many different approximation algorithms used in learning systems, each with its strengths and weaknesses. Choosing the appropriate algorithm depends on the type of problem and the type of training experiment. Examples of approximation algorithms:  LMS (Least Mean Square) algorithm: An example of a traditional algorithm used to approximate an objective function by minimizing the squared difference between predicted values and actual values. For example, let's say our system is trying to predict the price of a stock based on past market data. The LMS algorithm adjusts the system's internal forecast model so that it minimizes the difference between predicted prices and actual prices that occurred in the past.  Time Difference Learning (TD Learning): This algorithm is used in cases where the learning experience is indirect.Instead of getting a clear reward signal at each step, the system learns by evaluating the difference between current predictions and future predictions. For example, this type of learning could be used to train a game learning system to improve its performance. The system learns by comparing the results it achieves at each step with the results it expects to achieve in subsequent steps. It should be noted that these are only two examples, and there are many other approximation algorithms available. Choosing the appropriate algorithm depends on the details of the problem you are trying to solve. 18 6/2/2024 FINAL DESIGN FOR THE CHECKERS LEARNING SYSTEM The final system design involves four modules: 1.Performance System: Plays games and produces traces. 2.Critic: Analyzes game traces to generate training examples. 3.Generalizer: Learns a hypothesis from training examples. 4.Experiment Generator: Generates new problems based on the current hypothesis. 19 The final design typically consists of four basic units that work together to achieve the learning objective: Performance System: This module plays the role of a “player” in the learning system. It plays games of checkers against herself or other opponents and produces records of these games (so-called “play traces”). Game logs contain information about each player's moves and the state of the checkerboard after each move. Critic: module analyzes the playing records produced by the performance system. It evaluates the quality of each step based on the chosen objective function (for example, checkerboard evaluation). Based on this evaluation, the evaluator generates training examples for the system. Training examples represent specific states of the game (such as the position of the checkers on the board) along with their value according to an objective function (such as the quality of this state for the player). Generalizer: This module receives training examples generated by the assessor. It analyzes these examples and derives universal rules or an approximate model of the objective function. This rough model is what the learning system will learn, representing its knowledge about how to evaluate a checkerboard and make good moving decisions. Experiment Generator: This module uses the existing approximate model of the objective function generated by the generalizer. You create new problems or situations for the game based on this model. For example, it can generate a new starting position of pieces on a checkerboard for the performance system to play with and learn more. 20 6/2/2024 EXAMPLE: Task (T): Play checkers Performance Measure (P): % of games won in world tournament Training Experience (E): Games played against itself Target Function Representation: Linear combination of board features By following these steps, we can design an effective learning system for the checkers problem or similar tasks. 21 22 6/2/2024 SUPERVISED LEARNING 23 SUPERVISED LEARNING Learning from Examples: Supervised learning algorithms learn by being presented with training data that includes both the input (data point) and the desired output (target value). This is similar to how a student learns from a teacher who provides examples and corrects mistakes. Mapping Inputs to Outputs: The goal of supervised learning is to create a function that can accurately map new, unseen inputs to their corresponding outputs. This function is built by analyzing the patterns in the training data. Classification and Regression: Supervised learning encompasses two main categories of problems: classification (predicting discrete categories) and regression (predicting continuous values). Variety of Algorithms: There's no one-size-fits-all solution in supervised learning. Different algorithms are better suited for different types of problems and data. 24 6/2/2024 25 KEY POINTS: Supervised learning involves training a machine from labeled data. Labeled data consists of examples with the correct answer or classification. The machine learns the relationship between inputs (fruit images) and outputs (fruit labels). The trained machine can then make predictions on new, unlabeled data. 26 6/2/2024 UNSUPERVISED LEARNING 27 UNSUPERVISED LEARNING Unlabeled Data: Unlike supervised learning, unsupervised learning deals with data that lacks predefined categories or labels. The algorithm's task is to discover these hidden structures and patterns on its own. Density Estimation: This statistical approach estimates the probability distribution of the data, essentially trying to understand how the data points are distributed within the space. Clustering: This is a popular unsupervised learning technique that aims to group similar data points together. It's a powerful tool for exploratory data analysis, helping us uncover hidden patterns and relationships within the data. Example Breakdown: The example you provided perfectly illustrates the concept. We have data on patients' genders and ages, but no pre-defined categories (e.g., healthy, diabetic). Through unsupervised learning, particularly clustering, we might uncover groups with similar age ranges or gender distributions. This could be helpful for further analysis but wouldn't directly tell us about individual patients' health conditions. Additional Points: Unsupervised learning is valuable for tasks like anomaly detection (identifying unusual data points), dimensionality reduction (compressing complex data), and recommendation systems (suggesting items based on user behavior). While evaluating the "accuracy" of unsupervised learning models can be challenging, we can assess their effectiveness based on how well they achieve the desired outcome (e.g., meaningful clusters, good anomaly detection rates). 28 6/2/2024 29 REINFORCEMENT LEARNING 30 6/2/2024 REINFORCEMENT LEARNING Trial and Error with Rewards: Reinforcement learning operates in a middle ground between supervised and unsupervised learning. The agent doesn't receive explicit instructions on the correct actions (unlike supervised learning) but gets feedback through rewards (unlike unsupervised learning with no labels). This feedback guides the agent's exploration and learning process. Learning from a Critic: The reward system in reinforcement learning acts like a critic, providing feedback on the effectiveness of the agent's actions. It doesn't tell the agent how to improve, just whether the action was good or bad in terms of the reward received. Maximizing Rewards: The ultimate goal in reinforcement learning is for the agent to learn a policy that maximizes its long-term reward. The agent interacts with the environment, takes actions, and receives rewards based on those actions. The learning process involves exploring different actions and favoring those that lead to higher rewards. Example: Training a Dog: The analogy of teaching a dog a trick perfectly illustrates reinforcement learning. The dog receives positive reinforcement (treats) for desired behaviors and no reward (or potential punishment) for undesired ones. This feedback helps the dog learn the association between actions and rewards. Real-World Applications: Reinforcement learning has a wide range of applications beyond games like backgammon. It's used in robotics for controlling robot movements, in scheduling tasks for optimal efficiency, and even in recommendation systems where the "reward" could be user satisfaction. Comparison with Supervised Learning: As you rightly pointed out, reinforcement learning differs significantly from supervised learning. In supervised learning, the agent learns from labeled examples provided by an expert. Reinforcement learning, on the other hand, operates through trial and error, guided by the reward system. 31 PERSPECTIVES AND ISSUES IN MACHINE LEARNING 32 6/2/2024 PERSPECTIVES IN MACHINE LEARNING This passage introduces a fascinating perspective on machine learning: viewing it as a search problem through a vast space of possibilities. Here's a breakdown of the key points: Hypothesis Space: The core idea is that machine learning algorithms navigate a vast space of potential solutions (hypotheses) to find the one that best fits the training data and any existing knowledge. This space encompasses all possible models or functions the learner can create. Example: Checkers Learner: Imagine training an AI to play checkers. The hypothesis space would include all possible evaluation functions – ways to assign scores to different board configurations. The learner searches through this space by adjusting weights assigned to different factors (w0 to w6) to find the function that best predicts winning moves based on training examples. Learning Algorithms as Search Tools: The LMS algorithm (or other learning algorithms) act as search tools within this space. They iteratively refine the model (adjusting weights in the checkers example) based on the difference between the model's predictions and the actual training data. This helps the algorithm converge towards a better fit. Importance of Hypothesis Representation: The choice of how the model is represented (e.g., linear functions, decision trees) significantly impacts the search process. Different representations are suitable for learning different types of functions. Search Strategies and Underlying Structure: Each learning algorithm leverages the specific structure of the chosen hypothesis space to guide its search. 33 ISSUES IN MACHINE LEARNING Effective Learning Algorithms: A core question is what kind of algorithms are best suited to learn general patterns (target functions) from specific training examples. Convergence and Training Data: How much training data is required for an algorithm to reliably converge on the desired function? Generalizability and Prior Knowledge: Generalization Beyond Training Data: A critical challenge is ensuring the learned model performs well on unseen data, not just the training data it was shown. Role of Prior Knowledge: Can incorporating existing knowledge help the learning process even if the knowledge isn't entirely accurate? Active Learning and Strategy: Active Learning Strategies: Is it possible for the learning algorithm to actively choose the most informative training examples to improve its learning efficiency? Function Approximation and Representation: Choosing the Right Functions: How can we determine the best type of functions for the learning model to focus on? Automating Function Selection: Can this process of choosing suitable functions be automated within the learning algorithm itself? Representation Learning: Adaptive Representations: Can the learning algorithm automatically adjust its internal representation (the way it stores and processes information) to improve its ability to learn the target function? 34 ‫‪6/2/2024‬‬ ‫‪1‬‬ ‫‪PYTHON‬‬ ‫‪35‬‬ ‫‪PYTHON‬‬ ‫هذه اللغة تعتبر لغة حديثة ومن خصائصها‪:‬‬ ‫▸‬ ‫سهولة التعلم واستعمال‪.‬‬ ‫‪‬‬ ‫الجمل والتراكيب بسيطة‪.‬‬ ‫‪‬‬ ‫لها جمل لمعالجة اﻷخطاء اﻻستثنائية ‪Handling Exception -‬‬ ‫‪‬‬ ‫تدعم ‪Object Oriented Programming‬‬ ‫‪‬‬ ‫البناء التدريج والديناميكي للبرنامج‪.‬‬ ‫‪‬‬ ‫تدعم اﻻسلوب البنائي ‪Approach Structured -‬ﻻ يوجد أمر ‪GOTO‬الذي يجعل البرنامج صعب‬ ‫‪‬‬ ‫التتبع‬ ‫لغة مفسرة ‪Interpreted‬‬ ‫‪‬‬ ‫مفتوحة المصدر ‪source open‬‬ ‫‪‬‬ ‫‪36‬‬ ‫‪36‬‬ ‫‪6/2/2024‬‬ ‫الكلمات المحجوزة – ‪PYTHON‬‬ ‫▸ فهي الكلمات التي تحجز مسبقًا في اللغة لتأديتها وظائف معينة‪ ،‬وﻻ يمكن استخدامها لتسمية المتغيرات أو الدوال‪.‬الكلمات‬ ‫المحجوزة تختلف من لغة برمجية إلى أخرى‪.‬‬ ‫▸ عند استخدام كلمة محجوزة لتسمية متغير أو دالة‪ ،‬قد يؤدي ذلك إلى أخطاء في البرمجة‪.‬لذا يُفضل دائ ًما تجنب استخدام‬ ‫الكلمات المحجوزة كأسماء للمتغيرات أو الدوال‪.‬‬ ‫‪37‬‬ ‫‪37‬‬ ‫كيفية ‪PYTHON -‬‬ ‫تشغيل‬ ‫كتابة وحفظ البرنامج‪:‬‬ ‫‪.4‬‬ ‫تثبيت ‪Python:‬او المترجم الخاص بها‬ ‫‪.1‬‬ ‫استخدم محرر النصوص لكتابة البرنامج واحفظه بامتداد ‪py..‬‬ ‫‪‬‬ ‫تشغيل البرنامج‪:‬‬ ‫‪.5‬‬ ‫‪Python‬من‬ ‫قم بتحميل وتثبيت‬ ‫▹‬ ‫انتقل إلى المجلد واكتب ` ‪python‬اسم_الملف‪py`..‬‬ ‫‪‬‬ ‫‪https://www.python.org/.‬‬ ‫‪ Python‬التفاعلي‪:‬‬ ‫‪.6‬‬ ‫فتﺢ الطرفية أو نافذة اﻷوامر‪:‬‬ ‫‪.2‬‬ ‫اكتب ` `‪python‬لتفعيل الوضع التفاعلي‪.‬‬ ‫‪‬‬ ‫افتﺢ الطرفية ) )‪Linux/macOS‬أو نافذة‬ ‫▹‬ ‫اﻷوامر )‪Windows).‬‬ ‫التحقق من تثبيت ‪Python:‬‬ ‫‪.3‬‬ ‫أكتب ` `‪python --version‬للتحقق من‬ ‫▹‬ ‫التثبيت الصحيﺢ‪.‬‬ ‫‪38‬‬ ‫‪38‬‬ ‫‪6/2/2024‬‬ ‫كيفية ‪PYTHON -‬‬ ‫تشغيل‬ ‫كتابة وحفظ البرنامج‪:‬‬ ‫‪.4‬‬ ‫تثبيت ‪Python:‬او المترجم الخاص بها‬ ‫‪.1‬‬ ‫استخدم محرر النصوص لكتابة البرنامج واحفظه بامتداد ‪py..‬‬ ‫‪‬‬ ‫تشغيل البرنامج‪:‬‬ ‫‪.5‬‬ ‫‪Python‬من‬ ‫قم بتحميل وتثبيت‬ ‫▹‬ ‫انتقل إلى المجلد واكتب ` ‪python‬اسم_الملف‪py`..‬‬ ‫‪‬‬ ‫‪https://www.python.org/.‬‬ ‫‪ Python‬التفاعلي‪:‬‬ ‫‪.6‬‬ ‫فتﺢ الطرفية أو نافذة اﻷوامر‪:‬‬ ‫‪.2‬‬ ‫اكتب ` `‪python‬لتفعيل الوضع التفاعلي‪.‬‬ ‫‪‬‬ ‫افتﺢ الطرفية ) )‪Linux/macOS‬أو نافذة‬ ‫▹‬ ‫اﻷوامر )‪Windows).‬‬ ‫التحقق من تثبيت ‪Python:‬‬ ‫‪.3‬‬ ‫أكتب ` `‪python --version‬للتحقق من‬ ‫▹‬ ‫التثبيت الصحيﺢ‪.‬‬ ‫‪39‬‬ ‫‪39‬‬ ‫القيم والمتغيرات‬ ‫‪2‬‬ ‫‪VALUES AND‬‬ ‫‪VARIABLES‬‬ ‫‪40‬‬ ‫‪6/2/2024‬‬ ‫القيم والمتغيرات ‪VALUES AND VARIABLES -‬‬ ‫▸ القيم – ‪Values‬‬ ‫رقمية صحيحة‬ ‫رقمية كسرية‬ ‫قيم تخيلية‬ ‫–قيمة نصية‬ ‫منطقية‬ ‫‪- Integer‬‬ ‫‪– Float‬‬ ‫‪String‬‬ ‫‪502‬‬ ‫‪0.1‬‬ ‫‪-45j‬‬ ‫”برمجة“‬ ‫‪True‬‬ ‫‪140‬‬ ‫‪3.14‬‬ ‫‪5j‬‬ ‫"‪"Programming‬‬ ‫‪False‬‬ ‫‪123‬‬ ‫‪0.5-‬‬ ‫”‪“CS011‬‬ ‫‪41‬‬ ‫‪41‬‬ ‫القيم والمتغيرات ‪VALUES AND VARIABLES -‬‬ ‫▸ القيم – ‪Values‬‬ ‫رقمية‬ ‫‪1234‬‬ ‫"‪"1234‬‬ ‫نصية‬ ‫صحيحة‬ ‫في لغة ‪ ،Python‬يمكنك تحويل القيم من نوع إلى نوع آخر باستخدام مجموعة من الدوال المكتبية‪.‬هذه‬ ‫▸‬ ‫العملية تُعرف بـ "تحويل اﻷنواع" ‪ Type Conversion‬وتساعد في تعديل القيم لتناسب اﻻستخدام المطلوب‪.‬‬ ‫)‪ - str(1234‬لتحويل من الصحيﺢ الي النص‬ ‫▹‬ ‫)”‪ – int(“1234‬للتحويل من نص الي صحيﺢ‬ ‫▹‬ ‫‪42‬‬ ‫‪42‬‬ ‫‪6/2/2024‬‬ ‫القيم والمتغيرات ‪VALUES AND VARIABLES -‬‬ ‫▸ قيم تخيلية‬ ‫‪43‬‬ ‫‪43‬‬ ‫ في لغة البرمجة ‪ ،Python‬يُستخدم نوع البيانات ` `‪complex‬لتمثيل اﻷعداد المركبة‪.‬يتألف العدد‬ ‫المركب من جزء حقيقي وجزء خيالي‪ ،‬حيث يتم تعبير عن الجزء الخيالي باستخدام الحرف ` `‪j‬أو‬ ‫` ‪J`.‬الصيغة العامة للعدد المركب هي ``‪ ،a + bj‬حيث يكون ` `‪a‬هو الجزء الحقيقي‪ ،‬و` `‪b‬هو‬ ‫الجزء الخيالي‪ ،‬ويُستخدم ` `‪j‬لتمثيل الوحدة الخيالية‪.‬‬ ‫‪.1‬تمثيل اﻷعداد الخيالية‪ :‬يمكن استخدام أنواع البيانات المركبة لتمثيل اﻷعداد الخيالية والعمليات‬ ‫الرياضية المرتبطة بها‪ ،‬مثل الجمع والطرح والضرب والقسمة‪.‬‬ ‫‪.2‬التطبيقات العلمية والهندسية‪ :‬في العديد من المجاﻻت العلمية والهندسية‪ ،‬تظهر اﻷعداد الخيالية في‬ ‫تمثيل الظواهر الطبيعية واﻹشارات والتحليل الرياضي‪.‬‬ ‫‪.3‬الرسوم البيانية والمحاكاة‪ :‬يمكن استخدام اﻷعداد المركبة في بناء النماذج الرياضية المعقدة‬ ‫والمحاكاة‪ ،‬مما يتيﺢ للمبرمجين تمثيل بنى البيانات بشكل فعال‪.‬‬ ‫‪.4‬الحوسبة الرياضية‪ :‬في بعض الحاﻻت‪ ،‬قد تكون العمليات الرياضية أكثر دقة عند استخدام اﻷعداد‬ ‫المركبة‪ ،‬وهذا يكون مه ًما في تطبيقات مثل تحليل اﻹشارات وتقنيات المعالجة الرقمية‪.‬‬ ‫للتوضيﺢ‪ ،‬في مجاﻻت الهندسة الكهربائية وعلوم الكمبيوتر‪ ،‬يمكن أن يظهر استخدام اﻷعداد المركبة‬ ‫في تمثيل المتغيرات الكهربائية أو تحليل اﻹشارات‪.‬‬ ‫‪44‬‬ ‫‪6/2/2024‬‬ ‫القيم والمتغيرات ‪VALUES AND VARIABLES -‬‬ ‫المتغيرات – ‪variables‬‬ ‫▸‬ ‫هو اسم يشير الي عنوان لتخزين قيمة من القيم المذكورة سابقا‪.‬‬ ‫‪‬‬ ‫يتكون اسم المتغير من الحروف الﻼتينية واﻷرقام ‪ 0,1,2,3,4,5,6,7,8,9‬والرمز‬ ‫‪‬‬ ‫"_" على ان يبدا بحرف‪.‬‬ ‫عادة الرمز "_" تستعمل لربط كلمتين أو أكثر‪.‬‬ ‫‪‬‬ ‫يمكننا تخيل المتغير على انه مكان )صندوق( توضع فيه قيمة معينة وقابلة للتغير‪.‬‬ ‫‪‬‬ ‫‪45‬‬ ‫‪45‬‬ ‫القيم والمتغيرات ‪VALUES AND VARIABLES -‬‬ ‫مﻼحظة‪:‬‬ ‫▸‬ ‫ضرورة التمييز بين الشرطة السفلية "_" وإشارة الناقص "‪ "-‬فهذه اﻻخيرة غير مسموح بها في اسم المتغير‪.‬‬ ‫‪‬‬ ‫اختيار أسماء توضﺢ بوضوح الغرض أو الوظيفة التي يقوم بها المتغير‪ ،‬مثﻼ‪:‬‬ ‫‪‬‬ ‫‪ name‬لتخزين اﻻسماء‬ ‫‪‬‬ ‫‪ birth_date‬لتخزين تاريخ الميﻼد‬ ‫‪‬‬ ‫أمثلة ﻷسماء جائزة كأسماء متغيرات‪:‬‬ ‫‪‬‬ ‫‪name‬‬ ‫‪phone_no‬‬ ‫‪CS011‬‬ ‫‪student_id‬‬ ‫‪birthdate‬‬ ‫كل المتغيرات تبدأ بالحروف صغيرة لماذا؟‬ ‫▸‬ ‫‪46‬‬ ‫‪46‬‬ ‫‪6/2/2024‬‬ ‫القيم والمتغيرات ‪VALUES AND VARIABLES -‬‬ ‫▸ يمكنك تعريف المتغير باستخدام اسم وتعيين قيمة له‪:‬‬ ‫‪Python‬يأتي بنظام ديناميكي للنوع‪ ،‬حيث يتم تحديد نوع المتغير تلقائيا ً‬ ‫‪‬‬ ‫يمكنك إعادة تعيين قيم المتغيرات في أي وقت‬ ‫‪‬‬ ‫‪47‬‬ ‫‪47‬‬ ‫المخرجات والمدخﻼت‬ ‫‪INPUTS AND‬‬ ‫‪3‬‬ ‫‪OUTPUTS‬‬ ‫‪48‬‬ ‫‪6/2/2024‬‬ ‫المخرجات والمدخﻼت – ‪INPUTS AND OUTPUTS‬‬ ‫المخرجات‪:‬‬ ‫▸‬ ‫لعرض نص ‪:‬‬ ‫‪‬‬ ‫القاعدة العامة لعرض نص على الشاشة استخدام عﻼمة التنصيص المزدوجة " او المفردة ‘ مثﻼ‪:‬‬ ‫‪‬‬ ‫‪49‬‬ ‫‪49‬‬ ‫المخرجات والمدخﻼت – ‪INPUTS AND OUTPUTS‬‬ ‫المخرجات‪:‬‬ ‫▸‬ ‫مثال‪:‬‬ ‫‪‬‬ ‫اكتب برنامج لعرض جملة ”!‪“Hello world‬‬ ‫‪‬‬ ‫لتنفيذ البرنامج يتم كتابة اسم )(‪ main‬كما هو مبين‪.‬‬ ‫‪‬‬ ‫واستخدام اﻻمر ‪ print‬لعرض النص الموجود بين عﻼمات التنصيص " " على شاشة الحاسوب‬ ‫‪‬‬ ‫‪50‬‬ ‫‪50‬‬ ‫‪6/2/2024‬‬ ‫المخرجات والمدخﻼت – ‪INPUTS AND OUTPUTS‬‬ ‫المخرجات‪:‬‬ ‫▸‬ ‫مثال‪:2‬‬ ‫‪‬‬ ‫برنامج لعرض مجموعة من النصوص‪.‬‬ ‫‪‬‬ ‫‪51‬‬ ‫‪51‬‬ ‫المخرجات والمدخﻼت – ‪INPUTS AND OUTPUTS‬‬ ‫المخرجات‪:‬‬ ‫▸‬ ‫لعرض قيمة عددية‪:‬‬ ‫‪‬‬ ‫تستخدم الجملة ‪ print‬لعرض قيمة )او قيم( عددية كاﻻتي‪:‬‬ ‫‪‬‬ ‫‪52‬‬ ‫‪52‬‬ ‫‪6/2/2024‬‬ ‫المخرجات والمدخﻼت – ‪INPUTS AND OUTPUTS‬‬ ‫▸ المخرجات‪:‬‬ ‫‪53‬‬ ‫‪53‬‬ ‫المخرجات والمدخﻼت – ‪INPUTS AND OUTPUTS‬‬ ‫المدخﻼت‪:‬‬ ‫▸‬ ‫كيف يتم اسناد قيمة لمتغير؟‬ ‫‪‬‬ ‫يمكنك استخدام دالة ` `)(‪input‬ﻻستقبال إدخال من المستخدم‪.‬‬ ‫‪‬‬ ‫هذه الدالة تقوم بقراءة اﻹدخال من واجهة المستخدم )مثل سطر اﻷوامر( وترجع القيمة‬ ‫‪‬‬ ‫كنص‪.‬‬ ‫ﻻحظ أنه يجب عليك تحويل القيمة المسترجعة من ` `)(‪input‬حسب الحاجة إلى نوع‬ ‫‪‬‬ ‫البيانات المناسب‪.‬‬ ‫وحفظ القيمة المدخلة في متغير‪.‬‬ ‫‪‬‬ ‫‪54‬‬ ‫‪54‬‬ ‫‪6/2/2024‬‬ ‫المخرجات والمدخﻼت – ‪INPUTS AND OUTPUTS‬‬ ‫▸ المدخﻼت‪:‬‬ ‫مثال‪ :‬برنامج يقرا رقم القيد واسم الطالب والمتوسط المتحصل عليه في الثانوية وعرضها على الشاشة‬ ‫‪‬‬ ‫مﻼحظة‪:‬‬ ‫▸‬ ‫‪\n‬‬ ‫▹‬ ‫يعني اﻻنتقال الي سطر جديد‬ ‫‪55‬‬ ‫‪55‬‬ ‫المخرجات والمدخﻼت – ‪INPUTS AND OUTPUTS‬‬ ‫▸ المدخﻼت‪:‬‬ ‫مﻼحظات‬ ‫‪‬‬ ‫‪56‬‬ ‫‪56‬‬ ‫‪6/2/2024‬‬ ‫المخرجات والمدخﻼت – ‪INPUTS AND OUTPUTS‬‬ ‫المدخﻼت‪:‬‬ ‫▸‬ ‫إسناد قيم للمتغيرات باستخدام جملة التعيين ‪Assignment statemen‬‬ ‫‪‬‬ ‫يتم استخدام عملية تسنيد ) ‪Assignment).‬يتيﺢ لك هذا العمل إعطاء قيمة لمتغير بحيث يمكنك استخدامها ﻻحقًا في البرنامج‪.‬‬ ‫‪‬‬ ‫‪57‬‬ ‫‪57‬‬ ‫المخرجات والمدخﻼت – ‪INPUTS AND OUTPUTS‬‬ ‫▸ المدخﻼت‪:‬‬ ‫ما نوع القيمة التي تم تخزينها بالجملة التالية؟‬ ‫‪‬‬ ‫”‪student_id = “123456789‬‬ ‫نصية‪:‬‬ ‫▸‬ ‫وﻻ يمكن استخدامها في أي عملية حسابية اﻻ بعد تحويلها الي قيمة رقمية من النوع الصحيﺢ‬ ‫▹‬ ‫)‪student_id = int(student_id‬‬ ‫‪58‬‬ ‫‪58‬‬ ‫‪6/2/2024‬‬ ‫المخرجات والمدخﻼت – ‪INPUTS AND OUTPUTS‬‬ ‫▸ المدخﻼت‪:‬‬ ‫يظهر رسالة للمستخدم توجيهه ﻹدخال نص‬ ‫يقوم بقراءة المدخﻼت التي أدخلها المستخدم ويخزنها في‬ ‫متغير‬ ‫يطبع المدخﻼت التي قام المستخدم بإدخالها‬ ‫‪59‬‬ ‫‪59‬‬ ‫"التعلم هو الركيزة التي تبني بها جسر النجاح‪".‬‬ ‫‪60‬‬

Use Quizgecko on...
Browser
Browser