コード例 #1
0
def averaged_weights(weights_init, learning_set, probabilities, categories,
                     number_of_categories, condition, alpha, beta, n_trials):
    """Compute avrage weights over 500 runs of the model 

    Keyword arguments:
    weights_init -- weights after a single run of the model 
    learning set --  trials on which the model is trained (array)
    probabilities -- probabilities of each trial in learning_set (vector)
    categories --  all categories (e.g., [0, 1] - affix1 and affix2) (vector)
    number_of_categories -- the number of cateogries (affixes) (integer)
    condition -- "suffix" or "prefix" (string)
    alpha -- cue saliency (integer or array)
    beta -- learning rate (integer)
    n_trials -- number of trials (integer)
    """
    i = 0
    while i < 10:
        if condition == "prefix":
            network = Simulation(learning_set, probabilities, categories,
                                 number_of_categories, "prefix", alpha, beta,
                                 n_trials)
            new_weights = network.simulate()
        else:
            network = Simulation(learning_set, probabilities, categories,
                                 number_of_categories, "suffix", alpha, beta,
                                 n_trials)
            new_weights = network.simulate()
        weights_init += new_weights
        i += 1
    weights_avg = (weights_init) / 10.0
    return weights_avg
コード例 #2
0
def exp1_follow_up():
    alpha = exp1_alpha()
    learning_set, probabilities, categories, number_of_categories = experiment_1.get_experiment1_setup(
    )
    beta = 0.1
    n_trials = 2000

    p = Simulation(learning_set, probabilities, categories,
                   number_of_categories, "prefix", alpha, beta, n_trials)
    prefix_weights = p.simulate()

    s = Simulation(learning_set, probabilities, categories,
                   number_of_categories, "suffix", alpha, beta, n_trials)
    suffix_weights = s.simulate()

    # Figure 5.1 in thesis
    plots.exp1_plt_weights(prefix_weights, 1)
    plots.exp1_plt_weights(suffix_weights, 2)
    plt.show()

    # Experiment 1 plot raw weights at test: Figure 5.2 panel A in thesis
    test_features = [0]
    test_trials = [49, 99, 499, 999, 1499, 1999]
    labels = ["50", "100", "500", "1000", "1500", "2000"]
    prefix_averaged_weights = testmodel.averaged_weights(
        prefix_weights, learning_set, probabilities, categories,
        number_of_categories, "prefix", alpha, beta, n_trials)
    suffix_averaged_weights = testmodel.averaged_weights(
        suffix_weights, learning_set, probabilities, categories,
        number_of_categories, "suffix", alpha, beta, n_trials)

    # Prefix
    prefix_correct_weights = prefix_averaged_weights[:, 0]
    prefix_incorrect_weights = prefix_averaged_weights[:, 1]
    prefix_results = testmodel.sums(test_features, test_trials,
                                    prefix_correct_weights,
                                    prefix_incorrect_weights)

    # Suffix
    suffix_correct_weights = suffix_averaged_weights[:, 0]
    suffix_incorrect_weights = suffix_averaged_weights[:, 1]
    suffix_results = testmodel.sums(test_features, test_trials,
                                    suffix_correct_weights,
                                    suffix_incorrect_weights)

    plots.plt_sum_intervals(prefix_results, 1, len(test_trials), labels)
    plots.plt_sum_intervals(suffix_results, 2, len(test_trials), labels)
    plt.show()

    # Plot Luce's choice axiom results: Figure 5.2 panel B in thesis
    prefix_500 = prefix_results[:, 2]
    suffix_500 = suffix_results[:, 2]
    sum_weights = [prefix_500, suffix_500]
    sum_weights = np.transpose(np.stack(sum_weights))

    prob_correct = testmodel.luces_choice(sum_weights)
    plots.plt_luce(prob_correct)
    plt.show()
コード例 #3
0
def exp1_follow_up():
    # alpha = exp1_alpha()
    alpha = 0.1
    learning_set, probabilities, categories, number_of_categories = get_experiment1_setup(
    )
    beta = 0.1
    n_trials = 2000

    p = Simulation(learning_set, probabilities, categories,
                   number_of_categories, "prefix", alpha, beta, n_trials)
    prefix_weights = p.simulate()

    s = Simulation(learning_set, probabilities, categories,
                   number_of_categories, "suffix", alpha, beta, n_trials)
    suffix_weights = s.simulate()

    # Figure 5.1 in thesis
    plots.exp1_plt_weights(prefix_weights, 1)
    plots.exp1_plt_weights(suffix_weights, 2)
    plt.show()
コード例 #4
0
from simulations import Simulation
import json
import sys
import numpy as np
import os

task_id = sys.argv[1]
task_id = int(task_id)-1

dest = '/jukebox/wang/deverett/simulations/batch_9'

with open('generation_params.json','r') as f:
    params = json.loads(f.read())
vars = params['variables']
vals = params['values']

var_n = int(np.floor(float(task_id)/float(len(vals[0]))))
val_n = task_id % len(vals[0])

varr = vars[var_n]
val_list = vals[var_n]
val = val_list[val_n]
    
name = "%02d_%03d"%(var_n+1,val_n+1)
sim = Simulation(name)
setattr(sim,varr,val)
sim.generate_movie()
sim.save_mov(fmt='tif',dest=dest)
sim.save_data(fmt='npy', dest=dest)
#sim.save_data(fmt='mat', dest=dest)
コード例 #5
0
    probabilities = np.array([0.75, 0.25, 0.75, 0.25]) / 2.
    categories = np.array([0, 0, 1, 1])

    number_of_categories = 2

    return (learning_set, probabilities, categories, number_of_categories)


learning_set, probabilities, categories, number_of_categories = get_experiment3_setup(
)
alpha = 0.1
beta = 0.1
n_trials = 7000

p = Simulation(learning_set, probabilities, categories, number_of_categories,
               "prefix", alpha, beta, n_trials)
prefix_weights = p.simulate()

s = Simulation(learning_set, probabilities, categories, number_of_categories,
               "suffix", alpha, beta, n_trials)
suffix_weights = s.simulate()


def exp3_test_raw(test_features, test_trials):
    """Test the model as follows:
    Do a single run of the model. 
    Do an additional 499 runs and average the weights across runs (testmodel.averaged_weights).
    For a test item, sum up the weights of its features for the correct and the incorerct affix (testmodel.test).

    Return:
        weights: for both conditions, the raw weight sum for the correct affix and the incorrect affix 
コード例 #6
0
import sys
import Image
import numpy as np

from sys import path
path.append('.')

from nanowebs import creeNanoWeb1
from nanowebs import creeNanoWeb2
from nanowebs import creeNanoWeb3

from simulations import Simulation


#Créer une ditribution de probabilité uniforme
def creeEstimation(taille):
    pi_t = dict()
    for i in range(taille):
        pi_t[i] = 1.0 / float(taille)
    return np.array(pi_t.values())


pi_t = np.array([0.08, 0.1, 0.1, 0.05, 0.3, 0.05, 0.01, 0.02, 0.09, 0.02])

nanoweb = creeNanoWeb3()
s = Simulation(nanoweb)
s.trace(10, "epsilon1.txt")
#s.estimate(10000,0.0001,pi_t)
s.estimate(10000, 0.0001, creeEstimation(len(nanoweb.matrice)))
s.showFrequencies()
コード例 #7
0
from simulations import Simulation
# this is for manually generating single simulations. for batches, use "generate_simulation*s*.py"

dest = './output'
name = 'high_npil_22'

sim = Simulation(name)
sim.imaging_noise = [0.,0.18] #0.1, 0.4 [making normal=0.18]
sim.neuropil_mag = 2.2 #0.05, 2.2 [normal=1.0]
sim.generate_movie()
sim.save_mov(fmt='tif',dest=dest)
sim.save_data(fmt='npy', dest=dest)
コード例 #8
0
 def train_model(self):
     prefix_weights = Simulation(self.learning_set, self.probabilities, self.categories, self.number_of_categories,
                                 "prefix", self.beta, self.n_trials).simulate()
     suffix_weights = Simulation(self.learning_set, self.probabilities, self.categories, self.number_of_categories,
                                 "suffix", self.beta, self.n_trials).simulate()
     return prefix_weights, suffix_weights