Vector and Jacobian: From Similarity to an detectable gradient
The two-dimensional search vector, non-linear map and limited differentials are used to connect shapes, local linearization and reverse transmission.
Learning objectives and first steps4 objectives 2 first repairs
Try to do it after reading
- Distinguishing points, cosine, projection from O'Leaks
- Shape for Jacobian according to input output dimensions
- Local linear prediction of output changes and checking of error scales
- Check the gradient of the vector to the mark with a limited differential
Suggested first
- Coordinates, Squares and Square Roots
- One-guide multiply
Retrieve what mathematical objects are shared with the training gradient
Search systems express queries and commodities as vectors; The sequence model compresss a history into a hidden state; The counterfactual model maps user profiles into projections under multiple candidate actions. These scenarios need to be clear about three things: what does a number mean, which axis is a set of numbers, and how to respond to a slightly changed output when input is entered. This chapter begins with two-dimensional synthetic data, and all coordinates and parameters are used only for computation purposes, without matching actual users.
The first step is the one-digit lead and the matrix multiplier. Read after reading should be able to write independently the input output shape of the map, to determine the calibre of two vectors “close closer” and to transmit back the gradient of one mark of loss. Two-dimensional maps are easy to observe; The fact that the conclusions are moved to a high dimension still depends on the same set of algebras does not mean that high-dimensional space must be faithfully displayed in two-dimensional projection.
It doesn't necessarily mean it's more similar
Query vector q = (1,2) and candidate vector k = (2,1). The points are the sum of the corresponding coordinates, with an outcome of 4; Both parameters are root number 5, with a cosine similarity of 0.8. If the candidate is multiplied tenfold (20,10), the count becomes 40, but the cosine remains 0.8. (a) Accumulation is influenced by both length and angle; The cosine normalizes the length. Training targets therefore change the semantics if they express activity or confidence by using vector-mode lengths and suddenly re-unify units when deployed.
E.C. squared is (1-2) 2+ (2-1) 2=2. Only when both sides are normalized to the unit paradigm will the distance square be equal to 2−2 cos tiles, which results in an opposite but consistent ranking with the cosine. Zero vectors have no well defined cosine; The minimal amount of work achieved is only to prevent the elimination of zero and does not create meaningful directions from the air. The projection factor is q k divided by q q, i.e. 4/5, the projection point is 0.8,1.6. References Projection and subspace unit for MIT Check its geometry.
Jacobian is a local map of the disturbance to the output disturbance
Set f(x₁,x₂) =( x ₁²+2 x ₂, x ₁ x 2) both input and output are in 2D real-digit space. Using the column vector, Jacobian 's line output, column input, so the shape is "out dimension multiplied by input dimension". It's the first act. x 1, 2), second act ( x ₂, x ₁)。 At x = (1,2) the output is (5,2) and Jacobian is [(2,2], [2,1]. If the frame puts batch in the first axis, the single sample Jacobian will not be able to steal batch for special solicitation.
Disturbing = (0.01, 0.02). Linear forecast output changes (0.02,0) are directly recalculated (0.0199, 0.0002). The error came from a second entry: the first dimension was 12 = 0.0001 and the second dimension was 1 quinto 2 = 0.0002. Halve the disturbance by half, and the error should be reduced to one quarter, not one half. This scaling pattern is more appropriate for diagnostic reasoning than a single “number is similar”.
Back from vector output to a mark loss
L = one-half square square of the output vector, then the gradient to the output is f(x). Chain law gives the input gradient J ᵀ f and at the current point is (14,12). (a) The transposition here is irrevocable: the gradient is a column vector shape that is an input dimension multiplied by one; The output dimension of the output is the output dimension of the input of Jacobian.Vector calculus section for MML and Matrix guide part for CS229 This could be used to check the agreement.
Reverse transmission usually calculates the amount of vector with Jacobian, and there is no need to store the huge Jacobian in its entirety. If the output is 100,000 dimensions embedding, enter a million-digit parameter, the visible tectonic matrix will waste a lot of memory. Note that the size of the gradient is dependent on the unit; If the parameters and input are not re-marked together, the performance of the optimisation will change significantly.
For a sample, set the input matrix shape as a batch size multiplied by a feature dimension, and the weight shape as a feature dimension multiplied by an output dimension, while keeping the bulk axis forward to the output. (a) The sample-by-species independent map, the gradient of which should be transmitted along the calculated maps within each sample and then the batch summation or average as agreed; The coordinates of the same group of other users cannot be mistakenly characterized as a person. When checking the array multiplying, the name and length of the axis can be written simultaneously in the code note to avoid masking a conversion error when the two lengths are exactly the same. Where a level of unimodalization depends on batch statistics, the lead numbers between the samples are coupled and should be analysed separately.
Resume with Standard Python
The following is the Python3 standard library code, CPU, no random number, which is actually implemented. The central difference only checks the current point and does not prove that all branches have the correct number of guides.
import math
def f(x): a, b = x return [a*a + 2*b, a*b]
def loss(x): return sum(v*v for v in f(x)) / 2
x, delta = [1.0, 2.0], [0.01, -0.02]jacobian = [[2.0, 2.0], [2.0, 1.0]]base, changed = f(x), f([a+b for a, b in zip(x, delta)])linear = [sum(a*b for a, b in zip(row, delta)) for row in jacobian]print(base, changed, linear)eps = 1e-5numeric = []for j in range(2): plus, minus = x.copy(), x.copy() plus[j] += eps minus[j] -= eps numeric.append((loss(plus)-loss(minus))/(2*eps))assert all(math.isclose(a,b,abs_tol=1e-7) for a,b in zip(numeric,[14,12]))print([round(v, 6) for v in numeric]) # [14.0, 12.0]There is also a compromise on the length of the limited differential steps. (a) Too big, second-order errors are obvious, and loss of accuracy is caused by the loss of floating points close twice in the hour; The right and left lead may vary when ReLU is encountered with zero points or sorting, and cut off such non-glossy operations. A small sample that is far from the boundary should be selected before a specific test of the boundary agreement can be made to identify automatic de minimis errors in the absence of inconsistent differences.
Self-detection: pair shapes, values and semantics
Zoom the candidate vector tenfold. What happens with cosine, point and distance?
The cosine remains 0.8, the dots become 40 and the distance squares becomes 425. The same direction does not mean the same distance from O'Leaks.
A map of output from 3D to 2D. How many rows is Jacobian?
Two rows are agreed by the column vector. Each row is an output bias to three inputs.
Why is the second output so close to local level unchanged, but the real value changed?
The first step is just the same. The remaining change is the multiplier of disturbances - 0.0002. This does not mean that the output is not dependent on input at all.
Can you use Jacobian of this chapter as a global fixed map?
Can't. It relies on guidance points; After input changes, the 2 x1 in the first row and the 2nd row x2, x1 will also change.
Why is there a conversion when retransmitting to input?
The output gradient is a two-dimensional column vector. The chain-based rules summarize the contribution of each output to the same input, corresponding to the J T-by-output gradient; Corresponding dimensions are also necessary checks.
Is it reasonable to return the similarity when the cosine search is zero in both vectors?
That's unreasonable. Zero vectors have no direction; The controlled default value can be returned and the reasons for the missing are recorded, but the value cannot be interpreted in the context of the underlying values as being completely similar.
Readable Next Optimized versus conditional To understand why the same gradient is gathering very differently along different axes Linear Modeling and Regularization See how the projection is used to come together.
Interactive Counting / Fixed Data
I want you to put the shape into the calculation
Left fixed A = [(1, 2, 3, 4, 5, 6)]. Check the shape and then calculate the results.
1 2 3 4 5 6
1 0 0 1 1 1
4 5 10 11
Inner dimension 3 is consistent with 3. The first result is 1 x 1 + 2 x 0 + 3 x 1 = 4.
Displays the initial results at the moment. Enables JavaScript to operate the case.
Sources and reconciliations
Definitions, methods and interfaces are available.
- Mathematics for Machine Learning — Chapters 2–5
- MIT 18.06SC Linear Algebra — projections and subspaces
- Stanford CS229 Lecture Notes — matrix derivatives
Figures and calculations are reorganized according to this chapter. Mathematical measurements, framework operations and real business effects are described separately in the body of the text.