Skip to content

a complete 'algorithm' #199

Description

@paciorek

Via the rope swing, here's a first algorithm using all the various pieces from our tunneling work.

This works. So it's not an issue. But I was quite happy to see it all come together. No wet feet. No muddy takeoff.

modelBase_nC <- nimbleModel:::modelBase_nClass
instr_nC <- nimbleModel:::instr_nClass

metropolisCl = nClass(
    Rpublic = list(
        initialize = function(model, target_, ...) {
            super$initialize(...)
            self$target <- target_  # Did `target <- target_` used to work without `self`, as we have in `modelBase_nClass' initialize`?
            self$m <- model
            self$calcNodes <- model$makeCompiledInstrList(makeInstrList(model, model$getDependencies(target_)))
        }
    ),
    Cpublic = list(
        target = 'string',
        calcNodes = 'nList(instr_nC)',
        m = 'modelBase_nC',
        run = nFunction(
            fun=function() {
                as(m[[target]],'numericVector') <- rnorm(1, as(m[[target]],'numericScalar'), 1)
                result <- m$calculate_impl(calcNodes)    # Needs operator handling to allow use of `calculate`.
                return(result)
            }, returnType = 'numericScalar'
        )
    )
)

cstuff <- nCompile(metropolisCl, mclass)
cm <- cstuff[[2]]$new()
cm$calculate()  # lifted node
calgo <- cstuff[[1]]$new(cm, 'mu')   # Specialize algo to model and target node.
calgo$run()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions