正则表达式比较(Regex - BREs, EREs, PCRE)
常见的几个正则库的语法比较。 原链接: Regex cheatsheet
Regex cheatsheet
Many programs use regular expression to find & replace text. However, they tend to come with their own different flavor.
You can probably expect most modern software and programming languages to be using some variation of the Perl flavor, “PCRE”; however command-line tools (grep, less, …) will often use the POSIX flavor (sometimes with an extended variant, e.g. egrep
or sed -r
). ViM also comes with its own syntax (a superset of what Vi accepts).
This cheatsheet lists the respective syntax of each flavor, and the software that uses it.
Extended Regular Expression 有时可以通过命令行标志 -E
与 Unix 实用程序一起使用。其他 Unix 实用程序,如 awk
,默认使用 ERE。
ERE 与 BRE 的主要区别在于删除了一些反斜杠:\{...\}
变为 {...}
并且 \(...\)
变为 (...)
。
Homebrew
Homebrew 中的一些概念及配置国内镜像源方法。
安装 Homebrew
执行以下命令,脚本会提示选择国内几个比较常用的镜像,选择中科大镜像然后一路安装即可。
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
# Set Homebrew-bottles mirror
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles
IPv4/IPv6 网络
DNS
- DoH: DNS over Https
- DoT: DNS over TLS
公共 DNS 服务
DNS 服务器 | IPv4 | IPv6 | DoH | DoT |
---|---|---|---|---|
DNSPod Public DNS | 129.29.29.29 | 2402:4e00:: | https://doh.pub/dns-query | dot.pub |
阿里云 Public DNS | 223.5.5.5 | 2400:3200::1 | dns.alidns.com | dns.alidns.com |
Cloudflare DNS | 1.1.1.1 |
需要注意,DNS 能否够解析 IPv6 地址和 DNS 本身是否使用 IPv6 地址没有关系。即是说,只要 DNS 支持 IPv6 地址解析,那么访问 IPv4 的 DNS 也可以得到 IPv6 的地址。
Nginx
安装 Nginx
RHEL/CentOS
Install prerequisites
sudo yum install yum-utils
Set up the yum repository
vim /etc/yum.repos.d/nginx.repo
使用 Git LFS 存储二进制文件
Git LFS 简介
Git LFS 是由 Atlassian, GitHub 和其他开源贡献者开发的 Git 扩展,目的是减少大文件对 Git 仓库的影响,其以一种偷懒的方式下载相关版本的文件。具体来讲,就是只有在执行 checkout
命令时才会下载文件,而 clone
或 fetch
均不会下载文件。
Git LFS 通过将仓库中的大文件替换为一个 指针文件 来达到这一目的。
设置 Nodejs 环境
支持向量机(Support Vector Machine)
SVM 的决策边界(Decision Boundary)
其目标是找到一个线性函数 $\theta^Tx$,可以将样本集中的正类和负类分隔开,当 $\theta^Tx \ge 0$ 时表示正类,当 $\theta^Tx \lt 0$ 时表示负类,而 $\theta^Tx = 0$ 所代表的直线则是区分正负类的决策边界。
机器学习 - 相关概念的总结
概念解释
-
假设函数(Hypothesis Function): 用来拟合数据集,有线性函数和非线性函数。
-
正向传播(Forward Propagation): 用来计算假设函数的输出值 $h_\theta(x)$(即 $\hat{y}$)。
-
代价函数(Cost Function): 用来检验假设函数的输出值 $\hat{y}$ 与真实值 $y$ 之间的误差大小。
-
反向传播(Backpropagation): 用来计算代价函数 $J(\theta)$ 关于参数 $\theta$ 的偏导数 $\dfrac{\partial}{\partial \theta}J(\theta)$。
-
优化算法(Optimization Method): 使用参数 $\theta$ 最小化代价函数 $J(\theta)$。
机器学习 - 反向传播
反向传播(Backpropagation)
反向传播是通过计算假设函数与真实值之间的误差值($error = h_\theta(x^{(i)}) - y^{(i)}$),并反向传播这个误差值,最终用于计算参数 $\theta_{ij}$ 的偏导数。支撑这一理论的核心思想是多元复合函数的链式求导,下面通过一个简单的例子进行描述。
机器学习 - 各类函数的求导
线性函数 $z$ 对参数 $\theta_j$ 求导
线性函数 $z$:
\[z = \theta_0x_0 + \theta_1x_1 + \dots + \theta_jx_j\]其关于 $\theta_j$ 的导数:
\[\begin{aligned} \dfrac{\partial z}{\partial\theta_j} &= \dfrac{\partial}{\partial\theta_j}(\theta_0x_0) + \dfrac{\partial}{\partial\theta_j}(\theta_1x_1) + \dots + \dfrac{\partial}{\partial\theta_j}(\theta_jx_j) \\ &= 0 + 0 + \dots + x_j \\ &= x_j \end{aligned}\]机器学习 - 线性回归、逻辑回归与正则化
基本概念
假设函数 (Hypothesis Function): 根据输入的特征来预测输出结果。它是从输入变量到输出变量的函数,从输入特征空间到输出标签空间的映射,通常表示为 $h_\theta(x)$。在有监督学习中,这个函数通常是由训练数据中学习得到的,这就是为什么要叫 机器学习,所有训练出来的权重参数,都是用来逼进这个函数,我们希望通过这个学习出来的假设函数,可以从新的数据预测出想要的结果。
损失函数 (Loss Function):描述的是单个训练样本的预测值与真实值之间的误差。损失函数是关于单一训练样本的函数,它度量了一个样本的预测值与实际值的差异。例如,在回归任务中常用的损失函数是平方损失函数 $L(\theta)=(h_\theta(x)-y)^2$,其中是 $h_\theta(x)$ 预测值, $y$ 是真实值。
线性回归(Linear Regression)
假设函数(Hypothesis Function): 线性函数
\[h_\theta(x) = \theta_1x_1 + \theta_2x_2 + \cdots + \theta_nx_n + b = [\theta_1 \ \theta_2 \ \dots \ \theta_n] \begin{bmatrix} x_1 \\ x_2 \\ \vdots \\ x_n \end{bmatrix} + b = \theta^Tx+b \text{ (单个样本)}\] \[h_\theta(x) = \begin{bmatrix} h_\theta(x^{(1)}) \\ h_\theta(x^{(2)}) \\ \vdots \\ h_\theta(x^{(m)}) \end{bmatrix} = \begin{bmatrix} \theta_1x^{(1)}_1 + \theta_2x^{(1)}_2 + \dots + \theta_nx^{(1)}_n + b \\ \theta_1x^{(2)}_1 + \theta_2x^{(2)}_2 + \dots + \theta_nx^{(2)}_n + b \\ \vdots \\ \theta_1x^{(m)}_1 + \theta_2x^{(m)}_2 + \dots + \theta_nx^{(m)}_n + b \\ \end{bmatrix} = \begin{bmatrix} x^{(1)}_1 \ x^{(1)}_2 \ \dots \ x^{(1)}_n \\ x^{(2)}_1 \ x^{(2)}_2 \ \dots \ x^{(2)}_n \\ \vdots \\ x^{(m)}_1 \ x^{(m)}_2 \ \dots \ x^{(m)}_n \\ \end{bmatrix} \begin{bmatrix} \theta_1 \\ \theta_2 \\ \vdots \\ \theta_n \end{bmatrix} + \begin{bmatrix} b \\ b \\ \vdots \\ b \end{bmatrix} = X\theta + b \text{ (多个样本)}\]Docker
安装及升级 docker
RedHat/CentOS
安装仓库文件
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
安装 docker
sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin
升级 docker 版本
sudo yum update 'docker-ce*'
docker system
管理 docker 系统
# 检查 docker 占用的系统空间
docker system df
# 显示 docker 系统信息
docker system info
# 删除无用的容器,网络,镜像等
docker system prune
机器学习 - 梯度下降
梯度下降(gradient descent)
定义代价函数(define a cost function)
平方代价函数(quadratic cost function)或均方误差(mean squared error or MSE)
\[C(w, b) = \frac{1}{2n}\sum_x\| y(x) - \hat{y}(x) \|^2 \tag{1}\label{eq1}\]其中,$w$ 代表网络中的全部权重值,$b$ 代表全部偏差值,$n$ 代表训练样本的总数,$\hat{y}(x)$ 是输入训练样本 $x$ 时网络的输出值,当然,$\hat{y}$ 同时依赖于 $w,b和x$,$y(x)$ 是训练样本 $x$ 对应的实际值。我们可以从平方代价函数看出两个特点:
- $C(w,b)$ 是一个非负数,因为它的每一项都是非负的。
- 当 $C(w,b)$ 变得越小,例如 $C(w,b)\approx 0$ 时,则输出值 $\hat{y}$ 越接近实际值 $y$。
所以,我们训练算法的目的就是找到合适的权重值($w$)和偏差值($b$),使得代价函数 $C(w,b)$ 尽可能的小。
共计 103 篇文章,6 页。