Basic Python tools
Project description
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 yet
The 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 as
tf.keras.callbacks.ModelCheckpoint
ortf.keras.callbacks.BackupAndRestore
do not work well with custom models. Neither doesmodel_save
. -
Standardized ML pattern Fully driven by
cdxbasics.Config
configurations with self-documenting configuration handling. Self-declarativelayers.Agent
andlayers.RecurrentAgent
. -
Monitoring training progress Seggregation of tracking training progress from visualizing it.
As a result, the pattern allows multi-processing withray
.
Installation
Install by
conda install cdx_tf -c hansbuehler
or
pip install cdx_tf
Basic usage pattern
The main presumption of the pattern is that there are two kinds of "models" involved in training the desired agents.
-
The agents themselves
Such agents are networks which map input features to actions. Such agents will usually be implemented using
models.DenseAgent
ormodels.RecurrentAgent
which provides a default implementation pattern for recurrent agents which make self-declarative use of features, and which can have standard configuration patterns for users.The
models
module also contains simpler models, encapsulated indense_model
which transparently covers, well, dense simple models and variables in the case where the model has no input features. -
The
gym
This 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 from
gym.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 from
gym.ProgressData
. The main idea ofProgressData
is that it abstracts data collection from the actual visualization of the data. This seggregation allows to sendProgressData
during training through an asynchronous queue - this way training can be parallelized including across machines. We show an example usingray
.The core training loop
gym.train
by default caches progress of training, which means that it can be interrupted and picked up again at any time.train
also 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 using
cdxbasics.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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file cdx_tf-0.1.4.tar.gz
.
File metadata
- Download URL: cdx_tf-0.1.4.tar.gz
- Upload date:
- Size: 40.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/6.0.0 pkginfo/1.9.6 requests/2.29.0 requests-toolbelt/0.9.1 tqdm/4.65.0 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 749f47edf9a1607be50661bc5205684a663e959a535501dbf4173c34afce9bb4 |
|
MD5 | 6ecaabcdb07a85ad053231310a384dd5 |
|
BLAKE2b-256 | 2916f865116e657b80999b98ad67abf5edc2a35f48747e8af54191cac9dd7b7f |
File details
Details for the file cdx_tf-0.1.4-py3-none-any.whl
.
File metadata
- Download URL: cdx_tf-0.1.4-py3-none-any.whl
- Upload date:
- Size: 43.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/6.0.0 pkginfo/1.9.6 requests/2.29.0 requests-toolbelt/0.9.1 tqdm/4.65.0 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37f9e552d6a31b93604eed8d444d733e31ae910e36d7b29dd07439b761467b35 |
|
MD5 | 39fb499646aec9893de57ded65f1d77c |
|
BLAKE2b-256 | ef7699fb0637e29cfb8a14461686e2b0d78dbe4f720c6a4de5b0a17991020c1b |