MedGANGenerator<T>
Models & Types · AiDotNet.NeuralNetworks.SyntheticData
medGAN — generates synthetic patient records by pairing a pre-trained autoencoder with a generative adversarial network whose generator produces points in the autoencoder’s latent space.
Inheritance: NeuralNetworkBase<T> → NeuralSyntheticTabularGeneratorBase<T> → MedGANGenerator<T>
Implements: ISyntheticTabularGenerator<T>
For Beginners
Real patient records cannot be shared, but fake ones with the same statistical shape can. Learning to invent them directly is hard because a record is a list of yes/no answers, and the usual machinery needs smooth numbers. So this does it in two stages. First it learns to squash a real record down to a short list of numbers and rebuild it — that is the autoencoder. Then it learns to invent new short lists that rebuild into records a critic cannot distinguish from real ones. The critic gets one extra hint: alongside each record it sees the average of the whole batch, which makes it obvious if the inventor keeps producing the same record over and over.
How It Works
Choi et al., “Generating Multi-label Discrete Patient Records using Generative Adversarial Networks” (arXiv:1703.06490). GANs are built for continuous data, but patient records are high-dimensional and discrete — binary diagnosis codes or integer counts. medGAN’s answer is to never make the generator emit a record at all. Instead an autoencoder is pre-trained on the real records, and the generator learns only to produce a plausible point in that autoencoder’s continuous latent space; the pre-trained decoder turns that point into a record:
The composition is x~ = Dec(G(z)): “the pre-trained decoder Dec can pick up the right
signals from G(z) to convert it to the patient record Dec(G(z))”. The decoder is not frozen after
pre-training — it is updated jointly with the generator by the adversarial objective, so the
parameter set of the generator step is theta_(g,dec).
The three efficiency devices. The paper names three, and all three are implemented here rather than described:
The discriminator deliberately has NEITHER batch normalization NOR shortcut connections.
The two-stage objective. Pre-training minimizes reconstruction error over the real records — cross entropy for binary variables, squared error for counts. The GAN then optimizes
with k = 2 discriminator updates per generator update. The second line is the non-saturating
generator objective, and the presence of theta_dec in it is the detail that makes the
decoder adapt to the generator rather than the other way round.
Beyond the paper, and off by default so that the default configuration is exactly
medGAN’s: EnablePrivacy trains the discriminator under DP-SGD
(Abadi et al. 2016) for a formal privacy bound where the paper offers only an empirical
observation, and ConstraintWeight penalizes generated values
outside the range observed in training.
Constructors
| Constructor | Summary |
|---|---|
MedGANGenerator() |
Initializes a new instance with default architecture settings. |
MedGANGenerator(NeuralNetworkArchitecture<T> architecture, MedGANOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) |
Initializes a new medGAN generator with the specified architecture. |
Properties
| Property | Summary |
|---|---|
IReadOnlyList<ColumnMetadata> Columns { get; } |
|
MedGANOptions<T> Options { get; } |
Gets the medGAN-specific options. |
bool IsFitted { get; set; } |
|
int DiscriminatorInputWidth { get; } |
Gets the width the discriminator actually consumes: twice the record width when minibatch averaging is on, because each sample arrives concatenated with the batch average. |
int NoiseDimension { get; } |
Gets the dimension r of the random prior z, which equals the embedding dimension unless NoiseDimension overrides it. |
Methods
| Method | Summary |
|---|---|
Dictionary<string, T> GetFeatureImportance() |
|
Dictionary<string, Tensor<T>> GetNamedLayerActivations(Tensor<T> input) |
|
Matrix<T> Generate(int numSamples, Vector<T> conditionColumn, Vector<T> conditionValue) |
|
ModelMetadata<T> GetModelMetadata() |
|
Task FitAsync(Matrix<T> data, IReadOnlyList<ColumnMetadata> columns, int? epochs, CancellationToken cancellationToken) |
|
Tensor<T> ForwardForTraining(Tensor<T> input) |
Training forward — the same autoencoder reconstruction as PredictCore, overridden so the tape-based Train path trains encoder + decoder rather than walking the full Layers list (which also holds the generator and discriminator, and woul… |
void Fit(Matrix<T> data, IReadOnlyList<ColumnMetadata> columns, int? epochs) |