Package: cdx-tf
cdx_tf (do not use this yet)Basic utilities for TensorFlow, following the Deep Hedging usage pattern.This library is not ready for public use yetThe main component is a new keras model base class,Gym, whose implementation pattern eases:Automated caching during training, including state of the optimizer.
The motivation for introducing this class is that the standard tf/keras caching schemes such astf.keras.callbacks.ModelCheckpointortf.keras.callbacks.BackupAndRestoredo not work well with custom models. Neither doesmodel_save.Standardized ML pattern
Fully driven bycdxbasics.Configconfigurations with self-documenting configuration handling. Self-declarativelayers.Agentandlayers.RecurrentAgent.Monitoring training progress
Seggregation of tracking training progress from visualizing it.As a result, the pattern allows multi-processing withray.InstallationInstall byconda install cdx_tf -c hansbuehlerorpip install cdx_tfBasic usage patternThe main presumption of the pattern is that there are two kinds of "models" involved in training the desired agents.The agents themselvesSuch agents are networks which map input features to actions. Such agents will usually be implemented usingmodels.DenseAgentormodels.RecurrentAgentwhich provides a default implementation pattern for recurrent agents which make self-declarative use of features, and which can have standard configuration patterns for users.Themodelsmodule also contains simpler models, encapsulated indense_modelwhich transparently covers, well, dense simple models and variables in the case where the model has no input features.ThegymThis is the model which executes the main business logic around the agents. In case of Deep Hedging, this is the core Monte Carlo loop for hedging derivatives. Gyms are derived fromgym.Gym, and trained withgym.train.Training: during training we will typically collect data about the progress of training such as the history of losses,  current agent performance etc. This is implemented by deriving fromgym.ProgressData. The main idea ofProgressDatais that it abstracts data collection from the actual visualization of the data. This seggregation allows to sendProgressDataduring training through an asynchronous queue - this way training can be parallelized including across machines. We show an example usingray.The core training loopgym.trainby default caches progress of training, which means that it can be interrupted and picked up again at any time.trainalso handles training and validation sets more robustly than tensorflow does if the sample weights are not uniform.The default implementation provides a simple text summaries, but graphical updates as used in Deep Hedging can be implemented usingcdxbasics.dynaplot.Serialization: the integrated caching methdology means that a model can easily be restored from a saved file.Restoration in this package is different than native TensorFlow model serialization: our serialization will essentially restore all weights of a model reconstructed using Python code correctly - including in the compiled optimizer. The common TensorFlow serialization attempts to serialze the traced ("complied") model.The latter results a faster compiled model, while out method ensures that you have a valid Python object you can work with. It is also our preferred choice during active model development, as it is more robust vs code changes.