有没有办法在SAS的proc物流中获得Hessian矩阵?或者哪一个可以选择计算它从离开proc procitic?
我一直在阅读函数文档,但无法看到有一种方法可以将它包含在输出表中.
我想查找给定图像的山脊。(边缘没有边缘!)示例如下图所示

我认为Hessian矩阵会直观地工作。因此,我从2D-高斯方程开始对Hessian矩阵内核进行了硬编码,如下所述。 如何构建2D粗麻布矩阵内核
我使用surf可视化的方法创建了3个二阶导数内核(D_xx,D_yy和D_xy),它们看上去都是正确的。
然后,我应用了这些内核并对图像进行了2D卷积。
我不确定下一步该怎么做,是否需要使用D_xx,D_yy和D_xy来表示特征值和向量?我们如何通过对每个像素进行2×2矩阵的特征分析来从图像中提取出棱线?任何想法,公式甚至代码都将大有帮助。
附带的代码生成二维Hessian矩阵
[x y]=meshgrid(round(-N/2):round(N/2), round(-N/2):round(N/2));
common = x.^2+y.^2;
Lxx = ((-1+x.^2/(sigma^2)).*exp(-common/(2*sigma^2))) / (2*pi*sigma^4);
Lxx = Lxx./ sum(Lxx(:));
Lyy = ((-1+y.^2/(sigma^2)).*exp(-common/(2*sigma^2))) / (2*pi*sigma^4);
Lyy = Lyy./ sum(Lyy(:));
Lxy = ((x.*y)/(2*pi*sigma^6)).*exp(-common/(2*sigma^2));
Lxy = Lxy./ sum(Lxy(:));
Run Code Online (Sandbox Code Playgroud) 简而言之,我想知道火炬中是否存在张量命令,它给出了张量满足某个标准的元素索引.
这是matlab代码,说明了我希望能够在火炬中做什么:
my_mat = magic(3); % returns a 3 by 3 matrix with the numbers 1 through 9
greater_than_fives = find(my_mat > 5); % find indices of all values greater than 5, the " > 5" is a logical elementwise operator that returns a matrix of all 0's and 1's and finally the "find" command picks out the indices with a "1" in them
my_mat(greater_than_fives) = 0; % set all values greater than 5 equal to 0
Run Code Online (Sandbox Code Playgroud)
我知道我可以使用for循环在火炬中执行此操作,但是有一些等同于matlab的find命令可以让我更紧凑地执行此操作吗?
这是非常新的,所以请耐心等待...
我有一个预定义的单词列表
checklist = ['A','FOO']
Run Code Online (Sandbox Code Playgroud)
一个单词列表line.split()看起来像这样
words = ['fAr', 'near', 'A']
Run Code Online (Sandbox Code Playgroud)
我需要checklistin 的完全匹配words,所以我只找到'A':
if checklist[0] in words:
Run Code Online (Sandbox Code Playgroud)
这没用,所以我尝试了一些我在这里找到的建议:
if re.search(r'\b'checklist[0]'\b', line):
Run Code Online (Sandbox Code Playgroud)
无济于事,因为我显然无法找到那样的列表对象......对此有何帮助?
我们正在尝试使用 Spark 上的 MLLIB 在 python 中训练具有指定初始模型的高斯混合模型 (GMM)。pyspark 的 Doc 1.5.1 说我们应该使用 GaussianMixtureModel 对象作为 GaussianMixture.train 方法的“initialModel”参数的输入。在创建我们自己的初始模型之前(例如计划使用 Kmean 结果),我们只是想测试这个场景。因此,我们尝试使用第一个训练的输出中的 GaussianMixtureModel 来初始化第二个训练。但这个微不足道的场景会引发错误。您能帮我们确定这里发生了什么吗?非常感谢纪尧姆
PS:我们运行 (py) Spark 1.5.1 和 hadoop 2.6
下面是简单的场景代码和错误:
from pyspark.mllib.clustering import GaussianMixture
from numpy import array
import sys
import os
import pyspark
### Local default options
K=2 # "k" (int) Set the number of Gaussians in the mixture model. Default: 2
convergenceTol=1e-3 # "convergenceTol" (double) Set the largest change in log-likelihood at which convergence is considered to have occurred.
maxIterations=100 …Run Code Online (Sandbox Code Playgroud) 我必须计算数千个离散概率向量之间的Kullback-Leibler发散(KLD).目前我正在使用以下代码,但它对我的目的来说太慢了.我想知道是否有更快的方法来计算KL Divergence?
import numpy as np
import scipy.stats as sc
#n is the number of data points
kld = np.zeros(n, n)
for i in range(0, n):
for j in range(0, n):
if(i != j):
kld[i, j] = sc.entropy(distributions[i, :], distributions[j, :])
Run Code Online (Sandbox Code Playgroud) 我有一张在Google上找到的图片.我的目的是用该样本图像训练GOCR,然后用我获得的知识重现结果.我用了
gocr -i /tmp/scanned2.jpg -m 2 -p /home/marc/.db/ -m 256 -m 130
Run Code Online (Sandbox Code Playgroud)
训练它.-m 2使用个人数据库,-p指定它所在的位置,-m 256忽略通常的ocr数据库,-m 130进行交互式训练.在我完成训练后(这真的需要很长时间才能完成)我看了一下结果并且没问题.但是当我尝试重用我的数据库时,它似乎不起作用.我用的时候
gocr -i /tmp/scanned2.jpg -m 2 -p /home/marc/.db/ -m 256
Run Code Online (Sandbox Code Playgroud)
这实际上是与上面相同的命令,只是没有数据库的交互式训练,它不能识别我在上一次训练中训练GOCR的许多事情.难道它不应该产生与我训练时得到的结果相同的结果吗?
我的系统是Linux Mint 3.16.0-38.我通过apt-get安装了GOCR并拥有最新版本.
我正在尝试使用Theano来计算关于向量以及几个标量的函数的粗糙度(编辑:也就是说,我基本上希望附加到我正在计算粗麻布的向量的标量) .这是一个最小的例子:
import theano
import theano.tensor as T
A = T.vector('A')
b,c = T.scalars('b','c')
y = T.sum(A)*b*c
Run Code Online (Sandbox Code Playgroud)
我的第一次尝试是:
hy = T.hessian(y,[A,b,c])
Run Code Online (Sandbox Code Playgroud)
哪个失败了 AssertionError: tensor.hessian expects a (list of) 1 dimensional variable as 'wrt'
我的第二次尝试是将A,b和c与:
wrt = T.concatenate([A,T.stack(b,c)])
hy = T.hessian(y,[wrt])
Run Code Online (Sandbox Code Playgroud)
哪个失败了 DisconnectedInputError: grad method was asked to compute the gradient with respect to a variable that is not part of the computational graph of the cost, or is used only by a non-differentiable operator: Join.0
在这种情况下计算粗麻线的正确方法是什么?
更新:为了澄清我在寻找什么,假设A是2元素向量.然后黑森州将是:
[[d2y/d2A1, d2y/dA1dA2, d2y/dA1dB, …Run Code Online (Sandbox Code Playgroud) 假设我有一个有5个隐藏层的人工神经网络.目前,忘记神经网络模型的细节,如偏差,使用的激活函数,数据类型等等.当然,激活功能是可区分的.
通过符号区分,以下计算目标函数相对于图层权重的渐变:
w1_grad = T.grad(lost, [w1])
w2_grad = T.grad(lost, [w2])
w3_grad = T.grad(lost, [w3])
w4_grad = T.grad(lost, [w4])
w5_grad = T.grad(lost, [w5])
w_output_grad = T.grad(lost, [w_output])
Run Code Online (Sandbox Code Playgroud)
通过这种方式,计算梯度WRT W1梯度WRT W2,W3,W4和W5必须先计算.类似于计算梯度wrt w2,梯度wrt w3,必须首先计算w4和w5.
但是,我可以使用以下代码计算每个权重矩阵的渐变:
w1_grad, w2_grad, w3_grad, w4_grad, w5_grad, w_output_grad = T.grad(lost, [w1, w2, w3, w4, w5, w_output])
Run Code Online (Sandbox Code Playgroud)
我想知道,这两种方法在性能方面有什么区别吗?Theano是否足够智能以避免使用第二种方法重新计算渐变?智能我的意思是计算w3_grad,Theano应该[最好]使用w_output_grad,w5_grad和w4_grad的预先计算的梯度,而不是再次计算它们.
gradient automatic-differentiation neural-network python-2.7 theano
我必须在 C 中使用 ncurses 绘制一个框;
首先,为了简单起见,我定义了一些值:
#define RB "\e(0\x6a\e(B" (ASCII 188,Right bottom, for example)
Run Code Online (Sandbox Code Playgroud)
我在 Ubuntu 上用 gcc 编译,带有-finput-charset=UTF-8标志。
但是,如果我尝试使用 addstr 或 printw 进行打印,则会得到六进制代码。我做错了什么?
python ×4
statistics ×2
string ×2
theano ×2
apache-spark ×1
c ×1
convolution ×1
gcc ×1
glm ×1
gradient ×1
lua ×1
matlab ×1
ncurses ×1
numpy ×1
ocr ×1
performance ×1
pyspark ×1
python-2.7 ×1
regex ×1
sas ×1
sas-iml ×1
scanning ×1
scipy ×1
torch ×1
unicode ×1