Skip to content

Commit 4b7cdd0

Browse files
committed
Also update this file.
1 parent 394c62c commit 4b7cdd0

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

misc/experimental/dual_solution_manual_cgc.jl

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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
3442
end
3543
if 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
319327
end
320328

321-
rows, cols = hessian_structure_duality(auxdata)
329+
rows, cols = hessian_structure_duality_cgc(auxdata)
322330
cind = CartesianIndex.(rows, cols)
323331
values = zeros(length(cind))
324332

0 commit comments

Comments
 (0)