Measure Zero


  • About

  • Quotes

  • Notes

  • Sitemap

  • Search

快速幂

2020-06-03 | ~ | Algorithms

要求 $a^n$, 其中 $a\in\mathbb R$, $n\in\mathbb Z$. 先不妨假设 $n\ge 0$, 基本想法是

\[a^n = \begin{cases} a^{n/2}a^{n/2}, & \text{if $n$ is even,}\\ a^{(n-1)/2}a^{(n-1)/2}a, & \text{if $n$ is odd.} \end{cases}\]

很容易写出时间复杂度 $O(\log n)$ 的递归算法, 而要写迭代算法需要再想一想.

Read more »

Python 杂录

2020-05-30 | ~ 2023-01-10 | Language

第二篇杂录 侧重最佳实践.

最近 (2021/10/28) 发现官方文档有 Programming FAQ — Python 3.10.0 documentation, 很有用.

Misc

  • python - What do * (single star) and / (slash) do as independent parameters? - Stack Overflow
  • performance - Python: Remove all duplicates from a large list of lists efficiently and elegantly - Stack Overflow 用 pandas 对大列表快速保序去重

一些语法糖

2023/1/10

(1,) + (2, 3)
# (1, 2, 3)

a = {1: 1}
b = {2: 2}
{**a, **b}
# {1: 1, 2: 2}

nonlocal

2022/7/5

忘了看哪个源码的时候读到的

Python の nonlocal と global の違い - Qiita

functools

lru_cache 以及 singledispatch

Read more »

日语杂录

2020-02-02 | ~ 2022-03-20 | Language

天王山

2022/3/20

意思是关键点

参考 「天王山」の意味と語源とは?分野別の使い方と例文・英語も紹介 | TRANS.Biz

Read more »

主定理的证明

2020-01-15 | ~ | Algorithms

算法分析的那个定理.

Master Theorem

\[T(n) = \begin{cases} \Theta(1), & \text{if } n = 1,\\ aT(n/b) + f(n), & \text{if } n>1. \end{cases}\]

where $a\ge1$, $b>1$ are constants and $f$ is nonnegative. Then

  1. If $f(n) = O(n^{\log_b a-\varepsilon})$ for some constant $\varepsilon >0$, then $T(n) = \Theta(n^{\log_b a})$.
  2. If $f(n) = \Theta(n^{\log_b a})$, then $T(n) = \Theta(n^{\log_b a}\log n)$.
  3. If $f(n) = \Omega(n^{\log_b a+\varepsilon})$ for some constant $\varepsilon >0$, and if $af(n/b)\le cf(n)$ for some constant $c<1$ and all sufficiently large $n$, then $T(n) = \Theta(f(n))$.
Read more »

在 TeXworks 中自定义代码补全

2020-01-08 | ~ | Language

因为 TeXworks 用了太多年, 不太想换 IDE, 还是继续用了.

参考 官方文档.

文件地址: TeXworks 菜单栏的 “帮助” -> “TeXworks 配置与资源” -> “资源” -> “completion” 文件夹 -> “tw-latex.txt” 文件.

语法

<alias>:=<text>

The <alias>:= part can be omitted to turn the code text into its own alias. <text> must fit in a single line. Empty lines and lines starting with a % are ignored.

第一句话的意思是, 单纯写 blahblah 相当于 blahblah:=blahblah.

<text> 中连续的空格是有效的.

  • #RET# 表示 return, 换行.
  • #INS# 表示 insert, 光标会被放置在此处.
  • • bullet 是 placeholder, 使用 <Ctrl>+<Tab> 让光标移动到下一个占位符处.
Read more »

A Wrong Way to Do Cross-Validation

2019-12-12 | ~ | Machine Learning

While this point may seem obvious to the reader, we have seen this blunder committed many times in published papers in top rank journals.

Consider a classification problem with a large number of predictors, as may arise, for example, in genomic or proteomic applications. A typical strategy for analysis might be as follows:

  1. Screen the predictors: find a subset of “good” predictors that show fairly strong (univariate) correlation with the class labels.
  2. Using just this subset of predictors, build a multivariate classifier.
  3. Use cross-validation to estimate the unknown tuning parameters and to estimate the prediction error of the final model.
Read more »

Side Note: Information Entropy, Cross-Entropy and KL Divergence

2019-11-30 | ~ | Mathematics

我们考虑一个事件 $A$, 它发生的概率是 $p$. 假设我们观测到事件 $A$ 发生, 我们希望定义一个信息量 $I(p)$ 来衡量 “$A$ 发生了” 这件事给了我们多少信息.

  1. $I(p)$ 是关于 $p$ 的递减函数. 如果事件发生概率高, 而且它发生了, 我们得到的信息应该比较少, 因为我们认为它确实容易发生, 这不稀奇.
  2. 考虑另一个独立的事件 $B$, 它发生的概率是 $q$, 则 $I(pq) = I(p) + I(q)$. 也就是说我们希望独立事件同时发生时提供的信息量应该是他们分别提供的信息量之和.
Read more »

一次手磨咖啡体验

2019-11-21 | ~ 2020-12-03 | Food and Cooking

上周六 (2019/11/16) 在学校北区咖啡馆体验了一次手磨咖啡, 简单地记录一下. 也叫手冲咖啡.

1. 制作手磨咖啡的流程

主办方提供的器材如图

Read more »

Bootstrap 失效的一个例子

2019-11-08 | ~ | Statistics

假设 $Y_1, \dots, Y_n$ 独立同分布, 服从 $[0,\theta]$ 上的均匀分布. 则其似然函数为

\[L(\theta|Y_1, \dots, Y_n) = \frac{1}{\theta^n} \prod_{k=1}^n 1_{\{ 0\le Y_k\le \theta \}}.\]
Read more »

中位数两则, 线性时间与 leetcode 4

2019-10-21 | ~ 2020-06-07 | Algorithms

找中位数最暴力的方法是先排序再取中位数, 时间复杂度 $O(n\log n)$. 后来才得知中位数有时间复杂度 $O(n)$ 的算法, 事实上任意顺序统计量都可以用 $O(n)$ 时间找出.

Read more »
1 … 16 17 18
Shiina

Shiina

知乎 豆瓣 bangumi Instagram Weibo
Creative Commons
RSS
© 2019 - 2025   Shiina   CC BY-NC-ND 4.0
RSS  
Powered by Jekyll
 
Theme NexT.Mist