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

Updated docs and minor fixes to density_advanced #135

Closed
wants to merge 9 commits into from
25 changes: 13 additions & 12 deletions dadapy/density_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def compute_grads(self, comp_covmat=False):

# ----------------------------------------------------------------------------------------------

def compute_pearson(self, comp_p_mat=False, method="jaccard"):
def compute_pearson(self, comp_p_mat=False, similarity_method="jaccard"):
"""
Compute, for any couple (i,j) of points connected on the directed neighbourhood graph, an estimate of the
Pearson correlation coefficient between the directed deltaFij computed with the gradients in i and in j, namely
Expand All @@ -193,13 +193,13 @@ def compute_pearson(self, comp_p_mat=False, method="jaccard"):

Args:
comp_p_mat (bool): if True, also computes the pearson_mat attribute.
method (str): method to compute the neighbourhood similarity index (see documentation for
compute_neigh_similarity_index).
similarity_method (str): similarity_method to compute the neighbourhood similarity index (see documentation
for compute_neigh_similarity_index).
"""

# check or compute neigh_similarity_index
if self.neigh_similarity_index is None:
self.compute_neigh_similarity_index(method=method)
self.compute_neigh_similarity_index(method=similarity_method)
# check or compute grads
if self.grads is None:
self.compute_grads()
Expand Down Expand Up @@ -234,7 +234,7 @@ def compute_pearson(self, comp_p_mat=False, method="jaccard"):
self.pearson_mat = p_mat.todense()
np.fill_diagonal(self.pearson_mat, 1.0)

def compute_deltaFs(self, pearson_method="jaccard", comp_p_mat=False):
def compute_deltaFs(self, similarity_method="jaccard", comp_p_mat=False):
"""Compute deviations deltaFij to standard kNN log-densities at point j as seen from point i using
a linear expansion with as slope the semisum of the average gradient of the log-density over
the neighbourhood of points i and j.
Expand All @@ -246,7 +246,7 @@ def compute_deltaFs(self, pearson_method="jaccard", comp_p_mat=False):
The log-density differences are stored Fij_array, their variances in Fij_array_var.

Args:
pearson_method: see docs for compute_pearson function
similarity_method: see docs for neigh_graph.compute_neigh_similarity_index function
comp_p_mat: see docs for compute_pearson function

"""
Expand All @@ -270,7 +270,9 @@ def compute_deltaFs(self, pearson_method="jaccard", comp_p_mat=False):

# check or compute common_neighs
if self.pearson_mat is None:
self.compute_pearson(method=pearson_method, comp_p_mat=comp_p_mat)
self.compute_pearson(
similarity_method=similarity_method, comp_p_mat=comp_p_mat
)

Fij_array = 0.5 * np.einsum("ij, ij -> i", g1 + g2, self.neigh_vector_diffs)
vari = np.einsum(
Expand All @@ -296,18 +298,17 @@ def compute_deltaFs(self, pearson_method="jaccard", comp_p_mat=False):

# ----------------------------------------------------------------------------------------------

def compute_deltaFs_inv_cross_covariance(self, pearson_method="jaccard"):
def compute_deltaFs_inv_cross_covariance(self, similarity_method="jaccard"):
"""Compute the appoximate inverse cross-covariance of the deltaFs cov[deltaFij,deltaFlm] using the LSDI
approximation (see compute_density_BMTI_reg docs)
approximation (see compute_density_BMTI docs)

Args:
pearson_method: see docs for compute_pearson function

similarity_method: see docs for neigh_graph.compute_neigh_similarity_index function
"""

# check for deltaFs
if self.pearson_mat is None:
self.compute_pearson(method=pearson_method, comp_p_mat=True)
self.compute_pearson(similarity_method=similarity_method, comp_p_mat=True)

# check or compute deltaFs_grads_semisum
if self.Fij_var_array is None:
Expand Down
5 changes: 5 additions & 0 deletions docs/source/density_advanced.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
The density_advanced module
================================

.. automodule:: density_advanced
:members:
4 changes: 3 additions & 1 deletion docs/source/implemented_algorithms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ The algorithms currently implemented are:
* k-NN ("k-nearest neighbours estimator")
* PAk ("Point adaptive k-NN estomator")
* k*-NN ("k-star nearest neighbours estimator")
* point-adaptive mean-shift gradient estimator
* BMTI ("Binless Multidimensional Thermodynamic Integration")

Density based clustering
--------------------------
Expand Down Expand Up @@ -52,4 +54,4 @@ These algorithms estimate the information content of each feature in the dataset
and assign a weight to each feature. The weights can take one the value zero, leading to feature selection.
The algorithm currently implemented is:

* DII ("Differentiable Information Imbalance")
* DII ("Differentiable Information Imbalance")
7 changes: 4 additions & 3 deletions docs/source/modules.rst
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
Modules (API reference)
=======================

The package contains the following modules: id_estimation, density_estimation, clustering, metric_comparisons,
feature_weighting,data, data_sets.
The package contains the following modules:


.. toctree::
:maxdepth: 2

base
id_estimation
neigh_graph
density_estimation
density_advanced
clustering
id_discrete
metric_comparisons
feature_weighting
data
utils
utils
5 changes: 5 additions & 0 deletions docs/source/neigh_graph.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
The neigh_graph module
================================

.. automodule:: neigh_graph
:members:
Loading