예제 #1
0
def run_nns(testset, s_vectors, ticks=None, verbose=True):
    if ticks is None:
        ticks = range(len(s_vectors))
    ticks, N = set(ticks), len(ticks)

    avgs, stds = [], []
    nnset = learners.NNSet()
    for t, s_vector in enumerate(s_vectors):

        nnset.add((), s_vector)

        if t in ticks:
            if verbose:
                gfx.print_progress(len(avgs), N)
            errors = []
            for s_vector_goal in testset:
                distances, idx = nnset.nn_y(s_vector_goal, k=1)
                s_vector = nnset.ys[idx[0]]
                errors.append(dist(s_vector_goal, s_vector))
            avgs.append(np.mean(errors))
            stds.append(np.std(errors))

    if verbose:
        gfx.print_progress(N, N)

    return avgs, stds
예제 #2
0
def run_nns(testset, s_vectors, ticks=None, verbose=True):
    if ticks is None:
        ticks = range(len(s_vectors))
    ticks, N = set(ticks), len(ticks)

    avgs, stds = [], []
    nnset = learners.NNSet()
    for t, s_vector in enumerate(s_vectors):

        nnset.add((), s_vector)

        if t in ticks:
            if verbose:
                gfx.print_progress(len(avgs), N)
            errors = []
            for s_vector_goal in testset:
                distances, idx = nnset.nn_y(s_vector_goal, k=1)
                s_vector = nnset.ys[idx[0]]
                errors.append(dist(s_vector_goal, s_vector))
            avgs.append(np.mean(errors))
            stds.append(np.std(errors))

    if verbose:
        gfx.print_progress(N, N)

    return avgs, stds
예제 #3
0
def run_exploration(env, ex, N, mesh=None, verbose=False, prefix=""):
    explorations, s_vectors, s_goals = [], [], []

    for i in range(N):
        if verbose and i % 100 == 0:
            gfx.print_progress(i, N, prefix=prefix)
        exploration = ex.explore()
        feedback = env.execute(exploration["m_signal"])
        ex.receive(exploration, feedback)
        s_vectors.append(tools.to_vector(feedback["s_signal"], env.s_channels))
        if "s_goal" in exploration:
            s_goals.append(tools.to_vector(exploration["s_goal"], env.s_channels))
        if mesh is not None:
            mesh.add(feedback["s_signal"], m_signal=exploration["m_signal"])
        explorations.append((exploration, feedback))
    if verbose:
        gfx.print_progress(N, N, prefix=prefix)

    return explorations, s_vectors, s_goals
예제 #4
0
def run_exploration(env, ex, N, mesh=None, verbose=False, prefix=''):
    explorations, s_vectors, s_goals = [], [], []

    for i in range(N):
        if verbose and i % 100 == 0:
            gfx.print_progress(i, N, prefix=prefix)
        exploration = ex.explore()
        feedback = env.execute(exploration['m_signal'])
        ex.receive(exploration, feedback)
        s_vectors.append(tools.to_vector(feedback['s_signal'], env.s_channels))
        if 's_goal' in exploration:
            s_goals.append(
                tools.to_vector(exploration['s_goal'], env.s_channels))
        if mesh is not None:
            mesh.add(feedback['s_signal'], m_signal=exploration['m_signal'])
        explorations.append((exploration, feedback))
    if verbose:
        gfx.print_progress(N, N, prefix=prefix)

    return explorations, s_vectors, s_goals