Exemple #1
0
def getVector():
        vector, names = [], []
        try:
                coef = 0
                while True:
                        value, id = engine.setCoefficient(coef, 0)
                        engine.setCoefficient(coef, value) # TODO: HACK
                        vector.append(value)
                        names.append(id)
                        coef += 1
        except IndexError:
                pass
        return vector, names
Exemple #2
0
def runWorker(pipe, tests, vector):
        for coef in range(len(vector)):
                engine.setCoefficient(coef, vector[coef])
        passive = {}
        positions = [item[0] for item in tests]
        bestScores = None
        message = pipe.recv()
        while message != None:
                if message[0] == 'update':
                        bestScores = lastScores
                elif message[0] == 'next':
                        passive = dict(zip(positions, bestScores))
                elif message[0] == 'setCoefficient':
                        (command, coef, value) = message
                        engine.setCoefficient(coef, value)
                elif message[0] == 'evaluateVector':
                        (command, useCache) = message
                        sumSquaredErrors, lastScores, active = evaluateVector(tests, passive, useCache)
                        pipe.send((sumSquaredErrors, len(tests), active))
                message = pipe.recv()