Example #1
0
def tKrig():
    '''
    Kriging test    
    '''
    Loc, POIC, Prec = DataLoad.lcsv('TestData\GaugeLoc.csv',
                                       'TestData\InterpPts.csv',
                                       'TestData\Dataset.csv')
    Loc = numpy.array(Loc)/1000.0
    POIC = numpy.array(POIC)/1000.0
    SVExp, CovMea = Kriging.exp_semivariogram(Prec, Loc)
    xopt, ModOpt, VarFunArr = Kriging.theor_variogram(SVExp)
    Z, SP, ZAvg = Kriging.Krig(10.0, POIC, Loc, Prec, CovMea, ModOpt, xopt, 
                               VarFunArr,10 ,11, 'Ord')
    print Z
    print ZAvg
    return Z, ZAvg, CovMea
Example #2
0
    def animate(self, i):
        Z, T, F, W, WD = DataHandler.propagation(
            i, self.option, self.enteredWindSpeedValue,
            self.enteredWindDirectionValue, self.enteredTemperatureValue,
            self.enteredTrafficValue, self.enteredRainfallValue)
        xMesh, yMesh, zPrediction, Zi = Kriging.execute(X, Y, Z, i)
        self.fig.clf()
        subplot = self.fig.add_subplot(111)

        subplot.set_title(self.createTitle(self.option, i, T, F, W, WD))
        subplContourf = subplot.imshow(backgroundImage, extent=[0, 90, 0, 60])
        subplContourf = subplot.contourf(xMesh,
                                         yMesh,
                                         np.transpose(zPrediction),
                                         50,
                                         cmap=newCmap,
                                         alpha=0.6,
                                         vmin=-80,
                                         vmax=190)
        subplContourf = subplot.scatter(X,
                                        Y,
                                        c=Zi,
                                        cmap=newCmap,
                                        vmin=0,
                                        vmax=80)
        colorbar = self.fig.colorbar(subplContourf, fraction=0.03)
        colorbar.set_label('Smog level')
        cursor = mplcursors.cursor(subplContourf, hover=True)
        cursor.connect(
            "add",
            lambda sel: sel.annotation.set_text(pointNames[sel.target.index]))

        if i == self.numberOfMeasurements - 1:
            self.animation = None
            self.pauseButton.config(text="Show again")
            self.dailySimButton["state"] = "normal"
            self.weeklySimButton["state"] = "normal"
pre = Preprocess(all_dat='../all_games.pkl', pca_model='../eco_full_pca.pkl')
X, y = pre.ready_player_one(2)
scale = MinMaxScaler((-1.,1.))
X = scale.fit_transform(X)

from tqdm import tqdm

file_address = 'p2_bfgs_sigma_alpha8.286TRUNCATED.json'
with open(file_address, 'r') as f:
    best_obj, best_sig = json.load( f)
f.close()

# unit_sig = np.ones(31)
# bounds = np.array(31*[[-1., 1.]])
# bestKrig = Kriging(best_sig, bounds=bounds)
# bestKrig.fit(X,y)

bounds = np.array(30*[[-1., 1.]])
num_ini_guess = 2
kriging_model = Kriging(best_sig, bounds=bounds, num_ini_guess=num_ini_guess)

with Model() as model: # model specifications in PyMC3 are wrapped in a with-statement
    # Define likelihood
    likelihood = kriging_model.obj(l,a)

with model:
    start = {'Intercept_logodds': np.array(-1.4488360894175776),
             'sigma_log': np.array(-0.7958719902826098),
             'x_logodds': np.array(-0.3564261325183015)}
    step = NUTS(scaling=start) # Instantiate MCMC sampling algorithm
    trace = sample(2000, step, start=start, progressbar=True) # draw 2000 posterior samples using NUTS sampling
from tqdm import tqdm

file_address = 'p2_bfgs_sigma_alpha8.286TRUNCATED.json'
with open(file_address, 'r') as f:
    best_obj, best_sig = json.load(f)
f.close()

# unit_sig = np.ones(31)
# bounds = np.array(31*[[-1., 1.]])
# bestKrig = Kriging(best_sig, bounds=bounds)
# bestKrig.fit(X,y)

bounds = np.array(30 * [[-1., 1.]])
num_ini_guess = 2
kriging_model = Kriging(best_sig, bounds=bounds, num_ini_guess=num_ini_guess)

with Model(
) as model:  # model specifications in PyMC3 are wrapped in a with-statement
    # Define likelihood
    likelihood = kriging_model.obj(l, a)

with model:
    start = {
        'Intercept_logodds': np.array(-1.4488360894175776),
        'sigma_log': np.array(-0.7958719902826098),
        'x_logodds': np.array(-0.3564261325183015)
    }
    step = NUTS(scaling=start)  # Instantiate MCMC sampling algorithm
    trace = sample(
        2000, step, start=start,