Диссертация (1137066), страница 16
Текст из файла (страница 16)
d a t a ) )K<− l e n g t h ( c o n c e p t . s e t )v a r s<−neg . d a t a [ g , ]p e r e s e k<−r b i n d ( v a r s , v a r s _new )s e p<−Reduce ( f = rbind , l a p p l y ( names ( v a r s ) , f u n c t i o n ( v ) c ( min ( p e r e s e k [ [ v ] ] ) , max (peresek [[ v ] ] ) ) ) )wi<−d a t a . frame ( low . b o r d e r = s e p [ , 1 ] , h i g h . b o r d e r = s e p [ , 2 ] )# i f ( n c o l ( wi ) ! = 2 ) { p r i n t ( wi )#print ( i )#print (g)#p r i n t ( gnew )#}names ( wi )<−c ( " low .
b o r d e r " , " h i g h . b o r d e r " )row . names ( wi )<−names ( v a r s )pos . image<−what . e x t e n t ( d a t a = pos . data , b o r d e r . frame = wi )i f ( l e n g t h ( pos . image ) <= a l p h a ∗nrow ( pos . d a t a ) ) {neg . image<−what . e x t e n t ( d a t a = neg . data , b o r d e r . frame = wi )c o n c e p t . s e t [K+ 1 ]<− l i s t ( l i s t ( I d =row .
names ( unknown . d a t a ) [ gnew ] ,Rownumber=gnew ,Type= " N e g a t i v e " ,E x t e n t =c ( row . names ( neg . d a t a ) [ neg . image ] , row .names ( unknown . d a t a ) [ gnew ] ) ,E x t e n t _ i n d e x = l i s t ( neg . image= neg . image , gnew=gnew),92I n t e n t =wi ,Alpha = l e n g t h ( pos . image ) / nrow ( pos . d a t a ) ) )}}# }i f ( length ( concept . set ) ) {i f ( ! ( v o t i n g%i n%c ( " c o u n t " , " u n i q u e " , " p e r i m " , " p e r i m w i t h c o u n t " ) ) ) {warning ( p a s t e 0 ( " v o t i n g was ’ " , v o t i n g , " ’ o u t o f known v a l u e s : r e p l a c e d w i t h’ count ’ " ) )v o t i n g<−" c o u n t " }i f ( v o t i n g == " c o u n t " ) {p .
c n t<−0n . c n t<−0f o r ( i i n 1 : l e n g t h ( c o n c e p t . s e t ) ) { x<− c o n c e p t . s e t [ [ i ] ]i f ( x$ Type== " P o s i t i v e " ) {p . c n t<−p . c n t + ( l e n g t h ( x$ E x t e n t ) −1)∗ i f e l s e ( w e i g h t . a l p h a ,1 − x$ Alpha , 1 )}else {n . c n t<−n .
c n t + ( l e n g t h ( x$ E x t e n t ) −1)∗ i f e l s e ( w e i g h t . a l p h a ,1 − x$ Alpha , 1 )}}}else {i f ( v o t i n g == " u n i q u e " ) {p . s e t<−c h a r a c t e r ( 0 )n . s e t<−c h a r a c t e r ( 0 )f o r ( i i n 1 : l e n g t h ( c o n c e p t . s e t ) ) { x<− c o n c e p t . s e t [ [ i ] ]i f ( x $ Type== " P o s i t i v e " ) {p .
s e t<−union ( p . s e t , x $ E x t e n t [ − 1 ] )}else {n . s e t<−union ( n . s e t , x $ E x t e n t [ − 1 ] )}p . c n t<− l e n g t h ( unique ( p . s e t ) )n . c n t<− l e n g t h ( unique ( n . s e t ) )}}else {93i f ( v o t i n g == " p e r i m " ) {p . c n t<−0n . c n t<−0f o r ( i i n 1 : l e n g t h ( c o n c e p t .
s e t ) ) { x<− c o n c e p t . s e t [ [ i ] ]i f ( x$ Type== " P o s i t i v e " ) {p . c n t<−p . c n t + w e i g h t e n ( x $ I n t e n t ) ∗ i f e l s e ( w e i g h t . a l p h a ,1 − x $ Alpha , 1 )}else {n . c n t<−n . c n t + w e i g h t e n ( x $ I n t e n t ) ∗ i f e l s e ( w e i g h t .
a l p h a ,1 − x $ Alpha , 1 )}}}else {# i f ( v o t i n g ==" p e r i m w i t h c o u n t " ) {p . c n t<−0n . c n t<−0f o r ( i i n 1 : l e n g t h ( c o n c e p t . s e t ) ) { x<− c o n c e p t . s e t [ [ i ] ]i f ( x$ Type== " P o s i t i v e " ) {p . c n t<−p . c n t + w e i g h t e n ( x $ I n t e n t ) ∗ ( l e n g t h ( x$ E x t e n t ) −1)∗ i f e l s e ( w e i g h t .a l p h a ,1 − x$ Alpha , 1 )}else {n . c n t<−n .
c n t + w e i g h t e n ( x $ I n t e n t ) ∗ ( l e n g t h ( x$ E x t e n t ) −1)∗ i f e l s e ( w e i g h t .a l p h a ,1 − x$ Alpha , 1 )}}#}}}# c ( p . cnt , n . cnt )}}else {p . c n t<−NAn . c n t<−NA}l i s t ( c o n c e p t . s e t , d a t a . frame ( i d =row . names ( unknown . d a t a ) [ gnew ] , v o t i n g = v o t i n g ,w e i g h t . a l p h a = w e i g h t . a l p h a , p . c n t =p . c n t , n . c n t =n . c n t , margin=p . c n t −n . c n t , n .
row .neg =nrow ( neg . d a t a ) , n . row . pos =nrow ( pos . d a t a ) , sum ( u n l i s t ( l a p p l y ( c o n c e p t . s e t ,f u n c t i o n ( x ) x$ Type== " P o s i t i v e " ) ) ) , sum ( u n l i s t ( l a p p l y ( c o n c e p t . s e t , f u n c t i o n ( x ) x94$ Type== " N e g a t i v e " ) ) ) ) )}l a z i f i e r <− f u n c t i o n ( s u b s a m p l e . s i z e , num_ i t e r , a l p h a , v o t i n g = " p e r i m w i t h c o u n t " ,w e i g h t . a l p h a =FALSE ) {p r e d . m a t r i x<−d a t a . frame ( i d = " 1234567890 " , v o t i n g = " h a h a h a " , w e i g h t .
a l p h a =FALSE , p .c n t =0 , n . c n t =0 , margin =0 , nrow . neg =0 , nrow . pos =0 , c n t . pos . h y p o s =0 , c n t . neg . h y p o s=0 , s t r i n g s A s F a c t o r s = FALSE ) [ − 1 , ]f o r ( i i n 1 : nrow ( . G l o b a l E n v $ t e s t . d a t a ) ) {l p<− l a z y . p r e d i c t ( gnew = i , unknown . d a t a = . G l o b a l E n v $ t e s t . d a t a [ , rem ( names ( t e s t. d a t a ) , . G l o b a l E n v $ t a r g e t ) ] , pos .
d a t a = pos . d a t a [ , rem ( names ( pos . d a t a ) , .G l o b a l E n v $ t a r g e t ) ] , neg . d a t a = neg . d a t a [ , rem ( names ( neg . d a t a ) , . G l o b a l E n v $t a r g e t ) ] , s u b s a m p l e . s i z e = s u b s a m p l e . s i z e , num_ i t e r s = num_ i t e r , a l p h a = a l p h a ,voting =voting , weight . alpha=weight . alpha )p r e d . m a t r i x [ nrow ( p r e d . m a t r i x ) + 1 , ]<− l p [ [ 2 ] ]}p r e d . m a t r i x $ t a r g e t <− . G l o b a l E n v $ t e s t .
d a t a [ , . G l o b a l E n v $ t a r g e t ]g i n i . t a b l e [ nrow ( g i n i . t a b l e ) + 1 , ] <<−c ( s u b s a m p l e . s i z e ,num_ i t e r ,# r o c ( x=−p r e d . m a t r i x $ margin , t a r g e t =p r e d .matrix $ target ) $ gini ,g i n i . c a l c ( x=−p r e d . m a t r i x $ margin , y = p r e d .m a t r i x $ t a r g e t ) $AR,mean ( p r e d .
m a t r i x $ c n t . pos . h y p o s ) ,mean ( p r e d . m a t r i x $ c n t . neg . h y p o s ) ,sum ( p r e d . m a t r i x $ c n t . neg . h y p o s ==0 & p r e d .m a t r i x $ c n t . pos . h y p o s ==0) / nrow ( p r e d .matrix ) ,alpha . t h r e s h o l d =alpha ,voting=voting ,weight . alpha=weight .
alpha )l o o k . l p <<− l pp r i n t ( c ( s u b s a m p l e . s i z e , num_ i t e r , a l p h a , v o t i n g , w e i g h t . a l p h a , a s . c h a r a c t e r ( Sys. time ( ) ) ) )}95what . i n t e n t <− f u n c t i o n ( data , o b j e c t s ) {# d a t a<−d# o b j e c t s <−c ( 1 : 1 0 )# d a t a<−a s . d a t a . f r a m e ( d a t a )# o b j e c t s <− a s .
n u m e r i c ( o b j e c t s )# N o t e t h a t by t h i s l i n e we a l s o e x c l u d e o b j e c t s w i t h NAs i n t h e d a t a# o b j e c t s <− l i k e . o b j e c t s ( d a t a , o b j e c t s )i f ( l e n g t h ( o b j e c t s ) ==0) { warning ( " L i s t o f o b j e c t s a f t e r a l l t h e c h e c k s r e s u l t e di n empty s e t : ( " )stop }s e p .
rows <<− l a p p l y ( o b j e c t s , f u n c t i o n ( i ) u n l i s t ( d a t a [ i , ] ) )#NB ! ! ! ! T h i s pmax and pmin f u c n t i o n s can be e x p e n s i v e ! ! P r o b a b l y b e t t e r t o u s ef o r −l o o p sd a t a . frame ( low .
b o r d e r = do . c a l l ( pmin , s e p . rows ) ,h i g h . b o r d e r =do . c a l l ( pmax , s e p . rows ) ) # v a r . name=names ( d a t a )}# F i n d s t h e IMAGE o f t h e PATTERN b o r d e r . f r a m ewhat . e x t e n t <− f u n c t i o n ( data , b o r d e r . frame ) {b o r d e r . frame<−a s . d a t a . frame ( b o r d e r . frame )# i f ( ! l i k e . border . frame ( data , border .
frame ) ) { s t o p }# I f any o f b o r d e r s i s NA we t h i n k t h a t t h e r e i s no l i m i t a t i o n# b o r d e r . f r a m e [ i s . na ( b o r d e r . f r a m e [ , " low . b o r d e r " ] ) , " low . b o r d e r " ]<− − I n f# b o r d e r .
f r a m e [ i s . na ( b o r d e r . f r a m e [ , " h i g h . b o r d e r " ] ) , " h i g h . b o r d e r " ]<− I n f# T h i s l i n e i s j u s t t o i n i t i a l i z e what . e x t e n twhat . e x t e n t <−which ( d a t a [ , 1 ] > = b o r d e r . frame [ 1 , " low . b o r d e r " ] & d a t a [ , 1 ] < = b o r d e r .frame [ 1 , " h i g h . b o r d e r " ] )f o r ( x i n names ( d a t a ) ) {what .
e x t e n t <− i n t e r s e c t ( what . e x t e n t , which ( d a t a [ , x ] >= b o r d e r . frame [ x , " low . b o r d e r" ] & d a t a [ , x ] <= b o r d e r . frame [ x , " h i g h . b o r d e r " ] ) )}what . e x t e n t96}n o r m a l i z e<− f u n c t i o n ( s e t ) {mins<− u n l i s t ( l a p p l y ( names ( s e t ) , f u n c t i o n ( s ) min ( s e t [ [ s ] ] , na .
rm=TRUE) ) , u s e . names=TRUE)maxs<− u n l i s t ( l a p p l y ( names ( s e t ) , f u n c t i o n ( s ) max ( s e t [ [ s ] ] , na . rm=TRUE) ) , u s e . names=TRUE)r e s<−d a t a . frame ( min=mins , max=maxs , row . names=names ( s e t ) )res}w e i g h t e n<− f u n c t i o n ( b o r d e r . frame ) {i f ( ! e x i s t s ( " minmax . t a b l e " , where = 1 ) ) { s t o p ( " E r r o r i n w e i g h t e n : no ’ minmax . t a b l e ’f o u n d ! p l s , r u n ’ n o r m a l i z e ’ f u n c t i o n on i n i t i a l d a t a " ) }i f ( ! a l l ( row .
names ( b o r d e r . frame ) ==row . names ( . G l o b a l E n v $minmax . t a b l e ) ) ) { s t o p ( "E r r o r i n w e i g h t e n : row . names o f b o r d e r . f r a m e do n o t match row . names o f ’minmax . t a b l e ’ " ) }# n o r m a l i z e hypo ’ s i n t e r v a l s :b o r d e r . frame $ low .
b o r d e r<− ( b o r d e r . frame $ low . b o r d e r − . G l o b a l E n v $minmax . t a b l e $min) / ( . G l o b a l E n v $minmax . t a b l e $max − . G l o b a l E n v $minmax . t a b l e $min )b o r d e r . frame $ h i g h . b o r d e r<− ( b o r d e r . frame $ h i g h . b o r d e r − . G l o b a l E n v $minmax . t a b l e $min ) / ( . G l o b a l E n v $minmax . t a b l e $max − . G l o b a l E n v $minmax . t a b l e $min )( nrow ( b o r d e r . frame )−sum ( b o r d e r .
frame $ h i g h . b o r d e r −b o r d e r . frame $ low . b o r d e r ) ) / nrow( b o r d e r . frame )}rem<− f u n c t i o n ( v e c t o r 1 , v e c t o r 2 ) {i f ( is . null ( vector2 ) ) {vector1 }else {i f ( l e n g t h ( i n t e r s e c t ( v e c t o r 1 , v e c t o r 2 ) ) ==0) {vector1}else {v e c t o r 1 [−which ( v e c t o r 1%i n%v e c t o r 2 ) ]}}}# Launching S c r i p t :97# Get d a t ap r e p a r e . d a t a<− f u n c t i o n ( l g d . t h r e s h o l d = 0 . 5 ) {. G l o b a l E n v $ pos . smpl<−sample ( row . names ( d [ d [ , t a r g e t ] > l g d . t h r e s h o l d , ] ) , s i z e = 1 0 0 ). G l o b a l E n v $ neg .