Skip to content

Commit

Permalink
Merge pull request #25 from LCAV/angles_icassp
Browse files Browse the repository at this point in the history
Fix angle functionalities
  • Loading branch information
duembgen committed Nov 8, 2019
2 parents 8f63d6c + ab0e260 commit 40ee200
Show file tree
Hide file tree
Showing 17 changed files with 109 additions and 510 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ python:

install:
- pip install -r requirements.txt
- pip install -r optional_requirements.txt

script:
- pytest
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## Unreleased

## [0.0.5] - 2019-11-08
### Changed

- Remove unused angle algorithms, keeping only basic angle operations. The angle-based algorithms are a niche application and are now in a different respository.

- Make cvxpy a compulsory dependence.


## [0.0.4] - 2019-09-12
### Changed

Expand Down
19 changes: 13 additions & 6 deletions CONTRIBUTE.rst → CONTRIBUTE.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
How to contribute
=================
# How to contribute

Release new version
-------------------
## Release new version

1. Change the version number in

- pylocus/__init__.py
- setup.py
- docs/source/conf.py

2. Add a new section to CHANGELOG.md

3. Run the following commands

```bash
python3 setup.py sdist bdist_wheel
python3 -m twine upload --repository-url https://test.pypi.org/legacy/ dist/*
python3 -m pip install --index-url https://test.pypi.org/simple/ --no-deps example-pkg-your-username
python3 -c "import pylocus.lateration" # test that it worked.
```

4. If all looks ok, then run

python3 -m twine upload dist/*
```
python3 -m twine upload dist/*
```

(If above does not work, make sure that the information in ~/.pypirc is up to date)

5. Do not forget to create a new release on github as well.

5. If above does not work, make sure that the information in ~/.pypirc is up to date.
51 changes: 16 additions & 35 deletions README.rst → README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
Welcome to pylocus
==================

.. image:: https://travis-ci.org/LCAV/pylocus.svg?branch=master
:target: https://travis-ci.org/LCAV/pylocus

Python Localization Package
---------------------------

# Welcome to pylocus, a python localization package
[![Build Status](https://travis-ci.org/LCAV/pylocus.svg?branch=master)](https://travis-ci.org/LCAV/pylocus)

This package contains Multidimensional Scaling, lateration, and other algorithms useful for localization using distances and/or angles.

Local install
*************
## Local install

Since this package is in an early development phase, this is the recommended install method.
The latest updates will not always be immediately available on pip, they will be bundled
Expand All @@ -20,42 +12,31 @@ regularly, you can be sure to be using the latest version.

To perform a local install on your computer, run from this folder level (where setup.py is located):

.. code-block:: bash
```bash

pip install -e .
pip install -e .

```

This installs the package using symbolic links, avoiding the need for a reinstall whenever the source code is changed.
If you use conda, then

.. code-block:: bash
conda develop .
```bash
conda develop .
```

does the same trick.

Install
*******

To install from pip, simply run :
## Install

.. code-block:: bash
To install from [pip](https://pypi.python.org/pypi/pylocus), simply run :

```bash
pip install pylocus
```

PyPi link : https://pypi.python.org/pypi/pylocus
## Documentation

Requirements
************

Depending on which parts of the project you are using, you might need to install more heavy requirements such as cvxpy and cxopt. These are not included in the default install and can be installed by running the following line.

.. code-block:: bash
pip install -r optional_requirements.txt
Documentation
*************
This is a constantly growing package and documentation is work-in-progress. The current version can be found on [ReadTheDocs](http://pylocus.readthedocs.org/en/latest/)

See the tutorials folder for some exmaple scripts on how to use this package. More scripts will be added soon.

This is a constantly growing package and documentation is work-in-progress. The current version can be found on ReadTheDocs: http://pylocus.readthedocs.org/en/latest/
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
# The short X.Y version.
version = u'0.0'
# The full version, including alpha/beta/rc tags.
release = u'0.0.4'
release = u'0.0.5'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 0 additions & 2 deletions optional_requirements.txt

This file was deleted.

2 changes: 1 addition & 1 deletion pylocus/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
### This file exists only to tell python that this folder is a package.
__version__ = "0.0.5"
3 changes: 3 additions & 0 deletions pylocus/algorithms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/usr/bin/env python
# module ALGORITHMS

from math import pi

import numpy as np

IMPLEMENTED_METHODS = ['MDS',
Expand Down
6 changes: 1 addition & 5 deletions pylocus/basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def eigendecomp(G, d):
factor = np.empty((N,), dtype=lamda.dtype)
np.sqrt(lamda_sorted[:d], out=factor[0:d])
factor[d:] = 0.0
return factor, np.real(u)
return np.real(factor), np.real(u)


def assert_print(this_should_be_less_than, this=1e-10):
Expand Down Expand Up @@ -178,7 +178,3 @@ def matrix_from_vector(vector, N):
matrix = np.zeros((N, N), dtype=vector.dtype)
matrix[triu_idx[0], triu_idx[1]] = vector
return matrix


if __name__ == "__main__":
print('nothing happens when running this module.')
8 changes: 8 additions & 0 deletions pylocus/basics_angles.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,11 @@ def get_theta_tensor(theta, corners, N):
theta_tensor[int(idx[0]), int(idx[1]), int(idx[2])] = theta[k]
theta_tensor[int(idx[0]), int(idx[2]), int(idx[1])] = theta[k]
return theta_tensor


def get_index(corners, Pk, Pij):
''' get index mask corresponding to angle at corner Pk with Pi, Pj.'''
angle1 = [Pk, Pij[0], Pij[1]]
angle2 = [Pk, Pij[1], Pij[0]]
index = np.bitwise_or(corners == angle1, corners == angle2)
return index.all(axis=1)
23 changes: 10 additions & 13 deletions pylocus/edm_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
# module EDM_COMPLETION
import numpy as np

try:
from cvxpy import *
except:
print("WARNING from pylocs.edm_completion module: Failed to load cvxpy. This might lead to errors later on.")
import cvxpy as cp

from pylocus.basics import get_edm

Expand Down Expand Up @@ -94,7 +91,7 @@ def kappa(gram):

def kappa_cvx(gram, n):
e = np.ones((n, 1))
return reshape(diag(gram), (n, 1)) * e.T + e * reshape(diag(gram), (1, n)) - 2 * gram
return cp.reshape(cp.diag(gram), (n, 1)) * e.T + e * cp.reshape(cp.diag(gram), (1, n)) - 2 * gram

method = kwargs.pop('method', 'maximize')
options = {'solver': 'CVXOPT'}
Expand All @@ -109,19 +106,19 @@ def kappa_cvx(gram, n):
V = np.c_[-np.ones((n - 1, 1)) / np.sqrt(n), np.eye(n - 1) -
np.ones((n - 1, n - 1)) / (n + np.sqrt(n))].T

H = Variable((n - 1, n - 1), PSD=True)
H = cp.Variable((n - 1, n - 1), PSD=True)
G = V * H * V.T # * is overloaded
edm_optimize = kappa_cvx(G, n)

if method == 'maximize':
obj = Maximize(trace(H) - lamda *
norm(multiply(W, (edm_optimize - edm_missing)), p=1))
obj = cp.Maximize(cp.trace(H) - lamda *
cp.norm(cp.multiply(W, (edm_optimize - edm_missing)), p=1))
# TODO: add a reference to paper where "minimize" is used instead of maximize.
elif method == 'minimize':
obj = Minimize(trace(H) + lamda *
norm(multiply(W, (edm_optimize - edm_missing)), p=1))
obj = cp.Minimize(cp.trace(H) + lamda *
norm(cp.multiply(W, (edm_optimize - edm_missing)), p=1))

prob = Problem(obj)
prob = cp.Problem(obj)

total = prob.solve(**options)
if print_out:
Expand All @@ -138,9 +135,9 @@ def kappa_cvx(gram, n):

if (print_out):
if H.value is not None:
print('trace of H:', np.trace(H.value))
print('cp.trace of H:', cp.trace(H.value))
print('other cost:', lamda *
norm(multiply(W, (edm_complete - edm_missing)), p=1).value)
norm(cp.multiply(W, (edm_complete - edm_missing)), p=1).value)

return np.array(edm_complete)

Expand Down
16 changes: 6 additions & 10 deletions pylocus/lateration.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
import numpy as np
from scipy.linalg import eigvals, eigvalsh

try:
from cvxpy import *
except:
print("WARNING from pylocs.lateration module: Failed to load cvxpy. This might lead to errors later on.")

import cvxpy as cp

from pylocus.basics import assert_print, assert_all_print

Expand Down Expand Up @@ -302,8 +298,8 @@ def RLS_SDR(anchors, W, r, print_out=False):
m = anchors.shape[0]
d = anchors.shape[1]

G = Variable(m + 1, m + 1)
X = Variable(d + 1, d + 1)
G = cp.Variable(m + 1, m + 1)
X = cp.Variable(d + 1, d + 1)
constraints = [G[m, m] == 1.0,
X[d, d] == 1.0,
G >> 0, X >> 0,
Expand All @@ -313,10 +309,10 @@ def RLS_SDR(anchors, W, r, print_out=False):
Ci[:-1, -1] = -anchors[i]
Ci[-1, :-1] = -anchors[i].T
Ci[-1, -1] = np.linalg.norm(anchors[i])**2
constraints.append(G[i, i] == trace(Ci * X))
constraints.append(G[i, i] == cp.trace(Ci * X))

obj = Minimize(trace(G) - 2 * sum_entries(mul_elemwise(r, G[m, :-1].T)))
prob = Problem(obj, constraints)
obj = cp.Minimize(cp.trace(G) - 2 * cp.sum_entries(cp.mul_elemwise(r, G[m, :-1].T)))
prob = cp.Problem(obj, constraints)

## Solution
total = prob.solve(verbose=True)
Expand Down
12 changes: 5 additions & 7 deletions pylocus/mds.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#!/usr/bin/env python
# module MDS
import numpy as np
try:
from cvxpy import *
except:
print("WARNING from pylocs.mds module: Failed to load cvxpy. This might lead to errors later on.")

import cvxpy as cp

from pylocus.basics import eigendecomp

Expand Down Expand Up @@ -122,12 +120,12 @@ def relaxedEMDS(X0, N, d, C, b, KE, print_out=False, lamda=10):
""" Find the set of points from an edge kernel with geometric constraints, using convex rank relaxation.
"""
E = C.shape[1]
X = Variable((E, E), PSD=True)
X = cp.Variable((E, E), PSD=True)

constraints = [C[i, :] * X == b[i] for i in range(C.shape[0])]

obj = Minimize(trace(X) + lamda * norm(KE - X))
prob = Problem(obj, constraints)
obj = cp.Minimize(cp.trace(X) + lamda * cp.norm(KE - X))
prob = cp.Problem(obj, constraints)

try:
# CVXOPT is more accurate than SCS, even though slower.
Expand Down
7 changes: 2 additions & 5 deletions pylocus/plots_cti.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,9 @@ def plot_tag_position(point_sets, title='', size=[10, 10], filename='', names=No

legend = []
for p, points in enumerate(point_sets):
try:
N = points.shape[0]
except:
N = len(points)
if N == 0:
if len(points) == 0:
break
N = points.shape[0]
if p == 0:
for i in range(N):
pi = points[i]
Expand Down
Loading

0 comments on commit 40ee200

Please sign in to comment.