Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

remove wrong files

  • Loading branch information...
commit 3815cbb311da8819b686661ce7007a7cb62e0f7a 1 parent 622fa89
Liang Zhang authored
399 src/RLFM-ars-logistic/C/MCEM_EStep_logistic.c~
... ... @@ -1,399 +0,0 @@
1   -/*
2   -To Compile:
3   -R CMD SHLIB util.c MCEM_EStep.c -o MCEM_EStep.so
4   -
5   -*/
6   -
7   -#include <R.h>
8   -#include <Rmath.h>
9   -#include <R_ext/Lapack.h>
10   -#include "util.h"
11   -//#include "logistic.h"
12   -#include "arsspline.h"
13   -
14   -///// centered logistic ars code starts from here
15   -// FUNCTION: mainEffect_condMeanVar
16   -// thisEffIndex: nObs x 1 otherEffIndex: nObs x 1 y_minus_xb_minus_uv: nObs x 1
17   -// fittedEff: nThisEff x 1 otherEff: nOtherEff x 1
18   -// For alpha, call
19   -// mainEffect_condMeanVar(1, user, item, y-xb-uv, g0w, beta, var_y, var_alpha, nObs, nUsers, nItems, sample, NULL, NULL, ...);
20   -// For beta, call
21   -// mainEffect_condMeanVar(1, item, user, y-xb-uv, d0z, alpha, var_y, var_beta, nObs, nItems, nUsers, sample, NULL, NULL, ...);
22   -// Observation index (consider, say, user i) - R indices (starting from 1, NOT 0)
23   -// obsIndex[ oiStart[i]+0 ], ..., obsIndex[ oiStart[i]+oiNum[i]-1 ] are the indices of user i's observations
24   -// in y, x, user, item
25   -void mainEffect_condMeanVarSample_arscid(
26   - // OUTPUT
27   - double* outSample, //int* naccepts,
28   - double* ars_XI, /* ars_ninit X ncov X nThisEff*/
29   - //INPUT
30   - const int* thisEffIndex /*user or item*/, const int* otherEffIndex /*item or user*/,
31   - const double* y, const double* offset, /*xb+uv*/
32   - const double* fittedEff /*g0w or d0z*/,
33   - const double* otherEff /*beta or alpha*/,
34   - const double* var_eff /*var_alpha or var_beta*/,
35   - const int* nObs, const int* nThisEff, const int* nOtherEff,
36   - const int* obsIndex, const int* oiStart, const int* oiNum,
37   - const int* ars_ninit, const double* ars_qcent, const double* ars_xl, const double* ars_xu, const double* ars_alpha,
38   - // OTHER
39   - const int* debug
40   -
41   - ){
42   - int i,j,k,m, thisIndex, otherIndex, oIndex;
43   - //*naccepts = 0;
44   - GetRNGstate();
45   - int neval = 0;
46   - for(i=0; i<*nThisEff; i++){
47   - thisIndex = i+1;
48   - if(oiNum[i]>0){
49   - double* y_thisEff = (double*)calloc(oiNum[i], sizeof(double)); // the observations for this user
50   - double* offset_thisEff = (double*)calloc(oiNum[i], sizeof(double)); // the offsets for this user
51   - double* X = (double*)calloc(oiNum[i], sizeof(double)); // the design matrix nobs*ncov, ncov=1 for main effects
52   - for (j=0;j<oiNum[i];j++)
53   - X[j] = 1;
54   - for(j=0; j<oiNum[i]; j++){
55   - oIndex = obsIndex[R_VEC(oiStart[i]+j)];
56   - otherIndex = otherEffIndex[R_VEC(oIndex)];
57   - if(*debug > 0) CHK_R_INDEX(oIndex, *nObs);
58   - if(*debug > 0) CHK_R_INDEX(otherIndex, *nOtherEff);
59   - if(*debug > 1) if(thisEffIndex[R_VEC(oIndex)] != i+1) error("error in obsIndex, oiStart, oiNum\n");
60   - y_thisEff[j] = y[R_VEC(oIndex)];
61   - offset_thisEff[j] = offset[R_VEC(oIndex)] + otherEff[R_VEC(otherIndex)];
62   - }
63   - //double new_thisEff = 0;
64   - //int accept = 0;
65   - int ncov = 1;
66   - //MHlogistic(&outSample[i], X, y_thisEff, offset_thisEff, &fittedEff[i], var_eff, &oiNum[i], &ncov, &new_thisEff, &accept);
67   - ARSLOGISTICSPLINE(offset_thisEff, &fittedEff[i], var_eff, X, y_thisEff, &ncov, &oiNum[i], &outSample[i], ars_qcent, ars_ninit, ars_ninit, ars_xl, ars_xu, &ars_XI[i*(*ars_ninit)], ars_alpha, &neval);
68   - //printf("%f\n",outSample[i]);
69   - //outSample[i] = new_thisEff;
70   - //if (accept==1) *naccepts = *naccepts + 1;
71   - free(y_thisEff);
72   - free(offset_thisEff);
73   - free(X);
74   - }
75   - }
76   - PutRNGstate();
77   -}
78   -void factor_condMeanVarSample_arscid(
79   - // OUTPUT
80   - double* outSample, //int* naccepts,
81   - double* ars_XI, /* ars_ninit X ncov X nThisEff*/
82   - // INPUT
83   - const int* thisEffIndex /*user or item*/, const int* otherEffIndex /*item or user*/,
84   - const double* y, const double* offset, /*xb+alpha+beta*/
85   - const double* fittedEff /*Gw or Dz*/,
86   - const double* otherEff /*v or u*/,
87   - const double* var_eff /*var_u or var_v*/,
88   - const int* nObs, const int* nThisEff, const int* nOtherEff, const int* nFactors,
89   - const int* obsIndex, const int* oiStart, const int* oiNum,
90   - const int* ars_ninit, const double* ars_qcent, const double* ars_xl, const double* ars_xu, const double* ars_alpha,
91   - // OTHER
92   - const int* debug
93   - ){
94   - int i,j,k,m, thisIndex, otherIndex, oIndex;
95   - int* neval = (int*)calloc(*nFactors,sizeof(double));
96   - //*naccepts = 0;
97   - GetRNGstate();
98   - for(i=0; i<*nThisEff; i++){
99   - thisIndex = i+1;
100   - if(oiNum[i]>0)
101   - {
102   - double* y_thisEff = (double*)calloc(oiNum[i], sizeof(double)); // the observations for this user
103   - double* offset_thisEff = (double*)calloc(oiNum[i], sizeof(double)); // the offsets for this user
104   - double* vj = (double*)calloc(oiNum[i]*(*nFactors), sizeof(double)); // the design matrix nobs*ncov, ncov=nfactors
105   - double* thisEff_i = (double*)calloc((*nFactors),sizeof(double));
106   - //double* new_thisEff_i = (double*)calloc((*nFactors),sizeof(double));
107   - double* fittedEff_i = (double*)calloc((*nFactors),sizeof(double));
108   - double* var_this_eff = (double*)calloc((*nFactors),sizeof(double));
109   -
110   - for (j=0;j<*nFactors;j++)
111   - {
112   - thisEff_i[j] = outSample[C_MAT(i,j,*nThisEff)];
113   - fittedEff_i[j] = fittedEff[C_MAT(i,j,*nThisEff)];
114   - var_this_eff[j] = var_eff[j];
115   - }
116   - for(j=0; j<oiNum[i]; j++){
117   - oIndex = obsIndex[R_VEC(oiStart[i]+j)];
118   - otherIndex = otherEffIndex[R_VEC(oIndex)];
119   - if(*debug > 0) CHK_R_INDEX(oIndex, *nObs);
120   - if(*debug > 0) CHK_R_INDEX(otherIndex, *nOtherEff);
121   - if(*debug > 1) if(thisEffIndex[R_VEC(oIndex)] != i+1) error("error in obsIndex, oiStart, oiNum\n");
122   - y_thisEff[j] = y[R_VEC(oIndex)];
123   - offset_thisEff[j] = offset[R_VEC(oIndex)];
124   - for(k=1; k<=*nFactors; k++) {
125   - vj[R_MAT((j+1),k,oiNum[i])] = otherEff[R_MAT(otherIndex,k,*nOtherEff)];
126   - }
127   - }
128   - //double new_thisEff = 0;
129   - // int accept = 0;
130   - // MHlogistic(thisEff_i, vj, y_thisEff, offset_thisEff, fittedEff_i, var_eff, &oiNum[i], nFactors, new_thisEff_i, &accept);
131   - //for (j=0;j<*nFactors;j++)
132   - // printf("%f ",thisEff_i[j]);
133   - //printf("\n");
134   - ARSLOGISTICSPLINE(offset_thisEff, fittedEff_i, var_this_eff, vj, y_thisEff, nFactors, &oiNum[i], thisEff_i, ars_qcent, ars_ninit, ars_ninit, ars_xl, ars_xu, &ars_XI[i*(*ars_ninit)*(*nFactors)], ars_alpha, neval);
135   -
136   - for (j=0;j<*nFactors;j++)
137   - {
138   - //printf("%f ",thisEff_i[j]);
139   - outSample[C_MAT(i,j,*nThisEff)] = thisEff_i[j];
140   - //if (accept==1) *naccepts = *naccepts + 1;
141   - }
142   - //printf("\n");
143   - free(y_thisEff);
144   - free(offset_thisEff);
145   - free(vj);
146   - free(thisEff_i);
147   - //free(new_thisEff_i);
148   - free(fittedEff_i);
149   - free(var_this_eff);
150   - }
151   - }
152   - PutRNGstate();
153   - free(neval);
154   -}
155   -
156   -
157   -void computeMeanSumvar_arsc(
158   - // OUTPUT
159   - double *mean, double *sumvar,
160   - // INPUT
161   - const double *sum, const double *sos /* sum of squares */, const int length, const int nSamples
162   - ){
163   - int k;
164   - double ratio = ((double)nSamples) / (nSamples - 1.0);
165   - sumvar[0] = 0;
166   - for(k=0; k<length; k++){
167   - mean[k] = sum[k] / nSamples;
168   - sumvar[0] += (sos[k] / (nSamples - 1.0)) - (ratio * mean[k] * mean[k]);
169   - }
170   -}
171   -
172   -void computeMeanSumvarFactor_arsc(
173   - // OUTPUT
174   - double *mean, double *sumvar /* nFactors x 1*/,
175   - // INPUT
176   - const double *sum, const double *sos /* sum of squares */, const int length, const int nFactors, const int nSamples
177   - ){
178   - int k,l;
179   - double ratio = ((double)nSamples) / (nSamples - 1.0);
180   - for (k=0;k<nFactors;k++)
181   - sumvar[k] = 0;
182   - for (l=0; l<nFactors;l++)
183   - for(k=0; k<length; k++){
184   - mean[C_MAT(k,l,length)] = sum[C_MAT(k,l,length)] / nSamples;
185   - sumvar[l] += (sos[C_MAT(k,l,length)] / (nSamples - 1.0)) - (ratio * mean[C_MAT(k,l,length)] * mean[C_MAT(k,l,length)]);
186   - }
187   -}
188   -
189   -void InitializeXI_arsc(double* xi, const int ninit, const int ncov, const int nthisEff, const double xu, const double xl)
190   -{
191   - int i,j,k;
192   - for (i=0;i<nthisEff;i++)
193   - for (j=0;j<ncov;j++)
194   - for (k=0;k<ninit;k++)
195   - {
196   - double tmp = xl + (k + 2.0)*(xu - xl)/(ninit + 1.0);
197   - if (tmp>=xu) tmp = tmp - .1;
198   - if (tmp<=xl) tmp = tmp + .1;
199   - xi[i*(ncov*ninit)+j*ninit+k] = tmp;
200   - }
201   -}
202   -void MCEM_EStep_arscid(
203   - // OUTPUT
204   - double* o_mean /*nObs x 1*/,
205   - double* alpha_mean/*nUsers x 1*/, double* alpha_sumvar/*1x1*/,
206   - double* beta_mean/*nItems x 1*/, double* beta_sumvar/*1x1*/,
207   - double* u_mean/*nUsers x nFactors*/, double* u_sumvar/*nFactors x 1*/,
208   - double* v_mean/*nItems x nFactors*/, double* v_sumvar/*nFactors x 1*/,
209   - double* ars_XI_alpha, double* ars_XI_beta,
210   - double* ars_XI_u, double* ars_XI_v,
211   - //double* acceptrate_maineff, // the overall acceptance rate for main effects
212   - //double* acceptrate_fact, // the overall acceptance rate for factors
213   - // INPUT
214   - const int* nSamples, const int* nBurnin,
215   - const int* user/*nObs x 1*/, const int* item/*nObs x 1*/,
216   - const double* y/*nObs x 1*/, const double* xb/*nObs x 1*/,
217   - const double* g0w/*nUsers x 1*/, const double* d0z/*nItems x 1*/,
218   - const double* Gw/*nUsers x nFactors*/, const double* Dz/*nItems x nFactors*/,
219   - const double* alpha_in/*nUsers x 1*/, const double* beta_in/*nItems x 1*/,
220   - const double* u_in/*nUsers x nFactors*/, const double* v_in/*nItems x nFactors*/,
221   - const double* var_alpha, const double* var_beta,
222   - const double* var_u, const double* var_v, /*nFactors x 1*/
223   - const int* nObs, const int* nUsers, const int* nItems, const int* nFactors,
224   - const int* ars_ninit, const double* ars_qcent, const double* ars_xl, const double* ars_xu, const double* ars_alpha,
225   - // OTHER
226   - const int* debug, const int* main_effects, const int* beta_int, const int* center
227   -
228   - ){
229   - int *obsIndex_user, *oiStart_user, *oiNum_user,
230   - *obsIndex_item, *oiStart_item, *oiNum_item,
231   - s, k, f, user_i, item_j, naccepts;
232   - double *alpha, *beta, *u, *v,
233   - *alpha_sum, *alpha_sos, *beta_sum, *beta_sos, *u_sum, *u_sos, *v_sum, *v_sos,
234   - *temp, *xb_plus_uv, *xb_plus_alpha_beta, uv;
235   - double *ars_xl_v = (double*)calloc(1, sizeof(double));
236   - ars_xl_v[0] = 0;
237   -
238   - // double *ars_XI_alpha, *ars_XI_beta, *ars_XI_u, *ars_XI_v;
239   - //double accept_maineff_denom = 0, accept_maineff_numeri = 0,
240   - // accept_fact_denom = 0, accept_fact_numeri = 0;
241   -
242   -
243   - // Allocate space for sum and sum-of-squares
244   - alpha_sum = (double*)calloc(*nUsers, sizeof(double));
245   - beta_sum = (double*)calloc(*nItems, sizeof(double));
246   - u_sum = (double*)calloc((*nUsers)*(*nFactors), sizeof(double));
247   - v_sum = (double*)calloc((*nItems)*(*nFactors), sizeof(double));
248   - alpha_sos = (double*)calloc(*nUsers, sizeof(double));
249   - beta_sos = (double*)calloc(*nItems, sizeof(double));
250   - u_sos = (double*)calloc((*nUsers)*(*nFactors), sizeof(double));
251   - v_sos = (double*)calloc((*nItems)*(*nFactors), sizeof(double));
252   - // Allocate space for the observation indices
253   - obsIndex_user = (int*)calloc(*nObs, sizeof(int));
254   - oiStart_user = (int*)calloc(*nUsers, sizeof(int));
255   - oiNum_user = (int*)calloc(*nUsers, sizeof(int));
256   - obsIndex_item = (int*)calloc(*nObs, sizeof(int));
257   - oiStart_item = (int*)calloc(*nItems, sizeof(int));
258   - oiNum_item = (int*)calloc(*nItems, sizeof(int));
259   - // Allocate space for XI ars
260   - //ars_XI_alpha = (double*)calloc((*ars_ninit)*(*nUsers), sizeof(double));
261   - //ars_XI_beta = (double*)calloc((*ars_ninit)*(*nItems), sizeof(double));
262   - //ars_XI_u = (double*)calloc((*ars_ninit)*(*nFactors)*(*nUsers), sizeof(double));
263   - //ars_XI_v = (double*)calloc((*ars_ninit)*(*nFactors)*(*nItems), sizeof(double));
264   -
265   - // Allocate temp space
266   - temp = (double*)calloc(*nObs, sizeof(double));
267   -
268   - memset(o_mean,0,(*nObs)*sizeof(double));
269   - // Use the memory space of the output to store the current alpha, beta, u and v
270   - alpha = alpha_mean; beta = beta_mean; u = u_mean; v = v_mean;
271   - // Use the temp space for both xb_plus_uv and xb_plus_alpha_beta
272   - xb_plus_uv = temp;
273   - xb_plus_alpha_beta = temp;
274   -
275   -
276   - // Create Observation indices for users and items
277   - generateObsIndex(obsIndex_user, oiStart_user, oiNum_user, user, nObs, nUsers, debug);
278   - generateObsIndex(obsIndex_item, oiStart_item, oiNum_item, item, nObs, nItems, debug);
279   -
280   - // Initialize alpha, beta, u, v
281   - for(k=0; k<*nUsers; k++) alpha[k] = alpha_in[k];
282   - for(k=0; k<*nItems; k++) beta[k] = beta_in[k];
283   - for(k=0; k<(*nUsers)*(*nFactors); k++) u[k] = u_in[k];
284   - for(k=0; k<(*nItems)*(*nFactors); k++) v[k] = v_in[k];
285   -
286   - // Initialize ars_XI_alpha, etc.
287   - InitializeXI_arsc(ars_XI_alpha, *ars_ninit, 1, *nUsers, *ars_xu, *ars_xl);
288   - InitializeXI_arsc(ars_XI_beta, *ars_ninit, 1, *nItems, *ars_xu, *ars_xl);
289   - InitializeXI_arsc(ars_XI_u, *ars_ninit, *nFactors, *nUsers, *ars_xu, *ars_xl);
290   - InitializeXI_arsc(ars_XI_v, *ars_ninit, *nFactors, *nItems, *ars_xu, *ars_xl_v);
291   -
292   - for(s=0; s<(*nSamples+*nBurnin); s++){
293   -
294   - // Compute xb+uv
295   - for(k=0; k<*nObs; k++){
296   - user_i = user[k]; item_j = item[k];
297   - if(*debug > 0) CHK_R_INDEX(user_i, *nUsers);
298   - if(*debug > 0) CHK_R_INDEX(item_j, *nItems);
299   - uv = 0;
300   - for(f=1; f<=*nFactors; f++) uv += u[R_MAT(user_i,f,*nUsers)] * v[R_MAT(item_j,f,*nItems)];
301   - xb_plus_uv[k] = xb[k] + uv;
302   - }
303   - // Sample alpha
304   - //mainEffect_condMeanVarSample_arsc(alpha, &naccepts, user, item, y, xb_plus_uv, g0w, beta, var_alpha, nObs, nUsers, nItems, obsIndex_user, oiStart_user, oiNum_user, debug);
305   - //accept_maineff_denom += *nUsers; accept_maineff_numeri += naccepts;
306   - mainEffect_condMeanVarSample_arscid(alpha, ars_XI_alpha, user, item, y, xb_plus_uv, g0w, beta, var_alpha, nObs, nUsers, nItems, obsIndex_user, oiStart_user, oiNum_user, ars_ninit, ars_qcent, ars_xl, ars_xu,ars_alpha,debug);
307   - //center
308   - if(*center==1){ center_array(alpha, *nUsers); }
309   - // Sample beta
310   - //mainEffect_condMeanVarSample_arsc(beta, &naccepts, item, user, y, xb_plus_uv, d0z, alpha, var_beta, nObs, nItems, nUsers, obsIndex_item, oiStart_item, oiNum_item, debug);
311   - //accept_maineff_denom += *nItems; accept_maineff_numeri += naccepts;
312   - mainEffect_condMeanVarSample_arscid(beta, ars_XI_beta, item, user, y, xb_plus_uv, d0z, alpha, var_beta, nObs, nItems, nUsers, obsIndex_item, oiStart_item, oiNum_item, ars_ninit, ars_qcent, ars_xl, ars_xu,ars_alpha,debug);
313   - //subtract mean from the betas ...
314   - if(*center==1 && *beta_int==0){ center_array(beta, *nItems); }
315   -
316   - // Compute y - (xb + alpha + beta)
317   - for(k=0; k<*nObs; k++){
318   - user_i = user[k]; item_j = item[k];
319   - if(*debug > 0) CHK_R_INDEX(user_i, *nUsers);
320   - if(*debug > 0) CHK_R_INDEX(item_j, *nItems);
321   - xb_plus_alpha_beta[k] = xb[k] + alpha[R_VEC(user_i)] + beta[R_VEC(item_j)];
322   - }
323   -
324   - if(*main_effects==0){
325   - // Sample u
326   - //factor_condMeanVarSample_arsc(u, &naccepts, user, item, y, xb_plus_alpha_beta, Gw, v, var_u, nObs, nUsers, nItems, nFactors, obsIndex_user, oiStart_user, oiNum_user, debug);
327   - //accept_fact_denom += *nUsers; accept_fact_numeri += naccepts;
328   - factor_condMeanVarSample_arscid(u, ars_XI_u, user, item, y, xb_plus_alpha_beta, Gw, v, var_u, nObs, nUsers, nItems, nFactors, obsIndex_user, oiStart_user, oiNum_user, ars_ninit, ars_qcent, ars_xl, ars_xu,ars_alpha,debug);
329   - if(*center==1){ center_array_2d(u, *nUsers, *nFactors, 2); }
330   - // Sample v
331   - //factor_condMeanVarSample_arsc(v, &naccepts, item, user, y, xb_plus_alpha_beta, Dz, u, var_v, nObs, nItems, nUsers, nFactors, obsIndex_item, oiStart_item, oiNum_item, debug);
332   - //accept_fact_denom += *nItems; accept_fact_numeri += naccepts;
333   - factor_condMeanVarSample_arscid(v, ars_XI_v, item, user, y, xb_plus_alpha_beta, Dz, u, var_v, nObs, nItems, nUsers, nFactors, obsIndex_item, oiStart_item, oiNum_item, ars_ninit, ars_qcent, ars_xl_v, ars_xu,ars_alpha,debug);
334   - //if(*center==1){ center_array_2d(v, *nItems, *nFactors, 2); }
335   - }
336   - // Ignore the first several samples
337   - if(s >= *nBurnin){
338   - // update o
339   - for(k=0; k<*nObs; k++){
340   - user_i = user[k]; item_j = item[k];
341   - if(*debug > 0) CHK_R_INDEX(user_i, *nUsers);
342   - if(*debug > 0) CHK_R_INDEX(item_j, *nItems);
343   - uv = 0;
344   - for(f=1; f<=*nFactors; f++) uv += u[R_MAT(user_i,f,*nUsers)] * v[R_MAT(item_j,f,*nItems)];
345   - double o = alpha[R_VEC(user_i)] + beta[R_VEC(item_j)] + uv;
346   - o_mean[k] += o/(*nSamples);
347   - }
348   - // update alpha
349   - for(k=0; k<*nUsers; k++){
350   - alpha_sum[k] += alpha[k];
351   - alpha_sos[k] += alpha[k]*alpha[k];
352   - }
353   - // update beta
354   - for(k=0; k<*nItems; k++){
355   - beta_sum[k] += beta[k];
356   - beta_sos[k] += beta[k]*beta[k];
357   - }
358   - // update u
359   - for(k=0; k<(*nUsers)*(*nFactors); k++){
360   - u_sum[k] += u[k];
361   - u_sos[k] += u[k]*u[k];
362   - }
363   - // update v
364   - for(k=0; k<(*nItems)*(*nFactors); k++){
365   - v_sum[k] += v[k];
366   - v_sos[k] += v[k]*v[k];
367   - }
368   - }
369   - }
370   -
371   - computeMeanSumvar_arsc(alpha_mean, alpha_sumvar, alpha_sum, alpha_sos, *nUsers, *nSamples);
372   - computeMeanSumvar_arsc(beta_mean, beta_sumvar, beta_sum, beta_sos, *nItems, *nSamples);
373   - computeMeanSumvarFactor_arsc(u_mean, u_sumvar, u_sum, u_sos, *nUsers, *nFactors, *nSamples);
374   - computeMeanSumvarFactor_arsc(v_mean, v_sumvar, v_sum, v_sos, *nItems, *nFactors, *nSamples);
375   - //*acceptrate_maineff = accept_maineff_numeri/accept_maineff_denom;
376   - //*acceptrate_fact = accept_fact_numeri/accept_fact_denom;
377   -
378   - Free(alpha_sos);
379   - Free(beta_sos);
380   - Free(u_sos);
381   - Free(v_sos);
382   - Free(alpha_sum);
383   - Free(beta_sum);
384   - Free(u_sum);
385   - Free(v_sum);
386   -
387   - Free(obsIndex_user);
388   - Free(oiStart_user);
389   - Free(oiNum_user);
390   - Free(obsIndex_item);
391   - Free(oiStart_item);
392   - Free(oiNum_item);
393   - //Free(ars_XI_alpha);
394   - //Free(ars_XI_beta);
395   - //Free(ars_XI_u);
396   - //Free(ars_XI_v);
397   - Free(temp);
398   -}
399   -
500 src/RLFM-ars-logistic/C/util.c~
... ... @@ -1,500 +0,0 @@
1   -
2   -
3   -#include <R.h>
4   -#include <Rmath.h>
5   -#include <R_ext/Lapack.h>
6   -#include <R_ext/Applic.h>
7   -#include "util.h"
8   -
9   -void sym_eigen(const double* x, const int *nrow, double *eigen_val, double *eigen_vec){
10   - char jobz = 'V', uplo = 'L';
11   - double work_size, *work;
12   - int i,j, info, lwork=-1;
13   -
14   - for(i=0; i<(*nrow)*(*nrow); i++) eigen_vec[i] = x[i];
15   -
16   - F77_NAME(dsyev)(&jobz, &uplo, nrow, eigen_vec, nrow, eigen_val, &work_size, &lwork, &info);
17   - if(info != 0) error("error in dsyev(...)");
18   -
19   - lwork = work_size;
20   - work = (double*)Calloc(lwork, double);
21   - F77_NAME(dsyev)(&jobz, &uplo, nrow, eigen_vec, nrow, eigen_val, work, &lwork, &info);
22   - if(info != 0) error("error in dsyev(...)");
23   -
24   - Free(work);
25   -}
26   -
27   -void sym_inv_byCholesky(
28   - double *A /* n x n matrix */, const int *n, const int *check_sym
29   -){
30   - char uplo = 'L';
31   - int info, i, j;
32   -
33   - if(*check_sym > 0) CHK_SYMMETRIC(A, *n, i, j);
34   -
35   - F77_NAME(dpotrf)(&uplo, n, A, n, &info);
36   - if(info != 0) error("error in dpotrf(...): info=%d", info);
37   - F77_NAME(dpotri)(&uplo, n, A, n, &info);
38   - if(info != 0) error("error in dpotri(...): info=%d", info);
39   - for(i=1; i<(*n); i++){
40   - for(j=0; j<i; j++){
41   - A[C_MAT(j,i,*n)] = A[C_MAT(i,j,*n)];
42   - }
43   - }
44   -}
45   -
46   -void sym_inv3DA_byCholesky(
47   - double *invA /* k x n x n matrix */, const double *A /* k x n x n matrix */,
48   - const int *k, const int *n, double *temp /* n x n */, const int *check_sym
49   -){
50   - for(int i=0; i<*k; i++){
51   - for(int j=0; j<*n; j++)
52   - for(int m=0; m<*n; m++) temp[C_MAT(j,m,*n)] = A[C_3DA(i,j,m,*k,*n)];
53   - sym_inv_byCholesky(temp, n, check_sym);
54   -
55   - for(int j=0; j<*n; j++)
56   - for(int m=0; m<*n; m++) invA[C_3DA(i,j,m,*k,*n)] = temp[C_MAT(j,m,*n)];
57   - }
58   -}
59   -
60   -void sum_margin(
61   - // OUTPUT
62   - double *ans,
63   - // INPUT
64   - const double *A, const int *nrow, const int *ncol,
65   - const int *side // side=1: Sum up each row and return a vector with length nrow
66   - // side=2: Sum up each column and return a vector with length ncol
67   -){
68   - int i, j, end;
69   - if((*side) == 1){
70   - end=(*nrow)*(*ncol);
71   - for(i=0; i<*nrow; i++) ans[i] = 0;
72   - for(j=0; j<end; j+=(*nrow))
73   - for(i=0; i<*nrow; i++) ans[i] += A[i+j];
74   - }else if((*side) == 2){
75   - for(j=0; j<*ncol; j++){
76   - end = (j+1)*(*nrow);
77   - ans[j] = 0;
78   - for(i=j*(*nrow); i<end; i++) ans[j] += A[i];
79   - }
80   - }else{
81   - error("Unknown side=%d (please specify side=1 (for rows) or side=2 (for columns)");
82   - }
83   -}
84   -
85   -void center_array(
86   - // Array to be centered
87   - double *x,
88   - // INPUT
89   - int n // array length
90   - ){
91   - // double sum = 0.0;
92   - double mean = x[0];
93   - // get sum
94   - //for(int i=0; i<n; i++){sum += x[i];}
95   - //mean = sum / (double) n;
96   - //get mean ... more stable ...
97   - for(int i=1; i<n; i++){
98   - mean = ( (double) i / (double) (i+1) ) * mean + ( 1.0 / (double) (i+1) ) * x[i];
99   - }
100   -
101   - // Rprintf("mean = %f\n", mean);
102   - // center
103   - for(int i=0; i<n; i++){x[i] -= mean;}
104   -}
105   -
106   -void center_array_2d(
107   - // Array to be centered
108   - double *x,
109   - // INPUT
110   - int n, // number of rows
111   - int m, // number of columns
112   - int dim // 1 for subtracting row mean, 2 for column
113   -){
114   -
115   - double sum, mean;
116   - int i,j;
117   -
118   - if(dim == 1){
119   - for(i = 0; i<n; i++){
120   - sum = 0.0;
121   - for(j = 0; j<m; j++){sum += x[C_MAT(i, j, n)];}
122   - mean = sum / (double) m;
123   - for(j = 0; j<m; j++){x[C_MAT(i, j, n)] -= mean;}
124   - }
125   - } else if(dim == 2){
126   - for(j = 0; j<m; j++){
127   - //sum = 0.0;
128   - //for(i = 0; i<n; i++){sum += x[C_MAT(i, j, n)];}
129   - //mean = sum / (double) n;
130   -
131   - mean = x[C_MAT(0, j, n)];
132   - for(i=1; i<n; i++){
133   - mean = ((double)i/(double)(i+1)) * mean + (1.0/(double) (i+1))*x[C_MAT(i,j,n)];
134   - }
135   - // Rprintf("fac mean col %d = %f\n", j, mean);
136   - for(i = 0; i<n; i++){x[C_MAT(i, j, n)] -= mean;}
137   - }
138   -
139   - }
140   -}
141   -
142   -void center_array_online(
143   - // Array to be centered
144   - double *x,
145   - // INPUT
146   - int n, // array length
147   - int * oiNum
148   - ){
149   - // double sum = 0.0;
150   - double mean = 0.0;
151   - int nav = 0;
152   - // get sum
153   - //for(int i=0; i<n; i++){sum += x[i];}
154   - //mean = sum / (double) n;
155   - //get mean ... more stable ...
156   - for(int i=0; i<n; i++){
157   - if(oiNum[i]>0){
158   - mean = ( (double) nav / (double) (nav+1) ) * mean + \
159   - ( 1.0 / (double) (nav+1) ) * x[i];
160   - nav += 1;
161   - }
162   - }
163   -
164   - // Rprintf("mean = %f\n", mean);
165   - // center
166   - for(int i=0; i<n; i++){
167   - if(oiNum[i]>0){
168   - x[i] -= mean;
169   - }
170   - }
171   -}
172   -
173   -void center_array_2d_online(
174   - // Array to be centered
175   - double *x,
176   - // INPUT
177   - int n, // number of rows
178   - int m, // number of columns
179   - int dim, // 1 for subtracting row mean, 2 for column
180   - int * oiNum
181   -){
182   -
183   - double sum, mean;
184   - int i,j;
185   - int nav;
186   -
187   - // dim == 1 is broken!!!
188   - if(dim == 1){
189   - for(i = 0; i<n; i++){
190   - if(oiNum[i]>0){
191   - sum = 0.0;
192   - for(j = 0; j<m; j++){sum += x[C_MAT(i, j, n)];}
193   - mean = sum / (double) m;
194   - for(j = 0; j<m; j++){x[C_MAT(i, j, n)] -= mean;}
195   - }
196   - }
197   - } else if(dim == 2){
198   - for(j = 0; j<m; j++){
199   - //sum = 0.0;
200   - //for(i = 0; i<n; i++){sum += x[C_MAT(i, j, n)];}
201   - //mean = sum / (double) n;
202   - nav = 0;
203   - mean = 0.0;
204   - for(i=0; i<n; i++){
205   - if(oiNum[i]>0){
206   - mean = ((double)nav/(double)(nav+1)) * mean + \
207   - (1.0/(double) (nav+1))*x[C_MAT(i,j,n)];
208   - nav += 1;
209   - }
210   - }
211   - // Rprintf("fac mean col %d = %f\n", j, mean);
212   - for(i = 0; i<n; i++){
213   - if(oiNum[i]>0){
214   - x[C_MAT(i, j, n)] -= mean;
215   - }
216   - }
217   - }
218   -
219   - }
220   -}
221   -
222   -
223   -void print_vector(char* prefix, double* vector, int length){
224   - int i;
225   - if(prefix != NULL) Rprintf("%s", prefix);
226   - for(i=0; i<length; i++)
227   - Rprintf("%f ", vector[i]);
228   - Rprintf("\n");
229   -}
230   -
231   -void print_matrix(const char* prefix, const double* matrix, const int nrow, const int ncol){
232   - int i,j;
233   - for(i=0; i<nrow; i++){
234   - if(prefix != NULL) Rprintf("%s", prefix);
235   - for(j=0; j<ncol; j++)
236   - Rprintf("%f\t", matrix[C_MAT(i,j,nrow)]);
237   - Rprintf("\n");
238   - }
239   -}
240   -
241   -// The intput/output are all R indices (start from 1, NOT 0)
242   -void generateObsIndex(
243   - //OUTPUT
244   - int* obsIndex, // E.g., consider user i
245   - int* start, // y[ obsIndex[ start[i]+(0:(num[i]-1)) ] ]
246   - int* num, // are the observations of user i
247   - //INPUT
248   - const int* effIndex /* user or item */,
249   - const int* nObs, const int* nEff,
250   - //OTHER
251   - const int* debug
252   -){
253   - int *ind, i, j, cIndex, eIndex, oIndex;
254   - ind = (int*)Calloc(*nEff, int);
255   -
256   - for(i=0; i<*nObs; i++){
257   - eIndex = effIndex[i];
258   - if(*debug > 0){
259   - CHK_R_INDEX(eIndex, *nEff);
260   - }
261   - num[R_VEC(eIndex)]++;
262   - }
263   -
264   - start[0] = 1; ind[0] = 1;
265   - for(i=1; i<*nEff; i++){
266   - start[i] = start[i-1]+num[i-1];
267   - ind[i] = start[i];
268   - }
269   -
270   - for(i=0; i<*nObs; i++){
271   - cIndex = R_VEC(effIndex[i]);
272   - obsIndex[R_VEC(ind[cIndex])] = i+1;
273   - ind[cIndex]++;
274   - }
275   -
276   - if(*debug > 0){
277   - for(i=0; i<*nEff; i++){
278   - if(ind[i] != start[i]+num[i]) error("logical error (level 1)");
279   - if(*debug > 1){
280   - for(j=0; j<num[i]; j++){
281   - oIndex = obsIndex[R_VEC(start[i]+j)];
282   - if(effIndex[R_VEC(oIndex)] != i+1)
283   - error("logical error (level 2)");
284   - }
285   - }
286   - }
287   - }
288   -
289   - Free(ind);
290   -}
291   -
292   -#define stepredn 0.2
293   -#define acctol 0.0001
294   -#define reltest 10.0
295   -#define _(A) A
296   -
297   -static double * vect(int n)
298   -{
299   - return (double *)R_alloc(n, sizeof(double));
300   -}
301   -
302   -int nParam_debug = 0;
303   -double* gr_debug = NULL;
304   -
305   -void my_cgmin(int n, double *Bvec, double *X, double *Fmin,
306   - optimfn fminfn, optimgr fmingr, int *fail,
307   - double abstol, double intol, void *ex, int type, int trace,
308   - int *fncount, int *grcount, int maxit)
309   -{
310   - Rboolean accpoint;
311   - double *c, *g, *t;
312   - int count, cycle, cyclimit;
313   - double f;
314   - double G1, G2, G3, gradproj;
315   - int funcount=0, gradcount=0, i;
316   - double newstep, oldstep, setstep, steplength=1.0;
317   - double tol;
318   -
319   - if (maxit <= 0) {
320   - *Fmin = fminfn(n, Bvec, ex);
321   - *fncount = *grcount = 0;
322   - *fail = FALSE;
323   - return;
324   - }
325   - if (trace) {
326   - Rprintf(" Conjugate gradients function minimizer\n");
327   - switch (type) {
328   - case 1: Rprintf("Method: Fletcher Reeves\n"); break;
329   - case 2: Rprintf("Method: Polak Ribiere\n"); break;
330   - case 3: Rprintf("Method: Beale Sorenson\n"); break;
331   - default:
332   - error(_("unknown 'type' in CG method of optim"));
333   - }
334   - }
335   - c = vect(n); g = vect(n); t = vect(n);
336   -
337   - // DEBUG
338   - nParam_debug = n;
339   - gr_debug = g;
340   - // END
341   -
342   - print_vector("INITIAL: ", gr_debug, nParam_debug);
343   -
344   - setstep = 1.7;
345   - *fail = 0;
346   - cyclimit = n;
347   - tol = intol * n * sqrt(intol);
348   -
349   - if (trace) Rprintf("tolerance used in gradient test=%g\n", tol);
350   - f = fminfn(n, Bvec, ex);
351   - print_vector("AFTER fminfn IN cgmin: ", gr_debug, nParam_debug);
352   - if (!R_FINITE(f)) {
353   - error(_("Function cannot be evaluated at initial parameters"));
354   - } else {
355   - *Fmin = f;
356   - funcount = 1;
357   - gradcount = 0;
358   - do {
359   - for (i = 0; i < n; i++) {
360   - t[i] = 0.0;
361   - c[i] = 0.0;
362   - }
363   - cycle = 0;
364   - oldstep = 1.0;
365   - count = 0;
366   - do {
367   - cycle++;
368   - if (trace) {
369   - Rprintf("gradcount=%d, funcount=%d, Fmin=%f\n", gradcount, funcount, *Fmin);
370   - Rprintf("parameters:\n");
371   - for (i = 1; i <= n; i++) {
372   - Rprintf("%10.5f ", Bvec[i - 1]);
373   - if (i / 7 * 7 == i && i < n)
374   - Rprintf("\n");
375   - }
376   - Rprintf("\n");
377   - }
378   - gradcount++;
379   - if (gradcount > maxit) {
380   - *fncount = funcount;
381   - *grcount = gradcount;
382   - *fail = 1;
383   - return;
384   - }
385   - if (trace) {
386   - Rprintf("BEFORE: gradient:\n");
387   - for (i = 1; i <= n; i++) {
388   - Rprintf("%10.5f ", g[i - 1]);
389   - if (i / 7 * 7 == i && i < n)
390   - Rprintf("\n");
391   - }
392   - Rprintf("\n");
393   - }
394   - fmingr(n, Bvec, g, ex);
395   - if (trace) {
396   - Rprintf("AFTER: gradient:\n");
397   - for (i = 1; i <= n; i++) {
398   - Rprintf("%10.5f ", g[i - 1]);
399   - if (i / 7 * 7 == i && i < n)
400   - Rprintf("\n");
401   - }
402   - Rprintf("\n");
403   - }
404   - G1 = 0.0;
405   - G2 = 0.0;
406   - for (i = 0; i < n; i++) {
407   - X[i] = Bvec[i];
408   - switch (type) {
409   -
410   - case 1: /* Fletcher-Reeves */
411   - G1 += g[i] * g[i];
412   - G2 += c[i] * c[i];
413   - break;
414   -
415   - case 2: /* Polak-Ribiere */
416   - G1 += g[i] * (g[i] - c[i]);
417   - G2 += c[i] * c[i];
418   - break;
419   -
420   - case 3: /* Beale-Sorenson */
421   - G1 += g[i] * (g[i] - c[i]);
422   - G2 += t[i] * (g[i] - c[i]);
423   - break;
424   -
425   - default:
426   - error(_("unknown type in CG method of optim"));
427   - }
428   - c[i] = g[i];
429   - }
430   - if (G1 > tol) {
431   - if (G2 > 0.0)
432   - G3 = G1 / G2;
433   - else
434   - G3 = 1.0;
435   - gradproj = 0.0;
436   - for (i = 0; i < n; i++) {
437   - t[i] = t[i] * G3 - g[i];
438   - gradproj += t[i] * g[i];
439   - }
440   - steplength = oldstep;
441   -
442   - accpoint = FALSE;
443   - do {
444   - count = 0;
445   - for (i = 0; i < n; i++) {
446   - Bvec[i] = X[i] + steplength * t[i];
447   - if (reltest + X[i] == reltest + Bvec[i])
448   - count++;
449   - }
450   - if (count < n) { /* point is different */
451   - f = fminfn(n, Bvec, ex);
452   - funcount++;
453   - accpoint = (R_FINITE(f) &&
454   - f <= *Fmin + gradproj * steplength * acctol);
455   -
456   - if (!accpoint) {
457   - steplength *= stepredn;
458   - if (trace){
459   - Rprintf("* %f\n", f);
460   - }
461   - } else *Fmin = f; /* we improved, so update value */
462   - }
463   - } while (!(count == n || accpoint));
464   - if (count < n) {
465   - newstep = 2 * (f - *Fmin - gradproj * steplength);
466   - if (newstep > 0) {
467   - newstep = -(gradproj * steplength * steplength / newstep);
468   - for (i = 0; i < n; i++)
469   - Bvec[i] = X[i] + newstep * t[i];
470   - *Fmin = f;
471   - f = fminfn(n, Bvec, ex);
472   - funcount++;
473   - if (f < *Fmin) {
474   - *Fmin = f;
475   - if (trace) Rprintf("i< ");
476   - } else { /* reset Bvec to match lowest point */
477   - if (trace) Rprintf("i> ");
478   - for (i = 0; i < n; i++)
479   - Bvec[i] = X[i] + steplength * t[i];
480   - }
481   - }
482   - }
483   - }
484   - oldstep = setstep * steplength;
485   - if (oldstep > 1.0)
486   - oldstep = 1.0;
487   - } while ((count != n) && (G1 > tol) && (cycle != cyclimit));
488   -
489   - } while ((cycle != 1) ||
490   - ((count != n) && (G1 > tol) && *Fmin > abstol));
491   -
492   - }
493   - if (trace) {
494   - Rprintf("Exiting from conjugate gradients minimizer\n");
495   - Rprintf(" %d function evaluations used\n", funcount);
496   - Rprintf(" %d gradient evaluations used\n", gradcount);
497   - }
498   - *fncount = funcount;
499   - *grcount = gradcount;
500   -}
130 src/RLFM-ars-logistic/C/util.h~
... ... @@ -1,130 +0,0 @@
1   -
2   -#include <R_ext/Applic.h>
3   -
4   -#define R_VEC(i) (i-1)
5   -#define R_MAT(i,j,nrow) (((j-1)*(nrow))+(i-1))
6   -#define R_3DA(i,j,k,nrow,ncol) ((((k-1)*(ncol))+(j-1))*(nrow) + (i-1))
7   -
8   -#define C_MAT(i,j,nrow) (((j)*(nrow))+(i))
9   -#define C_3DA(i,j,k,nrow,ncol) ((((k)*(ncol))+(j))*(nrow) + (i))
10   -
11   -#define CHK_C_INDEX(index, num) if(index < 0 || index >= num) error("index out of bound: index=%d, bound=%d", index, num)
12   -#define CHK_C_INDEX_2D(row_i, col_j, nrow, ncol) if(row_i < 0 || row_i >= nrow || col_j < 0 || col_j >= ncol) error("index out of bound: i=%d, j=%d nrow=%d ncol=%d", row_i, col_j, nrow, ncol)
13   -
14   -#define CHK_R_INDEX(index, num) if(index < 1 || index > num) error("index out of bound: index=%d, bound=%d", index, num)
15   -#define CHK_SYMMETRIC(A, nrow, i, j) for(i=0; i<nrow; i++) for(j=0; j<i; j++) if(abs(A[C_MAT(i,j,nrow)] - A[C_MAT(j,i,nrow)]) > 1e-10) error("A symmetric matrix is not symmetric: %f vs %f, diff=%e", A[C_MAT(i,j,nrow)], A[C_MAT(j,i,nrow)], A[C_MAT(i,j,nrow)] - A[C_MAT(j,i,nrow)])
16   -
17   -#define MAX(x,y) (x) > (y) ? (x) : (y)
18   -
19   -typedef struct {
20   - int* user/*nObs x 1*/; int* item/*nObs x 1*/;
21   - double* y/*nObs x 1*/; double* xb/*nObs x 1*/;
22   - double* g0w/*nUsers x 1*/; double* d0z/*nItems x 1*/;
23   - double* Gw/*nUsers x nFactors*/; double* Dz/*nItems x nFactors*/;
24   - double* var_y; double* var_alpha; double* var_beta; double* var_u; double* var_v;
25   - int* nObs; int* nUsers; int* nItems; int* nFactors;
26   - int* User_obsIndex; int* User_oiStart; int* User_oiNum;
27   - int* Item_obsIndex; int* Item_oiStart; int* Item_oiNum;
28   - int* debug;
29   -} RegParams;
30   -
31   -typedef struct {
32   - int* user/*nObs x 1*/; int* item/*nObs x 1*/;
33   - double* y/*nObs x 1*/; double* xb/*nObs x 1*/;
34   - double* g0w/*nUsers x 1*/; double* d0z/*nItems x 1*/;
35   - double* Gw/*nUsers x nFactors*/; double* Dz/*nItems x nFactors*/;
36   - double* var_y; double* var_alpha; double* var_beta; double* var_u; double* var_v;
37   - int* nObs; int* nUsers; int* nItems; int* nFactors;
38   - int* nVar_y; int* nVar_alpha; int* nVar_beta; int* nVar_u; int* nVar_v;
39   - double* inv_var_u; double* inv_var_v;
40   - int* User_obsIndex; int* User_oiStart; int* User_oiNum;
41   - int* Item_obsIndex; int* Item_oiStart; int* Item_oiNum;
42   - int* debug;
43   -} RegParams2;
44   -
45   -typedef struct {
46   - int* user/*nObs x 1*/; int* item/*nObs x 1*/;
47   - double* y/*nObs x 1*/; double* x/*nObs x nJointFeatures*/;
48   - double* w/*nUsers x nUserFeatures*/; double* z/*nItems x nItemFeatures*/;
49   - double* lambda_b; double* lambda_g0; double* lambda_d0; double* lambda_G; double* lambda_D;
50   - int* nObs; int* nUsers; int* nItems; int* nFactors;
51   - int* nJointFeatures; int* nUserFeatures; int* nItemFeatures;
52   - int* debug;
53   -} RegInputFeatureOnly;
54   -
55   -// Matrix inversion (only for a symmetric matrix)
56   -void sym_inv_byCholesky(double *A /* n x n matrix */, const int *n, const int *check_sym);
57   -
58   -// Matrix inversion (only for a symmetric matrix) 3-dim array
59   -void sym_inv3DA_byCholesky(
60   - double *invA /* k x n x n matrix */, const double *A /* k x n x n matrix */,
61   - const int *k, const int *n, double *temp /* n x n */, const int *check_sym
62   -);
63   -
64   -// Compute the eigenvalues and vectors of a symmetric matrix x
65   -void sym_eigen(const double* x, const int *nrow, double *eigen_val, double *eigen_vec);
66   -
67   -void sum_margin(
68   - // OUTPUT
69   - double *ans,
70   - // INPUT
71   - const double *A, const int *nrow, const int *ncol,
72   - const int *side // side=1: Sum up each row and return a vector with length nrow
73   - // side=2: Sum up each column and return a vector with length ncol
74   -);
75   -
76   -void center_array(
77   - // Array to be centered
78   - double *x,
79   - // INPUT
80   - int n // array length
81   -);
82   -
83   -void center_array_2d(
84   - // Array to be centered
85   - double *x,
86   - // INPUT
87   - int n, // number of rows
88   - int m, // number of columns
89   - int dim // 1 for subtracting row mean, 2 for column
90   -);
91   -
92   -void center_array_online(
93   - // Array to be centered
94   - double *x,
95   - // INPUT
96   - int n, // array length
97   - int * oiNum
98   -);
99   -
100   -void center_array_2d_online(
101   - // Array to be centered
102   - double *x,
103   - // INPUT
104   - int n, // number of rows
105   - int m, // number of columns
106   - int dim, // 1 for subtracting row mean, 2 for column
107   - int * oiNum
108   -);
109   -
110   -
111   -// The intput/output are all R indices (start from 1, NOT 0)
112   -void generateObsIndex(
113   - //OUTPUT
114   - int* obsIndex, // E.g., consider user i
115   - int* start, // y[ obsIndex[ start[i]+(0:(num[i]-1)) ] ]
116   - int* num, // are the observations of user i
117   - //INPUT
118   - const int* effIndex /* user or item */,
119   - const int* nObs, const int* nEff,
120   - //OTHER
121   - const int* debug
122   -);
123   -
124   -void print_vector(char* prefix, double* vector, int length);
125   -void print_matrix(const char* prefix, const double* matrix, const int nrow, const int ncol);
126   -
127   -void my_cgmin(int n, double *Bvec, double *X, double *Fmin,
128   - optimfn fminfn, optimgr fmingr, int *fail,
129   - double abstol, double intol, void *ex, int type, int trace,
130   - int *fncount, int *grcount, int maxit);

0 comments on commit 3815cbb

Please sign in to comment.
Something went wrong with that request. Please try again.