TASK 2

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

np.argmax()

>>> a = np.array([[0, 1, 2], [7, 4, 5]]) >>> np.argmax(a, axis=1) array([2, 0])

Make a np.array deep copy:

>>> x = np.array([1, 2, 3]) >>> y = x >>> z = np.copy(x) modify x change y, but doesn't change z >>> f = np.zeros(3) >>> f[:] = x[:] not sure, but f should be a deep copy

the index of an array can be a list

>>>arr = np.array([11, 22 ,33, 40, 50, 60, 77, 88, 99]) >>>print(arr[[1,2,3]]) [99 88 77 60 50 40 33 22 11] [22 33 40]

Example 2: Remove Elements Equal to Some Value in List

#define original array of values original_array = np.array([1, 2, 2, 4, 5, 7, 9, 12, 12]) #remove elements whose value is equal to 2, 5, or 12 new_array = np.setdiff1d(original_array, [2, 5, 12]) #view new array print(new_array) [1 4 7 9]

data = np.expand_dims(data, axis=2) print(data.shape) data = np.expand_dims(data, axis=0) print(data.shape)

(2, 2, 1) (1, 2, 2) #add 1 dimension to selected axis: x,y,z

recommendation system

A: Collaborative Filtering Systems intuition PS: Collaborative filtering systems generate recommendations based on the preferences of many users that are identified to be similar to you. Collaborative filtering is the process of predicting the interests of one user by identifying preferences and information from many users. 识别许多用户的偏好和信息 The underlying intuition behind collaborative filtering is that if users A and B have similar tastes in a product, then A and B are likely to have similar tastes in other products as well. B: Content-Based Systems intuition PS: Content-based systems generate recommendations based on the user's profile and previous preference. They try to match users to items that they've liked previously. The level of similarity between items is generally established based on attributes of items liked by the user. Unlike most collaborative filtering models which leverage ratings between the target user and other users, content-based models focus on the ratings provided by the target user themselves. PS: B learns from the consumer's past, and can only generate a recommendation based on information already have from that user, more passively, while A predict the consumer's future need (without looking at the consumer's past information), so it recommendation is more active I think. Imagery(意象): a closed circle, out of the box, cross different groups, requires a more reactive environment, and has an issue of cold start since it asks for a more reactive dataset.

np.random.randint(3)

Basically, the randint() method in Python returns a random integer value between the two lower and higher limits (including both limits)

matrix vector multiplication python numpy using numpy.dot or a.dot(b)

Because numpy arrays are not matrices, the standard operations *, +, -, / work element-wise on arrays. PS: I think this just mean you can use these operators on the numpy array directly, and they work element-wise when both side operand are array. a = np.array([1,2,3]) b = np.array([1,2,3]) print(a+b) And when one side is a single number, that's what we called Braodcasting. a = np.array([1,2,3]) b = 2 print(a+b)

numpy.clip(a, a_min, a_max)

Clip (limit) the values in an array. if an interval of [0, 1] is specified, values smaller than 0 become 0, and values larger than 1 become 1. clip meaning truncate

Why Numpy cont.

Elements in NumPy arrays are stored contiguously in memory, allowing for more efficient computations NumPy arrays consume less memory than traditional lists NumPy arrays offer useful operations that can be done efficiently and are often tailored for the needs of machine learning

G_x: change in x, horizontal change

G_y: change in y, vertical change

Davies-Bouldin index and Silhouette Coefficient

Hello, the thing is, we can't really say what clustering quality measure is good or not. The very notion of "good clustering" is relative, and is a question of point of view. The same applies for the quality measures. It depends on what you want to evaluate. For instance, the Davies-Bouldin Index evaluates intra-cluster similarity and inter-cluster differences. If you consider these to be good criteria, go for the Davies-Bouldin. The Silhouette Index measure the distance between each data point, the centroid of the cluster it was assigned to and the closest centroid belonging to another cluster. If you consider that this is a good criterion, go for the silhouette index. The same goes with all quality measures. You have to look what these quality indexes are measuring and check wether or not it seems relevant for the kind of clustering you are doing. Other aspects that you may want to consider are wether or not these quality measures are normalized. For instance, the silhouette index is normalized and a value close to 1 is always good (for this index) whatever clustering you are trying to evaluate. However, the Davies-Bouldin for instance is not normalized and it's difficult to compare 2 values of Davies-Bouldin from different data sets. Another important aspect is to check that the quality measure that you want to apply uses the same metric than the clustering algorithm the results of which you are trying to evaluate. Otherwise, your quality measure will be biased.

misrepresented 不如实叙述的,误传的

If system features are misrepresented to users, coworkers, or supervisors, the individual computing professional is responsible for any resulting injury.

convolution = the process of extracting features from an image input: image -> kernel or filter -> output: feature map

In Computer Vision, convolution is generally used to extract or create a feature map (with the help of kernels) out of the input image.

What causes "fatal: not a git repository"? The fatal: not a git repository error makes it clear that you're not in a git repository, but the reason you're not in such a repository may be one of two: 1. You tried to run the command but did not navigate to the project folder where the git repository is located. 2. You are in the project directory, but you didn't initialize the Git repository for that project folder.

Local repository Remote repository

Use Sobel filter(matrix) to compute G_x, G_y quickly

Note: the 3 by 3 matrix has more weight around the center entries

Pooling

Technically, this is what do the job of extracting by summarizeing In general terms pooling refers to a small portion, so here we take a small portion of the input and try to take the average value referred to as average pooling or take a maximum value termed as max pooling, so by doing pooling on an image we are not taking out all the values we are taking a summarized value over all the values present !!! YET, WE WANT THE OUTPUT TO HAVE THE SAME SHAPE AS INPUT, thus we need padding.

np.square()

Return the element-wise square of the input.

ACM Updates Code of Ethics

The revised Code of Ethics addresses the significant advances in computing technology and the growing pervasiveness of computing in all aspects of society.

Difference between Kernel and Filter Kernel = Filter #when the depth is 1 (when RGB, we have 3 channels so need three kernels)

To be straightforward: A filter is a collection of kernels, although we use filter and kernel interchangeably. Example: Let's say you want to apply a 3x3xN filter to a K x K x N input with stride =1 and pad = 0. So each of the 3 x 3 matrix in 3 x 3 x N filter is a kernel.

jagged array

ValueError: setting an array element with a sequence.

jupyter notebook

What is the difference between Jupyter Notebook and console (cmd)? Jupyter Book comes with a command-line interface similar to the IPython console, but, instead of only being able to work with a single line of code at a time, it allows you to break your code and text into cells. you can easily edit and re-execute any code that had been written in a notebook. Furthermore, you can save a notebook, and thus return to it later.

pad v垫

While applying convolutions we will not obtain the output dimensions the same as input we will lose data over borders so we append a border of zeros and recalculate the convolution covering all the input values. Padding width should be half of the filter's shape (correspondingly)

If I don't use cmap = 'gray' it actually returns a semi-neon green color picture.

You should be using a gray colormap for 3.2. The neon-green is matplotlib.imshow's default colormap ('viridis'). Anytime you are plotting an image with just one color channel (so not a 3 channel RGB type image) it will default to this unless you expressly set it to cmap = 'gray'

x = np.array([1, 2]) print(x) print(x.shape) y = np.expand_dims(x, axis = 0) print(y) print(y.shape)

[1 2] (2,) [[1 2]] (1, 2) Ps: when an array is just initialized, it is a 1D array without dimension. To make this array a vector or a matrix for matrix-vector multiplication, we need to have it's 2D/3D dimension. We can do this by .reshape() or np.expand_dims(). Anyway, pay attention to the denotation [1 2] vs. [[1 2]], the former is an array, the latter is an vector!

Broadcasting

a = np.array([0.0, 10.0, 20.0, 30.0]) >>> b = np.array([1.0, 2.0, 3.0]) >>> a[:, np.newaxis] + b array([[ 1., 2., 3.], [11., 12., 13.], [21., 22., 23.], [31., 32., 33.]])

illuminance照度

a higer way of saying lighting condistions

wild card

a playing card that can have any value

np.concatenate( (a,b) )

a sequence of arrays enclosed in a tuple

Problems with Both Forms of Utilitarianism: Forces us to use a single scale or measure for disparate things

a single scale or measure 一个单一的衡量标准

stride of 2 = every time we skip two columns and convolute

a stride of 1 i.e (no skip)

np.random.choice(a, size=None, replace=False)

a: 1-D array-like or int If an int, the random sample is generated as if it were np.arange(a)

test

answer: standard blur

You can initilize an array simply by arr = []

arr.reshape() arr.size #length arr.shape #sort of (because it has comma) length when matrix is 1d but it's a tuple

Representting RGB Images in NumPy

array = np.zeros([5, 3, 3]) 15 pixels each having 3 color channel

np.argwhere() return an array of indices, but the shape of array is not flatten

array([[0, 1, 2], [3, 4, 5]]) >>> np.argwhere(x>1) array( [[0, 2], [1, 0], [1, 1], [1, 2]])

a = np.array([[11,22,33],[40,50,60],[77,88,99]]) b = a[0:2,0:2] c = a[2,2]

b is slicing PS: 0 included, 2 excluded, stop before it c is indexing

Corner Response Function

basically return a corner likelihood score for each pixel - if the window is the whole image, then score for every pixel?

Prime number definition

can only be divided by two numbers, 1 and itself

intensity in grayscal 100 x 100

color in RGB 100 x 100 x 3 height, width, channel

copyImg = colorImg[1, :, 1]

copying the [line/row, pixels/columns, color channel]

np.random.randn(3,4) #return matrix 3x4

creates an array of specified shape and fills it with random values as per standard normal distribution.

Euclidean distance

dist = np.linalg.norm(x - y) euclidean = np.sqrt((x[0]-y[0])**2 + (x[1]-y[1])**2) print(euclidean) print() print(dist)

pool = window = a portion of the input image we 'circle out', specification of pool determine what we do with those valued in the window, sum, square, average, max, etc. input image pad pool - stride - filter/kernel - calculated values to form a feature map

filter = kernel = a matrix of weights, used to multiply with the window, the product of the filter and window is the resulting value Sums over the product of the filter and the window 广义上不同,狭义上相同 a matrix called kernel which has always odd size

np.argsort()

not returns the sorted array value but an array of indices of the same shape as arr that would sort the array in increasing order (from less to more)

>>> a = np.array([[11,22,33],[40,50,60],[77,88,99]) >>> b = a.reshape(-1) >>> print(b) [11 22 33 40 50 60 77 88 99]

flatten the matrix to 1d reshape to other dimension: y = x.reshape(3,3)

Example of Broadcasting: key here is np.sum() along aixs

for i in range(x.shape[0]): for j in range(y.shape[0]): dist2[i,j] = np.sqrt(np.sum((x[i]-y[j])**2)) for i in range(x.shape[0]): dist2[i] = np.sqrt(np.sum((x[i]-y )**2, axis=1)) it's crazy smart: if we operate entries, we will have to use them for loop, but an entirely vectorized operation doesn't. So it's much faster! https://stackoverflow.com/questions/27948363/numpy-broadcast-to-perform-euclidean-distance-vectorized A has dimensions 2 x 4 B has dimensions 3 x 4 A - B "In order to do element-wise subtraction, we have to pad either A or B to satisfy numpy's broadcast rules. I'll choose to pad A with an extra dimension so that it becomes 2 x 1 x 4, which allows the arrays' dimensions to line up for broadcasting" # add the extra dimension to A A[:,np.newaxis,:] has dimensions 2 x 1 x 4 B has dimensions 3 x 4 Numpy broadcasting(stretching) lining up dimensions from right to left, the number of dimensions doesn't have to be the same, but the aligned dimensions size must be compatible(either same/or 1).

derivative = change = gradient

gradient with respect to x,y = partial derivative

Implementation of NNDR

https://github.com/mmahrouss/Local-Feature-Matching/blob/master/student.py

Code: Implement a sliding kernel matrix over the image using for loop

https://stackoverflow.com/questions/63036809/how-do-i-use-only-numpy-to-apply-filters-onto-images/63041700#63041700?newreg=8e34f58cccca46d8b89c7c7f6c22b382

Code: Pad Border

https://www.geeksforgeeks.org/python-opencv-cv2-copymakeborder-method/

SVD AND Principle component analysis

https://www.youtube.com/watch?v=CpD9XlTu3ys

Feature Detection - interest point detection

identity the interest point What points should we choose? Corner because it's so distinct that change in any direction has a significant change in intensity. How do we detect corner?

broadcasting to swap colors without using loop

img = np.arange(27).reshape((3,3,3)) red = img[:,:,0].copy() blue = img[:,:,2].copy() img[:,:,2] = red img[:,:,0] = blue

If you're doing image processing in Python, then the first thing you'll need to do is load the image.

n Python, there are several toolkits that can help you do this. But if you're doing your image processing in the context of machine learning, one of the best toolkits to do this is the Skimage package.

agent

n.代理人,代理商; 剂

Example 3: Remove Elements Based on Index Position

new_array = np.delete(original_array, [0, 6])

chatGPT

question phrased conversationally

Image: height x width = rows x columns = y-coordinates & x-coordinates

that is, we only need to swap when accessing the corresponding pixel on image use Img[y,x], but other than that, x-coordinate are still in horizontall direction, y - coordinates are in vertical direction

The term broadcasting refers to how numpy treats arrays with different Dimension during arithmetic operations

传播 import numpy as np A = np.array([[11, 22, 33], [10, 20, 30]]) print(A) b = 4 print(b) C = A + b print(C) [[11 22 33] [10 20 30]] 4 [[15 26 37] [14 24 34]]

一个image由lines,pixels,channels 组成

如果我们plot an image with only channel values: R, G, B or L, A, B rgb_image_indoor[..., 0] 那这张图就变成one channel image with不同的red intensity

casts doubt on these claims

对这些说法表示怀疑

Epipolar geometry is the geometry of stereo vision. When two cameras view a 3D scene from two distinct positions, there are a number of geometric relations between the 3D points and their projections onto the 2D images that lead to constraints between the image points.

立体视觉的几何

taking precautions to ensure the accuracy of data,

采取预防措施,以确保数据的准确性

Pngs have an alpha component aside from the r, g, and b channels. You need to remove that alpha component before doing the conversion.

The 4th channel (alpha) is for transparency

"企业扁平化" in English can be translated to "corporate flattening" or "flat organizational structure." This refers to a type of management structure in which there are fewer layers of hierarchy within an organization. In a flat organizational structure, employees often have more autonomy and decision-making authority, as there is less emphasis on strict top-down management. This can lead to increased efficiency, better communication, and a more collaborative work environment. However, it may also present challenges such as ambiguity in roles and responsibilities, and potentially slower decision-making in certain situations.

"corporate flattening" or "flat organizational structure.

chatGPT - smooth

"it's harder for a large-sized company to be aware of all potential employee reactions to being monitored compare to small and medium sized corporation as large companies' employee demographics is more diverse, hence, to consider the implications to each sub-groups and find that balance point is difficult" large companies may struggle to account for all potential employee reactions to monitoring, given their diverse demographics, making it difficult to strike a balance that addresses the concerns of each sub-group

W-2 vs. 1099

1)Employee vs Self-Employed Worker 2)For the former one, income tax is withheld by the company, while for the latter one, you file your own taxes. 3)For the former one, you='re eligible for certain benefits, such as health insurance, retirement plans (401k), and unemployment benefits, while the latter one is NONE. Social Security & Retirement Plan: Both are sources of retirement income (养老金), but they are different in a few key ways. Eligibility: social security requires you to earn 4 credits each year for ten years (must make $6,560 in 2o23 to earn the full four credits), and can get the full retirement income after your full retirement age (in the case of being born on 1972, it's 67), 假设老妈最高工资$54,000, 且缴纳social security tax for 10 years, 按最高的35年,其他25年是0,到67岁后可是领取,每月可以领$1005。没交满35年只是少,没交满10年就没有。假设从以前开始在美国生活,满35年同样条件也只是$2033。 Whether you're an employee who receives a W-2 form or a self-employed worker who receives a 1099 form, your ability to earn Social Security credits is based on the amount of money you earn and pay Social Security taxes on during the year. For self-employed workers, they can buy retirement plans as well, it's called Solo 401k, which works basically the same as W-2's 401K. Neither has a specific minimum contribution period or a specific minimum contribution amount.

Why we use NumPy arrays in machine learning over traditional Python lists?

But how is NumPy so fast ! Python is taking a lot of time to do the same thing. This is because NumPy is written in C and C++ and Python is interpreted. NumPy is a wrapper around C and C++ code. What you see here with numpy_array + 1 actually is processed in the C language and all the loops happen at a much lower level compared to Python, which results in speedups. This means that NumPy is much faster than Python for numerical computations and also has similar rules to C. An example -- all NumPy arrays MUST be of the same type! You cannot mix integers and floats in the same array exactly the same as how C and C++ define their own arrays! We'll discuss this in a bit.

Intensity refers to the amount of light. For grayscale, a greater intensity value means brighter, and a lower value means darker

greater intensity value in gray scale = greater amount of light, less amount of grey

cv2.cvtColor() method is used to convert an image from one color space to another. There are more than 150 color-space conversion methods available in OpenCV. We will use some of color Note: this method converts the image's color space, not individual channel's!

image = cv2.cvtColor(src, cv2.COLOR_BGR2HSV ) image = cv2.cvtColor(src, cv2.COLOR_BGR2GRAY ) image = cv2.cvtColor(src, cv2.COLOR_BGR2LAB)

Let explore what's the difference between * and np.dot() a = np.array([[2,2],[3,3]]) print(a) print() print(a*[1,2]) print() print(np.dot(a,[1,2])) print() print(a*(np.array([1,2]).reshape(2,1))) print() print(np.array([1,2]).reshape(2,1)) print() print(np.dot(a,(np.array([1,2]).reshape(2,1))))

key difference between * and np.dot(): the summing over [[2 2] [3 3]] #2when using *, if the operand is a single element, then it's broadcasting; if the operand is a is array or list, they're treated the same under *, which simply multiplies every element in the operand column to column and row to row, ANYWAY, the Dimension of the matrix/vector remains intact [[2 4] [3 6]] #3when using a dot product, array operand and list operand are treated differently, list, still the same way, multiplies every element in the list column to column and row to row, yet, summing along the row [6 9] [[2 2] [6 6]] [[1] [2]] #6when using a dot product, the array operand, and list operand is treated differently, array, it's treated as a matrix-vector multiplication, and the dimension must match [[6] [9]]

Example 1: Remove Elements Equal to Specific Value

new_array = np.delete(original_array, np.where(original_array == 12))

What is the negative of grayscale image? Image negative is produced by subtracting each pixel from the maximum intensity value. For example in an 8-bit grayscale image, the max intensity value is 255, thus each pixel is subtracted from 255 to produce the output image.

new_intensity = max_intensity - old_intensity.

numpy way of loading/saving

np.load() np.save() .npy file #matrix

np.random.randint(low, high=None, size=None) Return random integers from low (inclusive) to high (exclusive).

np.random.choice(5, 3) array([0, 3, 4]) # random #This is equivalent to np.random.randint(0,5,3)

SIFT descriptor (signature)

once we find the descriptive, unique interest points, we need more information around the point for matching. A point alone is not helpful for matching

Python,IndexError: arrays used as indices must be of integer (or boolean) type

print(matches.dtype) The problem was solved just by converting the float array into int array: matches = matches.astype(int)


Set pelajaran terkait

Вступ до спеціальності

View Set

AP Psychology Sensation & Perception

View Set

5a. Basic Concepts of Sensation and Perception; Vision

View Set

Unit 5: Lesson 2: LS Assignment 2

View Set

Completing the Application, Underwriting, and Delivering the Policy

View Set

Exam 1 sociology Practice Questions

View Set

Year 7 Lesson 2 What is your name?

View Set

Canvas Module 5: Quiz(from Textbook Module 6)

View Set