@@ -25,12 +25,20 @@ if map_size == 4
2525 graph = create_graph (param, 4 , 4 , type = " map" )
2626 # Customize graph
2727 graph[:Zjn ] = fill (0.1 , graph[:J ], param[:N ])
28- Ni = find_node (graph, 2 , 3 )
29- graph[:Zjn ][Ni, 1 ] = 2
30- Ni = find_node (graph, 2 , 1 )
31- graph[:Zjn ][Ni, 2 ] = 1
32- Ni = find_node (graph, 4 , 4 )
33- graph[:Zjn ][Ni, 3 ] = 1
28+ if param[:N ] == 3
29+ Ni = find_node (graph, 2 , 3 )
30+ graph[:Zjn ][Ni, 1 ] = 2
31+ Ni = find_node (graph, 2 , 1 )
32+ graph[:Zjn ][Ni, 2 ] = 1
33+ Ni = find_node (graph, 4 , 4 )
34+ graph[:Zjn ][Ni, 3 ] = 1
35+ else
36+ using Random: rand
37+ for i in 1 : param[:N ]
38+ Ni = find_node (graph, rand ((1 , 2 , 3 , 4 )), rand ((1 , 2 , 3 , 4 )))
39+ graph[:Zjn ][Ni, i] = rand () * 2
40+ end
41+ end
3442end
3543if map_size == 3
3644 graph = create_graph (param, 3 , 3 , type = " map" )
@@ -172,12 +180,12 @@ sum(abs.(gradient_duality_cgc(x0, auxdata) ./ ForwardDiff.gradient(objective, x0
172180
173181
174182# Now the Hessian
175- function hessian_structure_duality (auxdata)
183+ function hessian_structure_duality_cgc (auxdata)
176184 graph = auxdata. graph
177185 param = auxdata. param
178186
179187 # Create the Hessian structure
180- H_structure = tril (repeat (sparse (I (graph. J)), param. N, param. N) + kron (sparse (I (param. N)), sparse (graph. adjacency)))
188+ H_structure = tril (repeat (sparse (I (graph. J)), param. N, param. N) + kron (sparse (ones (Int, param . N, param . N)), sparse (graph . adjacency))) # tril(repeat(sparse(I(graph.J)), param.N, param.N) + kron(sparse( I(param.N)), sparse(graph.adjacency)))
181189
182190 # Get the row and column indices of non-zero elements
183191 rows, cols, _ = findnz (H_structure)
@@ -318,7 +326,7 @@ function hessian_duality_cgc(
318326 return values
319327end
320328
321- rows, cols = hessian_structure_duality (auxdata)
329+ rows, cols = hessian_structure_duality_cgc (auxdata)
322330cind = CartesianIndex .(rows, cols)
323331values = zeros (length (cind))
324332
0 commit comments