A hidden (state) conditional random field (HCRF) implementation written in Python and Cython.
Project description
pyhcrf
A hidden (state) conditional random field (HCRF) written in Python and Cython.
This package is a fork of the original pyhcrf
, written by
Dirko Coetsee, featuring Python 3 and Windows support
with a cleaner code base maintained by Martin Larralde.
Overview
pyhcrf
implements a HCRF model with a sklearn
-inspired
interface. The model classifies sequences according to a latent state sequence.
This package provides methods to learn parameters from example sequences and to
classify new sequences. See the paper
by Wang et al. and the report
by Dirko Coetsee.
States
Each state is numbered 0, 1, ..., num_states - 1
. The state machine starts
in state 0
and ends in num_states - 1
. Currently the state transitions are
constrained so that, on each element in the input sequence, the state machine
either stays in the current state or advances to a state represented by the
next number. This default can be changed by setting the transitions
and
corresponding transition_parameters
properties.
Dependencies
pyhcrf
depends on numpy
, scipy
(for the LM-BFGS optimiser and scipy.sparse
),
and also needs cython
for building from source.
Example
X = [array([[ 1. , -0.82683403, 2.48881337],
[ 1. , -1.07491808, 1.55848197],
[ 1. , 6.7814359 , 4.01074595]]),
array([[ 1. , -3.01165932, -2.15972362],
[ 1. , -3.41449473, -2.2668825 ]]),
array([[ 1. , -2.64921323, -1.20159641],
[ 1. , 0.31139394, 1.58841159]]),
array([[ 1. , 5.85226017, 2.43317499],
[ 1. , -1.57598266, -2.07585778]]),
array([[ 1. , -0.32999744, -2.70695361],
[ 1. , 0.44311988, 0.36400733]]),
array([[ 1. , -0.05301562, 3.95424435],
[ 1. , 3.04540498, -3.25040276]]),
array([[ 1. , -4.29117715, 0.9167861 ],
[ 1. , -3.22775884, 1.83277224]]),
array([[ 1. , -2.80856491, 1.95630489],
[ 1. , 1.62290542, -0.7457237 ]]),
array([[ 1. , -2.32682366, 2.60844469],
[ 1. , 2.12320609, 1.04483217]]),
array([[ 1. , -4.17616178, 4.09969658],
[ 1. , 0.67287935, -5.67652159]])]
y = [0, 1, 0, 1, 1, 0, 1, 0, 0, 0]
>>> from pyhcrf import HCRF
>>> from sklearn.metrics import confusion_matrix
>>> model = HCRF(num_states=3, random_seed=3, optimizer_kwargs={'maxfun':200})
>>> model.fit(X, y)
>>> pred = model.predict(X)
>>> confusion_matrix(y, pred)
array([[12, 0],
[ 0, 8]])
Installation
Download/clone and run
python setup.py build_ext --inplace
python setup.py install
License
The original code, and all contributions made subsequently in this fork, are licensed with BSD-2-Clause.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for pyhcrf-0.1.0-pp36-pypy36_pp73-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e77e3adffecb8e34970258649a833ede37088b4549ea30bcd2a90822ceabd5d |
|
MD5 | eedaf3d1b5816af553fb1bf7b10baf46 |
|
BLAKE2b-256 | afcf56b2a676f48a9f9cb0fa2892cb6f3bd5f039d9321de2fee2519adfce8cfa |
Hashes for pyhcrf-0.1.0-pp36-pypy36_pp73-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e06a63e9b398165c0dbf50b4d5d8eb8c09e73e7bcfbc534a0946916a6975437 |
|
MD5 | 622a32d85e1796a0aeeac54e1239fdeb |
|
BLAKE2b-256 | e7466b1612fc5341ec04fa9a3e67778d4c6136be870f8abc33e20bdf2c81a878 |
Hashes for pyhcrf-0.1.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26b4ebcaf1ffdadb04953dacd0517390e58f9abe7249e642f3c712b726f240b5 |
|
MD5 | 16a4232b1a50c0ae255f00e9342f42fb |
|
BLAKE2b-256 | ff931bc256b6c1ac49146ca449f74ef409c260e8595e6a5e208d1800f1f8f966 |
Hashes for pyhcrf-0.1.0-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 09b06bf397451e224e62b7b0451a285f0d14c9406cc22f393ba7d81e5c75ff08 |
|
MD5 | e2a62c62506affd100dc9463a5177e8c |
|
BLAKE2b-256 | 70d110d0c01ef4c30dc8b56bab448c11caf9c5362f73db5ea7997054ed39662a |
Hashes for pyhcrf-0.1.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f526d9571c30c18109d4c8f4e32fa09d960e37ffb2f5c407d013a033b988fbfd |
|
MD5 | c4ee54843178991844f82242590009f7 |
|
BLAKE2b-256 | 47ccdaf3e3afe292995ec4aa5414c5c8bbbfa3780e709022dc904fcfc0cf98b0 |
Hashes for pyhcrf-0.1.0-cp38-cp38-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3949b399128eab93ae5fae90c786f3dd14a42f022e47cb15428e268cdf54bdb7 |
|
MD5 | 8ed312209388985c53a602e5ce6da17d |
|
BLAKE2b-256 | a8ae6880e070a77bbc6e9407200e8a00a6729cdffd6f8b381e1c53528853a878 |
Hashes for pyhcrf-0.1.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d74f4d450ecadeeb7175f9387c525be074a5ab6690854d484d90a7918587f04b |
|
MD5 | 924b23edf595b79c224d2629c459701b |
|
BLAKE2b-256 | adea5ccf688059c5f9d3427d0ed74b3708f5d49104036d018aaabdc655da53f8 |
Hashes for pyhcrf-0.1.0-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 915333ae7e5c713fde7c0247fe32c0e5bc52502e50c04dc68713d880d10f2bbe |
|
MD5 | ff20279ed3e1a95ec3c71bb42f8d4b05 |
|
BLAKE2b-256 | e8e8b045a9c89dc57f26f935ccbd4ed5b7d3467d40a3179173659b9b011d56bd |
Hashes for pyhcrf-0.1.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | af4865a6e2085bd7acf1683aa6ee41c726b68aa587a726313cfbe6f7cb658e11 |
|
MD5 | 487ab79b959f89a700e448054f326770 |
|
BLAKE2b-256 | 15bcaad97f78939f813fe8e949b1acd498b5315282f1706687090a5af65e84bd |
Hashes for pyhcrf-0.1.0-cp37-cp37m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1cb6eb5c5e6bb5a94b5a9b954eebcff9ac1191b43011781048b9ee723f7a41f9 |
|
MD5 | f708d1fa051d8d4840ed0551f79ca4f0 |
|
BLAKE2b-256 | 443299c48cb064ffef9da4fc3f8b4001833c8b905670fe09ffe7773b23a89150 |
Hashes for pyhcrf-0.1.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3b23edfa7ffc3fa403fa8b5d1d1e268225abf59b448a75e6663d08150104682 |
|
MD5 | 79492ac7169a0825e2ed1299081d6b04 |
|
BLAKE2b-256 | 21cd0e53f15385b3ba199a0dfe66e3fd545c673d39f143cc6c3bb6ba6b6eca9a |
Hashes for pyhcrf-0.1.0-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7737aa3aa99cf552192ac4c9bbd8adec5fa5734eb7032af3c89dd9c96c8fc317 |
|
MD5 | e90faeadd5bfd86385bf389e3fc23678 |
|
BLAKE2b-256 | 1d621becc6ab69399a9b747e74c306ebd47965a2395c8cc44bbb1d34f651f160 |
Hashes for pyhcrf-0.1.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64a0cf50a3d1cbc89e1af14269b660a81552e4c3e337c54c0aa5c904eb8b96ca |
|
MD5 | b0314e9c45b63ad78bc660200beba18d |
|
BLAKE2b-256 | ada50c7ab214daec4bc7d1a8b227acd760e179f46bad476ea8c6072afab5e53f |
Hashes for pyhcrf-0.1.0-cp36-cp36m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5046cb6642494bf46508688a966272257d4ddb0f2dd96bccba03725f64f4eaed |
|
MD5 | a1768fab8a5bc7adce26450b94d23569 |
|
BLAKE2b-256 | 892ca38229ef308ec01b3ad4bc9eda85158efd1b9e56f2ff1963651fc9ba3c63 |
Hashes for pyhcrf-0.1.0-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8bd83e4f0bee26d5fc24a6746290baf1757592ed16e4cfc75faa570b1868f8d3 |
|
MD5 | a4bbdd1d893b5dcc52f8afcaef05b053 |
|
BLAKE2b-256 | fce01f229f0682a7847948de85425b4a4b44357523187b50012a9872ead4f740 |
Hashes for pyhcrf-0.1.0-cp35-cp35m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25507ecde74e41c447715b34f0beb3619fae9aff963bf8b00af68b0d6bba3253 |
|
MD5 | 40a1d39874962c552539991b7229f6c3 |
|
BLAKE2b-256 | 5c08e670525ccfb85a81c52a36798da0d52a95da1ce5c55488eaba4fc1450f73 |
Hashes for pyhcrf-0.1.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6666552c267e888e4ec1ac8acbad2f20c4b9e180999a08d8a56516017702faa3 |
|
MD5 | be9672935a994bb5e72f456ae688df8c |
|
BLAKE2b-256 | 51414715efab003fb84965cc1a84167212b4c436ba05631688d2e6fc42930ee6 |
Hashes for pyhcrf-0.1.0-cp35-cp35m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6df2c05f9f393970a61d8e39b380ffb7f56145ee186a672befb939dd24ecaaa |
|
MD5 | c85465425c6d2e78c3a9d03e0f754e67 |
|
BLAKE2b-256 | d9fdbbc66ec61418fb43951f994acbd03fb7fb9cb75d401a6e429c1d32d1cf4e |