Ejemplo n.º 1
0
    Nx = xparticles.shape[0]
    Ntheta = xparticles.shape[2]
    result = zeros(3)
    observations = zeros(Nx * Ntheta)
    weightobs = zeros(Nx * Ntheta)
    for j in range(Ntheta):
        observations[(Nx * j):(Nx * (j+1))] = \
                observationGenerator(xparticles[..., j], thetaparticles[:, j]).reshape(Nx)
        weightobs[(Nx * j):(Nx * (j + 1))] = repeat(thetaweights[j],
                                                    repeats=Nx)
    observations = power(observations, 2)
    weightobs = weightobs / sum(weightobs)
    obsmean = average(observations, weights=weightobs)
    ind = argsort(observations)
    observations = observations[ind]
    weightobs = weightobs[ind]
    cumweightobs = cumsum(weightobs)
    quantile5 = observations[searchsorted(cumweightobs, 0.05)]
    quantile95 = observations[searchsorted(cumweightobs, 0.95)]
    result[0] = obsmean
    result[1] = quantile5
    result[2] = quantile95
    return result


modelx.addPredictionList([{
    "function": predictionSquaredObservations,
    "dimension": 3,
    "name": "squaredobs"
}])
Ejemplo n.º 2
0
modelx.addObsPrediction()
def predictionSquaredObservations(xparticles, thetaweights, thetaparticles, t):
    Nx = xparticles.shape[0]
    Ntheta = xparticles.shape[2]
    result = zeros(3)
    observations = zeros(Nx * Ntheta)
    weightobs = zeros(Nx * Ntheta)
    for j in range(Ntheta):
        observations[(Nx * j):(Nx * (j+1))] = \
                observationGenerator(xparticles[..., j], thetaparticles[:, j]).reshape(Nx)
        weightobs[(Nx * j):(Nx * (j+1))] = repeat(thetaweights[j], repeats = Nx)
    observations = power(observations, 2)
    weightobs = weightobs / sum(weightobs)
    obsmean = average(observations, weights = weightobs)
    ind = argsort(observations)
    observations = observations[ind]
    weightobs = weightobs[ind]
    cumweightobs = cumsum(weightobs)
    quantile5 = observations[searchsorted(cumweightobs, 0.05)]
    quantile95 = observations[searchsorted(cumweightobs, 0.95)]
    result[0] = obsmean
    result[1] = quantile5
    result[2] = quantile95
    return result
modelx.addPredictionList([{"function": predictionSquaredObservations, "dimension": 3, "name": "squaredobs"}])