小编kot*_*ota的帖子

在 Python 中实现离散高斯内核?

我希望实现由 Lindeberg 在他关于尺度空间理论的工作中定义的离散高斯核

它被定义为 T(n,t) = exp(-t)*I_n(t) 其中 I_n 是第一类修正贝塞尔函数

我正在尝试使用 Numpy 和 Scipy 在 Python 中实现这一点,但遇到了一些麻烦。

def discrete_gaussian_kernel(t, n):
    return math.exp(-t) * scipy.special.iv(n, t)
Run Code Online (Sandbox Code Playgroud)

我尝试绘制:

import math
import numpy as np
import scipy
from matplotlib import pyplot as plt

def kernel(t, n):
    return math.exp(-t) * scipy.special.iv(n, t)
ns = np.linspace(-5, 5, 1000)
y0 = discrete_gaussian_kernel(0.5, ns)
y1 = discrete_gaussian_kernel(1, ns)
y2 = discrete_gaussian_kernel(2, ns)
y3 = discrete_gaussian_kernel(4, ns)
plt.plot(ns, y0, ns, y1, ns, y2, ns, …
Run Code Online (Sandbox Code Playgroud)

python numpy gaussian scipy

5
推荐指数
1
解决办法
2843
查看次数

具有抽象基类的子类的C++模板特化

假设我有一个纯粹的抽象基类.类模板实现此接口,并且是专用的.现在,我的问题是这个专业化应该能够处理专业化的子类.所以,我尝试了enable_if,但是子类最终变得抽象......我怎么能绕过这个?

举例:

// This example doesn't work because a subclass of A does not satisfy the
// specialization for B<T>::foo()
class A {
public:
    virtual void foo() = 0;
};

template <class T>
class B : public A {
    ...
public:
    ...
    void foo();
    ...
};

void B::foo() {
    ...
}

template <>
void B<A>::foo() {
    ...
}

class C : A {
    ...
public:
    ...
    void foo();
    ...
};

int main() {
    B<C> bar;  // I was like "this …
Run Code Online (Sandbox Code Playgroud)

c++ templates template-specialization enable-if c++11

1
推荐指数
1
解决办法
2534
查看次数