diff --git a/README.md b/README.md index d201a7c..27bff2f 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -# Bootstrap your plot +# Bootplot: bootstrap your plot -**Bootstrap your plot** is a library that lets you easily visualize uncertainty. You only need to provide a function -that generates a plot from your data and pass it to `bootstrapped_plot`. This will generate a static image and an +**Bootplot** is a library that lets you easily visualize uncertainty. You only need to provide a function +that generates a plot from your data and pass it to `bootplot`. This will generate a static image and an animation of your data uncertainty. The method works by resampling the original dataset and plotting each bootstrapped sample. @@ -14,7 +14,7 @@ line and visualize the uncertainty with the following code: import numpy as np from sklearn.linear_model import LinearRegression -from src import bootstrapped_plot +from bootplot import bootplot def make_linear_regression(data_subset, data_full, ax): @@ -41,7 +41,7 @@ if __name__ == '__main__': dataset[:, 1] = dataset[:, 0] * 1.5 + 2 + noise # Create image and animation that show uncertainty - bootstrapped_plot( + bootplot( make_linear_regression, dataset, output_image_path='bootstrapped_linear_regression.png', diff --git a/bootplot/__init__.py b/bootplot/__init__.py new file mode 100644 index 0000000..469e785 --- /dev/null +++ b/bootplot/__init__.py @@ -0,0 +1,3 @@ +from bootplot.sorting import sort_images, PCASorter, LucasKanadeSorter, HorizontalMassSorter, TravelingSalesmanSorter, \ + FarnebackSorter +from bootplot.base import bootplot diff --git a/src/base.py b/bootplot/base.py similarity index 82% rename from src/base.py rename to bootplot/base.py index 110f7d8..b56a3d5 100644 --- a/src/base.py +++ b/bootplot/base.py @@ -8,7 +8,7 @@ from tqdm import tqdm from PIL import Image -from src.sorting import sort_images +from bootplot.sorting import sort_images def fig_to_array(fig, ax): @@ -50,17 +50,17 @@ def decay_images(images, m: int, decay_length: int): return decayed_images -def bootstrapped_plot(f: callable, - data: np.ndarray, - m: int = 100, - output_size_px: Tuple[int, int] = (512, 512), - output_image_path: Union[str, Path] = None, - output_animation_path: Union[str, Path] = None, - sort_type: str = 'tsp', - sort_kwargs: dict = None, - decay: int = 0, - fps: int = 60, - verbose: bool = False): +def bootplot(f: callable, + data: np.ndarray, + m: int = 100, + output_size_px: Tuple[int, int] = (512, 512), + output_image_path: Union[str, Path] = None, + output_animation_path: Union[str, Path] = None, + sort_type: str = 'tsp', + sort_kwargs: dict = None, + decay: int = 0, + fps: int = 60, + verbose: bool = False): px_size_inches = 1 / plt.rcParams['figure.dpi'] fig, ax = plt.subplots(figsize=(output_size_px[0] * px_size_inches, output_size_px[1] * px_size_inches)) bootstrapped_matrices = np.stack([ diff --git a/src/image_features.py b/bootplot/image_features.py similarity index 100% rename from src/image_features.py rename to bootplot/image_features.py diff --git a/src/sorting.py b/bootplot/sorting.py similarity index 99% rename from src/sorting.py rename to bootplot/sorting.py index 2b0814e..8401a46 100644 --- a/src/sorting.py +++ b/bootplot/sorting.py @@ -11,7 +11,7 @@ import scipy import networkx as nx -from src.image_features import compute_hog_features, compute_center_of_mass, compute_center_of_mass_per_component +from bootplot.image_features import compute_hog_features, compute_center_of_mass, compute_center_of_mass_per_component class Sorter(abc.ABC): diff --git a/demo/bar_chart.py b/demo/bar_chart.py index 6e53303..9e25f63 100644 --- a/demo/bar_chart.py +++ b/demo/bar_chart.py @@ -1,5 +1,5 @@ import numpy as np -from src import bootstrapped_plot +from bootplot import bootplot def make_bar_chart(data_subset, data_full, ax): @@ -21,7 +21,7 @@ def make_bar_chart(data_subset, data_full, ax): np.random.seed(0) dataset = np.random.binomial(20, 0.3, size=1000) - bootstrapped_plot( + bootplot( make_bar_chart, dataset, m=100, diff --git a/demo/linear_regression.py b/demo/linear_regression.py index 747c95e..4bcedf0 100644 --- a/demo/linear_regression.py +++ b/demo/linear_regression.py @@ -1,7 +1,7 @@ import numpy as np from sklearn.linear_model import LinearRegression -from src import bootstrapped_plot +from bootplot import bootplot def make_linear_regression(data_subset, data_full, ax): @@ -26,7 +26,7 @@ def make_linear_regression(data_subset, data_full, ax): noise = np.random.randn(len(dataset)) * 2.5 dataset[:, 1] = dataset[:, 0] * 1.5 + 2 + noise - bootstrapped_plot( + bootplot( make_linear_regression, dataset, m=100, diff --git a/demo/multiple_point_plot.py b/demo/multiple_point_plot.py index 518b316..dafffd2 100644 --- a/demo/multiple_point_plot.py +++ b/demo/multiple_point_plot.py @@ -1,5 +1,5 @@ import numpy as np -from src import bootstrapped_plot +from bootplot import bootplot def make_point_plot(data_subset, data_full, ax): @@ -27,7 +27,7 @@ def make_point_plot(data_subset, data_full, ax): j = float(np.random.randint(n_classes)) dataset[i] = [j, np.random.randn() * j] - bootstrapped_plot( + bootplot( make_point_plot, dataset, m=100, diff --git a/demo/pie_chart.py b/demo/pie_chart.py index 064586e..5231c78 100644 --- a/demo/pie_chart.py +++ b/demo/pie_chart.py @@ -1,5 +1,5 @@ import numpy as np -from src import bootstrapped_plot +from bootplot import bootplot def make_pie_chart(data_subset, data_full, ax): @@ -30,7 +30,7 @@ def make_pie_chart(data_subset, data_full, ax): dataset = np.random.binomial(7, 0.2, size=1000) - bootstrapped_plot( + bootplot( make_pie_chart, dataset, m=100, diff --git a/demo/polynomial_regression.py b/demo/polynomial_regression.py index d3b5840..bba8fcc 100644 --- a/demo/polynomial_regression.py +++ b/demo/polynomial_regression.py @@ -1,7 +1,7 @@ import numpy as np from sklearn.linear_model import LinearRegression from sklearn.preprocessing import PolynomialFeatures -from src import bootstrapped_plot +from bootplot import bootplot def make_polynomial_regression(data_subset, data_full, ax): @@ -30,7 +30,7 @@ def make_polynomial_regression(data_subset, data_full, ax): noise = np.random.randn(len(dataset)) * 2.5 dataset[:, 1] = dataset[:, 0] * 1.5 + 2 + noise - bootstrapped_plot( + bootplot( make_polynomial_regression, dataset, m=100, diff --git a/demo/single_point_plot.py b/demo/single_point_plot.py index a342c56..ea4e99a 100644 --- a/demo/single_point_plot.py +++ b/demo/single_point_plot.py @@ -1,5 +1,5 @@ import numpy as np -from src import bootstrapped_plot +from bootplot import bootplot def make_plot_demo_point_plot(data_subset, data_full, ax): @@ -16,7 +16,7 @@ def make_plot_demo_point_plot(data_subset, data_full, ax): n_observations = 1000 dataset = np.random.uniform(low=-5.5, high=5.5, size=(n_observations,)) - mat = bootstrapped_plot( + mat = bootplot( make_plot_demo_point_plot, dataset, m=100, diff --git a/demo/text.py b/demo/text.py index 7801eb2..2ae599c 100644 --- a/demo/text.py +++ b/demo/text.py @@ -1,6 +1,6 @@ import numpy as np from sklearn.linear_model import LinearRegression -from src import bootstrapped_plot +from bootplot import bootplot def make_plot_demo_text(data_subset, data_full, ax): @@ -32,7 +32,7 @@ def make_plot_demo_text(data_subset, data_full, ax): noise = np.random.randn(len(dataset)) * 2.5 dataset[:, 1] = (dataset[:, 0] * 1.5 + noise) / 5 + 2.551 - bootstrapped_plot( + bootplot( make_plot_demo_text, dataset, m=100, diff --git a/src/__init__.py b/src/__init__.py deleted file mode 100644 index a7c84fd..0000000 --- a/src/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from src.sorting import sort_images, PCASorter, LucasKanadeSorter, HorizontalMassSorter, TravelingSalesmanSorter, \ - FarnebackSorter -from src.base import bootstrapped_plot \ No newline at end of file