Example #1
0
    def __init__(self, parameters, target, repetitions, db_name, transform=dont_transform):
        print("v. 0.3")
        fixed_parameters, lower_limits, upper_limits, dtypes = split(parameters)
        SimulationSet.setup(dtypes, target, transform)
        InputSet.setup(lower_limits, upper_limits, dtypes, fixed_parameters)
        self.repetitions = repetitions
        self.remote_saudifirms = RemoteSaudiFirms(task=5007, result=5008, kill=5009)
        self.local_saudifirms = RemoteSaudiFirms(task=5567, result=5568, kill=5569)

        self._db = dataset.connect("sqlite:///%s.sqlite3" % db_name)
        parameters = json.dumps(sorted(fixed_parameters.items()))
        hash = sha224(parameters).hexdigest()[:7]
        overview = self._db['overview']
        overview.insert({'hash': hash, 'json_string': parameters})
        self.db = self._db[hash]
        self.db_name = db_name
 def insert(self, input, metric):
     """
     inserts an array into the data
     :param input: ndarray
     :
     """
     assert isinstance(input, np.ndarray)
     input = InputSet.respect_bounds(input)
     if not self.is_in_data(input):
         self.inputs.append(input)
         self.metrics.append(metric)
Example #3
0
    def initialize(self, initial_runs):
        self.simulations = SimulationSet()
        for row in self.db:
            try:
                input = json.loads(row['input'])
                output = json.loads(row['output'])
            except TypeError:
                logger.info(row['output'])
            self.simulations.insert(input, output)
        logger.info("loaded %i" % len(self.simulations))

        if len(self.simulations) < initial_runs:
            middle_point = InputSet.middle_point()
            simulation_candidates = centered_latin_hypercube_I(middle_point, np.ones_like(middle_point), InputSet.lb, InputSet.ub, initial_runs)
            self.run_add(simulation_candidates)
        print("done loading/initializing")
Example #4
0
 def print_dict(self):
     inputset = InputSet()
     inputset.insert(InputSet.middle_point())
     logger.info(dict(inputset[0]))
Example #5
0
 def run_input(self, weight=0.5):
     self.run_local(InputSet.weight_point(weight))
Example #6
0
                        x_min = float(target[j])
                else:
                    if float(output[j]) < float(target[j]):
                        if float(output[j]) < x_min:
                            x_min = float(output[j])
                    else:
                        if float(target[j]) < x_min:
                            x_min = float(target[j])
            sum_error += error
        mse = sum_error / test.size()
        rms = numpy.sqrt(mse)
        return rms/(x_max-x_min)

if __name__ == "__main__":

    data_set = InputSet()
    data_set.load("../data/servo.data")

    #<<ID: 487; SCORE: 0.20303 [{q:0.937668}{h:17}{c:144,54,41,81,85,52,140,67,48,138,95,110,6,32,5,86,22}{gamma:0.996954,2.48103,0.602891,3,1.42868,0.0979053,3,1.21504,0.922433,0.357251,0.131358,1.23423,0,0,0.299883,0.263622,1.9044}{lambda:0.0446531}]>>
    #centers = [144,54,41,81,85,52,140,68,48,138,95,110,6,32,5,86,22]
    #gammas = [0.996954,2.48103,1.602891,3,1.42868,0.0979053,3,1.21504,0.922433,0.357251,0.131358,1.23423,0,0,0.299883,0.263622,1.9044]
    #q = 0.937668
    #l = 0.0446531
    #hnn3 = HNN3(data_set, centers, gammas, q, l, "cls")
    #print str(hnn3.get_accuracy()*100) + "%"

    #<<ID: 28724; SCORE: 0.180124 [{q:0.254867}{h:41}{c:33,104,136,22,30,83,0,138,12,63,130,17,10,147,18,42,139,152,71,31,45,140,124,109,59,13,20,27,102,1,68,97,132,129,149,34,85,123,87,116,134}{gamma:0.963652,1.22752,0.502414,2.06288,0.957675,0.527096,2.29231,2.58408,0.419801,1.09144,0.742667,0.613447,0.301913,1.21125,0.695696,2.16505,0.0783844,0.550067,1.94488,0.679182,1.83098,0.42336,2.02004,0.700278,0.938683,1.02612,2.87757,0.962745,1.6509,0.88908,2.14539,0.078447,0.064547,1.38313,0.0152284,1.5391,0.87585,0.50174,2.01498,0.384209,1.39222}{lambda:0.140671}]>>
    #centers2 = [33,104,136,22,30,83,0,138,12,63,130,17,10,147,18,42,139,152,71,31,45,140,124,109,59,13,20,27,102,1,68,97,132,129,149,34,85,123,87,116,134]
    #gammas2 = [0.963652,1.22752,0.502414,2.06288,0.957675,0.527096,2.29231,2.58408,0.419801,1.09144,0.742667,0.613447,0.301913,1.21125,0.695696,2.16505,0.0783844,0.550067,1.94488,0.679182,1.83098,0.42336,2.02004,0.700278,0.938683,1.02612,2.87757,0.962745,1.6509,0.88908,2.14539,0.078447,0.064547,1.38313,0.0152284,1.5391,0.87585,0.50174,2.01498,0.384209,1.39222]
    #q2 = 0.254867
    #hnn3_2 = HNN3(data_set, centers2, gammas2, q2, "cls")
Example #7
0
        l = self.genoma[1].genes[0]
        centers = self.genoma[3].genes
        gammas = self.genoma[4].genes
        hnn3 = HNN3(self.data_set, centers, gammas, q, l)
        return hnn3

    def update_score(self):
        if self.data_set.mode == "cls":
            self.score = self.__fitness_function_classification()
        else:
            self.score = self.__fitness_function_regression()

    def __str__(self):
        s = "<< ID: " + str(self.id) + ", SCORE: " + str(self.score)
        for i, v in enumerate(self.genoma):
            s = s + " { " + str(v) + " } "
        s += ">>"
        return s


if __name__ == "__main__":
    data_set = InputSet()
    data_set.load("hepatitis.data")
    ind = IndividualHNN3(data_set)
    ind.update_score()
    print ind
    for i in range(20):
        o = ind.mutate()
        print o
        o.update_score()
Example #8
0
def centered_latin_hypercube_I(center, schlinge, lb, ub, samples):
    ret_lh = _centered_latin_hypercube(center, schlinge, lb, ub, samples)
    candidates = InputSet()
    for input in ret_lh:
        candidates.insert(input)
    return candidates
Example #9
0
                else:
                    if float(output[j]) < float(target[j]):
                        if float(output[j]) < x_min:
                            x_min = float(output[j])
                    else:
                        if float(target[j]) < x_min:
                            x_min = float(target[j])
            sum_error += error
        mse = sum_error / test.size()
        rms = numpy.sqrt(mse)
        return rms / (x_max - x_min)


if __name__ == "__main__":

    data_set = InputSet()
    data_set.load("../data/servo.data")

    #<<ID: 487; SCORE: 0.20303 [{q:0.937668}{h:17}{c:144,54,41,81,85,52,140,67,48,138,95,110,6,32,5,86,22}{gamma:0.996954,2.48103,0.602891,3,1.42868,0.0979053,3,1.21504,0.922433,0.357251,0.131358,1.23423,0,0,0.299883,0.263622,1.9044}{lambda:0.0446531}]>>
    #centers = [144,54,41,81,85,52,140,68,48,138,95,110,6,32,5,86,22]
    #gammas = [0.996954,2.48103,1.602891,3,1.42868,0.0979053,3,1.21504,0.922433,0.357251,0.131358,1.23423,0,0,0.299883,0.263622,1.9044]
    #q = 0.937668
    #l = 0.0446531
    #hnn3 = HNN3(data_set, centers, gammas, q, l, "cls")
    #print str(hnn3.get_accuracy()*100) + "%"

    #<<ID: 28724; SCORE: 0.180124 [{q:0.254867}{h:41}{c:33,104,136,22,30,83,0,138,12,63,130,17,10,147,18,42,139,152,71,31,45,140,124,109,59,13,20,27,102,1,68,97,132,129,149,34,85,123,87,116,134}{gamma:0.963652,1.22752,0.502414,2.06288,0.957675,0.527096,2.29231,2.58408,0.419801,1.09144,0.742667,0.613447,0.301913,1.21125,0.695696,2.16505,0.0783844,0.550067,1.94488,0.679182,1.83098,0.42336,2.02004,0.700278,0.938683,1.02612,2.87757,0.962745,1.6509,0.88908,2.14539,0.078447,0.064547,1.38313,0.0152284,1.5391,0.87585,0.50174,2.01498,0.384209,1.39222}{lambda:0.140671}]>>
    #centers2 = [33,104,136,22,30,83,0,138,12,63,130,17,10,147,18,42,139,152,71,31,45,140,124,109,59,13,20,27,102,1,68,97,132,129,149,34,85,123,87,116,134]
    #gammas2 = [0.963652,1.22752,0.502414,2.06288,0.957675,0.527096,2.29231,2.58408,0.419801,1.09144,0.742667,0.613447,0.301913,1.21125,0.695696,2.16505,0.0783844,0.550067,1.94488,0.679182,1.83098,0.42336,2.02004,0.700278,0.938683,1.02612,2.87757,0.962745,1.6509,0.88908,2.14539,0.078447,0.064547,1.38313,0.0152284,1.5391,0.87585,0.50174,2.01498,0.384209,1.39222]
    #q2 = 0.254867
    #hnn3_2 = HNN3(data_set, centers2, gammas2, q2, "cls")
        q = self.genoma[0].genes[0]
        l = self.genoma[1].genes[0]
        centers = self.genoma[3].genes
        gammas = self.genoma[4].genes
        hnn3 = HNN3(self.data_set, centers, gammas, q, l)
        return hnn3
    
    def update_score(self):
        if self.data_set.mode == "cls":
            self.score = self.__fitness_function_classification()
        else:
            self.score = self.__fitness_function_regression()

    def __str__(self):
        s = "<< ID: " + str(self.id) + ", SCORE: " + str(self.score)
        for i,v in enumerate(self.genoma):
            s = s + " { " + str(v) + " } "
        s += ">>"
        return s

if __name__ == "__main__":
    data_set = InputSet()
    data_set.load("hepatitis.data")
    ind = IndividualHNN3(data_set)
    ind.update_score()
    print ind
    for i in range(20):
        o = ind.mutate()
        print o
        o.update_score()