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
10 changes: 6 additions & 4 deletions src/Math-Matrix/ManifestMathMatrix.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
Please describe the package using the class comment of the included manifest class. The manifest class also includes other additional metadata for the package. These meta data are used by other tools such as the SmalllintManifestChecker and the critics Browser
"
Class {
#name : #ManifestMathMatrix,
#superclass : #PackageManifest,
#category : #'Math-Matrix-Manifest'
#name : 'ManifestMathMatrix',
#superclass : 'PackageManifest',
#category : 'Math-Matrix-Manifest',
#package : 'Math-Matrix',
#tag : 'Manifest'
}

{ #category : #'meta-data - dependency analyser' }
{ #category : 'meta-data - dependency analyser' }
ManifestMathMatrix class >> manuallyResolvedDependencies [
^ #(#'Collections-Streams' #'Math-Operations-Extensions')
]
8 changes: 4 additions & 4 deletions src/Math-Matrix/Number.extension.st
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Extension { #name : #Number }
Extension { #name : 'Number' }

{ #category : #'*Math-Matrix' }
{ #category : '*Math-Matrix' }
Number >> addWithRegularMatrix: aMatrix [
"Adds itself to every row of the matrix"
^ PMMatrix rows: (aMatrix rowsCollect: [ :row | row + self ])
]

{ #category : #'*Math-Matrix' }
{ #category : '*Math-Matrix' }
Number >> complexConjugate [
"The complex conjugate of a complex number (a + bi) is another complex number (a - bi).
Every real number x is also a complex number with imaginary part equal to 0.
Expand All @@ -18,7 +18,7 @@ Number >> complexConjugate [
^ self
]

{ #category : #'*Math-Matrix' }
{ #category : '*Math-Matrix' }
Number >> productWithMatrix: aMatrix [
^aMatrix class rows: (aMatrix rowsCollect: [:r| self productWithVector: r])
]
39 changes: 20 additions & 19 deletions src/Math-Matrix/PMJacobiTransformation.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ eigenvectors := jacobi transform columnsCollect: [ :each | each].
```
"
Class {
#name : #PMJacobiTransformation,
#superclass : #Object,
#name : 'PMJacobiTransformation',
#superclass : 'Object',
#instVars : [
'precision',
'desiredPrecision',
Expand All @@ -21,30 +21,31 @@ Class {
'lowerRows',
'transform'
],
#category : #'Math-Matrix'
#category : 'Math-Matrix',
#package : 'Math-Matrix'
}

{ #category : #creation }
{ #category : 'creation' }
PMJacobiTransformation class >> matrix: aSymmetricMatrix [
^ super new initialize: aSymmetricMatrix
]

{ #category : #creation }
{ #category : 'creation' }
PMJacobiTransformation class >> new [
"Prevent using this message to create instances."

^ self error: 'Illegal creation message for this class'
]

{ #category : #accessing }
{ #category : 'accessing' }
PMJacobiTransformation >> desiredPrecision: aNumber [
"Defines the desired precision for the result."

aNumber > 0 ifFalse: [ ^ self error: 'Illegal precision: ' , aNumber printString ].
desiredPrecision := aNumber
]

{ #category : #operation }
{ #category : 'operation' }
PMJacobiTransformation >> evaluate [
"Perform the iteration until either the desired precision is attained or the number of iterations exceeds the maximum."

Expand All @@ -58,7 +59,7 @@ PMJacobiTransformation >> evaluate [
^ result
]

{ #category : #operation }
{ #category : 'operation' }
PMJacobiTransformation >> evaluateIteration [

| indices |
Expand All @@ -67,7 +68,7 @@ PMJacobiTransformation >> evaluateIteration [
^ precision
]

{ #category : #transformation }
{ #category : 'transformation' }
PMJacobiTransformation >> exchangeAt: anInteger [
"Private"

Expand All @@ -82,7 +83,7 @@ PMJacobiTransformation >> exchangeAt: anInteger [
each at: anInteger put: temp ]
]

{ #category : #operation }
{ #category : 'operation' }
PMJacobiTransformation >> finalizeIterations [
"Transfer the eigenValues into a vector and set this as the result.
eigen values and transform matrix are sorted using a bubble sort."
Expand All @@ -95,21 +96,21 @@ PMJacobiTransformation >> finalizeIterations [
self sortEigenValues
]

{ #category : #testing }
{ #category : 'testing' }
PMJacobiTransformation >> hasConverged [

^ precision <= desiredPrecision
]

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

super initialize.
desiredPrecision := Float machineEpsilon.
maximumIterations := 50
]

{ #category : #initialization }
{ #category : 'initialization' }
PMJacobiTransformation >> initialize: aSymmetricMatrix [
"Private"

Expand All @@ -125,7 +126,7 @@ PMJacobiTransformation >> initialize: aSymmetricMatrix [
yourself) ]
]

{ #category : #accessing }
{ #category : 'accessing' }
PMJacobiTransformation >> largestOffDiagonalIndices [
"Private"

Expand All @@ -143,22 +144,22 @@ PMJacobiTransformation >> largestOffDiagonalIndices [
^ Array with: m with: n
]

{ #category : #accessing }
{ #category : 'accessing' }
PMJacobiTransformation >> maximumIterations: anInteger [
"Defines the maximum number of iterations."

(anInteger isInteger and: [ anInteger > 1 ]) ifFalse: [ ^ self error: 'Invalid maximum number of iteration: ' , anInteger printString ].
maximumIterations := anInteger
]

{ #category : #printing }
{ #category : 'printing' }
PMJacobiTransformation >> printOn: aStream [
"Append to the argument aStream, a sequence of characters that describes the receiver."

lowerRows do: [ :each | each printOn: aStream ] separatedBy: [ aStream cr ]
]

{ #category : #transformation }
{ #category : 'transformation' }
PMJacobiTransformation >> sortEigenValues [
"Private - Use a bubble sort."

Expand All @@ -175,13 +176,13 @@ PMJacobiTransformation >> sortEigenValues [
bound := m ]
]

{ #category : #transformation }
{ #category : 'transformation' }
PMJacobiTransformation >> transform [

^ PMMatrix rows: transform
]

{ #category : #transformation }
{ #category : 'transformation' }
PMJacobiTransformation >> transformAt: anInteger1 and: anInteger2 [
"Private"

Expand Down
17 changes: 9 additions & 8 deletions src/Math-Matrix/PMJacobiTransformationHelper.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,29 @@
I store eigenvalues and eigenvectors of a symmetric matrix computed with PMJacobiTransformation
"
Class {
#name : #PMJacobiTransformationHelper,
#superclass : #Object,
#name : 'PMJacobiTransformationHelper',
#superclass : 'Object',
#instVars : [
'eigenvalues',
'eigenvectors'
],
#category : #'Math-Matrix'
#category : 'Math-Matrix',
#package : 'Math-Matrix'
}

{ #category : #creation }
{ #category : 'creation' }
PMJacobiTransformationHelper class >> matrix: aSymmetricMatrix [
^ super new initialize: aSymmetricMatrix
]

{ #category : #creation }
{ #category : 'creation' }
PMJacobiTransformationHelper class >> new [
"Prevent using this message to create instances."

^ self error: 'Illegal creation message for this class'
]

{ #category : #initialization }
{ #category : 'initialization' }
PMJacobiTransformationHelper >> initialize: aSymmetricMatrix [

| jacobi |
Expand All @@ -32,13 +33,13 @@ PMJacobiTransformationHelper >> initialize: aSymmetricMatrix [
eigenvectors := jacobi transform columnsCollect: [ :each | each].
]

{ #category : #accessing }
{ #category : 'accessing' }
PMJacobiTransformationHelper >> values [

^ eigenvalues
]

{ #category : #accessing }
{ #category : 'accessing' }
PMJacobiTransformationHelper >> vectors [

^ eigenvectors
Expand Down
35 changes: 18 additions & 17 deletions src/Math-Matrix/PMLUPDecomposition.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,29 @@ sol2 := s solve: #(7 10 9).
]]]
"
Class {
#name : #PMLUPDecomposition,
#superclass : #Object,
#name : 'PMLUPDecomposition',
#superclass : 'Object',
#instVars : [
'rows',
'permutation',
'parity'
],
#category : #'Math-Matrix'
#category : 'Math-Matrix',
#package : 'Math-Matrix'
}

{ #category : #creation }
{ #category : 'creation' }
PMLUPDecomposition class >> direct: anArrayOfArrays [

^ self basicNew initialize: anArrayOfArrays.
]

{ #category : #creation }
{ #category : 'creation' }
PMLUPDecomposition class >> equations: anArrayOfArrays [
^ self new initialize: (anArrayOfArrays collect: [ :each | each copy ])
]

{ #category : #private }
{ #category : 'private' }
PMLUPDecomposition >> backwardSubstitution: anArray [
"Private"
| n sum answer |
Expand All @@ -55,7 +56,7 @@ PMLUPDecomposition >> backwardSubstitution: anArray [
^answer
]

{ #category : #private }
{ #category : 'private' }
PMLUPDecomposition >> decompose [
"Private"
| n |
Expand All @@ -68,7 +69,7 @@ PMLUPDecomposition >> decompose [
].
]

{ #category : #operations }
{ #category : 'operations' }
PMLUPDecomposition >> determinant [
| n |
permutation isNil
Expand All @@ -80,7 +81,7 @@ PMLUPDecomposition >> determinant [
into: [ :det :each | n := n + 1. ( each at: n) * det ]
]

{ #category : #private }
{ #category : 'private' }
PMLUPDecomposition >> forwardSubstitution: anArray [
"Private"
| n sum answer|
Expand All @@ -95,14 +96,14 @@ PMLUPDecomposition >> forwardSubstitution: anArray [
^answer
]

{ #category : #initialization }
{ #category : 'initialization' }
PMLUPDecomposition >> initialize: anArrayOfArrays [
rows := anArrayOfArrays.
parity := 1.
^ self
]

{ #category : #operations }
{ #category : 'operations' }
PMLUPDecomposition >> inverseMatrixComponents [
| n inverseRows column |
permutation isNil
Expand All @@ -120,7 +121,7 @@ PMLUPDecomposition >> inverseMatrixComponents [
^inverseRows
]

{ #category : #operations }
{ #category : 'operations' }
PMLUPDecomposition >> largestPivotFrom: anInteger [
"Private - Answers the largest pivot element in column anInteger, from position anInteger upward."
| valueOfMaximum indexOfMaximum value |
Expand All @@ -136,7 +137,7 @@ PMLUPDecomposition >> largestPivotFrom: anInteger [
^ indexOfMaximum
]

{ #category : #private }
{ #category : 'private' }
PMLUPDecomposition >> pivotAt: anInteger [
"Private"
| inversePivot size k |
Expand All @@ -153,7 +154,7 @@ PMLUPDecomposition >> pivotAt: anInteger [
].
]

{ #category : #printing }
{ #category : 'printing' }
PMLUPDecomposition >> printOn: aStream [

| delimitingString |
Expand All @@ -170,13 +171,13 @@ PMLUPDecomposition >> printOn: aStream [
separatedBy: [ aStream cr ]
]

{ #category : #private }
{ #category : 'private' }
PMLUPDecomposition >> protectedDecomposition [
"Private - If decomposition fails, set permutation to 0."
[ self decompose] on: Error do: [ :signal | permutation := 0. signal return: nil].
]

{ #category : #private }
{ #category : 'private' }
PMLUPDecomposition >> solve: anArrayOrVector [
permutation isNil
ifTrue: [ self protectedDecomposition ].
Expand All @@ -186,7 +187,7 @@ PMLUPDecomposition >> solve: anArrayOrVector [
[self backwardSubstitution: ( self forwardSubstitution: anArrayOrVector)] on: ZeroDivide do: [:e| nil] ]
]

{ #category : #private }
{ #category : 'private' }
PMLUPDecomposition >> swapRow: anInteger1 withRow: anInteger2 [
"Private - Swap the rows indexed by the given integers."
| swappedRow |
Expand Down
Loading