idx
int64
0
41.2k
question
stringlengths
73
5.81k
target
stringlengths
5
918
10,800
public static String generateStringExample ( String format , List < String > enumValues ) { if ( enumValues == null || enumValues . isEmpty ( ) ) { if ( format == null ) { return "string" ; } else { switch ( format ) { case "byte" : return "Ynl0ZQ==" ; case "date" : return "1970-01-01" ; case "date-time" : return "1970...
Generates examples for string properties or parameters with given format
10,801
public static Integer generateIntegerExample ( List < Integer > enumValues ) { if ( enumValues == null || enumValues . isEmpty ( ) ) { return 0 ; } else { return enumValues . get ( 0 ) ; } }
Generates examples for integer properties - if there are enums it uses first enum value returns 0 otherwise .
10,802
private static Map < HttpMethod , Operation > getOperationMap ( Path path ) { Map < HttpMethod , Operation > result = new LinkedHashMap < > ( ) ; if ( path . getGet ( ) != null ) { result . put ( HttpMethod . GET , path . getGet ( ) ) ; } if ( path . getPut ( ) != null ) { result . put ( HttpMethod . PUT , path . getPu...
Returns the operations of a path as a map which preserves the insertion order .
10,803
public static List < PathOperation > toPathOperationsList ( Map < String , Path > paths , String host , String basePath , Comparator < PathOperation > comparator ) { List < PathOperation > pathOperations = new ArrayList < > ( ) ; paths . forEach ( ( relativePath , path ) -> pathOperations . addAll ( toPathOperationsLis...
Converts the Swagger paths into a list of PathOperations .
10,804
public static List < PathOperation > toPathOperationsList ( String path , Path pathModel ) { List < PathOperation > pathOperations = new ArrayList < > ( ) ; getOperationMap ( pathModel ) . forEach ( ( httpMethod , operation ) -> pathOperations . add ( new PathOperation ( httpMethod , path , operation ) ) ) ; return pat...
Converts a Swagger path into a PathOperation .
10,805
public String getTitle ( ) { String operationName = operation . getSummary ( ) ; if ( isBlank ( operationName ) ) { operationName = getMethod ( ) . toString ( ) + " " + getPath ( ) ; } return operationName ; }
Returns the display title for an operation
10,806
public MarkupDocBuilder apply ( MarkupDocBuilder markupDocBuilder , OverviewDocument . Parameters params ) { Swagger swagger = params . swagger ; Info info = swagger . getInfo ( ) ; buildDocumentTitle ( markupDocBuilder , info . getTitle ( ) ) ; applyOverviewDocumentExtension ( new Context ( Position . DOCUMENT_BEFORE ...
Builds the overview MarkupDocument .
10,807
private void applyOverviewDocumentExtension ( Context context ) { extensionRegistry . getOverviewDocumentExtensions ( ) . forEach ( extension -> extension . apply ( context ) ) ; }
Apply extension context to all OverviewContentExtension
10,808
public MarkupDocBuilder apply ( MarkupDocBuilder markupDocBuilder , DefinitionsDocument . Parameters params ) { Map < String , Model > definitions = params . definitions ; if ( MapUtils . isNotEmpty ( definitions ) ) { applyDefinitionsDocumentExtension ( new Context ( Position . DOCUMENT_BEFORE , markupDocBuilder ) ) ;...
Builds the definitions MarkupDocument .
10,809
private void applyDefinitionsDocumentExtension ( Context context ) { extensionRegistry . getDefinitionsDocumentExtensions ( ) . forEach ( extension -> extension . apply ( context ) ) ; }
Apply extension context to all DefinitionsContentExtension
10,810
private void buildDefinition ( MarkupDocBuilder markupDocBuilder , String definitionName , Model model ) { if ( logger . isDebugEnabled ( ) ) { logger . debug ( "Definition processed : '{}'" , definitionName ) ; } if ( config . isSeparatedDefinitionsEnabled ( ) ) { MarkupDocBuilder defDocBuilder = copyMarkupDocBuilder ...
Generate definition files depending on the generation mode
10,811
private void applyDefinitionComponent ( MarkupDocBuilder markupDocBuilder , String definitionName , Model model ) { definitionComponent . apply ( markupDocBuilder , DefinitionComponent . parameters ( definitionName , model , 2 ) ) ; }
Builds a concrete definition
10,812
private void definitionRef ( MarkupDocBuilder markupDocBuilder , String definitionName ) { buildDefinitionTitle ( markupDocBuilder , crossReference ( markupDocBuilder , definitionDocumentResolverDefault . apply ( definitionName ) , definitionName , definitionName ) , "ref-" + definitionName ) ; }
Builds a cross - reference to a separated definition file .
10,813
private void buildDefinitionTitle ( MarkupDocBuilder markupDocBuilder , String title , String anchor ) { markupDocBuilder . sectionTitleWithAnchorLevel2 ( title , anchor ) ; }
Builds definition title
10,814
public static Object generateExample ( AbstractSerializableParameter < ? > parameter ) { switch ( parameter . getType ( ) ) { case "integer" : return 0 ; case "number" : return 0.0 ; case "boolean" : return true ; case "string" : return ExamplesUtil . generateStringExample ( parameter . getFormat ( ) , parameter . getE...
Generate a default example value for parameter .
10,815
private Type getType ( Map < String , Model > definitions , DocumentResolver definitionDocumentResolver ) { Validate . notNull ( parameter , "parameter must not be null!" ) ; Type type = null ; if ( parameter instanceof BodyParameter ) { BodyParameter bodyParameter = ( BodyParameter ) parameter ; Model model = bodyPara...
Retrieves the type of a parameter or otherwise null
10,816
public Optional < Object > getDefaultValue ( ) { Validate . notNull ( parameter , "parameter must not be null!" ) ; if ( parameter instanceof AbstractSerializableParameter ) { AbstractSerializableParameter serializableParameter = ( AbstractSerializableParameter ) parameter ; return Optional . ofNullable ( serializableP...
Retrieves the default value of a parameter
10,817
public static PlotCanvas plot ( SparseMatrix sparse ) { double [ ] lowerBound = { 0 , 0 } ; double [ ] upperBound = { sparse . ncols ( ) , sparse . nrows ( ) } ; PlotCanvas canvas = new PlotCanvas ( lowerBound , upperBound , false ) ; canvas . add ( new SparseMatrixPlot ( sparse ) ) ; canvas . getAxis ( 0 ) . setLabelV...
Create a sparse matrix plot canvas .
10,818
public BaseGrid setFrameVisible ( boolean v ) { for ( int i = 0 ; i < axis . length ; i ++ ) { axis [ i ] . setGridVisible ( v ) ; } return this ; }
Set if the frame visible .
10,819
public BaseGrid setAxisLabel ( String ... axisLabels ) { if ( axisLabels . length != base . getDimension ( ) ) { throw new IllegalArgumentException ( "Axis label size don't match base dimension." ) ; } for ( int i = 0 ; i < axisLabels . length ; i ++ ) { axis [ i ] . setAxisLabel ( axisLabels [ i ] ) ; } return this ; ...
Set axis labels .
10,820
public String [ ] getAxisLabel ( ) { String [ ] array = new String [ axis . length ] ; for ( int i = 0 ; i < array . length ; i ++ ) { array [ i ] = axis [ i ] . getAxisLabel ( ) ; } return array ; }
Get axis label .
10,821
public void paint ( Graphics g ) { for ( int i = 0 ; i < axis . length ; i ++ ) { axis [ i ] . paint ( g ) ; } }
Draw the grid .
10,822
public long learn ( double confidence , PrintStream out ) { long n = 0 ; ttree = fim . buildTotalSupportTree ( ) ; for ( int i = 0 ; i < ttree . root . children . length ; i ++ ) { if ( ttree . root . children [ i ] != null ) { int [ ] itemset = { ttree . root . children [ i ] . id } ; n += learn ( out , null , itemset...
Mines the association rules . The discovered rules will be printed out to the provided stream .
10,823
public List < AssociationRule > learn ( double confidence ) { List < AssociationRule > list = new ArrayList < > ( ) ; ttree = fim . buildTotalSupportTree ( ) ; for ( int i = 0 ; i < ttree . root . children . length ; i ++ ) { if ( ttree . root . children [ i ] != null ) { int [ ] itemset = { ttree . root . children [ i...
Mines the association rules . The discovered frequent rules will be returned in a list .
10,824
private long learn ( PrintStream out , List < AssociationRule > list , int [ ] itemset , int size , Node node , double confidence ) { long n = 0 ; if ( node . children == null ) { return n ; } for ( int i = 0 ; i < size ; i ++ ) { if ( node . children [ i ] != null ) { int [ ] newItemset = FPGrowth . insert ( itemset ,...
Generates association rules from a T - tree .
10,825
private long learn ( PrintStream out , List < AssociationRule > list , int [ ] itemset , int support , double confidence ) { long n = 0 ; int [ ] [ ] combinations = getPowerSet ( itemset ) ; for ( int i = 0 ; i < combinations . length ; i ++ ) { int [ ] complement = getComplement ( combinations [ i ] , itemset ) ; if (...
Generates all association rules for a given item set .
10,826
private static int [ ] getComplement ( int [ ] subset , int [ ] fullset ) { int size = fullset . length - subset . length ; if ( size < 1 ) { return null ; } int [ ] complement = new int [ size ] ; int index = 0 ; for ( int i = 0 ; i < fullset . length ; i ++ ) { int item = fullset [ i ] ; boolean member = false ; for ...
Returns the complement of subset .
10,827
private static int [ ] [ ] getPowerSet ( int [ ] set ) { int [ ] [ ] sets = new int [ getPowerSetSize ( set . length ) ] [ ] ; getPowerSet ( set , 0 , null , sets , 0 ) ; return sets ; }
Returns all possible subsets except null and full set .
10,828
private static int getPowerSet ( int [ ] set , int inputIndex , int [ ] sofar , int [ ] [ ] sets , int outputIndex ) { for ( int i = inputIndex ; i < set . length ; i ++ ) { int n = sofar == null ? 0 : sofar . length ; if ( n < set . length - 1 ) { int [ ] subset = new int [ n + 1 ] ; subset [ n ] = set [ i ] ; if ( so...
Recursively calculates all possible subsets .
10,829
private static double incompleteFractionSummation ( double alpha , double beta , double x ) { final int MAXITER = 500 ; final double EPS = 3.0E-7 ; double aplusb = alpha + beta ; double aplus1 = alpha + 1.0 ; double aminus1 = alpha - 1.0 ; double c = 1.0 ; double d = 1.0 - aplusb * x / aplus1 ; if ( Math . abs ( d ) < ...
Incomplete fraction summation used in the method regularizedIncompleteBeta using a modified Lentz s method .
10,830
private double [ ] [ ] expd ( double [ ] [ ] D , double perplexity , double tol ) { int n = D . length ; double [ ] [ ] P = new double [ n ] [ n ] ; double [ ] DiSum = Math . rowSums ( D ) ; int nprocs = MulticoreExecutor . getThreadPoolSize ( ) ; int chunk = n / nprocs ; List < PerplexityTask > tasks = new ArrayList <...
Compute the Gaussian kernel ( search the width for given perplexity .
10,831
private Node buildNode ( int begin , int end ) { int d = keys [ 0 ] . length ; Node node = new Node ( ) ; node . count = end - begin ; node . index = begin ; double [ ] lowerBound = new double [ d ] ; double [ ] upperBound = new double [ d ] ; for ( int i = 0 ; i < d ; i ++ ) { lowerBound [ i ] = keys [ index [ begin ]...
Build a k - d tree from the given set of dataset .
10,832
private void search ( double [ ] q , Node node , Neighbor < double [ ] , E > neighbor ) { if ( node . isLeaf ( ) ) { for ( int idx = node . index ; idx < node . index + node . count ; idx ++ ) { if ( q == keys [ index [ idx ] ] && identicalExcluded ) { continue ; } double distance = Math . squaredDistance ( q , keys [ ...
Returns the nearest neighbors of the given target starting from the give tree node .
10,833
private void search ( double [ ] q , Node node , double radius , List < Neighbor < double [ ] , E > > neighbors ) { if ( node . isLeaf ( ) ) { for ( int idx = node . index ; idx < node . index + node . count ; idx ++ ) { if ( q == keys [ index [ idx ] ] && identicalExcluded ) { continue ; } double distance = Math . dis...
Returns the neighbors in the given range of search target from the give tree node .
10,834
public DenseMatrix inverse ( ) { int n = L . nrows ( ) ; DenseMatrix inv = Matrix . eye ( n ) ; solve ( inv ) ; return inv ; }
Returns the matrix inverse .
10,835
public void actionPerformed ( ActionEvent e ) { if ( e . getActionCommand ( ) . compareTo ( "Copy" ) == 0 ) { StringBuilder sbf = new StringBuilder ( ) ; int numcols = table . getSelectedColumnCount ( ) ; int numrows = table . getSelectedRowCount ( ) ; int [ ] rowsselected = table . getSelectedRows ( ) ; int [ ] colsse...
This method is activated on the Keystrokes we are listening to in this implementation . Here it listens for Copy and Paste ActionCommands . Selections comprising non - adjacent cells result in invalid selection and then copy action cannot be performed . Paste is done by aligning the upper left corner of the selection w...
10,836
public BigramCollocation [ ] find ( Corpus corpus , int k ) { BigramCollocation [ ] bigrams = new BigramCollocation [ k ] ; HeapSelect < BigramCollocation > heap = new HeapSelect < > ( bigrams ) ; Iterator < Bigram > iterator = corpus . getBigrams ( ) ; while ( iterator . hasNext ( ) ) { Bigram bigram = iterator . next...
Finds top k bigram collocations in the given corpus .
10,837
public BigramCollocation [ ] find ( Corpus corpus , double p ) { if ( p <= 0.0 || p >= 1.0 ) { throw new IllegalArgumentException ( "Invalid p = " + p ) ; } double cutoff = chisq . quantile ( p ) ; ArrayList < BigramCollocation > bigrams = new ArrayList < > ( ) ; Iterator < Bigram > iterator = corpus . getBigrams ( ) ;...
Finds bigram collocations in the given corpus whose p - value is less than the given threshold .
10,838
private double likelihoodRatio ( int c1 , int c2 , int c12 , long N ) { double p = ( double ) c2 / N ; double p1 = ( double ) c12 / c1 ; double p2 = ( double ) ( c2 - c12 ) / ( N - c1 ) ; double logLambda = logL ( c12 , c1 , p ) + logL ( c2 - c12 , N - c1 , p ) - logL ( c12 , c1 , p1 ) - logL ( c2 - c12 , N - c1 , p2 )...
Returns the likelihood ratio test statistic - 2 log &lambda ;
10,839
private double logL ( int k , long n , double x ) { if ( x == 0.0 ) x = 0.01 ; if ( x == 1.0 ) x = 0.99 ; return k * Math . log ( x ) + ( n - k ) * Math . log ( 1 - x ) ; }
Help function for calculating likelihood ratio statistic .
10,840
public static void denoise ( double [ ] t , Wavelet wavelet , boolean soft ) { wavelet . transform ( t ) ; int n = t . length ; int nh = t . length >> 1 ; double [ ] wc = new double [ nh ] ; System . arraycopy ( t , nh , wc , 0 , nh ) ; double error = Math . mad ( wc ) / 0.6745 ; double lambda = error * Math . sqrt ( 2...
Adaptive denoising a time series with given wavelet .
10,841
private void sety2 ( double [ ] x , double [ ] y ) { double p , qn , sig , un ; double [ ] u = new double [ n - 1 ] ; y2 [ 0 ] = u [ 0 ] = 0.0 ; for ( int i = 1 ; i < n - 1 ; i ++ ) { sig = ( x [ i ] - x [ i - 1 ] ) / ( x [ i + 1 ] - x [ i - 1 ] ) ; p = sig * y2 [ i - 1 ] + 2.0 ; y2 [ i ] = ( sig - 1.0 ) / p ; u [ i ] ...
Calculate the second derivatives of the interpolating function at the tabulated points . At the endpoints we use a natural spline with zero second derivative on that boundary .
10,842
public double bic ( double [ ] data ) { if ( components . isEmpty ( ) ) { throw new IllegalStateException ( "Mixture is empty!" ) ; } int n = data . length ; double logLikelihood = 0.0 ; for ( double x : data ) { double p = p ( x ) ; if ( p > 0 ) { logLikelihood += Math . log ( p ) ; } } return logLikelihood - 0.5 * np...
BIC score of the mixture for given data .
10,843
private static int [ ] seed ( SparseDataset data , int k ) { int n = data . size ( ) ; int [ ] y = new int [ n ] ; SparseArray centroid = data . get ( Math . randomInt ( n ) ) . x ; double [ ] D = new double [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { D [ i ] = Double . MAX_VALUE ; } for ( int i = 1 ; i < k ; i ++ ) { f...
Initialize clusters with KMeans ++ algorithm .
10,844
public double cdf2tiled ( double x ) { if ( x < 0 ) { throw new IllegalArgumentException ( "Invalid x: " + x ) ; } return 1.0 - Beta . regularizedIncompleteBetaFunction ( 0.5 * nu , 0.5 , nu / ( nu + x * x ) ) ; }
Two - tailed cdf .
10,845
public double quantile2tiled ( double p ) { if ( p < 0.0 || p > 1.0 ) { throw new IllegalArgumentException ( "Invalid p: " + p ) ; } double x = Beta . inverseRegularizedIncompleteBetaFunction ( 0.5 * nu , 0.5 , 1.0 - p ) ; return Math . sqrt ( nu * ( 1.0 - x ) / x ) ; }
Two - tailed quantile .
10,846
public AttributeDataset parse ( String name , InputStream stream ) throws IOException , ParseException { try ( BufferedReader reader = new BufferedReader ( new InputStreamReader ( stream ) ) ) { return parse ( name , null , reader ) ; } }
Parse a dataset from an input stream .
10,847
public static String coordToString ( double ... c ) { StringBuilder builder = new StringBuilder ( "(" ) ; for ( int i = 0 ; i < c . length ; i ++ ) { builder . append ( Math . round ( c [ i ] , 2 ) ) . append ( "," ) ; } if ( c . length > 0 ) { builder . setCharAt ( builder . length ( ) , ')' ) ; } else { builder . app...
Convert coordinate to a string .
10,848
public static < T extends Comparable < ? super T > > T median ( T [ ] a ) { int k = a . length / 2 ; return select ( a , k ) ; }
Find the median of an array of type double .
10,849
public static double measure ( int [ ] truth , double [ ] probability ) { if ( truth . length != probability . length ) { throw new IllegalArgumentException ( String . format ( "The vector sizes don't match: %d != %d." , truth . length , probability . length ) ) ; } double pos = 0 ; double neg = 0 ; for ( int i = 0 ; i...
Caulculate AUC for binary classifier .
10,850
public Neuron [ ] neurons ( ) { HashMap < Integer , Neuron > hash = new HashMap < > ( ) ; Neuron [ ] neurons = new Neuron [ nodes . size ( ) ] ; int i = 0 ; for ( Node node : nodes ) { Neuron [ ] neighbors = new Neuron [ node . edges . size ( ) ] ; neurons [ i ] = new Neuron ( node . w , neighbors ) ; hash . put ( node...
Returns the neurons in the network .
10,851
public int predict ( double [ ] x ) { double minDist = Double . MAX_VALUE ; int bestCluster = 0 ; int i = 0 ; for ( Node neuron : nodes ) { double dist = Math . squaredDistance ( x , neuron . w ) ; if ( dist < minDist ) { minDist = dist ; bestCluster = i ; } i ++ ; } if ( y == null || y . length != nodes . size ( ) ) {...
Cluster a new instance to the nearest neuron .
10,852
public double [ ] inverseProjection ( int x , int y ) { double [ ] sc = new double [ 2 ] ; double ratio = ( canvas . base . upperBound [ 0 ] - canvas . base . lowerBound [ 0 ] ) / ( canvas . getWidth ( ) * ( 1 - 2 * canvas . margin ) ) ; sc [ 0 ] = canvas . base . lowerBound [ 0 ] + ratio * ( x - canvas . getWidth ( ) ...
Project the screen coordinate back to the logical coordinates .
10,853
public int [ ] [ ] getClusterLabel ( ) { if ( y == null ) { throw new IllegalStateException ( "Neuron cluster labels are not available. Call partition() first." ) ; } int [ ] [ ] clusterLabels = new int [ height ] [ width ] ; for ( int i = 0 , l = 0 ; i < height ; i ++ ) { for ( int j = 0 ; j < width ; j ++ ) { cluster...
Returns the cluster labels for each neuron . If the neurons have not been clustered throws an Illegal State Exception .
10,854
public int [ ] partition ( int k ) { int n = width * height ; double [ ] [ ] units = new double [ n ] [ d ] ; for ( int i = 0 , l = 0 ; i < height ; i ++ ) { for ( int j = 0 ; j < width ; j ++ , l ++ ) { units [ l ] = neurons [ i ] [ j ] ; } } double [ ] [ ] proximity = new double [ n ] [ ] ; for ( int i = 0 ; i < n ; ...
Clustering the neurons into k groups . And then assigns the samples in each neuron to the corresponding cluster .
10,855
public int predict ( double [ ] x ) { double best = Double . MAX_VALUE ; int ii = - 1 , jj = - 1 ; for ( int i = 0 ; i < height ; i ++ ) { for ( int j = 0 ; j < width ; j ++ ) { double dist = Math . squaredDistance ( neurons [ i ] [ j ] , x ) ; if ( dist < best ) { best = dist ; ii = i ; jj = j ; } } } if ( y == null )...
Cluster a new instance to the nearest neuron . For clustering purpose one should build a sufficient large map to capture the structure of data space . Then the neurons of map can be clustered into a small number of clusters . Finally the sample should be assign to the cluster of its nearest neurons .
10,856
public SparseDataset parse ( String name , String path ) throws IOException , ParseException { return parse ( name , new File ( path ) ) ; }
Parse a libsvm sparse dataset from given file .
10,857
public SparseDataset parse ( String name , InputStream stream ) throws IOException , ParseException { BufferedReader reader = new BufferedReader ( new InputStreamReader ( stream ) ) ; try { String line = reader . readLine ( ) ; if ( line == null ) { throw new IOException ( "Empty data source." ) ; } String [ ] tokens =...
Parse a libsvm sparse dataset from an input stream .
10,858
public AttributeDataset parse ( String name , String path ) throws IOException , ParseException { return parse ( name , new File ( path ) ) ; }
Parse a TXT dataset from given file .
10,859
public AttributeDataset parse ( String name , InputStream stream ) throws IOException , ParseException { BufferedReader reader = new BufferedReader ( new InputStreamReader ( stream ) ) ; String line = reader . readLine ( ) ; if ( line == null ) { throw new IOException ( "Empty data source." ) ; } String [ ] tokens = li...
Parse a TXT dataset from an input stream .
10,860
public static DenseMatrix matrix ( double [ ] [ ] A ) { if ( nlmatrixZeros != null ) { try { return ( DenseMatrix ) nlmatrixArray2D . newInstance ( ( Object ) A ) ; } catch ( Exception e ) { logger . error ( "Failed to call NLMatrix(double[][]): {}" , e ) ; } } return new JMatrix ( A ) ; }
Creates a matrix initialized by A .
10,861
public static DenseMatrix matrix ( int nrows , int ncols ) { if ( nlmatrixZeros != null ) { try { return ( DenseMatrix ) nlmatrixZeros . newInstance ( nrows , ncols ) ; } catch ( Exception e ) { logger . error ( "Failed to call NLMatrix(int, int): {}" , e ) ; } } return new JMatrix ( nrows , ncols ) ; }
Creates a matrix of all zeros .
10,862
public static DenseMatrix matrix ( int nrows , int ncols , double value ) { if ( nlmatrixOnes != null ) { try { return ( DenseMatrix ) nlmatrixOnes . newInstance ( nrows , ncols , value ) ; } catch ( Exception e ) { logger . error ( "Failed to call NLMatrix(int, int, double): {}" , e ) ; } } return new JMatrix ( nrows ...
Creates a matrix filled with given value .
10,863
public static PlotCanvas plot ( double [ ] x ) { double [ ] lowerBound = { Math . min ( x ) , GaussianDistribution . getInstance ( ) . quantile ( 1 / ( x . length + 1.0 ) ) } ; double [ ] upperBound = { Math . max ( x ) , GaussianDistribution . getInstance ( ) . quantile ( x . length / ( x . length + 1.0 ) ) } ; PlotCa...
Create a plot canvas with the one sample Q - Q plot to standard normal distribution . The x - axis is the quantiles of x and the y - axis is the quantiles of normal distribution .
10,864
public static PlotCanvas plot ( double [ ] x , double [ ] y ) { double [ ] lowerBound = { Math . min ( x ) , Math . min ( y ) } ; double [ ] upperBound = { Math . max ( x ) , Math . max ( y ) } ; PlotCanvas canvas = new PlotCanvas ( lowerBound , upperBound ) ; canvas . add ( new QQPlot ( x , y ) ) ; return canvas ; }
Create a plot canvas with the two sample Q - Q plot . The x - axis is the quantiles of x and the y - axis is the quantiles of y .
10,865
public static PlotCanvas plot ( int [ ] x , DiscreteDistribution d ) { double [ ] lowerBound = { Math . min ( x ) , d . quantile ( 1 / ( x . length + 1.0 ) ) } ; double [ ] upperBound = { Math . max ( x ) , d . quantile ( x . length / ( x . length + 1.0 ) ) } ; PlotCanvas canvas = new PlotCanvas ( lowerBound , upperBou...
Create a plot canvas with the one sample Q - Q plot to given distribution . The x - axis is the quantiles of x and the y - axis is the quantiles of given distribution .
10,866
private void precompute ( ) { sinTheta = Math . sin ( theta ) ; cosTheta = Math . cos ( theta ) ; sinPhi = Math . sin ( phi ) ; cosPhi = Math . cos ( phi ) ; }
Pre - computes sin and cos of rotation angles .
10,867
public double [ ] project ( double [ ] xyz ) { double [ ] coord = new double [ 3 ] ; coord [ 0 ] = cosTheta * xyz [ 1 ] - sinTheta * xyz [ 0 ] ; coord [ 1 ] = cosPhi * xyz [ 2 ] - sinPhi * cosTheta * xyz [ 0 ] - sinPhi * sinTheta * xyz [ 1 ] ; coord [ 2 ] = cosPhi * sinTheta * xyz [ 1 ] + sinPhi * xyz [ 2 ] + cosPhi * ...
Returns the camera coordinates .
10,868
public double z ( double [ ] xyz ) { return cosPhi * sinTheta * xyz [ 1 ] + sinPhi * xyz [ 2 ] + cosPhi * cosTheta * xyz [ 0 ] ; }
Returns z - axis value in the camera coordinates .
10,869
public void rotate ( double t , double p ) { theta = theta - t / 100 ; phi = phi + p / 100 ; precompute ( ) ; reset ( ) ; }
Rotates the plot i . e . change the view angle .
10,870
private static int pivsign ( int [ ] piv , int n ) { int pivsign = 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( piv [ i ] != ( i + 1 ) ) pivsign = - pivsign ; } return pivsign ; }
Returns the pivot sign .
10,871
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 ) ) ; } int nb = LAPACK . getInstance ( ) . ilaenv ( 1 , "DGETRI" , "" , n , - 1 , - 1 , - 1 ) ; if ( nb < 0 ) { logger . warn...
Returns the matrix inverse . The LU matrix will overwritten with the inverse of the original matrix .
10,872
private void buildCoverTree ( ) { ArrayList < DistanceSet > pointSet = new ArrayList < > ( ) ; ArrayList < DistanceSet > consumedSet = new ArrayList < > ( ) ; E point = data [ 0 ] ; int idx = 0 ; double maxDist = - 1 ; for ( int i = 1 ; i < data . length ; i ++ ) { DistanceSet set = new DistanceSet ( i ) ; double dist ...
Builds the cover tree .
10,873
private double max ( ArrayList < DistanceSet > v ) { double max = 0.0 ; for ( DistanceSet n : v ) { if ( max < n . dist . get ( n . dist . size ( ) - 1 ) ) { max = n . dist . get ( n . dist . size ( ) - 1 ) ; } } return max ; }
Returns the max distance of the reference point p in current node to it s children nodes .
10,874
public static String diff ( String expression ) throws InvalidExpressionException { ExpressionTree expTree = parseToTree ( expression ) ; expTree . derive ( ) ; expTree . reduce ( ) ; return expTree . toString ( ) ; }
Compute the symbolic derivative .
10,875
public static final double diff ( String expression , double val ) throws InvalidExpressionException { ExpressionTree expTree = parseToTree ( expression ) ; expTree . derive ( ) ; expTree . reduce ( ) ; return expTree . getVal ( ) ; }
Compute numeric derivative
10,876
public static String diffReadable ( String expression ) throws InvalidExpressionException { ExpressionParser p = new ExpressionParser ( ) ; return p . format ( diff ( expression ) ) ; }
Compute the reformatted symbolic derivative .
10,877
public static String rewrite ( String expression ) throws InvalidExpressionException { ExpressionTree expTree = parseToTree ( expression ) ; expTree . reduce ( ) ; return expTree . toString ( ) ; }
Rewrite the expression to eliminate redundant terms and simplify the expression .
10,878
private static final ExpressionTree parseToTree ( String expression ) throws InvalidExpressionException { ExpressionParser parser = new ExpressionParser ( ) ; parser . parse ( expression ) ; return new ExpressionTree ( parser . getVar ( ) , parser . getTokens ( ) ) ; }
Parse a mathematical expression and form a binary expression tree .
10,879
public double rand ( ) { double np = n * p ; if ( np < 1.E-6 ) { return PoissonDistribution . tinyLambdaRand ( np ) ; } boolean inv = false ; if ( p > 0.5 ) { inv = true ; } if ( np < 55 ) { if ( p <= 0.5 ) { rng = new ModeSearch ( p ) ; } else { rng = new ModeSearch ( 1.0 - p ) ; } } else { if ( p <= 0.5 ) { rng = new...
This function generates a random variate with the binomial distribution .
10,880
private double weightedEdit ( char [ ] x , char [ ] y ) { if ( x . length < y . length ) { char [ ] swap = x ; x = y ; y = swap ; } int radius = ( int ) Math . round ( r * Math . max ( x . length , y . length ) ) ; double [ ] [ ] d = new double [ 2 ] [ y . length + 1 ] ; d [ 0 ] [ 0 ] = 0.0 ; for ( int j = 1 ; j <= y ....
Weighted edit distance .
10,881
private int br ( char [ ] x , char [ ] y ) { if ( x . length > y . length ) { char [ ] swap = x ; x = y ; y = swap ; } final int m = x . length ; final int n = y . length ; int ZERO_K = n ; if ( n + 2 > FKP [ 0 ] . length ) FKP = new int [ 2 * n + 1 ] [ n + 2 ] ; for ( int k = - ZERO_K ; k < 0 ; k ++ ) { int p = - k - ...
Berghel & Roach s extended Ukkonen s algorithm .
10,882
private void init ( ) { if ( x == null ) { x = new double [ z [ 0 ] . length ] ; for ( int i = 0 ; i < x . length ; i ++ ) { x [ i ] = i + 0.5 ; } } if ( y == null ) { y = new double [ z . length ] ; for ( int i = 0 ; i < y . length ; i ++ ) { y [ i ] = y . length - i - 0.5 ; } } int n = z . length * z [ 0 ] . length ;...
Initialize the internal variables .
10,883
public Complex minus ( Complex b ) { Complex a = this ; double real = a . re - b . re ; double imag = a . im - b . im ; return new Complex ( real , imag ) ; }
Returns this - b .
10,884
public Complex reciprocal ( ) { double scale = re * re + im * im ; return new Complex ( re / scale , - im / scale ) ; }
Returns the reciprocal .
10,885
public Complex exp ( ) { return new Complex ( Math . exp ( re ) * Math . cos ( im ) , Math . exp ( re ) * Math . sin ( im ) ) ; }
Returns the complex exponential .
10,886
public Complex sin ( ) { return new Complex ( Math . sin ( re ) * Math . cosh ( im ) , Math . cos ( re ) * Math . sinh ( im ) ) ; }
Returns the complex sine .
10,887
private double [ ] getAugmentedResponse ( double [ ] y ) { double [ ] ret = new double [ y . length + p ] ; System . arraycopy ( y , 0 , ret , 0 , y . length ) ; return ret ; }
transform the original response array by padding 0 at the tail
10,888
private double [ ] [ ] getAugmentedData ( double [ ] [ ] x ) { double [ ] [ ] ret = new double [ x . length + p ] [ p ] ; double padding = c * Math . sqrt ( lambda2 ) ; for ( int i = 0 ; i < x . length ; i ++ ) { for ( int j = 0 ; j < p ; j ++ ) { ret [ i ] [ j ] = c * x [ i ] [ j ] ; } } for ( int i = x . length ; i <...
transform the original data array by padding a weighted identity matrix and multiply a scaling
10,889
public BinarySparseDataset parse ( String name , URI uri ) throws IOException , ParseException { return parse ( name , new File ( uri ) ) ; }
Parse a binary sparse dataset from given URI .
10,890
public BinarySparseDataset parse ( String name , InputStream stream ) throws IOException , ParseException { try ( BufferedReader reader = new BufferedReader ( new InputStreamReader ( stream ) ) ) { BinarySparseDataset sparse = new BinarySparseDataset ( name ) ; String line = reader . readLine ( ) ; if ( line == null ) ...
Parse a binary sparse dataset from an input stream .
10,891
public static PlotCanvas plot ( double [ ] [ ] data ) { double [ ] lowerBound = { - 0.5 , 0.36 } ; double [ ] upperBound = { data [ 0 ] . length , data . length * 0.87 + 0.5 } ; PlotCanvas canvas = new PlotCanvas ( lowerBound , upperBound , false ) ; canvas . add ( new Hexmap ( data ) ) ; canvas . getAxis ( 0 ) . setFr...
Create a plot canvas with the pseudo hexmap plot of given data .
10,892
public boolean stopCellEditing ( ) { JFormattedTextField ftf = ( JFormattedTextField ) getComponent ( ) ; if ( ftf . isEditValid ( ) ) { try { ftf . commitEdit ( ) ; } catch ( java . text . ParseException ex ) { } } else { Toolkit . getDefaultToolkit ( ) . beep ( ) ; textField . selectAll ( ) ; return false ; } return ...
of this method so that everything gets cleaned up .
10,893
private void init ( ) { width = Double . MAX_VALUE ; for ( int i = 1 ; i < data . length ; i ++ ) { double w = Math . abs ( data [ i ] [ 0 ] - data [ i - 1 ] [ 0 ] ) ; if ( width > w ) { width = w ; } } leftTop = new double [ data . length ] [ 2 ] ; rightTop = new double [ data . length ] [ 2 ] ; leftBottom = new doubl...
Calculate bar width and position .
10,894
public double rand ( ) { int mm = m ; int nn = n ; if ( mm > N / 2 ) { mm = N - mm ; } if ( nn > N / 2 ) { nn = N - nn ; } if ( nn > mm ) { int swap = nn ; nn = mm ; mm = swap ; } if ( rng == null ) { if ( ( double ) nn * mm >= 20 * N ) { rng = new Patchwork ( N , mm , nn ) ; } else { rng = new Inversion ( N , mm , nn ...
Uses inversion by chop - down search from the mode when the mean &lt ; 20 and the patchwork - rejection method when the mean &gt ; 20 .
10,895
void init ( double [ ] [ ] proximity ) { size = proximity . length ; this . proximity = new float [ size * ( size + 1 ) / 2 ] ; for ( int j = 0 , k = 0 ; j < size ; j ++ ) { for ( int i = j ; i < size ; i ++ , k ++ ) { this . proximity [ k ] = ( float ) proximity [ i ] [ j ] ; } } }
Initialize the linkage with the lower triangular proximity matrix .
10,896
public 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 ; if ( weight == null ) { for ( int i = 0 ; i < x . length ; i ++ ) { double d = Math . abs ( ...
Minkowski distance between the two arrays of type integer .
10,897
public DenseMatrix getR ( ) { int n = qr . ncols ( ) ; DenseMatrix R = Matrix . zeros ( n , n ) ; for ( int i = 0 ; i < n ; i ++ ) { R . set ( i , i , tau [ i ] ) ; for ( int j = i + 1 ; j < n ; j ++ ) { R . set ( i , j , qr . get ( i , j ) ) ; } } return R ; }
Returns the upper triangular factor .
10,898
public DenseMatrix getQ ( ) { int m = qr . nrows ( ) ; int n = qr . ncols ( ) ; DenseMatrix Q = Matrix . zeros ( m , n ) ; for ( int k = n - 1 ; k >= 0 ; k -- ) { Q . set ( k , k , 1.0 ) ; for ( int j = k ; j < n ; j ++ ) { if ( qr . get ( k , k ) != 0 ) { double s = 0.0 ; for ( int i = k ; i < m ; i ++ ) { s += qr . g...
Returns the orthogonal factor .
10,899
public SparseDataset parse ( String name , InputStream stream ) throws IOException , ParseException { BufferedReader reader = new BufferedReader ( new InputStreamReader ( stream ) ) ; try { int nrow = 1 ; String line = reader . readLine ( ) ; for ( ; nrow <= 3 && line != null ; nrow ++ ) { String [ ] tokens = line . tr...
Parse a sparse dataset from an input stream .