Skip to content

Commit 86ddde5

Browse files
committed
add gmm train file
0 parents  commit 86ddde5

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

Diff for: matlab/main_gmm_train.m

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
% Train gmm with written and also inline codes
2+
clear;
3+
clc;
4+
addpath('../../../gmm');
5+
6+
% Define the filename as a variable
7+
filename = 'onshore_detrend_150_180.mat'; % Data file to load
8+
model_filename = strrep(filename, '.mat', '_model.mat'); % Modify filename for saving model
9+
10+
% Gaussian mixture model using matlab function
11+
%% load data x1 and x2
12+
f = fullfile('../../../data/hovsore_wind/data',filename);
13+
calmstd = load(f).calmstd;
14+
x1 = calmstd.u;
15+
x2 = calmstd.u_stdv;
16+
X(:,1) = x1;
17+
X(:,2) = x2;
18+
19+
%% GMM training
20+
maxComponent = 8; % number of components
21+
22+
% code written
23+
gmModel = gmm_train(X, maxComponent);
24+
25+
26+
% %% MATLAB inline code
27+
% options = statset('Display','final','MaxIter', 1000);
28+
% AIC = zeros(1,maxComponents);
29+
% gm = cell(1,maxComponents);
30+
% for k = 1:maxComponents
31+
% gm{k} = fitgmdist(X,k,'Options',options, 'Replicates', 3);
32+
% AIC(k)= gm{k}.AIC;
33+
% end
34+
% [minAIC,numComponents] = min(AIC);
35+
% gmModel = gm{numComponents};
36+
%
37+
% % Generate new points
38+
% Xp = random(gmModel, 1e8);
39+
% x_i = Xp(:,1);
40+
% x_j = Xp(:,2);
41+
42+
save(fullfile('../res', model_filename),'gmModel');

0 commit comments

Comments
 (0)