Ejemplo n.º 1
0
# Build the data generators
if load_memory or use_keras_fit:
    print('Loading data to memory...')
generator = SeriesDataGenerator(dlwp,
                                train_data,
                                input_sel=input_selection,
                                output_sel=output_selection,
                                input_time_steps=input_time_steps,
                                output_time_steps=output_time_steps,
                                batch_size=batch_size,
                                add_insolation=add_solar,
                                load=load_memory,
                                shuffle=shuffle,
                                interval=step_interval)
if use_keras_fit:
    p_train, t_train = generator.generate([])
if validation_data is not None:
    val_generator = SeriesDataGenerator(dlwp,
                                        validation_data,
                                        input_sel=input_selection,
                                        output_sel=output_selection,
                                        input_time_steps=input_time_steps,
                                        output_time_steps=output_time_steps,
                                        batch_size=batch_size,
                                        add_insolation=add_solar,
                                        load=load_memory,
                                        interval=step_interval)
    if use_keras_fit:
        val = val_generator.generate([])
else:
    val_generator = None
Ejemplo n.º 2
0
        dlwp.time_dim = 2
    sequence = dlwp._n_steps
else:
    sequence = None

# Create data generator
generator = SeriesDataGenerator(dlwp,
                                data,
                                batch_size=216,
                                input_sel=input_selection,
                                output_sel=output_selection,
                                input_time_steps=input_time_steps,
                                output_time_steps=output_time_steps,
                                add_insolation=add_insolation,
                                sequence=sequence)
p_val, t_val = generator.generate([], scale_and_impute=False)

# Create TimeSeriesEstimator
estimator = TimeSeriesEstimator(dlwp, generator)

# Make a time series prediction and convert the predictors for comparison
print('Predicting with model %s...' % model_label)
forecast = estimator.predict(num_plot_steps, verbose=1)
forecast = forecast.sel(**selection)

# Scale the forecast
if scale_variables:
    forecast = forecast * variable_std + variable_mean

# Take the Laplacian if vorticity is desired
if plot_laplace:
Ejemplo n.º 3
0
# Build the data generators
if load_memory or use_keras_fit:
    print('Loading data to memory...')
generator = SeriesDataGenerator(dlwp,
                                train_data,
                                input_sel=io_selection,
                                output_sel=io_selection,
                                input_time_steps=io_time_steps,
                                output_time_steps=io_time_steps,
                                sequence=integration_steps,
                                add_insolation=add_solar,
                                batch_size=batch_size,
                                load=load_memory,
                                shuffle=shuffle)
if use_keras_fit:
    p_train, t_train = generator.generate([])
if validation_data is not None:
    val_generator = SeriesDataGenerator(dlwp,
                                        validation_data,
                                        input_sel=io_selection,
                                        output_sel=io_selection,
                                        input_time_steps=io_time_steps,
                                        output_time_steps=io_time_steps,
                                        sequence=integration_steps,
                                        add_insolation=add_solar,
                                        batch_size=batch_size,
                                        load=load_memory)
    if use_keras_fit:
        val = val_generator.generate([])
else:
    val_generator = None
Ejemplo n.º 4
0
                                           weighting='midlatitude')
else:
    loss_function = 'mse'

# Build the model
dlwp.build_model(layers, loss=loss_function, optimizer='adam', metrics=['mae'])
print(dlwp.model.summary())

#%% Initialize the scaler/imputer if necessary

# Generate the data to fit the scaler and imputer. The generator will by default apply scaling because it is necessary
# to automate its use in the Keras fit_generator method, so disable it when dealing with data to fit the scaler and
# imputer. If using pre-scaled data (i.e., dlwp was initialized with scaler_type=None and the Preprocessor data was
# generated with scale_variables=True), this step should be omitted.
fit_set = list(range(2))  # Use a much larger value when it matters
p_fit, t_fit = generator.generate(fit_set, scale_and_impute=False)
dlwp.init_fit(p_fit, t_fit)
p_fit, t_fit = (None, None)

#%% Train, evaluate, and save the model

# Train and evaluate the model
start_time = time.time()
print('Begin training...')
history = History()
early = EarlyStoppingMin(
    min_epochs=min_epochs,
    monitor='val_loss' if val_generator is not None else 'loss',
    min_delta=0.,
    patience=patience,
    restore_best_weights=True,
Ejemplo n.º 5
0
# Build the data generators
if load_memory or use_keras_fit:
    print('Loading data to memory...')
generator = SeriesDataGenerator(dlwp,
                                train_data,
                                input_sel=io_selection,
                                output_sel=io_selection,
                                input_time_steps=io_time_steps,
                                output_time_steps=io_time_steps,
                                sequence=integration_steps,
                                add_insolation=add_solar,
                                batch_size=batch_size,
                                load=load_memory,
                                shuffle=shuffle)
if use_keras_fit:
    p_train, t_train = generator.generate([])
if validation_data is not None:
    val_generator = SeriesDataGenerator(dlwp,
                                        validation_data,
                                        input_sel=io_selection,
                                        output_sel=io_selection,
                                        input_time_steps=io_time_steps,
                                        output_time_steps=io_time_steps,
                                        sequence=integration_steps,
                                        add_insolation=add_solar,
                                        batch_size=batch_size,
                                        load=load_memory)
    if use_keras_fit:
        val = val_generator.generate([])
else:
    val_generator = None