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

Rule extraction print_rules error attempting to access 1-element Vector{Float64} at index [2] #900

Closed
Zapiano opened this issue Nov 20, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Zapiano
Copy link
Collaborator

Zapiano commented Nov 20, 2024

Apparently all rules that have two conditions (e.g., if A > x and B <= y) also have two consequents, and if they have only one condition (e.g., if A > x) they also have only one consequent (and that's what is causing this error). This is weird and it could mean one (or more) of the following things:

  1. My interpretation of what a consequent means was wrong
  2. The values that we are getting and that we are calling "consequent" is actually something else
  3. There's a bug in SIRUS

This needs to be investigated (and the bug fixed).

Since I remember getting one condition rules in the past and not having this issue, so I'm leaning towards option (3)...

The code needed to generate this:

# Supposing you have loaded a `dom`, sampled some `scens` and have a result set `rs`

# Extract some metric
stac = ADRIA.metrics.scenario_total_cover(rs)

# Cluster
n_clusters = 6
clusters_stac = ADRIA.analysis.cluster_scenarios(
    stac[timeinterval, :],
    n_clusters;
    distance=:euclidean)
highest_clusters(x) = x .>= x .∈ [sort(x; rev=true)[1:2]]
target_stac = ADRIA.analysis.find_scenarios(
    stac[timeinterval, :], clusters_stac, highest_clusters
)

# Select 
ms = ADRIA.model_spec(dom)
fields_iv =
    ADRIA.component_params(rs, [Intervention, SeedCriteriaWeights])[
        .!ADRIA.component_params(rs, [Intervention, SeedCriteriaWeights]).is_constant, :
    ].fieldname
scens_iv = scens[:, fields_iv]

max_rules = 20
rules_iv = ADRIA.analysis.cluster_rules(target_stac, scens, max_rules; lambda=1e-3)
ADRIA.analysis.print_rules(rules_iv)

And the error message is:

ERROR: BoundsError: attempt to access 1-element Vector{Float64} at index [2]
Stacktrace:
  [1] throw_boundserror(A::Vector{Float64}, I::Tuple{Int64})
    @ Base .\essentials.jl:14
  [2] getindex
    @ .\essentials.jl:916 [inlined]
  [3] consequent
    @ C:\Users\pribeiro\AIMS\Code\ADRIA.jl\src\analysis\rule_extraction.jl:105 [inlined]
  [4] (::ADRIA.analysis.var"#rule_string#93"{…})(rule::ADRIA.analysis.Rule{…})
    @ ADRIA.analysis C:\Users\pribeiro\AIMS\Code\ADRIA.jl\src\analysis\rule_extraction.jl:101
etc
@Zapiano Zapiano added the bug Something isn't working label Nov 20, 2024
@Zapiano Zapiano closed this as completed Nov 20, 2024
@Zapiano
Copy link
Collaborator Author

Zapiano commented Nov 20, 2024

Closed as this was actually caused by a change in #899 and was already fixed there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant