当前位置:   article > 正文

【回归预测-CNN预测】基于卷积神经网络CNN实现数据回归预测附matlab代码_cnn 回归问题

cnn 回归问题

   1 内容介绍

电力系统的安全稳定运行与国民经济的发展及社会人身财产安全息息相关.准确的短期负荷预测结果是电网指导电力系统制定发电计划,协调机组运行,调度负荷分配及制定检修计划的重要依据.随着智能电网的发展及越来越多的分布式电源的接入,影响短期负荷预测结果的因素更加复杂,使负荷呈现更强的非线性,这种严峻的环境也对短期负荷预测的准确度和适应性提出了更高的要求.电力系统的负荷由于数据量庞大,受众多因素影响等使其具有随机性,非线性,时序性等特点.卷积神经网络(Convolutional Neural Networks,CNN)能够深入挖掘信息的多重特点并从中获得有用的特征描述,是一种准确高效的特征提取方法.本文结合负荷序列的特点,使用CNN来对电力系统短期负荷进行预测。

2 仿真代码

clc, clearvars, close all
%------------------------------------------------------------------------------------------------

function X_aug = image_augmentation(Xdata,aug_params)
%Randomly augment images slice-by-slice between given ranges, optionally add Gaussian noise:

X_aug = zeros(size(Xdata));

imageAugmenter = imageDataAugmenter( ...
    'RandRotation',aug_params.rot, ...
    'RandXTranslation',aug_params.trans_x, ...
    'RandYTranslation',aug_params.trans_y, ...
    'RandXReflection', aug_params.refl_x, ...
    'RandYReflection', aug_params.refl_y, ...
    'RandScale', aug_params.scale, ...
    'RandXShear', aug_params.shear_x, ...
    'RandYShear', aug_params.shear_y);

for i = 1:size(Xdata,4)
Xtrain_single = Xdata(:,:,:,i);
Xtrain_single_aug = augment(imageAugmenter,Xtrain_single);

if aug_params.add_gauss_noise == 1
Xtrain_single_aug = imnoise(Xtrain_single_aug,'gaussian',0,aug_params.gauss_noise_var);
end

   1 内容介绍

电力系统的安全稳定运行与国民经济的发展及社会人身财产安全息息相关.准确的短期负荷预测结果是电网指导电力系统制定发电计划,协调机组运行,调度负荷分配及制定检修计划的重要依据.随着智能电网的发展及越来越多的分布式电源的接入,影响短期负荷预测结果的因素更加复杂,使负荷呈现更强的非线性,这种严峻的环境也对短期负荷预测的准确度和适应性提出了更高的要求.电力系统的负荷由于数据量庞大,受众多因素影响等使其具有随机性,非线性,时序性等特点.卷积神经网络(Convolutional Neural Networks,CNN)能够深入挖掘信息的多重特点并从中获得有用的特征描述,是一种准确高效的特征提取方法.本文结合负荷序列的特点,使用CNN来对电力系统短期负荷进行预测。

2 仿真代码

clc, clearvars, close all
%------------------------------------------------------------------------------------------------

function X_aug = image_augmentation(Xdata,aug_params)
%Randomly augment images slice-by-slice between given ranges, optionally add Gaussian noise:

X_aug = zeros(size(Xdata));

imageAugmenter = imageDataAugmenter( ...
    'RandRotation',aug_params.rot, ...
    'RandXTranslation',aug_params.trans_x, ...
    'RandYTranslation',aug_params.trans_y, ...
    'RandXReflection', aug_params.refl_x, ...
    'RandYReflection', aug_params.refl_y, ...
    'RandScale', aug_params.scale, ...
    'RandXShear', aug_params.shear_x, ...
    'RandYShear', aug_params.shear_y);

for i = 1:size(Xdata,4)
Xtrain_single = Xdata(:,:,:,i);
Xtrain_single_aug = augment(imageAugmenter,Xtrain_single);

if aug_params.add_gauss_noise == 1
Xtrain_single_aug = imnoise(Xtrain_single_aug,'gaussian',0,aug_params.gauss_noise_var);
end

X_aug(:,:,:,i) = Xtrain_single_aug;
end


%%%%% Deep learning convolutional neural network regression v1.1 %%%%%
% With network parameter gridsearch, input normalization and geometric image augmenation:

function [X_equal,Y_equal] = ROS(Xdata,Ydata,duplication_factor)
%Equalize output (Ydata) distribution using random oversampling:

[Ydata_counts, Ydata_bins] = histcounts(Ydata);
Ydata_max_count = max(Ydata_counts);
Ydata_max_count_ratio = floor(Ydata_max_count*(1./Ydata_counts));

Ydata_max_count_ratio = Ydata_max_count*(1./Ydata_counts);
Ydata_max_count_ratio_norm = Ydata_max_count_ratio/sum(Ydata_max_count_ratio);

for i = 1:numel(Ydata)
    Ydata_bins_temp = Ydata_bins(1:end-1);
    Ydata_bins_temp(Ydata_bins_temp > Ydata(i)) = 0;
    [~,Ydata_bin_idx] = max(Ydata_bins_temp);
    Ydata_prob(i,1) = Ydata_max_count_ratio_norm(Ydata_bin_idx);
end

ROS_selection = randsample(numel(Ydata),numel(Ydata)*duplication_factor,true,Ydata_prob(:,1));
Y_equal = Ydata(ROS_selection);
X_equal = Xdata(:,:,:,ROS_selection);


%For testing, to view original and randomly oversampled input histogram:
%{
figure()
histogram(Ydata,Ydata_bins)
xlabel('RBC content (%)')
ylabel('Count')

figure()
histogram(Y_equal,Ydata_bins)
xlabel('RBC content (%)')
ylabel('Count')
%}


;

disp(['Network accuracy: ', num2str(results_test.accuracy_test)])
disp(['Network absolute error: ', num2str(results_test.error_abs_test)])
disp(['Network RMSE: ', num2str(results_test.rmse_test)])


%Plot display predicted against true Y values for test set images:
linear_fit = polyfit(YTest,results_test.predicted_test,1);
x_space = linspace(0,0.6);
y_fit = polyval(linear_fit,x_space);
y_space = x_space;

dlm = fitlm(YTest,results_test.predicted_test,'Intercept',false);
figure()
hold on
plot(YTest,'r-');hold on
plot(results_test.predicted_test,'b-')
xlabel('时间') 
ylabel('值') 
legend('真实值','预测值')
figure()
hold on
scatter(YTest,results_test.predicted_test)
plot(x_space,y_fit)
plot(x_space,y_space,'k--')
hold off
title('Network test set predictions')
xlabel('True Y value') 
ylabel('Predicted Y value') 
axis([0 0.6 0 0.6])

function options = network_options(params,XVal,YVal,show_plots)

if strcmp(params.optimizer,'sgdm') && show_plots == 1
    
    options = trainingOptions(params.optimizer, ...
    'MiniBatchSize',params.batch_size, ...
    'MaxEpochs',params.max_epochs, ...
    'InitialLearnRate',params.learn_rate, ...
    'LearnRateSchedule',params.learn_rate_schedule, ...
    'LearnRateDropFactor',params.learn_rate_drop_factor, ...
    'LearnRateDropPeriod',params.learn_rate_drop_period, ...
    'Shuffle',params.shuffle, ...
    'L2Regularization',params.L2_reg, ...    
    'ValidationData',{XVal,YVal}, ...
    'ValidationFrequency',params.validationFrequency, ...
    'Plots','training-progress', ...
    'Momentum',params.momentum, ...
    'Verbose',false);

elseif strcmp(params.optimizer,'sgdm') && show_plots == 0
    
    options = trainingOptions(params.optimizer, ...
    'MiniBatchSize',params.batch_size, ...
    'MaxEpochs',params.max_epochs, ...
    'InitialLearnRate',params.learn_rate, ...
    'LearnRateSchedule',params.learn_rate_schedule, ...
    'LearnRateDropFactor',params.learn_rate_drop_factor, ...
    'LearnRateDropPeriod',params.learn_rate_drop_period, ...
    'Shuffle',params.shuffle, ...
    'L2Regularization',params.L2_reg, ...    
    'ValidationData',{XVal,YVal}, ...
    'ValidationFrequency',params.validationFrequency, ...
    'Momentum',params.momentum, ...
    'Verbose',false);

elseif strcmp(params.optimizer,'adam') && show_plots == 1
    
   options = trainingOptions(params.optimizer, ...
    'MiniBatchSize',params.batch_size, ...
    'MaxEpochs',params.max_epochs, ...
    'InitialLearnRate',params.learn_rate, ...
    'LearnRateSchedule',params.learn_rate_schedule, ...
    'LearnRateDropFactor',params.learn_rate_drop_factor, ...
    'LearnRateDropPeriod',params.learn_rate_drop_period, ...
    'Shuffle',params.shuffle, ...
    'L2Regularization',params.L2_reg, ...    
    'ValidationData',{XVal,YVal}, ...
    'ValidationFrequency',params.validationFrequency, ...
    'Plots','training-progress', ...
    'Verbose',false);

elseif strcmp(params.optimizer,'adam') && show_plots == 0
    
    options = trainingOptions(params.optimizer, ...
    'MiniBatchSize',params.batch_size, ...
    'MaxEpochs',params.max_epochs, ...
    'InitialLearnRate',params.learn_rate, ...
    'LearnRateSchedule',params.learn_rate_schedule, ...
    'LearnRateDropFactor',params.learn_rate_drop_factor, ...
    'LearnRateDropPeriod',params.learn_rate_drop_period, ...
    'Shuffle',params.shuffle, ...
    'L2Regularization',params.L2_reg, ...    
    'ValidationData',{XVal,YVal}, ...
    'ValidationFrequency',params.validationFrequency, ...
    'Verbose',false);

else
       
    disp('Model parameters not defined!')
    
end

function X_aug = image_augmentation(Xdata,aug_params)
%Randomly augment images slice-by-slice between given ranges, optionally add Gaussian noise:

X_aug = zeros(size(Xdata));

imageAugmenter = imageDataAugmenter( ...
    'RandRotation',aug_params.rot, ...
    'RandXTranslation',aug_params.trans_x, ...
    'RandYTranslation',aug_params.trans_y, ...
    'RandXReflection', aug_params.refl_x, ...
    'RandYReflection', aug_params.refl_y, ...
    'RandScale', aug_params.scale, ...
    'RandXShear', aug_params.shear_x, ...
    'RandYShear', aug_params.shear_y);

for i = 1:size(Xdata,4)
Xtrain_single = Xdata(:,:,:,i);
Xtrain_single_aug = augment(imageAugmenter,Xtrain_single);

if aug_params.add_gauss_noise == 1
Xtrain_single_aug = imnoise(Xtrain_single_aug,'gaussian',0,aug_params.gauss_noise_var);
end

X_aug(:,:,:,i) = Xtrain_single_aug;
end

3 运行结果

4 参考文献

[1]闫康. 基于卷积神经网络和灰色模型的轴承健康评估及预测研究. 

博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。

部分理论引用网络文献,若有侵权联系博主删除。

   1 内容介绍

电力系统的安全稳定运行与国民经济的发展及社会人身财产安全息息相关.准确的短期负荷预测结果是电网指导电力系统制定发电计划,协调机组运行,调度负荷分配及制定检修计划的重要依据.随着智能电网的发展及越来越多的分布式电源的接入,影响短期负荷预测结果的因素更加复杂,使负荷呈现更强的非线性,这种严峻的环境也对短期负荷预测的准确度和适应性提出了更高的要求.电力系统的负荷由于数据量庞大,受众多因素影响等使其具有随机性,非线性,时序性等特点.卷积神经网络(Convolutional Neural Networks,CNN)能够深入挖掘信息的多重特点并从中获得有用的特征描述,是一种准确高效的特征提取方法.本文结合负荷序列的特点,使用CNN来对电力系统短期负荷进行预测。

2 仿真代码

clc, clearvars, close all
%------------------------------------------------------------------------------------------------

function X_aug = image_augmentation(Xdata,aug_params)
%Randomly augment images slice-by-slice between given ranges, optionally add Gaussian noise:

X_aug = zeros(size(Xdata));

imageAugmenter = imageDataAugmenter( ...
    'RandRotation',aug_params.rot, ...
    'RandXTranslation',aug_params.trans_x, ...
    'RandYTranslation',aug_params.trans_y, ...
    'RandXReflection', aug_params.refl_x, ...
    'RandYReflection', aug_params.refl_y, ...
    'RandScale', aug_params.scale, ...
    'RandXShear', aug_params.shear_x, ...
    'RandYShear', aug_params.shear_y);

for i = 1:size(Xdata,4)
Xtrain_single = Xdata(:,:,:,i);
Xtrain_single_aug = augment(imageAugmenter,Xtrain_single);

if aug_params.add_gauss_noise == 1
Xtrain_single_aug = imnoise(Xtrain_single_aug,'gaussian',0,aug_params.gauss_noise_var);
end

X_aug(:,:,:,i) = Xtrain_single_aug;
end


%%%%% Deep learning convolutional neural network regression v1.1 %%%%%
% With network parameter gridsearch, input normalization and geometric image augmenation:

function [X_equal,Y_equal] = ROS(Xdata,Ydata,duplication_factor)
%Equalize output (Ydata) distribution using random oversampling:

[Ydata_counts, Ydata_bins] = histcounts(Ydata);
Ydata_max_count = max(Ydata_counts);
Ydata_max_count_ratio = floor(Ydata_max_count*(1./Ydata_counts));

Ydata_max_count_ratio = Ydata_max_count*(1./Ydata_counts);
Ydata_max_count_ratio_norm = Ydata_max_count_ratio/sum(Ydata_max_count_ratio);

for i = 1:numel(Ydata)
    Ydata_bins_temp = Ydata_bins(1:end-1);
    Ydata_bins_temp(Ydata_bins_temp > Ydata(i)) = 0;
    [~,Ydata_bin_idx] = max(Ydata_bins_temp);
    Ydata_prob(i,1) = Ydata_max_count_ratio_norm(Ydata_bin_idx);
end

ROS_selection = randsample(numel(Ydata),numel(Ydata)*duplication_factor,true,Ydata_prob(:,1));
Y_equal = Ydata(ROS_selection);
X_equal = Xdata(:,:,:,ROS_selection);


%For testing, to view original and randomly oversampled input histogram:
%{
figure()
histogram(Ydata,Ydata_bins)
xlabel('RBC content (%)')
ylabel('Count')

figure()
histogram(Y_equal,Ydata_bins)
xlabel('RBC content (%)')
ylabel('Count')
%}


;

disp(['Network accuracy: ', num2str(results_test.accuracy_test)])
disp(['Network absolute error: ', num2str(results_test.error_abs_test)])
disp(['Network RMSE: ', num2str(results_test.rmse_test)])


%Plot display predicted against true Y values for test set images:
linear_fit = polyfit(YTest,results_test.predicted_test,1);
x_space = linspace(0,0.6);
y_fit = polyval(linear_fit,x_space);
y_space = x_space;

dlm = fitlm(YTest,results_test.predicted_test,'Intercept',false);
figure()
hold on
plot(YTest,'r-');hold on
plot(results_test.predicted_test,'b-')
xlabel('时间') 
ylabel('值') 
legend('真实值','预测值')
figure()
hold on
scatter(YTest,results_test.predicted_test)
plot(x_space,y_fit)
plot(x_space,y_space,'k--')
hold off
title('Network test set predictions')
xlabel('True Y value') 
ylabel('Predicted Y value') 
axis([0 0.6 0 0.6])

function options = network_options(params,XVal,YVal,show_plots)

if strcmp(params.optimizer,'sgdm') && show_plots == 1
    
    options = trainingOptions(params.optimizer, ...
    'MiniBatchSize',params.batch_size, ...
    'MaxEpochs',params.max_epochs, ...
    'InitialLearnRate',params.learn_rate, ...
    'LearnRateSchedule',params.learn_rate_schedule, ...
    'LearnRateDropFactor',params.learn_rate_drop_factor, ...
    'LearnRateDropPeriod',params.learn_rate_drop_period, ...
    'Shuffle',params.shuffle, ...
    'L2Regularization',params.L2_reg, ...    
    'ValidationData',{XVal,YVal}, ...
    'ValidationFrequency',params.validationFrequency, ...
    'Plots','training-progress', ...
    'Momentum',params.momentum, ...
    'Verbose',false);

elseif strcmp(params.optimizer,'sgdm') && show_plots == 0
    
    options = trainingOptions(params.optimizer, ...
    'MiniBatchSize',params.batch_size, ...
    'MaxEpochs',params.max_epochs, ...
    'InitialLearnRate',params.learn_rate, ...
    'LearnRateSchedule',params.learn_rate_schedule, ...
    'LearnRateDropFactor',params.learn_rate_drop_factor, ...
    'LearnRateDropPeriod',params.learn_rate_drop_period, ...
    'Shuffle',params.shuffle, ...
    'L2Regularization',params.L2_reg, ...    
    'ValidationData',{XVal,YVal}, ...
    'ValidationFrequency',params.validationFrequency, ...
    'Momentum',params.momentum, ...
    'Verbose',false);

elseif strcmp(params.optimizer,'adam') && show_plots == 1
    
   options = trainingOptions(params.optimizer, ...
    'MiniBatchSize',params.batch_size, ...
    'MaxEpochs',params.max_epochs, ...
    'InitialLearnRate',params.learn_rate, ...
    'LearnRateSchedule',params.learn_rate_schedule, ...
    'LearnRateDropFactor',params.learn_rate_drop_factor, ...
    'LearnRateDropPeriod',params.learn_rate_drop_period, ...
    'Shuffle',params.shuffle, ...
    'L2Regularization',params.L2_reg, ...    
    'ValidationData',{XVal,YVal}, ...
    'ValidationFrequency',params.validationFrequency, ...
    'Plots','training-progress', ...
    'Verbose',false);

elseif strcmp(params.optimizer,'adam') && show_plots == 0
    
    options = trainingOptions(params.optimizer, ...
    'MiniBatchSize',params.batch_size, ...
    'MaxEpochs',params.max_epochs, ...
    'InitialLearnRate',params.learn_rate, ...
    'LearnRateSchedule',params.learn_rate_schedule, ...
    'LearnRateDropFactor',params.learn_rate_drop_factor, ...
    'LearnRateDropPeriod',params.learn_rate_drop_period, ...
    'Shuffle',params.shuffle, ...
    'L2Regularization',params.L2_reg, ...    
    'ValidationData',{XVal,YVal}, ...
    'ValidationFrequency',params.validationFrequency, ...
    'Verbose',false);

else
       
    disp('Model parameters not defined!')
    
end

function X_aug = image_augmentation(Xdata,aug_params)
%Randomly augment images slice-by-slice between given ranges, optionally add Gaussian noise:

X_aug = zeros(size(Xdata));

imageAugmenter = imageDataAugmenter( ...
    'RandRotation',aug_params.rot, ...
    'RandXTranslation',aug_params.trans_x, ...
    'RandYTranslation',aug_params.trans_y, ...
    'RandXReflection', aug_params.refl_x, ...
    'RandYReflection', aug_params.refl_y, ...
    'RandScale', aug_params.scale, ...
    'RandXShear', aug_params.shear_x, ...
    'RandYShear', aug_params.shear_y);

for i = 1:size(Xdata,4)
Xtrain_single = Xdata(:,:,:,i);
Xtrain_single_aug = augment(imageAugmenter,Xtrain_single);

if aug_params.add_gauss_noise == 1
Xtrain_single_aug = imnoise(Xtrain_single_aug,'gaussian',0,aug_params.gauss_noise_var);
end

X_aug(:,:,:,i) = Xtrain_single_aug;
end

3 运行结果

4 参考文献

[1]闫康. 基于卷积神经网络和灰色模型的轴承健康评估及预测研究. 

博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。

部分理论引用网络文献,若有侵权联系博主删除。

X_aug(:,:,:,i) = Xtrain_single_aug;
end


%%%%% Deep learning convolutional neural network regression v1.1 %%%%%
% With network parameter gridsearch, input normalization and geometric image augmenation:

function [X_equal,Y_equal] = ROS(Xdata,Ydata,duplication_factor)
%Equalize output (Ydata) distribution using random oversampling:

[Ydata_counts, Ydata_bins] = histcounts(Ydata);
Ydata_max_count = max(Ydata_counts);
Ydata_max_count_ratio = floor(Ydata_max_count*(1./Ydata_counts));

Ydata_max_count_ratio = Ydata_max_count*(1./Ydata_counts);
Ydata_max_count_ratio_norm = Ydata_max_count_ratio/sum(Ydata_max_count_ratio);

for i = 1:numel(Ydata)
    Ydata_bins_temp = Ydata_bins(1:end-1);
    Ydata_bins_temp(Ydata_bins_temp > Ydata(i)) = 0;
    [~,Ydata_bin_idx] = max(Ydata_bins_temp);
    Ydata_prob(i,1) = Ydata_max_count_ratio_norm(Ydata_bin_idx);
end

ROS_selection = randsample(numel(Ydata),numel(Ydata)*duplication_factor,true,Ydata_prob(:,1));
Y_equal = Ydata(ROS_selection);
X_equal = Xdata(:,:,:,ROS_selection);


%For testing, to view original and randomly oversampled input histogram:
%{
figure()
histogram(Ydata,Ydata_bins)
xlabel('RBC content (%)')
ylabel('Count')

figure()
histogram(Y_equal,Ydata_bins)
xlabel('RBC content (%)')
ylabel('Count')
%}


;

disp(['Network accuracy: ', num2str(results_test.accuracy_test)])
disp(['Network absolute error: ', num2str(results_test.error_abs_test)])
disp(['Network RMSE: ', num2str(results_test.rmse_test)])


%Plot display predicted against true Y values for test set images:
linear_fit = polyfit(YTest,results_test.predicted_test,1);
x_space = linspace(0,0.6);
y_fit = polyval(linear_fit,x_space);
y_space = x_space;

dlm = fitlm(YTest,results_test.predicted_test,'Intercept',false);
figure()
hold on
plot(YTest,'r-');hold on
plot(results_test.predicted_test,'b-')
xlabel('时间') 
ylabel('值') 
legend('真实值','预测值')
figure()
hold on
scatter(YTest,results_test.predicted_test)
plot(x_space,y_fit)
plot(x_space,y_space,'k--')
hold off
title('Network test set predictions')
xlabel('True Y value') 
ylabel('Predicted Y value') 
axis([0 0.6 0 0.6])

function options = network_options(params,XVal,YVal,show_plots)

if strcmp(params.optimizer,'sgdm') && show_plots == 1
    
    options = trainingOptions(params.optimizer, ...
    'MiniBatchSize',params.batch_size, ...
    'MaxEpochs',params.max_epochs, ...
    'InitialLearnRate',params.learn_rate, ...
    'LearnRateSchedule',params.learn_rate_schedule, ...
    'LearnRateDropFactor',params.learn_rate_drop_factor, ...
    'LearnRateDropPeriod',params.learn_rate_drop_period, ...
    'Shuffle',params.shuffle, ...
    'L2Regularization',params.L2_reg, ...    
    'ValidationData',{XVal,YVal}, ...
    'ValidationFrequency',params.validationFrequency, ...
    'Plots','training-progress', ...
    'Momentum',params.momentum, ...
    'Verbose',false);

elseif strcmp(params.optimizer,'sgdm') && show_plots == 0
    
    options = trainingOptions(params.optimizer, ...
    'MiniBatchSize',params.batch_size, ...
    'MaxEpochs',params.max_epochs, ...
    'InitialLearnRate',params.learn_rate, ...
    'LearnRateSchedule',params.learn_rate_schedule, ...
    'LearnRateDropFactor',params.learn_rate_drop_factor, ...
    'LearnRateDropPeriod',params.learn_rate_drop_period, ...
    'Shuffle',params.shuffle, ...
    'L2Regularization',params.L2_reg, ...    
    'ValidationData',{XVal,YVal}, ...
    'ValidationFrequency',params.validationFrequency, ...
    'Momentum',params.momentum, ...
    'Verbose',false);

elseif strcmp(params.optimizer,'adam') && show_plots == 1
    
   options = trainingOptions(params.optimizer, ...
    'MiniBatchSize',params.batch_size, ...
    'MaxEpochs',params.max_epochs, ...
    'InitialLearnRate',params.learn_rate, ...
    'LearnRateSchedule',params.learn_rate_schedule, ...
    'LearnRateDropFactor',params.learn_rate_drop_factor, ...
    'LearnRateDropPeriod',params.learn_rate_drop_period, ...
    'Shuffle',params.shuffle, ...
    'L2Regularization',params.L2_reg, ...    
    'ValidationData',{XVal,YVal}, ...
    'ValidationFrequency',params.validationFrequency, ...
    'Plots','training-progress', ...
    'Verbose',false);

elseif strcmp(params.optimizer,'adam') && show_plots == 0
    
    options = trainingOptions(params.optimizer, ...
    'MiniBatchSize',params.batch_size, ...
    'MaxEpochs',params.max_epochs, ...
    'InitialLearnRate',params.learn_rate, ...
    'LearnRateSchedule',params.learn_rate_schedule, ...
    'LearnRateDropFactor',params.learn_rate_drop_factor, ...
    'LearnRateDropPeriod',params.learn_rate_drop_period, ...
    'Shuffle',params.shuffle, ...
    'L2Regularization',params.L2_reg, ...    
    'ValidationData',{XVal,YVal}, ...
    'ValidationFrequency',params.validationFrequency, ...
    'Verbose',false);

else
       
    disp('Model parameters not defined!')
    
end

function X_aug = image_augmentation(Xdata,aug_params)
%Randomly augment images slice-by-slice between given ranges, optionally add Gaussian noise:

X_aug = zeros(size(Xdata));

imageAugmenter = imageDataAugmenter( ...
    'RandRotation',aug_params.rot, ...
    'RandXTranslation',aug_params.trans_x, ...
    'RandYTranslation',aug_params.trans_y, ...
    'RandXReflection', aug_params.refl_x, ...
    'RandYReflection', aug_params.refl_y, ...
    'RandScale', aug_params.scale, ...
    'RandXShear', aug_params.shear_x, ...
    'RandYShear', aug_params.shear_y);

for i = 1:size(Xdata,4)
Xtrain_single = Xdata(:,:,:,i);
Xtrain_single_aug = augment(imageAugmenter,Xtrain_single);

if aug_params.add_gauss_noise == 1
Xtrain_single_aug = imnoise(Xtrain_single_aug,'gaussian',0,aug_params.gauss_noise_var);
end

X_aug(:,:,:,i) = Xtrain_single_aug;
end

3 运行结果

4 参考文献

[1]闫康. 基于卷积神经网络和灰色模型的轴承健康评估及预测研究. 

博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。

部分理论引用网络文献,若有侵权联系博主删除。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/喵喵爱编程/article/detail/801735
推荐阅读
相关标签
  

闽ICP备14008679号