private double queryWork ( Vec x , Set < Integer > validIndecies , SparseVector logProd ) { if ( originalVecs == null ) throw new UntrainedModelException ( "Model has not yet been created, queries can not be perfomed" ) ; double logH = 0 ; for ( int i = 0 ; i < sortedDimVals . length ; i ++ ) { double [ ] X = sortedDimVals [ i ] ; double h = bandwidth [ i ] ; logH += log ( h ) ; double xi = x . get ( i ) ; //Only values within a certain range will have an effect on the result, so we will skip to that range! int from = Arrays . binarySearch ( X , xi - h * k . cutOff ( ) ) ; int to = Arrays . binarySearch ( X , xi + h * k . cutOff ( ) ) ; //Mostly likely the exact value of x is not in the list, so it retursn the inseration points from = from < 0 ? - from - 1 : from ; to = to < 0 ? - to - 1 : to ; Set < Integer > subIndecies = new IntSet ( ) ; for ( int j = max ( 0 , from ) ; j < min ( X . length , to + 1 ) ; j ++ ) { int trueIndex = sortedIndexVals [ i ] [ j ] ; if ( i == 0 ) { validIndecies . add ( trueIndex ) ; logProd . set ( trueIndex , log ( k . k ( ( xi - X [ j ] ) / h ) ) ) ; } else if ( validIndecies . contains ( trueIndex ) ) { logProd . increment ( trueIndex , log ( k . k ( ( xi - X [ j ] ) / h ) ) ) ; subIndecies . add ( trueIndex ) ; } } if ( i > 0 ) { validIndecies . retainAll ( subIndecies ) ; if ( validIndecies . isEmpty ( ) ) break ; } } return logH ; }
Performs the main work for performing a density query .