format long;

[w1, w2, w3, e] = trainNeuralNetworkB("trainStormsNorm.txt", 0.1);

testData = load("testingYear2008.txt");
normalize = [1, 1, 1, -Inf, -Inf,-Inf, -Inf, -Inf, -Inf];
for j=1:size(testData)(1, 1)
  for k=4:9
    if abs(testData(j, k)) > normalize(1, k)
      normalize(1, k) = abs(testData(j, k));
    endif
  endfor
endfor

plot(e, 'g-');

normalizedTestData = testData./normalize;
normalizedDst = testNeuralNetworkB(w1, w2, w3, normalizedTestData);
Dst = normalizedDst*normalize(1, 9);

#s
s = 0;
for i=1:size(normalizedTestData, 1)
  s += (normalizedTestData(i, 9)-normalizedDst(1, i)).^2;
endfor
s = s/size(normalizedTestData, 1);
s = sqrt(s)

#storm comparing
i = 37;
count1 = 0;
Storms1 = [];
while i<size(testData, 1)-110
  if testData(i, 9)-testData(i+2, 9) >= 40   
    diff = testData(i, 9)-testData(i+2, 9)  
    count1 = count1 + 1;
    Storms1 = [Storms1; count1, (i-36), (i+2+108)];
    i=i+110;
  else 
    i=i+1;
  endif  
endwhile

i = 37;
count2 = 0;
Storms2 = [];
while i<size(testData, 1)-110      
  if Dst(1, i)-Dst(1, i+2) >= 40 
    diff = Dst(1, i)-Dst(1, i+2)
    count2 = count2 + 1;
    Storms2 = [Storms2; count2, (i-36), (i+2+108)];
    i=i+110;
  else 
    i=i+1;
  endif  
endwhile

Storms1
Storms2
#

fig2 = figure;
figure(fig2);
plot(testData(1:1000, 9), 'r-');
hold on;
plot(testData(1:1000, 9), 'r.');
hold on;
plot(Dst(1:1000), 'b-');
hold on;
plot(Dst(1:1000), 'bo.');