Skip to content

Commit a40b6db

Browse files
committed
docs
1 parent 68e8d97 commit a40b6db

File tree

4 files changed

+74
-53
lines changed

4 files changed

+74
-53
lines changed

skdim/_commonfuncs.py

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -115,47 +115,48 @@ def asPointwise(data, class_instance, precomputed_knn=None, n_neighbors=100, n_j
115115
return np.array([class_instance.fit(data[i, :]).dimension_ for i in knn])
116116

117117

118-
class DocInheritorBase(type):
119-
""" A metaclass to append GlobalEstimator or LocalEstimator Attributes section docstring to each estimator"""
120-
121-
def __new__(mcs, class_name, class_bases, class_dict):
122-
# inherit class docstring: the docstring is constructed by traversing
123-
# the mro for the class and merging their docstrings, with each next
124-
# docstring as serving as the 'parent', and the accumulated docstring
125-
# serving as the 'child'
126-
this_doc = class_dict.get("__doc__", None)
127-
for mro_cls in (mro_cls for base in class_bases for mro_cls in base.mro()):
128-
prnt_cls_doc = mro_cls.__doc__
129-
if prnt_cls_doc is not None:
130-
if prnt_cls_doc == "The most base type":
131-
prnt_cls_doc = None
132-
this_doc = mcs.class_doc_inherit(prnt_cls_doc, this_doc)
133-
134-
class_dict["__doc__"] = this_doc
135-
136-
return type.__new__(mcs, class_name, class_bases, class_dict)
137-
138-
@staticmethod
139-
def class_doc_inherit(prnt_doc, child_doc):
140-
""" Merge the docstrings of a parent class and its child.
141-
Parameters
142-
----------
143-
prnt_cls_doc: Union[None, str]
144-
child_doc: Union[None, str]
145-
"""
146-
if prnt_doc is None or "dimension_" not in prnt_doc:
147-
return child_doc
148-
else:
149-
if "Attributes" in child_doc:
150-
prnt_doc_attr = prnt_doc.index("dimension_")
151-
child_doc = child_doc + prnt_doc[prnt_doc_attr:] + "\n"
152-
else:
153-
prnt_doc_attr = prnt_doc.index("Attributes")
154-
child_doc = child_doc + "\n " + prnt_doc[prnt_doc_attr:]
155-
return child_doc
156-
157-
158-
class GlobalEstimator(BaseEstimator, metaclass=DocInheritorBase):
118+
# class DocInheritorBase(type):
119+
# """ A metaclass to append GlobalEstimator or LocalEstimator Attributes section docstring to each estimator"""
120+
#
121+
# def __new__(mcs, class_name, class_bases, class_dict):
122+
# # inherit class docstring: the docstring is constructed by traversing
123+
# # the mro for the class and merging their docstrings, with each next
124+
# # docstring as serving as the 'parent', and the accumulated docstring
125+
# # serving as the 'child'
126+
# this_doc = class_dict.get("__doc__", None)
127+
# for mro_cls in (mro_cls for base in class_bases for mro_cls in base.mro()):
128+
# prnt_cls_doc = mro_cls.__doc__
129+
# if prnt_cls_doc is not None:
130+
# if prnt_cls_doc == "The most base type":
131+
# prnt_cls_doc = None
132+
# this_doc = mcs.class_doc_inherit(prnt_cls_doc, this_doc)
133+
#
134+
# class_dict["__doc__"] = this_doc
135+
#
136+
# return type.__new__(mcs, class_name, class_bases, class_dict)
137+
#
138+
# @staticmethod
139+
# def class_doc_inherit(prnt_doc, child_doc):
140+
# """ Merge the docstrings of a parent class and its child.
141+
#
142+
# Parameters
143+
# ----------
144+
# prnt_cls_doc: Union[None, str]
145+
# child_doc: Union[None, str]
146+
# """
147+
# if prnt_doc is None or "dimension_" not in prnt_doc:
148+
# return child_doc
149+
# else:
150+
# if "Attributes" in child_doc:
151+
# prnt_doc_attr = prnt_doc.index("dimension_")
152+
# child_doc = child_doc + prnt_doc[prnt_doc_attr:] + "\n"
153+
# else:
154+
# prnt_doc_attr = prnt_doc.index("Attributes")
155+
# child_doc = child_doc + "\n " + prnt_doc[prnt_doc_attr:]
156+
# return child_doc
157+
158+
159+
class GlobalEstimator(BaseEstimator): # , metaclass=DocInheritorBase):
159160
""" Template base class: inherit BaseEstimator, define predict, fit_predict, fit_pw, predict_pw, fit_predict_pw
160161
161162
Attributes
@@ -190,6 +191,7 @@ def predict(self, X=None):
190191

191192
def fit_predict(self, X, y=None):
192193
"""Fit estimator and return ID
194+
193195
Parameters
194196
----------
195197
X : {array-like}, shape (n_samples, n_features)
@@ -203,8 +205,7 @@ def fit_predict(self, X, y=None):
203205
return self.fit(X).dimension_
204206

205207
def fit_pw(self, X, precomputed_knn=None, smooth=False, n_neighbors=100, n_jobs=1):
206-
"""
207-
Creates an array of pointwise ID estimates (self.dimension_pw_) by fitting the estimator in kNN of each point.
208+
"""Creates an array of pointwise ID estimates (self.dimension_pw_) by fitting the estimator in kNN of each point.
208209
209210
Parameters
210211
----------
@@ -220,6 +221,7 @@ def fit_pw(self, X, precomputed_knn=None, smooth=False, n_neighbors=100, n_jobs=
220221
Additionally computes a smoothed version of pointwise estimates by
221222
taking the ID of a point as the average ID of each point in its neighborhood (self.dimension_pw_)
222223
smooth_
224+
223225
Returns
224226
-------
225227
self : object
@@ -282,8 +284,7 @@ def predict_pw(self, X=None):
282284
def fit_predict_pw(
283285
self, X, precomputed_knn=None, smooth=False, n_neighbors=100, n_jobs=1
284286
):
285-
"""
286-
Returns an array of pointwise ID estimates by fitting the estimator in kNN of each point.
287+
"""Returns an array of pointwise ID estimates by fitting the estimator in kNN of each point.
287288
288289
Parameters
289290
----------
@@ -334,7 +335,7 @@ def fit_predict_pw(
334335
return dimension_pw_
335336

336337

337-
class LocalEstimator(BaseEstimator, metaclass=DocInheritorBase):
338+
class LocalEstimator(BaseEstimator): # , metaclass=DocInheritorBase):
338339
""" Template base class: generic _fit, fit, predict_pw for local ID estimators
339340
340341
Attributes
@@ -369,6 +370,7 @@ def fit(
369370
n_jobs=1,
370371
):
371372
"""Fitting method for local ID estimators
373+
372374
Parameters
373375
----------
374376
X : {array-like}, shape (n_samples, n_features)
@@ -457,6 +459,7 @@ def fit_predict(
457459
n_jobs=1,
458460
):
459461
"""Fit-predict method for local ID estimators
462+
460463
Parameters
461464
----------
462465
X : {array-like}, shape (n_samples, n_features)

skdim/id/_DANCo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050

5151

5252
class DANCo(GlobalEstimator):
53-
"""Intrinsic dimension estimation using the Dimensionality from Angle and Norm Concentration algorithm. [Ceruti2012]_ [IDJohnsson]_
53+
"""Intrinsic dimension estimation using the Dimensionality from Angle and Norm Concentration algorithm. [Ceruti2012]_ [IDLombardi]_ [IDJohnsson]_
5454
5555
Parameters
5656
----------

skdim/id/_FisherS.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ def fit(self, X, y=None):
9393
-------
9494
self : object
9595
Returns self.
96+
self.dimension_: float
97+
The estimated intrinsic dimension
9698
self.n_alpha : 1D np.array, float
9799
Effective dimension profile as a function of alpha
98100
self.n_single : float

skdim/id/_TwoNN.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,27 @@
2929
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3030
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3131
#
32-
33-
# Author of the speed modifications (with sklearn dependencies): Jonathan Bac
34-
# Date : 02-Jan-2020
35-
# -----------------------------
36-
32+
# MIT License
33+
#
34+
# Copyright (c) 2019 fmottes
35+
#
36+
# Permission is hereby granted, free of charge, to any person obtaining a copy
37+
# of this software and associated documentation files (the "Software"), to deal
38+
# in the Software without restriction, including without limitation the rights
39+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
40+
# copies of the Software, and to permit persons to whom the Software is
41+
# furnished to do so, subject to the following conditions:
42+
#
43+
# The above copyright notice and this permission notice shall be included in all
44+
# copies or substantial portions of the Software.
45+
#
46+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
47+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
48+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
49+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
50+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
51+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
52+
# SOFTWARE.
3753

3854
from sklearn.utils.validation import check_array
3955

@@ -44,7 +60,7 @@
4460

4561

4662
class TwoNN(GlobalEstimator):
47-
"""Intrinsic dimension estimation using the TwoNN algorithm. [Facco2019]_ [IDFacco]_
63+
"""Intrinsic dimension estimation using the TwoNN algorithm. [Facco2019]_ [IDFacco]_ [IDMottes]_
4864
4965
Parameters
5066
----------

0 commit comments

Comments
 (0)