Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
gmrandazzo committed Aug 17, 2023
1 parent 2269c36 commit 51f55ff
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 26 deletions.
4 changes: 2 additions & 2 deletions docs/GettingStartedInC.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion docs/Install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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/<user>/mylocalenv, then you need to export the
following variable

.. coide-block::
.. code-block::
export LISCIENTIFIC_LIB_DIR=/home/<user>/mylocalenv
Expand Down
67 changes: 61 additions & 6 deletions src/python_bindings/libscientific/clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
105 changes: 88 additions & 17 deletions src/python_bindings/libscientific/cpca.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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()
Expand Down

0 comments on commit 51f55ff

Please sign in to comment.