Exemple #1
0
def main():
    alpha = params['alpha']
    figInd = 0

    probeDistance = 1
    nSpuriousDims = 0
    hiVObs, loVObs = preTrainingObservations(nSpuriousDims)
    oProbe = probeObservation(probeDistance, nSpuriousDims)

    model = WorldModel(CRP(alpha), Gauss())
    hiVCP = experience(hiVObs, oProbe, model)
    loVCP = experience(loVObs, oProbe, model)

    figInd += 1
    fig = plt.figure(figInd)
    plt.clf()
    h1, = plt.plot(hiVObs[:, 0], hiVObs[:, 1], '.c')
    h2, = plt.plot(loVObs[:, 0], loVObs[:, 1], '.m')
    h3, = plt.plot(oProbe[0], oProbe[1], 'xr')
    plt.autoscale(tight=False)
    m = max(plt.axis())
    plt.axis((-m, m, -m, m))
    plt.axis('equal')
    adjustPlot(plt.gca())
    plt.xlabel('Feature 1')
    plt.ylabel('Feature 2')
    plt.legend([h1, h2, h3],
               ['High Variance Training', 'Low Variance Training', 'Probe'],
               loc='best')
    plt.savefig('figures/' + filename + '-' + str(figInd) + '.pdf',
                bbox_inches='tight')

    figInd += 1
    fig = plt.figure(figInd)
    fig.clear()
    ax = plt.subplot(1, 2, 1)
    bar_width = 0.2
    rat1 = -np.diff(hiVCP, axis=0)
    rat2 = -np.diff(loVCP, axis=0)
    plt.bar(np.array([-bar_width / 2, +bar_width / 2]),
            np.array([rat1, rat2]).squeeze(),
            bar_width,
            color=('c', 'm'),
            zorder=1)
    m = np.max(np.abs(plt.ylim()))
    plt.ylim([-m, m])
    adjustPlot(ax, fuzzyzero=True)
    plt.xticks(np.array([-bar_width / 2, +bar_width / 2]),
               ['High Variance\nTraining', 'Low Variance\nTraining'])
    plt.ylabel('State Evidence Ratio')
    plt.savefig('figures/' + filename + '-' + str(figInd) + '.pdf',
                bbox_inches='tight')
                np.pi).astype(int)  # 2 clusters, animal1

partition2_1 = np.zeros((nExperiences, ))  # 1 cluster, animal2
partition2_2 = np.mod(animal2.experiences[:, 0] - midpoint2,
                      2 * np.pi) > np.pi  # 2 clusters, animal2

#%%
# partition_prob
figInd += 1
figInd = 2
fig = plt.figure(figInd)
fig.clear()
ax = plt.subplot(1, 2, 1)
bar_width = 0.2
inds = np.array([0, 1]) - bar_width / 2
rat1 = animal1.partition_prob(partition1_1) - animal1.partition_prob(
    partition1_2)
rat2 = animal1.partition_prob(partition2_1) - animal1.partition_prob(
    partition2_2)
plt.bar(np.array([-bar_width / 2, +bar_width / 2]),
        -np.array([rat2, rat1]),
        bar_width,
        color='rb')
m = np.max(np.abs(plt.ylim()))
plt.ylim([-m, m])
adjustPlot(ax, fuzzyzero=True)
plt.xticks(np.array([-bar_width / 2, +bar_width / 2]), ['Random', 'Directed'])
plt.ylabel('Negative Partition Evidence Ratio')
plt.savefig('figures/' + filename + '-' + str(figInd) + '.pdf',
            bbox_inches='tight')
Exemple #3
0
#%%
figInd += 1
#%%
fig = plt.figure(figInd)
fig.clear()
bar_width = 0.2
idxs = np.array([0, 15, 30]) + 1  #+5
idxs = np.array([0, 20, 40]) + 1  #+5
for i in range(3):
    plt.bar(
        np.array([1, 2, 3]) + (i - 1) * bar_width, posts[idxs, i], bar_width)
    #plt.plot(np.array([1,2,3])+(i-1)*bar_width/10, posts[idxs,i], 'x')
labels = []
for idx in idxs:
    labels.append(r'$\alpha$ = ' + str(alphas[idx]))
adjustPlot(plt.gca(), fuzzyzero=False)
plt.xticks(np.array([1, 2, 3]), labels)
plt.ylabel('Unnormalized Log Posterior')
plt.legend(('All Separate', '"Correct"', 'All Together'), loc='lower center')
#%%
plt.savefig('figures/' + filename + '-' + str(figInd) + '.pdf',
            bbox_inches='tight')

#%%
figInd += 1
#%%
fig = plt.figure(figInd)
fig.clear()
plt.plot(np.log10(alphas), posts)
plt.xlabel('Log10(alpha)')
plt.ylabel('Unnormalized Log Posterior')
ax = plt.gca()
a, b = 1, 7
plt.plot(x, stats.beta.pdf(x,a,b),linewidth=3)
print(param_results(a,b)[0])
a, b = 1.5, 1
plt.plot(x, stats.beta.pdf(x,a,b),linewidth=3)
print(param_results(a,b)[0])

ylims=ax.get_ylim()
plt.plot([0+thresh, 0+thresh], ylims,'--k')
plt.plot([1-thresh, 1-thresh], ylims,'--k')
ax.set_ylim([0, ylims[1]])
ax.set_xlim([0,1])
plt.xlabel('Rate Modulation')
plt.ylabel('Probability Density')
adjustPlot(ax)
plt.savefig('figures/' + filename + '-' + str(figInd) + '.pdf', bbox_inches='tight')
  

#%%
maxER = 10
color1='slategrey'
color2='slategrey'

#%%
figInd += 1
f=plt.figure(figInd)
f.clear()
b=1
for a in range(1,maxER+1):
    p, rrs = param_results(a,b)
Exemple #5
0
#%%

figInd = 0
lw = 0.7
alphas = [1e0, 1e-5, 1e-10]

figInd += 1
plt.figure(figInd)
plt.clf()

for alpha in alphas:
    N = 20
    rets = experiment(N=N, alpha=alpha)
    lps = rets[1]
    experiences = rets[7]
    posts = rets[8]

    plt.plot(np.arange(N) + 1,
             -(lps[:, 0] - lps[:, 1]),
             label=r'$\alpha$ = {:.0e}'.format(alpha))
xlims = plt.xlim()
plt.ylim((-50 / 2, 50 / 2))
adjustPlot(plt.gca(), fuzzyzero=True)
plt.legend()
plt.xlabel('# of experiences')
plt.ylabel('Negative Partition Evidence Ratio')

#%%
plt.savefig('figures/' + filename + '-' + str(figInd) + '.pdf',
            bbox_inches='tight')