IMLCV.implementations.CvDiscovery#

Module Contents#

Classes#

Encoder

Base class for all neural network modules. Layers and models should subclass this class.

Decoder

Base class for all neural network modules. Layers and models should subclass this class.

VAE

Base class for all neural network modules. Layers and models should subclass this class.

TranformerAutoEncoder

TransoformerLDA

class IMLCV.implementations.CvDiscovery.Encoder[source]#

Bases: flax.linen.Module

Base class for all neural network modules. Layers and models should subclass this class.

All Flax Modules are Python 3.7 dataclasses. Since dataclasses take over __init__, you should instead override setup(), which is automatically called to initialize the module.

Modules can contain submodules, and in this way can be nested in a tree structure. Submodels can be assigned as regular attributes inside the setup() method.

You can define arbitrary “forward pass” methods on your Module subclass. While no methods are special-cased, __call__ is a popular choice because it allows you to use module instances as if they are functions:

from flax import linen as nn

class Module(nn.Module):
  features: Tuple[int, ...] = (16, 4)

  def setup(self):
    self.dense1 = Dense(self.features[0])
    self.dense2 = Dense(self.features[1])

  def __call__(self, x):
    return self.dense2(nn.relu(self.dense1(x)))

Optionally, for more concise module implementations where submodules definitions are co-located with their usage, you can use the compact() wrapper.

latents: int[source]#
layers: int[source]#
nunits: int[source]#
dim: int[source]#
__call__(x)[source]#
class IMLCV.implementations.CvDiscovery.Decoder[source]#

Bases: flax.linen.Module

Base class for all neural network modules. Layers and models should subclass this class.

All Flax Modules are Python 3.7 dataclasses. Since dataclasses take over __init__, you should instead override setup(), which is automatically called to initialize the module.

Modules can contain submodules, and in this way can be nested in a tree structure. Submodels can be assigned as regular attributes inside the setup() method.

You can define arbitrary “forward pass” methods on your Module subclass. While no methods are special-cased, __call__ is a popular choice because it allows you to use module instances as if they are functions:

from flax import linen as nn

class Module(nn.Module):
  features: Tuple[int, ...] = (16, 4)

  def setup(self):
    self.dense1 = Dense(self.features[0])
    self.dense2 = Dense(self.features[1])

  def __call__(self, x):
    return self.dense2(nn.relu(self.dense1(x)))

Optionally, for more concise module implementations where submodules definitions are co-located with their usage, you can use the compact() wrapper.

latents: int[source]#
layers: int[source]#
nunits: int[source]#
dim: int[source]#
__call__(z)[source]#
class IMLCV.implementations.CvDiscovery.VAE[source]#

Bases: flax.linen.Module

Base class for all neural network modules. Layers and models should subclass this class.

All Flax Modules are Python 3.7 dataclasses. Since dataclasses take over __init__, you should instead override setup(), which is automatically called to initialize the module.

Modules can contain submodules, and in this way can be nested in a tree structure. Submodels can be assigned as regular attributes inside the setup() method.

You can define arbitrary “forward pass” methods on your Module subclass. While no methods are special-cased, __call__ is a popular choice because it allows you to use module instances as if they are functions:

from flax import linen as nn

class Module(nn.Module):
  features: Tuple[int, ...] = (16, 4)

  def setup(self):
    self.dense1 = Dense(self.features[0])
    self.dense2 = Dense(self.features[1])

  def __call__(self, x):
    return self.dense2(nn.relu(self.dense1(x)))

Optionally, for more concise module implementations where submodules definitions are co-located with their usage, you can use the compact() wrapper.

latents: int[source]#
layers: int[source]#
nunits: int[source]#
dim: int[source]#
setup()[source]#

Initializes a Module lazily (similar to a lazy __init__).

setup is called once lazily on a module instance when a module is bound, immediately before any other methods like __call__ are invoked, or before a setup-defined attribute on self is accessed.

This can happen in three cases:

  1. Immediately when invoking apply(), init() or init_and_output().

  2. Once the module is given a name by being assigned to an attribute of another module inside the other module’s setup method (see __setattr__()):

    class MyModule(nn.Module):
      def setup(self):
        submodule = Conv(...)
    
        # Accessing `submodule` attributes does not yet work here.
    
        # The following line invokes `self.__setattr__`, which gives
        # `submodule` the name "conv1".
        self.conv1 = submodule
    
        # Accessing `submodule` attributes or methods is now safe and
        # either causes setup() to be called once.
    
  3. Once a module is constructed inside a method wrapped with compact(), immediately before another method is called or setup defined attribute is accessed.

__call__(x, z_rng)[source]#
encode(x)[source]#
classmethod reparameterize(rng, mean, logvar)[source]#
class IMLCV.implementations.CvDiscovery.TranformerAutoEncoder(outdim, periodicity=None, bounding_box=None, descriptor='sb', descriptor_kwargs={})[source]#

Bases: IMLCV.base.CVDiscovery.Transformer

_fit(cv: list[IMLCV.base.CV.CV], nl: list[NeighbourList] | None, nunits=250, nlayers=3, lr=0.0001, num_epochs=100, batch_size=32, **kwargs)[source]#
class IMLCV.implementations.CvDiscovery.TransoformerLDA(outdim, periodicity=None, bounding_box=None, descriptor='sb', descriptor_kwargs={})[source]#

Bases: IMLCV.base.CVDiscovery.Transformer

_fit(cv_list: list[IMLCV.base.CV.CV], nl_list: list[NeighbourList] | None, kernel=False, harmonic=True, sort='rematch', shrinkage=0, alpha_rematch=0.1, max_iterations=50, **kwargs)[source]#