Пример #1
0
def likelihood_ps(measur_vec,bvec):

    # -- modify load buses
    ppc["bus"][ind,2] = bvec

    # -- estimate the transformer measurements
    ppopt   = pypo.ppoption(PF_ALG=2, VERBOSE=0, OUT_ALL=0) 
    r       = pypo.runpf(ppc, ppopt)
    estim   = r[0]['gen'][:,2] 
    
    # -- calculate the likelihood
    sig     = 10.0

    return np.exp(-((estim - measur_vec)**2).sum()/(2*sig**2))
        
ppc0       = get_ppc14(op_change=1,dlt=0,busN=1) #trivial case: original solutin
ppc = cp.deepcopy(ppc0)
measur_vec = ppc0['gen'][:,2]
ind   = ppc0["bus"][:,1]==1 
np.random.seed(314)

# -- modify the load buses

loads = ppc0['bus'][:,0][ppc0['bus'][:,1]==1]
tmp = 0
LK_vec = []
for bs in loads:
    L_vec = []
    for mod in np.arange(0,2.1,0.1):
        bvec  = ppc0["bus"][ind,2].copy()
        bvec[tmp] *=  mod
Пример #2
0
    # -- calculate the likelihood
    sig = 1.0
    if (theta >= 0.0).all():
        return -((estim - y) ** 2).sum() / (2 * sig ** 2)
    else:
        return -np.inf


# -- utilities
ndim = 9
nwalkers = 300
nsteps = 100
cut = 50

# -- intialize the 14-bus system
ppc0 = get_ppc14(1, 0, 1)  # 0 implies no change
ppc = cp.deepcopy(ppc0)
# y     = ppc0['gen'][:,2].copy() # default measured values of transformers
ind = ppc0["bus"][:, 1] == 1  # building indices
# binit = ppc0["bus"][ind,2].copy()

for val in [1.00, 2.00, 5.00, 10.00, 20.00]:
    # -- Initialize sample
    print("initializing sampler...")
    np.random.seed(314)
    ppc["bus"][ind, 2] = val * np.ones(ndim)
    sol = pypo.runpf(ppc, pypo.ppoption(PF_ALG=2, VERBOSE=0, OUT_ALL=0))
    y = sol[0]["gen"][:, 2]
    binit = ppc["bus"][ind, 2].copy()
    sampler = emcee.EnsembleSampler(nwalkers, ndim, lnlike, args=[y])
    pos = np.array([binit * (1.0 + 0.2 * np.random.randn(ndim)) for i in range(nwalkers)]).clip(min=0.0)