~ubuntu-branches/ubuntu/trusty/igraph/trusty-proposed

« back to all changes in this revision

Viewing changes to src/revolver_ml_cit.c

  • Committer: Package Import Robot
  • Author(s): Mathieu Malaterre
  • Date: 2013-05-27 14:01:54 UTC
  • mfrom: (4.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20130527140154-oxwwmr0gj3kdy4ol
Tags: 0.6.5-2
Upload to sid

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: C -*-  */
2
2
/* 
3
3
   IGraph library.
4
 
   Copyright (C) 2007  Gabor Csardi <csardi@rmki.kfki.hu>
5
 
   MTA RMKI, Konkoly-Thege Miklos st. 29-33, Budapest 1121, Hungary
 
4
   Copyright (C) 2007-2012  Gabor Csardi <csardi.gabor@gmail.com>
 
5
   334 Harvard street, Cambridge, MA 02139 USA
6
6
   
7
7
   This program is free software; you can redistribute it and/or modify
8
8
   it under the terms of the GNU General Public License as published by
21
21
 
22
22
*/
23
23
 
24
 
#include "igraph.h"
25
 
#include "memory.h"
26
 
#include "random.h"
 
24
#include "igraph_revolver.h"
 
25
#include "igraph_memory.h"
 
26
#include "igraph_random.h"
27
27
#include "config.h"
28
28
#include "igraph_math.h"
 
29
#include "igraph_interface.h"
 
30
#include "igraph_progress.h"
 
31
#include "igraph_interrupt_internal.h"
 
32
#include "igraph_structural.h"
 
33
#include "igraph_nongraph.h"
 
34
#include "igraph_stack.h"
29
35
 
30
36
#include <math.h>
31
37
 
150
156
 
151
157
  igraph_i_revolver_ml_D_data_t *data=extra;
152
158
  
153
 
  if (!igraph_vector_is_equal(par, &data->lastparam)) {
 
159
  if (!igraph_vector_all_e(par, &data->lastparam)) {
154
160
    igraph_i_revolver_ml_D_eval(par, data);
155
161
  }
156
162
 
157
163
  return data->lastf;
158
164
}
159
165
 
160
 
/* This function gievs the gradient of the objective function at
 
166
/* This function gives the gradient of the objective function at
161
167
   the supplied parameter vector. Called by the optimizer.
162
168
*/
163
169
 
167
173
 
168
174
  igraph_i_revolver_ml_D_data_t *data=extra;
169
175
 
170
 
  if (!igraph_vector_is_equal(par, &data->lastparam)) {
 
176
  if (!igraph_vector_all_e(par, &data->lastparam)) {
171
177
    igraph_i_revolver_ml_D_eval(par, data);
172
178
  }
173
179
 
313
319
  igraph_vector_destroy(&res);
314
320
  IGRAPH_FINALLY_CLEAN(1);
315
321
 
316
 
  return 0;
 
322
  return ret;
317
323
}
318
324
 
319
325
/* These functions assemble the A(d)=d^alpha+a kernel function and 
374
380
  igraph_vector_destroy(&res);
375
381
  IGRAPH_FINALLY_CLEAN(1);
376
382
  
377
 
  return 0;
 
383
  return ret;
378
384
}
379
385
 
380
386
/*------------------------------------------------------------------*/
497
503
                                        void *extra) {
498
504
 
499
505
  igraph_i_revolver_ml_DE_data_t *data=extra;
500
 
  long int i;
501
506
  
502
 
  if (!igraph_vector_is_equal(par, &data->lastparam)) {
 
507
  if (!igraph_vector_all_e(par, &data->lastparam)) {
503
508
    igraph_i_revolver_ml_DE_eval(par, data);
504
509
  }
505
510
 
507
512
    IGRAPH_WARNING("Target function evaluated to non-finite value.");
508
513
  }
509
514
  
510
 
  printf("eval (");
511
 
  for (i=0; i<igraph_vector_size(par); i++) {
512
 
    printf("%f ", VECTOR(*par)[i]);
513
 
  }
514
 
  printf(" ): ");
515
 
  printf("%g\n", data->lastf);
 
515
  /* printf("eval ("); */
 
516
  /* for (i=0; i<igraph_vector_size(par); i++) { */
 
517
  /*   printf("%f ", VECTOR(*par)[i]); */
 
518
  /* } */
 
519
  /* printf(" ): "); */
 
520
  /* printf("%g\n", data->lastf); */
516
521
  return data->lastf;
517
522
}
518
523
 
521
526
                                igraph_vector_t *res, void *extra) {
522
527
 
523
528
  igraph_i_revolver_ml_DE_data_t *data=extra;
524
 
  long int i;
525
529
  
526
 
  if (!igraph_vector_is_equal(par, &data->lastparam)) {
 
530
  if (!igraph_vector_all_e(par, &data->lastparam)) {
527
531
    igraph_i_revolver_ml_DE_eval(par, data);
528
532
  }
529
533
  
530
534
  igraph_vector_update(res, &data->lastgrad);
531
 
  printf("derivative (");
532
 
  for (i=0; i<igraph_vector_size(par); i++) {
533
 
    printf("%f ", VECTOR(*par)[i]);
534
 
  }
535
 
  printf(" ): ");
536
 
  for (i=0; i<igraph_vector_size(res); i++) {
537
 
    printf("%f ", VECTOR(*res)[i]);
538
 
  }
539
 
  printf("\n");
 
535
  /* printf("derivative ("); */
 
536
  /* for (i=0; i<igraph_vector_size(par); i++) { */
 
537
  /*   printf("%f ", VECTOR(*par)[i]); */
 
538
  /* } */
 
539
  /* printf(" ): "); */
 
540
  /* for (i=0; i<igraph_vector_size(res); i++) { */
 
541
  /*   printf("%f ", VECTOR(*res)[i]); */
 
542
  /* } */
 
543
  /* printf("\n"); */
540
544
}
541
545
 
542
546
void igraph_i_revolver_ml_DE_free(igraph_vector_ptr_t *ptr) {
625
629
  igraph_matrix_destroy(&info.A_vect);
626
630
  IGRAPH_FINALLY_CLEAN(10);
627
631
 
628
 
  return 0;
 
632
  return ret;
629
633
}
630
634
 
631
635
igraph_real_t igraph_i_revolver_ml_DE_alpha_a_f(const igraph_vector_t *var,
697
701
  igraph_vector_destroy(&res);
698
702
  IGRAPH_FINALLY_CLEAN(1);
699
703
 
700
 
  return 0;
 
704
  return ret;
701
705
}
702
706
 
703
707
/*------------------------------------------------------------------*/
849
853
                                        void *extra) {
850
854
 
851
855
  igraph_i_revolver_ml_AD_data_t *data=extra;
852
 
  long int i;
853
856
  
854
 
  if (!igraph_vector_is_equal(par, &data->lastparam)) {
 
857
  if (!igraph_vector_all_e(par, &data->lastparam)) {
855
858
    igraph_i_revolver_ml_AD_eval(par, data);
856
859
  }
857
860
 
859
862
    IGRAPH_WARNING("Target function evaluated to non-finite value.");
860
863
  }
861
864
  
862
 
  printf("eval (");
863
 
  for (i=0; i<igraph_vector_size(par); i++) {
864
 
    printf("%f ", VECTOR(*par)[i]);
865
 
  }
866
 
  printf(" ): ");
867
 
  printf("%g\n", data->lastf);
 
865
  /* printf("eval ("); */
 
866
  /* for (i=0; i<igraph_vector_size(par); i++) { */
 
867
  /*   printf("%f ", VECTOR(*par)[i]); */
 
868
  /* } */
 
869
  /* printf(" ): "); */
 
870
  /* printf("%g\n", data->lastf); */
868
871
  return data->lastf;
869
872
}
870
873
 
873
876
                                igraph_vector_t *res, void *extra) {
874
877
 
875
878
  igraph_i_revolver_ml_AD_data_t *data=extra;
876
 
  long int i;
877
879
  
878
 
  if (!igraph_vector_is_equal(par, &data->lastparam)) {
 
880
  if (!igraph_vector_all_e(par, &data->lastparam)) {
879
881
    igraph_i_revolver_ml_AD_eval(par, data);
880
882
  }
881
883
  
882
884
  igraph_vector_update(res, &data->lastgrad);
883
 
  printf("derivative (");
884
 
  for (i=0; i<igraph_vector_size(par); i++) {
885
 
    printf("%f ", VECTOR(*par)[i]);
886
 
  }
887
 
  printf(" ): ");
888
 
  for (i=0; i<igraph_vector_size(res); i++) {
889
 
    printf("%f ", VECTOR(*res)[i]);
890
 
  }
891
 
  printf("\n");
 
885
  /* printf("derivative ("); */
 
886
  /* for (i=0; i<igraph_vector_size(par); i++) { */
 
887
  /*   printf("%f ", VECTOR(*par)[i]); */
 
888
  /* } */
 
889
  /* printf(" ): "); */
 
890
  /* for (i=0; i<igraph_vector_size(res); i++) { */
 
891
  /*   printf("%f ", VECTOR(*res)[i]); */
 
892
  /* } */
 
893
  /* printf("\n"); */
892
894
}
893
895
 
894
896
void igraph_i_revolver_ml_AD_free(igraph_vector_ptr_t *ptr) {
973
975
  igraph_matrix_destroy(&info.A_vect);
974
976
  IGRAPH_FINALLY_CLEAN(11);
975
977
 
976
 
  return 0;
 
978
  return ret;
977
979
}
978
980
 
979
981
igraph_real_t igraph_i_revolver_ml_AD_alpha_a_beta_f(const igraph_vector_t *var,
1291
1293
                                         void *extra) {
1292
1294
 
1293
1295
  igraph_i_revolver_ml_ADE_data_t *data=extra;
1294
 
  long int i;
1295
1296
  
1296
 
  if (!igraph_vector_is_equal(par, &data->lastparam)) {
 
1297
  if (!igraph_vector_all_e(par, &data->lastparam)) {
1297
1298
    igraph_i_revolver_ml_ADE_eval(par, data);
1298
1299
  }
1299
1300
 
1301
1302
    IGRAPH_WARNING("Target function evaluated to non-finite value.");
1302
1303
  }
1303
1304
  
1304
 
  printf("eval (");
1305
 
  for (i=0; i<igraph_vector_size(par); i++) {
1306
 
    printf("%f ", VECTOR(*par)[i]);
1307
 
  }
1308
 
  printf(" ): ");
1309
 
  printf("%g\n", data->lastf);
 
1305
  /* printf("eval ("); */
 
1306
  /* for (i=0; i<igraph_vector_size(par); i++) { */
 
1307
  /*   printf("%f ", VECTOR(*par)[i]); */
 
1308
  /* } */
 
1309
  /* printf(" ): "); */
 
1310
  /* printf("%g\n", data->lastf); */
1310
1311
  return data->lastf;
1311
1312
}
1312
1313
 
1315
1316
                                 igraph_vector_t *res, void *extra) {
1316
1317
 
1317
1318
  igraph_i_revolver_ml_ADE_data_t *data=extra;
1318
 
  long int i;
1319
1319
  
1320
 
  if (!igraph_vector_is_equal(par, &data->lastparam)) {
 
1320
  if (!igraph_vector_all_e(par, &data->lastparam)) {
1321
1321
    igraph_i_revolver_ml_ADE_eval(par, data);
1322
1322
  }
1323
1323
  
1324
1324
  igraph_vector_update(res, &data->lastgrad);
1325
 
  printf("derivative (");
1326
 
  for (i=0; i<igraph_vector_size(par); i++) {
1327
 
    printf("%f ", VECTOR(*par)[i]);
1328
 
  }
1329
 
  printf(" ): ");
1330
 
  for (i=0; i<igraph_vector_size(res); i++) {
1331
 
    printf("%f ", VECTOR(*res)[i]);
1332
 
  }
1333
 
  printf("\n");
 
1325
  /* printf("derivative ("); */
 
1326
  /* for (i=0; i<igraph_vector_size(par); i++) { */
 
1327
  /*   printf("%f ", VECTOR(*par)[i]); */
 
1328
  /* } */
 
1329
  /* printf(" ): "); */
 
1330
  /* for (i=0; i<igraph_vector_size(res); i++) { */
 
1331
  /*   printf("%f ", VECTOR(*res)[i]); */
 
1332
  /* } */
 
1333
  /* printf("\n"); */
1334
1334
}
1335
1335
 
1336
1336
void igraph_i_revolver_ml_ADE_free(igraph_vector_ptr_t *ptr) {
1420
1420
  igraph_array3_destroy(&info.A_vect);
1421
1421
  IGRAPH_FINALLY_CLEAN(10);
1422
1422
 
1423
 
  return 0;
 
1423
  return ret;
1424
1424
}
1425
1425
 
1426
1426
igraph_real_t igraph_i_revolver_ml_ADE_alpha_a_beta_f(const igraph_vector_t *var,
3069
3069
  
3070
3070
  for (t=0; t<no_of_nodes; t++) {
3071
3071
    long int n, nneis;
3072
 
    IGRAPH_CHECK(igraph_adjacent(graph, &neis, t, IGRAPH_OUT));
 
3072
    IGRAPH_CHECK(igraph_incident(graph, &neis, t, IGRAPH_OUT));
3073
3073
    nneis=igraph_vector_size(&neis);    
3074
3074
    
3075
3075
    IGRAPH_ALLOW_INTERRUPTION();
3167
3167
  
3168
3168
  for (t=0; t<no_of_nodes; t++) {
3169
3169
    long int n, nneis;
3170
 
    IGRAPH_CHECK(igraph_adjacent(graph, &neis, t, IGRAPH_OUT));
 
3170
    IGRAPH_CHECK(igraph_incident(graph, &neis, t, IGRAPH_OUT));
3171
3171
    nneis=igraph_vector_size(&neis);
3172
3172
    
3173
3173
    IGRAPH_ALLOW_INTERRUPTION();
3269
3269
  
3270
3270
  for (t=0; t<no_of_nodes; t++) {
3271
3271
    long int n, nneis;
3272
 
    IGRAPH_CHECK(igraph_adjacent(graph, &neis, t, IGRAPH_OUT));
 
3272
    IGRAPH_CHECK(igraph_incident(graph, &neis, t, IGRAPH_OUT));
3273
3273
    nneis=igraph_vector_size(&neis);
3274
3274
    
3275
3275
    IGRAPH_ALLOW_INTERRUPTION();
3345
3345
  
3346
3346
  for (t=0; t<no_of_nodes; t++) {
3347
3347
    long int n, nneis;
3348
 
    IGRAPH_CHECK(igraph_adjacent(graph, &neis, t, IGRAPH_OUT));
 
3348
    IGRAPH_CHECK(igraph_incident(graph, &neis, t, IGRAPH_OUT));
3349
3349
    nneis=igraph_vector_size(&neis);
3350
3350
 
3351
3351
    IGRAPH_ALLOW_INTERRUPTION();
3442
3442
    long int n, nneis;
3443
3443
    long int tcat=VECTOR(*gcats)[t];
3444
3444
    igraph_vector_view(&gpar, &MATRIX(*par,0,tcat), parlen);
3445
 
    IGRAPH_CHECK(igraph_adjacent(graph, &neis, t, IGRAPH_OUT));
 
3445
    IGRAPH_CHECK(igraph_incident(graph, &neis, t, IGRAPH_OUT));
3446
3446
    nneis=igraph_vector_size(&neis);
3447
3447
    
3448
3448
    IGRAPH_ALLOW_INTERRUPTION();