lab improvement with matlab
DESCRIPTION
Lab improvement with Matlab. Response. Figures. Tables. One MK data. Ori. Ori. SF. d16. SF. SF. d16. d16. Ori. Ori. Computer. Another MK data. Monkey. Visual Stimuli. Combined Data. D16. Physiological Signs. How things were. Posters, Papers Thesis Graduation. Response. - PowerPoint PPT PresentationTRANSCRIPT
Lab improvement with Matlab
Ori
Response
Ori
SF
d16
Ori
SF
d16
SF
d16
Physiological Signs
Posters, PapersThesis
Graduation
Figures
Ori
D16
How things were
Tables
Another MK data
Combined Data
One MK data
Computer
Monkey
Vis
ua
l S
tim
uli
Another MK data
Ori
Response
Ori
SF
d16
Ori
SF
d16
Computer
Monkey
Vis
ua
l S
tim
uli
SF
d16
Physiological Signs
Posters, PapersThesis
Graduation
Tables
Combined Data
Ori
D16
Figures
Problems: slow
One MK dataCommand Driving
Limited Types of Exp
Text File output Not fitted curves
Error-prone table align by copy & paste
Monitoring 1 week experiment; 2-3 week data analysis; 11-12 monkeys/ year
Another MK data
Ori
Response
Ori
SF
d16
Ori
SF
d16
Computer
Monkey
Vis
ua
l S
tim
uli
SF
d16
Physiological Signs
Posters, PapersThesis
Graduation
Tables
Combined Data
Ori
D16
Figures
Possible Solution
One MK data
Graphic User Interface
New visual Stimuli
Instant online plotBetter visualizing
Curve fitting
Automatically generated Database
Eliminate copy & paste
Recording
Improvements
1.New visual stimuli2.Graphic user interface3.Online results plotting and curve fitting 4.Data management5.Physiological signs recording
0 100 200 300 40010
15
20
25
30
35
40
45
0 100 200 300 4000
10
20
30
40
50
PhaseHow to build GUIExample codes: busybox.mOn the web
Online plotting Curve fitting
Fourier analysisAnimal 343HemisphereLUnit 64Exp 4
1 0 30.58 19.622 8 23.48 15.663 16 22.39 7.824 24 17.92 1.585 32 14.21 3.996 40 15.75 8.087 48 21.78 14.768 56 14.21 13.279 64 21.78 25.39
10 72 19.92 34.7311 80 26.26 36.8912 88 35.53 39.2413 96 41.08 36.8914 104 36.91 39.2615 112 37.84 41.9616 120 39.54 30.3517 0 19 12.4418 0 28.11 18.2119 0 14.21 5.31
1. Pick up some model function y_est=fitFun(p,x) the model has to be reasonable, e.g. Gaussian
2. Provide the initial values [100, -80 , 20]
3. Select some algorithm
4. Understand what are you looking for function d= objectiveFun(p, y, x) y_est=fitFun(p,x); d = sqrt( sum( (y_est - y).^2 ) );
Minimize the objective function
0
20
40
60
80
-160 -120 -80 -40 0
Orientation (degree)
Resp
on
se (
sp
ikes/s
ec)
General steps to do curve fitting
Standard error of parametersIf the standard error is small, it means that a small variation in the parameter would produce a curve that fits the data much worse. Therefore, we say that we know the value of that parameter well. If the standard error is large, a relatively large variation of that parameter would not spoil the fit much; therefore, we do not really know the parameter’s value well.
Pearsons R known as the goodness of fit. It is computed as the fraction of the total variation of the Y values of data points that is attributable to the assumed model curve, and its values typically range from 0 to 1. Values close to 1 indicate a good fit.
Chi-squareSum of residual square divided by the number of degrees of freedom (data points -parameter). To reduce the bias caused by the number of parameters. The smaller this value, the better the fit.
How good is the fit?
ResidualRandomly distribution, no clear pattern.
% pick the model, prepare the fitting options, initial values, methods, algorithm fopt = fitoptions('method','NonlinearLeastSquares','Algorithm','Levenberg-Marquardt');coef_guess = [mean(yyvals) 1 0 ]; set(fopt,'Startpoint',coef_guess);ftyp = fittype(’fitFun' ,'dependent',{'y'},'independent',{'x'},'coefficients',{'a', 'b', 'c'});
% do the curve fitting[fitresult,goodness,fitinfo] = fit(xxvals,yyvals,ftyp ,fopt);yyfit=feval(fitresult,xxvals);
% Get the residuals rr=fitinfo.residuals;
% chisquarejj=fitinfo.Jacobian; [nd np]=size(jj); dfe1=nd-np; chisqr=rr'*rr/dfe1;
% parameter standard errorvar_cov=inv(jj' * jj); se=sqrt(diag(var_cov))*chisqr;
% pearsons Rmeasdiff=(yyvals-mean(yyvals)); modeldiff=(yyfit-mean(yyfit));pr1=measdiff' * modeldiff; pr2=measdiff' * measdiff; pr3=modeldiff' * modeldiff;pearsons=pr1/(sqrt(pr2)*sqrt(pr3));
Use Curve Fitting Toolbox for unconstrained fit
Modified from Hope’s codes
fmincon
p = [ p1 p2 p3 p4 ]; %initial guess
A = [1 0 -1 0]; B = [0]; %A*p’<B; in this case:%1*p1+0*p2+(-1)*p3+0*p4<0;%p1-p3<0; %p1<p3;
Aeq = [ ]; Beq = [ ]; %Aeq*p’=Beq; this case, none
LB = [0 0 0 0]; %lower boundaryUB = [ 10 200 40 10]; %upper boundary
opts = optimset('fmincon');
p = fmincon('ObjFun', p, A, B, Aeq, Beq, LB, UB, [ ], opts, y, x);fitX=[0:0.1:12]; fitY=sizeFun(p,fitX);
use optimization toolbox for constrained fitParameters follow certain relation. e.g. p1<p3
Size (degree)
Resp
onse
(sp
ikes/
sec)
A Matlab figure is worth thousands of words
3
4
5
6
7
8
9
10
0 50 100 150 200 250 300 350
Res
pons
e (s
pike
s/se
c)
Phase (degree)
m = x: [16x1 double]response: [16x1 double]std: [16x1 double]rightOnly: 6.6410rightOnlyStd: 1.4200leftOnly: 5.2510leftOnlyStd: 1.4230noise: 1.2360noiseStd: 0.4490index: [1x1 struct]fit: [6.35 2.79 30.45]
m.index= RMS: 2.4606
BII: 0.3575 SN: 0.8684 mean: 6.35 amplitude: 2.79 optPhase: 30.45 DOM: 6.6410 meanBM: 0.9000 peakBM: 1.2218 maxBM: 1.6744 minBM: 0.5120
h=hgload(figurename), m=get(h, ‘userdata’);
h=gcfset(h, ‘userdata’, m);hgsave(h, figurename);
•newEmptyMK to create an empty data structure, which holds many units•feedMKWithFigures to go through each figure and fill up this empty data structure •getRoutineFigures to make routine figures across the units (30-40 figures in one click)•getparam to get any combination of parameters to make figure or export into a text file•Combine different monkeys data, Mkcombined=[Mk343;Mk300;Mk299];
MK343
unit #1
unit # n-2 .......exp_GeneralscDepth_absDepth_relativeV1orV2unitNo.
exp_BoriFitDomEyepeakFire_m1preferDir_m2std_m3oriBWType
exp_D16RMS:BIISN:betterMono:MeanOverMono:MaxOverMono:MinOverMono:noise:realBetterMono:
exp_Size:RpeakSize:RpeakFire:RflatSize:RflatFire:LpeakSize:LpeakFire:LflatSize:LflatFire:Type:
GeneralInfo #2 #m#m-1
exp_cstc_m1c_m2c_m3I_m1I_m2I_m3X_m1X_m2Xm3
exp #1
-160 -140 -120 -100 -80 -60 -40 -20 0 20 400
10
20
30
40
50
60
Orientation (degree)
Response (spikes/sec)
343d09301F0
0 50 100 150 200 250 300 350 4000
5
10
15
20
25
30
35
Spatial Phase (degree)
Response (spikes/sec)
343d05904F0
BII= 0.39 peakBM= 0.85
1 2 5 10 20 50 800
5
10
15
20
25
30
35
40
45
Contrast of Center Stimuli (%)
Response (spikes/sec)
343d02808. F0
0 2 4 6 8 10 120
10
20
30
40
50
Size (degree)
Response (spikes/sec)
343d02803F0
Each Monkey has N unitsEach unit has M experimentsEach experiment has one figureEach figure contains many measurements
Post-experiment data management
Mk343.mat is NxM cell array; Mk343{unitNum}{expNum}.OriBW
No more copy & past, align spread sheet, just call matlab functions
How things are
PostersPapersThesis
Graduation
More time to think and write
Quickergraduation
2-3 weeks analysis1-2 days analysis
Before: 1week, 3-5 exp x 50-60 cells; Now: 1 week, 10-15 exp x 100+ cells;
Computer
Monkey
Response Figures, fitted
Vis
ua
l S
tim
uli
CenterSurround
BasicExps
Timing
Physiological Signs
Binocular
DatabaseAutomatically
Generated
newEmptyMKfeedMKWithFigures
Thanks
Scott for leading me into the doorHope for helping me on many projects
Yiji and lab coworkers for helpful discussion
A small progress opens a new door
Single unit responses correlate to EEG?A, b, wavesDifferent anesthesia drugs effects
If you want to know the actual computing algorithmmore control over the fitting process
1. example code (fitogive)
2. example code (Levenberg-Marquardt)
3. book “Numerical Optimization” (by Jorge Nocedal)