import time

import numpy as np
import yaml

import quantitation

# Set parameters
path_cfg = 'examples/basic.yml'

# Load config
cfg = yaml.load(open(path_cfg, 'rb'))

# Load data
mapping_peptides = np.loadtxt(cfg['data']['path_mapping_peptides'],
                              dtype=np.int)
mapping_states_obs, intensities_obs = np.loadtxt(cfg['data']['path_data_state'],
                                                 dtype=[('peptide', np.int),
                                                        ('intensity',
                                                         np.float)],
                                                 unpack=True)

# Run MCMC sampler
time_start = time.time()
draws, accept_stats = quantitation.mcmc_serial(intensities_obs,
                                               mapping_states_obs,
                                               mapping_peptides, cfg)
time_done = time.time()

# Print timing information
print "%f seconds for %d iterations" % (time_done-time_start,
                                        cfg['settings']['n_iterations'])
print "%f seconds per iteration" % ((time_done-time_start) /
                                    (0.+cfg['settings']['n_iterations']))

# Extract posterior means
means = {}
for k, x in draws.iteritems():
    means[k] = np.mean(x, 0)


Add basic test script for mcmc_serial. Code now passes with conditions on prior.
Add basic test script for mcmc_serial. Code now passes with conditions on prior.

Code runs with all prior inputs on ups2 and simulated data. However, variance
hyperparameters exhibit issues when used with improper priors on the rate
parameter. The shape and rate parameters diverge towards infinity as their ratio
(the expected precision) remains fixed. All logic and mathematics have been
checked extremely carefully and no errors appear to remain. I believe, at this
point, that the given problem arises from posterior impropriety. This needs to
be checked mathematically, likely on a simpler hierarchical model with no
missing data, two layers of variance parameters, and three layers of normal
means/observations.
