def model_fit(param): print "Training %s" % param[0] neural_shape = [param[0], 15, 1] X_train = param[1][0] y_train = param[1][1] X_test = param[1][2] y_test = param[1][3] acoNet = ACOEstimator(Q=0.08, epsilon=0.55) fit_param = {"neural_shape": neural_shape} acoNet.fit(X_train, y_train, **fit_param) fit_param["weights_matrix"] = acoNet.best_archive neuralNet = NeuralFlowRegressor() neuralNet.fit(X_train, y_train, **fit_param) return param[0], np.sqrt(neuralNet.score(X_test, y_test))
def model_fit(param): print "Training %s"%param[0] X_train = param[1][0] y_train = param[1][1] X_test = param[1][2] y_test = param[1][3] neural_shape = [y_train.shape[1]*param[0],10,y_train.shape[1]] acoNet = ACOEstimator(Q=0.08,epsilon=0.55) fit_param = { "neural_shape":neural_shape } acoNet.fit(X_train,y_train,**fit_param) fit_param["weights_matrix"] = acoNet.best_archive neuralNet = NeuralFlowRegressor() neuralNet.fit(X_train,y_train,**fit_param) return param[0],np.sqrt(neuralNet.score(X_test,y_test))
if __name__ == '__main__': best_estimator = None best_score = np.Inf for loop in np.arange(1, 20): n_input = 4 n_periodic = 1 n_hidden = 15 neural_shape = [n_input + n_periodic, n_hidden, 1] Q = 0.09 epsilon = 0.55 dataFeeder = TrafficFeeder() X_train, y_train = dataFeeder.fetch_traffic_training( n_input, 1, (40, 46)) X_test, y_test = dataFeeder.fetch_traffic_test(n_input, 1, (46, 48)) # retrieve = [n_input+1,(X_train,y_train,X_test,y_test)] acoNet = ACOEstimator(Q=Q, epsilon=epsilon) fit_param = {"neural_shape": neural_shape} acoNet.fit(X_train, y_train, **fit_param) fit_param["weights_matrix"] = acoNet.best_archive neuralNet = NeuralFlowRegressor() neuralNet.fit(X_train, y_train, **fit_param) y_pred = dataFeeder.convert(neuralNet.predict(X_test)) score = np.sqrt(mean_squared_error(y_pred, y_test)) if (score < best_score): best_estimator = acoNet print score # plot_fig(y_pred,y_test) print best_score, best_estimator
from data.TrafficFeeder import TrafficFeeder from experiments.initializer import * from utils.SplitTrainTest import SplitTrainTest param_dicts = { "Q": np.arange(0.01, 0.1, step=0.01), "epsilon": np.arange(0.1, 1.0, step=0.05) } n_sliding_window = 4 n_periodic = 1 n_input = n_sliding_window + n_periodic neural_shape = [n_input, 15, 1] dataFeeder = TrafficFeeder() X, y = dataFeeder.fetch_traffic_training(n_sliding_window, n_periodic, (40, 46)) estimator = ACOEstimator() archive_solution = construct_solution(estimator.number_of_solutions, neural_shape) cv = SplitTrainTest(X.shape[0]) fit_param = {'neural_shape': neural_shape, "archive": archive_solution} # estimator.fit(X,y,**fit_param) gs = GridSearchCV(estimator, param_grid=param_dicts, cv=cv, n_jobs=-1, fit_params=fit_param, scoring='mean_squared_error') gs.fit(X, y) print gs.best_estimator_ print gs.best_estimator_.score(X, y)
y_test = np.zeros(testing_set_size - 1) for i in range(0, testing_set_size - 1): y_test[i] = data.cpu_rate[i + training_set_size + 1] # Number of hiddens node (one hidden layer) n_hidden = np.array([55]) # Define neural shape # Input layer: [n_sample*n_size] # Hidden layer: # Output layer: regression # neural_shape = [fuzzy_set_size,n_hidden,fuzzy_set_size] # neural_shape = [fuzzy_set_size,n_hidden,fuzzy_set_size] # Initialize ACO Estimator 130 estimator = ACOEstimator(Q=0.65, epsilon=0.2, number_of_solutions=10, hidden_nodes=n_hidden) # fit_param = {'neural_shape':neural_shape} # fuzzy before training # fuzzy step: X_train_f = fuzzy(X_train) y_train_f = fuzzy(y_train) X_test_f = fuzzy(X_test) # # # Initialize neural network model for regression neuralNet = NeuralFlowRegressor(learning_rate=1E-04, hidden_nodes=n_hidden) # # There are many techniques for combining GA with NN. One of this, the optimizer solution of GA will be weights initialized of NN optimizer = OptimizerNNEstimator(estimator, neuralNet) # # optimizer = neuralNet
y_test = np.zeros(testing_set_size - 1) for i in range(0, testing_set_size - 1): y_test[i] = data.cpu_usage[i + training_set_size + 1] # Number of hiddens node (one hidden layer) n_hidden = 52 # Define neural shape # Input layer: [n_sample*n_size] # Hidden layer: # Output layer: regression # neural_shape = [fuzzy_set_size,n_hidden,fuzzy_set_size] neural_shape = [fuzzy_set_size * 2, n_hidden, fuzzy_set_size] # Initialize ACO Estimator estimator = ACOEstimator(Q=0.65, epsilon=0.2, number_of_solutions=130) fit_param = {'neural_shape': neural_shape} # fuzzy before training # fuzzy step: X_train_f = fuzzy(X_train) y_train_f = fuzzy(y_train) X_test_f = fuzzy(X_test) sliding_number = 2 X_train = list(SlidingWindow(X_train_f, sliding_number)) # # Initialize neural network model for regression neuralNet = NeuralFlowRegressor() X_test_f = list(SlidingWindow(X_test_f, sliding_number)) # There are many techniques for combining GA with NN. One of this, the optimizer solution of GA will be weights initialized of NN
if __name__ == '__main__': best_estimator = None best_score = np.Inf for loop in np.arange(1,20): n_input = 4 n_periodic = 1 n_hidden = 15 neural_shape = [n_input+n_periodic,n_hidden,1] Q = 0.09 epsilon = 0.55 dataFeeder = TrafficFeeder() X_train,y_train = dataFeeder.fetch_traffic_training(n_input,1,(40,46)) X_test,y_test = dataFeeder.fetch_traffic_test(n_input,1,(46,48)) # retrieve = [n_input+1,(X_train,y_train,X_test,y_test)] acoNet = ACOEstimator(Q=Q,epsilon=epsilon) fit_param = { "neural_shape":neural_shape } acoNet.fit(X_train,y_train,**fit_param) fit_param["weights_matrix"] = acoNet.best_archive neuralNet = NeuralFlowRegressor() neuralNet.fit(X_train,y_train,**fit_param) y_pred = dataFeeder.convert(neuralNet.predict(X_test)) score = np.sqrt(mean_squared_error(y_pred,y_test)) if(score<best_score): best_estimator = acoNet print score # plot_fig(y_pred,y_test) print best_score,best_estimator