org.encog.ml.data.buffer
Class BufferedMLDataSet
- java.lang.Object
-
- org.encog.ml.data.buffer.BufferedMLDataSet
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Iterable<MLDataPair>, MLDataSet
public class BufferedMLDataSet extends java.lang.Object implements MLDataSet, java.io.Serializable
This class is not memory based, so very long files can be used, without running out of memory. This dataset uses a Encog binary training file as a buffer. When used with a slower access dataset, such as CSV, XML or SQL, where parsing must occur, this dataset can be used to load from the slower dataset and train at much higher speeds. This class makes use of Java file channels for maximum file access performance. If you are going to create a binary file, by using the add methods, you must call beginLoad to cause Encog to open an output file. Once the data has been loaded, call endLoad. You can also use the BinaryDataLoader class, with a CODEC, to load many other popular external formats. The binary files produced by this class are in the Encog binary training format, and can be used with any Encog platform. Encog binary files are stored using "little endian" numbers.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field and Description static java.lang.StringERROR_ADDError message for ADD.static java.lang.StringERROR_REMOVEError message for REMOVE.
-
Constructor Summary
Constructors Constructor and Description BufferedMLDataSet(java.io.File binaryFile)Construct the dataset using the specified binary file.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidadd(MLData data1)Add only input data, for an unsupervised dataset.voidadd(MLData inputData, MLData idealData)Add both the input and ideal data.voidadd(MLDataPair pair)Add a data pair of both input and ideal data.voidbeginLoad(int inputSize, int idealSize)Begin loading to the binary file.voidclose()Close the dataset.voidendLoad()This method should be called once all the data has been loaded.MLDataPairget(int index)EncogEGBFilegetEGB()java.io.FilegetFile()intgetIdealSize()intgetInputSize()BufferedMLDataSetgetOwner()voidgetRecord(long index, MLDataPair pair)Read an individual record.longgetRecordCount()Determine the total number of records in the set.booleanisSupervised()java.util.Iterator<MLDataPair>iterator()voidload(MLDataSet training)Load the specified training set.MLDataSetloadToMemory()Load the binary dataset to memory.voidopen()Open the binary file for reading.BufferedMLDataSetopenAdditional()Opens an additional instance of this dataset.voidremoveAdditional(BufferedMLDataSet child)Remove an additional dataset that was created.voidsetOwner(BufferedMLDataSet theOwner)Set the owner of this dataset.intsize()
-
-
-
Field Detail
-
ERROR_ADD
public static final java.lang.String ERROR_ADD
Error message for ADD.- See Also:
- Constant Field Values
-
ERROR_REMOVE
public static final java.lang.String ERROR_REMOVE
Error message for REMOVE.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
BufferedMLDataSet
public BufferedMLDataSet(java.io.File binaryFile)
Construct the dataset using the specified binary file.- Parameters:
binaryFile- The file to use.
-
-
Method Detail
-
open
public void open()
Open the binary file for reading.
-
iterator
public java.util.Iterator<MLDataPair> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<MLDataPair>- Returns:
- An iterator.
-
getRecordCount
public long getRecordCount()
Description copied from interface:MLDataSetDetermine the total number of records in the set.- Specified by:
getRecordCountin interfaceMLDataSet- Returns:
- The record count.
-
getRecord
public void getRecord(long index, MLDataPair pair)Read an individual record.
-
openAdditional
public BufferedMLDataSet openAdditional()
Description copied from interface:MLDataSetOpens an additional instance of this dataset.- Specified by:
openAdditionalin interfaceMLDataSet- Returns:
- An additional training set.
-
add
public void add(MLData data1)
Add only input data, for an unsupervised dataset.
-
add
public void add(MLDataPair pair)
Add a data pair of both input and ideal data.
-
getIdealSize
public int getIdealSize()
- Specified by:
getIdealSizein interfaceMLDataSet- Returns:
- The ideal data size.
-
getInputSize
public int getInputSize()
- Specified by:
getInputSizein interfaceMLDataSet- Returns:
- The input data size.
-
isSupervised
public boolean isSupervised()
- Specified by:
isSupervisedin interfaceMLDataSet- Returns:
- True if this dataset is supervised.
-
getOwner
public BufferedMLDataSet getOwner()
- Returns:
- If this dataset was created by openAdditional, the set that created this object is the owner. Return the owner.
-
setOwner
public void setOwner(BufferedMLDataSet theOwner)
Set the owner of this dataset.- Parameters:
theOwner- The owner.
-
removeAdditional
public void removeAdditional(BufferedMLDataSet child)
Remove an additional dataset that was created.- Parameters:
child- The additional dataset to remove.
-
beginLoad
public void beginLoad(int inputSize, int idealSize)Begin loading to the binary file. After calling this method the add methods may be called.- Parameters:
inputSize- The input size.idealSize- The ideal size.
-
endLoad
public void endLoad()
This method should be called once all the data has been loaded. The underlying file will be closed. The binary fill will then be opened for reading.
-
getFile
public java.io.File getFile()
- Returns:
- The binary file used.
-
getEGB
public EncogEGBFile getEGB()
- Returns:
- The EGB file to use.
-
loadToMemory
public MLDataSet loadToMemory()
Load the binary dataset to memory. Memory access is faster.- Returns:
- A memory dataset.
-
load
public void load(MLDataSet training)
Load the specified training set.- Parameters:
training- The training set to load.
-
get
public MLDataPair get(int index)
-
-
DMelt 3.0 © DataMelt by jWork.ORG