data
fn DataLoader.new #
fn DataLoader.new[T](data &la.Matrix[T], labels []T, batch_size int, shuffle bool) &DataLoader[T]
DataLoader.new creates a new DataLoader data is [nb_samples][nb_features] matrix labels is [nb_samples] vector
fn DataLoader.new_with_sampler #
fn DataLoader.new_with_sampler[T](data &la.Matrix[T], labels []T, batch_size int, sampler Sampler) !&DataLoader[T]
new_with_sampler creates a DataLoader that obtains its sample order from a custom sampler. The sampler is called once per epoch, including after reset.
fn FixedBatchSampler.new #
fn FixedBatchSampler.new(sampler Sampler, batch_size int, drop_last bool) !&FixedBatchSampler
FixedBatchSampler.new creates a fixed-size batch sampler.
fn Subset.new #
fn Subset.new[T](dataset &Dataset[T], indices []int) &Subset[T]
Subset.new creates a new Subset from a Dataset
fn SubsetRandomSampler.new #
fn SubsetRandomSampler.new(indices []int) &SubsetRandomSampler
SubsetRandomSampler.new snapshots the requested subset indices.
fn TensorDataset.new #
fn TensorDataset.new[T](x &la.Matrix[T], y []T) &TensorDataset[T]
TensorDataset.new creates a new TensorDataset
fn WeightedRandomSampler.new #
fn WeightedRandomSampler.new(weights []f64, num_samples int, replacement bool) !&WeightedRandomSampler
WeightedRandomSampler.new snapshots weights and validates the draw count.
interface BatchSampler #
interface BatchSampler {
sample_batches(dataset_size int) ![][]int
}
BatchSampler produces explicit batches of sample indices.
interface Dataset #
interface Dataset[T] {
// len returns the number of samples in the dataset
len() int
// get returns the input and label at index i
get(i int) !(&la.Matrix[T], []T)
}
Dataset is an interface for accessing data in batches
interface Sampler #
interface Sampler {
sample_indices(dataset_size int) ![]int
}
Sampler produces sample indices for a dataset of the provided size.
fn (DataLoader[T]) len #
fn (dl &DataLoader[T]) len() int
len returns the number of batches per epoch
fn (DataLoader[T]) next #
fn (mut dl DataLoader[T]) next() !(&la.Matrix[T], []T)
next returns the next batch of data and labels returns an error when no more batches are available
fn (DataLoader[T]) reset #
fn (mut dl DataLoader[T]) reset()
reset resets the DataLoader to start a new epoch
fn (Subset[T]) len #
fn (s &Subset[T]) len() int
len returns the number of samples in the subset
fn (Subset[T]) get #
fn (s &Subset[T]) get(i int) !(&la.Matrix[T], []T)
get returns the input and label at subset index i
fn (Subset[T]) split #
fn (s &Subset[T]) split(train_ratio f64) !(&Subset[T], &Subset[T])
split splits a Subset into train and validation subsets train_ratio is the proportion of data to use for training
fn (TensorDataset[T]) len #
fn (ds &TensorDataset[T]) len() int
len returns the number of samples
fn (TensorDataset[T]) get #
fn (ds &TensorDataset[T]) get(i int) !(&la.Matrix[T], []T)
get returns the input matrix and labels at index i
struct DataLoader #
struct DataLoader[T] {
pub:
data &la.Matrix[T] // full data matrix [nb_samples][nb_features]
labels []T // labels [nb_samples]
batch_size int
shuffle bool
sampler Sampler
pub mut:
indices []int // sample order for the current epoch
position int // current position in epoch
resample_on_next bool
}
DataLoader defines a public data structure for this module.
struct FixedBatchSampler #
struct FixedBatchSampler {
sampler Sampler
batch_size int
drop_last bool
}
FixedBatchSampler groups another sampler's indices into fixed-size batches.
fn (FixedBatchSampler) sample_batches #
fn (s &FixedBatchSampler) sample_batches(dataset_size int) ![][]int
sample_batches asks the underlying sampler for indices and groups them.
struct RandomSampler #
struct RandomSampler {}
RandomSampler returns every dataset index once in a random order.
fn (RandomSampler) sample_indices #
fn (s &RandomSampler) sample_indices(dataset_size int) ![]int
sample_indices shuffles a full index range using Fisher-Yates.
struct SequentialSampler #
struct SequentialSampler {}
SequentialSampler returns every dataset index in order.
fn (SequentialSampler) sample_indices #
fn (s &SequentialSampler) sample_indices(dataset_size int) ![]int
sample_indices returns [0, 1, ..., dataset_size-1].
struct Subset #
struct Subset[T] {
pub:
dataset &Dataset[T]
indices []int
}
Subset defines a public data structure for this module.
struct SubsetRandomSampler #
struct SubsetRandomSampler {
pub:
indices []int
}
SubsetRandomSampler returns the configured subset in a random order.
fn (SubsetRandomSampler) sample_indices #
fn (s &SubsetRandomSampler) sample_indices(dataset_size int) ![]int
sample_indices shuffles the subset after checking dataset bounds.
struct TensorDataset #
struct TensorDataset[T] {
pub mut:
x &la.Matrix[T]
y []T
}
TensorDataset defines a public data structure for this module.
struct WeightedRandomSampler #
struct WeightedRandomSampler {
weights []f64
num_samples int
replacement bool
}
WeightedRandomSampler draws indices in proportion to non-negative weights.
fn (WeightedRandomSampler) sample_indices #
fn (s &WeightedRandomSampler) sample_indices(dataset_size int) ![]int
sample_indices draws the configured number of weighted dataset indices.
- fn DataLoader.new
- fn DataLoader.new_with_sampler
- fn FixedBatchSampler.new
- fn Subset.new
- fn SubsetRandomSampler.new
- fn TensorDataset.new
- fn WeightedRandomSampler.new
- interface BatchSampler
- interface Dataset
- interface Sampler
- type DataLoader[T]
- type Subset[T]
- type TensorDataset[T]
- struct DataLoader
- struct FixedBatchSampler
- struct RandomSampler
- struct SequentialSampler
- struct Subset
- struct SubsetRandomSampler
- struct TensorDataset
- struct WeightedRandomSampler