Foreign SP helpers: module venture.lite.sp_help

Helpers for creating SP objects.

class venture.lite.sp_help.FunctionPSP(f, descr=None, sim_grad=None)

Bases: venture.lite.psp.DeterministicPSP

description(name)

Return a string describing this PSP. The string may include the name argument, which is the symbol that the enclosing SP is bound to.

gradientOfSimulate(args, _value, direction)

Return the gradient of this PSP’s simulation function. This method is needed only for Hamiltonian Monte Carlo.

Specifically, the gradient of the simulation function must be with respect to the given direction on the output space, at the point given by the args struct (the input space is taken to be the full list of parents). In other words, the Jacobian-vector product

direction^T J_simulate(args).

For PSPs with one scalar output, the direction will be a number, and the correct answer is the gradient of simulate multiplied by that number.

The gradient should be returned as a list of the partial derivatives with respect to each parent node represented in the args.

We circumvent problems with trying to compute derivatives of stochastic functions by mixing over the randomness consumed. What this practically means is that the gradient to be computed is the gradient of the deterministic function of the arguments that is this process, if its randomness is fixed at some particular stream of bits. The gradient will, in general, depend on what those bits are. Pending a better interface for communicating it, the value argument of this method is the value that simulating this PSP outputs when using the fixed randomness with respect to which the gradient is to be computed. We hope that, for sufficiently simple PSPs, this proxy is sufficient.

The exact circumstances when this method is needed for HMC are this PSP appearing as the operator of a non-principal, non-absorbing scaffold node (that is, in the non-principal part of the DRG, or in the brush).

simulate(args)

Simulate this process with the given parameters and return the result.

venture.lite.sp_help.binaryNum(f, sim_grad=None, descr=None)
venture.lite.sp_help.binaryNumInt(f, sim_grad=None, descr=None)
venture.lite.sp_help.binaryNumS(output)
venture.lite.sp_help.binaryPred(f, descr=None)
venture.lite.sp_help.deterministic(f, descr=None, sim_grad=None)
venture.lite.sp_help.deterministic_psp(f, descr=None, sim_grad=None)
venture.lite.sp_help.deterministic_typed(f, args_types, return_type, descr=None, sim_grad=None, **kwargs)
venture.lite.sp_help.deterministic_typed_psp(f, args_types, return_type, descr=None, sim_grad=None, **kwargs)
venture.lite.sp_help.dispatching_psp(types, psps)
venture.lite.sp_help.esr_output(request)
venture.lite.sp_help.naryNum(f, sim_grad=None, descr=None)
venture.lite.sp_help.no_request(output)
venture.lite.sp_help.type_test(tp)
venture.lite.sp_help.typed_func(*args, **kwargs)
venture.lite.sp_help.typed_func_psp(f, args_types, return_type, descr=None, sim_grad=None, **kwargs)
venture.lite.sp_help.typed_nr(output, args_types, return_type, **kwargs)
venture.lite.sp_help.unaryNum(f, sim_grad=None, descr=None)
venture.lite.sp_help.unaryNumS(f)
venture.lite.sp_help.zero_gradient(args, _direction)