Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Generalised Linear Models to FSharpStats #334

Merged
merged 54 commits into from
Oct 24, 2024
Merged
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
6288d55
Implement IRLS solver for GLMs
LibraChris Feb 8, 2024
425d12b
Rename variables
LibraChris May 8, 2024
d1c9c41
add qr based GLM
LibraChris May 10, 2024
d637be7
add inital tests for the glm
LibraChris May 10, 2024
d0fc5ee
Update glm QR Solver
LibraChris May 14, 2024
d24955a
Add new Test for GLMs using Gamma Distribution
LibraChris May 14, 2024
ddcf09c
Add tests for the Poisson linker functions
LibraChris May 14, 2024
60c3ec1
Add tests for the Gamma linker functions
LibraChris May 14, 2024
0f0661c
Rename testcases to Reflect their log function
LibraChris May 14, 2024
fe83ba6
Add tests for the LogitLinkFunction
LibraChris May 14, 2024
ab44068
Add tests for the InverseSquaredLinkFunction
LibraChris May 15, 2024
c00980e
Add tests by example for glm IrLS solver
LibraChris May 15, 2024
1e6a524
Add tests for the IdentityLinkFunction
LibraChris May 15, 2024
ac416bf
Add tests groudwork for the BinomialLinkFunction
LibraChris May 15, 2024
8f88c1e
Add tests for the variance of Binominal Family
LibraChris May 16, 2024
148a933
Add tests for the variance of Poisson Family
LibraChris May 16, 2024
a8b5f00
Add tests for the variance of Gaussian/Normal Family
LibraChris May 16, 2024
2cbef3c
Fix test implemetation for familyVarianceFunctions
LibraChris May 16, 2024
a73a07e
Add tests for the variance of Gamma Family
LibraChris May 16, 2024
4d03d46
Add tests for the variance of Inv.Gaussian Family
LibraChris May 16, 2024
4465115
Rename test Cases based on their DistributionFamily
LibraChris May 16, 2024
a6e6568
Fix LogitLinkFunction
LibraChris May 16, 2024
de1fcd7
remove redundant BinomialLinkFunction
LibraChris May 16, 2024
3554a02
Remove redundant LinkFunction
LibraChris May 16, 2024
c1f38f1
Fix InverseSquaredLinkFunction
LibraChris May 16, 2024
2a3b096
Updated Gamma Distribution Variance function
LibraChris May 16, 2024
3f5a349
add Deriv Functions
LibraChris May 18, 2024
2787fbd
add Tests for Link and deriv
LibraChris May 18, 2024
3ee33e3
fix various Linkfunctions
LibraChris May 18, 2024
43cea23
Rework GLM QR Solver
LibraChris May 22, 2024
3e83833
Modify tests
LibraChris May 22, 2024
2816155
Add tests prototype for QR-Stepwise iteration
LibraChris May 22, 2024
c5ced84
Fix QR based solver for GLMs
LibraChris May 22, 2024
5029c3a
Modify Variance tests
LibraChris May 22, 2024
c3dddcb
Update statistics
LibraChris May 28, 2024
a7c5c1b
Update GeneralisedLinearModel.fs
LibraChris May 28, 2024
d8877b7
Update GeneralisedLinearModel.fs
LibraChris May 29, 2024
3cd68a8
Update GeneralisedLinearModel.fs
LibraChris May 30, 2024
253ac91
Rework GLMStatistics
LibraChris May 31, 2024
19cad0f
Remove deprecated GLM.Irls
LibraChris May 31, 2024
1b3336f
Fix minor testing issue
LibraChris May 31, 2024
a1d0ee4
add getFamilyReisualDeviance for more families
LibraChris Jun 2, 2024
37d03e0
Write code comments and documentation
LibraChris Jun 5, 2024
5e9a1b6
add Documentation for GLM Usage
LibraChris Jun 7, 2024
72bfb83
Update formating for documentation
LibraChris Jun 10, 2024
a8a0004
added data for Documentation
LibraChris Jun 10, 2024
f694340
remote tests for binominal family variance
LibraChris Jun 10, 2024
8dcd8ab
Adress changes requested in #344
LibraChris Jun 12, 2024
170519e
Adress changes requested in #334
LibraChris Jun 18, 2024
ba5ae9c
Update xml comments
LibraChris Jun 19, 2024
6c3a235
fix building error
LibraChris Jul 3, 2024
2e80081
Fix Typo
LibraChris Jul 3, 2024
13b3de9
Fix indentations
LibraChris Aug 26, 2024
df24c3f
Updated XML documentation
LibraChris Oct 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename testcases to Reflect their log function
- Rename Poisson -> LogLinkFunction
- Rename Gamme -> InverseLinkFunction
  • Loading branch information
LibraChris committed Jul 3, 2024
commit 0f0661c7609f76e4a71ef1279ae2de69384f96bf
34 changes: 16 additions & 18 deletions tests/FSharp.Stats.Tests/GeneralisedLinearModels.fs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ module internal HelperFunctions =
[<Tests>]
let linkerFunctions =
testList "Test Linker functions for GLM" [
testCase "Poisson" <| fun () ->
testCase "LogLinkFunction" <| fun () ->
let linkInvExpected =
[|
FSharp.Stats.Ops.inf
Expand All @@ -105,8 +105,7 @@ let linkerFunctions =
0.
|]

let family = Fitting.GLM.GlmDistributionFamily.Poisson
let link = Fitting.GLM.GlmDistributionFamily.getLinkFunction family
let link = Fitting.GLM.LinkFunctions.LogLinkFunction
let linkF = link.getLink
let linkFInv = link.getInvLink
let linkFInvDer = link.getInvLinkDerivative
Expand All @@ -119,17 +118,17 @@ let linkerFunctions =
let expected = linkInvExpected.[i]
let actual = linkFInvActual.[i]
if isInf actual then
Expect.isTrue (isInf expected) $" isInf Element {i} Poisson inverse Linkfunction is incorrect. {testingArray.[i]} was linked to {actual} instead to {expected}"
Expect.isTrue (isInf expected) $" isInf Element {i} LogLinkFunction inverse Linkfunction is incorrect. {testingArray.[i]} was linked to {actual} instead to {expected}"
elif isNegInf actual then
Expect.isTrue (isNegInf expected) $" isNegInf Element {i} Poisson inverse Linkfunction is incorrect. {testingArray.[i]} was linked to {actual} instead to {expected}"
Expect.isTrue (isNegInf expected) $" isNegInf Element {i} LogLinkFunction inverse Linkfunction is incorrect. {testingArray.[i]} was linked to {actual} instead to {expected}"
elif isNan actual then
Expect.isTrue (isNan expected) $"isNan Element {i} Poisson inverse Linkfunction is incorrect. {testingArray.[i]} was linked to {actual} instead to {expected}"
Expect.isTrue (isNan expected) $"isNan Element {i} LogLinkFunction inverse Linkfunction is incorrect. {testingArray.[i]} was linked to {actual} instead to {expected}"
else
Expect.floatClose
Accuracy.medium
expected
actual
$" Else Element {i} Poisson inverse Linkfunction is incorrect. {testingArray.[i]} was linked to {actual} instead to {expected}"
$" Else Element {i} LogLinkFunction inverse Linkfunction is incorrect. {testingArray.[i]} was linked to {actual} instead to {expected}"

for i=0 to testingArray.Length-1 do
let expected = linkInvDerExpected.[i]
Expand All @@ -147,7 +146,7 @@ let linkerFunctions =
actual
$" Else Element {i} Poisson inverse derivative Linkfunction is incorrect. {testingArray.[i]} was linked to {actual} instead to {expected}"

testCase "Gamma" <| fun () ->
testCase "InverseLinkFunction" <| fun () ->
let linkInvExpected =
[|
0.
Expand All @@ -170,8 +169,7 @@ let linkerFunctions =
-0.00000000e+00
|]

let family = Fitting.GLM.GlmDistributionFamily.Gamma
let link = Fitting.GLM.GlmDistributionFamily.getLinkFunction family
let link = Fitting.GLM.LinkFunctions.InverseLinkFunction
let linkF = link.getLink
let linkFInv = link.getInvLink
let linkFInvDer = link.getInvLinkDerivative
Expand All @@ -184,33 +182,33 @@ let linkerFunctions =
let expected = linkInvExpected.[i]
let actual = linkFInvActual.[i]
if isInf actual then
Expect.isTrue (isInf expected) $" isInf Element {i} Gamma inverse Linkfunction is incorrect. {testingArray.[i]} was linked to {actual} instead to {expected}"
Expect.isTrue (isInf expected) $" isInf Element {i} InverseLinkFunction inverse Linkfunction is incorrect. {testingArray.[i]} was linked to {actual} instead to {expected}"
elif isNegInf actual then
Expect.isTrue (isNegInf expected) $" isNegInf Element {i} Gamma inverse Linkfunction is incorrect. {testingArray.[i]} was linked to {actual} instead to {expected}"
Expect.isTrue (isNegInf expected) $" isNegInf Element {i} InverseLinkFunction inverse Linkfunction is incorrect. {testingArray.[i]} was linked to {actual} instead to {expected}"
elif isNan actual then
Expect.isTrue (isNan expected) $"isNan Element {i} Gamma inverse Linkfunction is incorrect. {testingArray.[i]} was linked to {actual} instead to {expected}"
Expect.isTrue (isNan expected) $"isNan Element {i} InverseLinkFunction inverse Linkfunction is incorrect. {testingArray.[i]} was linked to {actual} instead to {expected}"
else
Expect.floatClose
Accuracy.medium
expected
actual
$" Else Element {i} Gamma inverse Linkfunction is incorrect. {testingArray.[i]} was linked to {actual} instead to {expected}"
$" Else Element {i} InverseLinkFunction inverse Linkfunction is incorrect. {testingArray.[i]} was linked to {actual} instead to {expected}"

for i=0 to testingArray.Length-1 do
let expected = linkInvDerExpected.[i]
let actual = linkFInvDerActual.[i]
if isInf actual then
Expect.isTrue (isInf expected) $" isInf Element {i} Gamma inverse derivative Linkfunction is incorrect. {testingArray.[i]} was linked to {actual} instead to {expected}"
Expect.isTrue (isInf expected) $" isInf Element {i} InverseLinkFunction inverse derivative Linkfunction is incorrect. {testingArray.[i]} was linked to {actual} instead to {expected}"
elif isNegInf actual then
Expect.isTrue (isNegInf expected) $" isNegInf Element {i} Gamma inverse derivative Linkfunction is incorrect. {testingArray.[i]} was linked to {actual} instead to {expected}"
Expect.isTrue (isNegInf expected) $" isNegInf Element {i} InverseLinkFunction inverse derivative Linkfunction is incorrect. {testingArray.[i]} was linked to {actual} instead to {expected}"
elif isNan actual then
Expect.isTrue (isNan expected) $"isNan Element {i} Gamma inverse derivative Linkfunction is incorrect. {testingArray.[i]} was linked to {actual} instead to {expected}"
Expect.isTrue (isNan expected) $"isNan Element {i} InverseLinkFunction inverse derivative Linkfunction is incorrect. {testingArray.[i]} was linked to {actual} instead to {expected}"
else
Expect.floatClose
Accuracy.medium
expected
actual
$" Else Element {i} Gamma inverse derivative Linkfunction is incorrect. {testingArray.[i]} was linked to {actual} instead to {expected}"
$" Else Element {i} InverseLinkFunction inverse derivative Linkfunction is incorrect. {testingArray.[i]} was linked to {actual} instead to {expected}"

]

Expand Down