22 void general_altra(
double *x,
double *v,
int n,
double *G,
double *ind,
int nodes,
double mult)
26 double lambda,twoNorm, ratio;
31 if ((
int) ind[0]==-1){
36 if ((
int) ind[1]!=-1){
37 printf(
"\n Error! \n Check ind");
56 memcpy(x, v,
sizeof(
double) * n);
69 for(j=(
int) ind[3*i]-1;j< (int) ind[3*i+1];j++)
70 twoNorm += x[(
int) G[j]-1 ] * x[(int) G[j]-1 ];
71 twoNorm=sqrt(twoNorm);
73 lambda=mult*ind[3*i+2];
75 ratio=(twoNorm-lambda)/twoNorm;
80 for(j=(
int) ind[3*i]-1;j<(int) ind[3*i+1];j++)
81 x[(
int) G[j]-1 ]*=ratio;
87 for(j=(
int) ind[3*i]-1;j<(int) ind[3*i+1];j++)
93 void general_altra_mt(
double *X,
double *V,
int n,
int k,
double *G,
double *ind,
int nodes,
double mult)
97 double *x=(
double *)malloc(
sizeof(
double)*k);
98 double *v=(
double *)malloc(
sizeof(
double)*k);
130 for(i=0;i < nodes; i++){
135 for(j=(
int) ind[3*i]-1;j< (int) ind[3*i+1];j++)
136 twoNorm += x[(
int) G[j]-1 ] * x[(int) G[j]-1 ];
137 twoNorm=sqrt(twoNorm);
139 twoNorm=twoNorm/ind[3*i+2];
141 if (twoNorm >*lambda2_max )
142 *lambda2_max=twoNorm;
150 double twoNorm, lambda;
157 if ((
int) ind[0]==-1){
162 if ((
int) ind[1]!=-1){
163 printf(
"\n Error! \n Check ind");
170 tree_norm+=fabs(x[j]);
173 tree_norm=tree_norm * lambda;
185 for(;i < nodes; i++){
191 for(j=(
int) ind[3*i]-1;j< (int) ind[3*i+1];j++)
192 twoNorm += x[(
int) G[j]-1 ] * x[(int) G[j]-1 ];
193 twoNorm=sqrt(twoNorm);
197 tree_norm=tree_norm + lambda*twoNorm;
206 double lambda=0,squaredWeight=0, lambda1,lambda2;
207 double *x=(
double *)malloc(
sizeof(
double)*n);
208 double *ind2=(
double *)malloc(
sizeof(
double)*nodes*3);
215 if ( (
int)ind[0]==-1 )
216 squaredWeight=n*ind[2]*ind[2];
218 squaredWeight=ind[2]*ind[2];
220 for (i=1;i<nodes;i++){
221 squaredWeight+=ind[3*i+2]*ind[3*i+2];
226 lambda=sqrt(lambda/squaredWeight);
236 for(i=0;i<nodes;i++){
238 ind2[3*i+1]=ind[3*i+1];
239 ind2[3*i+2]=ind[3*i+2]*lambda;
264 for(i=0;i<nodes;i++){
265 ind2[3*i+2]=ind[3*i+2]*lambda1;
298 for(i=0;i<nodes;i++){
299 ind2[3*i+2]=ind[3*i+2]*lambda2;
323 while ( fabs(lambda2-lambda1) > lambda2 * 1e-10 ){
327 lambda=(lambda1+lambda2)/2;
331 for(i=0;i<nodes;i++){
332 ind2[3*i+2]=ind[3*i+2]*lambda;
371 double *v=(
double *)malloc(
sizeof(
double)*k);
391 if (lambda>lambdaMax)
void general_altra(double *x, double *v, int n, double *G, double *ind, int nodes, double mult)
double general_treeNorm(double *x, int ldx, int n, double *G, double *ind, int nodes)
void general_altra_mt(double *X, double *V, int n, int k, double *G, double *ind, int nodes, double mult)
double general_findLambdaMax_mt(double *V, int n, int k, double *G, double *ind, int nodes)
void general_computeLambda2Max(double *lambda2_max, double *x, int n, double *G, double *ind, int nodes)
double general_findLambdaMax(double *v, int n, double *G, double *ind, int nodes)