Maximilian E. Schüle | In-Database Machine Learning 1
Chair III: Database Systems, Professorship for Data Mining and Analytics Chair XXV: Data Science and Engineering Department of Informatics Technical University of Munich
In-Database Machine Learning: Using Gradient Descent and Tensor - - PowerPoint PPT Presentation
Chair III: Database Systems, Professorship for Data Mining and Analytics Chair XXV: Data Science and Engineering Department of Informatics Technical University of Munich In-Database Machine Learning: Using Gradient Descent and Tensor Algebra
Maximilian E. Schüle | In-Database Machine Learning 1
Chair III: Database Systems, Professorship for Data Mining and Analytics Chair XXV: Data Science and Engineering Department of Informatics Technical University of Munich
Maximilian E. Schüle | In-Database Machine Learning 2
Maximilian E. Schüle | In-Database Machine Learning 3
CC BY-SA 3.0, TimothyRias https://commons.wikimedia.org/w/index.php? curid=14729540
Maximilian E. Schüle | In-Database Machine Learning 4
ma, b(rm)=a∗rm+b≈medv
lrm,medv(a,b)=(ma,b(rm)−medv)2
Maximilian E. Schüle | In-Database Machine Learning 5
CC BY-SA 3.0, TimothyRias https://commons.wikimedia.org/w/index.php? curid=14729540
Maximilian E. Schüle | In-Database Machine Learning 6
m
e l f u n c t i
m l
s f u n c t i
l mw(x)=∑
i∈m
xi∗wi≈ y lx , y(w)=(mw(x)− y)2
Maximilian E. Schüle | In-Database Machine Learning 7
G r a d i e n t D e s c e n t T r a i n i n g D a t a I n i t i a l We i g h t s
L
s F u n c t i
L a b e l l i n g
M
e l F u n c t i
T e s t D a t a C a l c u l a t e d We i g h t s
Maximilian E. Schüle | In-Database Machine Learning 8
Operator Left Pipeline λ Injected Code Right Pipeline k-Means Input Points λ
λ ( a , b ) s q r t ( ( a . x
. x ) ^ 2 + ( a . y
. y ) ^ 2 ) s e l e c t * f r
k m e a n s ( ( t a b l e p
n t s ) , λ ( a , b ) s q r t ( ( a . x
. x ) ^ 2 + ( a . y
. y ) ^ 2 ) , 2 )
Euclidean Distance
Maximilian E. Schüle | In-Database Machine Learning 9
L
s f u n c t i
M
e l f u n c t i
We i g h t s n t u p l e w i t h m a t t r i b u t e s W { [ w _ 1 , w _ 2 , … , w _ m ] } X { [ x _ 1 , x _ 2 , . . , x _ m , y ] } λ ( W , X ) ( W . w _ 1 * X . x _ 1 + . . . + X . x _ m
) ² λ ( W , X ) ( W . w _ 1 * X . x _ 1 + . . . + X . x _ m ) c r e a t e t a b l e t r a i n i n g d a t a ( x f l
t , y f l
t ) ; c r e a t e t a b l e w e i g h t s ( a f l
t , b f l
t ) ; i n s e r t i n t
r a i n i n g d a t a … i n s e r t i n t
e i g h t s … s e l e c t * f r
g r a d i e n t d e s c e n t ( – l
s f u n c t i
a s λ
x p r e s s i
λ ( d a t a , w e i g h t s ) ( w e i g h t s . a * d . x + w e i g h t s . b
. y ) ² ,
r a i n i n g s e t a n d i n i t i a l w e i g h t s ( s e l e c t x , y f r
t r a i n i n g d a t a d ) , ( s e l e c t a , b f r
w e i g h t s ) ,
e a r n i n g r a t e a n d m a x . n u m b e r
i t e r a t i
. 5 , 1 ) ; c r e a t e t a b l e t e s t d a t a ( x f l
t ) ; c r e a t e t a b l e w e i g h t s ( a f l
t , b f l
t ) ; i n s e r t i n t
r a i n i n g d a t a … i n s e r t i n t
e i g h t s … s e l e c t * f r
l a b e l i n g ( –
e l f u n c t i
a s λ
x p r e s s i
λ ( d a t a , w e i g h t s ) ( w e i g h t s . a * d . x + w e i g h t s . b ) ,
r a i n i n g s e t a n d i n i t i a l w e i g h t s ( s e l e c t x , y f r
t e s t d a t a d ) , ( s e l e c t a , b f r
w e i g h t s ) ) ; mw(x)=∑
i∈m
xi∗wi≈ y lx , y(w)=(mw(x)− y)2 w=(w1, w2,..., wm) x=( x1, x2,...,xm, y)
Maximilian E. Schüle | In-Database Machine Learning 10
m a i n s u b s u b s u b m a x . I t e r a t i
s B a t c h / S t
G D T r a i n i n g D a t a I n i t i a l We i g h t s λ m a i n s u b s u b s u b S t
h a s t i c G r a d i e n t D e s c e n t 1 . . . m a x I t e r I n i t i a l We i g h t s λ m a i n m a x . I t e r a t i
s
s u b s u b s u b S t
h a s t i c G r a d i e n t D e s c e n t B a t c h / S t
G D T r a i n i n g D a t a I n i t i a l We i g h t s λ
G r a d i e n t D e s c e n t T r a i n i n g D a t a I n i t i a l We i g h t s
L a b e l l i n g
T e s t D a t a
Maximilian E. Schüle | In-Database Machine Learning 11
m a i n s u b s u b s u b m a x . I t e r a t i
s B a t c h / S t
G D T r a i n i n g D a t a I n i t i a l We i g h t s λ m a i n s u b s u b s u b S t
h a s t i c G r a d i e n t D e s c e n t 1 . . . m a x I t e r λ m a i n m a x . I t e r a t i
s
s u b s u b s u b S t
h a s t i c G r a d i e n t D e s c e n t B a t c h / S t
G D T r a i n i n g D a t a λ
I n i t i a l We i g h t s I n i t i a l We i g h t s
Maximilian E. Schüle | In-Database Machine Learning 12
p
P l a c e h
d e r + 2 C
s t a n t * b V a r i a b l e a V a r i a b l e x P l a c e h
d e r
E x p r e s s i
T r e e .
* p
+ 1 * 1 a s e t t
x * 2 c h a i n r u l e
+ * b a x O r i g i n a l T r e e
G r a d i e n t D e s c e n t T r a i n i n g D a t a I n i t i a l We i g h t s
L
s F u n c t i
c
s u m e ( ) c
s u m e ( ) p r
u c e ( ) p r
u c e ( )
Maximilian E. Schüle | In-Database Machine Learning 13
s e l e c t ( a r r a y _ i n v e r s e ( a r r a y _ t r a n s p
e ( x ) * x ) ) * ( a r r a y _ t r a n s p
e ( x ) * y ) f r
( s e l e c t a r r a y _ a g g ( x ) x f r
( s e l e c t a r r a y [ 1 , x _ 1 , x _ 2 ] a s x f r
d a t a p
n t s ) s x ) t x , ( s e l e c t a r r a y _ a g g ( y ) y f r
( s e l e c t a r r a y [ y ] y f r
d a t a p
n t s ) s y ) t y ; w=(X ' T X ')−1 X ' T y
w=(w1, w2,..., wm) x=( x1, x2,...,xm ) T∈ℝ
I 1×...×Im=o,U ∈ℝ J1=o×...×Jn,
(t t)i1i2i3...im=ti2i1i3...im (t +s)i1i2... im=ti1i2...im+si1i 2... im si1i2...im−1 j2... jm=∑k∈[o] ti1i2...im−1kuk j2... j m y=( y1, y2,..., yn)
t
Maximilian E. Schüle | In-Database Machine Learning 14
CC BY-SA 2.0, https://flic.kr/p/sJG5
Maximilian E. Schüle | In-Database Machine Learning 15
CC BY-SA 2.0, https://flic.kr/p/sJG5
Maximilian E. Schüle | In-Database Machine Learning 16
1
1
1
2
1
3
1
4
1
5
1
6
1
−
1
1 1
1
1
2
1
3
1
4
N u m b e r
T u p l e s T i m e i n s S i m p l e l i n e a r r e g r e s s i
.
1
1
1
2
1
3
1
4
1
5
1
6
1
−1
1 1
1
1
2
1
3
1
4
N u m b e r
T u p l e s T i m e i n s Mu l t i p l e l i n e a r r e g r e s s i
.
1
1
1
2
1
3
1
4
1
5
1
6
1
−
1
1 1
1
1
2
1
3
1
4
1
5
N u m b e r
T u p l e s T i m e i n s L
i s t i c r e g r e s s i
.
R T e n s
F l
T e n s
F l
P U Ma r i a D B P S Q L H y P e r MA D l i b
Maximilian E. Schüle | In-Database Machine Learning 17
L i n . R e g .
2 4 6 8 10 T ensorFlow T ensorFlow T ensorFlow T ensorFlow Time in s Declaration Data Loading TF Session Computation
R e g .
M u l .
L i n . R e g . L i n . R e g . G D L
.
2 4 6 8 10 T ensorFlow-GPU T ensorFlow-GPU T ensorFlow-GPU T ensorFlow-GPU Time in s
L i n .
2 4 6 8 10 HyPer HyPer HyPer HyPer Time in s 2 4 6 8 10 R R R R Time in s
( a ) 1
5t
u p l e s .
R e g . R e g . G D R e g .
10 20 30 T ensorFlow T ensorFlow T ensorFlow T ensorFlow Time in s Declaration Data Loading TF Session Computation 10 20 30 T ensorFlow-GPU T ensorFlow-GPU T ensorFlow-GPU T ensorFlow-GPU Time in s 10 20 30 HyPer HyPer HyPer HyPer Time in s 10 20 30 R R R R Time in s
( b ) 1
6t
u p l e s .
L i n . L i n . L i n . R e g . L
. L i n .
Maximilian E. Schüle | In-Database Machine Learning 18
2 4 6 8 1
.4 .5 .6 .7 .8
N u m b e r
T h r e a d s
T i m e i n s m a t e r i a l i s i n g p i p e l i n e d c
b i n e d
( a ) S c a l e T e s t s .
1 1 1 2 1 3 1 4 1 5 1 6 1 − 5 1 − 4 1 − 3 1 − 2 1 − 1 1
N u m b e r
T u p l e s
T i m e i n s m a t e r i a l i s i n g p i p e l i n e d c
b i n e d
( b ) V a r y i n g t h e i n p u t s i z e .
1 1
1
1
2
1
3 1 − 2 1 − 1 1 1 1
N u m b e r
I t e r a t i
s
T i m e i n s m a t e r i a l i s i n g p i p e l i n e d c
b i n e d
( c ) V a r y i n g t h e n u m b e r
i t e r a t i
s .
Maximilian E. Schüle | In-Database Machine Learning 19
T ensorFlow T ensorFlow T ensorFlow T ensorFlow Declaration Data Loading T ensorFlow-GPU T ensorFlow-GPU T ensorFlow-GPU T ensorFlow-GPU HyPer HyPer HyPer HyPer R R R R