Last active
December 26, 2015 18:59
-
-
Save Vijesh2/7198221 to your computer and use it in GitHub Desktop.
Exploring implementation of kth central moments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type moment_type = | |
| | CENTRAL | |
| | ZERO | |
| let intToFloat intList = | |
| intList | |
| |> List.map (fun (i:int) -> (float i)) | |
| let ave intList = | |
| intList | |
| |> intToFloat | |
| |> List.average | |
| let moment offset_flag k (sample : float List) = | |
| let offset = | |
| match offset_flag with | |
| | CENTRAL -> List.average sample | |
| | ZERO -> 0.0 | |
| let mean = | |
| sample | |
| |> List.average | |
| sample | |
| |> List.map (fun i -> pown (i - offset) k) | |
| |> List.average | |
| let central_moment = moment CENTRAL | |
| let zero_moment = moment ZERO | |
| let bothMoments i = | |
| [central_moment i; zero_moment i] | |
| let first_moments = bothMoments 1 | |
| let second_moments() = bothMoments 2 | |
| let third_moments() = bothMoments 3 | |
| // sample use | |
| let sample1 = [-5;-4;1;2;3;] | |
| printfn "first moments (central | zero) of %A are (%A | %A)" sample1 (sample1 |> intToFloat |> (List.iter |> first_moments)) | |
| printfn "second moments (central | zero) of %A are (%A | %A)" sample1 (sample1 |> intToFloat |> second_moments) | |
| printfn "third moments (central | zero) of %A are (%A | %A)" sample1 (sample1 |> intToFloat |> third_moments) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment