idx
int64
0
41.2k
question
stringlengths
73
5.81k
target
stringlengths
5
918
11,000
public void put ( K [ ] key , V value ) { Node child = root . get ( key [ 0 ] ) ; if ( child == null ) { child = new Node ( key [ 0 ] ) ; root . put ( key [ 0 ] , child ) ; } child . addChild ( key , value , 1 ) ; }
Add a key with associated value to the trie .
11,001
public V get ( K [ ] key ) { Node child = root . get ( key [ 0 ] ) ; if ( child != null ) { return child . getChild ( key , 1 ) ; } return null ; }
Returns the associated value of a given key . Returns null if the key doesn t exist in the trie .
11,002
public DenseMatrix inverse ( ) { int m = lu . nrows ( ) ; int n = lu . ncols ( ) ; if ( m != n ) { throw new IllegalArgumentException ( String . format ( "Matrix is not square: %d x %d" , m , n ) ) ; } DenseMatrix inv = Matrix . zeros ( n , n ) ; for ( int i = 0 ; i < n ; i ++ ) { inv . set ( i , piv [ i ] , 1.0 ) ; } ...
Returns the matrix inverse . For pseudo inverse use QRDecomposition .
11,003
private static double AndersonDarling ( double [ ] x ) { int n = x . length ; Arrays . sort ( x ) ; for ( int i = 0 ; i < n ; i ++ ) { x [ i ] = GaussianDistribution . getInstance ( ) . cdf ( x [ i ] ) ; if ( x [ i ] == 0 ) x [ i ] = 0.0000001 ; if ( x [ i ] == 1 ) x [ i ] = 0.9999999 ; } double A = 0.0 ; for ( int i =...
Calculates the Anderson - Darling statistic for one - dimensional normality test .
11,004
public String get ( String name ) { Parameter param = parameters . get ( name ) ; if ( param != null ) return param . value ; else return null ; }
Returns the value of a given parameter . Null if the parameter does not present .
11,005
private List < String > filterMonadics ( String [ ] args ) { List < String > filteredArgs = new ArrayList < > ( ) ; for ( String arg : args ) { filteredArgs . add ( arg ) ; Parameter param = parameters . get ( arg ) ; if ( param != null && param . paramType == ParameterType . MONADIC ) { filteredArgs . add ( "1" ) ; } ...
Parses the args array looking for monads arguments without value such as - verbose and if found inserts forces a value of 1 and returns the transformed args as a List
11,006
public List < String > parse ( String [ ] args ) { List < String > extras = new ArrayList < > ( ) ; List < String > filteredArgs = filterMonadics ( args ) ; for ( int i = 0 ; i < filteredArgs . size ( ) ; i ++ ) { String key = filteredArgs . get ( i ) ; if ( key . equalsIgnoreCase ( "-h" ) || key . equalsIgnoreCase ( "...
Parse the arguments .
11,007
public DecisionTree [ ] getTrees ( ) { DecisionTree [ ] forest = new DecisionTree [ trees . size ( ) ] ; for ( int i = 0 ; i < forest . length ; i ++ ) forest [ i ] = trees . get ( i ) . tree ; return forest ; }
Returns the decision trees .
11,008
public void setMnemonic ( int mnemonic ) { this . mnemonic = mnemonic ; renderButton . setMnemonic ( mnemonic ) ; editButton . setMnemonic ( mnemonic ) ; }
The mnemonic to activate the button when the cell has focus
11,009
private void add ( Node node , int size , int index , int [ ] itemset , int support ) { if ( node . children == null ) { node . children = new Node [ size ] ; } int item = order [ itemset [ index ] ] ; if ( node . children [ item ] == null ) { node . children [ item ] = new Node ( itemset [ index ] ) ; } if ( index == ...
Inserts a node into a T - tree .
11,010
public int getSupport ( int [ ] itemset ) { if ( root . children != null ) { return getSupport ( itemset , itemset . length - 1 , root ) ; } else { return 0 ; } }
Returns the support value for the given item set .
11,011
private int getSupport ( int [ ] itemset , int index , Node node ) { int item = order [ itemset [ index ] ] ; Node child = node . children [ item ] ; if ( child != null ) { if ( index == 0 ) { return child . support ; } else { if ( child . children != null ) { return getSupport ( itemset , index - 1 , child ) ; } } } r...
Returns the support value for the given item set if found in the T - tree and 0 otherwise .
11,012
private void initTokenizer ( StreamTokenizer tokenizer ) { tokenizer . resetSyntax ( ) ; tokenizer . whitespaceChars ( 0 , ' ' ) ; tokenizer . wordChars ( ' ' + 1 , '\u00FF' ) ; tokenizer . whitespaceChars ( ',' , ',' ) ; tokenizer . commentChar ( '%' ) ; tokenizer . quoteChar ( '"' ) ; tokenizer . quoteChar ( '\'' ) ;...
Initializes the StreamTokenizer used for reading the ARFF file .
11,013
private void getFirstToken ( StreamTokenizer tokenizer ) throws IOException { while ( tokenizer . nextToken ( ) == StreamTokenizer . TT_EOL ) { } if ( ( tokenizer . ttype == '\'' ) || ( tokenizer . ttype == '"' ) ) { tokenizer . ttype = StreamTokenizer . TT_WORD ; } else if ( ( tokenizer . ttype == StreamTokenizer . TT...
Gets next token skipping empty lines .
11,014
private void getLastToken ( StreamTokenizer tokenizer , boolean endOfFileOk ) throws IOException , ParseException { if ( ( tokenizer . nextToken ( ) != StreamTokenizer . TT_EOL ) && ( ( tokenizer . ttype != StreamTokenizer . TT_EOF ) || ! endOfFileOk ) ) { throw new ParseException ( "end of line expected" , tokenizer ....
Gets token and checks if it s end of line .
11,015
private void getNextToken ( StreamTokenizer tokenizer ) throws IOException , ParseException { if ( tokenizer . nextToken ( ) == StreamTokenizer . TT_EOL ) { throw new ParseException ( "premature end of line" , tokenizer . lineno ( ) ) ; } if ( tokenizer . ttype == StreamTokenizer . TT_EOF ) { throw new ParseException (...
Gets next token checking for a premature and of line .
11,016
private String readHeader ( StreamTokenizer tokenizer , List < Attribute > attributes ) throws IOException , ParseException { String relationName = null ; attributes . clear ( ) ; getFirstToken ( tokenizer ) ; if ( tokenizer . ttype == StreamTokenizer . TT_EOF ) { throw new ParseException ( PREMATURE_END_OF_FILE , toke...
Reads and stores header of an ARFF file .
11,017
private Attribute parseAttribute ( StreamTokenizer tokenizer ) throws IOException , ParseException { Attribute attribute = null ; getNextToken ( tokenizer ) ; String attributeName = tokenizer . sval ; getNextToken ( tokenizer ) ; if ( tokenizer . ttype == StreamTokenizer . TT_WORD ) { if ( tokenizer . sval . equalsIgno...
Parses the attribute declaration .
11,018
private void readTillEOL ( StreamTokenizer tokenizer ) throws IOException { while ( tokenizer . nextToken ( ) != StreamTokenizer . TT_EOL ) { } tokenizer . pushBack ( ) ; }
Reads and skips all tokens before next end of line token .
11,019
public static Attribute [ ] getAttributes ( InputStream stream ) throws IOException , ParseException { Reader r = new BufferedReader ( new InputStreamReader ( stream ) ) ; StreamTokenizer tokenizer = new StreamTokenizer ( r ) ; ArffParser parser = new ArffParser ( ) ; parser . initTokenizer ( tokenizer ) ; List < Attri...
Returns the attribute set of given stream .
11,020
public AttributeDataset parse ( InputStream stream ) throws IOException , ParseException { try ( Reader r = new BufferedReader ( new InputStreamReader ( stream ) ) ) { StreamTokenizer tokenizer = new StreamTokenizer ( r ) ; initTokenizer ( tokenizer ) ; List < Attribute > attributes = new ArrayList < > ( ) ; String rel...
Parse a dataset from given stream .
11,021
private void readInstance ( StreamTokenizer tokenizer , AttributeDataset data , Attribute [ ] attributes ) throws IOException , ParseException { double [ ] x = responseIndex >= 0 ? new double [ attributes . length - 1 ] : new double [ attributes . length ] ; double y = Double . NaN ; for ( int i = 0 , k = 0 ; i < attri...
Reads a single instance .
11,022
private void readSparseInstance ( StreamTokenizer tokenizer , AttributeDataset data , Attribute [ ] attributes ) throws IOException , ParseException { double [ ] x = responseIndex >= 0 ? new double [ attributes . length - 1 ] : new double [ attributes . length ] ; double y = Double . NaN ; int index = - 1 ; do { getNex...
Reads a sparse instance using the tokenizer .
11,023
private static double startv ( Matrix A , double [ ] [ ] q , double [ ] [ ] wptr , int step ) { double rnm = Math . dot ( wptr [ 0 ] , wptr [ 0 ] ) ; double [ ] r = wptr [ 0 ] ; for ( int id = 0 ; id < 3 ; id ++ ) { if ( id > 0 || step > 0 || rnm == 0 ) { for ( int i = 0 ; i < r . length ; i ++ ) { r [ i ] = Math . ran...
Generate a starting vector in r and returns |r| . It returns zero if the range is spanned and throws exception if no starting vector within range of operator can be found .
11,024
private static void ortbnd ( double [ ] alf , double [ ] bet , double [ ] eta , double [ ] oldeta , int step , double rnm , double eps ) { if ( step < 1 ) { return ; } if ( 0 != rnm ) { if ( step > 1 ) { oldeta [ 0 ] = ( bet [ 1 ] * eta [ 1 ] + ( alf [ 0 ] - alf [ step ] ) * eta [ 0 ] - bet [ step ] * oldeta [ 0 ] ) / ...
Update the eta recurrence .
11,025
private static double purge ( int ll , double [ ] [ ] Q , double [ ] r , double [ ] q , double [ ] ra , double [ ] qa , double [ ] eta , double [ ] oldeta , int step , double rnm , double tol , double eps , double reps ) { if ( step < ll + 2 ) { return rnm ; } double t , tq , tr ; int k = idamax ( step - ( ll + 1 ) , e...
Examine the state of orthogonality between the new Lanczos vector and the previous ones to decide whether re - orthogonalization should be performed .
11,026
private static int idamax ( int n , double [ ] dx , int ix0 , int incx ) { int ix , imax ; double dmax ; if ( n < 1 ) { return - 1 ; } if ( n == 1 ) { return 0 ; } if ( incx == 0 ) { return - 1 ; } ix = ( incx < 0 ) ? ix0 + ( ( - n + 1 ) * incx ) : ix0 ; imax = ix ; dmax = Math . abs ( dx [ ix ] ) ; for ( int i = 1 ; i...
Find the index of element having maximum absolute value .
11,027
private static void store ( double [ ] [ ] q , int j , double [ ] s ) { if ( null == q [ j ] ) { q [ j ] = s . clone ( ) ; } else { Math . copy ( s , q [ j ] ) ; } }
Based on the input operation flag stores to or retrieves from memory a vector .
11,028
public static double d ( int [ ] x , int [ ] y ) { if ( x . length != y . length ) throw new IllegalArgumentException ( String . format ( "Arrays have different length: x[%d], y[%d]" , x . length , y . length ) ) ; double dist = 0.0 ; for ( int i = 0 ; i < x . length ; i ++ ) { double d = Math . abs ( x [ i ] - y [ i ]...
Chebyshev distance between the two arrays of type integer .
11,029
public void valueChanged ( TreeSelectionEvent e ) { DefaultMutableTreeNode node = ( DefaultMutableTreeNode ) tree . getLastSelectedPathComponent ( ) ; if ( node != null && node . isLeaf ( ) ) { int pos = workspace . getDividerLocation ( ) ; workspace . setTopComponent ( ( JPanel ) node . getUserObject ( ) ) ; workspace...
Required by TreeSelectionListener interface .
11,030
public void learn ( double [ ] [ ] data ) { int p = data [ 0 ] . length ; Attribute [ ] attributes = new Attribute [ p ] ; for ( int i = 0 ; i < p ; i ++ ) { attributes [ i ] = new NumericAttribute ( "V" + i ) ; } learn ( attributes , data ) ; }
Learns transformation parameters from a dataset . All features are assumed numeric .
11,031
public double [ ] [ ] transform ( double [ ] [ ] x ) { double [ ] [ ] y = new double [ x . length ] [ ] ; for ( int i = 0 ; i < y . length ; i ++ ) { y [ i ] = transform ( x [ i ] ) ; } return y ; }
Transform an array of feature vectors .
11,032
public double d ( double [ ] x , double [ ] y ) { if ( x . length != y . length ) throw new IllegalArgumentException ( String . format ( "Arrays have different length: x[%d], y[%d]" , x . length , y . length ) ) ; return 1 - Math . cor ( x , y ) ; }
Pearson correlation distance between the two arrays of type double .
11,033
public static double pearson ( int [ ] x , int [ ] y ) { if ( x . length != y . length ) throw new IllegalArgumentException ( String . format ( "Arrays have different length: x[%d], y[%d]" , x . length , y . length ) ) ; return 1 - Math . cor ( x , y ) ; }
Pearson correlation distance between the two arrays of type int .
11,034
public static double spearman ( int [ ] x , int [ ] y ) { if ( x . length != y . length ) throw new IllegalArgumentException ( String . format ( "Arrays have different length: x[%d], y[%d]" , x . length , y . length ) ) ; return 1 - Math . spearman ( x , y ) ; }
Spearman correlation distance between the two arrays of type int .
11,035
public static double kendall ( int [ ] x , int [ ] y ) { if ( x . length != y . length ) throw new IllegalArgumentException ( String . format ( "Arrays have different length: x[%d], y[%d]" , x . length , y . length ) ) ; return 1 - Math . kendall ( x , y ) ; }
Kendall rank correlation distance between the two arrays of type int .
11,036
public static void swap ( float arr [ ] , int i , int j ) { float a = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = a ; }
Swap two positions .
11,037
private double getNodeCost ( Node node , double [ ] center ) { int d = center . length ; double scatter = 0.0 ; for ( int i = 0 ; i < d ; i ++ ) { double x = ( node . sum [ i ] / node . count ) - center [ i ] ; scatter += x * x ; } return node . cost + node . count * scatter ; }
Returns the total contribution of all data in the given kd - tree node assuming they are all assigned to a mean at the given location .
11,038
public double clustering ( double [ ] [ ] centroids , double [ ] [ ] sums , int [ ] counts , int [ ] membership ) { int k = centroids . length ; Arrays . fill ( counts , 0 ) ; int [ ] candidates = new int [ k ] ; for ( int i = 0 ; i < k ; i ++ ) { candidates [ i ] = i ; Arrays . fill ( sums [ i ] , 0.0 ) ; } return fil...
Given k cluster centroids this method assigns data to nearest centroids . The return value is the distortion to the centroids . The parameter sums will hold the sum of data for each cluster . The parameter counts hold the number of data of each cluster . If membership is not null it should be an array of size n that wi...
11,039
static void columnAverageImpute ( double [ ] [ ] data ) throws MissingValueImputationException { for ( int j = 0 ; j < data [ 0 ] . length ; j ++ ) { int n = 0 ; double sum = 0.0 ; for ( int i = 0 ; i < data . length ; i ++ ) { if ( ! Double . isNaN ( data [ i ] [ j ] ) ) { n ++ ; sum += data [ i ] [ j ] ; } } if ( n =...
Impute the missing values with column averages .
11,040
public static < T > double loocv ( ClassifierTrainer < T > trainer , T [ ] x , int [ ] y ) { int m = 0 ; int n = x . length ; LOOCV loocv = new LOOCV ( n ) ; for ( int i = 0 ; i < n ; i ++ ) { T [ ] trainx = Math . slice ( x , loocv . train [ i ] ) ; int [ ] trainy = Math . slice ( y , loocv . train [ i ] ) ; Classifie...
Leave - one - out cross validation of a classification model .
11,041
public static < T > double cv ( int k , ClassifierTrainer < T > trainer , T [ ] x , int [ ] y , ClassificationMeasure measure ) { if ( k < 2 ) { throw new IllegalArgumentException ( "Invalid k for k-fold cross validation: " + k ) ; } int n = x . length ; int [ ] predictions = new int [ n ] ; CrossValidation cv = new Cr...
Cross validation of a classification model .
11,042
public static < T > double cv ( int k , RegressionTrainer < T > trainer , T [ ] x , double [ ] y , RegressionMeasure measure ) { if ( k < 2 ) { throw new IllegalArgumentException ( "Invalid k for k-fold cross validation: " + k ) ; } int n = x . length ; double [ ] predictions = new double [ n ] ; CrossValidation cv = n...
Cross validation of a regression model .
11,043
public static < T > double [ ] bootstrap ( int k , ClassifierTrainer < T > trainer , T [ ] x , int [ ] y ) { if ( k < 2 ) { throw new IllegalArgumentException ( "Invalid k for k-fold bootstrap: " + k ) ; } int n = x . length ; double [ ] results = new double [ k ] ; Accuracy measure = new Accuracy ( ) ; Bootstrap boots...
Bootstrap accuracy estimation of a classification model .
11,044
public static < T > double [ ] bootstrap ( int k , RegressionTrainer < T > trainer , T [ ] x , double [ ] y , RegressionMeasure measure ) { if ( k < 2 ) { throw new IllegalArgumentException ( "Invalid k for k-fold bootstrap: " + k ) ; } int n = x . length ; double [ ] results = new double [ k ] ; Bootstrap bootstrap = ...
Bootstrap performance estimation of a regression model .
11,045
public SparseMatrix toSparseMatrix ( ) { int [ ] pos = new int [ numColumns ] ; int [ ] colIndex = new int [ numColumns + 1 ] ; for ( int i = 0 ; i < numColumns ; i ++ ) { colIndex [ i + 1 ] = colIndex [ i ] + colSize [ i ] ; } int nrows = size ( ) ; int [ ] rowIndex = new int [ n ] ; double [ ] x = new double [ n ] ; ...
Convert into Harwell - Boeing column - compressed sparse matrix format .
11,046
public Text add ( String id , String title , String body ) { ArrayList < String > bag = new ArrayList < > ( ) ; for ( String sentence : splitter . split ( body ) ) { String [ ] tokens = tokenizer . split ( sentence ) ; for ( int i = 0 ; i < tokens . length ; i ++ ) { tokens [ i ] = tokens [ i ] . toLowerCase ( ) ; } fo...
Add a document to the corpus .
11,047
public double [ ] dijkstra ( int s , boolean weighted ) { double [ ] wt = new double [ n ] ; Arrays . fill ( wt , Double . POSITIVE_INFINITY ) ; PriorityQueue queue = new PriorityQueue ( wt ) ; for ( int v = 0 ; v < n ; v ++ ) { queue . insert ( v ) ; } wt [ s ] = 0.0 ; queue . lower ( s ) ; while ( ! queue . empty ( )...
Calculates the shortest path by Dijkstra algorithm .
11,048
public double [ ] [ ] sample ( int n ) { double [ ] [ ] samples = new double [ 2 * n ] [ ] ; MultivariateGaussianDistribution [ ] gauss = new MultivariateGaussianDistribution [ k ] ; for ( int i = 0 ; i < k ; i ++ ) { gauss [ i ] = new MultivariateGaussianDistribution ( m [ i ] , v ) ; } for ( int i = 0 ; i < n ; i ++ ...
Generate n samples from each class .
11,049
public int purge ( int minPts ) { List < Neuron > outliers = new ArrayList < > ( ) ; for ( Neuron neuron : neurons ) { if ( neuron . n < minPts ) { outliers . add ( neuron ) ; } } neurons . removeAll ( outliers ) ; for ( Neuron neuron : neurons ) { neuron . neighbors . removeAll ( outliers ) ; } outliers . clear ( ) ; ...
Removes neurons with the number of samples less than a given threshold . The neurons without neighbors will also be removed .
11,050
private double bic ( int n , int d , double distortion ) { double variance = distortion / ( n - 1 ) ; double p1 = - n * LOG2PI ; double p2 = - n * d * Math . log ( variance ) ; double p3 = - ( n - 1 ) ; double L = ( p1 + p2 + p3 ) / 2 ; int numParameters = d + 1 ; return L - 0.5 * numParameters * Math . log ( n ) ; }
Calculates the BIC for single cluster .
11,051
private double bic ( int k , int n , int d , double distortion , int [ ] clusterSize ) { double variance = distortion / ( n - k ) ; double L = 0.0 ; for ( int i = 0 ; i < k ; i ++ ) { L += logLikelihood ( k , n , clusterSize [ i ] , d , variance ) ; } int numParameters = k + k * d ; return L - 0.5 * numParameters * Mat...
Calculates the BIC for the given set of centers .
11,052
private static double logLikelihood ( int k , int n , int ni , int d , double variance ) { double p1 = - ni * LOG2PI ; double p2 = - ni * d * Math . log ( variance ) ; double p3 = - ( ni - k ) ; double p4 = ni * Math . log ( ni ) ; double p5 = - ni * Math . log ( n ) ; double loglike = ( p1 + p2 + p3 ) / 2 + p4 + p5 ; ...
Estimate the log - likelihood of the data for the given model .
11,053
public void nextDoubles ( double [ ] d , double lo , double hi ) { real . nextDoubles ( d ) ; double l = hi - lo ; int n = d . length ; for ( int i = 0 ; i < n ; i ++ ) { d [ i ] = lo + l * d [ i ] ; } }
Generate n uniform random numbers in the range [ lo hi )
11,054
public int [ ] permutate ( int n ) { int [ ] x = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { x [ i ] = i ; } permutate ( x ) ; return x ; }
Generates a permutation of 0 1 2 ... n - 1 which is useful for sampling without replacement .
11,055
public void add ( double [ ] x ) { if ( root == null ) { root = new Node ( ) ; root . add ( new Leaf ( x ) ) ; root . update ( x ) ; } else { root . add ( x ) ; } }
Add a data point into CF tree .
11,056
public void setGraphics ( java . awt . Graphics2D g2d ) { this . g2d = g2d ; g2d . setRenderingHint ( RenderingHints . KEY_ANTIALIASING , RenderingHints . VALUE_ANTIALIAS_ON ) ; g2d . setRenderingHint ( RenderingHints . KEY_RENDERING , RenderingHints . VALUE_RENDER_QUALITY ) ; }
Set the Java2D graphics object .
11,057
public void clip ( ) { int x = ( int ) ( projection . canvas . getWidth ( ) * projection . canvas . margin ) ; int y = ( int ) ( projection . canvas . getHeight ( ) * projection . canvas . margin ) ; int w = ( int ) ( projection . canvas . getWidth ( ) * ( 1 - 2 * projection . canvas . margin ) ) ; int h = ( int ) ( pr...
Restrict the draw area to the valid base coordinate space .
11,058
private void drawLine ( int [ ] ... coord ) { int [ ] x = new int [ coord . length ] ; for ( int i = 0 ; i < coord . length ; i ++ ) { x [ i ] = coord [ i ] [ 0 ] ; } int [ ] y = new int [ coord . length ] ; for ( int i = 0 ; i < coord . length ; i ++ ) { y [ i ] = coord [ i ] [ 1 ] ; } g2d . drawPolyline ( x , y , coo...
Draw poly line .
11,059
public void drawLine ( double [ ] ... coord ) { int [ ] [ ] sc = new int [ coord . length ] [ ] ; for ( int i = 0 ; i < sc . length ; i ++ ) { sc [ i ] = projection . screenProjection ( coord [ i ] ) ; } drawLine ( sc ) ; }
Draw poly line . The coordinates are in logical coordinates .
11,060
public void drawLineBaseRatio ( double [ ] ... coord ) { int [ ] [ ] sc = new int [ coord . length ] [ ] ; for ( int i = 0 ; i < sc . length ; i ++ ) { sc [ i ] = projection . screenProjectionBaseRatio ( coord [ i ] ) ; } drawLine ( sc ) ; }
Draw poly line . The logical coordinates are proportional to the base coordinates .
11,061
public void drawPoint ( char dot , double ... coord ) { int size = 2 ; int midSize = 3 ; int bigSize = 4 ; int [ ] sc = projection . screenProjection ( coord ) ; int x = sc [ 0 ] ; int y = sc [ 1 ] ; switch ( dot ) { case '+' : g2d . drawLine ( x - size , y , x + size , y ) ; g2d . drawLine ( x , y - size , x , y + siz...
Draw a dot with given pattern . The coordinates are in logical coordinates .
11,062
public void fillPolygon ( double [ ] ... coord ) { int [ ] [ ] c = new int [ coord . length ] [ 2 ] ; for ( int i = 0 ; i < coord . length ; i ++ ) { c [ i ] = projection . screenProjection ( coord [ i ] ) ; } int [ ] x = new int [ c . length ] ; for ( int i = 0 ; i < c . length ; i ++ ) { x [ i ] = c [ i ] [ 0 ] ; } i...
Fill polygon . The coordinates are in logical coordinates .
11,063
public void fillPolygon ( float alpha , double [ ] ... coord ) { int [ ] [ ] c = new int [ coord . length ] [ 2 ] ; for ( int i = 0 ; i < coord . length ; i ++ ) { c [ i ] = projection . screenProjection ( coord [ i ] ) ; } int [ ] x = new int [ c . length ] ; for ( int i = 0 ; i < c . length ; i ++ ) { x [ i ] = c [ i...
Fill polygon . The coordinates are in logical coordinates . This also supports basic alpha compositing rules for combining source and destination colors to achieve blending and transparency effects with graphics and images .
11,064
public void drawRect ( double [ ] topLeft , double [ ] rightBottom ) { if ( ! ( projection instanceof Projection2D ) ) { throw new UnsupportedOperationException ( "Only 2D graphics supports drawing rectangles." ) ; } int [ ] sc = projection . screenProjection ( topLeft ) ; int [ ] sc2 = projection . screenProjection ( ...
Draw the outline of the specified rectangle .
11,065
public void drawRectBaseRatio ( double [ ] topLeft , double [ ] rightBottom ) { if ( ! ( projection instanceof Projection2D ) ) { throw new UnsupportedOperationException ( "Only 2D graphics supports drawing rectangles." ) ; } int [ ] sc = projection . screenProjectionBaseRatio ( topLeft ) ; int [ ] sc2 = projection . s...
Draw the outline of the specified rectangle . The logical coordinates are proportional to the base coordinates .
11,066
public void fillRectBaseRatio ( double [ ] topLeft , double [ ] rightBottom ) { if ( ! ( projection instanceof Projection2D ) ) { throw new UnsupportedOperationException ( "Only 2D graphics supports drawing rectangles." ) ; } int [ ] sc = projection . screenProjectionBaseRatio ( topLeft ) ; int [ ] sc2 = projection . s...
Fill the specified rectangle . The logical coordinates are proportional to the base coordinates .
11,067
public void rotate ( double x , double y ) { if ( ! ( projection instanceof Projection3D ) ) { throw new UnsupportedOperationException ( "Only 3D graphics supports rotation." ) ; } ( ( Projection3D ) projection ) . rotate ( x , y ) ; }
Rotate the 3D view based on the changes on mouse position .
11,068
public double learn ( double [ ] x ) { if ( x . length != n ) { throw new IllegalArgumentException ( String . format ( "Invalid input vector size: %d, expected: %d" , x . length , n ) ) ; } projection . ax ( x , y ) ; for ( int j = 0 ; j < p ; j ++ ) { for ( int i = 0 ; i < n ; i ++ ) { double delta = x [ i ] ; for ( i...
Update the model with a new sample .
11,069
private static RadialBasisFunction [ ] rep ( RadialBasisFunction rbf , int k ) { RadialBasisFunction [ ] arr = new RadialBasisFunction [ k ] ; Arrays . fill ( arr , rbf ) ; return arr ; }
Returns an array of radial basis functions initialized with given values .
11,070
public DenseMatrix getS ( ) { DenseMatrix S = Matrix . zeros ( U . nrows ( ) , V . nrows ( ) ) ; for ( int i = 0 ; i < s . length ; i ++ ) { S . set ( i , i , s [ i ] ) ; } return S ; }
Returns the diagonal matrix of singular values
11,071
public int rank ( ) { if ( ! full ) { throw new IllegalStateException ( "This is not a FULL singular value decomposition." ) ; } int r = 0 ; for ( int i = 0 ; i < s . length ; i ++ ) { if ( s [ i ] > tol ) { r ++ ; } } return r ; }
Returns the effective numerical matrix rank . The number of nonnegligible singular values .
11,072
public int nullity ( ) { if ( ! full ) { throw new IllegalStateException ( "This is not a FULL singular value decomposition." ) ; } int r = 0 ; for ( int i = 0 ; i < s . length ; i ++ ) { if ( s [ i ] <= tol ) { r ++ ; } } return r ; }
Returns the dimension of null space . The number of negligible singular values .
11,073
public DenseMatrix range ( ) { if ( ! full ) { throw new IllegalStateException ( "This is not a FULL singular value decomposition." ) ; } int nr = 0 ; DenseMatrix rnge = Matrix . zeros ( m , rank ( ) ) ; for ( int j = 0 ; j < n ; j ++ ) { if ( s [ j ] > tol ) { for ( int i = 0 ; i < m ; i ++ ) { rnge . set ( i , nr , U...
Returns a matrix of which columns give an orthonormal basis for the range space .
11,074
public DenseMatrix nullspace ( ) { if ( ! full ) { throw new IllegalStateException ( "This is not a FULL singular value decomposition." ) ; } int nn = 0 ; DenseMatrix nullsp = Matrix . zeros ( n , nullity ( ) ) ; for ( int j = 0 ; j < n ; j ++ ) { if ( s [ j ] <= tol ) { for ( int jj = 0 ; jj < n ; jj ++ ) { nullsp . s...
Returns a matrix of which columns give an orthonormal basis for the null space .
11,075
public void ensureCapacity ( int capacity ) { if ( capacity > data . length ) { int newCap = Math . max ( data . length << 1 , capacity ) ; int [ ] tmp = new int [ newCap ] ; System . arraycopy ( data , 0 , tmp , 0 , data . length ) ; data = tmp ; } }
Increases the capacity if necessary to ensure that it can hold at least the number of values specified by the minimum capacity argument .
11,076
public IntArrayList set ( int index , int val ) { if ( index < 0 || index >= size ) { throw new IndexOutOfBoundsException ( String . valueOf ( index ) ) ; } data [ index ] = val ; return this ; }
Replaces the value at the specified position in this list with the specified value .
11,077
public int remove ( int index ) { if ( index < 0 || index >= size ) { throw new IndexOutOfBoundsException ( String . valueOf ( index ) ) ; } int old = get ( index ) ; if ( index == 0 ) { System . arraycopy ( data , 1 , data , 0 , size - 1 ) ; } else if ( size - 1 == index ) { } else { System . arraycopy ( data , index ...
Removes the value at specified index from the list .
11,078
private double rdist ( double [ ] x1 , double [ ] x2 ) { double d = 0.0 ; for ( int i = 0 ; i < x1 . length ; i ++ ) { double t = x1 [ i ] - x2 [ i ] ; d += t * t ; } return Math . sqrt ( d ) ; }
Cartesian distance .
11,079
public static double [ ] [ ] histogram ( int [ ] data , double [ ] breaks ) { int k = breaks . length - 1 ; if ( k <= 1 ) { throw new IllegalArgumentException ( "Invalid number of bins: " + k ) ; } double [ ] [ ] freq = new double [ 3 ] [ k ] ; for ( int i = 0 ; i < k ; i ++ ) { freq [ 0 ] [ i ] = breaks [ i ] ; freq [...
Generate the histogram of n bins .
11,080
public static double [ ] breaks ( double [ ] x , double h ) { return breaks ( Math . min ( x ) , Math . max ( x ) , h ) ; }
Returns the breakpoints between histogram cells for a dataset based on a suggested bin width h .
11,081
public static double [ ] breaks ( double min , double max , double h ) { if ( h <= 0.0 ) { throw new IllegalArgumentException ( "Invalid bin width: " + h ) ; } if ( min > max ) { throw new IllegalArgumentException ( "Invalid lower and upper bounds: " + min + " > " + max ) ; } int k = ( int ) Math . ceil ( ( max - min )...
Returns the breakpoints between histogram cells for a given range based on a suggested bin width h .
11,082
public static double [ ] breaks ( double [ ] x , int k ) { return breaks ( Math . min ( x ) , Math . max ( x ) , k ) ; }
Returns the breakpoints between histogram cells for a dataset .
11,083
public static double [ ] breaks ( double min , double max , int k ) { if ( k <= 1 ) { throw new IllegalArgumentException ( "Invalid number of bins: " + k ) ; } if ( min > max ) { throw new IllegalArgumentException ( "Invalid lower and upper bounds: " + min + " > " + max ) ; } double h = ( max - min ) / k ; return break...
Returns the breakpoints between histogram cells for a given range .
11,084
public static int bins ( double [ ] x , double h ) { if ( h <= 0.0 ) { throw new IllegalArgumentException ( "Invalid bin width: " + h ) ; } double max = Math . max ( x ) ; double min = Math . min ( x ) ; return ( int ) Math . ceil ( ( max - min ) / h ) ; }
Returns the number of bins for a data based on a suggested bin width h .
11,085
public BitString [ ] learn ( int size , int generation , ClassifierTrainer < double [ ] > trainer , ClassificationMeasure measure , double [ ] [ ] x , int [ ] y , int k ) { if ( size <= 0 ) { throw new IllegalArgumentException ( "Invalid population size: " + size ) ; } if ( k < 2 ) { throw new IllegalArgumentException ...
Genetic algorithm based feature selection for classification .
11,086
public double valueOf ( String s ) throws ParseException { Integer i = map . get ( s ) ; if ( i == null ) { if ( open ) { i = values . size ( ) ; map . put ( s , i ) ; values . add ( s ) ; } else { throw new ParseException ( "Invalid string value: " + s , 0 ) ; } } return i ; }
Returns the ordinal value of a string value .
11,087
private void initBaseCoordsProjection ( ) { baseScreenCoords = new int [ canvas . base . baseCoords . length ] [ 2 ] ; for ( int i = 0 ; i < canvas . base . dimension + 1 ; i ++ ) { double [ ] ratio = baseCoordsScreenProjectionRatio ( canvas . base . baseCoords [ i ] ) ; baseScreenCoords [ i ] [ 0 ] = ( int ) ( canvas ...
Initialize base coordinates on Java2D screen .
11,088
public int [ ] screenProjection ( double ... coord ) { double [ ] sc = new double [ 2 ] ; sc [ 0 ] = baseScreenCoords [ 0 ] [ 0 ] ; sc [ 1 ] = baseScreenCoords [ 0 ] [ 1 ] ; for ( int i = 0 ; i < canvas . base . dimension ; i ++ ) { sc [ 0 ] += ( ( coord [ i ] - canvas . base . baseCoords [ 0 ] [ i ] ) / ( canvas . bas...
Project logical coordinates to Java2D coordinates .
11,089
public int [ ] screenProjectionBaseRatio ( double ... coord ) { double [ ] sc = new double [ 2 ] ; sc [ 0 ] = baseScreenCoords [ 0 ] [ 0 ] ; sc [ 1 ] = baseScreenCoords [ 0 ] [ 1 ] ; for ( int i = 0 ; i < canvas . base . dimension ; i ++ ) { sc [ 0 ] += coord [ i ] * ( baseScreenCoords [ i + 1 ] [ 0 ] - baseScreenCoord...
Project logical coordinates in base ratio to Java2D coordinates .
11,090
public double logLikelihood ( double [ ] x ) { double L = 0.0 ; for ( double xi : x ) L += logp ( xi ) ; return L ; }
The likelihood given a sample set following the distribution .
11,091
private static void createThreadPool ( ) { if ( nprocs == - 1 ) { int n = - 1 ; try { String env = System . getProperty ( "smile.threads" ) ; if ( env != null ) { n = Integer . parseInt ( env ) ; } } catch ( Exception ex ) { logger . error ( "Failed to create multi-core execution thread pool" , ex ) ; } if ( n < 1 ) { ...
Creates the worker thread pool .
11,092
public static < T > List < T > run ( Collection < ? extends Callable < T > > tasks ) throws Exception { createThreadPool ( ) ; List < T > results = new ArrayList < > ( ) ; if ( threads == null ) { for ( Callable < T > task : tasks ) { results . add ( task . call ( ) ) ; } } else { if ( threads . getActiveCount ( ) < np...
Executes the given tasks serially or parallel depending on the number of cores of the system . Returns a list of result objects of each task . The results of this method are undefined if the given collection is modified while this operation is in progress .
11,093
public static PlotCanvas plot ( String id , double [ ] data ) { Histogram histogram = new Histogram ( data ) ; histogram . setID ( id ) ; double [ ] lowerBound = { Math . min ( data ) , 0 } ; double [ ] upperBound = { Math . max ( data ) , 0 } ; double [ ] [ ] freq = histogram . getHistogram ( ) ; for ( int i = 0 ; i <...
Create a plot canvas with the histogram plot .
11,094
TotalSupportTree buildTotalSupportTree ( ) { TotalSupportTree ttree = new TotalSupportTree ( minSupport , T0 . numFreqItems , T0 . order ) ; learn ( null , null , ttree ) ; return ttree ; }
Mines the frequent item sets . The discovered frequent item sets will be stored in a total support tree .
11,095
private long learn ( PrintStream out , List < ItemSet > list , TotalSupportTree ttree ) { if ( MulticoreExecutor . getThreadPoolSize ( ) > 1 ) { return grow ( out , list , ttree , T0 , null , null , null ) ; } else { return grow ( out , list , ttree , T0 , null ) ; } }
Mines the frequent item sets . The discovered frequent item sets will be printed out to the provided stream .
11,096
private void collect ( PrintStream out , List < ItemSet > list , TotalSupportTree ttree , int [ ] itemset , int support ) { if ( list != null ) { synchronized ( list ) { list . add ( new ItemSet ( itemset , support ) ) ; } } if ( out != null ) { synchronized ( out ) { for ( int i = 0 ; i < itemset . length ; i ++ ) { o...
Adds an item set to the result .
11,097
private long grow ( PrintStream out , List < ItemSet > list , TotalSupportTree ttree , FPTree . Node node , int [ ] itemset , int support ) { int height = 0 ; for ( FPTree . Node currentNode = node ; currentNode != null ; currentNode = currentNode . parent ) { height ++ ; } int n = 0 ; if ( height > 0 ) { int [ ] items...
Mines all combinations along a single path tree
11,098
private long grow ( PrintStream out , List < ItemSet > list , TotalSupportTree ttree , HeaderTableItem header , int [ ] itemset , int [ ] localItemSupport , int [ ] prefixItemset ) { long n = 1 ; int support = header . count ; int item = header . id ; itemset = insert ( itemset , item ) ; collect ( out , list , ttree ,...
Mines FP - tree with respect to a single element in the header table .
11,099
private boolean getLocalItemSupport ( FPTree . Node node , int [ ] localItemSupport ) { boolean end = true ; Arrays . fill ( localItemSupport , 0 ) ; while ( node != null ) { int support = node . count ; Node parent = node . parent ; while ( parent != null ) { localItemSupport [ parent . id ] += support ; parent = pare...
Counts the supports of single items in ancestor item sets linked list .