コード例 #1
0
ファイル: test_systems.py プロジェクト: neuromusic/pyentropy
def do_1d_check(method, qe_method):
    xc = x.copy()
    yc = y.copy()
    s = DiscreteSystem(xc,(1,10),yc,(1,10))
    # calculate all entropies
    s.calculate_entropies(method=method, calc=allcalc, qe_method=qe_method)
    # check output assinged
    assert_(s.H == getattr(s,'H_%s'%method.replace('-','')))
    v = np.array([s.H[k] for k in allcalc])
    assert_array_almost_equal(v, alltrue, decimal=2)
    # check didn't do something nasty to inputs
    assert_array_equal(x, xc)
    assert_array_equal(y, yc)
コード例 #2
0
ファイル: test_systems.py プロジェクト: w-klijn/pyentropy
def do_1d_check(method, qe_method):
    xc = x.copy()
    yc = y.copy()
    s = DiscreteSystem(xc, (1, 10), yc, (1, 10))
    # calculate all entropies
    s.calculate_entropies(method=method, calc=allcalc, qe_method=qe_method)
    # check output assinged
    assert_(s.H == getattr(s, 'H_%s' % method.replace('-', '')))
    v = np.array([s.H[k] for k in allcalc])
    assert_array_almost_equal(v, alltrue, decimal=2)
    # check didn't do something nasty to inputs
    assert_array_equal(x, xc)
    assert_array_equal(y, yc)
コード例 #3
0
ファイル: mi.py プロジェクト: gic888/gdblocks
def minf_pyent(isp, osp, meth):
    x, xdim = _pyentcond(osp)
    y, ydim = _pyentcond(isp)
    ds = DiscreteSystem(x, xdim, y, ydim)
    calc = ["HX", "HXY", "HY"]
    if meth.endswith('_sh'):
        meth = meth[:-3]
        calc.extend(['HiXY', 'HshXY'])
    ds.calculate_entropies(meth, calc=calc)
    if len(calc) == 3:
        return (ds.I(), ds.H['HY'], ds.H['HX'])
    else:
        return (ds.Ish(), ds.H['HY'], ds.H["HX"])
コード例 #4
0
ファイル: info_scatters.py プロジェクト: robince/sensorcop
def plot_calc(x,y,ax=None, xlim=[-4, 4], ylim=[-4,4]):
    if ax is None:
        f = plt.figure()
        ax = f.add_subplot(111)

    # correlation
    cor = np.corrcoef(x,y)[0,1]

    # information
    m = 8 
    qx = quantise(x, m, uniform='sampling')[0]
    qy = quantise(y, m, uniform='sampling')[0]
    s = DiscreteSystem(qx, (1,m), qy, (1,m))
    s.calculate_entropies(method='plugin', calc=['HX','HXY'])
    I = s.I()

    # p-values?

    Nplot = 500
    plotidx = np.random.permutation(len(x))[:Nplot]
    ax.scatter(x[plotidx],y[plotidx], s=5, edgecolors='none')
    #ax.set_title("r=%.1f  I=%.2f" % (cor, I))
    ax.set_xlim(xlim)
    ax.set_ylim(ylim)
    for sp in ['left','right','bottom','top']:
        ax.spines[sp].set_color('none')
    ax.xaxis.set_ticks_position('none')
    ax.yaxis.set_ticks_position('none')
    ax.set_xticklabels([])
    if np.abs(cor)<1e-3:
        cor = 0.0
    if np.isnan(cor):
        cor = '-'
    else:
        cor = "%.2f"%cor
    ax.text(0.2, 1, cor, horizontalalignment='center', verticalalignment='bottom', 
            transform = ax.transAxes, color='#663300', fontsize=12, fontweight='bold')
    ax.text(0.8, 1, "%.2f"%I, horizontalalignment='center', verticalalignment='bottom', 
            transform = ax.transAxes, color='#b20000', fontsize=12, fontweight='bold')
    return ax
コード例 #5
0
ファイル: test_systems.py プロジェクト: neuromusic/pyentropy
def test_toy1():
    s = DiscreteSystem(x,(3,3),y,(1,2))
    s.calculate_entropies(method='plugin', calc=toycalc)
    v = np.array([s.H[t] for t in toycalc])
    assert_array_almost_equal(v, toytrue)
コード例 #6
0
ファイル: test_systems.py プロジェクト: w-klijn/pyentropy
def test_toy1():
    s = DiscreteSystem(x, (3, 3), y, (1, 2))
    s.calculate_entropies(method='plugin', calc=toycalc)
    v = np.array([s.H[t] for t in toycalc])
    assert_array_almost_equal(v, toytrue)
コード例 #7
0
#!/usr/bin/env python
import numpy as np
import pyentropy
from pyentropy import DiscreteSystem
import matplotlib.pyplot as plt

N = 10
Nq = 50
Nx = 1
noise = 1
ntrials = 10
for trial in xrange(ntrials):
    x = N * np.random.rand(Nx, 10000)
    y = np.zeros(10000)
    xq = np.empty((Nx, 10000), dtype=int)
    for n in range(Nx):
        xq[n, :] , _, _ = pyentropy.quantise(x[n, :], Nq)
        y += x[n, :]
    y += noise*np.random.randn(10000)
    yq, _, _ = pyentropy.quantise(y, Nq)

    s = DiscreteSystem(xq, (Nx, Nq), yq, (1, Nq))
    s.calculate_entropies(method='plugin', calc=['HX', 'HXY'])
    print(s.I())
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.scatter(xq, yq, s=2)
    ax.set_title('MI: %s' % s.I())
    fig.savefig('mi_%d.png' % trial)
    plt.close()