Skip to content

Commit f97ce9b

Browse files
Cleanups (#47)
Various random cleanups before wider circulation. * renamed reservoir_iterable to reservoir_sample * Improve animation example UI * Miscellanous minor improvements * gitignore tweaks * Exclude some files from being packaged
1 parent 799dcb4 commit f97ce9b

15 files changed

+91
-110
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@
33
.DS_Store
44
Cargo.lock
55
/p3
6+
/visualizations
7+
/visualizations_python/__pycache__
8+
/visualizations_python/parameters_for_histogram.yaml

ARCHITECTURE.md

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Architecture
22

3-
This document describes the highest level architecture of the library iterative_methods_done_right_in_rust. As a tree structure, the code base looks like this:
3+
The high level architecture of the iterative_methods crate. As a tree structure, the code base looks like this:
44

55
```
66
iterative_methods_done_right_in_rust
@@ -21,24 +21,30 @@ If you haven't already, please see the README.md document for an introduction to
2121

2222
The remaining sections will address the contents and structure of each directory of the tree.
2323

24-
## src
25-
26-
In `src` the lib.rs file contains all of the code needed to use the tools in this library. Unit tests are included. Most of the code base consists of iterator adaptors. They currently include
27-
- ReservoirIterable
28-
- StepBy
29-
- Tee
30-
- TimedIterable
31-
and their associated functions and structs.
3224

25+
## src
3326

27+
In `src`, `lib.rs` exports iterative methods (via algorithms.rs) and
28+
utilities consisting of iterator adaptors. They currently include
29+
- take_until
30+
- assess
31+
- inspect
32+
- last
33+
- time
34+
- step_by
35+
- write_yaml_documents
36+
- enumerate
37+
- {weighted_}reservoir_sample
38+
and their associated implementations. Unit tests are included.
3439

3540
## examples
3641

37-
Examples demonstrating the basic functionality are provided. Currently, the examples include
38-
- Fibonnacci
39-
- Conjugate Gradient Method (CGIterable)
42+
Examples demonstrating different functionality. Currently:
43+
44+
- Conjugate Gradient Method (ConjugateGradient)
4045
- Weighted Reservoir Sampling
46+
- Output to yaml, e.g., for animations
4147

4248
## tests
4349

44-
Integration tests are provided.
50+
Some integration tests.

COPYING.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ edition = "2018"
66
description = "Iterative methods and associated utilities as StreamingIterators."
77
license = "MIT OR Apache-2.0"
88
keywords = ["math","stream","machine-learning","algorithm","optimization"]
9+
repository = "https://github.com/daniel-vainsencher/iterative_methods_rs"
10+
readme = "README.md"
11+
exclude = ["/local", "/visualizations", "/p3", "/visualizations_python/__pycache__", "visualizations_python/parameters_for_histogram.yaml"]
12+
913
[lib]
1014
name = "iterative_methods"
1115
path = "src/lib.rs"

Plan.org

Lines changed: 0 additions & 35 deletions
This file was deleted.

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
1-
This project aims to implement iterative methods and associated utilities in Rust.
1+
The iterative_methods project implements iterative methods and
2+
associated utilities in Rust.
23

34
It currently demonstrates the following techniques we find powerful:
45
- Implement iterative methods as StreamingIterators.
5-
- Implement utilities useful to iterative methods as generic adaptors
6+
- Implement iterative methods utilities as generic adaptors
67
of StreamingIterators.
78
- Test non-trivial methods via property testing (quickcheck).
89
- Generic output via streaming yaml
910

11+
If you're not familiar with iterative methods or what the above mean,
12+
[start
13+
here](https://daniel-vainsencher.github.io/book/iterative_methods_part_1.html).
14+
1015
Future plans:
1116
- Expand/stabilize design
12-
- Add new iterative methods
17+
- Add more iterative methods
1318
- Add higher level utilities
1419
- Add simple function call interface to methods.
1520

1621
Stability/evolution:
1722
- The design is actively evolving, breakage is to be expected
18-
everywhere.
23+
everywhere. Feedback welcome! email us or open issues on the repo.
1924
- Some utilities (e.g., take_until) probably belong elsewhere (e.g.,
2025
{Streaming}Iterator) and so might migrate entirely.
2126

examples/reservoir_histogram_animation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fn write_reservoir_visualizations_data_to_yaml(
7171
let stream = enumerate(stream);
7272
let stream = write_yaml_documents(stream, parameters["stream_file"].to_string())
7373
.expect("Create File and initialize yaml iter failed.");
74-
let stream = reservoir_iterable(stream, capacity, None);
74+
let stream = reservoir_sample(stream, capacity, None);
7575
let stream = write_yaml_documents(stream, parameters["reservoir_samples_file"].to_string())
7676
.expect("Create File and initialize yaml iter failed.");
7777

examples/reservoir_sampling_mean_convergence.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn reservoir_sampling_mean_convergence() -> std::io::Result<()> {
3131

3232
// Create another copy of the stream to perform reservoir sampling and write to yaml:
3333
let stream = utils::generate_enumerated_step_stream(stream_size, num_of_initial_values, 0, 1);
34-
let res_iter = reservoir_iterable(stream, capacity, None);
34+
let res_iter = reservoir_sample(stream, capacity, None);
3535
let reservoir_samples_file = "./target/debug/examples/reservoirs.yaml";
3636
// Write data to file for visualization.
3737
let mut res_to_yaml = write_yaml_documents(res_iter, reservoir_samples_file.to_string())

examples/weighted_reservoir_sampling.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use streaming_iterator::*;
55

66
/// Utility function to generate a sequence of (float, int as float)
77
/// values wrapped in a WeightedDatum struct that will be used in tests
8-
/// of ReservoirIterable.
8+
/// of ReservoirSample.
99
fn generate_seeded_values(num_values: usize, int_range_bound: usize) -> Vec<WeightedDatum<f64>> {
1010
let mut prng = Pcg64::seed_from_u64(1);
1111
let mut seeded_values: Vec<WeightedDatum<f64>> = Vec::new();
@@ -32,7 +32,7 @@ fn wrs_demo() {
3232
println!("Random Numbers for Alg: \n (The values are used as the probabilities and the weights as indices.) \n {:#?} \n ", probability_and_index);
3333

3434
let stream = convert(stream);
35-
let mut stream = weighted_reservoir_iterable(stream, 2, Some(Pcg64::seed_from_u64(1)));
35+
let mut stream = weighted_reservoir_sample(stream, 2, Some(Pcg64::seed_from_u64(1)));
3636
println!("Reservoir - initially empty: \n {:#?} \n", stream.reservoir);
3737
let mut _index = 0usize;
3838
while let Some(reservoir) = stream.next() {

examples/wrs_histogram_animation.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ fn write_wrs_visualizations_data_to_yaml(
8282
.expect("Create File and initialize yaml iter failed.");
8383
// Add constant weights to all items
8484
let stream = wd_iterable(stream, |_x| 1.0f64);
85-
let stream = weighted_reservoir_iterable(stream, capacity, None);
85+
let stream = weighted_reservoir_sample(stream, capacity, None);
8686
// remove the weights, which were only needed for applying WRS.
8787
let stream = stream.map(|x| {
8888
let x: Vec<Numbered<f64>> = x.iter().map(|wd| wd.value.clone()).collect();
@@ -172,7 +172,14 @@ fn main() -> std::io::Result<()> {
172172
let (visualize, stream_size, capacity) = set_visualization_parameters();
173173
remove_yaml_files()?;
174174
write_wrs_visualizations_data_to_yaml(stream_size, capacity)?;
175-
println!("Data is written to yaml files.");
175+
println!(
176+
"Animation data files saved at:
177+
./target/debug/examples/population_for_histogram.yaml
178+
./target/debug/examples/reservoirs_for_histogram.yaml
179+
./target/debug/examples/reservoir_means.yaml
180+
./target/debug/examples/stream_for_histogram.yaml
181+
"
182+
);
176183
if visualize {
177184
make_visualization_in_python(
178185
"./visualizations_python/reservoir_histograms_initial_final.py",
@@ -186,15 +193,7 @@ fn main() -> std::io::Result<()> {
186193
"./visualizations_python/reservoir_histogram_animation.py",
187194
"Animation of reservoir and stream histograms",
188195
)?;
189-
} else {
190-
println!(
191-
"The following .yaml files have been created:\n
192-
./target/debug/examples/population_for_histogram.yaml \n
193-
./target/debug/examples/reservoirs_for_histogram.yaml \n
194-
./target/debug/examples/reservoir_means.yaml \n
195-
./target/debug/examples/stream_for_histogram.yaml \n
196-
"
197-
);
196+
println!("Animations saved at visualizations/*.html")
198197
}
199198
Ok(())
200199
}

pull_request_template.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# Intent:
22

3-
- [ ] Explain here what the goal is, so reviewer can read the implementation and judge whether that goal is achieved.
3+
<Explain the goal of the PR for the implementation to be judged
4+
against. Link to relevant context including issues, papers, etc>
45

56
# Validation:
67

7-
- [ ] Are changes covered by tests so we know existing functionality is not broken?
8-
- [ ] Is the new functionality covered by tests?
9-
- [ ] For functionality that is impractical to test
10-
- [ ] is there a demo?
11-
- [ ] does it look like you'd expect?
8+
<Survey coverage by existing or new tests, create a checklist for
9+
uncovered changes. For changes impractical to test, list them and
10+
consider a demo for human checking.>
1211

1312
# State of PR
14-
- [ ] Ready to merge on master
15-
- [ ] CI passes
16-
- [ ] Code is documented via rustdoc commments for readers post-landing
17-
- [ ] Changes that need explanation pre-landing (why make the change) have self-review comments
13+
<Check boxes when done>
14+
- [ ] Rustdoc and implementation comments?
15+
- [ ] Self review comments on non-obvious changes?
16+
- [ ] It seems to you ready to merge on master?
17+

0 commit comments

Comments
 (0)