GenSVM
gensvm_zv.c
Go to the documentation of this file.
1 
33 #include "gensvm_zv.h"
34 
50 void gensvm_calculate_ZV(struct GenModel *model, struct GenData *data,
51  double *ZV)
52 {
53  if (data->Z == NULL)
54  gensvm_calculate_ZV_sparse(model, data, ZV);
55  else
56  gensvm_calculate_ZV_dense(model, data, ZV);
57 }
58 
71  struct GenData *data, double *ZV)
72 {
73  long i, j, jj, jj_start, jj_end, K,
74  n_row = data->spZ->n_row;
75  double z_ij;
76 
77  K = model->K;
78 
79  long *Zia = data->spZ->ia;
80  long *Zja = data->spZ->ja;
81  double *vals = data->spZ->values;
82 
83  for (i=0; i<n_row; i++) {
84  jj_start = Zia[i];
85  jj_end = Zia[i+1];
86 
87  for (jj=jj_start; jj<jj_end; jj++) {
88  j = Zja[jj];
89  z_ij = vals[jj];
90 
91  cblas_daxpy(K-1, z_ij, &model->V[j*(K-1)], 1,
92  &ZV[i*(K-1)], 1);
93  }
94  }
95 }
96 
109  struct GenData *data, double *ZV)
110 {
111  // use n from data, assume m and K are the same between model and data
112  long n = data->n;
113  long m = model->m;
114  long K = model->K;
115 
116  cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, n, K-1, m+1,
117  1.0, data->Z, m+1, model->V, K-1, 0, ZV, K-1);
118 }
long * ja
column indices, should be of length nnz
Definition: gensvm_sparse.h:67
double * Z
Definition: gensvm_base.h:68
double * V
augmented weight matrix
Definition: gensvm_base.h:115
A structure to represent the data.
Definition: gensvm_base.h:57
double * values
actual nonzero values, should be of length nnz
Definition: gensvm_sparse.h:63
A structure to represent a single GenSVM model.
Definition: gensvm_base.h:92
Header file for gensvm_zv.c.
long K
number of classes in the dataset
Definition: gensvm_base.h:95
void gensvm_calculate_ZV_dense(struct GenModel *model, struct GenData *data, double *ZV)
Compute the product Z*V for when Z is a dense matrix.
Definition: gensvm_zv.c:108
void gensvm_calculate_ZV(struct GenModel *model, struct GenData *data, double *ZV)
Wrapper around sparse/dense versions of this function.
Definition: gensvm_zv.c:50
long n
number of instances
Definition: gensvm_base.h:60
void gensvm_calculate_ZV_sparse(struct GenModel *model, struct GenData *data, double *ZV)
Compute the product Z*V for when Z is a sparse matrix.
Definition: gensvm_zv.c:70
long m
number of predictor variables in the dataset
Definition: gensvm_base.h:99
long * ia
cumulative row lengths, should be of length n_row+1
Definition: gensvm_sparse.h:65
struct GenSparse * spZ
sparse representation of the augmented data matrix
Definition: gensvm_base.h:71
long n_row
number of rows of the original matrix
Definition: gensvm_sparse.h:58