idx int64 0 41.2k | question stringlengths 73 5.81k | target stringlengths 5 918 |
|---|---|---|
19,300 | public static < T > List < T > getUnique ( Collection < T > collection ) { HashSet < T > set = new HashSet < > ( ) ; List < T > out = new ArrayList < > ( ) ; for ( T t : collection ) { if ( ! set . contains ( t ) ) { out . add ( t ) ; set . add ( t ) ; } } return out ; } | Returns a list containing only unique values in a collection |
19,301 | public long numParams ( ) { int ret = 0 ; for ( INDArray val : params . values ( ) ) ret += val . length ( ) ; return ret ; } | The number of parameters for the model |
19,302 | public void add ( Chromosome element ) { if ( population . size ( ) == populationSize ) { cullOperator . cullPopulation ( ) ; } population . add ( element ) ; Collections . sort ( population , chromosomeComparator ) ; triggerPopulationChangedListeners ( population ) ; } | Add a Chromosome to the population and call the PopulationListeners . Culling may be triggered . |
19,303 | public INDArray readDataSet ( String datasetName , String ... groups ) throws UnsupportedKerasConfigurationException { synchronized ( Hdf5Archive . LOCK_OBJECT ) { if ( groups . length == 0 ) return readDataSet ( this . file , datasetName ) ; Group [ ] groupArray = openGroups ( groups ) ; INDArray a = readDataSet ( gro... | Read data set as ND4J array from group path . |
19,304 | public String readAttributeAsJson ( String attributeName , String ... groups ) throws UnsupportedKerasConfigurationException { synchronized ( Hdf5Archive . LOCK_OBJECT ) { if ( groups . length == 0 ) { Attribute a = this . file . openAttribute ( attributeName ) ; String s = readAttributeAsJson ( a ) ; a . deallocate ( ... | Read JSON - formatted string attribute from group path . |
19,305 | public boolean hasAttribute ( String attributeName , String ... groups ) { synchronized ( Hdf5Archive . LOCK_OBJECT ) { if ( groups . length == 0 ) return this . file . attrExists ( attributeName ) ; Group [ ] groupArray = openGroups ( groups ) ; boolean b = groupArray [ groupArray . length - 1 ] . attrExists ( attribu... | Check whether group path contains string attribute . |
19,306 | public List < String > getDataSets ( String ... groups ) { synchronized ( Hdf5Archive . LOCK_OBJECT ) { if ( groups . length == 0 ) return getObjects ( this . file , H5O_TYPE_DATASET ) ; Group [ ] groupArray = openGroups ( groups ) ; List < String > ls = getObjects ( groupArray [ groupArray . length - 1 ] , H5O_TYPE_DA... | Get list of data sets from group path . |
19,307 | public List < String > getGroups ( String ... groups ) { synchronized ( Hdf5Archive . LOCK_OBJECT ) { if ( groups . length == 0 ) return getObjects ( this . file , H5O_TYPE_GROUP ) ; Group [ ] groupArray = openGroups ( groups ) ; List < String > ls = getObjects ( groupArray [ groupArray . length - 1 ] , H5O_TYPE_GROUP ... | Get list of groups from group path . |
19,308 | private List < String > getObjects ( Group fileGroup , int objType ) { synchronized ( Hdf5Archive . LOCK_OBJECT ) { List < String > groups = new ArrayList < > ( ) ; for ( int i = 0 ; i < fileGroup . getNumObjs ( ) ; i ++ ) { BytePointer objPtr = fileGroup . getObjnameByIdx ( i ) ; if ( fileGroup . childObjType ( objPtr... | Get list of objects with a given type from a file group . |
19,309 | private String readAttributeAsJson ( Attribute attribute ) throws UnsupportedKerasConfigurationException { synchronized ( Hdf5Archive . LOCK_OBJECT ) { VarLenType vl = attribute . getVarLenType ( ) ; int bufferSizeMult = 1 ; String s ; while ( true ) { byte [ ] attrBuffer = new byte [ bufferSizeMult * 2000 ] ; BytePoin... | Read JSON - formatted string attribute . |
19,310 | private String readAttributeAsString ( Attribute attribute ) throws UnsupportedKerasConfigurationException { synchronized ( Hdf5Archive . LOCK_OBJECT ) { VarLenType vl = attribute . getVarLenType ( ) ; int bufferSizeMult = 1 ; String s = null ; while ( true ) { byte [ ] attrBuffer = new byte [ bufferSizeMult * 2000 ] ;... | Read attribute as string . |
19,311 | public String readAttributeAsFixedLengthString ( String attributeName , int bufferSize ) throws UnsupportedKerasConfigurationException { synchronized ( Hdf5Archive . LOCK_OBJECT ) { Attribute a = this . file . openAttribute ( attributeName ) ; String s = readAttributeAsFixedLengthString ( a , bufferSize ) ; a . dealloc... | Read string attribute from group path . |
19,312 | private String readAttributeAsFixedLengthString ( Attribute attribute , int bufferSize ) throws UnsupportedKerasConfigurationException { synchronized ( Hdf5Archive . LOCK_OBJECT ) { VarLenType vl = attribute . getVarLenType ( ) ; byte [ ] attrBuffer = new byte [ bufferSize ] ; BytePointer attrPointer = new BytePointer ... | Read attribute of fixed buffer size as string . |
19,313 | public INDArray reducedBasis ( double variance ) { INDArray vars = Transforms . pow ( eigenvalues , - 0.5 , true ) ; double res = vars . sumNumber ( ) . doubleValue ( ) ; double total = 0.0 ; int ndims = 0 ; for ( int i = 0 ; i < vars . columns ( ) ; i ++ ) { ndims ++ ; total += vars . getDouble ( i ) ; if ( total / re... | Return a reduced basis set that covers a certain fraction of the variance of the data |
19,314 | public INDArray convertToComponents ( INDArray data ) { INDArray dx = data . subRowVector ( mean ) ; return Nd4j . tensorMmul ( eigenvectors . transpose ( ) , dx , new int [ ] [ ] { { 1 } , { 1 } } ) . transposei ( ) ; } | Takes a set of data on each row with the same number of features as the constructing data and returns the data in the coordinates of the basis set about the mean . |
19,315 | public INDArray convertBackToFeatures ( INDArray data ) { return Nd4j . tensorMmul ( eigenvectors , data , new int [ ] [ ] { { 1 } , { 1 } } ) . transposei ( ) . addiRowVector ( mean ) ; } | Take the data that has been transformed to the principal components about the mean and transform it back into the original feature set . Make sure to fill in zeroes in columns where components were dropped! |
19,316 | public static INDArray pca ( INDArray A , int nDims , boolean normalize ) { INDArray factor = pca_factor ( A , nDims , normalize ) ; return A . mmul ( factor ) ; } | Calculates pca vectors of a matrix for a flags number of reduced features returns the reduced feature set The return is a projection of A onto principal nDims components |
19,317 | public static INDArray pca_factor ( INDArray A , int nDims , boolean normalize ) { if ( normalize ) { INDArray mean = A . mean ( 0 ) ; A . subiRowVector ( mean ) ; } long m = A . rows ( ) ; long n = A . columns ( ) ; INDArray s = Nd4j . create ( A . dataType ( ) , m < n ? m : n ) ; INDArray VT = Nd4j . create ( A . dat... | Calculates pca factors of a matrix for a flags number of reduced features returns the factors to scale observations |
19,318 | public static INDArray pca2 ( INDArray in , double variance ) { INDArray [ ] covmean = covarianceMatrix ( in ) ; INDArray [ ] pce = principalComponents ( covmean [ 0 ] ) ; INDArray vars = Transforms . pow ( pce [ 1 ] , - 0.5 , true ) ; double res = vars . sumNumber ( ) . doubleValue ( ) ; double total = 0.0 ; int ndims... | This method performs a dimensionality reduction including principal components that cover a fraction of the total variance of the system . It does all calculations about the mean . |
19,319 | public String timestamp ( ) { float totalSeconds = this . length ( ) ; float second = totalSeconds % 60 ; int minute = ( int ) totalSeconds / 60 % 60 ; int hour = ( int ) ( totalSeconds / 3600 ) ; StringBuilder sb = new StringBuilder ( ) ; if ( hour > 0 ) { sb . append ( hour + ":" ) ; } if ( minute > 0 ) { sb . append... | Timestamp of the wave length |
19,320 | public byte [ ] getFingerprintFromFile ( String fingerprintFile ) { byte [ ] fingerprint = null ; try { InputStream fis = new FileInputStream ( fingerprintFile ) ; fingerprint = getFingerprintFromInputStream ( fis ) ; fis . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return fingerprint ; } | Get bytes from fingerprint file |
19,321 | public byte [ ] getFingerprintFromInputStream ( InputStream inputStream ) { byte [ ] fingerprint = null ; try { fingerprint = new byte [ inputStream . available ( ) ] ; inputStream . read ( fingerprint ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return fingerprint ; } | Get bytes from fingerprint inputstream |
19,322 | public void saveFingerprintAsFile ( byte [ ] fingerprint , String filename ) { FileOutputStream fileOutputStream ; try { fileOutputStream = new FileOutputStream ( filename ) ; fileOutputStream . write ( fingerprint ) ; fileOutputStream . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } | Save fingerprint to a file |
19,323 | protected ArrayList < String > getLabels ( String textResource ) throws IOException { ArrayList < String > labels = new ArrayList < > ( ) ; File resourceFile = getResourceFile ( ) ; try ( InputStream is = new BufferedInputStream ( new FileInputStream ( resourceFile ) ) ; Scanner s = new Scanner ( is ) ) { while ( s . h... | Returns labels based on the text file resource . |
19,324 | public void setPoints ( int [ ] points ) { this . points = new ArrayList < > ( ) ; for ( int i = 0 ; i < points . length ; i ++ ) { this . points . add ( points [ i ] ) ; } } | Sets Huffman tree points |
19,325 | public void printAvailableCompressors ( ) { StringBuilder builder = new StringBuilder ( ) ; builder . append ( "Available compressors: " ) ; for ( String comp : codecs . keySet ( ) ) { builder . append ( "[" ) . append ( comp ) . append ( "] " ) ; } System . out . println ( builder . toString ( ) ) ; } | Prints available compressors to standard out |
19,326 | public DataBuffer compress ( DataBuffer buffer , String algorithm ) { algorithm = algorithm . toUpperCase ( ) ; if ( ! codecs . containsKey ( algorithm ) ) throw new RuntimeException ( "Non-existent compression algorithm requested: [" + algorithm + "]" ) ; return codecs . get ( algorithm ) . compress ( buffer ) ; } | Compress the data buffer given a specified algorithm |
19,327 | public INDArray compress ( INDArray array , String algorithm ) { algorithm = algorithm . toUpperCase ( ) ; if ( ! codecs . containsKey ( algorithm ) ) throw new RuntimeException ( "Non-existent compression algorithm requested: [" + algorithm + "]" ) ; return codecs . get ( algorithm ) . compress ( array ) ; } | Returns a compressed version of the given ndarray |
19,328 | public DataBuffer decompress ( DataBuffer buffer , DataType targetType ) { if ( buffer . dataType ( ) != DataType . COMPRESSED ) throw new IllegalStateException ( "You can't decompress DataBuffer with dataType of: " + buffer . dataType ( ) ) ; CompressedDataBuffer comp = ( CompressedDataBuffer ) buffer ; CompressionDes... | Decompress the given databuffer |
19,329 | public void decompressi ( INDArray array ) { if ( array . data ( ) . dataType ( ) != DataType . COMPRESSED ) return ; val comp = ( CompressedDataBuffer ) array . data ( ) ; val descriptor = comp . getCompressionDescriptor ( ) ; if ( ! codecs . containsKey ( descriptor . getCompressionAlgorithm ( ) ) ) throw new Runtime... | in place decompression of the given ndarray . If the ndarray isn t compressed this will do nothing |
19,330 | public void overrideMinorityDefault ( int index ) { if ( targetMinorityDistMap . containsKey ( index ) ) { minorityLabelMap . put ( index , 0 ) ; } else { throw new IllegalArgumentException ( "Index specified is not contained in the target minority distribution map specified with the preprocessor. Map contains " + Arra... | Will change the default minority label from 1 to 0 and correspondingly the majority class from 0 to 1 for the label at the index specified |
19,331 | public static void convert ( RecordReader reader , RecordWriter writer ) throws IOException { convert ( reader , writer , true ) ; } | Write all values from the specified record reader to the specified record writer . Closes the record writer on completion |
19,332 | public static void convert ( RecordReader reader , RecordWriter writer , boolean closeOnCompletion ) throws IOException { if ( ! reader . hasNext ( ) ) { throw new UnsupportedOperationException ( "Cannot convert RecordReader: reader has no next element" ) ; } while ( reader . hasNext ( ) ) { writer . write ( reader . n... | Write all values from the specified record reader to the specified record writer . Optionally close the record writer on completion |
19,333 | public static LayerConstraint mapConstraint ( String kerasConstraint , KerasLayerConfiguration conf , Map < String , Object > constraintConfig ) throws UnsupportedKerasConfigurationException { LayerConstraint constraint ; if ( kerasConstraint . equals ( conf . getLAYER_FIELD_MINMAX_NORM_CONSTRAINT ( ) ) || kerasConstra... | Map Keras to DL4J constraint . |
19,334 | public static LayerConstraint getConstraintsFromConfig ( Map < String , Object > layerConfig , String constraintField , KerasLayerConfiguration conf , int kerasMajorVersion ) throws InvalidKerasConfigurationException , UnsupportedKerasConfigurationException { Map < String , Object > innerConfig = KerasLayerUtils . getI... | Get constraint initialization from Keras layer configuration . |
19,335 | protected static < T extends IEvaluation > T attempFromLegacyFromJson ( String json , IllegalArgumentException originalException ) { if ( json . contains ( "org.deeplearning4j.eval.Evaluation" ) ) { String newJson = json . replaceAll ( "org.deeplearning4j.eval.Evaluation" , "org.nd4j.evaluation.classification.Evaluatio... | Attempt to load DL4J IEvaluation JSON from 1 . 0 . 0 - beta2 or earlier . Given IEvaluation classes were moved to ND4J with no major changes a simple find and replace for the class names is used . |
19,336 | public void shuffle ( INDArray array , Random rnd , int ... dimension ) { shuffle ( Collections . singletonList ( array ) , rnd , dimension ) ; } | In place shuffle of an ndarray along a specified set of dimensions |
19,337 | public static void crashDumpOutputDirectory ( File rootDir ) { if ( rootDir == null ) { String userDir = System . getProperty ( "user.dir" ) ; if ( userDir == null ) { userDir = "" ; } crashDumpRootDirectory = new File ( userDir ) ; return ; } crashDumpRootDirectory = rootDir ; } | Method that can be use to customize the output directory for memory crash reporting . By default the current working directory will be used . |
19,338 | public static double getWeightRegularizerFromConfig ( Map < String , Object > layerConfig , KerasLayerConfiguration conf , String configField , String regularizerType ) throws UnsupportedKerasConfigurationException , InvalidKerasConfigurationException { Map < String , Object > innerConfig = KerasLayerUtils . getInnerLa... | Get weight regularization from Keras weight regularization configuration . |
19,339 | public Map < String , long [ ] > getParamShapes ( ) { Map < String , long [ ] > map = new LinkedHashMap < > ( ) ; map . putAll ( weightParams ) ; map . putAll ( biasParams ) ; return map ; } | Get the parameter shapes for all parameters |
19,340 | public Configuration getConfiguration ( ) { try { globalLock . readLock ( ) . lock ( ) ; return configuration ; } finally { globalLock . readLock ( ) . unlock ( ) ; } } | Returns current Allocator configuration |
19,341 | public Pointer getPointer ( DataBuffer buffer , AllocationShape shape , boolean isView , CudaContext context ) { return memoryHandler . getDevicePointer ( buffer , context ) ; } | This method returns actual device pointer valid for specified shape of current object |
19,342 | public Pointer getPointer ( INDArray array , CudaContext context ) { if ( array . isEmpty ( ) ) return null ; return memoryHandler . getDevicePointer ( array . data ( ) , context ) ; } | This method returns actual device pointer valid for specified INDArray |
19,343 | public Pointer getHostPointer ( INDArray array ) { if ( array . isEmpty ( ) ) return null ; synchronizeHostData ( array ) ; return memoryHandler . getHostPointer ( array . data ( ) ) ; } | This method returns actual host pointer valid for current object |
19,344 | public void freeMemory ( AllocationPoint point ) { if ( point . getAllocationStatus ( ) == AllocationStatus . DEVICE ) { this . getMemoryHandler ( ) . getMemoryProvider ( ) . free ( point ) ; point . setAllocationStatus ( AllocationStatus . HOST ) ; this . getMemoryHandler ( ) . getMemoryProvider ( ) . free ( point ) ;... | This method releases memory allocated for this allocation point |
19,345 | public AllocationPoint allocateMemory ( DataBuffer buffer , AllocationShape requiredMemory , boolean initialize ) { AllocationPoint point = null ; if ( configuration . getMemoryModel ( ) == Configuration . MemoryModel . IMMEDIATE ) { point = allocateMemory ( buffer , requiredMemory , memoryHandler . getInitialLocation ... | This method allocates required chunk of memory |
19,346 | protected synchronized long seekUnusedZero ( Long bucketId , Aggressiveness aggressiveness ) { AtomicLong freeSpace = new AtomicLong ( 0 ) ; int totalElements = ( int ) memoryHandler . getAllocatedHostObjects ( bucketId ) ; float shortAverage = zeroShort . getAverage ( ) ; float longAverage = zeroLong . getAverage ( ) ... | This method seeks for unused zero - copy memory allocations |
19,347 | protected long seekUnusedDevice ( Long threadId , Integer deviceId , Aggressiveness aggressiveness ) { AtomicLong freeSpace = new AtomicLong ( 0 ) ; float shortAverage = deviceShort . getAverage ( ) ; float longAverage = deviceLong . getAverage ( ) ; float shortThreshold = shortAverage / ( Aggressiveness . values ( ) .... | This method seeks for unused device memory allocations for specified thread and device |
19,348 | public void memcpyAsync ( DataBuffer dstBuffer , Pointer srcPointer , long length , long dstOffset ) { this . memoryHandler . memcpyAsync ( dstBuffer , srcPointer , length , dstOffset ) ; } | This method implements asynchronous memcpy if that s available on current hardware |
19,349 | public void memcpy ( DataBuffer dstBuffer , DataBuffer srcBuffer ) { this . memoryHandler . memcpy ( dstBuffer , srcBuffer ) ; } | This method implements blocking memcpy |
19,350 | public List < String > asLabels ( ) { List < String > labels = new ArrayList < > ( ) ; for ( T element : getElements ( ) ) { labels . add ( element . getLabel ( ) ) ; } return labels ; } | Returns this sequence as list of labels |
19,351 | public Pair < List < String > , AtomicLong > call ( List < String > lstOfWords ) throws Exception { List < String > stops = stopWords . getValue ( ) ; Counter < String > counter = new Counter < > ( ) ; for ( String w : lstOfWords ) { if ( w . isEmpty ( ) ) continue ; if ( ! stops . isEmpty ( ) ) { if ( stops . contains... | Function to add to word freq counter and total count of words |
19,352 | public void addHook ( TrainingHook trainingHook ) { if ( trainingHookList == null ) { trainingHookList = new ArrayList < > ( ) ; } trainingHookList . add ( trainingHook ) ; } | Add a hook for the master for pre and post training |
19,353 | public DataType nd4jTypeFromOnnxType ( OnnxProto3 . TensorProto . DataType dataType ) { switch ( dataType ) { case DOUBLE : return DataType . DOUBLE ; case FLOAT : return DataType . FLOAT ; case FLOAT16 : return DataType . HALF ; case INT32 : case INT64 : return DataType . INT ; default : return DataType . UNKNOWN ; } ... | Convert an onnx type to the proper nd4j type |
19,354 | public static double toClassifierPrediction ( Vector vector ) { double max = Double . NEGATIVE_INFINITY ; int maxIndex = 0 ; for ( int i = 0 ; i < vector . size ( ) ; i ++ ) { double curr = vector . apply ( i ) ; if ( curr > max ) { maxIndex = i ; max = curr ; } } return maxIndex ; } | This is for the edge case where you have a single output layer and need to convert the output layer to an index |
19,355 | public static LabeledPoint pointOf ( Collection < Writable > writables ) { double [ ] ret = new double [ writables . size ( ) - 1 ] ; int count = 0 ; double target = 0 ; for ( Writable w : writables ) { if ( count < writables . size ( ) - 1 ) ret [ count ++ ] = Float . parseFloat ( w . toString ( ) ) ; else target = Fl... | Returns a labeled point of the writables where the final item is the point and the rest of the items are features |
19,356 | public static JavaRDD < DataSet > fromLabeledPoint ( JavaRDD < LabeledPoint > data , final long numPossibleLabels , long batchSize ) { JavaRDD < DataSet > mappedData = data . map ( new Function < LabeledPoint , DataSet > ( ) { public DataSet call ( LabeledPoint lp ) { return fromLabeledPoint ( lp , numPossibleLabels ) ... | Convert an rdd of labeled point based on the specified batch size in to data set |
19,357 | public static JavaRDD < DataSet > fromLabeledPoint ( JavaSparkContext sc , JavaRDD < LabeledPoint > data , final long numPossibleLabels ) { return data . map ( new Function < LabeledPoint , DataSet > ( ) { public DataSet call ( LabeledPoint lp ) { return fromLabeledPoint ( lp , numPossibleLabels ) ; } } ) ; } | From labeled point |
19,358 | public static JavaRDD < DataSet > fromContinuousLabeledPoint ( JavaSparkContext sc , JavaRDD < LabeledPoint > data ) { return data . map ( new Function < LabeledPoint , DataSet > ( ) { public DataSet call ( LabeledPoint lp ) { return convertToDataset ( lp ) ; } } ) ; } | Convert rdd labeled points to a rdd dataset with continuous features |
19,359 | private static List < LabeledPoint > toLabeledPoint ( List < DataSet > labeledPoints ) { List < LabeledPoint > ret = new ArrayList < > ( ) ; for ( DataSet point : labeledPoints ) { ret . add ( toLabeledPoint ( point ) ) ; } return ret ; } | Convert a list of dataset in to a list of labeled points |
19,360 | public static JavaRDD < DataSet > fromContinuousLabeledPoint ( JavaRDD < LabeledPoint > data , boolean preCache ) { if ( preCache && ! data . getStorageLevel ( ) . useMemory ( ) ) { data . cache ( ) ; } return data . map ( new Function < LabeledPoint , DataSet > ( ) { public DataSet call ( LabeledPoint lp ) { return co... | Converts a continuous JavaRDD LabeledPoint to a JavaRDD DataSet . |
19,361 | public static JavaRDD < DataSet > fromLabeledPoint ( JavaRDD < LabeledPoint > data , final long numPossibleLabels ) { return fromLabeledPoint ( data , numPossibleLabels , false ) ; } | Converts JavaRDD labeled points to JavaRDD datasets . |
19,362 | public static JavaRDD < DataSet > fromLabeledPoint ( JavaRDD < LabeledPoint > data , final long numPossibleLabels , boolean preCache ) { if ( preCache && ! data . getStorageLevel ( ) . useMemory ( ) ) { data . cache ( ) ; } return data . map ( new Function < LabeledPoint , DataSet > ( ) { public DataSet call ( LabeledP... | Converts JavaRDD labeled points to JavaRDD DataSets . |
19,363 | public static JavaRDD < LabeledPoint > fromDataSet ( JavaRDD < DataSet > data , boolean preCache ) { if ( preCache && ! data . getStorageLevel ( ) . useMemory ( ) ) { data . cache ( ) ; } return data . map ( new Function < DataSet , LabeledPoint > ( ) { public LabeledPoint call ( DataSet dataSet ) { return toLabeledPoi... | Convert an rdd of data set in to labeled point . |
19,364 | public static Constructor < ? > getEmptyConstructor ( Class < ? > clazz ) { Constructor < ? > c = clazz . getDeclaredConstructors ( ) [ 0 ] ; for ( int i = 0 ; i < clazz . getDeclaredConstructors ( ) . length ; i ++ ) { if ( clazz . getDeclaredConstructors ( ) [ i ] . getParameterTypes ( ) . length < 1 ) { c = clazz . ... | Gets the empty constructor from a class |
19,365 | public static void setProperties ( Object obj , Properties props ) throws Exception { for ( Field field : obj . getClass ( ) . getDeclaredFields ( ) ) { field . setAccessible ( true ) ; if ( props . containsKey ( field . getName ( ) ) ) { set ( field , obj , props . getProperty ( field . getName ( ) ) ) ; } } } | Sets the properties of the given object |
19,366 | public static Properties getFieldsAsProperties ( Object obj , Class < ? > [ ] clazzes ) throws Exception { Properties props = new Properties ( ) ; for ( Field field : obj . getClass ( ) . getDeclaredFields ( ) ) { if ( Modifier . isStatic ( field . getModifiers ( ) ) ) continue ; field . setAccessible ( true ) ; Class ... | Get fields as properties |
19,367 | public boolean pingDeviceForFreeMemory ( Integer deviceId , long requiredMemory ) { long freeMem = nativeOps . getDeviceFreeMemory ( - 1 ) ; if ( freeMem - requiredMemory < DEVICE_RESERVED_SPACE ) return false ; else return true ; } | This method checks specified device for specified amount of memory |
19,368 | public void plotVocab ( BarnesHutTsne tsne , int numWords , UiConnectionInfo connectionInfo ) { try { final List < String > labels = fitTnseAndGetLabels ( tsne , numWords ) ; final INDArray reducedData = tsne . getData ( ) ; StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < reducedData . rows ( ) && i < ... | Render the words via TSNE |
19,369 | public void putVector ( String word , INDArray vector ) { if ( word == null ) throw new IllegalArgumentException ( "No null words allowed" ) ; if ( vector == null ) throw new IllegalArgumentException ( "No null vectors allowed" ) ; int idx = vocab . indexOf ( word ) ; syn0 . slice ( idx ) . assign ( vector ) ; } | Inserts a word vector |
19,370 | public void consume ( InMemoryLookupTable < T > srcTable ) { if ( srcTable . vectorLength != this . vectorLength ) throw new IllegalStateException ( "You can't consume lookupTable with different vector lengths" ) ; if ( srcTable . syn0 == null ) throw new IllegalStateException ( "Source lookupTable Syn0 is NULL" ) ; th... | This method consumes weights of a given InMemoryLookupTable |
19,371 | public void initializeInstance ( PopulationModel populationModel ) { super . initializeInstance ( populationModel ) ; parentSelection . initializeInstance ( populationModel . getPopulation ( ) ) ; } | Will be called by the selection operator once the population model is instantiated . |
19,372 | public short [ ] interpolate ( int oldSampleRate , int newSampleRate , short [ ] samples ) { if ( oldSampleRate == newSampleRate ) { return samples ; } int newLength = Math . round ( ( ( float ) samples . length / oldSampleRate * newSampleRate ) ) ; float lengthMultiplier = ( float ) newLength / samples . length ; shor... | Do interpolation on the samples according to the original and destinated sample rates |
19,373 | public static < T > Set < T > intersection ( Collection < T > parentCollection , Collection < T > removeFromCollection ) { Set < T > results = new HashSet < > ( parentCollection ) ; results . retainAll ( removeFromCollection ) ; return results ; } | Set specific operations |
19,374 | public static < T > Set < T > difference ( Collection < ? extends T > s1 , Collection < ? extends T > s2 ) { Set < T > s3 = new HashSet < > ( s1 ) ; s3 . removeAll ( s2 ) ; return s3 ; } | Return is s1 \ s2 |
19,375 | @ SuppressWarnings ( "unchecked" ) public static < T > T readObject ( InputStream is ) { try { ObjectInputStream ois = new ObjectInputStream ( is ) ; T ret = ( T ) ois . readObject ( ) ; ois . close ( ) ; return ret ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } } | Reads an object from the given input stream |
19,376 | public static byte [ ] toByteArray ( Serializable toSave ) { try { ByteArrayOutputStream bos = new ByteArrayOutputStream ( ) ; ObjectOutputStream os = new ObjectOutputStream ( bos ) ; os . writeObject ( toSave ) ; byte [ ] ret = bos . toByteArray ( ) ; os . close ( ) ; return ret ; } catch ( Exception e ) { throw new R... | Converts the given object to a byte array |
19,377 | public static void writeObject ( Serializable toSave , OutputStream writeTo ) { try { ObjectOutputStream os = new ObjectOutputStream ( writeTo ) ; os . writeObject ( toSave ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } } | Writes the object to the output stream THIS DOES NOT FLUSH THE STREAM |
19,378 | public void initialize ( InputSplit split ) throws IOException , InterruptedException { super . initialize ( split ) ; this . iter = getIterator ( 0 ) ; this . initialized = true ; } | Using String as StandardCharsets . UTF_8 is not serializable |
19,379 | public static < K , V > CounterMap < K , V > parallelCounterMap ( ) { CounterMap < K , V > totalWords = new CounterMap < > ( ) ; return totalWords ; } | Returns a thread safe counter map |
19,380 | public void apply ( GloveWeightLookupTable table ) { table . getBias ( ) . putScalar ( w1 . getIndex ( ) , table . getBias ( ) . getDouble ( w1 . getIndex ( ) ) - w1BiasUpdate ) ; table . getBias ( ) . putScalar ( w2 . getIndex ( ) , table . getBias ( ) . getDouble ( w2 . getIndex ( ) ) - w2BiasUpdate ) ; table . getSy... | Apply the changes to the table |
19,381 | public void set ( T value ) { try { lock . writeLock ( ) . lock ( ) ; this . value = value ; } finally { lock . writeLock ( ) . unlock ( ) ; } } | This method assigns new value |
19,382 | public boolean cas ( T expected , T newValue ) { try { lock . writeLock ( ) . lock ( ) ; if ( Objects . equals ( value , expected ) ) { this . value = newValue ; return true ; } else return false ; } finally { lock . writeLock ( ) . unlock ( ) ; } } | This method implements compare - and - swap |
19,383 | protected ImageWritable doTransform ( ImageWritable image , Random random ) { if ( image == null ) { return null ; } Mat mat = converter . convert ( image . getFrame ( ) ) ; Mat box = new Mat ( height , width , mat . type ( ) ) ; box . put ( borderValue ) ; x = ( mat . cols ( ) - width ) / 2 ; y = ( mat . rows ( ) - he... | Takes an image and returns a boxed version of the image . |
19,384 | public static INDArray pooling2D ( INDArray img , int kh , int kw , int sy , int sx , int ph , int pw , int dh , int dw , boolean isSameMode , Pooling2D . Pooling2DType type , Pooling2D . Divisor divisor , double extra , int virtualHeight , int virtualWidth , INDArray out ) { Pooling2D pooling = Pooling2D . builder ( )... | Pooling 2d implementation |
19,385 | public static int outSize ( int size , int k , int s , int p , int dilation , boolean coverAll ) { k = effectiveKernelSize ( k , dilation ) ; if ( coverAll ) return ( size + p * 2 - k + s - 1 ) / s + 1 ; else return ( size + p * 2 - k ) / s + 1 ; } | The out size for a convolution |
19,386 | public static INDArray conv2d ( INDArray input , INDArray kernel , Type type ) { return Nd4j . getConvolution ( ) . conv2d ( input , kernel , type ) ; } | 2d convolution ( aka the last 2 dimensions |
19,387 | public static long [ ] dataBufferToArray ( DataBuffer buffer ) { int rank = buffer . getInt ( 0 ) ; val ret = new long [ Shape . shapeInfoLength ( rank ) ] ; ret [ 0 ] = rank ; for ( int e = 1 ; e < Shape . shapeInfoLength ( rank ) ; e ++ ) { ret [ e ] = buffer . getInt ( e ) ; } return ret ; } | Obtain the values from the shape buffer for the array |
19,388 | public static OptimizationConfiguration fromYaml ( String json ) { try { return JsonMapper . getYamlMapper ( ) . readValue ( json , OptimizationConfiguration . class ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } | Create an optimization configuration from the json |
19,389 | public double calculateAverageAuc ( ) { double ret = 0.0 ; for ( int i = 0 ; i < numLabels ( ) ; i ++ ) { ret += calculateAUC ( i ) ; } return ret / ( double ) numLabels ( ) ; } | Macro - average AUC for all outcomes |
19,390 | public static Consumer < Subscription > subscriberLoop ( final FragmentHandler fragmentHandler , final int limit , final AtomicBoolean running , final AtomicBoolean launched ) { final IdleStrategy idleStrategy = new BusySpinIdleStrategy ( ) ; return subscriberLoop ( fragmentHandler , limit , running , idleStrategy , la... | Return a reusable parametrized event loop that calls a default idler when no messages are received |
19,391 | public static Consumer < Subscription > subscriberLoop ( final FragmentHandler fragmentHandler , final int limit , final AtomicBoolean running , final IdleStrategy idleStrategy , final AtomicBoolean launched ) { return ( subscription ) -> { try { while ( running . get ( ) ) { idleStrategy . idle ( subscription . poll (... | Return a reusable parameterized event loop that calls and idler when no messages are received |
19,392 | public static void printAvailableImage ( final Image image ) { final Subscription subscription = image . subscription ( ) ; System . out . println ( String . format ( "Available image on %s streamId=%d sessionId=%d from %s" , subscription . channel ( ) , subscription . streamId ( ) , image . sessionId ( ) , image . sou... | Print the information for an available image to stdout . |
19,393 | protected static int [ ] adaptForTensorDescr ( int [ ] shapeOrStrides ) { if ( shapeOrStrides . length >= 4 ) return shapeOrStrides ; int [ ] out = new int [ 4 ] ; int i = 0 ; for ( ; i < shapeOrStrides . length ; i ++ ) { out [ i ] = shapeOrStrides [ i ] ; } for ( ; i < 4 ; i ++ ) { out [ i ] = 1 ; } return out ; } | From CuDNN documentation - Tensors are restricted to having at least 4 dimensions ... When working with lower dimensional data it is recommended that the user create a 4Dtensor and set the size along unused dimensions to 1 . |
19,394 | protected void checkBufferCoherence ( ) { if ( values . length ( ) < length ) { throw new IllegalStateException ( "nnz is larger than capacity of buffers" ) ; } if ( values . length ( ) * rank ( ) != indices . length ( ) ) { throw new IllegalArgumentException ( "Sizes of values, indices and shape are incoherent." ) ; }... | Check that the length of indices and values are coherent and matches the rank of the matrix . |
19,395 | protected static DataBuffer createSparseInformationBuffer ( int rank ) { int [ ] flags = new int [ rank ] ; long [ ] sparseOffsets = new long [ rank ] ; int [ ] hiddenDimension = new int [ ] { - 1 } ; return Nd4j . getSparseInfoProvider ( ) . createSparseInformation ( flags , sparseOffsets , hiddenDimension , rank ) ; ... | Create a SparseInfo databuffer given rank if of the sparse matrix . |
19,396 | protected static DataBuffer createValueBuffer ( float [ ] values ) { checkNotNull ( values ) ; if ( values . length == 0 ) { return Nd4j . createBuffer ( 1 ) ; } return Nd4j . createBuffer ( values ) ; } | Create a DataBuffer for values of given array of values . |
19,397 | protected static DataBuffer createIndiceBuffer ( long [ ] [ ] indices , long [ ] shape ) { checkNotNull ( indices ) ; checkNotNull ( shape ) ; if ( indices . length == 0 ) { return Nd4j . getDataBufferFactory ( ) . createLong ( shape . length ) ; } if ( indices . length == shape . length ) { return Nd4j . createBuffer ... | Create a DataBuffer for indices of given arrays of indices . |
19,398 | public long [ ] translateToPhysical ( long [ ] virtualIndexes ) { long [ ] physicalIndexes = new long [ underlyingRank ( ) ] ; int idxPhy = 0 ; int hidden = 0 ; for ( int idxVir = 0 ; idxVir < virtualIndexes . length ; idxVir ++ ) { if ( hidden < getNumHiddenDimension ( ) && hiddenDimensions ( ) [ hidden ] == idxVir ) ... | Translate the view index to the corresponding index of the original ndarray |
19,399 | public void addOrUpdate ( long [ ] indexes , double value ) { long [ ] physicalIndexes = isView ( ) ? translateToPhysical ( indexes ) : indexes ; for ( int i = 0 ; i < length ; i ++ ) { long [ ] idx = getUnderlyingIndicesOf ( i ) . asLong ( ) ; if ( Arrays . equals ( idx , physicalIndexes ) ) { if ( value == 0 ) { remo... | Add a new element in the ndarray or update the value if there is already a non - null element at this position |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.