-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.json
1 lines (1 loc) · 131 KB
/
content.json
1
{"pages":[{"title":"about","text":"Contact: hyperuan@gmail.com or hyperuan@163.com","link":"/about/index.html"}],"posts":[{"title":"Brew Install 报错","text":"Problem123$ brew updatefatal: gitError: another SolutionqitaCSDNstackoverflow","link":"/2021/03/26/Brew-Install-%E6%8A%A5%E9%94%99/"},{"title":"Brooks Theorem","text":"Lemma$\\chi(G)\\leq\\Delta(G)+1$,that is:the chromatic number is no more thanthe maximum degree plus one. HINT:第一感是这个结论不平凡,$\\Delta(G)+1$种颜色local满足每个点的闭邻域,但如何保证global不会产生矛盾?给每个闭邻域规定一个量子态$c(N[v])\\sim U\\binom{[\\Delta+1]}{d(v)+1}$,即每个闭邻域的染色方案等概率取自$\\binom{[\\Delta+1]}{d(v)+1}$,让每个闭邻域的量子态坍缩(若两个闭邻域坍缩导致同一个点颜色不同则得到的染色方案非法)这样得到的染色方案是否有一定概率是合法的难以决断。给每个点规定一个量子态$c(v)\\sim U\\binom{[\\Delta+1]}{1}$,即每个点的染色方案等概率取自$\\binom{[\\Delta+1]}{1}$,让每个点的量子态坍缩,这样得到的染色方案必然有一定概率是合法的,只需让所有点按照任意次序坍缩并始终维护合法状态。$\\bigstar$ PROOF:Let $\\sigma=[v_1,v_2,\\cdots,v_n]$ be any ordering of $V(G)$.Color $V(G)$ with $\\Delta(G)+1$ colors in ordering $\\sigma$,and we’ve done, since the $\\Delta(G)+1$ colors sufficeevery closed neighbors $N[v]$ for any $v\\in V(G)$, and $V(G)$ is a finite set.$\\square$ Theorem (Brooks, 1941)$G$ is a connected graph.$\\chi(G)=\\Delta(G)+1$,iff (if and only if),$G$ is either a complete graph,or an odd cycle. (version1)Or equivalently,$G$ is neither a complete graph,nor an odd cycle,iff $\\chi(G)\\leq\\Delta(G)$. (version2) PROOF:We’ll prove version1 or version2 in 5 cases.Case I: $\\Delta=0\\text{ or }1$;$~~~~G$ is a single vertex or two connected vertices,$~~~~$proving version1.Case II: $\\Delta=2$;$~~~~G$ is a path or an odd cycle or an even cycle,$~~~~$proving version2, version1, version2 respectively.Case III: $\\Delta\\geq3$ and $G$ is irregular;$~~~~$We’ll prove version2 in this case.$~~~~$There exists a vertex $v\\in V$$~~~~$such that $d(v)<\\Delta$, since $G$ is irregular.$~~~~$Let $\\overline{T}$ be an inv-DFS spanning tree of $G$$~~~~$such that $v$ is the inv-root of $\\overline{T}$.$~~~~$Let $\\overline{L},\\overline{\\sigma}$ be the correspondent inv-label and inv-DFS ordering.$~~~~$We color $G$ in ordering $\\overline\\sigma$.$~~~~$By Lemma2 $\\vert P_{\\overline L}(w)\\vert\\leq\\Delta-1,\\text{ }\\forall\\text{ }w\\neq v$,$~~~~$So $\\Delta$ colors suffice $w$.$~~~~$At last $\\Delta$ colors suffice $v$, noting that $d(v)<\\Delta$.Case IV: $\\Delta\\geq3$ and $G$ is regular but not biconnected;$~~~~$We’ll prove version2 in this case.$~~~~$Since $G$ isn’t biconnected, $G$ contains a cut $v\\in V$.$~~~~$Let $G-v=H_1\\oplus H_2\\oplus\\cdots\\oplus H_s$ with $s\\geq2$.$~~~~$Let $G_i=G[V(H_i)\\cup\\lbrace v\\rbrace]$ for each $i\\in[s]$.$~~~~$Noting that $d_{G_i}(v)<\\Delta(G)=\\Delta(G_i)$,$~~~~$we have $\\chi(G_i)\\leq\\Delta(G_i)=\\Delta(G)$ applying Case III to $G_i$.$~~~~$By permutating coloring, we can make sure the colors of $v$ in each $G_i$ are the same.$~~~~$Therefore $\\Delta(G)$ colors suffice $G$.Case V: $\\Delta\\geq3$ and $G$ is regular and biconnected.$~~~~$If $G$ is complete, then it proves version1.$~~~~$We’ll prove version2 assuming $G$ isn’t complete.$~~~~$Case V(i): there exists $\\lbrace u,v\\rbrace\\subset V(G)$ such that $G-\\lbrace u,v\\rbrace$ is disconnected.$~~~~~~~~$Let $G-\\lbrace u,v\\rbrace=H_1\\oplus H_2\\oplus\\cdots\\oplus H_s$ with $s\\geq2$.$~~~~~~~~$Since $G-u$ is connected, there exists $v’\\in V(H_i)$ such that $(v,v’)\\in E(G)$.$~~~~~~~~$Since $G-v$ is connected, there exists $u’\\neq v’\\in V(H_i)$ such that $(u,u’)\\in E(G)$,$~~~~~~~~$noting that if $u’$ must be equal to $v’$ then $v’$ is a cut of $G$.$~~~~~~~~$Let $G_i=G[V(H_i)\\cup\\lbrace u,v\\rbrace]$ for each $i\\in[s]$.$~~~~~~~~$Noting that $d_{G_i}(u)<\\Delta(G)=\\Delta(G_i)$,$~~~~~~~~$we have $\\chi(G_i)\\leq\\Delta(G_i)=\\Delta(G)$ applying Case III to $G_i$.$~~~~~~~~$Let $c_i$ be a $\\Delta(G)$-coloring of $G_i$ for each $i\\in[s]$.$~~~~~~~~$If $(u,v)\\in E(G)$, then $c_i(u)\\neq c_i(v)$, meaning that$~~~~~~~~$we can permutate $c_i$ on $V(G_i)$ to make sure$~~~~~~~~$$c_i(u)=c_j(u)$ and $c_i(v)=c_j(v)$ for any $i,j\\in[s]$,$~~~~~~~~$thus obtaining a $\\Delta(G)$-coloring of $G$.$~~~~~~~~$If $d_{G_i}(u)<\\Delta(G)-1$ or $d_{G_i}(v)<\\Delta(G)-1$ for each $i\\in[s]$,$~~~~~~~~$then $v$ or $u$ has at least $2$ choices for $c_i$,$~~~~~~~~$meaning that we can modify $c_i(u)$ or $c_i(v)$ to make sure $c_i(u)\\neq c_i(v)$.$~~~~~~~~$If $(u,v)\\notin E(G)$ and $d_{G_i}(u)=d_{G_i}(v)=\\Delta(G)-1$ for some $i\\in[s]$,$~~~~~~~~$then $s=2$ and $d_{G_2}(u)=d_{G_2}(v)=1<\\Delta(G)-1$ assuming that $i=1$.$~~~~~~~~$Noting that $\\chi(G_1)\\leq\\Delta(G_1)=\\Delta(G)$ applying Case III to $G_1$,$~~~~~~~~$let $c_1$ be a $\\Delta(G)$-coloring of $G_1$.$~~~~~~~~$Similarly let $c_2$ be a $\\Delta(G)$-coloring of $G_2$.$~~~~~~~~$Noting that $u,v$ have $\\Delta(G)-1$ choices for $c_2$,$~~~~~~~~$we can make $c_2(u)=c_2(v)$ or $c_2(u)\\neq c_2(v)$ according to $c_1(u),c_1(v)$.$~~~~~~~~$At last by permutating $c_2$ on $V(G_2)$,$~~~~~~~~$we can make sure $c_1(u)=c_2(u)$ and $c_1(v)=c_2(v)$.$~~~~~~~~$So $c_1$ combining $c_2$ is a $\\Delta(G)$-coloring of $G$.$~~~~$Case V(ii): $G-\\lbrace u,v\\rbrace$ is connected for any $\\lbrace u,v\\rbrace\\subset V(G)$.$~~~~~~~~$We choose $u,v$ such that $D_G(u,v)=2$, since $G$ is connected and not complete.$~~~~~~~~$Let vertex $w\\in N_G(u)\\cap N_G(v)$.$~~~~~~~~$Firstly we color $u,v$ with the same color.$~~~~~~~~$Let $\\overline T$ be an inv-DFS spanning tree of $G-\\lbrace u,v\\rbrace$,$~~~~~~~~$with inv-DFS ordering $\\overline\\sigma$,$~~~~~~~~$such that $w$ is the inv-root of $\\overline T$.$~~~~~~~~$Then we color $V(G)\\setminus\\lbrace u,v\\rbrace$ in ordering $\\overline\\sigma$, and we’ve done.$~~~~~~~~$$\\Delta(G)$ colors suffice $w$ because $u,v$ have the same color.$\\square$ Concept of Case IIIInv-DFS Spanning TreeA graph is a tree providedit’s connected with no cycles.$T$ is a spanning tree of a connected graph $G$,provided $T$ is a tree, and $T\\leq G$, and $V(T)=V(G)$. Let $\\sigma=[v_1,v_2,\\cdots,v_n]$ be aDFS (depth first search) ordering of $G$.Define the label $L(v_i)=i$ for any $i\\in[n]$.Define the inv-label $\\overline L(v_i)=1+n-i$ for any $i\\in[n]$.The ordering $\\overline\\sigma=[v_n,v_{n-1},\\cdots,v_1]$is called an inv-DFS ordering of $G$. $T$ is a DFS spanning tree of $G$, provided$T$ is generated by a DFS of $G$, andthe direction of each edge is from the smaller labelto the larger label of its two vertices.The vertex with label $1$ is the root of $T$.$\\overline T$ is an inv-DFS spanning tree of $G$, provided$\\overline T$ is generated by a DFS of $G$, andthe direction of each edge is from the smaller inv-labelto the larger inv-label of its two vertices.The vertex with inv-label $n$ is the inv-root of $\\overline T$. Lemma1This lemma asserts that none inv-root vertexmust point to a neighbor vertex with larger inv-label.Lemma1 $\\forall\\text{ }v\\in V:\\text{ }\\overline{L}(v)\\neq n,\\text{ }\\exists\\text{ }w\\in N(v)$$\\text{ s.t. }\\overline{L}(v)<\\overline{L}(w).$ PROOF:Suppose to the contrary$\\exists\\text{ }v\\in V:\\text{ }\\overline{L}(v)\\neq n,$$\\text{ s.t. }\\forall\\text{ }w\\in N(v):\\text{ }\\overline{L}(v)>\\overline{L}(w)$,which means the inv-root and $v$ are unreachable in the DFS,violating that the graph is connected.$\\square$ Inv-label Predecessors and SuccessorsThe larger inv-label successors $S_{\\overline L}(v)$ of $v\\in V$is defined by $S_{\\overline L}(v)=\\lbrace w\\in N(v):\\overline{L}(v)<\\overline{L}(w)\\rbrace$. The smaller inv-label predecessors $P_{\\overline L}(v)$ of $v\\in V$is defined by $P_{\\overline L}(v)=\\lbrace u\\in N(v):\\overline{L}(u)<\\overline{L}(v)\\rbrace$. Lemma2This lemma gives the bound of $S_{\\overline L}$ and $P_{\\overline L}$.Lemma2 $\\forall\\text{ }v\\in V:\\text{ }\\overline{L}(v)\\neq n$,it holds that$\\begin{cases}\\vert S_{\\overline L}(v)\\vert\\geq1 \\\\\\vert P_{\\overline L}(v)\\vert\\leq d(v)-1\\leq\\Delta-1\\end{cases}$ PROOF:Noting that $\\vert P_{\\overline L}(v)\\vert=d(v)-\\vert S_{\\overline L}(v)\\vert$,and by Lemma1 $S_{\\overline L}(v)\\neq\\emptyset$.$\\square$ Basic DefinitionThe cardinality of a set $X$is the number of its elements, denoted by $\\vert X\\vert$.Define the set $[k]=\\lbrace1,2,\\cdots,k\\rbrace$,for any positive integer $k\\in\\mathbb{Z}^+$.Define the set $\\binom{A}{k}=\\lbrace B\\subset A:\\vert B\\vert=k\\rbrace$for any proper $A$ and $k$. $X=X_1\\oplus X_2\\oplus\\cdots\\oplus X_s$ is a partition of set $X$,provided $X=\\bigcup\\limits_{i\\in[s]}X_i$,and $X_i\\neq\\emptyset$ for any $i\\in[s]$,and $X_i\\cap X_j=\\emptyset$ for any distinct $i,j\\in[s]$. $G$ is a (simple) graph(finite, undirected, unweighted,with no self-cycles and multi-edges).$V=V(G)$ is the vertex set of $G$.$E=E(G)$ is the edge set of $G$.$n=\\vert V\\vert$ is the order of $G$.$m=\\vert E\\vert$ is the size of $G$. The incident edges $E_v$ of $v\\in V$,is defined by $E_v=\\lbrace e\\in E: v\\in V(e)\\rbrace$. Graph $H$ is a subgraph of Graph $G$,denoted by $H\\leq G$,provided $V(H)\\subset V(G)$ and $E(H)\\subset E(G)$. Set $U\\subset V(G)$.The induced subgraph of $G$ generated by $U$,denoted by $G[U]$,is defined by $V(G[U])=U$, and$E(G[U])=\\lbrace e\\in E(G):V(e)\\subset U\\rbrace$. The chromatic number of $G$,denoted by $\\chi(G)$, is the minimumnumber $k$ such that $G$ is $k$-colorable.$G$ is $k$-colorable, providedthere exists a coloring $c:V\\longrightarrow[k]$.A (proper/valid) ($k$-)coloring $c$ of $G$ isa function $c:V\\longrightarrow[k]$ such that$c(u)\\neq c(v)$ for any $(u,v)\\in E$. $N(v)$ is the (open) neighbors of vertex $v\\in V$,defined by $N(v)=N_G(v)=\\lbrace u\\in V:(u,v)\\in E\\rbrace$.$N[v]=N_G[v]=\\lbrace v\\rbrace\\cup N(v)$ is the closed neighbors.$N(U)=N_G(U)=\\bigcup\\limits_{u\\in U}N(u)$ is the neighbors of set $U\\subset V$. $d(v)$ is the degree of vertex $v\\in V$,defined by $d(v)=d_G(v)=\\vert N(v)\\vert$.$\\Delta(G)$ is the maximum degree of $G$,defined by $\\Delta=\\Delta(G)=\\max\\limits_{v\\in V}d(v)$.$\\delta(G)$ is the minimum degree of $G$,defined by $\\delta=\\delta(G)=\\min\\limits_{v\\in V}d(v)$. $G$ is ($k$-)regular provided$d(u)=d(v)=k$ for any $u,v\\in V$,otherwise $G$ is irregular. $G$ is a complete graph,provided $d(v)=n-1$ for any $v\\in V$.A complete graph with order $n$is denoted by $K_n$. $G$ is a cycle,provided $d(v)=2$ for any $v\\in V$,and $G$ is connected.If $n\\equiv1(\\mod2)$,then $G$ is an odd cycle,otherwise $G$ is an even cycle. $G$ is connected provided$u\\sim v$ for any distinct $u,v\\in V$,otherwise $G$ is disconnected.$u,v\\in V$ are reachable,denoted by $u\\sim v$, providedthere exists a $u,v$ path,otherwise unreachable and $u\\nsim v$.A $u,v$ path is a list $[w_1,w_2,\\cdots,w_{l+1}]$satisfying $w_1=u$ and $w_{l+1}=v$,and $w_i\\neq w_j$ for any distinct $i,j\\in[l+1]$,and $(w_i,w_{i+1})\\in E$ for any $i\\in[l]$.The length of path $P=[w_1,w_2,\\cdots,w_{l+1}]$ is $l$,denoted by $\\vert P\\vert=l$. Let $\\mathcal{P}(u,v)$ be the set of all $u,v$ paths.The distance between $u,v$, denoted by $D_G(u,v)$,is defined by $D_G(u,v)=\\min\\limits_{P\\in\\mathcal{P}(u,v)}\\vert P\\vert$. The graph $G-v$ is obtained from $G$by deleting $E_v$ and $v$,for vertex $v\\in V$.The graph $G-U$ is defined by$G-U=G-u_1-u_2-\\cdots-u_s$,for any $U=\\lbrace u_1,u_2,\\cdots,u_s\\rbrace\\subset V$. $G$ is $k$-(vertex-)connected provided$G-U$ is connected for any $U\\in\\binom{V}{k-1}$.$G$ is biconnected when $G$ is $2$-connected.A vertex $v\\in V$ is a cut of $G$ provided$G-v$ is disconnected. Graph $H$ is disconnected.$V(H)=V_1\\oplus V_2\\oplus\\cdots\\oplus V_s$ is a partition of $V(H)$.The induced subgraphs $H[V_1],H[V_2],\\cdots,H[V_s]$are the components of $H$, provided$H[V_i]$ is connected for any $i\\in[s]$,and $v_i\\in V_i,v_j\\in V_j$ are unreachable in $G$for any distinct $i,j\\in[s]$.We write $H=H_1\\oplus H_2\\oplus\\cdots\\oplus H_s$,if denoting $H_i=H[V_i]$ for any $i\\in[s]$. Reference Notes Introduction to Graph Theory, West","link":"/2024/04/10/Brooks-Theorem/"},{"title":"Configure CentOS Environment on MacOS","text":"苹果电脑本地配置CentOS环境 近期在苹果电脑本地搞项目,需要干净的开发测试环境。尝试方案:MacOS安装Docker拉CentOS镜像。以下是具体步骤及可能出现的问题。 清理环境MacOS以前也装过Docker,先删除干净。其他不用的文件、软件删了腾出空间。 安装Docker 下载包选择是Intel Processor还是Apple Chip(左上角About This Mac) MacOS必须是最近3个版本(Mojave无法打开docker.dmg,升到最新的Sonoma,如果进度卡住重启再试一次,折腾2小时) 安装Linux Linux选择最经典的CentOS7(考虑到需要支持C++17,后续需要考虑迁移到CentOS8) 注册dockerhub(国内目前无法登录) 实测以上注册可以跳过,直接命令行下Docker拉取CentOS7镜像 启动一个CentOS7容器,进入命令行,创建用户,配置基本环境,持久化生成新的镜像(以后都使用这个镜像) 容器获取本地时区 启动项目 本地创建目录,用于git clone项目,与容器共享 新的镜像启动一个容器,挂载到本地目录,为防止这个容器爆掉限制启动内存4g 容器内配置项目环境,持久化再生成镜像(以后启动都使用这个镜像) Docker.CentOS7下root安装rpmbuild,构建RPMs必须从root切换到其他user 公共基础配置在root下进行,非公共配置、跑实例在非root下进行;若跑实例的数据都挂载到本地,也可直接root下运行 本地多个镜像构成了继承派生关系的有向图,中间镜像若命令行也无法强制删除可在DockerDesktop上删除 Docker.CentOS7.root更新g++版本 Docker.CentOS7.root更新cmake版本 cmake背景知识 Docker.CentOS7.root安装OpenSSL Docker.CentOS7.root安装git 升级git 报错curl Docker.CentOS7.root安装编译配置googletest 编译器相关$\\textbf{src-files}\\xrightarrow[\\text{check declaration/grammar errors}]{\\textbf{compile}}$$\\textbf{ obj-files}\\xrightarrow[]{\\textbf{pack}}\\textbf{library/archive-files}$$\\textbf{ }\\xrightarrow[\\text{check definition errors}]{\\textbf{link}}\\textbf{exe-files}$ makefile: Linux C/C++ 编译规则的脚本语言,每个项目的每个功能都有一个makefile配置文件,通过make命令执行,实现自动化编译CMakeLists.txt: 每个项目都有一个CMakeLists.txt文件,通过cmake ..命令生成所有makefile,不必再写makefile cmake官方基础教程 C++编译工具cmake vs bazel 编译问题汇总 undefined reference to pthread_create cmake ../ -DTEST=ON -Dgtest_disable_pthreads=OFF unknown type name z_size_t zlib版本从1.2.13回滚1.2.12 Linux常用命令 查找文件 12find . -name CMakeLists.txt #当前目录递归查找所有名为CMakeLists.txt的文件find . -type f |xargs grep "edgeHash" #当前目录递归查找包含"edgeHash"内容的文件 Vim生成空行Linux终端进入Vim命令模式,执行 1command + O 在当前行下生成一个空行,并进入编辑模式 Vim光标快速跳转Linux终端进入Vim命令模式,执行 123456gg # 跳转到文件开头G # 跳转到文件末尾0 # 跳转到行首$ # 跳转到行尾w # 跳转到下一个单词b # 跳转到上一个单词 Vim复制粘贴Linux终端进入Vim命令模式,执行 123yy # 复制当前行5yy # 复制当前行往下总共5行p # 粘贴到当前行 Vim删除Linux终端进入Vim命令模式,执行 12dd # 删除光标所在行x # 删除光标所在字符 永久设置alias 12vim ~/.bashrcalias cd...='cd ../..' # 返回上上层目录","link":"/2024/03/09/Configure-CentOS-Environment-on-MacOS/"},{"title":"FM 模型训练问题汇总","text":"problem 0DataFrame 转置再转字典 12dv = DictVectorizer()X_train_vec = dv.fit_transform(list(X_train.T.to_dict().values)) 出现告警 1Warning: DataFrame columns are not unique, some columns will be omitted python solution转置之前的行索引index有duplicate 12345678910111213141516X_train = df_train[fm_feature_cols]y_train = df_train[LABEL_COL].valuesy_train_cls = (y_train>=PARAM_LABEL_THRES).astype(np.int32)X_test = df_test[fm_feature_cols]y_test = df_test[LABEL_COL].valuesy_test_cls = (y_test>=PARAM_LABEL_THRES).astype(np.int32)print('is X_train.index unique? {0}'.format(X_train.index.is_unique))print('is X_test.index unique? {0}'.format(X_test.index.is_unique))X_train.reset_index(drop=True, inplace=True)X_test.reset_index(drop=True, inplace=True)dv = DictVectorizer()X_train_vec = dv.fit_transform(list(X_train.T.to_dict().values))X_test_vec = dv.transform(list(X_test.T.to_dict().values))fm = pylibfm.FM(num_factors=10, num_iter=iters, verbose=True, task='classification', init_learning_rate=0.001, learning_rate_schedule='optimal')fm.fit(X_train, y_train_cls)preds = fm.predict(X_test_vec) problem 112345678910X_train = df_train[fm_feature_cols]y_train = df_train[LABEL_COL].valuesy_train_cls = (y_train>=PARAM_LABEL_THRES).astype(np.int32)X_test = df_test[fm_feature_cols]y_test = df_test[LABEL_COL].valuesy_test_cls = (y_test>=PARAM_LABEL_THRES).astype(np.int32)dv = DictVectorizer()X_train_vec = dv.fit_transform(list(X_train.T.to_dict().values))X_test_vec = dv.transform(list(X_test_vec.T.to_dict().values))fm.fit(X_train_arr, y_train_cls) 报错 1ValueError: Found input variables with inconsistent numbers of samples 原因 12345print('len(X_train_arr)={0}'.format(X_train_arr.shape[0]))print('len(y_train_cls)={0}'.format(len(y_train_cls)))#len(X_train_arr)=245299#len(y_train_cls)=503458#X_train 和 y_train_cls 长度不一致 solution123dv = DictVectorizer()X_train_vec = dv.fit_transform(list(X_train.T.to_dict().values()))X_test_vec = dv.transform(list(X_test.T.to_dict().values())) problem 21TypeError: sparse matrix length is ambiguous; use getnnz() or shape[0] solution12print('len(X_train)={0}'.format(len(X_train)))print('len(y_train_cls={0}'.format(len(y_train_cls))) 这里没问题 1234567dv = DictVectorizer()X_train_vec = dv.fit_transform(list(X_train.T.to_dict().values()))X_test_vec = dv.transform(list(X_test.T.to_dict().values()))print('len(X_train_vec)={0}'.format(len(X_train_vec)))print('len(y_train_cls)={0}'.format(len(y_train_cls)))print('len(X_test_vec)={0}'.format(len(X_test_vec)))print('len(y_test_cls)={0}'.format(len(y_test_cls))) 这里报错,改为 1234567dv = DictVectorizer()X_train_vec = dv.fit_transform(list(X_train.T.to_dict().values()))X_test_vec = dv.transform(list(X_test.T.to_dict().values()))print('len(X_train_vec)={0}'.format(X_train_vec.shape[0]))print('len(y_train_cls)={0}'.format(len(y_train_cls)))print('len(X_test_vec)={0}'.format(X_test_vec.shape[0]))print('len(y_test_cls)={0}'.format(len(y_test_cls))) problem 3使用 DictVectorizer 向量化 DataFrame由于 DataFrame 数据量超过 1G自动转为 scipy.sparse.sparse.csr.csr_matrix 类型不能直接用于 pylibfm.FM.fit先将 csr_matrix 转为 list 再训练内存超过此 Python 进程内存达到 270 G 直接爆掉触发 OOM 从而 linux 内核 kill 该进程 problem 4训练 pylibfm.FM 模型 12-- Epoch 161Training log loss: nan solution可能列的数据类型问题 => 检查发现问题(object类型需要转成string类型,但不影响训练结果)目前 github 项目 pyFMclassification存在bug两次调用sigmoid函数01 classification log loss 改为 regression mse problem 501分类应用regression模型 12fm = pylibfm.FM(num_factors=10, num_iters=iters, verbose=True, task='regression', init_learning_rate=0.001, learning_rate_schedule='optimal')fm.fit(X_train_arr, y_train_cls) 报错 1ValueError: Buffer dtype mismatch, expected 'DOUBLE' but got 'int' solution1y_train_cls = (y_train.values>=PARAM_LABEL_THRES).astype(np.float64) problem 6分类改为回归 12fm = pylibfm.FM(num_factors=10, num_iters=iters, verbose=True, task='regression', init_learning_rate=0.001, learning_rate_schedule='optimal')fm.fit(X_train_arr, y_train_cls) 仍然出现问题 12-- Epoch 1Training MSE: nan solution少数据量/多数据量分别测一下=> 少量数据 classification 正常 problem 7少数据量测试报错 123-- Epoch 1Training MSE: nanValueError: Input contains NaN, infinity or a value too large for dtype('float64') 回归 label 训练溢出(可能原因是某些特征未归一化) solution=>直接改为分类->NaN=>改为分类并且特征归一化->结果正常(1000样本) 结果正常(10000样本) 临界点60万样本120特征 内存不足(全部样本) problem 8模型验证 12preds = fm.predict(X_test_csr)test_logloss = log_loss(y_test_cls, preds) 报错 12ValueError: y_true contains only one label (0).Please provide the true labels explicitly through the labels argument. solution验证集的label全为0没有1随机划分训练集验证集=>分层划分 12345678910111213141516def split_train_valid_random(df, test_frac=0.1): df = df.sample(frac=1).reset_index(drop=True, inplace=True) n_test = int(len(df) * test_frac) df_test, df_train = df[:n_test], df[n_test:] df_train.reset_index(drop=True, inplace=True) df_test.reset_index(drop=True, inplace=True) return df_train, df_testdef split_train_valid_stratify(df, primary_key='chatroom_id', label='clickuv', test_frac=0.1): df = df.drop_dumplicates(subset=[primary_key, label]) x = df[primary_key].values y = df[label].values y = (y / 3).astype(int) y[np.where(y > 5)] = 5 row_train, row_test, _, _, = train_test_split(x, y, stratify=y, test_size=test_frac) return row_train, row_test","link":"/2021/08/13/FM-%E6%A8%A1%E5%9E%8B%E8%AE%AD%E7%BB%83%E9%97%AE%E9%A2%98%E6%B1%87%E6%80%BB/"},{"title":"DeepFM 实战","text":"Github 下载轮子注意事项 从 Tensorflow2.0 切换到 1.14.0 Python 切换到 3.6.8 手动下载添加 yellowfin 包 下载 Kaggle 数据","link":"/2021/08/30/DeepFM-%E5%AE%9E%E6%88%98/"},{"title":"FM 系列模型性能比较","text":"基本 FM 模型包 libfm | C++11 pywfm | python alphaFM | C++11 fastFm | C/Cython/Python pyFM | Python libFM | Tensorflow spark-libFM | scala DiFacto | C++ pyFM 测试 实验序号 raw features linear features factors iters 训练时间 总时间 训练集 row 训练集 logloss 验证集 row 验证集 logloss 验证集 auc 验证集 acc 测试集 row 测试集 logloss 测试集 auc 测试集 acc 机器 1 124 40w 10 20 1h38m 2h36m 518648 0.33822 162770 0.3947 0.8268 0.8303 31979 1.1479 0.6123 0.2320 luban 服务器 2 124 40w 15 30 4h4m 4h52m 518742 0.30285 162548 0.3635 0.8564 0.8503 31979 1.1922 0.5778 0.2511 luban 服务器 3 4 2w 15 30 1h49m 2h41m 4000000 0.31214 1000000 0.3669 0.8342 0.8480 31979 1.8640 0.4074 0.1390 luban 服务器 4 4 2w 4 60 2h57m 3h15m 5000000 0.30302 1250000 0.3673 0.8333 0.8477 31979 1.9496 0.5598 0.1653 luban 服务器 5 4 2w 8 60 3h16m 4h15m 5000000 0.28222 1250000 0.3492 0.8489 0.8575 31979 1.9372 0.5023 0.1454 luban 服务器 6 4 2w 30 30 4h19m 5h18m 5000000 0.28640 1250000 0.3478 0.8461 0.8585 31979 1.8359 0.4332 0.1513 luban 服务器 7 22 8w 30 30 6h18m 7h9m 2000000 0.29670 500000 0.3769 0.8208 0.8457 31979 2.3700 0.6774 0.0919 luban 服务器 8 22 8w 20 30 4h20m 5h10m 2000000 0.30264 500000 0.3809 0.8165 0.8437 31979 2.2959 0.4705 0.1144 luban 服务器 9 22 8w 20 30 4h31m 5h28m 2000000 0.28568 500000 0.3750 0.8208 0.8474 31979 2.1205 0.2859 0.1672 luban 云平台 10 22 8w 40 40 22h28m 23h33m 4000000 0.20939 1000000 0.2838 0.9051 0.8923 31979 4.3235 0.7143 0.1193 luban 云平台 11 22 8w 40 40 43h58m 46h43m 7846452 0.26457 2000000 0.3044 0.8927 0.8766 1453918 0.4240 0.7056 0.8524 luban 云平台 train_all (features=124) 效果不佳train_naked (features=4) 近似随机噪声train_basic (features=22) ‘硬train一发‘测试集AUC提升至0.7","link":"/2021/08/23/FM-%E7%B3%BB%E5%88%97%E6%A8%A1%E5%9E%8B%E6%80%A7%E8%83%BD%E6%AF%94%E8%BE%83/"},{"title":"Graph Minor","text":"Edge Deletion$G=(V,E)$ is a graph.$\\mathcal{G}$ is the set of all graphs with any vertices and any edges.$\\mathcal{G}_{i,j}$ is the set of all graphs with $i$ vertices and $j$ edges.For $e\\in E$,$D_e:\\mathcal{G}\\longrightarrow\\mathcal{G}$ is an edge-deletion operationsatisfying for $G=(V,E)\\in\\mathcal{G}\\text{ and }G’=(V’,E’)=D_e(G)$ it holds that$V’=V$ and $E’=E\\setminus\\lbrace e\\rbrace$. The graph $D_e(G)$ is also denoted as $G-e$ or $G\\setminus e$. $\\underline{\\textbf{Lemma0}}$$G\\in\\mathcal{G}_{i,j}\\Longrightarrow D_e(G)\\in\\mathcal{G}_{i,j-1}$. Vertex DeletionFor $G=(V,E)$ and $v\\in V$,let $E_v=\\lbrace e\\in E:\\text{ }V(e)\\cap\\lbrace v\\rbrace\\neq\\emptyset\\rbrace$ bethe set of edges incident to $v$.$D_v:\\mathcal{G}\\longrightarrow\\mathcal{G}$ is an vertex-deletion operationsatisfying for $G=(V,E)\\in\\mathcal{G}\\text{ and }G’=(V’,E’)=D_v(G)$ it holds that$V’=V\\setminus\\lbrace v\\rbrace$ and $E’=E\\setminus E_v$. The graph $D_v(G)$ is also denoted as $G-v$ or $G\\setminus v$. $\\underline{\\textbf{Lemma1}}$$G\\in\\mathcal{G}_{i,j}\\Longrightarrow D_v(G)\\in\\mathcal{G}_{i-1,j-k}$where $k=\\vert E_v\\vert$. Edge ContractionFor $G=(V,E)$, and $w\\notin V$, and $e=(u,v)\\in E$,let $W=V\\cup\\lbrace w\\rbrace\\setminus\\lbrace u,v\\rbrace$ be the set of vertices merging $u,v$,and $E_w=\\lbrace(w,x):\\text{ }(u,x)\\in E\\text{ or }(v,x)\\in E\\rbrace$$=\\lbrace(w,x):\\text{ }(u,x)\\in E_u\\text{ or }(v,x)\\in E_v\\rbrace$,and $E’=E\\setminus E_u\\setminus E_v\\cup E_w$.$C_e:\\mathcal{G}\\longrightarrow\\mathcal{G}$ is an edge-contraction operationsatisfying for $G=(V,E)\\in\\mathcal{G}$ it holds that $C_e(G)=(V’,E’)$. The graph $C_e(G)$ is also denoted as $G/e$. $\\underline{\\textbf{Lemma2}}$$G\\in\\mathcal{G}_{i,j}\\Longrightarrow C_e(G)\\in\\mathcal{G}_{i-1,j-k}$where $k=\\vert E_v\\cap E_u\\vert$ for $e=(u,v)\\in E$. MinorNow that we have $3$ type ofoperations(Edge-Deletion/Vertex-Deletion/Edge-Contraction),for graphs $G$ and $H$,$H$ is said to be a minor of $G$,denoted as $H\\leq G$,if there exists a list of operations $O_1,O_2,\\cdots O_k$such that $H=O_k\\circ\\cdots\\circ O_2\\circ O_1(G)=O_k(\\cdots(O_2(O_1(G))))$. $\\underline{\\textbf{Lemma3(transitive)}}$$F\\leq H\\text{ and }H\\leq G\\Longrightarrow F\\leq G$. Vertex MergeFor $G=(V,E)$, and $U\\subset V$, and $u\\notin V$,define $E_U=\\lbrace(x,y)\\in E: \\lbrace x,y\\rbrace\\cap U\\neq\\emptyset\\rbrace$,and $E_{U_1}=\\lbrace(x,y)\\in E: \\vert\\lbrace x,y\\rbrace\\cap U\\vert=1\\rbrace$,and $E_u=\\lbrace(u,y): (x,y)\\in E_{U_1}\\text{ and }x\\in U\\rbrace$.Then $M_U:\\mathcal{G}\\longrightarrow\\mathcal{G}$ is a vertex-mergeoperation of $G$ satisfying for $M_U(G)=G’=(V’,E’)$it holds that $V’=V\\cup\\lbrace u\\rbrace\\setminus U$ and$E’=E\\cup E_u\\setminus E_U$. The graph $M_U(G)$ is also denoted as $G/U$. $\\underline{\\textbf{Theorem4}}$$G=(V,E)$ is a graph.$V_0,V_1,\\cdots,V_k$ is a partition of $V$.$G[V_i]$ is connected for each $i\\in\\lbrace1,2,\\cdots,k\\rbrace$.Let graph $H=(G-V_0)/V_1/\\cdots/V_k$.Let graph $F$ be any spanning subgraph of $H$.Then $F$ is a minor of $G$. PROOF:Since $F$ is a spanning subgraph of $H$,there exists s set of edge-deletion operations $D_{e_1},D_{e_2},\\cdots,D_{e_x}$such that $F=D_{e_x}\\circ\\cdots\\circ D_{e_2}\\circ D_{e_1}(H)$,meaning that $F$ is a minor of $H$.By transitive of minor, it suffices to show $H$ is a minor of $G$,which is true because $H=(G-V_0)/V_1/\\cdots/V_k$.$\\square$","link":"/2024/03/16/Graph-Minor/"},{"title":"Kruskal 习题集合","text":"Easy 入门暂无 Medium 普及 LeetCode 1631 Path With Minimum Effort 最小体力消耗路径题解 哔哩哔哩 西瓜视频推荐度 ☆☆☆ LeetCode 1584 Min Cost to Connect All Points 连接所有点的最小代价题解 哔哩哔哩 西瓜视频推荐度 ☆☆☆☆ Hard 提高暂无","link":"/2021/02/01/Kruskal-%E4%B9%A0%E9%A2%98%E9%9B%86%E5%90%88/"},{"title":"ParseException line x:y cannnot recognize input near","text":"problemlinux 命令行执行 hive sql 脚本 run.sh 1234567#!/bin/shsource /etc/profilesource ~/.bash_profileyest=$(date -d "-1 days" "+%Y-%m-%d")yest2=$(date -d "-2 days" "+%Y-%m-%d")hive -hiveconf YEST_DATE${yest} YEST2_DATE=${yest2} -f test.sql > test.csv 报错 1FAILED: ParseException line xx:yy cannot recognize input near '$' '{' 'hivevar' in select clause 1FAILED: ParseException line xx:yy cannot recognize input near 'where' 'city_id' '=' in subquery source solution脚本 test.sql 存在语法不严谨","link":"/2021/08/23/ParseException-line-x-y-cannnot-recognize-input-near/"},{"title":"Permutation Importance","text":"Scikit-learn の Random Forest の Permutation importance を計算Sckit-learn的Random Forest的featureimportance_ 是Gini importance,可能有偏差。如果在意偏差的话,可以使用rfpimp等模块来计算并评价Permutation importance。 背景Random Forest对不需要计算成本却能显示出良好的预测性能非常满意,不过也有非线性的,说明变量的重量没有正负,评价也有困难的时候。 我觉得没有什么好的方法,查了很多之后,因为是千回百转的学习,所以作为备忘录整理好。 结果找到了以下的Repository。parrt/random-forest-importances 嗯,好像计算Permutation importance的重量的module。想着Permutation importance是什么呢,正好用日语整理的Tweet被Retweet了。Twitter好厉害。 用构建了OOB和外部套装等预测模型构筑中未使用的数据的预测模型进行预测,以当时的预测性能为基础线。然后,将某个说明变量的值像y-randomization那样打乱,构建预测模型,同样计算预测性能。那个时候,那个说明变量越重要预测性能就越大。通过各说明变量将其作为重要度的是Permutation Importance。 嗯,Random Forest的重要性例如像以下幻灯片的第8张那样“在制作决定木后随机地更换说明变量。之后预测OOB,根据更换前和预测性能的差来计算”,所以“感觉差不多,差别也会有那么大的变化吗?”一开始是这么想的。 但是,从最初介绍的rfpimp首页的链接可以进行的这个Repository作者的博客里有以下文章。https://explained.ai/rf-importance/index.html 123The most common mechanism to compute feature importances, and the one used in scikit-learn’s RandomForestClassifier and RandomForestRegressor, is the mean decrease in impurity (or gini importance) mechanism (check out the Stack Overflow conversation). 在Scikit-learn中,各说明变量的重要性是用Gini importance这个指标来计算的。 Gini importance简单来说就是Gini系数越小越容易判别的值,由于各说明变量的关系,需要变小多少的指标。如果是日语的话,以下的网站比较容易理解。 因为是难得的机会,所以在Sckit-learn的module中也试着看了一下。RandomForestClassifier在其中使用DecisionTreeClassifier。而且DecisionTreeClassifier好像使用了其中cython写的代码。所以才高速的吧。我虽然不能读cython,但是我发现了可能是这里的部分。 可以看出是取了差别作为importance。另外,DecisionTreeClassifier的Docomentation上也写着使用Gini importance。 也就是说,Sckit-learn的Random Forest的说明变量的重量是“在制作决定树后随机更换说明变量。之后预测OOB,根据更换前和预测性能的差来计算”,这是我的误解,实际上是使用Gini importance的。 因此,Repository的作者制作了寻求Permutation importance的module。终于理解了。学到了很多。 关于rfpimp module学习了很多东西,这次请允许我省略。不仅可以简单地计算Permutation importance,还可以汇总多个说明变量来计算Permutation importance,我觉得这是非常有趣的module。刚才介绍的作者的博客上也写了偏颇情况的说明,Jupter Notebook上也有易懂的Example,真是帮了我大忙了。 最后Gini importance当然也有好的地方,那就是重量计算快的地方之一。因为Permutation importance在其性质上需要多次进行预测模型构筑,所以比起Gini importance,计算权重更花费时间,可以说很容易地反复进行。 另一方面,Permutation importance不仅适用于Random Forest,也适用于其他机器学习方法,特别是对SVM等以往说明变量的权重无法得到的方法,由此可求出说明变量的权重。请一定要熟练使用。","link":"/2021/09/02/Permutation-Importance/"},{"title":"SPARK SQL ...including 1 partition column(s) having constant value(s)","text":"Solution 1select * from partitioned_table导致不能被选择的常数分区列将脚本中所有的 select * 展开为每一列REF 2彻底删除整个表drop table if exists table_dev; √alter table table_dev if exists partition (dt=’year-month-day’); × 3通过改变create table if not exists table_dev (col1 string, col2 string) partitioned by (dt string);中的列的数量发现问题2 4调试的方法一个是单元测试,一个是AB测试","link":"/2021/07/30/SPARK-SQL-including-1-partition-column-s-having-constant-value-s/"},{"title":"Swing/user-cf/item-cf召回算法","text":"introductionSwing 意为荡秋千,表示 item-user-item 三角关系,该算法是阿里提出的召回算法,对物品 i,j 的所有共同购买用户 U,计算从任意两个用户 u,v 的角度得到 i,j 的相似度$s(u,v,i,j)=\\frac{1}{\\alpha + \\left|I_u\\cap I_v\\right|}$然后求和得到 i,j 的相似度$\\textbf{sim}(i,j) = \\sum_{u\\in U}\\sum_{v\\in U} s(u,v,i,j)$ user-cf 基于相似用户之间的物品扩散item-cf 基于相似物品之间的用户扩散二者做复合运算,与分开两路召回相比,复杂度多一层循环,对用户推荐的物品增多可考虑基于四部图随机游走的 tradeoff 方案 question该算法的假设是若两用户 u,v 除 i,j 外的共同购买物品越多,则 i,j 相似度越低若两用户 u,v 除 i,j 外的共同购买物品越少,则 i,j 相似度越高这个假设难以理解,我的观点如下:若两用户 u,v 除 i,j 外的共同购买物品越多,则 u,v 相似度越高若两用户 u,v 除 i,j 外的共同购买物品越少,则 u,v 相似度越低这表示 i,j 具有强转移性,所以 Swing 算法召回的是具有强转移性(互补/关联)的物品,而不是具有相似性的物品","link":"/2021/08/09/Swing-%E5%8F%AC%E5%9B%9E%E7%AE%97%E6%B3%95/"},{"title":"Union Find Set 习题集合","text":"Easy 入门暂无 Medium 普及 洛谷 P3367 【模板】并查集题解 哔哩哔哩 西瓜视频推荐度 ☆☆☆☆☆ Hard 提高暂无","link":"/2021/02/02/Union-Find-Set-%E4%B9%A0%E9%A2%98%E9%9B%86%E5%90%88/"},{"title":"fatal unable to access github","text":"problem 1部署 hexo 1hexo d 报错 1fatal: unable to access 'https://github.com/edogawashinichi/edogawashinichi.github.io.git/': The requested URL returned error: 403 solution2021-08-13 起 github 不再允许自动保存密码Personal Access Token kartik tyagi problem 2部署 hexo 1hexo d 报错 1fatal: unable to access 'https://github.com/edogawashinichi/edogawashinichi.github.io.git/': Failed to connect to github.com port 443: Operation timed out 或 1fatal: unable to access 'https://github.com/edogawashinichi/edogawashinichi.github.io.git/': LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443 solution网络问题,重复执行几次 hexo d","link":"/2021/08/16/fatal-unable-to-access-https-github-com-edogawashinichi-edogawashinichi-github-io-git/"},{"title":"install pyFM","text":"手动安装国内 github 不稳定,先下载再安装 在https://github.com/coreylynch/pyFM中手动下载包 将包解压,更改里面的setup.py文件,去掉setup.py文件里面的libraries=[“m”]一行 cd到当前文件夹下python setup.py install 参考","link":"/2021/08/12/install-pyFM/"},{"title":"hexo back","text":"知乎太坑,转回github。 环境调通好久不用,环境有些问题,解决https://blog.csdn.net/eagleuniversityeye/article/details/85267550在package.json目录下执行npm install hexo-server –save 命令忘差不多了,攒起来同样在package.json目录下启动本地服务 hexo s写文章 hexo new “文章标题”清空public下的内容 hexo clean把source的内容生成到public下 hexo g把public下的内容同步到github仓库 hexo d github需要使用PAT代替密码进行远程连接解决https://stackoverflow.com/questions/68775869/message-support-for-password-authentication-was-removed 用的免费梯子,hexo d经常连不上githubfatal: unable to access ‘https://github.com/需要多试几次(一般需要3次)hexo d成功github.io页面刷新一般也存在一定延时 hexo d同步自动使用github原来的账号密码解决:把https方式改为http方式https://www.lintstar.top/2021/08/4b8ee7df.html#Hexo-连接-Github host key verification failed原因是github.com更换了ip解决:重新连接保存到本地https://timmousk.com/blog/host-key-verification-failed-git/ git@github.com: Permission denied (publickey)原因:github新版本删除了原来的mac笔记本的ssh-pubkey解决:github增加两个ssh-pubkey(authentication,signing)https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account github加载不出settings页面解决:直接输入https://github.com/settings回车 发博客流程命令行都在package.yml所在路径下执行 本地创建文章1hexo new "文章标题" 编辑文章使用sublime或vim 重新渲染生成网页12hexo cleanhexo g 本地预览1hexo s 浏览器登录localhost:4000 同步到远程1hexo d","link":"/2024/02/29/hexo-back/"},{"title":"model saving disabled","text":"problem在 jupyter notebook 上打开保存的模型文件报错 123Error! ./models/fm_scaler.mdl is not UTF-8 encodedSaving disabled.See Console for more details. solution误导性输出因为 jupyter 无法打开二进制文件服务器终端查看文件类型 12file fm_scaler.mdlfm_scaler.mdl 8086 relocatable (Microsoft)","link":"/2021/08/20/model-saving-disabled/"},{"title":"no module named tkinter","text":"problem执行 Python 脚本 1import matplotlib.pyplot as plt 报错 1ModuleNotFoundError: No module named '_tkinter' solution需要重新安装Python","link":"/2021/08/16/no-module-named-tkinter/"},{"title":"开源软件商用","text":"开源协议是否可以商用(总结) Apache BSD GPL MIT Mozilla 能否商用 Apache Licence是对商业应用友好的许可。使用者也可以在需要的时候修改代码来满足需要并作为开源或商业产品发布/销售。 商业软件可以使用,也可以修改使用BSD协议的代码。 商业软件不能使用GPL协议的代码。 商业软件可以使用,也可以修改MIT协议的代码,甚至可以出售MIT协议的代码。 商业软件可以使用,也可以修改MPL协议的代码,但修改后的代码版权归软件的发起者。 其他参考","link":"/2021/09/03/%E5%BC%80%E6%BA%90%E8%BD%AF%E4%BB%B6%E5%95%86%E7%94%A8/"},{"title":"pyFM vs fastFM","text":"Translation 使用 Movielens 尝试分解机 Python 实现 pyFM、fastFM——2019 年 12 月 11 日你好,我是 Guglilac (@guglilac)。 本文是关于对 Movielens 数据集使用 pyFM 和 fastFM 这两个最大的因子分解机 (FM) 的 Python 实现。 如何使用fastFMGitHub - ibayer/fastFM: fastFM: A Library for Factorization Machines 据说不仅可以使用回归和分类,还可以使用 BPR 损失来预测排名,但是在另一个人的文章中,BPR 不起作用。 我也和这篇文章分开试过BPR loss,但是没学好。在本文中,Movielens 用于评分预测,所以让我们仅使用回归模型来学习。 输入以与 pyFM 相同的方式作为 scipy 的稀疏矩阵给出。结果只贴pyFM,这里只贴写法。 只需初始化并正常安装即可。 123from fastFM import als,sgdmodel = als.FMRegression(n_iter=100, l2_reg_w=0.1, l2_reg_V=0.1, rank=10)model.fit(X_train,y_train) 但是,默认情况下,根本不显示学习历史,也不应用学习曲线,因此不清楚学习是否在进行。 如果你查一下,指南 — fastFM 0.2.10 文档 正如本页所写,似乎您需要自己实现显示学习历史的部分。 当我试图模仿它时, 12345678910111213141516171819202122from sklearn.metrics import mean_squared_errorimport numpy as npdef get_rmse(model,X, y): y_pred=model.predict(X) return np.sqrt(mean_squared_error(y_pred, y))def train(model,X_train,y_train,n_iter,iter_size=1): model.fit(X_train,y_train) # initのためにこれが必要 rmse_hist=[] iter_size=1 for i in range(n_iter): model.fit(X_train, y_train,n_more_iter=iter_size) rmse_train=get_rmse(model,X_train,y_train) rmse_hist.append(rmse_train) if (i+1)%10==0: print(f" epoch = {i+1}, Train RMSE : {rmse_train: 0.4f}") return model,rmse_histmodel = als.FMRegression(n_iter=0, l2_reg_w=0.1, l2_reg_V=0.1, rank=10)model,history=train(model,X_train,y_train, n_iter=100) 需要实现模型初始化时n_iter = 0,迭代一次n_more_iter,更新模型,每次计算loss。 这次不包括验证,但当然您也可以包含验证数据来计算损失。 现在您可以根据历史绘制学习曲线。 如何使用 pyFMGitHub - coreylynch/pyFM: Factorization machines in python 这次使用的图书馆。仅支持回归和分类。 同样,输入作为稀疏矩阵给出。我为获取 Movielens 数据并对其进行处理的部分创建了自己的类。 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960import numpy as npimport pandas as pdfrom scipy.sparse import csr_matrixfrom pathlib import Pathimport codecsimport category_encoders as ceclass MovielensLoader: def __init__(self, data_dir=Path("./ml-100k"), user_filename="u.user",item_filename="u.item"): self.data_dir = data_dir self.user_path = data_dir / user_filename self.item_path = data_dir / item_filename def create_dataset(self, include_user_features=True, include_item_features=True): df_train, y_train = self.load_log_and_ratings(log_filename="ua.base") df_test, y_test = self.load_log_and_ratings(log_filename="ua.test") target_col = ["uid", "mid"] if include_user_features: users = self.load_users() target_col = list(set(target_col + users.columns.tolist())) df_train = pd.merge(df_train, users, on="uid") df_test = pd.merge(df_test, users, on="uid") if include_item_features: items = self.load_items() df_train = pd.merge(df_train, items, on="mid") df_test = pd.merge(df_test, items, on="mid") self.encoder = ce.OneHotEncoder(cols=target_col) X_train = self.encoder.fit_transform(df_train) X_test = self.encoder.transform(df_test) X_train = csr_matrix(X_train, dtype=np.float) X_test = csr_matrix(X_test, dtype=np.float) return X_train, y_train, X_test, y_test def load_log_and_ratings(self, log_filename, drop_columns=["timestamp"]): logs = pd.read_csv(self.data_dir / log_filename, names=["uid", "mid", "rating", "timestamp"], sep="\\t", dtype=str) ratings = np.array(logs["rating"], dtype=np.float) drop_columns.append("rating") logs = logs.drop(drop_columns, axis=1) return logs, ratings def load_users(self, drop_columns=["age", "zip_code"]): users = pd.read_csv(self.user_path, names=["uid", "age", "gender", "occupation", "zip_code"], sep="|", dtype=str) users = users.drop(drop_columns, axis=1) return users def load_items(self): with codecs.open(self.item_path, "r", "Shift-JIS", "ignore") as f: items = pd.read_table(f, names=["mid", "title", "released", "video_released", "IMDb_URL", "unknown", "Action", "Adventure", "Animation", "Children", "Comedy", "Crime", "Documentary", "Drama", "Fantasy", "Film_Noir", "Horror", "Musical", "Mystery", "Romance", "Sci_Fi", "Thriller", "War", "Western"], delimiter="|", dtype=str) items = items.drop(["title", "released", "video_released", "IMDb_URL"], axis=1) return items 从 MovieLens | GroupLens 下载 Movielens 数据并只准备目录 ./ml-100k。由于 Movielens 在满负荷使用时数据过多,因此发布了各种大小的数据。这次我尝试使用 100k 数据。 Movielens 包含用户附加到项目(电影)的评分数据,每个用户和项目都与一个特征相关联。 用户特征包括年龄、性别、职业,项目特征包括流派。 这一次,我们将使用性别和职业作为用户特征,并使用类型作为项目。 FM 的优点是可以放入这些上下文信息。如果不使用,它将是一个类似于矩阵分解的模型。 这一次,有和没有这些上下文信息 1include_user_features=True, include_item_features=True 我试图通过部分参数来控制。 下面我们进行初始化和学习。 1pylibfm.FM(num_factors=10, num_iter=100, verbose=True, task="regression", initial_learning_rate=0.001, learning_rate_schedule="optimal") 让我们看看结果。下面,计算测试数据中的RMSE。 12345baseline 1.1220FM 1.1979 (user, itemあり)FM 1.1871 (itemだけ)FM 0.9417 (userだけ)FM 0.9465 (userもitemもなし) 基线是一个不断返回训练数据平均评分的模型。目前,在没有用户和项目的上下文(MF)和用户的附加信息的情况下,RMSE 低于基线,但结果是当包含项目的类型信息时,RMSE 增加。 我还没有调整超参数,所以也许这就是原因。 奖金(其他图书馆)GitHub - jfloff/pywFM: pywFM is a Python wrapper for Steffen Rendle’s factorization machines library libFM FM 作者 Rendle 的官方库 libFM 的 Python 包装器。仅支持回归和分类。 pyfms · PyPI 它是基于 theano 的,但我也发现了类似的东西。很抱歉我没有正确地看到它。 综上所述我尝试使用一次热编码使用 pandas 的 get_dummies 一次,但是如果在测试时出现 train 时不存在的特征,或者相反,如果 train 时存在的某些东西在测试时消失,维度是我不能用的,因为我做不到。 查了一下,Category Encoders 转换类别特征无压力——Qiita 很方便。 不要使用 get_dummies …","link":"/2021/08/12/pyFM-vs-fastFM/"},{"title":"枚举所有子集","text":"Problem 枚举全集的所有子集枚举数组 $a={1,2,3,6}$的所有子集 解答 solution构建 $[0, 2^n]$ 到 $a$ 的所有子集的双射从 0000 枚举到 1111 代码 code123int n = a.size()for (int i = 0; i < (1 << n); ++i) {} Problem 枚举非全集的所有子集三个字符串 A=’abd’, B=’be’, C=’df’枚举每个字符串的所有子集 解答 solution构建二进制表示 A=001011, B=010010, C=101000对于A的所有子集,subset从A开始枚举,然后迭代subset -= 1,然后限制在A空间上 subset &= A 即 subset = (subset - 1) & A变换前后subset在A空间上至多相差1,因为它们在全空间上相差1,也就是说变换前后subset在A空间上要么相等要么相邻由于每个subset在A空间之外的分量都是0然后嵌入到全空间上,subset-1必然导致subset在A空间上发生改变,所以变换前后subset在A空间上是相邻的,这样就完成了对非全空间A的所有子集的顺序遍历 代码 code123for (int subset = A; subset; ) { subset = (subset - 1) & A;}","link":"/2021/02/26/%E6%9E%9A%E4%B8%BE%E6%89%80%E6%9C%89%E5%AD%90%E9%9B%86/"},{"title":"物料智能编码","text":"背景 Why物料编码是 ERP 信息化的一个基本问题。物料具有多种属性,不同的物料其名称可能是相同的,不能仅根据物料名称来区分不同物料,需要给每种物料一个唯一的编码。对物料进行编码的过程中,由于存在地区时间的差异等因素,会出现一种物料多个编码的情况,这就容易造成物资积压、调度性差、资源浪费等问题。因此我们需要一个便于录入读取并且易于扩展的物料编码解决方案。 问题描述 What对于多种(可能高达数十万种)物料,并且物料的种类可能随着时间不断增加,如何给每种物料一个编码,要求: 每种物料的编码唯一,且一旦确定就不再更改 给定一个编码,相关工作人员不需查询就容易知道是何种物料 给定一个物料,可以知道其编码是否已经存在 给定一个物料,若其编码已经存在,相关工作人员不需查询就容易知道其编码 案例 Example由于原始数据难以脱敏,现以三国人物作为物料 数据 data 姓名 表字 势力 武力 统帅 智力 内政 外交 魅力 忠诚 武器 坐骑 技能 曹操 孟德 魏 70 90 75 80 70 90 60 青釭剑 绝影 奸雄 诸葛亮 孔明 蜀 65 92 96 99 98 95 95 朱雀羽扇 木牛流马 八阵 关羽 云长 蜀 98 95 85 60 50 95 98 青龙偃月刀 赤兔 武圣 刘备 玄德 蜀 75 80 75 75 70 98 80 雌雄双股剑 的卢 仁德 张飞 翼德 蜀 97 80 80 50 60 75 98 丈八蛇矛 无 咆哮 吕布 奉先 群 100 75 50 50 60 70 30 方天画戟 赤兔 无双 董卓 仲颖 群 80 80 65 60 70 60 40 无 赤兔 暴虐 司马懿 仲达 魏 80 90 90 90 80 80 65 无 无 天命 孙权 仲谋 吴 70 85 75 80 70 85 65 吴六剑 无 制衡 周瑜 公瑾 吴 85 95 85 75 75 80 90 无 无 英姿 袁绍 本初 群 70 75 70 70 60 85 80 无 无 名门 张角 无 群 70 80 80 70 55 90 50 无 无 黄天 司马昭 子尚 晋 80 90 85 80 80 75 50 无 无 昭心 贾诩 文和 群 65 65 97 85 85 75 70 无 无 毒士 贾诩 文和 魏 65 65 97 85 85 75 90 无 无 毒士 荀彧 文若 魏 65 65 96 96 80 90 95 无 无 节命 荀攸 公达 魏 65 65 99 80 75 80 90 无 无 奇策 郭嘉 奉孝 魏 60 65 98 90 90 90 95 无 无 天妒 程昱 仲德 魏 85 85 92 80 70 70 90 无 无 设伏 姜维 伯约 蜀 88 90 92 88 80 85 95 无 无 志继 姜维 伯约 魏 88 90 92 80 75 80 75 无 无 挑衅 鲁肃 子敬 吴 70 80 90 80 95 75 90 无 无 缔盟 吕蒙 子明 吴 80 90 90 75 60 75 90 无 无 博学 陆逊 伯言 吴 70 90 92 75 70 80 90 无 无 连营 孙坚 文台 吴 95 90 80 70 70 90 80 古锭刀 无 英魂 许褚 仲康 魏 97 80 60 50 50 75 90 贯石斧 无 裸衣 典韦 无 魏 99 65 55 50 50 75 95 双戟 无 强袭 黄忠 汉升 蜀 95 80 75 60 60 70 85 麒麟弓 无 烈弓 马超 孟起 群 97 85 70 70 70 80 80 无 无 铁骑 马超 孟起 蜀 97 85 70 70 70 80 80 无 无 铁骑 赵云 子龙 蜀 96 70 75 70 70 90 95 银月霸王枪 无 龙胆 魏延 文长 蜀 93 80 82 70 60 65 85 无 无 狂骨 法正 孝直 蜀 74 79 97 74 69 88 95 无 无 恩怨 庞统 士元 蜀 65 65 96 90 90 75 90 无 无 涅槃 孙策 伯符 吴 94 90 65 70 70 90 80 无 无 激昂 太史慈 子义 吴 94 85 75 65 65 90 90 无 无 天义 甘宁 兴霸 吴 94 85 80 65 65 75 90 无 无 奇袭 张辽 文远 魏 93 85 80 65 70 85 85 无 无 突袭 徐晃 公明 魏 90 85 85 65 65 85 90 无 无 断粮 夏侯惇 元让 魏 94 88 70 65 65 88 95 无 无 刚烈 庞德 令明 魏 94 85 70 65 65 85 90 无 无 猛进 曹纯 子和 魏 70 75 75 70 65 80 95 无 无 缮甲 初步编码 tentative给每个人物唯一一个编码 外部环境规定每个属性的重要性,不同属性的重要性可以相同0 姓名 1 表字 势力 武器 坐骑 技能 2 武力 统帅 智力 内政 外交 魅力 忠诚 对于非数值型属性,重要性相同的属性按照信息熵由小到大排列0 姓名 1 势力 2 坐骑 3 武器 4 表字 5 技能 对于数值型属性,除非外部环境规定,一般不纳入编码规定加入 6 武力 7 智力 非数值型属性之间以拼音首字母(为了区分度可能增加至多个)大小写分割,数值型属性都用两位数字表示 编码 姓名 势力 坐骑 武器 表字 技能 武力 智力 CCweJYqgjMDjx7075 曹操 魏 绝影 青釭剑 孟德 奸雄 70 75 ZGLsMNLMzqysKMbz6596 诸葛亮 蜀 木牛流马 朱雀羽扇 孔明 八阵 65 96 GYsCTqlyydYCws9885 关羽 蜀 赤兔 青龙偃月刀 云长 武圣 98 85 优化后的编码 optimize 某些属性与主要属性的交叉熵比较大,去掉这些冗余的属性 信息熵较小且重要性较大的属性放在最前面便于分类 编码 姓名 势力 武力 智力 Ecc7075 曹操 魏 70 75 Szgl6596 诸葛亮 蜀 65 96 Sgy9885 关羽 蜀 98 85 Slb7575 刘备 蜀 75 75 Szf9780 张飞 蜀 97 80 Qlb0050 吕布 群 100 50 Qdz8065 董卓 群 80 65 Esmy8090 司马懿 魏 80 90 Usq7075 孙权 吴 70 75 Uzy8585 周瑜 吴 85 85 Qys7070 袁绍 群 70 70 Qzj7080 张角 群 70 80 Jsmz8085 司马昭 晋 80 85 Qjx6597 贾诩 群 65 97 Ejx6597 贾诩 魏 65 97 Exy6596 荀彧 魏 65 96 Exy6599 荀攸 魏 65 99 Egj6098 郭嘉 魏 60 98 Ecy8592 程昱 魏 85 92 Sjw8892 姜维 蜀 88 92 Ejw8892 姜维 魏 88 92 Uls7090 鲁肃 吴 70 90 Ulm8090 吕蒙 吴 80 90 Ulx7092 陆逊 吴 70 92 Usj9580 孙坚 吴 95 80 Exc9760 许褚 魏 97 60 Edw9955 典韦 魏 99 55 Shz9575 黄忠 蜀 95 75 Qmc9770 马超 群 97 70 Smc9770 马超 蜀 97 70 Szy9675 赵云 蜀 96 75 Swy9382 魏延 蜀 93 82 Sfz7497 法正 蜀 74 97 Spt6596 庞统 蜀 65 96 Usc9465 孙策 吴 94 65 Utsc9475 太史慈 吴 94 75 Ugn9480 甘宁 吴 94 80 Ezl9380 张辽 魏 93 80 Exh9085 徐晃 魏 90 85 Exhd9470 夏侯惇 魏 94 70 Epd9470 庞德 魏 94 70 Ecc7075zh 曹纯 魏 70 75 编码的可扩展性 scalability 每当产生冲突时,已经编码的物料其编码保持不变 对新添加的物料编码增加维度,优先选择信息熵较大的非数值型属性,综合考虑重要性、复杂度 姓名 表字 势力 武力 统帅 智力 内政 外交 魅力 忠诚 武器 坐骑 技能 曹操 孟德 魏 70 90 75 80 70 90 60 青釭剑 绝影 奸雄 曹纯 子和 魏 70 75 75 70 65 80 95 无 无 缮甲 编码 姓名 势力 武力 智力 表字 Ecc7075 曹操 魏 70 75 Ecc7075zh 曹纯 魏 70 75 子和 解决方案 How","link":"/2021/02/02/%E7%89%A9%E6%96%99%E6%99%BA%E8%83%BD%E7%BC%96%E7%A0%81/"},{"title":"Immunity to All Poisons, the 7th Level of Nine-Yang-Divine-Skill, for Network-Max-Flow","text":"网络最大流之九阳神功第七层「诸毒不侵」 Preface 前言The mechanic who wishes to do his work well,must first sharpen his tools. Having Solved the basic theoretical problems,immunity to all poisons,the 7th level of Nine-Yang-Divine-Skill,goes back to algorithmic problems again. 工欲善其事必先利其器, 解决了基本理论问题, 九阳神功第七层「诸毒不侵」再次回到算法问题。 Shortest Augmenting Path Algorithm 最短提升路算法Pseudo Code 伪代码123456789101112131415161718192021222324252627282930313233343536ALGORITHM ShortestAugmentingPath;BEGIN F := 0; init distance function D; init predecessor function Pred; v := s; WHILE D(s) < n DO BEGIN IF v has an admissible arc THEN BEGIN Advance(v); if v == t then Augment() and v := s; END ELSE Retreat(v); ENDENDFUNCTION Advance(v);BEGIN get an admissible arc (v,w); Pred(w) := v; v := w;ENDFUNCTION Retreat(v);BEGIN D(v) := min{D(u)+1 : (u,v) in A, r(u,v)>0}; IF v != s THEN v := Pred(v);ENDFUNCTION Augment;BEGIN P := the admissible augmenting path from s to t; delta := min{r(u,v) : (u,v) in A(P)}; augment delta units of flow F along path P;END Concept 概念$G=(V,A,~\\mathcal{C})$ is the network,with source $s\\in V$ and sink $t\\in V$. $\\forall\\text{ }u,v\\in V$.$P_{u,v}$ is a path from $u$ to $v$.$Q_{u,v}$ is a shortest path from $u$ to $v$. $A$ is symmetric:$(u,v)\\in A\\Longrightarrow(v,u)\\in A$. $f$ is a flow of $G$.$r=\\mathcal{C}-f$ is the residual of $G$ w.r.t. $f$.The residual network $G[r]=(V,A_r,r)$ satisfying $A_r=\\lbrace a\\in A:r(a)>0\\rbrace$. DistanceThe distance from $v$ to $t$, denoted as $\\mathfrak{D}(v)$,is the length of $Q_{v,t}$. Quasi-DistanceA function $D:V\\longrightarrow\\mathbb{N}$ is called a quasi-distance,if $D(t)=0$ and $D(u)\\leq D(v)+1,\\text{ }\\forall\\text{ }(u,v)\\in A$. AdmissibleAn arc $(u,v)\\in A$ is called admissible w.r.t. $D$ if $D(u)=D(v)+1$.$P_{u,v}$ is called admissible if every arc of $P_{u,v}$ is admissible. ExactA quasi-distance $D$ is called exact if $D=\\mathfrak{D}$. Lemma 引理$\\underline{\\textbf{Lemma0}}$For any arc $(u,v)$,it holds $\\mathfrak{D}(u)=\\mathfrak{D}(v)-1\\text{ or }\\mathfrak{D}(v)\\text{ or }\\mathfrak{D}(v)+1$.So $\\mathfrak{D}$ is a quasi-distance. $\\textbf{proof:}$The extended path $(u,v)Q_{v,t}$ is a path from $u$ to $t$,thus leading to $\\mathfrak{D}(u)\\leq\\vert(u,v)Q_{v,t}\\vert=1+\\mathfrak{D}(v)$.Since $(u,v)\\in A\\Longrightarrow(v,u)\\in A$,the extended path $(v,u)Q_{u,t}$ is a path from $v$ to $t$,thus leading to $\\mathfrak{D}(v)\\leq\\vert(v,u)Q_{u,t}\\vert=1+\\mathfrak{D}(u)$.$\\square$ $\\underline{\\textbf{Lemma1}}$For any vertex $v\\in V$,there exists an admissible path $P_{v,t}$ w.r.t. $\\mathfrak{D}$,which is exactly $Q_{v,t}$. $\\textbf{proof:}$Since $G$ is connected and $A$ is symmetric,by BFS from $t$ backward to $v$,we get an admissible $v,t$ path $P_{v,t}$,which is of course the shortest path.$\\square$ $\\underline{\\textbf{Lemma2}}$For any quasi-distance $D$,it holds that $D\\leq\\mathfrak{D}$. $\\textbf{proof:}$For any vertex $v\\in V$,let the shortest path $Q_{v,t}=v_0v_1\\cdots v_l$,with $v_0=v$ and $v_l=t$.By definition of quasi-distance,$D(v_{l-1})\\leq D(v_l)+1=1$,$D(v_{l-2})\\leq D(v_{l-1})+1$,$\\vdots$$D(v_0)\\leq D(v_1)+1$.The summation gives $D(v)\\leq l=\\mathfrak{D}(v)$.$\\square$ $\\underline{\\textbf{Lemma3}}$In $G[r]$, if $D(s)\\geq\\vert V\\vert$,then $G[r]$ contains no path from $s$ to $t$. $\\textbf{proof:}$Suppose to the contrary $G[r]$ contains a path $Q_{s,t}$.By Lemma2, $D(s)\\leq\\mathfrak{D}(s)=\\vert Q_{s,t}\\vert\\leq\\vert V\\vert-1$,violating $D(s)\\geq\\vert V\\vert$.$\\square$ $\\underline{\\textbf{Lemma4}}$If $P_{s,t}$ is admissible w.r.t. $D$, then it’s a shortest path. $\\textbf{proof:}$Since $P_{s,t}$ is admissible,then $\\mathfrak{D}(s)\\leq\\vert P_{s,t}\\vert=D(s)$.By Lemma2, $D(s)\\leq\\mathfrak{D}(s)$.Therefore $D(s)=\\mathfrak{D}(s)$,meaning that $P_{s,t}$ is a shortest $s,t$ path.$\\square$ $\\underline{\\textbf{Lemma5}}$When the ShortestAugmentingPath algorithm terminates,the residual network contains no augmenting paths. $\\textbf{proof:}$when the algorithm terminates,it holds $D(s)\\geq\\vert V\\vert$.The result follows by Lemma3.$\\square$ $\\underline{\\textbf{Theorem6}}$When the ShortestAugmentingPath algorithm terminates,it outputs a max-flow of the network. $\\textbf{proof:}$By Lemma5, and Theorem0 ofGecko Roaming the Wall, the 6th Level of Nine-Yang-Divine-Skill, for Network-Max-Flow, 网络最大流之九阳神功第六层「壁虎游墙」.$\\square$ $\\underline{\\textbf{Theorem7}}$Suppose the algorithm terminates.Let $f_1,f_2,\\cdots,f_t$ be the flows the algorithm generates,$G[r_1],G[r_2],\\cdots,G[r_t]$ be the correspondent residual networks,and $D_1,D_2,\\cdots,D_t$ be the correspondent quasi-distance functions.Then $D_1\\leq D_2\\leq\\cdots\\leq D_t$.Furthurmore, for any $D_{i}\\leq D_{i+1}$,if no Retreat is operated,then $D_{i}=D_{i+1}$,otherwise there exists $v\\in V$,such that $D_{i}(v)<D_{i+1}(v)$. Summary 小结This post introduces ShortestAugmentingPath algorithm. Reference 参考 Purple Qi of the Rich Mist, the 1st Level of Nine-Yang-Divine-Skill, for Network-Max-Flow, 网络最大流之九阳神功第一层「氤氲紫气」 Tendon Changing and Marrow Cleansing, the 2nd Level of Nine-Yang-Divine-Skill, for Network-Max-Flow, 网络最大流之九阳神功第二层「易筋洗髓」 Fiery Qi of the Ultimate Yang, the 3rd Level of Nine-Yang-Divine-Skill, for Network-Max-Flow, 网络最大流之九阳神功第三层「至阳热气」 Bone Shrinking Technique, the 4th Level of Nine-Yang-Divine-Skill, for Network-Max-Flow, 网络最大流之九阳神功第四层「缩骨大法」 Turtle Breathing Technique, the 5th Level of Nine-Yang-Divine-Skill, for Network-Max-Flow, 网络最大流之九阳神功第五层「龟息大法」 Gecko Roaming the Wall, the 6th Level of Nine-Yang-Divine-Skill, for Network-Max-Flow, 网络最大流之九阳神功第六层「壁虎游墙」 Immunity to All Poisons, the 7th Level of Nine-Yang-Divine-Skill, for Network-Max-Flow, 网络最大流之九阳神功第七层「诸毒不侵」 Indestructible Vajra Body, the 8th Level of Nine-Yang-Divine-Skill, for Network-Max-Flow, 网络最大流之九阳神功第八层「金刚不坏」 Rebound Attack, the 9th Level of Nine-Yang-Divine-Skill, for Network-Max-Flow, 网络最大流之九阳神功第九层「反弹攻击」 Stronger with Each Use, the 10th Level of Nine-Yang-Divine-Skill, for Network-Max-Flow, 网络最大流之九阳神功第十层「愈使愈强」","link":"/2024/03/06/%E7%BD%91%E7%BB%9C%E6%9C%80%E5%A4%A7%E6%B5%81%E4%B9%8B%E4%B9%9D%E9%98%B3%E7%A5%9E%E5%8A%9F%E7%AC%AC%E4%B8%83%E5%B1%82%E3%80%8C%E8%AF%B8%E6%AF%92%E4%B8%8D%E4%BE%B5%E3%80%8D/"},{"title":"Gecko Roaming the Wall, the 6th Level of Nine-Yang-Divine-Skill, for Network-Max-Flow","text":"网络最大流之九阳神功第六层「壁虎游墙」 Preface 前言It’s a ridge viewing from a horizontal perspective, while a peak from otherwise, with distinct distances and heights. To comprehend the nature of Network-Max-Flow, it’s required to observe it from various perspectives. Therefore, gecko roaming the wall, the 6th level of Nine-Yang-Divine-Skill, will continue to discuss theoretical problems. 横看成岭侧成峰,远近高低各不同。 欲识庐山真面目,就需要从各个角度去观察网络最大流。 所以九阳神功第六层「壁虎游墙」继续讨论理论问题。 Convergence Condition 算法收敛条件Augmenting-Path 提升路$G=(V,A,~\\mathcal{C})$ is a network,where $\\mathcal{C}:A\\longrightarrow\\mathbb{R}$ unless otherwise regulated.$P$ is an $s,t$ path of $G$.$f:A\\longrightarrow\\mathbb{R}$ is a flow of $G$.$r=\\mathcal{C}-f$ is the residual of $G$ with respect to $f$.Then $P$ is called an augmenting-path of $G$,if $r(a)>0$ for any arc $a\\in A(P)$. Theorem0 定理0Alias of Convergence Condition Theorem. For any algorithm based on augmenting-paths, it’s always provided that: the network contains no augmenting-paths when the algorithm terminates. We’ll prove Theorem7 of the 5th level of Nine-Yang-Divine-Skill in the following pipeline. $\\underline{\\textbf{Theorem0}}$$f$ is a max-flow of $G$ iff $G$ contains no augmenting-paths. $\\textbf{proof:}$$”\\Longrightarrow”$ Obviously. If not, $f$ will be augmented.$”\\Longleftarrow”$ By Lemma2 there exists a cut $(S,\\bar S)$ s.t. $r(S,\\bar S)=0$. By Lemma3 of the 5th Level of Nine-Yang-Divine-Skill, $f$ is a max-flow.$\\square$ Lemma1 引理1Let $\\mathcal{P}(G)$ be the set of all $s,t$ paths of $G$, i.e. $\\mathcal{P}(G)=\\lbrace P:~P\\text{ is an }s,t\\text{ path of }G\\rbrace$. $\\underline{\\textbf{Lemma1}}$$G$ contains no augmenting-paths iff for any $P\\in\\mathcal{P}(G)$ there exists $a\\in A(P)$ s.t. $r(a)=0$. $\\textbf{proof:}$$”\\Longrightarrow”$ If not, there exists $P\\in\\mathcal{P}(G)$ s.t. for all $a\\in A(P):~r(a)\\neq0$. By $f$’s property (i) Bound, we have $r(a)>0$. This means $P$ is an augmenting-path, violating that $G$ contains no augmenting-paths.$”\\Longleftarrow”$ Similarly using proof by contradiction.$\\square$ Lemma2 引理2Let $Q$ be a path starting with $s$ but not containing $t$. $Q$ is called an s-partial-augmenting-path(SPAP) of $G$, if $r(a)>0$ for any arc $a\\in A(Q)$. Let $\\mathcal{Q}(G)=\\lbrace Q:~Q\\text{ is an SPAP of }G\\rbrace$. Let $V(\\mathcal{Q})=\\bigcup\\limits_{Q\\in\\mathcal{Q}(G)}V(Q)$. $\\underline{\\textbf{Lemma2}}$$G$ contains no augmenting-paths iff there exists a cut $(S,\\bar S)$ s.t. $r(S,\\bar S)=0$. $\\textbf{proof:}$$”\\Longleftarrow”$ $r(S,\\bar S)=0$ is equivalent to $r(a)=0,\\text{ }\\forall\\text{ }a\\in(S,\\bar S)$.By Lemma6, any $s,t$ path $P$ meets $(S,\\bar S)$ at $a\\in A(P)\\cap(S,\\bar S)$ with $r(a)=0$,indicating that $P$ isn’t an augmenting-path by Lemma1.$”\\Longrightarrow”$ Let $S=V(\\mathcal{Q})$ and we’ve done.It suffices to show $r(a)=0,\\text{ }\\forall\\text{ }a\\in(S,\\bar S)$.Suppose to the contrary that $\\exists\\text{ }a=(x,y)\\in(S,\\bar S)\\text{ s.t. }r(a)\\neq0$.By the definition of $V(\\mathcal{Q})$, there exists $Q\\in\\mathcal{Q}(G)$s.t. $x$ is a vertex, particularly the last vertex of $Q$.Since $r(a)>0$, then the extended path $Qy\\in\\mathcal{Q}(G)$, violating that $y\\in\\bar S$.$\\square$ Corollary3 推论3If the loop of the algorithm is executed in finite steps,we call the algorithm terminates. $\\underline{\\textbf{Corollary3}}$If the algorithm terminates, then it outputs a max-flow of the network. $\\textbf{proof:}$The condition the algorithm terminates implies the network contains no augmenting-paths.The result follows by Theorem0.$\\square$ Is there any case in which the algorithm doesn’t terminate? Theorem4 定理4Next we’ll prove Lemma6 of the 5th Level of Nine-Yang-Divine-Skill in the following pipeline. $\\underline{\\textbf{Theorem4}}$If $\\mathcal{C}:A\\longrightarrow\\mathbb{Q}$ and $f:A\\longrightarrow\\mathbb{Q}$, then the algorithm terminates. $\\textbf{proof:}$For any $a_i\\in A$, let $\\mathcal{C}(a_i)=\\frac{x_i}{y_i}$ and $f(a_i)=\\frac{z_i}{w_i}$,where $x_i,y_i,z_i,w_i\\in\\mathbb{N}$ and $(x_i,y_i)=1,~(z_i,w_i)=1$.Let $M=\\prod\\limits_{i:a_i\\in A}y_iw_i$. Let $\\mathcal{C}’=M\\cdot\\mathcal{C}$ and $f’=M\\cdot f$.It’s easy to see $\\mathcal{C}’,f’$ are natural numbers.Applying Theorem5 to $\\mathcal{C}’,f’$ we’ve done.$\\square$ Theorem5 定理5$\\underline{\\textbf{Theorem5}}$If $\\mathcal{C}:A\\longrightarrow\\mathbb{N}$ and $f:A\\longrightarrow\\mathbb{N}$, then the algorithm terminates. $\\textbf{proof:}$Suppose to the contrary that the algorithm doesn’t terminate.Let $\\lbrace f_i\\rbrace_{i=0}^\\infty$ be the progression of flows generated by the algorithm.On one hand, since $\\mathcal{C},f$ is constrained from $\\mathbb{R}$ to $\\mathbb{N}$,then $\\vert f_i\\vert+1\\leq\\vert f_{i+1}\\vert,\\text{ }\\forall\\text{ }i\\in\\mathbb{N}$,which leads to $\\lim\\limits_{i\\to\\infty}\\vert f_i\\vert=\\infty$,meaning that the progression is unbounded.On the other hand, by Lemma1 and Lemma2 of the 5th Level of Nine-Yang-Divine-Skill, $\\vert f_i\\vert\\leq\\mathcal{C}(t_*),\\text{ }\\forall\\text{ }i\\in\\mathbb{N}$,meaning that the progression is upper-bounded by the capacity of the minimal cut, which is a contradiction.$\\square$ Lemma6 引理6This lemma asserts that an $s,t$ path ought to meet any cut of the network. $\\underline{\\textbf{Lemma6}}$Let $(S,\\bar S)$ be any cut, and $P$ be any $s,t$ path, of $G$. Then $A(P)\\cap(S,\\bar S)\\neq\\varnothing$. $\\textbf{proof:}$Let $P=v_0v_1\\cdots v_l$ with $v_0=s$ and $v_l=t$.Noting that $s\\in S$ and $t\\in\\bar S$,there exists a minimal index $i\\in\\lbrace1,2,\\cdots,l\\rbrace$ satisfying $v_i\\in\\bar S$,hence $(v_{i-1},v_i)\\in(S,\\bar S)$.$\\square$ Path Flow Decomposition 路径流量分解We’nna prove the theorem of the 4th Level of Nine-Yang-Divine-Skill in the following pipeline. Path Flow 路径流量$P$ is an $s,t$ path of $G$.$f$ is a flow of $G$.Then $f$ is called a path-flow of $G$,if $f(a)=C,\\text{ }\\forall\\text{ }a\\in A(P)$ for some constant $C\\in\\mathbb{R}$,and $f(a)=0,\\text{ }\\forall\\text{ }a\\in A\\setminus A(P)$. Let $f_P$ denote a flow satisfyingif $a\\in A(P)$, then $f_P(a)=1$;otherwise $f_P(a)=0$. Cycle Flow 环流$C$ is a cycle of $G$.$f$ is a flow of $G$.Then $f$ is called a cycle-flow of $G$,if $f(a)=T,\\text{ }\\forall\\text{ }a\\in A(C)$ for some constant $T\\in\\mathbb{R}$,and $f(a)=0,\\text{ }\\forall\\text{ }a\\in A\\setminus A(C)$. Theorem7 定理7Alias of Path Flow Decomposition Theorem. For capacity $\\mathcal{C}:A\\longrightarrow\\mathbb{R}$ and flow $f:A\\longrightarrow\\mathbb{R}$,we define an assignment operation from $f$ to $\\mathcal{C}$:$\\mathcal{C}\\leftarrow f$ as $\\forall\\text{ }(u,v)\\in A$,let $\\mathcal{C}(u,v)=\\mathcal{C}(v,u)=\\max\\lbrace f(u,v),f(v,u)\\rbrace$. We define a partial-order on flows:for $f,g\\in\\mathcal{F}(G)$, we say $f<g$,if $f(u,v)\\leq g(u,v),\\text{ }\\forall\\text{ }(u,v)\\in A$,and $\\exists\\text{ }(u,v)\\in A\\text{ s.t. }f(u,v)<g(u,v)$. We define an equivalent-relationship on flows:for $f,g\\in\\mathcal{F}(G)$, we say $f\\equiv g$,if $f,g$ differ by several cycle-flows. $\\underline{\\textbf{Theorem7}}$For any flow $f$ of $G$, there exists a progression $\\lbrace f_i\\rbrace_{i=1}^\\infty$ of path-flows of $G$s.t. $f=\\sum\\limits_{i=1}^\\infty f_i$. $\\textbf{proof:}$Let network $G’=(V,A,\\mathcal{C}’)$ with $\\mathcal{C}’\\longleftarrow f$,and obviously $f$ is a max-flow of $G’$.Let $f_0$ be the 0-flow of $G’$.Let $F_i=\\sum\\limits_{j=0}^if_j,\\text{ }\\forall\\text{ }i\\in\\mathbb{N}$.If there exists an augmenting-path $P_i$ of $G’$ with respect to $F_i$,which can be determined in polynomial time by some search method,let $f_{i+1}=\\delta\\cdot f_{P_i}$ with $\\delta=\\min\\limits_{a\\in A(P_i)}r(a)$;Otherwise let $f_{i+1}=f_{i+2}=\\cdots=0$,in which case obviously $f=F_i$ holds by Theorem0.It suffices to show $\\lim\\limits_{i\\to\\infty}F_i=f$,in the case that for every $F_i$ there exists $P_i$.Noting that $F_i<F_{i+1}<f,\\text{ }\\forall\\text{ }i\\in\\mathbb{N}$,then for every $(u,v)\\in A$ the progression $\\lbrace F_i(u,v)\\rbrace_{i=0}^\\infty$ converges.So let $\\lim\\limits_{i\\to\\infty}F_i=f’$ where $f’\\leq f$.Suppose to the contrary that $\\exists\\text{ }(u,v)\\in A$ satisfying $\\lim\\limits_{i\\to\\infty}F_i(u,v)=f’(u,v)<f(u,v)$.If there exists no augmenting-paths containing $(u,v)$ with respect to $f’$,then $(u,v)$ is contained by several cycle-flows of $f-f’$,thus by Lemma8 $f’$ can be expressed as $\\sum\\limits_{i=1}^\\infty g_i$;Otherwise $\\exists P$ containing $(u,v)$ w.r.t. $f’$,let $\\delta=\\min\\limits_{a\\in A(P)}(f-f’)(u,v)$ and $g=f’+\\delta*f_P$,violating that $f’$ is the summation of all the $f_P$ s.$\\square$ Lemma8 引理8$\\underline{\\textbf{Lemma8}}$For any $f,g\\in\\mathcal{F}(G)$ satisfying $f\\equiv g$,if $f=\\sum\\limits_{i=1}^\\infty f_i$ for some progression $\\lbrace f_i\\rbrace_{i=1}^\\infty$ of flows of $G$,then $g=\\sum\\limits_{i=1}^\\infty g_i$ for some progression $\\lbrace g_i\\rbrace_{i=1}^\\infty$ of flows of $G$. $\\textbf{proof:}$Noting that a cycle-flow is a flow,and $f,g$ differ by several cycle-flows.$\\square$ Summary 小结This post demonstrates Convergence Condition Theorem of algorithms based on augmenting-paths technique. Also it demonstrates Path Flow Decomposition Theorem. Reference 参考 Purple Qi of the Rich Mist, the 1st Level of Nine-Yang-Divine-Skill, for Network-Max-Flow, 网络最大流之九阳神功第一层「氤氲紫气」 Tendon Changing and Marrow Cleansing, the 2nd Level of Nine-Yang-Divine-Skill, for Network-Max-Flow, 网络最大流之九阳神功第二层「易筋洗髓」 Fiery Qi of the Ultimate Yang, the 3rd Level of Nine-Yang-Divine-Skill, for Network-Max-Flow, 网络最大流之九阳神功第三层「至阳热气」 Bone Shrinking Technique, the 4th Level of Nine-Yang-Divine-Skill, for Network-Max-Flow, 网络最大流之九阳神功第四层「缩骨大法」 Turtle Breathing Technique, the 5th Level of Nine-Yang-Divine-Skill, for Network-Max-Flow, 网络最大流之九阳神功第五层「龟息大法」 Gecko Roaming the Wall, the 6th Level of Nine-Yang-Divine-Skill, for Network-Max-Flow, 网络最大流之九阳神功第六层「壁虎游墙」 Immunity to All Poisons, the 7th Level of Nine-Yang-Divine-Skill, for Network-Max-Flow, 网络最大流之九阳神功第七层「诸毒不侵」 Indestructible Vajra Body, the 8th Level of Nine-Yang-Divine-Skill, for Network-Max-Flow, 网络最大流之九阳神功第八层「金刚不坏」 Rebound Attack, the 9th Level of Nine-Yang-Divine-Skill, for Network-Max-Flow, 网络最大流之九阳神功第九层「反弹攻击」 Stronger with Each Use, the 10th Level of Nine-Yang-Divine-Skill, for Network-Max-Flow, 网络最大流之九阳神功第十层「愈使愈强」","link":"/2024/03/01/%E7%BD%91%E7%BB%9C%E6%9C%80%E5%A4%A7%E6%B5%81%E4%B9%8B%E4%B9%9D%E9%98%B3%E7%A5%9E%E5%8A%9F%E7%AC%AC%E5%85%AD%E5%B1%82%E3%80%8C%E5%A3%81%E8%99%8E%E6%B8%B8%E5%A2%99%E3%80%8D/"},{"title":"Coloring Algorithm","text":"$G=(V,E)$ is a graph of order $n$ and size $m$.$\\sigma=[v_1,v_2,\\cdots,v_n]$ is any ordering of $V$.$N(v)$ is the neighbors of $v\\in V$.$d(v)$ is the degree of $v\\in V$.$\\Delta$ is the maximum degree of $G$.$\\delta$ is the minimum degree of $G$.$c:V\\longrightarrow\\lbrace1,2,\\cdots,n\\rbrace$ is a coloring of $G$. Naive Coloring Algorithm123456ALGORITHM NaiveColoring(G);BEGIN FOR vi IN sigma c(vi) := i; RETURN c;END This algorithm gives an $n$-coloring of $G$ in linear time,without considering the information of $E$. Greedy Coloring Algorithm12345678910111213141516ALGORITHM GreedyColoring(G);BEGIN c := 0; /// init FOR v IN sigma uc := {c(u): u in N(v)}; /// used colors stored in hashtable c(v) := FindMinAvailableColor(v, uc); /// color v with min available color RETURN c;ENDFUNCTION FindMinAvailableColor(v, uc);BEGIN FOR i IN [1,2,...,d(v)] IF i NOT IN uc RETURN i; RETURN d(v) + 1;END This algorithm gives a $(\\Delta+1)$-coloring of $G$.The time complexity is $O(m+n)$, becausefirstly each vertex is visited once;secondly each edge is visited at most twice;thirdly at most d(v) colors are checkedto obtain the min available color for each $v\\in V$. Welsh Powell AlgorithmLet $\\sigma=[v_1,v_2,\\cdots,v_n]$ such that $d(v_1)\\geq d(v_2)\\geq\\cdots\\geq d(v_n)$.The body of the algorithm is the same as Greedy Coloring Algorithm.The time complexity is $O(m+n\\log n)$ due to additionally sorting the vertices.Welsh Powell Algorithm gives a $k$-coloring of $G$,such that $k\\leq1+\\max\\limits_{i=1}^n\\min\\lbrace i-1,d(v_i)\\rbrace$,where $\\min\\lbrace i-1,d(v_i)\\rbrace$ means the max number of colored neighbors of $v_i$. Planar Graph Coloring AlgorithmLet $G=(V,E,F)$ be a normal plane (connected, simple) graphwith $n=\\vert V\\vert$ vertices, $m=\\vert E\\vert$ edges, $o=\\vert F\\vert$ faces.Foreseening the Four Color Theorem, we only consider triangulated $G$(including the infinite face on $\\mathbb{R}^2$, or every face on $\\mathbb{S}^2$).The minimum case we consider is $K_4$ with $n=4,m=6,o=4$,which implies $G$ is $3$-connected with $\\delta\\geq3$. $\\underline{\\textbf{THEOREM}}$ (Euler’s Formula)$n-m+o=2$ . Let $d_H(U)=\\sum\\limits_{v\\in U}d_H(v)$ be the total degree of set $U$ in graph $H$,where $H=G\\text{ or }G^*$ (often omitted when $H=G$).$\\underline{\\textbf{THEOREM}}$ (First Graph Theorem)$2m=d(V)=\\sum\\limits_{v\\in V}d(v)$ .$\\underline{\\textbf{THEOREM}}$ (Planar Dual Version)$2m=d_{G^*}(F)=\\sum\\limits_{f\\in F}d_{G^*}(f)$ $\\underline{\\textbf{PROPOSITION}}$ $3o\\leq2m$ . PROOF: $2m=\\sum\\limits_{f\\in F}d_{G^*}(f)\\geq\\sum\\limits_{f\\in F}3=3o\\ .\\ \\square$ $\\underline{\\textbf{PROPOSITION}}$ $m\\leq3n-6$ . PROOF: $3o=3(2+m-n)\\leq2m\\ . \\ \\square$ $\\underline{\\textbf{PROPOSITION}}$ $m\\geq\\frac{3}{2}n$ . PROOF: $2m=\\sum\\limits_{v\\in V}d(v)\\geq\\sum\\limits_{v\\in V}3=3n\\ . \\ \\square$ $\\underline{\\textbf{PROPOSITION}}$$\\begin{cases}\\frac{3}{2}n\\leq m\\leq3n-6 & \\bigstar \\\\\\frac{1}{2}(n+4)\\leq o\\leq2n-4 & \\star \\\\\\frac{1}{3}(m+6)\\leq n\\leq\\frac{2}{3}m & \\bigstar \\\\\\frac{1}{3}(m+6)\\leq o\\leq\\frac{2}{3}m & \\star \\\\\\frac{1}{2}(o+4)\\leq n\\leq2o-4 & \\star\\\\\\frac{3}{2}o\\leq m\\leq3o-6 & \\star\\end{cases}$ $\\underline{\\textbf{PROPOSITION}}$ (triangulated)$\\begin{cases}n=\\frac{1}{3}(m+6)=\\frac{1}{2}(o+4) \\\\m=3n-6=\\frac{3}{2}o \\\\o=2n-4=\\frac{2}{3}m\\end{cases}$ $O(n)$ is an asymptotic linear function of $n$ provided$\\lim\\limits_{n\\to\\infty}\\frac{O(n)}{n}=C$ for some constant $C\\in\\mathbb{R}^+$.$\\underline{\\textbf{PROPOSITION}}$$O(o)=O(n)=O(m)$ . Let $V_{i,j}$ be the set of vertices in $G$ of degree $i,i+1,\\cdots,j$for any $i\\leq j\\in\\mathbb{Z}^+$.Let $n_{i,j}=\\vert V_{i,j}\\vert$ be the number of elements in $V_{i,j}$.For convenience let $V_i=V_{i,i}$ and $n_i=n_{i,i}$.$\\underline{\\textbf{PROPOSITION}}$ $n_{3,6}>\\frac{n}{4}$ . PROOF:Suppose to the contrary $n_{3,6}\\leq\\frac{n}{4}$.Noting that $n=n_{3,6}+n_{7,\\infty}$,we have $n_{7,\\infty}\\geq\\frac{3}{4}n$.This implies $d(V)=d(V_{3,6})+d(V_{7,\\infty})$$\\ \\ \\ \\ \\geq3n_{3,6}+7n_{7,\\infty}$$\\ \\ \\ \\ =3(n-n_{7,\\infty})+7n_{7,\\infty}=3n+4n_{7,\\infty}$$\\ \\ \\ \\ \\geq3n+4\\cdot\\frac{3}{4}n=6n$,violating that $\\frac{1}{2}d(V)=m\\leq3n-6$.$\\square$ $\\underline{\\textbf{PROPOSITION}}$$n_{3,k}>\\frac{k-5}{k-2}n$ for any integer $k\\geq6$.$n_{k,\\Delta}\\leq\\frac{k-6}{k-3}n$ for any integer $k\\geq7$. PROOF:Suppose to the contrary $n_{3,k}\\leq\\lambda n$.Noting that $n=n_{3,k}+n_{k+1,\\infty}$,we have $n_{k+1,\\infty}\\geq(1-\\lambda)n$.This implies $d(V)=d(V_{3,k})+d(V_{k+1,\\infty})$$\\ \\ \\ \\ \\geq3n_{3,k}+(k+1)n_{k+1,\\infty}$$\\ \\ \\ \\ =3(n-n_{k+1,\\infty})+(k+1)n_{k+1,\\infty}$$\\ \\ \\ \\ =3n+(k-2)n_{k+1,\\infty}$$\\ \\ \\ \\ \\geq3n+(k-2)\\cdot(1-\\lambda)n$$\\ \\ \\ \\ =\\lbrace k+1-(k-2)\\lambda\\rbrace n$,violating that $\\frac{1}{2}d(V)=m\\leq3n-6$.This implies $k+1-(k-2)\\lambda=6$.$\\square$ A set $U\\subset V$ is independent providedany distinct $u,v\\in U$ is not adjacent.$\\underline{\\textbf{PROPOSITION}}$An independent set $U\\subset V_{3,6}$ with $\\vert U\\vert>\\lfloor\\frac{n}{28}\\rfloor$can be found in $O(n)$ time. PROOF:We pick each vertex $v$ from $V_{3,6}$ similarly to Greedy Coloring Algorithm.Since $d(v)\\leq6$, then $\\vert N(v)\\cap V_{3,6}\\vert\\leq6$.That’s to say, for each $v$ at most $6$ vertices are wasted,meaning that we can pick a vertex from $V_{3,6}$ every $7$ vertices.Since $n_{3,6}>\\frac{n}{4}$, we have $\\vert U\\vert>\\lfloor\\frac{n}{4}\\cdot\\frac{1}{7}\\rfloor$.$\\square$ $\\underline{\\textbf{COROLLARY}}$An independent set $U\\subset V_{3,9}$ with $\\vert U\\vert>\\lfloor\\frac{2n}{35}\\rfloor$can be found in $O(n)$ time, which is the best estimation to fraction of vertices. $\\underline{\\textbf{THEOREM}}$ (Heawood, Kempe, 1890)Every planar graph is $5$-colorable.Let $T_k(n)$ be the time complexity to $k$-color a planar graph of order $n$.$\\underline{\\textbf{PROPOSITION}}$$T_7(n)\\leq T_7(\\lambda n)+O(n)$ for some constant $0<\\lambda<\\frac{27}{28}$. PROOF:Firstly we find a set $U\\subset V_{3,6}$ with $\\vert U\\vert>\\lfloor\\frac{n}{28}\\rfloor$ in $O(n)$ time.Then we $7$-color the graph $G[V\\setminus U]$.At last we color each $v\\in U$ adjacent to at most $6$ colors.$\\square$ $\\underline{\\textbf{PROPOSITION}}$$T_7(n)=O(n)$ . PROOF: $T_7(n)\\leq T_7(1)+O(n\\frac{1-\\lambda^t}{1-\\lambda})\\ .\\ \\square$ $\\underline{\\textbf{THEOREM}}$ (Lipton, Miller, 1976)$T_5(n)=O(n)$ . PROOF:It suffices to prove $T_5(n)\\leq T_5(\\lambda n)+O(n)$ for some constant $0<\\lambda<\\frac{27}{28}$. Kempe’s Algorithm$\\underline{\\textbf{PROPOSITION}}$A planar graph contains a vertex of degree at most $5$. PROOF:The average degree satisfies $3\\leq\\frac{1}{n}\\sum\\limits_{v\\in V} d(v)=\\frac{2m}{n}\\leq6-\\frac{12}{n}<6$.For triangulated $G$ similarly we have $\\frac{2m}{n}=6-\\frac{12}{n}\\in[3,6)$.$\\square$ $\\underline{\\textbf{PROPOSITION}}$Removing a vertex from a planar graph remains a planar graph. 6 Coloring Algorithm123456789ALGORITHM SixColoring(G);BEGIN IF vertices=1 color G; RETURN; find v in V such that d(v)<=5; SixColoring(G-v); /// G-v is planar color v; /// 6 colors sufficeEND This algorithm gives a $6$-coloring of $G$ in $O(n^2+m)=O(n^2)$ time. To analyse complexity for recurrence functions.Let $T(n)$ be the time complexity for input graph of order $n$.The recurrence relation satisties the equation $T(n)=T(n-1)+O(n)$,if no extra technique is used to find a vertex with degree at most $5$.Solving the equation, we have $T(n)=O(n^2)$. 5 Coloring Algorithm (Square Time)1234567891011121314151617ALGORITHM FiveColoring(G);BEGIN IF vertices=1 color G; RETURN; find v in V such that d(v)<=5; FiveColoring(G-v); IF distinct colors of N(v) <= 4 color v; /// 5 colors suffice ELSE /// 5 distinct colors /* Kempe Chain Transformation */ let N(v)=[u1,u2,u3,u4,u5] clockwise around v; find a Kempe Chain, say from u1 to u3; find the induced component C containing u2 generated by colors c(u2),c(u4); c(v) := c(u2); swap colors of C;END This algorithm gives a $5$-coloring of $G$ in $O(n^2+nm)=O(n^2)$ time. Complexity Analysis$T(n)=$$\\ \\ O(1)+O(n)+T(n-1)+O(d_v)+O(m)=$$\\ \\ \\ \\ T(n-1)+O(n)$.So $T(n)=O(n^2)$. 5 Coloring Algorithm (Linear Time)This algorithm gives a $5$-coloring of $G$ in $O(n)$ time,improving the recursive implementation to an iterative one,by means of sophisticated designed data structures.$\\underline{\\textbf{PROPOSITION}}$$G$ contains no $K_5$ as its subgraph, since $K_5$ is not planar.$\\underline{\\textbf{PROPOSITION}}$There exist $2$ non-adjacent neighbors for any vertex in $G$ of degree $5$. 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115ALGORITHM LinearFiveColoring(G);BEGIN /* L[v],Q4,Q5 are doubly linked data structure */ init L[v] for each v in V; /// adjacency lists of G init Q4 := {}; /// queue maintains vertices of degree at most 4 init Q5 := {}; /// queue maintains vertices of degree 5 /* hashtable to indicate whether vertex v is in Q4,Q5 */ init P := {}; /// contains a pointer of an element v in Q4,Q5 /* vertex degree */ init D[v] for each v in V; /* order of the graph */ init N; /* s in S has 2 fields: */ /* (i) the removed vertex v */ /* (ii) either point to L[v] at the time v was removed */ /* or point to the vertex u with which v was merged */ init S := {}; /// stack maintains vertices removed from G /* help to maintain adjacency lists for merging vertices*/ init M[v]:={false} for each v in V; calculate Q4,Q5,P,D,N; Reduce; Color;END/* update Q4,Q5 when deleting w */FUNCTION CheckDelete(w);BEGIN IF D[w]=5 add w to Q5; ELIF D[w]=4 move w from Q5 to Q4;END/* update Q4,Q5 when adding a neighbor to w */FUNCTION CheckAdd(w);BEGIN IF D[w]=6 delete v from Q5; ELIF D[w]=5 move w from Q4 to Q5;ENDFUNCTION Delete(v);BEGIN FOR w in L[v] delete v from L[w]; D[w] := D[w] - 1; CheckDelete(w); S push (v, pointer to L[v]); queue Q4,Q5 delete vertex v by pointer P[v]; /// Q4,Q5 is doubly linked N := N - 1; /// number of verticesEND/* u's neighbors are merged to v's neighbors */FUNCTION Merge(u, v);BEGIN /* mark all neighbors of v */ FOR w in L[v] M[w] := true; /*deal with neighbors of u */ FOR w in L[u] delete u from L[w]; IF M[w] = false /* w is adjacent to u but not to v */ add w to L[v]; add v to L[w]; D[v] := D[v] + 1; CheckAdd(v); ELSE /* w is adjacent to both u and v */ D[w] := D[w] - 1; CheckDelete(w); /* reset all neighbors of v */ FOR w in L[v] M[w] := false; Q4,Q5 delete u by P[u]; S push (u, pointer to v); /// u pushed on S earlier than v N := N - 1;END /// FUNCTION Merge/* reduce the graph to at most 5 vertices */FUNCTION Reduce;BEGIN WHILE N > 5 IF Q4 not empty Delete(Q4.out); ELSE /// Q4 empty but Q5 not empty v := Q5.out; IF there exist x,y in L[v] such that D[x] < k and D[y] < k and x,y are non-adjacent Delete(v); Merge(x,y); ELSE Q5.in(v);END/* color all vertices in reverse order of S */FUNCTION Color;BEGIN color the remaining vertices; /// those on Q4 because N<=5 WHILE S not empty (u,p) := S.pop; IF p point to L[u] color u with color different from colors of L[u]; ELSE /// p point to some vertex v color u with color of v; /// v must be colored earlier than uEND To analyse the time complexity of LinearFiveColoring ALGORITHM.$\\underline{\\textbf{CLAIM1}}$For FUNCTION Reduce, every time the program executes to LINE92,Q4 maintains all vertices of degree less than $5$,and Q5 maintains all vertices of degree $5$,of the reduced graph at this time. PROOF: This is a loop invariant which can be proved by induction. $\\underline{\\textbf{CLAIM2}}$LinearFiveColoring ALGORITHM will color any planar graph with at most $5$ colors. PROOF:(i) On LINE106 of FUNCTION Color, $5$ colors suffice.(ii) On LINE109 of FUNCTION Color, $v$ is deleted at some time satisfying D[v]<=4.Noting that only these at most $4$ neighbors are colored earlier than $v$, So $v$ can be colored with at most $5$ colors.(iii) On LINE109 of FUNCTION Color, $v$ is deleted at some time,satisfying D[v]=5 and $v$ has non-adjacent neighbors $x,y$ of degreeless than $k$. Then on stack $S$, $v$ is pushed firstly with $5$ neighbors, $x$ is pushed secondly when merging to $y$, and $y$ is pushed thirdly.So $v$ can be colored with at most $5$ colors after $x,y$ are colored with the same color by induction.(iv) On LINE103 of FUNCTION Color, by induction $v$ can be colored with at most $5$ colors. A blocked vertex is a vertex returned to the end of queue Q5(FUNCTION Reduce LINE102).A stage is from a point when Q4 is empty to the point when Q4 is empty again.$\\underline{\\textbf{THEOREM}}$ (Willams, 1985)The number of blocked vertices is no more than $O(n)$. Wernicke 5 Coloring Algorithm (Linear Time)Wernicke Theorem leads to this linear time $5$-coloring algorithm,which doesn’t rely on complicated data structures.$\\underline{\\textbf{Theorem}}$ (Wernicke, 1904)A normal plane graph must contain a vertex, which either(i) has at most four neighbors, or(ii) has five neighbors, one of which has degree at most six. 123456789101112131415ALGORITHM WernickeFiveColoring(G);BEGIN IF G is trivial coloring G directly; RETURN; take a vertex x of G with degree at most 5; /// amortized linear time in total IF x has at most 4 neighbors H := G-x; ELSE let a,b,c,d,e be the 5 neighbors of x clockwise. take non-adjacent u,v from a,b,c,d,e; /// constant time let H be the graph of G-x merging u,v; /// constant time WernickeFiveColoring(H); coloring x;END To analyse the complexity, we have $T(n-2)+O(1)\\leq T(n)\\leq T(n-1)+O(1)$. 4 Coloring AlgorithmA graph is planar, providedit can be drawn in a plane such thatits edges intersect only at their ends.Such a drawing is called a planar embedding of the graph.Any such particular embedding is called a plane graph.A plane graph partitions the plane into a number ofarcwise-connected open sets which are called the faces.A face is incident to an edge if the edge is one of those which surrounds the face.A face is incident to a vertex if the vertex is an end of an edge the face is incident to.A planar graph is normal if it contains no bridges.A $k$-face is a face incident to exactly $k$ edges provided the graph is normal.$G^*$ is the dual graph of $G$ provided $G$ is normal. $G$ is a plane graph.$v$ is a vertex of $G$ such that $d(v)=5$.Then $v$ has $5$ incident faces,and we denote the set of them by $\\mathcal{F}=\\lbrace F_1,F_2,F_3,F_4,F_5\\rbrace$.$v$ is a bad vertex, provided$4$ of $\\mathcal{F}$ are triangles,and the remaining one is a triangle or 4-face or 5-face,called TypeI, TypeII, TypeIII respectively. A wheel of size $k$, denoteby $W_k$,is a join graph $C_k\\lor K_1$.A join graph $G\\lor H$ of graph $G$ and $H$,is defined by $V(G\\lor H)=V(G)\\cup V(H)$,and $E(G\\lor H)=E(G)\\cup E(H)\\cup E’$,where $E’=\\lbrace (u,v):\\ \\forall\\ u\\in V(G),\\ \\forall\\ v\\in V(H)\\rbrace$.$C_k$ is a cycle of order $k$.$K_k$ is a complete graph of order $k$. $\\underline{\\textbf{LEMMA0}}$ $\\chi(W_5)=4$.$\\underline{\\textbf{LEMMA1}}$ $v$ is a bad vertex of TypeI.Then the induced subgraph $G[N[v]]$ admits a subgraph $W_5$,hence $\\chi(G[N[v]])=4$.$\\underline{\\textbf{LEMMA2}}$ $v$ is a bad vertex of TypeII or TypeIII,$u_1,u_2$ are the neighbors of $v$ in the $4$-face or $5$-face.Then $c(u_1)=c(u_2)$ provided $c$ is a $3$-coloring of $G$.Let graph $G’=G/\\lbrace u_1,u_2\\rbrace$.Then $G’$ is also $3$-colorable planar.$\\underline{\\textbf{LEMMA3}}$ $G$ contains(i) a vertex of degree at most 4or (ii) a bad vertex. PROOF:By discharging method.Initial charge $w$ for each $V(G)\\cup F(G)$:$w(v)=d_G(v)-6$ for $v\\in V(G)$,$w(f)=2d_{G^*}(f)-6$ for $f\\in F(G)$.By Euler’s Formula,$\\sum\\limits_{v\\in V(G)}w(v)+\\sum\\limits_{f\\in F(G)}w(f)=$$\\sum\\limits_{v\\in V(G)}d_G(v)-6n+2\\sum\\limits_{f\\in F(G)}d_{G^*}(f)-6o=$$2m-6n+4m-6o=6(m-n-o)=-12.$Dischanging rules:(R1) each $4$-face or $5$-face sends $1/2$ to each of its incident vertex of degree $5$.(R2) each $k$-face($k\\geq6$) sends $1$ to each of its incident vertex of degree $5$.Let $w’$ be the charge after one discharging.Supposing to the contrary that $G$ contains no (i) and (ii),we’ll show $w’(v)\\geq0\\ \\forall\\ v\\in V(G)$ and $w’(f)\\geq0\\ \\forall\\ f\\in F(G)$,violating that $\\sum\\limits_{v\\in V(G)}w’(v)+\\sum\\limits_{f\\in F(G)}w’(f)=$$\\sum\\limits_{v\\in V(G)}w(v)+\\sum\\limits_{f\\in F(G)}w(f)$.It’s easy to calculate$w’(f)\\geq\\begin{cases}w(f)=0, & \\text{if }d_{G^*}(f)=3; \\\\w(f)-4\\cdot1/2=2-2=0, & \\text{if }d_{G^*}(f)=4;\\\\w(f)-5\\cdot1/2=4-2.5>0, & \\text{if }d_{G^*}(f)=5;\\\\w(f)-k=2k-6-k=k-6\\geq0, & \\text{if }d_{G^*}(f)\\geq6.\\end{cases}$For $v\\in V(G)$, if $d_G(v)\\geq6$, then $w’(v)=w(v)\\geq0$.So we assume $d_G(v)=5$.Noting that $w(v)=-1$,if $v$ is incident to a $k$-face($k\\geq6$),then $w’(v)\\geq-1+1=0$.So we assume $v$ is only incident to $3,4,5$-faces.Since $G$ contains no bad vertices,$v$ is incident to at least $2$ of $4,5$-faces,also leading to $w’(v)\\geq-1+2\\cdot1/2=0$.$\\square$ Note:$\\delta=5$ 的平面图,必然包含一个点是TypeI,TypeII,TypeIII之一,其他配置可有可无。放电法如何描述其他配置? $\\underline{\\textbf{LEMMA4}}$ $c$ is a $4$-coloring of $G$.$x_1,x_2,x_3,x_4$ are $4$ vertices of a $k$-face($k\\geq4$) of $G$.Then there exists a $4$-coloring $c’$ such that $\\vert c’(x_1,x_2,x_3,x_4)\\vert\\leq3$.Moreover, we can obtain $c’$ from $c$ in linear time. PROOF:This can be done by Kempe Chain Transformation.$\\square$ 3 Colorable AlgorithmSuppose $G$ is a $3$-colorable planar graph.The following algorithm gives a $4$-coloring of $G$. 1234567891011121314151617181920ALGORITHM ThreeColorable(G);BEGIN IF vertices<=3 color G; /// 3 colors suffice RETURN; ELIF there exists v in V such that d(v)<=4 ThreeColorable(G-v); /// G-v is 3-colorable planar IF d(v)<=3 color v; /// 4 colors suffice ELSE /// d(v)=4 color v possibly by Kempe Chain Transformation; /// 4 colors suffice RETURN; /* vertices>=4 and there exists a bad vertex */ find a bad vertex v with u1,u2 as in LEMMA2; /// this can be done in linear time /* v must be TypeII or TypeIII */ /* otherwise v is TypeI, violating G is 3-colorable */ merge u1,u2 to obtain graph G'; /// G' is 3-colorable planar ThreeColorable(G'); color G by G';END The time complexity is $O(n^2+nm)=O(n^2)$. Complexity Analysis$T(n)=T(n-1)+O(n)$ Note:通过递归子问题给出 $\\sigma$,子问题的染色结果可能需要kempe链变换;合并两点的条件:合并两点相当于这两点染相同颜色(要求这两点不相邻),合并之后的图仍然是平面图(要求这两点位于同一个face),可染色数也不能改变,这两个点是否必须距离为2? 3 Colorable Decision AlgorithmSuppose $G$ is a planar graph.The following algorithm gives a $4$-coloring of $G$if $G$ is $3$-colorable, otherwise outputs $\\chi(G)=4$. 1234567891011121314151617181920212223242526272829303132ALGORITHM ThreeColorableDecision(G);BEGIN find a partition of V=V1+V2+V3 such that vertices in V1 have degree at most 4, vertices in V2 are bad vertices of TypeII or TypeIII; /* vertices in V3 are the rest configurations including TypeI */ IF vertices<=4 or G is the icosahedron color G; /// 4 colors suffice RETURN; IF V1 not empty take a vertex v in V1, and let G'=G-v; ThreeColorableDecision(G'); /// G' is planar IF chi(G')=4 output chi(G)=4; RETURN; ELSE color v possibly by Kempe Chain Transformation; /// 4 colors suffice RETURN; ELIF V2 not empty take a bad vertex v in V2 with u1,u2; merge u1,u2 to obtain graph G'; ThreeColorableDecision(G'); /// G' is planar IF chi(G')=4 output chi(G)=4; RETURN; ELSE color G by G'; /// 4 colors suffice RETURN; ELSE output chi(G)=4; RETURN;END The time complexity is also $O(n^2)$. Bound on Chromatic Number$\\chi$ is the chromatic number of graph $G$.$\\omega$ is the order of a maximum clique of $G$. $\\underline{\\textbf{PROPOSITION}}$ $\\chi\\leq\\Delta+1\\leq n$.$\\underline{\\textbf{PROPOSITION}}$ $\\chi\\leq\\max\\limits_{i=1}^n\\min\\lbrace i-1,d(v_i)\\rbrace+1$. A list of vertices $[v_1,v_2,\\cdots,v_{n-k-1}]$is called a $k$-colorable list, providedfor any $i\\in\\lbrace0,1,\\cdots,n-k-1\\rbrace$,there exists $v\\in V(G_i)$ such that $d_{G_i}(v)<k$,where $G_i=G-v_1-v_2-\\cdots-v_i$. $\\underline{\\textbf{PROPOSITION}}$If $G$ admits a $k$-colorable list,then $G$ is $k$-colorable. Interval GraphLet $G=(V,E)$ be an interval graph.Any $I=[I\\text{.left}, I\\text{.right}]\\in V$ is a closed interval on real numbers.$(I,J)\\in E$ provided $I\\cap J\\neq\\emptyset$ for any distinct $I,J\\in V$. $\\underline{\\textbf{PROPOSITION}}$ $\\chi(G)=\\omega(G)$. PROOF:Since $\\chi\\geq\\omega$, it suffices to show $\\chi\\leq\\omega$.Let $\\sigma=[I_1,I_2,\\cdots,I_n]$ such that$I_1\\text{.left}\\leq I_2\\text{.left}\\leq\\cdots\\leq I_n\\text{.left}$.Let $c$ be a $k$-coloring of $G$ given by Greedy Coloring Algorithm.Suppose $I_i$ is the current coloring vertex, and $c(I_i)=k$.Then there exists $S\\in\\binom{N(I_i)}{k-1}$ such that $c(S)=\\lbrace1,2,\\cdots,k-1\\rbrace$,meaning that $I_i\\text{.left}\\in\\bigcap\\limits_{I_j\\in S}I_j$.So $S\\cup\\lbrace I_i\\rbrace$ forms a $k$-clique.By definition of maximum clique $\\omega\\geq k$,and by definition of chromatic number $\\chi\\leq k$,we have $\\omega\\geq\\chi$.$\\square$ Planar GraphLet $G=(V,E)$ be a planar graph. $\\underline{\\textbf{THEOREM}}$ (Appel, Haken, 1976)Every planar graph is $4$-colorable.$\\underline{\\textbf{COROLLARY}}$ $\\chi(G)\\leq4$. $\\underline{\\textbf{LEMMA}}$Connecting a new vertex to at least $k$ vertices of a $k$-connected graph remains a $k$-connected graph. PROOF: 【图论】连通度之fan引理 A minimal counterexample is a planar graph $G$ that is not $4$-colorable,such that every planar graph $G’$ with $\\vert V(G’)\\vert+\\vert E(G’)\\vert<\\vert V(G)\\vert+\\vert E(G)\\vert$ is $4$-colorable.$\\underline{\\textbf{PROPOSITION}}$Every minimal counterexample is $5$-critial, triangulated,of minimum degree at least $5$, $5$-connected,$6$-connected except for vertices of degree $5$. PROOF:Let $G$ be a minimal counterexample.(i) $5$-critialBy definition.(ii) triangulated (including the infinite face)Suppose to the contrary $G$ is not triangulated.Then $G$ contains a $k$-face $F$ ($k\\geq4$).It’s claimed that $F$ contains $2$ non-adjacent vertices $u,v$.(We take vertices $u,v$ of $F$, which are not connected inside $F$.If $u,v$ are not adjacent out of $F$, we’ve done.Otherwise $u,v$ seperate the boundary of $F$ into $2$ parts,from each of which we can take a vertex.)Merging $u,v$ we get a smaller graph $G’$.It’s claimed that $G’$ is not $4$-colorable.Supposing not so, then we can extend a $4$-coloring of $G’$ to $G’$,since we only need to restate $u,v$ of face $F$,violating that $G$ is not $4$-colorable.So $G’$ is a smaller counterexample,violating that $G$ is minimal.(iii) of minimum degree at least $5$Suppose to the contrary $G$ contains a vertex $v$ of degree less than $5$.It’s claimed that $G-v$ is not $4$-colorable.Supposing not so, we can extend a $4$-coloring of $G-v$ to $G$if colors of $N(v)$ are less than $4$, otherwise by means of Kempe Chain Transformation,violating that $G$ is not $4$-colorable.So $G-v$ is a smaller counterexample, violating that $G$ is minimum.(iv) $5$-connectedSuppose to the contrary that $G$ is not $5$-connected.Then there exists a set $U$ of $4$ vertices of $G$ such that $G-U$ is disconnected.Then $G$ has a minimum vertex separator $S$ with $\\vert S\\vert\\leq4$.Case I: $\\vert S\\vert=1$ with $S=\\lbrace a\\rbrace$.This is impossible because $N(a)$ forms a cycle around $a$.Case II: $\\vert S\\vert=2$ with $S=\\lbrace a,b\\rbrace$.If $a,b$ are connected, this is impossible because $N(a)\\cup N(b)$ forms a cycle around $a,b$.Otherwise $a,b$ are not connected, this is impossible because $G-S=G-a-b$ is still connected.Case III: $\\vert S\\vert=3$ with $S=\\lbrace a,b,c\\rbrace$.If $G[S]$ is not connected, then $G-S=G-a-b-c$ is connected.Otherwise $G[S]$ is connected, then $G[S]$ is a path or cycle.If $G[S]$ is a path, then $N(a)\\cup N(b)\\cup N(c)$ forms a cycle around $a,b,c$.If $G[S]$ is a cycle, then $G-S=H_1\\oplus H_2$,where $H_1$ is the component inside this cycleand $H_2$ is the component outside this cycle,noting that any component inside or outside this cyclemust connect to all of $a,b,c$,because $\\kappa(G)=3$ by Menger’s Theorem,which will partition the inside or outside into at least $3$ sections.Let the induced graph $G_i=G[V(H_i)\\cup S]$ for $i=1,2$.Noting that $G$ is $4$-critical, then $G_i$ is $4$-colorable.Let $c_i$ be a $4$-coloring of $G_i$.Since $S$ is compelete, $a,b,c$ have distinct colors for $c_i$.So we can permutate $c_1$ on $V(G_1)$ to make sure$c_1(v)=c_2(v)$ for each $v\\in S$,thus obtaining a $4$-coloring of $G$,which is a contradiction.Case IV: $\\vert S\\vert=4$ with $S=\\lbrace a,b,c,d\\rbrace$.If $G[S]$ is not connected, we’ll go to Case I,II,III.Otherwise if $G[S]$ contains no cycle, then $N(a)\\cup N(b)\\cup N(c)\\cup N(d)$ forms a cycle around $a,b,c,d$.If $G[S]$ is connected and $G[S]$ contains a $3$-cycle $C_3$,then $G-S$ contains no components inside $C_3$,otherwise the connectivity of this component is upperbounded by $3$,violating that $\\kappa(G)=4$ by Menger’s Theorem.So we only consider the situation $C_4$ is a subgraph of $G[S]$,and $G-S$ has one component inside $C_4$ and one outside $C_4$.If $G[S]$ contains an edge inside $C_4$,then it would partition the inside into $2$ sections,leading to the inside component inside a $C_3$,which is impossible by $\\kappa(G)=4$.So we may assume $G[S]=C_4$ with no extra edges.Since the inside or outside component partitions the inside or outside into at least $4$ sections,we have exactly one component inside/outside $C_4$.Let $G-S=H_1\\oplus H_2$,where $H_1$ is the inside componentand $H_2$ is the outside component.Let $G_i=G[V(H_i)\\cup S]$.Noting $G$ is $5$-critical, let $c_i$ be a $4$-coloring of $G_i$.There is a gap to directly prove $G$ is $4$-colorable.In conclusion, the minimum counterexample of the Four Color Theorem is $4$-connected.Let $\\mathcal{G}$ be the set of all minimum counterexample of the Four Color Theorem.Supposing $\\mathcal{G}\\neq\\emptyset$, if any $G\\in\\mathcal{G}$ is constructed from a $5$-connected planar graph by adding a new vertex to at least $5$ existed vertices,then $G$ is $5$-connected.While in Turner’s article in $2012$, $5$-connected or internally $6$-connected is refered as there are no vertices of degree at most $4$. Complexity of Problems$\\underline{\\textbf{CLAIM}}$It’s trivial to $k$-color a planar graph in linear time(if possible) for $k\\in\\mathbb{Z}^+\\setminus\\lbrace3,4,5\\rbrace$. $\\underline{\\textbf{CLAIM}}$It’s NP-hard to $3$-color a planar graph(if possible), even if restricted to $\\Delta=4$. $\\underline{\\textbf{CLAIM}}$It’s NP-Complete to find the chromaticnumber of a graph. $\\underline{\\textbf{CLAIM}}$It’s NP-Complete to decide whethera planar graph is $4$-colorable. Reference尽量看1990年之后的论文,较早的论文由于排版问题出现各种打印错误,术语使用与现在出入大,引用检查的人少,读起来吃力。以下列出值得精读的文章书籍: Robertson, The Four Color Theorem, 1997 Wilson, Four Colors Suffice, 2002","link":"/2024/04/17/Coloring-Algorithm/"},{"title":"FCT Proof of Robertson et al. in 1997","text":"The Four Color Theorem (abbreviated as FCT)has a long and notorious history.So far its computer-based proof is not widely accepted,or rather, a considerable part of mathematicians are not satisfied with this,because it fails to be a hen that lays eggs like the proof of Fermat’s theorem.This post tries to read the paper of Robertson intensively. Basic knowledge on graph theory and FCT is assumed.We’ll document concepts and theorems in the following pipeline. Contracting Four ColorableProposition7 gives a proper $3$-edge-coloring of a (near-)triangulationby contracting the edges of a non-empty, non-spanning, and sparse edge set. Concept1 Non SpanningA set of edges of a graph thatforms a forest subgraph of the graph,is non-spanning if it contains no circuitof the graph by adding to the setan arbitrary edge of the graph,otherwise is a spanning tree.A circuit is a closed walk,which has no repeated edges.A cycle is a closed path,which has no repeated edges and vertices.A cycle of length $k$ is denoted by $C_k$. Concept2 Sparse Edge SetA set of edges of a (near-)triangulationis sparse, provided it takes at most one edgefrom each triangle of the graph.In the case of near-triangulation,the infinite region is incident with no edge of the set. The complement of a sparse set is dense. Concept3 Tri Coloring ModuloLet $G$ be a (near-)triangulation.Let $X\\subset E(G)$ be sparse (may be $\\varnothing$).Let $\\overline X:=E(G)-X$ be the dense complement.Let $\\kappa:\\overline X\\longrightarrow\\lbrace-1,0,1\\rbrace$ be a $3$-edge-coloring of $T$restricted to $\\overline X$ (may be improper).Then $\\kappa$ is a tri-coloring of $G$ modulo $X$, providedfor any triangle of $G$ (with edges denoted by $e,f,g$),(i) if $\\lbrace e,f,g\\rbrace\\subset\\overline X$,$\\ \\ \\ \\ $then $\\lbrace\\kappa(e),\\kappa(f),\\kappa(g)\\rbrace=\\lbrace-1,0,1\\rbrace$. (proper colored triangle)(ii) otherwise say $\\lbrace e,f\\rbrace\\subset\\overline X$,$\\ \\ \\ \\ \\ \\ $then $\\kappa(e)=\\kappa(f)$. (improper colored triangle) Note that a tri-coloring of $G$ modulo $\\varnothing$ is a proper $3$-edge-coloring of $G$,which is called a tri-coloring for short. Concept4 Quotient Graph ModuloLet $H$ be a subgraph of graph $G$.Let $H_1,H_2,\\cdots,H_k$ be all the components of $H$.Then graph $Q$ is the quotient graph of $G$ modulo $H$, provided$Q$ is obtained from $G$ by merging/contracting each component of $H$ to a single vertexand preserving all other vertices and edges,which is denoted by $Q:=G/H:=G/H_1/H_2/\\cdots/H_k$. Note that quotient graphs preserve planarity. Concept5 Quotient Coloring ExtensionLet $H$ be a subgraph of graph $G$.Let $H_1,H_2,\\cdots,H_k$ be all the components of $H$.Let $Q$ be the quotient graph of $G$ modulo $H$,particularly letting $V(Q):=\\lbrace H_1,H_2,\\cdots,H_k\\rbrace$ and$E(Q):=\\lbrace (H_i,H_j):$$\\ \\ \\ \\ \\ \\ \\ \\ v_i\\in V(H_i),\\ v_j\\in V(H_j),\\ (v_i,v_j)\\in E(G)\\setminus E(H)\\rbrace$.Supposing that $Q$ is loopless,let $\\phi:V(Q)\\longrightarrow\\mathbb{Z}$ be a proper vertex-coloring of $Q$.Then $\\phi:V(G)\\longrightarrow\\mathbb{Z}$ is a quotient coloring extension from $Q$ to $G$,provided $\\phi(v):=\\phi(H_i)$ for any $v\\in V(H_i)$. Note that the quotient coloring extension is improper if $E(H)\\neq\\varnothing$. Concept6 Tait Coloring TransformationLet $\\phi:V(G)\\longrightarrow\\mathbb{Z}_2\\times\\mathbb{Z}_2$ be a $4$-vertex-coloring of graph $G$.Then $\\phi:E(G)\\longrightarrow\\mathbb{Z}_2\\times\\mathbb{Z}_2$,defined by $\\phi(e):=\\phi(u)+\\phi(v)$ for any $e=(u,v)\\in E(G)$,is a $4$-edge-coloring of $G$,which is a Tait coloring transformation of $\\phi$ from vertices to edges. Noting that $\\phi(e)=(0,0)$ iff $\\phi(u)=\\phi(v)$,then proper $\\phi$ on vertices implies a $3$-edge-coloring on edges. Proposition7 NonSpanning Sparse TriColoringLet $T$ be a minimal counterexample of FCT.Let $X\\subset E(T)$ be non-empty, non-spanning, and sparse.Then $T$ admits a tri-coloring modulo $X$. PROOF:Firstly, we construct the quotient graph $S:=T/H$,where the subgraph $H:=(V(T), X)$,noting that $T$ must be a triangulation.Then we have(i) $S$ is loopless(allow vertex coloring), because $X$ is non-spanning;(ii) $S$ is a smaller(because non-empty) planar graph than $T$;Therefore $S$ admits a proper $4$-vertex-coloring $\\phi$,which implies a quotient coloring extension from $S$ to $T$.Secondly, by Tait coloring transformation of $\\phi$ from $V(T)$ to $E(T)$,we obtain a $4$-edge-coloring of $T$.To get rid of value $(0,0)$ of $\\phi$ on edges,we restrict $\\phi$ from $E(T)$ to $\\overline X:=E(T)-X$, obtaining $\\kappa:=\\phi\\vert_{\\overline X}$.As can be verified, $\\kappa$ is a tri-coloring modulo $X$.At last, let $\\lbrace(0,1),(1,1),(1,0)\\rbrace\\longleftrightarrow\\lbrace-1,0,1\\rbrace$,to make the binary colors the same as colors in the computer program.$\\square$ Consistent Edge ColoringConcept8 Signed MatchingLet $R$ be a circuit of a (near-)triangulation.A match in $R$ is a set of $2$ distinct edges of $R$.A signed match in $R$ is a pair $(\\lbrace e,f\\rbrace,\\mu)$,where $\\lbrace e,f\\rbrace$ is a match and $\\mu=\\pm1$ is the sign.A signed matching $M$ in $R$ is a set of signed matches,so that for any distinct $(\\lbrace e,f\\rbrace,\\mu),(\\lbrace e’,f’\\rbrace,\\mu’)\\in M$it holds that(i) $\\lbrace e,f\\rbrace\\cap\\lbrace e’,f’\\rbrace=\\varnothing$;(ii) $e,f$ belong to the same component in the subgraph $R-\\lbrace e’,f’\\rbrace$. Noting that omitting the signs, $M$ contains no duplicated edges of $R$.Let $E(M)$ be the set of all edges contained in $M$, i.e.$E(M):=\\lbrace e\\in m:\\ (m,\\mu)\\in M\\rbrace$. Concept9 Theta FitLet $R$ be a circuit of a (near-)triangulation.Let $M$ be a signed matching in $R$.Let $\\kappa$ be an edge-coloring of $R$ (may be improper).For any $\\theta\\in\\lbrace-1,0,1\\rbrace$, let$E(\\theta;\\kappa,R):=\\lbrace e\\in E(R):\\ \\kappa(e)=\\theta\\rbrace$,$E(\\overline\\theta;\\kappa,R):=\\lbrace e\\in E(R):\\ \\kappa(e)\\neq\\theta\\rbrace$.$\\kappa$ $\\theta$-fits $M$, if(i) $E(M)=E(\\overline\\theta;\\kappa,R)$;(ii) $\\kappa(e)=\\kappa(f)$ iff $\\mu=1$ for each $(\\lbrace e,f\\rbrace,\\mu)\\in M$. Note that given one $\\kappa$ we have $3$ signed matchings,denoted by $M(\\overline\\theta;\\kappa,R)$ for each $\\theta\\in\\lbrace-1,0,1\\rbrace$,which is consisted of edges $E(\\overline\\theta;\\kappa,R)$. Concept10 ConsistentLet $R$ be a circuit of a (near-)triangulation.A set $\\mathscr{C}$ of edge-colorings of $R$ is consistent, if(i) for any $\\kappa\\in\\mathscr{C}$, any $\\theta\\in\\lbrace-1,0,1\\rbrace$,there exists a signed matching $M$ such that $\\kappa$ $\\theta$-fits $M$;(ii) For $\\theta$ and $M$ in (i), $\\mathscr{C}$ contains every $\\kappa$ that $\\theta$-fits $M$. Note that $\\mathscr{C}\\neq\\varnothing$, becausewe can simply give a tri-coloring of $R$,and choose relatively adjacent edge pairs of $2$ colors,to form the edge set of $M$ then calculate the sign. For $M:=M(\\overline\\theta;\\kappa,R)$ in (i) we denote its orbit by $\\mathscr{C}_M$,which all fix the color of $E(\\theta;\\kappa,R)$ to $\\theta$.Then $\\mathscr{C}=\\bigsqcup\\limits_M\\mathscr{C}_M$, i.e.$\\mathscr{C}$ is partitioned into some orbitsunder the action of some signed matchings. Let $\\mathscr{C}’$ be another consistent set of edge-colorings of $R$.Then $\\mathscr{C}\\cup\\mathscr{C}’$ is consistent by definition.Let $\\mathscr{D}$ be any set of edge-colorings of $R$.Then $\\mathscr{D}$ has a unique maximal consistent subset $\\mathscr{C}$provided $\\varnothing$ is consistent. Concept11 LiftLet $G$ be a triangulation.Let $H$ be a near-triangulation of $G$ (may not be $2$-connected),with a closed walk $W:=v_0,f_1,v_1,\\cdots,f_k,v_k=v_0$tracing the boundary of the infinite region,where $v_0,v_1,\\cdots,v_k$ are vertices,and $f_1,\\cdots,f_k$ are edges.Let $\\kappa$ be a (proper) tri-coloring of $H$.Let $R$ be a circuit of $G$, with all edges $e_1,e_2,\\cdots,e_k$ in order.Define map $\\varphi$ by $\\varphi(e_i):=f_i$ for each $1\\leq i\\leq k$,which is called $\\varphi$ wraps $R$ around $H$.Define map $\\lambda$ by $\\lambda(e):=\\kappa(\\varphi(e))$ for each $e\\in E(R)$,which is an edge-coloring of $R$, called a lift of $\\kappa$ by $\\varphi$. Concept12 RibLet $H$ be a near-triangulation.Let $\\kappa$ be a tri-coloring of $H$.Let $\\theta\\in\\lbrace-1,0,1\\rbrace$.A $\\overline\\theta,\\kappa$-rib of $H$ is a sequence $B:=g_0,r_1,g_1,\\cdots,r_t,g_t$,such that(i) $g_0,g_1,\\cdots,g_t$ are distinct edges of $H$;(ii) $r_1,\\cdots,r_t$ are distinct finite regions of $H$;(iii) if $t=0$ then $g_0$ is a bridge of $H$;(iv) if $t>0$ then both of $g_0,g_t$ are incident with the infinite region of $H$;(v) $r_i$ is incident with $g_{i-1}$ and $g_i$ for each $1\\leq i\\leq t$;(vi) $\\kappa(g_i)\\neq\\theta$ ( or $g_i\\in E(\\overline\\theta;\\kappa,B)$ ) for each $0\\leq i\\leq t$. Note that a rib may not be a path omitting the regions. If $\\theta=0$ we can conclude that(vii) $\\kappa(g_0),\\kappa(g_1),\\cdots,\\kappa(g_t)$ are $\\pm1$ alternatively(because $\\kappa$ is proper and $\\kappa(g_i)\\in\\lbrace-1,1\\rbrace$);(viii) $\\kappa(e)=0$ for any edge $e$ that is incident with some $r_i$ of $B$(because triangle $r_i$ is also incident with $g_{i-1}$ and $g_i$);(ix) if $H$ admits a $\\overline0,\\kappa$-rib $B$,then it also admits $B$ as its $\\overline0,-\\kappa$-rib(simply reverse the signs of $\\kappa(g_0),\\kappa(g_1),\\cdots,\\kappa(g_t)$). $2$ ribs are disjoint provided they share neither edges nor regions. Proposition13 WrapAround Lift ConsistentLet $H$ be a near-triangulation.Let $\\varphi$ wrap circuit $R$ around $H$.Let $\\mathscr{C}$ be the set of all lifts by $\\varphi$ of (proper )tri-colorings of $H$.Then $\\mathscr{C}$ is consistent. PROOF:Let $\\lambda\\in\\mathscr{C}$ and $\\theta\\in\\lbrace-1,0,1\\rbrace$.W.L.O.G. assume $\\theta=0$(because we can permutate $-1,0,1$ on the edge-colorings).Since $\\lambda$ is a lift, there exists a tri-coloring $\\kappa$ of $H$such that $\\lambda=\\kappa\\circ\\varphi$.Let $W:=v_0,f_1,v_1,\\cdots,f_k,v_k=v_0$ be a closed walkthat traces the boundary of the infinite region of $H$.Let $e_0,e_1,\\cdots,e_k$ be all edges of $R$ in order.For the above $\\theta=0$ and $\\kappa$,we’ll construct each rib $B:=g_0,r_1,g_1,\\cdots,r_t,g_t$.Firstly, make sure any $2$ ribs are disjoint.Secondly, if $\\kappa(f_i)=\\theta=0$ then let $f_i$ belong to no ribotherwise let $f_i$ belong to a unique rib.Thirdly, for each $f_i,f_j$, initialize $g_0:=f_i$ and $g_t:=f_j$.Lastly, walk through $H$ to find alternative $\\kappa(g_0),\\kappa(g_1),\\cdots,\\kappa(g_t)$,if such valid $B$ exists, add $(\\lbrace e_i,e_j\\rbrace,\\mu)$ to the signed matching $M$,where $\\mu:=1$ if $\\kappa(f_i)=\\kappa(f_j)$ otherwise $\\mu:=-1$.For one possible partition of ribs,we obtain a signed matching $M$ that $\\lambda$ $\\theta$-fits,as can be verified, noting that we can set $\\lambda(e_i):=\\theta=0$ foredge $e_i\\in E(R)$ that’s not appear in $E(M)$,thus modifying $\\kappa(f_i):=\\theta=0$.Let $\\lambda’$ be any edge-coloring of $R$ that $\\theta$-fits the above $M:=M(\\theta;\\lambda,R)$.Define $\\kappa’’(f_i):=\\lambda’(e_i)$ for all $1\\leq i\\leq k$.This is well-defined (every point has exactly one image),because(i) for each $f_i$ in $W$, $\\kappa’’(f_i)$ has at least one image $\\lambda’(e_i)$;(ii) for $f_i=f_j$ in $W$, we have $\\lambda(e_i)=\\kappa(\\varphi(e_i))=\\kappa(f_i)=\\kappa(f_j)=\\lambda(e_j)$,and then we have $(\\lbrace e_i,e_j\\rbrace,1)\\in M$ which forces $\\lambda’(e_i)=\\lambda’(e_j)$,hence $\\kappa’’(f_i)=\\lambda’(e_i)=\\lambda’(e_j)=\\kappa’’(f_j)$ is the same image.Define a tri-coloring $\\kappa’$ of $H$ by reversing the signs of some $\\overline{\\theta},\\kappa$-ribs,so that $\\kappa’\\vert_{\\lbrace f_1,f_2,\\cdots,f_k\\rbrace}=\\kappa’’$.Then $\\lambda’$ is a lift of $\\kappa’$ by $\\varphi$, hence $\\lambda’\\in\\mathscr{C}$ as required.$\\square$ ConfigurationNote that the minimal counterexample of FCT (abbreviated as MCFCT)must be triangulated, of minimal degree $5$.A positive example of FCT (abbreviated as PEFCT) is a planar graph that is $4$-colorable. RingA (proper) $k$-ring of a triangulation is a cycle on $k$ edgeswith at least $1$ vertex in each of its interior and exterior. A $k$-ring is non-trivial, if there areat least $2$ vertices in each of its interior and exterior,otherwise is trivial. A $k$-ring is bending, if there areat least $4$ vertices in each of its interior and exterior,and there exists a vertex not on the ring, whichis adjacent to $3$ consecutive vertices of the ring. 4 RingWe consider all four-rings in context of triangulations, unless otherwise regulated. ConjugateAn improper $k$-ring contains $0$ vertex in its interior or exterior.An improper $k$-ring with no edge inside is denoted as $R_k^0$.An improper $k$-ring with exactly one edge inside is denoted as $R_k^1$. An improper $4$-ring of a triangulation must has $2$ vertices,the primary components, which are adjacent with an edge inside the ring,and the other $2$ vertices are guard components. Let $R$ be an improper $4$-ring, composed of vertices $a,b,c,d$.Let $a,c$ be the primary components, $b,d$ be the guard components.Then the triangulated ring $R-(a,c)+(b,d)$ is conjugate to $R$. A scheme $i,j,k,l$ of $R$ refers to the colors of $a,b,c,d$ respectively for some coloring of the graph. Logic ExpressionLet $T$ be a triangulation.Let $R$ be a four-ring (proper or not).Let $S$ be a scheme of $R$. If $S$ is proper, i.e.there exists a proper $4$-coloring $\\phi$ of $T$ such that $\\phi\\vert_{R}=S$,then we denote this by $S(R,T)$ or $S(R)$ or $S(T)$ or $S$,otherwise $\\overline{S}(R,T)$ or $\\overline{S}(R)$ or $\\overline{S(T)}$ or $\\overline S$(we can omit any context unless causing confusion).If $S$ can be properly extended to exterior,then we denote this by $S_x$, otherwise $\\overline{S_x}$.If $S$ can be properly extended to interior,then we denote this by $S_i$, otherwise $\\overline{S_i}$.Note that $S$ indicates that it can be properly extended to both exterior and interior,and $\\overline S$ indicates that it can be properly extended to neither exterior nor interior. If schemes $S_1,S_2,\\cdots,S_k$ covers all possibilities of $R$,then we denote this by $S_1\\lor S_2\\lor\\cdots\\lor S_k=1$ or $S_1\\lor S_2\\lor\\cdots\\lor S_k$, deriving OR expression. If proper scheme $A$ of $R$ implies either scheme $B$ of $R$ or scheme $C$ of $R$ is proper,then we denote this by $A\\longrightarrow B\\lor C$, deriving INFER expression. Naturally we have AND expression of two schemes, e.g. $S=S_x\\land S_i$.As OR expression defined above, we have $\\overline{S}=\\overline{S_x}\\lor\\overline{S_i}$. Birkhoff DeductionDefine four schemes of four-rings:$A=1,2,1,2$, $\\ \\ B=1,2,1,3$, $\\ \\ C=1,2,3,2$, $\\ \\ D=1,2,3,4$. For the following two propositions, we refer $A,B,C,D$ to $A(R_4^0),B(R_4^0),C(R_4^0),D(R_4^0)$ respectively.$\\underline{\\textbf{Proposition}}$Considering symmetry, it holds $A\\lor B\\lor C\\lor D$.$\\underline{\\textbf{Proposition}}$Considering symmetry, it holds that$\\begin{cases}A\\longrightarrow B\\lor C\\\\B\\longrightarrow A\\lor D\\\\C\\longrightarrow A\\lor D\\\\D\\longrightarrow B\\lor C.\\end{cases}$ Bernhart Theorem$\\underline{\\textbf{Theorem}}$ (Bernhart, 1948)Transforming an improper four-ring of a MCFCT into its conjugate ring will produce a PEFCT. PROOF:Let $T$ be a MCFCT containing ring $R_4^1$, with primary components $a,c$ and guard components $b,d$.Since $\\overline{A_i}(T)\\land\\overline{B_i}(T)$, we have $C_i(T)\\land D_i(T)$.Since $T$ is a MCFCT, we have $\\overline{C_x}(T)\\land\\overline{D_x}(T)$.Define graph $P:=T/(a,c)$, i.e. contracting edge $(a,c)$ of $T$ to one vertex.Since $T$ is a MCFCT, then $P$ is a PEFCT.If $C_x(P)\\lor D_x(P)$, then $C_x(T)\\lor D_x(T)$ (because $P,T$ have the same structure outside their rings),indicating that $C(T)\\lor D(T)$, which violates that $T$ is a MCFCT.Therefore $A_x(P)\\lor B_x(P)$.Now it’s ready to define graph $Q:=P+(b,d)$ containing ring $R_4^1$, with primary components $b,d$ and guard components $a,c$.If $B_x(P)$, then $B_x(Q)$ (since $P,Q$ have the same structure outside their rings),combining that $B_i(Q)$ we have $B(Q)$ as required.If $A_x(P)$, then $A_x(Q)$ but $\\overline{A_i}(Q)$.If there is no $2,3$-chain between $b,d$, then we can transform $A$ to $B$ as required.Otherwise we can transform $A$ to $C$, which is impossible because $\\overline{C_x}(P)$.$\\square$ 5 RingLet $R_5=abcde$ be a $5$-ring with regions $a,b,c,d,e$ connected clockwisely.Define $10$ schemes for $R_5$:$A=1,2,3,2,3,\\ \\ \\ \\ A^\\star=1,2,3,4,2$$B=3,1,2,3,2,\\ \\ \\ \\ B^\\star=2,1,2,3,4$$C=2,3,1,2,3,\\ \\ \\ \\ C^\\star=4,2,1,2,3$$D=3,2,3,1,2,\\ \\ \\ \\ D^\\star=3,4,2,1,2$$E=2,3,2,3,1,\\ \\ \\ \\ E^\\star=2,3,4,2,1$ Considering symmetry and four-colorability (CSFC)$\\underline{\\textbf{Proposition}}$CSFC, it holds that $A\\lor B\\lor C\\lor D\\lor E\\lor A^\\star\\lor B^\\star\\lor C^\\star\\lor D^\\star\\lor E^\\star$.$\\underline{\\textbf{Proposition}}$CSFC, it holds that$\\begin{cases}A\\longrightarrow E\\lor D^\\star\\\\A\\longrightarrow B\\lor C^\\star\\\\A^\\star\\longrightarrow D\\lor C^\\star\\\\A^\\star\\longrightarrow C\\lor D^\\star.\\end{cases}$By symmetry we have $20$ such relations in total. 5 ConnectedA triangulation is $5$-connected, providedit contains no $k$-ring for $k\\in\\lbrace2,3,4\\rbrace$. Note that this definition is equivalent to$5$-vertex-connected in Menger Theorem.$\\underline{\\textbf{Lemma}}$The minimal degree of a minimal counterexample of FCT is $5$.$\\underline{\\textbf{Proposition}}$A triangulation is $5$-connected iff it’s $5$-vertex-connected.(assuming that the triangulation contains at least $6$ vertices) PROOF:“$\\Longleftarrow$” Obviously.“$\\Longrightarrow$”Let $G$ be a triangulation with $\\vert V(G)\\vert\\geq6$.Suppose to the contrary $G$ is not $5$-vertex-connected.Let $S$ be a minimal vertex separator of $G$ with $k=\\vert S\\vert\\leq4$.Then the induced subgraph $G[S]$ must be connected,because if not so then $S$ would not be minimal.And $G[S]$ must contain a cycle, becauseif not so then $G-S$ is connected.And $G[S]$ must contain a $k$-ring, becauseif it only contains smaller rings,then $S$ would not be minimal.$\\square$ Internally 6 ConnectedA triangulation is internally $6$-connected, if(i) it’s $5$-connected;(ii) it contains no non-trivial $5$-ring. Nearly 7 ConnectedA triangulation is nearly $7$-connected, if(i) it’s internally $6$-connected;(ii) it contains no bending $6$-ring. CombinationIn this section, a plane graph allows multi-edges and cut-edges, but self-loops are not allowed.A plane graph is normal if each of its faces has degree at least three.Note that a cut-edge counts twice for the degree of its face. $\\underline{\\textbf{Theorem}}$ (Wernicke, 1904)Every normal plane graph must contain a vertex which is either(i) of degree at most four, or(ii) of degree five, but adjacent to at most four vertices, or(iii) of degree five, and adjacent to five vertices, one of which has degree at most six.$\\underline{\\textbf{Corollary}}$Every normal plane graph of minimum degree five has a vertex of degree fivewhich is adjacent to a vertex of degree five or six. Reduction$4$ types of reduction on original maps are introduced by Birkhoff. After a successive reductions, we obtain a reduced map,which is either a map of one region of the entire surface,or a regular map, so that(i) all vertices are of degree $3$;(ii) every region is topologically simply-connected (without holes);(iii) no $2$ or $3$ regions form a multiply-connected region (with holes);(iv) every region has degree at least $5$. $\\underline{\\textbf{Lemma}}$Every map has a region of degree at most $5$.$\\underline{\\textbf{Proposition}}$For a reduced map, it holds that$f_5=12+f_7+2f_8+3f_9+\\cdots$,where $f_k$ is the number of regions of degree $k$. PROOF:By Euler’s formula,numberOfRegions + numberOfVertices = numberOfEdges + 2,wherenumberOfRegions = $\\sum\\limits_{k=5}^\\infty f_k$,numberOfVertices = $\\frac{1}{3}\\cdot\\sum\\limits_{k=5}^\\infty kf_k$,numberOfEdges = $\\frac{1}{2}\\cdot\\sum\\limits_{k=5}^\\infty kf_k$.$\\square$ Type I: Non Adjacent Regions Around a VertexFor a vertex of degree at least $4$,we can merge $2$ non-adjacent regions at this vertexwith the same color, obtaining a smaller map. Type II: One Multiply Connected RegionFor a region topologically multiply-connected,it seperates the surface into several parts,each of which is a smaller map,and by permutating colors we can effect superpositionof colorings of every parts. Type III: Two or Three Joint Multiply Connected RegionSimilarly to one multiply-connected region,we can permutate the colors of the $2$ or $3$ regionsto make sure they are the same in the colors of every parts,since they are adjacent to each other. Type IV: Small Degree RegionDegree $1,2,3,4$ is regarded as small degree of a region.For a region of degree at most $3$,we can color it last with a forth color.For a region of degree $4$,there exists a pair of its neighbor regionssuch that they are non-adjacent.Merging these $3$ regions to form one region,we obtain a smaller map. Kempe ChainSupposing a map is colored with at least $2$ colors,a Kempe chain is a connected componentof an induced submap of $2$ colors. For a ring $R$ of $n$ regions,it sepetates the map $M$ into $2$ parts $M_1,M_2$.Considering $R+M_1$ colored with colors $a,b,c,d$,for $2$ regions of $R$, if they’re on the same $a,b$ Kempe chain,then connect them with an $a,b$ line.All these lines of different pairs of colors form a scheme on $R$.A scheme has $3$ properties:(i) No $2$ lines in complementary colors cross;(ii) If a line connects regions $\\alpha,\\beta$ and a same line connects regions $\\beta,\\gamma$, then a same line connects regions $\\alpha,\\gamma$.(iii) for regions $\\alpha,\\beta,\\gamma,\\delta$ in cyclical ordering on $R$, either $\\alpha,\\gamma$ are not connected by a line of any $2$ colors, or $\\beta,\\delta$ are not connected by a line of complementary colors.(For reduced maps, this is equivalent to say, either $\\alpha,\\gamma$ are connected by a line of any $2$ colors, or $\\beta,\\delta$ are connected by a line of complementary colors.)We can derive the formal principal(iv) a given scheme on $R$ gives rise to a new scheme,in which $2$ complementary sets of lines are unaltered,and the corresponding colors are permutated on $R$ in any wayso that all those connected by these lines are transposed together. ReducibleA ring $R$ of $n$ regions is reducible, iffor some $k$ any $2$ sets of scheme I and IIhave at least one coloring in common. $\\Phi(n):=k-n$ is the reducible number of $R$,where $k$ is the minimal number such that $R$ is reducible. Note that reducible means if the reduced map is $4$-colorablethen we can $4$-color the original map,hence we don’t have to consider maps with this reducible configuration. $\\underline{\\textbf{Proposition}}$A $n$-ring is reducible for $n\\leq3$. $\\underline{\\textbf{Theorem}}$A $4$-ring is reducible, and the reducible number is $0$. PROOF:Let the $4$-ring be $R$, its exterior region $M_1$, interior region $M_2$.Let $\\alpha_1,\\alpha_2,\\alpha_3,\\alpha_4$ be the regions on $R$ in cyclical ordering.Let $\\mathcal{M}_1,\\mathcal{M}_2$ be formed from $R+M_1,R+M_2$, respectively,by topologically shrinking $M_1,M_2$ to a point,with $\\alpha_1,\\alpha_3$ joined according to type I reduction.Then the colors of $\\alpha_1,\\alpha_2,\\alpha_3,\\alpha_4$ is either $a,b,a,b$ or $a,b,a,c$.Suppose we have $a,b,a,b$ for $M_2+R$ and $a,b,a,c$ for $M_1+R$.Note that $\\mathcal{M}_2$ can be any choice, so that we have a common coloring for $R$ in $M_2+R$ and $M_1+R$.Now we choose $\\mathcal{M}_2$ to be formed from $R+M_2$ by shrinking $M_2$ to a point with $\\alpha_2,\\alpha_4$ joined.So we have either $a,b,a,b$ or $a,b,c,b$ for $M_1+R$.By now we have $a,b,a,b$ for $M_2+R$, and$a,b,a,c$ or $a,b,c,b$ for $M_1+R$.Note that $a,b,a,b$ for $M_2+R$ implieseither we don’t have a $b,d$ line connecting $\\alpha_2,\\alpha_4$,meaning that we can have $a,b,a,d$ for $M_2+R$,which is equivalent to $a,b,a,c$ for $M_1+R$,or we don’t have a $a,c$ line connecting $\\alpha_1,\\alpha_3$,meaning that we can have $a,b,c,b$ for $M_2+R$.$\\square$ Since any map reduced by type I,II,III,IV reductions contains a region of degree $5$,after reductions of all $n$-rings ($n\\leq4$), such a region of degree $5$ is surrounded by $5$ regions.The surrounded $5$ regions must form a $5$-ring, because every vertex is of degree $3$. $\\underline{\\textbf{Theorem}}$A $5$-ring is reducible, and the reducible number is $1$. PROOF: By the following two lemmas. $\\square$ $\\underline{\\textbf{Corollary}}$The minimal counterexample of FCT is internally $6$-connected. (dual graphs of maps) $\\underline{\\textbf{Lemma}}$$\\Phi(5)\\leq1$, i.e. the reducible number of a $5$-ring is no more than $1$. PROOF:Let $R$ be the $5$-ring, $M_1$ its interior region, and $M_2$ exterior.Let $\\alpha_1,\\alpha_2,\\alpha_3,\\alpha_4,\\alpha_5$ be the regions of $R$ in cyclical ordering.Let $\\mathcal{M}_1,\\mathcal{M}_2$ be consisted of $R$ and a single contained region formed from $R+M_1,R+M_2$ respectively.Fixing the color of the single contained region, the colors of $R$ must be $a,b,a,b,c$ in cyclical ordering,in which the region colored $c$ is called the marked region.If the marked region is the same in $M_2+\\mathcal{M}_1$ and $M_1+\\mathcal{M}_2$,then we can permutate $a,b$ to obtain a joined coloring of $M_2+R+M_1$.If the marked regions are not adjacent, then we can make them adjacent by performing Kempe chain formal principal.Suppose we have $a,b,c,a,b$ and $c,a,b,a,b$ for $\\alpha_1,\\alpha_2,\\alpha_3,\\alpha_4,\\alpha_5$ in $M_2+\\mathcal{M}_1$ and $M_1+\\mathcal{M}_2$ respectively.Then either there is a $b,c$ line connecting $\\alpha_2,\\alpha_5$, or there is a $a,d$ line connecting $\\alpha_1,\\alpha_4$, in $M_2+R$ of $M_2+\\mathcal{M}_1$,from which we obtain $a,b,c,d,b$ and $a,c,b,a,b$ respectively.For the case $a,c,b,a,b$ we have adjacent marked regions.Now form a second map $\\mathcal{M}_2$ by shrinking $M_2$ to a point and joining $\\alpha_2,\\alpha_5$ so that $\\mathcal{M}_2$ consists of $4$ regions.Then we have $*,a,*,*,a$ in $M_1+R$ of $M_1+\\mathcal{M}_2$, where $*$ is different from $a$.We may let the last $2$ star be $b,c$, and the first star choose from $b,c,d$.Hence we have $b,a,b,c,a$ or $c,a,b,c,a$ or $d,a,b,c,a$ in $M_1+R$ of $M_1+\\mathcal{M}_2$.Note that $b,a,b,c,a$ has the marked region $\\alpha_4$, which is adjacent to the marked region $\\alpha_3$ in $M_2+\\mathcal{M}_1$.And $c,a,b,c,a$ has the same marked region $\\alpha_3$ as in $M_2+\\mathcal{M}_1$.We only need to consider the case $d,a,b,c,a$ in $M_1+R$ of $M_1+\\mathcal{M}_2$,which is equivalent to $a,b,c,d,b$ by permutating colors.This is just what we’ve already obtained when there is a $b,c$ line connecting $\\alpha_2,\\alpha_5$ in $M_2+R$ of $M_2+\\mathcal{M}_1$.In summarise, we can always guarantee the two partial schemes either have the same colors in $R$ or have adjacent marked regions in $R$, in any cases.It suffices to prove, if the marked regions in $M_2+\\mathcal{M}_1$ and $M_1+\\mathcal{M}_2$ are adjacent, then we can find $2$ schemes of $M_2+\\mathcal{M}_1$ and $M_1+\\mathcal{M}_2$ having a coloring for $R$ in common.W.L.O.G. we can take $c,a,b,a,b$ and $b,c,a,b,a$ for $\\alpha_1,\\alpha_2,\\alpha_3,\\alpha_4,\\alpha_5$ in $M_1+\\mathcal{M}_2$ and $M_2+\\mathcal{M}_1$ respectively.For $b,c,a,b,a$, if there doesn’t exist a $b,c$ line connecting $\\alpha_1,\\alpha_2,\\alpha_4$, then we have $c,b,a,b,a$ by performing Kempe chain formal principal for $\\alpha_1,\\alpha_2$, which is the same as $c,a,b,a,b$.Otherwise we have $b,c,d,b,a$ by performing Kempe chain formal principal for $\\alpha_3$.Now form $\\mathcal{M}_2$ by shrinking $M_2$ to a point, and joining $\\alpha_1,\\alpha_4$.Then similarly we have $b,c,d,b,a$ or $b,c,d,b,c$ or $b,c,d,b,d$ in $M_1+\\mathcal{M}_2$,of which the first one is a same scheme just appeared in $M_2+\\mathcal{M}_1$, and the third one is also equivalent to $b,c,a,b,a$.So we only need to consider $b,c,d,b,c$ in $M_1+\\mathcal{M}_2$.With a repetition of this kind of argument, we do always find common colorings in both schemes, covering all cases.$\\square$ $\\underline{\\textbf{Lemma}}$$\\Phi(5)\\neq0$, i.e. the reducible number of a $5$-ring cannot be 0.","link":"/2024/05/18/FCT-Proof-of-Robertson-et-al-in-1997/"}],"tags":[{"name":"Mac","slug":"Mac","link":"/tags/Mac/"},{"name":"homebrew","slug":"homebrew","link":"/tags/homebrew/"},{"name":"qita","slug":"qita","link":"/tags/qita/"},{"name":"CSDN","slug":"CSDN","link":"/tags/CSDN/"},{"name":"stackoverflow","slug":"stackoverflow","link":"/tags/stackoverflow/"},{"name":"coloring","slug":"coloring","link":"/tags/coloring/"},{"name":"vertex-coloring","slug":"vertex-coloring","link":"/tags/vertex-coloring/"},{"name":"chromatic-number","slug":"chromatic-number","link":"/tags/chromatic-number/"},{"name":"Brooks","slug":"Brooks","link":"/tags/Brooks/"},{"name":"CentOS","slug":"CentOS","link":"/tags/CentOS/"},{"name":"Linux","slug":"Linux","link":"/tags/Linux/"},{"name":"MacOS","slug":"MacOS","link":"/tags/MacOS/"},{"name":"Docker","slug":"Docker","link":"/tags/Docker/"},{"name":"FM","slug":"FM","link":"/tags/FM/"},{"name":"ML","slug":"ML","link":"/tags/ML/"},{"name":"DeepFM","slug":"DeepFM","link":"/tags/DeepFM/"},{"name":"Github","slug":"Github","link":"/tags/Github/"},{"name":"Tensorflow","slug":"Tensorflow","link":"/tags/Tensorflow/"},{"name":"Python","slug":"Python","link":"/tags/Python/"},{"name":"kaggle","slug":"kaggle","link":"/tags/kaggle/"},{"name":"Kruskal","slug":"Kruskal","link":"/tags/Kruskal/"},{"name":"algorithm","slug":"algorithm","link":"/tags/algorithm/"},{"name":"LeetCode","slug":"LeetCode","link":"/tags/LeetCode/"},{"name":"hive","slug":"hive","link":"/tags/hive/"},{"name":"sql","slug":"sql","link":"/tags/sql/"},{"name":"linux","slug":"linux","link":"/tags/linux/"},{"name":"feature","slug":"feature","link":"/tags/feature/"},{"name":"git","slug":"git","link":"/tags/git/"},{"name":"Hexo","slug":"Hexo","link":"/tags/Hexo/"},{"name":"Spark","slug":"Spark","link":"/tags/Spark/"},{"name":"SQL","slug":"SQL","link":"/tags/SQL/"},{"name":"召回","slug":"召回","link":"/tags/%E5%8F%AC%E5%9B%9E/"},{"name":"推荐系统","slug":"推荐系统","link":"/tags/%E6%8E%A8%E8%8D%90%E7%B3%BB%E7%BB%9F/"},{"name":"并查集","slug":"并查集","link":"/tags/%E5%B9%B6%E6%9F%A5%E9%9B%86/"},{"name":"洛谷","slug":"洛谷","link":"/tags/%E6%B4%9B%E8%B0%B7/"},{"name":"StackOverflow","slug":"StackOverflow","link":"/tags/StackOverflow/"},{"name":"macOS","slug":"macOS","link":"/tags/macOS/"},{"name":"model","slug":"model","link":"/tags/model/"},{"name":"encoding","slug":"encoding","link":"/tags/encoding/"},{"name":"tkinter","slug":"tkinter","link":"/tags/tkinter/"},{"name":"subset","slug":"subset","link":"/tags/subset/"},{"name":"space","slug":"space","link":"/tags/space/"},{"name":"ERP","slug":"ERP","link":"/tags/ERP/"},{"name":"三国","slug":"三国","link":"/tags/%E4%B8%89%E5%9B%BD/"},{"name":"九阳神功","slug":"九阳神功","link":"/tags/%E4%B9%9D%E9%98%B3%E7%A5%9E%E5%8A%9F/"},{"name":"Nine-Yang-Divine-Skill","slug":"Nine-Yang-Divine-Skill","link":"/tags/Nine-Yang-Divine-Skill/"},{"name":"网络最大流","slug":"网络最大流","link":"/tags/%E7%BD%91%E7%BB%9C%E6%9C%80%E5%A4%A7%E6%B5%81/"},{"name":"Network-Max-Flow","slug":"Network-Max-Flow","link":"/tags/Network-Max-Flow/"},{"name":"Four-Color-Theorem","slug":"Four-Color-Theorem","link":"/tags/Four-Color-Theorem/"},{"name":"edge-coloring","slug":"edge-coloring","link":"/tags/edge-coloring/"},{"name":"Tait","slug":"Tait","link":"/tags/Tait/"},{"name":"Kempe","slug":"Kempe","link":"/tags/Kempe/"},{"name":"Birkhoff","slug":"Birkhoff","link":"/tags/Birkhoff/"}],"categories":[{"name":"数学","slug":"数学","link":"/categories/%E6%95%B0%E5%AD%A6/"},{"name":"操作系统","slug":"操作系统","link":"/categories/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/"},{"name":"机器学习","slug":"机器学习","link":"/categories/%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0/"},{"name":"深度学习","slug":"深度学习","link":"/categories/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0/"},{"name":"图论","slug":"数学/图论","link":"/categories/%E6%95%B0%E5%AD%A6/%E5%9B%BE%E8%AE%BA/"},{"name":"数据结构&算法","slug":"数据结构-算法","link":"/categories/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84-%E7%AE%97%E6%B3%95/"},{"name":"工程项目","slug":"工程项目","link":"/categories/%E5%B7%A5%E7%A8%8B%E9%A1%B9%E7%9B%AE/"},{"name":"推荐系统","slug":"机器学习/推荐系统","link":"/categories/%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0/%E6%8E%A8%E8%8D%90%E7%B3%BB%E7%BB%9F/"},{"name":"debug","slug":"debug","link":"/categories/debug/"},{"name":"jupyter","slug":"jupyter","link":"/categories/jupyter/"}]}