Exemplo n.º 1
0
#coding=utf-8

from utils.structure import structure
from utils.learning_rate_finder import LearningRateFinder
from utils.sample import Sample
import pickle
import numpy as np
import matplotlib.pyplot as plt

model = structure(3, 950, 'mean_squared_error', 'relu', 'random_uniform', 'adam', 0)

lrf = LearningRateFinder(model)

muestra = Sample(ratio=[0.4, 1.6], T=[0.2, 1.1], r=[0.02, 0.1], o=[0.01, 1.0])

muestra.create('sample', 10**4, log=True)

x, y = muestra.open('sample', log=True)

lrf.find(
    x, y,
    1e-10, 1e+1,
    stepsPerEpoch=np.ceil((len(x) / float(1024))),
    batchSize=1024)

lrf.plot_loss()
#Método de smith
plt.savefig('Learning_Rate')
Exemplo n.º 2
0
CPUs = len(tf.config.experimental.list_physical_devices('CPU'))

if GPUs > 0:

    print("Num GPUs Available: ", GPUs)
    print("Num CPUs Available: ", CPUs)
    config = tf.compat.v1.ConfigProto(device_count={'GPU': GPUs, 'CPU': CPUs})
    sess = tf.compat.v1.Session(config=config)
    tf.compat.v1.keras.backend.set_session(sess)

model = structure(3, 950, 'mean_squared_error', 'relu', 'random_uniform',
                  'adam', 0)

muestra = Sample(ratio=[0.4, 1.6], T=[0.2, 1.1], r=[0.02, 0.1], o=[0.01, 1.0])

muestra.create('train', 10**6, log=True)

x_train, y_train = muestra.open('train', log=True)

muestra.create('test', 10**6, log=True)

x_test, y_test = muestra.open('test', log=True)

muestra.create('validation', 10**5, log=True)

x_val, y_val = muestra.open('validation', log=True)


def step_decay(epoch):
    lrate = 0.001 * math.pow(0.9, math.floor((1 + epoch) / 10))
    return lrate
Exemplo n.º 3
0
from utils.sample import Sample
from utils.black_scholes import raiz_ratio, d1_ratio, call_price_ratio
from utils.biseccion import bisec
import time
import pickle
import math
import numpy as np
from os import path, mkdir, strerror
from scipy.optimize import brentq
import tensorflow as tf



opn = Sample(ratio=[0.4, 1.6], T=[0.2, 1.1], r=[0.02, 0.1], o=[0.01, 1])

opn.create('prueba', N=10**5)
x_test, y_test = opn.open('prueba')

start_time = time.time()

j = 0
fails = []
i = 0
for c, ratio, r, T in x_test:

    def f(x):
        return raiz_ratio(c, ratio, r, x, T) #x seria la variable para aplicar bisección
    
    
    o = bisec(f, 0.01, 1, 10**-4) #error absoluto medio