Skip to content

Commit

Permalink
Fixes #97, adds inbounds to main actionmodel loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
zeyus committed Apr 16, 2024
1 parent 09812f3 commit ed8782a
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions src/fitting/create_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,24 +143,38 @@ Create a Turing model object used for fitting an ActionModels agent.
#If there is only a single action
if !multiple_actions

#If the action isn't missing, or if missing actions are to be imputed
if !ismissing(actions[group][timestep]) || impute_missing_actions
#Sample the action from the probability distribution
actions[group][timestep] ~ action_distribution
# If missing actions are to be imputed, we do not care if the action exists
if !impute_missing_actions
# If we should not impute missing actions, we need to check if the action exists
@inbounds action_exists = !ismissing(actions[group][timestep])
# if the action doesn't exist, we skip this timestep
if !action_exists
continue
end
end

#Sample the action from the probability distribution
actions[group][timestep] ~ action_distribution


#If there are multiple actions
else
#Go through each separate action
for (action_idx, single_distribution) in enumerate(action_distribution)

#If the action isn't missing, or if missing actions are to be imputed
if !ismissing(actions[group][timestep, action_idx]) ||
impute_missing_actions

#Sample the action from the probability distribution
actions[group][timestep, action_idx] ~ single_distribution
# If missing actions are to be imputed, we do not care if the action exists
if !impute_missing_actions
# If we should not impute missing actions, we need to check if the action exists
@inbounds action_exists = !ismissing(actions[group][timestep, action_idx])
# if the action doesn't exist, we skip this timestep
if !action_exists
continue
end
end

#Sample the action from the probability distribution
@inbounds actions[group][timestep, action_idx] ~ single_distribution

end
end
end
Expand Down

0 comments on commit ed8782a

Please sign in to comment.