def interation(self, inputs, target, lRate, oscillations, lwp): if (printT): print("in: ", inputs, " target: ", target) for i in self.nodes: node = self.nodes[i] weightsOld = node.weights node.weights = { parentNodeId: node.weights[parentNodeId] + (lRate * node.delta_Wi(inputs, self.nodes, target, parentNodeId)) for parentNodeId in node.weights} for id in node.weights: if (nan(node.weights[id])): print("NaN WEight ", id) node.weights[id] = 0 for i in self.nodes: if (i == 'out'): out = self.nodes[i] if (out.hasNan): e = float('nan') else: try: e = (target - out.out) ** 2 except OverflowError: e = float('nan') if (lwp and out.delta_E_out < 0): lwp = False oscillations += 1 elif (not lwp and out.delta_E_out > 0): lwp = True oscillations += 1 self.nodes[i].cleanUp() if (oscillations > 5): lRate *= 0.9 oscillations = 0 return (lRate, oscillations, lwp, e)
def add_data(): columns = docentes resumenes = [] # Resumenes Docentes Agregando Data a la BD for index, resumen in docentes.iterrows(): data = {} for column in columns: try: value = int( resumen[column]) if not nan(resumen[column]) else None except: value = resumen[column] data[column] = value data['tipo_resumen'] = 'docentes' investigacion = Investigacion(data) # Creamos el Objeto resumenes.append(investigacion) # db.session.add(investigacion) # Agregamos a la session # del docentes # del resumenes_docentes # Resumenes Estudiantes Agregando Data a la BD for index, resumen in estudiantes.iterrows(): data = {} for column in columns: try: value = int( resumen[column]) if not nan(resumen[column]) else None except: value = resumen[column] data[column] = value data['tipo_resumen'] = 'estudiantes' investigacion = Investigacion(data) # Creamos el Objeto resumenes.append(investigacion) # db.session.add(investigacion) # del estudiantes # del resumenes_estudiantes db.session.add_all(resumenes) db.session.commit() # Realizamos la operacion atomica # del resumenes print('Base de datos con Resumenes')
def __attributes_setter__(self, values): if self.id is not None: del values['id'] for attribute in values.keys(): try: value = int(values[attribute]) if not nan(values[attribute]) else None except: value = values[attribute] setattr(self, attribute, value)
def getOut(self, inputs, nodes): if (self.out != False): return self.out if (len(self.parents) == 0): self.out = inputs[self.id] else: valueWeightTuples = [(nodes[i].getOut(inputs, nodes), self.weights[i]) for i in self.parents] self.out = self.function.calc(valueWeightTuples) self.hasNan = False if (nan(self.out)): print("NAN in ", self.id) self.hasNan = True self.out = 0 return self.out
def sumLocation(self, point): """Update the total moment about a new location.""" # make sure that the supplied point is a list of three numbers if type(point) != list and len(point) != 3: raise TypeError("Point must be a three-item list of numbers") else: for coord in point: if math.nan(coord): raise TypeError("""Point must be a three-item list of numbers""") self.__sumLocation = point self.__update()
print("lets go") fetcher = PersistentFetcher( "/home/ps/PycharmProjects/evo-feature-engineer/data") dataProvider = DataProvider(fetcher) data = dataProvider.getData(None, None) net = generate(data, 9) lRate, oscillations, lwp, mse = 0.001, 0, True, 101 iters = 0 while (mse > 1 and iters < 10): print("ITERATION: ", iters) sum_e = 0 nans = 0 for d in data: lRate, oscillations, lwp, e = net.interation(d.x, d.y, lRate, oscillations, lwp) if (nan(e)): nans += 1 else: sum_e += e iters += 1 valids = len(data) - nans mse = sum_e / (valids) if valids > 0 else -1 print("NaNs: ", nans) print("mean absolute error: ", math.sqrt(mse)) mean = sum([d.y for d in data]) / len(data) print("Mean ", mean) var = sum([(d.y - mean)**2 for d in data]) / len(data) print("Standard variantion, ", math.sqrt(var)) print("Variance ,", var) pred = net.predict(data[0].x)