Skip to content

Commit

Permalink
add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaevers committed Jul 2, 2024
1 parent 006b6c2 commit 48eeaa6
Show file tree
Hide file tree
Showing 5 changed files with 288 additions and 15 deletions.
2 changes: 1 addition & 1 deletion example.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def example_uamds():
#plotsND.plot_contour_samples(distribs_lo, 10000, 128, None, [5, 25, 50, 75, 95])

def example_kde():
samples = np.random.randn(1000,2)
samples = np.random.randn(1000, 2)
distr = ua.distribution.distribution(samples)
plots2D.plot_contour(distr)

Expand Down
15 changes: 2 additions & 13 deletions examples/dimensionalityReduction.ipynb → examples/ownData.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,12 @@
"execution_count": null,
"id": "initial_id",
"metadata": {
"collapsed": true,
"is_executing": true
"collapsed": true
},
"outputs": [],
"source": [
"import uadapy"
""
]
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [],
"metadata": {
"collapsed": false
},
"id": "11bfe50ff5bc1eb0"
}
],
"metadata": {
Expand Down
133 changes: 133 additions & 0 deletions examples/uamds.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 24,
"id": "initial_id",
"metadata": {
"collapsed": true,
"ExecuteTime": {
"end_time": "2024-07-02T14:56:08.629731500Z",
"start_time": "2024-07-02T14:56:08.622215400Z"
}
},
"outputs": [],
"source": [
"import uadapy.data as data\n",
"import uadapy.dr.uamds as uamds\n",
"import uadapy.plotting.plots2D as plots2D\n",
"import numpy as np"
]
},
{
"cell_type": "markdown",
"source": [
"# Loading data\n",
"We provide ready-to-use toy datasets for getting started with the analysis quickly. In this example, we fit normal distributions to the points of the iris-dataset."
],
"metadata": {
"collapsed": false
},
"id": "7d50ba4e72fe8896"
},
{
"cell_type": "code",
"execution_count": 25,
"outputs": [],
"source": [
"distribs_hi = data.load_iris_normal()"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2024-07-02T14:56:09.122543800Z",
"start_time": "2024-07-02T14:56:09.107284800Z"
}
},
"id": "399ccab20e87f833"
},
{
"cell_type": "markdown",
"source": [
"# Applying UAMDS\n",
"Uncertainty-aware multi-dimensional scaling can be applied directly to reduce the data to a user-defined target dimension."
],
"metadata": {
"collapsed": false
},
"id": "6a4094383bfc23a6"
},
{
"cell_type": "code",
"execution_count": 26,
"outputs": [],
"source": [
"distribs_lo = uamds.uamds(distribs_hi, dims=2)"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2024-07-02T14:56:09.660688100Z",
"start_time": "2024-07-02T14:56:09.644078700Z"
}
},
"id": "17d410f46ac143ad"
},
{
"cell_type": "markdown",
"source": [
"# Visualizing data\n",
"The data can be directly visualized, for example as a contour plot."
],
"metadata": {
"collapsed": false
},
"id": "b90713040349a03b"
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"np.random.seed(0)\n",
"plots2D.plot_contour(distribs_lo, ranges=[[5,13],[8,15]])"
],
"metadata": {
"collapsed": false,
"is_executing": true
},
"id": "36652dfe9d1204d4"
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [],
"metadata": {
"collapsed": false
},
"id": "8215650467252202"
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
145 changes: 145 additions & 0 deletions examples/upca.ipynb

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion uadapy/plotting/plots1D.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,11 @@ def plot_1d_distribution(distributions, num_samples, plot_types:list, seed=55, f

fig, axs, samples, palette, num_plots, num_cols = setup_plot(distributions, num_samples, seed, fig, axs, colors, **kwargs)

num_attributes = np.shape(samples)[2]
# Check number of attributes
num_attributes = 1
if np.ndim(samples) > 2:
num_attributes = np.shape(samples)[2]

if labels:
ticks = range(len(labels))
else:
Expand All @@ -169,6 +173,8 @@ def plot_1d_distribution(distributions, num_samples, plot_types:list, seed=55, f
y_min = 9999
y_max = -9999
for k, sample in enumerate(samples):
if np.ndim(sample) == 1:
sample = np.array(sample).reshape(1,-1)
if 'boxplot' in plot_types:
boxprops = dict(facecolor=palette[k % len(palette)], edgecolor='black')
whiskerprops = dict(color='black', linestyle='--')
Expand Down

0 comments on commit 48eeaa6

Please sign in to comment.