# Results

## Random Image

A random image is generated from the causal VAE model. This is generated by simply calling the model. The causal factors that are inputs to the decoder are randomly sampled and the decoder generates an image.&#x20;

```python
r_img , r_attrs = vae.inference_model()
plot_model_image(r_img)
```

The attributes are the causal inputs passed to the decoder. Since the procedural generation scheme also takes in the same attributes, we can generate the original image by using the procedural generation code.

We compare the images generated by both the decoder and the procedural generation scheme.

![Randomly Sampled Image.](https://1424433991-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFBM73ocV8YCzRKuMr4%2F-MH9bO_y6XQIXGFrVNPk%2F-MH9cH9XZvW0tXmJKSCf%2FSelection_072.png?alt=media\&token=5dad9511-e6f1-41c3-9c24-e3d97749293c)

## Reconstructed Image

Reconstructing the input images is native to autoencoders. We can test the reconstruction capabilities of the causal model by feeding in the inputs and the labels.

```
recon_img = vae.reconstruct_img(test_images[0][0:10].cuda(), test_labels[0][0:10].cuda())
plt.imshow(recon_img[1].detach().cpu().permute(1,2,0)) 
```

![Reconstructed Image](https://1424433991-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFBM73ocV8YCzRKuMr4%2F-MH9bO_y6XQIXGFrVNPk%2F-MH9z_2iMMNWqE5qyN-q%2FSelection_072.png?alt=media\&token=cb1778bb-c5d0-42a5-a01d-d6ee41304128)

## Conditioned Images

### Conditioned on Latent Variables and infer Observed Variables from the Image

In this scenario, we condition on the latent variables actor's attacking strength and defense capabilities to be _**HIGH**_ and the reactor's attacking, strength, and defense capabilities to be _**LOW**_. We have made the actor more strong and the reactor more vulnerable. The rest of the entities are sampled after conditioning on this evidence/query. We intuitively expect that the actor will attack given that his capabilities are high and the reactor will get hurt from this. When we run the conditioned model, we get the following image from the decoder.

![Actor attacks and the reactor is dead.](https://1424433991-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFBM73ocV8YCzRKuMr4%2F-MHqQzleKWoLcRqEuyVU%2F-MHx6gIslgFgme_rE6sf%2Faction_reaction_died_put_it.png?alt=media\&token=4520eb81-7db9-42e9-9cc0-9aeec4781554)

{% hint style="warning" %}
The conditional distribution given the evidence is computed separately and fed into the inference model
{% endhint %}

The observed variables are sampled from the above conditional distribution. From the sampled values, the labels can be fed into the procedural generation scheme to get the actual image.&#x20;



### Conditioned on Observed Variables and infer Latent Variables from the Image

In this scenario, we condition on the observed variables like the actor character and its type and infer the strength, attacking and defensive capabilities of the actor.

```python
querygrain(grainObj, nodes=c("AD", "AA", "AS"), evidence = list(AC="satyr", RC="golem", AT="type1", RT="type3"))
```

![Conditional Probability](https://1424433991-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFBM73ocV8YCzRKuMr4%2F-MI13-DhviCFqSFGuW88%2F-MIDAgHAtjH6CvrDmiQm%2FSelection_074.png?alt=media\&token=f00295ec-d3ca-4304-a17f-36c87790389a)

The above code gets us the condition distribution of the latent nodes of the actor given the evidence of observed variables.

```python

# sample conditioning statements - sample on observed and infer latent.
cond2 = {
    "actor": torch.tensor([1,0]).cuda(),
    "reactor": torch.tensor([0,1]).cuda(),
    "actor_type": torch.tensor([1,0,0]).unsqueeze(0).cuda(),
    "reactor_type": torch.tensor([0,0,1]).unsqueeze(0).cuda()
}

conditioned_model = pyro.condition(vae.inference_model, data=cond2)
c_img, c_attrs = conditioned_model(cpts)
plot_model_image(c_img)
```

![A sample image generated by decoder given the above evidence.](https://1424433991-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFBM73ocV8YCzRKuMr4%2F-MI13-DhviCFqSFGuW88%2F-MIDBALMnGb5hWJ1uOBd%2Fcondition_observed_infer_latent.png?alt=media\&token=72d29995-fda5-466b-aafd-52524c2ccbdf)

## Intervention Images

In this example, we will see the difference between the condition and the intervention statements in terms of the probability distribution. The intervention we apply is on the actor's action and set it to attack. Now, we infer on the upstream nodes to the actor's action like the actor's attacking capability.&#x20;

```python
intervention_2_bn <- mutilated(dfit, list(AACT="Attack"))
intervention_2_grain <- as.grain(intervention_2_bn)
```

![Intervention distribution of Actor Attack](https://1424433991-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFBM73ocV8YCzRKuMr4%2F-MIDBTmyo8DthBRATg85%2F-MIHXzi-A9KKm68Kmd3b%2FSelection_079.png?alt=media\&token=65bcc837-e67c-4819-b3ee-31af48d73711)

![Conditional distribution of Actor Attack](https://1424433991-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFBM73ocV8YCzRKuMr4%2F-MIDBTmyo8DthBRATg85%2F-MIHY3SIDIhtFpDXHswb%2FSelection_080.png?alt=media\&token=97ae1f3d-74c6-4104-b795-15b1bb5799ad)

We can see that the attacking capability is different in the intervention distribution than in conditional distribution.  Like the above, we infer for all the nodes necessary and we sample from that distribution. &#x20;

![Image generated from intervention distribution.](https://1424433991-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFBM73ocV8YCzRKuMr4%2F-MIHsPgIpntdAJjHTWpD%2F-MIHySpHZcQo1ElGKxvq%2Fintervention_distribution.png?alt=media\&token=c455756a-d059-4738-b868-0cef4427e0cf)

