git-svn-id: https://hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/Rgraphviz@88840 bc3139a8-67e5-0310-9ffc-ced21a209358
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,50 @@ |
1 |
+#include "general.h" |
|
2 |
+#include "SparseMatrix.h" |
|
3 |
+#include "spring_electrical.h" |
|
4 |
+#include "post_process.h" |
|
5 |
+#include "stress_model.h" |
|
6 |
+ |
|
7 |
+void stress_model(int dim, SparseMatrix B, real **x, int maxit_sm, real tol, int *flag){ |
|
8 |
+ int m; |
|
9 |
+ SparseStressMajorizationSmoother sm; |
|
10 |
+ real lambda = 0; |
|
11 |
+ /*int maxit_sm = 1000, i; tol = 0.001*/ |
|
12 |
+ int i; |
|
13 |
+ SparseMatrix A = B; |
|
14 |
+ |
|
15 |
+ if (!SparseMatrix_is_symmetric(A, FALSE) || A->type != MATRIX_TYPE_REAL){ |
|
16 |
+ if (A->type == MATRIX_TYPE_REAL){ |
|
17 |
+ A = SparseMatrix_symmetrize(A, FALSE); |
|
18 |
+ A = SparseMatrix_remove_diagonal(A); |
|
19 |
+ } else { |
|
20 |
+ A = SparseMatrix_get_real_adjacency_matrix_symmetrized(A); |
|
21 |
+ } |
|
22 |
+ } |
|
23 |
+ A = SparseMatrix_remove_diagonal(A); |
|
24 |
+ |
|
25 |
+ *flag = 0; |
|
26 |
+ m = A->m; |
|
27 |
+ if (!x) { |
|
28 |
+ *x = MALLOC(sizeof(real)*m*dim); |
|
29 |
+ srand(123); |
|
30 |
+ for (i = 0; i < dim*m; i++) (*x)[i] = drand(); |
|
31 |
+ } |
|
32 |
+ |
|
33 |
+ sm = SparseStressMajorizationSmoother_new(A, dim, lambda, *x, WEIGHTING_SCHEME_NONE);/* do not under weight the long distances */ |
|
34 |
+ |
|
35 |
+ if (!sm) { |
|
36 |
+ *flag = -1; |
|
37 |
+ goto RETURN; |
|
38 |
+ } |
|
39 |
+ |
|
40 |
+ |
|
41 |
+ SparseStressMajorizationSmoother_smooth(sm, dim, *x, maxit_sm, 0.001); |
|
42 |
+ for (i = 0; i < dim*m; i++) { |
|
43 |
+ (*x)[i] /= sm->scaling; |
|
44 |
+ } |
|
45 |
+ SparseStressMajorizationSmoother_delete(sm); |
|
46 |
+ |
|
47 |
+ RETURN: |
|
48 |
+ if (A != B) SparseMatrix_delete(A); |
|
49 |
+ |
|
50 |
+} |