-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
22 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,21 +24,20 @@ python -m venv /path/to/deglib_env && . /path/to/deglib_env/bin/activate | |
**Get the Source** | ||
```shell | ||
# clone git repository | ||
# TODO: "-b feat/python_bindings" not necessary after merge | ||
git clone -b feat/python_bindings [email protected]:Visual-Computing/DynamicExplorationGraph.git | ||
cd DynamicExplorationGraph | ||
git clone [email protected]:Visual-Computing/DynamicExplorationGraph.git | ||
cd DynamicExplorationGraph/python | ||
``` | ||
|
||
**Install the Package from Source** | ||
```shell | ||
cd python | ||
pip install setuptools pybind11 build | ||
python setup.py copy_build_files # copy c++ library to ./lib/ | ||
pip install . | ||
``` | ||
This will compile the C++ code and install deglib into your virtual environment, so it may take a while. | ||
|
||
**Testing** | ||
|
||
To execute all tests. | ||
```shell | ||
pytest | ||
|
@@ -75,29 +74,32 @@ vectors and D is the number of dimensions of each feature vector. | |
### Building a Graph | ||
|
||
```python | ||
import deglib | ||
|
||
graph = deglib.builder.EvenRegularGraphBuilder.build_from_data(dataset, edges_per_vertex=32) | ||
graph = deglib.builder.build_from_data(dataset, edges_per_vertex=32, callback="progress") | ||
graph.save_graph("/path/to/graph.deg") | ||
rd_graph = deglib.graph.load_readonly_graph("/path/to/graph.deg") | ||
``` | ||
|
||
### Searching the Graph | ||
```python | ||
# query can have shape (D,) or (Q, D), where | ||
# D is the dimensionality of the dataset and | ||
# Q is the number of queries. | ||
query = np.random.random((dims,)).astype(np.float32) | ||
result = graph.search(query, eps=0.1, k=10) # get 10 nearest features to query | ||
for r in result: | ||
print(r.get_internal_index(), r.get_distance()) | ||
result, dists = graph.search(query, eps=0.1, k=10) # get 10 nearest features to query | ||
print('best dataset index:', result[0]) | ||
best_match = dataset[result[0]] | ||
``` | ||
|
||
For more examples see [tests](tests). | ||
|
||
### Referencing C++ memory | ||
Consider the following example: | ||
```python | ||
feature_vector = graph.get_feature_vector(42) | ||
del graph | ||
print(feature_vector) | ||
``` | ||
This will crash as `feature_vector` is holding a reference to memory that is owned by `graph`. This can lead to segmentation faults. | ||
This will crash as `feature_vector` is holding a reference to memory that is owned by `graph`. This can lead to undefined behaviour (most likely segmentation fault). | ||
Be careful to keep objects in memory that are referenced. If you need it use the `copy=True` option: | ||
|
||
```python | ||
|
@@ -131,11 +133,13 @@ elements from the graph, external labels and internal indices are equal. | |
# as long as no elements are removed | ||
# external labels and internal indices are equal | ||
for i, vec in enumerate(data): | ||
builder.add_entry(i, vec) | ||
builder.add_entry(i, vec) | ||
``` | ||
|
||
### Eps | ||
TODO | ||
The eps-search-parameter controls how many nodes are checked during search. | ||
Lower eps values like 0.001 are faster but less accurate. | ||
Higher eps values like 0.1 are slower but more accurate. Should always be greater 0. | ||
|
||
### Relative Neighborhood Graph / RNG-conform | ||
TODO | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters