@@ -57,16 +57,7 @@ describe('projectron', () => {
5757
5858 test ( 'kernel polynomial' , ( ) => {
5959 const model = new Projectron ( 0.1 , 'polynomial' )
60- const s = 5
61- const x = [ ]
62- for ( let i = 0 ; i < 50 ; i ++ ) {
63- const r = ( i / 50 ) * Math . PI
64- x . push ( [ Math . cos ( r ) * s + Math . random ( ) - 0.5 , Math . sin ( r ) * s + Math . random ( ) - 0.5 ] )
65- }
66- for ( let i = 0 ; i < 50 ; i ++ ) {
67- const r = ( i / 50 ) * Math . PI
68- x . push ( [ s - Math . cos ( r ) * s + Math . random ( ) - 0.5 , s - Math . sin ( r ) * s - s / 2 + Math . random ( ) - 0.5 ] )
69- }
60+ const x = Matrix . concat ( Matrix . randn ( 50 , 2 , 0 , 0.2 ) , Matrix . randn ( 50 , 2 , 5 , 0.2 ) ) . toArray ( )
7061 const t = [ ]
7162 for ( let i = 0 ; i < x . length ; i ++ ) {
7263 t [ i ] = Math . floor ( i / 50 ) * 2 - 1
@@ -146,16 +137,7 @@ describe('projectron++', () => {
146137
147138 test ( 'kernel polynomial' , ( ) => {
148139 const model = new Projectronpp ( 0.1 , 'polynomial' )
149- const s = 5
150- const x = [ ]
151- for ( let i = 0 ; i < 50 ; i ++ ) {
152- const r = ( i / 50 ) * Math . PI
153- x . push ( [ Math . cos ( r ) * s + Math . random ( ) - 0.5 , Math . sin ( r ) * s + Math . random ( ) - 0.5 ] )
154- }
155- for ( let i = 0 ; i < 50 ; i ++ ) {
156- const r = ( i / 50 ) * Math . PI
157- x . push ( [ s - Math . cos ( r ) * s + Math . random ( ) - 0.5 , s - Math . sin ( r ) * s - s / 2 + Math . random ( ) - 0.5 ] )
158- }
140+ const x = Matrix . concat ( Matrix . randn ( 50 , 2 , 0 , 0.2 ) , Matrix . randn ( 50 , 2 , 5 , 0.2 ) ) . toArray ( )
159141 const t = [ ]
160142 for ( let i = 0 ; i < x . length ; i ++ ) {
161143 t [ i ] = Math . floor ( i / 50 ) * 2 - 1
@@ -165,7 +147,7 @@ describe('projectron++', () => {
165147 }
166148 const y = model . predict ( x )
167149 const acc = accuracy ( y , t )
168- expect ( acc ) . toBeGreaterThan ( 0.55 )
150+ expect ( acc ) . toBeGreaterThan ( 0.8 )
169151 } )
170152
171153 test ( 'custom kernel' , ( ) => {
0 commit comments