PageRank Calculation in Simplist Form - From Adjancy Matrix - math

I was asked to create an adjancy matrix from a table of:
A B C
A 0 1 0
B 1 0 1
C 0 0 0
I got this:
A B C
A 1/6 2/3 1/6
B 5/12 1/6 5/12
C 1/6 1/6 1/6
I am now being asked if I can sketch out in words, formulas or pseudocode, how I can calculate from the matrix using matrix multiplication. I have tried reading the book on information but I cannot understand it.
Can anyone please tell me how I can do this in words, without too many math related symbols or explain the symbols to me. I am currently here in the IR book:
http://nlp.stanford.edu/IR-book/pdf/21link.pdf
I am panicking as I will be asked this but I am not sure at all!
Even if I had it just in words in a simple form, that would be great!
Thanks guys!

You have to do an eigenvalue calculation.
http://www.rose-hulman.edu/~bryan/googleFinalVersionFixed.pdf

Related

Division in Projection Matrices

Disclaimer: This question is not the same question as other projection matrix questions.
So Projection Matrices are 4x4 Matrices that are multiplied with 4D vectors to flatten them onto a 2D plane. Like this one:
1 0 0 0
0 1 0 0
0 0 0 0
0 0 1 0
But in the explanation, it says that the x and y coordinates of the vector are divided by Z. But I don't understand how this works because each part of the matrix that is multiplied by Z is 0. A comment in another question on this subject said, "The hardware does this for you." And I didn't quite get what it meant by that. Thank you in advance!
I was confounded by this nomenclature issue, too. Here is a bit better explanation in regards to Vulkan: https://matthewwellings.com/blog/the-new-vulkan-coordinate-system/
After the programmable vertex stage a set of fixed function vertex operations are run. During this process your homogeneous coordinates in clip space are divided by wc
Clearly, calling those matrices projection matrices is very misleading if the actual perspective correction isn't actually done by them. :)

How to split a sequence in k homogeneous parts?

I'd like to split a sequence into k parts, and optimize the homogeneity of these sub-parts.
Example : 0 0 0 0 0 1 1 2 3 3 3 2 2 3 2 1 0 0 0
Result : 0 0 0 0 0 | 1 1 2 | 3 3 3 2 2 3 2 | 1 0 0 0 when you ask for 4 parts (k = 4)
Here, the algorithm did not try to split in fixed-length parts, but instead tried to make sure elements in the same parts are as homogeneous as possible.
What algorithm should I use ? Is there an implementation of it in R ?
Maybe you can use Expectation-maximization algorithm. Your points would be (value, position). In your example, this would be something like:
With the E-M algorithm, the result would be something like (by hand):
This is the desired output, so you can consider using this, and if it really works in all your scenarios. An annotation, you must assign previously the number of clusters you want, but I think it's not a problem for you, as you have set out your question.
Let me know if this worked ;)
Edit:
See this picture, is what you talked about. With k-means you should control the delta value, this is, how the position increment, to have its value to the same scale that value. But with E-M this doesn't matter.
Edit 2:
Ok I was not correct, you need to control the delta value. It is not the same if you increment position by 1 or by 3: (two clusters)
Thus, as you said, this algorithm could decide to cluster points that are not neighbours if their position is far but their value is close. You need to guarantee this not to happen, with a high increment of delta. I think that with a increment of 2 * (max - min) values of your sequence this wouldn't happen.
Now, your points would have the form (value, delta * position).

Can anyone recommend some Transformation Matrix tutorials for dummies? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
Can anyone recommend some good starting points for understanding Transformation Matrices for dummies like me with poor math skills.
I'm willing to learn the math, and I'm not a complete idiot (I hope) but the examples I'm finding seem to require a huge leap from what I know, to what I need to know.
I wrote a web program that can be used to play around with transformation matrices. It allows preset types and custom ones.
Play with it online or grab the source.
It should be easy to play with the numbers and instantly see how it affects the house drawing. Look at the code available online to determine what it's doing, and you should be able to understand what's going on.
If you're having trouble, realise that the 3×3 matrix is simply being multiplied by each vertex (X & Y coordinate) in the house shape. Matrix multiplication with the vertex (we will now refer to it as a vector) and a transformation matrix looks like so...
1 0 0 1
0 1 0 * 2
0 0 1 0
On the left is an identity matrix (an idempotent matrix that doesn't affect the vector) and a vector of 1, 2, 0 (assume this maps to position X1 and Y2 in the program mentioned above's graph and ignore the final 0).
Matrix multiplication can be visualised like so...
a b c x a * x + b * y + c * z
d e f + y = d * x + e * y + f * z
g h i z g * x + h * y + i * z
So, in our example, that would be...
1 0 0 1 1 * 1 + 0 * 2 + 0 * 0
0 1 0 * 2 = 0 * 1 + 1 * 2 + 0 * 0
0 0 1 0 0 * 1 + 0 * 2 + 1 * 0
Do that math and we get the final vector...
1
2
0
Since we said our identity matrix shouldn't modify the values, we can see above that that is the case as the resulting vector matched the original.
To explain further, consider when you need to translate the vector. Let's say we want to translate the house by 5 pixels along the X axis. We want to start with the identity matrix, but change the top right number to 5 and make the extra dimension in the vector 1 (you will see why briefly).
1 0 5 1 1 * 1 + 0 * 2 + 5 * 1
0 1 0 * 2 = 0 * 1 + 1 * 2 + 0 * 1
0 0 1 1 0 * 1 + 0 * 2 + 1 * 1
We do the math again...
6
2
1
We can see that the first number (X in our coordinates) has been translated along the X axis by 5. Try it in the program linked above.
The reason we made the third value 1 is so when the math was performed, the translation was considered. Had it been 0, it will be ignored, as any number multiplied by 0 results in 0.
If you're still having trouble, check out videos online (this one, for example) which can help explain it in a more visual fashion.
Remember: pretty much anyone can drive a car, and pretty much anyone can learn this, despite any self-evaluated poor understanding of math. Just keep at it: persistence is key. Good luck.
Like duffymo has pointed out, Matrix Transformations is nothing more but (pre)multiplying a vector (like a 3d point) by a matrix. However, that is pure mathematics, and hard for some people to visualise.
The best way to understand transformation matrices (at least for me) is to get an example code, get it running, and play around with the numbers. Try to see if you can place an object farther away, or rotated by 45 degrees. Try putting the transformations in different order and see what the results are.
All working? Good.
Once you get a feel of that, and if you're brave enough to tackle the maths, you could take these steps:
First, understand how matrix multiplications work. Some links:
http://en.wikipedia.org/wiki/Matrix_multiplication
http://www.gamedev.net/reference/list.asp?categoryid=28#259
Also borrow highschool math textbooks from any of your friends.
Google is your friend.
Once you are comfortable with multiplying a matrix by hand, you will get a feel of why transformations are written that way. As you use them, the understanding of matrices will eventually come to you.
Secondly, I always recommend spending an afternoon trying to implement your own Matrix class and define a few common operations like mul(Vector v), transpose() or even createTranslationMatrix(float x, float y, float z). Put in a few tests and see if the results are the same with what you did by hand.
If you've come that far, try implementing your own Perspective Transformation! It's the most amazing thing we never come to appreciate. A useful explanation here:
Deriving Projection Matrices
You will be very proud of yourself once you have accomplished one of the most labourous, yet under-appreciated tasks of implementing a matrix object. Good luck!
A transformation is nothing more than a matrix multiplying a vector to produce the transformed vector, so if you don't understand matrix multiplication and addition you can't get very far.
Start with matricies and linear algebra. There are lots of books out there, but realize that based on the statement that I made above you don't need to read that whole book. You won't need eigenvalues or Gaussian elimination or vector spaces or any of the other stuff that will be advanced and difficult.
You just need to know how to extend what you know about multiplying and adding numbers to matricies.
Getting the entries in that transformation matrix is another matter altogether. You'll need a good book on mathematics and computer graphics. You won't find that in a linear algebra textbook.

Matrix operations to enumerate all paths through n-partite graph

I have an n-partite (undirected) graph, given as an adjacency matrix, for instance this one here:
a b c d
a 0 1 1 0
b 0 0 0 1
c 0 0 0 1
d 0 0 0 0
I would like to know if there is a set of matrix operations that I can apply to this matrix, which will result in a matrix that "lists" all paths (of length n, i.e. through all the partitions) in this graph. For the above example, there are paths a->b->d and a->c->d. Hence, I would like to get the following matrix as a result:
a b c d
1 1 0 1
1 0 1 1
The first path contains nodes a,b,d and the second one nodes a,c,d. If necessary, the result matrix may have some all-0 lines, as here:
a b c d
1 1 0 1
0 0 0 0
1 0 1 1
0 0 0 0
Thanks!
P.S. I have looked at algorithms for computing the transitive closure, but these usually only tell if there is a path between two nodes, and not directly which nodes are on that path.
One thing you can do is to compute the nth power of you matrix A. The result will tell you how many paths there of length n from any one vertex to any other.
Now if you're interested in knowing all of the vertices along the path, I don't think that using purely matrix operations is the way to go. Bearing in mind that you have an n-partite graph, I would set up a data structure as follows: (Bear in mind that space costs will be expensive for all but small values.)
Each column will have one entry of each of the nodes in our graph. The n-th column will contain 1 in if this node is reachable on the n-th iteration from our designated start vertex or start set, and zero otherwise. Each column entry will also contain a list of back pointers to the vertices in the n-1 column which led to this vertex in the nth column. (This is like the viterbi algorithm, except that we have to maintain a list of backpointers for each entry rather than just one.) The complexity of doing this is (m^2)*n, where m is the number of vertices in the graph, and n is the length of the desired path.
I'm a little bit confused by your top matrix: with an undidrected graph, I would expect the adjacency matrix to be symmetric.
No, There is no pure matrix way to generate all paths. Please use pure combinatorial algorithms.
'One thing you can do is to compute the nth power of you matrix A. The result will tell you how many paths there of length n from any one vertex to any other.'
The power of matriax generates walks not paths.

How do I calculate the number of permutations in base 3 combinatorics?

I've never been much for math and I'm hoping that someone can help me out with the following.
I have 5 boxes:
1 2 3 4 5
[ ] [ ] [ ] [ ] [ ]
The boxes can either be white, gray, or black (or think of it as 0, 1, 2)
How many possible states can the box set be in?
What is the pseudocode (or in any language) to generate all the possible outcomes??
ie...
00000
00001
00011
00111
etc, etc...
I really appreciate any help anyone can give me with this.
the answer for the number of combinations is: 3x3x3x3x3 (3^5) since each box can have 3 possible colors.
As for generating the outcomes, see if you can figure it out using this matrix with 0, 1, or 2 to represent the color of the box. On a smaller scale (lets assume 3 boxes) it would look like this:
0 0 0
0 0 1
0 0 2
0 1 0
0 1 1
0 1 2
0 2 0
0 2 1
0 2 2
1 0 0
1 0 1
1 0 2
1 1 0
1 1 1
1 1 2
1 2 0
1 2 1
1 2 2
2 0 0
2 0 1
2 0 2
2 1 0
2 1 1
2 1 2
2 2 0
2 2 1
2 2 2
This is a classic permutation generation problem. You have 3 possibilities for each position, and 5 positions. The total number of generated string is 3^5 = 243.
You need recursion if you want a general solution (a simple iterative loop only works for a single instance of the problem).
Here's a quick example:
public static void Main(string[] args){
Generate("", 5);
}
private void Generate(string s, int limit)
{
if (s.Length == limit)
Console.WriteLine(s);
else
{
Generate(s+"0", limit);
Generate(s+"1", limit);
Generate(s+"2", limit);
}
}
To answer your first question, what would the answer be if the boxes could contain only one of two values? So, what's the answer if the boxes contain one of three values?
To answer your second question, what pseudocode generates all possible outcomes of one box? Now, pseudocode generates all possible outcomes of two boxes?
I'd recommend solving the problem on paper first. Try to solve it with a smaller number of boxes (maybe three), and list all possibilities. Then, think of how your reasoning went, or how you'd explain what you did to a small child.
This seems like a homework problem. I'll just give you some help as to the solution then.
What you are saying is that each box has three states, which are all independent. One box would have 3 solutions, and two boxes would have 3 * 3 solutions - for each state of the first box the second box would have three states as well. Extend that to 5 boxes.
To generate each solution, you can just cycle through it. It is easy to make nested for loops for each box, and multiplying by powers of 10 can let you show the number at once.
You can generalize the code for multiple boxes in a similar way.
Thank you all for your answers, at least those of you who actually gave me one.
While I can appreciate that the question sounded like it was pulled straight out of Computer Science 101, it wasn't. The irony of the matter is that it was for real life on a real deadline and I didn't have time to hearken back to when I was being taught this stuff and said to myself, "when am I ever going to need this crap"
If I wanted to be patronized and treated like a school boy I would go back to my elementary school and ask my 5th grade teacher if I can go to the bathroom
Thanks again
the number of states is 3^5.
pseudocode is
for value from 0 to 3^5-1
print base3(value)
where base3 is a function that repeatedly takes modulo 3 to get a digit, then removes that digit (by dividing by 3)
Hint: imagine that each box is a position in a number and each colour is a different digit. In the real world, how many combinations (including zero) do you get with 2 positions and 10 possible digits? What about 3 positions? What's the relationship between adding an extra position and the number of combinations, given the number of digits you have available?
Unique number of combinations: 3^5=243
Code:
n = 0
for i = 0 to 3^5-1
{
s = ""
for j = 1 to 5
{
d = n mod 3
s = toascii(d) . s
n = n / 3
}
println s
i = i + 1
}
Here's how I first learned to do this: first think about how many choices you are making. You are making five choices, one for each box. So write down five blank lines with multiplication signs:
__ x __ x __ x __ x __ = ?
In each blank, write the number of objects you have to choose from for that box. Since you have 3 numbers to choose from for each box, you write a 3 in every blank:
3 x 3 x 3 x 3 x 3 = 243
This gives you the total number of permutations for those choices.
The number of possibilities is 3 to the power 5
If you loop from 0 to that number minus 1 and express it in base 3 you will have all the possibilities (remember to prepend 0s where necessary)
In Ruby:
number_of_possibilities = 3**5-1
for i in (0..number_of_possibilities)
base_3_number = i.to_s(3)
puts "%05d" % base_3_number # number formatting used to prepend 0s where necessary
end
Can I ask what about this you don't understand or whats tripping you up? I see that everyone here has simply answered the question, but if you've copied their answers, you've learned nothing, and thus completely missed the point of the homework. Assuming your next lesson builds upon this one, you're just going to fall further behind.
If you either worked for me or were in my class I'd simply ask the following...
"How do you think the problem should be solved?" The answer to which might reveal where you're getting hung up. A wise professor of mine at CMU once said "I can't help you understand this until you know what you don't understand" I never did figure out what I didn't understand and I dropped his class, but the lesson stuck with me.
I know its probably too late, but for these homework questions I really think we should be helping the person learn as opposed to simply providing an answer and doing their homework for them.
Your problem needs nothing more than the rule of product in combinatorics.
You can choose the state of the first box in 3 ways, and the state of the second box in 3 ways, and ... and the state of the 5th box in 3 ways. The number of ways in which you can set the state of all the boxes is the product of all the five (equal) numbers of ways, i.e. 3x3x3x3x3 = 35.
Similar question: how many numbers can you form with 5 digits in the decimal system, counting the leading zeros? That is, how many numbers are there from 00000 to 99999? You can choose the first digit in 10 ways (0...9), and so on and so on, and the answer is 10x10x10x10x10 = 100000, as you already know.
Don't even try to write code to answer this! The reason is that you need some very large numbers (factorials) to calculate it. These create numbers much larger than any base type in the CLR. You can use this opensource library to do the calculation.
void solve(int p=0,int n=5,int d=0)
{
if (n==p)
{
int rev=d;
int i=0;
while (i<5) {
cout << rev%10;
rev /= 10;
i++;## Heading ##
}
cout << endl;
return;
}
for(int i=0; i<3 ; i++)
{
solve(p+1,n, d*10 + i);
}
}

Resources