├── .gitignore ├── LICENSE ├── gvps.h ├── gvps_full.c ├── gvps_obsrv.c ├── gvps_sampled.c ├── gvps_sampled.hc ├── gvps_variable.c ├── gvps_viterbi.hc ├── libgvps.sln ├── libgvps.vcxproj ├── makefile └── readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | *~ 3 | *.o 4 | *.a 5 | 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, Kanru Hua 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | -------------------------------------------------------------------------------- /gvps.h: -------------------------------------------------------------------------------- 1 | /* 2 | libgvps 3 | === 4 | 5 | Copyright (c) 2015, Kanru Hua 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without modification, 9 | are permitted provided that the following conditions are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright notice, this 12 | list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright notice, 15 | this list of conditions and the following disclaimer in the documentation and/or 16 | other materials provided with the distribution. 17 | 18 | 3. Neither the name of the copyright holder nor the names of its contributors 19 | may be used to endorse or promote products derived from this software without 20 | specific prior written permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 23 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 26 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 29 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #ifndef GVPS 35 | #define GVPS 36 | 37 | typedef struct 38 | { 39 | FP_TYPE p; 40 | int state; 41 | void* ptr; 42 | } gvps_pair; 43 | 44 | typedef struct 45 | { 46 | gvps_pair* pair; 47 | int N; 48 | } gvps_obsrv_slice; 49 | 50 | typedef struct 51 | { 52 | gvps_obsrv_slice** slice; 53 | int T; 54 | } gvps_obsrv; 55 | 56 | gvps_obsrv* gvps_obsrv_create(int T); 57 | gvps_obsrv* gvps_obsrv_create_full(int T, int nstate); 58 | gvps_obsrv_slice* gvps_obsrv_slice_create(int nstate); 59 | int gvps_obsrv_slice_free(gvps_obsrv_slice* slice); 60 | int gvps_obsrv_free(gvps_obsrv* seq); 61 | 62 | typedef FP_TYPE (* gvps_fobsrv)(void* context, int t, int n); 63 | typedef int (* gvps_fnobsrv)(void* context, int t); 64 | typedef FP_TYPE (* gvps_ftran_sampled)(void* context, int ds, int t); 65 | typedef FP_TYPE (* gvps_ftran)(void* context, int s1, int s2, int t2); 66 | typedef int (* gvps_ftrexist)(void* context, int s1, int s2, int t2); 67 | typedef int (* gvps_fntran)(void* context, int t); 68 | 69 | #define GVPS_ARG_SPSAMPHIDDEN (int* dst, void* context, int nstate, gvps_obsrv* obsrv, \ 70 | gvps_ftran_sampled ftransame, gvps_ftran_sampled ftrandiff, gvps_fntran fntran, int nhiddenprune) 71 | 72 | #define GVPS_ARG_SPSAMP (int* dst, void* context, int nstate, gvps_obsrv* obsrv, \ 73 | gvps_ftran_sampled ftran, gvps_fntran fntran) 74 | 75 | #define GVPS_ARG_FULLSAMPHIDDEN (int* dst, void* context, gvps_obsrv* obsrv, \ 76 | gvps_ftran_sampled ftransame, gvps_ftran_sampled ftrandiff, gvps_fntran fntran, int nhiddenprune) 77 | 78 | #define GVPS_ARG_FULLSAMP (int* dst, void* context, gvps_obsrv* obsrv, \ 79 | gvps_ftran_sampled ftran, gvps_fntran fntran) 80 | 81 | FP_TYPE gvps_sparse_sampled_hidden GVPS_ARG_SPSAMPHIDDEN; 82 | FP_TYPE gvps_sparse_sampled GVPS_ARG_SPSAMP; 83 | 84 | FP_TYPE gvps_sparse_circular_hidden GVPS_ARG_SPSAMPHIDDEN; 85 | FP_TYPE gvps_sparse_circular GVPS_ARG_SPSAMP; 86 | 87 | FP_TYPE gvps_full_sampled_hidden GVPS_ARG_FULLSAMPHIDDEN; 88 | FP_TYPE gvps_full_sampled GVPS_ARG_FULLSAMP; 89 | 90 | FP_TYPE gvps_full_circular_hidden GVPS_ARG_FULLSAMPHIDDEN; 91 | FP_TYPE gvps_full_circular GVPS_ARG_FULLSAMP; 92 | 93 | FP_TYPE gvps_sparse_sampled_hidden_static GVPS_ARG_SPSAMPHIDDEN; 94 | FP_TYPE gvps_sparse_sampled_static GVPS_ARG_SPSAMP; 95 | 96 | FP_TYPE gvps_sparse_circular_hidden_static GVPS_ARG_SPSAMPHIDDEN; 97 | FP_TYPE gvps_sparse_circular_static GVPS_ARG_SPSAMP; 98 | 99 | FP_TYPE gvps_full_sampled_hidden_static GVPS_ARG_FULLSAMPHIDDEN; 100 | FP_TYPE gvps_full_sampled_static GVPS_ARG_FULLSAMP; 101 | 102 | FP_TYPE gvps_full_circular_hidden_static GVPS_ARG_FULLSAMPHIDDEN; 103 | FP_TYPE gvps_full_circular_static GVPS_ARG_FULLSAMP; 104 | 105 | /* not implemented due to tractability/performance issues 106 | FP_TYPE gvps_full_hidden(int* dst, void* context, gvps_obsrv* obsrv, 107 | gvps_ftran ftransame, gvps_ftran ftrandiff, gvps_ftrexist ftrexist); 108 | */ 109 | FP_TYPE gvps_full(int* dst, void* context, gvps_obsrv* obsrv, 110 | gvps_ftran ftran, gvps_ftrexist ftrexist); 111 | FP_TYPE gvps_full_static(int* dst, void* context, gvps_obsrv* obsrv, 112 | gvps_ftran ftran); 113 | 114 | FP_TYPE gvps_variable(int* dst, void* context, gvps_obsrv* obsrv, 115 | gvps_ftran ftran, gvps_ftrexist ftrexist); 116 | 117 | #endif 118 | 119 | -------------------------------------------------------------------------------- /gvps_full.c: -------------------------------------------------------------------------------- 1 | /* 2 | libgvps 3 | === 4 | 5 | Copyright (c) 2015, Kanru Hua 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without modification, 9 | are permitted provided that the following conditions are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright notice, this 12 | list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright notice, 15 | this list of conditions and the following disclaimer in the documentation and/or 16 | other materials provided with the distribution. 17 | 18 | 3. Neither the name of the copyright holder nor the names of its contributors 19 | may be used to endorse or promote products derived from this software without 20 | specific prior written permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 23 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 26 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 29 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #include "gvps.h" 35 | #include 36 | #include 37 | 38 | #define max(a, b) ((a) > (b) ? (a) : (b)) 39 | #define min(a, b) ((a) < (b) ? (a) : (b)) 40 | #define abs(x) ((x) > 0 ? (x) : (- (x))) 41 | 42 | #define FULL 43 | #define FULLTRAN 44 | FP_TYPE gvps_full(int* dst, void* context, gvps_obsrv* obsrv, 45 | gvps_ftran ftran, gvps_ftrexist ftrexist) 46 | { 47 | #define FTREXIST 48 | #include "gvps_viterbi.hc" 49 | } 50 | #undef FTREXIST 51 | 52 | FP_TYPE gvps_full_static(int* dst, void* context, gvps_obsrv* obsrv, 53 | gvps_ftran ftran) 54 | { 55 | #define STATIC 56 | #include "gvps_viterbi.hc" 57 | } 58 | 59 | -------------------------------------------------------------------------------- /gvps_obsrv.c: -------------------------------------------------------------------------------- 1 | /* 2 | libgvps 3 | === 4 | 5 | Copyright (c) 2015, Kanru Hua 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without modification, 9 | are permitted provided that the following conditions are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright notice, this 12 | list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright notice, 15 | this list of conditions and the following disclaimer in the documentation and/or 16 | other materials provided with the distribution. 17 | 18 | 3. Neither the name of the copyright holder nor the names of its contributors 19 | may be used to endorse or promote products derived from this software without 20 | specific prior written permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 23 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 26 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 29 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #include "gvps.h" 35 | #include 36 | #include 37 | 38 | gvps_obsrv* gvps_obsrv_create(int T) 39 | { 40 | gvps_obsrv* ret = malloc(sizeof(gvps_obsrv)); 41 | ret -> slice = calloc(T, sizeof(gvps_obsrv_slice*)); 42 | ret -> T = T; 43 | memset(ret -> slice, 0, T * sizeof(gvps_obsrv_slice*)); 44 | return ret; 45 | } 46 | 47 | gvps_obsrv_slice* gvps_obsrv_slice_create(int nstate) 48 | { 49 | gvps_obsrv_slice* ret = malloc(sizeof(gvps_obsrv_slice)); 50 | ret -> pair = calloc(nstate, sizeof(gvps_pair)); 51 | ret -> N = nstate; 52 | return ret; 53 | } 54 | 55 | gvps_obsrv* gvps_obsrv_create_full(int T, int nstate) 56 | { 57 | int t; 58 | gvps_obsrv* ret = gvps_obsrv_create(T); 59 | for(t = 0; t < T; t ++) 60 | ret -> slice[t] = gvps_obsrv_slice_create(nstate); 61 | return ret; 62 | } 63 | 64 | int gvps_obsrv_slice_free(gvps_obsrv_slice* slice) 65 | { 66 | free(slice -> pair); 67 | free(slice); 68 | return 1; 69 | } 70 | 71 | int gvps_obsrv_free(gvps_obsrv* seq) 72 | { 73 | int t; 74 | for(t = 0; t < seq -> T; t ++) 75 | if(seq -> slice[t] != 0) 76 | gvps_obsrv_slice_free(seq -> slice[t]); 77 | free(seq -> slice); 78 | free(seq); 79 | return 1; 80 | } 81 | 82 | -------------------------------------------------------------------------------- /gvps_sampled.c: -------------------------------------------------------------------------------- 1 | /* 2 | libgvps 3 | === 4 | 5 | Copyright (c) 2015, Kanru Hua 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without modification, 9 | are permitted provided that the following conditions are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright notice, this 12 | list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright notice, 15 | this list of conditions and the following disclaimer in the documentation and/or 16 | other materials provided with the distribution. 17 | 18 | 3. Neither the name of the copyright holder nor the names of its contributors 19 | may be used to endorse or promote products derived from this software without 20 | specific prior written permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 23 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 26 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 29 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #include "gvps.h" 35 | #include 36 | #include 37 | 38 | #define max(a, b) ((a) > (b) ? (a) : (b)) 39 | #define min(a, b) ((a) < (b) ? (a) : (b)) 40 | #define abs(x) ((x) > 0 ? (x) : (- (x))) 41 | #define nprestore 15 42 | 43 | #define SAMPLED 44 | 45 | #undef STATIC 46 | #include "gvps_sampled.hc" 47 | 48 | #define STATIC 49 | #include "gvps_sampled.hc" 50 | 51 | -------------------------------------------------------------------------------- /gvps_sampled.hc: -------------------------------------------------------------------------------- 1 | /* 2 | libgvps 3 | === 4 | 5 | Copyright (c) 2015, Kanru Hua 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without modification, 9 | are permitted provided that the following conditions are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright notice, this 12 | list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright notice, 15 | this list of conditions and the following disclaimer in the documentation and/or 16 | other materials provided with the distribution. 17 | 18 | 3. Neither the name of the copyright holder nor the names of its contributors 19 | may be used to endorse or promote products derived from this software without 20 | specific prior written permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 23 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 26 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 29 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #undef FULL 35 | #ifdef STATIC 36 | FP_TYPE gvps_sparse_sampled_hidden_static 37 | #else 38 | FP_TYPE gvps_sparse_sampled_hidden 39 | #endif 40 | (int* dst, void* context, int nstate, 41 | gvps_obsrv* obsrv, 42 | gvps_ftran_sampled ftransame, gvps_ftran_sampled ftrandiff, gvps_fntran fntran, int nhiddenprune) 43 | { 44 | #define HIDDEN 45 | #include "gvps_viterbi.hc" 46 | } 47 | 48 | #ifdef STATIC 49 | FP_TYPE gvps_sparse_sampled_static 50 | #else 51 | FP_TYPE gvps_sparse_sampled 52 | #endif 53 | (int* dst, void* context, int nstate, 54 | gvps_obsrv* obsrv, 55 | gvps_ftran_sampled ftran, gvps_fntran fntran) 56 | { 57 | #undef HIDDEN 58 | #include "gvps_viterbi.hc" 59 | } 60 | 61 | #define CIRCULAR 62 | #ifdef STATIC 63 | FP_TYPE gvps_sparse_circular_hidden_static 64 | #else 65 | FP_TYPE gvps_sparse_circular_hidden 66 | #endif 67 | (int* dst, void* context, int nstate, 68 | gvps_obsrv* obsrv, 69 | gvps_ftran_sampled ftransame, gvps_ftran_sampled ftrandiff, gvps_fntran fntran, int nhiddenprune) 70 | { 71 | #define HIDDEN 72 | #include "gvps_viterbi.hc" 73 | } 74 | 75 | #ifdef STATIC 76 | FP_TYPE gvps_sparse_circular_static 77 | #else 78 | FP_TYPE gvps_sparse_circular 79 | #endif 80 | (int* dst, void* context, int nstate, 81 | gvps_obsrv* obsrv, 82 | gvps_ftran_sampled ftran, gvps_fntran fntran) 83 | { 84 | #undef HIDDEN 85 | #include "gvps_viterbi.hc" 86 | } 87 | #undef CIRCULAR 88 | 89 | #define FULL 90 | #ifdef STATIC 91 | FP_TYPE gvps_full_sampled_hidden_static 92 | #else 93 | FP_TYPE gvps_full_sampled_hidden 94 | #endif 95 | (int* dst, void* context, 96 | gvps_obsrv* obsrv, 97 | gvps_ftran_sampled ftransame, gvps_ftran_sampled ftrandiff, gvps_fntran fntran, int nhiddenprune) 98 | { 99 | #define HIDDEN 100 | #include "gvps_viterbi.hc" 101 | } 102 | 103 | #ifdef STATIC 104 | FP_TYPE gvps_full_sampled_static 105 | #else 106 | FP_TYPE gvps_full_sampled 107 | #endif 108 | (int* dst, void* context, 109 | gvps_obsrv* obsrv, 110 | gvps_ftran_sampled ftran, gvps_fntran fntran) 111 | { 112 | #undef HIDDEN 113 | #include "gvps_viterbi.hc" 114 | } 115 | 116 | #define CIRCULAR 117 | #ifdef STATIC 118 | FP_TYPE gvps_full_circular_hidden_static 119 | #else 120 | FP_TYPE gvps_full_circular_hidden 121 | #endif 122 | (int* dst, void* context, 123 | gvps_obsrv* obsrv, 124 | gvps_ftran_sampled ftransame, gvps_ftran_sampled ftrandiff, gvps_fntran fntran, int nhiddenprune) 125 | { 126 | #define HIDDEN 127 | #include "gvps_viterbi.hc" 128 | } 129 | 130 | #ifdef STATIC 131 | FP_TYPE gvps_full_circular_static 132 | #else 133 | FP_TYPE gvps_full_circular 134 | #endif 135 | (int* dst, void* context, 136 | gvps_obsrv* obsrv, 137 | gvps_ftran_sampled ftran, gvps_fntran fntran) 138 | { 139 | #undef HIDDEN 140 | #include "gvps_viterbi.hc" 141 | } 142 | #undef CIRCULAR 143 | 144 | -------------------------------------------------------------------------------- /gvps_variable.c: -------------------------------------------------------------------------------- 1 | /* 2 | libgvps 3 | === 4 | 5 | Copyright (c) 2015, Kanru Hua 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without modification, 9 | are permitted provided that the following conditions are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright notice, this 12 | list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright notice, 15 | this list of conditions and the following disclaimer in the documentation and/or 16 | other materials provided with the distribution. 17 | 18 | 3. Neither the name of the copyright holder nor the names of its contributors 19 | may be used to endorse or promote products derived from this software without 20 | specific prior written permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 23 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 26 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 29 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #include "gvps.h" 35 | #include 36 | #include 37 | 38 | #define max(a, b) ((a) > (b) ? (a) : (b)) 39 | #define min(a, b) ((a) < (b) ? (a) : (b)) 40 | #define abs(x) ((x) > 0 ? (x) : (- (x))) 41 | 42 | #define VARIABLE 43 | FP_TYPE gvps_variable(int* dst, void* context, gvps_obsrv* obsrv, 44 | gvps_ftran ftran, gvps_ftrexist ftrexist) 45 | { 46 | #define FTREXIST 47 | #include "gvps_viterbi.hc" 48 | } 49 | 50 | -------------------------------------------------------------------------------- /gvps_viterbi.hc: -------------------------------------------------------------------------------- 1 | /* 2 | libgvps 3 | === 4 | 5 | Copyright (c) 2015, Kanru Hua 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without modification, 9 | are permitted provided that the following conditions are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright notice, this 12 | list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright notice, 15 | this list of conditions and the following disclaimer in the documentation and/or 16 | other materials provided with the distribution. 17 | 18 | 3. Neither the name of the copyright holder nor the names of its contributors 19 | may be used to endorse or promote products derived from this software without 20 | specific prior written permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 23 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 26 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 29 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #undef a_h 35 | #undef p_h 36 | #undef a 37 | #undef p 38 | #undef trandiff 39 | #undef transame 40 | #undef nstate_at 41 | #undef state_at 42 | #undef p_at 43 | #undef tran 44 | 45 | int T = obsrv -> T; 46 | #ifdef FULL 47 | int nstate = obsrv -> slice[0] -> N; 48 | #define nstate_at(t) nstate 49 | #define state_at(t, n) n 50 | FP_TYPE* a_ = calloc(T * nstate, sizeof(FP_TYPE)); 51 | int* p_ = calloc(T * nstate, sizeof(int)); 52 | #define a(t, n) a_[(t) * nstate + (n)] 53 | #define p(t, n) p_[(t) * nstate + (n)] 54 | #else 55 | int* nsparse = calloc(T, sizeof(int)); 56 | #define nstate_at(t) nsparse[t] 57 | #define state_at(t, n) (obsrv -> slice[t] -> pair[n].state) 58 | FP_TYPE** a_ = calloc(T, sizeof(FP_TYPE*)); 59 | int** p_ = calloc(T, sizeof(int*)); 60 | #define a(t, n) a_[t][n] 61 | #define p(t, n) p_[t][n] 62 | #endif 63 | 64 | #define p_at(t, n) (obsrv -> slice[t] -> pair[n].p) 65 | 66 | #ifdef SAMPLED 67 | #ifdef STATIC 68 | FP_TYPE* transame_ = calloc(nstate, sizeof(FP_TYPE)); 69 | #else 70 | FP_TYPE* transame_ = calloc(T * nprestore, sizeof(FP_TYPE)); 71 | #endif 72 | 73 | #ifdef HIDDEN 74 | FP_TYPE* a_h_ = calloc(T * nstate, sizeof(FP_TYPE)); 75 | int* p_h_ = calloc(T * nstate, sizeof(int)); 76 | #define a_h(t, n) a_h_[(t) * nstate + (n)] 77 | #define p_h(t, n) p_h_[(t) * nstate + (n)] 78 | #ifdef STATIC 79 | FP_TYPE* trandiff_ = calloc(nstate, sizeof(FP_TYPE)); 80 | #define trandiff(t, d) trandiff_[d] 81 | #define transame(t, d) transame_[d] 82 | #else 83 | FP_TYPE* trandiff_ = calloc(T * nprestore, sizeof(FP_TYPE)); 84 | #define trandiff(t, d) (((d) < nprestore) ? trandiff_[(t) * nprestore + (d)] : log((*ftrandiff)(context, d, t))) 85 | #define transame(t, d) (((d) < nprestore) ? transame_[(t) * nprestore + (d)] : log((*ftransame)(context, d, t))) 86 | #endif 87 | #else 88 | #ifdef STATIC 89 | #define transame(t, d) transame_[d] 90 | #else 91 | #define transame(t, d) (((d) < nprestore) ? transame_[(t) * nprestore + (d)] : log((*ftran)(context, d, t))) 92 | #endif 93 | #endif 94 | 95 | #else 96 | #ifdef STATIC 97 | FP_TYPE* tran_ = calloc(nstate * nstate, sizeof(FP_TYPE)); 98 | #define transame(t2, s1, s2) tran_[(s1) * nstate + (s2)] 99 | #else 100 | #define transame(t2, s1, s2) (*ftran)(context, s1, s2, t2) 101 | #endif 102 | #endif 103 | 104 | int t, i, j; 105 | t = i = j = 0; 106 | 107 | #ifdef STATIC 108 | #ifdef SAMPLED 109 | int d; 110 | for(d = 0; d < nstate; d ++) 111 | { 112 | #ifdef HIDDEN 113 | transame(0, d) = log((*ftransame)(context, d, 0)); 114 | trandiff(0, d) = log((*ftrandiff)(context, d, 0)); 115 | #else 116 | transame(0, d) = log((*ftran)(context, d, 0)); 117 | #endif 118 | } 119 | #else 120 | for(i = 0; i < nstate; i ++) 121 | for(j = 0; j < nstate; j ++) 122 | transame(0, i, j) = (*ftran)(context, i, j, 0); 123 | #endif 124 | #endif 125 | 126 | #ifdef SAMPLED 127 | for(t = 0; t < T; t ++) 128 | { 129 | #ifndef FULL 130 | nsparse[t] = obsrv -> slice[t] -> N; 131 | a_[t] = calloc(nsparse[t], sizeof(FP_TYPE)); 132 | p_[t] = calloc(nsparse[t], sizeof(int)); 133 | #endif 134 | #ifndef STATIC 135 | int d; 136 | for(d = 0; d < nprestore; d ++) 137 | { 138 | #ifdef HIDDEN 139 | transame_[(t) * nprestore + d] = log((*ftransame)(context, d, t)); 140 | trandiff_[(t) * nprestore + d] = log((*ftrandiff)(context, d, t)); 141 | #else 142 | transame_[(t) * nprestore + d] = log((*ftran)(context, d, t)); 143 | #endif 144 | } 145 | #endif 146 | } 147 | #endif 148 | 149 | #ifdef VARIABLE 150 | for(t = 0; t < T; t ++) { 151 | nsparse[t] = obsrv -> slice[t] -> N; 152 | a_[t] = calloc(nsparse[t], sizeof(FP_TYPE)); 153 | p_[t] = calloc(nsparse[t], sizeof(int)); 154 | } 155 | #endif 156 | 157 | // initialization 158 | #ifdef HIDDEN 159 | FP_TYPE pexposed = 0; 160 | #endif 161 | for(i = 0; i < nstate_at(0); i ++) 162 | { 163 | FP_TYPE P = p_at(0, i); 164 | a(0, i) = log(P); 165 | #ifdef HIDDEN 166 | pexposed += P; 167 | #endif 168 | } 169 | #ifdef HIDDEN 170 | FP_TYPE phidden = log(1 - pexposed < 0.00001 ? 0.00001 : 1 - pexposed); 171 | for(i = 0; i < nstate; i ++) 172 | a_h(0, i) = phidden; 173 | #endif 174 | 175 | // DP searching 176 | for(t = 1; t < T; t ++) 177 | { 178 | int n, nprv; 179 | FP_TYPE maxp; 180 | int maxj; 181 | #ifdef SAMPLED 182 | int ntrans = (*fntran)(context, t); 183 | #endif 184 | #ifdef HIDDEN 185 | int ntransh = min(ntrans, nhiddenprune); 186 | pexposed = 0; 187 | #endif 188 | 189 | #undef transition_update 190 | #ifdef CIRCULAR 191 | #define transition_update(f, a, newj) \ 192 | int diff = abs(i - j); \ 193 | FP_TYPE psum = a + f(t, diff > nstate / 2 ? nstate - diff : diff); \ 194 | if(psum > maxp) \ 195 | { \ 196 | maxp = psum; \ 197 | maxj = newj; \ 198 | } 199 | #else 200 | #ifndef SAMPLED 201 | #define transition_update(f, a, newj) \ 202 | FP_TYPE psum = a + f(t, j, i); \ 203 | if(psum > maxp) \ 204 | { \ 205 | maxp = psum; \ 206 | maxj = newj; \ 207 | } 208 | #else 209 | #define transition_update(f, a, newj) \ 210 | FP_TYPE psum = a + f(t, abs(i - j)); \ 211 | if(psum > maxp) \ 212 | { \ 213 | maxp = psum; \ 214 | maxj = newj; \ 215 | } 216 | #endif 217 | #endif 218 | 219 | // exposed/hidden -> exposed 220 | for(n = 0; n < nstate_at(t); n ++) 221 | { 222 | maxp = -30e10; 223 | maxj = 0; 224 | i = state_at(t, n); 225 | #ifdef HIDDEN 226 | // hidden -> exposed 227 | #ifdef CIRCULAR 228 | for(int cj = i - ntrans; cj < i + ntrans + 1; cj ++) 229 | { 230 | j = (cj + nstate) % nstate; 231 | transition_update(trandiff, a_h(t - 1, j), -j - 1); 232 | } 233 | #else 234 | for(j = max(0, i - ntrans); j < min(nstate, i + ntrans + 1); j ++) 235 | { 236 | transition_update(trandiff, a_h(t - 1, j), -j - 1); 237 | } 238 | #endif 239 | #endif 240 | // exposed -> exposed 241 | for(nprv = 0; nprv < nstate_at(t - 1); nprv ++) 242 | { 243 | j = state_at(t - 1, nprv); 244 | #ifdef SAMPLED 245 | #ifndef CIRCULAR 246 | if(abs(i - j) > ntrans) continue; 247 | #endif 248 | #endif 249 | #ifdef FTREXIST 250 | if(! (*ftrexist)(context, j, i, t)) continue; 251 | #endif 252 | transition_update(transame, a(t - 1, nprv), nprv); 253 | } 254 | #ifdef HIDDEN 255 | pexposed += p_at(t, n); 256 | #endif 257 | a(t, n) = maxp + log(p_at(t, n)); 258 | p(t, n) = maxj; 259 | } 260 | 261 | #ifdef HIDDEN 262 | phidden = log(1 - pexposed < 0.00001 ? 0.00001 : 1 - pexposed); 263 | // exposed/hidden -> hidden 264 | for(i = 0; i < nstate; i ++) 265 | { 266 | maxp = -30e10; 267 | maxj = 0; 268 | // hidden -> hidden 269 | #ifdef CIRCULAR 270 | for(int cj = i - ntransh; cj < i + ntransh + 1; cj ++) 271 | { 272 | j = (cj + nstate) % nstate; 273 | transition_update(transame, a_h(t - 1, j), -j - 1); 274 | } 275 | #else 276 | for(j = max(0, i - ntransh); j < min(nstate, i + ntransh + 1); j ++) 277 | { 278 | transition_update(transame, a_h(t - 1, j), -j - 1); 279 | } 280 | #endif 281 | 282 | // exposed -> hidden 283 | for(nprv = 0; nprv < nstate_at(t - 1); nprv ++) 284 | { 285 | j = state_at(t - 1, nprv); 286 | #ifndef CIRCULAR 287 | if(abs(i - j) > ntrans) continue; 288 | #endif 289 | transition_update(trandiff, a(t - 1, nprv), nprv); 290 | } 291 | 292 | a_h(t, i) = maxp + phidden; 293 | p_h(t, i) = maxj; 294 | } 295 | #endif 296 | #ifdef SAMPLED 297 | (void)ntrans; // suppress unused variable warning 298 | #endif 299 | } 300 | 301 | // termination 302 | FP_TYPE optim = -30e10; 303 | int maxi = 0; 304 | t = T - 1; 305 | #ifdef HIDDEN 306 | // hidden 307 | for(i = 0; i < nstate; i ++) 308 | if(a_h(t, i) > optim) 309 | { 310 | optim = a_h(t, i); 311 | maxi = -i - 1; 312 | } 313 | #endif 314 | // exposed 315 | for(i = 0; i < nstate_at(t); i ++) 316 | if(a(t, i) > optim) 317 | { 318 | optim = a(t, i); 319 | maxi = i; 320 | } 321 | 322 | // back tracking 323 | dst[t] = maxi; 324 | while(t > 0) 325 | { 326 | t --; 327 | #ifdef HIDDEN 328 | dst[t] = dst[t + 1] < 0 ? p_h(t + 1, -dst[t + 1] - 1) : p(t + 1, dst[t + 1]); 329 | #else 330 | dst[t] = p(t + 1, dst[t + 1]); 331 | #endif 332 | } 333 | #ifdef HIDDEN 334 | for(t = 0; t < T; t ++) // offset hidden states by nstate 335 | dst[t] = dst[t] < 0 ? nstate - dst[t] - 1 : state_at(t, dst[t]); 336 | #else 337 | for(t = 0; t < T; t ++) // pair index to state index 338 | dst[t] = state_at(t, dst[t]); 339 | #endif 340 | 341 | // free 342 | #ifndef FULL 343 | for(t = 0; t < T; t ++) 344 | { 345 | free(a_[t]); 346 | free(p_[t]); 347 | } 348 | free(nsparse); 349 | #endif 350 | #if defined(STATIC) && ! defined(SAMPLED) 351 | free(tran_); 352 | #endif 353 | free(a_); free(p_); 354 | #ifdef SAMPLED 355 | free(transame_); 356 | #endif 357 | #ifdef HIDDEN 358 | free(a_h_); free(p_h_); 359 | free(trandiff_); 360 | #endif 361 | 362 | return optim; 363 | 364 | -------------------------------------------------------------------------------- /libgvps.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libgvps", "libgvps.vcxproj", "{6AB4E505-C7C0-420C-8E33-D424CD817A67}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {6AB4E505-C7C0-420C-8E33-D424CD817A67}.Debug|x64.ActiveCfg = Debug|x64 17 | {6AB4E505-C7C0-420C-8E33-D424CD817A67}.Debug|x64.Build.0 = Debug|x64 18 | {6AB4E505-C7C0-420C-8E33-D424CD817A67}.Debug|x86.ActiveCfg = Debug|Win32 19 | {6AB4E505-C7C0-420C-8E33-D424CD817A67}.Debug|x86.Build.0 = Debug|Win32 20 | {6AB4E505-C7C0-420C-8E33-D424CD817A67}.Release|x64.ActiveCfg = Release|x64 21 | {6AB4E505-C7C0-420C-8E33-D424CD817A67}.Release|x64.Build.0 = Release|x64 22 | {6AB4E505-C7C0-420C-8E33-D424CD817A67}.Release|x86.ActiveCfg = Release|Win32 23 | {6AB4E505-C7C0-420C-8E33-D424CD817A67}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /libgvps.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | {6AB4E505-C7C0-420C-8E33-D424CD817A67} 32 | Win32Proj 33 | libgvps 34 | 10.0 35 | 36 | 37 | 38 | StaticLibrary 39 | true 40 | v142 41 | Unicode 42 | 43 | 44 | StaticLibrary 45 | false 46 | Intel C++ Compiler 19.0 47 | true 48 | Unicode 49 | 50 | 51 | StaticLibrary 52 | true 53 | v142 54 | Unicode 55 | 56 | 57 | StaticLibrary 58 | false 59 | Intel C++ Compiler 19.0 60 | true 61 | Unicode 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | Level3 87 | Disabled 88 | FP_TYPE=float;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) 89 | CompileAsC 90 | 4244;4305 91 | 92 | 93 | Windows 94 | 95 | 96 | 97 | 98 | 99 | 100 | Level3 101 | Disabled 102 | FP_TYPE=float;_DEBUG;_LIB;%(PreprocessorDefinitions) 103 | CompileAsC 104 | 4244;4305 105 | 106 | 107 | Windows 108 | 109 | 110 | 111 | 112 | Level3 113 | 114 | 115 | MaxSpeed 116 | true 117 | true 118 | FP_TYPE=float;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) 119 | CompileAsC 120 | 4244;4305 121 | stdcpp14 122 | 123 | 124 | Windows 125 | true 126 | true 127 | 128 | 129 | 130 | 131 | Level3 132 | 133 | 134 | MaxSpeed 135 | true 136 | true 137 | FP_TYPE=float;NDEBUG;_LIB;%(PreprocessorDefinitions) 138 | CompileAsC 139 | 4244;4305 140 | stdcpp14 141 | 142 | 143 | Windows 144 | true 145 | true 146 | 147 | 148 | 149 | 150 | 151 | -------------------------------------------------------------------------------- /makefile: -------------------------------------------------------------------------------- 1 | 2 | PREFIX=/usr 3 | 4 | export FP_TYPE ?= float 5 | CONFIG = Debug 6 | 7 | #CC = clang-3.5 8 | CC = $(CROSS)gcc 9 | AR = $(CROSS)ar 10 | CFLAGS_COMMON = -DFP_TYPE=$(FP_TYPE) -std=c99 -Wall -fPIC $(CFLAGSEXT) 11 | CFLAGS_DBG = $(CFLAGS_COMMON) -Og -g 12 | CFLAGS_REL = $(CFLAGS_COMMON) -Ofast 13 | ifeq ($(CONFIG), Debug) 14 | CFLAGS = $(CFLAGS_DBG) 15 | else 16 | CFLAGS = $(CFLAGS_REL) 17 | endif 18 | ARFLAGS = -rv 19 | OUT_DIR = ./build 20 | OBJS = $(OUT_DIR)/gvps_sampled.o $(OUT_DIR)/gvps_obsrv.o $(OUT_DIR)/gvps_full.o $(OUT_DIR)/gvps_variable.o 21 | LIBS = 22 | 23 | default: $(OUT_DIR)/libgvps.a 24 | 25 | $(OUT_DIR)/libgvps.a: $(OBJS) 26 | $(AR) $(ARFLAGS) $(OUT_DIR)/libgvps.a $(OBJS) $(LIBS) 27 | @echo Done. 28 | 29 | $(OUT_DIR)/gvps_sampled.o : gvps_sampled.c gvps_sampled.hc gvps_viterbi.hc gvps.h 30 | $(OUT_DIR)/gvps_full.o : gvps_full.c gvps_viterbi.hc gvps.h 31 | $(OUT_DIR)/gvps_variable.o : gvps_variable.c gvps_viterbi.hc gvps.h 32 | 33 | $(OUT_DIR)/%.o : %.c gvps.h 34 | mkdir -p $(OUT_DIR) 35 | $(CC) $(CFLAGS) -o $(OUT_DIR)/$*.o -c $*.c 36 | 37 | install: $(OUT_DIR)/libgvps.a 38 | mkdir -p $(PREFIX)/lib/ $(PREFIX)/include/libgvps 39 | cp $(OUT_DIR)/libgvps.a $(PREFIX)/lib/ 40 | cp gvps.h $(PREFIX)/include/libgvps 41 | @echo Done. 42 | 43 | clean: 44 | @echo 'Removing all temporary binaries... ' 45 | @rm -f $(OUT_DIR)/libgvps.a $(OUT_DIR)/*.o 46 | @echo Done. 47 | 48 | clear: 49 | @echo 'Removing all temporary binaries... ' 50 | @rm -f $(OUT_DIR)/libgvps.a $(OUT_DIR)/*.o 51 | @echo Done. 52 | 53 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | libgvps 2 | --- 3 | 4 | libgvps stands for *Generic Viterbi Path Searcher*. 5 | 6 | This library is an implementation of Viterbi algorithm in a *probabilistic* formulation that helps you **find the most likely sequence given a set of states or candidates over a certain time period and the state transition probabilities**. 7 | 8 | libgvps allows the states/candidates space to be dense or sparse or even circular; transition probabilities can be either static or dynamic (along time axis). 9 | 10 | | Function | Geometric description | Examples (if any) 11 | | --- | --- | --- | 12 | | `gvps_sparse_sampled` | path searching on a plane 13 | | `gvps_sparse_sampled_hidden` | path searching on a double-sided plane with only one side exposed 14 | | `gvps_sparse_sampled_static` | path searching on a plane assuming time locality of trans. prob | F0 tracking 15 | | `gvps_sparse_sampled_hidden_static` | path searching on a double-sided plane with only one side exposed, assuming time locality of trans. prob | F0 tracking, (lowpass-like) filtering on a discrete/quantized signal 16 | | `gvps_sparse_circular` | path searching on a cylinder 17 | | `gvps_sparse_circular_hidden` | path searching on a double-sided cylinder with only one side exposed 18 | | `gvps_sparse_circular_static` | path searching on a cylinder assuming time locality of trans. prob 19 | | `gvps_sparse_circular_hidden_static` | path searching on a double-sided cylinder with only one side exposed, assuming time locality of trans. prob 20 | | `gvps_full_sampled` | path searching on a plane 21 | | `gvps_full_sampled_hidden` | path searching on a double-sided plane with only one side exposed 22 | | `gvps_full_sampled_static` | path searching on a plane assuming time locality of trans. prob | trajectory tracking in a gray-scale image, (lowpass-like) filtering on a discrete/quantized signal 23 | | `gvps_full_sampled_hidden_static` | path searching on a double-sided plane with only one side exposed, assuming time locality of trans. prob | trajectory tracking in a gray-scale image, allowing discontinuities 24 | | `gvps_full_circular` | path searching on a cylinder 25 | | `gvps_full_circular_hidden` | path searching on a double-sided cylinder with only one side exposed 26 | | `gvps_full_circular_static` | path searching on a cylinder assuming time locality of trans. prob 27 | | `gvps_full_circular_hidden_static` | path searching on a double-sided cylinder with only one side exposed, assuming time locality of trans. prob 28 | | `gvps_full` | path searching on a (topological) plane with arbitrary geometric assumptions 29 | | `gvps_full_static` | path searching on a (topological) plane with arbitrary geometric assumptions, assuming time locality of trans. prob | MAP inference for Hidden Markov Models 30 | | `gvps_variable` | path searching in an arbitrary space | unit selection speech synthesis --------------------------------------------------------------------------------