API Reference#
dnn_locate.loc_model#
loc_model#
- class dnn_locate.loc_model.loc_model(input_shape, discriminator, localizer_backend=None, tau_range=array([1, 2, 3, 4, 5, 6, 7, 8, 9]), target_r_square='auto', r_metric='acc', activation='tanh+relu', save_path=False)#
Bases:
object
class for discriminative feature detection for deep learning models.
- Parameters:
- input_shape{tuple-like} (shape of the feature/image)
For example, in MNIST dataset
input_shape = (28, 28, 1)
.- localizer_backend: {keras-defined neural network}
A backend neural network before reshape and Truncated ReLU activation.
- discriminator: {keras-defined neural network}
A pretrained neural network needs to be explained.
- tau_range{list-like}
List of tau to define the localizers.
- target_r_square: {float, [0,1]}
A target R_square to be explained.
- R_square: {list-like}
Records for R_square values based on a dataset.
- DA_plot(X, y, demo_ind=None, threshold=None, plt1_params={'cmap': 'binary'}, plt2_params={'cmap': 'OrRd'})#
Plots data-adaptive detected region for the fitted localizer.
- Parameters:
- X{array-like} of shape (n_samples, dim_features)
Instances matrix/tensor, where n_samples in the number of samples and dim_features is the dimension of the features.
- y{array-like} of shape (n_samples,)
Output vector/matrix relative to X.
- demo_ind{array-like} of shape (num_instance, num_labels) default=None
- threshold{array-like} or float, default=None
threshold to truncate the small detected pixels
- R_sqaure_path()#
Plot solution path for the proposed method wrt tau_range
- R_square(X, y)#
Report R_square for the fitted localizer based on a given dataset
- Parameters:
- X{array-like} of shape (n_samples, dim_features)
Instances matrix/tensor, where n_samples in the number of samples and dim_features is the dimension of the features.
- y{array-like} of shape (n_samples,)
Output vector/matrix relative to X.
- build_combined(optimizer=<keras.optimizers.optimizer_v2.adam.Adam object>)#
Building a localizer and a combined model for the proposed framework
- Parameters:
- localizer: {keras-defined neural network}
A neural network for localizer.
- optimizer: {keras-defined optimizer: ``tensorflow.keras.optimizers``}, default = ‘SGD(lr=.0005)’
A optimizer used to train the localizer.
- build_localizer(tau=10.0, max_value=1.0)#
Building a localizer for the proposed framework
- Parameters:
- tau: {float}
The magnitude of the localizer.
- max_value: {float, (0, 1]}
The maximum proportion of the localizer.
- fit(X_train, y_train, fit_params, datagen=None, demo_ind=None, X_test=None, y_test=None, optimizer=<keras.optimizers.optimizer_v2.gradient_descent.SGD object>)#
Fitting the localizer based on a given dataset.
- Parameters:
- X_train{array-like} of shape (n_samples, dim_features)
Instances matrix/tensor, where n_samples in the number of samples and dim_features is the dimension of the features.
- y_train{array-like} of shape (n_samples,)
Output vector/matrix relative to X.
- X_test{array-like} of shape (n_samples, dim_features), default = None
Instances features to compute the r_square. If
None
, X_test = X_train- y_test{array-like} of shape (n_samples,), default = None
Output to compute the r_square. If
None
, y_test = y_train- localizer{keras-defined neural network}
A neural network for localizer before Truncated RELU activation.
- fit_params: {dict of fitting parameters}
- See keras
fit
: (https://keras.rstudio.com/reference/fit.html), includingbatch_size
,epoch
,callbacks
, validation_split
,validation_data
, and so on.
- See keras
- demo_ind{array-like} default=None
The index set for demonstrated instances.
- optimizer: {keras-defined optimizer: ``tensorflow.keras.optimizers``}, default = ‘SGD(lr=.0005)’
A optimizer used to train the localizer.
- locate(X)#
Return the localized discriminative features by the fitted localizer.
- Parameters:
- X{array-like} of shape (n_samples, dim_features)
Instances matrix/tensor, where n_samples in the number of samples and dim_features is the dimension of the features.
- path_plot(threshold=None, plt1_params={'cmap': 'binary'}, plt2_params={'cmap': 'OrRd'})#
Plots generalized partial R values and its corresponding images wrt tau_range.
- Parameters:
- threshold{array-like} or float
threshold to truncate the small detected pixels
- plt1_params{dict-like}
dict for imshow for X_demo
- plt2_params{dict-like}
dict for imshow for X_diff_demo