idx int64 0 165k | question stringlengths 73 5.81k | target stringlengths 5 918 |
|---|---|---|
122,500 | public static PolynomialRoots createRootFinder ( RootFinderType type , int maxDegree ) { switch ( type ) { case EVD : return new RootFinderCompanion ( ) ; case STURM : FindRealRootsSturm sturm = new FindRealRootsSturm ( maxDegree , - 1 , 1e-10 , 30 , 20 ) ; return new WrapRealRootsSturm ( sturm ) ; } throw new IllegalA... | Creates a generic polynomial root finding class which will return all real or all real and complex roots depending on the algorithm selected . |
122,501 | public T grow ( ) { if ( size >= data . length ) { T a = createInstance ( ) ; add ( a ) ; return a ; } else { T a = data [ ( start + size ) % data . length ] ; if ( a == null ) { data [ ( start + size ) % data . length ] = a = createInstance ( ) ; } size ++ ; return a ; } } | Adds a new element to the end of the list and returns it . If the inner array isn t large enough then it will grow . |
122,502 | public T growW ( ) { T a ; if ( size >= data . length ) { a = data [ start ] ; if ( a == null ) data [ start ] = a = createInstance ( ) ; start = ( start + 1 ) % data . length ; } else { a = data [ ( start + size ) % data . length ] ; if ( a == null ) data [ ( start + size ) % data . length ] = a = createInstance ( ) ;... | Adds a new element to the end of the list and returns it . If the inner array isn t large enough then the oldest element will be written over . |
122,503 | public void initialize ( double [ ] initial , int numberOfParameters , double minimumFunctionValue ) { super . initialize ( initial , numberOfParameters , minimumFunctionValue ) ; y . reshape ( numberOfParameters , 1 ) ; xPrevious . reshape ( numberOfParameters , 1 ) ; x . reshape ( numberOfParameters , 1 ) ; gradientP... | Override parent to initialize matrices |
122,504 | protected boolean wolfeCondition ( DMatrixRMaj s , DMatrixRMaj y , DMatrixRMaj g_k ) { double left = CommonOps_DDRM . dot ( y , s ) ; double g_s = CommonOps_DDRM . dot ( g_k , s ) ; double right = ( c2 - 1 ) * g_s ; if ( left >= right ) { return ( fx - f_prev ) <= c1 * g_s ; } return false ; } | Indicates if there s sufficient decrease and curvature . If the Wolfe condition is meet then the Hessian will be positive definite . |
122,505 | public void reset ( ) { Element e = first ; while ( e != null ) { Element n = e . next ; e . clear ( ) ; available . add ( e ) ; e = n ; } first = last = null ; size = 0 ; } | Puts the linked list back into its initial state . Elements are saved for later use . |
122,506 | public Element < T > getElement ( int index , boolean fromFront ) { if ( index > size || index < 0 ) { throw new IllegalArgumentException ( "index is out of bounds" ) ; } if ( fromFront ) { Element < T > e = first ; for ( int i = 0 ; i < index ; i ++ ) { e = e . next ; } return e ; } else { Element < T > e = last ; for... | Returns the N th element when counting from the from or from the back |
122,507 | public Element < T > pushHead ( T object ) { Element < T > e = requestNew ( ) ; e . object = object ; if ( first == null ) { first = last = e ; } else { e . next = first ; first . previous = e ; first = e ; } size ++ ; return e ; } | Adds the element to the front of the list . |
122,508 | public Element < T > pushTail ( T object ) { Element < T > e = requestNew ( ) ; e . object = object ; if ( last == null ) { first = last = e ; } else { e . previous = last ; last . next = e ; last = e ; } size ++ ; return e ; } | Adds the element to the back of the list . |
122,509 | public Element < T > insertAfter ( Element < T > previous , T object ) { Element < T > e = requestNew ( ) ; e . object = object ; e . previous = previous ; e . next = previous . next ; if ( e . next != null ) { e . next . previous = e ; } else { last = e ; } previous . next = e ; size ++ ; return e ; } | Inserts the object into a new element after the provided element . |
122,510 | public Element < T > insertBefore ( Element < T > next , T object ) { Element < T > e = requestNew ( ) ; e . object = object ; e . previous = next . previous ; e . next = next ; if ( e . previous != null ) { e . previous . next = e ; } else { first = e ; } next . previous = e ; size ++ ; return e ; } | Inserts the object into a new element before the provided element . |
122,511 | public void swap ( Element < T > a , Element < T > b ) { if ( a . next == b ) { if ( a . previous != null ) { a . previous . next = b ; } if ( b . next != null ) { b . next . previous = a ; } Element < T > tmp = a . previous ; a . previous = b ; a . next = b . next ; b . previous = tmp ; b . next = a ; if ( first == a ... | Swaps the location of the two elements |
122,512 | public void remove ( Element < T > element ) { if ( element . next == null ) { last = element . previous ; } else { element . next . previous = element . previous ; } if ( element . previous == null ) { first = element . next ; } else { element . previous . next = element . next ; } size -- ; element . clear ( ) ; avai... | Removes the element from the list and saves the element data structure for later reuse . |
122,513 | public T removeHead ( ) { if ( first == null ) throw new IllegalArgumentException ( "Empty list" ) ; T ret = first . getObject ( ) ; Element < T > e = first ; available . push ( first ) ; if ( first . next != null ) { first . next . previous = null ; first = first . next ; } else { first = last = null ; } e . clear ( )... | Removes the first element from the list |
122,514 | public Object removeTail ( ) { if ( last == null ) throw new IllegalArgumentException ( "Empty list" ) ; Object ret = last . getObject ( ) ; Element < T > e = last ; available . add ( last ) ; if ( last . previous != null ) { last . previous . next = null ; last = last . previous ; } else { first = last = null ; } e . ... | Removes the last element from the list |
122,515 | public Element < T > find ( T object ) { Element < T > e = first ; while ( e != null ) { if ( e . object == object ) { return e ; } e = e . next ; } return null ; } | Returns the first element which contains object starting from the head . |
122,516 | public void addAll ( List < T > list ) { if ( list . isEmpty ( ) ) return ; Element < T > a = requestNew ( ) ; a . object = list . get ( 0 ) ; if ( first == null ) { first = a ; } else if ( last != null ) { last . next = a ; a . previous = last ; } for ( int i = 1 ; i < list . size ( ) ; i ++ ) { Element < T > b = requ... | Add all elements in list into this linked list |
122,517 | public void addAll ( T [ ] array , int first , int length ) { if ( length <= 0 ) return ; Element < T > a = requestNew ( ) ; a . object = array [ first ] ; if ( this . first == null ) { this . first = a ; } else if ( last != null ) { last . next = a ; a . previous = last ; } for ( int i = 1 ; i < length ; i ++ ) { Elem... | Adds the specified elements from array into this list |
122,518 | public void addMean ( double [ ] point , double responsibility ) { for ( int i = 0 ; i < mean . numRows ; i ++ ) { mean . data [ i ] += responsibility * point [ i ] ; } weight += responsibility ; } | Helper function for computing Gaussian parameters . Adds the point to mean and weight . |
122,519 | public void addCovariance ( double [ ] difference , double responsibility ) { int N = mean . numRows ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = i ; j < N ; j ++ ) { covariance . data [ i * N + j ] += responsibility * difference [ i ] * difference [ j ] ; } } for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; ... | Helper function for computing Gaussian parameters . Adds the difference between point and mean to covariance adjusted by the weight . |
122,520 | public static GrowQueue_B zeros ( int length ) { GrowQueue_B out = new GrowQueue_B ( length ) ; out . size = length ; return out ; } | Creates a queue with the specified length as its size filled with false |
122,521 | public static int findMaxIndex ( int [ ] a ) { int max = a [ 0 ] ; int index = 0 ; for ( int i = 1 ; i < a . length ; i ++ ) { int val = a [ i ] ; if ( val > max ) { max = val ; index = i ; } } return index ; } | Finds the index in a with the largest value . |
122,522 | public void reset ( ) { unusedEdges . addAll ( usedEdges ) ; unusedNodes . addAll ( usedNodes ) ; usedEdges . clear ( ) ; usedNodes . clear ( ) ; } | Takes all the used nodes and makes them unused . |
122,523 | public void resetHard ( ) { for ( int i = 0 ; i < usedEdges . size ( ) ; i ++ ) { Edge < N , E > e = usedEdges . get ( i ) ; e . data = null ; e . dest = null ; } for ( int i = 0 ; i < usedNodes . size ( ) ; i ++ ) { Node < N , E > n = usedNodes . get ( i ) ; n . data = null ; n . edges . reset ( ) ; } unusedEdges . ad... | Takes all the used nodes and makes them unused . Also dereferences any objects saved in data . |
122,524 | protected void init ( int initialMaxSize , Class < T > type , Factory < T > factory ) { this . size = 0 ; this . type = type ; this . factory = factory ; data = ( T [ ] ) Array . newInstance ( type , initialMaxSize ) ; if ( factory != null ) { for ( int i = 0 ; i < initialMaxSize ; i ++ ) { try { data [ i ] = createIns... | Data structure initialization is done here so that child classes can declay initialization until they are ready |
122,525 | public void reverse ( ) { for ( int i = 0 ; i < size / 2 ; i ++ ) { T tmp = data [ i ] ; data [ i ] = data [ size - i - 1 ] ; data [ size - i - 1 ] = tmp ; } } | Reverse the item order in this queue . |
122,526 | public T get ( int index ) { if ( index >= size ) throw new IllegalArgumentException ( "Index out of bounds: index " + index + " size " + size ) ; return data [ index ] ; } | Returns the element at the specified index . Bounds checking is performed . |
122,527 | public T grow ( ) { if ( size < data . length ) { return data [ size ++ ] ; } else { growArray ( ( data . length + 1 ) * 2 ) ; return data [ size ++ ] ; } } | Returns a new element of data . If there are new data elements available then array will automatically grow . |
122,528 | public void remove ( int index ) { T removed = data [ index ] ; for ( int i = index + 1 ; i < size ; i ++ ) { data [ i - 1 ] = data [ i ] ; } data [ size - 1 ] = removed ; size -- ; } | Removes an element from the queue by shifting elements in the array down one and placing the removed element at the old end of the list . |
122,529 | public void growArray ( int length ) { if ( this . data . length >= length ) return ; T [ ] data = ( T [ ] ) Array . newInstance ( type , length ) ; System . arraycopy ( this . data , 0 , data , 0 , this . data . length ) ; if ( factory != null ) { for ( int i = this . data . length ; i < length ; i ++ ) { data [ i ] =... | Increases the size of the internal array without changing the shape s size . If the array is already larger than the specified length then nothing is done . Elements previously stored in the array are copied over is a new internal array is declared . |
122,530 | protected void cauchyStep ( double regionRadius , DMatrixRMaj step ) { CommonOps_DDRM . scale ( - regionRadius , direction , step ) ; stepLength = regionRadius ; predictedReduction = regionRadius * ( owner . gradientNorm - 0.5 * regionRadius * gBg ) ; } | Computes the Cauchy step This is only called if the Cauchy point lies after or on the trust region |
122,531 | static double fractionCauchyToGN ( double lengthCauchy , double lengthGN , double lengthPtoGN , double region ) { double a = lengthGN , b = lengthCauchy , c = lengthPtoGN ; double cosineA = ( a * a - b * b - c * c ) / ( - 2.0 * b * c ) ; double angleA = Math . acos ( cosineA ) ; a = region ; double angleB = Math . asin... | Compute the fractional distance from P to GN where the point intersects the region s boundary |
122,532 | public DMatrixRMaj next ( DMatrixRMaj x ) { for ( int i = 0 ; i < r . numRows ; i ++ ) { r . set ( i , 0 , rand . nextGaussian ( ) ) ; } x . set ( mean ) ; multAdd ( A , r , x ) ; return x ; } | Makes a draw on the distribution and stores the results in parameter x |
122,533 | public void initialize ( List < Point > dataSet ) { bestFitPoints . clear ( ) ; if ( dataSet . size ( ) > matchToInput . length ) { matchToInput = new int [ dataSet . size ( ) ] ; bestMatchToInput = new int [ dataSet . size ( ) ] ; } } | Initialize internal data structures |
122,534 | public static < T > void randomDraw ( List < T > dataSet , int numSample , List < T > initialSample , Random rand ) { initialSample . clear ( ) ; for ( int i = 0 ; i < numSample ; i ++ ) { int indexLast = dataSet . size ( ) - i - 1 ; int indexSelected = rand . nextInt ( indexLast + 1 ) ; T a = dataSet . get ( indexSele... | Performs a random draw in the dataSet . When an element is selected it is moved to the end of the list so that it can t be selected again . |
122,535 | @ SuppressWarnings ( { "ForLoopReplaceableByForEach" } ) protected void selectMatchSet ( List < Point > dataSet , double threshold , Model param ) { candidatePoints . clear ( ) ; modelDistance . setModel ( param ) ; for ( int i = 0 ; i < dataSet . size ( ) ; i ++ ) { Point point = dataSet . get ( i ) ; double distance ... | Looks for points in the data set which closely match the current best fit model in the optimizer . |
122,536 | protected void matchPointsToClusters ( List < double [ ] > points ) { sumDistance = 0 ; for ( int i = 0 ; i < points . size ( ) ; i ++ ) { double [ ] p = points . get ( i ) ; int bestCluster = findBestMatch ( p ) ; double [ ] c = workClusters . get ( bestCluster ) ; for ( int j = 0 ; j < c . length ; j ++ ) { c [ j ] +... | Finds the cluster which is the closest to each point . The point is the added to the sum for the cluster and its member count incremented |
122,537 | protected int findBestMatch ( double [ ] p ) { int bestCluster = - 1 ; bestDistance = Double . MAX_VALUE ; for ( int j = 0 ; j < clusters . size ; j ++ ) { double d = distanceSq ( p , clusters . get ( j ) ) ; if ( d < bestDistance ) { bestDistance = d ; bestCluster = j ; } } return bestCluster ; } | Searches for this cluster which is the closest to p |
122,538 | protected void updateClusterCenters ( ) { for ( int i = 0 ; i < clusters . size ; i ++ ) { double mc = memberCount . get ( i ) ; double [ ] w = workClusters . get ( i ) ; double [ ] c = clusters . get ( i ) ; for ( int j = 0 ; j < w . length ; j ++ ) { c [ j ] = w [ j ] / mc ; } } } | Sets the location of each cluster to the average location of all its members . |
122,539 | protected static double distanceSq ( double [ ] a , double [ ] b ) { double sum = 0 ; for ( int i = 0 ; i < a . length ; i ++ ) { double d = a [ i ] - b [ i ] ; sum += d * d ; } return sum ; } | Returns the euclidean distance squared between the two poits |
122,540 | public T requestInstance ( ) { T a ; if ( unused . size ( ) > 0 ) { a = unused . pop ( ) ; } else { a = createInstance ( ) ; } return a ; } | Either returns a recycled instance or a new one . |
122,541 | protected T createInstance ( ) { try { return targetClass . newInstance ( ) ; } catch ( InstantiationException e ) { throw new RuntimeException ( e ) ; } catch ( IllegalAccessException e ) { throw new RuntimeException ( e ) ; } } | Creates a new instance using the class . overload this to handle more complex constructors |
122,542 | public void setFunction ( GradientLineFunction function , double funcMinValue ) { this . function = function ; this . funcMinValue = funcMinValue ; lineSearch . setFunction ( function , funcMinValue ) ; N = function . getN ( ) ; B = new DMatrixRMaj ( N , N ) ; searchVector = new DMatrixRMaj ( N , 1 ) ; g = new DMatrixR... | Specify the function being optimized |
122,543 | private boolean computeSearchDirection ( ) { function . computeGradient ( temp0_Nx1 . data ) ; for ( int i = 0 ; i < N ; i ++ ) { y . data [ i ] = temp0_Nx1 . data [ i ] - g . data [ i ] ; g . data [ i ] = temp0_Nx1 . data [ i ] ; } if ( iterations != 0 ) { EquationsBFGS . inverseUpdate ( B , s , y , temp0_Nx1 , temp1_... | Computes the next search direction using BFGS |
122,544 | private void resetMatrixB ( ) { double maxDiag = 0 ; for ( int i = 0 ; i < N ; i ++ ) { double d = Math . abs ( B . get ( i , i ) ) ; if ( d > maxDiag ) maxDiag = d ; } B . zero ( ) ; for ( int i = 0 ; i < N ; i ++ ) { B . set ( i , i , maxDiag ) ; } } | This is a total hack . Set B to a diagonal matrix where each diagonal element is the value of the largest absolute value in B . This will be SPD and hopefully not screw up the search . |
122,545 | private boolean performLineSearch ( ) { if ( lineSearch . iterate ( ) ) { if ( ! lineSearch . isConverged ( ) ) { if ( firstStep ) { initialStep /= 2 ; if ( initialStep != 0 ) { invokeLineInitialize ( fx , maxStep ) ; return false ; } else { if ( verbose != null && verboseLevel != 0 ) { verbose . println ( "Initial ste... | Performs a 1 - D line search along the chosen direction until the Wolfe conditions have been meet . |
122,546 | private void computeMean ( ) { meanError = 0 ; int size = allPoints . size ( ) ; for ( PointIndex < Point > inlier : allPoints ) { Point pt = inlier . data ; meanError += modelError . computeDistance ( pt ) ; } meanError /= size ; } | Computes the mean and standard deviation of the points from the model |
122,547 | public void initialize ( double initial [ ] , int numberOfParameters , double minimumFunctionValue ) { super . initialize ( initial , numberOfParameters ) ; tmp_p . reshape ( numberOfParameters , 1 ) ; regionRadius = config . regionInitial ; fx = cost ( x ) ; if ( verbose != null ) { verbose . println ( "Steps fx ... | Specifies initial state of the search and completion criteria |
122,548 | protected boolean updateDerivates ( ) { functionGradientHessian ( x , sameStateAsCost , gradient , hessian ) ; if ( config . hessianScaling ) { computeHessianScaling ( ) ; applyHessianScaling ( ) ; } if ( checkConvergenceGTest ( gradient ) ) { if ( verbose != null ) { verbose . println ( "Converged g-test" ) ; } return... | Computes all the derived data structures and attempts to update the parameters |
122,549 | protected boolean computeStep ( ) { if ( regionRadius == - 1 ) { parameterUpdate . computeUpdate ( p , Double . MAX_VALUE ) ; regionRadius = parameterUpdate . getStepLength ( ) ; if ( regionRadius == Double . MAX_VALUE || UtilEjml . isUncountable ( regionRadius ) ) { if ( verbose != null ) verbose . println ( "unconstr... | Changes the trust region s size and attempts to do a step again |
122,550 | protected boolean considerCandidate ( double fx_candidate , double fx_prev , double predictedReduction , double stepLength ) { double actualReduction = fx_prev - fx_candidate ; if ( actualReduction == 0 || predictedReduction == 0 ) { if ( verbose != null ) verbose . println ( totalFullSteps + " reduction of zero" ) ; r... | Consider updating the system with the change in state p . The update will never be accepted if the cost function increases . |
122,551 | public void initialize ( double initial [ ] , int numberOfParameters , int numberOfFunctions ) { super . initialize ( initial , numberOfParameters ) ; lambda = config . dampeningInitial ; nu = NU_INITIAL ; residuals . reshape ( numberOfFunctions , 1 ) ; diagOrig . reshape ( numberOfParameters , 1 ) ; diagStep . reshape... | Initializes the search . |
122,552 | protected boolean computeStep ( ) { if ( ! computeStep ( lambda , gradient , p ) ) { if ( config . mixture == 0.0 ) { throw new OptimizationException ( "Singular matrix encountered. Try setting mixture to a non-zero value" ) ; } lambda *= 4 ; if ( verbose != null ) verbose . println ( totalFullSteps + " Step computatio... | Compute a new possible state and determine if it should be accepted or not . If accepted update the state |
122,553 | private boolean processStepResults ( double fx_candidate , double actualReduction , double predictedReduction ) { double ratio = actualReduction / predictedReduction ; boolean accepted ; if ( fx_candidate < fx ) { lambda = lambda * max ( 1.0 / 3.0 , 1.0 - Math . pow ( 2.0 * ratio - 1.0 , 3.0 ) ) ; nu = NU_INITIAL ; acc... | Sees if this is an improvement worth accepting . Adjust dampening parameter and change the state if accepted . |
122,554 | private void acceptNewState ( double fx_candidate ) { DMatrixRMaj tmp = x ; x = x_next ; x_next = tmp ; fx = fx_candidate ; mode = Mode . COMPUTE_DERIVATIVES ; } | The new state has been accepted . Switch the internal state over to this |
122,555 | protected boolean computeStep ( double lambda , DMatrixRMaj gradient , DMatrixRMaj step ) { final double mixture = config . mixture ; for ( int i = 0 ; i < diagOrig . numRows ; i ++ ) { double v = min ( config . diagonal_max , max ( config . diagonal_min , diagOrig . data [ i ] ) ) ; diagStep . data [ i ] = v + lambda ... | Adjusts the Hessian s diagonal elements value and computes the next step |
122,556 | public double evaluate ( double variable ) { if ( size == 0 ) { return 0 ; } else if ( size == 1 ) { return c [ 0 ] ; } else if ( Double . isInfinite ( variable ) ) { int degree = computeDegree ( ) ; if ( degree % 2 == 0 ) variable = Double . POSITIVE_INFINITY ; if ( c [ degree ] < 0 ) variable = variable == Double . P... | Computes the polynomials output given the variable value Can handle infinite numbers |
122,557 | public boolean isIdentical ( Polynomial p , double tol ) { int m = Math . max ( p . size ( ) , size ( ) ) ; for ( int i = p . size ; i < m ; i ++ ) { if ( Math . abs ( c [ i ] ) > tol ) { return false ; } } for ( int i = size ; i < m ; i ++ ) { if ( Math . abs ( p . c [ i ] ) > tol ) { return false ; } } int n = Math .... | Checks to see if the coefficients of two polynomials are identical to within tolerance . If the lengths of the polynomials are not the same then the extra coefficients in the longer polynomial must be within tolerance of zero . |
122,558 | public void truncateZeros ( double tol ) { int i = size - 1 ; for ( ; i >= 0 ; i -- ) { if ( Math . abs ( c [ i ] ) > tol ) break ; } size = i + 1 ; } | Prunes zero coefficients from the end of a sequence . A coefficient is zero if its absolute value is less than or equal to tolerance . |
122,559 | public void findNeighbor ( P target , int searchN , FastQueue < KdTreeResult > results ) { if ( searchN <= 0 ) throw new IllegalArgumentException ( "I'm sorry, but I refuse to search for less than or equal to 0 neighbors." ) ; if ( tree . root == null ) return ; this . searchN = searchN ; this . target = target ; this ... | Finds the nodes which are closest to target and within range of the maximum distance . |
122,560 | private void checkBestDistance ( KdTree . Node node , FastQueue < KdTreeResult > neighbors ) { double distSq = distance . distance ( ( P ) node . point , target ) ; if ( distSq <= mostDistantNeighborSq ) { if ( neighbors . size ( ) < searchN ) { KdTreeResult r = neighbors . grow ( ) ; r . distance = distSq ; r . node =... | See if the node being considered is a new nearest - neighbor |
122,561 | protected double expectation ( ) { double sumChiSq = 0 ; for ( int i = 0 ; i < info . size ( ) ; i ++ ) { PointInfo p = info . get ( i ) ; double bestLikelihood = 0 ; double bestChiSq = Double . MAX_VALUE ; double total = 0 ; for ( int j = 0 ; j < mixture . size ; j ++ ) { GaussianLikelihoodManager . Likelihood g = lik... | For each point compute the responsibility for each Gaussian |
122,562 | protected void maximization ( ) { for ( int i = 0 ; i < mixture . size ; i ++ ) { mixture . get ( i ) . zero ( ) ; } for ( int i = 0 ; i < info . size ; i ++ ) { PointInfo p = info . get ( i ) ; for ( int j = 0 ; j < mixture . size ; j ++ ) { mixture . get ( j ) . addMean ( p . point , p . weights . get ( j ) ) ; } } f... | Using points responsibility information to recompute the Gaussians and their weights maximizing the likelihood of the mixture . |
122,563 | public boolean process ( int offset , int length , double ... data ) { if ( data . length < 3 ) throw new IllegalArgumentException ( "At least three points" ) ; A . reshape ( data . length , 3 ) ; y . reshape ( data . length , 1 ) ; int indexDst = 0 ; int indexSrc = offset ; for ( int i = 0 ; i < length ; i ++ ) { doub... | Computes polynomial coefficients for the given data . |
122,564 | public double innerVectorHessian ( DMatrixRMaj v ) { int M = A . getNumRows ( ) ; double sum = 0 ; sum += innerProduct ( v . data , 0 , A , v . data , 0 ) ; sum += 2 * innerProduct ( v . data , 0 , B , v . data , M ) ; sum += innerProduct ( v . data , M , D , v . data , M ) ; return sum ; } | Vector matrix inner product of Hessian in block format . |
122,565 | public void computeGradient ( S jacLeft , S jacRight , DMatrixRMaj residuals , DMatrixRMaj gradient ) { x1 . reshape ( jacLeft . getNumCols ( ) , 1 ) ; x2 . reshape ( jacRight . getNumCols ( ) , 1 ) ; multTransA ( jacLeft , residuals , x1 ) ; multTransA ( jacRight , residuals , x2 ) ; CommonOps_DDRM . insert ( x1 , gra... | Computes the gradient using Schur complement |
122,566 | private Node buildFromPoints ( int lower , int upper ) { if ( upper == lower ) { return null ; } final Node node = new Node ( ) ; node . index = lower ; if ( upper - lower > 1 ) { int i = random . nextInt ( upper - lower - 1 ) + lower ; listSwap ( items , lower , i ) ; listSwap ( indexes , lower , i ) ; int median = ( ... | Builds the tree from a set of points by recursively partitioning them according to a random pivot . |
122,567 | private void nthElement ( int left , int right , int n , double [ ] origin ) { int npos = partitionItems ( left , right , n , origin ) ; if ( npos < n ) nthElement ( npos + 1 , right , n , origin ) ; if ( npos > n ) nthElement ( left , npos , n , origin ) ; } | Ensures that the n - th element is in a correct position in the list based on the distance from origin . |
122,568 | private int partitionItems ( int left , int right , int pivot , double [ ] origin ) { double pivotDistance = distance ( origin , items [ pivot ] ) ; listSwap ( items , pivot , right - 1 ) ; listSwap ( indexes , pivot , right - 1 ) ; int storeIndex = left ; for ( int i = left ; i < right - 1 ; i ++ ) { if ( distance ( o... | Partition the points based on their distance to origin around the selected pivot . |
122,569 | private < E > void listSwap ( E [ ] list , int a , int b ) { final E tmp = list [ a ] ; list [ a ] = list [ b ] ; list [ b ] = tmp ; } | Swaps two items in the given list . |
122,570 | private static double distance ( double [ ] p1 , double [ ] p2 ) { switch ( p1 . length ) { case 2 : return Math . sqrt ( ( p1 [ 0 ] - p2 [ 0 ] ) * ( p1 [ 0 ] - p2 [ 0 ] ) + ( p1 [ 1 ] - p2 [ 1 ] ) * ( p1 [ 1 ] - p2 [ 1 ] ) ) ; case 3 : return Math . sqrt ( ( p1 [ 0 ] - p2 [ 0 ] ) * ( p1 [ 0 ] - p2 [ 0 ] ) + ( p1 [ 1 ]... | Compute the Euclidean distance between p1 and p2 . |
122,571 | private PriorityQueue < HeapItem > search ( final double [ ] target , double maxDistance , final int k ) { PriorityQueue < HeapItem > heap = new PriorityQueue < HeapItem > ( ) ; if ( root == null ) { return heap ; } double tau = maxDistance ; final FastQueue < Node > nodes = new FastQueue < Node > ( 20 , Node . class ,... | Recursively search for the k nearest neighbors to target . |
122,572 | private boolean searchNearest ( final double [ ] target , double maxDistance , NnData < double [ ] > result ) { if ( root == null ) { return false ; } double tau = maxDistance ; final FastQueue < Node > nodes = new FastQueue < Node > ( 20 , Node . class , false ) ; nodes . add ( root ) ; result . distance = Double . PO... | Equivalent to the above search method to find one nearest neighbor . It is faster as it does not need to allocate and use the heap data structure . |
122,573 | public KdTree . Node findNeighbor ( P target ) { if ( tree . root == null ) return null ; this . target = target ; this . closest = null ; this . bestDistanceSq = maxDistanceSq ; stepClosest ( tree . root ) ; return closest ; } | Finds the node which is closest to target |
122,574 | public void process ( Polynomial poly ) { sturm . initialize ( poly ) ; if ( searchRadius <= 0 ) numRoots = sturm . countRealRoots ( Double . NEGATIVE_INFINITY , Double . POSITIVE_INFINITY ) ; else numRoots = sturm . countRealRoots ( - searchRadius , searchRadius ) ; if ( numRoots == 0 ) return ; if ( searchRadius <= 0... | Find real roots for the specified polynomial . |
122,575 | private void handleAllRoots ( ) { int totalFound = 0 ; double r = 1 ; int iter = 0 ; while ( iter ++ < maxBoundIterations && ( totalFound = sturm . countRealRoots ( - r , r ) ) <= 0 ) { r = 2 * r * r ; } if ( Double . isInfinite ( r ) ) throw new RuntimeException ( "r is infinite" ) ; if ( iter >= maxBoundIterations ) ... | Search for all real roots . First find a region about 0 which contains at least one root . Then search above and below . |
122,576 | private void bisectionRoot ( double l , double u , int index ) { int iter = 0 ; while ( u - l > boundTolerance * Math . abs ( l ) && iter ++ < maxBoundIterations ) { double m = ( l + u ) / 2.0 ; int numRoots = sturm . countRealRoots ( m , u ) ; if ( numRoots == 1 ) { l = m ; } else { u = m ; } } roots [ index ] = ( l +... | Searches for a single real root inside the range . Only one root is assumed to be inside |
122,577 | private void boundEachRoot ( double l , double u , int startIndex , int numRoots ) { int iter = 0 ; double allUpper = u ; int root = 0 ; int lastFound = 0 ; double lastUpper = u ; while ( root < numRoots && iter ++ < maxBoundIterations ) { double m = ( l + u ) / 2.0 ; int found = sturm . countRealRoots ( l , m ) ; if (... | Finds a crude upper and lower bound for each root that includes only one root . |
122,578 | public boolean iterate ( ) { boolean converged ; switch ( mode ) { case COMPUTE_DERIVATIVES : totalFullSteps ++ ; converged = updateDerivates ( ) ; if ( ! converged ) { totalSelectSteps ++ ; converged = computeStep ( ) ; } break ; case DETERMINE_STEP : totalSelectSteps ++ ; converged = computeStep ( ) ; break ; case CO... | Performs one iteration |
122,579 | public void computeHessianScaling ( DMatrixRMaj scaling ) { double max = 0 ; for ( int i = 0 ; i < scaling . numRows ; i ++ ) { double v = scaling . data [ i ] = sqrt ( abs ( scaling . data [ i ] ) ) ; if ( v > max ) max = v ; } max *= 1e-12 ; for ( int i = 0 ; i < scaling . numRows ; i ++ ) { scaling . data [ i ] += m... | Applies the standard formula for computing scaling . This is broken off into its own function so that it easily invoked if the function above is overridden |
122,580 | public double computePredictedReduction ( DMatrixRMaj p ) { return - CommonOps_DDRM . dot ( gradient , p ) - 0.5 * hessian . innerVectorHessian ( p ) ; } | Computes predicted reduction for step p |
122,581 | public void setTo ( int [ ] array , int offset , int length ) { resize ( length ) ; System . arraycopy ( array , offset , data , 0 , length ) ; } | Sets this array to be equal to the array segment |
122,582 | public void insert ( int index , int value ) { if ( size == data . length ) { int temp [ ] = new int [ size * 2 ] ; System . arraycopy ( data , 0 , temp , 0 , index ) ; temp [ index ] = value ; System . arraycopy ( data , index , temp , index + 1 , size - index ) ; this . data = temp ; size ++ ; } else { size ++ ; for ... | Inserts the value at the specified index and shifts all the other values down . |
122,583 | public void removeHead ( int total ) { for ( int j = total ; j < size ; j ++ ) { data [ j - total ] = data [ j ] ; } size -= total ; } | Removes the first total elements from the queue . Element total will be the new start of the queue |
122,584 | private void init ( List < T > list ) { this . list = list ; indexes = new int [ list . size ( ) ] ; counters = new int [ list . size ( ) ] ; for ( int i = 0 ; i < indexes . length ; i ++ ) { counters [ i ] = indexes [ i ] = i ; } total = 1 ; for ( int i = 2 ; i <= indexes . length ; i ++ ) { total *= i ; } permutation... | Initializes the permutation for a new list |
122,585 | public boolean next ( ) { if ( indexes . length <= 1 || permutation >= total - 1 ) return false ; int N = indexes . length - 2 ; int k = N ; swap ( k , counters [ k ] ++ ) ; while ( counters [ k ] == indexes . length ) { k -= 1 ; swap ( k , counters [ k ] ++ ) ; } swap ( counters [ k ] , k ) ; while ( k < indexes . len... | This will permute the list once |
122,586 | public boolean previous ( ) { if ( indexes . length <= 1 || permutation <= 0 ) return false ; int N = indexes . length - 2 ; int k = N ; while ( counters [ k ] <= k ) { k -- ; } swap ( counters [ k ] , k ) ; counters [ k ] -- ; swap ( k , counters [ k ] ) ; int foo = k + 1 ; while ( counters [ k + 1 ] == k + 1 && k < i... | This will undo a permutation . |
122,587 | public List < T > getPermutation ( List < T > storage ) { if ( storage == null ) storage = new ArrayList < T > ( ) ; else storage . clear ( ) ; for ( int i = 0 ; i < list . size ( ) ; i ++ ) { storage . add ( get ( i ) ) ; } return storage ; } | Returns a list containing the current permutation . |
122,588 | public Sms recipient ( Recipient ... recipients ) { this . recipients . addAll ( Arrays . asList ( recipients ) ) ; return this ; } | Add a recipient for the message |
122,589 | public Sms from ( String name , String phoneNumber ) { return from ( name , new PhoneNumber ( phoneNumber ) ) ; } | Set the sender using the phone number as string . |
122,590 | public Sms to ( PhoneNumber ... numbers ) { for ( PhoneNumber number : numbers ) { to ( ( String ) null , number ) ; } return this ; } | Add a recipient specifying the phone number . |
122,591 | public Sms to ( String ... numbers ) { for ( String num : numbers ) { to ( new Recipient ( num ) ) ; } return this ; } | Add a recipient specifying the phone number as string . |
122,592 | public Sms to ( String name , PhoneNumber number ) { to ( new Recipient ( name , number ) ) ; return this ; } | Add a recipient specifying the name and the phone number . |
122,593 | public static Recipient [ ] toRecipient ( PhoneNumber [ ] to ) { Recipient [ ] addresses = new Recipient [ to . length ] ; int i = 0 ; for ( PhoneNumber t : to ) { addresses [ i ++ ] = new Recipient ( t ) ; } return addresses ; } | Converts a list of phone numbers to a list of recipients . |
122,594 | public static Recipient [ ] toRecipient ( String [ ] to ) { Recipient [ ] addresses = new Recipient [ to . length ] ; int i = 0 ; for ( String t : to ) { addresses [ i ++ ] = new Recipient ( t ) ; } return addresses ; } | Converts a list of string to a list of recipients . |
122,595 | public SendGridBuilder username ( String ... username ) { for ( String u : username ) { if ( u != null ) { usernames . add ( u ) ; } } return this ; } | Set username for SendGrid HTTP API . |
122,596 | public SendGridBuilder password ( String ... password ) { for ( String p : password ) { if ( p != null ) { passwords . add ( p ) ; } } return this ; } | Set password for SendGrid HTTP API . |
122,597 | public static boolean isInvalid ( Object bean ) { if ( bean == null ) { return false ; } return isPrimitiveOrWrapper ( bean . getClass ( ) ) || INVALID_TYPES . contains ( bean . getClass ( ) ) || isInstanceOfInvalid ( bean . getClass ( ) ) ; } | Check if the bean type can be wrapped or not . |
122,598 | public Email recipient ( Recipient ... recipients ) { this . recipients . addAll ( Arrays . asList ( recipients ) ) ; return this ; } | Add a recipient of the mail . |
122,599 | public Email to ( EmailAddress ... to ) { for ( EmailAddress t : to ) { recipient ( t , RecipientType . TO ) ; } return this ; } | Add a to recipient address . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.