0% found this document useful (0 votes)
12 views

AI - Assignment 2 Zaryab Khan

Artificial intelligence

Uploaded by

zaryab6742
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

AI - Assignment 2 Zaryab Khan

Artificial intelligence

Uploaded by

zaryab6742
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

ASSIGNMENT#2

Name: Zaryab Khan


Roll No: 301-211004
Submitted To: Dr. Hammad
Subject: Artificial Intelligence
Semester: 6th
Class: BSCS
Section: ‘A’

Question 01:
Explain and compare the well-known python Libraries including
Tensor Flow, Numpy, Keras, Pytorch, Nango, Jiango etc

Answer:
NumPy
 Core foundation: NumPy (Numerical Python) is the fundamental building block for
scientific computing in Python. It offers high-performance multidimensional arrays,
linear algebra operations, and mathematical functions.
 Data structures: NumPy excels at working with large datasets represented as
dimensional arrays, providing efficient manipulation and calculations.
 Strengths:
o Fast and efficient array operations
o Linear algebra routines (matrix multiplication, inversion, etc.)
o Basic statistical functions
o Integration with other libraries like TensorFlow, SciPy, and Matplotlib
 Example:
Python
import numpy as np
data = np.array([1, 2, 3, 4, 5])
mean = np.mean(data)
print(mean) # Output: 3.0

TensorFlow
 Deep learning framework: TensorFlow is a powerful open-source library developed by
Google for numerical computation, large-scale machine learning, and deep learning.
 Computational graphs: It builds computational graphs that define the relationships
between data (tensors) and operations. TensorFlow can execute these graphs on
various platforms (CPUs, GPUs, TPUs).
 Strengths:
o Versatile for various machine learning tasks, from linear regression to deep
neural networks
o Production-ready with scalability and deployment options
o Integration with other Google tools like TensorFlow Lite and TensorFlow.js
o Example:

Python Code
import tensorflow as tf
x = tf.constant([1, 2, 3])
y = tf.constant([4, 5, 6])
dot_product = tf.reduce_sum(x * y)
print(dot_product.numpy()) # Output: 32

Keras
 High-level API: Keras is a high-level API built on top of TensorFlow that provides a
simpler and more user-friendly interface for building and training neural networks. It
abstracts away some of the lower-level details of TensorFlow, making it easier to get
started with deep learning.
 Strengths:
o Easier to use and quicker to prototype deep learning models compared to
TensorFlow
o Supports various neural network architectures (convolutional, recurrent, etc.)
o Seamless integration with TensorFlow for advanced customization
o Example:

Python
from tensorflow import keras
model = keras.Sequential([
keras.layers.Dense(4, activation='relu',
input_shape=(784,)),
keras.layers.Dense(10, activation='softmax')
])
model.compile(optimizer='adam',
loss='categorical_crossentropy', metrics=['accuracy'])
# ... (training code)

PyTorch
 Dynamic computational graphs: PyTorch is another popular open-source deep learning
framework known for its dynamic computational graphs. This allows for more flexibility
in defining models on the fly during training.
 Strengths:
o Ease of use with Pythonic syntax
o Efficient automatic differentiation for gradient calculations
o Active research community and extensive ecosystem
o Example:

Python
import torch
x = torch.tensor([1, 2, 3])
y = torch.tensor([4, 5, 6])
dot_product = torch.dot(x, y)
print(dot_product) # Output: tensor(32)

SciPy
 Scientific computing: While not strictly a deep learning library, SciPy (Scientific Python)
complements NumPy by providing a collection of algorithms and functions for various
scientific computing tasks, including optimization, integration, interpolation, and signal
processing.
 Strengths:
o Broad range of scientific computing tools
o Integration with NumPy and other scientific libraries
o Example:

Python
import scipy.optimize
def objective(x):
return x**2 - 4*x + 6
result = scipy.optimize.minimize(objective, 2)
print(result.x) # Output: 3.0 (minimum of the objective
function)

Matplotlib
 Visualization: Matplotlib is a fundamental library for creating static, animated, and
interactive visualizations in Python. It's invaluable for data exploration, model analysis,
and generating publication-quality plots.
 Strengths:
o Wide variety of plot types (line, scatter, histogram, etc.)
o Customization options for fine-tuning plot appearance
o Integration with other scientific Python libraries
o Example:

Python
import matplotlib.pyplot as plt
x = [1, 2, 3, 4]

Question 03:
Explain the reinforcement learning with real world examples

Answer:
Reinforcement learning (RL) is a type of machine learning where an agent interacts with its
environment, learns from its experiences (rewards and penalties), and takes actions to
maximize a long-term goal. Unlike supervised learning with labeled data, RL doesn't receive
explicit instructions but figures out optimal behavior through trial and error.

Here's how it works:


1. Agent: The learning entity that interacts with the environment.
2. Environment: The world the agent operates in, providing feedback through rewards or
penalties.
3. Action: The choices the agent makes in the environment.
4. Reward: Positive feedback for desirable actions that move the agent closer to its goal.
5. Penalty: Negative feedback for undesirable actions.

Real-World Examples of Reinforcement Learning:


1. Playing Games: AI agents in games like AlphaGo or chess programs learn through trial
and error, experimenting with different moves and strategies to win against better
opponents.
2. Robot Navigation: Robots in warehouses or factories use RL to navigate their
environment, avoiding obstacles and optimizing delivery routes by receiving rewards for
reaching their estination efficiently.
3. Traffic Light Control: RL algorithms can be used to dynamically adjust traffic light timings
based on real-time traffic flow data. The system receives rewards for smoother traffic
flow and minimizes penalties for congestion.
4. Recommendation Systems: Recommender systems on e-commerce platforms or
streaming services use RL to personalize recommendations for users. The system learns
user preferences and receives rewards for providing relevant suggestions, leading to
increased user engagement.
5. Dynamic Pricing: RL algorithms can be used by companies to set dynamic prices for
products or services based on market demand and customer behavior. The system
receives rewards for maximizing profits while maintaining customer satisfaction.
Key Advantages of Reinforcement Learning:
1. Adapts to Changing Environments: RL agents can learn and adapt to new situations as
the environment changes, making them suitable for complex realworld problems.
2. Doesn't Require Explicit Instructions: Unlike supervised learning, RL doesn't require
pre-labeled data. It can learn by interacting with the environment and receiving
feedback.
3. Long-Term Goal Optimization: RL agents learn to make decisions that maximize their
long-term goals, considering the consequences of their actions over time.
4.

However, RL also has some challenges:


 Exploration vs. Exploitation: RL agents need to balance exploring new actions to learn
more about the environment versus exploiting what they already know to maximize
immediate rewards.
 High Computational Cost: Training RL models can be computationally expensive,
especially for complex environments with many possible actions.
 Reward Design: Defining the right reward structure is crucial for directing the agent's
learning towards the desired goals.

You might also like