idx int64 0 165k | question stringlengths 73 4.15k | target stringlengths 5 918 | len_question int64 21 890 | len_target int64 3 255 |
|---|---|---|---|---|
36,700 | @ Override public long getLength ( ) { final long vsHi = vStart & ~ 0xffff ; final long veHi = vEnd & ~ 0xffff ; final long hiDiff = veHi - vsHi ; return hiDiff == 0 ? ( ( vEnd & 0xffff ) - ( vStart & 0xffff ) ) : hiDiff ; } | Inexact due to the nature of virtual offsets . | 77 | 11 |
36,701 | private void fixBCFSplits ( List < FileSplit > splits , List < InputSplit > newSplits ) throws IOException { // addGuessedSplits() requires the given splits to be sorted by file // path, so do so. Although FileInputFormat.getSplits() does, at the time // of writing this, generate them in that order, we shouldn't rely o... | FileVirtualSplits uncompressed in FileSplits . | 169 | 11 |
36,702 | public static boolean parseBoolean ( String value , boolean defaultValue ) { if ( value == null ) return defaultValue ; value = value . trim ( ) ; // any of the following will final String [ ] acceptedTrue = new String [ ] { "yes" , "true" , "t" , "y" , "1" } ; final String [ ] acceptedFalse = new String [ ] { "no" , "... | Convert a string to a boolean . | 178 | 8 |
36,703 | public static void main ( String [ ] args ) { if ( args . length == 0 ) { System . out . println ( "Usage: SplittingBAMIndex [splitting BAM indices...]\n\n" + "Writes a few statistics about each splitting BAM index." ) ; return ; } for ( String arg : args ) { final File f = new File ( arg ) ; if ( f . isFile ( ) && f .... | Writes some statistics about each splitting BAM index file given as an argument . | 383 | 16 |
36,704 | public static synchronized void cancelNetworkCall ( String url , String requestMethod , long endTime , String exception ) { if ( url != null ) { String id = sanitiseURL ( url ) ; if ( ( connections != null ) && ( connections . containsKey ( id ) ) ) { connections . remove ( id ) ; } } } | When a network request is cancelled we stop tracking it and do not send the information through . Future updates may include sending the cancelled request timing through with information showing it was cancelled . | 70 | 35 |
36,705 | private static int postRUM ( String apiKey , String jsonPayload ) { try { if ( validateApiKey ( apiKey ) ) { String endpoint = RaygunSettings . getRUMEndpoint ( ) ; MediaType MEDIA_TYPE_JSON = MediaType . parse ( "application/json; charset=utf-8" ) ; OkHttpClient client = new OkHttpClient . Builder ( ) . connectTimeout... | Raw post method that delivers a pre - built RUM payload to the Raygun API . | 369 | 18 |
36,706 | public static void init ( Context context ) { String apiKey = readApiKey ( context ) ; init ( context , apiKey ) ; } | Initializes the Raygun client . This expects that you have placed the API key in your AndroidManifest . xml in a meta - data element . | 30 | 30 |
36,707 | public static void init ( Context context , String apiKey ) { RaygunClient . apiKey = apiKey ; RaygunClient . context = context ; RaygunClient . appContextIdentifier = UUID . randomUUID ( ) . toString ( ) ; RaygunLogger . d ( "Configuring Raygun (v" + RaygunSettings . RAYGUN_CLIENT_VERSION + ")" ) ; try { RaygunClient ... | Initializes the Raygun client with your Android application s context and your Raygun API key . The version transmitted will be the value of the versionName attribute in your manifest element . | 168 | 36 |
36,708 | public static void init ( Context context , String apiKey , String version ) { init ( context , apiKey ) ; RaygunClient . version = version ; } | Initializes the Raygun client with your Android application s context your Raygun API key and the version of your application | 33 | 23 |
36,709 | public static void send ( Throwable throwable , List tags , Map userCustomData ) { RaygunMessage msg = buildMessage ( throwable ) ; if ( msg == null ) { RaygunLogger . e ( "Failed to send RaygunMessage - due to invalid message being built" ) ; return ; } msg . getDetails ( ) . setTags ( RaygunUtils . mergeLists ( Raygu... | Sends an exception - type object to Raygun with a list of tags you specify and a set of custom data . | 208 | 24 |
36,710 | public static void sendPulseTimingEvent ( RaygunPulseEventType eventType , String name , long milliseconds ) { if ( RaygunClient . sessionId == null ) { sendPulseEvent ( RaygunSettings . RUM_EVENT_SESSION_START ) ; } if ( eventType == RaygunPulseEventType . ACTIVITY_LOADED ) { if ( RaygunClient . shouldIgnoreView ( nam... | Sends a pulse timing event to Raygun . The message is sent on a background thread . | 626 | 19 |
36,711 | public static < T extends Tag , V > void register ( Class < T > tag , Class < V > type , TagConverter < T , V > converter ) throws ConverterRegisterException { if ( tagToConverter . containsKey ( tag ) ) { throw new ConverterRegisterException ( "Type conversion to tag " + tag . getName ( ) + " is already registered." )... | Registers a converter . | 156 | 5 |
36,712 | public static < T extends Tag , V > void unregister ( Class < T > tag , Class < V > type ) { tagToConverter . remove ( tag ) ; typeToConverter . remove ( type ) ; } | Unregisters a converter . | 49 | 6 |
36,713 | public static < T extends Tag , V > V convertToValue ( T tag ) throws ConversionException { if ( tag == null || tag . getValue ( ) == null ) { return null ; } if ( ! tagToConverter . containsKey ( tag . getClass ( ) ) ) { throw new ConversionException ( "Tag type " + tag . getClass ( ) . getName ( ) + " has no converte... | Converts the given tag to a value . | 142 | 9 |
36,714 | public static < V , T extends Tag > T convertToTag ( String name , V value ) throws ConversionException { if ( value == null ) { return null ; } TagConverter < T , V > converter = ( TagConverter < T , V > ) typeToConverter . get ( value . getClass ( ) ) ; if ( converter == null ) { for ( Class < ? > clazz : getAllClass... | Converts the given value to a tag . | 209 | 9 |
36,715 | public static void writeTag ( OutputStream out , Tag tag ) throws IOException { writeTag ( out , tag , false ) ; } | Writes an NBT tag in big endian . | 28 | 11 |
36,716 | public void setValue ( List < Tag > value ) throws IllegalArgumentException { this . type = null ; this . value . clear ( ) ; for ( Tag tag : value ) { this . add ( tag ) ; } } | Sets the value of this tag . The list tag s type will be set to that of the first tag being added or null if the given list is empty . | 48 | 33 |
36,717 | public boolean add ( Tag tag ) throws IllegalArgumentException { if ( tag == null ) { return false ; } // If empty list, use this as tag type. if ( this . type == null ) { this . type = tag . getClass ( ) ; } else if ( tag . getClass ( ) != this . type ) { throw new IllegalArgumentException ( "Tag type cannot differ fr... | Adds a tag to this list tag . If the list does not yet have a type it will be set to the type of the tag being added . | 102 | 30 |
36,718 | public void setValue ( Map < String , Tag > value ) { this . value = new LinkedHashMap < String , Tag > ( value ) ; } | Sets the value of this tag . | 33 | 8 |
36,719 | public < T extends Tag > T get ( String tagName ) { return ( T ) this . value . get ( tagName ) ; } | Gets the tag with the specified name . | 29 | 9 |
36,720 | public < T extends Tag > T put ( T tag ) { return ( T ) this . value . put ( tag . getName ( ) , tag ) ; } | Puts the tag into this compound tag . | 34 | 9 |
36,721 | public < T extends Tag > T remove ( String tagName ) { return ( T ) this . value . remove ( tagName ) ; } | Removes a tag from this compound tag . | 29 | 9 |
36,722 | public static void register ( int id , Class < ? extends Tag > tag ) throws TagRegisterException { if ( idToTag . containsKey ( id ) ) { throw new TagRegisterException ( "Tag ID \"" + id + "\" is already in use." ) ; } if ( tagToId . containsKey ( tag ) ) { throw new TagRegisterException ( "Tag \"" + tag . getSimpleNam... | Registers a tag class . | 122 | 6 |
36,723 | public static Class < ? extends Tag > getClassFor ( int id ) { if ( ! idToTag . containsKey ( id ) ) { return null ; } return idToTag . get ( id ) ; } | Gets the tag class with the given id . | 45 | 10 |
36,724 | public static int getIdFor ( Class < ? extends Tag > clazz ) { if ( ! tagToId . containsKey ( clazz ) ) { return - 1 ; } return tagToId . get ( clazz ) ; } | Gets the id of the given tag class . | 49 | 10 |
36,725 | public static Tag createInstance ( int id , String tagName ) throws TagCreateException { Class < ? extends Tag > clazz = idToTag . get ( id ) ; if ( clazz == null ) { throw new TagCreateException ( "Could not find tag with ID \"" + id + "\"." ) ; } try { Constructor < ? extends Tag > constructor = clazz . getDeclaredCo... | Creates an instance of the tag with the given id using the String constructor . | 154 | 16 |
36,726 | @ Override protected synchronized void onMeasure ( int widthMeasureSpec , int heightMeasureSpec ) { int width = 200 ; if ( MeasureSpec . UNSPECIFIED != MeasureSpec . getMode ( widthMeasureSpec ) ) { width = MeasureSpec . getSize ( widthMeasureSpec ) ; } int height = thumbImage . getHeight ( ) + ( ! showTextAboveThumbs ... | Ensures correct size of the widget . | 176 | 9 |
36,727 | private void drawThumb ( float screenCoord , boolean pressed , Canvas canvas , boolean areSelectedValuesDefault ) { Bitmap buttonToDraw ; if ( ! activateOnDefaultValues && areSelectedValuesDefault ) { buttonToDraw = thumbDisabledImage ; } else { buttonToDraw = pressed ? thumbPressedImage : thumbImage ; } canvas . drawB... | Draws the normal resp . pressed thumb image on specified x - coordinate . | 99 | 15 |
36,728 | private void drawThumbShadow ( float screenCoord , Canvas canvas ) { thumbShadowMatrix . setTranslate ( screenCoord + thumbShadowXOffset , textOffset + thumbHalfHeight + thumbShadowYOffset ) ; translatedThumbShadowPath . set ( thumbShadowPath ) ; translatedThumbShadowPath . transform ( thumbShadowMatrix ) ; canvas . dr... | Draws a drop shadow beneath the slider thumb . | 90 | 10 |
36,729 | private void setNormalizedMinValue ( double value ) { normalizedMinValue = Math . max ( 0d , Math . min ( 1d , Math . min ( value , normalizedMaxValue ) ) ) ; invalidate ( ) ; } | Sets normalized min value to value so that 0 < = value < = normalized max value < = 1 . The View will get invalidated when calling this method . | 49 | 33 |
36,730 | private void setNormalizedMaxValue ( double value ) { normalizedMaxValue = Math . max ( 0d , Math . min ( 1d , Math . max ( value , normalizedMinValue ) ) ) ; invalidate ( ) ; } | Sets normalized max value to value so that 0 < = normalized min value < = value < = 1 . The View will get invalidated when calling this method . | 49 | 33 |
36,731 | @ SuppressWarnings ( "unchecked" ) protected T normalizedToValue ( double normalized ) { double v = absoluteMinValuePrim + normalized * ( absoluteMaxValuePrim - absoluteMinValuePrim ) ; // TODO parameterize this rounding to allow variable decimal points return ( T ) numberType . toNumber ( Math . round ( v * 100 ) / 10... | Converts a normalized value to a Number object in the value space between absolute minimum and maximum . | 80 | 19 |
36,732 | protected double valueToNormalized ( T value ) { if ( 0 == absoluteMaxValuePrim - absoluteMinValuePrim ) { // prevent division by zero, simply return 0. return 0d ; } return ( value . doubleValue ( ) - absoluteMinValuePrim ) / ( absoluteMaxValuePrim - absoluteMinValuePrim ) ; } | Converts the given Number value to a normalized double . | 69 | 11 |
36,733 | private double screenToNormalized ( float screenCoord ) { int width = getWidth ( ) ; if ( width <= 2 * padding ) { // prevent division by zero, simply return 0. return 0d ; } else { double result = ( screenCoord - padding ) / ( width - 2 * padding ) ; return Math . min ( 1d , Math . max ( 0d , result ) ) ; } } | Converts screen space x - coordinates into normalized values . | 87 | 11 |
36,734 | public static < K > void updateWeights ( double l2 , double learningRate , Map < K , Double > weights , Map < K , Double > newWeights ) { if ( l2 > 0.0 ) { for ( Map . Entry < K , Double > e : weights . entrySet ( ) ) { K column = e . getKey ( ) ; newWeights . put ( column , newWeights . get ( column ) + l2 * e . getVa... | Updates the weights by applying the L2 regularization . | 114 | 12 |
36,735 | public static < K > double estimatePenalty ( double l2 , Map < K , Double > weights ) { double penalty = 0.0 ; if ( l2 > 0.0 ) { double sumWeightsSquared = 0.0 ; for ( double w : weights . values ( ) ) { sumWeightsSquared += w * w ; } penalty = l2 * sumWeightsSquared / 2.0 ; } return penalty ; } | Estimates the penalty by adding the L2 regularization . | 94 | 12 |
36,736 | protected void keepTopFeatures ( Map < Object , Double > featureScores , int maxFeatures ) { logger . debug ( "keepTopFeatures()" ) ; logger . debug ( "Estimating the minPermittedScore" ) ; Double minPermittedScore = SelectKth . largest ( featureScores . values ( ) . iterator ( ) , maxFeatures ) ; //remove any entry wi... | This method keeps the highest scoring features of the provided feature map and removes all the others . | 339 | 18 |
36,737 | protected void removeRareFeatures ( Map < Object , Double > featureCounts , int rareFeatureThreshold ) { logger . debug ( "removeRareFeatures()" ) ; Iterator < Map . Entry < Object , Double > > it = featureCounts . entrySet ( ) . iterator ( ) ; while ( it . hasNext ( ) ) { Map . Entry < Object , Double > entry = it . n... | Removes any feature with less occurrences than the threshold . | 112 | 11 |
36,738 | public static TransposeDataCollection weightedProbabilitySampling ( AssociativeArray2D strataFrequencyTable , AssociativeArray nh , boolean withReplacement ) { TransposeDataCollection sampledIds = new TransposeDataCollection ( ) ; for ( Map . Entry < Object , AssociativeArray > entry : strataFrequencyTable . entrySet (... | Samples nh ids from each strata based on their Frequency Table | 164 | 15 |
36,739 | public static TransposeDataCollection randomSampling ( TransposeDataList strataIdList , AssociativeArray nh , boolean withReplacement ) { TransposeDataCollection sampledIds = new TransposeDataCollection ( ) ; for ( Map . Entry < Object , FlatDataList > entry : strataIdList . entrySet ( ) ) { Object strata = entry . get... | Samples nh ids from each strata by using Stratified Sampling | 158 | 16 |
36,740 | public static double variance ( TransposeDataCollection sampleDataCollection , AssociativeArray populationNh ) { double variance = 0.0 ; int populationN = 0 ; double mean = mean ( sampleDataCollection , populationNh ) ; for ( Map . Entry < Object , FlatDataCollection > entry : sampleDataCollection . entrySet ( ) ) { Ob... | Calculate the variance from the sample | 224 | 8 |
36,741 | public static double std ( TransposeDataCollection sampleDataCollection , AssociativeArray populationNh ) { return Math . sqrt ( variance ( sampleDataCollection , populationNh ) ) ; } | Calculate the standard deviation of the sample | 40 | 9 |
36,742 | public static AssociativeArray optimumSampleSize ( int n , AssociativeArray populationNh , AssociativeArray populationStdh ) { AssociativeArray nh = new AssociativeArray ( ) ; double sumNhSh = 0.0 ; for ( Map . Entry < Object , Object > entry : populationNh . entrySet ( ) ) { Object strata = entry . getKey ( ) ; Intege... | Returns the optimum sample size per strata under Neyman Allocation | 292 | 13 |
36,743 | public static < T > void throttledExecution ( Stream < T > stream , Consumer < T > consumer , ConcurrencyConfiguration concurrencyConfiguration ) { if ( concurrencyConfiguration . isParallelized ( ) ) { int maxThreads = concurrencyConfiguration . getMaxNumberOfThreadsPerTask ( ) ; int maxTasks = 2 * maxThreads ; Execut... | Takes the items of the stream in a throttled way and provides them to the consumer . It uses as many threads as the available processors and it does not start more tasks than 2 times the previous number . | 236 | 42 |
36,744 | protected static double betinc ( double x , double A , double B ) { double A0 = 0.0 ; double B0 = 1.0 ; double A1 = 1.0 ; double B1 = 1.0 ; double M9 = 0.0 ; double A2 = 0.0 ; while ( Math . abs ( ( A1 - A2 ) / A1 ) > 0.00001 ) { A2 = A1 ; double C9 = - ( A + M9 ) * ( A + B + M9 ) * x / ( A + 2.0 * M9 ) / ( A + 2.0 * M... | Internal function used by StudentCdf | 282 | 7 |
36,745 | public static double exponentialCdf ( double x , double lamda ) { if ( x < 0 || lamda <= 0 ) { throw new IllegalArgumentException ( "All the parameters must be positive." ) ; } double probability = 1.0 - Math . exp ( - lamda * x ) ; return probability ; } | Calculates the probability from 0 to X under Exponential Distribution | 67 | 13 |
36,746 | public static double betaCdf ( double x , double a , double b ) { if ( x < 0 || a <= 0 || b <= 0 ) { throw new IllegalArgumentException ( "All the parameters must be positive." ) ; } double Bcdf = 0.0 ; if ( x == 0 ) { return Bcdf ; } else if ( x >= 1 ) { Bcdf = 1.0 ; return Bcdf ; } double S = a + b ; double BT = Math... | Calculates the probability from 0 to X under Beta Distribution | 221 | 12 |
36,747 | public static double fCdf ( double x , int f1 , int f2 ) { if ( x < 0 || f1 <= 0 || f2 <= 0 ) { throw new IllegalArgumentException ( "All the parameters must be positive." ) ; } double Z = x / ( x + ( double ) f2 / f1 ) ; double FCdf = betaCdf ( Z , f1 / 2.0 , f2 / 2.0 ) ; return FCdf ; } | Calculates the probability from 0 to X under F Distribution | 102 | 12 |
36,748 | public static double gammaCdf ( double x , double a , double b ) { if ( a <= 0 || b <= 0 ) { throw new IllegalArgumentException ( "All the parameters must be positive." ) ; } double GammaCdf = ContinuousDistributions . gammaCdf ( x / b , a ) ; return GammaCdf ; } | Calculates the probability from 0 to X under Gamma Distribution | 73 | 12 |
36,749 | public static double uniformCdf ( double x , double a , double b ) { if ( a >= b ) { throw new IllegalArgumentException ( "The a must be smaller than b." ) ; } double probabilitySum ; if ( x < a ) { probabilitySum = 0.0 ; } else if ( x < b ) { probabilitySum = ( x - a ) / ( b - a ) ; } else { probabilitySum = 1 ; } ret... | Returns the cumulative probability of Uniform | 99 | 6 |
36,750 | public static double kolmogorov ( double z ) { //Kolmogorov distribution. Error<.0000001 if ( z < 0.27 ) { return 0.0 ; } else if ( z > 3.2 ) { return 1.1 ; } double ks = 0 ; double y = - 2 * z * z ; for ( int i = 27 ; i >= 1 ; i = i - 2 ) { ks = Math . exp ( i * y ) * ( 1 - ks ) ; } return 1.0 - 2.0 * ks ; } | Returns the cumulative probability of kolmogorov | 126 | 11 |
36,751 | public static double dirichletPdf ( double [ ] pi , double [ ] ai ) { double probability = 1.0 ; double sumAi = 0.0 ; double productGammaAi = 1.0 ; double tmp ; int piLength = pi . length ; for ( int i = 0 ; i < piLength ; ++ i ) { tmp = ai [ i ] ; sumAi += tmp ; productGammaAi *= gamma ( tmp ) ; probability *= Math . ... | Calculates probability pi ai under dirichlet distribution | 139 | 12 |
36,752 | public static double dirichletPdf ( double [ ] pi , double a ) { double probability = 1.0 ; int piLength = pi . length ; for ( int i = 0 ; i < piLength ; ++ i ) { probability *= Math . pow ( pi [ i ] , a - 1 ) ; } double sumAi = piLength * a ; double productGammaAi = Math . pow ( gamma ( a ) , piLength ) ; probability ... | Implementation for single alpha value . | 117 | 7 |
36,753 | public static double [ ] multinomialGaussianSample ( double [ ] mean , double [ ] [ ] covariance ) { MultivariateNormalDistribution gaussian = new MultivariateNormalDistribution ( mean , covariance ) ; gaussian . reseedRandomGenerator ( RandomGenerator . getThreadLocalRandom ( ) . nextLong ( ) ) ; return gaussian . sam... | Samples from Multinomial Normal Distribution . | 82 | 9 |
36,754 | public static double multinomialGaussianPdf ( double [ ] mean , double [ ] [ ] covariance , double [ ] x ) { MultivariateNormalDistribution gaussian = new MultivariateNormalDistribution ( mean , covariance ) ; return gaussian . density ( x ) ; } | Calculates the PDF of Multinomial Normal Distribution for a particular x . | 61 | 16 |
36,755 | public static Map . Entry < Object , Double > selectMaxKeyValue ( Map < Object , Double > keyValueMap ) { Double maxValue = Double . NEGATIVE_INFINITY ; Object maxValueKey = null ; for ( Map . Entry < Object , Double > entry : keyValueMap . entrySet ( ) ) { Double value = entry . getValue ( ) ; if ( value != null && va... | Selects the key - value entry with the largest value . | 136 | 12 |
36,756 | public static Map . Entry < Object , Object > selectMinKeyValue ( AssociativeArray keyValueMap ) { Double minValue = Double . POSITIVE_INFINITY ; Object minValueKey = null ; for ( Map . Entry < Object , Object > entry : keyValueMap . entrySet ( ) ) { Double value = TypeInference . toDouble ( entry . getValue ( ) ) ; if... | Selects the key - value entry with the smallest value . | 141 | 12 |
36,757 | public static < K , V > Map < K , V > sortNumberMapByKeyAscending ( Map < K , V > map ) { return sortNumberMapByKeyAscending ( map . entrySet ( ) ) ; } | Sorts by Key a Map in ascending order . | 50 | 10 |
36,758 | public static < K , V > Map < K , V > sortNumberMapByKeyDescending ( Map < K , V > map ) { return sortNumberMapByKeyDescending ( map . entrySet ( ) ) ; } | Sorts by Key a Map in descending order . | 48 | 10 |
36,759 | public static < K , V > Map < K , V > sortNumberMapByValueDescending ( Map < K , V > map ) { ArrayList < Map . Entry < K , V > > entries = new ArrayList <> ( map . entrySet ( ) ) ; Collections . sort ( entries , ( Map . Entry < K , V > a , Map . Entry < K , V > b ) -> { Double va = TypeInference . toDouble ( a . getVal... | Sorts by Value a Map in descending order . | 198 | 10 |
36,760 | public static AssociativeArray sortAssociativeArrayByValueAscending ( AssociativeArray associativeArray ) { ArrayList < Map . Entry < Object , Object > > entries = new ArrayList <> ( associativeArray . entrySet ( ) ) ; Collections . sort ( entries , ( Map . Entry < Object , Object > a , Map . Entry < Object , Object > ... | Sorts by Value a Associative Array in ascending order . | 196 | 12 |
36,761 | private static String unescapeHtml ( final String input ) { StringBuilder writer = null ; int len = input . length ( ) ; int i = 1 ; int st = 0 ; while ( true ) { // look for '&' while ( i < len && input . charAt ( i - 1 ) != ' ' ) { i ++ ; } if ( i >= len ) { break ; } // found '&', look for ';' int j = i ; while ( j ... | Unescapes HTML3 chars from a string . | 531 | 11 |
36,762 | public static String replaceImgWithAlt ( String html ) { Matcher m = IMG_ALT_TITLE_PATTERN . matcher ( html ) ; if ( m . find ( ) ) { return m . replaceAll ( " $1 " ) ; } return html ; } | Replaces the img tags with their alt text . | 61 | 10 |
36,763 | public static String safeRemoveAllTags ( String html ) { html = removeNonTextTags ( html ) ; html = unsafeRemoveAllTags ( html ) ; return html ; } | A safe way to remove the tags from an HTML string . The method removes first javascript css and other non text blocks and then removes all HTML tags . | 36 | 31 |
36,764 | public static String extractText ( String html ) { //return Jsoup.parse(text).text(); html = replaceImgWithAlt ( html ) ; html = safeRemoveAllTags ( html ) ; html = unescapeHtml ( html ) ; return html ; } | Extracts the text from an HTML page . | 57 | 10 |
36,765 | public static String extractTitle ( String html ) { Matcher m = TITLE_PATTERN . matcher ( html ) ; if ( m . find ( ) ) { return clear ( m . group ( 0 ) ) ; } return null ; } | Extracts the title of the page . | 52 | 9 |
36,766 | public static Map < HyperlinkPart , List < String > > extractHyperlinks ( String html ) { Map < HyperlinkPart , List < String > > hyperlinksMap = new HashMap <> ( ) ; hyperlinksMap . put ( HyperlinkPart . HTMLTAG , new ArrayList <> ( ) ) ; hyperlinksMap . put ( HyperlinkPart . URL , new ArrayList <> ( ) ) ; hyperlinksM... | Extracts the hyperlinks from an html string and returns their components in a map . | 251 | 18 |
36,767 | public static Map < String , String > extractMetatags ( String html ) { Map < String , String > metatagsMap = new HashMap <> ( ) ; Matcher m = METATAG_PATTERN . matcher ( html ) ; while ( m . find ( ) ) { if ( m . groupCount ( ) == 2 ) { String name = m . group ( 1 ) ; String content = m . group ( 2 ) ; metatagsMap . p... | Extracts the meta tags from an HTML page and returns them in a map . | 122 | 17 |
36,768 | public static double normalDistribution ( Double x , AssociativeArray params ) { double mean = params . getDouble ( "mean" ) ; double variance = params . getDouble ( "variance" ) ; //standardize the x value double z = ( x - mean ) / Math . sqrt ( variance ) ; return ContinuousDistributions . gaussCdf ( z ) ; } | Cumulative Normal Distribution Method . This method is called via reflection . | 81 | 14 |
36,769 | public static double bernoulliCdf ( int k , double p ) { if ( p < 0 ) { throw new IllegalArgumentException ( "The probability p can't be negative." ) ; } double probabilitySum = 0.0 ; if ( k < 0 ) { } else if ( k < 1 ) { //aka k==0 probabilitySum = ( 1 - p ) ; } else { //k>=1 aka k==1 probabilitySum = 1.0 ; } return pr... | Returns the cumulative probability under bernoulli | 106 | 9 |
36,770 | public static double binomial ( int k , double p , int n ) { if ( k < 0 || p < 0 || n < 1 ) { throw new IllegalArgumentException ( "All the parameters must be positive and n larger than 1." ) ; } k = Math . min ( k , n ) ; /* //Slow and can't handle large numbers $probability=StatsUtilities::combination($n,$k)*pow($p,$... | Returns the probability of k of a specific number of tries n and probability p | 179 | 15 |
36,771 | public static double binomialCdf ( int k , double p , int n ) { if ( k < 0 || p < 0 || n < 1 ) { throw new IllegalArgumentException ( "All the parameters must be positive and n larger than 1." ) ; } k = Math . min ( k , n ) ; double probabilitySum = approxBinomialCdf ( k , p , n ) ; return probabilitySum ; } | Returns the cumulative probability of k of a specific number of tries n and probability p | 90 | 16 |
36,772 | private static double approxBinomialCdf ( int k , double p , int n ) { //use an approximation as described at http://www.math.ucla.edu/~tom/distributions/binomial.html double Z = p ; double A = k + 1 ; double B = n - k ; double S = A + B ; double BT = Math . exp ( ContinuousDistributions . logGamma ( S ) - ContinuousDi... | Returns the a good approximation of cumulative probability of k of a specific number of tries n and probability p | 227 | 20 |
36,773 | public static double geometric ( int k , double p ) { if ( k <= 0 || p < 0 ) { throw new IllegalArgumentException ( "All the parameters must be positive." ) ; } double probability = Math . pow ( 1 - p , k - 1 ) * p ; return probability ; } | Returns the probability that the first success requires k trials with probability of success p | 63 | 15 |
36,774 | public static double geometricCdf ( int k , double p ) { if ( k <= 0 || p < 0 ) { throw new IllegalArgumentException ( "All the parameters must be positive." ) ; } double probabilitySum = 0.0 ; for ( int i = 1 ; i <= k ; ++ i ) { probabilitySum += geometric ( i , p ) ; } return probabilitySum ; } | Returns the cumulative probability of geometric | 82 | 6 |
36,775 | public static double negativeBinomial ( int n , int r , double p ) { //tested its validity with http://www.mathcelebrity.com/binomialneg.php if ( n < 0 || r < 0 || p < 0 ) { throw new IllegalArgumentException ( "All the parameters must be positive." ) ; } n = Math . max ( n , r ) ; //obvisouly the total number of tries... | Returns the probability of requiring n tries to achieve r successes with probability of success p | 146 | 16 |
36,776 | public static double negativeBinomialCdf ( int n , int r , double p ) { if ( n < 0 || r < 0 || p < 0 ) { throw new IllegalArgumentException ( "All the parameters must be positive." ) ; } n = Math . max ( n , r ) ; double probabilitySum = 0.0 ; for ( int i = 0 ; i <= r ; ++ i ) { probabilitySum += negativeBinomial ( n ,... | Returns the cumulative probability of negativeBinomial | 108 | 9 |
36,777 | public static double uniformCdf ( int k , int n ) { if ( k < 0 || n < 1 ) { throw new IllegalArgumentException ( "All the parameters must be positive and n larger than 1." ) ; } k = Math . min ( k , n ) ; double probabilitySum = k * uniform ( n ) ; return probabilitySum ; } | Returns the cumulative probability of uniform | 75 | 6 |
36,778 | public static double hypergeometric ( int k , int n , int Kp , int Np ) { if ( k < 0 || n < 0 || Kp < 0 || Np < 0 ) { throw new IllegalArgumentException ( "All the parameters must be positive." ) ; } Kp = Math . max ( k , Kp ) ; Np = Math . max ( n , Np ) ; /* //slow! $probability=StatsUtilities::combination($Kp,$k)*St... | Returns the probability of finding k successes on a sample of n from a population with Kp successes and size Np | 216 | 23 |
36,779 | public static double hypergeometricCdf ( int k , int n , int Kp , int Np ) { if ( k < 0 || n < 0 || Kp < 0 || Np < 0 ) { throw new IllegalArgumentException ( "All the parameters must be positive." ) ; } Kp = Math . max ( k , Kp ) ; Np = Math . max ( n , Np ) ; /* //slow! $probabilitySum=0; for($i=0;$i<=$k;++$i) { $prob... | Returns the cumulative probability of hypergeometric | 192 | 8 |
36,780 | public static double poisson ( int k , double lamda ) { if ( k < 0 || lamda < 0 ) { throw new IllegalArgumentException ( "All the parameters must be positive." ) ; } /* //Slow $probability=pow($lamda,$k)*exp(-$lamda)/StatsUtilities::factorial($k); */ //fast and can handle large numbers //Cdf(k)-Cdf(k-1) double probabil... | Returns the probability of k occurrences when rate is lamda | 138 | 11 |
36,781 | public static double poissonCdf ( int k , double lamda ) { if ( k < 0 || lamda < 0 ) { throw new IllegalArgumentException ( "All the parameters must be positive." ) ; } /* //Slow! $probabilitySum=0; for($i=0;$i<=$k;++$i) { $probabilitySum+=self::poisson($i,$lamda); } */ //Faster solution as described at: http://www.mat... | Returns the cumulative probability of poisson | 155 | 7 |
36,782 | public static int count ( Iterable it ) { int n = 0 ; for ( Object v : it ) { if ( v != null ) { ++ n ; } } return n ; } | Returns the number of not - null items in the iteratable . | 39 | 13 |
36,783 | public static double sum ( FlatDataCollection flatDataCollection ) { double sum = 0.0 ; Iterator < Double > it = flatDataCollection . iteratorDouble ( ) ; while ( it . hasNext ( ) ) { Double value = it . next ( ) ; if ( value != null ) { sum += value ; } } return sum ; } | Returns the sum of a Collection | 72 | 6 |
36,784 | public static double mean ( FlatDataCollection flatDataCollection ) { int n = 0 ; double mean = 0.0 ; Iterator < Double > it = flatDataCollection . iteratorDouble ( ) ; while ( it . hasNext ( ) ) { Double value = it . next ( ) ; if ( value != null ) { ++ n ; mean += value ; } } if ( n == 0 ) { throw new IllegalArgument... | Calculates the simple mean | 113 | 6 |
36,785 | public static double meanSE ( FlatDataCollection flatDataCollection ) { double std = std ( flatDataCollection , true ) ; double meanSE = std / Math . sqrt ( count ( flatDataCollection ) ) ; return meanSE ; } | Calculates Standard Error of Mean under SRS | 50 | 10 |
36,786 | public static double median ( FlatDataCollection flatDataCollection ) { double [ ] doubleArray = flatDataCollection . stream ( ) . filter ( x -> x != null ) . mapToDouble ( TypeInference :: toDouble ) . toArray ( ) ; int n = doubleArray . length ; if ( n == 0 ) { throw new IllegalArgumentException ( "The provided colle... | Calculates the median . | 152 | 6 |
36,787 | public static double min ( FlatDataCollection flatDataCollection ) { double min = Double . POSITIVE_INFINITY ; Iterator < Double > it = flatDataCollection . iteratorDouble ( ) ; while ( it . hasNext ( ) ) { Double v = it . next ( ) ; if ( v != null && min > v ) { min = v ; } } return min ; } | Calculates Minimum . | 82 | 5 |
36,788 | public static double max ( FlatDataCollection flatDataCollection ) { double max = Double . NEGATIVE_INFINITY ; Iterator < Double > it = flatDataCollection . iteratorDouble ( ) ; while ( it . hasNext ( ) ) { Double v = it . next ( ) ; if ( v != null && max < v ) { max = v ; } } return max ; } | Calculates Maximum . | 82 | 5 |
36,789 | public static double minAbsolute ( FlatDataCollection flatDataCollection ) { double minAbs = Double . POSITIVE_INFINITY ; Iterator < Double > it = flatDataCollection . iteratorDouble ( ) ; while ( it . hasNext ( ) ) { Double v = it . next ( ) ; if ( v != null ) { minAbs = Math . min ( minAbs , Math . abs ( v ) ) ; } } ... | Calculates Minimum absolute value . | 96 | 7 |
36,790 | public static double maxAbsolute ( FlatDataCollection flatDataCollection ) { double maxAbs = 0.0 ; Iterator < Double > it = flatDataCollection . iteratorDouble ( ) ; while ( it . hasNext ( ) ) { Double v = it . next ( ) ; if ( v != null ) { maxAbs = Math . max ( maxAbs , Math . abs ( v ) ) ; } } return maxAbs ; } | Calculates Maximum absolute value . | 90 | 7 |
36,791 | public static double geometricMean ( FlatDataCollection flatDataCollection ) { int n = 0 ; double geometricMean = 0.0 ; Iterator < Double > it = flatDataCollection . iteratorDouble ( ) ; while ( it . hasNext ( ) ) { Double v = it . next ( ) ; if ( v != null ) { if ( v <= 0.0 ) { throw new IllegalArgumentException ( "Ne... | Calculates Geometric Mean | 137 | 6 |
36,792 | public static double harmonicMean ( FlatDataCollection flatDataCollection ) { int n = 0 ; double harmonicMean = 0.0 ; Iterator < Double > it = flatDataCollection . iteratorDouble ( ) ; while ( it . hasNext ( ) ) { Double v = it . next ( ) ; if ( v != null ) { ++ n ; harmonicMean += 1.0 / v ; } } harmonicMean = n / harm... | Calculates Harmonic Mean | 102 | 6 |
36,793 | public static double variance ( FlatDataCollection flatDataCollection , boolean isSample ) { /* Uses the formal Variance = E(X^2) - mean^2 */ int n = 0 ; double mean = 0.0 ; double squaredMean = 0.0 ; Iterator < Double > it = flatDataCollection . iteratorDouble ( ) ; while ( it . hasNext ( ) ) { Double v = it . next ( ... | Calculates the Variance | 196 | 6 |
36,794 | public static double std ( FlatDataCollection flatDataCollection , boolean isSample ) { double variance = variance ( flatDataCollection , isSample ) ; double std = Math . sqrt ( variance ) ; return std ; } | Calculates the Standard Deviation | 45 | 7 |
36,795 | public static double cv ( double std , double mean ) { if ( mean == 0 ) { return Double . POSITIVE_INFINITY ; } double cv = std / mean ; return cv ; } | Calculates Coefficient of variation | 45 | 7 |
36,796 | public static double moment ( FlatDataCollection flatDataCollection , int r ) { double mean = mean ( flatDataCollection ) ; return moment ( flatDataCollection , r , mean ) ; } | Calculates Moment R if the mean is not known . | 39 | 12 |
36,797 | public static double moment ( FlatDataCollection flatDataCollection , int r , double mean ) { int n = 0 ; double moment = 0.0 ; Iterator < Double > it = flatDataCollection . iteratorDouble ( ) ; while ( it . hasNext ( ) ) { Double v = it . next ( ) ; if ( v != null ) { ++ n ; moment += Math . pow ( v - mean , r ) ; } }... | Calculates Moment R if the mean is known . | 128 | 11 |
36,798 | public static AssociativeArray percentiles ( FlatDataCollection flatDataCollection , int cutPoints ) { double [ ] doubleArray = flatDataCollection . stream ( ) . filter ( x -> x != null ) . mapToDouble ( TypeInference :: toDouble ) . toArray ( ) ; int n = doubleArray . length ; if ( n <= 0 || cutPoints <= 0 || n < cutP... | Calculates the percentiles given a number of cutPoints | 476 | 12 |
36,799 | public static double autocorrelation ( FlatDataList flatDataList , int lags ) { int n = count ( flatDataList ) ; if ( n <= 0 || lags <= 0 || n < lags ) { throw new IllegalArgumentException ( "All the parameters must be positive and n larger than lags." ) ; } FlatDataCollection flatDataCollection = flatDataList . toFlat... | Calculates the autocorrelation of a flatDataCollection for a predifined lag | 205 | 19 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.