private void process ( double [ ] data , double min , double max , KernelDensityFunction kernel , int window , double epsilon ) { dens = new double [ data . length ] ; var = new double [ data . length ] ; // This is the desired bandwidth of the kernel. double halfwidth = ( ( max - min ) / window ) * .5 ; for ( int current = 0 ; current < data . length ; current ++ ) { double value = 0.0 ; for ( int i = current ; i >= 0 ; i -- ) { double delta = Math . abs ( data [ i ] - data [ current ] ) / halfwidth ; final double contrib = kernel . density ( delta ) ; value += contrib ; if ( contrib < epsilon ) { break ; } } for ( int i = current + 1 ; i < data . length ; i ++ ) { double delta = Math . abs ( data [ i ] - data [ current ] ) / halfwidth ; final double contrib = kernel . density ( delta ) ; value += contrib ; if ( contrib < epsilon ) { break ; } } double realwidth = ( Math . min ( data [ current ] + halfwidth , max ) - Math . max ( min , data [ current ] - halfwidth ) ) ; double weight = realwidth / ( 2 * halfwidth ) ; dens [ current ] = value / ( data . length * realwidth * .5 ) ; var [ current ] = 1 / weight ; } }
Process a new array