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

Fixes for Laplace, Logistic and Weibull #302

Closed
wants to merge 2 commits into from

Conversation

MichalLauer
Copy link
Contributor

Proposed changes

This PR fixes several bugs within distributions.

Types of changes

Put an x in the boxes that apply or remove the lines that don't.

  • Bugfix (non-breaking change which fixes an issue)

Checklist

Put an x in the boxes that apply or remove the lines that don't. This is a reminder of what we are going to look for before merging your code.

  • I have added unit tests and all tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added documentation where necessary
  • Any dependent changes have been merged and published in downstream modules

Further comments

Fixes the following errors:

# Laplace distribution
Laplace$new(var = 4)
# Logistic distribution
Logistic$new(sd = 1)$getParameterValue('mean')
Logistic$new(sd = 1)$getParameterValue('scale')
Logistic$new(sd = 1)$getParameterValue('sd')
# Weibull distribution
Weibull$new(altscale = 3)$getParameterValue("shape")
Weibull$new(altscale = 3)$getParameterValue("scale")
Weibull$new(altscale = 3)$getParameterValue("altscale")

@RaphaelS1
Copy link
Collaborator

Thanks @MichalLauer. The first commit (359a137) is unreviewable, I can't tell what's been changed there at all. In the next two I can see the variable orders are reversed. Please let me know what you changed in the first commit

@MichalLauer
Copy link
Contributor Author

Hey @RaphaelS1, apologies, that's strange. I will look into it and try to fix the commit so it's clear what I've changed. For clarity, the change is in the computation of scales.

getParameterSet.Laplace <- function(object, ...) {
  pset(
    prm("mean", "reals", 0, tags = "required"),
    prm("scale", "posreals", 1, tags = c("linked", "required")),
    prm("var", "posreals", tags = c("linked", "required")),
    trafo = function(x, self) {
        scales <- list_element(x, "scale")
        vars <- list_element(x, "var")
        if (length(scales) && length(vars)) {
          stop("Can't update 'scale' and 'var' parameters simultaneously")
        }
        if (length(scales)) {
          vars <- setNames(2 * unlist(scales)^2,
                           gsub("scale", "var", names(scales)))
        } else {
         # !!! Here added unlist so it does not throw an error
          scales <- setNames(sqrt(unlist(vars) / 2),
                             gsub("var", "scale", names(vars)))
        }

        unique_nlist(c(vars, scales, x))
    }
  )
}

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

Successfully merging this pull request may close these issues.

2 participants