Can any one help me converting my below F# code into Kotlin:
//namespace SysIO
open System.Collections.Generic // for Dictionary
printf "Hi, Let's start \n"
let series = [|30;21;29;31;40;48;53;47;37;39;31;29;17;9;20;24;27;35;41;38;
27;31;27;26;21;13;21;18;33;35;40;36;22;24;21;20;17;14;17;19;
26;29;40;31;20;24;18;26;17;9;17;21;28;32;46;33;23;28;22;27;
18;8;17;21;31;34;44;38;31;30;26;32|]
let initialSeasonalComponents (series : int []) slen : IDictionary<int, double> =
let nSeasons = float (series.Length / slen)
let grouped =
series
|> Array.map float
|> Array.chunkBySize slen
let seasonAverages = grouped |> Array.map Array.average
Array.init slen (fun i -> i, (Array.zip grouped seasonAverages
|> Array.fold (fun s (els, av) -> els.[i] + s - av) 0.)
/ nSeasons) |> dict
printfn "Seasons Averageß: \n %A" (initialSeasonalComponents series 12)
let initialTrend (series : int []) (slen : int) : double =
series |> Array.windowed slen
|> Array.fold (fun s x ->
(x |> Array.rev |> Array.head) - (x |> Array.head) + s) 0
|> float
|> fun x -> x / (float slen)
printfn "Initial Trend: \n %A" (initialTrend series 12)
let tripleExponentialSmoothing series slen alpha beta gamma nPreds =
let mutable smooth = 0.
let mutable trend = 0.
let seasonals = initialSeasonalComponents series 12 |> Dictionary
seq {
for i in 0..(series.Length+nPreds-1) do
match i with
| 0 -> // initial values
smooth <- series |> Array.head |> float
trend <- initialTrend series slen
yield series |> Array.head |> float
| i when i >= series.Length -> // we are forecasting
let m = i - series.Length + 1
yield (smooth + float m * trend) + seasonals.[i%slen]
| _ ->
let v = series |> Array.head |> float
let lastSmooth = smooth
smooth <- alpha*(v-seasonals.Item(i%slen)) + (1.-alpha)*(smooth+trend)
trend <- beta * (smooth-lastSmooth) + (1.-beta)*trend
seasonals.[i%slen] <- gamma*(v-smooth) + (1.-gamma)*seasonals.[i%slen]
yield smooth + trend + seasonals.Item(i%slen) }
// result
let f = tripleExponentialSmoothing series 12 0.716 0.029 0.993 24
printfn "Forecast: \n %A" f