Sunspots

Example: Predicting Yearly Sunspot Activity with a Neural Network

Short History of Sunspots

Galileo Galilei (1564-1642) was one of the first independent discoverers of sunspots, others were T. Harriot, S. Marius and J. Fabricius. In 1613 Galileo described his observations in Istoria e dimostrazioni intorno alle macchie solari e loro accidenti (History and Demonstrations Concerning Sunspots and Their Properties). Based on his observations of the motion of sunspots he found that they are at or near the surface of the sun. This contradicted the Aristotelian and more importantly the Christian belief that all heavenly bodies are perfect with an immobile Earth in the center. A cleric C. Scheiner argued that sunspots are satellites of the Sun to save the perfection of the Sun. Despite the Christians condemnation of Galileo to life imprisonment and banning his writings for more than two hundred years, the infallible word of God did not withstand rational thought. Scientific observations have shown that a sunspot is a gas vortex in the Sun's photosphere. The biggest sunspots exceed Earth in size and have magnetic fields thousands of times stronger than Earth’s magnetic field.

S. H. Schwabe, an amateur astronomer, observed sunspots almost daily for 17 years before announcing in 1843 that sunspots vary in number in a cycle of about 10 years. His findings were confirmed by R. Wolf, an astronomer at the University of Zürich. Wolf calculated the cycle's length to an average of 11.1 years by use of earlier records. In 1849 he devised a system that is still used, of counting sunspots and sunspot groups known as Wolf's sunspot numbers. Wolf also correlated the sunspot cycle with the observations of the Earth's magnetism made by J. von Lamont. G. E. Hale discovered their magnetic fields in 1908. Alternating cycles of sunspots display opposite magnetic polarities, taken together they constitute the 22 year solar cycle. Northern lights (Aurora Borealis) have a period of maximum and minimum intensity that is almost exactly opposite that of the sunspot cycle. The intensity of the auroras is normally low when the sun is very active. Huge displays that occur farther from the earth’s poles than normal, however, occur more often while the sun is very active. Solar activity can influence other conditions on the Earth such as radio communications.

The economist W. Jevons sunspot theory was once widely accepted. According to his theory sunspots affect meteorological conditions. That is, during periods of sunspots, weather conditions are often more severe. Jevons felt that sunspots affected the quantity and quality of harvested crops which in turn affected the economy. The astronomer E. W. Maunder found that very few sunspots were seen between 1645 and 1715. This period, called the Maunder minimum, was associated with the Little Ice Age in Europe from around 1550 to 1850. It is not proven that this cold period was caused by the Maunder minimum, but there is evidence for other such low-activity periods at roughly 500-year intervals. When solar activity is high, strong magnetic fields carried by the solar wind block out high-energy galactic cosmic rays approaching the Earth and less carbon-14 is produced. Measurement of carbon-14 in dated tree rings has confirmed the low activity at the time.

Yearly Sunspot Numbers from 1700 to Present

Creating the Neural Network

The neural network in this example is given the yearly sunspot data for previous years and has to predict the sunspot activity for the following year. The number of neurons in the input layer matches the number of years of previous data. The data will be normalized in the 0-1 range so the Sigmoid activation functions are used.

<<Fann` <<Graphics` num = 30 ; (*Number of input neurons and number of previous ye ... 2754;Sigmoid, ActivationFunctionOutputLayerSigmoid, TrainingAlgorithmQuickprop] ;

Training

The data is divided into training data and test data, so the prediction accuracy of the network can be measured. A simple function is defined to group the data.

SpotData[dataspots_] := Module[{i}, sunspots = dataspots ; year = suns ... = Take[allspots, {1, -num - 1}] ; testspots = Take[allspots, {-num, -1}] ; SpotData[trainspots] ;

The neural network can now be trained on the training part of the data.

RowBox[{RowBox[{error, =, RowBox[{Train, [, RowBox[{net, ,, sundata, ,, Epochs5000, ,, ...  {Hue[1]}, ,, RowBox[{PlotRange, , RowBox[{{, RowBox[{0.05, ,, 0.005}], }}]}]}], ]}], ;}]

[Graphics:HTMLFiles/Sunspots_5.gif]

Testing

The network is compared with the training data to verify that the net can approximate the historic fluctuations.

predspots = {} ; Do[history = Take[normspots, {i, i + num - 1}] ; prediction = ... 54;, 0.25}], ,, SymbolShapeNone, ,, AxesOrigin {First[year] + num, 0}}], ]}], ;}]

[Graphics:HTMLFiles/Sunspots_7.gif]

Testing with data that the network was not trained on gives a measure of its ability to predict future sunspot activity. In the following diagram the blue line represents the actual sunspot activity over the period. The red line shows the predictions when the network is presented with historic data based on the actual sunspot activity (closed loop). The brown line shows the predictions when the previous predictions are used as historic data (open loop). The open loop predictions gradually become more divergent.

openspots = closedspots = {} ; openhistory = closedhistory = Take[normspots, {-num, -1}] ; Do[ ...  ,, SymbolShapeNone, ,, AxesOrigin {testspots〚1, 1〛, 0}}], ]}], ;}]

[Graphics:HTMLFiles/Sunspots_9.gif]

Prediction

The basic properties of the neural net has been verified and it can now be trained on data for the remaining time period.

SpotData[Join[Take[trainspots, -num], testspots]] ; RowBox[{RowBox[{error, =, RowBox[{Train, [ ... ;, 0.001}]}], ]}]}], ;}] LogListPlot[error, PlotJoinedTrue, PlotStyle {Hue[1]}] ;

[Graphics:HTMLFiles/Sunspots_11.gif]

Sunspot activity can now be predicted for the coming years. No claims are made here regarding the accuracy of the prediction and as could be seen with the open loop test the errors in the predictions build up over time.

predspots = {} ; predhistory = Take[normspots, {-num, -1}] ; Do[prediction = Execute[n ...  ,, SymbolShapeNone, ,, AxesOrigin {predspots〚1, 1〛, 0}}], ]}], ;}]

[Graphics:HTMLFiles/Sunspots_13.gif]

Sunspot Periodicity

Some characteristics are known concerning the periodic rise and fall of sunspot activity. The time between both maximum and minimum sunspot activity is about 11 years, but while the time to go from a minimum to a maximum is about 4 years, the fall from maximum to minimum is about 7 years. This can be verified on the historic data and it can be seen if the predicted data preserves the characteristics. Functions to find the local maxima/minima and report on the asymmetry are first defined.

localmax[u_, v_] := Module[{w = {}, j = 0, i}, For[i = 3, i<Length[v] - 2,  ... t〚All, 1〛, #>Min[maxspot〚All, 1〛] &]]]], " years. "]

The asymmetry in the historic data can now be verified.

SpotData[allspots] ; maxct = localmax[year, spots] ; minct = localmin[year, spots] ; SpotPeriodicity[minct, maxct] ;

RowBox[{Local maximum period: , , 10.9259, ,  years. , , Local minimum ...  ,  years. , , Local maximum to minimum: , , 6.62963, ,  years. }]

The degree to which predictions preserve the asymmetry can be tested. If the predictions fail this test then start again from the 'Creating the Neural Network' section.

maxpred = localmax[predspots〚All, 1〛, predspots〚All, 2〛] ; minpred ... ots〚All, 1〛, predspots〚All, 2〛] ; SpotPeriodicity[minpred, maxpred] ;

RowBox[{Local maximum period: , , 10., ,  years. , , Local minimum per ...  4.5, ,  years. , , Local maximum to minimum: , , 6., ,  years. }]

Saving

The trained network can be saved in Mathematica and Fann formats for future use before it is removed.

filepath = $HomeDirectory<>"/My Documents/My Math/" ; netfile = filepath<&g ... tfile] ; floatnetfile = filepath<>"sunspots.net" ; SaveFloat[floatnetfile, net] ;

Credits

The example builds on 'Time-Series Forecasting' by K. Kutza, 1996, with reference to D. E. Rumelhart, G. E. Hinton, R. J. Williams 'Learning Internal Representations by Error Propagation' in: D.E. Rumelhart, J.L. McClelland (Eds.) Parallel Distributed Processing, Volume 1, MIT Press, Cambridge, MA, pp. 318-362, 1986. The calculations on periodicity are based on similar calculations in the Mathcad 2001 Resource Center. Yearly, monthly and daily historical sunspot data is available at the National Geophysical Data Center, www.ngdc.noaa.gov. The short history of sunspots were compiled from quotations of articles in Encyclopædia Britannica and Encarta® Reference Library. This notebook is part of Fann for Mathematica © 2004 freegoldbar (http://www.geocities.com/freegoldbar/).

Discard[All] ;


Created by freegoldbar  (September 16, 2004)

Hosted by www.Geocities.ws

1