Yuanda's Blog

Welcome to Yuanda's blog.

Background

1. Transformer

The Transformer is the foundation of all modern large language models (LLMs), including GPT, Claude, Llama, and Gemini.
It is a sequence model that predicts each next token given all previous tokens:

1
P(x_t | x_1, x_2, …, x_{t-1})

Transformers use self-attention to capture relationships between tokens, allowing them to reason over long contexts and generate coherent, contextually relevant language.

However, Transformers are purely text-based — they do not natively know how to fetch real-time data or interact with tools and APIs.

That limitation is what protocols like MCP (Model Context Protocol) are designed to solve.

Read more »

You may already know the major Service types in Kubernetes, and the main differences like “ClusterIP only has cluster-internal access”, “NodePort opens a port on every node” and “LoadBalancer is built on top of the former two types”.

But you may have questions such as what cluster-internal access “really” means; how routing happens all the way to a Pod, and so on. Let’s take a deeper look at what’s under the hood.

Read more »

Leetcode 上 Two Pointers tag 的题目基本上有几大类的问题,总结如下。

类型1: 两个指针从两边往中间移动

LeetCode 11. Container With Most Water

想象两个下标 i < j, 如果 height[i] < height[j], 那么是否有必要搜索 [i, j - 1] 这个区间组成的 pair 呢?完全不必。由于 i, j 能接到的水是由短的那个柱子 height[i] 来决定的。如果让 j 向右移动到 i < k < j, 如果 height[i] < height[k] 那 water 仍然是 i 决定的,而且这个面积肯定没有 j 大;如果 height[i] > height[k] 那面积 height[k] * (k - i) 更没有 (i, j) 组成的面积大了。所以这种情况下只需让 i 往右移即可,不需要做重复的搜索。代码:

Read more »

This article analysis the top k largest/smallest element problem and the kth largest element problem. One of the method is based on QuickSelect and we will discuss the essential of this method then use it to solve extended problems.

All the algorithms to find top k elements introduced in this article also works for the kth largest problem. Therefore, we only focus on the top k largest problem from now. The problem of finding the kth largest/smallest number in a list or array is also called selection algorithm in computer science; such a number is called the kth order statistic. There are some statistic analysis on CLRS textbook so please refer to the textbook for more discussion.

1. The classic problem: find top k Largest elements

Question: Write an efficient program for printing k largest elements in an array. Elements in array can be in any order.
For example, if given array is [1, 23, 12, 9, 30, 2, 50] and you are asked for the largest 3 elements i.e., k = 3 then your program should print 50, 30 and 23.

Read more »

转载自:https://www.renfei.org/blog/bipartite-matching.html

这篇文章讲无权二分图(unweighted bipartite graph)的最大匹配(maximum matching)和完美匹配(perfect matching),以及用于求解匹配的匈牙利算法(Hungarian Algorithm);不讲带权二分图的最佳匹配。

二分图:简单来说,如果图中点可以被分为两组,并且使得所有边都跨越组的边界,则这就是一个二分图。准确地说:把一个图的顶点划分为两个不相交集 U 和V ,使得每一条边都分别连接U、V中的顶点。如果存在这样的划分,则此图为一个二分图。二分图的一个等价定义是:不含有「含奇数条边的环」的图。图 1 是一个二分图。为了清晰,我们以后都把它画成图 2 的形式。

匹配:在图论中,一个「匹配」(matching)是一个边的集合,其中任意两条边都没有公共顶点。例如,图 3、图 4 中红色的边就是图 2 的匹配。

Read more »

Manacher’s Algorithm can find a longest palindrome in a string in linear time. The essential of this algorithm is that it takes advantage of the following characteristics or observations about a palindrome and a sub-palindrome: the left side of a palindrome is a mirror image of its right side. This article firstly provides the code and then analyses the process of Manacher’s algorithm.

Let’s take an example: Leetcode 5. Longest Palindromic Substring. Here is the code that I submitted.

Read more »

This article includes my notes and sketch of the class CS-9223 AI FOR GAMES on Spring 2016 taught by Professor Julian Togelius.

This is not a very formal scientific article. It is only supposed to help understand the fundamental concepts about artificial intelligence for games and describe the main ideas about the papers provided by Professor Togelius. I will continuously work on making it much more human readable and accurate.

Update in 2016: check out my co-authored pater! Portfolio Online Evolution in StarCraft

Read more »

This article introduces how to set up Git and GitHub in a new computer and introduces some fundamental commands.

Set Up Git and GitHub

1 Configure GitHub user information on local computer

First download and install the latest version of Git. To set up user information for GitHub, open a terminal and type:

1
2
git config --global user.name “your_name”
git config --global user.email “email@email.com”

If the commands are used without “–global”, the user.name and user.email are only valid under current repository.

Read more »
0%