├── Curves ├── 2-Years │ ├── output │ ├── Max DewPoint.png │ ├── Max Humidity.png │ ├── Max Pressure.png │ ├── Min DewPoint.png │ ├── Min Humidity.png │ ├── Min Pressure.png │ ├── Actual Classes.png │ ├── Max Temperature.png │ ├── Max Visibility.png │ ├── Mean Wind Speed.png │ ├── Min Temperature.png │ ├── Min Visibility.png │ └── Predicted Classes.png ├── 5-Years │ ├── output │ ├── Max DewPoint.png │ ├── Max Humidity.png │ ├── Max Pressure.png │ ├── Min DewPoint.png │ ├── Min Humidity.png │ ├── Min Pressure.png │ ├── Max Temperature.png │ ├── Max Visibility.png │ ├── Mean Wind Speed.png │ ├── Min Temperature.png │ └── Min Visibility.png ├── Testing │ ├── 1month │ ├── January2016Events.png │ ├── January2016PredictionsMax DewPoint.png │ ├── January2016PredictionsMax Humidity.png │ ├── January2016PredictionsMax Pressure.png │ ├── January2016PredictionsMax Visibility.png │ ├── January2016PredictionsMin DewPoint.png │ ├── January2016PredictionsMin Humidity.png │ ├── January2016PredictionsMin Pressure.png │ ├── January2016PredictionsMin Visibility.png │ ├── January2016PredictionsMax Temperature.png │ └── January2016PredictionsMean Wind Speed.png ├── Output ├── Classes.png ├── Max DewPoint.png ├── Max Humidity.png ├── Max Pressure.png ├── Max Visibility.png ├── Min DewPoint.png ├── Min Humidity.png ├── Min Pressure.png ├── Min Visibility.png ├── Max Temperature.png ├── Mean Wind Speed.png └── Min Temperature.png ├── sigmoid.m ├── saveYearlyPrediction.m ├── OptimalThetaC2.txt ├── OptimalThetaC3.txt ├── forwardPropClassifier.m ├── forwardPropPredictor.m ├── backPropClassifier.m ├── saveNN.m ├── backPropPredictor.m ├── Classifier.m ├── OptimalThetaC1.txt ├── predictionCostFunction.m ├── README.md ├── nn.m ├── Predictor.m ├── loadYearlyWeather.m ├── YearlyForecast.m ├── OptimalThetaP1.txt ├── OptimalThetaP2.txt ├── TestMonth.m ├── plotCurves.m ├── main.cpp ├── January2016.txt ├── Weather1999.txt ├── Weather2002.txt ├── Weather2001.txt ├── Weather2012.txt ├── Weather2005.txt ├── Weather2009.txt ├── Weather2008.txt ├── Weather2000.txt ├── Weather2003.txt └── Weather2004.txt /Curves/2-Years/output: -------------------------------------------------------------------------------- 1 | Curves for 2 year data. 2 | -------------------------------------------------------------------------------- /Curves/5-Years/output: -------------------------------------------------------------------------------- 1 | Curves for training 5 years 2 | -------------------------------------------------------------------------------- /Curves/Testing/1month: -------------------------------------------------------------------------------- 1 | The month of January 2016 is plotted 2 | -------------------------------------------------------------------------------- /Curves/Output: -------------------------------------------------------------------------------- 1 | Example to show All curves for 2 years data are stored in this directory 2 | -------------------------------------------------------------------------------- /Curves/Classes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/Classes.png -------------------------------------------------------------------------------- /Curves/Max DewPoint.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/Max DewPoint.png -------------------------------------------------------------------------------- /Curves/Max Humidity.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/Max Humidity.png -------------------------------------------------------------------------------- /Curves/Max Pressure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/Max Pressure.png -------------------------------------------------------------------------------- /Curves/Max Visibility.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/Max Visibility.png -------------------------------------------------------------------------------- /Curves/Min DewPoint.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/Min DewPoint.png -------------------------------------------------------------------------------- /Curves/Min Humidity.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/Min Humidity.png -------------------------------------------------------------------------------- /Curves/Min Pressure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/Min Pressure.png -------------------------------------------------------------------------------- /Curves/Min Visibility.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/Min Visibility.png -------------------------------------------------------------------------------- /Curves/Max Temperature.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/Max Temperature.png -------------------------------------------------------------------------------- /Curves/Mean Wind Speed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/Mean Wind Speed.png -------------------------------------------------------------------------------- /Curves/Min Temperature.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/Min Temperature.png -------------------------------------------------------------------------------- /Curves/2-Years/Max DewPoint.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/2-Years/Max DewPoint.png -------------------------------------------------------------------------------- /Curves/2-Years/Max Humidity.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/2-Years/Max Humidity.png -------------------------------------------------------------------------------- /Curves/2-Years/Max Pressure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/2-Years/Max Pressure.png -------------------------------------------------------------------------------- /Curves/2-Years/Min DewPoint.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/2-Years/Min DewPoint.png -------------------------------------------------------------------------------- /Curves/2-Years/Min Humidity.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/2-Years/Min Humidity.png -------------------------------------------------------------------------------- /Curves/2-Years/Min Pressure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/2-Years/Min Pressure.png -------------------------------------------------------------------------------- /Curves/5-Years/Max DewPoint.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/5-Years/Max DewPoint.png -------------------------------------------------------------------------------- /Curves/5-Years/Max Humidity.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/5-Years/Max Humidity.png -------------------------------------------------------------------------------- /Curves/5-Years/Max Pressure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/5-Years/Max Pressure.png -------------------------------------------------------------------------------- /Curves/5-Years/Min DewPoint.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/5-Years/Min DewPoint.png -------------------------------------------------------------------------------- /Curves/5-Years/Min Humidity.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/5-Years/Min Humidity.png -------------------------------------------------------------------------------- /Curves/5-Years/Min Pressure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/5-Years/Min Pressure.png -------------------------------------------------------------------------------- /sigmoid.m: -------------------------------------------------------------------------------- 1 | ## Author: user 2 | ## Created: 2016-10-01 3 | 4 | function [s] = sigmoid (z) 5 | s = 2./(1+e.^((-2)*z)) - 1; 6 | endfunction -------------------------------------------------------------------------------- /Curves/2-Years/Actual Classes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/2-Years/Actual Classes.png -------------------------------------------------------------------------------- /Curves/2-Years/Max Temperature.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/2-Years/Max Temperature.png -------------------------------------------------------------------------------- /Curves/2-Years/Max Visibility.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/2-Years/Max Visibility.png -------------------------------------------------------------------------------- /Curves/2-Years/Mean Wind Speed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/2-Years/Mean Wind Speed.png -------------------------------------------------------------------------------- /Curves/2-Years/Min Temperature.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/2-Years/Min Temperature.png -------------------------------------------------------------------------------- /Curves/2-Years/Min Visibility.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/2-Years/Min Visibility.png -------------------------------------------------------------------------------- /Curves/5-Years/Max Temperature.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/5-Years/Max Temperature.png -------------------------------------------------------------------------------- /Curves/5-Years/Max Visibility.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/5-Years/Max Visibility.png -------------------------------------------------------------------------------- /Curves/5-Years/Mean Wind Speed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/5-Years/Mean Wind Speed.png -------------------------------------------------------------------------------- /Curves/5-Years/Min Temperature.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/5-Years/Min Temperature.png -------------------------------------------------------------------------------- /Curves/5-Years/Min Visibility.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/5-Years/Min Visibility.png -------------------------------------------------------------------------------- /Curves/2-Years/Predicted Classes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/2-Years/Predicted Classes.png -------------------------------------------------------------------------------- /Curves/Testing/January2016Events.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/Testing/January2016Events.png -------------------------------------------------------------------------------- /Curves/Testing/January2016PredictionsMax DewPoint.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/Testing/January2016PredictionsMax DewPoint.png -------------------------------------------------------------------------------- /Curves/Testing/January2016PredictionsMax Humidity.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/Testing/January2016PredictionsMax Humidity.png -------------------------------------------------------------------------------- /Curves/Testing/January2016PredictionsMax Pressure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/Testing/January2016PredictionsMax Pressure.png -------------------------------------------------------------------------------- /Curves/Testing/January2016PredictionsMax Visibility.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/Testing/January2016PredictionsMax Visibility.png -------------------------------------------------------------------------------- /Curves/Testing/January2016PredictionsMin DewPoint.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/Testing/January2016PredictionsMin DewPoint.png -------------------------------------------------------------------------------- /Curves/Testing/January2016PredictionsMin Humidity.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/Testing/January2016PredictionsMin Humidity.png -------------------------------------------------------------------------------- /Curves/Testing/January2016PredictionsMin Pressure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/Testing/January2016PredictionsMin Pressure.png -------------------------------------------------------------------------------- /Curves/Testing/January2016PredictionsMin Visibility.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/Testing/January2016PredictionsMin Visibility.png -------------------------------------------------------------------------------- /Curves/Testing/January2016PredictionsMax Temperature.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/Testing/January2016PredictionsMax Temperature.png -------------------------------------------------------------------------------- /Curves/Testing/January2016PredictionsMean Wind Speed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-a-y-a-n-k/Weather-Prediction-Using-Neural-Networks/HEAD/Curves/Testing/January2016PredictionsMean Wind Speed.png -------------------------------------------------------------------------------- /saveYearlyPrediction.m: -------------------------------------------------------------------------------- 1 | ## Author: user 2 | ## Created: 2016-10-01 3 | 4 | function saveYearlyPrediction (FP) 5 | file = "PredictionYear"; 6 | for year = 1997:2015 7 | fp = FP([(1+(year-1997)*365):((year-1996)*365)],:); 8 | save("-ascii",strcat(file,num2str(year),'.txt'),"fp"); 9 | endfor 10 | endfunction -------------------------------------------------------------------------------- /OptimalThetaC2.txt: -------------------------------------------------------------------------------- 1 | 1.99957301e+000 1.35176956e+000 -8.77566956e-001 1.37479885e+000 7.34905119e-001 2 | 5.14984942e-001 1.57673711e+000 -3.14221359e-001 3.26230316e-001 4.89446227e-001 3 | 1.45699698e+000 1.02585004e+000 -1.05261030e+000 1.08430777e+000 1.91566027e+000 4 | -1.64000546e+000 -6.06364767e-001 3.24480937e-001 -7.65716126e-001 -3.43215993e-001 5 | -------------------------------------------------------------------------------- /OptimalThetaC3.txt: -------------------------------------------------------------------------------- 1 | -7.51205048e-001 -7.54063762e-001 -5.93774080e-001 7.96366191e-001 9.55353044e-003 2 | -7.56179892e-001 -2.77651735e-001 -3.26086247e-001 6.24380673e-002 3.03700195e-001 3 | 1.17907971e-001 9.79010368e-001 7.91259575e-001 -1.14702777e-001 -3.67329255e-001 4 | 1.06400300e-001 1.44424806e-001 -4.95105741e-001 -3.54967377e-001 -7.13082820e-002 5 | -------------------------------------------------------------------------------- /forwardPropClassifier.m: -------------------------------------------------------------------------------- 1 | ## Author: user 2 | ## Created: 2016-9-31 3 | 4 | function [A2,A3,A4] = forwardPropClassifier (X,THETA1,THETA2,THETA3) 5 | m = size(X,2); 6 | A1 = X; 7 | Z2 = THETA1 * A1; 8 | A2 = [ones(1,m); sigmoid(Z2)]; 9 | Z3 = THETA2 * A2; 10 | A3 = [ones(1,m); sigmoid(Z3)]; 11 | Z4 = THETA3 * A3; 12 | A4 = sigmoid(Z4); 13 | endfunction 14 | -------------------------------------------------------------------------------- /forwardPropPredictor.m: -------------------------------------------------------------------------------- 1 | ## Author: user 2 | ## Created: 2016-10-01 3 | 4 | function [a1,a2,a3] = forwardPropPredictor (x,iT1,iT2) 5 | e = size(x,2); 6 | a1 = x; # Layer 1 input features 7 | z1 = iT1*a1; 8 | a2 = [ ones(1,e); z1]; # Layer 2 with bias unit 9 | z2 = iT2*a2; 10 | a3 = [ ones(1,e); z2]; # Layer 3 output features with bias 11 | endfunction -------------------------------------------------------------------------------- /backPropClassifier.m: -------------------------------------------------------------------------------- 1 | ## Author: user 2 | ## Created: 2016-9-31 3 | 4 | function [DELTA1,DELTA2,DELTA3] = backPropClassifier (Y, A3, A2, A1, h, THETA3, THETA2) 5 | err4 = h - Y; 6 | err3 = ((THETA3' * err4) .* (1-A3.^2) )(2:end); 7 | err2 = ((THETA2' * err3) .* (1-A2.^2) )(2:end); 8 | DELTA3 = (err4 * A3'); 9 | DELTA2 = (err3 * A2'); 10 | DELTA1 = (err2 * A1'); 11 | endfunction 12 | -------------------------------------------------------------------------------- /saveNN.m: -------------------------------------------------------------------------------- 1 | ## Author: user 2 | ## Created: 2016-11-01 3 | 4 | function saveNN(OT1,OT2,OTC1,OTC2,OTC3) 5 | file = "OptimalTheta"; 6 | save("-ascii",strcat(file,'P1','.txt'),"OT1"); 7 | save("-ascii",strcat(file,'P2','.txt'),"OT1"); 8 | save("-ascii",strcat(file,'C1','.txt'),"OTC1"); 9 | save("-ascii",strcat(file,'C2','.txt'),"OTC2"); 10 | save("-ascii",strcat(file,'C3','.txt'),"OTC3"); 11 | endfunction -------------------------------------------------------------------------------- /backPropPredictor.m: -------------------------------------------------------------------------------- 1 | ## Author: user 2 | ## Created: 2016-10-01 3 | 4 | function [gradVec] = backPropPredictor (a1,a2,a3,theta1,theta2,y,e,lambda) 5 | err3 = (a3 - y); 6 | err3([1],:) = []; 7 | 8 | err2 = theta2'*err3; 9 | err2([1],:) = []; # removing 1st row of bias 10 | 11 | Del2 = err3*a2'; 12 | Del1 = err2*a1'; 13 | 14 | D2 = (1/e)*(Del2) + lambda*theta2; 15 | D1 = (1/e)*(Del1) + lambda*theta1; 16 | 17 | gradVec = [D1(:);D2(:)]; 18 | endfunction -------------------------------------------------------------------------------- /Classifier.m: -------------------------------------------------------------------------------- 1 | ## Author: user 2 | ## Created: 2016-10-02 3 | 4 | function [THETA1,THETA2,THETA3,FC] = Classifier (X, Y, alpha, IEPSILON) 5 | 6 | THETA1 = 0; 7 | THETA2 = 0; 8 | THETA3 = 0; 9 | M = size(X,2); 10 | FC = 0; 11 | J = 0; 12 | [THETA1, THETA2, THETA3, J, FC] = nn(X(:,1), Y(:,1), THETA1, THETA2, THETA3, IEPSILON, 1, alpha, J, FC); 13 | for i = 2:M 14 | [THETA1, THETA2, THETA3, J, FC] = nn(X(:,i), Y(:,i), THETA1, THETA2, THETA3, IEPSILON, 0, alpha, J, FC); 15 | endfor 16 | FC([1],:) = []; 17 | endfunction -------------------------------------------------------------------------------- /OptimalThetaC1.txt: -------------------------------------------------------------------------------- 1 | -2.18735118e-003 -6.23677821e-001 -3.57269379e-001 4.76760114e-001 -3.80138526e-001 9.21467654e-001 -2.76194060e-003 1.54610820e-001 1.46771164e-001 7.71849509e-001 3.61449225e-001 9.67361543e-001 2 | -8.97399220e-001 2.75641350e-001 -2.51198851e-001 2.84434053e-003 -1.66438321e-001 -9.25169906e-001 6.88165028e-001 1.62802344e-001 -4.23154937e-001 -3.59152106e-001 -9.33863441e-001 -5.71153249e-001 3 | -3.28613161e-002 5.11016904e-001 4.32484882e-001 8.59522294e-001 2.46745541e-001 -6.73534583e-001 -6.88524223e-001 7.74527841e-002 7.59875465e-002 -9.24204188e-001 -5.58384297e-001 3.16795302e-001 4 | -1.22088907e-002 7.24113958e-001 3.38884716e-001 -3.52512707e-001 5.96828838e-001 -4.17200449e-001 -4.41110949e-001 5.87024165e-001 2.24220956e+000 -4.01072500e-001 9.68721336e-001 3.40344643e-001 5 | -------------------------------------------------------------------------------- /predictionCostFunction.m: -------------------------------------------------------------------------------- 1 | ## Author: user 2 | ## Created: 2016-10-01 3 | 4 | function [jVal,gradientVec] = predictionCostFunction (thetaVec,nof,x,y,e,lambda) 5 | # Use reshape to get theta matrices for each layer 6 | theta1 = reshape( thetaVec( 1:(nof-1)*nof ), nof-1, nof ); 7 | theta2 = reshape( thetaVec( ( (nof-1)*nof )+1:(nof-1)*nof*2), nof-1, nof ); 8 | 9 | # Aplying forward propagation 10 | [a1,a2,a3] = forwardPropPredictor(x,theta1,theta2); 11 | 12 | # Computing Error and Cost Function 13 | sqrError = sum(sum((a3 - y).^2)); 14 | jVal = (1/(2*e) )*( sqrError + lambda*sum(thetaVec.^2) ); # Cost Function J to minimize 15 | 16 | # Applying backpropagation 17 | [gradientVec] = backPropPredictor(a1,a2,a3,theta1,theta2,y,e,lambda); # Gradient Vector to make Optimum for minimization 18 | endfunction -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Weather-Prediction-Using-Neural-Networks 2 | Machine Learning Project for classifying Weather into ThunderStorm (0001) , Rainy(0010) , Foggy (0100) , Sunny(1000) and also predict weather features for next one month after training on 20 years data on a neural network 3 | This is my first Machine Learning Project. 4 | 5 | 6 | Steps To run the project: 7 | 8 | 1. Extract the files into a single directory ( say "MyWeatherProject" ) 9 | 10 | 2. Open Octave(GUI) and go to the above directory 11 | 12 | 3. Type the following in the COMMAND WINDOW : "YearlyForecast();" (without double quotes) 13 | 14 | 4. Open the files "PredictionWeather1997.txt" to "PredictionWeather2016.txt" and compare with actual results from "Weather1997.txt" to "Weather2015.txt". 15 | 16 | 5. Curves are plotted to compare predictions with actual weather conditions and they will be saved in the same directory... 17 | -------------------------------------------------------------------------------- /nn.m: -------------------------------------------------------------------------------- 1 | ## Author: user 2 | ## Created: 2016-10-09 3 | 4 | function [THETA1_new, THETA2_new, THETA3_new, J, FC] = nn (X, Y, THETA1, THETA2, THETA3, IEPSILON, init_w, alpha, J, FC) 5 | 6 | if (init_w == 1) 7 | nof = size(X,1); 8 | K = size(Y,1); 9 | J = 0; 10 | FC = zeros(1,K); 11 | THETA1 = 2*IEPSILON*rand( K, nof ) - IEPSILON; 12 | THETA2 = 2*IEPSILON*rand( K, K+1 ) - IEPSILON; 13 | THETA3 = 2*IEPSILON*rand( K, K+1 ) - IEPSILON; 14 | endif 15 | 16 | for i = 1:500 17 | [A2,A3,h] = forwardPropClassifier(X,THETA1,THETA2,THETA3); 18 | if i == 500 19 | h = (h > 0.5); 20 | FC = [FC;h']; 21 | J = J + ( sum( Y.*(h) ) + sum( ( 1 - Y ).*(1 - h) ) ); 22 | endif 23 | [DELTA1,DELTA2,DELTA3] = backPropClassifier (Y, A3, A2, X, h, THETA3, THETA2); 24 | THETA1_new = THETA1 - (alpha * DELTA1); 25 | THETA2_new = THETA2 - (alpha * DELTA2); 26 | THETA3_new = THETA3 - (alpha * DELTA3); 27 | endfor 28 | 29 | endfunction -------------------------------------------------------------------------------- /Predictor.m: -------------------------------------------------------------------------------- 1 | function [optTheta1,optTheta2,FP] = Predictor(X,iniTheta1,iniTheta2,lambda) 2 | nof = size(X,1); 3 | M = size(X,2); 4 | m = 365; 5 | e = M-m; 6 | x = X(:,1); 7 | y = X(:,366); 8 | 9 | for i = 367:M 10 | x = [x,X(:,i-m)]; 11 | y = [y,X(:,i)]; 12 | endfor 13 | 14 | # Unrolling into Theta Vector 15 | thetaVec = [ iniTheta1(:); iniTheta2(:) ]; 16 | 17 | # Minimize Cost Function to get OptTheta Vector 18 | options = optimset( 'GradObj', 'on', 'MaxIter', 1000000 ); 19 | [optThetaVec, jMin, exitFlag ] = fminunc( @(thetaVec)(predictionCostFunction(thetaVec,nof,x,y,e,lambda)), thetaVec, options ); 20 | 21 | # Reshaping Optimal Theta Vector into Matrices for Layer 1 and Layer 2 22 | optTheta1 = reshape( optThetaVec( 1:(nof-1)*nof ), nof-1, nof ); 23 | optTheta2 = reshape( optThetaVec( ( (nof-1)*nof )+1:(nof-1)*nof*2), nof-1, nof ); 24 | 25 | # Apply Forward Propogation to make final Predictions in Nueral Network 26 | [a1,a2,FP] = forwardPropPredictor(x,optTheta1,optTheta2); 27 | 28 | endfunction -------------------------------------------------------------------------------- /loadYearlyWeather.m: -------------------------------------------------------------------------------- 1 | ## Author: user 2 | ## Created: 2016-10-01 3 | 4 | function [X,Y] = loadYearlyWeather() 5 | 6 | #load all files 7 | file = "Weather"; 8 | year = 1997; 9 | 10 | load(strcat(file,num2str(year),".txt"),"-ascii"); 11 | X = eval( genvarname (strcat(file,num2str(year))) ); 12 | 13 | nof = size(X); 14 | nof = nof(2); # getting number of features including bias unit 15 | 16 | for year = 1998:2015 17 | load(strcat(file,num2str(year),".txt"),"-ascii"); 18 | X = [X;eval(genvarname(strcat(file,num2str(year))))]; # generate variable from file name and concat with existing matrix 19 | endfor 20 | 21 | # Classification of Weather 22 | Y = X(:,[nof]); 23 | 24 | # Removing Classification Column 25 | X(:,[nof]) = []; 26 | X = X'; 27 | 28 | #Generating bitmap of classes for each day 29 | Y = 2.^(log10(Y)); 30 | Nbits = 4; # number of bits you want your representation 31 | bitmap = uint32( 2.^[0:Nbits-1]); # create a bitwise-and mask for every bit 32 | a = zeros( length(Y), Nbits ); 33 | for ii = 1:length(Y) 34 | a(ii,:) = bitand(Y(ii), bitmap )~=0; 35 | endfor 36 | Y = a'; 37 | 38 | endfunction -------------------------------------------------------------------------------- /YearlyForecast.m: -------------------------------------------------------------------------------- 1 | ## Author: user 2 | ## Created: 2016-10-01 3 | 4 | function YearlyForecast() 5 | 6 | #load all the files having weather data each day 7 | [X,Y] = loadYearlyWeather(); 8 | 9 | lambda = 0.01; # regularization parameter 10 | IEPSILON = 1; # range for initial theta of each layer 11 | 12 | nof = size(X,1); # number of features 13 | M = size(X,2); # number of training examples 14 | m = 365; 15 | K = size(Y,1); # number of classification outputs 16 | 17 | # Choose initial Theta for Layer 1 and Layer 2 of Nueral Network 18 | iTheta1 = 2*IEPSILON*rand( nof - 1, nof ) - IEPSILON*ones(nof-1, nof); 19 | iTheta2 = 2*IEPSILON*rand( nof - 1, nof ) - IEPSILON*ones(nof-1, nof); 20 | 21 | # Training Nueral Network to make Predictions for 20 years 22 | [OT1,OT2,FP] = Predictor(X,iTheta1,iTheta2,lambda); 23 | 24 | alpha = 0.75; # learning rate 25 | 26 | # Training Nueral Network to make Classifications for 20 years 27 | [OTC1,OTC2,OTC3,FC] = Classifier(X,Y,alpha,IEPSILON); 28 | 29 | # Testing results obtained from 20 years to predict future weather features for January 2016 30 | TestMonth ( OT1, OT2, OTC1, OTC2, OTC3 ); 31 | 32 | # Save all data into text files 33 | FP = [(X(:,[1:m]))';FP']'; 34 | FP = [FP;FC']'; 35 | saveYearlyPrediction(FP); 36 | 37 | #Plot all curves for 20 years 38 | plotCurves(FP,X',Y); 39 | endfunction -------------------------------------------------------------------------------- /OptimalThetaP1.txt: -------------------------------------------------------------------------------- 1 | 2.25777508e-002 4.26559421e-002 4.94331788e-002 -5.71540620e-002 4.00460842e-001 -8.39140908e-001 -9.00940584e-001 6.41909564e-002 -3.95172197e-001 -3.77194264e-001 -7.28935357e-001 9.32543434e-002 2 | -5.58382856e-001 3.61161723e-001 -3.91820043e-001 1.01108597e-001 -4.18996571e-001 6.25566015e-001 7.02596413e-001 2.04082027e-001 -5.89959850e-001 5.66875519e-001 -8.30165004e-001 -4.86479910e-001 3 | 5.24220633e-001 -4.67545963e-001 -5.52429630e-001 -1.11609591e-001 1.09511899e-003 9.86326393e-002 8.20108711e-002 -3.58764404e-001 -1.14042632e-001 -4.15129894e-001 5.18974774e-001 7.83071605e-002 4 | -2.47874655e-001 3.97111399e-001 -1.41702080e-001 -1.78384799e-001 -2.08525930e-001 1.05523131e-003 1.30298291e-001 3.51949488e-001 4.52787771e-002 2.42643212e-001 -4.95158469e-001 1.03540038e-001 5 | 2.20477380e-001 -4.34269106e-001 -3.89131830e-001 1.90715404e-001 -1.33258492e-001 5.75428793e-001 5.09989146e-001 -4.24593576e-001 -8.71814961e-002 5.30781015e-002 5.29842719e-001 -2.49863842e-001 6 | 3.56833284e-001 9.84087904e-001 4.60830908e-001 4.41275531e-002 -4.36528450e-001 5.84113470e-001 6.93442695e-001 6.64735086e-001 -2.87924825e-001 7.28157804e-001 -1.12286537e+000 -4.30113448e-001 7 | 9.40279730e-002 -2.14067472e-002 -1.50475650e-002 -7.36743672e-002 1.02126253e-001 -3.43869697e-001 -3.36081669e-001 3.51406197e-001 3.33123046e-001 -1.26582025e-002 -7.02496790e-002 2.26483196e-001 8 | -9.61980268e-001 -5.55682497e-002 -8.72491096e-003 3.68293695e-001 3.12703134e-001 -2.46922938e-001 -4.95246966e-001 2.71393498e-001 -3.21745284e-001 1.71837379e-001 -1.02655011e-001 -2.24371595e-001 9 | 3.39860759e-001 7.11630499e-001 -2.59285555e-001 -7.76670524e-001 -3.30460286e-001 -5.56077723e-001 -1.37324799e-001 -4.11974212e-001 -3.79379969e-002 -6.59890835e-001 -1.63350460e-001 6.99087566e-001 10 | 5.40756729e-001 -3.57169445e-001 -4.98372826e-001 1.49522941e-002 -3.60156382e-001 7.55984449e-001 7.80952956e-001 -1.89242748e-001 5.54395615e-001 -7.55594814e-003 5.72147991e-001 -9.07508282e-002 11 | 5.08545172e-001 7.21178876e-001 3.85380614e-001 5.01314561e-003 -1.99814833e-001 1.90583757e-001 2.97108210e-001 -6.12289324e-003 -5.31361323e-001 1.88791849e-001 -5.03006185e-001 -2.45786692e-001 12 | -------------------------------------------------------------------------------- /OptimalThetaP2.txt: -------------------------------------------------------------------------------- 1 | 2.25777508e-002 4.26559421e-002 4.94331788e-002 -5.71540620e-002 4.00460842e-001 -8.39140908e-001 -9.00940584e-001 6.41909564e-002 -3.95172197e-001 -3.77194264e-001 -7.28935357e-001 9.32543434e-002 2 | -5.58382856e-001 3.61161723e-001 -3.91820043e-001 1.01108597e-001 -4.18996571e-001 6.25566015e-001 7.02596413e-001 2.04082027e-001 -5.89959850e-001 5.66875519e-001 -8.30165004e-001 -4.86479910e-001 3 | 5.24220633e-001 -4.67545963e-001 -5.52429630e-001 -1.11609591e-001 1.09511899e-003 9.86326393e-002 8.20108711e-002 -3.58764404e-001 -1.14042632e-001 -4.15129894e-001 5.18974774e-001 7.83071605e-002 4 | -2.47874655e-001 3.97111399e-001 -1.41702080e-001 -1.78384799e-001 -2.08525930e-001 1.05523131e-003 1.30298291e-001 3.51949488e-001 4.52787771e-002 2.42643212e-001 -4.95158469e-001 1.03540038e-001 5 | 2.20477380e-001 -4.34269106e-001 -3.89131830e-001 1.90715404e-001 -1.33258492e-001 5.75428793e-001 5.09989146e-001 -4.24593576e-001 -8.71814961e-002 5.30781015e-002 5.29842719e-001 -2.49863842e-001 6 | 3.56833284e-001 9.84087904e-001 4.60830908e-001 4.41275531e-002 -4.36528450e-001 5.84113470e-001 6.93442695e-001 6.64735086e-001 -2.87924825e-001 7.28157804e-001 -1.12286537e+000 -4.30113448e-001 7 | 9.40279730e-002 -2.14067472e-002 -1.50475650e-002 -7.36743672e-002 1.02126253e-001 -3.43869697e-001 -3.36081669e-001 3.51406197e-001 3.33123046e-001 -1.26582025e-002 -7.02496790e-002 2.26483196e-001 8 | -9.61980268e-001 -5.55682497e-002 -8.72491096e-003 3.68293695e-001 3.12703134e-001 -2.46922938e-001 -4.95246966e-001 2.71393498e-001 -3.21745284e-001 1.71837379e-001 -1.02655011e-001 -2.24371595e-001 9 | 3.39860759e-001 7.11630499e-001 -2.59285555e-001 -7.76670524e-001 -3.30460286e-001 -5.56077723e-001 -1.37324799e-001 -4.11974212e-001 -3.79379969e-002 -6.59890835e-001 -1.63350460e-001 6.99087566e-001 10 | 5.40756729e-001 -3.57169445e-001 -4.98372826e-001 1.49522941e-002 -3.60156382e-001 7.55984449e-001 7.80952956e-001 -1.89242748e-001 5.54395615e-001 -7.55594814e-003 5.72147991e-001 -9.07508282e-002 11 | 5.08545172e-001 7.21178876e-001 3.85380614e-001 5.01314561e-003 -1.99814833e-001 1.90583757e-001 2.97108210e-001 -6.12289324e-003 -5.31361323e-001 1.88791849e-001 -5.03006185e-001 -2.45786692e-001 12 | -------------------------------------------------------------------------------- /TestMonth.m: -------------------------------------------------------------------------------- 1 | ## Author: user 2 | ## Created: 2016-11-05 3 | 4 | function TestMonth ( OTP1, OTP2, OTC1, OTC2, OTC3 ) 5 | 6 | X = load("Weather2015.txt"); 7 | m = 31; 8 | X = (X([1:31],[1:12]))'; 9 | [a1,a2,FP] = forwardPropPredictor (X,OTP1,OTP2); 10 | 11 | X = 1:1:m; 12 | for i=2:12 13 | switch (i) 14 | case 2 15 | label = "Max Temperature"; 16 | case 3 17 | label = "Min Temperature"; 18 | case 4 19 | label = "Max DewPoint"; 20 | case 5 21 | label = "Min DewPoint"; 22 | case 6 23 | label = "Max Humidity"; 24 | case 7 25 | label = "Min Humidity"; 26 | case 8 27 | label = "Max Pressure"; 28 | case 9 29 | label = "Min Pressure"; 30 | case 10 31 | label = "Max Visibility"; 32 | case 11 33 | label = "Min Visibility"; 34 | case 12 35 | label = "Mean Wind Speed"; 36 | otherwise 37 | label = "unknown"; 38 | endswitch 39 | figure; 40 | Y1=FP(i,:)'; 41 | plot(X, Y1, '@r'); 42 | xlabel('Day'); 43 | ylabel(label); 44 | filename = sprintf(strcat('January2016Predictions',label,'.png')); 45 | saveas(gcf, filename, 'png'); 46 | for k = 1:100 47 | ; 48 | endfor 49 | endfor 50 | 51 | [A2,A3,Y] = forwardPropClassifier(FP,OTC1,OTC2,OTC3); 52 | Y = (Y > 0.5); 53 | Y3 = 0; 54 | for i = 1:m 55 | if Y(:,i) == [1;0;0;0] # Actually ThunderStorm 56 | Y3 = [Y3,1]; 57 | elseif Y(:,i) == [0;1;0;0] # Actually Rainy 58 | Y3 = [Y3,2]; 59 | elseif Y(:,i) == [0;0;1;0] # Actually Foggy 60 | Y3 = [Y3,3]; 61 | else 62 | Y3 = [Y3,4]; # Actually Sunny 63 | endif 64 | endfor 65 | Y3(:,1) = []; 66 | figure; 67 | plot(X, Y3,"*b"); 68 | xlabel('Day'); 69 | ylabel('Event'); 70 | filename = sprintf(strcat("January2016Events",'.png')); 71 | saveas(gcf, filename, 'png'); 72 | FP = [FP;Y]'; 73 | save("-ascii",'January2016.txt',"FP"); 74 | endfunction -------------------------------------------------------------------------------- /plotCurves.m: -------------------------------------------------------------------------------- 1 | function plotCurves(Prediction, Actual, Y) 2 | 3 | M = size(Actual,1); 4 | nof = size(Actual,2); 5 | X=1:1:M; 6 | 7 | for i=2:nof 8 | switch (i) 9 | case 2 10 | label = "Max Temperature"; 11 | case 3 12 | label = "Min Temperature"; 13 | case 4 14 | label = "Max DewPoint"; 15 | case 5 16 | label = "Min DewPoint"; 17 | case 6 18 | label = "Max Humidity"; 19 | case 7 20 | label = "Min Humidity"; 21 | case 8 22 | label = "Max Pressure"; 23 | case 9 24 | label = "Min Pressure"; 25 | case 10 26 | label = "Max Visibility"; 27 | case 11 28 | label = "Min Visibility"; 29 | case 12 30 | label = "Mean Wind Speed"; 31 | otherwise 32 | label = "unknown"; 33 | endswitch 34 | figure; 35 | Y1=Prediction(:,[i]); 36 | Y2=Actual(:,[i]); 37 | plot(X, Y2, '*g', X, Y1, '@r'); 38 | legend('Actual', 'Prediction'); 39 | xlabel('Day'); 40 | ylabel(label); 41 | filename = sprintf(strcat(label,'.png')); 42 | saveas(gcf, filename, 'png'); 43 | for k = 1:100 44 | ; 45 | endfor 46 | endfor 47 | 48 | Y3 = 0; 49 | Y4 = 0; 50 | for i = 1:M 51 | if Y(:,i) == [1;0;0;0] # Actually ThunderStorm 52 | Y3 = [Y3,1]; 53 | elseif Y(:,i) == [0;1;0;0] # Actually Rainy 54 | Y3 = [Y3,2]; 55 | elseif Y(:,i) == [0;0;1;0] # Actually Foggy 56 | Y3 = [Y3,3]; 57 | else 58 | Y3 = [Y3,4]; # Actually Sunny 59 | endif 60 | 61 | if Prediction(i,[13:16]) == [1,0,0,0] # Predicted ThunderStorm 62 | Y4 = [Y4,1]; 63 | elseif Prediction(i,[13:16]) == [0,1,0,0] # Predicted Rainy 64 | Y4 = [Y4,2]; 65 | elseif Prediction(i,[13:16]) == [0,0,1,0] # Predicted Foggy 66 | Y4 = [Y4,3]; 67 | else 68 | Y4 = [Y4,4]; # Predicted Sunny 69 | endif 70 | endfor 71 | 72 | Y3(:,1) = []; 73 | Y4(:,1) = []; 74 | figure; 75 | plot(X, Y3,"^b",X,Y4,'@r'); 76 | legend('Actual','Prediction'); 77 | xlabel('Day'); 78 | ylabel('Event'); 79 | filename = sprintf(strcat("Classes",'.png')); 80 | saveas(gcf, filename, 'png'); 81 | 82 | endfunction -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | string fun(string s) 8 | { 9 | if(!s.compare("Fog")) 10 | return "0100"; 11 | if(!s.compare("Rain")) 12 | return "0010"; 13 | if(!s.compare("Thunderstorm")) 14 | return "0001"; 15 | return "1000"; 16 | } 17 | 18 | int main() 19 | { 20 | fstream fin,fout; 21 | int i=1; 22 | bool arr[25]={false}; 23 | arr[1]=true; 24 | arr[3]=true; 25 | arr[4]=true; 26 | arr[6]=true; 27 | arr[7]=true; 28 | arr[9]=true; 29 | arr[10]=true; 30 | arr[12]=true; 31 | arr[13]=true; 32 | arr[15]=true; 33 | arr[16]=true; 34 | arr[19]=true; 35 | arr[21]=true; 36 | 37 | char buffer[33]; 38 | for(i=1;i<=6;i++) 39 | { 40 | itoa(i,buffer,10); 41 | string a(buffer); 42 | string s="200"+a+".txt"; 43 | fin.open(s.c_str(),ios::in); 44 | s="Weather"+s; 45 | fout.open(s.c_str(),ios::out); 46 | string line; 47 | while(!fin.eof()) 48 | { 49 | getline(fin,line); 50 | int count=0; 51 | fout<<"1 "; 52 | for(int i=0;i-1&&word[j]!='-') 75 | { 76 | newword=word[j]+newword; 77 | j--; 78 | } 79 | fout<