Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow even more complex bindings #133

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/fitting/binding.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ function _construct_bound_mapping(bindings, parameter_count)
parameter_mapping[b[1]][b[2]] = reference[2]

# mark for removal: find the parameter index in the global array
N = sum(length(parameter_mapping[q]) for q = 1:b[1]-1)
N = if b[1] > 1
sum(length(parameter_mapping[q]) for q = 1:b[1]-1)
else
0
end
index = N + b[2]
push!(remove, index)

Expand Down
3 changes: 1 addition & 2 deletions src/xspec-models/convolutional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,4 @@ function XS_Kerrconv(;
XS_Kerrconv(Index1, Index2, r_br_g, a, Incl, Rin_ms, Rout_ms)
end

export XS_CalculateFlux,
XS_Kerrconv
export XS_CalculateFlux, XS_Kerrconv
19 changes: 19 additions & 0 deletions test/fitting/test-binding.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,22 @@ new_bindings = SpectralFitting.adjust_free_bindings(prob.model, prob.bindings)
@test new_bindings == [[1 => 1, 2 => 3]]

# TODO: free parameters should not be allowed to bind to frozen parameters


# can we bind parameters within the same model
prob = FittingProblem(model1 => dummy_data1)
bind!(prob, 1 => :K_1, 1 => :a_1)
_, mapping = SpectralFitting._build_parameter_mapping(prob.model, prob.bindings)
@test mapping == ([1, 1, 2],)

# can we bind parameters within the same model
model1.a_2.frozen = false
prob = FittingProblem(model1 => dummy_data1, model1 => dummy_data1)
bind!(prob, 1 => :K_1, 2 => :K_1)
bind!(prob, 1 => :a_1, 2 => :a_1)
bind!(prob, 1 => :K_2, 2 => :K_2)
bind!(prob, 1 => :a_2, 2 => :a_2)
bind!(prob, 1 => :K_1, 1 => :a_1)
details(prob)
params, mapping = SpectralFitting._build_parameter_mapping(prob.model, prob.bindings)
@test mapping == ([1, 1, 2, 3], [1, 2, 2, 3])
Loading