22 void altra(
double *x,
double *v,
int n,
double *ind,
int nodes,
double mult)
25 double lambda,twoNorm, ratio;
30 if ((
int) ind[0]==-1){
35 if ((
int) ind[1]!=-1){
36 printf(
"\n Error! \n Check ind");
55 memcpy(x, v,
sizeof(
double) * n);
68 for(j=(
int) ind[3*i]-1;j< (int) ind[3*i+1];j++)
69 twoNorm += x[j] * x[j];
70 twoNorm=sqrt(twoNorm);
72 lambda=mult*ind[3*i+2];
74 ratio=(twoNorm-lambda)/twoNorm;
79 for(j=(
int) ind[3*i]-1;j<(int) ind[3*i+1];j++)
86 for(j=(
int) ind[3*i]-1;j<(int) ind[3*i+1];j++)
92 void altra_mt(
double *X,
double *V,
int n,
int k,
double *ind,
int nodes,
double mult)
96 double *x=(
double *)malloc(
sizeof(
double)*k);
97 double *v=(
double *)malloc(
sizeof(
double)*k);
107 altra(x, v, k, ind, nodes, mult);
127 for(i=0;i < nodes; i++){
132 for(j=(
int) ind[3*i]-1;j< (int) ind[3*i+1];j++)
133 twoNorm += x[j] * x[j];
134 twoNorm=sqrt(twoNorm);
136 twoNorm=twoNorm/ind[3*i+2];
138 if (twoNorm >*lambda2_max )
139 *lambda2_max=twoNorm;
143 double treeNorm(
double *x,
int ldx,
int n,
double *ind,
int nodes){
146 double twoNorm, lambda;
148 double tree_norm = 0;
153 if ((
int) ind[0]==-1){
158 if ((
int) ind[1]!=-1){
159 printf(
"\n Error! \n Check ind");
165 for(j=0;j<n*ldx;j+=ldx){
166 tree_norm+=fabs(x[j]);
169 tree_norm = tree_norm * lambda;
181 for(;i < nodes; i++){
187 int n_in_node = (int) ind[3*i+1] - (
int) ind[3*i]-1;
188 for(j=(
int) ind[3*i]-1;j< (int) ind[3*i]-1 + n_in_node*ldx;j+=ldx)
189 twoNorm += x[j] * x[j];
190 twoNorm=sqrt(twoNorm);
194 tree_norm = tree_norm + lambda*twoNorm;
203 double lambda=0,squaredWeight=0, lambda1,lambda2;
204 double *x=(
double *)malloc(
sizeof(
double)*n);
205 double *ind2=(
double *)malloc(
sizeof(
double)*nodes*3);
212 if ( (
int)ind[0]==-1 )
213 squaredWeight=n*ind[2]*ind[2];
215 squaredWeight=ind[2]*ind[2];
217 for (i=1;i<nodes;i++){
218 squaredWeight+=ind[3*i+2]*ind[3*i+2];
223 lambda=sqrt(lambda/squaredWeight);
233 for(i=0;i<nodes;i++){
235 ind2[3*i+1]=ind[3*i+1];
236 ind2[3*i+2]=ind[3*i+2]*lambda;
241 altra(x, v, n, ind2, nodes);
261 for(i=0;i<nodes;i++){
262 ind2[3*i+2]=ind[3*i+2]*lambda1;
267 altra(x, v, n, ind2, nodes);
295 for(i=0;i<nodes;i++){
296 ind2[3*i+2]=ind[3*i+2]*lambda2;
301 altra(x, v, n, ind2, nodes);
320 while ( fabs(lambda2-lambda1) > lambda2 * 1e-10 ){
324 lambda=(lambda1+lambda2)/2;
328 for(i=0;i<nodes;i++){
329 ind2[3*i+2]=ind[3*i+2]*lambda;
334 altra(x, v, n, ind2, nodes);
369 double *v=(
double *)malloc(
sizeof(
double)*k);
388 if (lambda>lambdaMax)
double treeNorm(double *x, int ldx, int n, double *ind, int nodes)
void computeLambda2Max(double *lambda2_max, double *x, int n, double *ind, int nodes)
void altra(double *x, double *v, int n, double *ind, int nodes, double mult)
double findLambdaMax(double *v, int n, double *ind, int nodes)
double findLambdaMax_mt(double *V, int n, int k, double *ind, int nodes)
void altra_mt(double *X, double *V, int n, int k, double *ind, int nodes, double mult)