def __init__(self, vac_size: int, hidden_size: int, return_seq: bool): self.hidden_size = hidden_size self.vac_size = vac_size self.return_seq = return_seq self.inner_size = self.vac_size + self.hidden_size self.W_forget = Param( np.random.uniform(low=-np.sqrt(1 / self.hidden_size), high=np.sqrt(1 / self.hidden_size), size=(self.hidden_size, self.inner_size))) self.b_forget = Param( np.random.uniform(low=-np.sqrt(1 / self.hidden_size), high=np.sqrt(1 / self.hidden_size), size=(self.hidden_size, 1))) self.W_input = Param( np.random.uniform(low=-np.sqrt(1 / self.hidden_size), high=np.sqrt(1 / self.hidden_size), size=(self.hidden_size, self.inner_size))) self.b_input = Param( np.random.uniform(low=-np.sqrt(1 / self.hidden_size), high=np.sqrt(1 / self.hidden_size), size=(self.hidden_size, 1))) self.W_cell_state = Param( np.random.uniform(low=-np.sqrt(1 / self.hidden_size), high=np.sqrt(1 / self.hidden_size), size=(self.hidden_size, self.inner_size))) self.b_cell_state = Param( np.random.uniform(low=-np.sqrt(1 / self.hidden_size), high=np.sqrt(1 / self.hidden_size), size=(self.hidden_size, 1))) self.W_output = Param( np.random.uniform(low=-np.sqrt(1 / self.hidden_size), high=np.sqrt(1 / self.hidden_size), size=(self.hidden_size, self.inner_size))) self.b_output = Param( np.random.uniform(low=-np.sqrt(1 / self.hidden_size), high=np.sqrt(1 / self.hidden_size), size=(self.hidden_size, 1))) self.cache = {} self.seq_size = 0
def __init__(self, filename): Param.__init__(self, filename)
def __init__(self): Param.__init__(self) self.layers = []
def __init__(self, device='cpu'): self.param = Param(device) self.sfm = SFM(self.param, device)
def __init__(self): Param.__init__(self) self.composite = None
from DbInteraction import DbInteraction from Param import Param import time import json import tensorflow as tf from tensorflow.keras import layers import numpy as np import matplotlib.pyplot as plt #%% p = Param() #инициализация класса с параметрами работы p.printParam() #вывод списка параметров print('Инициализация...') pathToDB = p.database.getPathForReport() db = DbInteraction() #иниц. класса для работы с БД db.initNNAnalysis(pathToDB) # отправка в него пути к БД db.addInfo() # добавить новую строку actualNumberOfData = db.getInfoSize() # узнать номер последней строки #%% t = time.localtime() compilationTime = "{0}.{1}.{2} {3}:{4}".format(t.tm_year, t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min) inputSize = db.getInfoData('dictionarySize', 1)[0][0]
def countParam(array, trnArray): i = 0 indexOfDecisions = getIndexOfDecision(trnArray) listOfDecisions = [] for checkOtherDecisions in indexOfDecisions: listOfDecisions.append(checkOtherDecisions.getDecision()) favorizationList = [] listOfParam = [] for xX in array: i += 1 param = Param() for decision in indexOfDecisions: param = Param() param.setTestObject("x" + str(i)) param.setCObjet(decision.getDecision()) listOfParamCounter = [] whichElem = 0 for elemOfX in xX: if whichElem == len(xX) - 1: continue counter = 0 for k in decision.getIndexList(): if elemOfX == trnArray[k][whichElem]: counter += 1 # check if other c has 0 objects # if true counter += 1 incrementByOne = True for elem in indexOfDecisions: if elem.getDecision() != decision.getDecision(): for j in elem.getIndexList(): if elemOfX == trnArray[j][ whichElem] or counter == 0: incrementByOne = False break if (incrementByOne == True): counter += 1 if (counter == 0): checkIfAllZero = True for k in range(len(trnArray) - 1): if elemOfX == trnArray[k][whichElem]: checkIfAllZero = False break if checkIfAllZero == False: favorization = Favorization() favorization.setDecision(decision.getDecision()) favorization.setWhichElem(whichElem) favorization.setTestObject(param.getTestObject()) favorizationList.append(favorization) whichElem += 1 listOfParamCounter.append(counter / len(decision.getIndexList())) paramResult = (len(decision.getIndexList()) / len(trnArray)) * sum(listOfParamCounter) param.setParam(paramResult) listOfParam.append(param) for elem in listOfParam: for favorization in favorizationList: if elem.getTestObject() == favorization.getTestObject( ) and elem.getCObject() != favorization.getDecision(): length = 0 for decisionElem in indexOfDecisions: if decisionElem.getDecision() == elem.getCObject(): length = len(decisionElem.getIndexList()) elem.setParam(elem.getParam() + ((1 / 2) * (1 / length))) return listOfParam
import json import tensorflow as tf from tensorflow.keras import layers import numpy as np import matplotlib.pyplot as plt #%% print('start') t = time.localtime() compilationTime = "{0}.{1}.{2} {3}:{4}".format(t.tm_year, t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min) p = Param() #инициализация класса с параметрами работы p.printParam() #вывод списка параметров db = DbInteraction() #иниц. класса для работы с БД db.initFullAnalysis(p.database.getDbCorpusPath()) #иниц. класса для работы с БД # отправка в него пути к БД corpusID = db.getCorpusID() #сохранение актуального ID, который # является индексом строки в БД print("Добавление информации в базу данных...") db.updateCorpus('name', p.getName(), corpusID) #добавление начальной инфо # рмации о корпусе. данные считываются с параметров и отправляются db.updateCorpus('language', p.parser.getLanguage(), corpusID) # db.updateCorpus('stemType', p.parser.getStemType(), corpusID) # db.updateCorpus('stopWordsType', p.parser.getStopWordsType(), corpusID) # db.updateCorpus('metric', p.featureExtraction.getMetricType(), corpusID) # db.updateCorpus('compilationTime', compilationTime, corpusID) db.updateCorpus('source', p.source.getCorpusName(), corpusID)
def __init__(self): Param.__init__(self) self.static = None
def __init__(self, n_in: int, n_out: int): self.n_in = n_in self.n_out = n_out self.W = Param(np.random.randn(self.n_in, self.n_out) / np.sqrt(self.n_in/2)) self.b = Param(np.random.randn(self.n_out)) self.input_value = 0
def train_predict(data, time_budget, n_class, schema): start_time = time.time() LOGGER.info("Start!") LOGGER.info("time_budget: {0}".format(time_budget)) data = generate_data(data, LOGGER) LOGGER.info("Num of features: {0}".format(data.num_features)) LOGGER.info("Num of classes: {0}".format(data.num_class)) params = [ Param("ModelGCN", [1, [16, 16], "leaky_relu"]), Param("ModelGCN", [1, [32, 32], "leaky_relu"]), Param("ModelGAT", [1, [32, 32], "leaky_relu"]), Param("ModelGAT4", [1, [32, 32], "leaky_relu"]), Param("ModelGCN", [1, [64, 64], "leaky_relu"]), Param("ModelGAT", [1, [64, 64], "leaky_relu"]), Param("ModelGAT4", [1, [64, 64], "leaky_relu"]), Param("ModelGCN", [1, [128, 128], "leaky_relu"]), Param("ModelGAT", [1, [128, 128], "leaky_relu"]), Param("ModelGAT4", [1, [128, 128], "leaky_relu"]), Param("ModelGCN", [1, [256, 256], "leaky_relu"]), Param("ModelGAT", [1, [256, 256], "leaky_relu"]), Param("ModelGAT4", [1, [256, 256], "leaky_relu"]), Param("ModelGCN", [2, [16, 16, 16], "leaky_relu"]), Param("ModelGCN", [2, [32, 32, 32], "leaky_relu"]), Param("ModelGCN", [2, [64, 64, 64], "leaky_relu"]), Param("ModelGCN", [2, [128, 128, 128], "leaky_relu"]), Param("ModelGCN", [2, [256, 256, 256], "leaky_relu"]), Param("ModelGCN", [3, [16, 16, 16, 16], "leaky_relu"]), Param("ModelGCN", [3, [32, 32, 32, 32], "leaky_relu"]), Param("ModelGCN", [3, [64, 64, 64, 64], "leaky_relu"]), Param("ModelGCN", [3, [128, 128, 128, 128], "leaky_relu"]), Param("ModelGCN", [3, [256, 256, 256, 256], "leaky_relu"]), Param("ModelGCN", [1, [16, 16], "relu"]), Param("ModelGCN", [1, [32, 32], "relu"]), Param("ModelGAT", [1, [32, 32], "relu"]), Param("ModelGAT4", [1, [32, 32], "relu"]), Param("ModelGCN", [1, [64, 64], "relu"]), Param("ModelGAT", [1, [64, 64], "relu"]), Param("ModelGAT4", [1, [64, 64], "relu"]), Param("ModelGCN", [1, [128, 128], "relu"]), Param("ModelGAT", [1, [128, 128], "relu"]), Param("ModelGAT4", [1, [128, 128], "relu"]), Param("ModelGCN", [1, [256, 256], "relu"]), Param("ModelGAT", [1, [256, 256], "relu"]), Param("ModelGAT4", [1, [256, 256], "relu"]), Param("ModelGCN", [2, [16, 16, 16], "relu"]), Param("ModelGCN", [2, [32, 32, 32], "relu"]), Param("ModelGCN", [2, [64, 64, 64], "relu"]), Param("ModelGCN", [2, [128, 128, 128], "relu"]), Param("ModelGCN", [2, [256, 256, 256], "relu"]), Param("ModelGCN", [3, [16, 16, 16, 16], "relu"]), Param("ModelGCN", [3, [32, 32, 32, 32], "relu"]), Param("ModelGCN", [3, [64, 64, 64, 64], "relu"]), Param("ModelGCN", [3, [128, 128, 128, 128], "relu"]), Param("ModelGCN", [3, [256, 256, 256, 256], "relu"]), Param("ModelGCN", [1, [16, 16], "leaky_relu"]), Param("ModelGCN", [1, [32, 32], "leaky_relu"]), Param("ModelGAT", [1, [32, 32], "leaky_relu"]), Param("ModelGAT4", [1, [32, 32], "leaky_relu"]), Param("ModelGCN", [1, [64, 64], "leaky_relu"]), Param("ModelGAT", [1, [64, 64], "leaky_relu"]), Param("ModelGAT4", [1, [64, 64], "leaky_relu"]), Param("ModelGCN", [1, [128, 128], "leaky_relu"]), Param("ModelGAT", [1, [128, 128], "leaky_relu"]), Param("ModelGAT4", [1, [128, 128], "leaky_relu"]), Param("ModelGCN", [1, [256, 256], "leaky_relu"]), Param("ModelGAT", [1, [256, 256], "leaky_relu"]), Param("ModelGAT4", [1, [256, 256], "leaky_relu"]), Param("ModelGCN", [2, [16, 16, 16], "leaky_relu"]), Param("ModelGCN", [2, [32, 32, 32], "leaky_relu"]), Param("ModelGCN", [2, [64, 64, 64], "leaky_relu"]), Param("ModelGCN", [2, [128, 128, 128], "leaky_relu"]), Param("ModelGCN", [2, [256, 256, 256], "leaky_relu"]), Param("ModelGCN", [3, [16, 16, 16, 16], "leaky_relu"]), Param("ModelGCN", [3, [32, 32, 32, 32], "leaky_relu"]), Param("ModelGCN", [3, [64, 64, 64, 64], "leaky_relu"]), Param("ModelGCN", [3, [128, 128, 128, 128], "leaky_relu"]), Param("ModelGCN", [3, [256, 256, 256, 256], "leaky_relu"]), Param("ModelGCN", [1, [16, 16], "relu"]), Param("ModelGCN", [1, [32, 32], "relu"]), Param("ModelGAT", [1, [32, 32], "relu"]), Param("ModelGAT4", [1, [32, 32], "relu"]), Param("ModelGCN", [1, [64, 64], "relu"]), Param("ModelGAT", [1, [64, 64], "relu"]), Param("ModelGAT4", [1, [64, 64], "relu"]), Param("ModelGCN", [1, [128, 128], "relu"]), Param("ModelGAT", [1, [128, 128], "relu"]), Param("ModelGAT4", [1, [128, 128], "relu"]), Param("ModelGCN", [1, [256, 256], "relu"]), Param("ModelGAT", [1, [256, 256], "relu"]), Param("ModelGAT4", [1, [256, 256], "relu"]), Param("ModelGCN", [2, [16, 16, 16], "relu"]), Param("ModelGCN", [2, [32, 32, 32], "relu"]), Param("ModelGCN", [2, [64, 64, 64], "relu"]), Param("ModelGCN", [2, [128, 128, 128], "relu"]), Param("ModelGCN", [2, [256, 256, 256], "relu"]), Param("ModelGCN", [3, [16, 16, 16, 16], "relu"]), Param("ModelGCN", [3, [32, 32, 32, 32], "relu"]), Param("ModelGCN", [3, [64, 64, 64, 64], "relu"]), Param("ModelGCN", [3, [128, 128, 128, 128], "relu"]), Param("ModelGCN", [3, [256, 256, 256, 256], "relu"]), Param("ModelGCN", [1, [16, 16], "leaky_relu"]), Param("ModelGCN", [1, [32, 32], "leaky_relu"]), Param("ModelGAT", [1, [32, 32], "leaky_relu"]), Param("ModelGAT4", [1, [32, 32], "leaky_relu"]), Param("ModelGCN", [1, [64, 64], "leaky_relu"]), Param("ModelGAT", [1, [64, 64], "leaky_relu"]), Param("ModelGAT4", [1, [64, 64], "leaky_relu"]), Param("ModelGCN", [1, [128, 128], "leaky_relu"]), Param("ModelGAT", [1, [128, 128], "leaky_relu"]), Param("ModelGAT4", [1, [128, 128], "leaky_relu"]), Param("ModelGCN", [1, [256, 256], "leaky_relu"]), Param("ModelGAT", [1, [256, 256], "leaky_relu"]), Param("ModelGAT4", [1, [256, 256], "leaky_relu"]), Param("ModelGCN", [2, [16, 16, 16], "leaky_relu"]), Param("ModelGCN", [2, [32, 32, 32], "leaky_relu"]), Param("ModelGCN", [2, [64, 64, 64], "leaky_relu"]), Param("ModelGCN", [2, [128, 128, 128], "leaky_relu"]), Param("ModelGCN", [2, [256, 256, 256], "leaky_relu"]), Param("ModelGCN", [3, [16, 16, 16, 16], "leaky_relu"]), Param("ModelGCN", [3, [32, 32, 32, 32], "leaky_relu"]), Param("ModelGCN", [3, [64, 64, 64, 64], "leaky_relu"]), Param("ModelGCN", [3, [128, 128, 128, 128], "leaky_relu"]), Param("ModelGCN", [3, [256, 256, 256, 256], "leaky_relu"]), Param("ModelGCN", [1, [16, 16], "relu"]), Param("ModelGCN", [1, [32, 32], "relu"]), Param("ModelGAT", [1, [32, 32], "relu"]), Param("ModelGAT4", [1, [32, 32], "relu"]), Param("ModelGCN", [1, [64, 64], "relu"]), Param("ModelGAT", [1, [64, 64], "relu"]), Param("ModelGAT4", [1, [64, 64], "relu"]), Param("ModelGCN", [1, [128, 128], "relu"]), Param("ModelGAT", [1, [128, 128], "relu"]), Param("ModelGAT4", [1, [128, 128], "relu"]), Param("ModelGCN", [1, [256, 256], "relu"]), Param("ModelGAT", [1, [256, 256], "relu"]), Param("ModelGAT4", [1, [256, 256], "relu"]), Param("ModelGCN", [2, [16, 16, 16], "relu"]), Param("ModelGCN", [2, [32, 32, 32], "relu"]), Param("ModelGCN", [2, [64, 64, 64], "relu"]), Param("ModelGCN", [2, [128, 128, 128], "relu"]), Param("ModelGCN", [2, [256, 256, 256], "relu"]), Param("ModelGCN", [3, [16, 16, 16, 16], "relu"]), Param("ModelGCN", [3, [32, 32, 32, 32], "relu"]), Param("ModelGCN", [3, [64, 64, 64, 64], "relu"]), Param("ModelGCN", [3, [128, 128, 128, 128], "relu"]), Param("ModelGCN", [3, [256, 256, 256, 256], "relu"]), Param("ModelGCN", [1, [16, 16], "leaky_relu"]), Param("ModelGCN", [1, [32, 32], "leaky_relu"]), Param("ModelGAT", [1, [32, 32], "leaky_relu"]), Param("ModelGAT4", [1, [32, 32], "leaky_relu"]), Param("ModelGCN", [1, [64, 64], "leaky_relu"]), Param("ModelGAT", [1, [64, 64], "leaky_relu"]), Param("ModelGAT4", [1, [64, 64], "leaky_relu"]), Param("ModelGCN", [1, [128, 128], "leaky_relu"]), Param("ModelGAT", [1, [128, 128], "leaky_relu"]), Param("ModelGAT4", [1, [128, 128], "leaky_relu"]), Param("ModelGCN", [1, [256, 256], "leaky_relu"]), Param("ModelGAT", [1, [256, 256], "leaky_relu"]), Param("ModelGAT4", [1, [256, 256], "leaky_relu"]), Param("ModelGCN", [2, [16, 16, 16], "leaky_relu"]), Param("ModelGCN", [2, [32, 32, 32], "leaky_relu"]), Param("ModelGCN", [2, [64, 64, 64], "leaky_relu"]), Param("ModelGCN", [2, [128, 128, 128], "leaky_relu"]), Param("ModelGCN", [2, [256, 256, 256], "leaky_relu"]), Param("ModelGCN", [3, [16, 16, 16, 16], "leaky_relu"]), Param("ModelGCN", [3, [32, 32, 32, 32], "leaky_relu"]), Param("ModelGCN", [3, [64, 64, 64, 64], "leaky_relu"]), Param("ModelGCN", [3, [128, 128, 128, 128], "leaky_relu"]), Param("ModelGCN", [3, [256, 256, 256, 256], "leaky_relu"]), Param("ModelGCN", [1, [16, 16], "relu"]), Param("ModelGCN", [1, [32, 32], "relu"]), Param("ModelGAT", [1, [32, 32], "relu"]), Param("ModelGAT4", [1, [32, 32], "relu"]), Param("ModelGCN", [1, [64, 64], "relu"]), Param("ModelGAT", [1, [64, 64], "relu"]), Param("ModelGAT4", [1, [64, 64], "relu"]), Param("ModelGCN", [1, [128, 128], "relu"]), Param("ModelGAT", [1, [128, 128], "relu"]), Param("ModelGAT4", [1, [128, 128], "relu"]), Param("ModelGCN", [1, [256, 256], "relu"]), Param("ModelGAT", [1, [256, 256], "relu"]), Param("ModelGAT4", [1, [256, 256], "relu"]), Param("ModelGCN", [2, [16, 16, 16], "relu"]), Param("ModelGCN", [2, [32, 32, 32], "relu"]), Param("ModelGCN", [2, [64, 64, 64], "relu"]), Param("ModelGCN", [2, [128, 128, 128], "relu"]), Param("ModelGCN", [2, [256, 256, 256], "relu"]), Param("ModelGCN", [3, [16, 16, 16, 16], "relu"]), Param("ModelGCN", [3, [32, 32, 32, 32], "relu"]), Param("ModelGCN", [3, [64, 64, 64, 64], "relu"]), Param("ModelGCN", [3, [128, 128, 128, 128], "relu"]), Param("ModelGCN", [3, [256, 256, 256, 256], "relu"]), ] logger_killed_model_process = [True for _ in range(max_num_parallel)] params_running = [None for _ in range(max_num_parallel)] while True: for i in range(max_num_parallel): if time.time() - start_time >= time_budget - 5: break if not is_subprocess_alive(pid_model[i]): if logger_killed_model_process[i]: LOGGER.info( "Model process {0} has been killed".format(i)) if params_running[i]: params_running[i].running = False params_running[ i].retry = params_running[i].retry - 1 logger_killed_model_process[i] = False if os.path.exists(file_path("AOE_MODEL_{0}.result".format(i))): with FileLock(file_path("AOE_MODEL_{0}.lock".format(i))): temp_result = load_data( file_path("AOE_MODEL_{0}.result".format(i))) if temp_result.result is None: params_running[i].running = False params_running[ i].retry = params_running[i].retry - 1 os.remove( file_path( file_path( "AOE_MODEL_{0}.result".format(i)))) LOGGER.info("Result of Model {0} is None".format( params_running[i].index)) else: params[ params_running[i].index].result = temp_result os.remove( file_path( file_path( "AOE_MODEL_{0}.result".format(i)))) LOGGER.info( "Get result of Model {0}, {1}, {2}, {3}, {4}". format( params_running[i].index, "loss_train = {0:.6f}".format( params_running[i].result.loss_train), "loss_valid = {0:.6f}".format( params_running[i].result.loss_valid), "acc_train = {0:.6f}".format( params_running[i].result.acc_train), "acc_valid = {0:.6f}".format( params_running[i].result.acc_valid))) if not os.path.exists( file_path("AOE_MODEL_{0}.param".format( i))) and not os.path.exists( file_path("AOE_MODEL_{0}.result".format(i))): with FileLock(file_path("AOE_MODEL_{0}.lock".format(i))): for params_index in range(len(params)): if not params[params_index].running and params[ params_index].retry > 0: params[params_index].index = params_index params[params_index].running = True params[ params_index].time_budget = time_budget - ( time.time() - start_time) params_running[i] = params[params_index] save_data( file_path("AOE_MODEL_{0}.param".format(i)), params[params_index]) LOGGER.info( "Start Model {0}".format(params_index)) break if time.time() - start_time >= time_budget - 5: break if_continue = False for i in range(len(params)): if params[i].result is None: if_continue = True break if not if_continue: break os.system( "kill -9 `ps -ef | grep AutoGraphModel.py | awk '{print $2}' `") LOGGER.info("Start merge the result") params_result = [] for i in range(len(params)): if params[i].result is not None: params_result.append(params[i]) LOGGER.info("Num of result: {0}".format(len(params_result))) for i in range(len(params_result)): for j in range(i + 1, len(params_result)): if params_result[i].result.acc_valid > params_result[ j].result.acc_valid: params_result[i], params_result[j] = params_result[ j], params_result[i] params_result = params_result[-4:] # 下面这段话? # params_result.reverse() # for i in range(1, len(params_result)): # if params_result[i].result.acc_valid + 0.01 < params_result[0].result.acc_valid: # params_result = params_result[0:i] # break # params_result.reverse() # 上面这段话? for param in params_result: LOGGER.info("Final Model {0} {1}".format(param.index, param.model)) result = [item.result.result for item in params_result] # ensemble torch.backends.cudnn.deterministic = True device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") model = ModelEnsemble(num_features=data.num_features, num_class=data.num_class) data.split_train_valid() model = model.to(device) mask_train, mask_valid, mask_test, y = data.mask_train, data.mask_valid, data.mask_test, data.y mask_train = mask_train.to(device) mask_valid = mask_valid.to(device) mask_test = mask_test.to(device) y = y.to(device) for i in range(len(result)): result[i] = result[i].to(device) optimizer = torch.optim.Adam(model.parameters(), lr=0.005, weight_decay=5e-4) epoch = 1 best_loss_train = float("inf") best_loss_valid = float("inf") best_result = None best_epoch = 0 while best_epoch + 10 >= epoch: model.train() optimizer.zero_grad() predict = model(result) loss_train = nll_loss(predict[mask_train], y[mask_train]) loss_valid = nll_loss(predict[mask_valid], y[mask_valid]) loss_train.backward() optimizer.step() if loss_valid < best_loss_valid: best_loss_train = loss_train best_loss_valid = loss_valid best_result = predict best_epoch = epoch epoch += 1 LOGGER.info("Finish merge the result") return best_result[mask_test].max(1)[1].cpu().numpy().flatten()
def forward(self, seq: np.ndarray): """ forward pass :param seq: :return: """ h = Param(np.zeros((self.hidden_size, 1))) C = Param(np.zeros((self.hidden_size, 1))) ft = Param(np.zeros((self.hidden_size, 1))) it = Param(np.zeros((self.hidden_size, 1))) C_hat = Param(np.zeros((self.hidden_size, 1))) out = Param(np.zeros((self.hidden_size, 1))) self.seq_size = seq.shape self.cache = {} self.cache[-1] = (Param(h.value), Param(C.value)) output = np.empty((self.seq_size[0], self.hidden_size, 1)) for idx, x in enumerate(seq): x_oh = Param(np.row_stack((h.value, x))) ft.value = self.forget_gate(x=x_oh.value) it.value = self.input_gate(x=x_oh.value) C_hat.value = self.cell_state(x=x_oh.value) C.value = ft.value * C.value + it.value * C_hat.value out.value = self.output_gate(x=x_oh.value) h.value = out.value * tanh(C.value) output[idx] = h.value self.cache[idx] = (Param(x_oh.value), Param(ft.value), Param(it.value), Param(C_hat.value), Param(out.value), Param(h.value), Param(C.value)) if self.return_seq: return output else: return output[-1]
def __init__(self): Param.__init__(self) self.vector = None