Exemplo n.º 1
0
def neuralnetpredict(pm, bs, nc, numd, seed, zz=0):
    '''For the given box, mesh, numd, seed and redshift, do the neural network prediction
    from the network saved in cfg file and return predict, nnpred, nnmass
    '''
    dpath = '/global/project/projectdirs/astro250/chmodi/cosmo4d/'

    import yaml
    import nettools as ntools

    with open(dpath + 'train/models.yaml', 'r') as ymlfile:
        cfg = yaml.load(ymlfile)

    ptpath = dpath + 'train/' + cfg['%s-%s' %
                                    (int(bs), int(nc))][0][numd]['ppath']
    mtpath = ptpath + cfg['%s-%s' % (int(bs), int(nc))][0][numd]['mpath']
    # mtpath = ptpath + cfg['%s-%s'%(bs,nc)][0][numd]['mpathnf']
    ptup, pftname, plocal, pdict = ntools.setuppos2(ptpath)
    mtup, mftname, mlocal, mdict = ntools.setupmass(mtpath)
    R1, R2 = pdict['R1'], pdict['R2']

    num = int(numd * bs**3)
    meshdict, hdict = ntools.readfiles(
        pm,
        dpath + '/data/z%02d/L%04d_N%04d_S%04d_05step/' % (zz, bs, nc, seed),
        R1=R1,
        R2=R2,
        mexp=None)

    ftt = ntools.createdata(pm, meshdict, pdict['pftname'], plocal)
    mftt = ntools.createdata(pm, meshdict, mftname, mlocal)

    nnpred = ntools.applynet(ftt, ptup).reshape(nc, nc, nc)
    nnmass = ntools.applynet(mftt, mtup).reshape(nc, nc, nc)
    predict = nnpred * nnmass
    ##
    return pm.create(mode='real', value=predict), nnpred, nnmass
Exemplo n.º 2
0
sgs = [0.1, 0.20]

for seed in [100, 500, 900, 800]:
    meshdict, dummy = ntools.readfiles(
        pm,
        scratch + '/data/L%04d_N%04d_S%04d_05step/' % (bs, nc, seed),
        R1=R1,
        R2=R2,
        abund=abund,
        doexp=doexp,
        mexp=mexp,
        cc=cc,
        stellar=stellar)
    ftt = ntools.createdata(pm, meshdict, pdict['pftname'], plocal)
    mftt = ntools.createdata(pm, meshdict, mftname, mlocal)
    nnpred = ntools.applynet(ftt, ptup).reshape(nc, nc, nc)
    if regression:
        nnmass = ntools.applymassreg(mftt, mtup).reshape(nc, nc, nc)
    else:
        nnmass = ntools.applynet(mftt, mtup).reshape(nc, nc, nc)
    if doexp:
        nnmass = mf.fmexp(ntools.relu(nnmass), mexp, cc)
    predict = pm.create(mode='real')
    predict[...] = nnpred * nnmass
    predictR = ft.smooth(predict, Rsm, 'fingauss')

    #data

    hdictf = ntools.gridhalos(pm,
                              scratch + '/data/L%04d_N%04d_S%04d_40step/' %
                              (bs, fine * nc, seed),
Exemplo n.º 3
0
    sfac = pdict['sfac']
    R2 = R1 * sfac

#model
print('Reading Files')
meshdict, dummy = ntools.readfiles(pm,
                                   scratch +
                                   '/data/z%02d/L%04d_N%04d_S%04d_05step/' %
                                   (zz * 10, bs, nc, seed),
                                   R1=R1,
                                   R2=R2,
                                   abund=abund)

ftt = ntools.createdata(pm, meshdict, pdict['pftname'], plocal)
mftt = ntools.createdata(pm, meshdict, mftname, mlocal)
nnpred = ntools.applynet(ftt, ptup).reshape(nc, nc, nc)
predict = pm.create(mode='real', value=nnpred)
predictR = ft.smooth(predict, Rsm, 'fingauss')
if ovd: predictR[...] = (predictR[...] - predictR.cmean()) / (predictR.cmean())

#data

print('Generating data')

hdictf = ntools.gridhalos(pm,
                          dpath=scratch +
                          '/data/z%02d/L%04d_N%04d_S%04d_40step/' %
                          (zz * 10, bs, sfine * nc, seed),
                          R1=R1,
                          R2=R2,
                          pmesh=False,