def WalkThroughAllOptimizers(option): dataReader = DataReader(x_data_name, y_data_name) XData,YData = dataReader.ReadData() X = dataReader.NormalizeX() Y = dataReader.ToOneHot() n_input, n_output = dataReader.num_feature, dataReader.num_category n_hidden = 8 eta, batch_size, max_epoch = option[1], 10, 10000 eps = 0.06 params = HyperParameters41(n_input, n_output, n_hidden, eta, max_epoch, batch_size, eps, LossFunctionName.CrossEntropy3, InitialMethod.Xavier, option[0]) loss_history = CLossHistory() net = TwoLayerClassificationNet() #ShowData(XData, YData) net.train(dataReader, params, loss_history) trace = loss_history.GetMinimalLossData() print(trace.toString()) title = loss_history.ShowLossHistory(params) print("wait for 10 seconds...") wbs_min = WeightsBias30(params) wbs_min.W1 = trace.dict_weights["W1"] wbs_min.W2 = trace.dict_weights["W2"] wbs_min.B1 = trace.dict_weights["B1"] wbs_min.B2 = trace.dict_weights["B2"] ShowAreaResult(X, wbs_min, net, title) ShowData(X, YData)
dict_cache = net.ForwardCalculationBatch3(input, wb1, wb2) Z[0,i,j] = dict_cache["Output"][0,0] Z[1,i,j] = dict_cache["Output"][1,0] Z[2,i,j] = dict_cache["Output"][2,0] # end if # end for # end for return X,Y,Z if __name__ == '__main__': dataReader = DataReader(x_data_name, y_data_name) dataReader.ReadData() X = dataReader.NormalizeX() Y = dataReader.ToOneHot() n_input, n_output = dataReader.num_feature, dataReader.num_category n_hidden = 3 eta, batch_size, max_epoch = 0.1, 10, 10000 eps = 0.01 params = CParameters(n_input, n_hidden, n_output, eta, max_epoch, batch_size, eps, LossFunctionName.CrossEntropy3) loss_history = CLossHistory() net = TwoLayerClassificationNet() #ShowData(XData, YData) wb1, wb2 = net.train(dataReader, params, loss_history, net.ForwardCalculationBatch3)