Skip to main content

Library to help implement a complex-valued neural network (cvnn) using tensorflow as back-end

Project description

Complex-Valued Neural Networks (CVNN)

Done by @NEGU93 - J. Agustin Barrachina

Documentation Status PyPI version Anaconda cvnn version DOI

Using this library, the only difference with a Tensorflow code is that you should use cvnn.layers module instead of tf.keras.layers.

This is a library that uses Tensorflow as a back-end to do complex-valued neural networks as CVNNs are barely supported by Tensorflow and not even supported yet for pytorch (reason why I decided to use Tensorflow for this library).

Update:

  • Since v1.6 (28 July 2020), pytorch now supports complex vectors and complex gradient as BETA. But still have the same issues that Tensorflow has, so no reason to migrate yet.

Documentation

Please Read the Docs

Instalation Guide:

Using Anaconda

conda install -c negu93 cvnn

Using PIP

Vanilla Version installs all the minimum dependencies.

pip install cvnn

Plot capabilities has the posibility to plot the results obtained with the training with several plot libraries.

pip install cvnn[plotter]

Full Version installs full version with all features

pip install cvnn[full]

Short example

import numpy as np
import cvnn.layers as complex_layers
import tensorflow as tf

# Assume you already have complex data... example numpy arrays of dtype np.complex64
(train_images, train_labels), (test_images, test_labels) = get_dataset()        # to be done by each user

# Create your model
model = tf.keras.models.Sequential()
model.add(complex_layers.ComplexInput(input_shape=(32, 32, 3)))                     # Always use ComplexInput at the start
model.add(complex_layers.ComplexConv2D(32, (3, 3), activation='cart_relu'))
model.add(complex_layers.ComplexAvgPooling2D((2, 2)))
model.add(complex_layers.ComplexConv2D(64, (3, 3), activation='cart_relu'))
model.add(complex_layers.ComplexMaxPooling2D((2, 2)))
model.add(complex_layers.ComplexConv2D(64, (3, 3), activation='cart_relu'))
model.add(complex_layers.ComplexFlatten())
model.add(complex_layers.ComplexDense(64, activation='cart_relu'))
model.add(complex_layers.ComplexDense(10, activation='convert_to_real_with_abs'))   
# An activation that casts to real must be used at the last layer. 
# The loss function cannot minimize a complex number

# Compile it
model.compile(optimizer='adam', 
              loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
              metrics=['accuracy'])
model.summary()

# Train and evaluate
history = model.fit(train_images, train_labels, epochs=epochs, validation_data=(test_images, test_labels))
test_loss, test_acc = model.evaluate(test_images,  test_labels, verbose=2)

About me & Motivation

My personal website

I am a PhD student from Ecole CentraleSupelec with a scholarship from ONERA and the DGA

I am basically working with Complex-Valued Neural Networks for my PhD topic. In the need of making my coding more dynamic I build a library not to have to repeat the same code over and over for little changes and accelerate therefore my coding.

Cite Me

Code:

@MISC {NEGU93-CVNN,
    author       = {J. Agustin Barrachina},
    title        = {Complex-Valued Neural Networks (CVNN)},
    howpublished = {\url{https://github.com/NEGU93/cvnn}},
    doi          = {10.5281/zenodo.4140245},
    journal      = {GitHub repository},
    year         = {2019}
}

I recommend changing the year and adding a version item with the one you used.

Or cite the Zenodo version:

@software{j_agustin_barrachina_2020_4140245,
  author       = {J Agustin Barrachina},
  title        = {NEGU93/cvnn: First official release},
  month        = oct,
  year         = 2020,
  publisher    = {Zenodo},
  version      = {v0.3.40},
  doi          = {10.5281/zenodo.4140245},
  url          = {https://doi.org/10.5281/zenodo.4140245}
}

Paper:

@misc{barrachina2020complexvalued,
    title={Complex-Valued vs. Real-Valued Neural Networks for Classification Perspectives: An Example on Non-Circular Data},
    author={Jose Agustin Barrachina and Chenfang Ren and Christele Morisseau and Gilles Vieillard and Jean-Philippe Ovarlez},
    year={2020},
    eprint={2009.08340},
    archivePrefix={arXiv},
    primaryClass={stat.ML}
}

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cvnn-1.0.3.tar.gz (67.7 kB view details)

Uploaded Source

File details

Details for the file cvnn-1.0.3.tar.gz.

File metadata

  • Download URL: cvnn-1.0.3.tar.gz
  • Upload date:
  • Size: 67.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.5

File hashes

Hashes for cvnn-1.0.3.tar.gz
Algorithm Hash digest
SHA256 2eeb5500bb42ebf9d6183ee0b9d000c2fa33272ee1d21e4124578028d99cd24c
MD5 16295e9f58305a506fb571f4fc90d4ae
BLAKE2b-256 b6fc8151a4e4a3d6c6fedc41196a2629b3c83166b166166ddb43de64bd2d19c8

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page