gssl.classifiers package¶
Subpackages¶
Submodules¶
gssl.classifiers.CLGC module¶
Created on 23 de jun de 2020
@author: klaus
-
class
gssl.classifiers.CLGC.
CLGCClassifier
(alpha=0.1, num_iter=None, useEstimatedFreq=True)¶ Bases:
gssl.classifiers.classifier.GSSLClassifier
Constrained Local and Global Consistency Classifier. See [sousaconstrained].
-
__init__
(alpha=0.1, num_iter=None, useEstimatedFreq=True)¶ Constructor for the LGC classifier.
- Parameters
alpha (float) – A value between 0 and 1 (not inclusive) for alpha.
num_iter (float) – Optional. If not
Ǹone
, the number of iteration updates to perform
-
property
alpha
¶ \(\alpha\) such that \(\mu = \frac{1-\alpha}{\alpha}\) is the regularization factor multiplying the label fitting criterion. It is required that \(0 < \alpha < 1\).
-
fit
(X, W, Y, labeledIndexes, hook=None)¶ Classifies the input data.
- Parameters
X (NDArray[float].shape[N,D]) – Input matrix of N instances of dimension D.
W (NDArray[float].shape[N,N]) – The affinity matrix encoding the weighted edges.
Y (NDArray[float].shape[N,C]) – The initial belief matrix
hook (GSSLHook) – Optional. A hook to execute extra operations (e.g. plots) during the algorithm
- Returns
An updated belief matrix.
- Return type
NDArray[float].shape[N,C]
-
gssl.classifiers.GFHF module¶
Created on 27 de mar de 2019
@author: klaus
-
class
gssl.classifiers.GFHF.
GFHF
(num_iter=None)¶ Bases:
gssl.classifiers.classifier.GSSLClassifier
Label Propagation based on Gaussian Fields and Harmonic Functions. See [ZGL03].
-
__init__
(num_iter=None)¶ Constructor for GFHF classifier.
- Parameters
None –
-
fit
(X, W, Y, labeledIndexes, hook=None)¶ Classifies the input data.
- Parameters
X (NDArray[float].shape[N,D]) – Input matrix of N instances of dimension D.
W (NDArray[float].shape[N,N]) – The affinity matrix encoding the weighted edges.
Y (NDArray[float].shape[N,C]) – The initial belief matrix
hook (GSSLHook) – Optional. A hook to execute extra operations (e.g. plots) during the algorithm
- Returns
An updated belief matrix.
- Return type
NDArray[float].shape[N,C]
-
gssl.classifiers.GTAM module¶
Created on 27 de mar de 2019
@author: klaus
-
class
gssl.classifiers.GTAM.
GTAMClassifier
(mu=99.0, num_iter=None, useEstimatedFreq=True, constantProp=False, know_true_freq=True, weigh_by_degree=True)¶ Bases:
gssl.classifiers.classifier.GSSLClassifier
Classifier using Graph Transduction Through Alternating Minimization (GTAM - see [WJC08]).
-
__init__
(mu=99.0, num_iter=None, useEstimatedFreq=True, constantProp=False, know_true_freq=True, weigh_by_degree=True)¶ ” Constructor for GTAM classifier.
- Parameters
mu (float) – a parameter determining the importance of the fitting term. Default is
99.0
.num_iter (int) – Optional. The number of iterations to run. The default behaviour makes it N iterations given a NDArray[float].shape[N,D] input matrix.
useEstimatedFreq (Union[bool,NDArray[C],None]) – If
True
, then use estimated class freq. to balance the propagation. If it is a float array, it uses that as the frequency. IfNone
, assumes classes are equiprobable. Default isTrue
.useConstantProp (bool) – If
True
, then use try to maintain a constant proportion of labels in all iterations.
-
fit
(X, W, Y, labeledIndexes, hook=None)¶ Classifies the input data.
- Parameters
X (NDArray[float].shape[N,D]) – Input matrix of N instances of dimension D.
W (NDArray[float].shape[N,N]) – The affinity matrix encoding the weighted edges.
Y (NDArray[float].shape[N,C]) – The initial belief matrix
hook (GSSLHook) – Optional. A hook to execute extra operations (e.g. plots) during the algorithm
- Returns
An updated belief matrix.
- Return type
NDArray[float].shape[N,C]
-
gssl.classifiers.LGC module¶
-
class
gssl.classifiers.LGC.
LGCClassifier
(alpha=0.1, num_iter=None)¶ Bases:
gssl.classifiers.classifier.GSSLClassifier
Local and Global Consistency Classifier. See [ZBL+04].
-
__init__
(alpha=0.1, num_iter=None)¶ Constructor for the LGC classifier.
- Parameters
alpha (float) – A value between 0 and 1 (not inclusive) for alpha.
num_iter (float) – Optional. If not
Ǹone
, the number of iteration updates to perform
-
property
alpha
¶ \(\alpha\) such that \(\mu = \frac{1-\alpha}{\alpha}\) is the regularization factor multiplying the label fitting criterion. It is required that \(0 < \alpha < 1\).
-
fit
(X, W, Y, labeledIndexes, hook=None)¶ Classifies the input data.
- Parameters
X (NDArray[float].shape[N,D]) – Input matrix of N instances of dimension D.
W (NDArray[float].shape[N,N]) – The affinity matrix encoding the weighted edges.
Y (NDArray[float].shape[N,C]) – The initial belief matrix
hook (GSSLHook) – Optional. A hook to execute extra operations (e.g. plots) during the algorithm
- Returns
An updated belief matrix.
- Return type
NDArray[float].shape[N,C]
-
gssl.classifiers.LGC_tf module¶
Created on 23 de nov de 2019
@author: klaus
-
gssl.classifiers.LGC_tf.
LGC_iter_TF
(X, W, Y, labeledIndexes, alpha=0.1, num_iter=1000, hook=None)¶
-
gssl.classifiers.LGC_tf.
convert_sparse_matrix_to_sparse_tensor
(X, var_values=False)¶
-
gssl.classifiers.LGC_tf.
gather
(x, F)¶
-
gssl.classifiers.LGC_tf.
get_P
(TOTAL_ITER, ALPHA, S, F_0)¶
-
gssl.classifiers.LGC_tf.
get_S_fromtensor
(W)¶
-
gssl.classifiers.LGC_tf.
repeat
(x, n)¶
-
gssl.classifiers.LGC_tf.
row_normalize
(x)¶
-
gssl.classifiers.LGC_tf.
update_F
(TOTAL_ITER, ALPHA, S, F_0)¶
gssl.classifiers.LapEigLS module¶
Created on 27 de mar de 2019
@author: klaus
-
class
gssl.classifiers.LapEigLS.
LapEigLS
(p=0.2)¶ Bases:
gssl.classifiers.classifier.GSSLClassifier
Manifold Regularization with Laplacian Eigenmaps. Minimizes the Least Squares in a semi-supervised way by using a linear combination of the first \(p\) eigenfunctions. See [BN03].
-
__init__
(p=0.2)¶ Constructor for LapEigLS classifier.
- Parameters
p (Union[float,int]) – the labeled data. if float. Default is
0.2
-
fit
(X, W, Y, labeledIndexes, hook=None)¶ Classifies the input data.
- Parameters
X (NDArray[float].shape[N,D]) – Input matrix of N instances of dimension D.
W (NDArray[float].shape[N,N]) – The affinity matrix encoding the weighted edges.
Y (NDArray[float].shape[N,C]) – The initial belief matrix
hook (GSSLHook) – Optional. A hook to execute extra operations (e.g. plots) during the algorithm
- Returns
An updated belief matrix.
- Return type
NDArray[float].shape[N,C]
-
gssl.classifiers.RF module¶
-
class
gssl.classifiers.RF.
RFClassifier
(n_estimators=10)¶ Bases:
gssl.classifiers.classifier.GSSLClassifier
Supervised Random Forest classifier
-
__init__
(n_estimators=10)¶ Constructor for the LGC classifier.
- Parameters
alpha (float) – A value between 0 and 1 (not inclusive) for alpha.
-
fit
(X, W, Y, labeledIndexes, hook=None)¶ Classifies the input data.
- Parameters
X (NDArray[float].shape[N,D]) – Input matrix of N instances of dimension D.
W (NDArray[float].shape[N,N]) – The affinity matrix encoding the weighted edges.
Y (NDArray[float].shape[N,C]) – The initial belief matrix
hook (GSSLHook) – Optional. A hook to execute extra operations (e.g. plots) during the algorithm
- Returns
An updated belief matrix.
- Return type
NDArray[float].shape[N,C]
-
gssl.classifiers.SIIS module¶
Created on 27 de mar de 2019
@author: klaus
-
class
gssl.classifiers.SIIS.
SIISClassifier
(m=100, beta=10, alpha=100, rho=1.2, max_iter=1000)¶ Bases:
gssl.classifiers.classifier.GSSLClassifier
Label Propagation based on Semi-Supervised Learning under Inadequate and Incorrect Supervision (SIIS).
-
__init__
(m=100, beta=10, alpha=100, rho=1.2, max_iter=1000)¶ Constructor for SIIS classifier.
- Parameters
m (Union[float,int]) – The number of eigenvectors. It is given as either the absolute value (int), or a percentage of the labeled data (float).
alpha (float) – Value of parameter \(\alpha\) controlling the importance of the \(l_{2,1}\) norm smoothness term.
beta (float) – Value of parameter \(\beta\) controlling the importance of using smooth eigenfunctions within the already restricted eigenbasis.
max_iter (float) – Number of iterations.
rho (float) – Parameter for the convergence process. Default is
1.2
. Should not be changed unless there is a good reason.
-
static
edge_mat
(W)¶
-
fit
(X, W, Y, labeledIndexes, hook=None)¶ Classifies the input data.
- Parameters
X (NDArray[float].shape[N,D]) – Input matrix of N instances of dimension D.
W (NDArray[float].shape[N,N]) – The affinity matrix encoding the weighted edges.
Y (NDArray[float].shape[N,C]) – The initial belief matrix
hook (GSSLHook) – Optional. A hook to execute extra operations (e.g. plots) during the algorithm
- Returns
An updated belief matrix.
- Return type
NDArray[float].shape[N,C]
-
gssl.classifiers.classifier module¶
-
class
gssl.classifiers.classifier.
GSSLClassifier
¶ Bases:
object
Skeleton class for GSSL Classifiers.
-
classmethod
autohooks
(fun)¶ Automatically calls the begin and end method of the hook. The classifier result is passed as the ‘Y’ argument at the end.
-
fit
(X, W, Y, labeledIndexes, hook=None)¶ Classifies the input data.
- Parameters
X (NDArray[float].shape[N,D]) – Input matrix of N instances of dimension D.
W (NDArray[float].shape[N,N]) – The affinity matrix encoding the weighted edges.
Y (NDArray[float].shape[N,C]) – The initial belief matrix
hook (GSSLHook) – Optional. A hook to execute extra operations (e.g. plots) during the algorithm
- Returns
An updated belief matrix.
- Return type
NDArray[float].shape[N,C]
-
classmethod