コード例 #1
0
    
#    print("Loading data ...")
#    gf = GeoField()
#    gf.load("data/pres.mon.mean.nc", 'pres')
#    gf.transform_to_anomalies()
#    gf.normalize_monthly_variance()
#    gf.slice_date_range(date(1948, 1, 1), date(2012, 1, 1))
#    gf.slice_spatial(None, [20, 89])
#    gf.slice_months([12, 1, 2])

    # construct a test system    
    S = np.zeros(shape = (20, 50), dtype = np.int32)
    S[10:18, 25:45] = 1
    S[0:3, 6:12] = 2
    S[8:15, 2:12] = 3
    v, Sr = constructVAR(S, [0.0, 0.4, 0.8, 0.7], [-0.5, 0.5], [0.0, 0.0])
#    v, Sr = constructVAR(S, [0.0, 0.001, 0.01], [-0.1, 0.1], [0.00, 0.00], [0.01, 0.01])
    ts = v.simulate(200)
    gf = make_model_geofield(S, ts)
    
    # initialize a parallel pool
    pool = Pool(POOL_SIZE)

    # replace field with surrogate field
    sgf = SurrGeoFieldAR()
    sgf.copy_field(gf)
    sgf.prepare_surrogates(pool)
    sgf.construct_surrogate_with_noise()
    gf = sgf
    gf.d = gf.surr_data().copy()
    
コード例 #2
0
ファイル: smg_test.py プロジェクト: Skye777/ndw-climate
from spatial_model_generator import constructVAR, make_model_geofield
import numpy as np
import matplotlib.pyplot as plt
from geo_field import GeoField
from surr_geo_field_ar import SurrGeoFieldAR
import cPickle

# construct the testing model from a spec
S = np.zeros(shape=(20, 50), dtype=np.int32)
S[10:18, 25:45] = 1
S[0:3, 6:12] = 2
v, Sr = constructVAR(S, [0.0, 0.8, 0.8], [-0.1, 0.1], [0.0, 0.0])

#v, Sr = constructVAR2(S, [-0.2, 0.2], [0.0, 0.9, 0.9], 0.8)

#S = np.zeros(shape = (5, 10), dtype = np.int32)
#S[1:4, 0:2] = 1
#S[0:3, 6:9] = 2v, Sr = constructVAR(S, [0.0, 0.191, 0.120], [-0.1, 0.1], [0.00, 0.00], [0.01, 0.01])
ts = v.simulate(768)

gf = make_model_geofield(S, ts)
sgf = SurrGeoFieldAR()
sgf.copy_field(gf)
sgf.prepare_surrogates()
sgf.construct_surrogate_with_noise()
ts2 = sgf.surr_data()

plt.figure(figsize=(8, 8))
plt.imshow(S, interpolation='nearest')
plt.title('Structural matrix')
コード例 #3
0
        # compute RVDIM(1)
        rvdims[i] = rlam[0] / np.sum(rlam**2)**0.5

    return rvdims


if __name__ == "__main__":

    print("Estimate PCA components script version 1.0")

    S = np.zeros(shape=(20, 50), dtype=np.int32)
    S[10:18, 25:45] = 1
    S[0:3, 6:12] = 2
    S[8:15, 2:12] = 3
    v, Sr = constructVAR(S, [0.0, 0.6, 0.9, 0.7], [0.3, 0.5], [0.0, 0.0])
    ts = v.simulate(200)
    gf = make_model_geofield(S, ts)

    # initialize a parallel pool
    pool = Pool(POOL_SIZE)

    # compute the eigenvalues/eigenvectos of the covariance matrix of
    Ud, dlam, _ = pca_components_gf(gf.data())
    drdims = np.zeros((NUM_EIGS, ))
    for i in range(NUM_EIGS):
        drdims[i] = dlam[i] / np.sum(dlam[i:]**2)**0.5

    sd = SurrGeoFieldAR([0, 30], 'sbc')
    sd.copy_field(gf)
    sd.prepare_surrogates(pool)
コード例 #4
0
        
        # compute RVDIM(1)
        rvdims[i] = rlam[0] / np.sum(rlam**2)**0.5
    
    return rvdims


if __name__ == "__main__":

    print("Estimate PCA components script version 1.0")
    
    S = np.zeros(shape = (20, 50), dtype = np.int32)
    S[10:18, 25:45] = 1
    S[0:3, 6:12] = 2
    S[8:15, 2:12] = 3
    v, Sr = constructVAR(S, [0.0, 0.6, 0.9, 0.7], [0.3, 0.5], [0.0, 0.0])
    ts = v.simulate(200)
    gf = make_model_geofield(S, ts)
    
    # initialize a parallel pool
    pool = Pool(POOL_SIZE)
    
    # compute the eigenvalues/eigenvectos of the covariance matrix of
    Ud, dlam, _ = pca_components_gf(gf.data())
    drdims = np.zeros((NUM_EIGS,))
    for i in range(NUM_EIGS):
        drdims[i] = dlam[i] / np.sum(dlam[i:]**2)**0.5
    
    sd = SurrGeoFieldAR([0, 30], 'sbc')
    sd.copy_field(gf)
    sd.prepare_surrogates(pool)
コード例 #5
0
ファイル: smg_test.py プロジェクト: vejmelkam/ndw-climate

from spatial_model_generator import constructVAR, make_model_geofield
import numpy as np
import matplotlib.pyplot as plt
from geo_field import GeoField
from surr_geo_field_ar import SurrGeoFieldAR
import cPickle

# construct the testing model from a spec
S = np.zeros(shape = (20, 50), dtype = np.int32)
S[10:18, 25:45] = 1
S[0:3, 6:12] = 2
v, Sr = constructVAR(S, [0.0, 0.8, 0.8], [-0.1, 0.1], [0.0, 0.0])

#v, Sr = constructVAR2(S, [-0.2, 0.2], [0.0, 0.9, 0.9], 0.8)

#S = np.zeros(shape = (5, 10), dtype = np.int32)
#S[1:4, 0:2] = 1
#S[0:3, 6:9] = 2v, Sr = constructVAR(S, [0.0, 0.191, 0.120], [-0.1, 0.1], [0.00, 0.00], [0.01, 0.01])
ts = v.simulate(768)

gf = make_model_geofield(S, ts)
sgf = SurrGeoFieldAR()
sgf.copy_field(gf)
sgf.prepare_surrogates()
sgf.construct_surrogate_with_noise()
ts2 = sgf.surr_data() 

plt.figure(figsize = (8, 8))
plt.imshow(S, interpolation = 'nearest')
コード例 #6
0
    #    print("Loading data ...")
    #    gf = GeoField()
    #    gf.load("data/pres.mon.mean.nc", 'pres')
    #    gf.transform_to_anomalies()
    #    gf.normalize_monthly_variance()
    #    gf.slice_date_range(date(1948, 1, 1), date(2012, 1, 1))
    #    gf.slice_spatial(None, [20, 89])
    #    gf.slice_months([12, 1, 2])

    # construct a test system
    S = np.zeros(shape=(20, 50), dtype=np.int32)
    S[10:18, 25:45] = 1
    S[0:3, 6:12] = 2
    S[8:15, 2:12] = 3
    v, Sr = constructVAR(S, [0.0, 0.4, 0.8, 0.7], [-0.5, 0.5], [0.0, 0.0])
    #    v, Sr = constructVAR(S, [0.0, 0.001, 0.01], [-0.1, 0.1], [0.00, 0.00], [0.01, 0.01])
    ts = v.simulate(200)
    gf = make_model_geofield(S, ts)

    # initialize a parallel pool
    pool = Pool(POOL_SIZE)

    # replace field with surrogate field
    sgf = SurrGeoFieldAR()
    sgf.copy_field(gf)
    sgf.prepare_surrogates(pool)
    sgf.construct_surrogate_with_noise()
    gf = sgf
    gf.d = gf.surr_data().copy()