idx int64 0 165k | question stringlengths 73 4.15k | target stringlengths 5 918 | len_question int64 21 890 | len_target int64 3 255 |
|---|---|---|---|---|
36,800 | public static AssociativeArray frequencies ( FlatDataCollection flatDataCollection ) { AssociativeArray frequencies = new AssociativeArray ( ) ; for ( Object value : flatDataCollection ) { Object counter = frequencies . get ( value ) ; if ( counter == null ) { frequencies . put ( value , 1 ) ; } else { frequencies . pu... | Calculates the Frequency Table | 93 | 6 |
36,801 | public static void normalize ( AssociativeArray associativeArray ) { double sum = 0.0 ; //Prevents numeric underflow by subtracting the max. References: http://www.youtube.com/watch?v=-RVM21Voo7Q for ( Map . Entry < Object , Object > entry : associativeArray . entrySet ( ) ) { Double value = TypeInference . toDouble ( ... | Normalizes the provided associative array by dividing its values with the sum of the observations . | 180 | 18 |
36,802 | public static void normalizeExp ( AssociativeArray associativeArray ) { double max = max ( associativeArray . toFlatDataCollection ( ) ) ; double sum = 0.0 ; //Prevents numeric underflow by subtracting the max. References: http://www.youtube.com/watch?v=-RVM21Voo7Q for ( Map . Entry < Object , Object > entry : associat... | Normalizes the exponentials of provided associative array by using the log - sum - exp trick . | 206 | 21 |
36,803 | @ Override public Map < Integer , String > extract ( final String text ) { Set < String > tmpKwd = new LinkedHashSet <> ( generateTokenizer ( ) . tokenize ( text ) ) ; Map < Integer , String > keywordSequence = new LinkedHashMap <> ( ) ; int position = 0 ; for ( String keyword : tmpKwd ) { keywordSequence . put ( posit... | This method gets as input a string and returns as output a numbered sequence of the unique tokens . In the returned map as keys we store the position of the word in the original string and as value the actual unique token in that position . Note that the sequence includes only the position of the first occurrence of ea... | 102 | 69 |
36,804 | private static void setStorageEngine ( Dataframe dataset ) { //create a single storage engine for all the MapRealMatrixes if ( storageEngine == null ) { synchronized ( DataframeMatrix . class ) { if ( storageEngine == null ) { String storageName = "mdf" + RandomGenerator . getThreadLocalRandomUnseeded ( ) . nextLong ( ... | Initializes the static storage engine if it s not already set . | 103 | 13 |
36,805 | public static DataframeMatrix newInstance ( Dataframe dataset , boolean addConstantColumn , Map < Integer , Integer > recordIdsReference , Map < Object , Integer > featureIdsReference ) { if ( ! featureIdsReference . isEmpty ( ) ) { throw new IllegalArgumentException ( "The featureIdsReference map should be empty." ) ;... | Method used to generate a training Dataframe to a DataframeMatrix and extracts its contents to Matrixes . It populates the featureIdsReference map with the mappings between the feature names and the column ids of the matrix . Typically used to convert the training dataset . | 521 | 55 |
36,806 | public static RealVector parseRecord ( Record r , Map < Object , Integer > featureIdsReference ) { if ( featureIdsReference . isEmpty ( ) ) { throw new IllegalArgumentException ( "The featureIdsReference map should not be empty." ) ; } int d = featureIdsReference . size ( ) ; //create an Map-backed vector only if we ha... | Parses a single Record and converts it to RealVector by using an already existing mapping between feature names and column ids . | 287 | 26 |
36,807 | public void setMaxNumberOfThreadsPerTask ( Integer maxNumberOfThreadsPerTask ) { if ( maxNumberOfThreadsPerTask < 0 ) { throw new IllegalArgumentException ( "The max number of threads can not be negative." ) ; } else if ( maxNumberOfThreadsPerTask == 0 ) { this . maxNumberOfThreadsPerTask = AVAILABLE_PROCESSORS ; } els... | Setter for the maximum number of threads which can be used for a specific task by the framework . By convention if the value is 0 the max number of threads is set equal to the available processors . | 129 | 40 |
36,808 | public < T > void forEach ( Stream < T > stream , Consumer < ? super T > action ) { Runnable runnable = ( ) -> stream . forEach ( action ) ; ThreadMethods . forkJoinExecution ( runnable , concurrencyConfiguration , stream . isParallel ( ) ) ; } | Executes forEach on the provided stream . If the Stream is parallel it is executed using the custom pool else it is executed directly from the main thread . | 67 | 31 |
36,809 | public < T , R > Stream < R > map ( Stream < T > stream , Function < ? super T , ? extends R > mapper ) { Callable < Stream < R >> callable = ( ) -> stream . map ( mapper ) ; return ThreadMethods . forkJoinExecution ( callable , concurrencyConfiguration , stream . isParallel ( ) ) ; } | Executes map on the provided stream . If the Stream is parallel it is executed using the custom pool else it is executed directly from the main thread . | 79 | 30 |
36,810 | public < T , R , A > R collect ( Stream < T > stream , Collector < ? super T , A , R > collector ) { Callable < R > callable = ( ) -> stream . collect ( collector ) ; return ThreadMethods . forkJoinExecution ( callable , concurrencyConfiguration , stream . isParallel ( ) ) ; } | Executes collect on the provided stream using the provided collector . If the Stream is parallel it is executed using the custom pool else it is executed directly from the main thread . | 74 | 34 |
36,811 | public < T > Optional < T > min ( Stream < T > stream , Comparator < ? super T > comparator ) { Callable < Optional < T >> callable = ( ) -> stream . min ( comparator ) ; return ThreadMethods . forkJoinExecution ( callable , concurrencyConfiguration , stream . isParallel ( ) ) ; } | Executes min on the provided stream using the provided collector . If the Stream is parallel it is executed using the custom pool else it is executed directly from the main thread . | 74 | 34 |
36,812 | public double sum ( DoubleStream stream ) { Callable < Double > callable = ( ) -> stream . sum ( ) ; return ThreadMethods . forkJoinExecution ( callable , concurrencyConfiguration , stream . isParallel ( ) ) ; } | Executes sum on the provided DoubleStream using the provided collector . If the Stream is parallel it is executed using the custom pool else it is executed directly from the main thread . | 52 | 35 |
36,813 | public void save ( String storageName ) { //store the objects on storage storageEngine . saveObject ( "modelParameters" , modelParameters ) ; storageEngine . saveObject ( "trainingParameters" , trainingParameters ) ; //rename the storage storageEngine . rename ( storageName ) ; //reload the model parameters, necessary ... | Saves the KnowledgeBase using the storage engine . | 100 | 10 |
36,814 | protected AbstractTokenizer generateTokenizer ( ) { Class < ? extends AbstractTokenizer > tokenizer = parameters . getTokenizer ( ) ; if ( tokenizer == null ) { return null ; } try { return tokenizer . newInstance ( ) ; } catch ( InstantiationException | IllegalAccessException ex ) { throw new RuntimeException ( ex ) ;... | Generates a new AbstractTokenizer object by using the provided tokenizer class . | 75 | 16 |
36,815 | public static < T extends AbstractTextExtractor , TP extends AbstractTextExtractor . AbstractParameters > T newInstance ( TP parameters ) { try { //By convention the Parameters are enclosed in the Extactor. Class < T > tClass = ( Class < T > ) parameters . getClass ( ) . getEnclosingClass ( ) ; return tClass . getConst... | Generates a new instance of a AbstractTextExtractor by providing the Class of the AbstractTextExtractor . | 133 | 22 |
36,816 | public static AssociativeArray2D survivalFunction ( FlatDataCollection flatDataCollection ) { AssociativeArray2D survivalFunction = new AssociativeArray2D ( ) ; //AssociativeArray2D is important to maintain the order of the first keys Queue < Double > censoredData = new PriorityQueue <> ( ) ; Queue < Double > uncensore... | Calculates the survivalFunction by processing the flatDataCollection with the censored internalData . The flatDataCollection contains numbers in string format . The Censored entries contain a + symbol at the end of the number . | 839 | 44 |
36,817 | public static double median ( AssociativeArray2D survivalFunction ) { Double ApointTi = null ; Double BpointTi = null ; int n = survivalFunction . size ( ) ; if ( n == 0 ) { throw new IllegalArgumentException ( "The provided collection can't be empty." ) ; } for ( Map . Entry < Object , AssociativeArray > entry : survi... | Calculates median . | 420 | 5 |
36,818 | private static double ar ( AssociativeArray2D survivalFunction , int r ) { if ( survivalFunction . isEmpty ( ) ) { throw new IllegalArgumentException ( "The provided collection can't be empty." ) ; } AssociativeArray2D survivalFunctionCopy = survivalFunction ; //check if last one is censored and close it Map . Entry < ... | Ar function used to estimate mean and variance . | 586 | 9 |
36,819 | public static double meanVariance ( AssociativeArray2D survivalFunction ) { double meanVariance = 0 ; int m = 0 ; int n = 0 ; for ( Map . Entry < Object , AssociativeArray > entry : survivalFunction . entrySet ( ) ) { //Object ti = entry.getKey(); AssociativeArray row = entry . getValue ( ) ; Number mi = ( Number ) row... | Calculates the Variance of Mean . | 327 | 9 |
36,820 | public VM validate ( Iterator < Split > dataSplits , TrainingParameters trainingParameters ) { AbstractModeler modeler = MLBuilder . create ( trainingParameters , configuration ) ; List < VM > validationMetricsList = new LinkedList <> ( ) ; while ( dataSplits . hasNext ( ) ) { Split s = dataSplits . next ( ) ; Datafram... | Estimates the average validation metrics on the provided data splits . | 203 | 12 |
36,821 | public static < K > void updateWeights ( double l1 , double learningRate , Map < K , Double > weights , Map < K , Double > newWeights ) { if ( l1 > 0.0 ) { /* //SGD-L1 (Naive) for(Map.Entry<K, Double> e : weights.entrySet()) { K column = e.getKey(); newWeights.put(column, newWeights.get(column) + l1*Math.signum(e.getVa... | Updates the weights by applying the L1 regularization . | 295 | 12 |
36,822 | public static < K > double estimatePenalty ( double l1 , Map < K , Double > weights ) { double penalty = 0.0 ; if ( l1 > 0.0 ) { double sumAbsWeights = 0.0 ; for ( double w : weights . values ( ) ) { sumAbsWeights += Math . abs ( w ) ; } penalty = l1 * sumAbsWeights ; } return penalty ; } | Estimates the penalty by adding the L1 regularization . | 90 | 12 |
36,823 | public static DataType getDataType ( Object v ) { //NOTE: DO NOT CHANGE THE ORDER OF THE IFS!!! if ( DataType . BOOLEAN . isInstance ( v ) ) { return DataType . BOOLEAN ; } else if ( DataType . ORDINAL . isInstance ( v ) ) { return DataType . ORDINAL ; } else if ( DataType . NUMERICAL . isInstance ( v ) ) { return Data... | Detects the DataType of a particular value . | 176 | 10 |
36,824 | public static Double toDouble ( Object v ) { if ( v == null ) { return null ; } if ( v instanceof Boolean ) { return ( ( Boolean ) v ) ? 1.0 : 0.0 ; } return ( ( Number ) v ) . doubleValue ( ) ; } | Converts safely any Number to Double . | 60 | 8 |
36,825 | public static Integer toInteger ( Object v ) { if ( v == null ) { return null ; } if ( v instanceof Boolean ) { return ( ( Boolean ) v ) ? 1 : 0 ; } return ( ( Number ) v ) . intValue ( ) ; } | Converts safely any Number to Integer . | 56 | 8 |
36,826 | public static double calculateScore ( FlatDataList errorList ) { double DWdeltasquare = 0 ; double DWetsquare = 0 ; int n = errorList . size ( ) ; for ( int i = 0 ; i < n ; ++ i ) { Double error = errorList . getDouble ( i ) ; if ( i >= 1 ) { Double errorPrevious = errorList . getDouble ( i - 1 ) ; if ( errorPrevious !... | Calculates DW score | 148 | 5 |
36,827 | public final Iterator < Double > iteratorDouble ( ) { return new Iterator < Double > ( ) { private final Iterator < Object > objectIterator = ( Iterator < Object > ) internalData . iterator ( ) ; /** {@inheritDoc} */ @ Override public boolean hasNext ( ) { return objectIterator . hasNext ( ) ; } /** {@inheritDoc} */ @ ... | Iterator which casts the values of the Data Structure from Object to Double . This iterator should be used only when the underling Data Structure contains Numeric or Boolean values . Accessing this iterator when other data types are stored will lead to an Exception . | 139 | 49 |
36,828 | public static double euclidean ( AssociativeArray a1 , AssociativeArray a2 ) { Map < Object , Double > columnDistances = columnDistances ( a1 , a2 , null ) ; double distance = 0.0 ; for ( double columnDistance : columnDistances . values ( ) ) { distance += ( columnDistance * columnDistance ) ; } return Math . sqrt ( di... | Estimates the euclidean distance of two Associative Arrays . | 87 | 15 |
36,829 | public static double euclideanWeighted ( AssociativeArray a1 , AssociativeArray a2 , Map < Object , Double > columnWeights ) { Map < Object , Double > columnDistances = columnDistances ( a1 , a2 , columnWeights . keySet ( ) ) ; double distance = 0.0 ; for ( Map . Entry < Object , Double > entry : columnDistances . entr... | Estimates the weighted euclidean distance of two Associative Arrays . | 138 | 16 |
36,830 | public static double manhattan ( AssociativeArray a1 , AssociativeArray a2 ) { Map < Object , Double > columnDistances = columnDistances ( a1 , a2 , null ) ; double distance = 0.0 ; for ( double columnDistance : columnDistances . values ( ) ) { distance += Math . abs ( columnDistance ) ; } return distance ; } | Estimates the manhattan distance of two Associative Arrays . | 79 | 13 |
36,831 | public static double manhattanWeighted ( AssociativeArray a1 , AssociativeArray a2 , Map < Object , Double > columnWeights ) { Map < Object , Double > columnDistances = columnDistances ( a1 , a2 , columnWeights . keySet ( ) ) ; double distance = 0.0 ; for ( Map . Entry < Object , Double > entry : columnDistances . entr... | Estimates the weighted manhattan distance of two Associative Arrays . | 123 | 14 |
36,832 | public static AssociativeArray getRanksFromValues ( FlatDataList flatDataCollection ) { AssociativeArray tiesCounter = new AssociativeArray ( ) ; Map < Object , Double > key2AvgRank = new LinkedHashMap <> ( ) ; _buildRankArrays ( flatDataCollection , tiesCounter , key2AvgRank ) ; int i = 0 ; for ( Object value : flatDa... | Replaces the actual values of the flatDataCollection with their ranks and returns in the tieCounter the keys that occur more than once and the number of occurrences . The tieCounter does not store the list and ranks of the actual ties because we never use them . | 113 | 52 |
36,833 | public static AssociativeArray getRanksFromValues ( AssociativeArray associativeArray ) { AssociativeArray tiesCounter = new AssociativeArray ( ) ; Map < Object , Double > key2AvgRank = new LinkedHashMap <> ( ) ; _buildRankArrays ( associativeArray . toFlatDataList ( ) , tiesCounter , key2AvgRank ) ; for ( Map . Entry ... | Replaces the actual values of the associativeArray with their ranks and returns in the tieCounter the keys that occur more than once and the number of occurrences . The tieCounter does not store the list and ranks of the actual ties because we never use them . | 137 | 52 |
36,834 | public void fit ( Map < Object , URI > datasets ) { TrainingParameters tp = ( TrainingParameters ) knowledgeBase . getTrainingParameters ( ) ; Dataframe trainingData = Dataframe . Builder . parseTextFiles ( datasets , AbstractTextExtractor . newInstance ( tp . getTextExtractorParameters ( ) ) , knowledgeBase . getConfi... | Trains a Machine Learning modeler using the provided dataset files . The data map should have as index the names of each class and as values the URIs of the training files . The training files should contain one training example per row . | 90 | 47 |
36,835 | public Dataframe predict ( URI datasetURI ) { //create a dummy dataset map Map < Object , URI > dataset = new HashMap <> ( ) ; dataset . put ( null , datasetURI ) ; TrainingParameters trainingParameters = ( TrainingParameters ) knowledgeBase . getTrainingParameters ( ) ; Dataframe testDataset = Dataframe . Builder . pa... | Generates a Dataframe with the predictions for the provided data file . The data file should contain the text of one observation per row . | 122 | 27 |
36,836 | public Record predict ( String text ) { TrainingParameters trainingParameters = ( TrainingParameters ) knowledgeBase . getTrainingParameters ( ) ; Dataframe testDataset = new Dataframe ( knowledgeBase . getConfiguration ( ) ) ; testDataset . add ( new Record ( new AssociativeArray ( AbstractTextExtractor . newInstance ... | It generates a prediction for a particular string . It returns a Record object which contains the observation data the predicted class and probabilities . | 135 | 25 |
36,837 | public ClassificationMetrics validate ( Dataframe testDataset ) { logger . info ( "validate()" ) ; predict ( testDataset ) ; ClassificationMetrics vm = new ClassificationMetrics ( testDataset ) ; return vm ; } | It validates the modeler using the provided dataset and it returns the ClassificationMetrics . The testDataset should contain the real target variables . | 53 | 30 |
36,838 | public ClassificationMetrics validate ( Map < Object , URI > datasets ) { TrainingParameters trainingParameters = ( TrainingParameters ) knowledgeBase . getTrainingParameters ( ) ; //build the testDataset Dataframe testDataset = Dataframe . Builder . parseTextFiles ( datasets , AbstractTextExtractor . newInstance ( tra... | It validates the modeler using the provided dataset files . The data map should have as index the names of each class and as values the URIs of the training files . The data files should contain one example per row . | 113 | 45 |
36,839 | protected final String createKnowledgeBaseName ( String storageName , String separator ) { return storageName + separator + getClass ( ) . getSimpleName ( ) ; } | Generates a name for the KnowledgeBase . | 37 | 9 |
36,840 | public static < T > Set < Set < T > > combinations ( Set < T > elements , int subsetSize ) { return combinationsStream ( elements , subsetSize ) . collect ( Collectors . toSet ( ) ) ; } | Returns all the possible combinations of the set . | 47 | 9 |
36,841 | public static < T > Stream < Set < T > > combinationsStream ( Set < T > elements , int subsetSize ) { if ( subsetSize == 0 ) { return Stream . of ( new HashSet <> ( ) ) ; } else if ( subsetSize <= elements . size ( ) ) { Set < T > remainingElements = elements ; Iterator < T > it = remainingElements . iterator ( ) ; T X... | Returns all the possible combinations of the set in a stream . | 190 | 12 |
36,842 | public static < T > Iterator < T [ ] > combinationsIterator ( final T [ ] elements , final int subsetSize ) { return new Iterator < T [ ] > ( ) { /** * The index on the combination array. */ private int r = 0 ; /** * The index on the elements array. */ private int index = 0 ; /** * The indexes of the elements of the co... | Fast and memory efficient way to return an iterator with all the possible combinations of an array . | 477 | 18 |
36,843 | public static < T > Stream < T > stream ( Spliterator < T > spliterator , boolean parallel ) { return StreamSupport . < T > stream ( spliterator , parallel ) ; } | Converts an spliterator to a stream . | 39 | 9 |
36,844 | public static < T > Stream < T > stream ( Stream < T > stream , boolean parallel ) { if ( parallel ) { return stream . parallel ( ) ; } else { return stream . sequential ( ) ; } } | Converts an Stream to parallel or sequential . | 45 | 9 |
36,845 | public static Method findMethod ( Object obj , String methodName , Object ... params ) { Class < ? > [ ] classArray = new Class < ? > [ params . length ] ; for ( int i = 0 ; i < params . length ; i ++ ) { classArray [ i ] = params [ i ] . getClass ( ) ; } try { //look on all the public, protected, default and private m... | Finds the public protected default or private method of the object with the provided name and parameters . | 330 | 19 |
36,846 | @ Override public Map < String , Double > extract ( final String text ) { Map < Integer , String > ID2word = new HashMap <> ( ) ; //ID=>Kwd Map < Integer , Double > ID2occurrences = new HashMap <> ( ) ; //ID=>counts/scores Map < Integer , Integer > position2ID = new LinkedHashMap <> ( ) ; //word position=>ID maintain t... | This method gets as input a string and returns as output a map with the extracted keywords along with the number of their scores in the text . Their scores are a combination of occurrences and proximity metrics . | 603 | 39 |
36,847 | public static FlatDataCollection weightedSampling ( AssociativeArray weightedTable , int n , boolean withReplacement ) { FlatDataList sampledIds = new FlatDataList ( ) ; double sumOfFrequencies = Descriptives . sum ( weightedTable . toFlatDataCollection ( ) ) ; int populationN = weightedTable . size ( ) ; for ( int i =... | Samples n ids based on their a Table which contains weights probabilities or frequencies . | 267 | 17 |
36,848 | public static double xbarVariance ( double variance , int sampleN , int populationN ) { if ( populationN <= 0 || sampleN <= 0 || sampleN > populationN ) { throw new IllegalArgumentException ( "All the parameters must be positive and sampleN smaller than populationN." ) ; } double xbarVariance = ( 1.0 - ( double ) sampl... | Calculates Variance for Xbar for a finite population size | 97 | 13 |
36,849 | public static double xbarStd ( double std , int sampleN ) { return Math . sqrt ( xbarVariance ( std * std , sampleN , Integer . MAX_VALUE ) ) ; } | Calculates Standard Deviation for Xbar for infinite population size | 43 | 13 |
36,850 | public static double xbarStd ( double std , int sampleN , int populationN ) { return Math . sqrt ( xbarVariance ( std * std , sampleN , populationN ) ) ; } | Calculates Standard Deviation for Xbar for finite population size | 44 | 13 |
36,851 | public static double pbarVariance ( double pbar , int sampleN , int populationN ) { if ( populationN <= 0 || sampleN <= 0 || sampleN > populationN ) { throw new IllegalArgumentException ( "All the parameters must be positive and sampleN smaller than populationN." ) ; } double f = ( double ) sampleN / populationN ; doub... | Calculates Variance for Pbar for a finite population size | 121 | 13 |
36,852 | public static double pbarStd ( double pbar , int sampleN ) { return Math . sqrt ( pbarVariance ( pbar , sampleN , Integer . MAX_VALUE ) ) ; } | Calculates Standard Deviation for Pbar for infinite population size | 43 | 13 |
36,853 | public static double pbarStd ( double pbar , int sampleN , int populationN ) { return Math . sqrt ( pbarVariance ( pbar , sampleN , populationN ) ) ; } | Calculates Standard Deviation for Pbar for finite population size | 44 | 13 |
36,854 | public static int minimumSampleSizeForMaximumXbarStd ( double maximumXbarStd , double populationStd , int populationN ) { if ( populationN <= 0 ) { throw new IllegalArgumentException ( "The populationN parameter must be positive." ) ; } double minimumSampleN = 1.0 / ( Math . pow ( maximumXbarStd / populationStd , 2 ) +... | Returns the minimum required sample size when we set a specific maximum Xbar STD Error for finite population size . | 107 | 21 |
36,855 | public static int minimumSampleSizeForGivenDandMaximumRisk ( double d , double aLevel , double populationStd ) { return minimumSampleSizeForGivenDandMaximumRisk ( d , aLevel , populationStd , Integer . MAX_VALUE ) ; } | Returns the minimum required sample size when we set a predifined limit d and a maximum probability Risk a for infinite population size | 56 | 25 |
36,856 | public static int minimumSampleSizeForGivenDandMaximumRisk ( double d , double aLevel , double populationStd , int populationN ) { if ( populationN <= 0 || aLevel <= 0 || d <= 0 ) { throw new IllegalArgumentException ( "All the parameters must be positive." ) ; } double a = 1.0 - aLevel / 2.0 ; double Za = ContinuousDi... | Returns the minimum required sample size when we set a predefined limit d and a maximum probability Risk a for finite population size | 205 | 24 |
36,857 | public static double shinglerSimilarity ( String text1 , String text2 , int w ) { preprocessDocument ( text1 ) ; preprocessDocument ( text2 ) ; NgramsExtractor . Parameters parameters = new NgramsExtractor . Parameters ( ) ; parameters . setMaxCombinations ( w ) ; parameters . setMaxDistanceBetweenKwds ( 0 ) ; paramete... | Estimates the w - shingler similarity between two texts . The w is the number of word sequences that are used for the estimation . | 345 | 28 |
36,858 | private void bigMapInitializer ( StorageEngine storageEngine ) { //get all the fields from all the inherited classes for ( Field field : ReflectionMethods . getAllFields ( new LinkedList <> ( ) , this . getClass ( ) ) ) { //if the field is annotated with BigMap if ( field . isAnnotationPresent ( BigMap . class ) ) { in... | Initializes all the fields of the class which are marked with the BigMap annotation automatically . | 95 | 18 |
36,859 | private void initializeBigMapField ( StorageEngine storageEngine , Field field ) { field . setAccessible ( true ) ; try { BigMap a = field . getAnnotation ( BigMap . class ) ; field . set ( this , storageEngine . getBigMap ( field . getName ( ) , a . keyClass ( ) , a . valueClass ( ) , a . mapType ( ) , a . storageHint... | Initializes a field which is marked as BigMap . | 126 | 11 |
36,860 | public Trainable put ( String key , Trainable value ) { return bundle . put ( key , value ) ; } | Puts the trainable in the bundle using a specific key and returns the previous entry or null . | 24 | 20 |
36,861 | public void setParallelized ( boolean parallelized ) { for ( Trainable t : bundle . values ( ) ) { if ( t != null && t instanceof Parallelizable ) { ( ( Parallelizable ) t ) . setParallelized ( parallelized ) ; } } } | Updates the parallelized flag of all wrapped algorithms . | 58 | 11 |
36,862 | public static < T extends Trainable , TP extends Parameterizable > T create ( TP trainingParameters , Configuration configuration ) { try { Class < T > aClass = ( Class < T > ) trainingParameters . getClass ( ) . getEnclosingClass ( ) ; Constructor < T > constructor = aClass . getDeclaredConstructor ( trainingParameter... | Creates a new algorithm based on the provided training parameters . | 147 | 12 |
36,863 | public static < T extends Trainable > T load ( Class < T > aClass , String storageName , Configuration configuration ) { try { Constructor < T > constructor = aClass . getDeclaredConstructor ( String . class , Configuration . class ) ; constructor . setAccessible ( true ) ; return constructor . newInstance ( storageNam... | Loads an algorithm from the storage . | 115 | 8 |
36,864 | public static double combination ( int n , int k ) { if ( n < k ) { throw new IllegalArgumentException ( "The n can't be smaller than k." ) ; } double combinations = 1.0 ; double lowerBound = n - k ; for ( int i = n ; i > lowerBound ; i -- ) { combinations *= i / ( i - lowerBound ) ; } return combinations ; } | It estimates the number of k - combinations of n objects . | 87 | 12 |
36,865 | private StorageType getStorageTypeFromName ( String name ) { for ( Map . Entry < StorageType , DB > entry : storageRegistry . entrySet ( ) ) { DB storage = entry . getValue ( ) ; if ( isOpenStorage ( storage ) && storage . exists ( name ) ) { return entry . getKey ( ) ; } } return null ; //either the Map has not create... | Returns the StorageType using the name of the map . It assumes that names are unique across all StorageType . If not found null is returned . | 90 | 29 |
36,866 | private void closeStorageRegistry ( ) { for ( DB storage : storageRegistry . values ( ) ) { if ( isOpenStorage ( storage ) ) { storage . close ( ) ; } } storageRegistry . clear ( ) ; } | It closes all the storageengines in the registry . | 50 | 11 |
36,867 | private boolean blockedStorageClose ( StorageType storageType ) { DB storage = storageRegistry . get ( storageType ) ; if ( isOpenStorage ( storage ) ) { storage . commit ( ) ; //find the underlying engine Engine e = storage . getEngine ( ) ; while ( EngineWrapper . class . isAssignableFrom ( e . getClass ( ) ) ) { e =... | Closes the provided storage and waits until all changes are written to disk . It should be used when we move the storage to a different location . Returns true if the storage needed to be closed and false if it was not necessary . | 191 | 46 |
36,868 | @ Override public List < String > tokenize ( String text ) { List < String > tokens = new ArrayList <> ( Arrays . asList ( text . split ( "[\\p{Z}\\p{C}]+" ) ) ) ; return tokens ; } | Separates the tokens of a string by splitting it on white space . | 58 | 15 |
36,869 | public static Map . Entry < Object , Object > maxMin ( DataTable2D payoffMatrix ) { if ( payoffMatrix . isValid ( ) == false ) { throw new IllegalArgumentException ( "The payoff matrix does not have a rectangular format." ) ; } AssociativeArray minPayoffs = new AssociativeArray ( ) ; for ( Map . Entry < Object , Associ... | Returns the best option and the payoff under maxMin strategy | 243 | 11 |
36,870 | public static Map . Entry < Object , Object > maxMax ( DataTable2D payoffMatrix ) { if ( payoffMatrix . isValid ( ) == false ) { throw new IllegalArgumentException ( "The payoff matrix does not have a rectangular format." ) ; } Double maxMaxPayoff = Double . NEGATIVE_INFINITY ; Object maxMaxPayoffOption = null ; for ( ... | Returns the best option and the payoff under maxMax strategy | 233 | 11 |
36,871 | public static Map . Entry < Object , Object > savage ( DataTable2D payoffMatrix ) { if ( payoffMatrix . isValid ( ) == false ) { throw new IllegalArgumentException ( "The payoff matrix does not have a rectangular format." ) ; } //Deep clone the payoffMatrix to avoid modifying its original values DataTable2D regretMatri... | Returns the best option and the payoff under savage strategy | 253 | 10 |
36,872 | public static Map . Entry < Object , Object > laplace ( DataTable2D payoffMatrix ) { if ( payoffMatrix . isValid ( ) == false ) { throw new IllegalArgumentException ( "The payoff matrix does not have a rectangular format." ) ; } //http://orms.pef.czu.cz/text/game-theory/DecisionTheory.html AssociativeArray optionAverag... | Returns the best option and the payoff under laplace strategy | 278 | 11 |
36,873 | public static Map . Entry < Object , Object > hurwiczAlpha ( DataTable2D payoffMatrix , double alpha ) { if ( payoffMatrix . isValid ( ) == false ) { throw new IllegalArgumentException ( "The payoff matrix does not have a rectangular format." ) ; } AssociativeArray minPayoffs = new AssociativeArray ( ) ; AssociativeArr... | Returns the best option and the payoff under hurwiczAlpha strategy | 401 | 13 |
36,874 | public static Map . Entry < Object , Object > maximumLikelihood ( DataTable2D payoffMatrix , AssociativeArray eventProbabilities ) { if ( payoffMatrix . isValid ( ) == false ) { throw new IllegalArgumentException ( "The payoff matrix does not have a rectangular format." ) ; } Map . Entry < Object , Object > eventEntry ... | Returns the best option and the payoff under maximumLikelihood strategy | 148 | 12 |
36,875 | public static Map . Entry < Object , Object > bayes ( DataTable2D payoffMatrix , AssociativeArray eventProbabilities ) { if ( payoffMatrix . isValid ( ) == false ) { throw new IllegalArgumentException ( "The payoff matrix does not have a rectangular format." ) ; } AssociativeArray expectedPayoffs = new AssociativeArray... | Returns the best option and the payoff under bayes strategy | 255 | 11 |
36,876 | private static DataTable2D bivariateMatrix ( Dataframe dataSet , BivariateType type ) { DataTable2D bivariateMatrix = new DataTable2D ( ) ; //extract values of first variable Map < Object , TypeInference . DataType > columnTypes = dataSet . getXDataTypes ( ) ; Object [ ] allVariables = columnTypes . keySet ( ) . toArra... | Calculates BivariateMatrix for a given statistic | 645 | 10 |
36,877 | public static < K > void updateWeights ( double l1 , double l2 , double learningRate , Map < K , Double > weights , Map < K , Double > newWeights ) { L2Regularizer . updateWeights ( l2 , learningRate , weights , newWeights ) ; L1Regularizer . updateWeights ( l1 , learningRate , weights , newWeights ) ; } | Updates the weights by applying the ElasticNet regularization . | 86 | 12 |
36,878 | public static < K > double estimatePenalty ( double l1 , double l2 , Map < K , Double > weights ) { double penalty = 0.0 ; penalty += L2Regularizer . estimatePenalty ( l2 , weights ) ; penalty += L1Regularizer . estimatePenalty ( l1 , weights ) ; return penalty ; } | Estimates the penalty by adding the ElasticNet regularization . | 72 | 12 |
36,879 | public static int substr_count ( final String string , final String substring ) { if ( substring . length ( ) == 1 ) { return substr_count ( string , substring . charAt ( 0 ) ) ; } int count = 0 ; int idx = 0 ; while ( ( idx = string . indexOf ( substring , idx ) ) != - 1 ) { ++ idx ; ++ count ; } return count ; } | Count the number of substring occurrences . | 93 | 8 |
36,880 | public static int substr_count ( final String string , final char character ) { int count = 0 ; int n = string . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( string . charAt ( i ) == character ) { ++ count ; } } return count ; } | Count the number of times a character appears in the string . | 67 | 12 |
36,881 | public static String preg_replace ( String regex , String replacement , String subject ) { Pattern p = Pattern . compile ( regex ) ; return preg_replace ( p , replacement , subject ) ; } | Matches a string with a regex and replaces the matched components with a provided string . | 42 | 17 |
36,882 | public static String preg_replace ( Pattern pattern , String replacement , String subject ) { Matcher m = pattern . matcher ( subject ) ; StringBuffer sb = new StringBuffer ( subject . length ( ) ) ; while ( m . find ( ) ) { m . appendReplacement ( sb , replacement ) ; } m . appendTail ( sb ) ; return sb . toString ( )... | Matches a string with a pattern and replaces the matched components with a provided string . | 88 | 17 |
36,883 | public static int preg_match ( String regex , String subject ) { Pattern p = Pattern . compile ( regex ) ; return preg_match ( p , subject ) ; } | Matches a string with a regex . | 37 | 8 |
36,884 | public static int preg_match ( Pattern pattern , String subject ) { int matches = 0 ; Matcher m = pattern . matcher ( subject ) ; while ( m . find ( ) ) { ++ matches ; } return matches ; } | Matches a string with a pattern . | 49 | 8 |
36,885 | public static double round ( double d , int i ) { double multiplier = Math . pow ( 10 , i ) ; return Math . round ( d * multiplier ) / multiplier ; } | Rounds a number to a specified precision . | 37 | 9 |
36,886 | public static double log ( double d , double base ) { if ( base == 1.0 || base <= 0.0 ) { throw new IllegalArgumentException ( "Invalid base for logarithm." ) ; } return Math . log ( d ) / Math . log ( base ) ; } | Returns the logarithm of a number at an arbitrary base . | 62 | 14 |
36,887 | public static < K , V > Map < V , K > array_flip ( Map < K , V > map ) { Map < V , K > flipped = new HashMap <> ( ) ; for ( Map . Entry < K , V > entry : map . entrySet ( ) ) { flipped . put ( entry . getValue ( ) , entry . getKey ( ) ) ; } return flipped ; } | It flips the key and values of a map . | 87 | 10 |
36,888 | public static < T > void shuffle ( T [ ] array , Random rnd ) { //Implementing Fisher-Yates shuffle T tmp ; for ( int i = array . length - 1 ; i > 0 ; -- i ) { int index = rnd . nextInt ( i + 1 ) ; tmp = array [ index ] ; array [ index ] = array [ i ] ; array [ i ] = tmp ; } } | Shuffles the values of any array in place using the provided random generator . | 89 | 16 |
36,889 | public static < T extends Comparable < T > > Integer [ ] asort ( T [ ] array ) { return _asort ( array , false ) ; } | Sorts an array in ascending order and returns an array with indexes of the original order . | 34 | 18 |
36,890 | public static < T extends Comparable < T > > Integer [ ] arsort ( T [ ] array ) { return _asort ( array , true ) ; } | Sorts an array in descending order and returns an array with indexes of the original order . | 34 | 18 |
36,891 | public static < T > void arrangeByIndex ( T [ ] array , Integer [ ] indexes ) { if ( array . length != indexes . length ) { throw new IllegalArgumentException ( "The length of the two arrays must match." ) ; } //sort the array based on the indexes for ( int i = 0 ; i < array . length ; i ++ ) { int index = indexes [ i ... | Rearranges the array based on the order of the provided indexes . | 115 | 15 |
36,892 | public static double [ ] array_clone ( double [ ] a ) { if ( a == null ) { return a ; } return Arrays . copyOf ( a , a . length ) ; } | Copies the elements of double array . | 41 | 8 |
36,893 | public static double [ ] [ ] array_clone ( double [ ] [ ] a ) { if ( a == null ) { return a ; } double [ ] [ ] copy = new double [ a . length ] [ ] ; for ( int i = 0 ; i < a . length ; i ++ ) { copy [ i ] = Arrays . copyOf ( a [ i ] , a [ i ] . length ) ; } return copy ; } | Copies the elements of double 2D array . | 93 | 10 |
36,894 | public static AssociativeArray sum ( DataTable2D classifierClassProbabilityMatrix ) { AssociativeArray combinedClassProbabilities = new AssociativeArray ( ) ; for ( Map . Entry < Object , AssociativeArray > entry : classifierClassProbabilityMatrix . entrySet ( ) ) { //Object classifier = entry.getKey(); AssociativeArra... | Combines the responses of the classifiers by using estimating the sum of the probabilities of their responses . | 208 | 20 |
36,895 | public static AssociativeArray median ( DataTable2D classifierClassProbabilityMatrix ) { AssociativeArray combinedClassProbabilities = new AssociativeArray ( ) ; //extract all the classes first for ( Map . Entry < Object , AssociativeArray > entry : classifierClassProbabilityMatrix . entrySet ( ) ) { //Object classifie... | Combines the responses of the classifiers by using estimating the median of the probabilities of their responses . | 367 | 20 |
36,896 | public static AssociativeArray majorityVote ( DataTable2D classifierClassProbabilityMatrix ) { AssociativeArray combinedClassProbabilities = new AssociativeArray ( ) ; //extract all the classes first for ( Map . Entry < Object , AssociativeArray > entry : classifierClassProbabilityMatrix . entrySet ( ) ) { //Object cla... | Combines the responses of the classifiers by summing the votes of each winner class . | 329 | 18 |
36,897 | public AssociativeArray2D getWordProbabilitiesPerTopic ( ) { AssociativeArray2D ptw = new AssociativeArray2D ( ) ; ModelParameters modelParameters = knowledgeBase . getModelParameters ( ) ; TrainingParameters trainingParameters = knowledgeBase . getTrainingParameters ( ) ; //initialize a probability list for every topi... | Returns the distribution of the words in each topic . | 371 | 10 |
36,898 | private < K > void increase ( Map < K , Integer > map , K key ) { map . put ( key , map . getOrDefault ( key , 0 ) + 1 ) ; } | Utility method that increases the map value by 1 . | 40 | 11 |
36,899 | private < K > void decrease ( Map < K , Integer > map , K key ) { map . put ( key , map . getOrDefault ( key , 0 ) - 1 ) ; } | Utility method that decreases the map value by 1 . | 40 | 11 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.