⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 util_do_operation.m

📁 Standard model object recognition matlab code
💻 M
字号:
function y = util_do_operation (x, w_in, oper_type, varargin)% FUNCTION y = util_do_operation (x, w, oper_type, varargin)%% Sometimes, comp_get_next_layer can be cumbersome, since the input% and filter/weights need to be in some particular format.  Hence,% this is a simple function to run on input x and w.  Note that the% actual computations done here may be different (ie. check with% init_operation_def.m to make sure).  The inputs x and w are given% in a format of%    w = number of afferents x 1%    x = number of afferents x sample points% The accepted oper_type are:%   'gaussf': Gassian function with varargin{1} = sigma.%   'normsp': Normalized dot product with L2 norm.%   'normdp': Normalized dot product varargin{1} = [p q r]. num_d = size(x,1);num_x = size(x,2);switch oper_type  case ('gaussf')    % Gaussian function    w_rep = repmat(w_in, [1 size(x,2)]);    y     = sum((w_rep-x).^2);        % with this sigma, gaussian function at 0 is 0.01.    if length(varargin) > 0      sigma = varargin{1};    else      sigma = sum(w_in.^2);      sigma = sqrt(-sigma/2/log(0.01));      sigma = 1;    end    y     = exp(-y./2/sigma^2);    case ('normdp')    % Normalized dot product    if length(varargin) > 0      o_exp = varargin{1};      p = o_exp(1);      q = o_exp(2);      r = o_exp(3);      if length(varargin) > 1	% sigmoid parameters	o_sig = varargin{2};	a = o_sig(1);	b = o_sig(2);      else	a = sqrt(length(w_in)^(q*r/p));	b = 0.9;      end    else      error('Specify p, q, and r for normalized operation.');    end        w = w_in.^(q-p);    c  = (sum(w.^(q/(q-p))).^r)*(q*r/p-1)+eps;    y_max = p/q/r./(sum(w.^(q/(q-p))).^(r-1));    w_rep = repmat(w, [1 size(x,2)]);    y = sum(w_rep.*(x.^p))./(c+sum(x.^q).^r);    y = y./y_max;        y = 1./(1+exp(-a*(y-b)));      case ('dotpro')    % Just the dot product    %w_in  = w_in-0.3;    w_in  = w_in-mean(w_in);    w_rep = repmat(w_in, [1 size(x,2)]);    y     = sum(w_rep.*x);    y     = y.*(y>0); % rectify the response.    % Absolute y_max is when x=1 and w>0.    y_max = sum(w_rep.*(w_rep>0))+eps;    %y_max = repmat(max(y),[size(y,1) 1]);    y = y./y_max;        if length(varargin) > 0      % sigmoid parameters      o_sig = varargin{1};      a = o_sig(1);      b = o_sig(2);      y = 1./(1+exp(-a*(y-b)));    end        case ('modelo') % Model operation.    % x and w need to be converted into 3D and 4D matrices,    % respectively.    x_r(:,1,:)  = x';    f1(1,1,:,1) = w_in;    f2          = ones(size(f1));    addpath('~/Model/Ver5.0');    f = filt_package([],f1,f2,1,'s1');    y = comp_get_next_layer (x_r, f, 'normsp');end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -