예제 #1
0
def load_config():
    config_parser = ConfigParser.RawConfigParser()
    config_parser.read(options['load'])
    if not config_parser.has_section('Result'):
        raise IOError("Invalid configuration file.")

    moments   = config.readMatrix(config_parser, 'Result', 'moments',   float)
    density = config.readMatrix(config_parser, 'Result', 'density', float)
    mpost     = config.readVector(config_parser, 'Result', 'mpost',     float)
    if config_parser.has_option('Result', 'bprob'):
        bprob = config.readVector(config_parser, 'Result', 'bprob',     float)
    else:
        bprob     = []
    result = {
        'moments'   : moments,
        'density' : density,
        'bprob'     : bprob,
        'mpost'     : mpost }
    return result
예제 #2
0
def parseConfig(config_file):
    config_parser = ConfigParser.RawConfigParser()
    config_parser.read(config_file)

    if config_parser.sections() == []:
        raise IOError("Invalid configuration file.")
    if config_parser.has_section('Counts'):
        config.readVisualization(config_parser, 'Counts', os.path.dirname(config_file), options)
        config.readAlgorithm(config_parser, 'Counts', os.path.dirname(config_file), options)
        config.readMgsSamples(config_parser, 'Counts', os.path.dirname(config_file), options)
        counts = config.readCounts(config_parser, 'Counts')
        K, L   = len(counts), len(counts[0])
        alpha, beta, gamma = config.getParameters(config_parser, 'Counts', os.path.dirname(config_file), K, L)
        result = call_posterior(counts, alpha, beta, gamma)
        if options['save']:
            saveResult(result)
        else:
            if options['savefig']:
                importMatplotlib('Agg')
                from matplotlib.pyplot import savefig
                vis.plotBinning(result, options)
                savefig(options['savefig'], bbox_inches='tight', pad_inches=0)
            else:
                importMatplotlib()
                from matplotlib.pyplot import show
                vis.plotBinning(result, options)
                show()
    if config_parser.has_section('Trials'):
        config.readVisualization(config_parser, 'Trials', os.path.dirname(config_file), options)
        config.readAlgorithm(config_parser, 'Trials', os.path.dirname(config_file), options)
        config.readMgsSamples(config_parser, 'Trials', os.path.dirname(config_file), options)
        binsize   = config_parser.getint('Trials', 'binsize')
        timings   = config.readMatrix(config_parser, 'Trials', 'timings', int)
        srange    = None
        if config_parser.has_option('Trials', 'range'):
            srange = config.readVector(config_parser, 'Trials', 'range', int)
        x, counts = timingsToCounts(timings, binsize, srange)
        K, L   = len(counts), len(counts[0])
        alpha, beta, gamma = config.getParameters(config_parser, 'Trials', os.path.dirname(config_file), K, L)
        result    = call_posterior(counts, alpha, beta, gamma)
        if options['save']:
            saveResult(result)
        else:
            if options['savefig']:
                importMatplotlib('Agg')
                from matplotlib.pyplot import savefig
                vis.plotBinningSpikes(x, timings, result, options)
                savefig(options['savefig'], bbox_inches='tight', pad_inches=0)
            else:
                importMatplotlib()
                from matplotlib.pyplot import show
                vis.plotBinningSpikes(x, timings, result, options)
                show()
def loadResult():
    if options['load']:
        config_parser = ConfigParser.RawConfigParser()
        config_parser.read(options['load'])
        if not config_parser.has_section('Sampling Result'):
            raise IOError("Invalid configuration file.")

        distances = []
        bprob     = []

        counts    = config.readMatrix(config_parser, 'Sampling Result', 'counts',  int)
        moments   = config.readMatrix(config_parser, 'Sampling Result', 'moments', float)
        density   = config.readMatrix(config_parser, 'Sampling Result', 'density', float)
        samples   = config.readVector(config_parser, 'Sampling Result', 'samples', int)
        mpost     = config.readVector(config_parser, 'Sampling Result', 'mpost',   float)
        states    = config.readStates(config_parser, 'Sampling Result', 'states')
        if config_parser.has_option('Sampling Result', 'distances'):
            distances = config.readVector(config_parser, 'Sampling Result', 'distances', float)
        if config_parser.has_option('Sampling Result', 'bprob'):
            bprob = config.readVector(config_parser, 'Sampling Result', 'bprob',   float)
        result = {
            'distances' : distances,
            'moments'   : moments,
            'density'   : density,
            'bprob'     : bprob,
            'mpost'     : mpost,
            'counts'    : counts,
            'samples'   : samples,
            'states'    : states }
    else:
        result = {
            'distances' : [],
            'moments'   : [],
            'density'   : [],
            'bprob'     : [],
            'mpost'     : [],
            'counts'    : [],
            'samples'   : [],
            'states'    : [] }
    return result