Skip to main content

多尺度可分性度量的 Python 实现。

项目描述

安全性

可分离性度量的 Python 实现。

多尺度可分离性度量的 Python 实现,如 [1] 所示。可以在此处找到实现所依据的原始论文。

使用此软件包后,请考虑引用实现所基于的论文:

[1] TORRES, R. da S.; FALCAO, Alexandre X.; COSTA, L. da F. A graph-based approach for multiscale shape analysis. Pattern Recognition, v. 37, n. 6, p. 1163-1174, 2004.

目录

多尺度可分性

描述符的可分离性表明它在同一类个体之间的区分能力。它通过显示数据与描述符的距离来衡量描述符的有效性。

安装

方法 1 - PIP

赶紧跑: pip install sepyrability

方法 2 - 手动安装

首先,通过运行以下命令克隆目录:

git clone https://github.com/jrjoaorenato/SePYrability.git

该软件包需要以下依赖项:

  • 麻木的
  • matplotlib

您可以通过在包目录中运行以下命令来安装这些依赖项: pip install -r requirements.txt

之后,您可以在包目录中运行以下命令来安装包: pip install -e .

用法

您可以使用以下方法导入包: import sepyrability.separability as sep

已经实现的默认距离度量,可以通过以下方式导入: import sepyrability.distance as dis

目前实现的距离类型有:

  1. euclidian- 欧几里得距离
  2. cosine- 余弦距离

要访问您可以使用的距离:dis.<chosen distance>

正确导入包后,您可以使用以下属性计算多尺度可分性:

sep.calculate_separability(data, labels, distfun = dis.euclidian, dx = 0.02, start= 0.01, show_graph = True):
Arguments:
    n is the number of instances
    and f is the dimensionality of the features
    data {numpy Matrix [n x f]} -- The data on which separability is going to be calculated
    labels {np.array[n]} -- label information for each piece of data
    distfun {function} -- function used to calculate distance: euclidian
    dx {float} -- step size for distance calculation
    start {float} -- starting point for the steps
    show_graph {bool} -- Boolean to show or not the multiscale separability graph

Returns:
    multiscale_separability {dictionary} -- dictionary containing:
        - 'multiscale_separability' [array of floats] -- multiscale_separability for a specific radius
        - 'distance' [array of floats] -- corresponding radius distance for multiscale_separability
    auc -- area under the curve of the separability graph
    --plots graph if 'show_graph' is True

您可以使用 sep.calculate_separability(data, labels) 轻松获取多尺度可分离性数据。如果需要,您还可以指定与 euclidian 不同的距离函数,方法是将函数作为 distfun 的参数传递,包括您自己的,如下一会话所示。

自定义距离函数

您可以选择实现自己的距离函数并将其作为 distfun 的参数传递。这可以通过创建一个自定义函数来完成,该函数接收参考点“ref”和数据点“X”作为参数,并返回这两个点之间的距离。

注意:距离应在 0 和 1 之间标准化。

一个例子可以在下面看到:

def custom_euclidian(ref, X):
    #returns normalized euclidian distance from the reference point
    dist = X - ref
    dist = np.sqrt(np.sum(np.power(dist, 2), axis = 1))
    dist = dist/np.max(dist)
    return dist

#this can be called below by using:
ms, auc = sep.calculate_separability(Xt, Yt, distfun=dis.custom_euclidian)

例子

import sepyrability.separability as sep
import scipy.io as sio
import numpy as np

D = loadmat(<some .mat dataset location>)
X = D['X']
Y = D['Y']
ms, auc = sep.calculate_separability(Xt, Yt)

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

SePyrability-0.0.1.tar.gz (5.0 kB 查看哈希

已上传 source