Пример #1
0
def learning(task, ncues = 2, trial_n=0, learn=True, debugging=True, debugging_arm=False, debugging_learning = False, duration=duration):
    trial(task, ncues=ncues, trial_n=trial_n, learn=learn, debugging=debugging, debugging_arm=debugging_arm, duration=duration)

    if debugging_learning:
        debug_learning(connections["CTX.cog -> CTX.ass"].weights, connections["CTX.mot -> CTX.ass"].weights,
                       connections["CTX.cog -> STR.cog"].weights, CUE["value"])

    return
Пример #2
0
def learning(inverse=False,
             inverse_all=True,
             f=None,
             trial_n=0,
             debugging=True,
             protocol='Piron',
             familiar=True,
             learn=True,
             hist=False,
             P=[],
             D=[],
             mBc=[],
             ABC=[],
             NoMove=[],
             RT=[],
             RP=None,
             AP=None):
    if hist:
        histor, time = trial(inverse=inverse,
                             inverse_all=inverse_all,
                             f=f,
                             trial_n=trial_n,
                             learn=learn,
                             protocol=protocol,
                             hist=hist,
                             familiar=familiar,
                             debugging=debugging,
                             P=P,
                             D=D,
                             RP=RP,
                             AP=AP,
                             mBc=mBc,
                             ABC=ABC,
                             NoMove=NoMove)
    else:
        time = trial(inverse=inverse,
                     inverse_all=inverse_all,
                     f=f,
                     trial_n=trial_n,
                     learn=learn,
                     protocol=protocol,
                     hist=hist,
                     familiar=familiar,
                     debugging=debugging,
                     P=P,
                     D=D,
                     RP=RP,
                     AP=AP,
                     mBc=mBc,
                     ABC=ABC,
                     NoMove=NoMove)
    RT.append(time)
    if not len(P) == trial_n + 1:
        P.append(0)
    if hist:
        return histor, RT, P, D, RP, AP, mBc, ABC, NoMove
    else:
        return RT, P, D, RP, AP, mBc, ABC, NoMove
Пример #3
0
def learning(reverse = False, reverse_all = True, f = None, trial_n = 0, debugging = True, protocol = 'Piron', familiar = True, learn = True, hist = False, P = [], D = [], mBc = [], ABC = [], NoMove = [], RT = [], RP = None, AP = None):
	if hist:
		histor, time = trial(reverse = reverse, reverse_all = reverse_all, f = f, trial_n = trial_n, learn = learn, protocol = protocol, hist = hist, familiar = familiar, debugging = debugging, P = P, D = D, RP = RP, AP = AP, mBc = mBc, ABC = ABC, NoMove = NoMove)
	else:
		time = trial(reverse = reverse, reverse_all = reverse_all, f = f, trial_n = trial_n, learn = learn, protocol = protocol, hist = hist, familiar = familiar, debugging = debugging, P = P, D = D, RP = RP, AP = AP, mBc = mBc, ABC = ABC, NoMove = NoMove)
	RT.append(time)
	if not len(P) == trial_n+1:
		P.append(0)
	if hist:
		return histor, RT, P, D, RP, AP, mBc, ABC, NoMove
	else:
		return RT, P, D, RP, AP, mBc, ABC, NoMove
Пример #4
0
def testing_trials(f=None,
                   trials=n_trials,
                   debugging=True,
                   save=False,
                   protocol='Piron',
                   familiar=True,
                   hist=False):
    P, D, mBc, ABC, NoMove, RT = [], [], [], [], [], []
    AP = np.zeros(n)
    for j in range(trials):
        if debugging:
            print 'Trial: ', j + 1
        if hist:
            histor, time = trial(f=f,
                                 trial_n=j,
                                 learn=False,
                                 protocol=protocol,
                                 hist=hist,
                                 familiar=familiar,
                                 debugging=debugging,
                                 P=P,
                                 D=D,
                                 AP=AP,
                                 mBc=mBc,
                                 ABC=ABC,
                                 NoMove=NoMove)
        else:
            time = trial(f=f,
                         trial_n=j,
                         learn=False,
                         protocol=protocol,
                         hist=hist,
                         familiar=familiar,
                         debugging=debugging,
                         P=P,
                         D=D,
                         AP=AP,
                         mBc=mBc,
                         ABC=ABC,
                         NoMove=NoMove)
        RT.append(time)
        if not len(P) == j + 1:
            P.append(0)
    debug(f=f, P=P, D=D, AP=AP, mBc=mBc, ABC=ABC, NoMove=NoMove)
    print
    if save:
        return P, RT, np.array(D).mean(), AP, np.array(mBc).mean(), np.array(
            ABC).mean(), len(NoMove) / float(trials)
    if hist:
        return histor
Пример #5
0
def learning(task, trial_n = 0, learn = True, debugging = True):

	time = trial(task, trial_n = trial_n, learn = learn, debugging = debugging)

	if debugging and learn:
		debug_learning(connections["CTX.cog -> CTX.ass"].weights, connections["CTX.mot -> CTX.ass"].weights, connections["CTX.cog -> STR.cog"].weights, CUE["value"])

	return
Пример #6
0
def learning_trials(task, trials=n_learning_positions_trials, debugging=True, debug_simulation=False, duration=duration):
    if debug_simulation:
        steps = trials / 145
        print('  Starting   ', end=' ')

    for i in range(trials):

        trial(task, duration=duration, trial_n = i, debugging=debugging, wholeFig=True)

        if debug_simulation:
            if i % steps == 0:
                print('\b.', end=' ')
                sys.stdout.flush()

    if debug_simulation:
        print('   Done!')

    return
Пример #7
0
def testing_trials(f = None, trials = n_trials, debugging = True, save = False, protocol = 'Piron', familiar = True, hist = False):
	P, D, mBc, ABC, NoMove, RT = [], [], [], [], [], []
	AP = np.zeros(n)
	for j in range(trials):
		if debugging:
			print 'Trial: ', j + 1
		if hist:
			histor, time = trial(f = f, trial_n = j, learn = False, protocol = protocol, hist = hist, familiar = familiar, debugging = debugging, P = P, D = D, AP = AP, mBc = mBc, ABC = ABC, NoMove = NoMove)
		else:
			time = trial(f = f, trial_n = j, learn = False, protocol = protocol, hist = hist, familiar = familiar, debugging = debugging, P = P, D = D, AP = AP, mBc = mBc, ABC = ABC, NoMove = NoMove)
		RT.append(time)
		if not len(P) == j+1:
			P.append(0)
	debug(f = f, P = P, D = D, AP = AP, mBc = mBc, ABC = ABC, NoMove = NoMove)
	print
	if save:
		return P, RT, np.array(D).mean(), AP, np.array(mBc).mean(), np.array(ABC).mean(), len(NoMove)/float(trials)
	if hist:
		return histor
def learning(reverse = False, reverse_all = True, f = None, trial_n = 0, debugging = True, protocol = 'Piron', familiar = True, learn = True, hist = False, P = [], RT = [], ncues = 2):
	if hist:
		histor, time = trial(reverse = reverse, reverse_all = reverse_all, f = f, trial_n = trial_n, learn = learn, protocol = protocol, hist = hist, familiar = familiar, debugging = debugging, P = P, ncues = ncues)
	else:
		time = trial(reverse = reverse, reverse_all = reverse_all, f = f, trial_n = trial_n, learn = learn, protocol = protocol, hist = hist, familiar = familiar, debugging = debugging, P = P, ncues = ncues)
	RT.append(time)
	if not len(P) == trial_n+1:
		P.append(0)
	if hist:
		print("Mean Cognitive Striatal activity: [", end=' ')
		for i in range(n):
			print(np.amax(histor["STR"]["cog"][:,i]), end=' ')

			#print histor["STR"]["cog"][np.nonzero(histor["STR"]["cog"][:,i]),i].mean(),
			#print histor["STR"]["cog"][:,i].mean(),
		print("]")
		print("Mean Motor Striatal activity: [", end=' ')
		for i in range(n):
			print(histor["STR"]["mot"][np.nonzero(histor["STR"]["mot"][:,i]),i].mean(), end=' ')
			#print histor["STR"]["mot"][:,i].mean(),
		print("]")
		return histor, RT, P
	else:
		return RT, P
# -----------------------------------------------------------------------------
# Copyright (c) 2015, Meropi Topalidou
# Distributed under the (new) BSD License.
#
# Contributors: Meropi Topalidou ([email protected])
# -----------------------------------------------------------------------------

# Evolution of single trial with Piron protocol
# -----------------------------------------------------------------------------

if __name__ == "__main__":
	temp = '../cython/'
	import sys
	sys.path.append(temp)
	from model import *
	from display import *
	from trial import *

	reset(protocol = 'OneChoice')
	# Make GPi lesion
	#connections["GPI.cog -> THL.cog"].active = False
	#connections["GPI.mot -> THL.mot"].active = False
	global cues_cog, cues_mot
	cues_cog, cues_mot = trials_cues(protocol = 'OneChoice')
	#print cues_cog
	result = results(n_trials = 1)
	histor, time = trial(result, hist = True, debugging = True, protocol = 'OneChoice', wholeFig = True)
	if 1: display_ctx(histor, 3.0)
	if 0: display_ctx(histor, 3.0, "single-trial-NoBG.pdf")
	if 0: display_all(histor, 3.0)#, "single-trial-all.pdf")
    temp = '../cython/'
    import sys
    sys.path.append(temp)
    # model file build the structures and initialize the model
    from model import *
    from display import *
    from trial import *
    from task_a import Task_A

    # 1 if there is presentation of cues else 0
    cues_pres = 1

    # Initialize the system
    reset()

    # Define the shapes and the positions that we'll be used to each trial
    # n should be multiple of 6 because there are 6 valuable combinations of shapes and positions
    task = Task_A(n=6)

    # Compute a single trial
    time = trial(task, cues_pres=cues_pres, wholeFig=True)

    #retrieve the activity history of the structures
    histor = history()

    # Display cortical activity during the single trial
    if 1: display_ctx(histor, 3.0)#, "single-trial.pdf")

    # Display activity from all structures during the single trial
    if 0: display_all(histor, 3.0)  # , "single-trial-all.pdf")
Пример #11
0
	try:
		num_trials_input = input("Enter Num of trials or 'quit' to exit:")
		if num_trials_input == 'quit':
			break
		else:
			try:
				num_trials = Num_trials(num_trials_input).num_trials
				break
			except InvalidInput:
				print('Invalid Input!')
				continue
	except KeyboardInterrupt:
		print('User Interrupt')
	except EOFError:
		print('Input Error')

f = open("results.txt","w")
for position in positions:
	t = trial(position, num_trials)
	t.plot_hist()
	mean = t.mean_std()[0]
	std = t.mean_std()[1]
	f.write("Position = {}: mean = {:.4f}, std = {:.4f} \n".format(position, mean, std))
f.close()

		




    from display import *
    from trial import *
    from task_b import Task_B

    # 1 if there is presentation of cues else 0
    cues_pres = 1
    # Initialize the system
    reset()

    # Define the shapes and the positions that we'll be used to each trial
    # n should be multiple of 6 because there are 6 valuable combinations of positions
    task = Task_B(n=6)

    GPi_lesion = False
    # Make GPi lesion
    if GPi_lesion:
        connections["GPI.cog -> THL.cog"].active = False
        connections["GPI.mot -> THL.mot"].active = False

    # Compute a single trial
    trial(task, debugging=True, cues_pres=cues_pres, wholeFig=True)
    # Retrieve the activity history of the structures
    histor = history()

    # Display cortical activity during the single trial

    if 1: display_ctx(histor, 3.0)#, "single-trial.pdf"), "single-trial-NoBG.pdf")#

    # Display activity from all structures during the single trial
    if 0: display_all(histor, 3.0)  # , "single-trial-all.pdf")
Пример #13
0
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright (c) 2015, Meropi Topalidou
# Distributed under the (new) BSD License.
#
# Contributors: Meropi Topalidou ([email protected])
#				Nicolas Rougier  ([email protected])
# -----------------------------------------------------------------------------

# Evolution of single trial with Guthrie protocol
# -----------------------------------------------------------------------------

if __name__ == "__main__":
	from model import *
	from display import *
	from trial import *

	cues_pres = input('\nDo you want to present cues?\nChoose 1 for True or 0 for False\n')
	reset(protocol = 'Guthrie')
	# Make GPi lesion
	# connections["GPI.cog -> THL.cog"].active = False
	# connections["GPI.mot -> THL.mot"].active = False
	histor, time = trial(hist = True, debugging = True, protocol = 'Guthrie', cues_pres = cues_pres, wholeFig = True)
	if 1: display_ctx(histor, 3.0)
	if 0: display_ctx(histor, 3.0, "single-trial-NoBG.pdf")
	if 1: display_all(histor, 3.0)#, "single-trial-all.pdf")
def single_trial():
    # 1 if there is presentation of cues else 0
    cues_pres = 1
    trials = 1
    # Define the shapes and the positions that we'll be used to each trial
    # n should be multiple of 6 because there are 6 valuable combinations of shapes and positions
    task = Task_1ch(n=81*4)

    # Compute a single trial
    time = trial(task, cues_pres=cues_pres, ncues=1, duration=duration_learning_positions,
                                 debugging=True, wholeFig=True) # trial_continuous_move #
    print(("Moves        : ", task.records[0]["moves"]))
    print(("Time         : ", time))

    # retrieve the activity history of the structures
    # histor = history()
    # mot = histor["CTX"]["mot"][:time]
    # pfc1 = histor["PFC"]["theta1"][:time]
    # pfc2 = histor["PFC"]["theta2"][:time]
    # sma1 = histor["SMA"]["theta1"][:time]
    # sma2 = histor["SMA"]["theta2"][:time]
    # arm1 = histor["ARM"]["theta1"][:time]
    # arm2 = histor["ARM"]["theta2"][:time]
    # ppc1 = histor["PPC"]["theta1"][:time]
    # ppc2 = histor["PPC"]["theta2"][:time]
    #
    # plt.figure()
    # plt.plot(mot)
    # plt.title('Mot')
    #
    # plt.figure()
    # plt.plot(arm1)
    # plt.title('Arm1')
    #
    # plt.figure()
    # plt.plot(arm2)
    # plt.title('Arm2')
    #
    # plt.figure()
    # plt.plot(sma1)
    # plt.title('SMA1')
    # plt.figure()
    # plt.plot(sma2)
    # plt.title('SMA2')
    #
    # plt.figure()
    # plt.plot(pfc1)
    # plt.title('PFC1')
    # plt.figure()
    # plt.plot(pfc2)
    # plt.title('PFC2')
    #
    # plt.figure()
    # plt.plot(ppc1)
    # plt.title('PPC1')
    #
    # plt.figure()
    # plt.plot(ppc2)
    # plt.title('PPC2')
    # plt.show()
    # Display cortical activity during the single trial
    if 0: display_ctx(histor, 3.0)  # , "single-trial.pdf")
Пример #15
0
    # Define the shapes and the positions that we'll be used to each trial
    # n should be multiple of 6 because there are 6 valuable combinations of shapes and positions
    task = Task_A(n=6)

    folder = "../Results/Learn_Positions"
    f = folder + "/Records.npy"
    temp = np.load(f)
    connections["PPC.theta1 -> PFC.theta1"].weights = temp["Wppc_pfc1"][-1]
    connections["PFC.theta1 -> STR_PFC_PPC.theta1"].weights = temp["Wpfc_str1"][-1]
    connections["PPC.theta1 -> STR_PFC_PPC.theta1"].weights = temp["Wppc_str1"][-1]
    connections["PPC.theta2 -> PFC.theta2"].weights = temp["Wppc_pfc2"][-1]
    connections["PFC.theta2 -> STR_PFC_PPC.theta2"].weights = temp["Wpfc_str2"][-1]
    connections["PPC.theta2 -> STR_PFC_PPC.theta2"].weights = temp["Wppc_str1"][-1]
    # Compute a single trial
    time = trial(task, wholeFig=True, debugging=True)
    print "  Moves                 : ", task.records[0]["moves"]

    # retrieve the activity history of the structures
    histor = history()
    ctx = histor["CTX"]["mot"][:time]
    arm1 = histor["ARM"]["theta1"][:time]
    arm2 = histor["ARM"]["theta2"][:time]

    plt.figure()
    plt.plot(arm1)
    plt.title("Arm1")

    plt.figure()
    plt.plot(arm2)
    plt.title("Arm2")
Пример #16
0
import sys
sys.path.append(
    '/Users/mtopalid/Desktop/PhD/Models/Basal_Ganglia/Piron-et-al-2014/cython/'
)
from model import *
from display import *
from trial import *

reset(protocol='Piron')
#connections["CTX.cog -> STR.cog"].weights = np.array([ 0.75, 0.4761739, 0.45899682, 0.46005381])
histor, time = trial(hist=True, debugging=True, protocol='Piron')
if 1: display_ctx(histor, 3.0)
if 0: display_ctx(histor, 3.0, "single-trial.pdf")
if 0:
    display_all(histor, 3.0, "single-trial-all.pdf")
Пример #17
0
    sys.path.append(temp)
    # model file build the structures and initialize the model
    from model import *
    from display import *
    from trial import *
    from task_1ch import Task_1ch

    # 1 if there is presentation of cues else 0
    cues_pres = 1
    trials = 1
    # Define the shapes and the positions that we'll be used to each trial
    # n should be multiple of 6 because there are 6 valuable combinations of shapes and positions
    task = Task_1ch(n=6)

    # Compute a single trial
    time = trial(task, cues_pres=cues_pres, ncues=1, duration=duration_learning_positions, debugging=True, wholeFig=True)
    print "Moves        : ", task.records[0]["moves"]
    print time

    # retrieve the activity history of the structures
    histor = history()
    pfc1 = histor["PFC"]["theta1"][:time]
    pfc2 = histor["PFC"]["theta2"][:time]
    sma1 = histor["SMA"]["theta1"][:time]
    sma2 = histor["SMA"]["theta2"][:time]
    arm1 = histor["ARM"]["theta1"][:time]
    arm2 = histor["ARM"]["theta2"][:time]
    ppc1 = histor["PPC"]["theta1"][:time]
    ppc2 = histor["PPC"]["theta2"][:time]

    plt.figure()
Пример #18
0
import sys
sys.path.append('/Users/mtopalid/Desktop/PhD/Models/Basal_Ganglia/Topalidou-et-al-2015/cython/')
from model import *
from display import *
from trial import *

reset(protocol = 'Guthrie')
#connections["CTX.cog -> STR.cog"].weights = np.array([ 0.75, 0.4761739, 0.45899682, 0.46005381])
histor, time = trial(hist = True, debugging = True, protocol = 'Guthrie')
if 0: display_ctx(histor, 3.0)
if 1: display_all(histor, 3.0)
if 0: display_ctx(histor, 3.0, "single-trial.pdf")
if 0: display_all(histor, 3.0, "single-trial-all.pdf")
def single_trial():
    # 1 if there is presentation of cues else 0
    # cues_pres = 1
    # trials = 1
    # Define the shapes and the positions that we'll be used to each trial
    # n should be multiple of 6 because there are 6 valuable combinations of shapes and positions
    task = Task()

    # Compute a single trial
    time = trial(task, duration=duration, debugging=True,
                 wholeFig=True)
    # print "Moves        : ", task.records[0]["moves"]
    # print "Time         : ", time

    # retrieve the activity history of the structures
    histor = history(dur=time)
    ppc = histor["PPC"]["str"]#[:time]
    sma = histor["SMA"]["str"]#[:time]
    trg = histor["TARGET"]["str"]#[:time]
    ism = histor["ISM"]["str"]#[:time]
    m1in = histor["M1_in"]["str"]#[:time]
    m1out = histor["M1_out"]["str"]#[:time]
    str = histor["STR"]["str"]#[:time]
    # stn = histor["STN"]["str"][:time]
    thl = histor["THL"]["str"]#[:time]
    # gpi = histor["GPI"]["str"][:time]


    plt.figure(figsize=(18, 9))
    plt.subplot(331)
    plt.plot(ppc)
    plt.ylim(ppc.min() - 10, ppc.max() + 10)
    plt.xlim(-10, +5010)
    plt.title('PPC')

    plt.subplot(334)
    plt.plot(sma[:, 0], c='b', label="Up")
    plt.plot(sma[:, 1], c='r', label="Down")
    plt.plot(sma[:, 2], c='g', label="Stay")
    plt.plot(sma[:, 3], c='m', label="Right")
    plt.plot(sma[:, 4], c='c', label="Left")
    plt.legend()
    plt.ylim(sma.min() - 10, sma.max() + 10)
    # plt.xlim(-100, +5100)
    plt.title('SMA')

    plt.subplot(336)
    plt.plot(trg[:, 0], c='b', label=1)
    plt.plot(trg[:, 1], c='r', label=2)
    plt.plot(trg[:, 2], c='g', label=3)
    plt.plot(trg[:, 3], c='m', label=4)
    plt.plot(trg[:, 4], c='c', label=5)
    plt.plot(trg[:, 5], c='y', label=6)
    plt.plot(trg[:, 6], c='k', label=7)
    plt.plot(trg[:, 7], 'bo', label=8)
    plt.plot(trg[:, 8], 'r*', label=9)
    # plt.legend()
    plt.title('Target')
    #
    #
    plt.subplot(332)
    plt.plot(m1in)
    plt.title('M1in')

    plt.subplot(335)
    plt.plot(m1out[:, 0], c='b', label=0)
    plt.plot(m1out[:, 1], c='r', label=1)
    plt.plot(m1out[:, 2], c='g', label=2)
    plt.plot(m1out[:, 3], c='m', label=3)
    plt.plot(m1out[:, 4], c='c', label=4)
    plt.plot(m1out[:, 5], c='y', label=5)
    plt.plot(m1out[:, 6], c='k', label=6)
    plt.plot(m1out[:, 7], 'bo', label=7)
    plt.plot(m1out[:, 8], 'r*', label=8)
    plt.title('M1out')
    #
    #
    #
    plt.subplot(333)
    plt.plot(ism[:, 0], c='b', label=1)
    plt.plot(ism[:, 1], c='r', label=2)
    plt.plot(ism[:, 2], c='g', label=3)
    plt.plot(ism[:, 3], c='m', label=4)
    plt.plot(ism[:, 4], c='c', label=5)
    plt.plot(ism[:, 5], c='y', label=6)
    plt.plot(ism[:, 6], c='k', label=7)
    plt.plot(ism[:, 7], 'bo', label=8)
    plt.plot(ism[:, 8], 'r*', label=9)
    plt.title('ISM')

    plt.subplot(337)
    init_pos = task.trials[0]["initial_pos_arm"]
    prop = np.ones(trg.shape[0]) * init_pos
    plt.plot(prop)
    plt.title('Propioceptors')

    # plt.subplot(337)
    # plt.plot(stn)
    # plt.title('stn')
    # plt.ylim(stn.min()-10, stn.max()+10)
    # plt.xlim(-100, +5100)

    plt.subplot(338)
    plt.plot(str)
    plt.title('str')
    plt.ylim(str.min() - 10, str.max() + 10)
    # plt.xlim(-100, +5100)

    plt.subplot(339)
    plt.plot(thl)
    plt.title('Thalamus')
    plt.ylim(thl.min() - 10, thl.max() + 10)
    # plt.xlim(-100, +5100)

    # plt.subplot(335)
    # plt.plot(gpi)
    # plt.title('GPi')
    # plt.ylim(gpi.min()-100, gpi.max()+100)
    # plt.xlim(-100, +5100)
    plt.show()