SparseReader Class |
Namespace: Accord.IO
The SparseReader type exposes the following members.
Name | Description | |
---|---|---|
SparseReader(Stream) |
Initializes a new instance of the SparseReader class.
| |
SparseReader(StreamReader) |
Initializes a new instance of the SparseReader class.
| |
SparseReader(String) |
Initializes a new instance of the SparseReader class.
| |
SparseReader(Stream, Int32) |
Initializes a new instance of the SparseReader class.
| |
SparseReader(Stream, Encoding) |
Initializes a new instance of the SparseReader class.
| |
SparseReader(StreamReader, Int32) |
Initializes a new instance of the SparseReader class.
| |
SparseReader(String, Int32) |
Initializes a new instance of the SparseReader class.
| |
SparseReader(String, Encoding) |
Initializes a new instance of the SparseReader class.
| |
SparseReader(Stream, Encoding, Int32) |
Initializes a new instance of the SparseReader class.
| |
SparseReader(String, Encoding, Int32) |
Initializes a new instance of the SparseReader class.
|
Name | Description | |
---|---|---|
BaseStream |
Returns the underlying stream.
| |
Dimensions | Obsolete.
Obsolete. Please use NumberOfInputs instead.
| |
EndOfStream |
Gets a value that indicates whether the current
stream position is at the end of the stream.
| |
Intercept |
Gets or sets whether to include an intercept term
(bias) value at the beginning of each new sample.
Default is null (don't include anything).
| |
NumberOfInputs |
Gets the number of features present in this dataset. Please
note that, when using the sparse representation, it is not
strictly necessary to know this value.
| |
SampleDescriptions |
Gets the description associated with the last read values.
|
Name | Description | |
---|---|---|
Dispose |
Performs application-defined tasks associated with
freeing, releasing, or resetting unmanaged resources.
| |
Dispose(Boolean) |
Releases unmanaged and - optionally - managed resources
| |
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) | |
Finalize |
Releases unmanaged resources and performs other cleanup operations before the
SparseReader is reclaimed by garbage collection.
(Overrides ObjectFinalize.) | |
GetHashCode | Serves as the default hash function. (Inherited from Object.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
Read(SparseDouble, Boolean) |
Reads a sample from the file and returns it as a
SparseT sparse vector, together with
its associated output value.
| |
Read(SparseDouble, Double) |
Reads a sample from the file and returns it as a
SparseT sparse vector, together with
its associated output value.
| |
Read(SparseDouble, Int32) |
Reads a sample from the file and returns it as a
SparseT sparse vector, together with
its associated output value.
| |
Read(Int32, SparseDouble, Boolean) |
Reads count samples from the file and returns
them as a SparseT sparse vector, together with
their associated output values.
| |
Read(Int32, SparseDouble, Double) |
Reads count samples from the file and returns
them as a SparseT sparse vector, together with
their associated output values.
| |
Read(Int32, SparseDouble, Int32) |
Reads count samples from the file and returns
them as a SparseT sparse vector, together with
their associated output values.
| |
ReadDense |
Reads a sample from the file and returns it as a
dense vector, together with its associated output value.
| |
ReadDense(Int32) |
Reads count samples from the file and returns
them as a SparseT sparse vector, together with
their associated output values.
| |
ReadDenseToEnd |
Reads all samples from the file and returns them as a
dense vector, together with their associated output values.
| |
ReadLine |
Reads one line from the feature file, returning the array of values
for the sparse vector and its corresponding label.
| |
ReadSparse |
Reads a sample from the file and returns it as a
SparseT sparse vector, together with
its associated output value.
| |
ReadSparse(Int32) |
Reads count samples from the file and returns
them as a SparseT sparse vector, together with
their associated output values.
| |
ReadSparseToEnd |
Reads all samples from the file and returns them as a
SparseT sparse vector, together with
their associated output values.
| |
ReadToEnd(SparseDouble, Boolean) |
Reads all samples from the file and returns them as a
SparseT sparse vector, together with
their associated output values.
| |
ReadToEnd(SparseDouble, Double) |
Reads all samples from the file and returns them as a
SparseT sparse vector, together with
their associated output values.
| |
ReadToEnd(SparseDouble, Int32) |
Reads all samples from the file and returns them as a
SparseT sparse vector, together with
their associated output values.
| |
ToString | Returns a string that represents the current object. (Inherited from Object.) |
Name | Description | |
---|---|---|
HasMethod |
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.) | |
IsEqual |
Compares two objects for equality, performing an elementwise
comparison if the elements are vectors or matrices.
(Defined by Matrix.) | |
To(Type) | Overloaded.
Converts an object into another type, irrespective of whether
the conversion can be done at compile time or not. This can be
used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.) | |
ToT | Overloaded.
Converts an object into another type, irrespective of whether
the conversion can be done at compile time or not. This can be
used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.) |
The following example shows how to read all sparse samples from a file and retrieve them as a dense multidimensional vector.
// Suppose we are going to read a sparse sample file containing // samples which have an actual dimension of 4. Since the samples // are in a sparse format, each entry in the file will probably // have a much lesser number of elements. // int sampleSize = 4; // Create a new Sparse Sample Reader to read any given file, // passing the correct dense sample size in the constructor // SparseReader reader = new SparseReader(file, Encoding.Default, sampleSize); // Declare a vector to obtain the label // of each of the samples in the file // int[] labels = null; // Declare a vector to obtain the description (or comments) // about each of the samples in the file, if present. // string[] descriptions = null; // Read the sparse samples and store them in a dense vector array double[][] samples = reader.ReadToEnd(out labels, out descriptions);
Additionally, it is also possible to read each sample individually and sequentially. For this, we can use a while loop until we reach the end of the stream.
// Suppose we are going to read a sparse sample file containing // samples which have an actual dimension of 4. Since the samples // are in a sparse format, each entry in the file will probably // have a much lesser number of elements. // int sampleSize = 4; // Create a new Sparse Sample Reader to read any given file, // passing the correct dense sample size in the constructor // SparseReader reader = new SparseReader(file, Encoding.Default, sampleSize); // Declare some variables to receive each sample // int label = 0; string description; double[] sample; // Read a single sample from the file sample = reader.ReadDense(out label, out description); // Read all other samples from the file while (!reader.EndOfStream) { sample = reader.ReadDense(out label, out description); }