# 一个“朴素”的推荐系统

## Introduction

$$P(like|aritcle)$$

$$P(like|aritcle) = \frac{P(article|like)P(like)}{P(article|like)P(like)+P(article|dislike)P(dislike)}$$

# LeetCode Contest 78

"9001 discuss.leetcode.com"

class Solution:
def subdomainVisits(self, cpdomains):
"""
:type cpdomains: List[str]
:rtype: List[str]
"""
cnt = collections.defaultdict(int)
for cp in cpdomains:
while p != -1:
return ['{} {}'.format(v, k) for k, v in cnt.items()]


# Markov Decision Process: Finite horizon

This post is considered to the notes on finite horizon Markov decision process for lecture 18 in Andrew Ng's lecture series. In my previous two notes ([1], [2]) about Markov decision process (MDP), only state rewards are considered. We can easily generalize MDP to state-action reward.

## State-Action Reward

Our reward function now is a function in terms of both states and actions. More precisely, the reward function is a function

$$R: S \times A \to \R.$$

All other requirements in definition of MDP will remain intact. For completeness, we include the definition here. We shall pay attention to the fifth components.

# Markov Decision Process: Continuous states

I wrote this post for lecture 17 in Andrew Ng's lecture collections on Machine Learning. In my previous post, we discussed Markov Decision Process (MDP) in its simplest form, where the set of states and the set of actions are both finite. But in real world application, states and actions can be infinite and even continuous. For example, if we want to model states of a self-driving car in a 2D plane, we must at least have the position $(x, y)$, the direction $\theta$ of the car pointing to, its velocity $(v_x, v_y)$ and the rate $r$ of change in $\theta$. So the states of a car is at least a 6 dimensional space. For actions of a car, we can control how fast it goes in direction $\theta$ and we can also control $r$. Thus the actions have dimension 2.

In this post, we consider only continuous states with finite actions. Indeed, actions space usually has much lower dimension than states space, so in case of continuous actions, we might just discretize the actions spaces to get a finite set of representatives of actions. One may argue that we can also discretize the states space. Yes, we can do it, but only when the dimension $n$ of state space is small enough: if we discretize each dimension into $k$ parts, then there would be $k^n$ many states. If $n$ is large, then $k^n$ is not feasible. This is so called the curse of dimensionality. Moreover, discretizing states space usually results in lack of smoothness.

# Markov Decision Process

This article is my notes for 16th lecture in Machine Learning by Andrew Ng on Markov Decision Process (MDP). MDP is a typical way in machine learning to formulate reinforcement learning, whose tasks roughly speaking are to train agents to take actions in order to get maximal rewards in some settings. One example of reinforcement learning would be developing a game bot to play Super Mario on its own.

Another simple example is used in the lecture, and I will use it throughout the post as well. Since the example is really simple, so MDP shown below is not of the most general form, but only good enough to solve the example and give the idea of what MDP and reinforcement learning are. The example begins with a 3 by 4 grid as below.

This article is my notes on Principal Component Analysis (PCA) for Lecture 14 and 15 of Machine Learning by Andrew Ng. Given a set of high dimensional data $\{x^{(1)}, \dots, x^{(m)}\}$, where each $x^{(i)} \in \R^{n}$, with the assumption that these data actually roughly lie in a much smaller $k$ dimensional subspace, PCA tries to find a basis for this $k$ dimensional subspace. Let's look at a simple example: