Skip to content

Commit

Permalink
Merge pull request #2 from wichtounet/master
Browse files Browse the repository at this point in the history
Fix casts
  • Loading branch information
wichtounet committed Feb 25, 2015
2 parents 335d3bb + 17ac4df commit d1ec763
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/initialization_model.c
Expand Up @@ -50,7 +50,7 @@ void model_initialization(model_t* model, uint8_t nGaussians, uint8_t nDimension
for (int i = 0; i < 2; i++)
model->normalisation[i] = (double*)calloc(model->numberDimensions, sizeof(double));

model->list_D = malloc((model->numberStates - 2)*sizeof(double));
model->list_D = (double*)malloc((model->numberStates - 2)*sizeof(double));
if (!expanded)
for (int i = 0; i < model->numberStates - 2; i++)
model->list_D[i] = 1;
Expand Down
8 changes: 4 additions & 4 deletions src/test_histogram.c
Expand Up @@ -16,7 +16,7 @@ void test_histogram(model_t * model, double ** test_vect, int sample_length, int
// pre-processing operations
for (int i = 0; i < model->numberDimensions; i++)
for (int j = 0; j < sample_length; j++)
test_vect[i][j] = test_vect[i][j] + rand_num(2 * model->noise) - model->noise;
test_vect[i][j] = test_vect[i][j] + rand_num(2 * model->noise) - model->noise;

// normalization
for (int pos = 0; pos < sample_length; pos++)
Expand All @@ -28,8 +28,8 @@ void test_histogram(model_t * model, double ** test_vect, int sample_length, int
for (int nC = 0; nC < NClasses; nC++){

// parameter initialization
int *X = calloc(sample_length, sizeof(int));
double *Pvit = calloc(1, sizeof(double));
int *X = (int*)calloc(sample_length, sizeof(int));
double *Pvit = (double*)calloc(1, sizeof(double));

// computation of the X and Prob double
viterbi_log(model, test_vect, sample_length, X, Pvit);
Expand All @@ -53,4 +53,4 @@ void test_histogram(model_t * model, double ** test_vect, int sample_length, int

free(Pvit_t);

}
}
4 changes: 2 additions & 2 deletions src/test_matrix.c
Expand Up @@ -16,8 +16,8 @@ int test_matrix(model_t* foo_mat, double **Test_Vect, int T, int NClasses, int *
//struct Matrix mat_class = foo_mat[nC];

// parameter initialization
int *X = calloc(T, sizeof(int));
double *Pvit = calloc(1, sizeof(double));
int *X = (int*)calloc(T, sizeof(int));
double *Pvit = (double*)calloc(1, sizeof(double));

// computation of the X and Prob double
viterbi_log(foo_mat, Test_Vect, T, X, Pvit);
Expand Down
4 changes: 2 additions & 2 deletions src/viterbi_end.c
Expand Up @@ -21,7 +21,7 @@ void maxx(double *Ar, int dim, double *val, int *pos){
void viterbi_end(double *FI, int *XX, double *A_Vect, double *LogPdf, double *Pvit, int N, int T){

// end of viterbi
double *temp = calloc(N - 2, sizeof(double));
double *temp = (double*)calloc(N - 2, sizeof(double));
int n;
for (n = 1; n < (N - 1); n++){
if (A_Vect[(N - 1)*N + n] == 0)
Expand All @@ -33,7 +33,7 @@ void viterbi_end(double *FI, int *XX, double *A_Vect, double *LogPdf, double *Pv


// Allocation of memory
int *max_pos = malloc(sizeof(int));
int *max_pos = (int*)malloc(sizeof(int));
maxx(temp, N - 2, Pvit, max_pos);


Expand Down
38 changes: 19 additions & 19 deletions src/viterbi_log.c
Expand Up @@ -9,34 +9,34 @@
#include "../include/viterbi_end.h"

void viterbi_log(model_t* mat_class, double **Test_Vect, int T, int *X, double *Pvit){

int N = mat_class->numberStates;
int N_exp = mat_class->numberStates_exp;
int D = mat_class->numberDimensions;
int K = mat_class->numberGaussians;

double *LogPdf = calloc(T*(N_exp - 2), sizeof(double));
double *LogPdf = (double*)calloc(T*(N_exp - 2), sizeof(double));
int n, d, t, k, cnt;
cnt = 0;
for (n = 1; n < N - 1; n++){

double * Mu_Vect_Array = malloc(D*K*sizeof(double));
double * Sigma_Vect_Array = malloc(D*K*sizeof(double));
double * Test_Vect_Array = malloc(D*T*sizeof(double));
double * PComp_Vect_Array = malloc(K*sizeof(double));
double * Mu_Vect_Array = (double*)malloc(D*K*sizeof(double));
double * Sigma_Vect_Array = (double*)malloc(D*K*sizeof(double));
double * Test_Vect_Array = (double*)malloc(D*T*sizeof(double));
double * PComp_Vect_Array = (double*)malloc(K*sizeof(double));

for (d = 0; d < D; d++){
for (k = 0; k < K; k++){
Mu_Vect_Array[k + d*K] = mat_class->mu[d][n][k];
Sigma_Vect_Array[k + d*K] = mat_class->sigma[d][n][k];
}
for (t = 0; t < T; t++)
Test_Vect_Array[t + d*T] = Test_Vect[d][t];
Test_Vect_Array[t + d*T] = Test_Vect[d][t];
}
for (k = 0; k < K; k++)
PComp_Vect_Array[k] = mat_class->weights[n][k];

double *Log = calloc(T, sizeof(double));
double *Log = (double*)calloc(T, sizeof(double));

// compute the distribution
wdensity(Mu_Vect_Array, Sigma_Vect_Array, PComp_Vect_Array, Test_Vect_Array, Log, D, N, K, T);
Expand All @@ -55,16 +55,16 @@ void viterbi_log(model_t* mat_class, double **Test_Vect, int T, int *X, double *

// de-alloc the memory
free(Log);
}
}

int n1, n2;
double * A_Vect_Array = malloc(N_exp*N_exp*sizeof(double));
double * A_Vect_Array = (double*)malloc(N_exp*N_exp*sizeof(double));
for (n1 = 0; n1 < N_exp; n1++)
for (n2 = 0; n2 < N_exp; n2++)
A_Vect_Array[n1 + n2*N_exp] = mat_class->transition[n1][n2];
double * FI = calloc(N_exp*T, sizeof(double));
int * XX = calloc(N_exp*T, sizeof(int));

double * FI = (double*)calloc(N_exp*T, sizeof(double));
int * XX = (int*)calloc(N_exp*T, sizeof(int));

viterbi_init(FI, A_Vect_Array, LogPdf, N_exp, T);

Expand All @@ -77,16 +77,16 @@ void viterbi_log(model_t* mat_class, double **Test_Vect, int T, int *X, double *
printf("\n");
}
*/
viterbi_end(FI, XX, A_Vect_Array, LogPdf, Pvit, N_exp, T);

viterbi_end(FI, XX, A_Vect_Array, LogPdf, Pvit, N_exp, T);

free(LogPdf);
free(A_Vect_Array);
free(FI);

// backtrace of states and probabilities
X[T - 1] = XX[N_exp*T - 1];
//Prob[T - 1] = log(A_Vect_Array[X[T - 1]+ N*(N-1)]);
//Prob[T - 1] = log(A_Vect_Array[X[T - 1]+ N*(N-1)]);
for (t = T - 2; t > -1; t--){
X[t] = XX[(t + 1)*N_exp + X[(t + 1)] - 1];
//Prob[t] = log(A_Vect_Array[X[t] -1 + N*(X[t+1] - 1)]);
Expand All @@ -95,8 +95,8 @@ void viterbi_log(model_t* mat_class, double **Test_Vect, int T, int *X, double *
free(XX);

if (expanded){
// transform the expanded in normal
double * cumsum_List_D = malloc((N - 2 + 1)*sizeof(double));
// transform the expanded in normal
double * cumsum_List_D = (double*)malloc((N - 2 + 1)*sizeof(double));
cumsum_List_D[0] = 1;
for (int i = 0; i < N - 2; i++){
cumsum_List_D[i + 1] = cumsum_List_D[i] + mat_class->list_D[i];
Expand Down
10 changes: 5 additions & 5 deletions src/wdensity.c
Expand Up @@ -9,8 +9,8 @@ void wdensity(double *Mu_Vect, double *Sigma_Vect, double *PComp_Vect, double *T
// Parameter initialization
double logDetSigma, mahalaD, maxll, temp;
int k, t, d;
double *LOG = malloc(T * K * sizeof(double));
double *LOG_Array = malloc(T * K* sizeof(double));
double *LOG = (double*)malloc(T * K * sizeof(double));
double *LOG_Array = (double*)malloc(T * K* sizeof(double));

// first cycle
for (k = 0; k < K; k++)
Expand Down Expand Up @@ -47,14 +47,14 @@ void wdensity(double *Mu_Vect, double *Sigma_Vect, double *PComp_Vect, double *T

LOGPDF[t] = log(LOGPDF[t]) + maxll; //BUG


}

// free the memory
free(LOG);
free(LOG_Array);

return;


}

0 comments on commit d1ec763

Please sign in to comment.