plateform stringclasses 1
value | repo_name stringlengths 13 113 | name stringlengths 3 74 | ext stringclasses 1
value | path stringlengths 12 229 | size int64 23 843k | source_encoding stringclasses 9
values | md5 stringlengths 32 32 | text stringlengths 23 843k |
|---|---|---|---|---|---|---|---|---|
github | qihongl/mathCognition_PDP_RL-master | runAgent.m | .m | mathCognition_PDP_RL-master/[past]/sim15_forcing+/runAgent.m | 1,360 | utf_8 | a45bbbf2af406938d3fc529eb08d3c87 | % written by professor Jay McClelland
function [ results ] = runAgent()
global a w h p mode;
% rng(seed)
% w.seed = seed;
%% initialize the state
initState();
updateState();
computeAnswer(); % compute the true 'answers'
%% training the model once
i = 0;
indices = zeros(1,p.maxIter);
while ~(w.done) &... |
github | qihongl/mathCognition_PDP_RL-master | trainOne.m | .m | mathCognition_PDP_RL-master/[past]/sim15_forcing+/trainOne.m | 261 | utf_8 | edaa7ef58bfc2663a7bca442494a4c29 | % just testing, a short cut for running the model
function trainOne(epoch)
if nargin == 0
epoch = 5000;
end
record = trainAgent(epoch);
save('record','record');
% eval the performance
quiz()
checkLearning()
beep % notice me that the program was ended
end
|
github | qihongl/mathCognition_PDP_RL-master | updateWeights.m | .m | mathCognition_PDP_RL-master/[past]/sim15_forcing+/updateWeights.m | 706 | utf_8 | 53448a755be732aa3a23ac74686795a2 | % written by professor Jay McClelland
function [ ] = updateWeights()
% this function controls:
% 1. the reward policy
% 2. the weight update
% 3. activate the "teaching"
global a w p;
%% compute the reward values according to the reward policy
Rwd = computeRwd();
%% assign the reward values
a.Rwd = Rwd;
% ... |
github | qihongl/mathCognition_PDP_RL-master | initParams.m | .m | mathCognition_PDP_RL-master/[past]/sim15_forcing+/initParams.m | 1,760 | utf_8 | 4bb817ecd263aa4032ffd843f0032418 | % written by professor Jay McClelland
function [] = initParams(epoch)
% This program initialize and preallocate the parameters needed for the
% model. This should be executed before the simulations.
global p a
%% modeling parameters
p.wf = .1; % noise magnitude
p.lrate = .005; % learning rate
... |
github | qihongl/mathCognition_PDP_RL-master | computeRwd2.m | .m | mathCognition_PDP_RL-master/[past]/sim15_forcing+/computeRwd2.m | 1,731 | utf_8 | bb2799e2a46161ad5a12b2658bbcd32f | function rwd = computeRwd2()
%% this function controls the reward policy
global w p h;
w.actionCorrect = true;
if isNext()
w.rS.targRemain(w.rS.handPos == w.rS.targPos) = false;
rwd = p.r.midPos;
if ~targetRemain()
rwd = p.r.midPos;
w.done = true;
end
else
if w.rS.handPos < nextOb... |
github | qihongl/mathCognition_PDP_RL-master | updateState.m | .m | mathCognition_PDP_RL-master/[past]/sim15_forcing+/updateState.m | 949 | utf_8 | 71fbfd2359d475c11bde119d444d2c38 | % written by professor Jay McClelland
function [ ] = updateState()
%this function uses the real state to update the internal state
%after Act is called to execute the hand or eye movement action
global w h p;
%% compute the relative locations
% the relative locations of eye and hand
w.vS.eyePos = 0;
w.vS.ha... |
github | qihongl/mathCognition_PDP_RL-master | initState.m | .m | mathCognition_PDP_RL-master/[past]/sim15_forcing+/initState.m | 1,432 | utf_8 | 7561a06284dd85df0d01896e4fcb51af | % written by professor Jay McClelland
function [ ] = initState( )
global a w h p mode;
%realState is characterized by the position of a target to touch,
%position of eye, and position of hand 1-d space
%viewedState is the input I have given that my eye and hand are
%at particular positions w.r.t. the realSt... |
github | qihongl/mathCognition_PDP_RL-master | plotResults.m | .m | mathCognition_PDP_RL-master/[past]/sim15_forcing+/plotResults.m | 544 | utf_8 | da928d22f60607e06a82b5f24fe4b624 | function plotResults(record)
global d;
% initialize the parameters for the plot
d.fh = figure();
d.fh.WindowStyle = 'docked';
d.rax = subplot(3,1,1);
d.hax = subplot(3,1,2);
d.wax = subplot(3,1,3);
% d.dtimes = 2.^(10:10);
% load('record.mat');
for i = 1 : size(record.r{size(record.r,2)}.h,2)
plotRes(i, record);
e... |
github | qihongl/mathCognition_PDP_RL-master | trainAgent.m | .m | mathCognition_PDP_RL-master/[past]/sim15_forcing+/trainAgent.m | 1,231 | utf_8 | c65f4bcc763824d0db76ea96164657b8 | %% Trains the network n trials
% written by professor Jay McClelland
function [record] = trainAgent(epoch)
%% initialization
% initialize parameters
global p a w mode;
initParams(epoch);
% preallocate
record.a = cell(1,epoch);
s.steps = nan(1,epoch);
s.indices = cell(1,epoch);
s.completed = false(1,epoch)... |
github | qihongl/mathCognition_PDP_RL-master | computeRwd.m | .m | mathCognition_PDP_RL-master/[past]/sim15_forcing+/computeRwd.m | 2,610 | utf_8 | 10c26b1fe0767fa60553b9a7741014f2 | function Rwd = computeRwd()
%% this function controls the reward policy
global w p h;
w.actionCorrect = true;
% if there is remaining items
if targetRemain()
if w.out.handStep == 0 % not moving
Rwd = p.r.smallNeg;
% if stop too long, also termiante
% if h(w.stateNum).w.out.handStep == 0... |
github | qihongl/mathCognition_PDP_RL-master | Act.m | .m | mathCognition_PDP_RL-master/[past]/sim15_forcing+/Act.m | 402 | utf_8 | 9240309e992077ffcf3f10b3cc146514 | % written by professor Jay McClelland
function [ ] = Act( )
% here we act according to the action selected
% by selectAction
global w;
%% perform the actions
% update the real locations of hand and eye
w.rS.handPos = w.rS.handPos + w.out.handStep;
w.rS.eyePos = w.rS.eyePos + w.out.eyeStep;
w.rS.td = 1; %... |
github | qihongl/mathCognition_PDP_RL-master | runAgent.m | .m | mathCognition_PDP_RL-master/[past]/sim16.5.1_nohidden/runAgent.m | 935 | utf_8 | 63e17518c01b818647117d4c4ed5b343 | % written by professor Jay McClelland
function [ results ] = runAgent()
global a w h p mode;
%% initialize the state
initState();
updateState();
computeAnswer(); % compute the true 'answers'
%% training the model once
i = 0;
indices = zeros(1,p.maxIter);
while ~(w.done) && i < p.maxIter
%% choose ... |
github | qihongl/mathCognition_PDP_RL-master | trainOne.m | .m | mathCognition_PDP_RL-master/[past]/sim16.5.1_nohidden/trainOne.m | 594 | utf_8 | b04fa7f72976b17585c806628b34dfe6 | % just testing, a short cut for running the model
function record = trainOne(epoch, seed)
if nargin == 0
epoch = 10000;
seed = randi(99);
end
%% run the simulation
record = trainAgent(epoch, seed);
%% save the simulation results
saveDirName = getSaveDir();
save([saveDirName '/' 'record'],'record');
save('reco... |
github | qihongl/mathCognition_PDP_RL-master | showWeights.m | .m | mathCognition_PDP_RL-master/[past]/sim16.5.1_nohidden/showWeights.m | 583 | utf_8 | a5170d34eef2535437720fe5e1a446a5 | function [ ] = showWeights( )
% plot the weights of the model
global p d a;
% plot weights around fovea
axes(d.heatWts)
% imagesc(-p.eyeRad:p.eyeRad,-p.mvRad:p.mvRad+1, a.wts)
visualizeWeightsMatrix(a.wts)
title(d.heatWts, 'Weights: visual -> action', 'fontsize', d.FONTSIZE)
xlabel(d.heatWts, 'Visual input layer', 'fon... |
github | qihongl/mathCognition_PDP_RL-master | updateWeights.m | .m | mathCognition_PDP_RL-master/[past]/sim16.5.1_nohidden/updateWeights.m | 757 | utf_8 | 7f4eeccf457516b605f4f4f9540867d8 | % written by professor Jay McClelland
function [ ] = updateWeights()
% this function controls:
% 1. the reward policy
% 2. the weight update
% 3. activate the "teaching"
global p a w;
%% compute the reward values according to the reward policy
a.curRwd = computeRwd();
a.act_next = a.wts*w.vS.visInput';
a.act_... |
github | qihongl/mathCognition_PDP_RL-master | showState.m | .m | mathCognition_PDP_RL-master/[past]/sim16.5.1_nohidden/showState.m | 2,369 | utf_8 | c21f87f660c0fca0cff629e57b109e9f | % written by professor Jay McClelland
function [ ] = showState( )
global p w d a;
%% plot current and expected rewards over time
axes(d.rwd);
plot(w.rS.time,a.curRwd,'-b*'); hold on;
plot(w.rS.time,a.expRwd,'-r*');
legend({'current reward', 'esimtated reward'},...
'Location','northwest', 'fontsize', d.F... |
github | qihongl/mathCognition_PDP_RL-master | initParams.m | .m | mathCognition_PDP_RL-master/[past]/sim16.5.1_nohidden/initParams.m | 2,205 | utf_8 | 6b3281676830abff17d9afc164232c72 | % written by professor Jay McClelland
function [] = initParams(epoch)
% This program initialize and preallocate the parameters needed for the
% model. This should be executed before the simulations.
global p a
p.teachingStyle = 4;
% 1 = final reward only
% 2 = intermediate reward
% 3 = final reward only + tea... |
github | qihongl/mathCognition_PDP_RL-master | updateState.m | .m | mathCognition_PDP_RL-master/[past]/sim16.5.1_nohidden/updateState.m | 1,022 | utf_8 | a5543b71621025d356ba32965449739a | % written by professor Jay McClelland
function [ ] = updateState()
%this function uses the real state to update the internal state
%after Act is called to execute the hand or eye movement action
global w h p a;
%% compute the relative locations
% the relative locations of eye and hand
w.vS.eyePos = 0;
w.vS.... |
github | qihongl/mathCognition_PDP_RL-master | initState.m | .m | mathCognition_PDP_RL-master/[past]/sim16.5.1_nohidden/initState.m | 1,665 | utf_8 | 4089ab3033ac759bf8c9857f7d1932f2 | % written by professor Jay McClelland
function [ ] = initState( )
global a w h p mode;
%realState is characterized by the position of a target to touch,
%position of eye, and position of hand 1-d space
%viewedState is the input I have given that my eye and hand are
%at particular positions w.r.t. the realSt... |
github | qihongl/mathCognition_PDP_RL-master | trainAgent.m | .m | mathCognition_PDP_RL-master/[past]/sim16.5.1_nohidden/trainAgent.m | 1,501 | utf_8 | 704f98828c45de576b681eb325399789 | %% Trains the network n trials
% written by professor Jay McClelland
function [record] = trainAgent(epoch, seed)
%% initialization
% initialize parameters
global p a w mode;
initParams(epoch);
p.seed = seed;
rng(seed)
% preallocate
record.a = cell(1,epoch);
s.steps = nan(1,epoch);
s.indices = cell(1,epoch... |
github | qihongl/mathCognition_PDP_RL-master | runAgent.m | .m | mathCognition_PDP_RL-master/[past]/sim16.4_newPolicy/runAgent.m | 1,514 | utf_8 | 4fc12b3ebb17803f52dfcdb2c2e78338 | % written by professor Jay McClelland
function [ results ] = runAgent()
global a w h p mode;
% rng(seed)
% w.seed = seed;
%% initialize the state
initState();
updateState();
computeAnswer(); % compute the true 'answers'
%% training the model once
i = 0;
indices = zeros(1,p.maxIter);
while ~(w.done) &... |
github | qihongl/mathCognition_PDP_RL-master | trainOne.m | .m | mathCognition_PDP_RL-master/[past]/sim16.4_newPolicy/trainOne.m | 489 | utf_8 | 480fbd634b40a2e355805264ff3e4ac7 | % just testing, a short cut for running the model
function record = trainOne(epoch, seed)
if nargin == 0
epoch = 5000;
seed = randi(99);
end
%% run the simulation
record = trainAgent(epoch, seed);
%% save the simulation results
saveDirName = getSaveDir();
save([saveDirName '/' 'record'],'record');
save('recor... |
github | qihongl/mathCognition_PDP_RL-master | updateWeights.m | .m | mathCognition_PDP_RL-master/[past]/sim16.4_newPolicy/updateWeights.m | 765 | utf_8 | 3bb0300b99810b7bcf00c4e8586e5db3 | % written by professor Jay McClelland
function [ ] = updateWeights()
% this function controls:
% 1. the reward policy
% 2. the weight update
% 3. activate the "teaching"
global p a w;
%% compute the reward values according to the reward policy
curRwd = computeRwd2();
expRwd = max(a.wts*w.vS.visInput');
%% ass... |
github | qihongl/mathCognition_PDP_RL-master | showState.m | .m | mathCognition_PDP_RL-master/[past]/sim16.4_newPolicy/showState.m | 1,317 | utf_8 | 5f98a0c96bcf734cfce4abd1d109c314 | % written by professor Jay McClelland
function [ ] = showState( )
global p w d a;
% plot current and expected rewards over time
axes(d.rwd);
plot(w.rS.time,a.Rwd,'-b*'); hold on;
plot(w.rS.time,a.dfRwd,'-r*');
legend({'current reward', 'discounted future reward'},...
'Location','northwest', 'fontsize', d.F... |
github | qihongl/mathCognition_PDP_RL-master | move.m | .m | mathCognition_PDP_RL-master/[past]/sim16.4_newPolicy/move.m | 403 | utf_8 | 76f0765b052705d3747442411be8e898 | % written by professor Jay McClelland
function [ ] = move( )
% here we act according to the action selected
% by selectAction
global w;
%% perform the actions
% update the real locations of hand and eye
w.rS.handPos = w.rS.handPos + w.out.handStep;
w.rS.eyePos = w.rS.eyePos + w.out.eyeStep;
w.rS.td = 1; ... |
github | qihongl/mathCognition_PDP_RL-master | initParams.m | .m | mathCognition_PDP_RL-master/[past]/sim16.4_newPolicy/initParams.m | 2,627 | utf_8 | 0bca05063c6f1d6bbb17023f245ae6ea | % written by professor Jay McClelland
function [] = initParams(epoch)
% This program initialize and preallocate the parameters needed for the
% model. This should be executed before the simulations.
global p a
% p.teachingStyle = 2;
% 1 = final reward only
% 2 = intermediate reward
% 3 = final reward only + t... |
github | qihongl/mathCognition_PDP_RL-master | computeRwd2.m | .m | mathCognition_PDP_RL-master/[past]/sim16.4_newPolicy/computeRwd2.m | 1,991 | utf_8 | 45c515cd014a3a3691c14f39d80b2c7a | function Rwd = computeRwd2()
%% this function controls the reward policy
global w p h a;
w.actionCorrect = true;
if w.out.handStep == 0 % not moving
Rwd = p.r.smallNeg;
elseif ~isTouchingObj % touching empty spot
Rwd = p.r.smallNeg;
elseif objIsTouched % touching touched object
Rwd = p.r... |
github | qihongl/mathCognition_PDP_RL-master | updateState.m | .m | mathCognition_PDP_RL-master/[past]/sim16.4_newPolicy/updateState.m | 1,006 | utf_8 | 7a3e797d0ba3c3d7ef608f158f0418ec | % written by professor Jay McClelland
function [ ] = updateState()
%this function uses the real state to update the internal state
%after Act is called to execute the hand or eye movement action
global w h p a;
%% compute the relative locations
% the relative locations of eye and hand
w.vS.eyePos = 0;
w.vS.... |
github | qihongl/mathCognition_PDP_RL-master | initState.m | .m | mathCognition_PDP_RL-master/[past]/sim16.4_newPolicy/initState.m | 1,594 | utf_8 | d62eadf6f64277fd0e0e4533bcc1baf3 | % written by professor Jay McClelland
function [ ] = initState( )
global a w h p mode;
%realState is characterized by the position of a target to touch,
%position of eye, and position of hand 1-d space
%viewedState is the input I have given that my eye and hand are
%at particular positions w.r.t. the realSt... |
github | qihongl/mathCognition_PDP_RL-master | plotResults.m | .m | mathCognition_PDP_RL-master/[past]/sim16.4_newPolicy/plotResults.m | 544 | utf_8 | da928d22f60607e06a82b5f24fe4b624 | function plotResults(record)
global d;
% initialize the parameters for the plot
d.fh = figure();
d.fh.WindowStyle = 'docked';
d.rax = subplot(3,1,1);
d.hax = subplot(3,1,2);
d.wax = subplot(3,1,3);
% d.dtimes = 2.^(10:10);
% load('record.mat');
for i = 1 : size(record.r{size(record.r,2)}.h,2)
plotRes(i, record);
e... |
github | qihongl/mathCognition_PDP_RL-master | trainAgent.m | .m | mathCognition_PDP_RL-master/[past]/sim16.4_newPolicy/trainAgent.m | 1,501 | utf_8 | 61e7aeb84f1a92e22f73306d60a6cdcd | %% Trains the network n trials
% written by professor Jay McClelland
function [record] = trainAgent(epoch, seed)
%% initialization
% initialize parameters
global p a w mode;
initParams(epoch);
p.seed = seed;
rng(seed)
% preallocate
record.a = cell(1,epoch);
s.steps = nan(1,epoch);
s.indices = cell(1,epoch... |
github | qihongl/mathCognition_PDP_RL-master | computeRwd.m | .m | mathCognition_PDP_RL-master/[past]/sim16.4_newPolicy/computeRwd.m | 2,255 | utf_8 | ffb5370d99695989298f09793052de31 | function Rwd = computeRwd()
%% this function controls the reward policy
global w p h a;
w.actionCorrect = true;
% if there is remaining items
if targetRemain()
if w.out.handStep == 0 % not moving
Rwd = p.r.smallNeg;
elseif ~isTouchingObj % touching empty spot
Rwd = p.r.smallNeg;
e... |
github | qihongl/mathCognition_PDP_RL-master | chooseAction.m | .m | mathCognition_PDP_RL-master/[past]/sim02_multipleTouch/chooseAction.m | 392 | utf_8 | 925648f37fd388e3f865ab51a2e7654b | function [w] = chooseAction(w,p,a)
% obtain the probability distribution for actions
prob = softmax(a.q(w.curs+1,:), p.qscale);
% choose action based
w.cura = sample(prob);
end
function [action] = sample(pr)
rv = rand(1); % sample from a unifrom[0,1]
cp = cumsum(pr);
for i = 1:length(pr) % choose an action... |
github | qihongl/mathCognition_PDP_RL-master | softmax.m | .m | mathCognition_PDP_RL-master/[past]/sim02_multipleTouch/softmax.m | 613 | utf_8 | 3aee03817ba069a85b86380554be8359 | % SOFTMAX assign probabilities to options
% in my case, x is expected to be a vector of q values for a state: Q(s,:)
function [prob] = softmax(x, scale)
% if there is no input scaling factor, just don't scale it
if nargin == 1
scale = 1;
end
% transform when there is negative values
% TODO: this transformation i... |
github | qihongl/mathCognition_PDP_RL-master | initState.m | .m | mathCognition_PDP_RL-master/[past]/sim02_multipleTouch/initState.m | 750 | utf_8 | f1e9d156eef933e4dcf4b1f6a4d55dfd | % INITSTATE initialize the state parameters, or set up the "world"
% written by Professor Jay McClelland
function [w] = initState(p)
% preallocation
w.curs = 0; % current state
w.cura = 0; % current action
w.nexts = 0; % next state
w.nexta = 0; % next action
w.R = 0; % reward
w.steps ... |
github | qihongl/mathCognition_PDP_RL-master | touch.m | .m | mathCognition_PDP_RL-master/[past]/sim02_multipleTouch/touch.m | 1,447 | utf_8 | 5fe704a818053efb95fc3727696c6d9a | %% a RL based model for counting
function output = touch(seed, doPlotting)
if nargin == 0
seed = randi(99); doPlotting = true;
end
% initialization
rng(seed);
%% modeing parameters
p = setupParameters();
% preallocate & initilize Q to small values
a.q = .01 + zeros(p.range+1,p.nactions);
h.stepsUsed = zeros(p.tria... |
github | qihongl/mathCognition_PDP_RL-master | setupParameters.m | .m | mathCognition_PDP_RL-master/[past]/sim02_multipleTouch/setupParameters.m | 542 | utf_8 | b01cdd523bcbe9b9c6cc9ce71f927c35 | %SETUPPARAMETERS returns the parameters for the model
function [p] = setupParameters()
% modeling parameters
p.gamma = 0.5; % discount factor
p.alpha = 0.2; % learning rate
p.qscale = 3; % softmax scale factor
% other parameters
p.range = 5; % the size of the state space
p.numItems = 3; ... |
github | qihongl/mathCognition_PDP_RL-master | runAgent.m | .m | mathCognition_PDP_RL-master/[past]/sim07_teach/runAgent.m | 1,057 | utf_8 | 92e7828fc50bc0e0e05764999878bda0 | % written by professor Jay McClelland
function [ results ] = runAgent(seed)
global a w h p;
rng(seed)
w.seed = seed;
%% initialize the state
initState();
updateState();
%% training the model once
i = 0;
teachTrial = 0;
indices = zeros(1,p.maxIter);
while ~(w.done) && i < p.maxIter
% alternate actio... |
github | qihongl/mathCognition_PDP_RL-master | updateWeights.m | .m | mathCognition_PDP_RL-master/[past]/sim07_teach/updateWeights.m | 2,685 | utf_8 | 9b0f5c33f06e367198016bedfbbc85e7 | % written by professor Jay McClelland
function [ ] = updateWeights()
% this function controls:
% 1. the reward policy
% 2. the weight update
% 3. activate the "teaching"
global a w p;
%% Assign the reward values
actionCorrect = true;
% if the model doesn't move (choose the middle action)
if a.choice == p.mv... |
github | qihongl/mathCognition_PDP_RL-master | selectAction.m | .m | mathCognition_PDP_RL-master/[past]/sim07_teach/selectAction.m | 625 | utf_8 | 3a9c3092d2a311003e085817e0adc4b9 | % written by professor Jay McClelland
function [] = selectAction( )
% It computes the output, and choose the action probabilistically.
global w a p;
%% compute the output activation
a.act = a.wts * w.vS.visInput';
% bias toward action 0 (don't move)
a.act(p.mvRad + 1) = a.act(p.mvRad + 1) + a.bias;
% choose... |
github | qihongl/mathCognition_PDP_RL-master | showState.m | .m | mathCognition_PDP_RL-master/[past]/sim07_teach/showState.m | 710 | utf_8 | 39516e279c4d8abde3950cfe0d60e97d | % written by professor Jay McClelland
function [ ] = showState( )
global p w d a;
axes(d.rax);
plot(w.rS.time,a.Rwd,'-*'); hold on;
ylim(d.rax,[-0.1 5.1]); xlim(d.rax,[-0.25,w.rS.time+0.25]);
t = w.rS.time;
% plot the history of eye and hand positions
axes(d.hax);
plot(d.hax,[-p.spRad p.spRad],[t t]); hold... |
github | qihongl/mathCognition_PDP_RL-master | initParamsEtc.m | .m | mathCognition_PDP_RL-master/[past]/sim07_teach/initParamsEtc.m | 1,396 | utf_8 | 1ffef4274917eac0233dacc8c0d13daa | % written by professor Jay McClelland
function [] = initParamsEtc(epoch)
% This program initialize and preallocate the parameters needed for the
% model. This should be executed before the simulations.
global p a
%% modeling parameters
p.wf = .05; % noise magnitude
p.lrate = .1; % learning rate... |
github | qihongl/mathCognition_PDP_RL-master | choose.m | .m | mathCognition_PDP_RL-master/[past]/sim07_teach/choose.m | 347 | utf_8 | 1a233802878abe937719c82c11e02d4c | % written by professor Jay McClelland
function [ choice ] = choose(strengths)
%choose one of n alternatives according to it's strength
v = rand; % a number between 0 and 1
nstr = strengths/sum(strengths); %normalize strengths
cstr = cumsum(nstr); %get top edges of bins
choice = find(cstr>v,1); %returns ... |
github | qihongl/mathCognition_PDP_RL-master | updateState.m | .m | mathCognition_PDP_RL-master/[past]/sim07_teach/updateState.m | 992 | utf_8 | d639692c6cf8c919b6841fc384456701 | % written by professor Jay McClelland
function [ ] = updateState()
%this function uses the real state to update the internal state
%after Act is called to execute the hand or eye movement action
global w a d h p;
%% compute the relative locations
% the relative locations of eye and hand
w.vS.eyePos = 0;
w.v... |
github | qihongl/mathCognition_PDP_RL-master | initState.m | .m | mathCognition_PDP_RL-master/[past]/sim07_teach/initState.m | 1,519 | utf_8 | ba6aa8344ec8e7760db73c9653b6745c | % written by professor Jay McClelland
function [ ] = initState( )
global a w d h p;
%realState is characterized by the position of a target to touch,
%position of eye, and position of hand
%in a 101-pixel one-d space
%viewedState is the input I have given that my eye and hand are
%at particular positions w... |
github | qihongl/mathCognition_PDP_RL-master | plotResults.m | .m | mathCognition_PDP_RL-master/[past]/sim07_teach/plotResults.m | 544 | utf_8 | da928d22f60607e06a82b5f24fe4b624 | function plotResults(record)
global d;
% initialize the parameters for the plot
d.fh = figure();
d.fh.WindowStyle = 'docked';
d.rax = subplot(3,1,1);
d.hax = subplot(3,1,2);
d.wax = subplot(3,1,3);
% d.dtimes = 2.^(10:10);
% load('record.mat');
for i = 1 : size(record.r{size(record.r,2)}.h,2)
plotRes(i, record);
e... |
github | qihongl/mathCognition_PDP_RL-master | trainAgent.m | .m | mathCognition_PDP_RL-master/[past]/sim07_teach/trainAgent.m | 615 | utf_8 | 06ad6c8169633aa44cbd5942553c82c2 | % written by professor Jay McClelland
function [record] = trainAgent(epoch)
%% This function trains the network n trials
% initialize parameters
global p d a;
initParamsEtc(epoch);
initPlot();
% preallocate
record.a = cell(1,epoch);
record.steps = nan(1,epoch);
record.indices = cell(1,epoch);
% train the m... |
github | qihongl/mathCognition_PDP_RL-master | Act.m | .m | mathCognition_PDP_RL-master/[past]/sim07_teach/Act.m | 404 | utf_8 | c8ce5a2f3bcdf3fa4195dafad94f8e76 | % written by professor Jay McClelland
function [ ] = Act( )
% here we act according to the action selected
% by selectAction
global w p;
%% perform the actions
% update the real locations of hand and eye
w.rS.handPos = w.rS.handPos + w.out.handStep;
w.rS.eyePos = w.rS.eyePos + w.out.eyeStep;
w.rS.td = 1; ... |
github | qihongl/mathCognition_PDP_RL-master | runAgent.m | .m | mathCognition_PDP_RL-master/[past]/sim17_hidden/runAgent.m | 1,396 | utf_8 | 78cfdd498102155a8173ab8b178eb42d | % written by professor Jay McClelland
function [ results ] = runAgent()
global a w h p mode;
% rng(seed)
% w.seed = seed;
%% initialize the state
initState();
updateState();
computeAnswer(); % compute the true 'answers'
%% training the model once
i = 0;
indices = zeros(1,p.maxIter);
while ~(w.done) &... |
github | qihongl/mathCognition_PDP_RL-master | trainOne.m | .m | mathCognition_PDP_RL-master/[past]/sim17_hidden/trainOne.m | 420 | utf_8 | ef8b5c157164566a8367db9618905ba3 | % just testing, a short cut for running the model
function trainOne(epoch, seed)
if nargin == 0
epoch = 5000;
seed = randi(99);
end
% run the simulation
record = trainAgent(epoch, seed);
% save the simulation results
saveDirName = getSaveDir();
save([saveDirName '/' 'record'],'record');
save('record','record'... |
github | qihongl/mathCognition_PDP_RL-master | updateWeights.m | .m | mathCognition_PDP_RL-master/[past]/sim17_hidden/updateWeights.m | 1,109 | utf_8 | ff78f01258f198e6d43ac603bd4ab6fe | % written by professor Jay McClelland
function [ ] = updateWeights()
% this function controls:
% 1. the reward policy
% 2. the weight update
% 3. activate the "teaching"
global p a w;
%% compute the reward values according to the reward policy
curRwd = computeRwd();
expRwd = max(a.aAct);
%% assign the reward ... |
github | qihongl/mathCognition_PDP_RL-master | showState.m | .m | mathCognition_PDP_RL-master/[past]/sim17_hidden/showState.m | 813 | utf_8 | 380984d06fc063a982fb8fe6d467ae65 | % written by professor Jay McClelland
function [ ] = showState( )
global p w d a;
% plot rewards over time
axes(d.rwd);
plot(w.rS.time,a.Rwd,'-*'); hold on;
ylim(d.rwd,[p.r.bigNeg p.r.bigPos]);
xlim(d.rwd,[-0.25,w.rS.time+0.25]);
% plot the history of eye and hand positions
t = w.rS.time;
axes(d.history);... |
github | qihongl/mathCognition_PDP_RL-master | move.m | .m | mathCognition_PDP_RL-master/[past]/sim17_hidden/move.m | 403 | utf_8 | 76f0765b052705d3747442411be8e898 | % written by professor Jay McClelland
function [ ] = move( )
% here we act according to the action selected
% by selectAction
global w;
%% perform the actions
% update the real locations of hand and eye
w.rS.handPos = w.rS.handPos + w.out.handStep;
w.rS.eyePos = w.rS.eyePos + w.out.eyeStep;
w.rS.td = 1; ... |
github | qihongl/mathCognition_PDP_RL-master | initParams.m | .m | mathCognition_PDP_RL-master/[past]/sim17_hidden/initParams.m | 1,946 | utf_8 | 30bf24ac5f9544a8482937ec2e66e5a6 | % written by professor Jay McClelland
function [] = initParams(epoch)
% This program initialize and preallocate the parameters needed for the
% model. This should be executed before the simulations.
global p a
%% modeling parameters
p.wf = .1; % noise magnitude
p.lrate = .001; % learning rate
... |
github | qihongl/mathCognition_PDP_RL-master | updateState.m | .m | mathCognition_PDP_RL-master/[past]/sim17_hidden/updateState.m | 949 | utf_8 | 71fbfd2359d475c11bde119d444d2c38 | % written by professor Jay McClelland
function [ ] = updateState()
%this function uses the real state to update the internal state
%after Act is called to execute the hand or eye movement action
global w h p;
%% compute the relative locations
% the relative locations of eye and hand
w.vS.eyePos = 0;
w.vS.ha... |
github | qihongl/mathCognition_PDP_RL-master | initState.m | .m | mathCognition_PDP_RL-master/[past]/sim17_hidden/initState.m | 1,719 | utf_8 | 8dc549d48ae7d5fd6f3156ca975bd5db | % written by professor Jay McClelland
function [ ] = initState( )
global a w h p mode;
%realState is characterized by the position of a target to touch,
%position of eye, and position of hand 1-d space
%viewedState is the input I have given that my eye and hand are
%at particular positions w.r.t. the realSt... |
github | qihongl/mathCognition_PDP_RL-master | trainAgent.m | .m | mathCognition_PDP_RL-master/[past]/sim17_hidden/trainAgent.m | 1,703 | utf_8 | 96848e4205a55392efd3466dd79192d9 | %% Trains the network n trials
% written by professor Jay McClelland
function [record] = trainAgent(epoch, seed)
%% initialization
% initialize parameters
rng(seed)
global p a w mode;
initParams(epoch);
% preallocate
record.a = cell(1,epoch);
s.steps = nan(1,epoch);
s.indices = cell(1,epoch);
s.completed ... |
github | qihongl/mathCognition_PDP_RL-master | computeRwd.m | .m | mathCognition_PDP_RL-master/[past]/sim17_hidden/computeRwd.m | 2,173 | utf_8 | 0c8b1cffd9b43542da04ee92f5bc4d51 | function Rwd = computeRwd()
%% this function controls the reward policy
global w p h;
w.actionCorrect = true;
% if there is remaining items
if targetRemain()
if w.out.handStep == 0 % not moving
Rwd = p.r.smallNeg;
elseif ~isTouchingObj % touching empty spot
Rwd = p.r.smallNeg;
els... |
github | qihongl/mathCognition_PDP_RL-master | runAgent.m | .m | mathCognition_PDP_RL-master/[past]/sim16.1_gamma/runAgent.m | 1,392 | utf_8 | f58afc19f6593a1d0bea36a8402e7dca | % written by professor Jay McClelland
function [ results ] = runAgent()
global a w h p mode;
% rng(seed)
% w.seed = seed;
%% initialize the state
initState();
updateState();
computeAnswer(); % compute the true 'answers'
%% training the model once
i = 0;
indices = zeros(1,p.maxIter);
while ~(w.done) &... |
github | qihongl/mathCognition_PDP_RL-master | trainOne.m | .m | mathCognition_PDP_RL-master/[past]/sim16.1_gamma/trainOne.m | 489 | utf_8 | b1eb28641f494fe96c6daedab52a3ca7 | % just testing, a short cut for running the model
function record = trainOne(epoch, seed)
if nargin == 0
epoch = 2000;
seed = randi(99);
end
%% run the simulation
record = trainAgent(epoch, seed);
%% save the simulation results
saveDirName = getSaveDir();
save([saveDirName '/' 'record'],'record');
save('recor... |
github | qihongl/mathCognition_PDP_RL-master | updateWeights.m | .m | mathCognition_PDP_RL-master/[past]/sim16.1_gamma/updateWeights.m | 764 | utf_8 | 04391ab808a2c6442632b5f50d71b7e8 | % written by professor Jay McClelland
function [ ] = updateWeights()
% this function controls:
% 1. the reward policy
% 2. the weight update
% 3. activate the "teaching"
global p a w;
%% compute the reward values according to the reward policy
curRwd = computeRwd();
expRwd = max(a.wts*w.vS.visInput');
%% assi... |
github | qihongl/mathCognition_PDP_RL-master | showState.m | .m | mathCognition_PDP_RL-master/[past]/sim16.1_gamma/showState.m | 1,317 | utf_8 | 177371f3562e9304f1bf71be51424ff1 | % written by professor Jay McClelland
function [ ] = showState( )
global p w d a;
% plot current and expected rewards over time
axes(d.rwd);
plot(w.rS.time,a.Rwd,'-b*'); hold on;
plot(w.rS.time,a.dfRwd,'-r*');
legend({'current reward', 'discounted future reward'},...
'Location','northwest', 'fontsize', d.F... |
github | qihongl/mathCognition_PDP_RL-master | move.m | .m | mathCognition_PDP_RL-master/[past]/sim16.1_gamma/move.m | 403 | utf_8 | 76f0765b052705d3747442411be8e898 | % written by professor Jay McClelland
function [ ] = move( )
% here we act according to the action selected
% by selectAction
global w;
%% perform the actions
% update the real locations of hand and eye
w.rS.handPos = w.rS.handPos + w.out.handStep;
w.rS.eyePos = w.rS.eyePos + w.out.eyeStep;
w.rS.td = 1; ... |
github | qihongl/mathCognition_PDP_RL-master | initParams.m | .m | mathCognition_PDP_RL-master/[past]/sim16.1_gamma/initParams.m | 1,802 | utf_8 | 1dd413526a92b580aa53ff453ad443f7 | % written by professor Jay McClelland
function [] = initParams(epoch)
% This program initialize and preallocate the parameters needed for the
% model. This should be executed before the simulations.
global p a
%% modeling parameters
p.wf = .10; % noise magnitude
p.lrate = .001; % learning rate
... |
github | qihongl/mathCognition_PDP_RL-master | computeRwd2.m | .m | mathCognition_PDP_RL-master/[past]/sim16.1_gamma/computeRwd2.m | 1,731 | utf_8 | bb2799e2a46161ad5a12b2658bbcd32f | function rwd = computeRwd2()
%% this function controls the reward policy
global w p h;
w.actionCorrect = true;
if isNext()
w.rS.targRemain(w.rS.handPos == w.rS.targPos) = false;
rwd = p.r.midPos;
if ~targetRemain()
rwd = p.r.midPos;
w.done = true;
end
else
if w.rS.handPos < nextOb... |
github | qihongl/mathCognition_PDP_RL-master | updateState.m | .m | mathCognition_PDP_RL-master/[past]/sim16.1_gamma/updateState.m | 951 | utf_8 | 6c3388db9d1faa1711f00bbbdbd2b961 | % written by professor Jay McClelland
function [ ] = updateState()
%this function uses the real state to update the internal state
%after Act is called to execute the hand or eye movement action
global w h p a;
%% compute the relative locations
% the relative locations of eye and hand
w.vS.eyePos = 0;
w.vS.... |
github | qihongl/mathCognition_PDP_RL-master | initState.m | .m | mathCognition_PDP_RL-master/[past]/sim16.1_gamma/initState.m | 1,594 | utf_8 | d62eadf6f64277fd0e0e4533bcc1baf3 | % written by professor Jay McClelland
function [ ] = initState( )
global a w h p mode;
%realState is characterized by the position of a target to touch,
%position of eye, and position of hand 1-d space
%viewedState is the input I have given that my eye and hand are
%at particular positions w.r.t. the realSt... |
github | qihongl/mathCognition_PDP_RL-master | plotResults.m | .m | mathCognition_PDP_RL-master/[past]/sim16.1_gamma/plotResults.m | 544 | utf_8 | da928d22f60607e06a82b5f24fe4b624 | function plotResults(record)
global d;
% initialize the parameters for the plot
d.fh = figure();
d.fh.WindowStyle = 'docked';
d.rax = subplot(3,1,1);
d.hax = subplot(3,1,2);
d.wax = subplot(3,1,3);
% d.dtimes = 2.^(10:10);
% load('record.mat');
for i = 1 : size(record.r{size(record.r,2)}.h,2)
plotRes(i, record);
e... |
github | qihongl/mathCognition_PDP_RL-master | trainAgent.m | .m | mathCognition_PDP_RL-master/[past]/sim16.1_gamma/trainAgent.m | 1,306 | utf_8 | c9b2306ce46f720ca5e2613d7a28f60a | %% Trains the network n trials
% written by professor Jay McClelland
function [record] = trainAgent(epoch, seed)
%% initialization
% initialize parameters
global p a w mode;
initParams(epoch);
p.seed = seed;
rng(seed)
% preallocate
record.a = cell(1,epoch);
s.steps = nan(1,epoch);
s.indices = cell(1,epo... |
github | qihongl/mathCognition_PDP_RL-master | computeRwd.m | .m | mathCognition_PDP_RL-master/[past]/sim16.1_gamma/computeRwd.m | 2,281 | utf_8 | 803655ae19d2afbbfea096bb0ecaf0db | function Rwd = computeRwd()
%% this function controls the reward policy
global w p h;
w.actionCorrect = true;
% if there is remaining items
if targetRemain()
if w.out.handStep == 0 % not moving
Rwd = p.r.smallNeg;
elseif ~isTouchingObj % touching empty spot
Rwd = p.r.smallNeg;
els... |
github | qihongl/mathCognition_PDP_RL-master | runAgent.m | .m | mathCognition_PDP_RL-master/[past]/sim16.6_compUnit+/runAgent.m | 951 | utf_8 | 3ab7aa41579a6ca0bc9344afba37fe9d | % written by professor Jay McClelland
function [ results ] = runAgent()
global a w h p mode;
%% initialize the state
initState();
updateState();
computeAnswer(); % compute the true 'answers'
%% training the model once
i = 0;
indices = zeros(1,p.maxIter);
while ~(w.done) && i < p.maxIter
%% choose ... |
github | qihongl/mathCognition_PDP_RL-master | trainOne.m | .m | mathCognition_PDP_RL-master/[past]/sim16.6_compUnit+/trainOne.m | 490 | utf_8 | 2f501a1e78c37b040cf20d3e2224057f | % just testing, a short cut for running the model
function record = trainOne(epoch, seed)
if nargin == 0
epoch = 20000;
seed = randi(99);
end
%% run the simulation
record = trainAgent(epoch, seed);
%% save the simulation results
saveDirName = getSaveDir();
save([saveDirName '/' 'record'],'record');
save('reco... |
github | qihongl/mathCognition_PDP_RL-master | showWeights.m | .m | mathCognition_PDP_RL-master/[past]/sim16.6_compUnit+/showWeights.m | 583 | utf_8 | a5170d34eef2535437720fe5e1a446a5 | function [ ] = showWeights( )
% plot the weights of the model
global p d a;
% plot weights around fovea
axes(d.heatWts)
% imagesc(-p.eyeRad:p.eyeRad,-p.mvRad:p.mvRad+1, a.wts)
visualizeWeightsMatrix(a.wts)
title(d.heatWts, 'Weights: visual -> action', 'fontsize', d.FONTSIZE)
xlabel(d.heatWts, 'Visual input layer', 'fon... |
github | qihongl/mathCognition_PDP_RL-master | updateWeights.m | .m | mathCognition_PDP_RL-master/[past]/sim16.6_compUnit+/updateWeights.m | 715 | utf_8 | f68207b9c5645058cd2f2c36e1c92959 | % written by professor Jay McClelland
function [ ] = updateWeights()
% this function controls:
% 1. the reward policy
% 2. the weight update
% 3. activate the "teaching"
global p a w;
%% compute the reward values according to the reward policy
curRwd = computeRwd();
expRwd = max(a.wts*w.vS.visInput');
if ~w... |
github | qihongl/mathCognition_PDP_RL-master | showState.m | .m | mathCognition_PDP_RL-master/[past]/sim16.6_compUnit+/showState.m | 2,195 | utf_8 | 04a85884cc5f6e7cf26638c607de124f | % written by professor Jay McClelland
function [ ] = showState( )
global p w d a;
%% plot current and expected rewards over time
axes(d.rwd);
plot(w.rS.time,a.Rwd,'-b*'); hold on;
plot(w.rS.time,a.dfRwd,'-r*');
legend({'current reward', 'discounted future reward'},...
'Location','northwest', 'fontsize',... |
github | qihongl/mathCognition_PDP_RL-master | move.m | .m | mathCognition_PDP_RL-master/[past]/sim16.6_compUnit+/move.m | 403 | utf_8 | a8c158962dd0428e90aff3bada221b17 | % written by professor Jay McClelland
function [ ] = move( )
% here we act according to the action selected by selectAction()
global w;
%% perform the actions
% update the real locations of hand and eye
w.rS.handPos = w.rS.handPos + w.out.handStep;
w.rS.eyePos = w.rS.eyePos + w.out.eyeStep;
w.rS.td = 1; ... |
github | qihongl/mathCognition_PDP_RL-master | initParams.m | .m | mathCognition_PDP_RL-master/[past]/sim16.6_compUnit+/initParams.m | 2,292 | utf_8 | a9614ade9165ba47ba670a1c7830ec06 | % written by professor Jay McClelland
function [] = initParams(epoch)
% This program initialize and preallocate the parameters needed for the
% model. This should be executed before the simulations.
global p a
p.teachingStyle = 4;
% 1 = final reward only
% 2 = intermediate reward
% 3 = final reward only + tea... |
github | qihongl/mathCognition_PDP_RL-master | updateState.m | .m | mathCognition_PDP_RL-master/[past]/sim16.6_compUnit+/updateState.m | 1,071 | utf_8 | 2115a241334ecc83f328f0e8950e2495 | % written by professor Jay McClelland
function [ ] = updateState()
%this function uses the real state to update the internal state
%after Act is called to execute the hand or eye movement action
global w h p a;
%% compute the relative locations
% the relative locations of eye and hand
w.vS.eyePos = 0;
w.vS.... |
github | qihongl/mathCognition_PDP_RL-master | initState.m | .m | mathCognition_PDP_RL-master/[past]/sim16.6_compUnit+/initState.m | 1,718 | utf_8 | 155054be357b8d2fc0709003cef52a23 | % written by professor Jay McClelland
function [ ] = initState( )
global a w h p mode;
%realState is characterized by the position of a target to touch,
%position of eye, and position of hand 1-d space
%viewedState is the input I have given that my eye and hand are
%at particular positions w.r.t. the realSt... |
github | qihongl/mathCognition_PDP_RL-master | trainAgent.m | .m | mathCognition_PDP_RL-master/[past]/sim16.6_compUnit+/trainAgent.m | 1,501 | utf_8 | 61e7aeb84f1a92e22f73306d60a6cdcd | %% Trains the network n trials
% written by professor Jay McClelland
function [record] = trainAgent(epoch, seed)
%% initialization
% initialize parameters
global p a w mode;
initParams(epoch);
p.seed = seed;
rng(seed)
% preallocate
record.a = cell(1,epoch);
s.steps = nan(1,epoch);
s.indices = cell(1,epoch... |
github | qihongl/mathCognition_PDP_RL-master | computeRwd.m | .m | mathCognition_PDP_RL-master/[past]/sim16.6_compUnit+/computeRwd.m | 2,405 | utf_8 | 6ae764d9770a64eeca14089a4ad0c2a0 | function Rwd = computeRwd()
%% this function controls the reward policy
global w p h a;
% if there is remaining items
if targetRemain()
if a.choice == p.mvRange +1 % saying "done"
Rwd = p.r.smallNeg;
w.stopEarly = true; w.errors = w.errors+1;
w.done = true;
elseif a.choice == p.mvRad... |
github | qihongl/mathCognition_PDP_RL-master | chooseAction.m | .m | mathCognition_PDP_RL-master/[past]/sim01_touch/chooseAction.m | 383 | utf_8 | d2e240a744e3445217cd8f7a1c8214ce | function [w] = chooseAction(w,p,a)
% obtain the probability distribution for actions
prob = softmax(a.q(w.curs+1,:), p.qscale);
% choose action based
w.cura = sample(prob);
end
function [c] = sample(pr)
rv = rand(1); % sample from a unifrom[0,1]
cp = cumsum(pr);
for i = 1:length(pr) % choose an action
... |
github | qihongl/mathCognition_PDP_RL-master | softmax.m | .m | mathCognition_PDP_RL-master/[past]/sim01_touch/softmax.m | 520 | utf_8 | 8c98f3919ba08bbd98950e692e0b9d1f | % x is expected to be a vector of q values for a state: Q(s,:)
function [prob] = softmax(x, scale)
% if there is no input scaling factor, just don't scale it
if nargin == 1
scale = 1;
end
% transform when there is negative values
%
if any(x < 0)
x = x - min(x);
end
% softmax transformation
prob = (x.^scal... |
github | qihongl/mathCognition_PDP_RL-master | initState.m | .m | mathCognition_PDP_RL-master/[past]/sim01_touch/initState.m | 470 | utf_8 | 9c3cf1f04cea6ec6e12f9e9b6cfe811e | % INITSTATE initialize the state parameters, or set up the "world"
% written by Professor Jay McClelland
function [w] = initState(range)
% preallocation
w.curs = 0; % current state
w.cura = 0; % current action
w.nexts = 0; % next state
w.nexta = 0; % next action
w.R = 0; % reward
w.st... |
github | qihongl/mathCognition_PDP_RL-master | touch.m | .m | mathCognition_PDP_RL-master/[past]/sim01_touch/touch.m | 1,552 | utf_8 | 93235517864a25b4e852e537bec097cd | %% a RL based model for counting
function rundata = touch(seed, doPlotting)
if nargin == 0
seed = randi(99); doPlotting = true;
end
% initialization
rng(seed);
%% modeing parameters
p = setupParameters();
% preallocate and initilize Q to small values
a.q = .01 + zeros(p.range+1,p.nactions);
h.stepsToReward = zeros... |
github | qihongl/mathCognition_PDP_RL-master | setupParameters.m | .m | mathCognition_PDP_RL-master/[past]/sim01_touch/setupParameters.m | 425 | utf_8 | 33d4c4efe3a9ba981423ed662d871875 | %SETUPPARAMETERS returns the parameters for the model
function [p] = setupParameters()
% modeling parameters
p.gamma = .5; % discount factor
p.alpha = 0.1; % learning rate
p.qscale = 3; % softmax scale factor
% other parameters
p.range = 5; % the size of the state space
p.nactions = p.range... |
github | qihongl/mathCognition_PDP_RL-master | chooseAction.m | .m | mathCognition_PDP_RL-master/[past]/sim04_teach/chooseAction.m | 404 | utf_8 | f1c78df6cfcec9b33927e367641916fb | function [action] = chooseAction(w,a)
global p;
% obtain the probability distribution for actions
prob = softmax(a.q(w.curs+1,:), p.qscale);
% choose action based
action = sample(prob);
end
function [action] = sample(pr)
rv = rand(1); % sample from a unifrom[0,1]
cp = cumsum(pr);
for i = 1:length(pr) % choo... |
github | qihongl/mathCognition_PDP_RL-master | softmax.m | .m | mathCognition_PDP_RL-master/[past]/sim04_teach/softmax.m | 622 | utf_8 | 90f2f58a719facf0fbef333ac0a0b761 | % SOFTMAX assign probabilities to options
% in my case, x is expected to be a vector of q values for a state: Q(s,:)
function [prob] = softmax(x, scale)
% if there is no input scaling factor, just don't scale it
if nargin == 1
scale = 1;
end
% transform when there is negative values
% TODO: this transformation i... |
github | qihongl/mathCognition_PDP_RL-master | initState.m | .m | mathCognition_PDP_RL-master/[past]/sim04_teach/initState.m | 1,133 | utf_8 | bd86e844165f85c52edad742b55912a8 | % INITSTATE initialize the state parameters, or set up the "world"
% note that all things here are TRIAL SPECIFIC
% originally written by Professor Jay McClelland
function [w] = initState()
global p;
% preallocation
w.curs = 0; % current state
w.cura = 0; % current action
w.nexts = 0; % next state
... |
github | qihongl/mathCognition_PDP_RL-master | touch.m | .m | mathCognition_PDP_RL-master/[past]/sim04_teach/touch.m | 1,990 | utf_8 | 8f38f3e1594322b6dda1798b7d38d129 | %% a RL based model for counting
function output = touch(epochs, seed, ...
showPlot, showSteps, showProg)
if nargin == 0
epochs = 100; seed = randi(99);
showPlot = 1; showSteps = 0; showProg = 0;
end
rng(seed);
global p
%% initialization
% modeing parameters
setupParameters(epochs);
% preallocate & initi... |
github | qihongl/mathCognition_PDP_RL-master | setupParameters.m | .m | mathCognition_PDP_RL-master/[past]/sim04_teach/setupParameters.m | 762 | utf_8 | 755f01c57ea53a5f5d99728bae235312 | %SETUPPARAMETERS returns the parameters for the model
function [] = setupParameters(epochs)
global p;
% number of training epochs
p.trials = epochs;
% modeling parameters
p.gamma = 0.5; % discount factor
p.alpha = 0.2; % learning rate
p.qscale = 3; % softmax scaling factor
% other parameters
p.rang... |
github | qihongl/mathCognition_PDP_RL-master | runAgent.m | .m | mathCognition_PDP_RL-master/sim20_perfect/runAgent.m | 935 | utf_8 | 63e17518c01b818647117d4c4ed5b343 | % written by professor Jay McClelland
function [ results ] = runAgent()
global a w h p mode;
%% initialize the state
initState();
updateState();
computeAnswer(); % compute the true 'answers'
%% training the model once
i = 0;
indices = zeros(1,p.maxIter);
while ~(w.done) && i < p.maxIter
%% choose ... |
github | qihongl/mathCognition_PDP_RL-master | trainOne.m | .m | mathCognition_PDP_RL-master/sim20_perfect/trainOne.m | 598 | utf_8 | 115b2a4a98da3a5ef33182c04a622512 | % just testing, a short cut for running the model
function record = trainOne(epoch, seed)
if nargin == 0
epoch = 5000;
seed = randi(99);
end
%% run the simulation
record = trainAgent(epoch, seed);
%% save the simulation results
saveDirName = getSaveDir();
save([saveDirName '/' 'record'],'record');
save('recor... |
github | qihongl/mathCognition_PDP_RL-master | showWeights.m | .m | mathCognition_PDP_RL-master/sim20_perfect/showWeights.m | 583 | utf_8 | a5170d34eef2535437720fe5e1a446a5 | function [ ] = showWeights( )
% plot the weights of the model
global p d a;
% plot weights around fovea
axes(d.heatWts)
% imagesc(-p.eyeRad:p.eyeRad,-p.mvRad:p.mvRad+1, a.wts)
visualizeWeightsMatrix(a.wts)
title(d.heatWts, 'Weights: visual -> action', 'fontsize', d.FONTSIZE)
xlabel(d.heatWts, 'Visual input layer', 'fon... |
github | qihongl/mathCognition_PDP_RL-master | updateWeights.m | .m | mathCognition_PDP_RL-master/sim20_perfect/updateWeights.m | 1,053 | utf_8 | 47c33e182c1c5129cfb958693dd1ed13 | % written by professor Jay McClelland
function [ ] = updateWeights()
% this function controls:
% 1. the reward policy
% 2. the weight update
% 3. activate the "teaching"
global p a w;
%% compute the reward values according to the reward policy
a.curRwd = computeRwd();
% if reward == -1, do sth diff
a.act_next... |
github | qihongl/mathCognition_PDP_RL-master | showState.m | .m | mathCognition_PDP_RL-master/sim20_perfect/showState.m | 2,369 | utf_8 | c21f87f660c0fca0cff629e57b109e9f | % written by professor Jay McClelland
function [ ] = showState( )
global p w d a;
%% plot current and expected rewards over time
axes(d.rwd);
plot(w.rS.time,a.curRwd,'-b*'); hold on;
plot(w.rS.time,a.expRwd,'-r*');
legend({'current reward', 'esimtated reward'},...
'Location','northwest', 'fontsize', d.F... |
github | qihongl/mathCognition_PDP_RL-master | initParams.m | .m | mathCognition_PDP_RL-master/sim20_perfect/initParams.m | 2,283 | utf_8 | 177a9adc37e72056070df3a6093223bf | % written by professor Jay McClelland
function [] = initParams(epoch)
% This program initialize and preallocate the parameters needed for the
% model. This should be executed before the simulations.
global p a
p.teachingStyle = 4;
% 1 = final reward only
% 2 = intermediate reward
% 3 = final reward only + tea... |
github | qihongl/mathCognition_PDP_RL-master | updateState.m | .m | mathCognition_PDP_RL-master/sim20_perfect/updateState.m | 1,137 | utf_8 | b7f489fdff68b16f52c2b5336d86ef59 | % written by professor Jay McClelland
function [ ] = updateState()
%this function uses the real state to update the internal state
%after Act is called to execute the hand or eye movement action
global w h p a;
%% compute the relative locations
% the relative locations of eye and hand
w.vS.eyePos = 0;
w.vS.... |
github | qihongl/mathCognition_PDP_RL-master | initState.m | .m | mathCognition_PDP_RL-master/sim20_perfect/initState.m | 1,665 | utf_8 | 4089ab3033ac759bf8c9857f7d1932f2 | % written by professor Jay McClelland
function [ ] = initState( )
global a w h p mode;
%realState is characterized by the position of a target to touch,
%position of eye, and position of hand 1-d space
%viewedState is the input I have given that my eye and hand are
%at particular positions w.r.t. the realSt... |
github | qihongl/mathCognition_PDP_RL-master | trainAgent.m | .m | mathCognition_PDP_RL-master/sim20_perfect/trainAgent.m | 1,501 | utf_8 | 704f98828c45de576b681eb325399789 | %% Trains the network n trials
% written by professor Jay McClelland
function [record] = trainAgent(epoch, seed)
%% initialization
% initialize parameters
global p a w mode;
initParams(epoch);
p.seed = seed;
rng(seed)
% preallocate
record.a = cell(1,epoch);
s.steps = nan(1,epoch);
s.indices = cell(1,epoch... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.