Esempio n. 1
0
#  Lincense: Academic Free License (AFL) v3.0
#
import sys

from time import sleep
import numpy as np

from prosper.utils.parallel import pprint
from prosper.utils.datalog import dlog, StoreToH5, TextPrinter

# Parameters
rf_shape = (26, 26)
H = 16

# Configure Data-Logger
dlog.set_handler(('T', 'S', 'C'), TextPrinter)

# And GO!
D = rf_shape[0] * rf_shape[1]

Wshape = (H,D)
i = 0
for T in np.linspace(0., 20, 50):
    i = i + 1
    pprint( "%i th iteration..." % i)

    W = np.random.normal(size=Wshape)
    dlog.append_all( {
        'T': T,
        'W': W,
        'S': np.sin(T),
Esempio n. 2
0
    D = ts_size**2  # dimensionality of observed data

    # Approximation parameters for Expectation Truncation (It has to be Hprime>=gamma)
    Hprime = 5
    gamma = 3

    # Import and instantiate a model
    discriminative = False
    if discriminative:
        model = DBSC_ET(D, H, Hprime, gamma)
    else:
        model = BSC_ET(D, H, Hprime, gamma)

    # Configure DataLogger
    print_list = ('T', 'L', 'pi', 'sigma')
    dlog.set_handler(print_list, TextPrinter)  # prints things to terminal
    txt_list = ('T', 'L', 'pi', 'sigma')
    dlog.set_handler(txt_list, StoreToTxt, output_path +
                     '/results.txt')  # stores things in a txt file
    h5_list = ('T', 'L', 'pi', 'sigma', 'W')
    dlog.set_handler(h5_list, StoreToH5, output_path +
                     '/results.h5')  # stores things in an h5 file

    # Choose annealing schedule
    from prosper.em.annealing import LinearAnnealing
    anneal = LinearAnnealing(20)  # decrease
    anneal['T'] = [(0, 5.), (.8, 1.)]
    anneal['Ncut_factor'] = [(0, 0.), (0.5, 0.), (0.6, 1.)]
    # anneal['Ncut_factor'] = [(0,0.),(0.7,1.)]
    # anneal['Ncut_factor'] = [(0,0.),(0.7,1.)]
    anneal['W_noise'] = [(0, np.std(ts) / 2.), (0.7, 0.)]
Esempio n. 3
0
    # Disgnostic output
    pprint("=" * 40)
    pprint(" Running bars experiment (%d parallel processes)" % comm.size)
    pprint("  size of training set:   %d" % N)
    pprint("  size of bars images:    %d x %d" % (size, size))
    pprint("  number of hiddens:      %d" % H)
    pprint("  saving results to:      %s" % output_path)
    pprint()

    # Generate bars data
    my_data = model.generate_data(params_gt, N // comm.size)

    # Configure DataLogger
    print_list = ('T', 'Q', 'pi', 'sigma', 'N', 'MAE')
    store_list = ('*')
    dlog.set_handler(print_list, TextPrinter)
    dlog.set_handler(print_list, StoreToTxt, output_path + '/terminal.txt')
    dlog.set_handler(store_list, StoreToH5, output_path + '/result.h5')

    model_params = model.standard_init(my_data)

    if 'anneal' in params:
        anneal = params.get('anneal')
    else:
        # Choose annealing schedule
        anneal = LinearAnnealing(50)
        anneal['T'] = [(0, 2.), (.7, 1.)]
        anneal['Ncut_factor'] = [(0, 0.), (2. / 3, 1.)]
        anneal['anneal_prior'] = False

    # Create and start EM annealing
Esempio n. 4
0
pprint(" Running %d parallel processes" % comm.size)
pprint("=" * 70)

H = 2 * D2  # number of latent units
D = D2**2  # total size of image in pixels

my_N = N // comm.size

# Some sanity checks
assert Hprime <= H
assert gamma <= Hprime
assert D == D2**2

# Configure DataLogger
print_list = ('T', 'pi', 'sigma')
dlog.set_handler(print_list, TextPrinter)

# Invent some ground truth parameter models
params_gt = {'W': 10 * generate_bars_dict(H), 'pi': 2. / H, 'sigma': 1.0}

# Use model to generate data
model = BSC_ET(D, H, Hprime, gamma)
my_data = model.generate_data(params_gt, my_N)

model_params = model.standard_init(my_data)

# Choose annealing schedule
anneal = LinearAnnealing(50)
anneal['T'] = [(15, 1.), (-10, 1.)]
anneal['Ncut_factor'] = [(0, 0.), (2. / 3, 1.)]
anneal['anneal_prior'] = False