Skip to content

Instantly share code, notes, and snippets.

View deeperunderstanding's full-sized avatar
Tinkering

A Deeper Understanding deeperunderstanding

Tinkering
View GitHub Profile
@deeperunderstanding
deeperunderstanding / docker-compose.yml
Last active June 18, 2019 18:26
The final docker-compose file
version: '3'
services:
notebook:
build:
context: ./jupyter-notebook-docker
ports:
- "8888:8888"
depends_on:
- mlflow
environment:
@deeperunderstanding
deeperunderstanding / Dockerfile
Last active June 19, 2019 12:55
Jupyter Notebook Dockerfile
FROM jupyter/scipy-notebook
RUN conda install --quiet --yes \
'mlflow=1.0.0' \
'psycopg2'
batches = 10000
batch_size=64
losses_disc = []
losses_disc_cat = []
losses_ae = []
losses_val = []
real = np.ones((batch_size, 1))
fake = np.zeros((batch_size, 1))
window_size = train_x.shape[1]
input_dim = train_x.shape[2]
latent_dim = 32
cat_dim = 8
prior_discriminator = create_discriminator(latent_dim)
prior_discriminator.compile(loss='binary_crossentropy',
optimizer=Nadam(0.0002, 0.5),
metrics=['accuracy'])
def create_discriminator(latent_dim):
input_layer = Input(shape=(latent_dim,))
disc = Dense(128)(input_layer)
disc = ELU()(disc)
disc = Dense(64)(disc)
disc = ELU()(disc)
disc = Dense(1, activation="sigmoid")(disc)
model = Model(input_layer, disc)
return model
fun <T, R> Try.Companion.traverse(list: List<T>, transform: (T) -> Try<R>): Try<List<R>> = Try {
val newList = mutableListOf<R>()
for (value in list) {
when(val result = transform(value)) {
is Success -> newList.add(result.value)
is Failure -> throw result.error
}
}
newList
}
fun main() {
val lines = Try {
File("./my-pets.csv").readLines().map { it.split(',') }
}
val pets : Try<List<Pet>> = lines.flatMap { Try.traverse(it, ::toPet) }
when (pets) {
is Success -> println(pets.value)
fun toPet(values: List<String>) = Try.sequential {
val name = values[0]
val (age) = Try { values[1].trim().toInt() }
val (type) = PetType.lookup(values[2].trim())
Pet(name, age, type)
}
object TrySequence {
operator fun <T> Try<T>.component1(): T = when (this) {
is Success -> this.value
is Failure -> throw this.error
}
}
fun <T> Try.Companion.sequential(func: TrySequence.() -> T): Try<T> {
return Try { func(TrySequence) }
}
sealed class Try<T> {
companion object {
operator fun <T> invoke(func: () -> T): Try<T> =
try {
Success(func())
} catch (error: Exception) {
Failure(error)
}
}