Skip to main content

Django extension which adds model fields to store multi-dimensional Gaussian random variables.

Project description

Documentation Status Code Coverage Code style: black

django-gvar

Description

django-gvar is a Python module which allows to store multi-dimensional Gaussian random variables implemented by G. Peter Lepage's gvar module into Django's ORM Framework. It adds a GVarField, which can be used to store individual GVars, arrays of GVars, and Dictionaries of GVars.

Usage in scripts

After pip-installing the module, import the GVarField field into your project and use it out-of-the-box (changing settings is not required)

# myproject.models.py
from django.db import models
from django_gvar import GVarField

class ExampleTable(models.Model):
    a = GVarField()

After migrating new table definitions, the GVarField can be used as any other field in external scripts

from gvar import gvar
from myproject.models import ExampleTable

a = gvar([1, 2, 3], [4, 5, 6])
entry = ExampleTable(a=a)
entry.save()

Usage in forms

For web-forms, the default widget for GVarFields are text areas. Currently, the form supports single numbers and arrays as input. These forms utilize custom syntax to convert the input to GVars:

  • GVars without correlations are can specified by lists of numbers where parenthesis define standard deviations
1(2), 3(4), ...
  • GVars with correlations are specified as arrays of mean values and the covariance matrix separated by a |
[1, 2] | [[1, 2], [2, 3]]

Install

django-gvar can be installed from the repository root using pip

pip install [-e] [--user] .

Because it utilizes Django's JSONField, which is available for all database backends in Django version 3.1 (previously it was a Postgres only field), it currently depends on the development version of Django (Django==3.1a1). Once established, the dependencies will be updated accordingly.

Details

The underlying database type for django-gvars are JSONFields. It uses gvars gdumps and gloads to generate corresponding JSON. The project documentation specifies more details.

Examples

The tests directory implements a simple Django app using the GVarFields. To start it, install the repo as specified above and run

cd tests
python manage.py migrate # init that test database / only needs to be run once
python manage.py runserver # start a local server

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

django_gvar-0.1.0a0.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

django_gvar-0.1.0a0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file django_gvar-0.1.0a0.tar.gz.

File metadata

  • Download URL: django_gvar-0.1.0a0.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.2

File hashes

Hashes for django_gvar-0.1.0a0.tar.gz
Algorithm Hash digest
SHA256 64195d5504e3ec3c3e392f8c3cd2a03c731235c1490224e1fb8776575fc5fe83
MD5 02f19877237ecc28b412b2c321f60241
BLAKE2b-256 4f33a6a92a18dbe9f3b14999b19d09fa6be1307675c5d8a651c7989271ed3b67

See more details on using hashes here.

File details

Details for the file django_gvar-0.1.0a0-py3-none-any.whl.

File metadata

  • Download URL: django_gvar-0.1.0a0-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.2

File hashes

Hashes for django_gvar-0.1.0a0-py3-none-any.whl
Algorithm Hash digest
SHA256 9e9fcab43d274520ac2047777d92ec3e95228662eab17306c760752bea4b4ccc
MD5 a624f592ceb479c648f4efdad89e7250
BLAKE2b-256 ec5e0fb00fc81ebb67f926f5a91ec242c2088b3fc42d0b17c0dff2329c89e710

See more details on using hashes here.

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