Tag: Math
Quasi-Newton method derivation
This article introduces the two main forms of the quasi-Newton method: the BFGS method and the L-BFGS method. The BFGS method uses curvature information to preprocess gradients, thereby avoiding the need for a complete calculation of the Hessian matrix in traditional methods. The L-BFGS method further optimizes this preprocessing by saving only the curvature information of the most recent m iterations to calculate an approximation of the Hessian matrix, significantly reducing memory usage and computational effort....
Rand7 generates Rand10
This article explains how to use mathematical principles and C++ code to generate equiprobable random numbers. First, random numbers in the range of $[1, X * Y]$ with equal probability can be generated through the mathematical formula $(randX() - 1) * Y + randY()$. The proof process is based on $randX()$ and $randY()$ generating equal-probability random numbers between $[1, X]$ and $[1, Y]$ respectively. The joint probability table shows how to sample uniformly distributed random numbers between $[1, XY]$ from these random numbers. Next, the article provides a code example written in C++ that demonstrates how to generate uniform random numbers within a specified range by constructing a specific expression. However, this method is less efficient because it will only stop when the sample is between $[1, 10]$, and the numbers between $[11, 49]$ will be discarded. In order to improve efficiency, the article proposes an optimization method that reduces the range to $[1, 10]$ through modular division operations, and further optimizes it to only sample numbers between $[41, 49]$, thereby improving efficiency. Finally, the article also discusses ways to solve the problem from a base point of view, pointing out that if a given $rand1()$ can only generate uniform random numbers between $[0, 1]$, then binary encoding can be used to generate uniform random numbers between $[a, b]$....
Relationship between KL divergence, cross entropy and encoding
This article introduces the relationship between KL divergence and cross entropy, pointing out that the expectation of information amount is $-log(p)$, and entropy is the sum of expectations. KL divergence measures the difference between two probability distributions and explains their asymmetry and asymmetry. Furthermore, the article explores the relationship between information entropy and coding, and how to use Shannon's coding theorem to calculate entropy, thereby deriving the concept of average coding length. Finally, the article discusses the application of conditional entropy and maximum likelihood estimation in cross-entropy loss functions, emphasizing another understanding of cross-entropy as a loss function....
Common PEFT method principles
This article discusses LLM model fine-tuning methods trained on large-scale general data sets, especially how to adapt to specific tasks through methods such as adapters, prefixes, and prompts. In particular, the low-rank adaptive (LoRA) technology proposed by Microsoft is introduced. This method reduces the amount of calculations by decomposing the update matrix into the product of two low-rank matrices, and achieves similar effects to full fine-tuning. The article also discusses the specific principles, applications and challenges of LoRA....