Skip to main content

Solving quadratic optimization problems with Keras.

Project description

PyPI version Total alerts Language grade: Python

keras-quadopt

Solving quadratic optimization problems with resource constraints and upper boundaries using TF2/Keras.

Usage

import tensorflow as tf
import keras_quadopt as kqp
import time

# goodness scores
good = tf.constant([.51, .53, .55, .57])

# similarity matrices
simi_1 = tf.constant([
    [1, .9, .8, .7],
    [.9, 1, .6, .5],
    [.8, .6, 1, .4],
    [.7, .5, .4, 1],
])

simi_2 = tf.constant([
    [1, .7, .8, .3],
    [.7, 1, .4, .2],
    [.8, .4, 1, .6],
    [.3, .2, .6, 1],
])

# preference parameters
lam = 0.4
beta_1 = 0.25
beta_2 = 0.75

# compute weights
simi = kqp.aggregate_matrices(simi_1, beta_1, simi_2, beta_2)

start = time.time()
wbest, fbest = kqp.get_weights(good, simi, lam)
print(f"elapsed: {time.time() - start}")

Appendix

Installation

The keras-quadopt git repo is available as PyPi package

pip install keras-quadopt
pip install git+ssh://git@github.com/satzbeleg/keras-quadopt.git

Install a virtual environment

python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt --no-cache-dir
pip install -r requirements-dev.txt --no-cache-dir

(If your git repo is stored in a folder with whitespaces, then don’t use the subfolder .venv. Use an absolute path without whitespaces.)

Python commands

  • Check syntax: flake8 --ignore=F401 --exclude=$(grep -v '^#' .gitignore | xargs | sed -e 's/ /,/g')

  • Run Unit Tests: PYTHONPATH=. pytest

Publish

pandoc README.md --from markdown --to rst -s -o README.rst
python setup.py sdist
twine upload -r pypi dist/*

Clean up

find . -type f -name "*.pyc" | xargs rm
find . -type d -name "__pycache__" | xargs rm -r
rm -r .pytest_cache
rm -r .venv

Support

Please open an issue for support.

Contributing

Please contribute using Github Flow. Create a branch, add commits, and open a pull request.

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

keras-quadopt-0.1.0.tar.gz (8.4 kB view details)

Uploaded Source

File details

Details for the file keras-quadopt-0.1.0.tar.gz.

File metadata

  • Download URL: keras-quadopt-0.1.0.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.8.2 requests/2.27.1 setuptools/62.0.0 requests-toolbelt/0.9.1 tqdm/4.64.0 CPython/3.7.9

File hashes

Hashes for keras-quadopt-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8e242e802619237e6d81e0f5d94e3817e860da531b274da063c5a3fcbae7b709
MD5 c988e302e072af0168bc059b6c569b13
BLAKE2b-256 fe1a00ad3262eb6137144415b404c50b8931426b751d2ab96186432d2da0f91b

See more details on using hashes here.

Supported by

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