idx int64 0 41.2k | question stringlengths 73 5.81k | target stringlengths 5 918 |
|---|---|---|
11,100 | private FPTree getLocalFPTree ( FPTree . Node node , int [ ] localItemSupport , int [ ] prefixItemset ) { FPTree tree = new FPTree ( localItemSupport , minSupport ) ; while ( node != null ) { Node parent = node . parent ; int i = prefixItemset . length ; while ( parent != null ) { if ( localItemSupport [ parent . id ] ... | Generates a local FP tree |
11,101 | static int [ ] insert ( int [ ] itemset , int item ) { if ( itemset == null ) { int [ ] newItemset = { item } ; return newItemset ; } else { int n = itemset . length + 1 ; int [ ] newItemset = new int [ n ] ; newItemset [ 0 ] = item ; System . arraycopy ( itemset , 0 , newItemset , 1 , n - 1 ) ; return newItemset ; } } | Insert a item to the front of an item set . |
11,102 | static int [ ] drop ( int [ ] itemset ) { if ( itemset . length >= 1 ) { int n = itemset . length - 1 ; int [ ] newItemset = new int [ n ] ; System . arraycopy ( itemset , 1 , newItemset , 0 , n ) ; return newItemset ; } else { return null ; } } | Drops an item form the front of an item set . |
11,103 | private void setSlice ( ) { if ( labels == null ) { double min = base . getPrecisionUnit ( ) [ index ] * Math . ceil ( base . getLowerBounds ( ) [ index ] / base . getPrecisionUnit ( ) [ index ] ) ; double max = base . getPrecisionUnit ( ) [ index ] * Math . floor ( base . getUpperBounds ( ) [ index ] / base . getPreci... | Set the slices of axis . |
11,104 | private void initGridLines ( ) { gridLines = new Line [ base . getDimension ( ) - 1 ] [ linesSlicing . length ] ; int i2 = 0 ; for ( int i = 0 ; i < base . getDimension ( ) - 1 ; i ++ ) { if ( i2 == index ) { i2 ++ ; } for ( int j = 0 ; j < gridLines [ i ] . length ; j ++ ) { double [ ] originBase = new double [ base .... | Initialize grid lines . |
11,105 | public Axis removeLabel ( String label ) { if ( labels == null ) { throw new IllegalStateException ( ) ; } labels . remove ( label ) ; setSlice ( ) ; initGridLabels ( ) ; return this ; } | Remove a label from the axis . |
11,106 | public Axis setAxisLabel ( String label ) { if ( label == null ) { if ( index == 0 ) { label = "X" ; } else if ( index == 1 ) { label = "Y" ; } else if ( index == 2 ) { label = "Z" ; } } if ( label != null ) { double [ ] position = new double [ base . getDimension ( ) ] ; if ( base . getDimension ( ) == 2 ) { position ... | Sets the label of this axis . |
11,107 | public void paint ( Graphics g ) { if ( gridLines != null ) { if ( gridVisible ) { for ( int i = 0 ; i < gridLines . length ; i ++ ) { for ( int j = 1 ; j < gridLines [ i ] . length - 1 ; j ++ ) { gridLines [ i ] [ j ] . paint ( g ) ; } } } if ( frameVisible ) { for ( int i = 0 ; i < gridLines . length ; i ++ ) { gridL... | Draw the axis . |
11,108 | private void singlePointCrossover ( BitString father , BitString mother , BitString [ ] offsprings ) { int point = 0 ; while ( point == 0 ) { point = Math . randomInt ( length ) ; } int [ ] son = new int [ length ] ; System . arraycopy ( father . bits , 0 , son , 0 , point ) ; System . arraycopy ( mother . bits , point... | Single point crossover . |
11,109 | private void twoPointCrossover ( BitString father , BitString mother , BitString [ ] offsprings ) { int point1 = 0 ; while ( point1 == 0 || point1 == length - 1 ) { point1 = Math . randomInt ( length ) ; } int point2 = 0 ; while ( point2 == point1 || point2 == 0 || point2 == length - 1 ) { point2 = Math . randomInt ( l... | Two point crossover . |
11,110 | private void uniformCrossover ( BitString father , BitString mother , BitString [ ] offsprings ) { int [ ] son = new int [ length ] ; int [ ] daughter = new int [ length ] ; for ( int i = 0 ; i < length ; i ++ ) { if ( Math . random ( ) < 0.5 ) { son [ i ] = father . bits [ i ] ; daughter [ i ] = mother . bits [ i ] ; ... | Uniform crossover . |
11,111 | public PCA setProjection ( int p ) { if ( p < 1 || p > n ) { throw new IllegalArgumentException ( "Invalid dimension of feature space: " + p ) ; } this . p = p ; projection = Matrix . zeros ( p , n ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < p ; j ++ ) { projection . set ( j , i , eigvectors . get ( i ... | Set the projection matrix with given number of principal components . |
11,112 | @ SuppressWarnings ( "rawtypes" ) protected SortKey getSortKey ( JTable table , int column ) { RowSorter rowSorter = table . getRowSorter ( ) ; if ( rowSorter == null ) { return null ; } List sortedColumns = rowSorter . getSortKeys ( ) ; if ( ! sortedColumns . isEmpty ( ) ) { return ( SortKey ) sortedColumns . get ( 0 ... | Returns the current sort key or null if the column is unsorted . |
11,113 | private void organize ( ) { int m = ( int ) Math . sqrt ( contentPane . getComponentCount ( ) ) ; if ( m <= 0 ) m = 1 ; contentPane . setLayout ( new GridLayout ( m , 0 , 0 , 0 ) ) ; } | Reorganize the plots in the frame . Basically it reset the surface layout based on the number of plots in the frame . |
11,114 | private void initToolBar ( ) { toolbar = new JToolBar ( JToolBar . VERTICAL ) ; toolbar . setFloatable ( false ) ; add ( toolbar , BorderLayout . WEST ) ; JButton button = makeButton ( "save" , SAVE , "Save" , "Save" ) ; toolbar . add ( button ) ; button = makeButton ( "print" , PRINT , "Print" , "Print" ) ; toolbar . ... | Initialize toolbar . |
11,115 | private JButton makeButton ( String imageName , String actionCommand , String toolTipText , String altText ) { String imgLocation = "images/" + imageName + "16.png" ; URL imageURL = PlotCanvas . class . getResource ( imgLocation ) ; JButton button = new JButton ( ) ; button . setActionCommand ( actionCommand ) ; button... | Creates a button for toolbar . |
11,116 | public static int [ ] [ ] sort ( Attribute [ ] attributes , double [ ] [ ] x ) { int n = x . length ; int p = x [ 0 ] . length ; double [ ] a = new double [ n ] ; int [ ] [ ] index = new int [ p ] [ ] ; for ( int j = 0 ; j < p ; j ++ ) { if ( attributes [ j ] . getType ( ) == Attribute . Type . NUMERIC ) { for ( int i ... | Sorts each variable and returns the index of values in ascending order . Only numeric attributes will be sorted . Note that the order of original array is NOT altered . |
11,117 | public void impute ( double [ ] [ ] data , int maxIter ) throws MissingValueImputationException { if ( maxIter < 1 ) { throw new IllegalArgumentException ( "Invalid maximum number of iterations: " + maxIter ) ; } int [ ] count = new int [ data [ 0 ] . length ] ; for ( int i = 0 ; i < data . length ; i ++ ) { int n = 0 ... | Impute missing values in the dataset . |
11,118 | private void svdImpute ( double [ ] [ ] raw , double [ ] [ ] data ) { SVD svd = Matrix . newInstance ( data ) . svd ( ) ; int d = data [ 0 ] . length ; for ( int i = 0 ; i < raw . length ; i ++ ) { int missing = 0 ; for ( int j = 0 ; j < d ; j ++ ) { if ( Double . isNaN ( raw [ i ] [ j ] ) ) { missing ++ ; } else { dat... | Impute the missing values by SVD . |
11,119 | private static double bcuint ( double [ ] y , double [ ] y1 , double [ ] y2 , double [ ] y12 , double x1l , double x1u , double x2l , double x2u , double x1p , double x2p ) { if ( x1u == x1l ) { throw new IllegalArgumentException ( "Nearby control points take same value: " + x1u ) ; } if ( x2u == x2l ) { throw new Ille... | Bicubic interpolation within a grid square . |
11,120 | public static PlotCanvas plot ( double [ ] [ ] vertices , int [ ] [ ] edges ) { double [ ] lowerBound = Math . colMin ( vertices ) ; double [ ] upperBound = Math . colMax ( vertices ) ; PlotCanvas canvas = new PlotCanvas ( lowerBound , upperBound ) ; Wireframe frame = new Wireframe ( vertices , edges ) ; canvas . add (... | Create a wire frame plot canvas . |
11,121 | public int [ ] feature ( double [ ] x ) { if ( x . length != attributes . length ) { throw new IllegalArgumentException ( String . format ( "Invalid feature vector size %d, expected %d" , x . length , attributes . length ) ) ; } int [ ] features = new int [ attributes . length ] ; for ( int i = 0 ; i < features . lengt... | Generates the compact representation of sparse binary features for given object . |
11,122 | public String format ( String s ) { for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . substring ( i , i + 1 ) . equals ( "*" ) && i > 0 ) if ( isOperand ( s . substring ( i - 1 , i ) , var ) && i < s . length ( ) - 1 && s . substring ( i + 1 , i + 2 ) . equals ( var ) ) s = s . substring ( 0 , i ) + s . substrin... | Modifies the string to look more like it would if someone wrote the expression out on paper . |
11,123 | public String parse ( String expression ) throws InvalidExpressionException { this . expression = expression ; try { var = check ( ) ; } catch ( InvalidExpressionException e ) { e . printStackTrace ( ) ; } this . expression = formatString ( expression ) ; System . out . println ( this . expression ) ; tokens = tokenize... | Creates tokens in polish notation for and re - formats the expression unless an expression without valid syntax is passed in . |
11,124 | private String formatString ( String exp ) { exp = exp . replaceAll ( "\\s" , "" ) ; exp = exp . toLowerCase ( ) ; int count = 0 ; if ( exp . substring ( 0 , 1 ) . equals ( "-" ) ) { exp = "$" + exp . substring ( 1 ) ; } for ( int i = 0 ; i < exp . length ( ) ; i ++ ) { if ( exp . substring ( i , i + 1 ) . equals ( "("... | adds and deletes characters to aid in the creation of the binary expression tree |
11,125 | static void reverse ( double [ ] d , DenseMatrix V ) { int m = V . nrows ( ) ; int n = d . length ; int half = n / 2 ; for ( int i = 0 ; i < half ; i ++ ) { double tmp = d [ i ] ; d [ i ] = d [ n - i - 1 ] ; d [ n - i - 1 ] = tmp ; } for ( int j = 0 ; j < half ; j ++ ) { for ( int i = 0 ; i < m ; i ++ ) { double tmp = ... | Reverse the array to match JMatrix . |
11,126 | public static double logistic ( double x ) { double y = 0.0 ; if ( x < - 40 ) { y = 2.353853e+17 ; } else if ( x > 40 ) { y = 1.0 + 4.248354e-18 ; } else { y = 1.0 + Math . exp ( - x ) ; } return 1.0 / y ; } | Logistic sigmoid function . |
11,127 | public static double round ( double x , int decimal ) { if ( decimal < 0 ) { return round ( x / pow ( 10 , - decimal ) ) * pow ( 10 , - decimal ) ; } else { return round ( x * pow ( 10 , decimal ) ) / pow ( 10 , decimal ) ; } } | Round a double vale to given digits such as 10^n where n is a positive or negative integer . |
11,128 | public static double logFactorial ( int n ) { if ( n < 0 ) { throw new IllegalArgumentException ( String . format ( "n has to be nonnegative: %d" , n ) ) ; } double f = 0.0 ; for ( int i = 2 ; i <= n ; i ++ ) { f += Math . log ( i ) ; } return f ; } | log of factorial of n |
11,129 | public static double choose ( int n , int k ) { if ( n < 0 || k < 0 ) { throw new IllegalArgumentException ( String . format ( "Invalid n = %d, k = %d" , n , k ) ) ; } if ( n < k ) { return 0.0 ; } return Math . floor ( 0.5 + Math . exp ( logChoose ( n , k ) ) ) ; } | n choose k . Returns 0 if n is less than k . |
11,130 | public static double logChoose ( int n , int k ) { if ( n < 0 || k < 0 || k > n ) { throw new IllegalArgumentException ( String . format ( "Invalid n = %d, k = %d" , n , k ) ) ; } return Math . logFactorial ( n ) - Math . logFactorial ( k ) - Math . logFactorial ( n - k ) ; } | log of n choose k |
11,131 | public static int [ ] random ( double [ ] prob , int n ) { double [ ] q = new double [ prob . length ] ; for ( int i = 0 ; i < prob . length ; i ++ ) { q [ i ] = prob [ i ] * prob . length ; } int [ ] a = new int [ prob . length ] ; for ( int i = 0 ; i < prob . length ; i ++ ) { a [ i ] = i ; } int [ ] HL = new int [ p... | Given a set of m probabilities draw with replacement a set of n random number in [ 0 m ) . |
11,132 | public static double [ ] random ( double lo , double hi , int n ) { double [ ] x = new double [ n ] ; random . get ( ) . nextDoubles ( x , lo , hi ) ; return x ; } | Generate n uniform random numbers in the range [ lo hi ) . |
11,133 | public static int randomInt ( int lo , int hi ) { int w = hi - lo ; return lo + random . get ( ) . nextInt ( w ) ; } | Returns a random integer in [ lo hi ) . |
11,134 | public static int [ ] c ( int [ ] ... x ) { int n = 0 ; for ( int i = 0 ; i < x . length ; i ++ ) { n += x . length ; } int [ ] y = new int [ n ] ; for ( int i = 0 , k = 0 ; i < x . length ; i ++ ) { for ( int xi : x [ i ] ) { y [ k ++ ] = xi ; } } return y ; } | Merges multiple vectors into one . |
11,135 | public static boolean contains ( double [ ] [ ] polygon , double x , double y ) { if ( polygon . length <= 2 ) { return false ; } int hits = 0 ; int n = polygon . length ; double lastx = polygon [ n - 1 ] [ 0 ] ; double lasty = polygon [ n - 1 ] [ 1 ] ; double curx , cury ; for ( int i = 0 ; i < n ; lastx = curx , last... | Determines if the polygon contains the specified coordinates . |
11,136 | public static void reverse ( int [ ] a ) { int i = 0 , j = a . length - 1 ; while ( i < j ) { SortUtils . swap ( a , i ++ , j -- ) ; } } | Reverses the order of the elements in the specified array . |
11,137 | public static double [ ] rowMin ( double [ ] [ ] data ) { double [ ] x = new double [ data . length ] ; for ( int i = 0 ; i < x . length ; i ++ ) { x [ i ] = min ( data [ i ] ) ; } return x ; } | Returns the row minimum for a matrix . |
11,138 | public static double [ ] rowMax ( double [ ] [ ] data ) { double [ ] x = new double [ data . length ] ; for ( int i = 0 ; i < x . length ; i ++ ) { x [ i ] = max ( data [ i ] ) ; } return x ; } | Returns the row maximum for a matrix . |
11,139 | public static double [ ] rowSums ( double [ ] [ ] data ) { double [ ] x = new double [ data . length ] ; for ( int i = 0 ; i < x . length ; i ++ ) { x [ i ] = sum ( data [ i ] ) ; } return x ; } | Returns the row sums for a matrix . |
11,140 | public static double [ ] rowMeans ( double [ ] [ ] data ) { double [ ] x = new double [ data . length ] ; for ( int i = 0 ; i < x . length ; i ++ ) { x [ i ] = mean ( data [ i ] ) ; } return x ; } | Returns the row means for a matrix . |
11,141 | public static double [ ] rowSds ( double [ ] [ ] data ) { double [ ] x = new double [ data . length ] ; for ( int i = 0 ; i < x . length ; i ++ ) { x [ i ] = sd ( data [ i ] ) ; } return x ; } | Returns the row standard deviations for a matrix . |
11,142 | public static double [ ] colMin ( double [ ] [ ] data ) { double [ ] x = new double [ data [ 0 ] . length ] ; for ( int i = 0 ; i < x . length ; i ++ ) { x [ i ] = Double . POSITIVE_INFINITY ; } for ( int i = 0 ; i < data . length ; i ++ ) { for ( int j = 0 ; j < x . length ; j ++ ) { if ( x [ j ] > data [ i ] [ j ] ) ... | Returns the column minimum for a matrix . |
11,143 | public static double [ ] colMax ( double [ ] [ ] data ) { double [ ] x = new double [ data [ 0 ] . length ] ; for ( int i = 0 ; i < x . length ; i ++ ) { x [ i ] = Double . NEGATIVE_INFINITY ; } for ( int i = 0 ; i < data . length ; i ++ ) { for ( int j = 0 ; j < x . length ; j ++ ) { if ( x [ j ] < data [ i ] [ j ] ) ... | Returns the column maximum for a matrix . |
11,144 | public static double [ ] colSums ( double [ ] [ ] data ) { double [ ] x = data [ 0 ] . clone ( ) ; for ( int i = 1 ; i < data . length ; i ++ ) { for ( int j = 0 ; j < x . length ; j ++ ) { x [ j ] += data [ i ] [ j ] ; } } return x ; } | Returns the column sums for a matrix . |
11,145 | public static double [ ] colMeans ( double [ ] [ ] data ) { double [ ] x = data [ 0 ] . clone ( ) ; for ( int i = 1 ; i < data . length ; i ++ ) { for ( int j = 0 ; j < x . length ; j ++ ) { x [ j ] += data [ i ] [ j ] ; } } scale ( 1.0 / data . length , x ) ; return x ; } | Returns the column means for a matrix . |
11,146 | public static double [ ] colSds ( double [ ] [ ] data ) { if ( data . length < 2 ) { throw new IllegalArgumentException ( "Array length is less than 2." ) ; } int p = data [ 0 ] . length ; double [ ] sum = new double [ p ] ; double [ ] sumsq = new double [ p ] ; for ( double [ ] x : data ) { for ( int i = 0 ; i < p ; i... | Returns the column deviations for a matrix . |
11,147 | public static int sum ( int [ ] x ) { double sum = 0.0 ; for ( int n : x ) { sum += n ; } if ( sum > Integer . MAX_VALUE || sum < - Integer . MAX_VALUE ) { throw new ArithmeticException ( "Sum overflow: " + sum ) ; } return ( int ) sum ; } | Returns the sum of an array . |
11,148 | public static < T extends Comparable < ? super T > > T median ( T [ ] a ) { return QuickSelect . median ( a ) ; } | Find the median of an array of type double . The input array will be rearranged . |
11,149 | public static double var ( int [ ] x ) { if ( x . length < 2 ) { throw new IllegalArgumentException ( "Array length is less than 2." ) ; } double sum = 0.0 ; double sumsq = 0.0 ; for ( int xi : x ) { sum += xi ; sumsq += xi * xi ; } int n = x . length - 1 ; return sumsq / n - ( sum / x . length ) * ( sum / n ) ; } | Returns the variance of an array . |
11,150 | public static double squaredDistance ( int [ ] x , int [ ] y ) { if ( x . length != y . length ) { throw new IllegalArgumentException ( "Input vector sizes are different." ) ; } double sum = 0.0 ; for ( int i = 0 ; i < x . length ; i ++ ) { sum += sqr ( x [ i ] - y [ i ] ) ; } return sum ; } | The squared Euclidean distance . |
11,151 | public static double dot ( int [ ] x , int [ ] y ) { if ( x . length != y . length ) { throw new IllegalArgumentException ( "Arrays have different length." ) ; } double p = 0.0 ; for ( int i = 0 ; i < x . length ; i ++ ) { p += x [ i ] * y [ i ] ; } return p ; } | Returns the dot product between two vectors . |
11,152 | public static double dot ( SparseArray x , SparseArray y ) { Iterator < SparseArray . Entry > it1 = x . iterator ( ) ; Iterator < SparseArray . Entry > it2 = y . iterator ( ) ; SparseArray . Entry e1 = it1 . hasNext ( ) ? it1 . next ( ) : null ; SparseArray . Entry e2 = it2 . hasNext ( ) ? it2 . next ( ) : null ; doubl... | Returns the dot product between two sparse arrays . |
11,153 | public static double cov ( int [ ] x , int [ ] y ) { if ( x . length != y . length ) { throw new IllegalArgumentException ( "Arrays have different length." ) ; } if ( x . length < 3 ) { throw new IllegalArgumentException ( "array length has to be at least 3." ) ; } double mx = mean ( x ) ; double my = mean ( y ) ; doub... | Returns the covariance between two vectors . |
11,154 | public static double [ ] [ ] cov ( double [ ] [ ] data , double [ ] mu ) { double [ ] [ ] sigma = new double [ data [ 0 ] . length ] [ data [ 0 ] . length ] ; for ( int i = 0 ; i < data . length ; i ++ ) { for ( int j = 0 ; j < mu . length ; j ++ ) { for ( int k = 0 ; k <= j ; k ++ ) { sigma [ j ] [ k ] += ( data [ i ]... | Returns the sample covariance matrix . |
11,155 | public static double cor ( int [ ] x , int [ ] y ) { if ( x . length != y . length ) { throw new IllegalArgumentException ( "Arrays have different length." ) ; } if ( x . length < 3 ) { throw new IllegalArgumentException ( "array length has to be at least 3." ) ; } double Sxy = cov ( x , y ) ; double Sxx = var ( x ) ; ... | Returns the correlation coefficient between two vectors . |
11,156 | public static double [ ] [ ] cor ( double [ ] [ ] data , double [ ] mu ) { double [ ] [ ] sigma = cov ( data , mu ) ; int n = data [ 0 ] . length ; double [ ] sd = new double [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { sd [ i ] = sqrt ( sigma [ i ] [ i ] ) ; } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j <= i ... | Returns the sample correlation matrix . |
11,157 | public static double kendall ( int [ ] x , int [ ] y ) { if ( x . length != y . length ) { throw new IllegalArgumentException ( "Input vector sizes are different." ) ; } int is = 0 , n2 = 0 , n1 = 0 , n = x . length ; double aa , a2 , a1 ; for ( int j = 0 ; j < n - 1 ; j ++ ) { for ( int k = j + 1 ; k < n ; k ++ ) { a1... | The Kendall Tau Rank Correlation Coefficient is used to measure the degree of correspondence between sets of rankings where the measures are not equidistant . It is used with non - parametric data . |
11,158 | public static double norm1 ( double [ ] x ) { double norm = 0.0 ; for ( double n : x ) { norm += Math . abs ( n ) ; } return norm ; } | L1 vector norm . |
11,159 | public static double norm2 ( double [ ] x ) { double norm = 0.0 ; for ( double n : x ) { norm += n * n ; } norm = Math . sqrt ( norm ) ; return norm ; } | L2 vector norm . |
11,160 | public static double normInf ( double [ ] x ) { int n = x . length ; double f = Math . abs ( x [ 0 ] ) ; for ( int i = 1 ; i < n ; i ++ ) { f = Math . max ( f , Math . abs ( x [ i ] ) ) ; } return f ; } | L - infinity vector norm . Maximum absolute value . |
11,161 | public static void standardize ( double [ ] x ) { double mu = mean ( x ) ; double sigma = sd ( x ) ; if ( isZero ( sigma ) ) { logger . warn ( "array has variance of 0." ) ; return ; } for ( int i = 0 ; i < x . length ; i ++ ) { x [ i ] = ( x [ i ] - mu ) / sigma ; } } | Standardizes an array to mean 0 and variance 1 . |
11,162 | public static void standardize ( double [ ] [ ] x ) { int n = x . length ; int p = x [ 0 ] . length ; double [ ] center = colMeans ( x ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < p ; j ++ ) { x [ i ] [ j ] = x [ i ] [ j ] - center [ j ] ; } } double [ ] scale = new double [ p ] ; for ( int j = 0 ; j < ... | Standardizes each column of a matrix to 0 mean and unit variance . |
11,163 | public static void unitize1 ( double [ ] x ) { double n = norm1 ( x ) ; for ( int i = 0 ; i < x . length ; i ++ ) { x [ i ] /= n ; } } | Unitize an array so that L1 norm of x is 1 . |
11,164 | public static void unitize2 ( double [ ] x ) { double n = norm ( x ) ; for ( int i = 0 ; i < x . length ; i ++ ) { x [ i ] /= n ; } } | Unitize an array so that L2 norm of x = 1 . |
11,165 | private static int row ( int [ ] r , int f ) { int i = 0 ; while ( i < r . length && r [ i ] < f ) { ++ i ; } return ( ( i < r . length && r [ i ] == f ) ? i : - 1 ) ; } | Returns the index of given frequency . |
11,166 | public static void swap ( int [ ] x , int i , int j ) { int s = x [ i ] ; x [ i ] = x [ j ] ; x [ j ] = s ; } | Swap two elements of an array . |
11,167 | public static < E > void swap ( E [ ] x , E [ ] y ) { if ( x . length != y . length ) { throw new IllegalArgumentException ( String . format ( "Arrays have different length: x[%d], y[%d]" , x . length , y . length ) ) ; } for ( int i = 0 ; i < x . length ; i ++ ) { E s = x [ i ] ; x [ i ] = y [ i ] ; y [ i ] = s ; } } | Swap two arrays . |
11,168 | public static void plus ( double [ ] y , double [ ] x ) { if ( x . length != y . length ) { throw new IllegalArgumentException ( String . format ( "Arrays have different length: x[%d], y[%d]" , x . length , y . length ) ) ; } for ( int i = 0 ; i < x . length ; i ++ ) { y [ i ] += x [ i ] ; } } | Element - wise sum of two arrays y = x + y . |
11,169 | public static void minus ( double [ ] y , double [ ] x ) { if ( x . length != y . length ) { throw new IllegalArgumentException ( String . format ( "Arrays have different length: x[%d], y[%d]" , x . length , y . length ) ) ; } for ( int i = 0 ; i < x . length ; i ++ ) { y [ i ] -= x [ i ] ; } } | Element - wise subtraction of two arrays y = y - x . |
11,170 | public static double [ ] pow ( double [ ] x , double n ) { double [ ] array = new double [ x . length ] ; for ( int i = 0 ; i < x . length ; i ++ ) { array [ i ] = Math . pow ( x [ i ] , n ) ; } return array ; } | Raise each element of an array to a scalar power . |
11,171 | public static int [ ] [ ] sort ( double [ ] [ ] x ) { int n = x . length ; int p = x [ 0 ] . length ; double [ ] a = new double [ n ] ; int [ ] [ ] index = new int [ p ] [ ] ; for ( int j = 0 ; j < p ; j ++ ) { for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = x [ i ] [ j ] ; } index [ j ] = QuickSort . sort ( a ) ; } retur... | Sorts each variable and returns the index of values in ascending order . Note that the order of original array is NOT altered . |
11,172 | public String createInfix ( Expression root ) { String str = "" ; String closeParen = "" ; String leftOpenParen = "" ; String leftCloseParen = "" ; if ( root == null ) { return str ; } if ( ExpressionParser . isOperand ( root . getType ( ) , var ) ) { str += root . getType ( ) ; } else if ( root . getType ( ) . equals ... | creates string representing infix expression |
11,173 | public Expression constructTree ( ArrayList < String > postTokens ) { Expression root = null ; Stack < Expression > nodes = new Stack < > ( ) ; for ( String str : postTokens ) { if ( str . isEmpty ( ) ) { continue ; } if ( str . matches ( "[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?" ) ) { nodes . push ( new Constant ( Dou... | reads the tokens in order from the list and builds a tree |
11,174 | public SVM < T > train ( T [ ] x , int [ ] y , double [ ] weight ) { SVM < T > svm = null ; if ( k == 2 ) { svm = new SVM < > ( kernel , Cp , Cn ) ; } else { if ( this . weight == null ) { svm = new SVM < > ( kernel , Cp , k , strategy ) ; } else { svm = new SVM < > ( kernel , Cp , this . weight , strategy ) ; } } svm ... | Learns a SVM classifier with given training data . |
11,175 | public void learn ( double [ ] [ ] x , int [ ] y ) { if ( model == Model . GENERAL ) { throw new UnsupportedOperationException ( "General-mode Naive Bayes classifier doesn't support online learning." ) ; } if ( model == Model . MULTINOMIAL ) { for ( int i = 0 ; i < x . length ; i ++ ) { if ( x [ i ] . length != p ) { t... | Online learning of naive Bayes classifier on sequences which are modeled as a bag of words . Note that this method is NOT applicable for naive Bayes classifier with general generation model . |
11,176 | private void update ( ) { if ( ! predefinedPriori ) { for ( int c = 0 ; c < k ; c ++ ) { priori [ c ] = ( nc [ c ] + EPSILON ) / ( n + k * EPSILON ) ; } } if ( model == Model . MULTINOMIAL || model == Model . POLYAURN ) { for ( int c = 0 ; c < k ; c ++ ) { for ( int t = 0 ; t < p ; t ++ ) { condprob [ c ] [ t ] = ( ntc... | Update conditional probabilities . |
11,177 | public int predict ( double [ ] x , double [ ] posteriori ) { if ( x . length != p ) { throw new IllegalArgumentException ( String . format ( "Invalid input vector size: %d" , x . length ) ) ; } if ( posteriori != null && posteriori . length != k ) { throw new IllegalArgumentException ( String . format ( "Invalid poste... | Predict the class of an instance . |
11,178 | public double get ( int i ) { for ( Entry e : array ) { if ( e . i == i ) { return e . x ; } } return 0.0 ; } | Returns the value of i - th entry . |
11,179 | public boolean set ( int i , double x ) { if ( x == 0.0 ) { remove ( i ) ; return false ; } Iterator < Entry > it = array . iterator ( ) ; for ( int k = 0 ; it . hasNext ( ) ; k ++ ) { Entry e = it . next ( ) ; if ( e . i == i ) { e . x = x ; return false ; } else if ( e . i > i ) { array . add ( k , new Entry ( i , x ... | Sets or add an entry . |
11,180 | public void remove ( int i ) { Iterator < Entry > it = array . iterator ( ) ; while ( it . hasNext ( ) ) { Entry e = it . next ( ) ; if ( e . i == i ) { it . remove ( ) ; break ; } } } | Removes an entry . |
11,181 | public RandomForest merge ( RandomForest other ) { if ( this . importance . length != other . importance . length ) { throw new IllegalArgumentException ( "RandomForest have different sizes of feature vectors" ) ; } ArrayList < RegressionTree > mergedTrees = new ArrayList < > ( ) ; mergedTrees . addAll ( this . trees )... | Merges together two random forests and returns a new forest consisting of trees from both input forests . |
11,182 | public SparseMatrix parse ( InputStream stream ) throws IOException , ParseException { int nrows = 0 , ncols = 0 , n = 0 ; int [ ] colIndex ; int [ ] rowIndex ; double [ ] data ; try ( Scanner scanner = new Scanner ( stream ) ) { String line = scanner . nextLine ( ) ; String [ ] tokens = line . split ( "\\s+" ) ; if ( ... | Parse a Harwell - Boeing column - compressed sparse matrix dataset from an input stream . |
11,183 | private static Preconditioner diagonalPreconditioner ( Matrix A ) { return new Preconditioner ( ) { public void asolve ( double [ ] b , double [ ] x ) { double [ ] diag = A . diag ( ) ; int n = diag . length ; for ( int i = 0 ; i < n ; i ++ ) { x [ i ] = diag [ i ] != 0.0 ? b [ i ] / diag [ i ] : b [ i ] ; } } } ; } | Returns a simple preconditioner matrix that is the trivial diagonal part of A in some cases . |
11,184 | private static double snorm ( double [ ] x , int itol ) { int n = x . length ; if ( itol <= 3 ) { double ans = 0.0 ; for ( int i = 0 ; i < n ; i ++ ) { ans += x [ i ] * x [ i ] ; } return Math . sqrt ( ans ) ; } else { int isamax = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( Math . abs ( x [ i ] ) > Math . abs ( x [ is... | Compute L2 or L - infinity norms for a vector x as signaled by itol . |
11,185 | public JComponent learn ( ) { JPanel pane = new JPanel ( new GridLayout ( 1 , 2 ) ) ; double [ ] [ ] data = dataset [ datasetIndex ] . toArray ( new double [ dataset [ datasetIndex ] . size ( ) ] [ ] ) ; String [ ] labels = dataset [ datasetIndex ] . toArray ( new String [ dataset [ datasetIndex ] . size ( ) ] ) ; if (... | Execute the MDS algorithm and return a swing JComponent representing the clusters . |
11,186 | public void add ( double [ ] vals ) { ensureCapacity ( size + vals . length ) ; System . arraycopy ( vals , 0 , data , size , vals . length ) ; size += vals . length ; } | Appends an array to the end of this list . |
11,187 | private static double snorm ( double [ ] sx ) { int n = sx . length ; double ans = 0.0 ; for ( int i = 0 ; i < n ; i ++ ) { ans += sx [ i ] * sx [ i ] ; } return Math . sqrt ( ans ) ; } | Compute squared root of L2 norms for a vector . |
11,188 | private void gram ( SupportVector i ) { int n = sv . size ( ) ; int m = MulticoreExecutor . getThreadPoolSize ( ) ; i . kcache = new DoubleArrayList ( n ) ; if ( n < 100 || m < 2 ) { for ( SupportVector v : sv ) { i . kcache . add ( kernel . k ( i . x , v . x ) ) ; } } else { List < KernelTask > tasks = new ArrayList <... | Calculate the row of kernel matrix for a vector i . |
11,189 | private int dfs ( int [ ] [ ] merge , int index , int [ ] order , int i ) { int n = merge . length + 1 ; if ( merge [ index ] [ 0 ] > merge . length ) { i = dfs ( merge , merge [ index ] [ 0 ] - n , order , i ) ; } else { order [ i ++ ] = merge [ index ] [ 0 ] ; } if ( merge [ index ] [ 1 ] > merge . length ) { i = dfs... | DFS the tree to find the order of leafs to avoid the cross of lines in the plot . |
11,190 | public static PlotCanvas plot ( String id , int [ ] [ ] merge , double [ ] height ) { int n = merge . length + 1 ; Dendrogram dendrogram = new Dendrogram ( merge , height ) ; double [ ] lowerBound = { - n / 100 , 0 } ; double [ ] upperBound = { n + n / 100 , 1.01 * dendrogram . getHeight ( ) } ; PlotCanvas canvas = new... | Create a dendrogram plot . |
11,191 | public Date toDate ( double x ) { if ( Double . isNaN ( x ) ) { return null ; } return new Date ( Double . doubleToRawLongBits ( x ) ) ; } | Retruns the date object from internal double encoding . |
11,192 | public Cholesky cholesky ( ) { if ( nrows ( ) != ncols ( ) ) { throw new UnsupportedOperationException ( "Cholesky decomposition on non-square matrix" ) ; } int n = nrows ( ) ; for ( int j = 0 ; j < n ; j ++ ) { double d = 0.0 ; for ( int k = 0 ; k < j ; k ++ ) { double s = 0.0 ; for ( int i = 0 ; i < k ; i ++ ) { s +=... | Cholesky decomposition for symmetric and positive definite matrix . Only the lower triangular part will be used in the decomposition . |
11,193 | public QR qr ( ) { int m = nrows ( ) ; int n = ncols ( ) ; double [ ] rDiagonal = new double [ n ] ; for ( int k = 0 ; k < n ; k ++ ) { double nrm = 0.0 ; for ( int i = k ; i < m ; i ++ ) { nrm = Math . hypot ( nrm , get ( i , k ) ) ; } if ( nrm != 0.0 ) { if ( get ( k , k ) < 0 ) { nrm = - nrm ; } for ( int i = k ; i ... | QR Decomposition is computed by Householder reflections . |
11,194 | private static double [ ] balance ( DenseMatrix A ) { double sqrdx = Math . RADIX * Math . RADIX ; int n = A . nrows ( ) ; double [ ] scale = new double [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { scale [ i ] = 1.0 ; } boolean done = false ; while ( ! done ) { done = true ; for ( int i = 0 ; i < n ; i ++ ) { double r = ... | Given a square matrix this routine replaces it by a balanced matrix with identical eigenvalues . A symmetric matrix is already balanced and is unaffected by this procedure . |
11,195 | private static void balbak ( DenseMatrix V , double [ ] scale ) { int n = V . nrows ( ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { V . mul ( i , j , scale [ i ] ) ; } } } | Form the eigenvectors of a real nonsymmetric matrix by back transforming those of the corresponding balanced matrix determined by balance . |
11,196 | private static int [ ] elmhes ( DenseMatrix A ) { int n = A . nrows ( ) ; int [ ] perm = new int [ n ] ; for ( int m = 1 ; m < n - 1 ; m ++ ) { double x = 0.0 ; int i = m ; for ( int j = m ; j < n ; j ++ ) { if ( Math . abs ( A . get ( j , m - 1 ) ) > Math . abs ( x ) ) { x = A . get ( j , m - 1 ) ; i = j ; } } perm [ ... | Reduce a real nonsymmetric matrix to upper Hessenberg form . |
11,197 | private static void eltran ( DenseMatrix A , DenseMatrix V , int [ ] perm ) { int n = A . nrows ( ) ; for ( int mp = n - 2 ; mp > 0 ; mp -- ) { for ( int k = mp + 1 ; k < n ; k ++ ) { V . set ( k , mp , A . get ( k , mp - 1 ) ) ; } int i = perm [ mp ] ; if ( i != mp ) { for ( int j = mp ; j < n ; j ++ ) { V . set ( mp ... | Accumulate the stabilized elementary similarity transformations used in the reduction of a real nonsymmetric matrix to upper Hessenberg form by elmhes . |
11,198 | private static Complex cdiv ( double xr , double xi , double yr , double yi ) { double cdivr , cdivi ; double r , d ; if ( Math . abs ( yr ) > Math . abs ( yi ) ) { r = yi / yr ; d = yr + r * yi ; cdivr = ( xr + r * xi ) / d ; cdivi = ( xi - r * xr ) / d ; } else { r = yr / yi ; d = yi + r * yr ; cdivr = ( r * xr + xi ... | Complex scalar division . |
11,199 | protected static void sort ( double [ ] d , double [ ] e ) { int i = 0 ; int n = d . length ; for ( int j = 1 ; j < n ; j ++ ) { double real = d [ j ] ; double img = e [ j ] ; for ( i = j - 1 ; i >= 0 ; i -- ) { if ( d [ i ] >= d [ j ] ) { break ; } d [ i + 1 ] = d [ i ] ; e [ i + 1 ] = e [ i ] ; } d [ i + 1 ] = real ;... | Sort eigenvalues . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.