From 854349b0438c38d10fa58c419d9dc59bdd7b3d19 Mon Sep 17 00:00:00 2001 From: Oscar Suescun Elizalde Date: Mon, 31 Mar 2025 16:57:25 +0200 Subject: [PATCH] Optimizacion logica --- genCurvas.py | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/genCurvas.py b/genCurvas.py index 2a55f61..d92935b 100644 --- a/genCurvas.py +++ b/genCurvas.py @@ -54,12 +54,17 @@ def logica_offset(offset, error, errorObjetivo): limSup = 1 + errorObjetivo limInf = 1 - errorObjetivo - delta = random.random() * 1e-6 - if error <= limSup and error >= limInf: return True, None - - if error > 1: offset = offset - delta - elif error < 1: offset = offset + delta + + tasa_aprendizaje = 0.001 + + desviacion = error - 1 + delta = abs(tasa_aprendizaje * np.tanh(desviacion)) + + print(delta) + + if error >= limSup: offset -= delta + if error <= limInf: offset += delta return False, offset @@ -81,24 +86,29 @@ if __name__ == '__main__': ruta = f'{directorio}{nombre}' offset = 0 - generar_curva(offset,ruta) + E_original = 70 + + B = 4 * np.pi * 1e-7 * 1000 + offset + cte = E_original/B - # B = 1e-2 - # BObjetivo = 2e-2 + EObjetivo = 175 - # errorObjetivo = 0.01 + errorObjetivo = 0.01 - # flag = False + flag = False - # while flag == False: - # os.system('cls') + while flag == False: + os.system('cls') - # B = B + offset + B_nuevo = 4 * np.pi * 1e-7 * 1000 + offset - # error = B/BObjetivo + Ecalculado = cte * B_nuevo - # print(B) - # print(error) + error = Ecalculado/EObjetivo - # flag, offset = logica_offset(offset, error, errorObjetivo) \ No newline at end of file + print(Ecalculado) + print(error) + print() + + flag, offset = logica_offset(offset, error, errorObjetivo)