24 void general_altra(
double *x,
double *v,
int n,
double *G,
double *ind,
int nodes,
double mult)
28 double lambda,twoNorm, ratio;
33 if ((
int) ind[0]==-1){
38 if ((
int) ind[1]!=-1){
39 printf(
"\n Error! \n Check ind");
58 memcpy(x, v,
sizeof(
double) * n);
71 for(j=(
int) ind[3*i]-1;j< (int) ind[3*i+1];j++)
72 twoNorm += x[(
int) G[j]-1 ] * x[(int) G[j]-1 ];
73 twoNorm=sqrt(twoNorm);
75 lambda=mult*ind[3*i+2];
77 ratio=(twoNorm-lambda)/twoNorm;
82 for(j=(
int) ind[3*i]-1;j<(int) ind[3*i+1];j++)
83 x[(
int) G[j]-1 ]*=ratio;
89 for(j=(
int) ind[3*i]-1;j<(int) ind[3*i+1];j++)
95 void general_altra_mt(
double *X,
double *V,
int n,
int k,
double *G,
double *ind,
int nodes,
double mult)
99 double *x=(
double *)malloc(
sizeof(
double)*k);
100 double *v=(
double *)malloc(
sizeof(
double)*k);
110 general_altra(x, v, k, G, ind, nodes, mult);
123 void general_computeLambda2Max(
double *lambda2_max,
double *x,
int n,
double *G,
double *ind,
int nodes)
132 for(i=0;i < nodes; i++){
137 for(j=(
int) ind[3*i]-1;j< (int) ind[3*i+1];j++)
138 twoNorm += x[(
int) G[j]-1 ] * x[(int) G[j]-1 ];
139 twoNorm=sqrt(twoNorm);
141 twoNorm=twoNorm/ind[3*i+2];
143 if (twoNorm >*lambda2_max )
144 *lambda2_max=twoNorm;
148 double general_treeNorm(
double *x,
int ldx,
int n,
double *G,
double *ind,
int nodes)
152 double twoNorm, lambda;
159 if ((
int) ind[0]==-1){
164 if ((
int) ind[1]!=-1){
165 printf(
"\n Error! \n Check ind");
172 tree_norm+=fabs(x[j]);
175 tree_norm=tree_norm * lambda;
187 for(;i < nodes; i++){
193 for(j=(
int) ind[3*i]-1;j< (int) ind[3*i+1];j++)
194 twoNorm += x[(
int) G[j]-1 ] * x[(int) G[j]-1 ];
195 twoNorm=sqrt(twoNorm);
199 tree_norm=tree_norm + lambda*twoNorm;
204 double general_findLambdaMax(
double *v,
int n,
double *G,
double *ind,
int nodes)
208 double lambda=0,squaredWeight=0, lambda1,lambda2;
209 double *x=(
double *)malloc(
sizeof(
double)*n);
210 double *ind2=(
double *)malloc(
sizeof(
double)*nodes*3);
217 if ( (
int)ind[0]==-1 )
218 squaredWeight=n*ind[2]*ind[2];
220 squaredWeight=ind[2]*ind[2];
222 for (i=1;i<nodes;i++){
223 squaredWeight+=ind[3*i+2]*ind[3*i+2];
228 lambda=sqrt(lambda/squaredWeight);
238 for(i=0;i<nodes;i++){
240 ind2[3*i+1]=ind[3*i+1];
241 ind2[3*i+2]=ind[3*i+2]*lambda;
246 general_altra(x, v, n, G, ind2, nodes);
266 for(i=0;i<nodes;i++){
267 ind2[3*i+2]=ind[3*i+2]*lambda1;
272 general_altra(x, v, n, G, ind2, nodes);
300 for(i=0;i<nodes;i++){
301 ind2[3*i+2]=ind[3*i+2]*lambda2;
306 general_altra(x, v, n, G, ind2, nodes);
325 while ( fabs(lambda2-lambda1) > lambda2 * 1e-10 ){
329 lambda=(lambda1+lambda2)/2;
333 for(i=0;i<nodes;i++){
334 ind2[3*i+2]=ind[3*i+2]*lambda;
339 general_altra(x, v, n, G, ind2, nodes);
369 double general_findLambdaMax_mt(
double *V,
int n,
int k,
double *G,
double *ind,
int nodes)
373 double *v=(
double *)malloc(
sizeof(
double)*k);
386 lambda = general_findLambdaMax(v, k, G, ind, nodes);
393 if (lambda>lambdaMax)
405 #endif //USE_GPL_SHOGUN