Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here is a question for my final progamming project. I am not sure how to output the performance of my neural network as a confusion

Here is a question for my final progamming project. I am not sure how to output the performance of my neural network as a confusion matrix. I have attached my code below.

5. Test your trained neural network using the test data from step 2 and output the performance of your classifier as a confusion matrix. (10%)

 /****************************************************************************** D E C L A R A T I O N S ******************************************************************************/ #include  #include  #include  typedef int BOOL; typedef int INT; typedef double REAL; #define FALSE 0 #define TRUE 1 #define NOT ! #define AND && #define OR || #define MIN_REAL -HUGE_VAL #define MAX_REAL +HUGE_VAL #define MIN(x,y) ((x)<(y) ? (x) : (y)) #define MAX(x,y) ((x)>(y) ? (x) : (y)) #define LO 0.1 #define HI 0.9 #define BIAS 1 #define sqr(x) ((x)*(x)) typedef struct { /* A LAYER OF A NET: */ INT Units; /* - number of units in this layer */ REAL* Output; /* - output of ith unit */ REAL* Error; /* - error term of ith unit */ REAL** Weight; /* - connection weights to ith unit */ REAL** WeightSave; /* - saved weights for stopped training */ REAL** dWeight; /* - last weight deltas for momentum */ } LAYER; typedef struct { /* A NET: */ LAYER** Layer; /* - layers of this net */ LAYER* InputLayer; /* - input layer */ LAYER* OutputLayer; /* - output layer */ REAL Alpha; /* - momentum factor */ REAL Eta; /* - learning rate */ REAL Gain; /* - gain of sigmoid function */ REAL Error; /* - total net error */ } NET; /****************************************************************************** R A N D O M S D R A W N F R O M D I S T R I B U T I O N S ******************************************************************************/ void InitializeRandoms() { srand(4711); } INT RandomEqualINT(INT Low, INT High) { return rand() % (High-Low+1) + Low; } REAL RandomEqualREAL(REAL Low, REAL High) { return ((REAL) rand() / RAND_MAX) * (High-Low) + Low; } /****************************************************************************** A P P L I C A T I O N - S P E C I F I C C O D E ******************************************************************************/ #define NUM_LAYERS 4 #define N 4 #define M 1 INT Units[NUM_LAYERS] = {N, 100, 50, M}; #define FIRST_YEAR 0 #define NUM_YEARS 750 #define TRAIN_LWB (N) #define TRAIN_UPB (449) #define TRAIN_YEARS (TRAIN_UPB - TRAIN_LWB + 1) #define TEST_LWB (450) #define TEST_UPB (599) #define TEST_YEARS (TEST_UPB - TEST_LWB + 1) #define EVAL_LWB (600) #define EVAL_UPB (NUM_YEARS - 1) #define EVAL_YEARS (EVAL_UPB - EVAL_LWB + 1) REAL Sunspots_[NUM_YEARS][5]; REAL Sunspots [NUM_YEARS][5] = { //open,high,low,close,next_weeks_close 15.82,16.72,15.78,16.42,15.97, 16.71,16.71,15.64,15.97,15.79, 16.19,16.38,15.60,15.79,16.13, 15.87,16.63,15.82,16.13,17.14, 16.18,17.39,16.18,17.14,17.37, 17.33,17.48,16.97,17.37,17.28, 17.39,17.68,17.28,17.28,16.68, 16.98,17.15,15.96,16.68,16.58, 16.81,16.94,16.13,16.58,16.03, 16.58,16.75,15.42,16.03,16.11, 15.95,16.33,15.43,16.11,17.09, 16.38,17.24,16.26,17.09,17.47, 43.30,45.60,43.11,44.36,46.25, 44.20,46.25,44.01,46.25,46.00, 46.03,46.71,44.71,46.00,43.86, 46.05,46.27,43.42,43.86,43.82, 44.13,44.23,43.15,43.82,46.75, 43.96,46.79,43.88,46.75,45.53, 46.42,46.93,45.53,45.53,43.53, 44.94,45.12,43.01,43.53,43.72, 43.73,44.68,42.75,43.72,44.28, 43.86,45.54,43.53,44.28,44.17, 43.86,44.47,42.19,44.17,45.59, 44.75,45.61,44.10,45.59,45.36, 66.15,70.10,66.00,69.38,70.07, 69.42,70.50,68.35,70.07,71.68, 70.86,72.99,70.23,71.68,69.23, 71.52,72.82,69.00,69.23,71.38, 69.26,71.64,69.12,71.38,72.14, 71.43,72.99,71.15,72.14,73.04, 72.70,73.04,71.09,73.04,72.30, 72.35,74.29,70.00,72.30,71.80, 72.47,72.90,68.60,71.80,71.64, 71.60,72.50,69.91,71.64,69.10, 71.17,71.23,67.34,69.10,73.34, 70.29,73.50,70.03,73.34,74.01, 13.85,14.69,13.80,14.25,15.25, 14.17,15.25,14.09,15.25,14.25, 15.08,15.16,13.94,14.25,13.60, 14.25,14.26,13.40,13.60,14.29, 13.71,14.47,13.64,14.29,14.77, 14.51,14.87,14.35,14.77,14.75, 14.77,14.95,14.69,14.75,14.20, 14.38,14.52,13.79,14.20,14.12, 14.27,14.48,13.81,14.12,14.38, 14.18,14.70,13.92,14.38,14.04, 14.26,14.35,13.66,14.04,13.34, 14.20,14.22,13.32,13.34,13.37, 94.38,94.81,92.30,93.73,94.01, 93.21,94.70,92.51,94.01,92.75, 94.16,96.80,92.37,92.75,95.68, 92.71,97.79,92.51,95.68,99.59, 96.13,99.72,95.85,99.59,103.54, 99.62,103.55,98.75,103.54,105.86, 103.56,105.86,102.01,105.86,102.00, 104.86,105.30,98.03,102.00,103.04, 102.72,104.43,99.35,103.04,100.02, 103.42,104.45,97.01,100.02,105.06, 102.59,105.64,98.55,105.06,109.09, 106.90,110.15,105.64,109.09,113.12, 20.45,21.00,20.38,20.97,21.21, 20.94,21.23,20.70,21.21,20.72, 21.22,21.33,20.50,20.72,20.93, 20.84,21.61,20.73,20.93,22.05, 20.93,22.15,20.71,22.05,18.70, 22.11,22.34,18.61,18.70,18.85, 18.84,18.95,18.56,18.85,18.64, 18.73,18.74,18.23,18.64,18.40, 18.62,18.79,18.31,18.40,17.95, 18.36,18.37,17.76,17.95,17.14, 17.81,17.88,16.97,17.14,17.28, 17.34,17.64,17.20,17.28,17.04, 91.66,92.48,90.27,91.19,92.83, 90.95,92.85,90.12,92.83,93.78, 92.94,93.94,91.58,93.78,93.37, 93.89,94.97,92.93,93.37,97.11, 93.85,97.44,93.37,97.11,96.45, 97.28,98.23,95.70,96.45,98.72, 95.50,98.72,95.50,98.72,102.10, 99.23,103.94,99.23,102.10,103.75, 102.28,104.99,102.18,103.75,99.93, 104.12,104.77,97.60,99.93,102.80, 99.16,103.97,97.98,102.80,106.78, 103.86,107.01,103.20,106.78,108.32, 50.05,50.54,49.28,49.76,49.80, 48.30,49.80,47.20,49.80,48.35, 49.53,50.14,47.65,48.35,50.29, 48.44,50.66,48.26,50.29,52.53, 50.15,52.63,50.09,52.53,54.58, 52.62,54.75,52.51,54.58,55.98, 54.44,55.98,53.80,55.98,54.07, 54.95,55.30,52.36,54.07,53.87, 54.22,54.95,52.76,53.87,52.90, 54.10,54.49,51.82,52.90,52.99, 53.18,53.50,51.10,52.99,54.10, 53.80,54.64,52.89,54.10,55.19, 37.74,40.00,37.62,39.45,39.29, 39.01,39.81,38.92,39.29,39.74, 39.07,39.94,38.51,39.74,38.85, 39.64,39.95,38.65,38.85,40.71, 39.04,40.77,38.64,40.71,43.41, 40.80,44.05,40.71,43.41,43.56, 43.19,43.90,42.98,43.56,42.95, 42.83,43.28,41.60,42.95,43.55, 43.02,44.34,42.97,43.55,42.93, 43.53,43.61,42.16,42.93,41.23, 42.64,42.67,40.42,41.23,42.97, 41.46,43.24,40.87,42.97,42.85, 18.49,18.72,18.12,18.43,18.82, 18.61,18.82,18.46,18.82,19.74, 18.98,19.97,18.17,19.74,20.20, 19.93,20.74,19.74,20.20,20.56, 20.13,20.96,20.10,20.56,21.33, 20.77,21.44,20.73,21.33,21.44, 21.51,21.65,21.24,21.44,20.82, 20.88,21.21,20.08,20.82,20.37, 20.95,21.17,20.16,20.37,20.36, 20.40,20.79,19.94,20.36,19.25, 19.96,20.09,18.60,19.25,19.75, 19.68,19.93,19.25,19.75,20.34, 35.20,35.57,34.18,34.38,35.89, 34.16,35.89,34.07,35.89,36.51, 35.97,36.99,35.48,36.51,36.70, 36.46,38.12,36.30,36.70,36.80, 37.13,37.18,36.38,36.80,37.48, 36.80,37.48,36.41,37.48,38.48, 37.47,38.48,37.27,38.48,37.08, 39.30,39.38,36.78,37.08,37.22, 37.15,37.86,36.33,37.22,37.14, 37.26,37.78,36.54,37.14,36.00, 36.92,36.94,35.43,36.00,37.42, 36.29,37.82,36.03,37.42,37.56, 42.22,45.39,42.22,45.09,46.25, 44.86,46.25,44.57,46.25,47.23, 46.14,47.64,45.76,47.23,45.51, 46.69,47.83,45.36,45.51,47.43, 45.41,47.52,45.13,47.43,48.64, 47.71,49.39,47.61,48.64,48.67, 48.45,49.12,47.54,48.67,42.68, 47.57,48.55,42.08,42.68,42.61, 43.06,43.85,42.06,42.61,41.73, 42.90,43.05,41.26,41.73,41.32, 41.31,42.15,40.10,41.32,42.53, 41.85,43.28,41.35,42.53,40.98, 147.21,148.86,146.64,147.93,150.00, 147.00,150.00,146.00,150.00,155.50, 149.82,156.78,149.38,155.50,159.21, 155.42,164.35,155.33,159.21,164.00, 159.18,164.20,158.68,164.00,163.85, 164.08,166.25,163.18,163.85,164.84, 164.18,164.84,162.52,164.84,162.28, 163.57,164.26,159.03,162.28,161.83, 162.36,164.31,159.41,161.83,162.43, 161.60,167.72,158.85,162.43,155.89, 161.16,161.98,151.71,155.89,162.18, 157.64,162.74,157.07,162.18,164.27, 21.01,21.21,20.27,20.66,21.08, 20.71,21.33,20.57,21.08,20.82, 21.03,21.20,20.62,20.82,21.46, 21.03,21.94,20.93,21.46,21.68, 21.55,21.71,21.03,21.68,21.76, 21.74,21.86,21.35,21.76,22.14, 21.63,22.14,21.28,22.14,21.86, 21.95,22.19,21.01,21.86,21.56, 21.75,22.08,21.35,21.56,20.87, 21.69,21.74,20.61,20.87,19.93, 20.66,20.88,19.71,19.93,20.37, 19.90,20.60,19.88,20.37,19.72, 62.63,63.54,62.53,62.60,62.55, 62.29,62.98,62.00,62.55,62.66, 62.21,63.25,62.01,62.66,60.01, 62.56,62.72,60.00,60.01,60.84, 60.16,60.99,59.69,60.84,60.70, 60.88,61.17,60.42,60.70,61.11, 60.69,61.11,60.33,61.11,59.64, 60.68,61.08,59.36,59.64,61.06, 59.93,61.50,59.77,61.06,59.69, 61.09,61.10,59.11,59.69,58.57, 59.49,59.49,57.50,58.57,58.98, 58.67,59.16,58.50,58.98,59.49, 43.00,44.95,42.64,43.64,44.91, 43.27,44.97,43.00,44.91,45.29, 45.02,45.54,43.60,45.29,44.54, 45.21,45.88,44.26,44.54,44.59, 44.41,46.00,44.30,44.59,46.57, 44.75,46.89,44.65,46.57,48.00, 46.00,48.00,46.00,48.00,46.68, 47.20,47.27,45.21,46.68,45.52, 46.81,47.18,45.07,45.52,45.74, 45.62,47.10,44.76,45.74,45.74, 45.42,46.18,43.40,45.74,45.86, 46.28,46.38,44.77,45.86,46.35, 31.76,31.76,31.14,31.19,31.34, 30.91,31.72,30.89,31.34,31.35, 31.41,31.52,30.89,31.35,30.53, 31.39,31.77,30.50,30.53,31.19, 30.53,31.22,30.21,31.19,30.66, 31.18,31.25,30.24,30.66,30.91, 30.67,30.93,30.26,30.91,31.71, 30.72,32.20,30.66,31.71,31.58, 31.82,31.88,31.28,31.58,31.70, 31.56,31.79,31.18,31.70,30.99, 31.51,31.60,30.45,30.99,31.26, 30.78,31.49,30.43,31.26,31.61, 65.88,65.88,62.56,62.92,63.13, 62.70,63.86,62.56,63.13,62.77, 63.21,63.92,62.72,62.77,62.21, 62.87,63.31,62.14,62.21,62.56, 62.32,63.48,61.89,62.56,63.57, 62.67,64.75,62.32,63.57,64.55, 63.67,64.72,62.55,64.55,64.31, 63.36,64.40,63.33,64.31,65.21, 64.17,65.87,63.86,65.21,64.81, 65.32,65.84,64.47,64.81,62.70, 64.34,64.61,61.29,62.70,65.22, 63.13,65.39,63.05,65.22,67.22, 77.10,77.59,73.59,74.37,74.06, 74.25,74.49,72.46,74.06,75.01, 74.65,75.75,74.31,75.01,73.28, 74.25,75.85,73.05,73.28,74.05, 73.80,74.50,73.08,74.05,76.14, 74.13,76.32,73.30,76.14,76.13, 76.07,76.45,75.70,76.13,74.44, 75.95,76.45,74.42,74.44,76.03, 74.51,76.63,73.64,76.03,76.73, 76.38,77.25,74.97,76.73,72.99, 76.10,76.41,72.89,72.99,75.25, 73.50,75.75,73.38,75.25,75.99, 86.75,87.90,85.63,86.23,88.10, 85.70,88.80,85.70,88.10,89.29, 87.84,89.39,87.25,89.29,87.44, 89.21,90.50,87.20,87.44,88.29, 87.93,88.45,87.31,88.29,91.80, 88.17,91.95,87.81,91.80,92.96, 91.72,92.96,91.00,92.96,90.25, 92.73,93.65,89.27,90.25,92.19, 91.90,93.40,90.24,92.19,91.61, 92.58,94.16,89.71,91.61,88.98, 91.21,91.21,86.91,88.98,92.27, 90.27,92.98,90.17,92.27,93.13, 36.29,37.35,35.85,37.35,34.23, 37.26,37.61,34.23,34.23,33.90, 34.07,34.30,33.48,33.90,33.07, 33.99,33.99,33.00,33.07,32.89, 33.29,34.04,32.51,32.89,33.07, 32.94,33.30,32.74,33.07,32.85, 32.97,33.19,32.65,32.85,32.19, 32.75,32.80,31.85,32.19,33.06, 32.20,33.36,32.19,33.06,32.73, 33.00,33.48,32.45,32.73,31.91, 32.50,32.60,31.06,31.91,32.57, 32.09,32.90,32.04,32.57,33.07, 28.05,28.85,27.77,28.60,28.30, 28.20,28.50,28.00,28.30,28.02, 28.16,28.74,28.02,28.02,27.75, 28.02,29.46,27.45,27.75,27.77, 27.77,28.11,27.42,27.77,27.25, 27.80,28.34,27.07,27.25,27.06, 27.20,27.37,26.60,27.06,26.55, 26.78,27.10,26.43,26.55,25.95, 26.69,26.86,25.80,25.95,25.68, 26.13,26.27,25.35,25.68,24.80, 25.49,25.76,24.68,24.80,25.62, 25.18,25.95,25.15,25.62,25.48, 17.70,18.38,17.62,18.34,18.34, 18.22,18.48,18.13,18.34,18.36, 18.35,18.49,18.02,18.36,18.15, 18.33,18.76,18.14,18.15,19.30, 18.19,19.39,18.16,19.30,18.83, 19.27,19.30,18.62,18.83,19.19, 18.82,19.39,18.72,19.19,18.86, 18.88,19.13,18.67,18.86,19.66, 18.95,19.90,18.90,19.66,19.47, 19.64,19.75,19.30,19.47,20.18, 19.45,20.29,19.15,20.18,20.35, 20.32,20.50,19.74,20.35,20.38, 64.39,65.08,64.00,64.50,65.53, 64.40,65.53,63.40,65.53,65.91, 65.65,65.95,65.05,65.91,64.20, 65.90,66.95,63.14,64.20,63.61, 64.35,64.36,62.30,63.61,64.73, 63.95,64.97,63.80,64.73,64.30, 64.80,64.80,63.40,64.30,62.84, 63.73,64.40,62.53,62.84,62.03, 62.80,63.65,61.56,62.03,61.49, 62.00,62.30,61.12,61.49,60.60, 61.04,61.39,59.70,60.60,60.88, 60.96,61.52,60.54,60.88,62.08, 29.68,30.10,28.66,28.85,28.43, 28.54,28.61,27.71,28.43,28.33, 28.55,28.59,28.15,28.33,27.49, 28.46,28.95,27.41,27.49,27.97, 27.42,28.06,27.20,27.97,28.47, 27.97,28.59,27.63,28.47,28.57, 28.40,28.57,28.00,28.57,28.13, 28.32,28.42,27.61,28.13,27.92, 28.25,28.53,27.79,27.92,28.46, 27.95,28.89,27.73,28.46,27.94, 28.32,28.42,27.27,27.94,28.85, 28.77,29.10,27.95,28.85,30.62, 56.09,56.34,52.88,53.33,54.63, 53.12,54.84,52.96,54.63,55.00, 54.62,55.24,54.07,55.00,55.81, 55.14,57.78,54.97,55.81,57.41, 55.81,57.52,55.81,57.41,58.99, 57.32,59.12,56.97,58.99,60.92, 58.84,60.92,58.53,60.92,59.60, 60.60,61.15,59.05,59.60,59.18, 59.60,60.02,58.53,59.18,58.88, 59.26,59.72,57.88,58.88,58.06, 58.47,59.51,57.51,58.06,58.98, 58.44,59.28,57.99,58.98,59.71, 79.19,79.75,78.40,79.08,79.08, 78.27,79.90,77.81,79.08,80.20, 79.28,80.50,78.98,80.20,81.43, 80.26,83.08,80.26,81.43,82.52, 81.80,82.60,80.66,82.52,85.20, 82.85,85.46,82.73,85.20,85.01, 85.07,85.44,84.25,85.01,83.37, 84.54,84.69,81.81,83.37,82.86, 83.58,84.24,81.42,82.86,81.28, 83.03,84.05,80.26,81.28,80.16, 80.74,81.23,77.05,80.16,83.52, 81.30,83.59,80.57,83.52,85.32, 36.06,37.70,35.41,35.93,35.46, 36.55,36.58,34.98,35.46,34.95, 35.38,35.51,34.35,34.95,35.63, 34.88,36.59,34.88,35.63,36.31, 35.64,36.48,35.38,36.31,36.39, 36.30,36.77,35.77,36.39,36.62, 36.31,36.62,35.66,36.62,35.97, 36.24,36.32,35.34,35.97,36.08, 36.06,36.94,35.85,36.08,35.85, 36.13,36.65,35.65,35.85,35.84, 35.74,35.84,33.36,35.84,37.29, 36.66,37.32,36.37,37.29,38.47, 54.23,55.07,53.76,54.08,54.81, 53.65,55.36,53.54,54.81,55.73, 55.11,56.27,54.71,55.73,56.70, 55.39,57.90,55.30,56.70,56.03, 56.45,56.58,55.39,56.03,55.69, 56.07,56.73,55.30,55.69,55.38, 55.26,55.38,54.35,55.38,51.75, 53.81,54.01,51.52,51.75,52.07, 51.75,52.60,51.68,52.07,52.59, 52.26,53.88,51.75,52.59,51.52, 52.35,52.52,50.97,51.52,52.35, 51.73,52.95,51.38,52.35,52.13, 73.72,75.90,73.64,75.59,77.84, 75.13,77.84,74.58,77.84,78.98, 77.79,79.10,76.77,78.98,78.99, 78.85,79.98,77.93,78.99,83.28, 79.92,83.98,79.01,83.28,82.82, 83.45,84.00,81.61,82.82,84.50, 82.00,85.10,81.80,84.50,85.34, 84.97,88.23,84.73,85.34,85.08, 85.87,86.56,83.55,85.08,82.12, 85.84,86.08,80.10,82.12,80.85, 81.67,82.64,78.80,80.85,83.62, 81.87,83.93,81.86,83.62,84.68, 17.13,17.80,17.02,17.47,17.92, 17.42,18.47,17.42,17.92,16.52, 18.06,18.19,16.38,16.52,16.97, 16.36,16.97,15.88,16.97,17.00, 16.94,17.24,16.66,17.00,17.15, 17.27,17.96,16.83,17.15,17.10, 17.16,17.62,16.75,17.10,16.26, 17.00,17.29,16.26,16.26,16.48, 15.96,16.48,15.83,16.48,15.92, 16.73,16.83,15.77,15.92,15.28, 15.92,16.03,15.17,15.28,14.72, 15.29,15.50,14.59,14.72,15.23, 14.67,15.60,14.56,15.23,16.31, 45.54,46.29,45.11,45.36,46.28, 45.61,46.49,45.10,46.28,46.25, 46.36,46.95,45.60,46.25,47.11, 45.85,47.48,45.27,47.11,49.08, 47.19,49.15,46.77,49.08,50.20, 49.37,50.47,49.08,50.20,49.49, 50.06,50.46,49.22,49.49,51.19, 49.42,51.97,49.17,51.19,51.13, 50.74,51.38,49.79,51.13,49.28, 51.39,51.70,49.04,49.28,47.74, 49.13,49.38,47.33,47.74,48.50, 47.96,49.14,46.92,48.50,48.34, 48.35,50.15,48.15,48.34,52.34, 73.50,74.85,73.03,74.01,73.47, 73.38,74.85,72.71,73.47,72.60, 73.65,74.28,70.88,72.60,75.44, 72.72,75.44,71.75,75.44,79.78, 75.51,80.34,74.68,79.78,79.31, 80.35,80.65,78.09,79.31,79.03, 79.31,80.42,78.48,79.03,77.52, 78.66,78.81,75.83,77.52,76.99, 76.55,76.99,75.13,76.99,74.84, 77.80,78.35,74.09,74.84,72.69, 74.76,75.27,72.61,72.69,74.16, 73.06,75.51,72.69,74.16,71.26, 73.96,75.02,70.29,71.26,74.27, 13.42,13.61,13.16,13.37,13.48, 13.40,13.88,13.37,13.48,12.82, 13.50,13.64,12.82,12.82,12.31, 12.59,12.60,12.15,12.31,12.28, 12.32,12.60,12.23,12.28,12.31, 12.36,12.71,12.20,12.31,11.93, 12.28,12.43,11.91,11.93,11.58, 11.89,12.11,11.53,11.58,11.69, 11.47,11.69,11.29,11.69,11.28, 11.87,11.92,11.08,11.28,10.80, 11.18,11.20,10.41,10.80,10.68, 10.89,11.12,10.40,10.68,10.52, 10.59,10.94,10.48,10.52,11.09, 109.54,113.59,108.61,113.12,109.82, 113.75,113.93,108.88,109.82,107.21, 110.02,110.30,105.35,107.21,109.42, 105.58,109.42,102.16,109.42,115.41, 109.24,116.25,107.95,115.41,110.34, 116.24,116.55,108.39,110.34,106.33, 110.80,112.97,106.02,106.33,104.33, 105.87,108.27,101.47,104.33,104.60, 101.30,104.60,100.30,104.60,101.10, 106.41,106.60,99.15,101.10,96.79, 100.25,101.61,96.42,96.79,95.95, 96.93,98.45,94.20,95.95,100.01, 96.49,102.50,96.05,100.01,108.62, 17.36,17.60,16.99,17.04,17.65, 17.01,18.29,17.00,17.65,17.03, 17.71,17.76,16.97,17.03,16.94, 16.88,16.96,16.52,16.94,17.52, 16.93,17.64,16.90,17.52,17.56, 17.51,17.70,17.28,17.56,16.88, 17.53,17.99,16.64,16.88,16.53, 16.82,16.87,16.34,16.53,16.46, 16.41,16.46,16.11,16.46,16.01, 16.59,16.82,15.98,16.01,15.12, 16.04,16.17,15.01,15.12,14.97, 15.14,15.28,14.78,14.97,14.93, 14.94,15.64,14.92,14.93,15.86, 106.40,109.65,105.52,108.32,109.66, 108.52,109.94,107.51,109.66,106.24, 109.74,109.90,103.13,106.24,108.13, 104.95,108.34,103.04,108.13,109.44, 107.37,109.60,106.68,109.44,102.88, 109.48,109.57,101.11,102.88,102.39, 103.25,104.95,100.41,102.39,102.57, 102.03,104.53,99.61,102.57,103.21, 101.13,103.86,100.70,103.21,101.00, 104.61,105.21,99.57,101.00,99.67, 100.90,101.87,98.98,99.67,99.17, 100.04,101.29,97.71,99.17,97.90, 98.88,102.46,97.00,97.90,104.09, 54.11,55.80,53.70,55.19,55.40, 55.50,56.52,55.00,55.40,54.89, 55.45,55.81,53.17,54.89,55.91, 54.28,56.00,53.19,55.91,56.79, 55.69,56.88,54.54,56.79,54.63, 56.42,57.00,53.59,54.63,52.91, 54.94,56.13,52.55,52.91,52.74, 52.74,54.00,51.92,52.74,52.56, 51.75,52.56,50.50,52.56,50.29, 53.18,53.39,50.11,50.29,49.78, 50.30,50.90,49.52,49.78,49.57, 50.03,50.63,48.64,49.57,51.96, 49.50,51.98,49.46,51.96,54.47, 43.19,43.48,42.36,42.85,41.76, 42.87,43.05,41.40,41.76,41.52, 41.76,42.02,40.84,41.52,42.27, 40.97,42.46,40.45,42.27,43.10, 42.34,43.35,41.71,43.10,43.06, 43.47,43.79,42.30,43.06,41.52, 43.32,44.12,40.94,41.52,41.50, 41.26,41.84,40.68,41.50,41.52, 41.15,41.52,40.55,41.52,39.38, 41.90,41.99,39.17,39.38,38.50, 39.18,39.88,38.42,38.50,38.04, 38.63,38.86,37.77,38.04,37.58, 37.85,38.89,37.19,37.58,39.72, 19.81,20.50,19.53,20.34,20.19, 20.73,20.75,20.07,20.19,20.04, 20.24,20.37,19.60,20.04,19.95, 19.77,20.54,19.51,19.95,20.45, 20.14,20.85,19.89,20.45,20.01, 20.70,20.71,19.81,20.01,19.89, 19.97,20.42,19.76,19.89,19.62, 19.85,20.05,19.41,19.62,19.44, 19.32,19.52,18.97,19.44,18.82, 19.68,19.72,18.75,18.82,18.32, 18.71,18.80,18.14,18.32,18.49, 18.31,18.90,18.20,18.49,17.97, 18.34,18.94,17.97,17.97,19.20, 37.46,37.87,36.62,37.56,37.46, 37.48,37.96,37.21,37.46,38.17, 37.45,38.40,37.17,38.17,37.80, 37.70,38.50,37.20,37.80,37.15, 37.61,37.71,36.94,37.15,36.99, 37.44,37.67,36.77,36.99,37.01, 36.93,37.43,36.70,37.01,37.05, 36.69,37.94,36.55,37.05,36.00, 36.00,37.00,36.00,36.00,34.63, 36.18,36.28,34.43,34.63,33.47, 34.53,35.02,33.42,33.47,34.53, 33.46,34.93,33.41,34.53,35.08, 34.29,35.69,34.28,35.08,36.73, 42.42,42.83,37.60,40.98,40.70, 40.65,41.80,40.20,40.70,40.26, 40.71,41.55,40.12,40.26,40.99, 39.96,41.19,39.16,40.99,40.37, 41.06,41.30,39.99,40.37,40.81, 40.69,41.52,39.80,40.81,40.41, 40.79,41.74,40.22,40.41,35.98, 40.20,40.34,35.91,35.98,36.96, 35.58,36.96,35.44,36.96,36.11, 37.28,37.52,36.00,36.11,35.25, 35.99,36.24,35.14,35.25,35.00, 35.13,35.32,33.95,35.00,34.90, 34.79,35.65,34.55,34.90,37.05, 161.54,164.42,161.12,164.27,164.05, 164.42,164.75,163.16,164.05,166.21, 163.44,166.34,162.30,166.21,168.28, 164.64,168.28,162.19,168.28,170.58, 167.65,173.00,167.23,170.58,168.89, 172.11,173.54,167.50,168.89,169.92, 168.39,172.77,167.82,169.92,170.16, 169.81,171.41,166.53,170.16,167.50, 168.50,168.60,165.90,167.50,165.05, 168.44,169.89,164.13,165.05,163.18, 164.76,165.96,162.87,163.18,164.44, 164.44,165.10,161.52,164.44,165.07, 163.70,166.81,163.59,165.07,174.54, 20.44,20.66,19.56,19.72,20.02, 19.79,20.20,19.36,20.02,19.75, 20.07,20.20,19.41,19.75,21.46, 19.53,21.46,19.45,21.46,23.15, 21.37,23.19,21.33,23.15,23.25, 23.02,23.86,22.67,23.25,23.41, 23.13,23.83,22.65,23.41,23.22, 23.32,23.96,23.08,23.22,22.21, 22.92,23.03,22.21,22.21,21.73, 22.45,22.64,21.67,21.73,21.38, 21.80,22.44,21.26,21.38,21.19, 21.43,26.78,21.07,21.19,21.20, 21.19,21.74,21.06,21.20,22.53, 58.98,59.73,58.93,59.49,59.46, 59.50,60.18,59.25,59.46,60.56, 59.54,60.95,59.49,60.56,64.07, 60.45,64.54,60.10,64.07,65.72, 63.65,65.98,63.40,65.72,65.27, 65.92,66.46,64.80,65.27,66.62, 65.11,67.37,65.07,66.62,65.69, 66.41,66.79,65.28,65.69,66.77, 65.19,66.77,65.08,66.77,66.09, 67.31,67.34,65.80,66.09,66.09, 65.87,67.28,65.18,66.09,66.29, 66.32,67.36,65.47,66.29,65.06, 66.08,66.75,64.69,65.06,67.30, 46.10,46.88,45.51,46.35,46.84, 46.12,47.80,46.05,46.84,44.89, 47.00,47.37,44.83,44.89,44.68, 44.27,44.97,43.53,44.68,45.63, 44.65,46.02,44.38,45.63,45.04, 45.94,46.07,44.76,45.04,43.15, 44.75,45.50,42.98,43.15,43.13, 42.97,44.35,42.65,43.13,42.79, 42.40,42.92,41.69,42.79,41.57, 43.24,43.38,40.83,41.57,41.05, 41.10,41.50,40.10,41.05,40.80, 41.29,42.44,39.70,40.80,39.49, 40.50,41.53,39.44,39.49,41.58, 31.35,31.70,31.06,31.61,31.67, 31.71,31.88,31.35,31.67,33.36, 31.73,33.54,31.69,33.36,33.38, 32.72,33.67,32.70,33.38,33.59, 33.45,33.90,33.00,33.59,34.08, 33.60,34.49,33.22,34.08,34.89, 33.81,35.10,33.80,34.89,35.23, 34.84,35.44,34.48,35.23,34.75, 34.97,35.06,34.28,34.75,34.10, 34.79,35.00,34.05,34.10,33.79, 34.07,34.39,24.30,33.79,34.48, 33.92,34.72,33.76,34.48,34.60, 34.39,34.98,33.87,34.60,35.47, 65.20,67.48,65.03,67.22,67.27, 67.22,67.82,66.86,67.27,68.01, 67.25,68.47,66.41,68.01,67.88, 67.57,68.05,66.64,67.88,67.46, 67.95,67.98,65.81,67.46,66.90, 67.76,67.93,66.40,66.90,68.18, 66.86,68.77,66.83,68.18,68.30, 68.10,68.70,67.50,68.30,66.51, 67.59,67.90,66.30,66.51,65.53, 66.94,67.24,65.21,65.53,65.39, 65.51,68.05,65.07,65.39,65.62, 65.10,66.23,64.64,65.62,64.93, 65.37,66.82,64.43,64.93,68.09, 75.55,76.50,74.87,75.99,76.04, 76.31,76.91,75.66,76.04,77.38, 76.15,77.54,75.83,77.38,76.91, 76.89,78.41,76.40,76.91,78.31, 77.15,78.59,76.54,78.31,78.70, 78.40,79.37,78.20,78.70,80.74, 79.46,80.91,79.08,80.74,82.33, 80.44,82.85,80.44,82.33,81.62, 81.53,83.08,81.49,81.62,80.54, 82.13,82.25,80.01,80.54,80.36, 80.60,82.23,80.00,80.36,82.52, 80.43,82.72,80.39,82.52,81.84, 82.32,83.09,81.40,81.84,85.65, 92.42,94.33,91.90,93.13,93.22, 92.68,94.10,92.60,93.22,92.82, 93.59,94.64,91.75,92.82,93.92, 91.94,94.42,90.58,93.92,97.21, 93.91,97.50,93.27,97.21,95.60, 97.58,97.95,94.40,95.60,96.01, 95.30,97.18,94.44,96.01,93.56, 95.54,96.23,92.75,93.56,93.47, 92.29,93.47,91.38,93.47,90.70, 94.05,94.68,90.19,90.70,90.73, 90.38,92.43,90.24,90.73,91.78, 91.14,92.99,90.58,91.78,90.89, 91.42,93.92,90.68,90.89,96.67, 32.54,33.48,32.39,33.07,33.67, 33.34,33.70,33.01,33.67,34.51, 33.68,34.97,33.27,34.51,34.04, 34.20,34.29,33.51,34.04,35.95, 33.70,36.25,33.63,35.95,36.39, 36.44,36.75,35.95,36.39,37.08, 36.11,37.30,36.10,37.08,37.06, 37.06,37.65,36.69,37.06,36.21, 36.67,37.04,36.10,36.21,35.82, 36.39,36.76,35.76,35.82,35.45, 35.70,36.38,35.36,35.45,35.39, 35.03,35.88,34.99,35.39,34.55, 35.29,35.97,34.50,34.55,35.60, 25.66,25.72,25.30,25.48,26.07, 25.45,26.31,25.41,26.07,25.37, 26.19,26.25,25.09,25.37,25.52, 25.10,26.00,24.72,25.52,25.92, 25.56,26.87,25.34,25.92,25.87, 25.94,26.25,25.48,25.87,25.03, 25.80,25.96,24.95,25.03,24.49, 24.96,25.07,24.25,24.49,24.76, 24.21,25.03,24.03,24.76,23.90, 24.96,25.10,23.84,23.90,23.70, 23.90,24.25,23.69,23.70,24.26, 23.79,29.05,23.65,24.26,24.30, 24.17,24.86,24.16,24.30,26.02, 20.42,20.57,20.11,20.38,20.46, 20.55,20.61,20.15,20.46,20.53, 20.55,20.75,20.33,20.53,19.79, 20.32,20.88,19.79,19.79,20.97, 19.95,21.06,19.90,20.97,20.55, 21.14,21.20,20.07,20.55,20.92, 20.53,20.99,20.45,20.92,20.69, 20.84,21.28,20.68,20.69,20.93, 20.49,20.98,20.35,20.93,20.84, 21.00,21.45,20.66,20.84,20.11, 20.82,20.97,20.04,20.11,20.26, 20.08,20.73,20.03,20.26,20.08, 20.09,20.96,20.08,20.08,20.75, 61.08,62.30,60.61,62.08,61.90, 62.17,62.33,61.47,61.90,64.18, 62.02,64.21,61.90,64.18,63.27, 63.67,64.34,63.27,63.27,64.90, 63.08,65.10,62.60,64.90,65.27, 65.24,66.50,64.90,65.27,66.86, 64.93,67.31,64.86,66.86,67.36, 66.66,67.72,66.51,67.36,66.20, 66.80,67.20,65.70,66.20,65.43, 66.33,67.00,56.57,65.43,64.70, 65.36,65.64,64.65,64.70,64.69, 64.65,65.22,63.33,64.69,62.59, 64.51,65.29,62.44,62.59,64.27, 29.02,30.97,28.90,30.62,30.71, 30.74,31.00,29.99,30.71,30.65, 30.75,30.84,30.01,30.65,30.68, 30.42,30.68,29.91,30.68,31.12, 30.67,31.82,30.43,31.12,31.26, 31.60,31.94,31.03,31.26,31.41, 31.20,31.79,31.05,31.41,31.32, 31.32,31.77,30.90,31.32,31.29, 31.00,31.30,30.92,31.29,30.65, 31.48,31.65,30.52,30.65,30.34, 30.55,30.61,30.11,30.34,30.77, 30.28,30.95,30.17,30.77,30.44, 30.66,31.33,30.29,30.44,31.68, 59.09,60.01,58.37,59.71,59.58, 59.83,60.00,59.11,59.58,59.80, 59.85,60.85,59.00,59.80,61.32, 59.32,61.32,58.07,61.32,63.28, 61.32,63.37,60.91,63.28,63.43, 63.56,64.17,62.85,63.43,62.33, 63.23,64.09,62.18,62.33,62.25, 62.52,63.11,62.13,62.25,61.52, 61.74,62.00,60.36,61.52,61.18, 61.95,62.25,60.59,61.18,59.21, 61.35,61.68,58.71,59.21,57.92, 59.12,59.32,57.36,57.92,56.68, 57.57,58.28,56.12,56.68,59.11, 83.75,85.95,83.26,85.32,84.81, 85.66,86.00,84.18,84.81,83.45, 85.00,85.56,82.70,83.45,87.10, 82.60,87.10,81.10,87.10,89.58, 87.00,89.80,86.29,89.58,89.21, 90.03,90.67,85.80,89.21,88.98, 88.88,90.18,88.35,88.98,87.50, 88.46,89.25,86.65,87.50,86.33, 86.41,86.72,85.21,86.33,83.24, 87.00,87.79,82.43,83.24,82.70, 82.93,84.52,82.60,82.70,84.57, 82.92,85.26,82.52,84.57,84.33, 84.36,86.21,83.69,84.33,90.13, 37.44,38.95,37.42,38.47,37.72, 38.53,38.70,37.26,37.72,37.85, 37.75,38.00,37.34,37.85,36.91, 37.60,38.00,36.91,36.91,37.78, 37.07,38.42,36.82,37.78,37.28, 38.33,38.33,36.90,37.28,37.26, 37.28,37.68,36.95,37.26,37.15, 37.26,37.41,36.80,37.15,36.67, 36.75,37.03,36.24,36.67,35.63, 36.91,36.99,35.60,35.63,35.19, 35.57,36.14,35.16,35.19,35.51, 35.23,35.92,34.94,35.51,36.00, 35.35,36.17,35.20,36.00,37.80, 52.31,52.74,51.89,52.13,52.54, 52.31,53.24,52.06,52.54,53.55, 52.54,53.96,52.40,53.55,53.58, 53.08,53.95,52.91,53.58,54.98, 53.60,55.16,53.23,54.98,55.02, 55.08,55.79,53.20,55.02,55.72, 54.97,56.03,54.70,55.72,55.29, 55.61,56.47,54.95,55.29,54.70, 54.90,55.50,54.10,54.70,53.66, 54.88,55.22,53.04,53.66,52.72, 53.86,54.30,52.69,52.72,52.82, 52.91,53.29,51.79,52.82,52.41, 52.70,53.70,52.35,52.41,53.51, 83.86,84.94,82.61,84.68,85.95, 84.26,86.22,84.07,85.95,84.29, 85.95,86.15,82.38,84.29,86.36, 83.11,86.36,82.44,86.36,87.98, 86.29,88.00,85.89,87.98,82.69, 88.10,88.13,81.59,82.69,80.87, 83.01,83.76,79.42,80.87,81.57, 80.22,82.58,79.60,81.57,82.63, 80.22,82.63,80.07,82.63,81.18, 83.28,83.75,80.18,81.18,79.78, 80.93,81.87,79.72,79.78,79.02, 80.00,80.82,78.33,79.02,76.78, 78.65,81.12,76.78,76.78,82.01 }; REAL Mean; REAL TrainError; REAL TrainErrorPredictingMean; REAL TestError; REAL TestErrorPredictingMean; FILE* f; void NormalizeSunspots() { INT Year; REAL Min, Max; Min = MAX_REAL; Max = MIN_REAL; for(int i = 0; i<5;i++){ for (Year=0; YearAlpha = 0.5; Net->Eta = 0.05; Net->Gain = 0.5; NormalizeSunspots(); TrainErrorPredictingMean = 0; for (Year=TRAIN_LWB; Year<=TRAIN_UPB; Year++) { for (i=0; iLayer = (LAYER**) calloc(NUM_LAYERS, sizeof(LAYER*)); for (l=0; lLayer[l] = (LAYER*) malloc(sizeof(LAYER)); Net->Layer[l]->Units = Units[l]; Net->Layer[l]->Output = (REAL*) calloc(Units[l]+1, sizeof(REAL)); Net->Layer[l]->Error = (REAL*) calloc(Units[l]+1, sizeof(REAL)); Net->Layer[l]->Weight = (REAL**) calloc(Units[l]+1, sizeof(REAL*)); Net->Layer[l]->WeightSave = (REAL**) calloc(Units[l]+1, sizeof(REAL*)); Net->Layer[l]->dWeight = (REAL**) calloc(Units[l]+1, sizeof(REAL*)); Net->Layer[l]->Output[0] = BIAS; if (l != 0) { for (i=1; i<=Units[l]; i++) { Net->Layer[l]->Weight[i] = (REAL*) calloc(Units[l-1]+1, sizeof(REAL)); Net->Layer[l]->WeightSave[i] = (REAL*) calloc(Units[l-1]+1, sizeof(REAL)); Net->Layer[l]->dWeight[i] = (REAL*) calloc(Units[l-1]+1, sizeof(REAL)); } } } Net->InputLayer = Net->Layer[0]; Net->OutputLayer = Net->Layer[NUM_LAYERS - 1]; Net->Alpha = 0.9; Net->Eta = 0.25; Net->Gain = 1; } void RandomWeights(NET* Net) { INT l,i,j; for (l=1; lLayer[l]->Units; i++) { for (j=0; j<=Net->Layer[l-1]->Units; j++) { Net->Layer[l]->Weight[i][j] = RandomEqualREAL(-0.5, 0.5); } } } } void SetInput(NET* Net, REAL* Input) { INT i; for (i=1; i<=Net->InputLayer->Units; i++) { Net->InputLayer->Output[i] = Input[i-1]; } } void GetOutput(NET* Net, REAL* Output) { INT i; for (i=1; i<=Net->OutputLayer->Units; i++) { Output[i-1] = Net->OutputLayer->Output[i]; } } /****************************************************************************** S U P P O R T F O R S T O P P E D T R A I N I N G ******************************************************************************/ void SaveWeights(NET* Net) { INT l,i,j; for (l=1; lLayer[l]->Units; i++) { for (j=0; j<=Net->Layer[l-1]->Units; j++) { Net->Layer[l]->WeightSave[i][j] = Net->Layer[l]->Weight[i][j]; } } } } void RestoreWeights(NET* Net) { INT l,i,j; for (l=1; lLayer[l]->Units; i++) { for (j=0; j<=Net->Layer[l-1]->Units; j++) { Net->Layer[l]->Weight[i][j] = Net->Layer[l]->WeightSave[i][j]; } } } } /****************************************************************************** P R O P A G A T I N G S I G N A L S ******************************************************************************/ void PropagateLayer(NET* Net, LAYER* Lower, LAYER* Upper) { INT i,j; REAL Sum; for (i=1; i<=Upper->Units; i++) { Sum = 0; for (j=0; j<=Lower->Units; j++) { Sum += Upper->Weight[i][j] * Lower->Output[j]; } Upper->Output[i] = 1 / (1 + exp(-Net->Gain * Sum)); } } void PropagateNet(NET* Net) { INT l; for (l=0; lLayer[l], Net->Layer[l+1]); } } /****************************************************************************** B A C K P R O P A G A T I N G E R R O R S ******************************************************************************/ void ComputeOutputError(NET* Net, REAL* Target) { INT i; REAL Out, Err; Net->Error = 0; for (i=1; i<=Net->OutputLayer->Units; i++) { Out = Net->OutputLayer->Output[i]; Err = Target[i-1]-Out; Net->OutputLayer->Error[i] = Net->Gain * Out * (1-Out) * Err; Net->Error += 0.5 * sqr(Err); } } void BackpropagateLayer(NET* Net, LAYER* Upper, LAYER* Lower) { INT i,j; REAL Out, Err; for (i=1; i<=Lower->Units; i++) { Out = Lower->Output[i]; Err = 0; for (j=1; j<=Upper->Units; j++) { Err += Upper->Weight[j][i] * Upper->Error[j]; } Lower->Error[i] = Net->Gain * Out * (1-Out) * Err; } } void BackpropagateNet(NET* Net) { INT l; for (l=NUM_LAYERS-1; l>1; l--) { BackpropagateLayer(Net, Net->Layer[l], Net->Layer[l-1]); } } void AdjustWeights(NET* Net) { INT l,i,j; REAL Out, Err, dWeight; for (l=1; lLayer[l]->Units; i++) { for (j=0; j<=Net->Layer[l-1]->Units; j++) { Out = Net->Layer[l-1]->Output[j]; Err = Net->Layer[l]->Error[i]; dWeight = Net->Layer[l]->dWeight[i][j]; Net->Layer[l]->Weight[i][j] += Net->Eta * Err * Out + Net->Alpha * dWeight; Net->Layer[l]->dWeight[i][j] = Net->Eta * Err * Out; } } } } /****************************************************************************** S I M U L A T I N G T H E N E T ******************************************************************************/ void SimulateNet(NET* Net, REAL* Input, REAL* Output, REAL* Target, BOOL Training) { SetInput(Net, Input); PropagateNet(Net); GetOutput(Net, Output); ComputeOutputError(Net, Target); if (Training) { BackpropagateNet(Net); AdjustWeights(Net); } } void TrainNet(NET* Net, INT Epochs) { INT Year, n; REAL Output[M]; for (n=0; nError; } TestError = 0; for (Year=TEST_LWB; Year<=TEST_UPB; Year++) { SimulateNet(Net, &(Sunspots[Year-N][0]), Output, &(Sunspots[Year][4]), FALSE); TestError += Net->Error; } fprintf(f, " NMSE is %0.3f on Training Set and %0.3f on Test Set", TrainError / TrainErrorPredictingMean, TestError / TestErrorPredictingMean); } void EvaluateNet(NET* Net) { INT Year; REAL Output [M]; REAL Output_[M]; fprintf(f, " "); fprintf(f, "Year Sunspots Open-Loop Prediction Closed-Loop Prediction "); fprintf(f, " "); for (Year=EVAL_LWB; Year<=EVAL_UPB; Year++) { SimulateNet(Net, &(Sunspots [Year-N][0]), Output, &(Sunspots [Year][4]), FALSE); SimulateNet(Net, &(Sunspots_[Year-N][0]), Output_, &(Sunspots_[Year][4]), FALSE); Sunspots_[Year][4] = Output_[0]; fprintf(f, "%d %0.3f %0.3f %0.3f ", FIRST_YEAR + Year, Sunspots[Year][0], Output [0], Output_[0]); } } /****************************************************************************** M A I N ******************************************************************************/ int main() { NET Net; BOOL Stop; REAL MinTestError; InitializeRandoms(); GenerateNetwork(&Net); RandomWeights(&Net); InitializeApplication(&Net); Stop = FALSE; MinTestError = MAX_REAL; do { TrainNet(&Net, 10); TestNet(&Net); if (TestError < MinTestError) { fprintf(f, " - saving Weights ..."); MinTestError = TestError; SaveWeights(&Net); } else if (TestError > 1.2 * MinTestError) { fprintf(f, " - stopping Training and restoring Weights ..."); Stop = TRUE; RestoreWeights(&Net); } } while (NOT Stop); TestNet(&Net); EvaluateNet(&Net); FinalizeApplication(&Net); } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions