%该程序已在MATLAB2010b运行通过
function varargout = gui(varargin)
% GUI MATLAB code for gui.fig
% GUI, by itself, creates a new GUI or raises the existing
% singleton*.
%
% H = GUI returns the handle to a new GUI or the handle to
% the existing singleton*.
%
% GUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUI.M with the given input arguments.
%
% GUI('Property','Value',...) creates a new GUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before gui_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to gui_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help gui
% Last Modified by GUIDE v2.5 13-Sep-2015 19:51:50
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @gui_OpeningFcn, ...
'gui_OutputFcn', @gui_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before gui is made visible.
function gui_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to gui (see VARARGIN)
% Choose default command line output for gui
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes gui wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = gui_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
input = get(handles.edit1,'String');
input = str2num(input);
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a doubl
% --- Executes during object creation, after setting all properties.
input = get(handles.edit2,'String');
input = str2num(input);
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit3_Callback(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit3 as text
% str2double(get(hObject,'String')) returns contents of edit3 as a double
% --- Executes during object creation, after setting all properties.
input = get(handles.edit3,'String');
input = str2num(input);
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
C = 30;
theta = 2;%C为最小二乘支持向量机的正则化参数,theta为高斯径向基的核函数参数,两个需要进行优化选择调试
NumOfPre = 1;%预测天数,在此预测本季度最后七天
Time = 24;
Data = xlsread('a23.xls');%此为从excel表格读数据的命令,表示将表格的数据读到Data数组中,省略表格中的第一行第一列文字部分 可输入你要预测的表格名称
[M N] = size(Data);%计算读入数据的行和列 M行N列
for i = 1:3
maxData = max(Data(:,i));
minData = min(Data(:,i));
Data1(:,i) = (Data(:,i) - minData)/(maxData-minData);%对温度进行归一化处理
end
for i = 4:5
Data1(:,i) = Data(:,i);
end
for i = 6:N
Data1(:,i) = log10(Data(:,i)) ;%对负荷进行对数处理 温度和负荷的预处理 可采用不同的方法
end
Dim = M - 2 - NumOfPre;%训练样本数%训练样本数
Input = zeros(M-2,12,Time);%预先分配处理后的输入向量空间
y = zeros(Dim,Time);
for i = 3:M
for j = 1:Time
%%选取前一天温度、同一时刻的负荷,前两天的负荷,当天的温度作为输入特征
x = [Data1(i-1,1:5), Data1(i-1,j+5), Data1(i-2,j+5),Data1(i,1:5)];
Input(i-2,:,j) = x;
y(i-2,j) = Data1(i,j+5);
end
end
Dist = zeros(Dim,Dim,Time);%预先分配距离空间
for i=1:Time
for j=1:Dim
for k=1:Dim
Dist(j,k,i) = (Input(j,:,i) - Input(k,:,i))*(Input(j,:,i) - Input(k,:,i))';
end
end
end
Dist1 = exp(-Dist/(2*theta));%RBF
for i=1:Time
H = Dist1(:,:,i) + eye(Dim)/C;%最小二乘支持向量的H矩阵
f = -y(1:Dim,i);
Aeq = ones(Dim,1)';
beq = [0];
option.MaxIter=1000;
[a,fval]=quadprog(H,f,[],[],Aeq,beq);%,[],[],[],option);
b = 0;
for j = 1:Dim
b(j) = y(j,i) - a(j)/C - a'* Dist1(:,j,i);%求每个输入特征对应的b
end
b = sum(b)/Dim;%求平均b,消除误差
for j = Dim + 1:M-2
for k = 1:Dim
K(k) = exp(-(Input(j,:,i) - Input(k,:,i))*(Input(j,:,i) - Input(k,:,i))'/(2*theta));%预测输入特征与训练特征的RBF距离
end
Pre(j-Dim,i) = sum(a'*K') + b; %求解预测值
end
end
Len = M - (Dim + 3) + 1;%预测的天数 取本季度最后Len天
Pre = 10.^Pre;
for i = 1:Len
%figure
axes(handles.axes1);
pl
SVM实现负荷预测,其中包含基本SVM,PSO优化SVM,改进SVM三种方法
需积分: 45 194 浏览量
2018-09-17
11:00:15
上传
评论 22
收藏 713KB RAR 举报
oYuanDongLi1
- 粉丝: 6
- 资源: 4
最新资源
- NetOps-py通过sftp替换网络设备启动文件
- STM32单片机FPGA毕设电路原理论文报告任务驱动教学法在单片机课程教学中的应用
- STM32单片机FPGA毕设电路原理论文报告任务驱动法在单片机教学中的应用
- STM32单片机FPGA毕设电路原理论文报告人造金刚石压机智能化压力测控系统设计
- 以某列为依据匹配多项(Excel版)
- STM32单片机FPGA毕设电路原理论文报告人体短臂离心机实验台的显示控制系统
- STM32单片机FPGA毕设电路原理论文报告人工气候室监控系统的环境控制器研究
- STM32单片机FPGA毕设电路原理论文报告染整自动线张力控制系统的设计
- 数据挖掘与机器学习-实验
- 基于Linux系统Nginx的动态网站的LNMP环境源码包
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈