kd-tree是一种树数据结构, 用来存储多维数据。正如BST(二分搜索树)用值的大小关系来建树,左子节点的值 < 父节点 < 右子节点。 kd-tree也是用值的大小关系来建树,但是由于它处理的是多维数据, 以二维为例, 在根节点根据x值的大小关系来组织, 左子节点x值 < 父节点x值 < 右节点x值, 在下一层, 则换用y值的大小关系来组织, 左子节点y值 < 父节点y值 < 右节点y值,再下一层又换回x值,如此循环。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import os | |
import subprocess | |
file_list = [] | |
for f in os.listdir('.'): | |
if os.path.splitext(f)[1] == '.bin': | |
file_list.append(f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
name_base = 'odiac2013a_1km_excl_intl_{}{}' | |
meta = '''ENVI | |
samples = 43200 | |
lines = 21600 | |
data type = 4 | |
bands = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import scipy as sp | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
import seaborn as sns | |
from scipy.stats import norm | |
def sampler(data, samples=4, mu_init=.5, proposal_width=.5, plot=False, mu_prior_mu=0, mu_prior_sd=1.): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 代码来自 http://twiecki.github.io/blog/2015/11/10/mcmc-sampling/ | |
# | |
# | |
import numpy as np | |
import scipy as sp | |
import pandas as pd | |
import matplotlib.pyplot as plt |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
做实验的时候常常会遇到一个脚本跑的很慢的情况,这个时候我们常常会想方设法的去做一些优化,来让脚本跑的快一些。 但是优化带来了两个问题,一个是优化后的代码仍然是正确的吗,第二个问题是优化有效果吗?
第一个问题可以依靠编写合适的单元测试来解决, 但是究竟如何编写合适的单元测试仍然是一个很大的问题,这个问题我们留待以后在讨论。
第二个问题可以依靠性能分析来解决,性能分析就是测试代码的执行时间,很多时候我们经常会用如下的方式来做性能分析,但是这种方法一来麻烦,二来会把代码弄得很混乱。
from time import time
begin_tick = time()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.