Skip to content

Instantly share code, notes, and snippets.

@rustedgrail
Created September 11, 2017 01:29
Show Gist options
  • Save rustedgrail/9daf41f9f30f4713119866003f0fa626 to your computer and use it in GitHub Desktop.
Save rustedgrail/9daf41f9f30f4713119866003f0fa626 to your computer and use it in GitHub Desktop.
import tensorflow as tf
def gol_loss(world_next_probabilities, world_next_target):
"""Calculates loss between 2D Game of Life predictions and targets.
For a reference on Game of Life, see
[Wikipedia page](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life).
The implementation assumes:
* 2D square world of fixed size.
* Edge cells are always dead.
Args:
world_next_probabilities: A rank-2 `Tensor` representing probabilities
that each cell lives.
targets: A rank-2 `Tensor` representing the targets, that is, whether the
cell actually lives or not.
Returns:
A `float`, the loss value.
"""
with tf.name_scope("gol_loss"):
return tf.contrib.losses.log_loss(world_next_probabilities, world_next_target)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment