Exemple #1
0
def compute_test_accuracy(model):
    test_words, test_tags = zip(*[zip(*sentence) for sentence in test_data])
    test_words, test_tags = to_matrix(test_words, word_to_id), to_matrix(
        test_tags, tag_to_id)

    # predict tag probabilities of shape [batch,time,n_tags]
    predicted_tag_probabilities = model.predict(test_words, verbose=1)
    predicted_tags = predicted_tag_probabilities.argmax(axis=-1)

    # compute accurary excluding padding
    numerator = np.sum(
        np.logical_and((predicted_tags == test_tags), (test_words != 0)))
    denominator = np.sum(test_words != 0)
    return float(numerator) / denominator
    def update(self, dt):
        """Update the building template.

        This method just applies the current position of the entity to the
        renderable transform.

        :param dt: Time delta from last update.
        :type dt: float
        """
        x, y = self.pos

        m_x, m_y = to_matrix(x, y, self.scale_factor)
        if not in_matrix(self.matrix, m_x, m_y) or not self.matrix[m_y][m_x]:
            self.props.material.color = self.NON_BUILDABLE_COLOR
        else:
            self.props.material.color = self.BUILDABLE_COLOR

        self.obj.position = to_scene(x, y)
        self.obj.scale = Vec(1.05, 1.05, 1.05)
Exemple #3
0
    def update(self, dt):
        """Update the building template.

        This method just applies the current position of the entity to the
        renderable transform.

        :param dt: Time delta from last update.
        :type dt: float
        """
        x, y = self.pos

        m_x, m_y = to_matrix(x, y, self.scale_factor)
        if not in_matrix(self.matrix, m_x, m_y) or not self.matrix[m_y][m_x]:
            self[Renderable].node.params.update(self.NON_BUILDABLE_COLOR)
        else:
            self[Renderable].node.params.update(self.BUILDABLE_COLOR)

        t = self[Renderable].transform
        t.identity()
        t.translate(to_scene(x, y))
        t.scale(Vec(1.05, 1.05, 1.05))
def set_cell_walkable(evt):
    """Set a cell as walkable in the debug terrain."""
    context = evt.context
    x, y = to_matrix(evt.pos[0], evt.pos[1], context.scale_factor)
    if in_matrix(context.matrix, x, y):
        context.matrix[y][x] = True
Exemple #5
0
def set_cell_walkable(evt):
    """Set a cell as walkable in the debug terrain."""
    context = evt.context
    x, y = to_matrix(evt.pos[0], evt.pos[1], context.scale_factor)
    if in_matrix(context.matrix, x, y):
        context.matrix[y][x] = True
Exemple #6
0
        #q_values[(state, action)] += stats.alpha(state, action) * td_error

        for i in trajectory:
            st, ac = i
            q_values[(st, ac)] += alpha * td_error * stats.trace[(st, ac)]
            stats.decay_trace(st, ac, GAMMA, LAMBDA)

        state = new_state
        action = new_action

print('win: %d, lose: %d, draw: %d' % (sum(win), sum(lose), sum(draw)))
print('win: %0.1f%%, lose: %0.1f%%, draw: %0.1f%%' \
      %(sum(win)/EPISODES * 100, sum(lose)/EPISODES * 100, sum(draw)/EPISODES * 100))
print('usable ace: %0.2f%%' % (has_ace / EPISODES * 100))

q_value_matrix = to_matrix(q_values.dump_values())

fn = save_data(data=q_value_matrix \
      , prefix='sarsa-lambda' + ('-biased' if use_bias_env else ''), iterations=EPISODES)
print('Saved %s' % fn)

x = np.arange(len(win))

plt.scatter(x, win, label='WIN', color='green', s=1)
plt.scatter(x, lose, label='LOSE', color='red', s=1)
plt.scatter(x, draw, label='DRAW', color='blue', s=1)

l = u'λ'
plt.title('SARSA(%s=%0.1f)' % (u'λ', LAMBDA))

plt.legend()