diff --git a/docs/GettingStartedInC.rst b/docs/GettingStartedInC.rst index c10384d..4c2e32a 100644 --- a/docs/GettingStartedInC.rst +++ b/docs/GettingStartedInC.rst @@ -87,7 +87,7 @@ Matrix is a user-defined data type that contains: The data array is selected explicitly as a double type to work with an extensive range of numbers. -.. literalinclude:: ../../src/matrix.h +.. literalinclude:: ../src/matrix.h :language: c :lines: 30-33 @@ -178,7 +178,7 @@ Tensor is a user-defined data type that contains: The data array is selected explicitly as a double type to work with an extensive range of numbers. -.. literalinclude:: ../../src/tensor.h +.. literalinclude:: ../src/tensor.h :language: c :lines: 33-36 diff --git a/docs/Install.rst b/docs/Install.rst index 8dc6a73..710acef 100644 --- a/docs/Install.rst +++ b/docs/Install.rst @@ -50,7 +50,8 @@ please export the LIBSCIENTIFIC_LIB_DIR variable pointing to the libscientific.s For example, if the library is installed in /home//mylocalenv, then you need to export the following variable -.. coide-block:: +.. code-block:: + export LISCIENTIFIC_LIB_DIR=/home//mylocalenv diff --git a/src/python_bindings/libscientific/clustering.py b/src/python_bindings/libscientific/clustering.py index e884874..0f3b0b9 100644 --- a/src/python_bindings/libscientific/clustering.py +++ b/src/python_bindings/libscientific/clustering.py @@ -33,8 +33,26 @@ lsci.MDC.restype = None def most_descriptive_compound(x_input, nobjects): - """ - Most Descriptive Compound algorithm + """Most Descriptive Compound selection algorithm. + + Parameters + ---------- + x_input: List[List] + Input matrix + nobjects: int + Number of object select + + Returns + ------- + A list of selected objects/row id. + + Examples + -------- + >>> np.random.seed(12345) + >>> x = np.random.rand(100,2) + >>> mdc_ids = libscientific.clustering.most_descriptive_compound(x, 10) + >>> mdc_ids + [74, 97, 95, 7, 35, 25, 50, 10, 32, 59] """ if "Matrix" not in str(type(x_input)): x_input_ = mx.new_matrix(x_input) @@ -65,8 +83,26 @@ def most_descriptive_compound(x_input, nobjects): def max_dissimilarity_selection(x_input, nobjects): - """ - Max dissimilarity compound selection algorithm + """Max dissimilarity compound selection algorithm + + Parameters + ---------- + x_input: List[List] + Input matrix + nobjects: int + Number of object select + + Returns + ------- + A list of selected objects/row id. + + Examples + -------- + >>> np.random.seed(12345) + >>> x = np.random.rand(100,2) + >>> mdis_ids = libscientific.clustering.max_dissimilarity_selection(x, 10) + >>> mdis_ids + [57, 89, 88, 6, 23, 94, 56, 61, 39, 24] """ if "Matrix" not in str(type(x_input)): x_input_ = mx.new_matrix(x_input) @@ -98,8 +134,27 @@ def max_dissimilarity_selection(x_input, nobjects): def k_means_plus_plus(x_input, n_clusters): - """ - K-Means++ clustering using david arthur initialization + """K-Means++ clustering (kmeans + David Arthur initialization) + + Parameters + ---------- + x_input: List[List] + Input matrix + nobjects: int + Number of object select + + Returns + ------- + A list of selected objects/row id. + + Examples + -------- + >>> np.random.seed(12345) + >>> x = np.random.rand(100,2) + >>> clusters = libscientific.clustering.k_means_plus_plus(x, 3) + >>> clusters = libscientific.clustering.k_means_plus_plus(x, 3) + >>> clusters + [1, 2, 0, 0, 0, 0, 2, 2, 0, 0, 0, 1, ..., 0, 1, 1, 2, 2] """ if "Matrix" not in str(type(x_input)): x_input_ = mx.new_matrix(x_input) diff --git a/src/python_bindings/libscientific/cpca.py b/src/python_bindings/libscientific/cpca.py index 8c34fec..8b165f2 100644 --- a/src/python_bindings/libscientific/cpca.py +++ b/src/python_bindings/libscientific/cpca.py @@ -120,9 +120,36 @@ def print_cpca(mpca): class CPCA(): """ - CPCA model class + Consesus Principal Component Analysis + + Examples + -------- + >>> np.random.seed(12345) + >>> x = np.random.rand(100,2) + >>> clusters = libscientific.clustering.k_means_plus_plus(x, 3) + >>> clusters = libscientific.clustering.k_means_plus_plus(x, 3) + >>> clusters + [1, 2, 0, 0, 0, 0, 2, 2, 0, 0, 0, 1, ..., 0, 1, 1, 2, 2] + """ def __init__(self, scaling, npc): + """Init method + + Parameters + ---------- + scaling: int + scaling type to apply. Available scalings: + 0: No scaling. Only mean centering + 1: Mean centering and STDEV scaling + 2: Mean centering and Root-Mean-Square column scaling + 3: Mean centering and Pareto scaling + 4: Mean centering and min-max range scaling + 5: Mean centering and level scaling + + npc: int + Number of principal components + + """ self.model = new_cpca_model() self.scaling = scaling self.npc = npc @@ -134,8 +161,16 @@ def __del__(self): self.model = None def fit(self, t_input): - """ - fit a cpca model using an input tensor + """Fit the consensus pca + + Parameters + ---------- + t_input: tensor + libscientific tensor + + Returns + ------- + The fitted CPCA model class """ if "Tensor" in str(type(t_input)): cpca_algorithm(t_input.tns, self.scaling, self.npc, self.model) @@ -146,44 +181,80 @@ def fit(self, t_input): del t_input_ def get_super_scores(self): - """ - get the cpca super scores + """Get the CPCA super scores + + Returns + ------- + super_scores: List[List] + CPCA super scores """ return mx.matrix_to_list(self.model.contents.super_scores) def get_super_weights(self): - """ - get the cpca super weights + """Get the CPCA super weights + + Returns + ------- + super_weights: List[List] + CPCA super weights """ return mx.matrix_to_list(self.model.contents.super_weights) def get_block_scores(self): - """ - get the cpca block scores + """Get the CPCA block scores + + Returns + ------- + block_scores: List[List[List]] + CPCA block scores """ return tns.tensor_tolist(self.model.contents.block_scores) def get_block_loadings(self): - """ - get the cpca block loadings + """Get the CPCA block loadings + + Returns + ------- + block_loadings: List[List[List]] + CPCA block loadings """ return tns.tensor_tolist(self.model.contents.block_loadings) def get_block_expvar(self): - """ - get the cpca block variance explained + """Get the CPCA block explained variance + + Returns + ------- + block_exp_var: List[List[List]] + CPCA block explained variance """ return vlst.dvector_list_tolist(self.model.contents.block_expvar) def get_total_exp_variance(self): - """ - get the cpca total variance explained + """Get the CPCA total explained variance + + Returns + ------- + exp_var: List[List[List]] + CPCA total explained variance """ return vect.dvector_tolist(self.model.contents.total_expvar) def predict(self, t_input): - """ - get the cpca block variance explained + """Predict super scores and block scores using the CPCA model + + Parameters + ---------- + t_input: tensor + libscientific tensor + + Returns + ------- + p_super_scores: List[List] + CPCA predicted super scores + + p_block_scores: List[List[List]] + CPCA predicted block scores """ t_input_ = tns.new_tensor(t_input) p_super_scores_ = mx.init_matrix()