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

Wrong names in setindex-functions #50

Closed
solliolli opened this issue May 16, 2024 · 1 comment
Closed

Wrong names in setindex-functions #50

solliolli opened this issue May 16, 2024 · 1 comment

Comments

@solliolli
Copy link
Collaborator

solliolli commented May 16, 2024

The setindex-functions for probability and utility matrices throw an error if a non-existent state is given, but all the functions have probability_matrix.nodes[i] when it should be PM or UM, depending on the function.

  • Probability matrices:
    function Base.setindex!(PM::ProbabilityMatrix, p::T, I::Vararg{Union{String, Int},N}) where {N, T<:Real}
    I2 = []
    for i in 1:N
    if isa(I[i], String)
    if get(PM.indices[i], I[i], 0) == 0
    throw(DomainError("Node $(probability_matrix.nodes[i]) does not have state $(I[i])."))
    end
    push!(I2, PM.indices[i][I[i]])
    else
    push!(I2, I[i])
    end
    end
    PM.matrix[I2...] = p
    end
    function Base.setindex!(PM::ProbabilityMatrix{N}, P::Array{T}, I::Vararg{Union{String, Int, Colon}, N}) where {N, T<:Real}
    I2 = []
    for i in 1:N
    if isa(I[i], Colon)
    push!(I2, :)
    elseif isa(I[i], String)
    if get(PM.indices[i], I[i], 0) == 0
    throw(DomainError("Node $(probability_matrix.nodes[i]) does not have state $(I[i])."))
    end
    push!(I2, PM.indices[i][I[i]])
    else
    push!(I2, I[i])
    end
    end
    PM.matrix[I2...] = P
    end
  • Utility matrices:
    function Base.setindex!(UM::UtilityMatrix{N}, y::T, I::Vararg{Union{String, Int},N}) where {N, T<:Real}
    I2 = []
    for i in 1:N
    if isa(I[i], String)
    if get(UM.indices[i], I[i], 0) == 0
    throw(DomainError("Node $(probability_matrix.nodes[i]) does not have state $(I[i])."))
    end
    push!(I2, UM.indices[i][I[i]])
    else
    push!(I2, I[i])
    end
    end
    UM.matrix[I2...] = y
    end
    function Base.setindex!(UM::UtilityMatrix{N}, Y::Array{T}, I::Vararg{Union{String, Int, Colon}, N}) where {N, T<:Real}
    I2 = []
    for i in 1:N
    if isa(I[i], Colon)
    push!(I2, :)
    elseif isa(I[i], String)
    if get(UM.indices[i], I[i], 0) == 0
    throw(DomainError("Node $(probability_matrix.nodes[i]) does not have state $(I[i])."))
    end
    push!(I2, UM.indices[i][I[i]])
    else
    push!(I2, I[i])
    end
    end
    UM.matrix[I2...] = Y
    end
@solliolli
Copy link
Collaborator Author

I'm planning to make a pull request when I have more time, but in case I forget, this is a pretty good first issue for someone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant