def initialize_parallel_test_harness():
    # Parse command line args
    (options, args) = parse_cmd_line_args()

    # Load data from file or create synthetic test dataset
    data = load_data(options)

    print "Creating master population object"
    model = make_model(options.model, N=data['N'])
    stabilize_sparsity(model)
    popn = Population(model)
    popn.set_data(data)

    # Initialize the GLM with the data
    popn_true = None
    x_true = None
    if 'vars' in data:
        x_true = data['vars']

        # Load the true model
        data_dir = os.path.dirname(options.dataFile)
        model_file = os.path.join(data_dir, 'model.pkl')
        print "Loading true model from %s" % model_file
        with open(model_file) as f:
            model_true = cPickle.load(f)
            # HACK FOR EXISTING DATA!
            if 'N_dims' not in model_true['network']['graph']:
                model_true['network']['graph']['N_dims'] = 1
            if 'location_prior' not in model_true['network']['graph']:
                model_true['network']['graph']['location_prior'] = \
                         {
                             'type' : 'gaussian',
                             'mu' : 0.0,
                             'sigma' : 1.0
                         }
            if 'L' in x_true['net']['graph']:
                x_true['net']['graph']['L'] = x_true['net']['graph'][
                    'L'].ravel()
            # END HACK

            popn_true = Population(model_true)
            popn_true.set_data(data)

    # Create a client with direct view to all engines
    if options.json is not None:
        client = Client(options.json)
    else:
        client = Client(profile=options.profile)
    dview = client[:]
    print "Found %d engines." % len(dview)

    print "Initializing imports on each engine"
    initialize_imports(dview)

    print "Creating population objects on each engine"
    create_population_on_engines(dview, data, options.model)

    return options, popn, data, client, popn_true, x_true
def initialize_test_harness():
    """ Initialize a model with N neurons. Use the data if specified on the
        command line, otherwise sample new data from the model.
        Return a population object, the data, and a set of true parameters
        which is expected for synthetic tests 
    """
    # Parse command line args
    (options, args) = parse_cmd_line_args()

    # Load data from file or create synthetic test dataset
    data = load_data(options)

    print "Creating master population object"
    model = make_model(options.model, N=data['N'], dt=0.001)
    stabilize_sparsity(model)
    popn = Population(model)
    popn.add_data(data)

    # Initialize the GLM with the data
    popn_true = None
    x_true = None
    if 'vars' in data:
        x_true = data['vars']

        # Load the true model
        model_true = None
        data_dir = os.path.dirname(options.dataFile)
        model_file = os.path.join(data_dir, 'model.pkl')
        print "Loading true model from %s" % model_file
        with open(model_file) as f:
            model_true = cPickle.load(f)
            # HACK FOR EXISTING DATA!
            if 'N_dims' not in model_true['network']['graph']:
                model_true['network']['graph']['N_dims'] = 1
            if 'location_prior' not in model_true['network']['graph']:
                model_true['network']['graph']['location_prior'] = \
                         {
                             'type' : 'gaussian',
                             'mu' : 0.0,
                             'sigma' : 1.0
                         }
            if 'L' in x_true['net']['graph']:
                x_true['net']['graph']['L'] = x_true['net']['graph'][
                    'L'].ravel()
            # END HACK

            popn_true = Population(model_true)
            popn_true.add_data(data)
            ll_true = popn_true.compute_log_p(x_true)
            print "true LL: %f" % ll_true

    return options, popn, data, popn_true, x_true
def initialize_parallel_test_harness():
    # Parse command line args
    (options, args) = parse_cmd_line_args()

    # Load data from file or create synthetic test dataset
    data = load_data(options)

    print "Creating master population object"
    model = make_model(options.model, N=data["N"])
    stabilize_sparsity(model)
    popn = Population(model)
    popn.set_data(data)

    # Initialize the GLM with the data
    popn_true = None
    x_true = None
    if "vars" in data:
        x_true = data["vars"]

        # Load the true model
        data_dir = os.path.dirname(options.dataFile)
        model_file = os.path.join(data_dir, "model.pkl")
        print "Loading true model from %s" % model_file
        with open(model_file) as f:
            model_true = cPickle.load(f)
            # HACK FOR EXISTING DATA!
            if "N_dims" not in model_true["network"]["graph"]:
                model_true["network"]["graph"]["N_dims"] = 1
            if "location_prior" not in model_true["network"]["graph"]:
                model_true["network"]["graph"]["location_prior"] = {"type": "gaussian", "mu": 0.0, "sigma": 1.0}
            if "L" in x_true["net"]["graph"]:
                x_true["net"]["graph"]["L"] = x_true["net"]["graph"]["L"].ravel()
            # END HACK

            popn_true = Population(model_true)
            popn_true.set_data(data)

    # Create a client with direct view to all engines
    if options.json is not None:
        client = Client(options.json)
    else:
        client = Client(profile=options.profile)
    dview = client[:]
    print "Found %d engines." % len(dview)

    print "Initializing imports on each engine"
    initialize_imports(dview)

    print "Creating population objects on each engine"
    create_population_on_engines(dview, data, options.model)

    return options, popn, data, client, popn_true, x_true
def initialize_test_harness():
    """ Initialize a model with N neurons. Use the data if specified on the
        command line, otherwise sample new data from the model.
        Return a population object, the data, and a set of true parameters
        which is expected for synthetic tests 
    """
    # Parse command line args
    (options, args) = parse_cmd_line_args()

    # Load data from file or create synthetic test dataset
    data = load_data(options)
    
    print "Creating master population object"
    model = make_model(options.model, N=data['N'], dt=0.001)
    stabilize_sparsity(model)
    popn = Population(model)
    popn.add_data(data)

    # Initialize the GLM with the data
    popn_true = None
    x_true = None
    if 'vars' in data:
        x_true = data['vars']
        
        # Load the true model 
        model_true = None
        data_dir = os.path.dirname(options.dataFile)
        model_file = os.path.join(data_dir, 'model.pkl')
        print "Loading true model from %s" % model_file
        with open(model_file) as f:
            model_true = cPickle.load(f)
            # HACK FOR EXISTING DATA!
            if 'N_dims' not in model_true['network']['graph']:
                model_true['network']['graph']['N_dims'] = 1
            if 'location_prior' not in model_true['network']['graph']:
                model_true['network']['graph']['location_prior'] = \
                         {
                             'type' : 'gaussian',
                             'mu' : 0.0,
                             'sigma' : 1.0
                         }
            if 'L' in x_true['net']['graph']:
                x_true['net']['graph']['L'] = x_true['net']['graph']['L'].ravel()
            # END HACK

            popn_true = Population(model_true)
            popn_true.add_data(data)
            ll_true = popn_true.compute_log_p(x_true)
            print "true LL: %f" % ll_true

    return options, popn, data, popn_true, x_true
Beispiel #5
0
import os
import numpy as np

import matplotlib
if 'DISPLAY' not in os.environ:
    matplotlib.use('Agg')
import matplotlib.pyplot as plt

from pyglm.utils.io import parse_cmd_line_args, load_data
from pyglm.utils.sta import sta

# Parse command line args
(options, args) = parse_cmd_line_args()
# Load data and model
data = load_data(options)
stim = data['stim']
spks = data['S']

# Plot the STA at various lags
maxlag = 100
lags_to_plot = np.arange(maxlag, step=20)

# Downsample the spikes to the resolution of the stimulus
Tspks, N = spks.shape
Tstim = stim.shape[0]
# Flatten higher dimensional stimuli
if stim.ndim == 3:
    stimf = stim.reshape((Tstim, -1))
else:
    stimf = stim
Beispiel #6
0
import os
import numpy as np

import matplotlib
if 'DISPLAY' not in os.environ:
    matplotlib.use('Agg')
import matplotlib.pyplot as plt

from pyglm.utils.io import parse_cmd_line_args, load_data
from pyglm.utils.sta import sta

# Parse command line args
(options, args) = parse_cmd_line_args()
# Load data and model
data = load_data(options)
stim = data['stim']
spks = data['S']

# Plot the STA at various lags
maxlag = 100
lags_to_plot = np.arange(maxlag, step=20)


# Downsample the spikes to the resolution of the stimulus
Tspks, N = spks.shape
Tstim = stim.shape[0]
# Flatten higher dimensional stimuli
if stim.ndim == 3:
    stimf = stim.reshape((Tstim, -1))
else:
    stimf = stim