-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyPredict.m
More file actions
32 lines (27 loc) · 1.12 KB
/
yPredict.m
File metadata and controls
32 lines (27 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function [yPred] = yPredict(thetas, X)
% Returns predicted values from a linear model of the form yPred = X * thetas.
% Written by LEW but borrowed heavily from script written by Sam Failor.
% X: n x m matrix where n is the number of observations and m is the number
% of predictors (e.g., task variables, pupil size, etc.).
% thetas: m-dim vector of weights (from findThetas.m or similar)
% yPred = n-dim vector of predicted responses/outputs (e.g., binned calcium
% or spike rate)
%%%%%% CHECK DIMENSIONS %%%%%%
if size(thetas,1) > size(X,2)
% if X is one column short and doesn't already contain an intercept...
if size(thetas,1) - size(X,2) == 1 && round(mean(X(:,1))) ~= 1
% ...add one
X = addInt(X);
% disp('X seems to be missing an intercept; adding it now');
else
% otherwise throw an error
error('X and thetas are different sizes; cannot continue')
end
end
%%%%%% PREDICT Y VALUES %%%%%%
yPred = X*thetas;
% pause if yPred is NaNs (this means something is wrong)
if isnan(yPred)
keyboard
disp('yPred contains NaNs')
end