使用带有Tensorflow的Keras作为后端,我创建了CNN和DNN,以使用恒星光谱作为输入来预测三个恒星参数(温度,重力和金属度)。两种模型在应用于测试集时都能很好地预测,但为了使我的结果有用,有必要在我的预测中包含错误。
输入光谱各有7000个数据点,输出为3个值。每个光谱还有一个7000个数据点的误差数组,我希望能够通过我的模型传播,以便每个预测都有一组3个不确定性。有没有人对如何实现这一目标有任何经验或见解?
我的DNN结构如下所示:
# Define vars
activation = 'relu'
init = 'he_normal'
beta_1 = 0.9
beta_2 = 0.999
epsilon = 1e-08
input_shape = (None,7000)
epochs = 100
lr = 0.0009
batch_size = 64
n_hidden = [2048,1024,512,256,128]
# Design DNN Layers
model = Sequential([
InputLayer(batch_input_shape=input_shape),
Dense(n_hidden[0], init=init, activation=activation, bias=True),
Dense(n_hidden[1], init=init, activation=activation, bias=True),
Dense(n_hidden[2], init=init, activation=activation, bias=True),
Dense(n_hidden[3], init=init, activation=activation, bias=True),
Dense(n_hidden[4], init=init, activation=activation, bias=True),
Dense(l, init=init, activation='linear', bias=True),
])
# Optimization function
optimizer = Adam(lr=lr, beta_1=beta_1, beta_2=beta_2, epsilon=epsilon, decay=0.0)
# Compile and train network
model.compile(optimizer=optimizer, loss='mean_squared_error')
early_stopping = EarlyStopping(monitor='val_loss', min_delta=0.0001,
patience=3, verbose=2, mode='min')
## train_X.shape = (50000,7000)
## train_Y.shape = (50000,3)
## cv_X.shape = (10000,7000)
## cv_Y.shape = (10000,3)
history = model.fit(train_X, train_Y, validation_data=(cv_X, cv_Y),
nb_epoch=epochs, batch_size=batch_size, verbose=2, callbacks=[early_stopping])
我的CNN有些相似;基本上用1D-CNN层替换前几层并修改滤波器和滤波器长度的数量。关于如何通过模型传播错误的任何想法。我熟悉一些获取模型错误的方法(通过对同一模型和/或辍学层的多次训练),但我正在寻找的是实际预测中的错误。
修改
以下是CNN的架构
# Define vars
input_shape = (None,7000,1)
epochs = 30
activation = 'relu'
initializer = 'he_normal'
beta_1 = 0.9
beta_2 = 0.999
epsilon = 1e-08
batch_size = 64
n_hidden = [1024,512,256]
n_filters = [16,32,32,64,64]
lr = 0.001
model = Sequential([
InputLayer(batch_input_shape=input_shape),
Convolution1D(nb_filter=n_filters[0], filter_length=8, activation=activation, border_mode='same', init=initializer, input_shape=input_shape),
Convolution1D(nb_filter=n_filters[1], filter_length=8, activation=activation, border_mode='same', init=initializer),
MaxPooling1D(pool_length=4),
Convolution1D(nb_filter=n_filters[2], filter_length=8, activation=activation, border_mode='same', init=initializer),
Convolution1D(nb_filter=n_filters[3], filter_length=8, activation=activation, border_mode='same', init=initializer),
MaxPooling1D(pool_length=4),
Convolution1D(nb_filter=n_filters[4], filter_length=10, activation=activation),
MaxPooling1D(pool_length=4),
Flatten(),
Dense(output_dim=n_hidden[0], activation=activation, init=initializer),
Dense(output_dim=n_hidden[1], activation=activation, init=initializer),
Dense(output_dim=n_hidden[2], activation=activation, init=initializer),
Dense(output_dim=l, input_dim=n_hidden[2], activation='linear'),
])
# Compile Model
optimizer=Adam(lr=lr, beta_1=beta_1, beta_2=beta_2, epsilon=epsilon, decay=0.0)
model.compile(optimizer=optimizer, loss='mean_squared_error')
early_stopping = EarlyStopping(monitor='val_loss', min_delta=0.0001,
patience=3, verbose=2, mode='min')
history = model.fit(train_X, train_Y, validation_data=(cv_X, cv_Y),
nb_epoch=epochs, batch_size=batch_size, verbose=2, callbacks=[early_stopping])