160 likes | 298 Views
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.
E N D
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 Figures d16 Ori Ori SF d16 Ori SF d16 SF Computer Physiological Signs Problems: slow Tables One MK data Command Driving Ori Another MK data Monkey Error-prone table align by copy & paste Visual Stimuli Combined Data Not fitted curves Text File output Limited Types of Exp D16 Posters, Papers Thesis Graduation Monitoring 1 week experiment; 2-3 week data analysis; 11-12 monkeys/ year
Response Figures d16 Ori Ori SF d16 Ori SF d16 SF Computer Physiological Signs Possible Solution Tables One MK data Graphic User Interface Ori Another MK data Monkey Automatically generated Database Eliminate copy & paste Visual Stimuli Combined Data Curve fitting Instant online plot Better visualizing New visual Stimuli D16 Posters, Papers Thesis Graduation Recording
Improvements 1.New visual stimuli 2.Graphic user interface 3.Online results plotting and curve fitting 4.Data management 5.Physiological signs recording
Online plotting Curve fitting How to build GUI Example codes: busybox.m On the web
80 60 Response (spikes/sec) 40 20 0 -160 -120 -80 -40 0 Orientation (degree) General steps to do curve fitting 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
Residual Randomly distribution, no clear pattern. How good is the fit? Chi-square Sum 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. Standard error of parameters If 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.
Use Curve Fitting Toolbox for unconstrained fit % 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; % chisquare jj=fitinfo.Jacobian;[nd np]=size(jj); dfe1=nd-np; chisqr=rr'*rr/dfe1; % parameter standard error var_cov=inv(jj' * jj); se=sqrt(diag(var_cov))*chisqr; % pearsons R measdiff=(yyvals-mean(yyvals)); modeldiff=(yyfit-mean(yyfit)); pr1=measdiff' * modeldiff; pr2=measdiff' * measdiff; pr3=modeldiff' * modeldiff; pearsons=pr1/(sqrt(pr2)*sqrt(pr3)); Modified from Hope’s codes
Response (spikes/sec) Size (degree) use optimization toolbox for constrained fit Parameters follow certain relation. e.g. p1<p3 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 boundary UB = [ 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);
m = x: [16x1 double] response: [16x1 double] std: [16x1 double] rightOnly: 6.6410 rightOnlyStd: 1.4200 leftOnly: 5.2510 leftOnlyStd: 1.4230 noise: 1.2360 noiseStd: 0.4490 index: [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 10 9 Response (spikes/sec) 8 7 6 5 4 Phase (degree) 3 0 50 100 150 200 250 300 350 h=hgload(figurename), m=get(h, ‘userdata’); h=gcf set(h, ‘userdata’, m); hgsave(h, figurename); A Matlab figure is worth thousands of words
Post-experiment data management Each Monkey has N units Each unit has M experiments Each experiment has one figure Each figure contains many measurements Mk343.mat is NxM cell array; Mk343{unitNum}{expNum}.OriBW No more copy & past, align spread sheet, just call matlab functions • 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];
Response Figures, fitted Basic Exps Computer Posters Papers Thesis Graduation Center Surround Database Automatically Generated newEmptyMK feedMKWithFigures Monkey Binocular Visual Stimuli More time to think and write Quicker graduation Timing Physiological Signs How things are Before: 1week, 3-5 exp x 50-60 cells; Now: 1 week, 10-15 exp x 100+ cells; 2-3 weeks analysis 1-2 days analysis
Thanks Scott for leading me into the door Hope 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, waves Different anesthesia drugs effects
If you want to know the actual computing algorithm more control over the fitting process 1. example code (fitogive) 2. example code (Levenberg-Marquardt) 3. book “Numerical Optimization” (by Jorge Nocedal)