def NeuralNetwork(input_Nn, output_Nn):
    np_input_Nn = np.array(input_Nn[0])
    np_output_Nn = np.array(output_Nn[0])

    x = np_input_Nn.astype(float)  # .reshape(-1, 1)
    y = np_output_Nn.astype(float)  # .ravel()


    nn = MLPRegressor(
        hidden_layer_sizes=(100,), activation='tanh', solver='adam', alpha=0.0001, batch_size='auto',
        learning_rate='adaptive', learning_rate_init=0.001, power_t=0.5, max_iter=1000, shuffle=True,
        random_state=None, tol=0.0001, verbose=False, warm_start=False, momentum=0.9,
        nesterovs_momentum=True, early_stopping=True, validation_fraction=0.5, beta_1=0.9, beta_2=0.999,
        epsilon=1e-08)

    nn.n_outputs_ = 3
    n = nn.fit(x, y)
    # test_x = np.arange(0.0, 1, 0.05).reshape(-1, 1)
    test_x = np.array([0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                       0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
                       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0])

    test_y = nn.predict(test_x.reshape(1, -1))
    print(test_y)
    # fig = plt.figure()
    print(nn.score(x, y))
예제 #2
0
def deserialize_mlp_regressor(model_dict):
    model = MLPRegressor(**model_dict['params'])

    model.coefs_ = model_dict['coefs_']
    model.loss_ = model_dict['loss_']
    model.intercepts_ = model_dict['intercepts_']
    model.n_iter_ = model_dict['n_iter_']
    model.n_layers_ = model_dict['n_layers_']
    model.n_outputs_ = model_dict['n_outputs_']
    model.out_activation_ = model_dict['out_activation_']

    return model
예제 #3
0
          ]]),
    list([[7.61211153e-01], [5.29023058e-01], [-6.76783513e-01],
          [-1.23527535e-01], [1.04599422e-01], [1.06178562e+00],
          [-1.09977597e-43], [-1.22990539e-90], [-3.14851814e-21],
          [7.33380751e-01]])
]

net.intercepts_ = [
    list([
        1.44847648, 1.47542637, 0.51003163, 0.45278632, -0.0056204, 1.53020242,
        -0.23453891, -0.00187764, -0.21982535, 1.69397764
    ]),
    list([1.9355952])
]

net.n_outputs_ = 1
net.n_layers_ = 3
net.out_activation_ = "identity"


def dotProd(a, b):
    return sum(a[i] * b[i] for i in xrange(len(a)))


def arrToTuple(arr):
    tupArr = [tuple(elem) for elem in arr]
    return tuple(tupArr)


def isEndState(state):
    return state[1] == 0
예제 #4
0
# Validate input parameters.
# mlp_estimator._validate_hyperparameters() # 检查参数是否合理
if np.any(np.array(hidden_layer_sizes) <= 0):
    raise ValueError("hidden_layer_sizes must be > 0, got %s." %
                     hidden_layer_sizes)

# X, y = mlp_estimator._validate_input(X, y, incremental)
n_samples, n_features = X.shape

# Ensure y is 2D
# TODO:保证array为两维,即输入的y应该是np.array([[1, 2, 3]])这才是1行3列的array
# if y.ndim == 1:
#     y = y.reshape((-1, 1))

mlp_estimator.n_outputs_ = y.shape[1]

layer_units = ([n_features] + hidden_layer_sizes + [mlp_estimator.n_outputs_])

# check random state
mlp_estimator._random_state = check_random_state(mlp_estimator.random_state)

incremental = False
if not hasattr(mlp_estimator, 'coefs_') or (not mlp_estimator.warm_start
                                            and not incremental):
    # First time training the model
    mlp_estimator._initialize(y, layer_units)

# lbfgs does not support mini-batches
if mlp_estimator.solver == 'lbfgs':
    batch_size = n_samples