-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain2_gmm_model.m
43 lines (35 loc) · 1.05 KB
/
main2_gmm_model.m
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
% Train gmm with written and also inline codes
clear;
clc;
addpath('../gmm');
% Define the filename as a variable
data_filename = 'offshore_detrend.mat'; % Data file to load
model_filename = sprintf('model_gmm_%s', data_filename); % Modify filename for saving model
% Gaussian mixture model using matlab function
%% load data x1 and x2
f = fullfile('../data/hovsore_wind/data',data_filename);
calmstd = load(f).calmstd;
x1 = calmstd.u;
x2 = calmstd.u_stdv;
X(:,1) = x1;
X(:,2) = x2;
%% GMM training
maxComponent = 8; % number of components
% code written
gmModel = gmm_train(X, maxComponent);
% %% MATLAB inline code
% options = statset('Display','final','MaxIter', 1000);
% AIC = zeros(1,maxComponents);
% gm = cell(1,maxComponents);
% for k = 1:maxComponents
% gm{k} = fitgmdist(X,k,'Options',options, 'Replicates', 3);
% AIC(k)= gm{k}.AIC;
% end
% [minAIC,numComponents] = min(AIC);
% gmModel = gm{numComponents};
%
% % Generate new points
% Xp = random(gmModel, 1e8);
% x_i = Xp(:,1);
% x_j = Xp(:,2);
save(fullfile('res', model_filename),'gmModel');