-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRecipEntropySingle.m
More file actions
66 lines (61 loc) · 1.89 KB
/
RecipEntropySingle.m
File metadata and controls
66 lines (61 loc) · 1.89 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
function [] = RecipEntropySingle(Ningred_used,order,subsamp_index,save_flag)
% Fits a single maxent model of order order using the Ningred_used most
% common ingredients and saves it as subsample number subsamp_index
%
% Written by: DJ Strouse
% Last updated: Aug 19, 2013 by DJ Strouse
%
% INPUTS
% Ningred_used [=] positive integer = number of ingredients to use
% order [=] non-negative integer = order of maxent model (0=freqs)
% subsamp_index [=] positive integer = index of subsample
% save_flag [=] boolean = indicates whether or not to save data (def=true)
%
% OUTPUTS
% none
% init
if ~exist('save_flag','var')
save_flag = true;
end
load('data/recipes.mat');
mkdir(sprintf('data/standard/%iingred/order%i/subsamp%i',...
Ningred_used,order,subsamp_index)); % creates appropriate directory
cd(sprintf('data/standard/%iingred/order%i/subsamp%i',...
Ningred_used,order,subsamp_index)); % changes to appropriate directory
diary('diary.txt');
Ningred = size(recipes_binary,2);
Nrec = size(recipes_binary,1);
subsamp_size = round(.8*Nrec);
if Ningred_used>Ningred
error('Ningred_used>Ningred!')
end
disp(sprintf('Subsampling from %i recipes down to %i',Nrec,subsamp_size))
% use Ningred_used most common ingredients only
recipes_binary_subsamp = ExtractIngred(Ningred_used,ingred_freq,recipes_binary,ingreds);
% fit model
if order==0
disp('Subsampling raw frequencies')
freq =...
FindFreqs(recipes_binary_subsamp,subsamp_size,1);
disp('Subsampled raw frequencies')
if save_flag
save(...
'subsample.mat',...
'freq',...
'-v7.3');
end
else
disp(sprintf('Building model of order %i',order))
maxent =...
FitMaxEnt(recipes_binary_subsamp,order,subsamp_size,1);
disp(sprintf('Built model of order %i',order))
if save_flag
save(...
'subsample.mat',...
'maxent',...
'-v7.3');
end
end
%% fixes a problem when running this in cambridge
! rm -f nohup.out
end