Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Data/agriculture.mat
Binary file not shown.
13 changes: 0 additions & 13 deletions FindCSV.m

This file was deleted.

25 changes: 0 additions & 25 deletions FindFolders.m

This file was deleted.

13 changes: 0 additions & 13 deletions FindMAT.m

This file was deleted.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
![Weather](https://user-images.githubusercontent.com/12642226/126882902-fed11a73-99d1-41a8-8533-7b5cd16f4c8d.png)

# To work better it is recommended:
- The main code in the project folder
- The data in a subfolder called "Data"
Expand Down
Binary file added main.mlx
Binary file not shown.
Binary file added main.pdf
Binary file not shown.
13 changes: 13 additions & 0 deletions src/PlotFigure.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
clear;clc;
Datos=load('agriculture.mat');Datos=Datos.agriculture;
Min=min(Datos);
Max=max(Datos);
%nomalization
nDatos=(Datos./Max);%-Min;
%% plot
figure
plot(nDatos(:,2:5));
hold on
plot(nDatos(:,6),'--');
legend("Relative Humidity","Environment Temperature","Soil moisture"...
,"Light intensity","Rain Occurrence",'NumColumns',3);
Binary file added src/PlotVariables.fig
Binary file not shown.
Binary file added src/PlotVariables.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions src/fBar_MaeMseR2.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
% Bar graph root mean absolute error (MAE), mean square error (MSE) and R squared
% input: yest, y youtput
% return: mae,mse, r2
% More examples: https://github.com/vasanza/Matlab_Code
% Read more: https://vasanza.blogspot.com/
function [mae,mse,r2] = fBar_MaeMseR2(yest,youtput)
mae = sum(abs(yest-youtput)/length(yest));
%mse = mean((output - yest).^2);
mse = immse(yest, youtput);
r2 = fR2(youtput,yest);
% Difference between the mean square error and the true value
%dmser=mean(sqrt((yest-youtput).^2)./youtput);

c = categorical({'MAE','MSE','1-R2'});
values = [mae mse 1-r2];
figure;
b=bar(c,values);

%xlabel('xlabel')
ylabel('Error')
title('MAE, MSE and 1-R2')

xtips1 = b(1).XEndPoints - 0.2;
ytips1 = b(1).YEndPoints + 0.0003;
labels1 = string(b(1).YData);
text(xtips1,ytips1,labels1,'VerticalAlignment','middle')
end
26 changes: 26 additions & 0 deletions src/fBar_MseR2.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
% Bar graph root mean square error (MSE) and R squared
% input: yest, y youtput
% return: mse, r2
% More examples: https://github.com/vasanza/Matlab_Code
% Read more: https://vasanza.blogspot.com/
function [mse,r2] = fBar_MseR2(yest,youtput)
%rmse = sqrt(mean((output - yest).^2));
%rmse = sqrt(immse(yest, youtput));
%mse = mean((output - yest).^2);
mse = immse(yest, youtput);
r2 = fR2(youtput,yest);

c = categorical({'MSE','1-R2'});
values = [mse 1-r2];
figure;
b=bar(c,values);

%xlabel('xlabel')
ylabel('Error')
title('MSE and 1-R2')

xtips1 = b(1).XEndPoints - 0.2;
ytips1 = b(1).YEndPoints + 0.0003;
labels1 = string(b(1).YData);
text(xtips1,ytips1,labels1,'VerticalAlignment','middle')
end
28 changes: 28 additions & 0 deletions src/fBar_RmseMseMae.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
% Bar graph root mean square error (RMSE), mean square error (MSE) and mean absolute error (MAE)
% input: yest, y youtput
% return: rmse,mse, mae
% More examples: https://github.com/vasanza/Matlab_Code
% Read more: https://vasanza.blogspot.com/
function [rmse,mse,mae] = fBar_RmseMseMae(yest,youtput)
%rmse = sqrt(mean((output - yest).^2));
rmse = sqrt(immse(yest, youtput));
%mse = mean((output - yest).^2);
mse = immse(yest, youtput);
mae = sum(abs(yest-youtput)/length(yest));
% Difference between the mean square error and the true value
%dmser=mean(sqrt((yest-youtput).^2)./youtput);

c = categorical({'MAE','MSE','RMSE'});
values = [rmse mse mae];
figure;
b=bar(c,values);

%xlabel('xlabel')
ylabel('Error')
title('RMSE, MSE and MAE')

xtips1 = b(1).XEndPoints - 0.2;
ytips1 = b(1).YEndPoints + 0.0003;
labels1 = string(b(1).YData);
text(xtips1,ytips1,labels1,'VerticalAlignment','middle')
end
File renamed without changes.
File renamed without changes.
73 changes: 73 additions & 0 deletions src/myNeuralNetworkFunction_BR.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
function [y1] = myNeuralNetworkFunction_BR(x1)
%MYNEURALNETWORKFUNCTION neural network simulation function.
%
% Auto-generated by MATLAB, 12-Jul-2021 12:16:11.
%
% [y1] = myNeuralNetworkFunction(x1) takes these arguments:
% x = Qx5 matrix, input #1
% and returns:
% y = Qx1 matrix, output #1
% where Q is the number of samples.

%#ok<*RPMT0>

% ===== NEURAL NETWORK CONSTANTS =====

% Input 1
x1_step1.xoffset = [0.608695652173913;0.82370820668693;0.433566433566434;0.0124984476084822;0];
x1_step1.gain = [5.11111111111111;11.3448275862069;3.53086419753086;2.02531327181859;4];
x1_step1.ymin = -1;

% Layer 1
b1 = [0.00035174026259418046669;0.00051092816047968955297;-0.00048391175546749315125;-0.00050981894364561498;0.00053107338220117399161;0.00042076275179294889269;-0.08001026386788413769;-0.00052123117927782200952;0.15745448440093531839;-0.067634534449094715902];
IW1_1 = [0.00029940427633355415132 -0.00091351092567174430742 0.00035050945272335786752 0.00054201144080147822986 -0.0006553261154915732481;0.00043483496913422018532 -0.0013268466275537572387 0.00050908684357890937426 0.00078723075997475118991 -0.00095181600158640057574;-0.00041185539151189476913 0.0012567042505490203137 -0.00048217772185979798508 -0.00074561911857309566901 0.00090150388804861110621;-0.00043389146051596373839 0.0013239667398766085359 -0.00050798200136364002506 -0.00078552225583856721478 0.00094975028080367834317;0.00045196848775252984609 -0.0013791473561833049108 0.00052915087847809467135 0.00081825737359259107656 -0.00098932999443373213777;0.00035813397574167632129 -0.0010927404007482076527 0.00041927332239120770592 0.00064834552211519617081 -0.00078389209306386792731;0.60348615247481129931 -0.31381583708022858792 0.57257217686362416043 0.58517705395397245915 -0.00041552308730919947435;-0.00044359788315542270955 0.0013535954267334779529 -0.00051934848696569009107 -0.000803099149488242358 0.00097100231079647308235;-0.17588209086211484267 -0.11370070401550631811 -0.98882602763530946799 0.27919569916621544969 0.068327356243596343299;-0.8882180602117247803 0.1560561953219604947 -0.4013236356394274118 -0.18485228807893513969 0.051201117667770981723];

% Layer 2
b2 = 0.21194446183604778722;
LW2_1 = [0.0013771378901323138438 0.0020005088943848372586 -0.0018946378611525214845 -0.0019967650998719966952 0.0020801898158251267215 0.0016473761574264276716 0.56432693796989685797 -0.0020410398899658637253 -1.1382824405110656407 0.52130642137983940199];

% Output 1
y1_step1.ymin = -1;
y1_step1.gain = 3.53086419753086;
y1_step1.xoffset = 0.433566433566434;

% ===== SIMULATION ========

% Dimensions
Q = size(x1,1); % samples

% Input 1
x1 = x1';
xp1 = mapminmax_apply(x1,x1_step1);

% Layer 1
a1 = tansig_apply(repmat(b1,1,Q) + IW1_1*xp1);

% Layer 2
a2 = repmat(b2,1,Q) + LW2_1*a1;

% Output 1
y1 = mapminmax_reverse(a2,y1_step1);
y1 = y1';
end

% ===== MODULE FUNCTIONS ========

% Map Minimum and Maximum Input Processing Function
function y = mapminmax_apply(x,settings)
y = bsxfun(@minus,x,settings.xoffset);
y = bsxfun(@times,y,settings.gain);
y = bsxfun(@plus,y,settings.ymin);
end

% Sigmoid Symmetric Transfer Function
function a = tansig_apply(n,~)
a = 2 ./ (1 + exp(-2*n)) - 1;
end

% Map Minimum and Maximum Output Reverse-Processing Function
function x = mapminmax_reverse(y,settings)
x = bsxfun(@minus,y,settings.ymin);
x = bsxfun(@rdivide,x,settings.gain);
x = bsxfun(@plus,x,settings.xoffset);
end
73 changes: 73 additions & 0 deletions src/myNeuralNetworkFunction_LM.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
function [y1] = myNeuralNetworkFunction_LM(x1)
%MYNEURALNETWORKFUNCTION neural network simulation function.
%
% Auto-generated by MATLAB, 12-Jul-2021 12:17:06.
%
% [y1] = myNeuralNetworkFunction(x1) takes these arguments:
% x = Qx5 matrix, input #1
% and returns:
% y = Qx1 matrix, output #1
% where Q is the number of samples.

%#ok<*RPMT0>

% ===== NEURAL NETWORK CONSTANTS =====

% Input 1
x1_step1.xoffset = [0.608695652173913;0.82370820668693;0.433566433566434;0.0124984476084822;0];
x1_step1.gain = [5.11111111111111;11.3448275862069;3.53086419753086;2.02531327181859;4];
x1_step1.ymin = -1;

% Layer 1
b1 = [2.1949853578616629335;-1.7469328441935882967;0.99240755064494678983;1.0218472696166676084;-0.20364962239710274194;0.075006696145808071652;0.86849978954689988075;-1.7528113775439608801;-2.1635286289685735639;1.9533738151333810418];
IW1_1 = [-1.0200111942236536056 0.18371207872449493714 -1.4761242942088723673 -0.68794352417100779196 1.0905174575592302411;0.15849883407858353368 -0.76811703825605215368 1.6988832804854816505 -0.68283686162590440105 0.67432444400053681566;-0.64349214417223599138 0.40030808532394601684 1.1057920048993226114 0.21412508236109187298 1.1990683467370717441;-0.48795612410084338029 -1.2250250302922145451 0.67407093082124247552 0.81674746062738967645 -1.5287905283841298765;0.36787248393377131039 0.64062360566131126838 1.4243599683899237363 -0.54873720927763891542 -1.4872545148778710811;-0.9268852109842726783 -1.0196075464390572662 -0.34597136023448776809 -1.4471455571856632893 -0.5530734974790058045;0.48424032314825560253 -0.1811170079280729206 0.97468818170933824163 -1.3859231772694791118 1.142501422637789199;-0.64255807181742796708 0.67010085976123234808 -2.6434921749012407766 -0.68891688899908154475 1.4610370159121313094;0.15189272482242013873 0.50924382354552510943 1.5003722988369436742 -1.9880704228772694275 0.8904186285136883594;0.28925144735049329592 0.5742974445922626181 -1.0987458626795434391 -2.0475217260707032629 -0.7219189729790551624];

% Layer 2
b2 = 0.49227585916764610152;
LW2_1 = [-0.5167614963278497342 -0.11906540081385030838 0.61823532419030025054 0.19156553538645498813 0.23647371873576578105 -0.012726615235693293157 0.092360116876703701738 -0.334773211566524731 0.42646907290742258612 -0.34115551012335215697];

% Output 1
y1_step1.ymin = -1;
y1_step1.gain = 3.53086419753086;
y1_step1.xoffset = 0.433566433566434;

% ===== SIMULATION ========

% Dimensions
Q = size(x1,1); % samples

% Input 1
x1 = x1';
xp1 = mapminmax_apply(x1,x1_step1);

% Layer 1
a1 = tansig_apply(repmat(b1,1,Q) + IW1_1*xp1);

% Layer 2
a2 = repmat(b2,1,Q) + LW2_1*a1;

% Output 1
y1 = mapminmax_reverse(a2,y1_step1);
y1 = y1';
end

% ===== MODULE FUNCTIONS ========

% Map Minimum and Maximum Input Processing Function
function y = mapminmax_apply(x,settings)
y = bsxfun(@minus,x,settings.xoffset);
y = bsxfun(@times,y,settings.gain);
y = bsxfun(@plus,y,settings.ymin);
end

% Sigmoid Symmetric Transfer Function
function a = tansig_apply(n,~)
a = 2 ./ (1 + exp(-2*n)) - 1;
end

% Map Minimum and Maximum Output Reverse-Processing Function
function x = mapminmax_reverse(y,settings)
x = bsxfun(@minus,y,settings.ymin);
x = bsxfun(@rdivide,x,settings.gain);
x = bsxfun(@plus,x,settings.xoffset);
end