📄 prob_cache.cpp
字号:
/*
//
// INTEL CORPORATION PROPRIETARY INFORMATION
// This software is supplied under the terms of a license agreement or
// nondisclosure agreement with Intel Corporation and may not be copied
// or disclosed except in accordance with the terms of that agreement.
// Copyright(c) 1999-2006 Intel Corporation. All Rights Reserved.
//
// Intel(R) Integrated Performance Primitives Gaussian Mixture Sample for Windows*
//
// By downloading and installing this sample, you hereby agree that the
// accompanying Materials are being provided to you under the terms and
// conditions of the End User License Agreement for the Intel(R) Integrated
// Performance Primitives product previously accepted by you. Please refer
// to the file ippEULA.rtf located in the root directory of your Intel(R) IPP
// product installation for more information.
//
//
// Probabilities Cache Management Class
//
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <ipps.h>
#include <ippsr.h>
#include "prob_cache.h"
#include "prob_calc.h"
Prob_Cache::Prob_Cache(int N, int L, int K) {
state_number = N;
vec_length = L;
frame_num = K;
lost_prob = 0;
t = 0;
calc = NULL;
buffer = NULL;
last_calc = NULL;
len_stat = NULL;
if_calc = NULL;
ready = -2;
}
int Prob_Cache::Init_Cache(void) {
if (ready!=-2) return -10;
if (state_number<=0) return -1;
if (vec_length<=0) return -1;
if (frame_num<=0) return -1;
if (frame_num<256)
frame_num=256;
if (vec_length>frame_num)
vec_length=frame_num;
if (!(buffer = ippsMalloc_32f(vec_length*state_number+frame_num))) return -2;
if (!(last_calc = ippsMalloc_16s(state_number))) return -2;
if (!(if_calc = ippsMalloc_8u(state_number))) return -2;
if (!(len_stat = ippsMalloc_32s(vec_length+1))) return -2;
ready=-1;
return 0;
}
Prob_Cache::~Prob_Cache(void) {
state_number = 0;
vec_length = 0;
frame_num = 0;
lost_prob = 0;
t = 0;
if (len_stat) ippsFree(len_stat);
if (if_calc) ippsFree(if_calc);
if (last_calc) ippsFree(last_calc);
if (buffer) ippsFree(buffer);
calc = NULL;
buffer = NULL;
curbuf = NULL;
endbuf = NULL;
last_calc = NULL;
len_stat = NULL;
if_calc = NULL;
ready = -2;
}
void Prob_Cache::Get_Statistics(Len_Stat *stat) {
// all - all probabilities requested
// lost - number of wasted probabilities
// nums[i] - number of intervals of length i+1
int i;
ippsCopy_32f((float*)len_stat,(float*)(stat->nums),stat->len);
for (stat->all=i=0; i<stat->len; i++)
stat->all+=(i+1)*len_stat[i];
stat->lost=lost_prob;
}
bool Prob_Cache::Attach_Calc(Prob_Calc *c) {
if (ready!=-1) return false;
calc=c;
if (!calc) return false;
if (!calc->Ready()) return false;
if (calc->State_Number()>state_number) return false;
t=0;
curbuf=buffer;
endbuf=buffer+frame_num-1;
lost_prob=0;
ippsSet_16s(-1,last_calc,state_number);
ippsZero_32f((float*)len_stat,vec_length+1);
ippsZero_8u(if_calc,state_number);
length=calc->Lengths();
ready=0;
return true;
}
bool Prob_Cache::Detach_Calc(void) {
if (ready!=0) return false;
calc = NULL;
t = 0;
curbuf = NULL;
endbuf = NULL;
lost_prob = 0;
ready = -1;
return true;
}
bool Prob_Cache::Step_Forward(void) {
int i;
if (ready!=0) return false;
if (curbuf>endbuf) {
ippsCopy_32f(curbuf,buffer,vec_length*state_number);
curbuf=buffer;
} else {
curbuf++;
}
for (i=0; i<state_number; i++)
lost_prob+=((last_calc[i]>=t)&&(if_calc[i]==0));
ippsZero_8u(if_calc,state_number);
t++;
return calc->Step_Forward();
}
int Prob_Cache::Get_Probability(int state, float *prob) {
int num=0;
if (last_calc[state]<t) {
num=calc->Obv_Prob_Vec(state,curbuf+vec_length*state,vec_length);
if (num) {
last_calc[state]=t+num-1;
len_stat[num-1]++;
}
}
if_calc[state]=1;
*prob=curbuf[vec_length*state];
return 1;
}
int Prob_Cache::Get_ProbabilityAdd(int state, float *prob) {
if (last_calc[state]<t) {
calc->AddState(t,state,curbuf+vec_length*state,vec_length);
return -1;
}else{
if_calc[state]=1;
*prob=curbuf[vec_length*state];
}
return 1;
}
int Prob_Cache::Get_ProbabilityQueue(int state, float *prob) {
last_calc[state]=t+length[state]-1;
len_stat[length[state]-1]++;
if_calc[state]=1;
*prob=curbuf[vec_length*state];
return 1;
}
void Prob_Cache::Sync(void){
calc->Sync();
return;
}
int Prob_Cache::ReadyState(void){
return calc->ReadyState();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -