Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 14 additions & 13 deletions src/AI-LinearModels-Tests/AIAbstractLinearModelTest.class.st
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@
Class {
#name : #AIAbstractLinearModelTest,
#superclass : #TestCase,
#name : 'AIAbstractLinearModelTest',
#superclass : 'TestCase',
#instVars : [
'model'
],
#category : #'AI-LinearModels-Tests'
#category : 'AI-LinearModels-Tests',
#package : 'AI-LinearModels-Tests'
}

{ #category : #testing }
{ #category : 'testing' }
AIAbstractLinearModelTest class >> isAbstract [
^self == AIAbstractLinearModelTest
]

{ #category : #running }
{ #category : 'running' }
AIAbstractLinearModelTest >> regression [

^ self subclassResponsibility
]

{ #category : #running }
{ #category : 'running' }
AIAbstractLinearModelTest >> setUp [

super setUp.
model := self regression
]

{ #category : #tests }
{ #category : 'tests' }
AIAbstractLinearModelTest >> testDivergingException [
^ self subclassResponsibility
]

{ #category : #tests }
{ #category : 'tests' }
AIAbstractLinearModelTest >> testExactFitSingleVariable [
^ self subclassResponsibility
]

{ #category : #tests }
{ #category : 'tests' }
AIAbstractLinearModelTest >> testInconsistentFitOnDimension [

| input output |
Expand All @@ -45,7 +46,7 @@ AIAbstractLinearModelTest >> testInconsistentFitOnDimension [
self should: [ model fitX: input y: output ] raise: Error
]

{ #category : #tests }
{ #category : 'tests' }
AIAbstractLinearModelTest >> testInitializeWeightsToZeroOfSize [

| expectedInitWeigths |
Expand All @@ -55,13 +56,13 @@ AIAbstractLinearModelTest >> testInitializeWeightsToZeroOfSize [
self assert: model weights equals: expectedInitWeigths
]

{ #category : #tests }
{ #category : 'tests' }
AIAbstractLinearModelTest >> testPerformedIterationsIsInitialized [

self assert: model performedIterations equals: nil
]

{ #category : #tests }
{ #category : 'tests' }
AIAbstractLinearModelTest >> testPredictionWithNonFittedModel [

| input output |
Expand All @@ -70,7 +71,7 @@ AIAbstractLinearModelTest >> testPredictionWithNonFittedModel [
self should: [ output := model predict: input ] raise: Error
]

{ #category : #tests }
{ #category : 'tests' }
AIAbstractLinearModelTest >> testWeightedSumOf [

model bias: 2.
Expand Down
17 changes: 9 additions & 8 deletions src/AI-LinearModels-Tests/AILinearRegressionFixture.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,25 @@ I am a fixture with a small and simple example for linear regression.
I provide input matrix X and expected output vector y.
"
Class {
#name : #AILinearRegressionFixture,
#superclass : #Object,
#name : 'AILinearRegressionFixture',
#superclass : 'Object',
#instVars : [
'bias',
'inputMatrix',
'outputVector',
'weights'
],
#category : #'AI-LinearModels-Tests'
#category : 'AI-LinearModels-Tests',
#package : 'AI-LinearModels-Tests'
}

{ #category : #accessing }
{ #category : 'accessing' }
AILinearRegressionFixture >> bias [

^ bias
]

{ #category : #initialization }
{ #category : 'initialization' }
AILinearRegressionFixture >> initialize [

| function |
Expand All @@ -36,19 +37,19 @@ AILinearRegressionFixture >> initialize [

]

{ #category : #accessing }
{ #category : 'accessing' }
AILinearRegressionFixture >> inputMatrix [

^ inputMatrix
]

{ #category : #accessing }
{ #category : 'accessing' }
AILinearRegressionFixture >> outputVector [

^ outputVector
]

{ #category : #accessing }
{ #category : 'accessing' }
AILinearRegressionFixture >> weights [

^ weights
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,41 @@
Class {
#name : #AILinearRegressionLeastSquaresTest,
#superclass : #AILinearRegressionTest,
#category : #'AI-LinearModels-Tests'
#name : 'AILinearRegressionLeastSquaresTest',
#superclass : 'AILinearRegressionTest',
#category : 'AI-LinearModels-Tests',
#package : 'AI-LinearModels-Tests'
}

{ #category : #running }
{ #category : 'running' }
AILinearRegressionLeastSquaresTest >> regression [

^ AILinearRegressionLeastSquares new
]

{ #category : #tests }
{ #category : 'tests' }
AILinearRegressionLeastSquaresTest >> testInitializeWeightsToZeroOfSize [

self skip
]

{ #category : #tests }
{ #category : 'tests' }
AILinearRegressionLeastSquaresTest >> testLearningRateIsInitialized [

self skip
]

{ #category : #tests }
{ #category : 'tests' }
AILinearRegressionLeastSquaresTest >> testMaxIterationsIsInitialized [

self skip
]

{ #category : #tests }
{ #category : 'tests' }
AILinearRegressionLeastSquaresTest >> testPerformedIterationsIsInitialized [

self skip
]

{ #category : #tests }
{ #category : 'tests' }
AILinearRegressionLeastSquaresTest >> testWeightDerivativeforXCostDerivative [

self skip
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
Class {
#name : #AILinearRegressionLeastSquaresVanillaTest,
#superclass : #AILinearRegressionLeastSquaresTest,
#category : #'AI-LinearModels-Tests'
#name : 'AILinearRegressionLeastSquaresVanillaTest',
#superclass : 'AILinearRegressionLeastSquaresTest',
#category : 'AI-LinearModels-Tests',
#package : 'AI-LinearModels-Tests'
}

{ #category : #running }
{ #category : 'running' }
AILinearRegressionLeastSquaresVanillaTest >> regression [

^ AILinearRegressionLeastSquaresVanilla new
]

{ #category : #tests }
{ #category : 'tests' }
AILinearRegressionLeastSquaresVanillaTest >> testBiasDerivative [

self skip
]

{ #category : #tests }
{ #category : 'tests' }
AILinearRegressionLeastSquaresVanillaTest >> testCostDerivativeActual [

self skip
]

{ #category : #tests }
{ #category : 'tests' }
AILinearRegressionLeastSquaresVanillaTest >> testWeightedSumOf [

self skip
Expand Down
25 changes: 13 additions & 12 deletions src/AI-LinearModels-Tests/AILinearRegressionTest.class.st
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
Class {
#name : #AILinearRegressionTest,
#superclass : #AIAbstractLinearModelTest,
#name : 'AILinearRegressionTest',
#superclass : 'AIAbstractLinearModelTest',
#instVars : [
'fixture'
],
#category : #'AI-LinearModels-Tests'
#category : 'AI-LinearModels-Tests',
#package : 'AI-LinearModels-Tests'
}

{ #category : #running }
{ #category : 'running' }
AILinearRegressionTest >> regression [

^ AILinearRegression new
Expand All @@ -16,7 +17,7 @@ AILinearRegressionTest >> regression [
yourself
]

{ #category : #running }
{ #category : 'running' }
AILinearRegressionTest >> setUp [

super setUp.
Expand All @@ -25,7 +26,7 @@ AILinearRegressionTest >> setUp [

]

{ #category : #tests }
{ #category : 'tests' }
AILinearRegressionTest >> testBiasAlmostEqual [

model
Expand All @@ -35,15 +36,15 @@ AILinearRegressionTest >> testBiasAlmostEqual [
self assert: model bias closeTo: fixture bias precision: 0.001
]

{ #category : #tests }
{ #category : 'tests' }
AILinearRegressionTest >> testBiasDerivative [

self
assert: (model biasDerivative: #( 3 4 5 6))
equals: 4.5
]

{ #category : #tests }
{ #category : 'tests' }
AILinearRegressionTest >> testCostDerivativeActual [

self
Expand All @@ -55,7 +56,7 @@ AILinearRegressionTest >> testCostDerivativeActual [
equals: #(1 2 3)
]

{ #category : #tests }
{ #category : 'tests' }
AILinearRegressionTest >> testDivergingException [

"Training the model with non-sense, completely unproportioned data and with a very high learning rate to raise the diverging exception."
Expand All @@ -71,7 +72,7 @@ AILinearRegressionTest >> testDivergingException [
self should: [model fitX: input y: output] raise: ModelStartingToDivergeException
]

{ #category : #tests }
{ #category : 'tests' }
AILinearRegressionTest >> testExactFitSingleVariable [

| newInput expectedOutput actualOutput |
Expand All @@ -83,15 +84,15 @@ AILinearRegressionTest >> testExactFitSingleVariable [
actualOutput with: expectedOutput do: [ :actual :expected | self assert: actual closeTo: expected precision: 0.001 ]
]

{ #category : #tests }
{ #category : 'tests' }
AILinearRegressionTest >> testWeightDerivativeforXCostDerivative [

self
assert: (model weightDerivativeforX: #( (1 2 3) (4 5 6) (7 8 9) (10 11 12) ) costDerivative: #( 9 8 7 6 ))
equals: #( 37.5 45 52.5 )
]

{ #category : #tests }
{ #category : 'tests' }
AILinearRegressionTest >> testWeightsAlmostEqual [

model
Expand Down
Loading