2015-06-20 195 views
0

我有一個非常簡單的問題,但我也沒弄明白怎麼解決this.I擁有以下功能定義:將參數傳遞給Matlab的功能

function model = oasis(data, class_labels, parms) 
% model = oasis(data, class_labels, parms) 
% 
% Code version 1.3 May 2011 Fixed random seed setting 
% Code version 1.2 May 2011 added call to oasis_m.m 
% Code version 1.1 May 2011 handle gaps in class_labels 
% 
% Input: 
% -- data   - Nxd sparse matrix (each instance being a ROW) 
% -- class_labels - label of each data point (Nx1 integer vector) 
% -- parms (do sym, do_psd, aggress etc.) 
% 
% Output: 
% -- model.W - dxd matrix 
% -- model.loss_steps - a binary vector: was there an update at 
%   each iterations 
% -- modeo.parms, the actual parameters used in the run (inc. defaults) 
% 
% Parameters: 
% -- aggress: The cutoff point on the size of the correction 
%   (default 0.1) 
% -- rseed: The random seed for data point selection 
%   (default 1) 
% -- do_sym: Whether to symmetrize the matrix every k steps 
%   (default 0) 
% -- do_psd: Whether to PSD the matrix every k steps, including 
%   symmetrizing them (defalut 0) 
% -- do_save: Whether to save the intermediate matrices. Note that 
%   saving is before symmetrizing and/or PSD in case they exist 
%   (default 0) 
% -- save_path: In case do_save==1 a filename is needed, the 
%   format is save_path/part_k.mat 
% -- num_steps - Number of total steps the algorithm will 
%   run (default 1M steps) 
% -- save_every: Number of steps between each save point 
%   (default num_steps/10) 
% -- sym_every: An integer multiple of "save_every", 
%   indicates the frequency of symmetrizing in case do_sym=1. The 
%   end step will also be symmetrized. (default 1) 
% -- psd_every: An integer multiple of "save_every", 
%   indicates the frequency of projecting on PSD cone in case 
%   do_psd=1. The end step will also be PSD. (default 1) 
% -- use_matlab: Use oasis_m.m instead of oasis_c.c 
%  This is provided in the case of compilation problems. 
% 

我想要使用此功能,但我不知道如何設置參數,或使用默認值。在這種情況下,什麼是可變參數,它是一個保持所有其他變量的對象?我可以做一些像語法的東西,我們把參數的名字加上值嗎?例如:

model = oasis(data_example, labels_example, agress = 0.2) 

另外,如果我理解正確的,我得到兩個對象的輸出,這是模型和Modeo公司,所以我需要撥打這個電話來接收所有內容,該函數返回?

[model,modeo] = oasis(data_example, labels_example, ?(parms)?) 

回答

0

從上面的文檔中,我不知道哪一個是正確的,但在matlab中有兩種常用的可選參數。

參數值對:​​

model = oasis(data, class_labels, 'do_sym',1,'do_psd',0) 

結構:

params.do_sym=1 
params.do_psd=0 
model = oasis(data, class_labels, params) 

也許這兩種可能性中的一個是正確的。

+0

我解決了用參數創建結構的問題。對於輸出結果,Tamás評論說文本中有一個錯字 – Mike

1

從你的函數定義看來,params只是參數的佔位符。典型地,參數本身被傳遞作爲形式對輸入:

model = oasis(data, class_labels, 'do_sym',do_symValue, 'do_psd', do_psdValue,...)

其中do_symValuedo_psdValue和是要傳遞作爲各參數的值。

至於函數返回值,返回單個struct,其成員爲W,loss_stepsparms。我相信你認爲第二個輸出(modelo)只是文本中的一個錯字 - 至少是基於函數的定義。