Esempio n. 1
0
def plot_fits(m):
    # set font
    book_graphics.set_font()
    
    pl.figure(**book_graphics.three_quarter_plus_page_params)
    for ii in range(2):
        pl.subplot(1, 2, ii+1)
        model = m[ii]
        #
        graphics.plot_data_bars(model.input_data, color='grey', label='Simulated data')
        #
        pl.plot(model.ages, model.pi_age_true, 'w-', linewidth=3)
        pl.plot(model.ages, model.pi_age_true, 'k--', label='Truth')
        #
        #pl.plot(model.ages, model.vars['mu_age'].trace().T, '-', color='grey', alpha=.1)
        pl.plot(model.ages, model.vars['mu_age'].stats()['mean'], 'w-', linewidth=4)
        pl.plot(model.ages, model.vars['mu_age'].stats()['mean'], 'k-', linewidth=2, label='Posterior mean')

        pl.plot(model.ages, model.vars['mu_age'].stats()['95% HPD interval'][:,0], 'k-', label='Uncertainty interval')
        pl.plot(model.ages, model.vars['mu_age'].stats()['95% HPD interval'][:,1], 'k-')
        
        #
        if ii == 0:
            pl.legend(fancybox=True, shadow=True, loc='upper center', bbox_to_anchor=(1.15,-.2), ncol=2)
        pl.xlabel('Age (years)')
        pl.ylabel('Rate (per PY)')
        pl.axis([-5, 105, -.05, 1.])
        pl.yticks([0, .25, .5, .75])
        pl.xticks(fontsize='large')
        book_graphics.subtitle('(%s)'%'ab'[ii])

    #pl.subplots_adjust(top=.87, bottom=.44, wspace=.35) # l b r t w h #(top=.93, bottom=.53, wspace=.35)
    pl.subplots_adjust(top=.9, bottom=.3, wspace=.35)
Esempio n. 2
0
def plot_trace(X, scale=1., angle=0.):
    fig = pl.figure(figsize=(12, 4.75))

    ax1 = fig.add_subplot(1, 2, 1)
    # plot boundary
    t = pl.arange(0, 2 * pl.pi, .01)
    ax1.plot(
        pl.cos(angle) * pl.cos(t) - pl.sin(angle) * pl.sin(t) / scale,
        pl.cos(angle) * pl.sin(t) / scale + pl.sin(angle) * pl.cos(t), 'k:')

    # plot samples
    if isinstance(X, mc.Stochastic):
        tr = [X.trace()[:, 0], X.trace()[:, 1]]
    else:
        tr = [X[0].trace(), X[1].trace()]

    ax1.plot(tr[0], tr[1], 'ko-')

    # decorate plot
    book_graphics.set_font()
    pl.xlabel('$X_1$')
    pl.ylabel('$X_2$', rotation=0)
    pl.axis([-1.1, 1.1, -1.1, 1.1])
    pl.text(-1, 1, '(a)', fontsize=16, va='top', ha='left')

    for i in range(2):
        if i == 0:
            ax2 = fig.add_subplot(2, 4, 3 + 4 * i)
            ax2.plot(tr[i], 'k', drawstyle='steps-mid')
        else:
            ax2a = fig.add_subplot(2, 4, 3 + 4 * i, sharex=ax2)
            ax2a.plot(tr[i], 'k', drawstyle='steps-mid')
            pl.xlabel('Sample')

        pl.xticks([25, 50, 75])
        pl.yticks([-.5, 0, .5])
        pl.ylabel('$X_%d$' % (i + 1), rotation=0)
        pl.axis([-5, 105, -1.5, 1.5])
        pl.text(-1, 1.25, '(%s)' % 'bc'[i], fontsize=16, va='top', ha='left')

        if i == 0:
            ax3 = fig.add_subplot(2, 4, 4 + 4 * i)
            ax3.acorr(tr[i].reshape(100), color='k')
        else:
            ax3a = fig.add_subplot(2, 4, 4 + 4 * i, sharex=ax3)
            ax3a.acorr(tr[i].reshape(100), color='k')
            pl.xlabel('Autocorrelation')

        pl.xticks([-5, 0, 5])
        pl.yticks([0., .5, 1])
        pl.axis([-12, 12, -.1, 1.1])
        pl.text(-10, 1, '(%s)' % 'de'[i], fontsize=16, va='top', ha='left')

    pl.setp(ax2.get_xticklabels(), visible=False)
    pl.setp(ax3.get_xticklabels(), visible=False)
    pl.subplots_adjust(wspace=.55, hspace=.1, bottom=.14, left=.13)
Esempio n. 3
0
File: ball.py Progetto: aflaxman/gbd
def plot_trace(X, scale=1., angle=0.):
    fig = pl.figure(figsize=(12,4.75))
    
    ax1 = fig.add_subplot(1, 2, 1)
    # plot boundary
    t = pl.arange(0,2*pl.pi,.01)
    ax1.plot(pl.cos(angle)*pl.cos(t) - pl.sin(angle)*pl.sin(t)/scale, pl.cos(angle)*pl.sin(t)/scale + pl.sin(angle)*pl.cos(t), 'k:')
    
    # plot samples
    if isinstance(X, mc.Stochastic):
        tr = [X.trace()[:,0], X.trace()[:,1]]
    else:
        tr = [X[0].trace(), X[1].trace()]

    ax1.plot(tr[0], tr[1], 'ko-')
        
    # decorate plot
    book_graphics.set_font()
    pl.xlabel('$X_1$')
    pl.ylabel('$X_2$', rotation=0)
    pl.axis([-1.1,1.1,-1.1,1.1])
    pl.text(-1,1,'(a)', fontsize=16, va='top', ha='left')

    
    for i in range(2):
        if i == 0:
            ax2 = fig.add_subplot(2, 4, 3+4*i)
            ax2.plot(tr[i], 'k', drawstyle='steps-mid')
        else:
            ax2a = fig.add_subplot(2, 4, 3+4*i, sharex=ax2)
            ax2a.plot(tr[i], 'k', drawstyle='steps-mid')
            pl.xlabel('Sample')
        
        pl.xticks([25,50,75])
        pl.yticks([-.5,0,.5])
        pl.ylabel('$X_%d$'%(i+1), rotation=0)
        pl.axis([-5,105,-1.5,1.5])
        pl.text(-1,1.25,'(%s)'%'bc'[i], fontsize=16, va='top', ha='left')
        
        if i == 0:
            ax3 = fig.add_subplot(2, 4, 4+4*i)
            ax3.acorr(tr[i].reshape(100), color='k')
        else:
            ax3a = fig.add_subplot(2, 4, 4+4*i, sharex=ax3)
            ax3a.acorr(tr[i].reshape(100), color='k')
            pl.xlabel('Autocorrelation')
        
        pl.xticks([-5,0,5])
        pl.yticks([0., .5, 1])
        pl.axis([-12,12,-.1,1.1])
        pl.text(-10,1,'(%s)'%'de'[i], fontsize=16, va='top', ha='left')
        
    pl.setp(ax2.get_xticklabels(), visible=False)
    pl.setp(ax3.get_xticklabels(), visible=False)
    pl.subplots_adjust(wspace=.55, hspace=.1, bottom=.14,left=.13)
Esempio n. 4
0
def plot_fits(m):
    # set font
    book_graphics.set_font()

    pl.figure(**book_graphics.three_quarter_plus_page_params)
    for ii in range(2):
        pl.subplot(1, 2, ii + 1)
        model = m[ii]
        #
        graphics.plot_data_bars(model.input_data,
                                color='grey',
                                label='Simulated data')
        #
        pl.plot(model.ages, model.pi_age_true, 'w-', linewidth=3)
        pl.plot(model.ages, model.pi_age_true, 'k--', label='Truth')
        #
        #pl.plot(model.ages, model.vars['mu_age'].trace().T, '-', color='grey', alpha=.1)
        pl.plot(model.ages,
                model.vars['mu_age'].stats()['mean'],
                'w-',
                linewidth=4)
        pl.plot(model.ages,
                model.vars['mu_age'].stats()['mean'],
                'k-',
                linewidth=2,
                label='Posterior mean')

        pl.plot(model.ages,
                model.vars['mu_age'].stats()['95% HPD interval'][:, 0],
                'k-',
                label='Uncertainty interval')
        pl.plot(model.ages,
                model.vars['mu_age'].stats()['95% HPD interval'][:, 1], 'k-')

        #
        if ii == 0:
            pl.legend(fancybox=True,
                      shadow=True,
                      loc='upper center',
                      bbox_to_anchor=(1.15, -.2),
                      ncol=2)
        pl.xlabel('Age (years)')
        pl.ylabel('Rate (per PY)')
        pl.axis([-5, 105, -.05, 1.])
        pl.yticks([0, .25, .5, .75])
        pl.xticks(fontsize='large')
        book_graphics.subtitle('(%s)' % 'ab'[ii])

    #pl.subplots_adjust(top=.87, bottom=.44, wspace=.35) # l b r t w h #(top=.93, bottom=.53, wspace=.35)
    pl.subplots_adjust(top=.9, bottom=.3, wspace=.35)
Esempio n. 5
0
def plot_system(panel):
    fig = pl.figure(**book_graphics.half_page_params)

    book_graphics.set_font()

    ax1 = fig.add_subplot(2, 4, 2)
    ax1.step(t, h_b, 'k-')
    pl.xticks(pl.arange(0, 100, 25))  #, fontsize='x-large')
    pl.yticks([0., .01, .02])  #, fontsize='x-large')
    pl.axis([-5, 105, 0, .03])
    pl.ylabel('$h_b(t)$', rotation='horizontal', fontsize='xx-large')

    ax2 = fig.add_subplot(2, 4, 6, sharex=ax1)
    ax2.step(t, h_m, 'k-')
    pl.yticks([0., .01, .02])  #, fontsize='x-large')
    pl.xticks(pl.arange(0, 100, 25))  #, fontsize='x-large')
    pl.axis([-5, 105, 0, .03])
    pl.ylabel('$h_m(t)$', rotation='horizontal', fontsize='xx-large')
    pl.xlabel('Age (years)')  #, fontsize='xx-large')

    pl.setp(ax1.get_xticklabels(), visible=False)
    pl.subplots_adjust(hspace=.2)

    pl.subplot(1, 2, 2)
    pl.plot(t, S_approx, 'k-')
    pl.xticks(pl.arange(0, 101, 25))  #, fontsize='x-large')
    pl.yticks(pl.arange(.5, 3.5, .5))  #, fontsize='x-large')
    pl.axis([-5, 105, .9, 3.1])
    pl.xlabel('Age (years)')  #, fontsize='xx-large')
    pl.ylabel('$S(t)$', rotation='horizontal', fontsize='xx-large')

    if panel == 'b':
        pl.axis([-5, 105, .9, 1.6])

    pl.axes([0, 0, 1, 1], frameon=False)
    pl.xticks([])
    pl.yticks([])
    pl.figtext(0, 1, '\n (%s)' % panel, ha='left', va='top', fontsize=16)

    pl.subplots_adjust(left=0, wspace=.7, top=.99, bottom=.14)
Esempio n. 6
0
def plot_system(panel):
    fig = pl.figure(**book_graphics.half_page_params)
    
    book_graphics.set_font()
    
    ax1 = fig.add_subplot(2, 4, 2)
    ax1.step(t, h_b, 'k-')
    pl.xticks(pl.arange(0, 100, 25))#, fontsize='x-large')
    pl.yticks([0., .01, .02])#, fontsize='x-large')
    pl.axis([-5, 105, 0, .03])
    pl.ylabel('$h_b(t)$', rotation='horizontal', fontsize='xx-large')
    
    ax2 = fig.add_subplot(2, 4, 6, sharex=ax1)
    ax2.step(t, h_m, 'k-')
    pl.yticks([0., .01, .02])#, fontsize='x-large')
    pl.xticks(pl.arange(0, 100, 25))#, fontsize='x-large')
    pl.axis([-5, 105, 0, .03])
    pl.ylabel('$h_m(t)$', rotation='horizontal', fontsize='xx-large')
    pl.xlabel('Age (years)')#, fontsize='xx-large')
    
    pl.setp(ax1.get_xticklabels(), visible=False)
    pl.subplots_adjust(hspace=.2)

    pl.subplot(1, 2, 2)
    pl.plot(t, S_approx, 'k-')
    pl.xticks(pl.arange(0, 101, 25))#, fontsize='x-large')
    pl.yticks(pl.arange(.5, 3.5, .5))#, fontsize='x-large')
    pl.axis([-5, 105, .9, 3.1])
    pl.xlabel('Age (years)')#, fontsize='xx-large')
    pl.ylabel('$S(t)$', rotation='horizontal', fontsize='xx-large')
    
    if panel == 'b':
        pl.axis([-5,105,.9,1.6])

    pl.axes([0,0,1,1], frameon=False)
    pl.xticks([])
    pl.yticks([])
    pl.figtext(0, 1, '\n (%s)'%panel, ha='left', va='top', fontsize=16)
    
    pl.subplots_adjust(left=0, wspace=.7, top=.99, bottom=.14)
Esempio n. 7
0
# add to path, to make importing possible
import sys
sys.path += ['..', '../tests']
import os
import pylab as pl
import pymc as mc

import book_graphics
reload(book_graphics)
import validate_age_group
reload(validate_age_group)
from validate_age_group import *

# set font
book_graphics.set_font()

fit_age_standardizing_model.fmt = '^-1w7'
fit_midpoint_model.fmt = 'o-1w5'
fit_midpoint_covariate_model.fmt = 'x-2k5'
fit_disaggregation_model.fmt = '*-1w13'


def plot_fits(m):
    # set font
    book_graphics.set_font()

    pl.figure(**book_graphics.three_quarter_plus_page_params)
    for ii in range(2):
        pl.subplot(1, 2, ii + 1)
        model = m[ii]
Esempio n. 8
0
import sys
sys.path += ['../gbd', '../gbd/book', '../dm3-computation_only/', '../dm3-computation_only/book']
import pylab as pl
import pymc as mc
import pandas

import dismod3
reload(dismod3)

import book_graphics
reload(book_graphics)
import matplotlib as mpl

# set font
book_graphics.set_font()

def my_axis(ymax):
    pl.axis([-5,105,-ymax/10.,ymax])
	
def load_new_model():
    try:
        model = dismod3.data.load('/home/j/Project/dismod/output/dm-32458')
    except:
        model = dismod3.data.load('/home/j/Project/dismod/dismod_status/prod/dm-32458')
    model.keep(areas=['europe_western'], sexes=['male', 'total'])
    model.input_data = model.input_data.drop(['x_lnASDR_B03.4.3'],1)
    model.input_data.ix[model.get_data('i').index, 'area'] = 'all'
    model.parameters['i']['fixed_effects']['x_sex'] = dict(dist='Normal', mu=0, sigma=.0001)
    return model

best_model = load_new_model()