展会信息港展会大全

关于MATLAB 的程序,神经网络问题
来源:互联网   发布日期:2011-09-27 11:53:07   浏览:18664次  

导读:%以每三个月的销售量经归一化处理后作为输入 p=[0.5152 0.8173 1.0000 0.8173 1.0000 0.7308 1.0000 0.7308 0.1390 0.7308 0.1390 0.1087 0.1390 0.1087 0.3520...

提问人的追问   2011-08-14 13:08 这些没用的,是最上面的数据,这些是为了举个列子。我试了很多遍还是出不来来

回答人的补充   2011-08-14 13:53

主要是组织数据,里面的实际意义你也没详细讲,我这里就针对数据而言。

% 2007-4-30 8.43 10.58 11.47
% 2007-5-31 10.58 11.47 12.67
% 2007-6-29 11.47 12.67 17.31
% 2007-7-31 12.67 17.31 16.52
% 2007-8-31 17.31 16.52 18.5
% 2007-9-28 16.52 18.5 16.33
% 2007-10-31 18.5 16.33 16.62
% 2007-11-30 16.33 16.62 14.48
% 2007-12-28 16.62 14.48 13.26
% 2008-1-31 14.48 13.26 11.14
% 2008-2-29 13.26 11.14 13.32
% 2008-3-31 11.14 13.32 11.56
% 2008-4-30 13.32 11.56 9.04
% 2008-5-30 11.56 9.04 9.33
% 2008-6-30 9.04 9.33 9.03
% 2008-7-31 9.33 9.03 6.42
% 2008-8-29 9.03 6.42 4.83
% 2008-9-26 6.42 4.83 4.93
% 2008-10-31 4.83 4.93 5.45
% 2008-11-28 4.93 5.45 6.86
% 2008-12-31 5.45 6.86 7.31
% 2009-1-23 6.86 7.31 9.01
% 2009-2-27 7.31 9.01 9.52
% 2009-3-31 9.01 9.52 
% 2009-4-30 9.52  


% 用BP神经网络进行预测
clc; clear all; close all;
format long;

data = [8.43 10.58 11.47
10.58 11.47 12.67
11.47 12.67 17.31
12.67 17.31 16.52
17.31 16.52 18.5
16.52 18.5 16.33
18.5 16.33 16.62
16.33 16.62 14.48
16.62 14.48 13.26
14.48 13.26 11.14
13.26 11.14 13.32
11.14 13.32 11.56
13.32 11.56 9.04
11.56 9.04 9.33
9.04 9.33 9.03
9.33 9.03 6.42
9.03 6.42 4.83
6.42 4.83 4.93
4.83 4.93 5.45
4.93 5.45 6.86
5.45 6.86 7.31
6.86 7.31 9.01
7.31 9.01 9.52];
TT = data(:, 1:2);
t = data(:, 3);
damax=max(max(max(TT)),max(t));
damin=min(min(min(TT)),min(t));
[a,b]=size(TT);
for i=1:a
    pp(i,:)=(TT(i,:)-damin)/(damax-damin);
end
tt=(t-damin)/(damax-damin);
n=length(tt);
threshold=[0,1;0,1];
net=newff(threshold,[3,1],{'tansig','logsig'},'trainlm');
net.trainParam.epochs=1000;
net.trainParam.goal=0.001;
LP.lr=0.1;
pp = pp';
net=train(net,pp(:,1:n),tt');
for i=1:length(pp)
    p_test=pp(:,i);
    out(i)=sim(net,p_test);
    pre(i)=out(i)*(damax-damin)+damin;
end

figure; hold on; box on;
plot3(pp(1, 1:n), pp(2, 1:n), tt, 'b-+', pp(1, :), pp(2, :), out, 'r-');
legend('原曲线', '神经网络模拟曲线');
title('神经网络模拟(变换后)');
figure; hold on; box on;
plot3(TT(1:n, 1), TT(1:n, 2), t, 'b-+', TT(:, 1), TT(:, 2), out, 'r-');
legend('原曲线', '神经网络模拟曲线');
title('神经网络模拟(变换前)');

 

提问人的追问   2011-08-14 14:15

2007-4-308.43

2007-5-3110.58

2007-6-2911.47

2007-7-3112.67

2007-8-3117.31

2007-9-2816.52

2007-10-3118.5

2007-11-3016.33

2007-12-2816.62

2008-1-3114.48

2008-2-2913.26

2008-3-3111.14

2008-4-3013.32

2008-5-3011.56

2008-6-309.04

2008-7-319.33

2008-8-299.03

2008-9-266.42

2008-10-314.83

2008-11-284.93

2008-12-315.45

2009-1-236.86

2009-2-277.31

2009-3-319.01

2009-4-309.52

我用这一排数据来的。用前天昨天今天来预测明天的数据。

这是股票预测。

回答人的补充   2011-08-14 14:22

刚才的代码中,取前两列数据,也就是昨天、今天的数据,来预测目标数据,也就是明天的数据。

% 2007-4-30 8.43 10.58 11.47
% 2007-5-31 10.58 11.47 12.67
% 2007-6-29 11.47 12.67 17.31
% 2007-7-31 12.67 17.31 16.52
% 2007-8-31 17.31 16.52 18.5
% 2007-9-28 16.52 18.5 16.33
% 2007-10-31 18.5 16.33 16.62
% 2007-11-30 16.33 16.62 14.48
% 2007-12-28 16.62 14.48 13.26
% 2008-1-31 14.48 13.26 11.14
% 2008-2-29 13.26 11.14 13.32
% 2008-3-31 11.14 13.32 11.56
% 2008-4-30 13.32 11.56 9.04
% 2008-5-30 11.56 9.04 9.33
% 2008-6-30 9.04 9.33 9.03
% 2008-7-31 9.33 9.03 6.42
% 2008-8-29 9.03 6.42 4.83
% 2008-9-26 6.42 4.83 4.93
% 2008-10-31 4.83 4.93 5.45
% 2008-11-28 4.93 5.45 6.86
% 2008-12-31 5.45 6.86 7.31
% 2009-1-23 6.86 7.31 9.01
% 2009-2-27 7.31 9.01 9.52
% 2009-3-31 9.01 9.52
% 2009-4-30 9.52


% 用BP神经网络进行预测
clc; clear all; close all;
format long;

data = [8.43 10.58 11.47
    10.58 11.47 12.67
    11.47 12.67 17.31
    12.67 17.31 16.52
    17.31 16.52 18.5
    16.52 18.5 16.33
    18.5 16.33 16.62
    16.33 16.62 14.48
    16.62 14.48 13.26
    14.48 13.26 11.14
    13.26 11.14 13.32
    11.14 13.32 11.56
    13.32 11.56 9.04
    11.56 9.04 9.33
    9.04 9.33 9.03
    9.33 9.03 6.42
    9.03 6.42 4.83
    6.42 4.83 4.93
    4.83 4.93 5.45
    4.93 5.45 6.86
    5.45 6.86 7.31
    6.86 7.31 9.01
    7.31 9.01 9.52];
TT = data(:, 1:2);
t = data(:, 3);
damax=max(max(max(TT)),max(t));
damin=min(min(min(TT)),min(t));
[a,b]=size(TT);
for i=1:a
    pp(i,:)=(TT(i,:)-damin)/(damax-damin);
end
tt=(t-damin)/(damax-damin);
n=length(tt);
threshold=[0,1;0,1];
net=newff(threshold,[3,1],{'tansig','logsig'},'trainlm');
net.trainParam.epochs=1000;
net.trainParam.goal=0.001;
LP.lr=0.1;
pp = pp';
net=train(net,pp(:,1:n),tt');
for i=1:length(pp)
    p_test=pp(:,i);
    out(i)=sim(net,p_test);
    pre(i)=out(i)*(damax-damin)+damin;
end
p_test1 = [9.01 9.52];
p_test2 =(p_test1-damin)/(damax-damin);
out = sim(net, p_test2');
pre1 = out *(damax-damin)+damin

结果

pre1 =

   7.498638394693880

 

也就是,2009-3-31 9.01 9.52对应的结果。

赞助本站

人工智能实验室
AiLab云推荐
推荐内容
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港