BaseHalf
All posts

The same inner product can be a cost, a score, or a co-occurrence

In the same BaseHalf folder, I grew a second note from printed page 20 in §1.4, read the Applications paragraphs through sentiment, and worked Exercises 1.10, 1.11, and 1.12.

vmls-note-7.md still pointed at the definition on printed page 19, and 07-inner-product.md still had the properties I had checked. I stayed in the same Desktop folder in BaseHalf 0.7.0 and kept reading, now from the Applications paragraphs on printed page 20.

This is part 8 of the close reading of Boyd and Vandenberghe's Introduction to Applied Linear Algebra. I did not start a new canvas. The definition does not change. Each example is the same sum of matching products, with a different meaning for the two lists.

A short note on the same printed page, then the applications

In Card Detail I was on viewer page 30, printed page 20, selected text just above Applications, and chose Grow branch, again from the reader, not from the cover. The new file was vmls-note-8.md. It already listed vmls.pdf as upstream and pointed at page 30.

The selection is very short. It is only the first few letters of the sentence that closes the block-vector paragraph: the inner product of block vectors is the sum of the inner products of the blocks. The note title and the quoted line both stop at "The inn", so I am not treating that fragment as the whole sentence, and I am not treating it as a substitute for the Applications paragraphs that start immediately below it on the same page. That closing sentence was the last general fact I already had in 07-inner-product.md. I used the note as a hook to stay on printed pages 20-22 and read the applications, then wrote them into 08-inner-product-applications.md.

If a and b are 0-1 occurrence vectors, a^T b counts the indices where both entries are 1, which is also the number of objects in the intersection of the two subsets. I redid the book's 7-object example on that page, with 1-based indexes: a = (0, 1, 1, 1, 1, 1, 1) and b = (1, 0, 1, 0, 1, 0, 0) give 0·1 + 1·0 + 1·1 + 1·0 + 1·1 + 1·0 + 1·0 = 2. The two shared objects are 3 and 5. I also checked a shorter pair of my own: a = (1, 1, 0, 1) and b = (1, 0, 1, 1) give 2.

If f holds features of an object and w holds weights of the same size, the score is w^T f. I used w = (0.5, 2, −1) and f = (4, 1, 3), which give 2 + 2 − 3 = 1. A negative weight subtracts, so a feature can lower the score. If p holds prices and q holds quantities, p^T q is the total cost. With p = (2, 5, 1) and q = (3, 0, 4), the cost is 10. If a vehicle travels n segments at constant speed in each one, and s holds the speeds while t holds the times, s^T t is the total distance. On two segments, s = (10, 20) and t = (0.5, 0.25) give 10.

If p has nonnegative entries that add up to 1, and f_i is the value of some quantity when outcome i occurs, then f^T p is the expected value. I used p = (0.5, 0.5) and f = (10, 0), which give 5. A polynomial p(x) = c_1 + c_2 x + ··· + c_n x^{n-1} is evaluated at t by the inner product of c with the power vector z = (1, t, t^2, …, t^{n-1}). For p(x) = 2 + 3x and t = 4, I took c = (2, 3) and z = (1, 4), and c^T z = 14, which is p(4).

A cash flow c, with c_i received in period i, has net present value d^T c, where d_i = 1/(1+r)^{i-1}. I checked a two-period example with r = 1, so the second period is halved: c = (100, 100) and d = (1, 1/2) give 150. If s holds share counts, with a negative entry for a short position, and p holds prices, p^T s is the net value of the portfolio. With p = (10, 4) and s = (3, −2), the value is 22. For returns, the book uses a dollar-holdings vector or a fractional holdings vector w; r^T w is then a fractional return. If r = (0.10, 0.00) and w = (0.5, 0.5), the portfolio return is 0.05, or 5%.

For a crude document score, x is a histogram of word counts, and w marks dictionary words as +1, −1, or 0 according to a positive, negative, or neutral label. Then w^T x adds the positive counts and subtracts the negative counts. On a three-word dictionary, if x = (2, 1, 4) and w = (1, −1, 0), the score is 1.

I stopped at the end of §1.4. The next section is about the complexity of vector computations, not another meaning of the inner product.

Exercises 1.10, 1.11, and 1.12

The attempts are in 08-exercises.md. The statements stay in the book, on printed pages 26-27.

In Exercise 1.10, r is a 10-vector: the first eight entries are homework grades on a 0-10 scale, r_9 is the midterm on a 0-120 scale, and r_10 is the final on a 0-160 scale. The course score s should be on a 0-100 scale, with 25% from homework, 35% from the midterm, and 40% from the final, written as s = w^T r.

The eight homework grades first become a 0-100 number, then that number is scaled by 25%. Their average is still on a 0-10 scale, so multiplying by 10 and then by 0.25 gives a contribution of 0.3125 (r_1 + ··· + r_8). The midterm weight is 0.35 · (100/120) = 7/24 = 0.2916…, which is 0.2917 to four digits after the decimal point. The final weight is 0.40 · (100/160) = 0.2500. So

w = (0.3125, 0.3125, 0.3125, 0.3125, 0.3125, 0.3125, 0.3125, 0.3125, 0.2917, 0.2500)

If every homework is 10, the midterm is 120, and the final is 160, then s = 25 + 0.2917·120 + 40 = 100.004. The extra 0.004 is only from rounding 7/24 to 0.2917; the exact midterm weight times 120 is exactly 35. I also checked a record of my own, r = (8, 8, 8, 8, 8, 8, 8, 8, 96, 80), which gives 20 + 28.0032 + 20 = 68.0032, or exactly 68 with the unrounded midterm weight.

In Exercise 1.11, w is the word-count vector for a document against a dictionary of n words, and every word in the document is assumed to be in the dictionary. 1^T w is the total number of words. w_282 = 0 means word 282 in the dictionary does not appear in the document. The histogram is h = (1 / (1^T w)) w. I checked this on w = (2, 0, 6): the total is 8, and h = (0.25, 0, 0.75).

In Exercise 1.12, c is a 5-vector of cash holdings in USD, RMB, EUR, GBP, and JPY, in that order, so c_2 is the number of RMB held. A negative entry is a liability. The total net value in USD is p^T c, where p is also a 5-vector: p_i is the value in USD of one unit of currency i. In particular p_1 = 1. The other four entries are the exchange rates, in USD per one unit of each remaining currency. I checked the shape on made-up rates, not taken from a table: if p = (1, 0.14, 1.10, 1.30, 0.0065) and c = (100, 0, 20, −10, 0), then p^T c = 109. The owed pounds subtract, and the currencies with a zero holding drop out.

I checked all three exercises against the definition and the general examples in 07-inner-product.md, the application notes in 08-inner-product-applications.md, and the ones-vector notation in 01-notation.md, not against a solution key. I did not ask an agent to grade them in this session.

The same study folder after the Applications paragraphs of §1.4: the book, the notes from parts 1 to 7, the second Grow branch note, and the application and exercise notes, with connections already in the files.

What stays for the next section

vmls-note-8.md, 08-inner-product-applications.md, and 08-exercises.md now sit in the same folder as the inner-product definition. §1.4 is finished only in the sense that I have read the section and tried representative exercises that need it. The complexity of vector computations, §1.5, is still next.

This is part 8 of Learning applied linear algebra with BaseHalf, a close reading of Introduction to Applied Linear Algebra. Previous: The inner product adds the matching products.