Skip to content

Commit

Permalink
Merge pull request #340 from lorenalves/master
Browse files Browse the repository at this point in the history
Hotfix bug in neuron labelling
  • Loading branch information
rolfsimoes authored Aug 16, 2021
2 parents 4f229b7 + e0485b1 commit 9b3f842
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
6 changes: 4 additions & 2 deletions R/sits_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -919,13 +919,15 @@ plot.keras_model <- function(x, y, ...) {
if (type == "mapping") {
graphics::plot(koh$som_properties,
bgcol = koh$som_properties$paint_map,
"mapping", whatmap = whatmap
"mapping", whatmap = whatmap,
codeRendering = "lines"
)
}
else if (type == "codes") {
graphics::plot(koh$som_properties,
bgcol = koh$som_properties$paint_map,
"codes", whatmap = whatmap
"codes", whatmap = whatmap,
codeRendering = "lines"
)
}

Expand Down
33 changes: 26 additions & 7 deletions R/sits_som.R
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,32 @@ sits_som_map <- function(data,
id_neuron == neuron_id
)

# if more than one sample has been mapped, the a posteriori
# probability is considered
if (nrow(labels_neuron) > 1)
label_max <- nnet::which.is.max(labels_neuron$post_prob)
else
label_max <- nnet::which.is.max(labels_neuron$prior_prob)
return(labels_neuron[label_max, ]$label_samples)
#Get the maximum value of the prior probability
max_prob_index <- which.max(labels_neuron$prior_prob)
prob_max <- labels_neuron[max_prob_index, ]$prior_prob

#How many elements there are with the maximumn value?
number_of_label_max <- which(labels_neuron$prior_prob == prob_max )
label_max_final <- nnet::which.is.max(labels_neuron$prior_prob)


# if more than one sample has been mapped AND their max are the same,
# then a posteriori probability is considered
if (length(number_of_label_max) > 1)
{
#Get the maximum posterior among the tied classes
max_post <- max(labels_neuron[number_of_label_max, ]$post_prob)

# Where are the duplicated values?
label_max_post <- which(labels_neuron$post_prob == max_post )

#Is this value are in the maximum vector of the prior probability?
index_prior_max <- which(label_max_post %in% number_of_label_max == TRUE)
label_max_final <- label_max_post[index_prior_max]
}else
label_max_final <- nnet::which.is.max(labels_neuron$prior_prob)

return(labels_neuron[label_max_final, ]$label_samples)
})
labels_max <- unlist(lab_max)

Expand Down

0 comments on commit 9b3f842

Please sign in to comment.