AI - Assignment 2 Zaryab Khan
AI - Assignment 2 Zaryab Khan
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.