Skip to content

Commit

Permalink
Bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
antonio-leitao committed Jun 6, 2023
1 parent fcaface commit abc0fc1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 38 deletions.
12 changes: 3 additions & 9 deletions .github/workflows/build_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,15 @@ jobs:
name: Release
runs-on: ubuntu-latest
needs: [linux, windows, macos, sdist]
env:
PYPI_USERNAME: ${{ secrets.PYPI_USERNAME }}
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
steps:
- name: Test Environment Variables
run: |
echo "PyPI Username: $PYPI_USERNAME"
echo "PyPI Password: $PYPI_PASSWORD"
- uses: actions/download-artifact@v3
with:
name: wheels
- name: Publish to PyPI
uses: PyO3/maturin-action@v1
env:
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
with:
command: upload
username: ${{secrets.PYPI_USERNAME}}
password: ${{secrets.PYPI_PASSWORD}}
token: ${{ secrets.PYPI_TOKEN }}
args: --skip-existing *
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 35 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,36 @@ Implementation of Variable Length Markov Chains (VLMC) for Python.
Suffix tree building is done top-down using the ![Peres-Shield](https://link.springer.com/chapter/10.1007/11557067_24) order estimation method.
It is written in Rust and ported to Python with PyO3.

# Instalation
You can install using `pip`.
## Installation

```shell
### Installation with pip

Pre-built packages for many Linux, Windows, and OSX systems are available
in [PyPI](https://pypi.org/project/vlmc/) and can be installed with:

```sh
pip install vlmc
```
On uncommon architectures, you may need to first
[install Cargo](https://doc.rust-lang.org/cargo/getting-started/installation.html)
(i.e., the Rust programming language) first, and a subsequent
`pip install vlmc` will try to compile the package for your CPU architecture and operating system.

### Compilation from source

You need to [install Rust/Cargo](https://doc.rust-lang.org/cargo/getting-started/installation.html).

Installation uses [maturin](https://github.com/PyO3/maturin#maturin) for compiling and installing the Rust extension.
Maturin is best used within a Python virtual environment:

```sh
# activate your desired virtual environment first, then:
pip install maturin
git clone https://github.com/antonio-leitao/vlmc.git
cd vlmc
# build and install the package:
maturin develop --release
```

# Basic Usage

Expand All @@ -17,9 +41,9 @@ import vlmc
tree = vlmc.VLMC(max_depth, alphabet_size, n_jobs=-1)
```
Parameters:
-`max_depth`: Maximum depth of tree. Subsequences whose length exceed the `max_depth` will not be considered nor counted.
-`alphabet_size`: Total number of symbols in the alphabet. This number has to be bigger than the highest integer encountered, else it will cause runtime errors.
-`n_jobs`: Number of subprocesses to spawn when running the vlmc. Choose `-1` for using all available processes.
- `max_depth`: Maximum depth of tree. Subsequences whose length exceed the `max_depth` will not be considered nor counted.
- `alphabet_size`: Total number of symbols in the alphabet. This number has to be bigger than the highest integer encountered, else it will cause runtime errors.
- `n_jobs`: Number of subprocesses to spawn when running the vlmc. Choose `-1` for using all available processes.

# Methods

Expand All @@ -39,7 +63,7 @@ tree.fit(data)
> fit method returns `None` and not `self`. This is by design as to not expose the rust object to python.
Parameters:
-`data`: List of lists containing sequences of discrete values to fit on. Values are assumed to be integers form `0` to `alphabet_size`. List is expected to be two dimensional.
- `data`: List of lists containing sequences of discrete values to fit on. Values are assumed to be integers form `0` to `alphabet_size`. List is expected to be two dimensional.

### `get_suffix`
Given a sequence, returns the longest suffix that is present in the VLMC.
Expand All @@ -48,7 +72,7 @@ Given a sequence, returns the longest suffix that is present in the VLMC.
suffix = tree.get_suffix(sequence)
```
Arguments:
-`sequence`: list of integers representing a sequence of discrete varaibles.
- `sequence`: list of integers representing a sequence of discrete varaibles.
Returns:
- `suffix` : longest suffix of sequence that is present in the VLMC.

Expand All @@ -60,7 +84,7 @@ Will throw a `KeyError` if the sequence is not a tree node. Consider using `get_
counts = tree.get_counts(sequence)
```
Arguments:
-`sequence`: list of integers representing a sequence of discrete varaibles.
- `sequence`: list of integers representing a sequence of discrete varaibles.
Returns:
- `counts` : integer

Expand All @@ -72,7 +96,7 @@ Will throw a `KeyError` if the sequence is not a tree node. Consider using `get_
probabilities = tree.get_distribution(sequence)
```
Arguments:
-`sequence`: list of integers representing a sequence of discrete variables.
- `sequence`: list of integers representing a sequence of discrete variables.
Returns:
- `probabilities` : list of floats representing the probability of observing a specific state (index) as the next symbol.

Expand All @@ -82,24 +106,7 @@ Returns:
contexts = tree.get_contexts()
```
Returns:
-`contexts`: list of relevant contexts according to the Peres-Shield tree prunning method. Contexts are ordered by length.


## Parameters

### `contexts`
```python
contexts = tree.contexts
```
Returns:
- `contexts` : list of sequences of each node in the tree, each relevant context.
### `adjacency_matrix`
```python
matrix, labels = tree.adjacency_matrix
```
Returns:
- `matrix` : adjacency matrix representing the suffix tree.
- `labels` : list of sequences associated with each node of the tree.
- `contexts`: list of relevant contexts according to the Peres-Shield tree prunning method. Contexts are ordered by length.

# TODO
### Paralelization
Expand Down

0 comments on commit abc0fc1

Please sign in to comment.