def get_stiminfo(stim_path):
    stim = Stimulus2D.load(stim_path)

    assert len(stim.operations) <= 2
    if len(stim.operations) == 2:
        assert stim.operations[0][0] == "flip"
        assert stim.operations[1][0] == "rotate"
        flipped = True
        theta = stim.operations[1][1]
    elif len(stim.operations) == 1:
        if stim.operations[0][0] == "rotate":
            flipped = False
            theta = stim.operations[0][1]
        elif stim.operations[0][0] == "flip":
            flipped = True
            theta = 0
    elif len(stim.operations) == 0:
        flipped = False
        theta = 0

    info = {
        'v0': stim._v.tolist(),
        'v1': stim.vertices.tolist(),
        'flipped': flipped,
        'theta': theta,
        'stimulus': stim_path.namebase.split("_")[0],
    }

    return info
예제 #2
0
def simulate(task):
    stim_path = task["stim_path"]
    model_name = task["model"]
    seed = task["seed"]
    data_path = path.Path(task["data_path"])
    model_opts = task["model_opts"]

    X = Stimulus2D.load(stim_path)
    Xa = X.copy_from_initial().vertices
    Xb = X.copy_from_vertices().vertices

    try:
        model_class = getattr(m, model_name)
    except AttributeError:
        raise ValueError("unhandled model: %s" % model_name)

    np.random.seed(seed)
    if not data_path.exists():
        data_path.makedirs()

    for iopt, opts in model_opts.iteritems():
        logger.info("Task '%s', part %s", task['task_name'], iopt)
        dest = data_path.joinpath("part_%s" % iopt)
        model = model_class(Xa, Xb, **opts)
        try:
            model.sample()
        except SystemExit:
            raise
        except:
            print traceback.format_exc()

        if dest.exists():
            dest.rmtree_p()
        model.save(dest)
예제 #3
0
def pytest_generate_tests(metafunc):
    if hasattr(metafunc.function, "full"):
        theta = sorted(range(0, 360, 45) + [39])
        flipped = [True, False]
    elif hasattr(metafunc.function, "once"):
        theta = [0]
        flipped = [False]
    elif hasattr(metafunc.function, "smallrot"):
        theta = [20, 340]
        flipped = [True, False]
    else:
        theta = [39]
        flipped = [True, False]

    all_argnames = ['theta', 'flipped', 'Xa', 'Xb', 'model']
    argnames = [x for x in metafunc.fixturenames if x in all_argnames]

    if len(argnames) == 0:
        return

    argvalues = []

    for t, f in product(theta, flipped):
        # create stimulus
        X = Stimulus2D.random(8)
        if f:
            X.flip([0, 1])
        X.rotate(t)
        Xa = X.copy_from_initial()
        Xb = X.copy_from_vertices()

        # create model
        model = metafunc.cls.cls(
            Xa.vertices, Xb.vertices,
            S_sigma=S_sigma,
            step=step,
            prior=prior)

        args = dict(theta=t, flipped=f, Xa=Xa, Xb=Xb, model=model)
        argvalues.append([args[x] for x in argnames])

    metafunc.parametrize(argnames, argvalues)
예제 #4
0
def X0():
    X = Stimulus2D.random(8)
    return X