Math: What do vertical numbers in brackets represent? - math

My prof introduced a concept that required use of a vector, which he represented as follows (imagine there is only one pair of brackets below, tall enough to encapsulate both terms; I don't have the rep to paste an image and don't know how to format this otherwise):
v =
[-1/2]
[1/2 ]
One of my personal weaknesses is a lack of familiarity with mathematical notation. Is there an accepted way of interpreting this kind notation? Does it vary by discipline, or is this something generalizable that I really should know? Is there something intrinsic about this notation that would lead one to interpret it differently than if it were written v = [-1/4, 1/4]?
Thanks for the help!

A vector is a one-dimensional matrix, but it is a matrix nonetheless. Writing it out horizontally instead of vertically or vice versa changes the dimensionality of the matrix, changing its meaning among the rest of the equations.

Very often you will "transform" a vector by multiplying them by a matrix. For instance, to rotate a vector, you have to multiply it by the rotation matrix, etc. If your vectors are codified in columns, a multiplication by a matrix M will act from the left, M * v, because of the way the multiplication works (every row of M by the column vector v.) Alternatively, if your vectors are codified as rows (v = [-1/4, 1/4]) the multiplication will act from the right: v * M, again, because of the "row by column" definition of the multiplication of "matrices".
So, it is up to you to represent vectors as rows or columns provided your convention is consistent with the way you multiply them by matrices.

Related

Tensor multiplication of Rank 3

I have two tensors of rank 3 each, in other words two 3D matrix. I want to take dot product of these two matrix. I am confused to continue with this problem. Help me out with formula to do so.
A 3-way tensor (or equivalently 3D array or 3-order array) need not necessarily be of rank-3; Here, "rank of a tensor" means the minimum number of rank-1 tensors (i.e. outer product of vectors; For N-way tensor, it's the outer product of N vectors) needed to get your original tensor. This is explained in the below figure of so-called CP decomposition.
In the above figure, the original tensor(x) can be written as a sum of R rank-1 tensors, where R is a positive integer. In CP decomposition, we aim to find a minimum R that yields our original tensor X. And this minimum R is called the rank of our original tensor.
For a 3-way tensor, it is the minimum number of (a1,a2,a3...aR; b1,b2,b3...bR; c1,c2,c3...cR) vectors (where each of the vectors is n dimensional) required to obtain the original tensor. The tensor can be written as the outer product of these vectors as:
In terms of element-wise, we can write the 3-way tensor as:
Now, with that background, to answer your specific question, to take the dot product (also called tensor inner product), both tensors must be of same shape (for e.g. 3x2x5 and 3x2x5), then the inner product is defined as the sum of the element-wise product of their values.
where the script X and Y are the same-shape tensors.
P.S.: The tilde in the above formulae should not be interpreted as an approximation.
The vector inner product sum the elementwise products. The tensor inner product follows the same idea. Match the elements, multiply them, and add them all .

scale along a vector in new coordinate system

I want to use V1 to scale something in the 2nd coordinates, but I don't know how to calculate V1', the first coordinates use Transform T to the 2nd coordinate.
what should I do?
thanks.
If I understand your question properly,
V1' = V * T-1
where T-1 is inverse matrix to transform T
About multiply order - there are both "left multiply" and "right multiply" conventions. Vectors for them are row and column. And transformation matrices are transposed. For example, DirectX and OpenGL use different conventions. I don't know what one is used in cocos.

Converting matrix multiplication and sum function from Matlab to R

I'm converting a rather complicated set of code from Matlab to R. I have zero experience in Matlab and am a functioning novice in R.
I have a segment of code which reads (in matlab):
dSii=(sum(tao.*Sik,1))'-(sum(m'))'.*Sii-beta.*Sii./N.*(Iii+sum(Iik)');
Which I've simplified and will focus on the first segment (if I can solve the first segment I'm confident I can perform the rest):
J = (sum(A.*B,1))' - ...
tao (or A) and Sik (or B) are matrices. So my assumption is I'm performing matrix multiplication here (A * B)and summing the resultant column. The '1' is what is throwing me off in that statement. In R, that 1 would likely indicate we're talking about a sum of rows as opposed to columns(indicated by 2). But I can't find any supporting documentation for that kind of Matlab statement.
I was thinking of using a statement like this (but of course, too many '1's and ',')
J<- (apply(A*B, 1), 1, sum)
Thanks for all your help. I searched for other examples here and elsewhere and couldn't find an answer. I'm willing to work for it but this is akin to me studying French (which I don't know) to translate in Spanish (which I'm moderate in) while interpreting the whole process in English. :D
Because of the different conventions in R and Matlab, the idiosyncrasies have to be learned for each (just like your language analogy!). The Matlab command sum(A.*B,1) means multiply A and B element-wise, so they must be the same shape, and then sum along dimension 1, i.e. add each row together to get the column sums. Dimension 1 is the default so, sum(A.*B) would do the same thing as sum(A.*B,1). Because R treats * as element-wise for matrix multiplication, the following Matlab and R codes will produce the same column of numbers in J:
Matlab:
A=[[1,2,3];[4,5,6];[7,8,9]];
B=[[10,11,12];[13,14,15];[16,17,18]];
J=sum(A.*B,1)'; %the ' means to transpose the column sums to be a 3x1 matrix
R:
A<-matrix(c(1,2,3,4,5,6,7,8,9),3,byrow=T)
B<-matrix(c(10,11,12,13,14,15,16,17,18),3,byrow=T)
J<-matrix(colSums(A*B)) # no transpose needed here: nrow(J)==3

Calculating Cosine Similarity of two Vectors of Different Size

I have 2 questions,
I've made a vector from a document by finding out how many times each word appeared in a document. Is this the right way of making the vector? Or do I have to do something else also?
Using the above method I've created vectors of 16 documents, which are of different sizes. Now i want to apply cosine similarity to find out how similar each document is. The problem I'm having is getting the dot product of two vectors because they are of different sizes. How would i do this?
Sounds reasonable, as long as it means you have a list/map/dict/hash of (word, count) pairs as your vector representation.
You should pretend that you have zero values for the words that do not occur in some vector, without storing these zeros anywhere. Then, you can use the following algorithm to compute the dot product of these vectors (pseudocode):
algorithm dot_product(a : WordVector, b : WordVector):
dot = 0
for word, x in a do
y = lookup(word, b)
dot += x * y
return dot
The lookup part can be anything, but for speed, I'd use hashtables as the vector representation (e.g. Python's dict).

Make a matrix full-ranked?

How can I turn a regular matrix into a matrix full-ranked in R? Is there an available method for that?
I have a matrix that may have linearly dependent columns and I need to
pass it to a function that requires its argument to be a matrix with
full rank. Since linearly dependent columns are not of interest
anyway, I am looking for a function that removes such columns until
the matrix is full rank. There may be several solutions of course, but
any one of them should be fine.
Right now I am just constructing the matrix column by column and only
add a column if its the resulting matrix is still fullrank, but it
feels like there should be a better way to do this.
Another approach is to minimize |y - Ax|2 + c |x|2,
by tacking an identity matrix on to A and zeros to y.
The parameter c (a.k.a. λ)
trades off fitting y - Ax, and keeping |x| small.
Then run a second fit with the r largest components of x,
r = rank(A) (or any number you please).

Resources