math.matrices: Add some combinators for iterating over matrices. Add covariance matrix.
parent
b23e52f532
commit
7906632952
|
@ -282,3 +282,35 @@ IN: math.matrices.tests
|
|||
{ 6 12 18 }
|
||||
{ 7 14 21 } }
|
||||
} [ { 5 6 7 } { 1 2 3 } outer ] unit-test
|
||||
|
||||
|
||||
CONSTANT: test-points {
|
||||
{ 80 27 89 } { 80 27 88 } { 75 25 90 }
|
||||
{ 62 24 87 } { 62 22 87 } { 62 23 87 }
|
||||
{ 62 24 93 } { 62 24 93 } { 58 23 87 }
|
||||
{ 58 18 80 } { 58 18 89 } { 58 17 88 }
|
||||
{ 58 18 82 } { 58 19 93 } { 50 18 89 }
|
||||
{ 50 18 86 } { 50 19 72 } { 50 19 79 }
|
||||
{ 50 20 80 } { 56 20 82 } { 70 20 91 }
|
||||
}
|
||||
|
||||
{
|
||||
{
|
||||
{ 84+2/35 22+23/35 24+4/7 }
|
||||
{ 22+23/35 9+104/105 6+87/140 }
|
||||
{ 24+4/7 6+87/140 28+5/7 }
|
||||
}
|
||||
} [
|
||||
test-points sample-cov-matrix
|
||||
] unit-test
|
||||
|
||||
{
|
||||
{
|
||||
{ 80+8/147 21+85/147 23+59/147 }
|
||||
{ 21+85/147 9+227/441 6+15/49 }
|
||||
{ 23+59/147 6+15/49 27+17/49 }
|
||||
}
|
||||
} [
|
||||
test-points cov-matrix
|
||||
] unit-test
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors arrays columns kernel locals math math.bits
|
||||
math.functions math.order math.vectors sequences
|
||||
sequences.private fry ;
|
||||
sequences.private fry math.statistics ;
|
||||
IN: math.matrices
|
||||
|
||||
! Matrices
|
||||
|
@ -196,3 +196,11 @@ IN: math.matrices
|
|||
|
||||
: cartesian-matrix-column-map ( m quot -- m' )
|
||||
[ cols first2 ] prepose cartesian-matrix-map ; inline
|
||||
|
||||
: cov-matrix-ddof ( m ddof -- cov )
|
||||
'[ _ cov-ddof ] cartesian-matrix-column-map ; inline
|
||||
|
||||
: cov-matrix ( m -- cov ) 0 cov-matrix-ddof ; inline
|
||||
|
||||
: sample-cov-matrix ( m -- cov ) 1 cov-matrix-ddof ; inline
|
||||
|
||||
|
|
Loading…
Reference in New Issue