org.neuroph.core.data
Class DataSet
- java.lang.Object
-
- org.neuroph.core.data.DataSet
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Iterable<DataSetRow>, java.util.Collection<DataSetRow>, java.util.List<DataSetRow>
- Direct Known Subclasses:
- BufferedDataSet
public class DataSet extends java.lang.Object implements java.util.List<DataSetRow>, java.io.Serializable
This class represents a collection of data rows (DataSetRow instances) used for training and testing neural network. TODO: add logging
-
-
Constructor Summary
Constructors Constructor and Description DataSet(int inputSize)Creates an instance of new empty training setDataSet(int inputSize, int outputSize)Creates an instance of new empty training set
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description booleanadd(DataSetRow row)voidadd(int index, DataSetRow row)booleanaddAll(java.util.Collection<? extends DataSetRow> c)booleanaddAll(int index, java.util.Collection<? extends DataSetRow> c)booleanaddRow(DataSetRow row)Adds new row row to this data setvoidaddRow(double[] input)Adds a new dataset row with specified inputvoidaddRow(double[] input, double[] output)Adds a new dataset row with specified input and outputvoidclear()Removes all alements from training setbooleancontains(java.lang.Object o)booleancontainsAll(java.util.Collection<?> c)static DataSetcreateFromFile(java.lang.String filePath, int inputsCount, int outputsCount, java.lang.String delimiter)Creates and returns data set from specified csv filestatic DataSetcreateFromFile(java.lang.String filePath, int inputsCount, int outputsCount, java.lang.String delimiter, boolean loadColumnNames)Creates and returns data set from specified csv fileDataSet[]createTrainingAndTestSubsets(int trainSetPercent, int testSetPercent)Returns training and test subsets in the specified percent ratioDataSetRowget(int index)java.lang.StringgetColumnName(int idx)java.lang.String[]getColumnNames()DataSetColumnTypegetColumnType(int index)DataSetColumnType[]getColumnTypes()java.lang.StringgetFilePath()Returns full file path for this training setintgetInputSize()Returns input vector size of training elements in this training set This method is implementation of EngineIndexableSet interface, and it is added to provide compatibility with Encog data sets and FlatNetworkjava.lang.StringgetLabel()Returns label for this training setintgetOutputSize()Returns output vector size of training elements in this training set.DataSetRowgetRowAt(int idx)Returns training row at specified index positionjava.util.List<DataSetRow>getRows()Returns elements of this training setintindexOf(java.lang.Object row)booleanisEmpty()Returns true if training set is empty, false otherwisebooleanisSupervised()Returns true if data set is supervised, false otherwisejava.util.Iterator<DataSetRow>iterator()Returns Iterator for iterating training elements collectionintlastIndexOf(java.lang.Object row)java.util.ListIterator<DataSetRow>listIterator()java.util.ListIterator<DataSetRow>listIterator(int index)static DataSetload(java.lang.String filePath)Loads training set from the specified file TODO: throw checked exceptionse hereDataSetRowremove(int index)booleanremove(java.lang.Object row)booleanremoveAll(java.util.Collection<?> c)voidremoveRowAt(int idx)Removes training row at specified index positionbooleanretainAll(java.util.Collection<?> c)java.util.List<DataSet>sample(Sampling sampling)voidsave()Saves this training set to file specified in its filePath fieldvoidsave(java.lang.String filePath)Saves this training set to the specified filevoidsaveAsTxt(java.lang.String filePath, java.lang.String delimiter)DataSetRowset(int index, DataSetRow row)voidsetColumnName(int idx, java.lang.String columnName)voidsetColumnNames(java.lang.String[] columnNames)voidsetColumnType(int index, DataSetColumnType columnType)Sets column type for the given index.voidsetFilePath(java.lang.String filePath)Sets full file path for this training setvoidsetLabel(java.lang.String label)Sets label for this training setvoidshuffle()intsize()Returns number of training elements in this training set setjava.util.List<DataSet>split(int... sizePercents)java.util.List<DataSetRow>subList(int fromIndex, int toIndex)java.lang.Object[]toArray()<T> T[]toArray(T[] a)java.lang.StringtoCSV()Returns enire dataset in csv formatjava.lang.StringtoString()Returns string representation of this data set
-
-
-
Constructor Detail
-
DataSet
public DataSet(int inputSize)
Creates an instance of new empty training set- Parameters:
inputSize-
-
DataSet
public DataSet(int inputSize, int outputSize)Creates an instance of new empty training set- Parameters:
inputSize- Length of the input vectoroutputSize- Length of the output vector
-
-
Method Detail
-
addRow
public boolean addRow(DataSetRow row) throws VectorSizeMismatchException
Adds new row row to this data set- Parameters:
row- data set row to add- Throws:
VectorSizeMismatchException
-
addRow
public void addRow(double[] input)
Adds a new dataset row with specified input- Parameters:
input-
-
addRow
public void addRow(double[] input, double[] output)Adds a new dataset row with specified input and output- Parameters:
input-output-
-
removeRowAt
public void removeRowAt(int idx)
Removes training row at specified index position- Parameters:
idx- position of row to remove
-
iterator
public java.util.Iterator<DataSetRow> iterator()
Returns Iterator for iterating training elements collection- Specified by:
iteratorin interfacejava.lang.Iterable<DataSetRow>- Specified by:
iteratorin interfacejava.util.Collection<DataSetRow>- Specified by:
iteratorin interfacejava.util.List<DataSetRow>- Returns:
- Iterator for iterating training elements collection
-
getRows
public java.util.List<DataSetRow> getRows()
Returns elements of this training set- Returns:
- training elements
-
getRowAt
public DataSetRow getRowAt(int idx)
Returns training row at specified index position- Parameters:
idx- index position of training row to return- Returns:
- training row at specified index position
-
clear
public void clear()
Removes all alements from training set- Specified by:
clearin interfacejava.util.Collection<DataSetRow>- Specified by:
clearin interfacejava.util.List<DataSetRow>
-
isEmpty
public boolean isEmpty()
Returns true if training set is empty, false otherwise- Specified by:
isEmptyin interfacejava.util.Collection<DataSetRow>- Specified by:
isEmptyin interfacejava.util.List<DataSetRow>- Returns:
- true if training set is empty, false otherwise
-
isSupervised
public boolean isSupervised()
Returns true if data set is supervised, false otherwise- Returns:
-
size
public int size()
Returns number of training elements in this training set set- Specified by:
sizein interfacejava.util.Collection<DataSetRow>- Specified by:
sizein interfacejava.util.List<DataSetRow>- Returns:
- number of training elements in this training set set
-
getLabel
public java.lang.String getLabel()
Returns label for this training set- Returns:
- label for this training set
-
setLabel
public void setLabel(java.lang.String label)
Sets label for this training set- Parameters:
label- label for this training set
-
getColumnNames
public java.lang.String[] getColumnNames()
-
setColumnNames
public void setColumnNames(java.lang.String[] columnNames)
-
getColumnName
public java.lang.String getColumnName(int idx)
-
setColumnName
public void setColumnName(int idx, java.lang.String columnName)
-
getColumnTypes
public DataSetColumnType[] getColumnTypes()
-
getColumnType
public DataSetColumnType getColumnType(int index)
-
setColumnType
public void setColumnType(int index, DataSetColumnType columnType)Sets column type for the given index.- Parameters:
index- Index of the column in the row.columnType- Column type to set, nominal or numeric.
-
setFilePath
public void setFilePath(java.lang.String filePath)
Sets full file path for this training set- Parameters:
filePath-
-
getFilePath
public java.lang.String getFilePath()
Returns full file path for this training set- Returns:
- full file path for this training set
-
toString
public java.lang.String toString()
Returns string representation of this data set- Overrides:
toStringin classjava.lang.Object- Returns:
- string representation of this data set
-
toCSV
public java.lang.String toCSV()
Returns enire dataset in csv format- Returns:
-
save
public void save(java.lang.String filePath)
Saves this training set to the specified file- Parameters:
filePath-
-
save
public void save()
Saves this training set to file specified in its filePath field
-
saveAsTxt
public void saveAsTxt(java.lang.String filePath, java.lang.String delimiter)
-
load
public static DataSet load(java.lang.String filePath)
Loads training set from the specified file TODO: throw checked exceptionse here- Parameters:
filePath- training set file- Returns:
- loded training set
-
createFromFile
public static DataSet createFromFile(java.lang.String filePath, int inputsCount, int outputsCount, java.lang.String delimiter, boolean loadColumnNames)
Creates and returns data set from specified csv file- Parameters:
filePath- path to csv dataset file to importinputsCount- number of inputsoutputsCount- number of outputsdelimiter- delimiter of valuesloadColumnNames- true if csv file contains column names in first line, false otherwise- Returns:
- instance of dataset with values from specified file TODO: try with resources, provide information on exact line of error if format is not good in NumberFormatException
-
createFromFile
public static DataSet createFromFile(java.lang.String filePath, int inputsCount, int outputsCount, java.lang.String delimiter)
Creates and returns data set from specified csv file- Parameters:
filePath- path to csv dataset file to importinputsCount- number of inputsoutputsCount- number of outputsdelimiter- delimiter of values- Returns:
- instance of dataset with values from specified file
-
createTrainingAndTestSubsets
public DataSet[] createTrainingAndTestSubsets(int trainSetPercent, int testSetPercent)
Returns training and test subsets in the specified percent ratio- Parameters:
trainSetPercent-testSetPercent-- Returns:
-
split
public java.util.List<DataSet> split(int... sizePercents)
-
getOutputSize
public int getOutputSize()
Returns output vector size of training elements in this training set.
-
getInputSize
public int getInputSize()
Returns input vector size of training elements in this training set This method is implementation of EngineIndexableSet interface, and it is added to provide compatibility with Encog data sets and FlatNetwork
-
shuffle
public void shuffle()
-
contains
public boolean contains(java.lang.Object o)
- Specified by:
containsin interfacejava.util.Collection<DataSetRow>- Specified by:
containsin interfacejava.util.List<DataSetRow>
-
toArray
public java.lang.Object[] toArray()
- Specified by:
toArrayin interfacejava.util.Collection<DataSetRow>- Specified by:
toArrayin interfacejava.util.List<DataSetRow>
-
toArray
public <T> T[] toArray(T[] a)
- Specified by:
toArrayin interfacejava.util.Collection<DataSetRow>- Specified by:
toArrayin interfacejava.util.List<DataSetRow>
-
add
public boolean add(DataSetRow row)
- Specified by:
addin interfacejava.util.Collection<DataSetRow>- Specified by:
addin interfacejava.util.List<DataSetRow>
-
remove
public boolean remove(java.lang.Object row)
- Specified by:
removein interfacejava.util.Collection<DataSetRow>- Specified by:
removein interfacejava.util.List<DataSetRow>
-
containsAll
public boolean containsAll(java.util.Collection<?> c)
- Specified by:
containsAllin interfacejava.util.Collection<DataSetRow>- Specified by:
containsAllin interfacejava.util.List<DataSetRow>
-
addAll
public boolean addAll(java.util.Collection<? extends DataSetRow> c)
- Specified by:
addAllin interfacejava.util.Collection<DataSetRow>- Specified by:
addAllin interfacejava.util.List<DataSetRow>
-
addAll
public boolean addAll(int index, java.util.Collection<? extends DataSetRow> c)- Specified by:
addAllin interfacejava.util.List<DataSetRow>
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
- Specified by:
removeAllin interfacejava.util.Collection<DataSetRow>- Specified by:
removeAllin interfacejava.util.List<DataSetRow>
-
retainAll
public boolean retainAll(java.util.Collection<?> c)
- Specified by:
retainAllin interfacejava.util.Collection<DataSetRow>- Specified by:
retainAllin interfacejava.util.List<DataSetRow>
-
get
public DataSetRow get(int index)
- Specified by:
getin interfacejava.util.List<DataSetRow>
-
set
public DataSetRow set(int index, DataSetRow row)
- Specified by:
setin interfacejava.util.List<DataSetRow>
-
add
public void add(int index, DataSetRow row)- Specified by:
addin interfacejava.util.List<DataSetRow>
-
remove
public DataSetRow remove(int index)
- Specified by:
removein interfacejava.util.List<DataSetRow>
-
indexOf
public int indexOf(java.lang.Object row)
- Specified by:
indexOfin interfacejava.util.List<DataSetRow>
-
lastIndexOf
public int lastIndexOf(java.lang.Object row)
- Specified by:
lastIndexOfin interfacejava.util.List<DataSetRow>
-
listIterator
public java.util.ListIterator<DataSetRow> listIterator()
- Specified by:
listIteratorin interfacejava.util.List<DataSetRow>
-
listIterator
public java.util.ListIterator<DataSetRow> listIterator(int index)
- Specified by:
listIteratorin interfacejava.util.List<DataSetRow>
-
subList
public java.util.List<DataSetRow> subList(int fromIndex, int toIndex)
- Specified by:
subListin interfacejava.util.List<DataSetRow>
-
-
DMelt 3.0 © DataMelt by jWork.ORG