diff --git a/src/Math-Core/PMVector.class.st b/src/Math-Core/PMVector.class.st index 2786e4288..9a015f0ee 100644 --- a/src/Math-Core/PMVector.class.st +++ b/src/Math-Core/PMVector.class.st @@ -20,7 +20,7 @@ Class { #name : #PMVector, #superclass : #Array, #type : #variable, - #category : 'Math-Core' + #category : #'Math-Core' } { #category : #'instance creation' } @@ -167,7 +167,7 @@ PMVector >> cumsum [ ] -{ #category : #operation } +{ #category : #deprecated } PMVector >> dot: aVector [ "Answers the elementwise product of the receiver with aVector." | answer n | @@ -182,6 +182,21 @@ PMVector >> dot: aVector [ ] +{ #category : #operation } +PMVector >> hadamardProduct: aVector [ + "Answers the elementwise product of the receiver with aVector." + + | answer n | + answer := self class new: self size. + n := 0. + self + with: aVector + do: [ :a :b | + n := n + 1. + answer at: n put: a * b ]. + ^ answer +] + { #category : #'as yet unclassified' } PMVector >> householder [ "returns a collection of the skalar beta and the housholder vector" diff --git a/src/Math-Core/PMWeightedPoint.class.st b/src/Math-Core/PMWeightedPoint.class.st index a7beea989..68a6f6146 100644 --- a/src/Math-Core/PMWeightedPoint.class.st +++ b/src/Math-Core/PMWeightedPoint.class.st @@ -12,7 +12,7 @@ Class { 'weight', 'error' ], - #category : 'Math-Core' + #category : #'Math-Core' } { #category : #creation } diff --git a/src/Math-Matrix/PMJacobiTransformationHelper.class.st b/src/Math-Matrix/PMJacobiTransformationHelper.class.st index be6f6f9ce..7675cc075 100644 --- a/src/Math-Matrix/PMJacobiTransformationHelper.class.st +++ b/src/Math-Matrix/PMJacobiTransformationHelper.class.st @@ -8,7 +8,7 @@ Class { 'eigenvalues', 'eigenvectors' ], - #category : 'Math-Matrix' + #category : #'Math-Matrix' } { #category : #creation } diff --git a/src/Math-Matrix/PMLUPDecomposition.class.st b/src/Math-Matrix/PMLUPDecomposition.class.st index 75dbe790d..fe6392d72 100644 --- a/src/Math-Matrix/PMLUPDecomposition.class.st +++ b/src/Math-Matrix/PMLUPDecomposition.class.st @@ -26,7 +26,7 @@ Class { 'permutation', 'parity' ], - #category : 'Math-Matrix' + #category : #'Math-Matrix' } { #category : #creation } diff --git a/src/Math-Matrix/PMLargestEigenValueFinder.class.st b/src/Math-Matrix/PMLargestEigenValueFinder.class.st index 06dfac388..81478c9ab 100644 --- a/src/Math-Matrix/PMLargestEigenValueFinder.class.st +++ b/src/Math-Matrix/PMLargestEigenValueFinder.class.st @@ -20,7 +20,7 @@ Class { 'eigenvector', 'transposeEigenvector' ], - #category : 'Math-Matrix' + #category : #'Math-Matrix' } { #category : #information } diff --git a/src/Math-Matrix/PMLinearEquationSystem.class.st b/src/Math-Matrix/PMLinearEquationSystem.class.st index 8b021c459..3e5b8e3b6 100644 --- a/src/Math-Matrix/PMLinearEquationSystem.class.st +++ b/src/Math-Matrix/PMLinearEquationSystem.class.st @@ -22,7 +22,7 @@ Class { 'rows', 'solutions' ], - #category : 'Math-Matrix' + #category : #'Math-Matrix' } { #category : #creation } diff --git a/src/Math-Matrix/PMMatrix.class.st b/src/Math-Matrix/PMMatrix.class.st index c3547d753..900d3f209 100644 --- a/src/Math-Matrix/PMMatrix.class.st +++ b/src/Math-Matrix/PMMatrix.class.st @@ -15,7 +15,7 @@ Class { 'rows', 'lupDecomposition' ], - #category : 'Math-Matrix' + #category : #'Math-Matrix' } { #category : #example } @@ -31,7 +31,7 @@ b := PMMatrix rows: #( ( 1 2 3 ) (-2 1 7)). c := a * b. "Elementwise matrix product" -d := a dot:b. +d := a hadamardProduct: b. "This is how we can create a vector" a := #(1 4 9 16 25) asPMVector. @@ -407,7 +407,7 @@ PMMatrix >> dimension [ ^ self rows size @ (self rows at: 1) size ] -{ #category : #operation } +{ #category : #deprecated } PMMatrix >> dot: aMatrix [ "Answers the elementwise product of the receiver with aMatrix." ^ aMatrix elementwiseProductWithMatrix: self @@ -458,6 +458,11 @@ PMMatrix >> flattenRows [ ^ answer asPMVector ] +{ #category : #operation } +PMMatrix >> hadamardProduct: aMatrix [ + ^ aMatrix elementwiseProductWithMatrix: self +] + { #category : #comparing } PMMatrix >> hash [ ^ rows hash diff --git a/src/Math-Matrix/PMSingularMatrixError.class.st b/src/Math-Matrix/PMSingularMatrixError.class.st index 6bf7cc4d7..6aa9392a8 100644 --- a/src/Math-Matrix/PMSingularMatrixError.class.st +++ b/src/Math-Matrix/PMSingularMatrixError.class.st @@ -5,7 +5,7 @@ some calculations dont work with singular matrices and result eg with errors lik Class { #name : #PMSingularMatrixError, #superclass : #ArithmeticError, - #category : 'Math-Matrix' + #category : #'Math-Matrix' } { #category : #accessing } diff --git a/src/Math-Matrix/PMSingularValueDecomposition.class.st b/src/Math-Matrix/PMSingularValueDecomposition.class.st index 9753ef804..65a2723e3 100644 --- a/src/Math-Matrix/PMSingularValueDecomposition.class.st +++ b/src/Math-Matrix/PMSingularValueDecomposition.class.st @@ -40,7 +40,7 @@ Class { 'signU', 'signV' ], - #category : 'Math-Matrix' + #category : #'Math-Matrix' } { #category : #'instance creation' } diff --git a/src/Math-Matrix/PMSymmetricMatrix.class.st b/src/Math-Matrix/PMSymmetricMatrix.class.st index fbfce867b..2e8a34764 100644 --- a/src/Math-Matrix/PMSymmetricMatrix.class.st +++ b/src/Math-Matrix/PMSymmetricMatrix.class.st @@ -4,7 +4,7 @@ This class can be instantiated like DhbMatrix via #rows:, but the user has to ma Class { #name : #PMSymmetricMatrix, #superclass : #PMMatrix, - #category : 'Math-Matrix' + #category : #'Math-Matrix' } { #category : #'instance creation' } diff --git a/src/Math-PrincipalComponentAnalysis/PMSciKitLearnSVDFlipAlgorithm.class.st b/src/Math-PrincipalComponentAnalysis/PMSciKitLearnSVDFlipAlgorithm.class.st index 44f7ceeeb..1edaf980a 100644 --- a/src/Math-PrincipalComponentAnalysis/PMSciKitLearnSVDFlipAlgorithm.class.st +++ b/src/Math-PrincipalComponentAnalysis/PMSciKitLearnSVDFlipAlgorithm.class.st @@ -78,10 +78,10 @@ PMSciKitLearnSVDFlipAlgorithm >> signs [ { #category : #accessing } PMSciKitLearnSVDFlipAlgorithm >> uFlipped [ - ^ u dot: (self signMatrixForU). + ^ u hadamardProduct: (self signMatrixForU). ] { #category : #accessing } PMSciKitLearnSVDFlipAlgorithm >> vFlipped [ - ^ v dot: (self signMatrixForV) . + ^ v hadamardProduct: (self signMatrixForV) . ] diff --git a/src/Math-Tests-Core/PMVectorTest.class.st b/src/Math-Tests-Core/PMVectorTest.class.st index 84afe11c0..082e82fe0 100644 --- a/src/Math-Tests-Core/PMVectorTest.class.st +++ b/src/Math-Tests-Core/PMVectorTest.class.st @@ -164,6 +164,20 @@ PMVectorTest >> testVectorGreater [ ] +{ #category : #tests } +PMVectorTest >> testVectorHadamardProduct [ + "Code Example 8.1" + + | u v w | + u := #(1 2 3) asPMVector. + v := #(3 4 5) asPMVector. + w := u hadamardProduct: v. + self assert: (w size) equals: 3. + self assert: (w at: 1) equals: 3. + self assert: (w at: 2) equals: 8. + self assert: (w at: 3) equals: 15 +] + { #category : #tests } PMVectorTest >> testVectorLess [ diff --git a/src/Math-Tests-Matrix/PMAdditionalTest.class.st b/src/Math-Tests-Matrix/PMAdditionalTest.class.st index eea0c4266..8b32fa46b 100644 --- a/src/Math-Tests-Matrix/PMAdditionalTest.class.st +++ b/src/Math-Tests-Matrix/PMAdditionalTest.class.st @@ -5,7 +5,7 @@ here are tests that would be in Math-Tests-DHB-Numerical, if it could construct Class { #name : #PMAdditionalTest, #superclass : #TestCase, - #category : 'Math-Tests-Matrix' + #category : #'Math-Tests-Matrix' } { #category : #tests } diff --git a/src/Math-Tests-Matrix/PMMatrixTest.class.st b/src/Math-Tests-Matrix/PMMatrixTest.class.st index 2c065d7bd..b27b24464 100644 --- a/src/Math-Tests-Matrix/PMMatrixTest.class.st +++ b/src/Math-Tests-Matrix/PMMatrixTest.class.st @@ -1,7 +1,7 @@ Class { #name : #PMMatrixTest, #superclass : #TestCase, - #category : 'Math-Tests-Matrix' + #category : #'Math-Tests-Matrix' } { #category : #tests } @@ -352,6 +352,22 @@ PMMatrixTest >> testMatrixGreater [ self assert: ((b rowAt: 2) at: 3) equals: true ] +{ #category : #'linear algebra' } +PMMatrixTest >> testMatrixHadamardProduct [ + | a b c | + a := PMMatrix rows: #(#(1 0 1) #(-1 -2 3)). + b := PMMatrix rows: #(#(1 2 3) #(-2 1 7)). + c := a hadamardProduct: b. + self assert: c numberOfRows equals: 2. + self assert: c numberOfColumns equals: 3. + self assert: ((c rowAt: 1) at: 1) equals: 1. + self assert: ((c rowAt: 1) at: 2) equals: 0. + self assert: ((c rowAt: 1) at: 3) equals: 3. + self assert: ((c rowAt: 2) at: 1) equals: 2. + self assert: ((c rowAt: 2) at: 2) equals: -2. + self assert: ((c rowAt: 2) at: 3) equals: 21 +] + { #category : #comparing } PMMatrixTest >> testMatrixHash [ | a b c | @@ -428,7 +444,7 @@ PMMatrixTest >> testMatrixMultiplyElementwise [ | a b c | a := PMMatrix rows: #(#(1 0 1) #(-1 -2 3)). b := PMMatrix rows: #(#(1 2 3) #(-2 1 7)). - c := a dot:b. + c := a dot: b. self assert: c numberOfRows equals: 2. self assert: c numberOfColumns equals: 3. self assert: ((c rowAt: 1) at: 1) equals: 1. diff --git a/src/Math-Tests-Matrix/PMQRTest.class.st b/src/Math-Tests-Matrix/PMQRTest.class.st index 6f8a23303..930267b70 100644 --- a/src/Math-Tests-Matrix/PMQRTest.class.st +++ b/src/Math-Tests-Matrix/PMQRTest.class.st @@ -1,7 +1,7 @@ Class { #name : #PMQRTest, #superclass : #TestCase, - #category : 'Math-Tests-Matrix' + #category : #'Math-Tests-Matrix' } { #category : #running } diff --git a/src/Math-Tests-Matrix/PMRestTest.class.st b/src/Math-Tests-Matrix/PMRestTest.class.st index d4db439f1..667530dd8 100644 --- a/src/Math-Tests-Matrix/PMRestTest.class.st +++ b/src/Math-Tests-Matrix/PMRestTest.class.st @@ -1,7 +1,7 @@ Class { #name : #PMRestTest, #superclass : #TestCase, - #category : 'Math-Tests-Matrix' + #category : #'Math-Tests-Matrix' } { #category : #tests } diff --git a/src/Math-Tests-Matrix/PMSingularValueDecompositionTest.class.st b/src/Math-Tests-Matrix/PMSingularValueDecompositionTest.class.st index d3f6d1b79..43e06794e 100644 --- a/src/Math-Tests-Matrix/PMSingularValueDecompositionTest.class.st +++ b/src/Math-Tests-Matrix/PMSingularValueDecompositionTest.class.st @@ -35,7 +35,7 @@ Class { 'actualV', 'actualS' ], - #category : 'Math-Tests-Matrix' + #category : #'Math-Tests-Matrix' } { #category : #'as yet unclassified' } diff --git a/src/Math-Tests-Matrix/PMSymmetricMatrixTest.class.st b/src/Math-Tests-Matrix/PMSymmetricMatrixTest.class.st index 0d6ad00be..f0a1e2870 100644 --- a/src/Math-Tests-Matrix/PMSymmetricMatrixTest.class.st +++ b/src/Math-Tests-Matrix/PMSymmetricMatrixTest.class.st @@ -1,7 +1,7 @@ Class { #name : #PMSymmetricMatrixTest, #superclass : #TestCase, - #category : 'Math-Tests-Matrix' + #category : #'Math-Tests-Matrix' } { #category : #tests }