|
| 1 | +classdef Nmf < imagem.gui.Action |
| 2 | +% Non-negative matrix factorization of current table. |
| 3 | +% |
| 4 | +% Class Nmf |
| 5 | +% |
| 6 | +% Example |
| 7 | +% Nmf |
| 8 | +% |
| 9 | +% See also |
| 10 | +% |
| 11 | +% |
| 12 | +% ------ |
| 13 | +% Author: David Legland |
| 14 | + |
| 15 | +% Created: 2021-04-09, using Matlab 7.9.0.529 (R2009b) |
| 16 | +% Copyright 2012 INRA - Cepia Software Platform. |
| 17 | + |
| 18 | + |
| 19 | +%% Properties |
| 20 | +properties |
| 21 | +end % end properties |
| 22 | + |
| 23 | + |
| 24 | +%% Constructor |
| 25 | +methods |
| 26 | + function obj = Nmf() |
| 27 | + % Constructor for TablePcaAction class |
| 28 | + |
| 29 | + end |
| 30 | + |
| 31 | +end % end constructors |
| 32 | + |
| 33 | + |
| 34 | +%% Methods |
| 35 | +methods |
| 36 | + function run(obj, frame) %#ok<INUSL> |
| 37 | + |
| 38 | + if isempty(frame.Doc) |
| 39 | + return; |
| 40 | + end |
| 41 | + table = frame.Doc.Table; |
| 42 | + |
| 43 | + % default number of components |
| 44 | + nComps = min(5, size(table, 2)); |
| 45 | + |
| 46 | + % open a dialog to choose number of components |
| 47 | + prompt = {'Number of components:'}; |
| 48 | + title = 'Non-Negative Matrix Factorization'; |
| 49 | + dims = [1 35]; |
| 50 | + definput = {num2str(nComps)}; |
| 51 | + answer = inputdlg(prompt, title, dims, definput); |
| 52 | + |
| 53 | + % check user did not cancel |
| 54 | + if isempty(answer) |
| 55 | + return; |
| 56 | + end |
| 57 | + |
| 58 | + % parse user input |
| 59 | + nComps = str2double(answer{1}); |
| 60 | + if isnan(nComps) |
| 61 | + error('Could not interpret the number of components from string: %s', answer{1}); |
| 62 | + end |
| 63 | + |
| 64 | + [W, H] = nmf(table, nComps); |
| 65 | + |
| 66 | + % create a new frame for weights |
| 67 | + [frameW, docW] = createTableFrame(frame.Gui, W); %#ok<ASGLU> |
| 68 | + |
| 69 | + % create a new frame for coefficients |
| 70 | + [frameH, docH] = createTableFrame(frame.Gui, H); %#ok<ASGLU> |
| 71 | + |
| 72 | + |
| 73 | + % update history |
| 74 | + historyString = sprintf('[%s, %s] = nmf(%s, %d);\n', ... |
| 75 | + docW.Tag, docH.Tag, doc.Tag, nComps); |
| 76 | + addToHistory(frame, historyString); |
| 77 | + |
| 78 | + end |
| 79 | +end % end methods |
| 80 | + |
| 81 | +end % end classdef |
| 82 | + |
0 commit comments