Beispiel #1
0
def cycle():
    objective_func = array([10, -57, -9, -24])
    constraint_lhs = array([[1 / 2, -11 / 2, -5 / 2, 9],
                            [1 / 2, -3 / 2, -1 / 2, 1], [1, 0, 0, 0]])
    constraint_rhs = array([0, 0, 1])
    return StandardLinearProgram(objective_func, constraint_lhs,
                                 constraint_rhs)
Beispiel #2
0
 def make_sample_from_input_sent(sent, vocab_word_corpus, vocab_word_emb):
     sent = [w.lower() for w in sent]
     x = []
     if vocab_word_corpus:
         word_ids_corpus = array([
             w for w in convert_str_to_id(
                 sent=sent, vocab=vocab_word_corpus, unk=UNK)
         ])
         x.append([word_ids_corpus])
     if vocab_word_emb:
         word_ids_emb = array([
             w for w in convert_str_to_id(
                 sent=sent, vocab=vocab_word_emb, unk=UNK)
         ])
         x.append([word_ids_emb])
     return x
Beispiel #3
0
    def make_batches(self, samples):
        """
        :param samples: 1D: n_samples, 2D: [x, m, y]
        :return 1D: n_batches, 2D: batch_size; elem=[x, m, y]
        """
        np.random.shuffle(samples)
        samples.sort(key=lambda sample: len(sample[0]))

        batches = []
        batch = []
        prev_n_words = len(samples[0][0])
        for sample in samples:
            n_words = len(sample[0])
            if len(batch) == self.argv.batch_size or prev_n_words != n_words:
                batches.append(map(lambda b: array(b), zip(*batch)))
                batch = []
                prev_n_words = n_words
            batch.append(sample)
        if batch:
            batches.append(map(lambda b: array(b), zip(*batch)))
        return batches
Beispiel #4
0
    def add_mark_to_sample(sample, mark):
        x = [x_i[0] for x_i in sample]
        prd_indices = [i for i, m in enumerate(mark[0]) if m]

        n_words = len(x[0])
        n_prds = len(prd_indices)

        mark_ids = [[0 for _ in xrange(n_words)] for _ in xrange(n_prds)]
        for i, prd_index in enumerate(prd_indices):
            mark_ids[i][prd_index] = 1
        mark_ids = array(mark_ids)

        batch = map(lambda m: x + [m], mark_ids)
        batch = map(lambda b: b, zip(*batch))
        return batch
Beispiel #5
0
def makeObservations(x,y,ripl):
    xString = genSamples(x)
    ripl.observe(xString, array(y))
Beispiel #6
0
def basic():
    objective_func = array([5, 4, 3])
    constraint_lhs = array([[2, 3, 1], [4, 1, 2], [3, 4, 2]])
    constraint_rhs = array([5, 11, 8])
    return StandardLinearProgram(objective_func, constraint_lhs,
                                 constraint_rhs)
Beispiel #7
0
def unbounded():
    objective_func = array([1, -1])
    constraint_lhs = array([[-2, 3], [0, 4], [0, -1]])
    constraint_rhs = array([5, 7, 0])
    return StandardLinearProgram(objective_func, constraint_lhs,
                                 constraint_rhs)
Beispiel #8
0
def klee_minty2():
    objective_func = array([4, 2, 1])
    constraint_lhs = array([[1, 0, 0], [4, 1, 0], [8, 4, 1]])
    constraint_rhs = array([5, 25, 125])
    return StandardLinearProgram(objective_func, constraint_lhs,
                                 constraint_rhs)
Beispiel #9
0
def klee_minty():
    objective_func = array([100, 10, 1])
    constraint_lhs = array([[1, 0, 0], [20, 1, 0], [200, 20, 1]])
    constraint_rhs = array([1, 100, 10000])
    return StandardLinearProgram(objective_func, constraint_lhs,
                                 constraint_rhs)
Beispiel #10
0
def need_init():
    objective_func = array([-2, -1])
    constraint_lhs = array([[-1, 1], [-1, -2], [0, 1]])
    constraint_rhs = array([-1, -2, 1])
    return StandardLinearProgram(objective_func, constraint_lhs,
                                 constraint_rhs)