Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
jpm-behavior/main_final.m
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
149 lines (117 sloc)
4.5 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [] = main_final(beh_type,distinguish_str,beh) | |
% This function runs all of the modeling, followed by analysis code. | |
% It takes parameters | |
% beh_type: 'AGG', 'SIB', or 'BOTH' strings | |
% distinugish_str: how to distinguish this run's folder name | |
% beh: include behavior as a lagged variable (true) or not (false) | |
% create a directory to save results in | |
dirstring = strcat(beh_type, distinguish_str); | |
mkdir(dirstring); | |
numCores = feature('numcores'); | |
fprintf('* Creating parallel pool with %d workers...\n', numCores); | |
parallelTime = tic; | |
% Parallelization code is from the RPI IDEA repository. | |
try | |
if (~isempty(gcp('nocreate'))) | |
currentPool = gcp; | |
if currentPool.NumWorkers < numCores | |
delete(gcp('nocreate')); | |
parpool(numCores); | |
end | |
else | |
parpool(numCores); | |
end | |
catch E | |
fprintf('* Unable to create parallel pool.'); | |
diary off; | |
clearvars; | |
rethrow(E); | |
end | |
fprintf('*Parallel pool successfully created after %.2f seconds.\n',... | |
toc(parallelTime)); | |
%%%% GENERATE MODELS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
% Select variables to use for the model by prefix or by specific name | |
pats =["Weather_TMAX", "Moon Phase", "Allergen_Total",... | |
"Sleep", "BM", "Menses"]; | |
% set number of lagged days | |
lag = 1; | |
% Read in the data | |
[Xc, yc, pc, ynan, p, text_vars] = read_data(beh_type, lag, beh,... | |
dirstring, pats); | |
% Standardize to the population | |
Xc_uns = Xc; | |
save('Xc_uns_new.mat','Xc_uns'); | |
[Xc, xmeans, xstds] = zscore(Xc); | |
save('Xc_test_new.mat','Xc'); | |
save('pc_test_new.mat','pc'); | |
%error() | |
% Log output | |
dirstring_slash = strcat(dirstring,'/'); | |
log_output(dirstring_slash, strcat('xmeans', string(xmeans))) | |
log_output(dirstring_slash, strcat('xstds', string(xstds))) | |
% Random seeds to run over | |
rngs = 1:30; | |
% People in the cohort of 136 | |
people = 1:136; | |
% Set model inputs | |
linear_or_logistic = 'logistic'; | |
kernel_type = 'yes'; | |
% Put all in an outfile for logging | |
log_output(dirstring_slash,strcat('random numbers ', string(rngs))) | |
log_output(dirstring_slash,strcat('people ', string(people))) | |
log_output(dirstring_slash,linear_or_logistic) | |
log_output(dirstring_slash,kernel_type) | |
% Make a directory to save individuals' data in | |
mkdir(strcat(dirstring,'/individuals')); | |
filepath = strcat(dirstring,'/individuals/'); | |
% Start timer | |
tic | |
% Run each person's models in parallel | |
parfor person=people | |
file_saving_string = strcat(dirstring, '/individuals/',... | |
beh_type, distinguish_str, '_', linear_or_logistic,... | |
'_', kernel_type, '_', string(person), '.mat'); | |
% Skip person if their models are already run | |
if isfile(file_saving_string) | |
disp('file found alIBready') | |
continue | |
else | |
Mod_RNGs = cell(max(size(rngs)),1) | |
for RNG=rngs | |
Mod = RunCode(RNG, linear_or_logistic, kernel_type,... | |
person, Xc, pc, yc) | |
Mod_RNGs{RNG} = Mod; | |
if Mod.Best == -1 | |
break % Don't run additional models if the first one | |
% doesn't work | |
end | |
end | |
Mods = Mod_RNGs; | |
mySave(file_saving_string,Mods) | |
end | |
end | |
toc | |
% Get the current time as the save string file | |
c = string(clock); | |
c = strjoin(c(1:5),'_'); %convert to string | |
% Plot according to the BCR parameter | |
plotting_param = 'BCR'; | |
females = load('females.csv'); | |
vars = text_vars; | |
% file extension for reading/saving models | |
file_ext = strcat(distinguish_str, '_', linear_or_logistic,... | |
'_', kernel_type, '_'); | |
% Plot behavior and model performance plots | |
imbal_plots(dirstring, beh_type, plotting_param, filepath, ... | |
file_ext, Xc, yc, ynan, p, pc, c); | |
% Run the Pareto analysis | |
Run_Pareto(dirstring, beh_type, filepath, file_ext, ... | |
linear_or_logistic, kernel_type) | |
% Plot the Pareto analysis results | |
plot_important_feature(dirstring, females, beh_type, vars, c) | |
% Run hierarchical clustering | |
variable_hclust(dirstring, text_vars, c, Xc, pc, beh_type) | |
% Display, then close all figures | |
pause(10) | |
close all; | |
end |