- Notifications
You must be signed in to change notification settings - Fork0
Estimation of Neural Network Dimension using Algebraic Topology and Lie Theory.
License
karhunenloeve/NTOPL
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
- This is the link to the arxiv article.
- This is the link to slides for the talk given at the IMTA-7.
- This is the link to the transcript of the talk given at the IMTA-7.
In this paper we present an approach to determine the smallest possible number of perceptrons in a neural net in such a way that the topology of the input space can be learned sufficiently well. We introduce a general procedure based on persistent homology to investigate topological invariants of the manifold on which we suspect the data set. We specify the required dimensions precisely, assuming that there is a smooth manifold on or near which the data are located. Furthermore, we require that this space is connected and has a commutative group structure in the mathematical sense. These assumptions allow us to derive a decomposition of the underlying space whose topology is well known. We use the representatives of thek-dimensional homology groups from the persistence landscape to determine an integer dimension for this decomposition. This number is the dimension of the embedding that is capable of capturing the topology of the data manifold. We derive the theory and validate it experimentally on toy data sets.
Keywords: Embedding Dimension, Parameterization, Persistent Homology, Neural Networks and Manifold Learning.
@inproceedings{imta7/MelodiaL21, author = {Luciano Melodia and Richard Lenz}, editor = {Del Bimbo, A., Cucchiara, R., Sclaroff, S., Farinella, G.M., Mei, T., Bertini, M., Escalante, H.J., Vezzani, R.}, title = {Estimate of the Neural Network Dimension using Algebraic Topology and Lie Theory}, booktitle = {Pattern Recognition. ICPR International Workshops and Challenges, {IMTA VII} 2021, Milano, Italy, January 11, 2021, Proceedings}, series = {Lecture Notes in Computer Science}, volume = {12665}, pages = {15--29}, publisher = {Springer}, year = {2021}, url = {https://doi.org/10.1007/978-3-030-68821-9_2}, doi = {10.1007/978-3-030-68821-9_2},}
- Invertible autoencoders
autoencoderInvertible.py
- Remove tensor elements
- Get prime factors
- Load example Keras datasets
- Add gaussian noise to data
- Crop tensor elements
- Greate a group of convolutional layers
- Loop over a group of convolutional layers
- Invertible Keras neural network layer
- Convert dimensions into 2D-convolution
- Embedded invertible autoencoder model
- Count representatives from homology groups
countHomgroups.py
- Persistence landscapes
persistenceLandscapes.py
- Persistence statistics
persistenceStatistics.py
take_out_element(k:tuple,r)->tuple
A function taking out specific values.
- paramk: tuple object to be processed, type
tuple
. - paramr: value to be removed, type
int, float, string, None
. - returnk2: cropped tuple object, type
tuple
.
primeFactors(n)
A function that returns the prime factors of an integer.
- paramn: an integer, type
int
. - returnfactors: a list of prime factors, type
list
.
load_data_keras(dimensions:tuple,factor:float=255.0,dataset:str='mnist')->tuple
A utility function to load datasets.
This functions helps to load particular datasets ready for a processing with convolutionalor dense autoencoders. It depends on the specified shape (the input dimensions). This functionsis for validation purpose and works for keras datasets only.Supported datasets aremnist
(default),cifar10
,cifar100
andboston_housing
.The shapes:mnist (28,28,1)
,cifar10 (32,32,3)
,cifar100 (32,32,3)
- paramdimensions: dimension of the data, type
tuple
. - paramfactor: division factor, default is
255
, typefloat
. - paramdataset: keras dataset, default is
mnist
,typestr
. - returnX_train, X_test, input_image: , type
tuple
.
add_gaussian_noise(data:numpy.ndarray,noise_factor:float=0.5,mean:float=0.0,std:float=1.0)->numpy.ndarray
A utility function to add gaussian noise to data.
The purpose of this functions is validating certain models under gaussian noise.The noise can be added changing the mean, standard deviation and the amount ofnoisy points added.
- paramnoise_factor: amount of noise in percent, type
float
. - paramdata: dataset, type
np.ndarray
. - parammean: mean, type
float
. - paramstd: standard deviation, type
float
. - returnx_train_noisy: noisy data, type
np.ndarray
.
crop_tensor(dimension:int,start:int,end:int)->Callable
A utility function cropping a tensor along a given dimension.
The purpose of this function is to be used for multivariate cropping and to serveas a procedure for the invertible autoencoders, which need a cropping to make thematrices trivially invertible, as can be seen in theReal NVP
architecture.This procedure works up to dimension4
.
- paramdimension: the dimension of cropping, type
int
. - paramstart: starting index for cropping, type
int
. - paramend: ending index for cropping, type
int
. - returnLambda(func): Lambda function on the tensor, type
Callable
.
convolutional_group(_input:numpy.ndarray,filterNumber:int,alpha:float=5.5,kernelSize:tuple= (2,2),kernelInitializer:str='uniform',padding:str='same',useBias:bool=True,biasInitializer:str='zeros')
This group can be extended for deep learning models and is a sequence of convolutional layers.
The convolutions is a2D
-convolution and uses aLeakyRelu
activation function. After the activationfunction batch-normalization is performed on default, to take care of the covariate shift. As defaultthe padding is set to same, to avoid difficulties with convolution.
- param_input: data from previous convolutional layer, type
np.ndarray
. - paramfilterNumber: multiple of the filters per layer, type
int
. - paramalpha: parameter for
LeakyRelu
activation function, default5.5
, typefloat
. - paramkernelSize: size of the
2D
kernel, default(2,2)
, typetuple
. - paramkernelInitializer: keras kernel initializer, default
uniform
, typestr
. - parampadding: padding for convolution, default
same
, typestr
. - paramuseBias: whether or not to use the bias term throughout the network, type
bool
. - parambiasInitializer: initializing distribution of the bias values, type
str
. - returndata: processed data by neural layers, type
np.ndarray
.
loop_group(group:Callable,groupLayers:int,element:numpy.ndarray,filterNumber:int,kernelSize:tuple,useBias:bool=True,kernelInitializer:str='uniform',biasInitializer:str='zeros')->numpy.ndarray
This callable is a loop over a group specification.
The neural embeddings ends always with dimension1
in the color channel. For otherspecifications use the parametercolorChannel
. The function operates on every kerasgroup of layers using the same parameter set as2D
convolution.
- paramgroup: a callable that sets up the neural architecture, type
Callable
. - paramgroupLayers: depth of the neural network, type
int
. - paramelement: data, type
np.ndarray
. - paramfilterNumber: number of filters as exponential of
2
, typeint
. - paramkernelSize: size of the kernels, type
tuple
. - returndata: processed data by neural network, type
np.ndarray
. - paramuseBias: whether or not to use the bias term throughout the network, type
bool
. - parambiasInitializer: initializing distribution of the bias values, type
str
.
invertible_layer(data:numpy.ndarray,alpha:float=5.5,kernelSize:tuple= (2,2),kernelInitializer:str='uniform',groupLayers:int=6,filterNumber:int=2,croppingFactor:int=4,useBias:bool=True,biasInitializer:str='zeros')->numpy.ndarray
Returns an invertible neural network layer.
This neural network layer learns invertible subspaces, parameterized by higher dimensionalfunctions with a trivial invertibility. The higher dimensional functions are also neuralsubnetworks, trained during learning process.
- paramdata: data from previous convolutional layer, type
np.ndarray
. - paramalpha: parameter for
LeakyRelu
activation function, default5.5
, typefloat
. - paramgroupLayers: depth of the neural network, type
int
. - paramkernelSize: size of the kernels, type
tuple
. - paramfilterNumber: multiple of the filters per layer, type
int
. - paramcroppingFactor: should be a multiple of the strides length, type
int
. - paramuseBias: whether or not to use the bias term throughout the network, type
bool
. - parambiasInitializer: initializing distribution of the bias values, type
str
. - returndata: processed data, type
np.ndarray
.
invertible_subspace_dimension2(units:int)
A helper function converting dimensions into 2D convolution shapes.
This functions works only for quadratic dimension size. It reshapes the dataaccording to an embedding with the same dimension, represented by a2D
array.
- paramunits: , type
int
. - returnembedding: , type
tuple
.
invertible_subspace_autoencoder(data:numpy.ndarray,units:int,invertibleLayers:int,alpha:float=5.5,kernelSize:tuple= (2,2),kernelInitializer:str='uniform',groupLayers:int=6,filterNumber:int=2,useBias:bool=True,biasInitializer:str='zeros')
A function returning an invertible autoencoder model.
This model works only with a quadratic number as units. The convolutional embeddingdimension in2D
is determined, for the quadratic matrix, as the square root of therespective dimension of the dense layer. This module is for testing purposes and notmeant to be part of a productive environment.
- paramdata: data, type
np.ndarray
. - paramunits: projection dim. into lower dim. by dense layer, type
int
. - paraminvertibleLayers: amout of invertible layers in the middle of the network, type
int
. - paramalpha: parameter for
LeakyRelu
activation function, default5.5
, typefloat
. - paramkernelSize: size of the kernels, type
tuple
. - paramkernelInitializer: initializing distribution of the kernel values, type
str
. - paramgroupLayers: depth of the neural network, type
int
. - paramfilterNumber: multiple of the filters per layer, type
int
. - paramuseBias: whether or not to use the bias term throughout the network, type
bool
. - parambiasInitializer: initializing distribution of the bias values, type
str
. - paramfilterNumber: an integer factor for each convolutional layer, type
int
. - returnoutput: an output layer for keras neural networks, type
np.ndarray
.
concatenate_landscapes(persLandscape1:numpy.ndarray,persLandscape2:numpy.ndarray,resolution:int)->list
This function concatenates the persistence landscapes according to homology groups.
The computation of homology groups requires a certain resolution for each homology class.According to this resolution the direct sum of persistence landscapes has to be concatenatedin a correct manner, such that the persistent homology can be plotted according to then
-dimensionalpersistent homology groups.
- parampersLandscape1: persistence landscape, type
np.ndarray
. - parampersLandscape2: persistence landscape, type
np.ndarray
. - returnconcatenatedLandscape: direct sum of persistence landscapes, type
list
.
compute_persistence_landscape(data:numpy.ndarray,res:int=1000,persistenceIntervals:int=1,maxAlphaSquare:float=1000000000000.0,filtration:str= ['alphaComplex','vietorisRips','tangential'],maxDimensions:int=10,edgeLength:float=0.1,plot:bool=False,smoothen:bool=False,sigma:int=3)->numpy.ndarray
A function for computing persistence landscapes for 2D images.
This function computes the filtration of a 2D image dataset, the simplicial complex,the persistent homology and then returns the persistence landscape as array. It takesthe resolution of the landscape as parameter, the maximum size foralphaSquare
andoptions for certain filtrations.
- paramdata: data set, type
np.ndarray
. - paramres: resolution, default is
1000
, typeint
. - parampersistenceIntervals: interval for persistent homology, default is
1e12
,typefloat
. - parammaxAlphaSquare: max. parameter for delaunay expansion, type
float
. - paramfiltration: alphaComplex, vietorisRips, cech, delaunay, tangential, type
str
. - parammaxDimensions: only needed for VietorisRips, type
int
. - paramedgeLength: only needed for VietorisRips, type
float
. - paramplot: whether or not to plot, type
bool
. - paramsmoothen: whether or not to smoothen the landscapes, type
bool
. - paramsigma: smoothing factor for gaussian mixtures, type
int
. - returnlandscapeTransformed: persistence landscape, type
np.ndarray
.
compute_mean_persistence_landscapes(data:numpy.ndarray,resolution:int=1000,persistenceIntervals:int=1,maxAlphaSquare:float=1000000000000.0,filtration:str= ['alphaComplex','vietorisRips','tangential'],maxDimensions:int=10,edgeLength:float=0.1,plot:bool=False,tikzplot:bool=False,name:str='persistenceLandscape',smoothen:bool=False,sigma:int=2)->numpy.ndarray
This function computes mean persistence diagrams over 2D datasets.
The functions shows a progress bar of the processed data and takes the directsum of the persistence modules to get a summary of the landscapes of the varioussamples. Further it can be decided whether or not to smoothen the persistencelandscape by gaussian filter. A plot can be created withmatplotlib
or asanother option for scientific reporting withtikzplotlib
, or both.
Information: The color scheme has 5 colors defined. Thus 5 homology groups can bedisplayed in different colors.
- paramdata: data set, type
np.ndarray
. - paramresolution: resolution of persistent homology per group, type
int
. - parampersistenceIntervals: intervals for persistence classes, type
int
. - parammaxAlphaSquare: max. parameter for Delaunay expansion, type
float
. - paramfiltration:
alphaComplex
,vietorisRips
ortangential
, typestr
. - parammaxDimensions: maximal dimension of simplices, type
int
. - paramedgeLength: length of simplex edge, type
float
. - paramplot: whether or not to plot, type
bool
. - paramtikzplot: whether or not to plot as tikz-picture, type
bool
. - paramname: name of the file to be saved, type
str
. - paramsmoothen: whether or not to smoothen the landscapes, type
bool
. - paramsigma: smoothing factor for gaussian mixtures, type
int
. - returnmeanPersistenceLandscape: mean persistence landscape, type
np.ndarray
.
hausd_interval(data:numpy.ndarray,confidenceLevel:float=0.95,subsampleSize:int=-1,subsampleNumber:int=1000,pairwiseDist:bool=False,leafSize:int=2,ncores:int=2)->float
Computation of Hausdorff distance based confidence values.
Measures the confidence between two persistent features, wether they are drawn froma distribution fitting the underlying manifold of the data. This function is based onthe Hausdorff distance between the points.
- paramdata: a data set, type
np.ndarray
. - paramconfidenceLevel: confidence level, default
0.95
, typefloat
. - paramsubsampleSize: size of each subsample, type
int
. - paramsubsampleNumber: number of subsamples, type
int
. - parampairwiseDist: if
true
, a symmetricnxn
-matrix is generated out of the data, typebool
. - paramleafSize: leaf size for KDTree, type
int
. - paramncores: number of cores for parallel computing, type
int
. - returnconfidence: the confidence to be a persistent homology class, type
float
.
truncated_simplex_tree(simplexTree:numpy.ndarray,int_trunc:int=100)->tuple
This function return a truncated simplex tree.
A sparse representation of the persistence diagram in the form of a truncatedpersistence tree. Speeds up computation on large scale data sets.
- paramsimplexTree: simplex tree, type
np.ndarray
. - paramint_trunc: number of persistent interval kept per dimension, default is
100
, typeint
. - returnsimplexTreeTruncatedPersistence: truncated simplex tree, type
np.ndarray
.
About
Estimation of Neural Network Dimension using Algebraic Topology and Lie Theory.