- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有像下面这样的数据集,我试图找出具有最佳带宽的内核密度估计。
data = np.array([[1, 4, 3], [2, .6, 1.2], [2, 1, 1.2],
[2, 0.5, 1.4], [5, .5, 0], [0, 0, 0],
[1, 4, 3], [5, .5, 0], [2, .5, 1.2]])
但我不知道如何处理它。还有如何找到 Σ 矩阵。
更新
我尝试了 scikit-learn 工具包中的 KDE 函数来找出单变量(1D)kde,
# kde function
def kde_sklearn(x, x_grid, bandwidth):
kde = KernelDensity(kernel='gaussian', bandwidth=bandwidth).fit(x)
log_pdf = kde.score_samples(x_grid[:, np.newaxis])
return np.exp(log_pdf)
# optimal bandwidth selection
from sklearn.grid_search import GridSearchCV
grid = GridSearchCV(KernelDensity(), {'bandwidth': np.linspace(.1, 1.0, 30)}, cv=20)
grid.fit(x)
bw = grid.best_params_
# pdf using kde
pdf = kde_sklearn(x, x_grid, bw)
ax.plot(x_grid, pdf, label='bw={}'.format(bw))
ax.legend(loc='best')
plt.show()
任何人都可以帮助我将其扩展到多变量/在这种情况下是 3D 数据吗?
最佳答案
有趣的问题。您有几个选择:
This blog post详细介绍了内核密度估计 (KDE) 的各种库实现的相对优点。
我将向您展示什么(在我看来 - 是的,这有点基于意见)是最简单的方法,我认为这是您的情况的选项 2。
注意 此方法使用链接文档中描述的经验法则来确定带宽。使用的确切规则是 Scott 规则。你提到的 Σ 矩阵让我觉得带宽选择的经验法则对你来说是可以的,但你也谈到了最佳带宽,你提供的例子使用交叉验证来确定最佳带宽。因此,如果此方法不适合您的目的 - 请在评论中告诉我。
import numpy as np
from scipy import stats
data = np.array([[1, 4, 3], [2, .6, 1.2], [2, 1, 1.2],
[2, 0.5, 1.4], [5, .5, 0], [0, 0, 0],
[1, 4, 3], [5, .5, 0], [2, .5, 1.2]])
data = data.T #The KDE takes N vectors of length K for K data points
#rather than K vectors of length N
kde = stats.gaussian_kde(data)
# You now have your kde!! Interpreting it / visualising it can be difficult with 3D data
# You might like to try 2D data first - then you can plot the resulting estimated pdf
# as the height in the third dimension, making visualisation easier.
# Here is the basic way to evaluate the estimated pdf on a regular n-dimensional mesh
# Create a regular N-dimensional grid with (arbitrary) 20 points in each dimension
minima = data.T.min(axis=0)
maxima = data.T.max(axis=0)
space = [np.linspace(mini,maxi,20) for mini, maxi in zip(minima,maxima)]
grid = np.meshgrid(*space)
#Turn the grid into N-dimensional coordinates for each point
#Note - coords will get very large as N increases...
coords = np.vstack(map(np.ravel, grid))
#Evaluate the KD estimated pdf at each coordinate
density = kde(coords)
#Do what you like with the density values here..
#plot them, output them, use them elsewhere...
警告
这可能会产生糟糕的结果,具体取决于您的具体问题。要记住的事情显然是:
随着维度数量的增加,您想要观察到的数据点的数量必须呈指数增长 - 3 维中 9 个点的样本数据非常稀疏 - 尽管我假设这些点表明事实上你还有更多。
如正文中所述 - 以特定方式选择带宽 - 这可能导致估计的 pdf 过度(或可以想象但不太可能不足)平滑。
关于python - 如何在多变量/3D 中实现核密度估计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30696741/
我使用 4 核 i7 CPU(8 个逻辑核),debian linux 虚拟机也是 debian linux 程序使用 gcc 编译,没有进行特殊优化(默认编译设置) 我循环了该程序 1000 次。当
我有一个实时 linux 桌面应用程序(用 C 语言编写),我们正在移植到 ARM(4 核 Cortex v8-A72 CPU)。在架构上,它结合了高优先级显式 pthread(其中 6 个)和一对
我已经在 Digital Ocean ubuntu 实例上安装了 Solr 6: install_solr_service.sh solr-6.1.0.tgz 并验证 Solr 正在运行。但是,我无法
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 3 年前。 Improve this qu
关闭。这个问题需要更多focused .它目前不接受答案。 想改善这个问题吗?更新问题,使其仅关注一个问题 editing this post . 6年前关闭。 Improve this questi
我有一个大约 2000 维的特征向量。都是直方图特征。 我不知道在我的情况下哪个有效:将 SVM 与 RBF 核或卡方核应用? 你能建议我在我的情况下有效的内核吗? 最佳答案 一般来说,卡方和交集内核
我们有一台 12 核 MacPro 来进行一些蒙特卡罗计算。其 Intel Xeon 处理器启用了超线程 (HT),因此实际上应该有 24 个进程并行运行才能充分利用它们。然而,我们的计算在 12x1
所以这段代码: library(plyr) library(doMC) registerDoMC(cores=2) x=1:100 llply(x, some_function, .parallel=
Netty Server 流到 Netty 客户端(点对点,1 对 1): 好的 案例:Server和Client都是12 cores , 1Gbit NIC => 以每秒 300K 200 字节消息
我对以下 C# 代码的线程激活顺序感到困惑。它创建了 10 个线程,随机启动它们,每个线程模拟执行一个耗时的工作 10 次,如果你检查调试输出,线程似乎不是随机选择的,请看下面的输出示例,注意线程 #
这是我考试时提出的问题。我给出了以下答案,我的得分是0分。教授甚至不同意给予任何部分的认可,也没有告诉我我的答案有什么问题。谁能帮我找出我的答案有什么问题吗? 这是我在考试中给出的答案。缺点是:1)
我有一个 Intel Xeon E5-2620,它有 24 个 CPU。我写了一个应用程序,它创建 24 个线程来使用 openssl 解密 AES。当我在 100 万数据解密时将线程数从 1 增加到
我正在开发一个在图层上绘画的应用程序。这是一个示例代码,展示了我的绘画方式。 UIImageView * currentLayer = // getting the right layer... UI
在带有 2Tb DRAM 的 80 核 (160HT) nehalem 架构上运行一些测试后,我遇到了一个小的 HPC 问题: 当每个线程开始请求有关“错误”套接字上的对象的信息时,具有 2 个以上套
由于潜在的性能问题,我刚刚将测试实例从小型“标准”(1 核,1.75GB RAM)实例升级到中型“标准”实例(2 核,3.5GB RAM),这似乎是快速击中。我们确实存在应用程序池回收和必须重新预热某
我知道,为了在 Android 中保持响应式界面,繁重的工作必须在独立线程中完成。我很清楚如何实现这一点(通过使用 AsynTask...等),这不是问题的重点,只是让每个人都知道。 但是我已经在一个
我写了一个简单的多线程 Java 应用程序,主要方法只创建 5k 个线程,每个线程将循环处理一个包含 5M 条记录的列表。 我的机器规范: CPU 内核:12 个内核 内存:13Gb RAM 操作系统
让我们假设我们有固定数量的计算工作,没有阻塞、 sleep 、I/O 等待。工作可以很好地并行化——它由 100M 小而独立的计算任务组成。 什么是 4 核 CPU 的速度更快 - 运行 4 个线程或
我正在使用 WEKA/LibSVM 来训练术语提取系统的分类器。我的数据不是线性可分的,因此我使用 RBF 内核而不是线性内核。 我关注了guide from Hsu et al.并迭代 c 和 ga
谁能告诉我为什么在具有四个 ARMv7 处理器的 Jetson TK1 上调用 Python 的 multiprocessing.cpu_count() 函数会返回 1? >>> import mul
我是一名优秀的程序员,十分优秀!