def __init__(self, length=4, vocab_size=2, **kwargs):
        self._domain = domains.FixedLengthDiscreteDomain(vocab_size=vocab_size,
                                                         length=length)
        super(AlternatingChainIsingModel, self).__init__(**kwargs)

        if vocab_size % 2:
            raise ValueError('vocab_size must be even for '
                             'AlternatingChainIsingModel.')

        potentials = np.zeros(shape=[vocab_size, vocab_size], dtype=np.float32)
        for i in range(0, vocab_size, 2):
            potentials[i][i + 1] = 1.
            potentials[i + 1][i] = 1.

        self.potentials = tf.tile(potentials[tf.newaxis, :, :],
                                  [length - 1, 1, 1])

        self._global_optima = self._get_global_optima()
    def __init__(self,
                 length=8,
                 vocab_size=2,
                 seed=0,
                 fully_connected=False,
                 weight_variance=1.0,
                 **kwargs):
        self._domain = domains.FixedLengthDiscreteDomain(vocab_size=vocab_size,
                                                         length=length)
        super(IsingModel, self).__init__(**kwargs)

        random = np.random.RandomState(seed=seed)
        if fully_connected:
            self.potentials = tf.constant(random.normal(
                size=[length, length, vocab_size, vocab_size],
                scale=weight_variance),
                                          dtype=tf.float32)
        else:
            self.potentials = tf.constant(random.normal(
                size=[length - 1, vocab_size, vocab_size],
                scale=weight_variance),
                                          dtype=tf.float32)

        self._fully_connected = fully_connected
Beispiel #3
0
def build_domain(length=8, vocab_size=4, **kwargs):
    """Creates a `FixedLengthDiscreteDomain` with default arguments."""
    return domains.FixedLengthDiscreteDomain(length=length,
                                             vocab_size=vocab_size,
                                             **kwargs)