Skip to content

Coupled Oscillatory Circuits as Neural Networks

Notifications You must be signed in to change notification settings

rdnrtms/coc_nn_torch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Coupled Oscillatory Circuits as Neural Networks

Planned features

  • Implementation of nearest neighbour coupling on a grid instead of a fully connected network
  • Separation of loss functions from the model class to a separate class
  • Docstrings for every function and class
  • Separation of the simulation from the model classes
  • Rework the simulation to use external (user-defined) train and test sets

Installation

This project needs Python 3

  • Optional: Create a virtual environment
  • Clone repo git clone https://github.com/rdnrtms/coc_nn_torch/
  • Install prerequisite packages with pip install requirements.txt

Project description

This project is intended for testng out trainable, Coupled Oscillatory Networks, where the goal is to learn the parameters of an ODE, which describes the system. The underlying dynamics for n oscillators and m inverters is as follows:

where v is the voltages at the nodes of the system (with size n*m); P is a block diagonal matrix, for which the blocks are corresponding to a mxm permutation matrix corresponding to the left cyclical rotation; C' is the modified coupling matrix describing all the couplings between the oscillators; B' is the modified "connector" matrix of the inputs; R, Rc,Ri and C are circuit parameters, the inverter-inverter, coupling and input resistances and parasitive capacitances between inverters, respectively.

There is two different mode for the code to operate in (with the appropriate classes used in the code in brackets):

  • Test mode (COCRegular): this is just a plain integration of the ODE with given inputs, initial values, matrices and parameters
  • Training mode (COCPatternRecognition*): this creates learnable parameters for the couplings (and inputs, if needed) and using back propagation, it trains the parameters to achieve some goal, given by the loss function throughout a number of epochs

*: This will be expanded later on with more options

Contents

This project contains three python files and a default input file:

  • COC.py: the main implementation with abstract (COCAbstract, COCLearnableAbstract) and concrete classes (COCRegular and COCPatternRecognition)
  • utilities.py: utility functions for writing out tensors, timing functions and also for a handy progress bar class for the integration
  • sim.py: example run of a system
  • default.in: this is a default architecture with 5 oscillators, no inputs and running on cpu

The possible parameters in the input file:

  • oscNum (integer): number of oscillators in the system
  • R (real): Resistances between inverters inside a ring-oscillator (in \Ohm)
  • C (real): Capacitances between the inverters inside a ring-oscillator (in F)
  • Rc (real): Resistances between oscillators as couplings (in \Ohm)
  • Ri (real): Resistances between input voltage generators and oscillators (in \Ohm)
  • tBegin (real): The beginning of the simulation (in s), typically 0.0
  • tEnd (real): The end of the simulation (in s)
  • tNsamples (integer): Number of datapoints to store for an integration
  • save (0 or 1): If save is 1, the results are saved, otherwise just plotted
  • saveFolder (string): unique folder will be created here with all the simulation-related files
  • method (string): integration method -> "implicit" = implicit Adams-Bashford_Moulton method (for stiff systems), default: dopri5, rk 4-5, ode45 (more on this at github.com/rtqichen/torchdiffeq)
  • inputs (list of -1s and 1s): vector <- inputs for the system, useful when we know the inputs beforehand (1s: 0 phase shift, -1s: pi phase shift)
  • C (list of reals)*: it will be converted to matrix, but it is a coupling matrix described in the building process
  • B (list of reals)*: "input selector" matrix, described in the building process
  • A (real): Amplitude of input voltage generators
  • f (real): Frequency of input voltage generators
  • gpu (0 or 1): If gpu is available it uses it for calculation

*: Only needed when it runs in Test mode, not used in Training mode

The flowchart of the simulations

GitHub Logo

About

Coupled Oscillatory Circuits as Neural Networks

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages