# Gradient Flossing: Improving Gradient Descent through Dynamic Control of Jacobians
This repository contains the implementation code for manuscript:
__Gradient Flossing: Improving Gradient Descent through Dynamic Control of Jacobians__
## Overview
In this work we show that RNN training can be improved by pushing Lyapunov exponents of the forward pass to zero during or before training.
## Installation
#### Prerequisites
- Download [Julia](https://julialang.org/downloads/)
#### Dependencies
- Julia (1.6)
- Flux, BackwardsLinalg
## Getting started
To install the required packages, run the following in the julia REPL after installing Julia:
```
using Pkg
for pkg in ["Flux", "BackwardsLinalg"]
Pkg.add(pkg)
end
```
For example, to train an RNN on tracking delayed XOR task, run:
```
include("GradientFlossing_ExampleCode.jl")
# setting parameters:
N, E, Ef, Ei, Ep, Ni, B, S, T, Tp, Ti, sIC, sIn, sNet, sONS, lr, b1, b2, IC, g, gbar, I1, delay, wsS, wsM, wrS, wrM, bS, bM, nLE, task, intype, Lwnt=
80, 3001, 100, 500, 500, 2, 16, 1, 300, 55, 300, 1,1,1,1, 0.001f0, 0.9, 0.999, 1, 1.0, 0.0, 1.0,10, 1.0f0, 0.0f0, 1.0f0, 0.0f0, 0.1f0, 0.0f0,75, -1, 3, 0.0
trainRNNflossing(N, E, Ef, Ei, Ep, Ni, B, S, T, Tp, Ti, sIC, sIn, sNet, sONS, lr, b1, b2, IC, g, gbar, I1, delay, wsS, wsM, wrS, wrM, bS, bM, nLE, task, intype, Lwnt)
```
## Repository Overview
_GradientFlossing_ExampleCode.jl_:\
Example scripts for training networks with gradient flossing before training, with gradient flossing before and during training and without gradient flossing.
_GradientFlossing_XOR.jl_:\
Generates input and target output for copy task and delayed XOR task.
### Implementation details
A full specification of packages used and their versions can be found in _packages.txt_ .\
For learning rates the default ADAM parameters were used to avoid any impression of fine-tuning.\
All simulations were run on a single CPU and took on the order of minutes to a few of hours.