吴恩达机器学习练习2:optimset和fminunc函数

在练习2中使用了到了两个函数:optimset和fminunc。

%  Set options for fminunc
options = optimset('GradObj', 'on', 'MaxIter', 400);
%set the GradObj option to on,which tells fminunc that our function
%returns both the cost and gradient.
%This allows fminunc  to use the gradient when minimizing the function.
%set the MaxIter option to 400, so that fminunc will run for at most 400
%steps before it terminates.

%  Run fminunc to obtain the optimal theta
%  This function will return theta and the cost 
[theta, cost] = ...
	fminunc(@(t)(costFunction(t, X, y)), initial_theta, options);

1、通过help查看optimset函数

>> help optimset
 optimset Create/alter optimization OPTIONS structure.
    OPTIONS = optimset('PARAM1',VALUE1,'PARAM2',VALUE2,...) creates an
    optimization options structure OPTIONS in which the named parameters have
    the specified values.  Any unspecified parameters are set to [] (parameters
    with value [] indicate to use the default value for that parameter when
    OPTIONS is passed to the optimization function). It is sufficient to type
    only the leading characters that uniquely identify the parameter.  Case is
    ignored for parameter names.
    NOTE: For values that are strings, the complete string is required.
 
    OPTIONS = optimset(OLDOPTS,'PARAM1',VALUE1,...) creates a copy of OLDOPTS
    with the named parameters altered with the specified values.
 
    OPTIONS = optimset(OLDOPTS,NEWOPTS) combines an existing options structure
    OLDOPTS with a new options structure NEWOPTS.  Any parameters in NEWOPTS
    with non-empty values overwrite the corresponding old parameters in
    OLDOPTS.
 
    optimset with no input arguments and no output arguments displays all
    parameter names and their possible values, with defaults shown in {}
    when the default is the same for all functions that use that parameter. 
    Use optimset(OPTIMFUNCTION) to see parameters for a specific function.
 
    OPTIONS = optimset (with no input arguments) creates an options structure
    OPTIONS where all the fields are set to [].
 
    OPTIONS = optimset(OPTIMFUNCTION) creates an options structure with all
    the parameter names and default values relevant to the optimization
    function named in OPTIMFUNCTION. For example,
            optimset('fminbnd')
    or
            optimset(@fminbnd)
    returns an options structure containing all the parameter names and
    default values relevant to the function 'fminbnd'.
 
 optimset PARAMETERS for MATLAB
 Display - Level of display [ off | iter | notify 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值