Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve documentation #167

Merged
merged 80 commits into from
Feb 8, 2021
Merged
Changes from 1 commit
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
8070fe6
sort imports
sampan501 Jan 13, 2021
c0ac9e7
Merge branch 'master' into energy-mmd-disco
sampan501 Jan 13, 2021
ddfe3b0
fix docs error short underline
sampan501 Jan 13, 2021
65a2569
add energy source code
sampan501 Jan 13, 2021
05c8165
fix tutorials not rendering
sampan501 Jan 13, 2021
95b0a31
add more detail to compute distance and kernel
sampan501 Jan 13, 2021
1884dd2
Merge branch 'master' into better-docs
sampan501 Jan 13, 2021
c6916b9
add tutorials folder with overview
sampan501 Jan 14, 2021
5c83c70
add folder to gitignore
sampan501 Jan 15, 2021
07f55e2
add contributing guidelines to github repo
sampan501 Jan 15, 2021
fff2b0d
make docs look nicer
sampan501 Jan 15, 2021
a7d77fc
change reference to use automodule
sampan501 Jan 15, 2021
8484dbb
add changelog to single file
sampan501 Jan 15, 2021
e5a0402
remove reference folder
sampan501 Jan 15, 2021
760f10d
make clear the package reqs needs to be installed
sampan501 Jan 15, 2021
e4a5911
simplify autosummary table
sampan501 Jan 15, 2021
e44e1d4
remove old changelog files
sampan501 Jan 15, 2021
09e97f7
add file with all automodules
sampan501 Jan 15, 2021
3efedac
change docs layout
sampan501 Jan 15, 2021
7d4f7c0
add gallery and misc docs changes
sampan501 Jan 15, 2021
a996e77
change order of sidebar
sampan501 Jan 15, 2021
7c3bf1b
make install docs more clear
sampan501 Jan 15, 2021
5f8938c
update makefile with autogen and more options
sampan501 Jan 15, 2021
41a224f
update docs package requirements
sampan501 Jan 15, 2021
98cd501
remove github_links file
sampan501 Jan 15, 2021
8ce777e
remove old tutorial folder
sampan501 Jan 15, 2021
65dab0e
remove tutorials and gallery folders from docs
sampan501 Jan 15, 2021
7b1c6d7
add discriminability
sampan501 Jan 18, 2021
02bdeae
add statistic to the docs
sampan501 Jan 18, 2021
f902282
fix dcorr and hsic incorrect stats
sampan501 Jan 18, 2021
d439f6a
Merge branch 'master' into better-docs
sampan501 Jan 19, 2021
92e70c2
Merge branch 'master' into better-docs
sampan501 Jan 20, 2021
e64dae0
add citation page
sampan501 Jan 22, 2021
5f7b144
add internal links within docs
sampan501 Jan 22, 2021
4e68424
use readme in index.rst
sampan501 Jan 22, 2021
4e5d0d9
add links for dependencies
sampan501 Jan 22, 2021
a54fa40
use meth and class
sampan501 Jan 22, 2021
9a17205
update doc requirements
sampan501 Jan 22, 2021
615ec9d
remove docs tutorial page
sampan501 Jan 22, 2021
c85a5fa
update README to rst
sampan501 Jan 22, 2021
b61eb57
Update setup.py
sampan501 Jan 22, 2021
fe8cd2e
fix reference docs formatting
sampan501 Jan 22, 2021
f4b2844
remove figure from package overview
sampan501 Jan 22, 2021
a38fb43
add example folder
sampan501 Jan 22, 2021
45f27a4
add mgc map example
sampan501 Jan 22, 2021
2f83436
add independence simulations example
sampan501 Jan 22, 2021
a0d2412
add feature importance example
sampan501 Jan 22, 2021
572a640
install package pip netlify
sampan501 Jan 26, 2021
0f52c9a
Update netlify.toml
sampan501 Jan 26, 2021
81a58f9
add recommonmark
sampan501 Jan 26, 2021
34452d1
add matplotlib and seaborn
sampan501 Jan 26, 2021
550bf31
add tutorials and mmd
sampan501 Jan 26, 2021
b935187
add disco
sampan501 Jan 26, 2021
00de4f9
update doctest errors
sampan501 Jan 26, 2021
51c1dc8
Update mmd.py
sampan501 Jan 26, 2021
9c1e2ff
fix intersphinx mapping
sampan501 Jan 28, 2021
6b1bf60
move gaussian sim to new example
sampan501 Jan 28, 2021
8d9d0da
remove reps warning
sampan501 Feb 2, 2021
7a17b8e
add fast 1D Dcorr
sampan501 Feb 2, 2021
17225a9
add helper functions reference
sampan501 Feb 2, 2021
9b424cc
add manova and hotelling
sampan501 Feb 7, 2021
42007a2
fix documentation weird renderings
sampan501 Feb 7, 2021
fbbfb24
remove unused import indep_sims
sampan501 Feb 7, 2021
8f9db33
add max margin test
sampan501 Feb 8, 2021
f181538
fix doctest assertion errors
sampan501 Feb 8, 2021
1c657a8
cache numba
sampan501 Feb 8, 2021
6311eb0
add k-sample tutorial
sampan501 Feb 8, 2021
de0ddac
move general example to overview py file
sampan501 Feb 8, 2021
9a6e880
add time-series tutorial
sampan501 Feb 8, 2021
605ea9c
add time series tutorial
sampan501 Feb 8, 2021
5b0d7c9
add time series sims
sampan501 Feb 8, 2021
ec22b5c
fix tutorials
sampan501 Feb 8, 2021
db9b3e6
add v to tag name
sampan501 Feb 8, 2021
da680ec
change order of independence test
sampan501 Feb 8, 2021
f25bb81
add discriminability tutorial
sampan501 Feb 8, 2021
597b6c5
change name of time series sim file
sampan501 Feb 8, 2021
e936ea7
[skip ci] clean netlify directory
sampan501 Feb 8, 2021
7dd860d
[skip ci] rebuild docs
sampan501 Feb 8, 2021
eac3255
[skip ci] update netlify runtime version
sampan501 Feb 8, 2021
66ef343
change netlify build command to fix intersphinx
sampan501 Feb 8, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add mgc map example
  • Loading branch information
sampan501 committed Jan 22, 2021
commit 45f27a49b90bb8fea939c50cc5ff93d53dc52824
83 changes: 83 additions & 0 deletions examples/mgc_map.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
"""
MGC Map
========

hyppo offers the :class:`hyppo.independence.MGC` class, which is a powerful independence
test to fit a host of different types of data.
The MGC Map is essentially an array of local correlations (i.e. the test statistic that
at each nearest neighbor pair). The optimal scale is the nearest neighbor pair that
maximizes the test statistic, and this test statistic is the one we return as part of
MGC.
Let's look at how we can use hyppo
to find a trend in linear data sets (:meth:`hyppo.tools.linear`) and nonlinear data sets
(for example :meth:`hyppo.tools.spiral`) and visualize this map and optimal scale.
"""
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import seaborn as sns
from hyppo.independence import MGC
from hyppo.tools import linear, spiral

# make a dictionary that maps the simulation function to a string
sims = {
"Linear": linear,
"Spiral": spiral,
}


# make a function that runs the code depending on the simulation
def run_test(sim_type="Linear"):
"""Runs all the tests for both simulations."""

# simulate our data (100 samples, 3 dimensions)
x, y = sims[sim_type](n=100, p=3, noise=True)

# calculate the MGC test statistic, p-value, and get a dictionary with the
# mgc_map (shows the geometric nature of the relationship) and the optimal
# scale, which is the k,l nearest neighbors that maximize the test statistic
stat, pvalue, mgc_dict = MGC().test(x, y)
print(stat, pvalue)

# plot the MGC map with a map of the local correlations (as mentioned before,
# shows the geometric nature of the relationship), and the optimal scale,
# which is the maximimum smoothed test statistic
mgc_map = mgc_dict["mgc_map"]
opt_scale = mgc_dict["opt_scale"] # i.e. maximum smoothed test statistic
print("Optimal Scale:", opt_scale)

# create figure
fig, (ax, cax) = plt.subplots(
ncols=2, figsize=(9.45, 7.5), gridspec_kw={"width_ratios": [1, 0.05]}
)

# draw heatmap and colorbar
ax = sns.heatmap(mgc_map, cmap="YlGnBu", ax=ax, cbar=False)
fig.colorbar(ax.get_children()[0], cax=cax, orientation="vertical")
ax.invert_yaxis()

# optimal scale
ax.scatter(opt_scale[1], opt_scale[0], marker="X", s=200, color="red")

# make plots look nice
fig.suptitle("MGC Map - {}".format(sim_type), fontsize=17)
ax.xaxis.set_major_locator(ticker.MultipleLocator(10))
ax.xaxis.set_major_formatter(ticker.ScalarFormatter())
ax.yaxis.set_major_locator(ticker.MultipleLocator(10))
ax.yaxis.set_major_formatter(ticker.ScalarFormatter())
ax.set_xlabel("Neighbors for x")
ax.set_ylabel("Neighbors for y")
ax.set_xticks([0, 50, 100])
ax.set_yticks([0, 50, 100])
ax.xaxis.set_tick_params()
ax.yaxis.set_tick_params()
cax.xaxis.set_tick_params()
cax.yaxis.set_tick_params()
plt.show()


# run the created function for linear and spiral simulations. Notice how the
# MGC map looks different for a spiral simulation and linear simulation.
# Optimal scale informs this, linearly related data has a scale at the max
# scale, while nonlinearly related data does not.
run_test(sim_type="Linear")
run_test(sim_type="Spiral")