60 long i, j, k, jj_start, jj_end, jj;
61 double cmin, cmax, value, rnd;
62 double *col_min = NULL,
69 if (from_model == NULL) {
70 col_min =
Calloc(
double, m+1);
71 col_max =
Calloc(
double, m+1);
72 for (j=0; j<m+1; j++) {
74 col_max[j] = -1.0e100;
77 if (data->
Z == NULL) {
79 long *visit_count =
Calloc(
long, m+1);
81 jj_start = data->
spZ->
ia[i];
82 jj_end = data->
spZ->
ia[i+1];
83 for (jj=jj_start; jj<jj_end; jj++) {
84 j = data->
spZ->
ja[jj];
87 col_min[j] =
minimum(col_min[j], value);
88 col_max[j] =
maximum(col_max[j], value);
93 for (j=0; j<m+1; j++) {
94 if (visit_count[j] < n) {
95 col_min[j] =
minimum(col_min[j], 0.0);
96 col_max[j] =
maximum(col_max[j], 0.0);
102 for (i=0; i<
n; i++) {
103 for (j=0; j<m+1; j++) {
105 col_min[j] =
minimum(col_min[j], value);
106 col_max[j] =
maximum(col_max[j], value);
110 for (j=0; j<m+1; j++) {
111 cmin = (fabs(col_min[j]) < 1e-10) ? -1 : col_min[j];
112 cmax = (fabs(col_max[j]) < 1e-10) ? 1 : col_max[j];
113 for (k=0; k<K-1; k++) {
114 rnd = ((double) rand()) / ((
double) RAND_MAX);
115 value = 1.0/cmin + (1.0/cmax - 1.0/cmin)*rnd;
122 for (i=0; i<m+1; i++) {
123 for (j=0; j<K-1; j++) {
167 groups[data->
y[i]-1]++;
169 model->
rho[i] = ((
double) n)/((double) (
170 groups[data->
y[i]-1]*K));
173 err(
"[GenSVM Error]: Unknown weight specification.\n");
#define Calloc(type, size)
long * ja
column indices, should be of length nnz
void err(const char *fmt,...)
Parse a formatted string and write it to standard error.
#define matrix_get(M, cols, i, j)
void gensvm_initialize_weights(struct GenData *data, struct GenModel *model)
Initialize instance weights.
int weight_idx
which weights to use (1 = unit, 2 = group)
double * V
augmented weight matrix
long * y
array of class labels, 1..K
A structure to represent the data.
double * values
actual nonzero values, should be of length nnz
A structure to represent a single GenSVM model.
long n
number of instances in the dataset
double * rho
vector of instance weights
long K
number of classes in the dataset
long m
number of predictors (width of RAW)
#define matrix_set(M, cols, i, j, val)
Header file for gensvm_init.c.
long n
number of instances
long * ia
cumulative row lengths, should be of length n_row+1
struct GenSparse * spZ
sparse representation of the augmented data matrix
Header file for gensvm_print.c.
void gensvm_init_V(struct GenModel *from_model, struct GenModel *to_model, struct GenData *data)
Seed the matrix V from an existing model or using rand.