domainlab.compos.vae package

Subpackages

Submodules

domainlab.compos.vae.a_model_builder module

Integrate Chain-of-Responsibility and Builder Patter to construct VAE encoder and decoder

class domainlab.compos.vae.a_model_builder.AbstractModelBuilderChainNode(success_node=None)[source]

Bases: AbstractChainNodeHandler

to ensure chain of responsibility node AbstractChainNodeHandler always work even some node can not start their heavy weight business object, avoid override the initializer so that node construction is always light weight.

The config() method here is abstract, while child class has a concrete config method

abstract config(*kargs, **kwargs)[source]

use either list or dictionary input arguments to configure the model builder.

domainlab.compos.vae.a_vae_builder module

Integrate Chain-of-Responsibility and Builder Patter to construct VAE encoder and decoder

class domainlab.compos.vae.a_vae_builder.AbstractVAEBuilderChainNode(successor_node)[source]

Bases: AbstractChainNodeHandler

to ensure chain of responsibility node AbstractChainNodeHandler always work even some node can not start their heavy weight business object, avoid override the initializer so that node construction is always light weight.

abstract build_decoder()[source]
abstract build_encoder()[source]
init_business(zd_dim, zx_dim, zy_dim)[source]

initialize and return the heavy weight business object for doing the real job :param request: subclass can override request object to be string or function :return: the constructed service object

domainlab.compos.vae.c_vae_adaptor_model_recon module

This adaptor couples intensively with the heavy-weight model class The model class can be refactored, we do want to use the trained old-version model, which we only need to change this adaptor class.

class domainlab.compos.vae.c_vae_adaptor_model_recon.AdaptorReconVAEXYD(model)[source]

Bases: object

This adaptor couples intensively with the heavy-weight model class The model class can be refactored, we do want to use the trained old-version model, which we only need to change this adaptor class.

cal_latent(x)[source]

This method won’t be redundant as it will be used several times, and most importantly, it couples with the models encoder attribute, so we only need to change this one time. Suppose if model class changes, to use old trained models(we can not retrain them), we only need to change this method. :param x:

cal_prior_zd(vec_d)[source]
cal_prior_zy(vec_y)[source]
recon_ydx(zy, zd, zx, x)[source]
  1. The order of concatnation plays a vital role!

2. This method won’t be redundant as it will be used several times, and most importantly, it couples with the models encoder attribute, so we only need to change this one time. Suppose if model class changes, to use old trained models(we can not retrain them), we only need to change this method.

domainlab.compos.vae.c_vae_builder_classif module

Builder 1. classifier for domain and class 2. p(z_y|y) and p(z_d|d)

class domainlab.compos.vae.c_vae_builder_classif.ChainNodeVAEBuilderClassifCondPrior(successor_node)[source]

Bases: AbstractVAEBuilderChainNode

  1. This class defines common methods shared by child classes:
    • classifier for domain/class

    • conditional prior

  2. Bridge pattern: separate abstraction (vae model) and implementation)

build_decoder()[source]
build_encoder()[source]
construct_classifier(input_dim, output_dim)[source]

classifier can be used to both classify class-label and domain-label @param input_dim: can be both zy_dim or zd_dim

construct_cond_prior(input_dim, output_dim)[source]

For both p(z_y|y) and p(z_d|d)

is_myjob(request)[source]

is_myjob. :param request: subclass can override request object to be string or function :return True/False

domainlab.compos.vae.c_vae_recon module

Adaptor is vital for data generation so this class can be decoupled from model class. The model class can be refactored, we do want to use the trained old-version model, which we only need to change adaptor class.

class domainlab.compos.vae.c_vae_recon.ReconVAEXYD(model, na_adaptor=<class 'domainlab.compos.vae.c_vae_adaptor_model_recon.AdaptorReconVAEXYD'>)[source]

Bases: object

Adaptor is vital for data generation so this class can be decoupled from model class. The model class can be refactored, we do want to use the trained old-version model, which we only need to change adaptor class.

recon(x, vec_y=None, vec_d=None, sample_p_zy=False, sample_p_zd=False, scalar_zx2fill=None)[source]

common function

recon_cf(x, na_cf, dim_cf, device, vec_y=None, vec_d=None, zx2fill=None, sample_p_zy=False, sample_p_zd=False)[source]
Countefactual reconstruction:
param na_cf:

name of counterfactual, ‘y’ or ‘d’

param dim_cf:

dimension of counterfactual factor

domainlab.compos.vae.utils_request_chain_builder module

class domainlab.compos.vae.utils_request_chain_builder.VAEChainNodeGetter(request, topic_dim=None)[source]

Bases: object

  1. Hardcoded chain, each node use Scenario as request class

  2. Constructor takes parameters for VABuilder Subclasses

  3. heavy weight business objective is returned by selected node

  4. convert Scenario object to request object, so that class can be reused

domainlab.compos.vae.zoo_vae_builders_classif module

Chain node VAE builders

class domainlab.compos.vae.zoo_vae_builders_classif.ChainNodeVAEBuilderClassifCondPriorBase(successor_node)[source]

Bases: ChainNodeVAEBuilderClassifCondPrior

base class of AE builder

build_decoder()[source]

build_decoder.

build_encoder()[source]

build_encoder.

config_img(flag, request)[source]

config_img.

Parameters:
  • flag

  • request

is_myjob(request)[source]

is_myjob.

Parameters:

request

class domainlab.compos.vae.zoo_vae_builders_classif.NodeVAEBuilderArg(successor_node)[source]

Bases: ChainNodeVAEBuilderClassifCondPriorBase

Build encoder decoder according to commandline arguments

build_encoder()[source]

build_encoder.

is_myjob(request)[source]

is_myjob. :param request:

class domainlab.compos.vae.zoo_vae_builders_classif.NodeVAEBuilderImgAlex(successor_node)[source]

Bases: NodeVAEBuilderImgConvBnPool

build_encoder()[source]

build_encoder.

is_myjob(request)[source]

is_myjob.

Parameters:

request

class domainlab.compos.vae.zoo_vae_builders_classif.NodeVAEBuilderImgConvBnPool(successor_node)[source]

Bases: ChainNodeVAEBuilderClassifCondPriorBase

build_encoder()[source]

build_encoder.

is_myjob(request)[source]

is_myjob.

Parameters:

request

class domainlab.compos.vae.zoo_vae_builders_classif.NodeVAEBuilderUser(successor_node)[source]

Bases: ChainNodeVAEBuilderClassifCondPriorBase

Build encoders according to test_mk_exp file

build_encoder()[source]

build_encoder.

is_myjob(request)[source]

is_myjob.

Parameters:

request

domainlab.compos.vae.zoo_vae_builders_classif_topic module

Chain node VAE builders

class domainlab.compos.vae.zoo_vae_builders_classif_topic.NodeVAEBuilderImgTopic(successor_node)[source]

Bases: NodeVAEBuilderArg

NodeVAEBuilderImgTopic.

build_decoder(topic_dim)[source]

build_decoder.

Parameters:

topic_dim

build_encoder(device, topic_dim)[source]

build_encoder.

Parameters:
  • device

  • topic_dim

is_myjob(request)[source]

is_myjob.

Parameters:

request

Module contents