Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Neural Network Building Energy Forecast
Replies: 1   Last Post: Feb 15, 2013 6:40 AM

 Greg Heath Posts: 6,387 Registered: 12/7/04
Re: Neural Network Building Energy Forecast
Posted: Feb 15, 2013 6:40 AM

"Subodh Paudel" <subodhpaudel@gmail.com> wrote in message
<kfitfe\$8hi\$1@newscl01ah.mathworks.com>...
> Hai All,
> I want to forecast the building energy demand: input parameters:

outside temperature and solar radiation, and output parameter: energy
consumption
>
> I am choosing 2 layered network. I have a 1826 samples. My R2

value is in negative and i am not finding the solution of it? Please,
could you help me.
>
> The data size consists all inputs and targets in column vector.

[ I N ] = size( input ) % [ 2 1826 ]
[ O N ] = size( target ) % [ 1 1826 ]

>I have used 70% samples for the generalization and 30% for prediction.

Terminology:

total = design + test
design = train + validation

> The souce code is given:
>
> %Size of input and Target Layers I:Input Layer, O:Output Layer,

Official Terminology: 2 layers of Hidden and Output neurons. Input
elements are fan-in units and NOT neurons. The unmodifed term
'layer' does not apply to inputs. The typical MLP is a 2-layer FFNN.

I don't like this at all. Therefore I only refer to (3) layers of nodes (NOT
neurons!). Consequently, since the typical MLP always has a layer of
input nodes and a layer of output nodes, I refer to the typical topology
as a MLP or FFNN with one hidden layer (of nodes or neurons).

dN=size of
> %the data
> [dN I]=size(data);

Please remove the "d" it is unnecessary and confusing.

> dNt=round(0.7*dN); %70% of Data Used for the Training and
Generalization

Not standard terminology or proceedure
Design = Training and Validation
Use Validation set iteratively to determine training parameters and
choose best of multiple designs.
Need a nondesign subset (Test) to predict generalization error.
If results are unsatisfactory, need to repeat with a new trn/val/tst
data split (i.e., Test set is only used ONCE!)

> input_sample= data((1:dNt),1:2)';
> target_sample=data((1:dNt),3)';
> validation_inputsample=data(((dNt+1):dN),1:2)';
> validation_targetsample=data(((dNt+1):dN),3)';
>
> %DataProcessing of Training Sample (normalization with

mean 0.1 and 0.9)
> [pn,ps]=mapstd(input_sample,0.1,0.9);
> [tn,ts]=mapstd(target_sample,0.1,0.9);

No! There is absolutely no good reason to do that!
Standarization means zero-mean/unit-variance.

> %Apply Normalization to the Validation Input Sample
> an=mapstd('apply',validation_inputsample,ps);
>
> %Iterative Optimization wrt to RMSE to determine Hidden

Neurons:hidden_node,

Use dimensionless NMSE = MSE/MSE00 (MSE00 =
mean(var(target',1)) ) instead of scale dependent RMSE.
Then coefficient of determination (i.e., R^2) is given by
R2 =1-NMSE.

> %Learning Rate:lr_rate and Momentum:mc_rate
> sbmin=99999999;
> hidden_node=0;
> mc_rate=0;
> lr_rate=0;
> mm=1;

??
Always begin with the MATLAB defaults.

> %MLP (2-1-1 Network)with tangent hyperbolic transfer function in
the hidden layer and
> %Linear Activation Function in the Output Layer

TERMINOLOGY: 2-H-1 node topology

> %Initial Hidden Neuron Size Varies from 5 to 10

Ntrneq = Ntrn*O % No. of training equations
Nw = (I+1)*H+(H+1)*O % No. of unknown weights

To mitigate noise and measurement error when not
using regularization(msereg) or validation stopping,
require Ntrneq >= Nw but desire Ntrneq >> Nw.
This yields an upperbound for H

Hub = -1 + ceil( (Ntrneq-O)/(I+O+1)) % 319

%Hub = -1 + ceil( ( 0.7*1826-1)/(2+1+1) ) = 319
%Hmax ~ round(Hub/8) = 40

> for i=1:1:40;

How about starting with a coarse search 1:5:40

> net=newff(minmax(pn),[i 1],{'tansig','purelin'},'trainlm')
> net.performFcn='mse';
> net.performParam=[];
> net.trainParam.goal=0.01*var(tn);
> net.trainParam.epochs=1000;
> net.trainParam.show=30;
> net.trainParam.mu_max=1e10;

Too complicated. To start, use as many defaults as possible
For example

net=newff(minmax(pn),[i 1]);
net.trainParam.goal=0.01*var(tn);
net.trainParam.show=30;

> net.trainParam.max_fail=20;

Too high for val stopping. Just delete and accept the default of 6.

> for k=1:1:4 %Learning Rate Varies from 0.25 to 1
> lr=0.25+(k-1)*.25;
> net.trainParam.lr=lr;
> for m=1:1:4 %Momentum Varies from 0.25 to 1
> mc=0.25+(m-1)*0.25;
> net.trainParam.m=mc;
> net=init(net);%Assume 0 weight
> net=train(net,pn,tn);
> yn=sim(net,pn);
> y=mapstd('reverse',yn,ts);
> error=y-target_sample;
> RMSE(i,k,m)=sqrt(mse(error));%RMSE Value Check for

the Minimum Root Mean Square
> if RMSE(i,k,m)<sbmin
> sbmin=RMSE(i,k,m);
> hidden_node=i;
> mc_rate=mc;
> lr_rate=lr;
> IW_initial=net.IW{1,1};
> LW_initial=net.IW{2,1};
> hidden_bias_initial=net.b{1};
> output_bias_initial=net.b{2};
> end
> end
> end
> end

??? Life is already hard enough, why not accept most defaults
and just search over H and initial weights?

NOTE: minmax version of newff automatically configures the
initial weights.

I'll stop here. Basically, start simple and gradually make
improvements. Your current code will probably take hours and
not give you any insight.

Hope this helps.

Greg

> parameters =[hidden_node mc_rate lr_rate]
> net=newff(minmax(pn),[hidden_node 1],{'tansig','purelin'},'trainlm')
> net.performFcn='mse';
> net.performParam=[];
> net.trainParam.goal=0.01*var(tn);
> net.trainParam.epochs=1000;
> net.trainParam.show=30;
> net.trainParam.mu_max=1e10;
> net.trainParam.max_fail=20;
> net.trainParam.lr=lr_rate;
> net.trainParam.m=mc_rate;
>
> MSE_initial=mean(var(target_sample)); %Approximate MSE for

a constant output model
> net.IW{1,1}=IW_initial;
> net.IW{2,1}=LW_initial;
> net.b{1}=hidden_bias_initial;
> net.b{2}=output_bias_initial;
>
> net=train(net,pn,tn);
> yn=sim(net,an);
> y=mapstd('reverse',yn,ts);
> %Error Calculation
> error=y-validation_targetsample;
> percentage_error=abs(error)./y*100; %Percentage of Error
> RMSE=sqrt(mse(error)); %Root Mean Square Error
> NMSE= mse(error)/MSE_initial; % Normalized Mean Square Error
> R2=1-NMSE; %R^2 Statistics for the Regression Analysis
> MAE=mean(abs(error)); %Mean Absolute Error
> MAPE = mean(percentage_error); % Mean Absolute Percentage

Error
> %Analysis of Predicted and Target Values
> performance_error=[RMSE R2]
> pp=[validation_targetsample y];
> figure(1)
> plot(y,'g')
> hold
> plot(validation_targetsample,'r')
> title('comparision between actual targets and predictions'