Пример #1
0
def irrep_gen_func(partitions, _dir='fourier_eval'):
    fmats = {}
    ferrers = {}
    for p in partitions:
        # load the appropriate matrix
        f = FerrersDiagram(p)
        # TODO: this should load from the appropriate place
        #fourier_mat = np.load('./tile/{}/{}.npy'.format(_dir, p))
        try:
            fourier_mat = np.load('/local/hopan/tile/{}/{}.npy'.format(
                _dir, p))
        except:
            fourier_mat = np.load('/scratch/hopan/tile/{}/{}.npy'.format(
                _dir, p))
        scale = fourier_mat.shape[0] / S9_SIZE
        fmats[p] = scale * fourier_mat
        ferrers[p] = f

    def func(grid):
        tup = tuple(i for row in grid for i in row)
        val = 0
        pinv = Perm2.from_tup(tup).inv()
        for p, mat in fmats.items():
            f = ferrers[p]
            mat_inv = yor(f, pinv)
            val += np.sum(mat_inv * mat)

        return val

    return func
Пример #2
0
def par_ft(partition, fname, savedir, ncpu=16):
    if not os.path.exists(savedir):
        try:
            print('Directory {} doesnt exist. creating it now'.format(savedir))
            os.makedirs(savedir)
        except:
            print('Directory {} didnt exist. Tried to make it. Already made. Continuing...'.format(savedir))

    ferrers = FerrersDiagram(partition)
    print('Ferrers:')
    print(ferrers)
    df = pd.read_csv(fname, header=None, dtype={0: str, 1:int})
    check_memory()

    df_chunk = np.array_split(df, ncpu)
    arg_tups = [(chunk, ferrers) for chunk in df_chunk]
    savename = os.path.join(savedir, str(partition))
    print('Saving in: {}'.format(savename))
    if os.path.exists(savename):
        print('{} exists. Not running'.format(savename))

    with Pool(ncpu) as p:
        map_res = p.starmap(fts, arg_tups)
        # sum of these matrices is what we wnat
        fourier_mat = sum(map_res)
        np.save(savename, fourier_mat)
        return fourier_mat
Пример #3
0
def par_inv_ft(partition, fname, savedir, ncpu=16):
    if not os.path.exists(savedir):
        try:
            print('Directory {} doesnt exist. creating it now'.format(savedir))
            os.makedirs(savedir)
        except:
            print(
                'Directory {} didnt exist. Tried to make it. Already made. Continuing...'
                .format(savedir))

    ferrers = FerrersDiagram(partition)
    df = pd.read_csv(fname, header=None, dtype={0: str, 1: int})
    check_memory()

    df_chunk = np.array_split(df, ncpu)
    arg_tups = [(chunk, ferrers) for chunk in df_chunk]
    savename = os.path.join(savedir, str(partition)) + '.csv'
    print('Saving in: {}'.format(savename))
    if os.path.exists(savename):
        print('{} exists. Not running'.format(savename))
        return

    with Pool(ncpu) as p:
        results = p.starmap(inv_transform, arg_tups)
        concat_results = sum(results, [])
        df[1] = concat_results
        df.to_csv(savename, header=None, index=False)

    return df
Пример #4
0
def benchmark(n):
    '''
    Benchmark time/memory usage for generating all YoungTableau for S_8
    '''
    tstart = time.time()
    _partitions = partitions(n)
    s_n = sn(n)
    print('Starting...')
    times = []
    for idx, p in enumerate(_partitions):
        start = time.time()
        sdict = {}
        f = FerrersDiagram(p)
        if os.path.exists('/local/hopan/irreps/s_9/{}.pkl'.format(p)):
            print('Skipping {}'.format(p))
            continue
        for perm in s_n:
            start = time.time()
            y = yor(f, perm)
            end = time.time()
            if random.random() > 0.1 and len(times) < 1000:
                times.append(end - start)
            if len(times) >= 1000:
                pdb.set_trace()
            sdict[perm.tup_rep] = y

        done = time.time() - start
        print('Elapsed: {:.2f}mins | Done {} / {} | Partition: {}'.format(done / 60., idx, len(_partitions), p))

        with open('/local/hopan/irreps/s_{}/{}.pkl'.format(n, p), 'wb') as f:
            pickle.dump(sdict, f, protocol=pickle.HIGHEST_PROTOCOL)

    tend = time.time() - tstart
    print('Total time compute yor matrices for S_{}: {:3f}'.format(n, tend))
    print(CACHE)
Пример #5
0
def test_one():
    fname = '/local/hopan/tile/tile3.txt'
    df = pd.read_csv(fname, header=None, dtype={0: str, 1:int})
    df.columns = ['perm', 'distance']
    df = df[df['distance'] < 4]
    print(len(df))
    partition = (8, 1)
    ferrers = FerrersDiagram(partition)
    res = fts(df, ferrers)
    pdb.set_trace()
Пример #6
0
    def __init__(self, partitions):
        super(IrrepDVN, self).__init__()
        n_in = 0
        for p in partitions:
            f = FerrersDiagram(p)
            n_in += (len(f.tableaux) * len(f.tableaux))

        self.tile_size = sum(partitions[0])
        self.w = nn.Linear(n_in, 1)
        self.n_in = n_in
        self.n_out = 1
        self.init_weights()
Пример #7
0
    def __init__(self, n, partitions, reward='penalty'):
        '''
        n: int, size of tile puzzle
        partitions: list of partitions of 9(tuples of ints)
        '''
        super(TileIrrepEnv, self).__init__(n, one_hot=False,
                                           reward=reward)  # get grid state
        self.n = n
        self.partitions = partitions
        self.ferrers = [FerrersDiagram(p) for p in partitions]
        self.sn_irreps = [SnIrrep(p) for p in partitions]

        # will only know this from sn_irreps cat irreps!
        self.irrep_shape = self.cat_irreps(TileEnv.solved_grid(n)).shape
        self.observation_space = spaces.Box(low=-float('inf'),
                                            high=float('inf'),
                                            shape=self.irrep_shape)
Пример #8
0
def ft_full(f, n, algo='fft'):
    '''
    Computes the fourier transform using either the fft or the slow fourier transform.
    f: a function from S_n -> \mathbb{R}
    n: integer
    algo: string

    Returns: a dictionary mapping FerrersDiagrams(which index your irreps) to irrep matrices
    '''
    fourier_parts = {}
    parts = partitions(n)

    for p in parts:
        ferrers = FerrersDiagram(p)
        if algo == 'fft':
            fourier_parts[ferrers] = fft2(f, ferrers)
        elif algo == 'ft1':
            fourier_parts[ferrers] = fourier_transform(f, ferrers)
        elif algo == 'ft2':
            fourier_parts[ferrers] = fourier_transform2(f, ferrers)

    return fourier_parts
Пример #9
0
 def __init__(self, partition):
     self.partition = partition
     self.ferrers = FerrersDiagram(partition)
Пример #10
0
 def __init__(self, partition, n_hid, n_out):
     super(IrrepDQNMLP, self).__init__()
     ferrer = FerrersDiagram(partition)
     size = len(ferrer.tableaux) * len(ferrer.tableaux)
     self.net = MLP(size, n_hid, n_out)