summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--c/cartography_from_layers.c66
-rw-r--r--models/correlations/tune_qnn_adaptive.c9
2 files changed, 73 insertions, 2 deletions
diff --git a/c/cartography_from_layers.c b/c/cartography_from_layers.c
new file mode 100644
index 0000000..db95689
--- /dev/null
+++ b/c/cartography_from_layers.c
@@ -0,0 +1,66 @@
+/**
+ *
+ * Compute the cartography of a multiplex network (participation
+ * coefficient vs average degree) starting from the layers
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "utils.h"
+
+
+int main(int argc, char *argv[]){
+
+
+ int i, val, M;
+ unsigned int N, K, *J_slap=NULL, *r_slap=NULL;
+ unsigned int maxN;
+
+ double part;
+
+ unsigned int *k=NULL, *k2=NULL, *tmp;
+
+ FILE *fin;
+
+ maxN = 0;
+
+ M = 0;
+ while(argc-- > 1){
+ fin = openfile_or_exit(argv[argc], "r", 17);
+ M += 1;
+ if (J_slap)
+ free(J_slap);
+ if (r_slap)
+ free(r_slap);
+ J_slap = r_slap = NULL; /* This is somehow inefficient, since we
+ are going to reallocate that memory in
+ a moment....*/
+ read_slap(fin, &K, &N, &J_slap, &r_slap);
+ if (N > maxN){
+ tmp = realloc(k, N * sizeof(unsigned int));
+ VALID_PTR_OR_EXIT(tmp, 7);
+ k = tmp;
+ tmp = realloc(k2, N * sizeof(unsigned int));
+ VALID_PTR_OR_EXIT(tmp, 7);
+ k2 = tmp;
+
+ memset(k+maxN, 0, (N-maxN) * sizeof(unsigned int));
+ memset(k2+maxN, 0, (N-maxN) * sizeof(unsigned int));
+ maxN = N;
+ }
+ for(i=0; i<N; i++){
+ val = r_slap[i+1] - r_slap[i];
+ k[i] += val;
+ k2[i] += val * val;
+ }
+ }
+
+ for(i=0; i<maxN; i++){
+ part = 1.0 * M / (M-1) * (1 - 1.0 * k2[i] / (k[i] * k[i]));
+ printf("%d %f %f %d %d\n", i, 1.0 * k[i]/M, part, k[i], k2[i]);
+ }
+}
+
diff --git a/models/correlations/tune_qnn_adaptive.c b/models/correlations/tune_qnn_adaptive.c
index f645dbe..420d3ef 100644
--- a/models/correlations/tune_qnn_adaptive.c
+++ b/models/correlations/tune_qnn_adaptive.c
@@ -66,7 +66,10 @@ void tune_qnn_adaptive(double *R1, double *R2, int N, int *pairing, double eps,
a = 1.0;
F = 10000;
-
+
+ fit_current_trend(R1, R2, N, pairing, &mu, &a, &err);
+ fprintf(stderr, "Initial mu: %g a: %g corr: %g\n", mu, a, err);
+
//fprintf("%f %f %f %f %f\n", eps, beta, mu_target, act_mu, F);
tot = 0;
@@ -143,7 +146,9 @@ void tune_qnn_adaptive(double *R1, double *R2, int N, int *pairing, double eps,
fit_current_trend(R1, R2, N, pairing, &mu, &dummy_a, &err);
F = fabs(mu - mu_target);
}
-}
+ fit_current_trend(R1, R2, N, pairing, &mu, &a, &err);
+ fprintf(stderr, "Final mu: %g a: %g corr: %g\n", mu, a, err);
+ }
void dump_qnn(double *R1, double *R2, int N, int *pairing){