Introduction + science behind topic
Recently, when I wanted to sharpen my F# skill I come out with idea for small program. Its task is to proof global warming using ice drilling data. Keep in mind it’s not entirely 100% accurate, it’s more like training F# in interesting topic. Ice drilling is a technique in which you use deep stored ice to take its properties. You can determine CO2 levels and temperature what is needed to see correlation between them. More information here. This idea was very interesting to me also because in this small program I could use quite a few mechanism unique to F#.
type co2Csv = CsvProvider< "co2.csv", "\t" > let co2Data = co2Csv.Load("co2.csv").Rows
syntax like you can observe with
. Important to mention for type providers is also fact, that they can be used in many various types of data like sql, csv, json and even html to browse DOM.
let computeCorrelation (first : float list) (second : float list) = if first.Length <> second.Length then failwith "Collections needs to be same size" let firstAvg = List.average first let secondAvg = List.average second let sum = List.zip first second |> List.sumBy (fun x -> (fst x - firstAvg) * (snd x - secondAvg)) sum / (float first.Length * standardDevation first * standardDevation second)
let getCorrelationMeaning = function | 0.0 -> "No correlation" | x when Math.Abs(x) < 0.2 -> "Very minor correlation" | x when Math.Abs(x) < 0.4 -> "minor correlation" | x when Math.Abs(x) < 0.7 -> "Medium correlation" | x when Math.Abs(x) < 0.9 -> "Major correlation" | x when Math.Abs(x) < 1.0 -> "Very major correlation" | _ -> "Error - correlation must be between -1 and 1"
let co2Series = co2Data |> Seq.map (fun x -> (convertBPtoThousandsYears x.<code></code>Gas age<code></code>, x.<code></code>CO2 (ppmv)<code></code>)) let tempSeries = tempData |> Seq.map (fun x -> (convertBPtoThousandsYears x.<code></code>Ice age (GT4)<code></code>, x.DeltaTS))
let co2Chart = Chart.Line(co2Series, "CO2 [ppm]", Color = Color.Red) let tempChart = Chart.Line(tempSeries, "Temperature [C]", Color = Color.Blue)
Chart.Combine([ co2Chart; tempChart ]) |> Chart.WithXAxis(Title = "Thousands of years") |> Chart.WithLegend() |> Chart.Show