idx
int64
0
41.2k
question
stringlengths
74
4.04k
target
stringlengths
7
750
36,900
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 .
36,901
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 .
36,902
public ClassificationMetrics validate ( Map < Object , URI > datasets ) { TrainingParameters trainingParameters = ( TrainingParameters ) knowledgeBase . getTrainingParameters ( ) ; Dataframe testDataset = Dataframe . Builder . parseTextFiles ( datasets , AbstractTextExtractor . newInstance ( trainingParameters . getTex...
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 .
36,903
protected final String createKnowledgeBaseName ( String storageName , String separator ) { return storageName + separator + getClass ( ) . getSimpleName ( ) ; }
Generates a name for the KnowledgeBase .
36,904
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 .
36,905
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 ...
Returns all the possible combinations of the set in a stream .
36,906
public static < T > Iterator < T [ ] > combinationsIterator ( final T [ ] elements , final int subsetSize ) { return new Iterator < T [ ] > ( ) { private int r = 0 ; private int index = 0 ; private final int [ ] selectedIndexes = new int [ subsetSize ] ; private Boolean hasNext = null ; public boolean hasNext ( ) { if ...
Fast and memory efficient way to return an iterator with all the possible combinations of an array .
36,907
public static < T > Stream < T > stream ( Spliterator < T > spliterator , boolean parallel ) { return StreamSupport . < T > stream ( spliterator , parallel ) ; }
Converts an spliterator to a stream .
36,908
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 .
36,909
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 { Class < ? > klass = obj . getClass ( ) ; while ( klass != ...
Finds the public protected default or private method of the object with the provided name and parameters .
36,910
public Map < String , Double > extract ( final String text ) { Map < Integer , String > ID2word = new HashMap < > ( ) ; Map < Integer , Double > ID2occurrences = new HashMap < > ( ) ; Map < Integer , Integer > position2ID = new LinkedHashMap < > ( ) ; int numberOfWordsInDoc = buildInternalArrays ( text , ID2word , ID2o...
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 .
36,911
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 .
36,912
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
36,913
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
36,914
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
36,915
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
36,916
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
36,917
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
36,918
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 .
36,919
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
36,920
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
36,921
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 .
36,922
private void bigMapInitializer ( StorageEngine storageEngine ) { for ( Field field : ReflectionMethods . getAllFields ( new LinkedList < > ( ) , this . getClass ( ) ) ) { if ( field . isAnnotationPresent ( BigMap . class ) ) { initializeBigMapField ( storageEngine , field ) ; } } }
Initializes all the fields of the class which are marked with the BigMap annotation automatically .
36,923
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 .
36,924
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 .
36,925
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 .
36,926
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 .
36,927
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 .
36,928
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 .
36,929
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 ; }
Returns the StorageType using the name of the map . It assumes that names are unique across all StorageType . If not found null is returned .
36,930
private void closeStorageRegistry ( ) { for ( DB storage : storageRegistry . values ( ) ) { if ( isOpenStorage ( storage ) ) { storage . close ( ) ; } } storageRegistry . clear ( ) ; }
It closes all the storageengines in the registry .
36,931
private boolean blockedStorageClose ( StorageType storageType ) { DB storage = storageRegistry . get ( storageType ) ; if ( isOpenStorage ( storage ) ) { storage . commit ( ) ; Engine e = storage . getEngine ( ) ; while ( EngineWrapper . class . isAssignableFrom ( e . getClass ( ) ) ) { e = ( ( EngineWrapper ) e ) . ge...
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 .
36,932
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 .
36,933
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
36,934
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
36,935
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." ) ; } DataTable2D regretMatrix = new DataTable2D ( ) ; for ( Map . Entry < Object , AssociativeArr...
Returns the best option and the payoff under savage strategy
36,936
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." ) ; } AssociativeArray optionAverages = new AssociativeArray ( ) ; int numberOfEvents = payoffMat...
Returns the best option and the payoff under laplace strategy
36,937
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
36,938
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
36,939
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
36,940
private static DataTable2D bivariateMatrix ( Dataframe dataSet , BivariateType type ) { DataTable2D bivariateMatrix = new DataTable2D ( ) ; Map < Object , TypeInference . DataType > columnTypes = dataSet . getXDataTypes ( ) ; Object [ ] allVariables = columnTypes . keySet ( ) . toArray ( ) ; int numberOfVariables = all...
Calculates BivariateMatrix for a given statistic
36,941
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 .
36,942
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 .
36,943
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 .
36,944
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 .
36,945
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 .
36,946
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 .
36,947
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 .
36,948
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 .
36,949
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 .
36,950
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 .
36,951
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 .
36,952
public static < T > void shuffle ( T [ ] array , Random rnd ) { 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 .
36,953
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 .
36,954
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 .
36,955
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." ) ; } for ( int i = 0 ; i < array . length ; i ++ ) { int index = indexes [ i ] ; T tmp = array [ i ] ; array [ i ] ...
Rearranges the array based on the order of the provided indexes .
36,956
public static double [ ] array_clone ( double [ ] a ) { if ( a == null ) { return a ; } return Arrays . copyOf ( a , a . length ) ; }
Copies the elements of double array .
36,957
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 .
36,958
public static AssociativeArray sum ( DataTable2D classifierClassProbabilityMatrix ) { AssociativeArray combinedClassProbabilities = new AssociativeArray ( ) ; for ( Map . Entry < Object , AssociativeArray > entry : classifierClassProbabilityMatrix . entrySet ( ) ) { AssociativeArray listOfClassProbabilities = entry . g...
Combines the responses of the classifiers by using estimating the sum of the probabilities of their responses .
36,959
public static AssociativeArray median ( DataTable2D classifierClassProbabilityMatrix ) { AssociativeArray combinedClassProbabilities = new AssociativeArray ( ) ; for ( Map . Entry < Object , AssociativeArray > entry : classifierClassProbabilityMatrix . entrySet ( ) ) { AssociativeArray listOfClassProbabilities = entry ...
Combines the responses of the classifiers by using estimating the median of the probabilities of their responses .
36,960
public static AssociativeArray majorityVote ( DataTable2D classifierClassProbabilityMatrix ) { AssociativeArray combinedClassProbabilities = new AssociativeArray ( ) ; for ( Map . Entry < Object , AssociativeArray > entry : classifierClassProbabilityMatrix . entrySet ( ) ) { AssociativeArray listOfClassProbabilities = ...
Combines the responses of the classifiers by summing the votes of each winner class .
36,961
public AssociativeArray2D getWordProbabilitiesPerTopic ( ) { AssociativeArray2D ptw = new AssociativeArray2D ( ) ; ModelParameters modelParameters = knowledgeBase . getModelParameters ( ) ; TrainingParameters trainingParameters = knowledgeBase . getTrainingParameters ( ) ; int k = trainingParameters . getK ( ) ; for ( ...
Returns the distribution of the words in each topic .
36,962
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 .
36,963
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 .
36,964
protected < T extends Serializable > Map < String , Object > preSerializer ( T serializableObject ) { Map < String , Object > objReferences = new HashMap < > ( ) ; for ( Field field : ReflectionMethods . getAllFields ( new LinkedList < > ( ) , serializableObject . getClass ( ) ) ) { if ( field . isAnnotationPresent ( B...
This method is called before serializing the objects . It extracts all the not - serializable BigMap references of the provided object and stores them in a Map . Then it replaces all the references of the provided object with nulls to avoid their serialization . The main idea is that we temporarily remove from the obje...
36,965
protected < T extends Serializable > void postSerializer ( T serializableObject , Map < String , Object > objReferences ) { for ( Field field : ReflectionMethods . getAllFields ( new LinkedList < > ( ) , serializableObject . getClass ( ) ) ) { String fieldName = field . getName ( ) ; Object ref = objReferences . remove...
This method is called after the object serialization . It moves all the not - serializable BigMap references from the Map back to the provided object . The main idea is that once the serialization is completed we are allowed to restore back all the references which were removed by the preSerializer .
36,966
protected < T extends Serializable > void postDeserializer ( T serializableObject ) { Method method = null ; for ( Field field : ReflectionMethods . getAllFields ( new LinkedList < > ( ) , serializableObject . getClass ( ) ) ) { if ( field . isAnnotationPresent ( BigMap . class ) ) { field . setAccessible ( true ) ; tr...
This method is called after the object deserialization . It initializes all BigMaps of the serializable object which have a null value . The main idea is that once an object is deserialized it will contain nulls in all the BigMap fields which were not serialized . For all of those fields we call their initialization me...
36,967
public static boolean isActive ( Enum obj ) { Enum value = ACTIVE_SWITCHES . get ( ( Class ) obj . getClass ( ) ) ; return value != null && value == obj ; }
Validates whether the feature is active .
36,968
public boolean isValid ( ) { int totalNumberOfColumns = 0 ; Set < Object > columns = new HashSet < > ( ) ; for ( Map . Entry < Object , AssociativeArray > entry : internalData . entrySet ( ) ) { AssociativeArray row = entry . getValue ( ) ; if ( columns . isEmpty ( ) ) { for ( Object column : row . internalData . keySe...
Returns if the DataTable2D is valid . This data structure is considered valid it all the DataTable cells are set and as a result the DataTable has a rectangular format .
36,969
protected Object getSelectedClassFromClassScores ( AssociativeArray predictionScores ) { Map . Entry < Object , Object > maxEntry = MapMethods . selectMaxKeyValue ( predictionScores ) ; return maxEntry . getKey ( ) ; }
Estimates the selected class from the prediction scores .
36,970
public static FlatDataCollection randomSampling ( FlatDataList idList , int n , boolean randomizeRecords ) { FlatDataList sampledIds = new FlatDataList ( ) ; int populationN = idList . size ( ) ; Object [ ] keys = idList . toArray ( ) ; if ( randomizeRecords ) { PHPMethods . < Object > shuffle ( keys ) ; } int k = popu...
Samples n ids by using Systematic Sampling
36,971
private CL getFromClusterMap ( int clusterId , Map < Integer , CL > clusterMap ) { CL c = clusterMap . get ( clusterId ) ; if ( c . getFeatureIds ( ) == null ) { c . setFeatureIds ( knowledgeBase . getModelParameters ( ) . getFeatureIds ( ) ) ; } return c ; }
Always use this method to get the cluster from the clusterMap because it ensures that the featureIds are set . The featureIds can be unset if we use a data structure which stores stuff in file . Since the featureIds field of cluster is transient the information gets lost . This function ensures that it sets it back .
36,972
protected String getDirectory ( ) { String directory = storageConfiguration . getDirectory ( ) ; if ( directory == null || directory . isEmpty ( ) ) { directory = System . getProperty ( "java.io.tmpdir" ) ; } return directory ; }
Returns the location of the directory from the configuration or the temporary directory if not defined .
36,973
protected Path getRootPath ( String storageName ) { return Paths . get ( getDirectory ( ) + File . separator + storageName ) ; }
Returns the root path of the storage .
36,974
protected boolean deleteIfExistsRecursively ( Path path ) throws IOException { try { return Files . deleteIfExists ( path ) ; } catch ( DirectoryNotEmptyException ex ) { Files . walkFileTree ( path , new SimpleFileVisitor < Path > ( ) { public FileVisitResult visitFile ( Path file , BasicFileAttributes attrs ) throws I...
Deletes the file or directory recursively if it exists .
36,975
protected boolean deleteDirectory ( Path path , boolean cleanParent ) throws IOException { boolean pathExists = deleteIfExistsRecursively ( path ) ; if ( pathExists && cleanParent ) { cleanEmptyParentDirectory ( path . getParent ( ) ) ; return true ; } return false ; }
Deletes a directory and optionally removes the parent directory if it becomes empty .
36,976
private void cleanEmptyParentDirectory ( Path path ) throws IOException { Path normPath = path . normalize ( ) ; if ( normPath . equals ( Paths . get ( getDirectory ( ) ) . normalize ( ) ) || normPath . equals ( Paths . get ( System . getProperty ( "java.io.tmpdir" ) ) . normalize ( ) ) ) { return ; } try { Files . del...
Removes recursively all empty parent directories up to and excluding the storage directory .
36,977
protected boolean moveDirectory ( Path src , Path target ) throws IOException { if ( Files . exists ( src ) ) { createDirectoryIfNotExists ( target . getParent ( ) ) ; deleteDirectory ( target , false ) ; Files . move ( src , target ) ; cleanEmptyParentDirectory ( src . getParent ( ) ) ; return true ; } else { return f...
Moves a directory in the target location .
36,978
protected boolean createDirectoryIfNotExists ( Path path ) throws IOException { if ( ! Files . exists ( path ) ) { Files . createDirectories ( path ) ; return true ; } else { return false ; } }
Creates the directory in the target location if it does not exist .
36,979
public static double simpleMovingAverage ( FlatDataList flatDataList , int N ) { double SMA = 0 ; int counter = 0 ; for ( int i = flatDataList . size ( ) - 1 ; i >= 0 ; -- i ) { double Yti = flatDataList . getDouble ( i ) ; if ( counter >= N ) { break ; } SMA += Yti ; ++ counter ; } SMA /= counter ; return SMA ; }
Simple Moving Average
36,980
public static double weightedMovingAverage ( FlatDataList flatDataList , int N ) { double WMA = 0 ; double denominator = 0.0 ; int counter = 0 ; for ( int i = flatDataList . size ( ) - 1 ; i >= 0 ; -- i ) { double Yti = flatDataList . getDouble ( i ) ; if ( counter >= N ) { break ; } double weight = ( N - counter ) ; W...
Weighted Moving Average
36,981
public static double simpleExponentialSmoothing ( FlatDataList flatDataList , double a ) { double EMA = 0 ; int count = 0 ; for ( int i = flatDataList . size ( ) - 1 ; i >= 0 ; -- i ) { double Yti = flatDataList . getDouble ( i ) ; EMA += a * Math . pow ( 1 - a , count ) * Yti ; ++ count ; } return EMA ; }
Simple Explonential Smoothing
36,982
public static Double largest ( Iterator < Double > elements , int k ) { Iterator < Double > oppositeElements = new Iterator < Double > ( ) { public boolean hasNext ( ) { return elements . hasNext ( ) ; } public Double next ( ) { return - elements . next ( ) ; } } ; return - smallest ( oppositeElements , k ) ; }
Selects the kth largest element from an iterable object .
36,983
public static double nBar ( TransposeDataList clusterIdList ) { int populationM = clusterIdList . size ( ) ; double nBar = 0.0 ; for ( Map . Entry < Object , FlatDataList > entry : clusterIdList . entrySet ( ) ) { nBar += ( double ) entry . getValue ( ) . size ( ) / populationM ; } return nBar ; }
Returns the mean cluster size .
36,984
public static TransposeDataCollection randomSampling ( TransposeDataList clusterIdList , int sampleM ) { TransposeDataCollection sampledIds = new TransposeDataCollection ( ) ; Object [ ] selectedClusters = clusterIdList . keySet ( ) . toArray ( ) ; PHPMethods . < Object > shuffle ( selectedClusters ) ; for ( int i = 0 ...
Samples m clusters by using Cluster Sampling
36,985
public static String tokenizeSmileys ( String text ) { for ( Map . Entry < String , String > smiley : SMILEYS_MAPPING . entrySet ( ) ) { text = text . replaceAll ( smiley . getKey ( ) , smiley . getValue ( ) ) ; } return text ; }
Replaces all the SMILEYS_MAPPING within the text with their tokens .
36,986
public static String unifyTerminators ( String text ) { text = text . replaceAll ( "[\",:;()\\-]+" , " " ) ; text = text . replaceAll ( "[\\.!?]" , "." ) ; text = text . replaceAll ( "\\.[\\. ]+" , "." ) ; text = text . replaceAll ( "\\s*\\.\\s*" , ". " ) ; return text . trim ( ) ; }
Replaces all terminators with space or dots . The final string will contain only alphanumerics and dots .
36,987
public static String removeAccents ( String text ) { text = Normalizer . normalize ( text , Normalizer . Form . NFD ) ; text = text . replaceAll ( "[\\p{InCombiningDiacriticalMarks}]" , "" ) ; return text ; }
Removes all accepts from the text .
36,988
public static String clear ( String text ) { text = StringCleaner . tokenizeURLs ( text ) ; text = StringCleaner . tokenizeSmileys ( text ) ; text = StringCleaner . removeAccents ( text ) ; text = StringCleaner . removeSymbols ( text ) ; text = StringCleaner . removeExtraSpaces ( text ) ; return text . toLowerCase ( Lo...
Convenience method which tokenizes the URLs and the SMILEYS_MAPPING removes accents and symbols and eliminates the extra spaces from the provided text .
36,989
public static double getScoreValue ( DataTable2D dataTable ) { AssociativeArray result = getScore ( dataTable ) ; double score = result . getDouble ( "score" ) ; return score ; }
Convenience method to get the score of Chisquare .
36,990
public static LPResult solve ( double [ ] linearObjectiveFunction , List < LPSolver . LPConstraint > linearConstraintsList , boolean nonNegative , boolean maximize ) { int m = linearConstraintsList . size ( ) ; List < LinearConstraint > constraints = new ArrayList < > ( m ) ; for ( LPSolver . LPConstraint constraint : ...
Solves the LP problem and returns the result .
36,991
public final Object get2d ( Object key1 , Object key2 ) { AssociativeArray tmp = internalData . get ( key1 ) ; if ( tmp == null ) { return null ; } return tmp . internalData . get ( key2 ) ; }
Convenience function to get the value by using both keys .
36,992
public final Object put2d ( Object key1 , Object key2 , Object value ) { AssociativeArray tmp = internalData . get ( key1 ) ; if ( tmp == null ) { internalData . put ( key1 , new AssociativeArray ( ) ) ; } return internalData . get ( key1 ) . internalData . put ( key2 , value ) ; }
Convenience function used to put a value in a particular key positions .
36,993
public static String joinURL ( Map < URLParts , String > urlParts ) { try { URI uri = new URI ( urlParts . get ( URLParts . PROTOCOL ) , urlParts . get ( URLParts . AUTHORITY ) , urlParts . get ( URLParts . PATH ) , urlParts . get ( URLParts . QUERY ) , urlParts . get ( URLParts . REF ) ) ; return uri . toString ( ) ; ...
This method can be used to build a URL from its parts .
36,994
public static Map < DomainParts , String > splitDomain ( String domain ) { Map < DomainParts , String > domainParts = null ; String [ ] dottedParts = domain . trim ( ) . toLowerCase ( Locale . ENGLISH ) . split ( "\\." ) ; if ( dottedParts . length == 2 ) { domainParts = new HashMap < > ( ) ; domainParts . put ( Domain...
Splits a domain name to parts and returns them in a map .
36,995
public static double fleschKincaidReadingEase ( String strText ) { strText = cleanText ( strText ) ; return PHPMethods . round ( ( 206.835 - ( 1.015 * averageWordsPerSentence ( strText ) ) - ( 84.6 * averageSyllablesPerWord ( strText ) ) ) , 1 ) ; }
Returns the Flesch - Kincaid Reading Ease of text entered rounded to one digit .
36,996
public static double fleschKincaidGradeLevel ( String strText ) { strText = cleanText ( strText ) ; return PHPMethods . round ( ( ( 0.39 * averageWordsPerSentence ( strText ) ) + ( 11.8 * averageSyllablesPerWord ( strText ) ) - 15.59 ) , 1 ) ; }
Returns the Flesch - Kincaid Grade level of text entered rounded to one digit .
36,997
public static double gunningFogScore ( String strText ) { strText = cleanText ( strText ) ; return PHPMethods . round ( ( ( averageWordsPerSentence ( strText ) + percentageWordsWithThreeSyllables ( strText ) ) * 0.4 ) , 1 ) ; }
Returns the Gunning - Fog score of text entered rounded to one digit .
36,998
public static double colemanLiauIndex ( String strText ) { strText = cleanText ( strText ) ; int intWordCount = wordCount ( strText ) ; return PHPMethods . round ( ( ( 5.89 * ( letterCount ( strText ) / ( double ) intWordCount ) ) - ( 0.3 * ( sentenceCount ( strText ) / ( double ) intWordCount ) ) - 15.8 ) , 1 ) ; }
Returns the Coleman - Liau Index of text entered rounded to one digit .
36,999
public static double smogIndex ( String strText ) { strText = cleanText ( strText ) ; return PHPMethods . round ( 1.043 * Math . sqrt ( ( wordsWithThreeSyllables ( strText ) * ( 30.0 / sentenceCount ( strText ) ) ) + 3.1291 ) , 1 ) ; }
Returns the SMOG Index of text entered rounded to one digit .