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

Issue 29 - PMVector/PMMatrix >> #dot: does not compute a dot product. #119

Merged
merged 5 commits into from
May 22, 2019
Merged
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
19 changes: 17 additions & 2 deletions src/Math-Core/PMVector.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Class {
#name : #PMVector,
#superclass : #Array,
#type : #variable,
#category : 'Math-Core'
#category : #'Math-Core'
}

{ #category : #'instance creation' }
Expand Down Expand Up @@ -167,7 +167,7 @@ PMVector >> cumsum [

]

{ #category : #operation }
{ #category : #deprecated }
PMVector >> dot: aVector [
"Answers the elementwise product of the receiver with aVector."
| answer n |
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/Math-Core/PMWeightedPoint.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Class {
'weight',
'error'
],
#category : 'Math-Core'
#category : #'Math-Core'
}

{ #category : #creation }
Expand Down
2 changes: 1 addition & 1 deletion src/Math-Matrix/PMJacobiTransformationHelper.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Class {
'eigenvalues',
'eigenvectors'
],
#category : 'Math-Matrix'
#category : #'Math-Matrix'
}

{ #category : #creation }
Expand Down
2 changes: 1 addition & 1 deletion src/Math-Matrix/PMLUPDecomposition.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Class {
'permutation',
'parity'
],
#category : 'Math-Matrix'
#category : #'Math-Matrix'
}

{ #category : #creation }
Expand Down
2 changes: 1 addition & 1 deletion src/Math-Matrix/PMLargestEigenValueFinder.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Class {
'eigenvector',
'transposeEigenvector'
],
#category : 'Math-Matrix'
#category : #'Math-Matrix'
}

{ #category : #information }
Expand Down
2 changes: 1 addition & 1 deletion src/Math-Matrix/PMLinearEquationSystem.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Class {
'rows',
'solutions'
],
#category : 'Math-Matrix'
#category : #'Math-Matrix'
}

{ #category : #creation }
Expand Down
11 changes: 8 additions & 3 deletions src/Math-Matrix/PMMatrix.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Class {
'rows',
'lupDecomposition'
],
#category : 'Math-Matrix'
#category : #'Math-Matrix'
}

{ #category : #example }
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -458,6 +458,11 @@ PMMatrix >> flattenRows [
^ answer asPMVector
]

{ #category : #operation }
PMMatrix >> hadamardProduct: aMatrix [
^ aMatrix elementwiseProductWithMatrix: self
]

{ #category : #comparing }
PMMatrix >> hash [
^ rows hash
Expand Down
2 changes: 1 addition & 1 deletion src/Math-Matrix/PMSingularMatrixError.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion src/Math-Matrix/PMSingularValueDecomposition.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Class {
'signU',
'signV'
],
#category : 'Math-Matrix'
#category : #'Math-Matrix'
}

{ #category : #'instance creation' }
Expand Down
2 changes: 1 addition & 1 deletion src/Math-Matrix/PMSymmetricMatrix.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) .
]
14 changes: 14 additions & 0 deletions src/Math-Tests-Core/PMVectorTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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 [

Expand Down
2 changes: 1 addition & 1 deletion src/Math-Tests-Matrix/PMAdditionalTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
20 changes: 18 additions & 2 deletions src/Math-Tests-Matrix/PMMatrixTest.class.st
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Class {
#name : #PMMatrixTest,
#superclass : #TestCase,
#category : 'Math-Tests-Matrix'
#category : #'Math-Tests-Matrix'
}

{ #category : #tests }
Expand Down Expand Up @@ -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 |
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/Math-Tests-Matrix/PMQRTest.class.st
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Class {
#name : #PMQRTest,
#superclass : #TestCase,
#category : 'Math-Tests-Matrix'
#category : #'Math-Tests-Matrix'
}

{ #category : #running }
Expand Down
2 changes: 1 addition & 1 deletion src/Math-Tests-Matrix/PMRestTest.class.st
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Class {
#name : #PMRestTest,
#superclass : #TestCase,
#category : 'Math-Tests-Matrix'
#category : #'Math-Tests-Matrix'
}

{ #category : #tests }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Class {
'actualV',
'actualS'
],
#category : 'Math-Tests-Matrix'
#category : #'Math-Tests-Matrix'
}

{ #category : #'as yet unclassified' }
Expand Down
2 changes: 1 addition & 1 deletion src/Math-Tests-Matrix/PMSymmetricMatrixTest.class.st
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Class {
#name : #PMSymmetricMatrixTest,
#superclass : #TestCase,
#category : 'Math-Tests-Matrix'
#category : #'Math-Tests-Matrix'
}

{ #category : #tests }
Expand Down