Crate iterative_methods[][src]

Expand description

iterative-methods

A demonstration of the use of StreamingIterators and their adapters to implement iterative algorithms.

Modules

algorithms
conjugate_gradient
utils

Structs

AnnotatedIterable

An adaptor that annotates every underlying item x with f(x).

AnnotatedResult

Store a generic annotation next to the state.

Enumerate

An adaptor that enumerates items.

ExtractValue

An adaptor that converts items from WeightedDatum<T> to T.

Numbered

A struct that wraps an Item as Option<Item> and annotates it with an i64. Used by Enumerate.

ReservoirSample

An optimal reservoir sampling algorithm is implemented. ReservoirSample wraps a StreamingIterator, I and produces a StreamingIterator whose items are samples of size capacity from the stream of I. (This is not the capacity of the Vec which holds the reservoir; Rather, the length of the reservoir is normally referred to as its capacity.) To produce a reservoir of length capacity on the first call, the first call of the advance method automatically advances the input iterator capacity steps. Subsequent calls of advance on ReservoirIterator advance I by skip + 1 steps and will at most replace a single element of the reservoir. The random rng is of type Pcg64 by default, which allows seeded rng. This should be extended to generic type bound by traits for implementing seeding. See Algorithm L in https://en.wikipedia.org/wiki/Reservoir_sampling#An_optimal_algorithm and https://dl.acm.org/doi/abs/10.1145/198429.198435

StepBy

An iterator for stepping iterators by a custom amount.

TakeUntil

An adaptor that returns initial elements until and including the first satisfying a predicate.

TimedIterable

Times every call to advance on the underlying StreamingIterator. Stores both the time at which it starts, and the duration it took to run.

TimedResult

TimedResult decorates with two duration fields: start_time is relative to the creation of the process generating results, and duration is relative to the start of the creation of the current result.

ToFileIterable

Write items of StreamingIterator to a file.

ToYamlIterable

Write items of StreamingIterator to a Yaml file.

WdIterable

WdIterable provides an easy conversion of any iterable to one whose items are WeightedDatum. WdIterable holds an iterator and a function. The function is defined by the user to extract weights from the iterable and package the old items and extracted weights into items as WeightedDatum

WeightedDatum

Weighted Sampling The WeightedDatum struct wraps the values of a data set to include a weight for each datum. Currently, the main motivation for this is to use it for Weighted Reservoir Sampling (WRS).

WeightedReservoirSample

The weighted reservoir sampling algorithm of M. T. Chao is implemented. WeightedReservoirSample wraps a StreamingIterator, I, whose items must be of type WeightedDatum and produces a StreamingIterator whose items are samples of size capacity from the stream of I. (This is not the capacity of the Vec which holds the reservoir; Rather, the length of the reservoir is normally referred to as its capacity.) To produce a reservoir of length capacity on the first call, the first call of the advance method automatically advances the input iterator capacity steps. Subsequent calls of advance on ReservoirIterator advance I one step and will at most replace a single element of the reservoir. The random rng is of type Pcg64 by default, which allows seeded rng. See https://en.wikipedia.org/wiki/Reservoir_sampling#Weighted_random_sampling, https://arxiv.org/abs/1910.11069, or for the original paper, https://doi.org/10.1093/biomet/69.3.653. Future work might include implementing parallellized batch processing: https://dl.acm.org/doi/10.1145/3350755.3400287

Enums

UntilState

Traits

YamlDataType

Define a trait object for converting to YAML objects.

Functions

assess

Annotate every underlying item with its score, as defined by f.

enumerate

A constructor for Enumerate.

extract_value

The constructor for ExtractValue. Apply it to a StreamingIterator with Item = WeightedDatum<T> and it returns a StreamingIterator with Item = T.

inspect

Apply f to every underlying item.

item_to_file

An adaptor that writes each item to a new line of a file.

last

Get the item before the first None, assuming any exist.

new_datum

Constructor for WeightedDatum.

reservoir_sample

An adaptor for which the items are random samples of the underlying iterator up to the item processed. The constructor for ReservoirSample.

step_by

Creates an iterator starting at the same point, but stepping by the given amount at each iteration.

take_until

Creates an iterator which returns initial elements until and including the first satisfying a predicate.

time

Wrap each value of a streaming iterator with the durations:

wd_iterable

Annotates items of an iterable with a weight using a function f.

weighted_reservoir_sample

Create a random sample of the underlying weighted stream.

write_yaml_documents

Adaptor that writes each item to a YAML document.

write_yaml_object

Function used by ToYamlIterable to specify how to write each item to file.