Exemplo n.º 1
0
 def ook_decode_distribution(self, array):
     assert len(array) == len(self), "%d != %d" % (len(array), len(self))
     check.check_pdist(array)
     return {
         self.decode(i): probability
         for i, probability in enumerate(array)
     }
Exemplo n.º 2
0
 def sampling_ook_decode(self, array):
     assert len(array) == len(self), "%d != %d" % (len(array), len(self))
     check.check_pdist(array)
     # Sample 1 thing                    v
     #  from [0..N]           vvvvvvvvv
     #   with probabilties                  vvvvvvv
     index = np.random.choice(len(self), 1, p=array)[0]
     return self.decode(index)
Exemplo n.º 3
0
    def ook_decode(self, array):
        assert len(array) == len(self), "%d != %d" % (len(array), len(self))
        check.check_pdist(array)

        # If the array is all zeros
        if not np.any(array):
            return None

        # The index of the maximum value from the ook_encoding.
        #                  vvvvvvvvvvvvvv
        return self.decode(array.argmax())
Exemplo n.º 4
0
 def __init__(self, scope, output_labels, output_distribution):
     super(CustomOutput, self).__init__(scope)
     self.output_labels = check.check_instance(output_labels, mlbase.Labels)
     self.output_distribution = check.check_pdist(output_distribution)
     assert len(self.output_labels) == len(
         self.output_distribution), "%d != %d" % (len(
             self.output_labels), len(self.output_distribution))
Exemplo n.º 5
0
    def ook_encode(self, value, handle_unknown=False):
        encoding = [0] * len(self)

        if isinstance(value, dict):
            for key, probability in check.check_pdist(value).items():
                encoding[self.encode(key, handle_unknown)] = probability
        else:
            encoding[self.encode(value, handle_unknown)] = 1

        return np.array(encoding, dtype="float32")
Exemplo n.º 6
0
 def vector_decode_probability(self, array, value, handle_oov=False):
     assert len(array) == len(self), "%d != %d" % (len(array), len(self))
     check.check_pdist(array)
     return array[self.encode(value, handle_oov)]
Exemplo n.º 7
0
 def __init__(self, prediction, distribution, encoding):
     self.prediction = prediction
     self.distribution = check.check_pdist(distribution)
     self.encoding = encoding