Skip to content

API Documentation: Transforms

Implemented transformations and default options.

get_flow_builder(model)

Returns the transformation class based on the specified model type.

Parameters:

Name Type Description Default
model str

The model type.

required

Returns:

Name Type Description
get_transform function

The transformation class to use.

Source code in flowevidence/transforms.py
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
def get_flow_builder(model):
    """
    Returns the transformation class based on the specified model type.

    Args:
        model (str): The model type.

    Returns:
        get_transform (function): The transformation class to use.
    """

    transform_classes = {
        'maf': get_maf_transform,
        'nvp': get_nvp_transform,
        'rqs': get_rqs_transform
    }

    return transform_classes[model]

get_tranform_kwargs(model)

Returns the default keyword arguments for the specified model type.

Parameters:

Name Type Description Default
model str

The model type.

required

Returns:

Name Type Description
kwargs dict

The default keyword arguments for the model type.

Source code in flowevidence/transforms.py
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
def get_tranform_kwargs(model: str):
    """
    Returns the default keyword arguments for the specified model type.

    Args:
        model (str): The model type.

    Returns:
        kwargs (dict): The default keyword arguments for the model type.
    """

    maf_dict = {
        'hidden_features': 128,
        'activation': nn.ReLU(),
        'use_batch_norm': True,
        'dropout_probability': 0.1,
    }

    nvp_dict = {
        'layers': None,
        'leaky': 0.0,
        'init_zeros': True,
        'hidden_multiplier': 2,
        'dropout': 0.0,
    }

    rqs_dict = {
        'num_blocks': 5,
        'num_hidden_channels': 128,
        'num_bins': 8,
        'dropout_probability': 0.1,
    }

    kwargs = {
        'maf': maf_dict,
        'nvp': nvp_dict,
        'rqs': rqs_dict
    }

    return kwargs[model]

get_flow_transforms(num_dims, num_flow_steps, model='maf', extra_kwargs={})

Returns the transformation class and its default keyword arguments based on the specified model type.

Parameters:

Name Type Description Default
num_dims int

The number of dimensions in the input.

required
num_flow_steps int

The number of flow steps in the transformation.

required
model str

The model type.

'maf'
extra_kwargs dict

Additional keyword arguments for the transformation.

{}

Returns:

Name Type Description
transform_class Transform

The transformation class to use.

default_kwargs dict

The default keyword arguments for the transformation class.

Source code in flowevidence/transforms.py
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
def get_flow_transforms(num_dims: int, 
                        num_flow_steps: int, 
                        model: str = 'maf', 
                        extra_kwargs: dict = {}):
    """
    Returns the transformation class and its default keyword arguments based on the specified model type.

    Args:
        num_dims (int): The number of dimensions in the input.
        num_flow_steps (int): The number of flow steps in the transformation.
        model (str): The model type.
        extra_kwargs (dict): Additional keyword arguments for the transformation.

    Returns:
        transform_class (Transform): The transformation class to use.
        default_kwargs (dict): The default keyword arguments for the transformation class.    
    """

    default_kwargs = get_tranform_kwargs(model).copy()
    default_kwargs.update(extra_kwargs) 

    build_flow = get_flow_builder(model)

    flows = build_flow(num_flow_steps, num_dims, **default_kwargs)

    return flows