{"text": "function delay=delayest_3point(u2,u1,method,estimator,parameter);\n%delay=delayest_3point(u2,u1,method,estimator,parameter);\n%Estimates delay of u2 wrt u1 by interpolating the peak of the cross correlatio\n%using a three-point peak interpolation\n%method may be 'parabola','Gaussian','modGaussian','cosine'.\n%estimator may be 'xcorr','ASDF','AMDF' (AMDF is very slow).\n%if using modGaussian, parameter is a bias (always used if >=0, only used\n%for xc<0 for parameter < 0)\n\nif nargin<3\n method='parabola';\nend\n\nif nargin<4\n estimator='xcorr';\nend\n\nif nargin<5\n switch method\n case {'modGaussian','modgaussian'}\n parameter=1;\n end\nend\n\n\nN_p=numel(u2);%number of elements\n\n\n\nswitch estimator\n case {'xcorr','xc','xcorr_fft'}%cross correlation\n U1=fft(u1);\n U2=fft(u2);\n xc=ifft(U2.*conj(U1));%circular xcorr\n [tmp idx]=max(xc);\n case {'ASDF'}%average squared difference function\n xc = (-2*ifft(fft(u2).*conj(fft(u1))) + sum(u1.^2) + sum(u2.^2))/N_p;%ADSF\n [tmp idx]=min(xc);\n case {'AMDF'}%average magnitude difference function (this is a lot slower for large N_p)\n xc=sum(abs(repmat(u1',1,N_p)-hankel(u2',[u2(end)'; u2(1:(end-1))'])))/N_p;%AMDF\n [tmp idx]=min(xc);\nend\n\n\nR=zeros(1,3);%three points to use for interpolation\nR(2)=xc(idx);%peak\n\n%find neighbors, assuming periodic\nif idx==1\n R(1)=xc(end);\n R(3)=xc(2);\nelseif idx==numel(xc)\n R(1)=xc(end-1);\n R(3)=xc(1);\nelse\n R(1)=xc(idx-1);\n R(3)=xc(idx+1);\nend\n\n\nswitch method\n case {'Gaussian','gaussian'}\n %a=exp(log(R(2))+(log(R(3))-log(R(1)))^2/(16*log(R(2))-8*log(R(1))-8*log(R(3))));%peak value\n %b=(2*log(R(2))-log(R(1))-log(R(3)))/2;%width\n c=(log(R(3))-log(R(1)))/(4*log(R(2))-2*log(R(1))-2*log(R(3)));\n case {'parabola','parabolic'}\n \t%A=inv([1 -1 1;0 0 1;1 1 1])*R';\n %c=-A(2)/(2*A(1));\n %a=-1/4*A(2)^2/A(1)+A(3);%peak value\n c=(R(3)-R(1))/(2*(2*R(2)-R(1)-R(3)));\n case {'modGaussian','modgaussian'}\n if parameter>=0%always add bias\n R=R-min(R)+parameter*R(2);\n else%only add bias if R has a negative value\n if any(R<=0)\n R=R-min(R)-parameter*R(2);\n end\n end\n %a=exp(log(R(2))+(log(R(3))-log(R(1)))^2/(16*log(R(2))-8*log(R(1))-8*log(R(3))));\n %b=(2*log(R(2))-log(R(1))-log(R(3)))/2;\n c=(log(R(3))-log(R(1)))/(4*log(R(2))-2*log(R(1))-2*log(R(3)));\n case {'cosine'}\n omega=acos((R(1)+R(3))/(2*R(2)));\n theta=atan((R(1)-R(3))/(2*R(2)*sin(omega)));\n %A=R(2)/cos(theta);\n c=-theta/omega;\n otherwise\n error('unknown method')\nend\n\nlag=mod(idx-1+floor(N_p/2),N_p)-floor(N_p/2);%integer part\ndelay=lag+c;%delay estimate\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/25210-subsample-delay-estimation/delay_estimation_6_03/delayest_3point.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026505426831, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.7499632401444675}} {"text": "function p = predictOneVsAll(all_theta, X)\n%PREDICT Predict the label for a trained one-vs-all classifier. The labels \n%are in the range 1..K, where K = size(all_theta, 1). \n% p = PREDICTONEVSALL(all_theta, X) will return a vector of predictions\n% for each example in the matrix X. Note that X contains the examples in\n% rows. all_theta is a matrix where the i-th row is a trained logistic\n% regression theta vector for the i-th class. You should set p to a vector\n% of values from 1..K (e.g., p = [1; 3; 1; 2] predicts classes 1, 3, 1, 2\n% for 4 examples) \n\nm = size(X, 1);\nnum_labels = size(all_theta, 1);\n\n% You need to return the following variables correctly \np = zeros(size(X, 1), 1);\n\n% Add ones to the X data matrix\nX = [ones(m, 1) X];\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Complete the following code to make predictions using\n% your learned logistic regression parameters (one-vs-all).\n% You should set p to a vector of predictions (from 1 to\n% num_labels).\n%\n% Hint: This code can be done all vectorized using the max function.\n% In particular, the max function can also return the index of the \n% max element, for more information see 'help max'. If your examples \n% are in rows, then, you can use max(A, [], 2) to obtain the max \n% for each row.\n% \n\n\nall_preds = all_theta * X';\n[max_vals, max_ndxs] = max(all_preds);\np = max_ndxs';\n\n\n% =========================================================================\n\n\nend\n", "meta": {"author": "khanhnamle1994", "repo": "machine-learning", "sha": "fa391eb9429187a295c15a14ba24f4416667e5c1", "save_path": "github-repos/MATLAB/khanhnamle1994-machine-learning", "path": "github-repos/MATLAB/khanhnamle1994-machine-learning/machine-learning-fa391eb9429187a295c15a14ba24f4416667e5c1/machine-learning-ex3/ex3/predictOneVsAll.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637433190939, "lm_q2_score": 0.8723473813156294, "lm_q1q2_score": 0.749925415296403}} {"text": "function r=rmse(data,estimate)\n% Function to calculate root mean square error from a data vector or matrix \n% and the corresponding estimates.\n% Usage: r=rmse(data,estimate)\n% Note: data and estimates have to be of same size\n% Example: r=rmse(randn(100,100),randn(100,100));\n\n% delete records with NaNs in both datasets first\nI = ~isnan(data) & ~isnan(estimate); \ndata = data(I); estimate = estimate(I);\n\nr=sqrt(sum((data(:)-estimate(:)).^2)/numel(data));", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/21383-rmse/rmse.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067179697694, "lm_q2_score": 0.7956581073313275, "lm_q1q2_score": 0.749913111366888}} {"text": "clear all\n% explicit euler\n% m = 1; %adjust value of m\n% y(1) = 1;%input your initial condition\n% dt = 0.2; %adjust your step size\n% T = 0:dt:15; %set up your time domain, here I have [0,5]\n% for i = 2:length(T) %construct a 'for' loop\n% y(i) = y(i-1) + m*dt*(-3*(i-2)/(i-1))*y(i-1)+m*dt*(2*(1+(i-2)^3))*exp(-(i-2));\n% end\n% plot(T,y)\n% \n% Implicit euler\n% n = 1; %adjust value of m\n% w(1) = 1;%input your initial condition\n% dtt = 0.2; %adjust your step size\n% T1 = 0:dtt:15; %set up your time domain, here I have [0,5]\n% for j = 2:length(T1) %construct a 'for' loop\n% w(j) = (w(j-1)+ dtt*(2*(j^3))*exp(-j+1))/(1+3*dtt*(j-1)/j) ;\n% end\n% plot(T1,w)\n% \n% \n% Crank-Nicolson\nm = 1; %adjust value of m\ny(1) = 1;%input your initial condition\ndt = 0.2; %adjust your step size\nT = 0:dt:15; %set up your time domain, here I have [0,5]\nfor i = 2:length(T) %construct a 'for' loop\n y(i)=(dt*i^3*exp(-i+1)+dt*(i-1)^3*exp(-i+2)+...\n y(i-1)*(1-0.5*dt*(-3*i-6/(i-1))))/(1+0.5*dt*(3*i+3/i));\nend\nplot(T,y)\n\n\n\n\n\n", "meta": {"author": "wme7", "repo": "Aero-matlab", "sha": "9430008f2e3b84f28633775a44dff534e780fbac", "save_path": "github-repos/MATLAB/wme7-Aero-matlab", "path": "github-repos/MATLAB/wme7-Aero-matlab/Aero-matlab-9430008f2e3b84f28633775a44dff534e780fbac/Coupled/time.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067211996142, "lm_q2_score": 0.7956580927949806, "lm_q1q2_score": 0.7499131002361356}} {"text": "function [ l, u ] = vand2_lu ( n, x )\n\n%*****************************************************************************80\n%\n%% VAND2_LU returns the LU factors of the VAND2 matrix.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 05 November 2013\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Halil Oruc, George Phillips,\n% Explicit factorization of the Vandermonde matrix,\n% Linear Algebra and its Applications,\n% Volume 315, Number 1-3, 15 August 2000, pages 113-123.\n%\n% Parameters:\n%\n% Input, integer N, the order of the matrix.\n%\n% Input, real X(N), the values that define the matrix.\n%\n% Output, real L(N,N), U(N,N), the LU factors of the matrix.\n%\n l = zeros ( n, n );\n\n for i = 1 : n\n for j = 1 : i\n l(i,j) = 1.0;\n for k = 1 : j - 1\n l(i,j) = l(i,j) * ( x(i) - x(k) ) / ( x(j) - x(k) );\n end\n end \n end\n\n u = zeros ( n, n );\n\n for i = 1 : n\n for j = i : n\n u(i,j) = complete_symmetric_poly ( i, j - i, x );\n for k = 1 : i - 1\n u(i,j) = u(i,j) * ( x(i) - x(k) );\n end\n end\n end\n\n return\nend\n\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_mat/vand2_lu.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422645, "lm_q2_score": 0.8289388083214156, "lm_q1q2_score": 0.7498999407757476}} {"text": "function pp = splinefit(varargin)\n%SPLINEFIT Fit a spline to noisy data.\n% PP = SPLINEFIT(X,Y,BREAKS) fits a piecewise cubic spline with breaks\n% (knots) BREAKS to the noisy data (X,Y). X is a vector and Y is a vector\n% or an ND array. If Y is an ND array, then X(j) and Y(:,...,:,j) are\n% matched. Use PPVAL to evaluate PP.\n%\n% PP = SPLINEFIT(X,Y,P) where P is a positive integer interpolates the\n% breaks linearly from the sorted locations of X. P is the number of\n% spline pieces and P+1 is the number of breaks.\n%\n% OPTIONAL INPUT\n% Argument places 4 to 8 are reserved for optional input.\n% These optional arguments can be given in any order:\n%\n% PP = SPLINEFIT(...,'p') applies periodic boundary conditions to\n% the spline. The period length is MAX(BREAKS)-MIN(BREAKS).\n%\n% PP = SPLINEFIT(...,'r') uses robust fitting to reduce the influence\n% from outlying data points. Three iterations of weighted least squares\n% are performed. Weights are computed from previous residuals.\n%\n% PP = SPLINEFIT(...,BETA), where 0 < BETA < 1, sets the robust fitting\n% parameter BETA and activates robust fitting ('r' can be omitted).\n% Default is BETA = 1/2. BETA close to 0 gives all data equal weighting.\n% Increase BETA to reduce the influence from outlying data. BETA close\n% to 1 may cause instability or rank deficiency.\n%\n% PP = SPLINEFIT(...,N) sets the spline order to N. Default is a cubic\n% spline with order N = 4. A spline with P pieces has P+N-1 degrees of\n% freedom. With periodic boundary conditions the degrees of freedom are\n% reduced to P.\n%\n% PP = SPLINEFIT(...,CON) applies linear constraints to the spline.\n% CON is a structure with fields 'xc', 'yc' and 'cc':\n% 'xc', x-locations (vector)\n% 'yc', y-values (vector or ND array)\n% 'cc', coefficients (matrix).\n%\n% Constraints are linear combinations of derivatives of order 0 to N-2\n% according to\n%\n% cc(1,j)*y(x) + cc(2,j)*y'(x) + ... = yc(:,...,:,j), x = xc(j).\n%\n% The maximum number of rows for 'cc' is N-1. If omitted or empty 'cc'\n% defaults to a single row of ones. Default for 'yc' is a zero array.\n%\n% EXAMPLES\n%\n% % Noisy data\n% x = linspace(0,2*pi,100);\n% y = sin(x) + 0.1*randn(size(x));\n% % Breaks\n% breaks = [0:5,2*pi];\n%\n% % Fit a spline of order 5\n% pp = splinefit(x,y,breaks,5);\n%\n% % Fit a spline of order 3 with periodic boundary conditions\n% pp = splinefit(x,y,breaks,3,'p');\n%\n% % Constraints: y(0) = 0, y'(0) = 1 and y(3) + y\"(3) = 0\n% xc = [0 0 3];\n% yc = [0 1 0];\n% cc = [1 0 1; 0 1 0; 0 0 1];\n% con = struct('xc',xc,'yc',yc,'cc',cc);\n%\n% % Fit a cubic spline with 8 pieces and constraints\n% pp = splinefit(x,y,8,con);\n%\n% % Fit a spline of order 6 with constraints and periodicity\n% pp = splinefit(x,y,breaks,con,6,'p');\n%\n% See also SPLINE, PPVAL, PPDIFF, PPINT\n\n% Author: Jonas Lundgren 2010\n\n% 2009-05-06 Original SPLINEFIT.\n% 2010-06-23 New version of SPLINEFIT based on B-splines.\n% 2010-09-01 Robust fitting scheme added.\n% 2010-09-01 Support for data containing NaNs.\n% 2011-07-01 Robust fitting parameter added.\n\n% Copyright (c) 2010, Jonas Lundgren\n% All rights reserved.\n% \n% Redistribution and use in source and binary forms, with or without \n% modification, are permitted provided that the following conditions are \n% met:\n% \n% * Redistributions of source code must retain the above copyright \n% notice, this list of conditions and the following disclaimer.\n% * Redistributions in binary form must reproduce the above copyright \n% notice, this list of conditions and the following disclaimer in \n% the documentation and/or other materials provided with the distribution\n% \n% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" \n% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE \n% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE \n% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE \n% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR \n% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF \n% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS \n% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN \n% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) \n% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE \n% POSSIBILITY OF SUCH DAMAGE.\n\n% Check number of arguments\nerror(nargchk(3,7,nargin));\n\n% Check arguments\n[x,y,dim,breaks,n,periodic,beta,constr] = arguments(varargin{:});\n\n% Evaluate B-splines\nbase = splinebase(breaks,n);\npieces = base.pieces;\nA = ppval(base,x);\n\n% Bin data\n[junk,ibin] = histc(x,[-inf,breaks(2:end-1),inf]); %#ok\n\n% Sparse system matrix\nmx = numel(x);\nii = [ibin; ones(n-1,mx)];\nii = cumsum(ii,1);\njj = repmat(1:mx,n,1);\nif periodic\n ii = mod(ii-1,pieces) + 1;\n A = sparse(ii,jj,A,pieces,mx);\nelse\n A = sparse(ii,jj,A,pieces+n-1,mx);\nend\n\n% Don't use the sparse solver for small problems\nif pieces < 20*n/log(1.7*n)\n A = full(A);\nend\n\n% Solve\nif isempty(constr)\n % Solve Min norm(u*A-y)\n u = lsqsolve(A,y,beta);\nelse\n % Evaluate constraints\n B = evalcon(base,constr,periodic);\n % Solve constraints\n [Z,u0] = solvecon(B,constr);\n % Solve Min norm(u*A-y), subject to u*B = yc\n y = y - u0*A;\n A = Z*A;\n v = lsqsolve(A,y,beta);\n u = u0 + v*Z;\nend\n\n% Periodic expansion of solution\nif periodic\n jj = mod(0:pieces+n-2,pieces) + 1;\n u = u(:,jj);\nend\n\n% Compute polynomial coefficients\nii = [repmat(1:pieces,1,n); ones(n-1,n*pieces)];\nii = cumsum(ii,1);\njj = repmat(1:n*pieces,n,1);\nC = sparse(ii,jj,base.coefs,pieces+n-1,n*pieces);\ncoefs = u*C;\ncoefs = reshape(coefs,[],n);\n\n% Make piecewise polynomial\npp = mkpp(breaks,coefs,dim);\n\n\n%--------------------------------------------------------------------------\nfunction [x,y,dim,breaks,n,periodic,beta,constr] = arguments(varargin)\n%ARGUMENTS Lengthy input checking\n% x Noisy data x-locations (1 x mx)\n% y Noisy data y-values (prod(dim) x mx)\n% dim Leading dimensions of y\n% breaks Breaks (1 x (pieces+1))\n% n Spline order\n% periodic True if periodic boundary conditions\n% beta Robust fitting parameter, no robust fitting if beta = 0\n% constr Constraint structure\n% constr.xc x-locations (1 x nx)\n% constr.yc y-values (prod(dim) x nx)\n% constr.cc Coefficients (?? x nx)\n\n% Reshape x-data\nx = varargin{1};\nmx = numel(x);\nx = reshape(x,1,mx);\n\n% Remove trailing singleton dimensions from y\ny = varargin{2};\ndim = size(y);\nwhile numel(dim) > 1 && dim(end) == 1\n dim(end) = [];\nend\nmy = dim(end);\n\n% Leading dimensions of y\nif numel(dim) > 1\n dim(end) = [];\nelse\n dim = 1;\nend\n\n% Reshape y-data\npdim = prod(dim);\ny = reshape(y,pdim,my);\n\n% Check data size\nif mx ~= my\n mess = 'Last dimension of array y must equal length of vector x.';\n error('arguments:datasize',mess)\nend\n\n% Treat NaNs in x-data\ninan = find(isnan(x));\nif ~isempty(inan)\n x(inan) = [];\n y(:,inan) = [];\n mess = 'All data points with NaN as x-location will be ignored.';\n warning('arguments:nanx',mess)\nend\n\n% Treat NaNs in y-data\ninan = find(any(isnan(y),1));\nif ~isempty(inan)\n x(inan) = [];\n y(:,inan) = [];\n mess = 'All data points with NaN in their y-value will be ignored.';\n warning('arguments:nany',mess)\nend\n\n% Check number of data points\nmx = numel(x);\nif mx == 0\n error('arguments:nodata','There must be at least one data point.')\nend\n\n% Sort data\nif any(diff(x) < 0)\n [x,isort] = sort(x);\n y = y(:,isort);\nend\n\n% Breaks\nif isscalar(varargin{3})\n % Number of pieces\n p = varargin{3};\n if ~isreal(p) || ~isfinite(p) || p < 1 || fix(p) < p\n mess = 'Argument #3 must be a vector or a positive integer.';\n error('arguments:breaks1',mess)\n end\n if x(1) < x(end)\n % Interpolate breaks linearly from x-data\n dx = diff(x);\n ibreaks = linspace(1,mx,p+1);\n [junk,ibin] = histc(ibreaks,[0,2:mx-1,mx+1]); %#ok\n breaks = x(ibin) + dx(ibin).*(ibreaks-ibin);\n else\n breaks = x(1) + linspace(0,1,p+1);\n end\nelse\n % Vector of breaks\n breaks = reshape(varargin{3},1,[]);\n if isempty(breaks) || min(breaks) == max(breaks)\n mess = 'At least two unique breaks are required.';\n error('arguments:breaks2',mess);\n end\nend\n\n% Unique breaks\nif any(diff(breaks) <= 0)\n breaks = unique(breaks);\nend\n\n% Optional input defaults\nn = 4; % Cubic splines\nperiodic = false; % No periodic boundaries\nrobust = false; % No robust fitting scheme\nbeta = 0.5; % Robust fitting parameter\nconstr = []; % No constraints\n\n% Loop over optional arguments\nfor k = 4:nargin\n a = varargin{k};\n if ischar(a) && isscalar(a) && lower(a) == 'p'\n % Periodic conditions\n periodic = true;\n elseif ischar(a) && isscalar(a) && lower(a) == 'r'\n % Robust fitting scheme\n robust = true;\n elseif isreal(a) && isscalar(a) && isfinite(a) && a > 0 && a < 1\n % Robust fitting parameter\n beta = a;\n robust = true;\n elseif isreal(a) && isscalar(a) && isfinite(a) && a > 0 && fix(a) == a\n % Spline order\n n = a;\n elseif isstruct(a) && isscalar(a)\n % Constraint structure\n constr = a;\n else\n error('arguments:nonsense','Failed to interpret argument #%d.',k)\n end\nend\n\n% No robust fitting\nif ~robust\n beta = 0;\nend\n\n% Check exterior data\nh = diff(breaks);\nxlim1 = breaks(1) - 0.01*h(1);\nxlim2 = breaks(end) + 0.01*h(end);\nif x(1) < xlim1 || x(end) > xlim2\n if periodic\n % Move data inside domain\n P = breaks(end) - breaks(1);\n x = mod(x-breaks(1),P) + breaks(1);\n % Sort\n [x,isort] = sort(x);\n y = y(:,isort);\n else\n mess = 'Some data points are outside the spline domain.';\n warning('arguments:exteriordata',mess)\n end\nend\n\n% Return\nif isempty(constr)\n return\nend\n\n% Unpack constraints\nxc = [];\nyc = [];\ncc = [];\nnames = fieldnames(constr);\nfor k = 1:numel(names)\n switch names{k}\n case {'xc'}\n xc = constr.xc;\n case {'yc'}\n yc = constr.yc;\n case {'cc'}\n cc = constr.cc;\n otherwise\n mess = 'Unknown field ''%s'' in constraint structure.';\n warning('arguments:unknownfield',mess,names{k})\n end\nend\n\n% Check xc\nif isempty(xc)\n mess = 'Constraints contains no x-locations.';\n error('arguments:emptyxc',mess)\nelse\n nx = numel(xc);\n xc = reshape(xc,1,nx);\nend\n\n% Check yc\nif isempty(yc)\n % Zero array\n yc = zeros(pdim,nx);\nelseif numel(yc) == 1\n % Constant array\n yc = zeros(pdim,nx) + yc;\nelseif numel(yc) ~= pdim*nx\n % Malformed array\n error('arguments:ycsize','Cannot reshape yc to size %dx%d.',pdim,nx)\nelse\n % Reshape array\n yc = reshape(yc,pdim,nx);\nend\n\n% Check cc\nif isempty(cc)\n cc = ones(size(xc));\nelseif numel(size(cc)) ~= 2\n error('arguments:ccsize1','Constraint coefficients cc must be 2D.')\nelseif size(cc,2) ~= nx\n mess = 'Last dimension of cc must equal length of xc.';\n error('arguments:ccsize2',mess)\nend\n\n% Check high order derivatives\nif size(cc,1) >= n\n if any(any(cc(n:end,:)))\n mess = 'Constraints involve derivatives of order %d or larger.';\n error('arguments:difforder',mess,n-1)\n end\n cc = cc(1:n-1,:);\nend\n\n% Check exterior constraints\nif min(xc) < xlim1 || max(xc) > xlim2\n if periodic\n % Move constraints inside domain\n P = breaks(end) - breaks(1);\n xc = mod(xc-breaks(1),P) + breaks(1);\n else\n mess = 'Some constraints are outside the spline domain.';\n warning('arguments:exteriorconstr',mess)\n end\nend\n\n% Pack constraints\nconstr = struct('xc',xc,'yc',yc,'cc',cc);\n\n\n%--------------------------------------------------------------------------\nfunction pp = splinebase(breaks,n)\n%SPLINEBASE Generate B-spline base PP of order N for breaks BREAKS\n\nbreaks = breaks(:); % Breaks\nbreaks0 = breaks'; % Initial breaks\nh = diff(breaks); % Spacing\npieces = numel(h); % Number of pieces\ndeg = n - 1; % Polynomial degree\n\n% Extend breaks periodically\nif deg > 0\n if deg <= pieces\n hcopy = h;\n else\n hcopy = repmat(h,ceil(deg/pieces),1);\n end\n % to the left\n hl = hcopy(end:-1:end-deg+1);\n bl = breaks(1) - cumsum(hl);\n % and to the right\n hr = hcopy(1:deg);\n br = breaks(end) + cumsum(hr);\n % Add breaks\n breaks = [bl(deg:-1:1); breaks; br];\n h = diff(breaks);\n pieces = numel(h);\nend\n\n% Initiate polynomial coefficients\ncoefs = zeros(n*pieces,n);\ncoefs(1:n:end,1) = 1;\n\n% Expand h\nii = [1:pieces; ones(deg,pieces)];\nii = cumsum(ii,1);\nii = min(ii,pieces);\nH = h(ii(:));\n\n% Recursive generation of B-splines\nfor k = 2:n\n % Antiderivatives of splines\n for j = 1:k-1\n coefs(:,j) = coefs(:,j).*H/(k-j);\n end\n Q = sum(coefs,2);\n Q = reshape(Q,n,pieces);\n Q = cumsum(Q,1);\n c0 = [zeros(1,pieces); Q(1:deg,:)];\n coefs(:,k) = c0(:);\n % Normalize antiderivatives by max value\n fmax = repmat(Q(n,:),n,1);\n fmax = fmax(:);\n for j = 1:k\n coefs(:,j) = coefs(:,j)./fmax;\n end\n % Diff of adjacent antiderivatives\n coefs(1:end-deg,1:k) = coefs(1:end-deg,1:k) - coefs(n:end,1:k);\n coefs(1:n:end,k) = 0;\nend\n\n% Scale coefficients\nscale = ones(size(H));\nfor k = 1:n-1\n scale = scale./H;\n coefs(:,n-k) = scale.*coefs(:,n-k);\nend\n\n% Reduce number of pieces\npieces = pieces - 2*deg;\n\n% Sort coefficients by interval number\nii = [n*(1:pieces); deg*ones(deg,pieces)];\nii = cumsum(ii,1);\ncoefs = coefs(ii(:),:);\n\n% Make piecewise polynomial\npp = mkpp(breaks0,coefs,n);\n\n\n%--------------------------------------------------------------------------\nfunction B = evalcon(base,constr,periodic)\n%EVALCON Evaluate linear constraints\n\n% Unpack structures\nbreaks = base.breaks;\npieces = base.pieces;\nn = base.order;\nxc = constr.xc;\ncc = constr.cc;\n\n% Bin data\n[junk,ibin] = histc(xc,[-inf,breaks(2:end-1),inf]); %#ok\n\n% Evaluate constraints\nnx = numel(xc);\nB0 = zeros(n,nx);\nfor k = 1:size(cc,1)\n if any(cc(k,:))\n B0 = B0 + repmat(cc(k,:),n,1).*ppval(base,xc);\n end\n % Differentiate base\n coefs = base.coefs(:,1:n-k);\n for j = 1:n-k-1\n coefs(:,j) = (n-k-j+1)*coefs(:,j);\n end\n base.coefs = coefs;\n base.order = n-k;\nend\n\n% Sparse output\nii = [ibin; ones(n-1,nx)];\nii = cumsum(ii,1);\njj = repmat(1:nx,n,1);\nif periodic\n ii = mod(ii-1,pieces) + 1;\n B = sparse(ii,jj,B0,pieces,nx);\nelse\n B = sparse(ii,jj,B0,pieces+n-1,nx);\nend\n\n\n%--------------------------------------------------------------------------\nfunction [Z,u0] = solvecon(B,constr)\n%SOLVECON Find a particular solution u0 and null space Z (Z*B = 0)\n% for constraint equation u*B = yc.\n\nyc = constr.yc;\ntol = 1000*eps;\n\n% Remove blank rows\nii = any(B,2);\nB2 = full(B(ii,:));\n\n% Null space of B2\nif isempty(B2)\n Z2 = [];\nelse\n % QR decomposition with column permutation\n [Q,R,dummy] = qr(B2); %#ok\n R = abs(R);\n jj = all(R < R(1)*tol, 2);\n Z2 = Q(:,jj)';\nend\n\n% Sizes\n[m,ncon] = size(B);\nm2 = size(B2,1);\nnz = size(Z2,1);\n\n% Sparse null space of B\nZ = sparse(nz+1:nz+m-m2,find(~ii),1,nz+m-m2,m);\nZ(1:nz,ii) = Z2;\n\n% Warning rank deficient\nif nz + ncon > m2\n\tmess = 'Rank deficient constraints, rank = %d.';\n\twarning('solvecon:deficient',mess,m2-nz);\nend\n\n% Particular solution\nu0 = zeros(size(yc,1),m);\nif any(yc(:))\n % Non-homogeneous case\n\tu0(:,ii) = yc/B2;\n % Check solution\n\tif norm(u0*B - yc,'fro') > norm(yc,'fro')*tol\n mess = 'Inconsistent constraints. No solution within tolerance.';\n error('solvecon:inconsistent',mess)\n\tend\nend\n\n\n%--------------------------------------------------------------------------\nfunction u = lsqsolve(A,y,beta)\n%LSQSOLVE Solve Min norm(u*A-y)\n\n% Avoid sparse-complex limitations\nif issparse(A) && ~isreal(y)\n A = full(A);\nend\n\n% Solution\nu = y/A;\n\n% Robust fitting\nif beta > 0\n [m,n] = size(y);\n alpha = 0.5*beta/(1-beta)/m;\n for k = 1:3\n % Residual\n r = u*A - y;\n rr = r.*conj(r);\n rrmean = sum(rr,2)/n;\n rrmean(~rrmean) = 1;\n rrhat = (alpha./rrmean)'*rr;\n % Weights\n w = exp(-rrhat);\n spw = spdiags(w',0,n,n);\n % Solve weighted problem\n u = (y*spw)/(A*spw);\n end\nend\n\n", "meta": {"author": "wme7", "repo": "Aero-matlab", "sha": "9430008f2e3b84f28633775a44dff534e780fbac", "save_path": "github-repos/MATLAB/wme7-Aero-matlab", "path": "github-repos/MATLAB/wme7-Aero-matlab/Aero-matlab-9430008f2e3b84f28633775a44dff534e780fbac/K-wave/k-Wave/private/splinefit.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505376715774, "lm_q2_score": 0.8289388083214156, "lm_q1q2_score": 0.7498999386448053}} {"text": "function smin = choose_smin(kernel,sn,prob)\n%% Choose minimal spike spike to enforce sparsity constraint in spike inference \n% The function chooses a regularization weight for sparse deconvolution\n% with a given kernel and noise level. The weight of the regularizer\n% is chosen such that noise alone cannot lead to a non-zero solution is\n% at least prob.\n\n% Inputs:\n% kernel: deconvolution kernel \n% if length(kernel) == 1 or length(kernel) == 2, then kernel\n% is treated as a set of discrete time constants g. Otherwise,\n% it is treated as the actual vector.\n% sn: noise level\n% prob: probability of zero solution (deafult: 0.99)\n\n% Output:\n% smin: minimal spike size \n\n% Author: Pengcheng Zhou, Carnegie Mellon University, 2016\n% modified from choose_lambda.m Eftychios A. Pnevmatikakis, 2016, Simons Foundation\n% based on ideas and discussions with J. Tubiana and G. Debregeas, \n% Laboratorie Jean Parrin, UPMC, France \n\n% Reference for this approach:\n% Selesnick, I. (2012). Sparse deconvolution (an MM algorithm)\n\n%%\n\nif nargin < 3 || isempty(prob)\n prob = 0.99999;\nend\n\nif nargin < 2 || isempty(sn)\n sn = 1;\n warning('Noise value not provided. Using sn = 1...')\nend\n\nif length(kernel) <= 2\n kernel = filter(1,[1,-kernel(:)'],[1,zeros(1,999)]);\nend\n\nsmin = sn/norm(kernel)*norminv(prob);", "meta": {"author": "zhoupc", "repo": "CNMF_E", "sha": "ccca6f9db7d1d15b7dd1266eb9b29e417f92e79f", "save_path": "github-repos/MATLAB/zhoupc-CNMF_E", "path": "github-repos/MATLAB/zhoupc-CNMF_E/CNMF_E-ccca6f9db7d1d15b7dd1266eb9b29e417f92e79f/OASIS_matlab/functions/choose_smin.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.92522995296862, "lm_q2_score": 0.8104789155369047, "lm_q1q2_score": 0.7498793689042684}} {"text": "function sinh_values_test ( )\n\n%*****************************************************************************80\n%\n%% SINH_VALUES_TEST demonstrates the use of SINH_VALUES.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 23 June 2007\n%\n% Author:\n%\n% John Burkardt\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'SINH_VALUES_TEST:\\n' );\n fprintf ( 1, ' SINH_VALUES stores values of \\n' );\n fprintf ( 1, ' the hyperbolic sine function.\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' X FX\\n' );\n fprintf ( 1, '\\n' );\n\n n_data = 0;\n\n while ( 1 )\n\n [ n_data, x, fx ] = sinh_values ( n_data );\n\n if ( n_data == 0 )\n break\n end\n\n fprintf ( 1, ' %12f %24.16f\\n', x, fx );\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_values/sinh_values_test.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8577681122619885, "lm_q2_score": 0.8740772417253256, "lm_q1q2_score": 0.7497555856058984}} {"text": "function value = monomial_value ( dim_num, point_num, x, expon )\n\n%*****************************************************************************80\n%\n%% MONOMIAL_VALUE evaluates a monomial.\n%\n% Discussion:\n%\n% This routine evaluates a monomial of the form\n%\n% product ( 1 <= dim <= dim_num ) x(dim)^expon(dim)\n%\n% where the exponents are nonnegative integers. Note that\n% if the combination 0^0 is encountered, it should be treated\n% as 1.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 05 May 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer DIM_NUM, the spatial dimension.\n%\n% Input, integer POINT_NUM, the number of points at which the\n% monomial is to be evaluated.\n%\n% Input, real X(DIM_NUM,POINT_NUM), the point coordinates.\n%\n% Input, integer EXPON(DIM_NUM), the exponents.\n%\n% Output, real VALUE(POINT_NUM), the value of the monomial.\n%\n value(1:point_num) = 1.0;\n\n for dim = 1 : dim_num\n if ( 0 ~= expon(dim) )\n value(1:point_num) = value(1:point_num) .* x(dim,1:point_num).^expon(dim);\n end\n end\n\n return\nend", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/stroud/monomial_value.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772384450967, "lm_q2_score": 0.8577681104440172, "lm_q1q2_score": 0.7497555812031753}} {"text": "function [ ntree, itree, seed ] = tree_rooted_random ( nnode, seed )\n\n%*****************************************************************************80\n%\n%% TREE_ROOTED_RANDOM selects a random unlabeled rooted tree.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 28 June 2013\n%\n% Author:\n%\n% Original FORTRAN77 version by Albert Nijenhuis, Herbert Wilf.\n% FORTRAN90 version by John Burkardt.\n%\n% Reference:\n%\n% Albert Nijenhuis, Herbert Wilf,\n% Combinatorial Algorithms,\n% Academic Press, 1978, second edition,\n% ISBN 0-12-519260-6.\n%\n% Parameters:\n%\n% Input, integer NNODE, the number of nodes.\n%\n% Input/output, integer SEED, a seed for the random \n% number generator.\n%\n% Output, integer NTREE(NNODE). NTREE(I) is the number of \n% rooted, unlabeled trees on I nodes, for I = 1, 2, ... NNODE.\n%\n% Output, integer ITREE(NNODE). (I,ITREE(I)) is the I-th edge\n% of the output tree for I = 2,NNODE. ITREE(1)=0.\n%\n if ( nnode <= 0 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TREE_ROOTED_RANDOM - Fatal error!\\n' );\n fprintf ( 1, ' NNODE = %d\\n', nnode );\n fprintf ( 1, ' but NNODE must be at least 1.\\n' );\n error ( 'TREE_ROOTED_RANDOM - Fatal error!' );\n end\n%\n% Compute a table of the number of such trees for a given number of nodes.\n%\n ntree = tree_rooted_enum ( nnode );\n%\n% Now select one such tree at random.\n%\n l = 0;\n\n nval = nnode;\n is1 = 0;\n is2 = 0;\n \n while ( 1 )\n\n while ( 2 < nval )\n \n [ r, seed ] = r8_uniform_01 ( seed );\n\n iz = floor ( ( nval - 1 ) * ntree(nval) * r );\n\n id = 0;\n \n id = id + 1;\n itd = id * ntree(id);\n m = nval;\n j = 0;\n \n while ( 1 )\n \n j = j + 1;\n m = m - id;\n\n if ( m < 1 )\n id = id + 1;\n itd = id * ntree(id);\n m = nval;\n j = 0;\n continue\n end\n\n iz = iz - ntree(m) * itd;\n\n if ( iz < 0 )\n break\n end\n\n end\n\n is1 = is1 + 1;\n stack(1,is1) = j;\n stack(2,is1) = id;\n nval = m;\n \n end\n \n itree(is2+1) = l;\n l = is2 + 1;\n is2 = is2 + nval;\n\n if ( 1 < nval )\n itree(is2) = is2 - 1;\n end\n \n while ( 1 )\n \n nval = stack(2,is1);\n \n if ( nval ~= 0 )\n stack(2,is1) = 0;\n break\n end\n \n j = stack(1,is1);\n is1 = is1 - 1;\n m = is2 - l + 1;\n ll = itree(l);\n ls = l + ( j - 1 ) * m - 1;\n \n if ( j ~= 1 )\n for i = l : ls\n itree(i+m) = itree(i) + m;\n if ( mod(i-l,m) == 0 )\n itree(i+m) = ll;\n end\n end\n end\n \n is2 = ls + m;\n \n if ( is2 == nnode )\n return\n end\n\n l = ll;\n \n end\n\n end\n \n return\nend\n\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/treepack/tree_rooted_random.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772351648676, "lm_q2_score": 0.8577681086260461, "lm_q1q2_score": 0.7497555768004522}} {"text": "function h = p12_h ( n, x )\n\n%*****************************************************************************80\n%\n%% P12_H evaluates the Hessian for problem 12.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 28 March 2000\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the number of variables.\n%\n% Input, real X(N), the values of the variables.\n%\n% Output, real H(N,N), the N by N Hessian matrix.\n%\n h = zeros ( n, n );\n\n d1 = 2.0 / 3.0;\n\n for i = 1 : 99\n\n arg = i / 100.0;\n r = ( - 50.0 * log ( arg ) )^d1 + 25.0 - x(2);\n t1 = abs ( r )^x(3) / x(1);\n t2 = exp ( - t1 );\n t3 = t1 * t2 * ( t1 * t2 + ( t1 - 1.0 ) * ( t2 - arg ) );\n t = t1 * t2 * ( t2 - arg );\n logr = log ( abs ( r ) );\n\n h(1,1) = h(1,1) + 2.0 * t3 - 2.0 * t;\n h(1,2) = h(1,2) + 2.0 * t3 / r;\n h(1,3) = h(1,3) - 2.0 * t3 * logr;\n\n h(2,1) = h(2,1) + 2.0 * t3 / r;\n h(2,2) = h(2,2) + 2.0 * ( t + x(3) * t3 ) / r / r;\n h(2,3) = h(2,3) + 2.0 * ( t - x(3) * t3 * logr ) / r;\n\n h(3,1) = h(3,1) - 2.0 * t3 * logr;\n h(3,2) = h(3,2) + 2.0 * ( t - x(3) * t3 * logr ) / r;\n h(3,3) = h(3,3) + 2.0 * t3 * logr * logr;\n\n end\n\n h(1,1) = ( h(1,1) / x(1) ) / x(1);\n h(1,2) = h(1,2) * x(3) / x(1);\n h(1,3) = h(1,3) / x(1);\n\n h(2,1) = h(2,1) * x(3) / x(1);\n h(2,2) = h(2,2) * x(3);\n\n h(3,1) = h(3,1) / x(1);\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_opt/p12_h.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425267730008, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.7497224684792905}} {"text": "function [eef_transform,J]=directKinematics_1(q,TefTool,dh)\n%% Calculates the direct kinematics of a robotic manipulator \n\n% Syntax:\n% [eef_transform,J]=directKinematics(q,TefTool,dh)\n\n% Arreguments:\n% q: angles of the joints of the robot.\n% TefTool: transfomr matrix from the tool frame to the flange frame of the\n% robot.\n% dh: is a structure with the Denavit-Hartenberg parameters of the robot.\n\n\n% Return value:\n% eef_transform: transfomration matrix from end-effector to tool\n% J: jacobean at the tool center point (TCP) of the end-effector EEF.\n\n% Copyright:\n% Mohammad SAFEEA\n% 16th-Aug-2017\n% updated: 22nd-June-2018\n\n%% DH PARAMETERS FOR THE ROBOT\nalfa=dh.alfa;\nd=dh.d;\na=dh.a;\n\n%% Calculating the direct Kinematics\nT=zeros(4,4,7);\ni=1;\nT(:,:,i)=getDHMatrix(alfa{i},q(i),d{i},a{i});\n for i=2:7\n T(:,:,i)=T(:,:,i-1)*getDHMatrix(alfa{i},q(i),d{i},a{i});\n T(:,:,i)=normalizeColumns(T(:,:,i));\n end\n T(:,:,7)=T(:,:,7)*TefTool;\n T(:,:,7)=normalizeColumns(T(:,:,7));\n \n pef=T(1:3,4,7);\n for i=1:7\n k=T(1:3,3,i);\n pij=pef-T(1:3,4,i);\n J(1:3,i)=cross(k,pij);\n J(4:6,i)=k;\n end\n%% End effector transform\neef_transform=T(:,:,7);\nend\n\nfunction T=getDHMatrix(alfa,theta,d,a)\nT=zeros(4,4);\n\ncalpha=cos(alfa);\nsinalpha=sin(alfa);\ncoshteta=cos(theta);\nsintheta=sin(theta);\n\nT(1,1)=coshteta;\nT(2,1)=sintheta*calpha;\nT(3,1)=sintheta*sinalpha;\t\t\t\t\n\nT(1,2)=-sintheta;\nT(2,2)=coshteta*calpha;\nT(3,2)=coshteta*sinalpha;\n\nT(2,3)=-sinalpha;\nT(3,3)=calpha;\n\nT(1,4)=a;\nT(2,4)=-sinalpha*d;\nT(3,4)=calpha*d;\nT(4,4)=1;\n\nend\n\nfunction normalizedT=normalizeColumns(T)\n%% This function is used to normalize the columns of a rotation matrix with \n% some numerical errors resulting from matrix multiplication problems\nr=zeros(4,3); % corrected rotatio matrix, with zero badding row at the end\nfor j=1:3\n r(1:3,j)=T(1:3,j)/norm(T(1:3,j));\nend\nnormalizedT=[r,T(:,4)];\nend\n", "meta": {"author": "Modi1987", "repo": "KST-Kuka-Sunrise-Toolbox", "sha": "9299bed2b46058aeb4105d7fbff6d2290ce68bba", "save_path": "github-repos/MATLAB/Modi1987-KST-Kuka-Sunrise-Toolbox", "path": "github-repos/MATLAB/Modi1987-KST-Kuka-Sunrise-Toolbox/KST-Kuka-Sunrise-Toolbox-9299bed2b46058aeb4105d7fbff6d2290ce68bba/Matlab_client/directKinematics_1.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425289753969, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.7497224620180603}} {"text": "function X = matrandcong(m,n,gamma)\n%MATRANDCONG Create a random matrix with a fixed congruence.\n%\n% X = MATRANDCONG(M,N,GAMMA) creates a matrix X of size M x N such\n% that each column of X has norm 1 and any two columns of X have an inner\n% product equal to GAMMA.\n%\n% Based on code from Evrim Acar and the paper G. Tomasi and R. Bro, A\n% comparison of algorithms for fitting the PARAFAC model, Computational\n% Statistics & Data Analysis, 50: 1700-1734, 2006.\n%\n% See also MATRANDORTH, MATRANDNORM, CREATE_PROBLEM, CREATE_GUESS.\n%\n%MATLAB Tensor Toolbox.\n%Copyright 2015, Sandia Corporation.\n\n% This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others.\n% http://www.sandia.gov/~tgkolda/TensorToolbox.\n% Copyright (2015) Sandia Corporation. Under the terms of Contract\n% DE-AC04-94AL85000, there is a non-exclusive license for use of this\n% work by or on behalf of the U.S. Government. Export of this data may\n% require a license from the United States Government.\n% The full license terms can be found in the file LICENSE.txt\n\nCG = gamma * ones(n,n) + (1-gamma) * eye(n);\nCGR = chol(CG);\nX = randn(m,n);\n[Q,~] = qr(X,0);\nX = Q * CGR;\n", "meta": {"author": "zhangqianqianQQ", "repo": "MachineVisionAlgorithm", "sha": "683338f6c3b1aab9fa2b80026915fe936aebf0ee", "save_path": "github-repos/MATLAB/zhangqianqianQQ-MachineVisionAlgorithm", "path": "github-repos/MATLAB/zhangqianqianQQ-MachineVisionAlgorithm/MachineVisionAlgorithm-683338f6c3b1aab9fa2b80026915fe936aebf0ee/\u5206\u7c7b\u7b97\u6cd5/DEEP-TENSOR-FACTORIZATION-FOR-HYPERSPECTRAL-IMAGE-CLASSIFICATION-master/code/tensor_toolbox_2.6/matrandcong.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308110294983, "lm_q2_score": 0.8031738034238807, "lm_q1q2_score": 0.7497071747275998}} {"text": "% GAUSSIAN_DLOGPDF - The log pdf of a multivariate normal distribution.\n%\n% Computes the logarithm of the multivariate normal probability density\n% function N(Y|MU,COV), where Y is the random variable, MU is the mean\n% and COV is the covariance.\n%\n% The function is called as:\n%\n% L = GAUSSIAN_LOGPDF(Y_INVCOV_Y, Y_INVCOV_MU, MU_INVCOV_MU, LOGDET_COV, D)\n%\n% where\n%\n% Y_INVCOV_Y : Y'*INV(COV)*Y\n% Y_INVCOV_MU : Y'*INV(COV)*MU\n% MU_INVCOV_MU : MU'*INV(COV)*MU\n% LOGDET_COV : LOG(DET(COV))\n% D : the dimensionality of the distribution\n%\n% However, these terms should be computed more efficiently than using INV\n% and LOG(DET(..)).\n%\n% Letting the user to compute the terms allows greater efficiency and\n% flexibility.\n%\n% Also note that the function is linear with respect to its arguments. Thus,\n% some efficiency may be obtained for a large set of pdfs by summing the\n% terms and calling this function only once with scalar arguments.\n%\n% Usage:\n%\n% X = GAUSSIAN_DLOGPDF(Y, MU, L)\n%\n% X = GAUSSIAN_DLOGPDF(INVCOV_Y, INVCOV_MU)\n%\n% X = GAUSSIAN_DLOGPDF(D_Y_INVCOV_Y, D_Y_INVCOV_MU, D_MU_INVCOV_MU, ...\n% D_LOGDET_COV)\n\n% Last modified 2011-02-09\n% Copyright (c) Jaakko Luttinen (jaakko.luttinen@tkk.fi)\n\nfunction dx = gaussian_dlogpdf(p1, p2, p3, p4)\n\nif nargin == 3\n\n y = p1;\n mu = p2;\n L = p3;\n\n dx = -linsolve_lchol(L,y-mu);\n\nelseif nargin == 2\n \n invCov_y = p1;\n invCov_mu = p2;\n\n dx = invCov_mu - invCov_y;\n \nelseif nargin == 4\n \n dx = -0.5*(p1-2*p2+p3) - 0.5*p4;\n\nend\n\n\n", "meta": {"author": "jluttine", "repo": "matlab", "sha": "63406c7782b0869948f06e1dbc594460c165d24e", "save_path": "github-repos/MATLAB/jluttine-matlab", "path": "github-repos/MATLAB/jluttine-matlab/matlab-63406c7782b0869948f06e1dbc594460c165d24e/distributions/gaussian_dlogpdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.933430812881347, "lm_q2_score": 0.8031737963569014, "lm_q1q2_score": 0.74970716961842}} {"text": "function y = pinvNx2(x)\n\n% PINVNX2 computes a pseudo-inverse of the slices of an Nx2xM real-valued matrix.\n% Output has dimensionality 2xNxM. This implementation is generally faster\n% than calling pinv in a for-loop, once M > 2 \n\nsiz = [size(x) 1];\nxtx = zeros([2,2,siz(3:end)]);\nxtx(1,1,:,:) = sum(x(:,1,:,:).^2,1);\nxtx(2,2,:,:) = sum(x(:,2,:,:).^2,1);\ntmp = sum(x(:,1,:,:).*x(:,2,:,:),1);\nxtx(1,2,:,:) = tmp;\nxtx(2,1,:,:) = tmp;\nixtx = inv2x2(xtx);\ny = mtimes2xN(ixtx, permute(x, [2 1 3:ndims(x)]));\n\nfunction [d] = inv2x2(x)\n\n% INV2X2 computes inverse of matrix x, where x = 2x2xN, using explicit analytic definition\n\nadjx = [x(2,2,:,:) -x(1,2,:,:); -x(2,1,:,:) x(1,1,:,:)];\ndenom = x(1,1,:,:).*x(2,2,:,:) - x(1,2,:,:).*x(2,1,:,:);\nd = adjx./denom([1 1],[1 1],:,:);\n\nfunction [z] = mtimes2xN(x, y)\n\n% MTIMES2XN computes x*y where x = 2x2xM and y = 2xNxM\n% and output dimensionatity is 2xNxM \n\nsiz = size(y);\nz = zeros(siz);\n\nfor k = 1:siz(2)\n z(1,k,:,:) = x(1,1,:,:).*y(1,k,:,:) + x(1,2,:,:).*y(2,k,:,:);\n z(2,k,:,:) = x(2,1,:,:).*y(1,k,:,:) + x(2,2,:,:).*y(2,k,:,:);\nend\n", "meta": {"author": "spm", "repo": "spm12", "sha": "3085dac00ac804adb190a7e82c6ef11866c8af02", "save_path": "github-repos/MATLAB/spm-spm12", "path": "github-repos/MATLAB/spm-spm12/spm12-3085dac00ac804adb190a7e82c6ef11866c8af02/external/fieldtrip/utilities/private/pinvNx2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308110294983, "lm_q2_score": 0.8031737892899221, "lm_q1q2_score": 0.7497071615345274}} {"text": "function K_mat=Kernel_func(x,y,mu,lamda)\nxdatasize=size(x,1);\nydatasize=size(y,1);\nfor i=1:xdatasize\n for j=1:ydatasize\n K_mat(i,j)=mu*exp(-norm(x(i)-y(j))^2/(2*lamda^2));\n end\n end \nend\n\n", "meta": {"author": "epfl-lasa", "repo": "ML_toolbox", "sha": "61cc1245a2abe0c86a737d7b48bd645b28ffebee", "save_path": "github-repos/MATLAB/epfl-lasa-ML_toolbox", "path": "github-repos/MATLAB/epfl-lasa-ML_toolbox/ML_toolbox-61cc1245a2abe0c86a737d7b48bd645b28ffebee/methods/regression/gp/sgp/Kernel_func.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9546474168650673, "lm_q2_score": 0.7853085884247213, "lm_q1q2_score": 0.7496928153816125}} {"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% split1.m %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% function z = split1(x1,x2,f1,f2)\n% Input: points x1 and x2, x1 < x2, and corresponding function values f1\n% and f2\n% splits the interval [x1,x2] according to the golden section rule\n% the part containing the better point gets the larger fraction of the \n% interval\n\nfunction z = split1(x1,x2,f1,f2)\nif f1 <= f2\n z = x1 + 0.5*(-1 + sqrt(5))*(x2 - x1);\nelse\n z = x1 + 0.5*(3 - sqrt(5))*(x2 - x1);\nend\n", "meta": {"author": "lacerbi", "repo": "optimviz", "sha": "2cc41c19ffeaaa9a23239f53d80691cf3599357d", "save_path": "github-repos/MATLAB/lacerbi-optimviz", "path": "github-repos/MATLAB/lacerbi-optimviz/optimviz-2cc41c19ffeaaa9a23239f53d80691cf3599357d/utils/mcs/private/split1.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9362850093037731, "lm_q2_score": 0.8006920116079209, "lm_q1q2_score": 0.749675927537779}} {"text": "% SIGNED_DISTANCE Compute signed distance from points P to a mesh (V,F)\n%\n% [S,I,C,N] = signed_distance(P,V,F,'ParameterName',parameter_value,...)\n%\n% Inputs:\n% P #P by 3 list of query point positions\n% V #V by 3 list of vertex positions\n% F #F by 3 list of triangle indices\n% Optional:\n% 'SignedDistanceType' followed by\n% 'winding_number' use winding number (continuous sign value for\n% non-watertight)\n% {'pseudonormal'} use pseudo-normal, binary scale (but not robust for\n% non-watertight meshes.\n% Outputs:\n% S #P list of smallest signed distances\n% I #P list of facet indices corresponding to smallest distances\n% C #P by 3 list of closest points\n% N #P by 3 list of closest normals (only set if\n% \n% Example:\n% \n", "meta": {"author": "alecjacobson", "repo": "gptoolbox", "sha": "a0cb37d8edbcfb1e3587f793df8f24c76a2d7305", "save_path": "github-repos/MATLAB/alecjacobson-gptoolbox", "path": "github-repos/MATLAB/alecjacobson-gptoolbox/gptoolbox-a0cb37d8edbcfb1e3587f793df8f24c76a2d7305/mex/signed_distance.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850093037731, "lm_q2_score": 0.8006920092299292, "lm_q1q2_score": 0.7496759253113011}} {"text": "function p=gaussian(x,m,C);\n% p=gaussian(x,m,C);\n%\n% Evaluate the multi-variate density with mean vector m and covariance\n% matrix C for the input vector x.\n% \n% p=gaussian(X,m,C);\n% \n% Vectorized version: Here X is a matrix of column vectors, and p is \n% a vector of probabilities for each vector.\n% Jianbo Shi, 1997\nd=length(m);\n\nif size(x,1)~=d\n x=x';\nend\nN=size(x,2);\n\ndetC = det(C);\nif rcond(C)N),\n error('t0 must be between 1 and N.');\nelse\n if h <= 0 \n f = (1/N:1/N:0.5-1/N) ;\n y = zeros(1,N/2);\n y(2:N/2) = (f.^(-1-h)).*exp(-i*2*pi*f.*(t0-1));\n x = real(ifft(y,N)) ;\n x = x./max(x); \n x = x.' - sign(min(x))*abs(min(x)) ;\n else\n t = 1:N;\n x = abs(t-t0).^h;\n x = max(x)-x.' ;\n end\nend\n\nx=hilbert(x);", "meta": {"author": "HeLiangHIT", "repo": "time_frequency", "sha": "09c2abe92355ff5cd867bdb169229682e9d7af7c", "save_path": "github-repos/MATLAB/HeLiangHIT-time_frequency", "path": "github-repos/MATLAB/HeLiangHIT-time_frequency/time_frequency-09c2abe92355ff5cd867bdb169229682e9d7af7c/tf_tool_box/tftb-0.2/mfiles/anasing.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206870747657, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.749625108781788}} {"text": "function y = wprctile(x, p, w)\n%WPRCTILE Percentiles of a weighted sample.\n%\n% Description\n% Y = PRCTILE(X, P, W) returns percentiles of the values in X\n% (along the first dimension). P is a scalar or a vector of percent\n% values. W is a vector of unnormalized weights for samples. Length\n% of W has to be same as length of X. X need to be a a vector. Y is\n% the same size as P, and Y(i) contains the P(i)-th percentile.\n%\n% Example\n% y = prctile(x,50,w); % the median of x given sample weights w\n%\n% See also wmean, prctile\n%\n% Copyright (c) 2000-2013 Aki Vehtari\n\n% This software is distributed under the GNU General Public\n% License (version 3 or later); please refer to the file\n% License.txt, included with the software, for details.\n\nx=sort(x,1);\np=p./100;\ny=zeros(length(p),size(x,2));\nww=cumsum(w);ww=ww./ww(end);\nfor j=1:length(p)\n wi=min(find(ww>=p(j)));\n if wi==1\n y(j,:)=x(1,:);\n else\n w1=ww(wi-1);x1=x(wi-1,:);\n y(j,:)=x1+(x(wi,:)-x1).*(p(j)-w1)./(ww(wi)-w1);\n end\nend\n", "meta": {"author": "gpstuff-dev", "repo": "gpstuff", "sha": "114937ec0a201306489a66cbba38283e722fb998", "save_path": "github-repos/MATLAB/gpstuff-dev-gpstuff", "path": "github-repos/MATLAB/gpstuff-dev-gpstuff/gpstuff-114937ec0a201306489a66cbba38283e722fb998/misc/wprctile.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.901920681802153, "lm_q2_score": 0.8311430499496096, "lm_q1q2_score": 0.7496251062856728}} {"text": "function [ r ] = EffRank(s, thresh)\n%[ r ] = EffRank(s, thresh)\n% get the effective rank of an singular value array\n% s: the singular values in descending order\n% thresh: the total variance to preserve\n% author: Liang Xiong (lxiong@cs.cmu.edu)\n\nif nargin < 2; thresh = 0.99; end\nassert(all(s > 0), 'not a proper singular value array');\n\ns = sort(s.^2,'descend');\ncs = cumsum(s);\nif cs(end) < 1e-10\n error('EffRank has encounted a zero matrix');\nelse\n r = sum(cs./cs(end) <= thresh) + 1;\n r = min(length(s), r);\nend\n", "meta": {"author": "andrewssobral", "repo": "lrslibrary", "sha": "06d457349cb5f1fc56a583cd61af9f1d5150e3a1", "save_path": "github-repos/MATLAB/andrewssobral-lrslibrary", "path": "github-repos/MATLAB/andrewssobral-lrslibrary/lrslibrary-06d457349cb5f1fc56a583cd61af9f1d5150e3a1/algorithms/nmf/DRMF/EffRank.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9019206712569267, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.749625095634901}} {"text": "function [MSE, PSNR] = Calc_MSE_PSNR(clean,denoised)\n% Compute MSE and PSNR.\n%\n% clean: inputted clean image\n% denoised: inputted denoised image\n% MSE: outputted mean squared error\n% PSNR: outputted peak signal-to-noise ratio\n%\n% Author: Zhou Dengwen\n% zdw@ncepu.edu.cn\n% Department of Computer Science & Technology\n% North China Electric Power University(Beijing)(NCEPU)\n%\n% Last time modified: Jul. 15, 2008\n%\n\nN = prod(size(clean));\nclean = double(clean(:)); denoised = double(denoised(:));\nt1 = sum((clean-denoised).^2); t2 = sum(clean.^2);\nMSE = t1/N;\nPSNR = 10*log10(255*255/MSE);\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/20705-neighshrinksure-denoising/Calc_MSE_PSNR.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9304582593509315, "lm_q2_score": 0.8056321959813274, "lm_q1q2_score": 0.7496071307498544}} {"text": " function output = ir_radon_zwart_powell(theta, rr)\n%function output = ir_radon_zwart_powell(theta, yr)\n%|\n%| Compute analytic 2D Radon transform of Zwart-Powell box spline.\n%|\n%| in\n%| theta\tray angle in radian\n%| rr\tdistance between the point and the ray (normalized by the pixel size)\n%| output: radon transform of the Zwart-Powell box spline element\n%|\n%| This is the modified version of the code written by [1]\n%| to avoid symbolic math operation.\n%| Code written by Seongjin Yoon, Univ. of Michigan, Jan 2015\n%|\n%| Reference\n%| [1] A. Entezari, M. Nilchian, and M. Unser, \"A box spline calculus\n%| for the discretization of computed tomography reconstruction problems,\"\n%| IEEE Trans. Med. Imaging, vol. 31, no. 8, pp. 1532\u20131541, 2012.\n%|\n%| 2015-08-10 Jeff Fessler, added self test and parallelized\n\nif nargin == 1 && streq(theta, 'test'), ir_radon_zwart_powell_test, return, end\nif nargin < 2, ir_usage, end\n\ndim = size(theta);\ntheta = theta(:);\n\nzeta = zeros(numel(theta), 4);\nzeta(:,1) = cos(theta);\nzeta(:,2) = sin(theta);\nzeta(:,3) = zeta(:,1) + zeta(:,2);\nzeta(:,4) = zeta(:,1) - zeta(:,2);\n\ncond = abs(zeta) >= eps('single');\nN = sum(cond,2);\n\noutput = BoxSp4(rr(:), zeta, cond, N) ./ factorial(N-1);\noutput = reshape(output, dim);\n\n\nfunction output = BoxSp0(y, N)\n%output = heaviside(y) .* y.^(N-1);\nif any(size(y) ~= size(N)), keyboard, end\noutput = (y >= 0) .* y.^(N-1);\n\n\nfunction output = BoxSp1(y, zeta, cond, N)\ngood = cond(:,1);\noutput = (BoxSp0(y+0.5*zeta(:,1), N) ...\n\t- BoxSp0(y-0.5*zeta(:,1), N)) ./ zeta(:,1);\noutput(~good) = BoxSp0(y(~good), N(~good));\n\n\nfunction output = BoxSp2(y, zeta, cond, N)\ngood = cond(:,2);\noutput = (BoxSp1(y+0.5*zeta(:,2), zeta, cond, N) ...\n\t- BoxSp1(y-0.5*zeta(:,2), zeta, cond, N)) ./ zeta(:,2);\noutput(~good) = BoxSp1(y(~good), zeta(~good,:), cond(~good,:), N(~good));\n\n\nfunction output = BoxSp3(y, zeta, cond, N)\ngood = cond(:,3);\noutput = (BoxSp2(y+0.5*zeta(:,3), zeta, cond, N) ...\n\t- BoxSp2(y-0.5*zeta(:,3), zeta, cond, N)) ./ zeta(:,3);\noutput(~good) = BoxSp2(y(~good), zeta(~good,:), cond(~good,:), N(~good));\n\n\nfunction output = BoxSp4(y, zeta, cond, N)\ngood = cond(:,4);\noutput = (BoxSp3(y+0.5*zeta(:,4), zeta, cond, N) ...\n\t- BoxSp3(y-0.5*zeta(:,4), zeta, cond, N)) ./ zeta(:,4);\noutput(~good) = BoxSp3(y(~good), zeta(~good,:), cond(~good,:), N(~good));\n\n\n% ir_radon_zwart_powell_test()\nfunction ir_radon_zwart_powell_test\ntheta = linspace(0,pi,181);\nr = linspace(-1,1,101) * 2;\n[tt rr] = ndgrid(theta, r);\nsino = ir_radon_zwart_powell(tt, rr);\nim('colorneg', r, theta, sino'), cbar\n", "meta": {"author": "JeffFessler", "repo": "mirt", "sha": "b7f36cc46916821e8bc8502301b1554ebc7efe1d", "save_path": "github-repos/MATLAB/JeffFessler-mirt", "path": "github-repos/MATLAB/JeffFessler-mirt/mirt-b7f36cc46916821e8bc8502301b1554ebc7efe1d/fbp/ir_radon_zwart_powell.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582477806521, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.7496071127440984}} {"text": "function L = compute_point_laplacian(pts, type, rings, options)\n\n% compute_point_laplacian - compute a laplacian matrix L, L = -(Laplacian operator).\n%\n% L = compute_point_laplacian(pts, type, rings, options)\n%\n% If options.symmetrize=1 and options.normalize=0 then \n% L = D-W\n% If options.symmetrize=1 and options.normalize=1 then \n% L = eye(n)-D^{-1/2}*W*D^{-1/2}\n% If options.symmetrize=0 and options.normalize=1 then \n% L = eye(n)-D^{-1}*W.\n% where D=diag(sum(W,2)) and W is the unormalized weight matrix \n% (see compute_mesh_weight).\n%\n% type can 'combinatorial', 'distance', 'conformal'.\n%\n% See also compute_point_weight.\n%\n% Changed default value for symmetrize from 1 to 0 (JJCAO)\n% Copyright (c) 2009 jjcao\n\noptions.null = 0;\nnormalize = getoptions(options, 'normalize', 0);\nsymmetrize = getoptions(options, 'symmetrize', 1);\n\nW = compute_point_weight(pts, type, rings, options);\nn = size(W,1);\n \nif symmetrize==1 && normalize==0\n L = diag(sum(W,2)) - W;\nelseif symmetrize==1 && normalize==1\n L = speye(n) - diag(sum(W,2).^(-1/2)) * W * diag(sum(W,2).^(-1/2));\nelseif symmetrize==0 && normalize==1\n L = speye(n) - diag(sum(W,2).^(-1)) * W;\nelse\n error('Does not work with symmetrize=0 and normalize=0'); \nend\n", "meta": {"author": "taiya", "repo": "cloudcontr", "sha": "9c27e747136c5286c9a6e9f9c6b278f63cd5312f", "save_path": "github-repos/MATLAB/taiya-cloudcontr", "path": "github-repos/MATLAB/taiya-cloudcontr/cloudcontr-9c27e747136c5286c9a6e9f9c6b278f63cd5312f/matlab/toolbox/compute_point_laplacian.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545289551957, "lm_q2_score": 0.7905303211371899, "lm_q1q2_score": 0.7495449042626319}} {"text": "function [degree, node] = grNodeDegree(node, edges)\n%GRNODEDEGREE Degree of a node in a (undirected) graph.\n%\n% DEGREE = grNodeDegree(NODE_INDEX, EDGES);\n% return the degree of a node in the given edge list, that is the number\n% of edges connected to it.\n% NODE_INDEX is the index of the node, and EDGES is a liste of couples of\n% indices (origin and destination node). \n% This degree is the sum of inner degree (number of edges arriving on the\n% node) and the outer degree (number of emanating edges).\n% \n% Note: Also works when NODE_INDEX is a vector of indices\n%\n% DEGREE = grNodeDegree(EDGES);\n% Return the degree of each node references by the array EDGES. DEGREE is\n% a column vector with as many rows as the number of nodes referenced by\n% edges.\n%\n% [DEG, INDS] = grNodeDegree(EDGES);\n% Also returns the indices of the nodes that were referenced.\n% \n% Example\n% edges = [1 2;1 3;2 3;2 4;3 4];\n% grNodeDegree(2, edges)\n% ans =\n% 3\n% grNodeDegree(edges)'\n% ans =\n% 2 3 3 2\n%\n% See also grNodeInnerDegree, grNodeOuterDegree\n%\n\n% ------\n% Author: David Legland\n% E-mail: david.legland@grignon.inra.fr\n% Created: 2003-08-13\n% Copyright 2003-2022 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas)\n\n% If only edge array is given, assume we want the degree of each node\nif nargin == 1\n edges = node;\n node = unique(edges(:));\nend\n\n% allocate array for result\ndegree = zeros(size(node));\n\n% for each node ID, count the number of edges containing it\nfor i = 1:length(node(:))\n degree(i) = sum(edges(:,1) == node(i)) + sum(edges(:,2) == node(i));\nend\n", "meta": {"author": "mattools", "repo": "matGeom", "sha": "1fd2c937064be1ee1f4fd09fbfdf96145ebe5271", "save_path": "github-repos/MATLAB/mattools-matGeom", "path": "github-repos/MATLAB/mattools-matGeom/matGeom-1fd2c937064be1ee1f4fd09fbfdf96145ebe5271/matGeom/graphs/grNodeDegree.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479466, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.7495433029109088}} {"text": "function pass = test_battery(pref)\n% A large battery of functions. \n\nif ( nargin < 1 ) \n pref = chebfunpref; \nend \ntol = 1e8 * pref.cheb3Prefs.chebfun3eps;\n\nBattery = {@(x,y,z) cos(pi*x.*y.*z),... % 1\n @(x,y,z) cos(2*pi*x.*y.*z),... % 2\n @(x,y,z) cos(3*pi*x.*y.*z),... % 3\n @(x,y,z) cos(4*pi*x.*y.*z),... % 4\n @(x,y,z) cos(5*pi*x.*y.*z),... % 5\n @(x,y,z) cos(6*pi*x.*y.*z),... % 6\n @(x,y,z) cos(7*pi*x.*y.*z),... % 7\n @(x,y,z) sin(pi*x.*y.*z),... % 8\n @(x,y,z) sin(8*pi*x.*(1-x).*y.*(1-y).*z.*(1-z)),... % 9\n @(x,y,z) sin(8*pi*x.*(1-x).*y.*(1-y).*z.*(1-z).*(x-y-z).^2),... % 10\n @(x,y,z) cos(0*pi*(x-y-z).^2),... % 11\n @(x,y,z) cos(pi*(x-y-z).^2),... % 12\n @(x,y,z) cos(2*pi*(x-y-z).^2),... % 13\n @(x,y,z) exp(sin(4*pi./(1+x)).*sin(4*pi./(1+y)).*sin(4*pi./(1+z))),... % 14\n @(x,y,z) log(1+x.*y.*z),... % 15\n @(x,y,z) cos(pi*x.*sin(pi*y)) + cos(pi*y.*z.*sin(pi*x.*z)),... % 16\n @(x,y,z) cos(2*pi*x.*sin(pi*y).*cos(pi*z)) + cos(2*pi*y.*sin(pi*x)),... % 17\n @(x,y,z) (1-x.*y.*z)./(1+x.^2+y.^2),... % 18\n @(x,y,z) cos(pi*x.*y.^2.*z.^3).*cos(pi*z.*y.^2.*x.^3),... % 19\n @(x,y,z) cos(2*pi*x.*y.^2.*z.^3).*cos(2*pi*y.*x.^2.*z.^3),... % 20\n @(x,y,z) cos(3*pi*x.*y.^2.*(1+z)).*cos(3*pi*y.*x.^2.*(1+z)),... % 21 \n @(x,y,z) (x-y)./(3-x.^2+z.^2),... % 22 \n @(x,y,z) exp(-y.*x.^2.*z) + exp(-x.*y.^2.*z),... % 23\n @(x,y,z) exp((1-x.^2.*z)./(1+y.^2.*z)) + exp((1-y.^2.*z)./(1+x.^2.*z)),... % 24\n @(x,y,z) 10.^(-x.*y.*z),... % 25\n @(x,y,z) 10.^(-10*x.*y.*z),... % 26\n @(x,y,z) sin(x+y+z),... % 27\n @(x,y,z) exp(x+y+z).*cos(x+y+z),... % 28\n @(x,y,z) cos(pi/4+x+y+z),... % 29\n @(x,y,z) cos(pi/3+5*x+5*y+5*z),... % 30\n @(x,y,z) (x+y+z).^12,... % 31\n @(x,y,z) exp(x.^2.*y.^2.*z.^2).*cos(x+y+z),... % 32\n @(x,y,z) sin(x.*y.*z)+x+y+z,... % 33\n @(x,y,z) cos(100*x)-cos(100*y)-cos(100*z),... % 34\n @(x,y,z) x-y+z,... % 35\n @(x,y,z) -sin(x).*(sin(x.^2/pi).^2 - sin(y).*sin(y.^2/pi).^2) - sin(z).*sin(z.^2/pi).^2,... % 36\n @(x,y,z) -x.*sin(sqrt(abs(0.2+x))) - y.*sin(sqrt(abs(0.3+y))) - z.*sin(sqrt(abs(0.1+z))),... % 37 \n @(x,y,z) (x.^2+y.^2+z.^2)/4000 - cos(x).*cos(y/sqrt(2)) .* cos(z/sqrt(3))+1,... % 38\n @(x,y,z) exp(1./(1+(((x+1)/2).*((y+1)/2).*(z+1)/2).^2)),... % 39\n @(x,y,z) 2*exp(exp((x+1)/2)),... % 40\n };\n\n% Exact values for definite integrals computed with MATLAB's symbolic\n% toolbox.\nexact = [\n 0.8461106227350253, ...\n 0.6052157118483288, ...\n 0.4697661749231274, ...\n 0.3886397051915788, ...\n 0.3330920107414529, ...\n 0.2928314960173565, ...\n 0.2619772790103158, ...\n 0.3226674912855009, ...\n 0.1153949594968427, ...\n 0.0463743346003271, ...\n 1.0, ...\n 0.3854484437166375, ...\n 0.2595975105701650, ...\n 1.0700418045865364, ...\n 0.1103040719136995, ...\n 1.1941278093664705, ...\n 0.4916086077355209, ...\n 0.5741043338997425, ...\n 0.9381453489074456, ...\n 0.8830048694732021, ...\n 0.3411136775418946, ...\n 0.0101828389788635, ...\n 1.8529116285910792, ...\n 4.2715143503929390, ...\n 0.7859343211742496, ...\n 0.3352208605577725, ...\n 0.8793549306454008, ...\n -0.801590008944990, ...\n -0.577703137905825, ...\n -0.008766419956637, ...\n 5220.0021978021978, ...\n 0.0366931467095498, ...\n 1.6224340287967378, ...\n 0.0050636564110975, ...\n 0.5, ...\n -0.022434416365347, ...\n -1.181086511303566, ...\n 0.2694080277004217, ...\n 2.3340368233541618, ...\n 17.816513659679896, ...\n ];\n\ndom = [0 1 0 1 0 1];\nfor jj=1:1:length(Battery)\n % Test construction from the function handle:\n g = chebfun3(Battery{jj}, dom);\n pass(5*jj-4) = abs(sum3(g) - exact(jj)) < tol;\n \n % Test construction from the Chebfun3 object:\n % 1: Without specifying the variable to be separated in Phase 1:\n h = chebfun3(@(x,y,z) g(x,y,z), dom);\n pass(5*jj-3) = abs(sum3(h) - exact(jj)) < tol;\n \n % 2: Different variables specified to be separated in Phase 1. The\n % goal is to check that constructor has no issues with any choice of\n % variable chosen for the first separation.\n h1 = chebfun3(@(x,y,z) g(x,y,z), dom, 'fiberDim', 1);\n pass(5*jj-2) = abs(sum3(h1) - exact(jj)) < tol;\n \n h2 = chebfun3(@(x,y,z) g(x,y,z), dom, 'fiberDim', 2);\n pass(5*jj-1) = abs(sum3(h2) - exact(jj)) < tol;\n \n h3 = chebfun3(@(x,y,z) g(x,y,z), dom, 'fiberDim', 3);\n pass(5*jj) = abs(sum3(h3) - exact(jj)) < tol;\n \nend\n\nend", "meta": {"author": "chebfun", "repo": "chebfun", "sha": "8c49396a55e46ddd57a1d108c6a8f32e37536d54", "save_path": "github-repos/MATLAB/chebfun-chebfun", "path": "github-repos/MATLAB/chebfun-chebfun/chebfun-8c49396a55e46ddd57a1d108c6a8f32e37536d54/tests/chebfun3/test_battery.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248225478306, "lm_q2_score": 0.7981867849406659, "lm_q1q2_score": 0.7495172040889322}} {"text": "function [ ival, pint ] = plane_normal_line_exp_int_3d ( pp, normal, p1, p2 )\n\n%*****************************************************************************80\n%\n%% PLANE_NORMAL_LINE_EXP_INT_3D: intersection of plane and line in 3D.\n%\n% Discussion:\n%\n% The normal form of a plane in 3D is:\n%\n% PP is a point on the plane,\n% N is a normal vector to the plane.\n%\n% The explicit form of a line in 3D is:\n%\n% P1, P2 are two points on the line.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 07 May 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real PP(3), a point on the plane.\n%\n% Input, real NORMAL(3), a normal vector to the plane.\n%\n% Input, real P1(3), P2(3), two distinct points on the line.\n%\n% Output, integer IVAL, the kind of intersection;\n% 0, the line and plane seem to be parallel and separate;\n% 1, the line and plane intersect at a single point;\n% 2, the line and plane seem to be parallel and joined.\n%\n% Output, real PINT(3), the coordinates of a\n% common point of the plane and line, when IVAL is 1 or 2.\n%\n dim_num = 3;\n%\n% Make sure the line is not degenerate.\n%\n if ( line_exp_is_degenerate_nd ( dim_num, p1, p2 ) )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'PLANE_NORMAL_LINE_EXP_INT_3D - Fatal error!\\n' );\n fprintf ( 1, ' The line is degenerate.\\n' );\n error ( 'PLANE_NORMAL_LINE_EXP_INT_3D - Fatal error!' );\n end\n%\n% Make sure the plane normal vector is a unit vector.\n%\n temp = sqrt ( sum ( normal(1:dim_num).^2 ) );\n\n if ( temp == 0.0 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'PLANE_NORMAL_LINE_EXP_INT_3D - Fatal error!\\n' );\n fprintf ( 1, ' The normal vector of the plane is degenerate.\\n' );\n error ( 'PLANE_NORMAL_LINE_EXP_INT_3D - Fatal error!' );\n end\n\n normal(1:dim_num) = normal(1:dim_num) / temp;\n%\n% Determine the unit direction vector of the line.\n%\n direction(1:dim_num) = p2(1:dim_num) - p1(1:dim_num);\n temp = sqrt ( sum ( direction(1:dim_num).^2 ) );\n direction(1:dim_num) = direction(1:dim_num) / temp;\n%\n% If the normal and direction vectors are orthogonal, then\n% we have a special case to deal with.\n%\n if ( normal(1:dim_num) * direction(1:dim_num)' == 0.0 )\n\n temp = normal(1:dim_num) * ( p1(1:dim_num) - pp(1:dim_num) )';\n\n if ( temp == 0.0 )\n ival = 2;\n pint(1:dim_num) = p1(1:dim_num);\n else\n ival = 0;\n pint(1:dim_num) = Inf;\n end\n\n return\n end\n%\n% Determine the distance along the direction vector to the intersection point.\n%\n temp = ( ( pp(1:dim_num) - p1(1:dim_num) ) * normal(1:dim_num)' )...\n / ( direction(1:dim_num) * normal(1:dim_num)' );\n\n ival = 1;\n pint(1:dim_num) = p1(1:dim_num) + temp * direction(1:dim_num);\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/geometry/plane_normal_line_exp_int_3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789468908171, "lm_q2_score": 0.8376199673867852, "lm_q1q2_score": 0.7494935257649011}} {"text": "% Algorithm for finding connected components in a graph\n% Valid for undirected graphs only\n% INPUTS: adj - adjacency matrix\n% OUTPUTS: a list of the components comp{i}=[j1,j2,...jk}\n% Other routines used: find_conn_compI.m (embedded), degrees.m, kneighbors.m \n% GB, Last updated: October 2, 2009\n\n\nfunction comp_mat = find_conn_comp(adj)\n\n[deg,~,~]=degrees(adj); % degrees\ncomp_mat={}; % initialize components matrix\n\nfor i=1:length(deg)\n if deg(i)>0\n done=0;\n for x=1:length(comp_mat) % for every component check whether i is included\n if length(find(comp_mat{x}==i))>0 % i in comp_mat(x).mat\n done=1;\n break\n end\n end\n if not(done)\n comp=find_conn_compI(adj,i);\n comp_mat{length(comp_mat)+1}=comp;\n end\n \n elseif deg(i)==0\n comp_mat{length(comp_mat)+1}=[i];\n end\nend\n\n\nfunction comp=find_conn_compI(adj,i)\n% heuristic for finding the conn component to which \"i\" belongs to\n% works well in practice for large datasets\n% INPUTS: adjacency matrix and index of the key node\n% OUTPUTS: all node indices of the nodes to which \"i\" belongs to\n \nneigh1=kneighbors(adj,i,1);\nneigh1=unique([neigh1 i]); % add i to its own component\n \nwhile 1\n len0=length(neigh1);\n for j=1:len0\n neigh2=kneighbors(adj,neigh1(j),1);\n neigh1=unique([neigh1, neigh2]);\n end\n if len0==length(neigh1)\n comp=neigh1;\n return\n end\nend\n% Compute the total degree, in-degree and out-degree of a graph based on\n% the adjacency matrix; should produce weighted degrees, if the input matrix is weighted\n% INPUTS: adjacency matrix\n% OUTPUTS: degree, indegree and outdegree sequences\n% GB, Last Updated: October 2, 2009\n\nfunction [deg,indeg,outdeg]=degrees(adj)\n\nindeg = sum(adj);\noutdeg = sum(adj');\n\n% if isdirected(adj)\n deg = indeg + outdeg; % total degree\n% \n% else % undirected graph: indeg=outdeg\n% deg = indeg + diag(adj)'; % add self-loops twice, if any\n\n% end\n\n% Finds the number of k-neighbors (k links away) for every node\n% INPUTS: adjacency matrix, node index, k - number of links\n% OUTPUTS: vector of k-neighbors indices\n% GB, May 3, 2006\n\nfunction kneigh = kneighbors(adj,ind,k)\n\nadjk = adj;\nfor i=1:k-1; \n adjk = adjk*adj; \nend;\n\nkneigh = find(adjk(ind,:)>0);\n\nf_neigh = find(adjk(:,ind)>0);\nkneigh = unique([kneigh, f_neigh']);", "meta": {"author": "eldar", "repo": "deepcut", "sha": "096e2d174ddf2fbdc61458d9e7e6c6e897eac16c", "save_path": "github-repos/MATLAB/eldar-deepcut", "path": "github-repos/MATLAB/eldar-deepcut/deepcut-096e2d174ddf2fbdc61458d9e7e6c6e897eac16c/lib/multicut/find_conn_comp.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894632969137, "lm_q2_score": 0.8376199633332891, "lm_q1q2_score": 0.7494935174377743}} {"text": "\n%% Workspace initialization\n% The workspace is cleaned and some parameters and deffined\nclear all ; % this removes all variables stored in your current workspace\nclose all force ; % this closes all plotted figures\nclc ; % this clears the command window log\n\n% PARAMETERS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% \n% Set up the next parameters as your convenience.\n%\n% (2) This parameter must be an integer between 0 and 100.\n% It will be use to compute how many components you need explain a\n% given level of variance in the data.\n% For example:\n% PCA_level = 95 ;\n PCA_level = 95 ;\n%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\ndisp( ['================'] ) ;\ndisp( ['= PCA analysis ='] ) ;\ndisp( ['================'] ) ; disp( char(10) ) ;\n\n\n%% Loading and examinating the data\n% Data are read from an Excel or CSV file (genes at columns and samples at rows)\n% which must have the next structure:\n% - First column: the name of the class (cell-type, treatment, stage, etc)\n% - Second column: the name of the sample\n% - First row: a header with the name of the genes at each column. Notice\n% that the first two cells of the header corresponds to the sample's\n% class and samples's name.\ntic ; disp( [' - Loading data...'] ) ; disp( char(10) ) ;\n[ input_file,input_path ] = uigetfile( {'*.csv','Comma Sparated Values (*.csv)';'*.xls','Excel 97-2003 (*.xls)';'*.xlsx','Excel 2010 (*.xlsx)'},'MultiSelect','off' ) ;\n[ vector ] = strsplit( input_file,'.' ) ;\nfile_name = vector(1) ;\nextension = vector(2) ;\nif ( strcmp(extension,'csv') )\n T = readtable( [input_path,input_file],'Delimiter',',','ReadVariableNames',false ) ;\n if ( sum(strcmp(T{:,end},'')) > 1 )\n T(:,end) = [] ;\n end%if \n classes = T{2:end,1} ;\n names = T{2:end,2} ;\n if ( sum(sum(isnan(char(T{:,end})))) > 0 )\n genes = T{1,3:end-1} ; \n data = str2double(T{2:end,3:end-1}) ;\n else\n genes = T{1,3:end} ;\n data = str2double(T{2:end,3:end}) ;\n end%if\n clear T ;\nelse\n if ( strcmp(extension,'xls') || strcmp(extension,'xlsx') )\n [ data,txt ] = xlsread( [input_path,input_file] ) ;\n classes = txt(2:end,1) ;\n names = txt(2:end,2) ;\n genes = txt(1,3:end) ;\n clear txt ;\n else\n disp(' file-format error.')\n return ;\n end%if\nend%if\nwhos('data','names','classes','genes') ;\n% \"data\" is the matrix containing the normalized expression profiles from\n% single-cell qPCR data, with genes as columns and samples as rows. The\n% name of the genes at each column are in \"genes\", a row-vector.\n% Similarly, the name of each sample at each row of the \"data\" matrix are\n% stored in \"cell_names\", a column-vector. The names on these vectors must\n% be unique. The name of the classes at each row are stored in\n% \"classes_names\". This column vector has non-unique classes names.\nN = size(data,1) ;\nG = size(data,2) ;\nclasses_unique = unique( sort(classes) ) ;\nC = size(classes_unique,1) ;\nclasses_keys = zeros(N,1) ;\nK = size(classes_unique(:),1) ;\nfor k = 1:C\n classes_keys(strcmp(classes_unique(k),classes)) = k ;\n end%for\n \n% plotting parameters\n colors = hsv( C ) ;\n colors_soft = hsv2rgb( rgb2hsv(colors).*[ones(C,1) 0.5*ones(C,1) ones(C,1)] ) ;\n markers = {'+' 'o' '*' 's' 'x' 'd' '.' 'v' 'p' 'h'}' ;\n for k=1:ceil( C/size(markers,1)-1 )\n markers = [ markers(:) ; markers(:) ] ;\n end%for\n\n \n%% PCA\n% PCA is calculated using the corresponding function from the MATLAB's\n% statistical toolbox. \n disp( [char(10),'Performing PCA analysis...'] ) ;\n [coefficient,score,latent,tsquare,explained] = pca( data,'Algorithm','svd' ) ;\n % score*coefficient' = data - repmat(mean(data),size(data,1),1)\n PCA2 = rotatefactors(score(:,1:2),'Method','varimax') ;\n PCA3 = rotatefactors(score(:,1:3),'Method','varimax') ;\n IC = cumsum(explained) ;\n disp( [' Information content on the two first component: ',num2str(round(IC(2))),'%.'] ) ;\n disp( [' Information content on the three first component: ',num2str(round(IC(3))),'%.'] ) ;\n% writing output\n output_file = strjoin( [ input_path,file_name,'__PCA.csv' ],'' ) ;\n fid = fopen(output_file,'w') ;\n for k = 1:N\n fprintf( fid,'%s,%s,%f,%f,%f\\r\\n',names{k},classes{k},PCA3(k,:) ) ;\n end%for \n fclose(fid) ;\n% plotting the 2D PCA \n d = 0.1*( max(PCA2(:,1)) - min(PCA2(:,1)) ) ;\n x_min = min(PCA2(:,1))-d ;\n x_max = max(PCA2(:,1))+d ;\n d = 0.1*( max(PCA2(:,2)) - min(PCA2(:,2)) ) ;\n y_min = min(PCA2(:,2))-d ; \n y_max = max(PCA2(:,2))+d ;\n [ x y ] = meshgrid( x_min:(x_max-x_min)/100:x_max,y_min:(y_max-y_min)/100:y_max ) ;\n x = x(:) ; y = y(:) ;\n classification_result = classify( [x y],PCA2(:,1:2),classes,'quadratic' ) ;\n figure(1) ; set(1,'WindowStyle','docked') ;\n % set(1,'WindowStyle','normal','units','normalized','outerposition',[0 0 1 1]) ;\n hold on ; cla ; title(['2D PCA plot and discriminant analysis classification.']) ;\n if C > 1\n for k = 1:C\n index = strcmp( classification_result,classes_unique(k) ) ;\n scatter( x(index),y(index),100,colors_soft(k,:),'s','fill' ) ;\n end%for\n end%if\n h=[] ; text = [] ;\n for k = 1:C\n index = [classes_keys == k] ;\n text = [ text ; unique(classes(index)) ] ;\n h(k) = plot( PCA2(index,1),PCA2(index,2),markers{k},'Color',colors(k,:) ) ;\n end%for\n hold off ; grid on ;\n legend( h(:),text,'EdgeColor',[1 1 1],'Location','EO' ) ;\n xlabel('PC1 (first component)') ; xlim([x_min x_max]) ;\n ylabel('PC2 (second component)') ; ylim([y_min y_max]) ; \n% plotting the 3D PCA \n d = 0.1*( max(PCA3(:,3)) - min(PCA3(:,3)) ) ;\n z_min = min(PCA3(:,3))-d ; \n z_max = max(PCA3(:,3))+d ; \n figure(2) ; title(['3D PCA analysis.']) ;\n set(2,'WindowStyle','docked') ;\n cla ; hold on ; \n for k = 1:C\n index = [classes_keys == k] ;\n plot3( PCA3(index,1),PCA3(index,2),PCA3(index,3),markers{k},'Color',colors(k,:),'MarkerFaceColor','none','LineWidth',0.1 ) ;\n end%for\n hold off ; grid on ; view(135,25) ;\n legend( text,'EdgeColor',[1 1 1],'Location','EO' ) ; \n xlabel('PC1 (first component)') ; xlim([x_min x_max]) ;\n ylabel('PC2 (second component)') ; ylim([y_min y_max]) ; \n zlabel('PC3 (third component)') ; zlim( [z_min z_max] ) ; \n% plotting PCA information\n figure(3) ; set(3,'WindowStyle','docked') ; cla ; \n noc = min( sum(IC <= PCA_level)+1,G ) ;\n title(['PCA analysis. The ',num2str(PCA_level),'% is explained by the first ',num2str(noc),' copmonents.']) ; \n subplot(2,2,[1,2]) ; title(['Percentage of explained variance accumulated at each PCA component.']) ;\n hold on ; cla ;\n bar( IC(1:noc),1,'r' ) ;\n bar( IC.*([zeros(noc,1);ones(numel(IC)-noc,1)]),1,'b' ) ;\n hold off ;\n grid on ;\n legend( {['Less or equal than ',num2str(PCA_level),'%.'],['More than the ',num2str(PCA_level),'%.']},'EdgeColor',[1 1 1],'Location','NW' ) ; \n xlabel('component') ; xlim([0.5,size(IC,1)+0.5]) ;\n ylabel('% of variance') ; ylim( [0 100] ) ; \n subplot(2,2,3) ; title('PCA reconstruction, using all the components.') ;\n hold on ; cla ; \n imagesc( score*coefficient' + repmat(mean(data),size(data,1),1),[-1 1]*max(abs(data(:))) ) ;\n colormap( redgreencmap(100) ) ;\n hold off ;\n axis off ;\n subplot(2,2,4) ; title(['PCA approximation using ',num2str(noc),' of components.']) ;\n hold on ; cla ;\n imagesc( score*(coefficient.*[ones(G,noc) zeros(G,numel(IC)-noc)])' + repmat(mean(data),size(data,1),1),[-1 1]*max(abs(data(:))) ) ;\n colormap( redgreencmap(100) ) ;\n hold off ;\n axis off ; \n \n%% Picking data-points from the 2D plot\n choice = questdlg(['Do you want to identify a super class in you dataset?'],'Select superclass','Yes','No','Yes');\n switch choice\n case 'Yes'\n choice='No, I want to do it again' ;\n msgbox({'Select the data you are interested in by:','',' - doing click on a single point ',' - clicking and dragging to select all points in an area','','Press RETURN when you were ready.',''}) ;\n while strcmp(choice,'No, I want to do it again')\n figure(5) ; clf ; set(5,'WindowStyle','docked') ;\n hold on ;\n title(['2D PCA']) ;\n gscatter( PCA2(:,1),PCA2(:,2),classes,colors,strjoin([markers(1:C)'],'') ) ;\n hold off ; grid on ;\n xlim( [x_min x_max] ) ; xlabel('PCA1') ;\n ylim( [y_min y_max] ) ; ylabel('PCA2') ;\n legend( 'Location','EO' ) ;\n h=gname(names,5) ;\n superclass=get(h,'String') ; superclass=unique([superclass{:}]) ;\n fileID = fopen( strjoin( [ input_path,file_name,'__PCA_superclass.txt' ],'' ),'w' ) ;\n fprintf(fileID,'%s\\r\\n',superclass) ;\n fclose(fileID) ; \n choice = questdlg(['You have selected ',num2str(size(h,1)),' data points.',char(10),'Do you want to keep this selection or do you want to try it again'],'Are you Happy with your selection?','Yes, it is fine','No, I want to do it again','No, I want to do it again');\n end%while\n end%switch ", "meta": {"author": "zhangqianqianQQ", "repo": "MachineVisionAlgorithm", "sha": "683338f6c3b1aab9fa2b80026915fe936aebf0ee", "save_path": "github-repos/MATLAB/zhangqianqianQQ-MachineVisionAlgorithm", "path": "github-repos/MATLAB/zhangqianqianQQ-MachineVisionAlgorithm/MachineVisionAlgorithm-683338f6c3b1aab9fa2b80026915fe936aebf0ee/\u7279\u5f81\u63d0\u53d6\u7b97\u6cd5/PCA_analysis/pca_analysis.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.894789457685656, "lm_q2_score": 0.8376199633332891, "lm_q1q2_score": 0.7494935127376728}} {"text": "% Calculate head direction.\n%\n% Calculates the head direction for each position sample pair. Direction\n% is defined as east = 0 degrees, north = 90 degrees, west = 180 degrees,\n% south = 270 degrees. Direction is set to NaN for missing samples.\n% Position matrix contains information about front and back LED. Head\n% direction is the counter-clockwise direction from back LED to the front.\n%\n% USAGE\n% hd = calcHeadDirection(positions)\n%\n% positions Animal's position data, Nx5. Position data should\n% contain timestamps (1 column), X/Y coordinates of\n% first LED (2 and 3 columns correspondingly), X/Y\n% coordinates of the second LED (4 and 5 columns\n% correspondingly).\n% it is assumed that positions(:, 2:3) correspond to\n% front LED, and positions(:, 4:5) to the back LED.\n% The resulting hd is the directon from back LED to\n% the front LED.\n% hd Vector of head directions in degrees.\n%\nfunction hd = calcHeadDirection(positions)\n\n if size(positions, 2) < 5\n error('Position data should be 2D (type ''help analyses.calcHeadDirection'' for details).');\n end\n % 1 column contains timestamps\n x1 = positions(:, 2);\n y1 = positions(:, 3);\n x2 = positions(:, 4);\n y2 = positions(:, 5);\n\n hd = rem(atan2d(y2-y1, x2-x1) + 180, 360);\nend\n", "meta": {"author": "kavli-ntnu", "repo": "MINI2P_toolbox", "sha": "83311a49baea69ecf027e19390e608fd4eaeae8d", "save_path": "github-repos/MATLAB/kavli-ntnu-MINI2P_toolbox", "path": "github-repos/MATLAB/kavli-ntnu-MINI2P_toolbox/MINI2P_toolbox-83311a49baea69ecf027e19390e608fd4eaeae8d/Analysis/+analyses/calcHeadDirection.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947117065458, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.7494809343132174}} {"text": "function Y=hooklaw(X, td, E, ni);\n\n%Y=hooklaw(X, td, E, ni)\n%\n%This function calculates the strain or stress according to Hook's Law.\n%Transform direction determine the input variable td.\n%The proper values of td variable:\n%td='stress_strain' - if input variable X is a stress tensor\n%td='strain_stress' - if input variable X is a strain tensor\n%\n%But, for the purpose of computations we use the vector representation\n%of a tensor X(ij), so that:\n%X - is a vector representation of a tensor X(ij)\n% with the components in the following order:\n%\n%X=[Xxx Xyy Xzz Xxy Xxz Xzx Xyx Xyz Xxz]\n%or\n%X=[Xxx Xyy Xzz Xxy Xxz Xyz]\n%or\n%X=[Xxx Xyy Xzz]\n%\n%Dimension of X can be [m n]\n%where: m - represents the number of tensors to calculate\n% n = 9, 6 or 3 (see above)\n%\n%E - Young's modulus\n%ni - Poisson's coefficient\n%\n% Copyright (c) 2001 by Aleksander Karolczuk.\n% $Revision: 1.2 $ $Date: 2004/02/13\n\n\n\nerror(nargchk(4,4,nargin))\n\n[m n]=size(X);\n\nif n==3\n I=[1 1 1];\nelseif n==6\n I=[1 1 1 0 0 0];\nelseif n==9\n I=[1 1 1 0 0 0 0 0 0];\nelse\n error('Improper matrix dimension')\nend\n\nif lower(td)=='stress_strain'\n Y=((1+ni)/E)*(X-(ni/(1+ni))*(X*I')*I);\n elseif lower(td)=='strain_stress'\n Y=(E/(1+ni))*(X+(ni/(1-2*ni))*(X*I')*I);\n else\n error('Improper name of transform direction')\nend", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/24711-stress2strain/hooklaw.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947086083138, "lm_q2_score": 0.793105941403651, "lm_q1q2_score": 0.7494809179922656}} {"text": "%% Machine Learning Online Class\n% Exercise 8 | Anomaly Detection and Collaborative Filtering\n%\n% Instructions\n% ------------\n%\n% This file contains code that helps you get started on the\n% exercise. You will need to complete the following functions:\n%\n% estimateGaussian.m\n% selectThreshold.m\n% cofiCostFunc.m\n%\n% For this exercise, you will not need to change any code in this file,\n% or any other files other than those mentioned above.\n%\n\n%% Initialization\nclear ; close all; clc\n\n%% ================== Part 1: Load Example Dataset ===================\n% We start this exercise by using a small dataset that is easy to\n% visualize.\n%\n% Our example case consists of 2 network server statistics across\n% several machines: the latency and throughput of each machine.\n% This exercise will help us find possibly faulty (or very fast) machines.\n%\n\nfprintf('Visualizing example dataset for outlier detection.\\n\\n');\n\n% The following command loads the dataset. You should now have the\n% variables X, Xval, yval in your environment\nload('ex8data1.mat');\n\n% Visualize the example dataset\nplot(X(:, 1), X(:, 2), 'bx');\naxis([0 30 0 30]);\nxlabel('Latency (ms)');\nylabel('Throughput (mb/s)');\n\nfprintf('Program paused. Press enter to continue.\\n');\npause\n\n\n%% ================== Part 2: Estimate the dataset statistics ===================\n% For this exercise, we assume a Gaussian distribution for the dataset.\n%\n% We first estimate the parameters of our assumed Gaussian distribution, \n% then compute the probabilities for each of the points and then visualize \n% both the overall distribution and where each of the points falls in \n% terms of that distribution.\n%\nfprintf('Visualizing Gaussian fit.\\n\\n');\n\n% Estimate my and sigma2\n[mu sigma2] = estimateGaussian(X);\n\n% Returns the density of the multivariate normal at each data point (row) \n% of X\np = multivariateGaussian(X, mu, sigma2);\n\n% Visualize the fit\nvisualizeFit(X, mu, sigma2);\nxlabel('Latency (ms)');\nylabel('Throughput (mb/s)');\n\nfprintf('Program paused. Press enter to continue.\\n');\npause;\n\n%% ================== Part 3: Find Outliers ===================\n% Now you will find a good epsilon threshold using a cross-validation set\n% probabilities given the estimated Gaussian distribution\n% \n\npval = multivariateGaussian(Xval, mu, sigma2);\n\n[epsilon F1] = selectThreshold(yval, pval);\nfprintf('Best epsilon found using cross-validation: %e\\n', epsilon);\nfprintf('Best F1 on Cross Validation Set: %f\\n', F1);\nfprintf(' (you should see a value epsilon of about 8.99e-05)\\n');\nfprintf(' (you should see a Best F1 value of 0.875000)\\n\\n');\n\n% Find the outliers in the training set and plot the\noutliers = find(p < epsilon);\n\n% Draw a red circle around those outliers\nhold on\nplot(X(outliers, 1), X(outliers, 2), 'ro', 'LineWidth', 2, 'MarkerSize', 10);\nhold off\n\nfprintf('Program paused. Press enter to continue.\\n');\npause;\n\n%% ================== Part 4: Multidimensional Outliers ===================\n% We will now use the code from the previous part and apply it to a \n% harder problem in which more features describe each datapoint and only \n% some features indicate whether a point is an outlier.\n%\n\n% Loads the second dataset. You should now have the\n% variables X, Xval, yval in your environment\nload('ex8data2.mat');\n\n% Apply the same steps to the larger dataset\n[mu sigma2] = estimateGaussian(X);\n\n% Training set \np = multivariateGaussian(X, mu, sigma2);\n\n% Cross-validation set\npval = multivariateGaussian(Xval, mu, sigma2);\n\n% Find the best threshold\n[epsilon F1] = selectThreshold(yval, pval);\n\nfprintf('Best epsilon found using cross-validation: %e\\n', epsilon);\nfprintf('Best F1 on Cross Validation Set: %f\\n', F1);\nfprintf(' (you should see a value epsilon of about 1.38e-18)\\n');\nfprintf(' (you should see a Best F1 value of 0.615385)\\n');\nfprintf('# Outliers found: %d\\n\\n', sum(p < epsilon));\n", "meta": {"author": "Ayatans", "repo": "Machine-Learning-homework", "sha": "4550cfc0426c9da8072dff165130fff40d138c10", "save_path": "github-repos/MATLAB/Ayatans-Machine-Learning-homework", "path": "github-repos/MATLAB/Ayatans-Machine-Learning-homework/Machine-Learning-homework-4550cfc0426c9da8072dff165130fff40d138c10/machine-learning-ex8/ex8/ex8.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436397, "lm_q2_score": 0.8418256412990657, "lm_q1q2_score": 0.7494725127508136}} {"text": "function [X, sigma2, W] = ppcaEmbed(Y, dims)\n\n% PPCAEMBED Embed data set with probabilistic PCA.\n% FORMAT\n% DESC returns latent positions for a given data set via probabilistic\n% PCA.\n% ARG Y : the data set which you want the latent positions for.\n% ARG dims : the dimensionality of the latent space.\n% RETURN X : the latent positions.\n% RETURN sigma2 : the variance not explained by the latent positions.\n% RETURN W : the matrix required to invert the transformation, Y=X*W'.\n%\n% COPYRIGHT : Neil D. Lawrence, 2006\n%\n% SEEALSO : lleEmbed, isomapEmbed\n\n% MLTOOLS\n\nif ~any(any(isnan(Y)))\n if size(Y, 1)30000\n % Bug in MATLAB 7.0 means you have to do this.\n innerY = zeros(size(Ycentre, 1));\n for i = 1:size(Ycentre, 1)\n innerY(i, :) = Ycentre(i, :)*Ycentre';\n end\n else\n innerY = Ycentre*Ycentre';\n end\n [v, u] = eigdec(innerY, dims); \n v(find(v<0))=0;\n X = u(:, 1:dims)*sqrt(size(Y, 1));\n v = v/sqrt(size(Y, 1));\n sigma2 = (trace(innerY) - sum(v))/(size(Y, 2)-dims);\n W = X'*Ycentre;\n\n else\n [v, u] = pca(Y);\n v(find(v<0))=0;\n Ymean = mean(Y);\n Ycentre = zeros(size(Y));\n for i = 1:size(Y, 2);\n Ycentre(:, i) = Y(:, i) - Ymean(i);\n end\n X = Ycentre*u(:, 1:dims)*diag(1./sqrt(v(1:dims)));\n sigma2 = mean(v(dims+1:end));\n W = X'*Ycentre;\n end\nelse\n % Hacky implementation of Probabilistic PCA for when there is missing data.\n iters = 100;\n % Initialise W randomly\n d = size(Y, 2);\n q = dims;\n N = size(Y, 1);\n W = randn(d, q)*1e-3;\n sigma2 = 1;\n mu = zeros(d, 1);\n for i = 1:d\n obs = find(~isnan(Y(:, i)));\n if length(obs)>0\n mu(i) = mean(Y(obs, i));\n else\n mu(i) = 0;\n end\n end\n numObs = sum(sum(~isnan(Y)));\n for i = 1:iters\n M = W'*W + sigma2*eye(q);\n invM = inv(M);\n exp_xxT = zeros(q);\n exp_x = zeros(N, q);\n for n = 1:N\n obs = find(~isnan(Y(n, :)));\n exp_x(n, :) = (invM*W(obs, :)'*(Y(n, obs)' - mu(obs)))';\n end\n exp_xxT = N*sigma2*invM + exp_x'*exp_x;\n s = zeros(d, q);\n s2 = 0;\n for n = 1:N\n obs = find(~isnan(Y(n, :)));\n subY = zeros(size(Y(n, :)))';\n subY(obs) = Y(n, obs)' - mu(obs);\n s = s + (subY)*exp_x(n, :);\n s2 = s2 + sum((Y(n, obs)' - mu(obs)).^2) - 2*exp_x(n, :)*W(obs, :)'*(Y(n, obs)' - mu(obs));\n end\n W = s*inv(exp_xxT);\n sigma2 = 1/(numObs)*(s2 + trace(exp_xxT*W'*W));\n end\n \n X = exp_x;\nend\n", "meta": {"author": "SheffieldML", "repo": "GPmat", "sha": "4b5914a38ecbad9fb7a13a3392970bfc28c9d911", "save_path": "github-repos/MATLAB/SheffieldML-GPmat", "path": "github-repos/MATLAB/SheffieldML-GPmat/GPmat-4b5914a38ecbad9fb7a13a3392970bfc28c9d911/mltools/ppcaEmbed.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218412907381, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.7494001385652752}} {"text": "function a = plu_inverse ( n, pivot )\n\n%*****************************************************************************80\n%\n%% PLU_INVERSE returns the inverse of a PLU matrix.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 25 March 2015\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the order of the matrix.\n%\n% Input, integer PIVOT(N), the list of pivot rows. PIVOT(I)\n% must be a value between I and N, reflecting the choice of\n% pivot row on the I-th step. For no pivoting, set PIVOT(I) = I.\n%\n% Output, real A(N,N), the inverse matrix.\n%\n [ p, l, u ] = plu_plu ( n, pivot );\n\n p_inverse = p';\n\n l_inverse = tri_l1_inverse ( n, l );\n\n u_inverse = tri_u_inverse ( n, u );\n\n a = u_inverse * l_inverse * p_inverse;\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_mat/plu_inverse.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9219218391455085, "lm_q2_score": 0.8128673201042493, "lm_q1q2_score": 0.7494001347317903}} {"text": "function dz = rollingCartPoleDynamics(~,z,P) \n%DZ = ROLLINGCARTPOLEDYNAMICS(T,Z,P)\n% \n%FUNCTION: This function computes the dynamics of a rolling\n% cart-pole, and is designed to be called from ode45.\n% \n%INPUTS: \n% t = time. Dummy input for ode45. Not used.\n% z = [4xn] matrix of states.\n% P = struct of parameters\n%OUTPUTS: \n% dz = [4xn] matrix of state derivatives\n% \n%NOTES:\n% This file was automatically generated by writeRollingCartPoleDynamics\n\nm1 = P.m1; %disk mass\nm2 = P.m2; %bob mass\nI = P.I; %disk moment of inertia\ng = P.g ; %gravity\nl = P.l; %pendulum length\nr = P.r; %disk radius\n\nphi = z(1,:); %link one absolute angle\nth = z(2,:); %link one angular rate\ndphi = z(3,:); %link two absolute angle\ndth = z(4,:); %link two angular rate\n\nf1 = - m2.*r.*sin(th).*(dth.^2.*l + g.*cos(th)) - dth.^2.*l.*m1.*r.*sin(th);\nf2 = -g.*m2.*sin(th);\n\nM11 = - I - m1.*r.^2 - m2.*r.^2.*sin(th).^2;\nM12 = l.*m1.*r.*cos(th);\nM21 = m2.*r.*cos(th);\nM22 = -l.*m2;\n\nD = M11.*M22 - M12.*M21;\n\nddphi = (f2.*M12 - f1.*M22)./D;\nddth = -(f2.*M11 - f1.*M21)./D;\n\ndz = [...\n dphi; %derivative of link one absolute angle\n dth; %derivative of link one angular rate\n ddphi; %derivative of link two absolute angle\n ddth; %derivative of link two angular rate\n];\nend \n", "meta": {"author": "MatthewPeterKelly", "repo": "dscTutorials", "sha": "e1e97a9be03ec146f88bd6ddd9e06db7ee52e242", "save_path": "github-repos/MATLAB/MatthewPeterKelly-dscTutorials", "path": "github-repos/MATLAB/MatthewPeterKelly-dscTutorials/dscTutorials-e1e97a9be03ec146f88bd6ddd9e06db7ee52e242/LagrangeMechanics/rollingCartPole/rollingCartPoleDynamics.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218391455085, "lm_q2_score": 0.8128673201042493, "lm_q1q2_score": 0.7494001347317903}} {"text": "function GA\n% Genetic Algorithm(real coding)\n% By: Javad Ivakpour\n% E-mail: javad7@gmail.com\n% May 2006\n% Goal: find maximum of function that introduced in fun00.m file in current\n% directory and can be plotted in plot00\n% this file is also include the random serach for comparision\ntic\nclc\nfigure(1)\nclf\nclear all\nformat long\n\n%------------------------ parameters ------------------------\n% befor using this function you must specified your function in fun00.m\n% file in current directory and then set the parameters\nvar=2; % Number of variables (this item must be equal to the\n % number of variables that is used in the function in\n % fun00.m file)\nn=100; % Number of population\n\nm0=20; % Number of generations that max value remains constant\n % (use for termination criteria)\nnmutationG=20; %number of mutation children(Gaussian)\nnmutationR=20; %number of mutation children(random)\nnelit=2; %number of elitism children\nvaluemin=ones(1,var)*-5*pi; % min possible value of variables\nvaluemax=ones(1,var)*5*pi; % max possible value of variables\n\n%-------------------------------------------------------------------------\nnmutation=nmutationG+nmutationR;\nsigma=(valuemax-valuemin)/10; %Parameter that related to Gaussian\n % function and used in mutation step\nmax1=zeros(nelit,var);\nparent=zeros(n,var);\ncu=[valuemin(1) valuemax(1) valuemin(2) valuemax(2)];\nfor l=1:var\n p(:,l)=valuemin(l)+rand(n,1).*(valuemax(l)-valuemin(l));\nend\ninitial=p;\nm=m0;\nmaxvalue=ones(m,1)*-1e10;\nmaxvalue(m)=-1e5;\ng=0;\nmeanvalue(m)=0;\n%------------- **** termination criteria ****-------------\nwhile abs(maxvalue(m)-maxvalue(m-(m0-1)))>0.001*maxvalue(m) &...\n (abs(maxvalue(m))>1e-10 & abs(maxvalue(m-(m0-1)))>1e-10)...\n & m<10000 & abs(maxvalue(m)-meanvalue(m))>1e-5 | m<20\n sigma=sigma./(1.05);% reducing the sigma value\n % ------ **** % reducing the number of mutation()random **** ----\n g=g+1;\n if g>10 & nmutationR>0\n g=0;\n nmutationR=nmutationR-1;\n nmutation=nmutationG+nmutationR;\n end\n\n %------------- **** function evaluation ****-------------\n for i=1:n\n y(i)=fun00(p(i,:));\n end\n s=sort(y);\n maxvalue1(1:nelit)=s(n:-1:n-nelit+1);\n if nelit==0\n maxvalue1(1)=s(n);\n for i=1:n\n if y(i)==maxvalue1(1)\n max1(1,:)=p(i,:);\n end\n end\n end\n for k=1:nelit\n for i=1:n\n if y(i)==maxvalue1(k)\n max1(k,:)=p(i,:);\n end\n end\n end\n if var==2\n figure(1)\n subplot(2,2,1)\n hold off\n plot00(cu)\n hold on\n plot3(p(:,1),p(:,2),y,'ro')\n plot3(max1(1,1),max1(1,2),maxvalue1(1),'bh')\n title({' Genetic Algorithm '...\n ,'Performance of GA ( o : each individual)'},'color','b')\n\n end\n y=y-min(y)*1.02;\n sumd=y./sum(y);\n meanvalue=y./(sum(y)/n);\n\n\n %------------- **** Selection: Rolette wheel ****-------------\n for l=1:n\n sel=rand;\n sumds=0;\n j=1;\n while sumdsvaluemax(l)\n p(i,l)=valuemax(l);\n end\n end\n end\n end\n p;\n m=m+1;\n max1;\n maxvalue(m)=maxvalue1(1);\n maxvalue00(m-m0)=maxvalue1(1);\n mean00(m-m0)=sum(s)/n;\n meanvalue(m)=mean00(m-m0);\n figure(1)\n if var==2\n subplot(2,2,2)\n end\n hold off\n plot(maxvalue00,'b')\n hold on\n plot(mean00,'r')\n hold on\n title({'Performance of GA',...\n 'best value GA:blue, best value RS:black, mean value GA:red',''}...\n ,'color','b')\n xlabel('number of generations')\n ylabel('value')\n\n\n %------------- **** Random search ****-------------\n %------------- **** for comparision ****-------------\n p00=zeros(n,var);\n for l=1:var\n p00(:,l)=valuemin(l)+rand(n,1).*(valuemax(l)-valuemin(l));\n end\n for i=1:n\n y(i)=fun00(p00(i,:));\n end\n s=sort(y);\n maxvalueRAND(m-m0)=s(n);\n if m>(m0+1)\n if maxvalueRAND(m-m0) 0\n % split the polygons into a cell array\n polygons = splitPolygons3d(poly);\n nPolys = length(polygons);\n \n % compute area of each polygon\n area = zeros(nPolys, 1);\n for i = 1:nPolys\n area(i) = polygonArea3d(polygons{i});\n end\n \n return;\nend\n\n% put the first vertex at origin (reducing computation errors for polygons\n% far from origin)\nv0 = poly(1, :);\npoly = bsxfun(@minus, poly, v0);\n\n% indices of next vertices\nN = size(poly, 1);\niNext = [2:N 1];\n\n% compute cross-product of each elementary triangle formed by origin and\n% two consecutive vertices\ncp = cross(poly, poly(iNext,:), 2);\n\n% choose one of the triangles as reference for the normal direction\nvn = vectorNorm3d(cp);\n[tmp, ind] = max(vn); %#ok\ncpRef = cp(ind,:);\n\n% compute the sign of the area of each triangle\n% (need to compute the sign explicitely, as the norm of the cross product\n% does not keep orientation within supporting plane)\nsign_i = sign(dot(cp, repmat(cpRef, N, 1), 2));\n\n% compute area of each triangle, using sign correction\narea_i = vectorNorm3d(cp) .* sign_i;\n\n% sum up individual triangles area\narea = sum(area_i) / 2;\n", "meta": {"author": "Arrowstar", "repo": "ksptot", "sha": "2b414440d3b167ba2294f56dafce0f465c07f982", "save_path": "github-repos/MATLAB/Arrowstar-ksptot", "path": "github-repos/MATLAB/Arrowstar-ksptot/ksptot-2b414440d3b167ba2294f56dafce0f465c07f982/helper_methods/z_geom3d/geom3d/polygonArea3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809303, "lm_q2_score": 0.8459424373085145, "lm_q1q2_score": 0.7491932424117173}} {"text": "%TRNORM Normalize an SO(3) or SE(3) matrix\n%\n% TRNORM(R) is guaranteed to be a proper orthogonal matrix rotation\n% matrix (3x3) which is \"close\" to the input matrix R (3x3). If R\n% = [N,O,A] the O and A vectors are made unit length and the normal vector\n% is formed from N = O x A, and then we ensure that O and A are orthogonal\n% by O = A x N.\n%\n% TRNORM(T) as above but the rotational submatrix of the homogeneous\n% transformation T (4x4) is normalised while the translational part is\n% unchanged.\n%\n% If R (3x3xK) or T (4x4xK) representing a sequence then the normalisation\n% is performed on each of the K planes.\n%\n% Notes::\n% - Only the direction of A (the z-axis) is unchanged.\n% - Used to prevent finite word length arithmetic causing transforms to \n% become `unnormalized'.\n% - There is no Toolbox function for SO(2) or SE(2).\n%\n% See also OA2TR, SO3.trnorm, SE3.trnorm.\n\n%## 3d homogeneous \n\n% Copyright (C) 1993-2019 Peter I. Corke\n%\n% This file is part of The Spatial Math Toolbox for MATLAB (SMTB).\n% \n% Permission is hereby granted, free of charge, to any person obtaining a copy\n% of this software and associated documentation files (the \"Software\"), to deal\n% in the Software without restriction, including without limitation the rights\n% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies\n% of the Software, and to permit persons to whom the Software is furnished to do\n% so, subject to the following conditions:\n%\n% The above copyright notice and this permission notice shall be included in all\n% copies or substantial portions of the Software.\n%\n% THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR \n% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\n% FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n% COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\n% IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n% CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n%\n% https://github.com/petercorke/spatial-math\n\nfunction TR = trnorm(T)\n\n assert(ishomog(T) || isrot(T), 'SMTB:trnorm:badarg', 'expecting 3x3xN or 4x4xN hom xform');\n \n if ndims(T) == 3\n % recurse for transform sequence\n n = size(T);\n TR = zeros(n);\n for i=1:n(3)\n TR(:,:,i) = trnorm(T(:,:,i));\n end\n return\n end\n \n o = T(1:3,2); a = T(1:3,3);\n n = cross(o, a); % N = O x A\n o = cross(a, n); % O = A x N\n R = [unit(n) unit(o) unit(a)];\n \n if ishomog(T)\n TR = rt2tr( R, T(1:3,4) );\n elseif isrot(T)\n TR = R;\n end\n\n", "meta": {"author": "petercorke", "repo": "spatialmath-matlab", "sha": "6eeff4a79f14286705560b84f1fe72e0b7e0e7f7", "save_path": "github-repos/MATLAB/petercorke-spatialmath-matlab", "path": "github-repos/MATLAB/petercorke-spatialmath-matlab/spatialmath-matlab-6eeff4a79f14286705560b84f1fe72e0b7e0e7f7/trnorm.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9111797075998823, "lm_q2_score": 0.8221891283434876, "lm_q1q2_score": 0.7491620495558211}} {"text": "% RMSE - Evaluates root mean squared error.\n%\n% E = RMSE(Y)\n% \n% E = RMSE(Y1,Y2)\n\n% Last modified 2010-10-21\n% Copyright (c) Jaakko Luttinen (jaakko.luttinen@tkk.fi)\n\nfunction e = rmse(Y, Yh)\n\nif nargin < 2\n e = sqrt(Y(:)'*Y(:)/numel(Y));\nelse\n z = Y(:)-Yh(:);\n e = sqrt(z'*z/numel(z));\nend\n", "meta": {"author": "jluttine", "repo": "matlab", "sha": "63406c7782b0869948f06e1dbc594460c165d24e", "save_path": "github-repos/MATLAB/jluttine-matlab", "path": "github-repos/MATLAB/jluttine-matlab/matlab-63406c7782b0869948f06e1dbc594460c165d24e/algebra/rmse.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9111797075998823, "lm_q2_score": 0.8221891261650247, "lm_q1q2_score": 0.7491620475708499}} {"text": "function line = fitLine3d(points)\n%FITLINE3D Fit a 3D line to a set of points.\n%\n% LINE = fitLine3d(PTS)\n%\n% Example\n% pts = randn(300, 3);\n% pts = transformPoint3d(pts, createScaling3d([6 4 2]));\n% pts = transformPoint3d(pts, createRotationOx(pi/6));\n% pts = transformPoint3d(pts, createRotationOy(pi/4));\n% pts = transformPoint3d(pts, createRotationOz(pi/3));\n% pts = transformPoint3d(pts, createTranslation3d([5 4 3]));\n% elli = inertiaEllipsoid(pts);\n% figure; drawPoint3d(pts); axis equal;\n% hold on; drawEllipsoid(elli, ...\n% 'drawEllipses', true, 'EllipseColor', 'b', 'EllipseWidth', 3);\n% line = fitLine3d(pts);\n% drawLine3d(line, 'color', 'm', 'LineWidth', 4);\n%\n% See also\n% lines3d, inertiaEllipsoid, fitPlane\n%\n\n% ------\n% Author: David Legland\n% e-mail: david.legland@grignon.inra.fr\n% Created: 2012-11-11, using Matlab 7.9.0.529 (R2009b)\n% Copyright 2012 INRA - Cepia Software Platform.\n\n% number of points\nn = size(points, 1);\n\n% compute centroid\ncenter = mean(points);\n\n% compute the covariance matrix\ncovPts = cov(points)/n;\n\n% perform a principal component analysis with 2 variables, \n% to extract inertia axes\n[U, S] = svd(covPts);\n\n% sort axes from greater to lower\n[dummy, ind] = sort(diag(S), 'descend'); %#ok\n\n% format U to ensure first axis points to positive x direction\nU = U(ind, :);\nif U(1,1) < 0\n U = -U;\n % keep matrix determinant positive\n U(:,3) = -U(:,3);\nend\n\nline = [center U(:,1)'];\n", "meta": {"author": "Arrowstar", "repo": "ksptot", "sha": "2b414440d3b167ba2294f56dafce0f465c07f982", "save_path": "github-repos/MATLAB/Arrowstar-ksptot", "path": "github-repos/MATLAB/Arrowstar-ksptot/ksptot-2b414440d3b167ba2294f56dafce0f465c07f982/helper_methods/z_geom3d/geom3d/fitLine3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9086178919837705, "lm_q2_score": 0.8244619285331332, "lm_q1q2_score": 0.7491208595246495}} {"text": "function qoi_quad ( )\n\n%*****************************************************************************80\n%\n%% QOI_QUAD seeks the expected value of a quantity of interest.\n%\n% Discussion:\n%\n% Our base value for DELTA_BASE is 0.01.\n%\n% Our quantity of interest Q is the time at which the solution achieves\n% the value 0.99.\n%\n% Our parameter U is uniformly distributed in [-1,+1], and determines\n% our actual value of DELTA by\n%\n% DELTA = 2^U * DELTA_BASE.\n%\n% We seek the expected value of Q, which we define as:\n%\n% E(Q) = Integral ( -1 <= U <= +1 ) Q(Y(DELTA(U))) rho(U) dU\n%\n% where \n%\n% rho(U) = 1/2;\n% DELTA(U) = 2^U * DELTA_BASE;\n% Y(DELTA()) is the solution of the combustion ODE for an initial\n% condition of DELTA;\n% Q(Y) is the (first) time T* at which the solution Y(T*) = 0.99.\n%\n% We approximate the integral using a Clenshaw-Curtis quadrature rule.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 18 February 2013\n%\n% Author:\n%\n% John Burkardt\n%\n delta_base = 0.01;\n n_max = 12;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'QOI_QUAD\\n' );\n fprintf ( 1, ' Use quadrature to estimate the expected value of our\\n' );\n fprintf ( 1, ' quantity of interest Q, the time at which the\\n' );\n fprintf ( 1, ' combustion solution reaches 0.99.\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Using Clenshaw-Curtis quadrature of orders 1 through %d\\n', n_max );\n%\n% Set up an option to have ODE45 return when the solution reached 0.99.\n%\n options = odeset ( 'EVENTS', @event_function );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' N Estimated Q\\n' );\n fprintf ( 1, '\\n' );\n\n for n = 1 : n_max\n\n [ x, w ] = clenshaw_curtis_compute ( n );\n\n f = zeros ( n, 1 );\n\n for j = 1 : n\n%\n% Uniformly select \n% U, the logarithm base 2, between -1 and +1, of\n% F, a factor between 1/2 and 2, which multiplies \n% DELTA_BASE, the base value, which gives us\n% DELTA, the initial size of the flame.\n%\n u = x(j);\n factor = 2^u;\n delta = factor * delta_base;\n%\n% Set the starting point.\n%\n t_start = 0.0;\n y_start(1,1) = delta;\n%\n% Get the stopping point.\n%\n t_stop = 250.0;\n%\n% Call ODE45 to solve the problem, stopping immediately if the event \n% (y=0.99) is observed.\n%\n t_span = [ t_start, t_stop ];\n\n [ t, y ] = ode45 ( @flame_fun, t_span, y_start, options );\n%\n% Our function must be weighted by rho(u), which is uniformly 1/2.\n%\n f(j) = 0.5 * t(end);\n\n end\n%\n% Compute the integral estimate.\n%\n q = w' * f;\n\n fprintf ( 1, ' %2d %12g\\n', n, q );\n\n end\n%\n% Terminate.\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'QOI_QUAD\\n' );\n fprintf ( 1, ' Normal end of execution\\n' );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/flame_ode/qoi_quad.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.913676530465412, "lm_q2_score": 0.8198933425148214, "lm_q1q2_score": 0.7491173045406316}} {"text": "%% RATE OF CONVERGENCE OF MIXED FINITE ELEMENT METHOD (RT0-P0) FOR POISSON EQUATION\n%\n% This example is to show the rate of convergence of RT0-P0 mixed finite\n% element approximation of the Poisson equation on the unit square with the\n% following boundary conditions:\n%\n% - pure Dirichlet boundary condition.\n% - Pure Neumann boundary condition.\n% - mxied boundary condition.\n%\n% The basis, data structure and numerical test is summarized in Poisson3RT0femrate.\n%\n% The optimal rates of convergence for u and sigma are observed, namely,\n% 1st order for L2 norm of u, L2 norm of sigma and H(div) norm of sigma. \n% The 2nd order convergent rates between two discrete functions ||uI-uh|| \n% and ||sigmaI-sigmah|| are known as superconvergence.\n%\n% Triangular preconditioned GMRES (default solver) and Uzawa preconditioned\n% CG converges uniformly in all cases. Traingular preconditioner is two\n% times faster than PCG although GMRES is used.\n% See also PoissonBDM1mfemrate, Poissonfemrate, Poissonafemrate\n%\n% Copyright (C) Long Chen. See COPYRIGHT.txt for details.\n\n\n%% Setting\n[node,elem] = cubemesh([0,1,0,1,0,1],0.5);\nmesh = struct('node',node,'elem',elem);\noption.L0 = 1;\noption.maxIt = 3;\noption.printlevel = 1;\noption.elemType = 'RT0';\n% pde = mixedPossiondata;\n\n%% Dirichelt for u and Neumann boundary condition for sigma\noption.solver = 'uzawapcg';\npde = sincosdata3;\nmesh.bdFlag = setboundary3(node,elem,'Dirichlet');\nmfemPoisson3(mesh,pde,option);\n\n%% Neumann for u and Dirichlet boundary condition for sigma.\noption.solver = 'tri';\npde = sincosdata3;\nmesh.bdFlag = setboundary3(node,elem,'Neumann');\nmfemPoisson3(mesh,pde,option);", "meta": {"author": "lyc102", "repo": "ifem", "sha": "29f31c812001ca8d93dad08e67208ca60e8716d4", "save_path": "github-repos/MATLAB/lyc102-ifem", "path": "github-repos/MATLAB/lyc102-ifem/ifem-29f31c812001ca8d93dad08e67208ca60e8716d4/example/fem/mixedPoisson/Poisson3RT0mfemrate.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765234137297, "lm_q2_score": 0.8198933447152498, "lm_q1q2_score": 0.7491173007694841}} {"text": "function [x,N] = makesig(SigName,N)\n% [x,N] = makesig(SigName,N) Creates artificial test signal identical to the\n% standard test signals proposed and used by D. Donoho and I. Johnstone\n% in WaveLab (- a matlab toolbox developed by Donoho et al. the statistics\n% department at Stanford University).\n%\n% Input: SigName - Name of the desired signal (Default 'all')\n% 'AllSig' (Returns a matrix with all the signals)\n% 'HeaviSine'\n% 'Bumps'\n% 'Blocks'\n% 'Doppler'\n% 'Ramp'\n% 'Cusp'\n% 'Sing'\n% 'HiSine'\n% 'LoSine'\n% 'LinChirp'\n% 'TwoChirp'\n% 'QuadChirp'\n% 'MishMash'\n% 'WernerSorrows' (Heisenberg)\n% 'Leopold' (Kronecker)\n% N - Length in samples of the desired signal (Default 512)\n%\n% Output: x - vector/matrix of test signals\n% N - length of signal returned\n%\n% See also: \n%\n% References:\n% WaveLab can be accessed at\n% www_url: http://playfair.stanford.edu/~wavelab/\n% Also see various articles by D.L. Donoho et al. at\n% web_url: http://playfair.stanford.edu/\n%\n%Author: Jan Erik Odegard \n%This m-file is a copy of the code provided with WaveLab\n%customized to be consistent with RWT.\n\nif(nargin < 1)\n SigName = 'AllSig';\n N = 512;\nelseif(nargin == 1)\n N = 512;\nend;\nt = (1:N) ./N;\nx = [];\ny = [];\nif(strcmp(SigName,'HeaviSine') | strcmp(SigName,'AllSig')),\n y = 4.*sin(4*pi.*t);\n y = y - sign(t - .3) - sign(.72 - t);\nend;\nx = [x;y];\ny = [];\nif(strcmp(SigName,'Bumps') | strcmp(SigName,'AllSig')),\n pos = [ .1 .13 .15 .23 .25 .40 .44 .65 .76 .78 .81];\n hgt = [ 4 5 3 4 5 4.2 2.1 4.3 3.1 5.1 4.2];\n wth = [.005 .005 .006 .01 .01 .03 .01 .01 .005 .008 .005];\n y = zeros(size(t));\n for j =1:length(pos)\n y = y + hgt(j)./( 1 + abs((t - pos(j))./wth(j))).^4;\n end \nend;\nx = [x;y];\ny = [];\nif(strcmp(SigName,'Blocks') | strcmp(SigName,'AllSig')),\n pos = [ .1 .13 .15 .23 .25 .40 .44 .65 .76 .78 .81];\n hgt = [4 (-5) 3 (-4) 5 (-4.2) 2.1 4.3 (-3.1) 2.1 (-4.2)];\n y = zeros(size(t));\n for j=1:length(pos)\n y = y + (1 + sign(t-pos(j))).*(hgt(j)/2) ;\n end\nend;\nx = [x;y];\ny = [];\nif(strcmp(SigName,'Doppler') | strcmp(SigName,'AllSig')),\n y = sqrt(t.*(1-t)).*sin((2*pi*1.05) ./(t+.05));\nend;\nx = [x;y];\ny = [];\nif(strcmp(SigName,'Ramp') | strcmp(SigName,'AllSig')),\n y = t - (t >= .37);\nend;\nx = [x;y];\ny = [];\nif(strcmp(SigName,'Cusp') | strcmp(SigName,'AllSig')),\n y = sqrt(abs(t - .37));\nend;\nx = [x;y];\ny = [];\nif(strcmp(SigName,'Sing') | strcmp(SigName,'AllSig')),\n k = floor(N * .37);\n y = 1 ./abs(t - (k+.5)/N);\nend;\nx = [x;y];\ny = [];\nif(strcmp(SigName,'HiSine') | strcmp(SigName,'AllSig')),\n y = sin( pi * (N * .6902) .* t);\nend;\nx = [x;y];\ny = [];\nif(strcmp(SigName,'LoSine') | strcmp(SigName,'AllSig')),\n y = sin( pi * (N * .3333) .* t);\nend;\nx = [x;y];\ny = [];\nif(strcmp(SigName,'LinChirp') | strcmp(SigName,'AllSig')),\n y = sin(pi .* t .* ((N .* .125) .* t));\nend;\nx = [x;y];\ny = [];\nif(strcmp(SigName,'TwoChirp') | strcmp(SigName,'AllSig')),\n y = sin(pi .* t .* (N .* t)) + sin((pi/3) .* t .* (N .* t));\nend;\nx = [x;y];\ny = [];\nif(strcmp(SigName,'QuadChirp') | strcmp(SigName,'AllSig')),\n y = sin( (pi/3) .* t .* (N .* t.^2));\nend;\nx = [x;y];\ny = [];\nif(strcmp(SigName,'MishMash') | strcmp(SigName,'AllSig')), \n % QuadChirp + LinChirp + HiSine\n y = sin( (pi/3) .* t .* (N .* t.^2)) ;\n y = y + sin( pi * (N * .6902) .* t);\n y = y + sin(pi .* t .* (N .* .125 .* t));\nend;\nx = [x;y];\ny = [];\nif(strcmp(SigName,'WernerSorrows') | strcmp(SigName,'AllSig')),\n y = sin( pi .* t .* (N/2 .* t.^2)) ;\n y = y + sin( pi * (N * .6902) .* t);\n y = y + sin(pi .* t .* (N .* t));\n pos = [ .1 .13 .15 .23 .25 .40 .44 .65 .76 .78 .81];\n hgt = [ 4 5 3 4 5 4.2 2.1 4.3 3.1 5.1 4.2];\n wth = [.005 .005 .006 .01 .01 .03 .01 .01 .005 .008 .005];\n for j =1:length(pos)\n y = y + hgt(j)./( 1 + abs((t - pos(j))./wth(j))).^4;\n end \nend;\nx = [x;y];\ny = [];\nif(strcmp(SigName,'Leopold') | strcmp(SigName,'AllSig')),\n y = (t == floor(.37 * N)/N); \t\t% Kronecker\nend;\nx = [x;y];\ny = [];\n\n% disp(sprintf('MakeSignal: I don*t recognize << %s>>',SigName))\n% disp('Allowable SigNames are:')\n% disp('AllSig'),\n% disp('HeaviSine'),\n% disp('Bumps'),\n% disp('Blocks'),\n% disp('Doppler'),\n% disp('Ramp'),\n% disp('Cusp'),\n% disp('Crease'),\n% disp('Sing'),\n% disp('HiSine'),\n% disp('LoSine'),\n% disp('LinChirp'),\n% disp('TwoChirp'),\n% disp('QuadChirp'),\n% disp('MishMash'),\n% disp('WernerSorrows'),\n% disp('Leopold'),\n%end\n", "meta": {"author": "ricedsp", "repo": "D-AMP_Toolbox", "sha": "6e597d98c84755697b65554d59485d50a549c01a", "save_path": "github-repos/MATLAB/ricedsp-D-AMP_Toolbox", "path": "github-repos/MATLAB/ricedsp-D-AMP_Toolbox/D-AMP_Toolbox-6e597d98c84755697b65554d59485d50a549c01a/Packages/rwt/bin/makesig.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418116217418, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.7489974427093401}} {"text": "function [ SimilarityMatrix ] = similarity_neighbor_grid_further( x, side, types, dist)\n%similarity_neighbor_grid_further Summary of this function goes here\n\n % this assumes that the patch is laid out with first column, then second\n % column, ... final column (column major)\n\n% dist = 2;\n SimilarityMatrix = eye(side*side);\n\n % types - 1 - horizontal, 2 - vertical, 3 - diagonal (bl-tr), 4 -\n % diagonal (br - tl)\n for t=1:numel(types)\n\n if(types(t) == 1)\n \n % for horizontal we want to link both neighbours \n % (which are offset from the points by height)\n i = 1:(side*side-side*dist);\n % create the neighboring links for i\n SimilarityMatrix(sub2ind([side^2, side^2], i, i+side*dist)) = 1;\n SimilarityMatrix(sub2ind([side^2, side^2], i+side*dist, i)) = 1; \n \n end \n if(types(t) == 2)\n \n % for vertical we want to link both neighbours except at edge\n % cases which are mod(y_loc,side) = 0 as they are at the edges\n i = 1:side*side;\n i_to_rem =[];\n for s=1:dist\n i_to_rem = union(i_to_rem, i(mod(i+s-1, side) == 0));\n end\n i_both = setdiff(i, i_to_rem);\n % create the neighboring links for i\n SimilarityMatrix(sub2ind([side^2, side^2], i_both+dist, i_both)) = 1;\n SimilarityMatrix(sub2ind([side^2, side^2], i_both, i_both+dist)) = 1;\n \n end \n if(types(t) == 3)\n \n % for diagonal to top right, and bottom left don't use right most column\n i = 1:(side^2)-dist * side;\n i_to_rem = [];\n for s=1:dist\n i_to_rem = union(i_to_rem,i(mod(i-s, side) == 0));\n end\n i_both = setdiff(i, i_to_rem);\n % create the neighboring links for i\n SimilarityMatrix(sub2ind([side^2, side^2], i_both+dist*side-dist, i_both)) = 1;\n SimilarityMatrix(sub2ind([side^2, side^2], i_both, i_both+dist*side-dist)) = 1; \n end\n if(types(t) == 4)\n \n % for diagonal to top left, and bottom right don't use right most column\n i = 1:(side^2)-dist*side;\n i_to_rem = [];\n for s=1:dist\n i_to_rem = union(i_to_rem, i(mod(i+s-1, side) == 0));\n end\n i_both = setdiff(i, i_to_rem);\n % create the neighboring links for i\n SimilarityMatrix(sub2ind([side^2, side^2], i_both+dist*side+dist, i_both)) = 1;\n SimilarityMatrix(sub2ind([side^2, side^2], i_both, i_both+dist*side+ dist)) = 1; \n \n end\n \n end \n assert(isequal(SimilarityMatrix, SimilarityMatrix'));\nend", "meta": {"author": "TadasBaltrusaitis", "repo": "OpenFace", "sha": "3d4b5cf8d96138be42bed229447f36cbb09a5a29", "save_path": "github-repos/MATLAB/TadasBaltrusaitis-OpenFace", "path": "github-repos/MATLAB/TadasBaltrusaitis-OpenFace/OpenFace-3d4b5cf8d96138be42bed229447f36cbb09a5a29/model_training/CCNF/CCNF/lib/similarity_neighbor_grid_further.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898127684335, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.748992467391635}} {"text": "function [node,face,elem]=meshunitsphere(tsize,maxvol)\n%\n% [node,face,elem]=meshunitsphere(tsize,maxvol)\n%\n% create the surface and/or volumetric mesh of a unit sphere \n% centered at [0 0 0] and radius 1\n%\n% author: Qianqian Fang, \n%\n% input: \n% tsize: maximum size of the surface triangles (from 0 to 1)\n% maxvol: maximum volume of the tetrahedron; if one wants to return\n% elem without specifying maxvol, maxvol=tsize^3\n%\n% output:\n% node: node coordinates, 3 columns for x, y and z respectively\n% face: integer array with dimensions of NB x 3, each row represents\n% a surface mesh face element \n% elem: integer array with dimensions of NE x 4, each row represents\n% a tetrahedron. If ignored, this function only produces the surface\n%\n% example:\n% [node,face]=meshunitsphere(0.05);\n% [node,face,elem]=meshunitsphere(0.05,0.01);\n% plotmesh(node,elem,'x>0'); axis equal;\n%\n% -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)\n% \n\ndim=60;\nesize=tsize*dim;\nthresh=dim/2-1;\n[xi,yi,zi]=meshgrid(0:0.5:dim,0:0.5:dim,0:0.5:dim);\ndist=thresh-sqrt((xi-30).^2+(yi-30).^2+(zi-30).^2);\ndist(dist<0)=0;\nclear xi yi zi;\n\n% extract a level-set at v=thresh, being a sphere with R=thresh\n% the maximum element size of the surface triangles is tsize*dim\n\n[node,face]=vol2restrictedtri(dist,1,[dim dim dim],dim*dim*dim,30,esize,esize,40000);\nnode=(node-0.5)*0.5;\n\n[node,face]=removeisolatednode(node,face);\n\nnode=(node-30)/28;\nr0=sqrt(sum((node.*node)'));\nnode=node.*repmat(1./r0(:),1,3);\n\nif(nargout==3)\n if(nargin==1)\n maxvol=tsize*tsize*tsize;\n end\n [node,elem,face]=surf2mesh(node,face,[-1 -1 -1]*1.1,[1 1 1]*1.1,1,maxvol,[],[]);\n elem=elem(:,1:4);\nend\n\nface=face(:,1:3);\n", "meta": {"author": "fangq", "repo": "iso2mesh", "sha": "556f4c321467a3ee042d4c559b4edc11e01dc574", "save_path": "github-repos/MATLAB/fangq-iso2mesh", "path": "github-repos/MATLAB/fangq-iso2mesh/iso2mesh-556f4c321467a3ee042d4c559b4edc11e01dc574/meshunitsphere.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.905989815306765, "lm_q2_score": 0.8267117855317474, "lm_q1q2_score": 0.7489924578858338}} {"text": "function prime_plot ( n_max )\n\n%*****************************************************************************80\n%\n%% PRIME_PLOT makes a box plot of primes.\n%\n% Usage:\n%\n% prime_plot ( n_max )\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 02 June 2012\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N_MAX, the maximum number to be considered.\n%\n timestamp ( );\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'PRIME_PLOT\\n' );\n fprintf ( 1, ' MATLAB version\\n' );\n fprintf ( 1, ' Display primes and composite numbers.\\n' );\n fprintf ( 1, ' If N is composite, Box (N,D) is blue if N is divisible by D.\\n' );\n fprintf ( 1, ' If N is prime, Column (N,:) is red.\\n' );\n%\n% First argument is N_MAX.\n%\n if ( nargin < 1 )\n fprintf ( 1, '\\n' );\n n_max = input ( ' Enter N, the maximum number to check: ' );\n end\n\n clf\n%\n% Every box starts out WHITE.\n%\n for n = 1 : n_max\n\n for d = 1 : n_max\n\n x1 = n - 0.44;\n x2 = n + 0.44;\n y1 = d - 0.44;\n y2 = d + 0.44;\n\n patch ( [ x1, x2, x2, x1 ], [ y1, y1, y2, y2 ], 'w', 'EdgeColor', 'none' );\n\n end\n \n end\n%\n% By convention, 1 is NOT a prime!\n%\n n = 1;\n d = 1;\n\n x1 = n - 0.44;\n x2 = n + 0.44;\n y1 = d - 0.44;\n y2 = d + 0.44;\n patch ( [ x1, x2, x2, x1 ], [ y1, y1, y2, y2 ], 'b', 'EdgeColor', 'none' );\n\n for n = 2 : n_max\n\n prime = 1;\n\n d = 1;\n\n for d = 2 : min ( n_max, n - 1 )\n\n if ( mod ( n, d ) == 0 )\n x1 = n - 0.44;\n x2 = n + 0.44;\n y1 = d - 0.44;\n y2 = d + 0.44;\n patch ( [ x1, x2, x2, x1 ], [ y1, y1, y2, y2 ], 'b', 'EdgeColor', 'none' );\n prime = 0;\n end\n\n end\n\n d = n;\n\n if ( prime )\n x1 = n - 0.44;\n x2 = n + 0.44;\n y1 = 1 - 0.44;\n y2 = d + 0.44;\n patch ( [ x1, x2, x2, x1 ], [ y1, y1, y2, y2 ], 'r', 'EdgeColor', 'none' ); \n else\n x1 = n - 0.44;\n x2 = n + 0.44;\n y1 = d - 0.44;\n y2 = d + 0.44;\n patch ( [ x1, x2, x2, x1 ], [ y1, y1, y2, y2 ], 'b', 'EdgeColor', 'none' ); \n x1 = n - 0.44;\n x2 = n + 0.44;\n y1 = 1 - 0.44;\n y2 = 1 + 0.44;\n patch ( [ x1, x2, x2, x1 ], [ y1, y1, y2, y2 ], 'b', 'EdgeColor', 'none' ); \n end\n\n end\n\n xlabel ( '<---N--->' )\n ylabel ( '<--Divisors-->' )\n title ( 'Primes are red columns; blue squares are factors.' )\n\n axis ( [ 0.5, n + 0.5, 0.5, n + 0.5 ] );\n axis equal\n axis square\n axis tight\n\n filename = 'prime_plot.png';\n print ( '-dpng', filename );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Plot saved in file \"%s\".\\n', filename );\n%\n% Terminate.\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'PRIME_PLOT\\n' );\n fprintf ( 1, ' Normal end of execution.\\n' );\n fprintf ( 1, '\\n' );\n timestamp ( );\n\n return\nend\nfunction timestamp ( )\n\n%*****************************************************************************80\n%\n%% TIMESTAMP prints the current YMDHMS date as a timestamp.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 14 February 2003\n%\n% Author:\n%\n% John Burkardt\n%\n t = now;\n c = datevec ( t );\n s = datestr ( c, 0 );\n fprintf ( 1, '%s\\n', s );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/prime_plot/prime_plot.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528019683106, "lm_q2_score": 0.8791467627598857, "lm_q1q2_score": 0.7489915478746542}} {"text": "function [f,str] = constructpolynomialmatrix2d(matrixsize,locs,degree)\n\n% function [f,str] = constructpolynomialmatrix2d(matrixsize,locs,degree)\n%\n% is a 2D matrix size like [100 50]\n% is a row or column vector of indices into that matrix size\n% is the maximum polynomial degree desired.\n% should be no greater than 10.\n% \n% return , a matrix of dimensions length() x N\n% with polynomial basis functions evaluated at in\n% the columns. the polynomial basis functions are evaluated\n% over the range [-1,1] which is presumed to correspond to\n% the beginning and ending element along each of the two dimensions.\n% (if a dimension has only one element, the values are all set to 1.)\n% also, return , the algebraic expression that corresponds to\n% the columns of . 'x' refers to the first matrix dimension; 'y'\n% refers to the second matrix dimension.\n%\n% note that there may be various gain factors on the basis functions\n% (e.g. don't assume that they are all unit-length).\n%\n% also, beware of numerical precision issues for high degrees...\n%\n% see also constructpolynomialmatrix3d.m.\n%\n% history:\n% - 2013/05/23 - hard code the basis expansion to ensure consistent results across platforms.\n% this changes previous behavior.\n%\n% example:\n% [f,str] = constructpolynomialmatrix2d([30 30],find(ones(30,30)),2);\n% str\n% f = reshape(f,30,30,[]);\n% figure; imagesc(makeimagestack(f));\n\n% prep\nx = sym('x');\ny = sym('y');\n\n% do the algebra\n%str = char(expand((x+y+1)^degree));\nswitch degree\ncase 0\n str = '1';\ncase 1\n str = 'x+y+1';\ncase 2\n str = 'x^2+2*x*y+2*x+y^2+2*y+1';\ncase 3\n str = 'x^3+3*x^2*y+3*x^2+3*x*y^2+6*x*y+3*x+y^3+3*y^2+3*y+1';\ncase 4\n str = '1+4*x+4*y+6*x^2+12*x*y+6*y^2+4*x^3*y+6*x^2*y^2+12*x^2*y+4*x*y^3+12*x*y^2+x^4+4*x^3+y^4+4*y^3';\ncase 5\n str = '1+5*x+5*y+10*x^2+20*x*y+10*y^2+20*x^3*y+30*x^2*y^2+30*x^2*y+20*x*y^3+30*x*y^2+5*x^4+10*x^3+5*y^4+10*y^3+y^5+5*x*y^4+10*x^2*y^3+10*x^3*y^2+5*x^4*y+x^5';\ncase 6\n str = '1+6*x+6*y+15*x^2+30*x*y+15*y^2+60*x^3*y+90*x^2*y^2+60*x^2*y+60*x*y^3+60*x*y^2+15*x^4+20*x^3+15*y^4+20*y^3+6*x*y^5+y^6+6*y^5+30*x*y^4+15*x^2*y^4+60*x^2*y^3+60*x^3*y^2+20*x^3*y^3+15*x^4*y^2+30*x^4*y+6*x^5+x^6+6*x^5*y';\ncase 7\n str = '1+7*x+7*y+21*x^2+42*x*y+21*y^2+140*x^3*y+210*x^2*y^2+105*x^2*y+140*x*y^3+105*x*y^2+35*x^4+35*x^3+35*y^4+35*y^3+7*x*y^6+42*x*y^5+7*y^6+21*y^5+y^7+105*x*y^4+105*x^2*y^4+210*x^2*y^3+21*x^2*y^5+210*x^3*y^2+35*x^3*y^4+140*x^3*y^3+105*x^4*y^2+105*x^4*y+21*x^5+7*x^6+x^7+35*x^4*y^3+42*x^5*y+21*x^5*y^2+7*x^6*y';\ncase 8\n str = '1+8*x+8*y+28*x^2+56*x*y+28*y^2+280*x^3*y+420*x^2*y^2+168*x^2*y+280*x*y^3+168*x*y^2+70*x^4+56*x^3+70*y^4+56*y^3+56*x*y^6+168*x*y^5+8*x*y^7+28*y^6+56*y^5+8*y^7+y^8+280*x*y^4+28*x^2*y^6+420*x^2*y^4+560*x^2*y^3+168*x^2*y^5+560*x^3*y^2+280*x^3*y^4+560*x^3*y^3+56*x^3*y^5+420*x^4*y^2+280*x^4*y+56*x^5+28*x^6+8*x^7+x^8+70*x^4*y^4+280*x^4*y^3+168*x^5*y+168*x^5*y^2+56*x^5*y^3+56*x^6*y+28*x^6*y^2+8*x^7*y';\ncase 9\n str = '1+9*x+9*y+36*x^2+72*x*y+36*y^2+504*x^3*y+756*x^2*y^2+252*x^2*y+504*x*y^3+252*x*y^2+126*x^4+84*x^3+126*y^4+84*y^3+252*x*y^6+504*x*y^5+72*x*y^7+84*y^6+126*y^5+36*y^7+9*y^8+630*x*y^4+252*x^2*y^6+1260*x^2*y^4+1260*x^2*y^3+756*x^2*y^5+1260*x^3*y^2+1260*x^3*y^4+1680*x^3*y^3+504*x^3*y^5+1260*x^4*y^2+630*x^4*y+126*x^5+84*x^6+36*x^7+9*x^8+630*x^4*y^4+1260*x^4*y^3+504*x^5*y+756*x^5*y^2+504*x^5*y^3+252*x^6*y+252*x^6*y^2+72*x^7*y+x^9+y^9+9*x^8*y+36*x^7*y^2+84*x^6*y^3+126*x^5*y^4+126*x^4*y^5+84*x^3*y^6+36*x^2*y^7+9*x*y^8';\ncase 10\n str = '1+10*x+10*y+45*x^2+90*x*y+45*y^2+840*x^3*y+1260*x^2*y^2+360*x^2*y+840*x*y^3+360*x*y^2+210*x^4+120*x^3+210*y^4+120*y^3+840*x*y^6+1260*x*y^5+360*x*y^7+210*y^6+252*y^5+120*y^7+45*y^8+1260*x*y^4+1260*x^2*y^6+3150*x^2*y^4+2520*x^2*y^3+2520*x^2*y^5+2520*x^3*y^2+4200*x^3*y^4+4200*x^3*y^3+2520*x^3*y^5+3150*x^4*y^2+1260*x^4*y+252*x^5+210*x^6+120*x^7+45*x^8+3150*x^4*y^4+4200*x^4*y^3+1260*x^5*y+2520*x^5*y^2+2520*x^5*y^3+840*x^6*y+1260*x^6*y^2+360*x^7*y+10*x^9+10*y^9+x^10+90*x^8*y+360*x^7*y^2+840*x^6*y^3+1260*x^5*y^4+1260*x^4*y^5+840*x^3*y^6+360*x^2*y^7+90*x*y^8+10*x^9*y+45*x^8*y^2+y^10+120*x^7*y^3+210*x^6*y^4+252*x^5*y^5+210*x^4*y^6+120*x^3*y^7+45*x^2*y^8+10*x*y^9';\notherwise\n die;\nend\n\n%REMOVE since hard-coded now\n%str = sort(strsplit(str,'+'));%% sort the stuff in between + signs to try to ensure consistent ordering!!!\nstr = strsplit(str,'+');\nstr = cat(1,str,repmat({'+'},[1 length(str)]));\nstr = cat(2,str{:});\nstr = str(1:end-1);\n\n% add a little padding so the 1 step below will work for degree 0\nstr = [' ' str ' '];\n\n% change * to .*\n old = pwd; % THIS IS A TOTAL HACK TO AVOID FUNCTION NAME CONFLICTS!\n cd(fullfile(matlabroot,'toolbox','matlab','funfun'));\nstr = vectorize(str);\n cd(old);\n\n% remove +\nstr(str=='+') = ' ';\n\n% change 1 to ones(size(x),1)\nstr0 = strrep(str,' 1 ',' ones(size(x)) '); assert(length(str0) ~= length(str));\nstr = str0;\n\n% add brackets\nstr = [ '[' str ']' ];\n\n% prep the linear coordinates\n[x,y] = ind2sub(matrixsize,locs(:));\nif matrixsize(1)~=1\n x = normalizerange(x,-1,1,1,matrixsize(1));\nend\nif matrixsize(2)~=1\n y = normalizerange(y,-1,1,1,matrixsize(2));\nend\n\n% do it\nf = eval(str);\n", "meta": {"author": "qMRLab", "repo": "qMRLab", "sha": "036ff20b47e939877f746940a969494b55911636", "save_path": "github-repos/MATLAB/qMRLab-qMRLab", "path": "github-repos/MATLAB/qMRLab-qMRLab/qMRLab-036ff20b47e939877f746940a969494b55911636/External/knkutils/constructpolynomialmatrix2d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096181702032, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.7489878473195007}} {"text": "% Showing the effect of the POCS partial Fourier reconstruction.\n%\n% Mark a cell (code beginning with \"%%\") and\n% press + to evaluate the cell content only.\n\n\n%% simple example (2D, single coil, no phase errors)\n%\nN = 256;\niter = 30;\npf = 9/16; % a typical large partial fourier factor\np = single(phantom(N));\nkspRef = fftshift(fftshift( fft(fft( fftshift(fftshift( p, 1),2), [],1),[],2), 1),2);\nkspRef = kspRef + 3 * complex( randn(N), randn(N) ); % add noise\nkspPF = kspRef;\nkspPF(:,1:floor((1-pf)*N)) = 0;\n\nimReco = pocs( kspPF, iter, true );\n\nimRef = ifftshift(ifftshift( ifft(ifft( ifftshift(ifftshift( kspRef, 1),2), [],1),[],2), 1),2);\nimDirect = ifftshift(ifftshift( ifft(ifft( ifftshift(ifftshift( kspPF, 1),2), [],1),[],2), 1),2);\n\nfigure,\nimagesc(abs([imRef imReco imDirect]), [0 2*mean(abs(imRef(:)))])\naxis image\ntitle('reference (full dataset) | POCS reco | zero-padded reco')\ncolormap(gray(256))\n\n\n%% multicoil example with phase error\n%\nclear p kspRef kspPF imReco imRef imDirect\nN = 256;\niter = 30;\npf = 9/16;\n% Set up some pseudo coilmaps:\ncmap(1,:,:) = repmat( ( 3./(1:N) .^0.10) .* exp(1i*(1:N) *pi/(N/3)) , N, 1 );\ncmap(2,:,:) = repmat( ( 1./(1:N).'.^0.20) .* exp(1i*(1:N).'*pi/(N/4)) , 1, N );\ncmap(3,:,:) = repmat( fliplr(( 2./(1:N) .^0.04) .* exp(1i*(1:N) *pi/(N/8))), N, 1 );\ncmap(4,:,:) = repmat( flipud(( 2./(1:N).'.^0.15) .* exp(1i*(1:N).'*pi/(N/10))),1, N );\ncmap = single(cmap);\n\nNc = size(cmap,1);\np = reshape( single(phantom(N)), 1, N, N );\nsubs = { 1, 164:181, 187:193 };\np(subs{:}) = 0;\nsubs = { 1, 166:179, 189:191 };\np(subs{:}) = 1 * exp(1i * pi/2);\np = bsxfun( @times, cmap, p );\nkspRef = fftshift(fftshift( fft(fft( fftshift(fftshift( p, 2),3), [],2),[],3), 2),3);\nkspRef = kspRef + 10 * complex( randn(Nc,N,N), randn(Nc,N,N) ); % add noise\nkspPF = kspRef;\nkspPF(:,:,1:floor((1-pf)*N)) = 0;\n\nimReco = pocs( kspPF, iter, true );\n\nimReco = squeeze(sqrt(sum( abs(imReco).^2, 1)));\nimRef = ifftshift(ifftshift( ifft(ifft( ifftshift(ifftshift( kspRef, 2),3), [],2),[],3), 2),3);\nimRef = squeeze(sqrt(sum( abs(imRef).^2, 1)));\nimDirect = ifftshift(ifftshift( ifft(ifft( ifftshift(ifftshift( kspPF, 2),3), [],2),[],3), 2),3);\nimDirect = squeeze(sqrt(sum( abs(imDirect).^2, 1)));\n\nfigure,\nimagesc(abs([imRef imReco imDirect]),[0 2*mean(abs(imRef(:)))])\naxis image\ntitle('reference (full dataset) | POCS reco | zero-padded reco')\ncolormap(gray(256))\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/39350-mri-partial-fourier-reconstruction-with-pocs/pocs_example.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.91610961358942, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.748987839502344}} {"text": "function D = generate_2d_3x3_sparse_operator(mat, sz)\n% D = generate_first_difference_matrix_for_image(sz, {dif_order, spacing})\n% sz -- image size 2x1 or 3x1\n% dif_order -- 1 or 2. 1st or 2nd derivative\n% spacing -- size of pixel in physical units. 2x1 or 3x1\n%\n% Creates derivative matrix, if IMG is rect. image or volume, then\n% G = D * IMG(:); \n% G is [prod(size(IMG))*ndims]x[1] vector, containing drivatives in \n% 1, 2, {3} directions.\n%\n P = prod(sz);\n s1 = sz(1);\n s2 = sz(2);\n\n [m1, m2] = ndgrid([1 : s1-1, 1], 1 : s2);\n tp = m1(:) + (m2(:) - 1) * s1;\n tm = (m1(:)+1) + (m2(:) - 1) * s1;\n K = numel(tp);\n A1 = (sparse(1:K, tm, 1, K, P) - sparse(1:K, tp, 1, K, P)) / spacing(1);\n\n [m1, m2] = ndgrid(1 : s1, [1 : s2-1, 1]);\n tp = m1(:) + (m2(:) - 1) * s1;\n tm = m1(:) + (m2(:)) * s1;\n K = numel(tp);\n A2 = (sparse(1:K, tm, 1, K, P) - sparse(1:K, tp, 1, K, P)) / spacing(2);\n A = [A1; A2];\nend\n\n", "meta": {"author": "visva89", "repo": "pTVreg", "sha": "c359620e3c8435392db02354274d6c74d682d437", "save_path": "github-repos/MATLAB/visva89-pTVreg", "path": "github-repos/MATLAB/visva89-pTVreg/pTVreg-c359620e3c8435392db02354274d6c74d682d437/mutils/My/image_utils/generate_2d_3x3_sparse_operator.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.935346511643776, "lm_q2_score": 0.8006920092299293, "lm_q1q2_score": 0.7489244777342605}} {"text": "function [Y, s] = standardize(X)\n% Unitize the vectors to be unit length\n% By default dim = 1 (columns).\n% Written by Mo Chen (sth4nth@gmail.com).\nX = bsxfun(@minux,X,mean(X,2));\ns = sqrt(mean(sum(X.^2,1)));\nY = X/s;", "meta": {"author": "PRML", "repo": "PRMLT", "sha": "baac49f643db6b39e75307d3b21307b32b29a7a9", "save_path": "github-repos/MATLAB/PRML-PRMLT", "path": "github-repos/MATLAB/PRML-PRMLT/PRMLT-baac49f643db6b39e75307d3b21307b32b29a7a9/common/standardize.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465188527686, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.7489244746094584}} {"text": "function [STATS]=scatter_stats(D)\n\n%Fitting Gaussian mixture (1) model\nGM=gmdistribution.fit(D,1); \nMU=GM.mu; %Means\nMU_total=rms(MU); %Total mean\nVAR=GM.Sigma; %Variance\nSTD=sqrt(VAR); %Standard deviations\n[VAR_vec,VAR_eig] = eig(VAR); %Get principal components\nSTD_total=sqrt(trace(VAR_eig)./3); %Standard deviations\n\n%Creating output structure\nSTATS.GM=GM;\nSTATS.MU=MU;\nSTATS.MU_total=MU_total;\nSTATS.VAR=VAR;\nSTATS.STD=STD;\nSTATS.STD_total=STD_total;\n\nend\n \n%% \n% _*GIBBON footer text*_ \n% \n% License: \n% \n% GIBBON: The Geometry and Image-based Bioengineering add-On. A toolbox for\n% image segmentation, image-based modeling, meshing, and finite element\n% analysis.\n% \n% Copyright (C) 2006-2022 Kevin Mattheus Moerman and the GIBBON contributors\n% \n% This program is free software: you can redistribute it and/or modify\n% it under the terms of the GNU General Public License as published by\n% the Free Software Foundation, either version 3 of the License, or\n% (at your option) any later version.\n% \n% This program is distributed in the hope that it will be useful,\n% but WITHOUT ANY WARRANTY; without even the implied warranty of\n% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n% GNU General Public License for more details.\n% \n% You should have received a copy of the GNU General Public License\n% along with this program. If not, see .\n", "meta": {"author": "gibbonCode", "repo": "GIBBON", "sha": "8178520664a6148db939eaea87e75b3cba4f2b4f", "save_path": "github-repos/MATLAB/gibbonCode-GIBBON", "path": "github-repos/MATLAB/gibbonCode-GIBBON/GIBBON-8178520664a6148db939eaea87e75b3cba4f2b4f/lib/scatter_stats.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465080392795, "lm_q2_score": 0.8006920044739461, "lm_q1q2_score": 0.7489244703996767}} {"text": "function [ t, dtdr, dtds ] = shape_t10 ( r, s )\n\n%*****************************************************************************80\n%\n%% SHAPE_T10 evaluates shape functions for a 10 node reference triangle.\n%\n% Reference Element T10:\n%\n% |\n% 1 10\n% | |\\\n% | | \\\n% | 8 9\n% | | \\\n% S | \\\n% | 5 6 7\n% | | \\\n% | | \\\n% 0 1--2--3--4\n% |\n% +--0----R---1-->\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 14 April 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real R, S, the reference coordinates of a point.\n%\n% Output, real T(10), the basis functions at the point.\n%\n% Output, real DTDR(10), the R basis derivatives at the point.\n%\n% Output, real DTDS(10), the S basis derivatives at the point.\n%\n a = 1.0 / 3.0;\n b = 2.0 / 3.0;\n c = 1.0;\n\n t(1) = 4.5 * ( a - r - s ) * ( b - r - s ) * ( c - r - s );\n t(2) = 13.5 * r * ( b - r - s ) * ( c - r - s );\n t(3) = - 13.5 * r * ( a - r ) * ( c - r - s );\n t(4) = 4.5 * r * ( a - r ) * ( b - r );\n t(5) = 13.5 * s * ( b - r - s ) * ( c - r - s );\n t(6) = 27.0 * r * s * ( c - r - s );\n t(7) = 13.5 * r * s * ( r - a );\n t(8) = 13.5 * s * ( s - a ) * ( c - r - s );\n t(9) = 13.5 * r * s * ( s - a );\n t(10) = 4.5 * s * ( a - s ) * ( b - s );\n\n dtdr(1) = 4.5 * ( ( a - s ) * ( 2.0 * r - c - b + 2.0 * s ) ...\n - ( s - b ) * ( s - c ) - 2.0 * ( 2.0 * s - b - c ) * r - 3.0 * r * r );\n dtdr(2) = 13.5 * ( ( s - b ) * ( s - c ) + 2.0 * ( 2.0 * s - b - c ) * r ...\n + 3.0 * r * r );\n dtdr(3) = - 13.5 * ( a * ( c - s ) + 2.0 * ( s - a - c ) * r + 3.0 * r * r );\n dtdr(4) = 4.5 * ( a * b - 2.0 * ( a + b ) * r + 3.0 * r * r );\n dtdr(5) = 13.5 * s * ( 2.0 * s - b - c + 2.0 * r );\n dtdr(6) = 27.0 * s * ( c - s - 2.0 * r );\n dtdr(7) = 13.5 * s * ( 2.0 * r - a );\n dtdr(8) = - 13.5 * s * ( s - a );\n dtdr(9) = 13.5 * s * ( s - a);\n dtdr(10) = 0.0;\n\n dtds(1) = 4.5 * ( ( a - r ) * ( 2.0 * s - c - b + 2.0 * r ) ...\n - ( r - b ) * ( r - c ) - 2.0 * ( 2.0 * r - b - c ) * s - 3.0 * s * s );\n dtds(2) = 13.5 * r * ( 2.0 * s + 2.0 * r - b - c );\n dtds(3) = 13.5 * r * ( a - r );\n dtds(4) = 0.0;\n dtds(5) = 13.5 * ( ( r - b ) * ( r - c ) + 2.0 * ( 2.0 * r - b - c ) * s ...\n + 3.0 * s * s );\n dtds(6) = 27.0 * r * ( c - r - 2.0 * s );\n dtds(7) = 13.5 * r * ( r - a );\n dtds(8) = - 13.5 * ( a * ( c - r ) + 2.0 * ( r - c - a ) * s + 3.0 * s * s );\n dtds(9) = 13.5 * r * ( 2.0 * s - a );\n dtds(10) = 4.5 * ( a * b - 2.0 * ( a + b ) * s + 3.0 * s * s );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/fem2d_pack/shape_t10.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533051062237, "lm_q2_score": 0.8031738010682209, "lm_q1q2_score": 0.7489220653807912}} {"text": "function kpn_test ( )\n\n%*****************************************************************************80\n%\n%% KPN_TEST uses the KPN function for 1D quadrature over (-oo,+oo).\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 10 May 2012\n%\n% Author:\n%\n% John Burkardt\n%\n d = 1;\n exact = hermite_integral ( d );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'KPN_TEST:\\n' );\n fprintf ( 1, ' Kronrod-Patterson-Hermite quadrature over (-oo,+oo):\\n' );\n fprintf ( 1, ' Exact integral is %g\\n', exact );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Level Nodes Estimate Error\\n' );\n fprintf ( 1, '\\n' );\n\n for l = 1 : 5\n\n n = kpn_order ( l );\n\n nh = floor ( ( n + 1 ) / 2 );\n\n [ xh, wh ] = kpn ( l );\n\n if ( mod ( n, 2 ) == 1 )\n x = [ -xh(nh:-1:2); xh ];\n w = [ wh(nh:-1:2); wh ];\n else\n x = [ -xh(nh:-1:1); xh ];\n w = [ wh(nh:-1:1); wh ];\n end\n\n fx = hermite_integrand ( d, n, x );\n q = w' * fx;\n e = sqrt ( ( q - exact ).^2 ) / exact;\n\n fprintf( ' %2d %6d %10.5g %10.5g\\n', l, n, q, e )\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/sparse_grid_hw/kpn_test.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110569397307, "lm_q2_score": 0.839733963661418, "lm_q1q2_score": 0.7488840336810786}} {"text": "function [ rexp, sexp ] = poly_q4 ( )\n\n%*****************************************************************************80\n%\n%% POLY_Q4 returns the monomials associated with a 4 node quadrilateral.\n%\n% Reference Element Q4:\n%\n% |\n% 1 4-----3\n% | | |\n% | | |\n% S | |\n% | | |\n% | | |\n% 0 1-----2\n% |\n% +--0--R--1-->\n%\n% Formula:\n%\n% Given coefficients A(I), the polynomial interpolant at (R,S) is\n%\n% P(R,S) = sum ( 1 <= I <= N ) A(I) * R**REXP(I) * S**SEXP(I)\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 14 February 2003\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Output, integer REXP(4), SEXP(4), the powers of R and S associated\n% with each polynomial.\n%\n rexp(1:4) = [ 0, 0, 1, 1 ];\n sexp(1:4) = [ 0, 1, 0, 1 ];\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/fem2d_pack/poly_q4.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110569397306, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.748884031892631}} {"text": "%\n% [idx,netsim,dpsim,expref]=apclusterSparse(s,p)\n%\n% APCLUSTER uses affinity propagation (Frey and Dueck, Science,\n% 2007) to identify data clusters, using a set of real-valued\n% pair-wise data point similarities as input. Each cluster is\n% represented by a data point called a cluster center, and the\n% method searches for clusters so as to maximize a fitness\n% function called net similarity. The method is iterative and\n% stops after maxits iterations (default of 500 - see below for\n% how to change this value) or when the cluster centers stay\n% constant for convits iterations (default of 50). The command\n% apcluster(s,p,'plot') can be used to plot the net similarity\n% during operation of the algorithm.\n%\n% For N data points, there may be as many as N^2-N pair-wise\n% similarities (note that the similarity of data point i to k\n% need not be equal to the similarity of data point k to i).\n% These may be passed to APCLUSTER in an NxN matrix s, where\n% s(i,k) is the similarity of point i to point k. In fact, only\n% a smaller number of relevant similarities are needed for\n% APCLUSTER to work. If only M similarity values are known,\n% where M < N^2-N, they can be passed to APCLUSTER in an Mx3\n% matrix s, where each row of s contains a pair of data point\n% indices and a corresponding similarity value: s(j,3) is the\n% similarity of data point s(j,1) to data point s(j,2).\n%\n% APCLUSTER automatically determines the number of clusters,\n% based on the input p, which is an Nx1 matrix of real numbers\n% called preferences. p(i) indicates the preference that data\n% point i be chosen as a cluster center. A good choice is to \n% set all preference values to the median of the similarity\n% values. The number of identified clusters can be increased or\n% decreased by changing this value accordingly. If p is a\n% scalar, APCLUSTER assumes all preferences are equal to p.\n%\n% The fitness function (net similarity) used to search for\n% solutions equals the sum of the preferences of the the data\n% centers plus the sum of the similarities of the other data\n% points to their data centers.\n%\n% The identified cluster centers and the assignments of other\n% data points to these centers are returned in idx. idx(j) is\n% the index of the data point that is the cluster center for\n% data point j. If idx(j) equals j, then point j is itself a\n% cluster center. The sum of the similarities of the data\n% points to their cluster centers is returned in dpsim, the\n% sum of the preferences of the identified cluster centers is\n% returned in expref and the net similarity (sum of the data\n% point similarities and preferences) is returned in netsim.\n%\n% EXAMPLE\n%\n% N=100; x=rand(N,2); % Create N, 2-D data points\n% M=N*N-N; s=zeros(M,3); % Make ALL N^2-N similarities\n% j=1;\n% for i=1:N\n% for k=[1:i-1,i+1:N]\n% s(j,1)=i; s(j,2)=k; s(j,3)=-sum((x(i,:)-x(k,:)).^2);\n% j=j+1;\n% end;\n% end;\n% p=median(s(:,3)); % Set preference to median similarity\n% [idx,netsim,dpsim,expref]=apclusterSparse(s,p,'plot');\n% fprintf('Number of clusters: %d\\n',length(unique(idx)));\n% fprintf('Fitness (net similarity): %f\\n',netsim);\n% figure; % Make a figures showing the data and the clusters\n% for i=unique(idx)'\n% ii=find(idx==i); h=plot(x(ii,1),x(ii,2),'o'); hold on;\n% col=rand(1,3); set(h,'Color',col,'MarkerFaceColor',col);\n% xi1=x(i,1)*ones(size(ii)); xi2=x(i,2)*ones(size(ii)); \n% line([x(ii,1),xi1]',[x(ii,2),xi2]','Color',col);\n% end;\n% axis equal tight;\n%\n% PARAMETERS\n% \n% [idx,netsim,dpsim,expref]=apclusterSparse(s,p,'NAME',VALUE,...)\n% \n% The following parameters can be set by providing name-value\n% pairs, eg, apcluster(s,p,'maxits',1000):\n%\n% Parameter Value\n% 'maxits' Any positive integer. This specifies the\n% maximum number of iterations performed by\n% affinity propagation. Default: 1000.\n% 'convits' Any positive integer. APCLUSTER decides that\n% the algorithm has converged if the estimated\n% cluster centers stay fixed for convits\n% iterations. Increase this value to apply a\n% more stringent convergence test. Default: 100.\n% 'dampfact' A real number that is less than 1 and\n% greater than or equal to 0.5. This sets the\n% damping level of the message-passing method,\n% where values close to 1 correspond to heavy\n% damping which may be needed if oscillations\n% occur. Default: .9\n% 'plot' No value needed. This creates a figure that\n% plots the net similarity after each iteration\n% of the method. If the net similarity fails to\n% converge, consider increasing the values of\n% dampfact and maxits.\n% 'details' No value needed. This causes idx, netsim,\n% dpsim and expref to be stored after each\n% iteration.\n% 'nonoise' No value needed. Degenerate input similarities\n% (eg, where the similarity of i to k equals the\n% similarity of k to i) can prevent convergence.\n% To avoid this, APCLUSTER adds a small amount\n% of noise to the input similarities. This flag\n% turns off the addition of noise.\n%\n% Copyright (c) Brendan J. Frey and Delbert Dueck (2006). This\n% software may be freely used and distributed for\n% non-commercial purposes.\n\nfunction [idx,netsim,dpsim,expref]=apclusterSparse(s,p,varargin);\n\n% Handle arguments to function\nif nargin<2 error('Too few input arguments');\nelse\n maxits=1000; convits=100; lam=0.9; plt=0; details=0; nonoise=0;\n i=1;\n while i<=length(varargin)\n if strcmp(varargin{i},'plot')\n plt=1; i=i+1;\n elseif strcmp(varargin{i},'details')\n details=1; i=i+1;\n elseif strcmp(varargin{i},'nonoise')\n nonoise=1; i=i+1;\n elseif strcmp(varargin{i},'maxits')\n maxits=varargin{i+1};\n i=i+2;\n if maxits<=0 error('maxits must be a positive integer'); end;\n elseif strcmp(varargin{i},'convits')\n convits=varargin{i+1};\n i=i+2;\n if convits<=0 error('convits must be a positive integer'); end;\n elseif strcmp(varargin{i},'dampfact')\n lam=varargin{i+1};\n i=i+2;\n if (lam<0.5)||(lam>=1)\n error('dampfact must be >= 0.5 and < 1');\n end;\n else i=i+1;\n end;\n end;\nend;\nif lam>0.9\n fprintf('\\n*** Warning: Large damping factor in use. Turn on plotting\\n');\n fprintf(' to monitor the net similarity. The algorithm will\\n');\n fprintf(' change decisions slowly, so consider using a larger value\\n');\n fprintf(' of convits.\\n\\n');\nend;\n\n% Check that standard arguments are consistent in size\nif length(size(s))~=2 error('s should be a 2D matrix');\nelseif length(size(p))>2 error('p should be a vector or a scalar');\nelseif size(s,2)==3\n tmp=max(max(s(:,1)),max(s(:,2)));\n if length(p)==1 N=tmp; else N=length(p); end;\n if tmp>N\n error('data point index exceeds number of data points');\n elseif min(min(s(:,1)),min(s(:,2)))<=0\n error('data point indices must be >= 1');\n end;\nelseif size(s,1)==size(s,2)\n N=size(s,1);\n if (length(p)~=N)&&(length(p)~=1)\n error('p should be scalar or a vector of size N');\n end;\nelse error('s must have 3 columns or be square'); end;\n\n% Make vector of preferences\nif length(p)==1 p=p*ones(N,1); end;\n\n% Append self-similarities (preferences) to s-matrix\ntmps=[repmat([1:N]',[1,2]),p]; s=[s;tmps];\nM=size(s,1);\n\n% In case user did not remove degeneracies from the input similarities,\n% avoid degenerate solutions by adding a small amount of noise to the\n% input similarities\nif ~nonoise\n rns=randn('state'); randn('state',0);\n s(:,3)=s(:,3)+(eps*s(:,3)+realmin*100).*rand(M,1);\n randn('state',rns);\nend;\n\n% Construct indices of neighbors\nind1e=zeros(N,1);\nfor j=1:M k=s(j,1); ind1e(k)=ind1e(k)+1; end;\nind1e=cumsum(ind1e); ind1s=[1;ind1e(1:end-1)+1]; ind1=zeros(M,1); \nfor j=1:M k=s(j,1); ind1(ind1s(k))=j; ind1s(k)=ind1s(k)+1; end;\nind1s=[1;ind1e(1:end-1)+1];\nind2e=zeros(N,1);\nfor j=1:M k=s(j,2); ind2e(k)=ind2e(k)+1; end;\nind2e=cumsum(ind2e); ind2s=[1;ind2e(1:end-1)+1]; ind2=zeros(M,1); \nfor j=1:M k=s(j,2); ind2(ind2s(k))=j; ind2s(k)=ind2s(k)+1; end;\nind2s=[1;ind2e(1:end-1)+1];\n\n% Allocate space for messages, etc\nA=zeros(M,1); R=zeros(M,1); t=1;\nif plt netsim=zeros(1,maxits+1); end;\nif details\n idx=zeros(N,maxits+1);\n netsim=zeros(1,maxits+1); \n dpsim=zeros(1,maxits+1); \n expref=zeros(1,maxits+1); \nend;\n\n% Execute parallel affinity propagation updates\ne=zeros(N,convits); dn=0; i=0;\nwhile ~dn\n i=i+1; \n\n % Compute responsibilities\n for j=1:N\n ss=s(ind1(ind1s(j):ind1e(j)),3);\n as=A(ind1(ind1s(j):ind1e(j)))+ss;\n [Y,I]=max(as); as(I)=-realmax; [Y2,I2]=max(as);\n r=ss-Y; r(I)=ss(I)-Y2;\n R(ind1(ind1s(j):ind1e(j)))=(1-lam)*r+ ...\n lam*R(ind1(ind1s(j):ind1e(j)));\n end;\n\n % Compute availabilities\n for j=1:N\n rp=R(ind2(ind2s(j):ind2e(j)));\n rp(1:end-1)=max(rp(1:end-1),0);\n a=sum(rp)-rp;\n a(1:end-1)=min(a(1:end-1),0);\n A(ind2(ind2s(j):ind2e(j)))=(1-lam)*a+ ...\n lam*A(ind2(ind2s(j):ind2e(j)));\n end;\n\n % Check for convergence\n E=((A(M-N+1:M)+R(M-N+1:M))>0); e(:,mod(i-1,convits)+1)=E; K=sum(E);\n if i>=convits || i>=maxits\n se=sum(e,2);\n unconverged=(sum((se==convits)+(se==0))~=N);\n if (~unconverged&&(K>0))||(i==maxits) dn=1; end;\n end;\n\n % Handle plotting and storage of details, if requested\n if plt||details\n if K==0\n tmpnetsim=nan; tmpdpsim=nan; tmpexpref=nan; tmpidx=nan;\n else\n tmpidx=zeros(N,1); tmpdpsim=0;\n tmpidx(find(E))=find(E); tmpexpref=sum(p(find(E)));\n discon=0;\n for j=find(E==0)'\n ss=s(ind1(ind1s(j):ind1e(j)),3);\n ii=s(ind1(ind1s(j):ind1e(j)),2);\n ee=find(E(ii));\n if length(ee)==0 discon=1;\n else\n [smx imx]=max(ss(ee));\n tmpidx(j)=ii(ee(imx));\n tmpdpsim=tmpdpsim+smx;\n end;\n end;\n if discon\n tmpnetsim=nan; tmpdpsim=nan; tmpexpref=nan; tmpidx=nan;\n else tmpnetsim=tmpdpsim+tmpexpref;\n end;\n end;\n end;\n if details\n netsim(i)=tmpnetsim; dpsim(i)=tmpdpsim; expref(i)=tmpexpref;\n idx(:,i)=tmpidx;\n end;\n if plt\n netsim(i)=tmpnetsim;\n figure(234); \n tmp=1:i; tmpi=find(~isnan(netsim(1:i)));\n plot(tmp(tmpi),netsim(tmpi),'r-');\n xlabel('# Iterations');\n ylabel('Net similarity of quantized intermediate solution');\n drawnow;\n end;\nend;\n% Identify exemplars\nE=((A(M-N+1:M)+R(M-N+1:M))>0); K=sum(E);\nif K>0\n tmpidx=zeros(N,1); tmpidx(find(E))=find(E); % Identify clusters\n for j=find(E==0)'\n ss=s(ind1(ind1s(j):ind1e(j)),3);\n ii=s(ind1(ind1s(j):ind1e(j)),2);\n ee=find(E(ii));\n [smx imx]=max(ss(ee));\n tmpidx(j)=ii(ee(imx));\n end;\n EE=zeros(N,1);\n for j=find(E)'\n jj=find(tmpidx==j); mx=-Inf;\n ns=zeros(N,1); msk=zeros(N,1);\n for m=jj'\n mm=s(ind1(ind1s(m):ind1e(m)),2);\n msk(mm)=msk(mm)+1;\n ns(mm)=ns(mm)+s(ind1(ind1s(m):ind1e(m)),3);\n end;\n ii=jj(find(msk(jj)==length(jj)));\n [smx imx]=max(ns(ii));\n EE(ii(imx))=1;\n end;\n E=EE;\n tmpidx=zeros(N,1); tmpdpsim=0;\n tmpidx(find(E))=find(E); tmpexpref=sum(p(find(E)));\n for j=find(E==0)'\n ss=s(ind1(ind1s(j):ind1e(j)),3);\n ii=s(ind1(ind1s(j):ind1e(j)),2);\n ee=find(E(ii));\n [smx imx]=max(ss(ee));\n tmpidx(j)=ii(ee(imx));\n tmpdpsim=tmpdpsim+smx;\n end;\n tmpnetsim=tmpdpsim+tmpexpref;\nelse\n tmpidx=nan*ones(N,1); tmpnetsim=nan; tmpexpref=nan;\nend;\nif details\n netsim(i+1)=tmpnetsim; netsim=netsim(1:i+1);\n dpsim(i+1)=tmpnetsim-tmpexpref; dpsim=dpsim(1:i+1);\n expref(i+1)=tmpexpref; expref=expref(1:i+1);\n idx(:,i+1)=tmpidx; idx=idx(:,1:i+1);\nelse\n netsim=tmpnetsim; dpsim=tmpnetsim-tmpexpref;\n expref=tmpexpref; idx=tmpidx;\nend;\nif plt||details\n fprintf('\\nNumber of identified clusters: %d\\n',K);\n fprintf('Fitness (net similarity): %f\\n',tmpnetsim);\n fprintf(' Similarities of data points to exemplars: %f\\n',dpsim(end));\n fprintf(' Preferences of selected exemplars: %f\\n',tmpexpref);\n fprintf('Number of iterations: %d\\n\\n',i);\nend;\nif unconverged\n fprintf('\\n*** Warning: Algorithm did not converge. The similarities\\n');\n fprintf(' may contain degeneracies - add noise to the similarities\\n');\n fprintf(' to remove degeneracies. To monitor the net similarity,\\n');\n fprintf(' activate plotting. Also, consider increasing maxits and\\n');\n fprintf(' if necessary dampfact.\\n\\n');\nend;\n", "meta": {"author": "tobyma2020", "repo": "cluster", "sha": "c9c3706523859f8c34f9741be94fb2dd89fa4cc0", "save_path": "github-repos/MATLAB/tobyma2020-cluster", "path": "github-repos/MATLAB/tobyma2020-cluster/cluster-c9c3706523859f8c34f9741be94fb2dd89fa4cc0/algorithm/AP/apclusterSparse.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110483133801, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.7488840246487916}} {"text": "% TESTFITPLANE - demonstrates RANSAC plane fitting\n%\n% Usage: testfitplane(outliers, sigma, t, feedback)\n%\n% Arguments:\n% outliers - Fraction specifying how many points are to be\n% outliers.\n% sigma - Standard deviation of inlying points from the\n% true plane.\n% t - Distance threshold to be used by the RANSAC\n% algorithm for deciding whether a point is an\n% inlier. \n% feedback - Optional flag 0 or 1 to turn on RANSAC feedback\n% information.\n%\n% Try using: testfitplane(0.3, 0.05, 0.05)\n%\n% See also: RANSACFITPLANE, FITPLANE\n\n% Copyright (c) 2003-2005 Peter Kovesi\n% School of Computer Science & Software Engineering\n% The University of Western Australia\n% http://www.csse.uwa.edu.au/\n% \n% Permission is hereby granted, free of charge, to any person obtaining a copy\n% of this software and associated documentation files (the \"Software\"), to deal\n% in the Software without restriction, subject to the following conditions:\n% \n% The above copyright notice and this permission notice shall be included in \n% all copies or substantial portions of the Software.\n%\n% The Software is provided \"as is\", without warranty of any kind.\n\n% June 2003\n\nfunction testfitplane(outliers, sigma, t, feedback)\n if nargin == 3\n\tfeedback = 0;\n end\n \n % Hard wire some constants - vary these as you wish\n \n npts = 100; % Number of 3D data points\t\n \n % Define a plane ax + by + cz + d = 0\n a = 10; b = -3; c = 5; d = 1;\n \n B = [a b c d]';\n B = B/norm(B);\n \n outsigma = 30*sigma; % outlying points have a distribution that is\n % 30 times as spread as the inlying points\n \n vpts = round((1-outliers)*npts); % No of valid points\n opts = npts - vpts; % No of outlying points\n \n % Generate npts points in the plane\n X = rand(1,npts);\n Y = rand(1,npts);\n Z = (-a*X -b*Y -d)/c;\n \n XYZ = [X\n\t Y\n\t Z];\n \n % Add uniform noise of +/-sigma\n XYZ = XYZ + (2*rand(size(XYZ))-1)*sigma;\n \n % Generate opts random outliers\n \n n = length(XYZ);\n ind = randperm(n); % get a random set of point indices\n ind = ind(1:opts); % ... of length opts\n \n % Add uniform noise of outsigma to the points chosen to be outliers.\n% XYZ(:,ind) = XYZ(:,ind) + (2*rand(3,opts)-1)*outsigma;\n \n XYZ(:,ind) = XYZ(:,ind) + sign(rand(3,opts)-.5).*(rand(3,opts)+1)*outsigma; \n \n \n\n % Display the cloud of points\n figure(1), clf, plot3(XYZ(1,:),XYZ(2,:),XYZ(3,:), 'r*');\n \n % Perform RANSAC fitting of the plane\n [Bfitted, P, inliers] = ransacfitplane(XYZ, t, feedback);\n\n fprintf('Original plane coefficients: ');\n fprintf('%8.3f ',B);\n fprintf('\\nFitted plane coefficients: ');\n fprintf('%8.3f ',Bfitted); \n fprintf('\\n');\n \n % Display the triangular patch formed by the 3 points that gave the\n % plane of maximum consensus\n patch(P(1,:), P(2,:), P(3,:), 'g')\n \n box('on'), grid('on'), rotate3d('on')\n \n fprintf('\\nRotate image so that planar patch is seen edge on\\n');\n fprintf('If the fit has been successful the inlying points should\\n');\n fprintf('form a line\\n\\n'); \n \n\n \n \n", "meta": {"author": "DrGabor", "repo": "LiDAR", "sha": "707ca635db955cf00d833578ad1236f0790cdf98", "save_path": "github-repos/MATLAB/DrGabor-LiDAR", "path": "github-repos/MATLAB/DrGabor-LiDAR/LiDAR-707ca635db955cf00d833578ad1236f0790cdf98/RoadSegmenter/Ransac/testfitplane.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110368115781, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.7488840149903379}} {"text": "function [D] = wishart_kl (arg1,arg2,arg3,arg4)\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%\n% [D] = wishart_kl (B_q,B_p,alpha_q,alpha_p)\n%\n% computes the divergence \n% /\n% D(q||p) = | q(x)*log(q(x)/p(x)) dx\n% /\n% between two k-dimensional Wishart propability density for C given\n% scale matrix B and shape parameter alpha\n%\n% alpha\n% |B| alpha-(k+1)/2\n% p(x)= ------------- |C| exp (-tr(BC))\n% Gamma (alpha)\n% k\n%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\nif nargin == 4\n B_q = arg1; B_p = arg2; alpha_q = arg3; alpha_p = arg4;\nelseif nargin == 2\n B_q = arg1.Gam_rate; alpha_q = arg1.Gam_shape;\n B_p = arg2.Gam_rate; alpha_p = arg2.Gam_shape;\nelse\n error('Incorrect number of input arguments');\nend\n\nif size(B_q)~=size(B_p)\n error('Distributions must have equal dimensions');\nend\n\nK=size(B_p,1);\n\ntry\n Lq = -logdet(B_q,'chol');\n Lp = -logdet(B_p,'chol'); \ncatch \n disp('One of the two covariance matrices (or both) is not positive definite')\n disp('Check for NaNs in the time series. Also, are there enough time points?')\n error('Error computing the inverse of the covariance matrix.')\nend\n\nlZq = log(2) * (alpha_q*K/2) - Lq * (-alpha_q/2) + K*(K-1)/4 * log(pi); \nlZp = log(2) * (alpha_p*K/2) - Lp * (-alpha_p/2) + K*(K-1)/4 * log(pi); \n\nLq = Lq + K * log(2);\nLp = Lp + K * log(2);\n\nfor k = 1:K\n lZq = lZq + gammaln(alpha_q/2+0.5-0.5*k);\n lZp = lZp + gammaln(alpha_p/2+0.5-0.5*k);\n Lq = Lq + psi(alpha_q/2+0.5-0.5*k);\n Lp = Lp + psi(alpha_p/2+0.5-0.5*k);\nend\n\nD = (alpha_q/2-0.5-0.5*K)*Lq - (alpha_p/2-0.5-0.5*K)*Lp ...\n - alpha_q * K / 2 + alpha_q * trace(B_p / B_q) / 2 + lZp - lZq;\n\nreturn;\n\n", "meta": {"author": "OHBA-analysis", "repo": "HMM-MAR", "sha": "bb0433b75482e473980791a2b30afe2012cf6578", "save_path": "github-repos/MATLAB/OHBA-analysis-HMM-MAR", "path": "github-repos/MATLAB/OHBA-analysis-HMM-MAR/HMM-MAR-bb0433b75482e473980791a2b30afe2012cf6578/utils/math/wishart_kl.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240177362486, "lm_q2_score": 0.7981867873410141, "lm_q1q2_score": 0.7487981958443408}} {"text": "clc;\nclose all;\nclearvars;\nrng('default');\nn = 10;\n% Let's get a symmetric positive definite matrix\nA = gallery('gcdmat', n);\n% Compute its Cholesky decomposition\nL = chol(A, 'lower')\nb = randn(n, 1);\n% solve the problem\nx = L \\b\nx = spx.la.tris.forward_col(L, b)\n", "meta": {"author": "indigits", "repo": "sparse-plex", "sha": "43cae2978f62938d001baaa03308a2a717ee6c9b", "save_path": "github-repos/MATLAB/indigits-sparse-plex", "path": "github-repos/MATLAB/indigits-sparse-plex/sparse-plex-43cae2978f62938d001baaa03308a2a717ee6c9b/examples/linear_algebra/triangular/ex_forward_col_1.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404077216355, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.7487871123691283}} {"text": "% NORMAL_LOGPDF\n%\n% Y = NORMAL_LOGPDF(X)\n% Y = NORMAL_LOGPDF(X, MU, SIGMA)\n%\n% MU is the location parameter in (-INF, INF), default 0\n% SIGMA is the scale parameter in (0, INF)\n\n% Last modified 2010-11-12\n% Copyright (c) Jaakko Luttinen (jaakko.luttinen@tkk.fi)\n\nfunction y = lognormal_logpdf(x, varargin)\n\nif nargin <= 3\n if nargin == 1\n mu = 0;\n sigma = 1;\n else\n mu = varargin{1};\n sigma = varargin{2};\n end\n y = -0.5*log(2*pi) ...\n -log(sigma) ...\n -0.5*((x-mu)./sigma).^2;\nend\n", "meta": {"author": "jluttine", "repo": "matlab", "sha": "63406c7782b0869948f06e1dbc594460c165d24e", "save_path": "github-repos/MATLAB/jluttine-matlab", "path": "github-repos/MATLAB/jluttine-matlab/matlab-63406c7782b0869948f06e1dbc594460c165d24e/distributions/normal_logpdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9294404038127071, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.7487871048825364}} {"text": "% J. Shi and J. Malik,\n% \"Normalized Cuts and Image Segmentation\",\n% In Proc. IEEE Conf. Computer Vision and Pattern Recognition, \n% pages 731-737, 1997.\n\n% Asad Ali\n% GIK Institute of Engineering Sciences & Technology, Pakistan\n% Email: asad_82@yahoo.com\n\n% CONCEPT: Introduced the use of 2nd generalized eigenvector for clustering\nclear all;\nclose all;\n\n% generate the data\ndata = GenerateData(2);\nfigure,plot(data(:,1), data(:,2),'r+'),title('Original Data Points'); grid on;shg\n\naffinity = CalculateAffinity(data);\nfigure,imshow(affinity,[]), title('Affinity Matrix');\n\n% compute the degree matrix\nfor i=1:size(affinity,1)\n D(i,i) = sum(affinity(i,:));\nend\n\n% compute the unnormalized graph laplacian matrix\nL = D - affinity; \n\n[eigVectors,eigValues] = eig(L);\n\n% plot the eigen vector corresponding to the 2nd largest eigen value\nfigure,plot(eigVectors(:,2),'r*'),title('2nd Largest Eigenvector');\n\n% threshold the eigen vectors\n[xx1,yy1,val1] = find(eigVectors(:,2) > 0.15);\n[xx2,yy2,val2] = find(eigVectors(:,2) > 0 & eigVectors(:,2) < 0.15);\n[xx3,yy3,val3] = find(eigVectors(:,2) < 0);\n\nfigure,\nhold on;\nplot(data(xx1,1),data(xx1,2),'m*');\nplot(data(xx2,1),data(xx2,2),'b*');\nplot(data(xx3,1),data(xx3,2),'g*');\nhold off;\ntitle('Clustering Results using 2nd Generalized Eigen Vector');\ngrid on;shg\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/26354-spectral-clustering-algorithms/Spectral Clustering/Shi_Malik.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802350995702, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7487749284808328}} {"text": "% Mathematics Q2886713\n% https://math.stackexchange.com/questions/2886713\n% Prox Operator of L1 Norm with Linear Equality Constraint (Sum of Elements)\n% References:\n% 1. aa\n% Remarks:\n% 1. sa\n% TODO:\n% \t1. ds\n% Release Notes\n% - 1.0.000 18/08/2018\n% * First release.\n\n\n%% General Parameters\n\nsubStreamNumberDefault = 79;\n\nrun('InitScript.m');\n\nfigureIdx = 0; % abs(C) | ...\n abs(C) > pi - abs(abs(A)-abs(B)) );\n a1(indices) = NaN; a2(indices) = NaN;\n b1(indices) = NaN; b2(indices) = NaN;\n c1(indices) = NaN; c2(indices) = NaN;\n \nend", "meta": {"author": "vigente", "repo": "gerardus", "sha": "4d7c5195b826967781f1bb967872410e66b7cd3d", "save_path": "github-repos/MATLAB/vigente-gerardus", "path": "github-repos/MATLAB/vigente-gerardus/gerardus-4d7c5195b826967781f1bb967872410e66b7cd3d/matlab/ThirdPartyToolbox/SphericalTrigToolbox/aaa.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750440288019, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.7486150768118395}} {"text": "function p = matrix_T_pdf(A, M, V, K, n)\n% MATRIX_T_PDF Evaluate the density of a matrix under a Matrix-T distribution\n% p = matrix_T_pdf(A, M, V, K, n)\n\n% See \"Bayesian Linear Regression\", T. Minka, MIT Tech Report, 2001\n\n[d m] = size(K);\nis = 1:d;\nc1 = prod(gamma((n+1-is)/2)) / prod(gamma((n-m+1-is)/2));\nc2 = det(K)^(d/2) / det(pi*V)^(m/2); %% pi or 2pi?\np = c1 * c2 * det((A-M)'*inv(V)*(A-M)*K + eye(m))^(-n/2);\n\n", "meta": {"author": "fieldtrip", "repo": "fieldtrip", "sha": "c2039be598a02d86b39aae76bfa7aaa720f9801c", "save_path": "github-repos/MATLAB/fieldtrip-fieldtrip", "path": "github-repos/MATLAB/fieldtrip-fieldtrip/fieldtrip-c2039be598a02d86b39aae76bfa7aaa720f9801c/external/dmlt/external/murphy/KPMstats/matrix_T_pdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9532750387190131, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.7486150726420167}} {"text": "function arcsinh_values_test ( )\n\n%*****************************************************************************80\n%\n%% ARCSINH_VALUES_TEST demonstrates the use of ARCSINH_VALUES.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 23 June 2007\n%\n% Author:\n%\n% John Burkardt\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'ARCSINH_VALUES_TEST:\\n' );\n fprintf ( 1, ' ARCSINH_VALUES stores values of \\n' );\n fprintf ( 1, ' the hyperbolic arc sine function.\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' X FX\\n' );\n fprintf ( 1, '\\n' );\n\n n_data = 0;\n\n while ( 1 )\n\n [ n_data, x, fx ] = arcsinh_values ( n_data );\n\n if ( n_data == 0 )\n break\n end\n\n fprintf ( 1, ' %12f %24.16f\\n', x, fx );\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_values/arcsinh_values_test.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8652240895276223, "lm_q2_score": 0.865224084314688, "lm_q1q2_score": 0.7486127205885467}} {"text": "function geometry_test027 ( )\n\n%*****************************************************************************80\n%\n%% TEST027 tests ELLIPSE_POINTS_ARC_2D.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 14 February 2003\n%\n% Author:\n%\n% John Burkardt\n%\n n = 13;\n dim_num = 2;\n\n center(1:dim_num) = [ 5.0, -2.0 ];\n r1 = 3.0;\n r2 = 1.0;\n psi = pi / 6.0;\n theta1 = pi / 2.0;\n theta2 = 2.0 * pi;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TEST027\\n' );\n fprintf ( 1, ' ELLIPSE_POINTS_ARC_2D returns points on an\\n' );\n fprintf ( 1,' elliptical arc.\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' The ellipse has center %f %f\\n', center(1:dim_num) );\n fprintf ( 1, ' radii R1 = %f, R2 = %f\\n', r1, r2 );\n fprintf ( 1, ' and angle PSI = %f\\n', psi );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' The arc extends from THETA1 = %f\\n', theta1 );\n fprintf ( 1, ' to THETA2 = %f\\n', theta2 );\n\n p = ellipse_points_arc_2d ( center, r1, r2, psi, theta1, theta2, n );\n\n r8mat_transpose_print ( dim_num, n, p, ' Sample points:' );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/geometry/geometry_test027.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240964782011, "lm_q2_score": 0.8652240773641087, "lm_q1q2_score": 0.7486127205885461}} {"text": "function M=movsp2wv(N,Np);\n%MOVSP2WV Movie illustrating the passage from the spectrogram to the WVD.\n%\tM=MOVSP2WV(N,Np) generates the movie frames illustrating the passage\n%\tfrom the spectrogram to the WVD using different smoothing gaussian\n%\twindows in the smoothed pseudo-WVD. \n%\n%\tN : number of points for the signal;\n%\tNp : number of snapshots (default : 8)\n%\tM : matrix of movie frames.\n%\n%\tExample : \n%\t M=movsp2wv(128,15); movie(M,5);\n\n%\tO. Lemoine - June 1996.\n%\tCopyright (c) 1996 by CNRS (France).\n%\n% This program is free software; you can redistribute it and/or modify\n% it under the terms of the GNU General Public License as published by\n% the Free Software Foundation; either version 2 of the License, or\n% (at your option) any later version.\n%\n% This program is distributed in the hope that it will be useful,\n% but WITHOUT ANY WARRANTY; without even the implied warranty of\n% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n% GNU General Public License for more details.\n%\n% You should have received a copy of the GNU General Public License\n% along with this program; if not, write to the Free Software\n% Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\n\nif nargin<1,\n error('At least one argument required');\nelseif nargin==1,\n Np=8;\nend\nNp=odd(Np)-1;\n\nM = moviein(Np);\n\nt1=N/4; t2=3*N/4; t3=t1; t4=t2; \nf1=0.125; f2=f1; f3=0.375; f4=f3; \nt=1:N; \nT=sqrt(2*N);\n\nsig1=amgauss(N,t1,T).*fmconst(N,f1,t1); \nsig2=amgauss(N,t2,T).*fmconst(N,f2,t2); \nsig3=amgauss(N,t3,T).*fmconst(N,f3,t3); \nsig4=amgauss(N,t4,T).*fmconst(N,f4,t4); \n\nsig=sig1+sig2+sig3+sig4;\n\nh=tftb_window(49,'gauss');\n[tfr,t,f]=tfrsp(sig,t,N,h); tfr=tfr(1:N/2,:); f=f(1:N/2);\nMax=max(max(tfr)); V=[0.1 0.3 0.5 0.7 0.9]*Max;\ncontour(t,f,tfr,V);\nxlabel('Time'); ylabel('Frequency'); axis('xy')\nM(:,1) = getframe;\n\nNg0=odd(fliplr(linspace(3,N/4,Np/2-1)));\nNh0=odd(linspace(N/2,9*N/10,Np/2-1));\n\nfor k=2:Np/2,\n g=tftb_window(Ng0(k-1),'gauss');\n h=tftb_window(Nh0(k-1),'gauss');\n [tfr,t,f]=tfrspwv(sig,t,N,g,h);\n Max=max(max(tfr)); V=[0.1 0.3 0.5 0.7 0.9]*Max;\n contour(t,f,tfr,V);\n xlabel('Time'); ylabel('Frequency'); axis('xy')\n M(:,k) = getframe;\nend\n\n[tfr,t,f]=tfrwv(sig);\nMax=max(max(tfr)); V=[0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9]*Max;\ncontour(t,f,tfr,V);\nxlabel('Time'); ylabel('Frequency'); axis('xy')\nM(:,Np/2+1) = getframe;\n\nfor k=Np/2+2:Np,\n M(:,k) =M(:,Np+2-k);\nend\n", "meta": {"author": "HeLiangHIT", "repo": "time_frequency", "sha": "09c2abe92355ff5cd867bdb169229682e9d7af7c", "save_path": "github-repos/MATLAB/HeLiangHIT-time_frequency", "path": "github-repos/MATLAB/HeLiangHIT-time_frequency/time_frequency-09c2abe92355ff5cd867bdb169229682e9d7af7c/tf_tool_box/tftb-0.2/mfiles/movsp2wv.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267626522814, "lm_q2_score": 0.8615382165412809, "lm_q1q2_score": 0.7485274595787813}} {"text": "function circle_segment_test11 ( )\n\n%*****************************************************************************80\n%\n%% CIRCLE_SEGMENT_TEST11 demonstrates CIRCLE_SEGMENT_ROTATION_FROM_CHORD.\n%\n% Discussion:\n%\n% We make a table of all pairs of angles that are multiples of pi/12.\n%\n% For each pair, we compute the rotation, that is, the angle of the\n% central radius of the circle segment. We print out the result in\n% terms of multiples of pi/12.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 21 May 2013\n%\n% Author:\n%\n% John Burkardt\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'CIRCLE_SEGMENT_TEST11:\\n' );\n fprintf ( 1, ' CIRCLE_SEGMENT_ROTATION_FROM_CHORD is given the endpoints\\n' );\n fprintf ( 1, ' of a chord, and is asked to determine the angle of the\\n' );\n fprintf ( 1, ' central radius vector.\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' We make a table of all pairs of angles that are multiples\\n' );\n fprintf ( 1, ' of pi/12, determine the corresponding chord endpoints, and\\n' );\n fprintf ( 1, ' compute the rotation angle, also printed as a multiple of pi/12.\\n' );\n\n r = 2.0;\n c = [ 3.0; 5.0 ];\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' 0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0\\n' );\n fprintf ( 1, '\\n' );\n for i = 0 : 12\n rho1 = i * pi / 6;\n p1 = c + r * [ cos(rho1); sin(rho1) ];\n fprintf ( 1, ' %2d.0: ', i );\n for j = 0 : 12\n rho2 = j * pi / 6;\n p2 = c + r * [ cos(rho2); sin(rho2) ];\n alpha = circle_segment_rotation_from_chord ( r, c, p1, p2 );\n fprintf ( 1, ' %4.1f', round ( 10 * 6 * alpha / pi ) / 10 );\n end\n fprintf ( 1, '\\n' );\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/circle_segment/circle_segment_test11.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267626522814, "lm_q2_score": 0.8615382129861583, "lm_q1q2_score": 0.7485274564899956}} {"text": "% P2.7\nclear; clc;\nn1 = 0:20;\nx1 = 0.9.^n1;\nsubplot(3,2,1); stem(n1,x1,'ko'); title('First given sequence x1(n)');\naxis([-20 20 0 1]);\n[x1f,n1f] = sigfold(x1,n1); % obtain x1(-n)\nn2 = -20:0;\nx2 = 0.8.^(-n2);\nsubplot(3,2,2); stem(n2,x2,'ko'); title('Second given sequence x2(n)');\naxis([-20 20 0 1]);\n[x2f,n2f] = sigfold(x2,n2); % obtain x2(-n)\n[r,nr] = conv_m(x1,n1,x1f,n1f); % auto-correlation\nsubplot(3,2,3); stem(nr,r,'ko'); title('Auto-Correlation x1(n)*x1(-n)');\n[r,nr] = conv_m(x2,n2,x2f,n2f); % auto-correlation\nsubplot(3,2,4); stem(nr,r,'ko'); title('Auto-Correlation x2(n)*x2(-n)');\n[r,nr] = conv_m(x1f,n1f,x2,n2); % cross-correlation\nsubplot(3,1,3); stem(nr,r,'ko'); title('Cross-Correlation');", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/16323-ingle-proakis-chapter-2-solutions/P207.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037343628703, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.7485156775301236}} {"text": "function [w, dwdx, dwdxx] = Weight(type, para, di, dmI)\n% EVALUATE WEIGHT FUNCTION\n%\n% SYNTAX: [w, dwdr, dwdrr] = GaussWeight(type, para, di, dmi)\n%\n% INPUT PARAMETERS\n% type - Type of weight function\n% para - Weight function parameter\n% di - Distance\n% dmi - Support size\n% OUTPUT PARAMETERS\n% w - Value of weight function at r\n% dwdx - Value of first order derivative of weight function with respect to x at r\n% dwdxx- Value of Second order derivative of weight function with respect to x at r\n%\nr = abs(di) / dmI;\n\nif (di >= 0.0)\n drdx = 1.0/dmI;\nelse\n drdx = -1.0/dmI;\nend\n\n% EVALUATE WEIGHT FUNCTION AND ITS FIRST AND SECOND ORDER OF DERIVATIVES WITH RESPECT r AT r\nif (type == 'GAUSS')\n [w,dwdr,dwdrr] = Gauss(para,r);\nelseif (type == 'CUBIC')\n [w,dwdr,dwdrr] = Cubic(r);\nelseif (type == 'SPLIN')\n [w,dwdr,dwdrr] = Spline(r);\nelseif (type == 'power')\n [w,dwdr,dwdrr] = power_function(para,r); \nelseif (type == 'CSRBF')\n [w,dwdr,dwdrr] = CSRBF2(r);\nelse\n error('Invalid type of weight function.');\nend\n\ndwdx = dwdr * drdx;\ndwdxx = dwdrr * drdx * drdx;\n\n\nfunction [w,dwdr,dwdrr] = Gauss(beta,r)\nif (r>1.0)\n w = 0.0;\n dwdr = 0.0;\n dwdrr = 0.0;\nelse\n b2 = beta*beta;\n r2 = r*r;\n eb2 = exp(-b2);\n\n w = (exp(-b2*r2) - eb2) / (1.0 - eb2);\n dwdr = -2*b2*r*exp(-b2*r2) / (1.0 - eb2);\n dwdrr = -2*b2*exp(-b2*r2)*(1-2*b2*r2) / (1.0 - eb2);\nend\n\nfunction [w,dwdr,dwdrr] = Cubic(r)\nif (r>1.0)\n w = 0.0;\n dwdr = 0.0;\n dwdrr = 0.0;\nelse\n w = 1-6*r^2+8*r^3-3*r^4;\n dwdr = -12*r+24*r^2-12*r^3;\n dwdrr = -12+48*r-36*r^2;\nend\n\nfunction [w,dwdr,dwdrr] = power_function(arfa,r)\nif (r>1.0)\n w = 0.0;\n dwdr = 0.0;\n dwdrr = 0.0;\nelse\n a2 = arfa*arfa;\n r2 = r*r;\n w = exp(-r2/a2);\n dwdr = (-2*r/a2)*exp(-r2/a2);\n dwdrr = (-2/a2+(-2*r/a2).^2)*exp(-r2/a2);\nend\n\nfunction [w,dwdr,dwdrr] = Spline(r)\nif (r>1.0)\n w = 0.0;\n dwdr = 0.0;\n dwdrr = 0.0;\nelseif (r<=0.5)\n w = 2/3 - 4*r^2 + 4*r^3;\n dwdr = -8*r + 12*r^2;\n dwdrr = -8 + 24*r;\nelse\n w = 4/3 - 4*r + 4*r^2 - 4*r^3/3;\n dwdr = -4 + 8*r -4*r^2;\n dwdrr = 8 - 8*r;\nend\n\nfunction [w,dwdr,dwdrr] = CSRBF2(r)\nif (r>1.0)\n w = 0.0;\n dwdr = 0.0;\n dwdrr = 0.0;\nelse\n\tw = (1-r)^6*(6+36*r+82*r^2+72*r^3+30*r^4+5*r^5);\n\tdwdr = 11*r*(r+2)*(5*r^3+15*r^2+18*r+4)*(r-1)^5;\n dwdrr = 22*(25*r^5+100*r^4+142*r^3+68*r^2-16*r-4)*(r-1)^4;\nend\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/34514-moving-least-squaremls1d/Weight.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037221561136, "lm_q2_score": 0.8080672066194946, "lm_q1q2_score": 0.7485156612439311}} {"text": "function [ dmap ] = dataDensity( x, y, width, height, limits, fudge )\n%DATADENSITY Get a data density image of data \n% x, y - two vectors of equal length giving scatterplot x, y co-ords\n% width, height - dimensions of the data density plot, in pixels\n% limits - [xmin xmax ymin ymax] - defaults to data max/min\n% fudge - the amount of smear, defaults to size of pixel diagonal\n%\n% By Malcolm McLean\n%\n if(nargin == 4)\n limits(1) = min(x);\n limits(2) = max(x);\n limits(3) = min(y);\n limits(4) = max(y);\n end\n deltax = (limits(2) - limits(1)) / width;\n deltay = (limits(4) - limits(3)) / height;\n if(nargin < 6)\n fudge = sqrt(deltax^2 + deltay^2);\n end\n dmap = zeros(height, width);\n for ii = 0: height - 1\n yi = limits(3) + ii * deltay + deltay/2;\n for jj = 0 : width - 1\n xi = limits(1) + jj * deltax + deltax/2;\n dd = 0;\n for kk = 1: length(x)\n dist2 = (x(kk) - xi)^2 + (y(kk) - yi)^2;\n dd = dd + 1 / ( dist2 + fudge); \n end\n dmap(ii+1,jj+1) = dd;\n end\n end\n \n\nend\n\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/31726-data-density-plot/DataDensity/dataDensity.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896758909756, "lm_q2_score": 0.8128673201042492, "lm_q1q2_score": 0.7484798362211575}} {"text": "function [ov ov_n1 ov_n2] = calc_overlap(dres1, f1, dres2, f2)\n%%f2 can be an array and f1 should be a scalar.\n%%% this will find the overlap between dres1(f1) (only one) and all detection windows in dres2(f2(:))\n\nf2=f2(:)';\nn = length(f2);\n\ncx1 = dres1.x(f1);\ncx2 = dres1.x(f1)+dres1.w(f1)-1;\ncy1 = dres1.y(f1);\ncy2 = dres1.y(f1)+dres1.h(f1)-1;\n\ngx1 = dres2.x(f2);\ngx2 = dres2.x(f2)+dres2.w(f2)-1;\ngy1 = dres2.y(f2);\ngy2 = dres2.y(f2)+dres2.h(f2)-1;\n\nca = dres1.h(f1).*dres1.w(f1); %% area\nga = dres2.h(f2).*dres2.w(f2);\n\n%%% find the overlapping area\nxx1 = max(cx1, gx1);\nyy1 = max(cy1, gy1);\nxx2 = min(cx2, gx2);\nyy2 = min(cy2, gy2);\nw = xx2-xx1+1;\nh = yy2-yy1+1;\n\ninds = find((w > 0) .* (h > 0)); %% real overlap\nov = zeros(1, n);\nov_n1 = zeros(1, n);\nov_n2 = zeros(1, n);\ninter = w(inds).*h(inds); %% area of overlap\nu = ca + ga(inds) - w(inds).*h(inds); %% area of union\nov(inds) = inter ./ u; %% intersection / union\nov_n1(inds) = inter / ca; %% intersection / area in dres1\nov_n2(inds) = inter ./ ga(inds); %% intersection / area in dres2\n\n", "meta": {"author": "yuxng", "repo": "MDP_Tracking", "sha": "2f452a1f7204b6e3344925b8eaf39db1c7eecf2c", "save_path": "github-repos/MATLAB/yuxng-MDP_Tracking", "path": "github-repos/MATLAB/yuxng-MDP_Tracking/MDP_Tracking-2f452a1f7204b6e3344925b8eaf39db1c7eecf2c/3rd_party/DP_NMS/calc_overlap.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896802383028, "lm_q2_score": 0.8128673110375457, "lm_q1q2_score": 0.7484798314064307}} {"text": "function variance = gamma_variance ( a, b, c )\n\n%*****************************************************************************80\n%\n%% GAMMA_VARIANCE returns the variance of the Gamma PDF.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 11 September 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real A, B, C, the parameters of the PDF.\n% 0.0 < B,\n% 0.0 < C.\n%\n% Output, real VARIANCE, the variance of the PDF.\n%\n variance = b * b * c;\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/prob/gamma_variance.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9005297834483234, "lm_q2_score": 0.8311430541321951, "lm_q1q2_score": 0.7484690745522438}} {"text": "function [r,normr,nre,s] = reorth(Q,r,normr,index,alpha,method)\n\n%REORTH Reorthogonalize a vector using iterated Gram-Schmidt\n%\n% [R_NEW,NORMR_NEW,NRE] = reorth(Q,R,NORMR,INDEX,ALPHA,METHOD)\n% reorthogonalizes R against the subset of columns of Q given by INDEX. \n% If INDEX==[] then R is reorthogonalized all columns of Q.\n% If the result R_NEW has a small norm, i.e. if norm(R_NEW) < ALPHA*NORMR,\n% then a second reorthogonalization is performed. If the norm of R_NEW\n% is once more decreased by more than a factor of ALPHA then R is \n% numerically in span(Q(:,INDEX)) and a zero-vector is returned for R_NEW.\n%\n% If method==0 then iterated modified Gram-Schmidt is used.\n% If method==1 then iterated classical Gram-Schmidt is used.\n%\n% The default value for ALPHA is 0.5. \n% NRE is the number of reorthogonalizations performed (1 or 2).\n\n% References: \n% Aake Bjorck, \"Numerical Methods for Least Squares Problems\",\n% SIAM, Philadelphia, 1996, pp. 68-69.\n%\n% J.~W. Daniel, W.~B. Gragg, L. Kaufman and G.~W. Stewart, \n% ``Reorthogonalization and Stable Algorithms Updating the\n% Gram-Schmidt QR Factorization'', Math. Comp., 30 (1976), no.\n% 136, pp. 772-795.\n%\n% B. N. Parlett, ``The Symmetric Eigenvalue Problem'', \n% Prentice-Hall, Englewood Cliffs, NJ, 1980. pp. 105-109\n\n% Rasmus Munk Larsen, DAIMI, 1998.\n\n% Check input arguments.\n% warning('PROPACK:NotUsingMex','Using slow matlab code for reorth.')\nif nargin<2\n error('Not enough input arguments.')\nend\n[n k1] = size(Q);\nif nargin<3 | isempty(normr)\n% normr = norm(r);\n normr = sqrt(r'*r);\nend\nif nargin<4 | isempty(index)\n k=k1;\n index = [1:k]';\n simple = 1;\nelse\n k = length(index);\n if k==k1 & index(:)==[1:k]'\n simple = 1;\n else\n simple = 0;\n end\nend\nif nargin<5 | isempty(alpha)\n alpha=0.5; % This choice garanties that \n % || Q^T*r_new - e_{k+1} ||_2 <= 2*eps*||r_new||_2,\n % cf. Kahans ``twice is enough'' statement proved in \n % Parletts book.\nend\nif nargin<6 | isempty(method)\n method = 0;\nend\nif k==0 | n==0\n return\nend\nif nargout>3\n s = zeros(k,1);\nend\n\n\nnormr_old = 0;\nnre = 0;\nwhile normr < alpha*normr_old | nre==0\n if method==1\n if simple\n t = Q'*r;\n r = r - Q*t;\n else\n t = Q(:,index)'*r;\n r = r - Q(:,index)*t;\n end\n else \n for i=index, \n t = Q(:,i)'*r; \n r = r - Q(:,i)*t;\n end\n end\n if nargout>3\n s = s + t;\n end\n normr_old = normr;\n% normr = norm(r);\n normr = sqrt(r'*r);\n nre = nre + 1;\n if nre > 4\n % r is in span(Q) to full accuracy => accept r = 0 as the new vector.\n r = zeros(n,1);\n normr = 0;\n return\n end\nend\n", "meta": {"author": "andrewssobral", "repo": "lrslibrary", "sha": "06d457349cb5f1fc56a583cd61af9f1d5150e3a1", "save_path": "github-repos/MATLAB/andrewssobral-lrslibrary", "path": "github-repos/MATLAB/andrewssobral-lrslibrary/lrslibrary-06d457349cb5f1fc56a583cd61af9f1d5150e3a1/algorithms/mc/IALM-MC/utils/reorth.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972616934406, "lm_q2_score": 0.8596637559030338, "lm_q1q2_score": 0.7484209118662796}} {"text": "function [all_theta] = oneVsAll(X, y, num_labels, lambda)\n%ONEVSALL trains multiple logistic regression classifiers and returns all\n%the classifiers in a matrix all_theta, where the i-th row of all_theta \n%corresponds to the classifier for label i\n% [all_theta] = ONEVSALL(X, y, num_labels, lambda) trains num_labels\n% logisitc regression classifiers and returns each of these classifiers\n% in a matrix all_theta, where the i-th row of all_theta corresponds \n% to the classifier for label i\n\n% Some useful variables\nm = size(X, 1);\nn = size(X, 2);\n\n% You need to return the following variables correctly \nall_theta = zeros(num_labels, n + 1);\n\n% Add ones to the X data matrix\nX = [ones(m, 1) X];\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: You should complete the following code to train num_labels\n% logistic regression classifiers with regularization\n% parameter lambda. \n%\n% Hint: theta(:) will return a column vector.\n%\n% Hint: You can use y == c to obtain a vector of 1's and 0's that tell use \n% whether the ground truth is true/false for this class.\n%\n% Note: For this assignment, we recommend using fmincg to optimize the cost\n% function. It is okay to use a for-loop (for c = 1:num_labels) to\n% loop over the different classes.\n%\n% fmincg works similarly to fminunc, but is more efficient when we\n% are dealing with large number of parameters.\n%\n% Example Code for fmincg:\n%\n% % Set Initial theta\n% initial_theta = zeros(n + 1, 1);\n% \n% % Set options for fminunc\n% options = optimset('GradObj', 'on', 'MaxIter', 50);\n% \n% % Run fmincg to obtain the optimal theta\n% % This function will return theta and the cost \n% [theta] = ...\n% fmincg (@(t)(lrCostFunction(t, X, (y == c), lambda)), ...\n% initial_theta, options);\n%\n\nfor c = 1:num_labels\n options = optimset('GradObj', 'on', 'MaxIter', 50);\n\n all_theta(c, :) = fmincg (@(t)(lrCostFunction(t, X, (y == c), lambda)), ...\n zeros(n + 1, 1), options);\n\n% =========================================================================\n\n\nend\n", "meta": {"author": "SaveTheRbtz", "repo": "ml-class", "sha": "74ce689e21e9f3ca184e60313351b31112e5dd56", "save_path": "github-repos/MATLAB/SaveTheRbtz-ml-class", "path": "github-repos/MATLAB/SaveTheRbtz-ml-class/ml-class-74ce689e21e9f3ca184e60313351b31112e5dd56/ex3/oneVsAll.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473813156294, "lm_q2_score": 0.8577681122619883, "lm_q1q2_score": 0.7482717665077964}} {"text": "function varargout = createTetrakaidecahedron()\n%CREATETETRAKAIDECAHEDRON Create a 3D mesh representing a tetrakaidecahedron.\n%\n% [V, E, F] = createTetrakaidecahedron;\n% Create a mesh structure representing a tetrakaidecahedron, composed of\n% both square and hexagonal faces. Tetrakaidecahedron can be used to tile\n% the 3D Euclidean space.\n%\n% V is a 24-by-3 array with vertex coordinates,\n% E is a 36-by-2 array containing indices of neighbour vertices,\n% F is a 14-by-1 cell array containing vertex indices array of each face.\n%\n% [V, F] = createTetrakaidecahedron;\n% Returns only the vertices and the face vertex indices.\n%\n% MESH = createTetrakaidecahedron;\n% Returns the data as a mesh structure, with fields 'vertices', 'edges'\n% and 'faces'.\n%\n% Example\n% [n, e, f] = createTetrakaidecahedron;\n% drawMesh(n, f);\n% \n% See also \n% meshes3d, drawMesh\n\n% ------\n% Author: David Legland \n% E-mail: david.legland@inra.fr\n% Created: 2005-02-10\n% Copyright 2005-2022 INRA - TPV URPOI - BIA IMASTE\n\nnodes = [...\n 1 0 2;0 1 2;-1 0 2;0 -1 2;...\n 2 0 1;0 2 1;-2 0 1;0 -2 1;...\n 2 1 0;1 2 0;-1 2 0;-2 1 0;-2 -1 0;-1 -2 0;1 -2 0;2 -1 0;...\n 2 0 -1;0 2 -1;-2 0 -1;0 -2 -1;...\n 1 0 -2;0 1 -2;-1 0 -2;0 -1 -2];\n\nedges = [...\n 1 2;1 4;1 5;2 3;2 6;3 4;3 7;4 8;...\n 5 9;5 16;6 10;6 11;7 12;7 13;8 14;8 15;...\n 9 10;9 17;10 18;11 12;11 18;12 19;13 14;13 19;14 20;15 16;15 20;16 17;....\n 17 21;18 22;19 23;20 24;21 22;21 24;22 23;23 24];\n \n \nfaces = {...\n [1 2 3 4], ...\n [1 4 8 15 16 5], [1 5 9 10 6 2], [2 6 11 12 7 3], [3 7 13 14 8 4],...\n [5 16 17 9], [6 10 18 11], [7 12 19 13], [8 14 20 15],...\n [9 17 21 22 18 10], [11 18 22 23 19 12], [13 19 23 24 20 14], [15 20 24 21 17 16], ...\n [21 24 23 22]};\nfaces = faces';\n \n% format output\nvarargout = formatMeshOutput(nargout, nodes, edges, faces);\n\n", "meta": {"author": "mattools", "repo": "matGeom", "sha": "1fd2c937064be1ee1f4fd09fbfdf96145ebe5271", "save_path": "github-repos/MATLAB/mattools-matGeom", "path": "github-repos/MATLAB/mattools-matGeom/matGeom-1fd2c937064be1ee1f4fd09fbfdf96145ebe5271/matGeom/meshes3d/createTetrakaidecahedron.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278633625322, "lm_q2_score": 0.8479677583778258, "lm_q1q2_score": 0.7482703772256608}} {"text": "function FBC = FbCrop( FB, delta )\n% Crop a 2D filterbank (adjusting filter norms).\n%\n% Takes a filter bank and crops it by cropping off delta pixels from each\n% side. Ensures that the mean response of each filter is 0 and that the L1\n% norm is 1, i.e. sum(sum(abs(F)))==1.\n%\n% USAGE\n% FBC = FbCrop( FB, delta )\n%\n% INPUTS\n% FB - original filterbank\n% delta - amount to crop by\n%\n% OUTPUTS\n% FBC - cropped filterbank\n%\n% EXAMPLE\n% load FbDoG.mat; FBC=FbCrop(FB,4);\n% figure(1); montage2(FB,struct('extraInfo',1));\n% figure(2); montage2(FBC,struct('extraInfo',1));\n%\n% See also FBAPPLY2D\n%\n% Piotr's Computer Vision Matlab Toolbox Version 2.0\n% Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com]\n% Licensed under the Simplified BSD License [see external/bsd.txt]\n\nnd = ndims(FB);\nif( nd~=2 && nd~=3 ); error('I must an MxNxK array'); end\n\ncropsiz = size(FB);\ncropsiz = [cropsiz(1:2)-2*delta, cropsiz(3)];\nFBC = arrayToDims( FB, cropsiz );\n\nfor f=1:size(FB,3)\n FC = FBC(:,:,f);\n FC = FC - sum(sum(FC)) / numel(FC); % 0 mean\n FC = FC / sum(sum(abs(FC))); % L1 norm == 1\n FBC(:,:,f) = FC;\nend\n", "meta": {"author": "pdollar", "repo": "toolbox", "sha": "e87332637bbe8e8b92dd487c87567d9628404523", "save_path": "github-repos/MATLAB/pdollar-toolbox", "path": "github-repos/MATLAB/pdollar-toolbox/toolbox-e87332637bbe8e8b92dd487c87567d9628404523/filters/FbCrop.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8933094117351309, "lm_q2_score": 0.837619961306541, "lm_q1q2_score": 0.7482537948923493}} {"text": "function xyz = plane_normal_qr_to_xyz ( pp, normal, pq, pr, n, qr )\n\n%*****************************************************************************80\n%\n%% PLANE_NORMAL_QR_TO_XYZ: QR_TO_XYZ coordinates for a normal form plane.\n%\n% Discussion:\n%\n% The normal form of a plane in 3D is:\n%\n% PP is a point on the plane,\n% NORMAL is a normal vector to the plane.\n%\n% Two vectors PQ and PR can be computed with the properties that\n% * NORMAL, PQ and PR are pairwise orthogonal;\n% * PQ and PR have unit length;\n% * every point P in the plane has a \"QR\" representation\n% as P = PP + q * PQ + r * PR.\n%\n% This function is given the QR coordinates of a set of points on the\n% plane, and returns the XYZ coordinates.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 12 November 2010\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real PP(3), a point on the plane.\n%\n% Input, real NORMAL(3), a normal vector N to the plane. The\n% vector must not have zero length, but it is not necessary for N\n% to have unit length.\n%\n% Input, real PQ(3), a vector of unit length,\n% perpendicular to the vector N and the vector PR.\n%\n% Input, real PR(3), a vector of unit length,\n% perpendicular to the vector N and the vector PQ.\n%\n% Input, integer N, the number of points on the plane.\n%\n% Input, real QR(2,N), the QR coordinates of the points.\n%\n% Output, real XYZ(3,N), the XYZ coordinates of the points.\n%\n xyz = repmat ( pp, 1, n ) + [ pq'; pr' ]' * qr(1:2,1:n);\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/geometry/plane_normal_qr_to_xyz.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094060543488, "lm_q2_score": 0.8376199613065411, "lm_q1q2_score": 0.7482537901340129}} {"text": "function [ a, seed ] = markov_random ( n, key )\n\n%*****************************************************************************80\n%\n%% MARKOV_RANDOM returns a random Markov matrix.\n%\n% Discussion:\n%\n% A Markov matrix, also called a \"stochastic\" matrix, is distinguished\n% by two properties:\n%\n% * All matrix entries are nonnegative;\n% * The sum of the entries in each row is 1.\n%\n% A \"transition matrix\" is the transpose of a Markov matrix, and\n% has column sums equal to 1.\n%\n% Example:\n%\n% N = 4\n%\n% 1/10 2/10 3/10 4/10\n% 1 0 0 0\n% 5/10 2/10 3/10 0\n% 2/10 2/10 2/10 4/10\n%\n% Properties:\n%\n% A is generally not symmetric: A' /= A.\n%\n% 0 <= A(I,J) <= 1.0 for every I and J.\n%\n% The sum of the entries in each row of A is 1.\n%\n% Because it has a constant row sum of 1,\n% A has an eigenvalue of 1, and\n% a (right) eigenvector of ( 1, 1, 1, ..., 1 ).\n%\n% All the eigenvalues of A have modulus no greater than 1.\n%\n% The eigenvalue 1 lies on the boundary of all the Gerschgorin rowsum disks.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 16 October 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the order of A.\n%\n% Input, integer KEY, a positive value that selects the data.\n%\n% Output, real A(N,N), the matrix.\n%\n seed = key;\n\n [ a, seed ] = r8mat_uniform_01 ( n, n, seed );\n\n for i = 1 : n\n\n row_sum = sum ( a(i,1:n) );\n\n a(i,1:n) = a(i,1:n) / row_sum;\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_mat/markov_random.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.8376199653600372, "lm_q1q2_score": 0.7482537889967024}} {"text": "% function qs = equantile(X, ps, dim)\n%\n% Calculates empirical (non-smoothed) quantiles of multidimensional\n% arrays. Ignores NaN entries. Faster than, but similar to, the\n% quantile() function in the MATLAB Statistics toolbox.\n%\n% Input:\n% X: multidimensional vector/matrix over which to calculate\n% empirical quantiles.\n% ps: vector of quantile values (between 0 and 1)\n% dim: (optional) dimension along which to calculate quantiles\n%\n% Output:\n% qs: vector/matrix of empirical quantiles\n%\n%---------------------------------------------------------------------------------\n% Author: Eugene Brevdo (http://www.math.princeton.edu/~ebrevdo/)\n%---------------------------------------------------------------------------------\nfunction qs = equantile(X,ps,dim)\n\nndX = ndims(X);\nsX = size(X);\npsn = length(ps);\n\nassert(all(ps >= 0 & ps <= 1));\n\nneedsort = 0;\nif nargin<3\n % Sort properly depending on data\n if isvector(X) && ~issorted(X)\n needsort = 1;\n elseif ndX <= 2 && ~issorted(X,'rows')\n needsort = 1;\n elseif ndX > 2\n needsort = 1;\n end\n\n % Which dimension are we calculating quantiles along?\n if isvector(X)\n [tmpvar,mdim] = max(sX);\n dim = mdim;\n else\n dim = 1;\n end\nelse\n needsort = 1;\nend\n\n% Reshape data to make ensuing steps easier (quantile-dim becomes first dim)\ndperm = 1:ndX;\ndperm([1 dim]) = dperm([dim 1]);\nif (dim ~= 1)\n X = permute(X, dperm);\nend\nsXperm = sX(dperm);\n\n% Reshape to 2D; we calculate quantiles along first dimension\nX = reshape(X, sX(dim), prod(sX([1:dim-1, dim+1:ndX])));\n\nif (needsort),\n X = sort(X,1);\nend\n\n% If we see NaNs, need to calculate quantiles row-by-row.\n% Otherwise can do it in one fell swoop.\nXnan = isnan(X);\nif any(any(Xnan,2))\n hasnan = 1;\nelse\n hasnan = 0;\nend\n\nif (~hasnan)\n ks = round(ps*(sX(dim)-1) + 1); \n assert(all(ks >= 1 & ks <= sX(dim)));\n qs = X(ks,:);\nelse % if (hasnan)\n ns = zeros(size(X,2), 1);\n qs = nan(psn, size(X,2));\n\n % Limit ourselves to non-NaN values\n for ci=1:size(X,2)\n ni = find(Xnan(:, ci), 1, 'first')-1;\n % If don't find any NaNs, use full dim\n if isempty(ni), ni = sX(dim); end\n\n ns(ci) = ni;\n end\n\n % Calculate quantiles in each case\n Xcol = 1:size(X,2);\n for pi=1:psn\n p = ps(pi);\n ks = round(p*(ns-1)+1);\n % Pull out the proper elements of sorted X\n qs(pi,ks>0) = X(sub2ind(size(X), ks(ks>0)', Xcol(ks>0)));\n end\nend\n\n% Convert back to ndim array\nqs = reshape(qs, [psn, sX(1:dim-1), sX(dim+1:ndX)]);\n\n% Move coordinates back to their proper places\nif (dim ~= 1)\n qs = ipermute(qs, dperm);\nend\n", "meta": {"author": "HeLiangHIT", "repo": "time_frequency", "sha": "09c2abe92355ff5cd867bdb169229682e9d7af7c", "save_path": "github-repos/MATLAB/HeLiangHIT-time_frequency", "path": "github-repos/MATLAB/HeLiangHIT-time_frequency/time_frequency-09c2abe92355ff5cd867bdb169229682e9d7af7c/tf_tool_box/synchrosqueezing/util/equantile.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587934924569, "lm_q2_score": 0.8418256412990658, "lm_q1q2_score": 0.7481799412919715}} {"text": "function geometry_test007 ( )\n\n%*****************************************************************************80\n%\n%% TEST007 tests BALL_UNIT_SAMPLE_3D.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 14 February 2003\n%\n% Author:\n%\n% John Burkardt\n%\n dim_num = 3;\n n_sample = 1000;\n seed = 123456789;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TEST007\\n' );\n fprintf ( 1, ' For the unit ball in 3 dimensions:\\n' );\n fprintf ( 1, ' BALL_UNIT_SAMPLE_3D samples;\\n' );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' A few sample values:\\n' );\n fprintf ( 1, '\\n' );\n\n for i = 1 : 5\n [ x, seed ] = ball_unit_sample_3d ( seed );\n fprintf ( 1, ' %10f %10f %10f\\n', x(1:dim_num) );\n end\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Number of sample points = %d\\n', n_sample );\n\n average(1:dim_num) = 0.0;\n\n for i = 1 : n_sample\n [ x, seed ] = ball_unit_sample_3d ( seed );\n average(1:dim_num) = average(1:dim_num) + x(1:dim_num);\n end\n\n average(1:dim_num) = average(1:dim_num) / n_sample;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Now average the points, which should get a value\\n' );\n fprintf ( 1, ' close to zero, and closer as N_SAMPLE increases.\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Average: %10f %10f %10f\\n', average(1:dim_num) );\n\n average_r = 0.0;\n\n for i = 1 : n_sample\n [ x, seed ] = ball_unit_sample_3d ( seed );\n r = sqrt ( sum ( x(1:dim_num).^2 ) );\n average_r = average_r + r;\n end\n\n average_r = average_r / n_sample;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Now average the distance of the points from\\n' );\n fprintf ( 1, ' the center, which should be the \\n' );\n fprintf ( 1, ' 1/2**(1/dim_num) = %f\\n', 0.5^( 1.0 / dim_num ) );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Average: %f\\n', average_r );\n\n average_theta = 0.0;\n\n for i = 1 : n_sample\n [ x, seed ] = ball_unit_sample_3d ( seed );\n theta = r8_atan ( x(2), x(1) );\n average_theta = average_theta + theta;\n end\n\n average_theta = average_theta / n_sample;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Now average the angle THETA,\\n' );\n fprintf ( 1, ' which should be PI.\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Average: %f\\n', average_theta );\n\n average_phi = 0.0;\n\n for i = 1 : n_sample\n [ x, seed ] = ball_unit_sample_3d ( seed );\n r = sqrt ( sum ( x(1:dim_num).^2 ) );\n phi = acos ( x(3) / r );\n average_phi = average_phi + phi;\n end\n\n average_phi = average_phi / n_sample;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Now average the angle PHI,\\n' );\n fprintf ( 1, ' which should be PI/2.\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Average: %f\\n', average_phi );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/geometry/geometry_test007.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587905460026, "lm_q2_score": 0.8418256412990657, "lm_q1q2_score": 0.7481799388115706}} {"text": "function linplus_test525 ( )\n\n%*****************************************************************************80\n%\n%% TEST525 tests R8PP_FA, R8PP_SL.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 14 March 2009\n%\n% Author:\n%\n% John Burkardt\n%\n n = 5;\n seed = 123456789;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TEST525\\n' );\n fprintf ( 1, ' R8PP_FA factors a R8PP system,\\n' );\n fprintf ( 1, ' R8PP_SL solves a R8PP system.\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Matrix order N = %d\\n', n );\n%\n% Set the matrix.\n%\n [ a, seed ] = r8pp_random ( n, seed );\n\n r8pp_print ( n, a, ' The R8PP matrix:' );\n%\n% Set the desired solution.\n%\n x = r8vec_indicator ( n );\n\n r8vec_print ( n, x, ' The desired solution:' );\n%\n% Compute the corresponding right hand side.\n%\n b = r8pp_mxv ( n, a, x );\n\n r8vec_print ( n, b, ' The right hand side:' );\n%\n% Factor the matrix.\n%\n [ a_lu, info ] = r8pp_fa ( n, a );\n\n if ( info ~= 0 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Fatal error!\\n' );\n fprintf ( 1, ' R8PP_FA declares the matrix is singular!\\n' );\n fprintf ( 1, ' The value of INFO is %d\\n', info );\n return\n end\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' The R8PP matrix has been factored.\\n' );\n%\n% Solve the linear system.\n%\n x = r8pp_sl ( n, a_lu, b );\n \n r8vec_print ( n, x, ' Solution:' );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/linplus/linplus_test525.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995482, "lm_q2_score": 0.8418256432832332, "lm_q1q2_score": 0.748179938094616}} {"text": "function [node,elem] = cuboidmesh(cuboid,h)\n%% CUBEHEXMESH uniform mesh of cuboid\n%\n% [node,elem] = cuboidmesh([x0,x1,y0,y1,z0,z1],h) generates a uniform mesh of the\n% cuboid [x0,x1]*[y0,y1]*[z0,z1] with mesh size h.\n%\n% Example\n%\n%\n% Copyright (C) Long Chen. See COPYRIGHT.txt for details. \n\nx0 = cuboid(1); x1 = cuboid(2); \ny0 = cuboid(3); y1 = cuboid(4);\nz0 = cuboid(5); z1 = cuboid(6);\n\n[x,y,z] = meshgrid(x0:h:x1,y0:h:y1,z0:h:z1);\n\nnode = [x(:),y(:),z(:)];\n\n%% Generate elements\nnx = size(x,1) - 1; % number of cells in x-direction\nny = size(y,2) - 1; % number of cells in y-direction\nnz = size(z,2) - 1; % number of cells in z-direction\n\nelem = zeros(nx*ny*nz,8);\ncellidx = 1:nx*ny*nz;\n\n[i, j, k] = ind2sub([nx ny nz],cellidx); % index of cells in subscript form\n\ns =[ nx+1, ny+1, nz+1];\n\nelem(cellidx,1) = sub2ind3(s,i,j,k);\nelem(cellidx,2) = sub2ind3(s,i,j+1,k);\nelem(cellidx,3) = sub2ind3(s,i+1,j+1,k);\nelem(cellidx,4) = sub2ind3(s,i+1,j,k);\nelem(cellidx,5) = sub2ind3(s,i,j,k+1);\nelem(cellidx,6) = sub2ind3(s,i,j+1,k+1);\nelem(cellidx,7) = sub2ind3(s,i+1,j+1,k+1);\nelem(cellidx,8) = sub2ind3(s,i+1,j,k+1);\n\n function idx = sub2ind3(siz,i,j,k)\n nr = siz(1); nc = siz(2); nv = siz(3);\n if (max(j)>nc) || (max(i)>nr) || (max(k)>nv)\n error(message('MATLAB:mysub2ind:IndexOutOfRange'));\n end\n idx = (k-1)*nr*nc + (j-1)*nr+i;\n end\n\n\n\nend\n", "meta": {"author": "lyc102", "repo": "ifem", "sha": "29f31c812001ca8d93dad08e67208ca60e8716d4", "save_path": "github-repos/MATLAB/lyc102-ifem", "path": "github-repos/MATLAB/lyc102-ifem/ifem-29f31c812001ca8d93dad08e67208ca60e8716d4/mesh/cuboidmesh.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587817066392, "lm_q2_score": 0.8418256412990657, "lm_q1q2_score": 0.7481799313703679}} {"text": "function f=ref_idwilt(c,g,a,M)\n%REF_DWILT Reference Inverse Discrete Wilson Transform\n% Usage: f=ref_idwilt(c,g,a,M);\n%\n\n% Setup transformation matrix.\n\nL=size(g,1);\nW=size(c,2);\nN=L/a;\n\nF=zeros(L,M*N);\n\n\n\n% Weight coefficients.\n\nl=(0:L-1).';\n\npif=0;\n\nif 1\n % This version uses sines and cosines to express the basis functions.\n\n for n=0:N/2-1 \n % Do the unmodulated coefficient.\n F(:,2*M*n+1)=circshift(g,2*a*n);\n \n % Setting this to -n*a should produce a time-invariant transform.\n timeinv=0; %-n*a;\n \n % m odd case\n for m=1:2:M-1\n F(:,m+2*M*n+1) = sqrt(2)*sin(pi*m/M*(l+timeinv)+pif).*circshift(g,2*n*a);\n F(:,m+2*M*n+M+1) = sqrt(2)*cos(pi*m/M*(l+timeinv)+pif).*circshift(g,(2*n+1)*a);\n end;\n \n % m even case\n for m=2:2:M-1\n F(:,m+2*M*n+1) = sqrt(2)*cos(pi*m/M*(l+timeinv)+pif).*circshift(g,2*n*a);\n F(:,m+2*M*n+M+1) = sqrt(2)*sin(pi*m/M*(l+timeinv)+pif).*circshift(g,(2*n+1)*a);\n end;\n \n % Most modulated coefficient, Nyquest frequency.\n if mod(M,2)==0\n F(:,M+2*M*n+1)=(-1).^(l+timeinv).*circshift(g,2*n*a);\n else\n F(:,M+2*M*n+1)=(-1).^(l+timeinv).*circshift(g,(2*n+1)*a);\n end;\n end;\n\nelse\n\n % This version uses a cosine, \n\n for n=0:N/2-1 \n % Do the unmodulated coefficient.\n F(:,2*M*n+1)=circshift(g,2*a*n);\n \n timeinv=-n*a;\n \n % m odd case\n for m=1:2:M-1\n F(:,m+2*M*n+1) = sqrt(2)*cos(pi*m/M*(l+timeinv-M/2)+pif).*circshift(g,2*n*a);\n F(:,m+2*M*n+M+1) = sqrt(2)*sin(pi*m/M*(l+timeinv-M/2-a)+pif).*circshift(g,(2*n+1)*a);\n end;\n \n % m even case\n for m=2:2:M-1\n F(:,m+2*M*n+1) = sqrt(2)*cos(pi*m/M*(l+timeinv-M/2)+pif).*circshift(g,2*n*a);\n F(:,m+2*M*n+M+1) = sqrt(2)*sin(pi*m/M*(l+timeinv-M/2-a)+pif).*circshift(g,(2*n+1)*a);\n end;\n \n % Most modulated coefficient, Nyquest frequency.\n if mod(M,2)==0\n F(:,M+2*M*n+1)=(-1).^(l+timeinv).*circshift(g,2*n*a);\n else\n F(:,M+2*M*n+1)=(-1).^(l+timeinv-a).*circshift(g,(2*n+1)*a);\n end;\n end;\n\n\n\nend;\n\nf=F*c;\n\n", "meta": {"author": "ltfat", "repo": "ltfat", "sha": "4496a06ad8dddb85cd2e007216b765dc996ef327", "save_path": "github-repos/MATLAB/ltfat-ltfat", "path": "github-repos/MATLAB/ltfat-ltfat/ltfat-4496a06ad8dddb85cd2e007216b765dc996ef327/reference/ref_idwilt.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475810629193, "lm_q2_score": 0.7931059511841119, "lm_q1q2_score": 0.7481745805761376}} {"text": "function [ L, D, C, Cinv ] = get_transform_matrices_2d( R, method )\n%UNTITLED4 Summary of this function goes here\n% Detailed explanation goes here\nif method == 1\n % LDL Without the permutation\n [L, D] = ldl(R);\n C = inv(L); \n Cinv = L;\n\nelseif method == 2\n % Eigen Decomp\n [V,D] = eig(R);\n C = V.';\n Cinv = V;\n \nelseif method == 3\n % Cholesky Decomp (Special case of LDL, D=I)\n L = chol(R); % NOTE: this is the UPPER triangular transform\n L = L.';\n C = inv(L);\n Cinv = L;\n D = eye(2,2);\n\nelseif method == 4 %%% ANALYTICAL\n rho = R(1,2);\n L = [1 0; rho 1];\n D = diag([1, 1 - rho^2]);\n C = [1 0; -rho 1]; \n % C = inv(L);\n Cinv = L;\nend\n\n\nend\n\n", "meta": {"author": "jkirkby3", "repo": "PROJ_Option_Pricing_Matlab", "sha": "3859a390f395e452ad61440f95a5714dd8fb4d90", "save_path": "github-repos/MATLAB/jkirkby3-PROJ_Option_Pricing_Matlab", "path": "github-repos/MATLAB/jkirkby3-PROJ_Option_Pricing_Matlab/PROJ_Option_Pricing_Matlab-3859a390f395e452ad61440f95a5714dd8fb4d90/CTMC/Diffusion_2D/get_transform_matrices_2d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9433475746920261, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.7481745801365313}} {"text": "function R = RiemannND(x)\n% Riemann's non-differentiable function, R(x) for rational x = p/q\n\n[p,q] = rat(x);\nR = 0;\nfor k = 1:q-1\n R = R + sin(k^2*p*pi/q)/(sin(k*pi/2/q))^2;\nend\nR = R*pi/4/q/q;\nend", "meta": {"author": "vigente", "repo": "gerardus", "sha": "4d7c5195b826967781f1bb967872410e66b7cd3d", "save_path": "github-repos/MATLAB/vigente-gerardus", "path": "github-repos/MATLAB/vigente-gerardus/gerardus-4d7c5195b826967781f1bb967872410e66b7cd3d/matlab/ThirdPartyToolbox/OptiToolbox/Test Problems/Development/RiemannND.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9433475746920261, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.7481745801365313}} {"text": "function [XNorm mu stddev] = normalizeFeatures(X)\n\n% This function is used to normalize the features. It makes the mean of\n% each feature 0. Formula for normalizing feature taking all examples into\n% consideration is : [X(particular feature) - mean(of feature)]/ standard\n% deviation of feature.\n\nmu = mean(X);\nstddev = std(X);\n\nXNorm = bsxfun(@minus,X,mu); % subtract mean of each feature from original value\nXNorm = bsxfun(@rdivide,XNorm,stddev); % divide by standard deviation", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/42847-principal-component-analysis-pca/PCA/normalizeFeatures.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9343951661947455, "lm_q2_score": 0.8006920092299293, "lm_q1q2_score": 0.7481627430352045}} {"text": "%\n% Calculate the scalar multiplication of a scalar t and vector u \n%\n% Syntax: >> v = VectorScale(s,u)\n%\n% Input: t --- (numeric) the scalar\n% u --- (matrix/string/cell) a general vector that is either\n% (i) an mxn matrix, or\n% (ii) a polynomial in character string, or\n% (iii) a 1xk cell array, each u{j} is either (i) or (ii)\n%\n% Example:\n% >> v = VectorScale(3,{[1 2 3; 4 5 6], '7+8*x*y+9*z^3'});\n% >> v{:}\n% ans =\n% 3 6 9\n% 12 15 18\n% ans =\n% 21 + 24*x*y + 27*z^3\n%\n", "meta": {"author": "zarathustr", "repo": "LibQPEP", "sha": "99e5c23e746ace0bac4a86742c31db6fcf7297ba", "save_path": "github-repos/MATLAB/zarathustr-LibQPEP", "path": "github-repos/MATLAB/zarathustr-LibQPEP/LibQPEP-99e5c23e746ace0bac4a86742c31db6fcf7297ba/MATLAB/homotopy/VectorScale.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951698485602, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.748162734850865}} {"text": "% \n% Performs contour (circular) integral with\n% center x_0,y_0 and radius r, using discrete riemann approach.\n% The angs parameter specifies region of the circle\n% considering clockwise 0-2pi notation.\n% Result not normalized.\n% Author: J. Rouces\n%\nfunction sum = ContourIntegralCircular(imagen,y_0,x_0,r,angs)\n\n% EXHAUSTIVE EXTENSIVE ALGORITHM\n% rc = r^2;\n% sum = 0;\n% for x = max(1,x_0-r):min(size(imagen,2),x_0+r)\n% for y = max(1,y_0-r):min(size(imagen,1),y_0+r)\n% if abs((x-x_0)^2+(y-y_0)^2-rc)<2\n% sum = sum + imagen(y,x);\n% end\n% end\n% end\n% sum = sum/r;\n\n% LIGHT ALGORITHM\nsum = 0;\nfor ang = angs\n y = round(y_0-cos(ang)*r);\n x = round(x_0+sin(ang)*r);\n if y<1\n y = 1;\n elseif y>size(imagen,1)\n y = size(imagen,1);\n end\n if x<1\n x = 1;\n elseif x>size(imagen,2)\n x = size(imagen,2);\n end\n sum = sum + imagen(y,x);\nend", "meta": {"author": "Qingbao", "repo": "iris", "sha": "bb6b58b58fc0b517f53f6a6084066af127c13c47", "save_path": "github-repos/MATLAB/Qingbao-iris", "path": "github-repos/MATLAB/Qingbao-iris/iris-bb6b58b58fc0b517f53f6a6084066af127c13c47/Daugman/ContourIntegralCircular.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625031628428, "lm_q2_score": 0.8031737963569016, "lm_q1q2_score": 0.748126274829403}} {"text": " function y = jinc(x)\n%function y = jinc(x)\n% jinc(x) = J_1(pi x) / (2 x),\n% where J_1 is Bessel function of the first kind of order 1.\n% This is the 2D Fourier transform of a disk of diameter 1,\n% so its DC value is the area of that disk which is pi/4.\n% Equivalently it is the Hankel transform of rect = @(r) abs(r) < 1/2;\n% Jeff Fessler, University of Michigan\n\nx = abs(x); % kludge for bessel with negative arguments, perhaps not needed\ny = pi/4 + 0 * x; % jinc(0) = pi/4\nig = x ~= 0;\ny(ig) = besselj(1, pi * x(ig)) ./ (2 * x(ig));\n", "meta": {"author": "JeffFessler", "repo": "mirt", "sha": "b7f36cc46916821e8bc8502301b1554ebc7efe1d", "save_path": "github-repos/MATLAB/JeffFessler-mirt", "path": "github-repos/MATLAB/JeffFessler-mirt/mirt-b7f36cc46916821e8bc8502301b1554ebc7efe1d/utilities/jinc.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9099070109242131, "lm_q2_score": 0.8221891283434876, "lm_q1q2_score": 0.748115652185407}} {"text": "function Y = symNormalRnd(M, S, sz)\n\n% Generates independent symmetric matrices\n% according to a matrix-variate symmetric normal distribution.\n%\n% Y = symNormalRnd(M, S, sz)\n%\n%\n% Input:\n% M pxp mean symmetric matrix\n% S qxq covariance matrix\n% sz size of the array (e.g. number of samples)\n%\n% Output:\n% Y pxpx[sz] array of random symmetric matrices.\n%\n% Copyright: Armin Schwartzman, 2009\n%\n\n% HISTORY:\n% 2008.12.30 ASH (armins@hsph.harvard.edu) wrote it.\n\n% Check inputs\nif (size(M,1) ~= size(M,2)),\n error('Wrong input format');\nend\nif (size(S,1) ~= size(S,2)),\n error('Wrong input format');\nend\np = size(M,1);\nq = p*(p+1)/2;\nif (size(S,1) ~= q),\n error('Wrong input format');\nend\nif ~exist('sz'),\n sz = 1;\nend\n\n%-----------------------------------------------------------------\n% Generate multivariate normal\nN = prod(sz); % number of samples\nz = mvnrnd(zeros(1,q), S, N); % size Nxq\nz = reshape(z', [q sz]); % size qxN\nY = repmat(M, [1 1 sz]) + vecdinv(z);\n\nreturn\n", "meta": {"author": "vistalab", "repo": "vistasoft", "sha": "7f0102c696c091c858233340cc7e1ab02f064d4c", "save_path": "github-repos/MATLAB/vistalab-vistasoft", "path": "github-repos/MATLAB/vistalab-vistasoft/vistasoft-7f0102c696c091c858233340cc7e1ab02f064d4c/mrDiffusion/statistics/symNormalRnd.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070060380481, "lm_q2_score": 0.8221891283434876, "lm_q1q2_score": 0.7481156481680552}} {"text": "function [ average, sd, covc ] = covariance ( dim_num, point_num, x )\n\n%*****************************************************************************80\n%\n%% COVARIANCE does a covariance calculation for IHS solutions.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 02 April 2003\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer DIM_NUM, the spatial dimension.\n%\n% Input, integer POINT_NUM, the number of points to be generated.\n%\n% Input, integer X(DIM_NUM,POINT_NUM), the points.\n%\n% Output, real AVERAGE, the average minimum distance.\n%\n% Output, real SD, the standard deviation of the minimum distances.\n%\n% Output, real COVC, the covariance of the minimum distances.\n%\n\n%\n% Set up the distance matrix.\n%\n for i = 1 : point_num\n mindist(i) = realmax;\n for j = 1 : point_num\n if ( i ~= j )\n vec(1:dim_num) = x(1:dim_num,i) - x(1:dim_num,j);\n dist = sqrt ( vec(1:dim_num) * vec(1:dim_num)' );\n if ( dist < mindist(i) )\n mindist(i) = dist;\n end\n end\n end\n end\n%\n% Find the average minimum distance.\n%\n average = sum ( mindist(1:point_num) ) / point_num;\n%\n% Compute the standard deviation of the distances.\n%\n sd = std ( mindist(1:point_num) );\n%\n% Compute the covariance.\n%\n covc = sd / average;\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/ihs/covariance.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391558355999, "lm_q2_score": 0.8104789063814617, "lm_q1q2_score": 0.7481037655689046}} {"text": "function [ssarr, l_arr, cu_arr]=refparams_vecgsm(org,subands,M)\n\n%This function computes the parameters of the reference image. This is\n%called by vifvec.m.\n\nfor i=1:length(subands);\n sub=subands(i);\n y=org{sub};\n \n sizey=floor(size(y)./M)*M; % crop to exact multiple size\n y=y(1:sizey(1),1:sizey(2));\n \n \n % Collect MxM blocks. Rearrange each block into an\n % M^2 dimensional vector and collect all such vectors.\n % Collece ALL possible MXM blocks (even those overlapping) from the subband\n temp=[];\n for j=1:M\n for k=1:M\n temp=cat(1,temp,reshape(y(k:end-(M-k), j:end-(M-j)),1,[]));\n end\n end\n \n % estimate mean and covariance\n mcu=mean(temp')';\n cu=((temp-repmat(mcu,1,size(temp,2)))*(temp-repmat(mcu,1,size(temp,2)))')./size(temp,2); % covariance matrix for U\n \n % Collect MxM blocks as above. Use ONLY non-overlapping blocks to\n % calculate the S field\n temp=[];\n for j=1:M\n for k=1:M\n temp=cat(1,temp,reshape(y(k:M:end, j:M:end),1,[]));\n end\n end\n\n % Calculate the S field\n ss=(inv(cu)*temp);\n ss=sum(ss.*temp)./(M*M);\n ss=reshape(ss,sizey/M);\n \n % Eigen-decomposition\n [v,d]=eig(cu);\n l_arr(sub,:)=diag(d)';\n \n % rearrange for output\n ssarr{sub}=ss;\n temp=0;\n d=diag(d);\n cu_arr{sub}=cu;\nend \n\n", "meta": {"author": "jbhuang0604", "repo": "SelfExSR", "sha": "8f6dd8c1d20cb7e8792a7177b4f6fd677633f598", "save_path": "github-repos/MATLAB/jbhuang0604-SelfExSR", "path": "github-repos/MATLAB/jbhuang0604-SelfExSR/SelfExSR-8f6dd8c1d20cb7e8792a7177b4f6fd677633f598/quant_eval/ifcvec_release/refparams_vecgsm.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361604769414, "lm_q2_score": 0.8198933425148213, "lm_q1q2_score": 0.7481003334448294}} {"text": "function res = bhp(im,thresh,n)\n\n% inputs\n% im is the fourier transform of the image\n% thresh is the cutoff circle radius\n\n%outputs\n% res is the filtered image\n\n[r,c]=size(im);\nd0=thresh;\n\nd=zeros(r,c);\nh=zeros(r,c);\n\nfor i=1:r\n for j=1:c\n d(i,j)= sqrt( (i-(r/2))^2 + (j-(c/2))^2);\n end\nend\n\nfor i=1:r\n for j=1:c\n h(i,j)= 1 / (1+ (d0/d(i,j))^(2*n) ) ;\n end\nend\n\n\nfor i=1:r\n for j=1:c\n res(i,j)=(h(i,j))*im(i,j);\n\n end\nend\n\n\n\n\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/40579-frequency-domain-filtering-for-grayscale-images/freqfilters/bhp.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9124361604769413, "lm_q2_score": 0.8198933271118222, "lm_q1q2_score": 0.7481003193905759}} {"text": "function value = p27_f ( dim_num, point_num, x )\n\n%*****************************************************************************80\n%\n%% P27_F evaluates the integrand for problem 27.\n%\n% Dimension:\n%\n% N arbitrary.\n%\n% Region:\n%\n% 0 <= X(1:DIM_NUM) <= 1\n%\n% Integral Parameters:\n%\n% The integral depends on a parameter R and vector C(1:N).\n%\n% R defaults to 0.3.\n%\n% The reference suggests choosing C at random in [0,1]\n% and then multiplying by the normalizing factor (25/N).\n% C(1:N) defaults to 1/N.\n%\n% To get or set R, call P27_R8.\n% To get or set C, call P27_R8VEC.\n%\n% Integrand:\n%\n% cos ( 2 * pi * R + sum ( c(1:n) * x(1:n) ) )\n%\n% Exact Integral:\n%\n% 2^N * cos ( 2 * pi * R + 0.5 * sum ( c(1:n) ) )\n% * product ( sin ( 0.5 * c(1:n) ) / c(1:n) )\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 28 November 2011\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Alan Genz,\n% [Integral #1]\n% A Package for Testing Multiple Integration Subroutines,\n% in Numerical Integration: Recent Developments, Software\n% and Applications,\n% edited by Patrick Keast and Graeme Fairweather,\n% D Reidel, 1987, pages 337-340,\n% LC: QA299.3.N38.\n%\n% Thomas Patterson,\n% [Integral #5],\n% On the Construction of a Practical Ermakov-Zolotukhin \n% Multiple Integrator,\n% in Numerical Integration: Recent Developments, Software\n% and Applications,\n% edited by Patrick Keast and Graeme Fairweather,\n% D. Reidel, 1987, pages 269-290,\n% LC: QA299.3.N38.\n%\n% Parameters:\n%\n% Input, integer DIM_NUM, the dimension of the argument.\n%\n% Input, integer POINT_NUM, the number of points.\n%\n% Input, real X(DIM_NUM,POINT_NUM), the evaluation points.\n%\n% Output, real VALUE(POINT_NUM), the integrand values.\n%\n r = 0.0;\n r = p27_r8 ( 'G', 'R', r );\n\n c = [];\n c = p27_r8vec ( 'G', 'C', dim_num, c );\n\n value(1:point_num) = 0.0;\n\n for point = 1 : point_num\n\n arg = 2.0 * pi * r + c(1:dim_num,1)' * x(1:dim_num,point);\n value(point) = cos ( arg );\n\n end\n\n p27_i4 ( 'I', '#', point_num );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/quadrature_test/p27_f.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772286044094, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.7480799954253174}} {"text": "function zeta_test ( )\n\n%*****************************************************************************80\n%\n%% ZETA_TEST tests ZETA.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 06 October 2005\n%\n% Author:\n%\n% John Burkardt\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'ZETA_TEST\\n' );\n fprintf ( 1, ' ZETA evaluates the Riemann Zeta function.\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' N Zeta Zeta\\n' );\n fprintf ( 1, ' exact computed\\n' );\n fprintf ( 1, '\\n' );\n\n n_data = 0;\n\n while ( 1 )\n\n [ n_data, n, z1 ] = zeta_values ( n_data );\n\n if ( n_data == 0 )\n break\n end\n\n z2 = zeta ( n );\n\n fprintf ( 1, ' %6d %20e %20e\\n', n, z1, z2 );\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/polpak/zeta_test.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8740772220439509, "lm_q2_score": 0.8558511396138365, "lm_q1q2_score": 0.7480799865968117}} {"text": "function y = sigmoidabTransform(x, transform, varargin)\n\n% SIGMOIDABTRANSFORM Constrains a parameter to be between A and B\n% by a scaled logistic sigmoid function.\n%\n% FORMAT\n%\n% DESC contains commands to constrain parameters to be between A\n% and B via the sigmoid function, y=A+(B-A)/(1+exp(-x)).\n%\n% ARG x : input argument.\n%\n% ARG transform : type of transform, 'atox' maps a value into\n% the transformed space (i.e. makes it between A and B). 'xtoa' \n% maps the parameter back from transformed space to the original\n% space. 'gradfact' gives the factor needed to correct gradients\n% with respect to the transformed parameter, that is, it gives\n% the gradient dx/da where x is the transformed parameter and a\n% is the untransformed parameter.\n%\n% ARG transformsettings (first element of varargin): vector [A B] \n% giving the minimum and maximum values A and B for the transformed \n% parameter. If not given, assume A=0 and B=1 as in the function \n% sigmoidTransform.\n%\n% OUTPUT y : return argument.\n% \n% SEEALSO : negLogLogitTransform, expTransform\n%\n% COPYRIGHT : Neil D. Lawrence, 2004, 2005, 2006, 2007\n%\n% COPYRIGHT : Jaakko Peltonen, 2011\n%\n% COPYRIGHT : Antti Honkela, 2012\n\n% OPTIMI\n\n\n% Get the transformation settings from the varargin structure\nif ~isempty(varargin),\n transformsettings=varargin{1};\nelse\n transformsettings=[];\nend;\n\n\nidentitymode=0;\nif identitymode==1,\n % DEBUG ONLY, turns transformation to identity!\n fprintf(1,'Using identity mode for transform %s of parameter value %f\\n',transform, x)\n switch transform\n case 'atox'\n y=x;\n case 'xtoa'\n y=x;\n case 'gradfact'\n y=0*x+1;\n end\nelse\n % normal mode, logistic sigmoid between A and B\n \n if isempty(transformsettings),\n warning(sprintf('sigmoidabTransform(%f,%s) called without transformation settings\\n',x,transform));\n A=0; B=1;\n else\n A=transformsettings(1);\n B=transformsettings(2);\n end;\n \n limVal = 36;\n minval_sigmoid=A+(B-A)*eps;\n maxval_sigmoid=A+(B-A)*(1-eps);\n \n y = zeros(size(x));\n switch transform\n case 'atox'\n %x\n %A\n %B\n %fprintf(1,'transforming x %f, A %f, B %f\\n',x,A,B);\n \n I1 = x < -limVal;\n y(I1) = A+(B-A)*eps;\n\n I2 = x > limVal;\n y(I2) = A+(B-A)*(1-eps);\n \n I3 = ~I1 & ~I2;\n y(I3) = A+(B-A)*sigmoid(x(I3));\n \n case 'xtoa'\n % [x A B]\n %fprintf(1,'inverse-transforming x %f, A %f, B %f\\n',x,A,B);\n I1 = x<=minval_sigmoid;\n y(I1) = -limVal;\n \n I2 = x>=maxval_sigmoid;\n y(I2) = limVal;\n\n I3 = ~I1 & ~I2;\n y(I3) = invSigmoid((x(I3)-A)/(B-A));\n \n \n case 'gradfact'\n %fprintf(1,'gradfact-transforming x %f, A %f, B %f\\n',x,A,B);\n %y = (B-A)*x.*(1-x);\n y = (x-A).*(B-x)/(B-A);\n %y=0*x+1; % DEBUG ONLY, turns factors off!\n end\nend;\n\n \n", "meta": {"author": "SheffieldML", "repo": "GPmat", "sha": "4b5914a38ecbad9fb7a13a3392970bfc28c9d911", "save_path": "github-repos/MATLAB/SheffieldML-GPmat", "path": "github-repos/MATLAB/SheffieldML-GPmat/GPmat-4b5914a38ecbad9fb7a13a3392970bfc28c9d911/optimi/sigmoidabTransform.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813454, "lm_q2_score": 0.8333246015211008, "lm_q1q2_score": 0.7480715761443406}} {"text": "function w = ymdf_to_weekday_julian2 ( y, m, d, f )\n\n%*****************************************************************************80\n%\n%% YMDF_TO_WEEKDAY_JULIAN2 returns the weekday of a Julian YMDF date.\n%\n% Discussion:\n%\n% This routine computes the day of the week from the date in\n% the Julian calendar, that is, the calendar in force before the\n% Gregorian calendar, in which every fourth year was a leap year.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 18 March 2013\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Edward Richards,\n% Algorithm A,\n% Mapping Time, The Calendar and Its History,\n% Oxford, 1999, pages 307-308.\n%\n% Parameters:\n%\n% Input, integer Y, M, D, real F, the YMDF date.\n%\n% Output, integer W, the day of the week of the date.\n% The days are numbered from Sunday through Saturday, 1 through 7.\n%\n m_prime = mod ( 9 + m, 12 );\n q = floor ( m_prime / 10 );\n z = floor ( ( 13 * m_prime + 2 ) / 5 );\n t = 28 * m_prime + z + d - 365 * q + 59;\n\n c = i4_wrap ( t, 1, 7 );\n\n y_prime = y - q;\n v = floor ( y / 4 ) - floor ( y_prime / 4 );\n p = y + floor ( y / 4 ) + 4 - v;\n n = 7 - mod ( p, 7 );\n\n w = i4_wrap ( c + 1 - n, 1, 7 );\n\n return\nend", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/calpak/ymdf_to_weekday_julian2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695283896349, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.7480715628823433}} {"text": "function value = c8_log ( z )\n\n%*****************************************************************************80\n%\n%% C8_LOG evaluates the logarithm of a C8.\n%\n% Discussion:\n%\n% A C8 is a complex value.\n%\n% Here we use the relationship:\n%\n% C8_LOG ( Z ) = LOG ( MAG ( Z ) ) + i * ARG ( Z )\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 11 February 2015\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, complex Z, the argument.\n%\n% Output, complex VALUE, the function value.\n%\n arg = c8_arg ( z );\n mag = c8_mag ( z );\n\n value = log ( mag ) + arg * i;\n \n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/c8lib/c8_log.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8976952811593495, "lm_q2_score": 0.8333245891029456, "lm_q1q2_score": 0.7480715513117682}} {"text": "function KeplerUniversalVsSTK()\n%% Constants\nmu = 398600.4418;\n\n%% Polar GEO Altitude Orbit Propagation Comparison\nload('PolarGEO.mat');\nr0 = repmat(PosVel(1,1:3)',[1 size(PosVel,1)]);\nv0 = repmat(PosVel(1,4:6)',[1 size(PosVel,1)]);\n[r,v] = keplerUniversal(r0,v0,0:60:(size(PosVel,1)-1)*60,mu);\nPlotStateVectorErrors(r,v,PosVel,0:60:(size(PosVel,1)-1)*60,'GEO Altitude, Polar Inclination Propagation');\n\n%% LEO Orbit Propagation Comparison\nload('InclinedLEO.mat');\nr0 = repmat(PosVel(1,1:3)',[1 size(PosVel,1)]);\nv0 = repmat(PosVel(1,4:6)',[1 size(PosVel,1)]);\n[r,v] = keplerUniversal(r0,v0,0:60:(size(PosVel,1)-1)*60,mu);\nPlotStateVectorErrors(r,v,PosVel,0:60:(size(PosVel,1)-1)*60,'LEO Inclined Propagation');\n\n%% Hyperbolic LEO Altitude Orbit Propagtion Comparison\nload('HyperbolicLEO.mat');\nr0 = repmat(PosVel(1,1:3)',[1 size(PosVel,1)]);\nv0 = repmat(PosVel(1,4:6)',[1 size(PosVel,1)]);\n[r,v] = keplerUniversal(r0,v0,0:60:(size(PosVel,1)-1)*60,mu);\nPlotStateVectorErrors(r,v,PosVel,0:60:(size(PosVel,1)-1)*60,'Hyperbolic Orbit Propagation');\n\n%% Parabolic LEO Altitude Orbit Propagation comparison\nload('ParabolicLEO.mat');\nr0 = repmat(PosVel(1,1:3)',[1 size(PosVel,1)]);\nv0 = repmat(PosVel(1,4:6)',[1 size(PosVel,1)]);\n[r,v] = keplerUniversal(r0,v0,0:60:(size(PosVel,1)-1)*60,mu);\nPlotStateVectorErrors(r,v,PosVel,0:60:(size(PosVel,1)-1)*60,'Parabolic Orbit Propagation');\n\nend\n\nfunction PlotStateVectorErrors(r,v,PosVel,t,titleText)\nMaxPositionError = abs(r-PosVel(:,1:3)');\nMaxVelocityError = abs(v-PosVel(:,4:6)');\nfigure('color',[1 1 1]);\nsubplot(4,1,1); plot(t./60,MaxPositionError); title(titleText); ylabel('Pos Err (km)');\nsubplot(4,1,2); plot(t./60,MaxVelocityError); ylabel('Vel Err (km/s)'); \nsubplot(4,1,3); plot(t./60,abs(sqrt(sum(r.^2,1)) - sqrt(sum(PosVel(:,1:3)'.^2,1)))); ylabel('Pos Mag Err (km)'); xlabel('Time (m)');\nsubplot(4,1,4); plot(t./60,abs(sqrt(sum(v.^2,1)) - sqrt(sum(PosVel(:,4:6)'.^2,1)))); ylabel('Vel Mag Err (km/s)'); xlabel('Time (m)');\nend", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/35566-vectorized-analytic-two-body-propagator-kepler-universal-variables/KeplerUniversalVsSTK.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107843878721, "lm_q2_score": 0.7981867753392728, "lm_q1q2_score": 0.7480692538037461}} {"text": "function eg2OC_BVP\n%EG2OC_BVP Example 2 of optimal control tutorial.\n% This example is from D.E.Kirk's Optimal control theory: an introduction\n% example 6.2-2 on page 338-339\n% The problem is reformulated as a boundary value problem (BVP)\n% and solved with bvp4c solver\n\n% Initial guess for the solution\nsolinit = bvpinit(linspace(0,0.78,50), [0 0 0.5 0.5]);\noptions = bvpset('Stats','on','RelTol',1e-1);\nglobal R;\nR = 0.1;\nsol = bvp4c(@BVP_ode, @BVP_bc, solinit, options);\nt = sol.x;\ny = sol.y;\n\n% Calculate u(t) from x1,x2,p1,p2\nut = (y(3,:).*(y(1,:) + 1/4))/(2*0.1);\nn = length(t);\n% Calculate the cost\nJ = 0.78*(y(1,:)*y(1,:)' + y(2,:)*y(2,:)' + ut*ut'*0.1)/n;\n\nfigure(1);\nplot(t, y(1:2,:)','-');hold on;\nplot(t,ut', 'r:')\ntext(.2,0.08,'x_1(t)');\ntext(.3,-.1,'x_2(t)');\ntext(.2,.4, 'u(t)');\ns = strcat('Final cost is: J=',num2str(J));\ntext(.4,1,s);\nxlabel('time');\nylabel('states');\nhold off;\nprint -djpeg90 -r300 eg2_bvp.jpg\n\n%------------------------------------------------\n% ODE's for states and costates\nfunction dydt = BVP_ode(t,y)\nglobal R;\nt1 = y(1)+.25;\nt2 = y(2)+.5;\nt3 = exp(25*y(1)/(y(2)+2));\nt4 = 50/(y(1)+2)^2;\nu = y(3)*t1/(2*R);\n\ndydt = [-2*t1+t2*t3-t2*u\n 0.5-y(2)-t2*t3\n -2*y(1)+2*y(3)-y(3)*t2*t4*t3+y(3)*u+y(4)*t2*t4*t3\n -2*y(2)-y(3)*t3+y(4)*(1+t3)];\n\n% -----------------------------------------------\n% The boundary conditions:\n% x1(0) = 0.05, x2(0) = 0, tf = 0.78, p1(tf) = 0, p2(tf) = 0;\nfunction res = BVP_bc(ya,yb)\nres = [ ya(1) - 0.05\n ya(2) - 0\n yb(3) - 0\n yb(4) - 0 ];\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/25889-an-optimal-control-tutorial-for-beginners/eg2OC_BVP.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122163480667, "lm_q2_score": 0.824461932846258, "lm_q1q2_score": 0.7480443835853493}} {"text": "%EUL2TR Convert Euler angles to homogeneous transform\n%\n% T = EUL2TR(PHI, THETA, PSI, OPTIONS) is an SE(3) homogeneous\n% transformation matrix (4x4) with zero translation and rotation equivalent\n% to the specified Euler angles. These correspond to rotations about the Z,\n% Y, Z axes respectively. If PHI, THETA, PSI are column vectors (Nx1) then\n% they are assumed to represent a trajectory and R is a three-dimensional\n% matrix (4x4xN), where the last index corresponds to rows of PHI, THETA,\n% PSI.\n%\n% R = EUL2R(EUL, OPTIONS) as above but the Euler angles are taken from the\n% vector (1x3) EUL = [PHI THETA PSI]. If EUL is a matrix (Nx3) then R is a\n% three-dimensional matrix (4x4xN), where the last index corresponds to\n% rows of RPY which are assumed to be [PHI,THETA,PSI].\n%\n% Options::\n% 'deg' Angles given in degrees (radians default)\n%\n% Note::\n% - The vectors PHI, THETA, PSI must be of the same length.\n% - The translational part is zero.\n%\n% See also EUL2R, RPY2TR, TR2EUL, SE3.eul.\n\n% Copyright (C) 1993-2019 Peter I. Corke\n%\n% This file is part of The Spatial Math Toolbox for MATLAB (SMTB).\n% \n% Permission is hereby granted, free of charge, to any person obtaining a copy\n% of this software and associated documentation files (the \"Software\"), to deal\n% in the Software without restriction, including without limitation the rights\n% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies\n% of the Software, and to permit persons to whom the Software is furnished to do\n% so, subject to the following conditions:\n%\n% The above copyright notice and this permission notice shall be included in all\n% copies or substantial portions of the Software.\n%\n% THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR \n% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\n% FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n% COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\n% IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n% CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n%\n% https://github.com/petercorke/spatial-math\n\nfunction T = eul2tr(phi, varargin)\n\n R = eul2r(phi, varargin{:});\n T = r2t(R);\n", "meta": {"author": "petercorke", "repo": "spatialmath-matlab", "sha": "6eeff4a79f14286705560b84f1fe72e0b7e0e7f7", "save_path": "github-repos/MATLAB/petercorke-spatialmath-matlab", "path": "github-repos/MATLAB/petercorke-spatialmath-matlab/spatialmath-matlab-6eeff4a79f14286705560b84f1fe72e0b7e0e7f7/eul2tr.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122188543453, "lm_q2_score": 0.824461928533133, "lm_q1q2_score": 0.7480443817383297}} {"text": "function f = tt_loglikelihood(X,M)\n%TT_LOGLIKELIHOOD Compute log-likelihood of data X with model M.\n%\n% F = TT_LOGLIKELIHOOD(X,M) computes the log-likelihood of model M given\n% data X, where M is a ktensor and X is a tensor or sptensor.\n% Specifically, F = - (sum_i m_i - x_i * log_i) where i is a multiindex\n% across all tensor dimensions.\n%\n% See also cp_apr, tensor, sptensor, ktensor.\n%\n%MATLAB Tensor Toolbox.\n%Copyright 2012, Sandia Corporation.\n\n% This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others.\n% http://www.sandia.gov/~tgkolda/TensorToolbox.\n% Copyright (2012) Sandia Corporation. Under the terms of Contract\n% DE-AC04-94AL85000, there is a non-exclusive license for use of this\n% work by or on behalf of the U.S. Government. Export of this data may\n% require a license from the United States Government.\n% The full license terms can be found in the file LICENSE.txt\n\nN = ndims(X);\n\nif ~isa(M, 'ktensor')\n error('M must be a ktensor');\nend\n\nM = normalize(M,1,1);\n\nif isa(X, 'sptensor')\n xsubs = X.subs;\n A = M.U{1}(xsubs(:,1),:);\n for n = 2:N\n A = A .* M.U{n}(xsubs(:,n),:); \n end\n f = sum(X.vals .* log(sum(A,2))) - sum(sum(M.U{1}));\nelse\n f = sum(sum(double(tenmat(X,1)) .* log(double(tenmat(M,1))))) - sum(sum(M.U{1}));\nend\n\n\n", "meta": {"author": "andrewssobral", "repo": "mtt", "sha": "0152a77df09f24af4c294f46845931e4e0e63b55", "save_path": "github-repos/MATLAB/andrewssobral-mtt", "path": "github-repos/MATLAB/andrewssobral-mtt/mtt-0152a77df09f24af4c294f46845931e4e0e63b55/libs/tensor_toolbox_2.5/tt_loglikelihood.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122163480667, "lm_q2_score": 0.8244619220634456, "lm_q1q2_score": 0.7480443738019719}} {"text": "function [ n_data, x, fx ] = elliptic_ka_values ( n_data )\n\n%*****************************************************************************80\n%\n%% ELLIPTIC_KA_VALUES returns values of the complete elliptic integral K(ALPHA).\n%\n% Discussion:\n%\n% This is one form of what is sometimes called the complete elliptic integral\n% of the first kind.\n%\n% The function is defined by the formula:\n%\n% K(ALPHA) = integral ( 0 <= T <= PI/2 ) \n% dT / sqrt ( 1 - sin ( ALPHA )^2 * sin ( T )^2 )\n%\n% In Mathematica, the function can be evaluated by:\n%\n% EllipticK[(Sin[alpha*Pi/180])^2]\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 16 September 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Milton Abramowitz and Irene Stegun,\n% Handbook of Mathematical Functions,\n% US Department of Commerce, 1964.\n%\n% Stephen Wolfram,\n% The Mathematica Book,\n% Fourth Edition,\n% Wolfram Media / Cambridge University Press, 1999.\n%\n% Parameters:\n%\n% Input/output, integer N_DATA. The user sets N_DATA to 0 before the\n% first call. On each call, the routine increments N_DATA by 1, and\n% returns the corresponding data; when there is no more data, the\n% output value of N_DATA will be 0 again.\n%\n% Output, real X, the argument of the function, measured \n% in degrees.\n%\n% Output, real FX, the value of the function.\n%\n n_max = 18;\n\n fx_vec = [ ...\n 0.1570796326794897E+01, ...\n 0.1573792130924768E+01, ...\n 0.1582842804338351E+01, ...\n 0.1598142002112540E+01, ...\n 0.1620025899124204E+01, ...\n 0.1648995218478530E+01, ...\n 0.1685750354812596E+01, ...\n 0.1731245175657058E+01, ...\n 0.1786769134885021E+01, ...\n 0.1854074677301372E+01, ...\n 0.1935581096004722E+01, ...\n 0.2034715312185791E+01, ...\n 0.2156515647499643E+01, ...\n 0.2308786798167196E+01, ...\n 0.2504550079001634E+01, ...\n 0.2768063145368768E+01, ...\n 0.3153385251887839E+01, ...\n 0.3831741999784146E+01 ];\n\n x_vec = [ ...\n 0.0E+00, ...\n 5.0E+00, ... \n 10.0E+00, ...\n 15.0E+00, ...\n 20.0E+00, ...\n 25.0E+00, ...\n 30.0E+00, ...\n 35.0E+00, ...\n 40.0E+00, ...\n 45.0E+00, ...\n 50.0E+00, ...\n 55.0E+00, ...\n 60.0E+00, ...\n 65.0E+00, ...\n 70.0E+00, ...\n 75.0E+00, ...\n 80.0E+00, ...\n 85.0E+00 ];\n\n if ( n_data < 0 )\n n_data = 0;\n end\n\n n_data = n_data + 1;\n\n if ( n_max < n_data )\n n_data = 0;\n x = 0.0;\n fx = 0.0;\n else\n x = x_vec(n_data);\n fx = fx_vec(n_data);\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_values/elliptic_ka_values.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122163480667, "lm_q2_score": 0.8244619220634456, "lm_q1q2_score": 0.7480443738019719}} {"text": "function y = entr( x )\n\n%ENTR Scalar entropy.\n% ENTR(X) returns an array of the same size as X with the unnormalized\n% entropy function applied to each element:\n% { -X.*LOG(X) if X > 0,\n% ENTR(X) = { 0 if X == 0,\n% { -Inf otherwise.\n% If X is a vector representing a discrete probability distribution, then\n% SUM(ENTR(X)) returns its entropy.\n%\n% Disciplined convex programming information:\n% ENTR(X) is concave and nonmonotonic in X. Thus when used in CVX\n% expressions, X must be real and affine. Its use will effectively \n% constrain X to be nonnegative: there is no need to add an\n% additional X >= 0 to your model in order to enforce this.\n\nerror(nargchk(1,1,nargin));\ncvx_expert_check( 'entr', x );\ny = -rel_entr( x, 1 );\n\n% Copyright 2010 Michael C. Grant and Stephen P. Boyd.\n% See the file COPYING.txt for full copyright information.\n% The command 'cvx_where' will show where this file is located.\n", "meta": {"author": "goodshawn12", "repo": "REST", "sha": "e34ce521fcb36e7813357a9720072dd111edf797", "save_path": "github-repos/MATLAB/goodshawn12-REST", "path": "github-repos/MATLAB/goodshawn12-REST/REST-e34ce521fcb36e7813357a9720072dd111edf797/dependencies/BCILAB/dependencies/cvx-1.21.b795/functions/entr.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9149009642742805, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.7479996827355838}} {"text": "function r8po_print ( n, a, title )\n\n%*****************************************************************************80\n%\n%% R8PO_PRINT prints a R8PO matrix.\n%\n% Discussion:\n%\n% The R8PO storage format is appropriate for a symmetric positive definite \n% matrix and its inverse. (The Cholesky factor of an SPO matrix is an\n% upper triangular matrix, so it will be in R8GE storage format.)\n%\n% Only the diagonal and upper triangle of the square array are used.\n% This same storage scheme is used when the matrix is factored by\n% R8PO_FA, or inverted by R8PO_INVERSE. For clarity, the lower triangle\n% is set to zero.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 07 April 2006\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the order of the matrix.\n%\n% Input, real A(N,N), the R8PO matrix.\n%\n% Input, string TITLE, a title to be printed.\n%\n r8po_print_some ( n, a, 1, 1, n, n, title );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/linplus/r8po_print.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9149009549929797, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.7479996690474497}} {"text": "function [x] = gels(a,b,param)\n%\n% GELS Solves an overdetermined or underdetermined linear problem.\n%\n% [X] = GELS(A,B) same as [X] = GELS(A,B,'default') \n%\n% [X] = GELS(A,B,PARAM) if A is m-by-n and m > n then GELS computes the solution of the\n% linear least squares problem\n% min || A * X - B ||_F ,\n% if A is m-by-n and m < n then GELS computes the solution of the minimum norm problem\n% min || X ||_F s.t. A*X = B\n% PARAM controls the algorithm used:\n%\t\n% 'dc'\n% performs SVD factorization of A using the divide and conquer\n% method then solve the undetermined or overdetermined problem.\n% calls LAPACK routine _GELSD\n%\n% 'svd'\n% performs SVD factorization of A using QR iterations then solve the\n% undetermined or overdetermined problem.\n% calls LAPACK routine _GELSS\n%\n% 'y'\n% performs QR factorization of A then solve the undetermined or\n% overdetermined problem.\n% calls LAPACK routine _GELSY\n%\n% 'default'\n% (default)\n% performs QR factorization of A without pivoting, then solve the\n% undetermined or overdetermined problem. The fact that there is no\n% pivoting in the QR factorization means that A(:,1:min(size(A))\n% needs to be full rank.\n% calls LAPACK routine _GELS\n%\n% When A is m-by-n with m > n then [X] = GELS(A,B) is the same as X=A\\B.\n%\n% When A is m-by-n with m < n then [X] = GELS(A,B,PARAM) is _not_ the same as\n% X=A\\B. [X] = GELS(A,B,PARAM) solves the problem\n% (*) min_X || X ||_F s.t. AX=B\n% while X=A\\B solves AX=B by first performing a QR factorization of A\n% [Q,R,E] = QR(A)\n% then X is obtained via\n% X = E(:,1:m)*(R(:,1:m)\\(Q'*b))] \n%\tThe \\ method is faster than GELS, X is such that AX=B but X is not (in the\n%\tgeneral case) the solution of (*).\n%\n% See also: \\, MLDIVIDE.\n%\n\tx=[];\n\t\n\n\tif (nargout~=1),\n\t\tdisp('Wrong number of output parameters');\n\t\treturn;\n\tend;\n\n\tif (nargin~=2 && nargin~=3),\n\t\tdisp('Wrong number of input parameters');\n\t\treturn;\n\tend;\n\t\n\t%Do all the boring checking\n\tif (~isnumeric(a)),\n\t\tdisp('The matrix is not composed of numeric values.');\n\t\treturn;\n\telseif (isinteger(a)),\n\t\ta=double(a);\n\tend;\n\n\tif ((nargin == 2)||(strcmp(param,'default'))),\n\t\ttrans = 'N';\n\t\t[x,info] = gels_2(trans,a,b);\n\telse\n\t\tif (strcmp(param,'dc')),\n\t\t\trcond = -1; % machine precision\n\t\t\t[x,rank,info] = gelsd(a,b,rcond);\n\t\telseif (strcmp(param,'svd')),\n\t\t\trcond = -1; % machine precision\n\t\t\t[x,rank,info] = gelss(a,b,rcond);\n\t\telseif (strcmp(param,'y')),\n\t\t\trcond = eps; % machine precision\n\t\t\t[x,rank,info] = gelsy(a,b,rcond);\n\t\telse\n\t\t\tdisp('Type of algorithm not correct. Please choose dc, svd, y, or default.');\n\t\t\treturn;\n\t\tend;\n\tend;\t\n\n\t%Do post-call boring checking\n\tif (info~=0),\n\t\tdisp('Resolution failed, no solution returned!');\n\t\tx=[];\n\t\treturn;\n\tend;\n", "meta": {"author": "wme7", "repo": "Aero-matlab", "sha": "9430008f2e3b84f28633775a44dff534e780fbac", "save_path": "github-repos/MATLAB/wme7-Aero-matlab", "path": "github-repos/MATLAB/wme7-Aero-matlab/Aero-matlab-9430008f2e3b84f28633775a44dff534e780fbac/LapWrap/lib/m_files/gels.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009526726544, "lm_q2_score": 0.8175744673038222, "lm_q1q2_score": 0.7479996590171049}} {"text": "function [sx, dsdx, dsdp] = VBA_sparsifyPrior (x, logExponent, smoothness)\n% // VBA toolbox //////////////////////////////////////////////////////////\n%\n% [sx, dsdx, dsdp] = VBA_sparsifyPrior (x, varargin)\n% parameter transformation that emulates Laplace priors (L1-norm)\n%\n% IN:\n% - x: input value to be transformed\n% - logExponent: optional sparsity parameter. If P = 0, then the mapping \n% is regular and no sparsity is emulated. If P=log(2), then the mapping\n% emulates L1-norm like priors.\n% - smoothness: optional smoothness parameter of the sign approximation \n% (default = 1)\n%\n% In the general case, you won't have to change any of the optional\n% parameters. Those options allows to explore the properties of the\n% transformation and should not be changed.\n%\n% OUT:\n% - sx: transformed value\n% - dsdx: gradient of sx wrt x\n% - dsdP: gradient of sx wrt logExponent parameter\n%\n% /////////////////////////////////////////////////////////////////////////\n\n% check parameters\n% =========================================================================\nif nargin < 2\n logExponent = log(2);\nend\n\nif nargin < 3\n smoothness = []; % use VBA_sign default\nend\n\n% shortcuts\n% =========================================================================\n[signX, d_signX] = VBA_sign(x, smoothness);\n[absX, d_absX] = VBA_abs (x);\nexponent = exp(logExponent);\n\n% compute transformation\n% =========================================================================\n\nsx = signX .* (absX .^ exponent);\n\n% derivatives\n% =========================================================================\n\n% wrt to x\n% -------------------------------------------------------------------------\nif nargout < 2\n return;\nend\n\ndsdx = d_signX .* (absX .^ exponent) ...\n + exponent .* absX .^ (exponent - 1) .* signX .* d_absX; \n\n% wrt to logExponent\n% -------------------------------------------------------------------------\nif nargout < 3\n return;\nend\n\ndsdp = (absX .^ exponent) .* signX .* log(absX) .* exponent;\n", "meta": {"author": "MBB-team", "repo": "VBA-toolbox", "sha": "01ff63f43ef7a6473bc5e3f28dd9ffa58fcfb414", "save_path": "github-repos/MATLAB/MBB-team-VBA-toolbox", "path": "github-repos/MATLAB/MBB-team-VBA-toolbox/VBA-toolbox-01ff63f43ef7a6473bc5e3f28dd9ffa58fcfb414/utils/VBA_sparsifyPrior.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087965937711, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.7479560132356023}} {"text": "function[I]=besselitilde(varargin)\n%BESSELITILDE I-type Bessel function after factoring off exponential growth.\n%\n% ITILDE=BESSELITILDE(NU,Z) returns the modified Bessel function of the\n% first kind of order NU at argument Z, after factoring off the \n% asymptotic behavior of EXP(Z).\n%\n% BESSELITILDE is useful for products of modified Bessel functions in\n% which the exponential behaviors cancel, but that cannot be evaluated\n% directly because of numerical overflow.\n%\n% BESSELITILDE(NU,Z,N) use a summation truncated at N terms. The default\n% behavior uses N=30 and is highly accurate.\n%\n% See 10.40.1 of https://dlmf.nist.gov/10.40.\n%\n% This is low-level code used by WINDTRANS using an algorithm described \n% in Lilly and Elipot (2021).\n%\n% See also BESSELKTILDE.\n%\n% 'besselitilde --t' runs a test.\n%\n% Usage: I=besselitilde(nu,z);\n% I=besselitilde(nu,z,nterms);\n% __________________________________________________________________\n% This is part of JLAB --- type 'help jlab' for more information\n% (C) 2019--2021 J.M. Lilly --- type 'help jlab_license' for details\n \nif strcmp(varargin{1}, '--t')\n besselitilde_test,return\nend\n\nnu=varargin{1};\nz=varargin{2};\nnterms=30;\nif nargin==3\n nterms=varargin{3};\nend\n \nsizez=size(z);\nz=z(:);\n%let's sum over the third dimensions\nzk=vrep(-z,nterms,2); %this makes the alternating sign\nzk(:,1)=1;\nzk=cumprod(zk,2);\n\nk=(0:nterms-1)';\nak=(4*nu.^2-(2*k-1).^2);\nak(1)=1;\nak=cumprod(ak,1);\nak=frac(ak,factorial(k).*8.^k);\nif any(~isfinite(ak))\n ak=ak(1:find(~isfinite(ak),1,'first')-1);\nend\nzk=zk(:,1:length(ak));\n\nI=frac(1,sqrt(2*z*pi)).*((1./zk)*ak);\nI=reshape(I,sizez);\n%nterms\n\n% %let's sum over the third dimensions\n% zk=vrep(-z,nterms,3); %this makes the alternating sign\n% zk(:,:,1)=1;\n% zk=cumprod(zk,3);\n% \n% k=(0:nterms-1)';\n% ak=(4*nu.^2-(2*k-1).^2);\n% ak(1)=1;\n% ak=cumprod(ak,1);\n% ak=frac(ak,factorial(k).*8.^k);\n% if any(~isfinite(ak))\n% ak=ak(1:find(~isfinite(ak),1,'first')-1);\n% end\n% zk=zk(:,:,1:length(ak));\n% \n% ak=vrep(permute(ak,[3 2 1]),size(z),[1 2]);\n% \n% I=frac(1,sqrt(2*z*pi)).*sum(frac(ak,zk),3);\n\n\nfunction[]=besselitilde_test\n\n\nfor s=[1 -1]\n z=sqrt(s*1i)*[23:0.01:100]';\n %z=[20:0.01:100]';\n [bi0,bi]=vzeros(length(z),2);\n for i=1:2\n bi0(:,i)=exp(-z).*besseli(i-1,z);\n bi(:,i)=besselitilde(i-1,z);\n end\n \n if s==1\n reporttest('BESSELITILDE for z with phase of pi/4',allall(abs((bi0-bi)./bi)<1e-14))\n else\n reporttest('BESSELITILDE for z with phase of -pi/4',allall(abs((bi0-bi)./bi)<1e-14))\n end\n \n\tbi=vzeros(length(z),2);\n for i=1:2\n bi(:,i)=besselitilde(i-1,z,2);\n end\n \n if s==1\n reporttest('BESSELITILDE 2-term for z with phase of pi/4, order 0 and 1',allall(abs((bi0(:,1:2)-bi)./bi)<1e-3))\n else\n reporttest('BESSELITILDE 2-term for z with phase of -pi/4, order 0 and 1',allall(abs((bi0(:,1:2)-bi)./bi)<1e-3))\n end\n \n bi0=sqrt(frac(1,2*pi*z)).*(1+frac(1,8*z));\n bi1=sqrt(frac(1,2*pi*z)).*(1-frac(3,8*z)); \n \n if s==1\n reporttest('BESSELITILDE 2-term vs. analytic for z with phase of pi/4',allall(abs(([bi0 bi1]-bi)./bi)<1e-15))\n else\n reporttest('BESSELITILDE 2-term vs. analytic for z with phase of -pi/4',allall(abs(([bi0 bi1]-bi)./bi)<1e-15))\n end\nend\n\n% figure,plot(abs(z),abs(bi-bi0)),ylog\n\n\n% nu=5;\n% z=[0:0.001:100]';\n% tic;bi(:,1)=besselitilde(nu,z);toc\n% tic;bi(:,2)=sqrt(2*z*pi).*exp(-z).*besseli(nu,z);toc\n% figure,plot(z,log10(abs((bi(:,1)-bi(:,2))./bi(:,2))))\n% %wow, really excellent\n% \n% \n% tic;bi0=sqrt(2*z*pi).*exp(-z).*besseli(nu,z);toc\n% for i=1:50\n% bi(:,i)=besselitilde(nu,z,i);\n% end\n% bi0=vrep(bi0,size(bi,2),2);\n% plot(z,log10(abs((bi-bi0)./bi0)))\n% \n% \n\n\n\n\n", "meta": {"author": "jonathanlilly", "repo": "jLab", "sha": "9f32f63e647209bc1cb81c8713deb954857f1919", "save_path": "github-repos/MATLAB/jonathanlilly-jLab", "path": "github-repos/MATLAB/jonathanlilly-jLab/jLab-9f32f63e647209bc1cb81c8713deb954857f1919/jOceans/besselitilde.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088064979618, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.7479560125494988}} {"text": "function MS = createMesh3D(varargin)\n% MeshStructure = createMesh3D(Nx, Ny, Nz, Width, Height, Depth)\n% creates a uniform 3D mesh:\n% Nx is the number of cells in x (horizontal) direction\n% Ny is the number of cells in y (vertical) direction\n% Nz is the number of cells in z (perpendicular) direction\n% Lx is the domain length in x direction\n% Ly is the domain length in y direction\n% Lz is the domain length in z direction\n%\n% SYNOPSIS:\n% MeshStructure = createMesh3D(Nx, Ny, Nz, Lx, Ly, Lz)\n%\n% PARAMETERS:\n% Nx: number of cells in the x direction\n% Lx: domain length in x direction\n% Ny: number of cells in the y direction\n% Ly: domain length in y direction\n% Nz: number of cells in the z direction\n% Lz: domain length in z direction\n%\n% RETURNS:\n% MeshStructure.\n% dimensions=3 (3D problem)\n% numbering: shows the indexes of cellsn from left to right\n% and top to bottom and back to front\n% cellsize: x, y, and z elements of the cell size =[Lx/Nx,\n% Ly/Ny, Lz/Nz]\n% cellcenters.x: location of each cell in the x direction\n% cellcenters.y: location of each cell in the y direction\n% cellcenters.z: location of each cell in the z direction\n% facecenters.x: location of interface between cells in the\n% x direction\n% facecenters.y: location of interface between cells in the\n% y direction\n% facecenters.z: location of interface between cells in the\n% z direction\n% numberofcells: [Nx, Ny, Nz]\n%\n%\n% EXAMPLE:\n% Nx = 2;\n% Lx = 1.0;\n% Ny = 3;\n% Ly = 2.0;\n% Nz = 4;\n% Lz = 3.0;\n% m = createMesh3D(Nx, Ny, Nz, Lx, Ly, Lz);\n% [X, Y, Z] = ndgrid(m.cellcenters.x, m.cellcenters.y, m.cellcenters.z);\n% [Xf, Yf, Zf] = ndgrid(m.facecenters.x, m.facecenters.y, m.facecenters.z);\n% plot3(X(:), Y(:), Z(:), 'or')\n% hold on;\n% plot3(Xf(:), Yf(:), Zf(:), '+b')\n% legend('cell centers', 'cell corners');\n%\n% SEE ALSO:\n% createMesh1D, createMesh2D, createMeshCylindrical1D, ...\n% createMeshCylindrical2D, createCellVariable, createFaceVariable\n\n% Written by Ali A. Eftekhari\n% See the license file\n\nif nargin==6\n % uniform 1D mesh\n Nx=varargin{1};\n Ny=varargin{2};\n Nz=varargin{3};\n Width=varargin{4};\n Height=varargin{5};\n Depth=varargin{6};\n % cell size is dx\n dx = Width/Nx;\n dy = Height/Ny;\n dz = Depth/Nz;\n G=reshape(1:(Nx+2)*(Ny+2)*(Nz+2), Nx+2, Ny+2, Nz+2);\n CellSize.x= dx*ones(Nx+2,1);\n CellSize.y= dy*ones(Ny+2,1);\n CellSize.z= dz*ones(Nz+2,1);\n CellLocation.x= [1:Nx]'*dx-dx/2;\n CellLocation.y= [1:Ny]'*dy-dy/2;\n CellLocation.z= [1:Nz]'*dz-dz/2;\n FaceLocation.x= [0:Nx]'*dx;\n FaceLocation.y= [0:Ny]'*dy;\n FaceLocation.z= [0:Nz]'*dz;\nelseif nargin==3\n % nonuniform 1D mesh\n facelocationX=varargin{1};\n facelocationY=varargin{2};\n facelocationZ=varargin{3};\n facelocationX=facelocationX(:);\n facelocationY=facelocationY(:);\n facelocationZ=facelocationZ(:);\n Nx = length(facelocationX)-1;\n Ny = length(facelocationY)-1;\n Nz = length(facelocationZ)-1;\n G=reshape(1:(Nx+2)*(Ny+2)*(Nz+2), Nx+2, Ny+2, Nz+2);\n CellSize.x= [facelocationX(2)-facelocationX(1); ...\n facelocationX(2:end)-facelocationX(1:end-1); ...\n facelocationX(end)-facelocationX(end-1)];\n CellSize.y= [facelocationY(2)-facelocationY(1); ...\n facelocationY(2:end)-facelocationY(1:end-1); ...\n facelocationY(end)-facelocationY(end-1)];\n CellSize.z= [facelocationZ(2)-facelocationZ(1); ...\n facelocationZ(2:end)-facelocationZ(1:end-1); ...\n facelocationZ(end)-facelocationZ(end-1)];\n CellLocation.x= 0.5*(facelocationX(2:end)+facelocationX(1:end-1));\n CellLocation.y= 0.5*(facelocationY(2:end)+facelocationY(1:end-1));\n CellLocation.z= 0.5*(facelocationZ(2:end)+facelocationZ(1:end-1));\n FaceLocation.x= facelocationX;\n FaceLocation.y= facelocationY;\n FaceLocation.z= facelocationZ;\nend\nc=G([1,end], [1,end], [1, end]);\ne1=G([1, end], [1, end], 2:Nz+1);\ne2=G([1, end], 2:Ny+1, [1, end]);\ne3=G(2:Nx+1, [1, end], [1, end]);\nMS=MeshStructure(3, ...\n [Nx,Ny, Nz], ...\n CellSize, ...\n CellLocation, ...\n FaceLocation, ...\n c(:), ...\n [e1(:); e2(:); e3(:)]);\n", "meta": {"author": "simulkade", "repo": "FVTool", "sha": "49f5cb9ee8a5ff0befebd9fa71a99feae7c724d6", "save_path": "github-repos/MATLAB/simulkade-FVTool", "path": "github-repos/MATLAB/simulkade-FVTool/FVTool-49f5cb9ee8a5ff0befebd9fa71a99feae7c724d6/MeshGeneration/createMesh3D.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422645, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.7478852711306865}} {"text": "function t = traceProduct(A, B)\n\n% TRACEPRODUCT Returns the trace of the product of two matrices.\n% FORMAT\n% DESC returns the trace of the product of two matrices, tr(A*B).\n% ARG A : the first matrix in the product.\n% ARG B : the second matrix in the product.\n% RETURN t : the trace of the product.\n%\n% SEEALSO : trace\n%\n% COPYRIGHT : Neil D. Lawrence, 2004\n\n% NDLUTIL\n\nt = sum(sum(A.*B'));\n", "meta": {"author": "SheffieldML", "repo": "GPmat", "sha": "4b5914a38ecbad9fb7a13a3392970bfc28c9d911", "save_path": "github-repos/MATLAB/SheffieldML-GPmat", "path": "github-repos/MATLAB/SheffieldML-GPmat/GPmat-4b5914a38ecbad9fb7a13a3392970bfc28c9d911/ndlutil/traceProduct.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9046505351008904, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.7478852707426238}} {"text": "function value = year_is_embolismic_hebrew ( y )\n\n%*****************************************************************************80\n%\n%% YEAR_IS_EMBOLISMIC_HEBREW returns TRUE if the Hebrew year was embolismic.\n%\n% Discussion:\n%\n% In a 19 year cycle, there are 7 embolismic years. During these years,\n% an extra month, \"Adar II\", (sometimes called \"Veadar\") is inserted after\n% the month of Adar. Nonembolismic years are called \"common\" years.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 23 September 2012\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer Y, the year to be checked.\n%\n% Output, logical VALUE, TRUE if the year was embolismic.\n%\n if ( 12 <= i4_modp ( 7 * y + 13, 19 ) )\n value = 1;\n else\n value = 0;\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/calpak/year_is_embolismic_hebrew.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.747885266492189}} {"text": "classdef distance \n\n methods(Static)\n\n function result = pairwise_distances(X, distance)\n % Returns the pairwise distance matrix\n if (nargin < 2)\n distance = 'euclidean';\n end\n % Pair wise distance matrix (symmetric)\n result = squareform(pdist(X', distance));\n end\n\n function result = sqrd_l2_distances_cw(X)\n % The vectors are stored column wise.\n % Number of vectors = number of columns\n result = spx.commons.distance.pairwise_x_y(X);\n end\n\n function result = sqrd_l2_distances_rw(X)\n % The vectors are stored row wise.\n % Number of vectors = number of rows\n result = spx.commons.distance.pairwise_x_y(X');\n end\n\n\n function [ distance_matrix ] = pairwise_x_y( X, Y )\n % Computes pairwise distance squared between vectors in X and Y\n % c.f. pdist built-in function\n % We assume that vectors are column vectors\n % Dimension of space to which the vectors belong\n %N = size(X,1);\n % Number of vectors in X\n %nx = size(X,2);\n % Number of vectors in Y\n %ny = size(Y,2);\n % The result \n % distance_matrix(i,j) = distance (x_i, y_j)\n if nargin < 2\n Y = X;\n end\n distance_matrix = bsxfun(@plus,dot(X,X,1)',dot(Y,Y,1))-2*(X'*Y); \n end\n\n\n end\n\nend\n\n", "meta": {"author": "indigits", "repo": "sparse-plex", "sha": "43cae2978f62938d001baaa03308a2a717ee6c9b", "save_path": "github-repos/MATLAB/indigits-sparse-plex", "path": "github-repos/MATLAB/indigits-sparse-plex/sparse-plex-43cae2978f62938d001baaa03308a2a717ee6c9b/library/+spx/+commons/distance.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026663679976, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.7478149423691751}} {"text": "function ellipse_t = fit_ellipse( x,y,axis_handle )\n%\n% fit_ellipse - finds the best fit to an ellipse for the given set of points.\n%\n% Format: ellipse_t = fit_ellipse( x,y,axis_handle )\n%\n% Input: x,y - a set of points in 2 column vectors. AT LEAST 5 points are needed !\n% axis_handle - optional. a handle to an axis, at which the estimated ellipse \n% will be drawn along with it's axes\n%\n% Output: ellipse_t - structure that defines the best fit to an ellipse\n% a - sub axis (radius) of the X axis of the non-tilt ellipse\n% b - sub axis (radius) of the Y axis of the non-tilt ellipse\n% phi - orientation in radians of the ellipse (tilt)\n% X0 - center at the X axis of the non-tilt ellipse\n% Y0 - center at the Y axis of the non-tilt ellipse\n% X0_in - center at the X axis of the tilted ellipse\n% Y0_in - center at the Y axis of the tilted ellipse\n% long_axis - size of the long axis of the ellipse\n% short_axis - size of the short axis of the ellipse\n% status - status of detection of an ellipse\n%\n% Note: if an ellipse was not detected (but a parabola or hyperbola), then\n% an empty structure is returned\n\n% =====================================================================================\n% Ellipse Fit using Least Squares criterion\n% =====================================================================================\n% We will try to fit the best ellipse to the given measurements. the mathematical\n% representation of use will be the CONIC Equation of the Ellipse which is:\n% \n% Ellipse = a*x^2 + b*x*y + c*y^2 + d*x + e*y + f = 0\n% \n% The fit-estimation method of use is the Least Squares method (without any weights)\n% The estimator is extracted from the following equations:\n%\n% g(x,y;A) := a*x^2 + b*x*y + c*y^2 + d*x + e*y = f\n%\n% where:\n% A - is the vector of parameters to be estimated (a,b,c,d,e)\n% x,y - is a single measurement\n%\n% We will define the cost function to be:\n%\n% Cost(A) := (g_c(x_c,y_c;A)-f_c)'*(g_c(x_c,y_c;A)-f_c)\n% = (X*A+f_c)'*(X*A+f_c) \n% = A'*X'*X*A + 2*f_c'*X*A + N*f^2\n%\n% where:\n% g_c(x_c,y_c;A) - vector function of ALL the measurements\n% each element of g_c() is g(x,y;A)\n% X - a matrix of the form: [x_c.^2, x_c.*y_c, y_c.^2, x_c, y_c ]\n% f_c - is actually defined as ones(length(f),1)*f\n%\n% Derivation of the Cost function with respect to the vector of parameters \"A\" yields:\n%\n% A'*X'*X = -f_c'*X = -f*ones(1,length(f_c))*X = -f*sum(X)\n%\n% Which yields the estimator:\n%\n% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n% | A_least_squares = -f*sum(X)/(X'*X) ->(normalize by -f) = sum(X)/(X'*X) |\n% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%\n% (We will normalize the variables by (-f) since \"f\" is unknown and can be accounted for later on)\n% \n% NOW, all that is left to do is to extract the parameters from the Conic Equation.\n% We will deal the vector A into the variables: (A,B,C,D,E) and assume F = -1;\n%\n% Recall the conic representation of an ellipse:\n% \n% A*x^2 + B*x*y + C*y^2 + D*x + E*y + F = 0\n% \n% We will check if the ellipse has a tilt (=orientation). The orientation is present\n% if the coefficient of the term \"x*y\" is not zero. If so, we first need to remove the\n% tilt of the ellipse.\n%\n% If the parameter \"B\" is not equal to zero, then we have an orientation (tilt) to the ellipse.\n% we will remove the tilt of the ellipse so as to remain with a conic representation of an \n% ellipse without a tilt, for which the math is more simple:\n%\n% Non tilt conic rep.: A`*x^2 + C`*y^2 + D`*x + E`*y + F` = 0\n%\n% We will remove the orientation using the following substitution:\n% \n% Replace x with cx+sy and y with -sx+cy such that the conic representation is:\n% \n% A(cx+sy)^2 + B(cx+sy)(-sx+cy) + C(-sx+cy)^2 + D(cx+sy) + E(-sx+cy) + F = 0\n%\n% where: c = cos(phi) , s = sin(phi)\n%\n% and simplify...\n%\n% x^2(A*c^2 - Bcs + Cs^2) + xy(2A*cs +(c^2-s^2)B -2Ccs) + ...\n% y^2(As^2 + Bcs + Cc^2) + x(Dc-Es) + y(Ds+Ec) + F = 0\n%\n% The orientation is easily found by the condition of (B_new=0) which results in:\n% \n% 2A*cs +(c^2-s^2)B -2Ccs = 0 ==> phi = 1/2 * atan( b/(c-a) )\n% \n% Now the constants c=cos(phi) and s=sin(phi) can be found, and from them\n% all the other constants A`,C`,D`,E` can be found.\n%\n% A` = A*c^2 - B*c*s + C*s^2 D` = D*c-E*s\n% B` = 2*A*c*s +(c^2-s^2)*B -2*C*c*s = 0 E` = D*s+E*c \n% C` = A*s^2 + B*c*s + C*c^2\n%\n% Next, we want the representation of the non-tilted ellipse to be as:\n%\n% Ellipse = ( (X-X0)/a )^2 + ( (Y-Y0)/b )^2 = 1\n%\n% where: (X0,Y0) is the center of the ellipse\n% a,b are the ellipse \"radiuses\" (or sub-axis)\n%\n% Using a square completion method we will define:\n% \n% F`` = -F` + (D`^2)/(4*A`) + (E`^2)/(4*C`)\n%\n% Such that: a`*(X-X0)^2 = A`(X^2 + X*D`/A` + (D`/(2*A`))^2 )\n% c`*(Y-Y0)^2 = C`(Y^2 + Y*E`/C` + (E`/(2*C`))^2 )\n%\n% which yields the transformations:\n% \n% X0 = -D`/(2*A`)\n% Y0 = -E`/(2*C`)\n% a = sqrt( abs( F``/A` ) )\n% b = sqrt( abs( F``/C` ) )\n%\n% And finally we can define the remaining parameters:\n%\n% long_axis = 2 * max( a,b )\n% short_axis = 2 * min( a,b )\n% Orientation = phi\n%\n%\n\n% initialize\norientation_tolerance = 1e-3;\n\n% empty warning stack\nwarning( '' );\n\n% prepare vectors, must be column vectors\nx = x(:);\ny = y(:);\n\n% remove bias of the ellipse - to make matrix inversion more accurate. (will be added later on).\nmean_x = mean(x);\nmean_y = mean(y);\nx = x-mean_x;\ny = y-mean_y;\n\n% the estimation for the conic equation of the ellipse\nX = [x.^2, x.*y, y.^2, x, y ];\na = sum(X)/(X'*X);\n\n% check for warnings\nif ~isempty( lastwarn )\n disp( 'stopped because of a warning regarding matrix inversion' );\n ellipse_t = [];\n return\nend\n\n% extract parameters from the conic equation\n[a,b,c,d,e] = deal( a(1),a(2),a(3),a(4),a(5) );\n\n% remove the orientation from the ellipse\nif ( min(abs(b/a),abs(b/c)) > orientation_tolerance )\n \n orientation_rad = 1/2 * atan( b/(c-a) );\n cos_phi = cos( orientation_rad );\n sin_phi = sin( orientation_rad );\n [a,b,c,d,e] = deal(...\n a*cos_phi^2 - b*cos_phi*sin_phi + c*sin_phi^2,...\n 0,...\n a*sin_phi^2 + b*cos_phi*sin_phi + c*cos_phi^2,...\n d*cos_phi - e*sin_phi,...\n d*sin_phi + e*cos_phi );\n [mean_x,mean_y] = deal( ...\n cos_phi*mean_x - sin_phi*mean_y,...\n sin_phi*mean_x + cos_phi*mean_y );\nelse\n orientation_rad = 0;\n cos_phi = cos( orientation_rad );\n sin_phi = sin( orientation_rad );\nend\n\n% check if conic equation represents an ellipse\ntest = a*c;\nswitch (1)\ncase (test>0), status = '';\ncase (test==0), status = 'Parabola found'; warning( 'fit_ellipse: Did not locate an ellipse' );\ncase (test<0), status = 'Hyperbola found'; warning( 'fit_ellipse: Did not locate an ellipse' );\nend\n\n% if we found an ellipse return it's data\nif (test>0)\n \n % make sure coefficients are positive as required\n if (a<0), [a,c,d,e] = deal( -a,-c,-d,-e ); end\n \n % final ellipse parameters\n X0 = mean_x - d/2/a;\n Y0 = mean_y - e/2/c;\n F = 1 + (d^2)/(4*a) + (e^2)/(4*c);\n [a,b] = deal( sqrt( F/a ),sqrt( F/c ) ); \n long_axis = 2*max(a,b);\n short_axis = 2*min(a,b);\n\n % rotate the axes backwards to find the center point of the original TILTED ellipse\n R = [ cos_phi sin_phi; -sin_phi cos_phi ];\n P_in = R * [X0;Y0];\n X0_in = P_in(1);\n Y0_in = P_in(2);\n \n % pack ellipse into a structure\n ellipse_t = struct( ...\n 'a',a,...\n 'b',b,...\n 'phi',orientation_rad,...\n 'X0',X0,...\n 'Y0',Y0,...\n 'X0_in',X0_in,...\n 'Y0_in',Y0_in,...\n 'long_axis',long_axis,...\n 'short_axis',short_axis,...\n 'status','' );\nelse\n % report an empty structure\n ellipse_t = struct( ...\n 'a',[],...\n 'b',[],...\n 'phi',[],...\n 'X0',[],...\n 'Y0',[],...\n 'X0_in',[],...\n 'Y0_in',[],...\n 'long_axis',[],...\n 'short_axis',[],...\n 'status',status );\nend\n\n% check if we need to plot an ellipse with it's axes.\nif (nargin>2) & ~isempty( axis_handle ) & (test>0)\n \n % rotation matrix to rotate the axes with respect to an angle phi\n R = [ cos_phi sin_phi; -sin_phi cos_phi ];\n \n % the axes\n ver_line = [ [X0 X0]; Y0+b*[-1 1] ];\n horz_line = [ X0+a*[-1 1]; [Y0 Y0] ];\n new_ver_line = R*ver_line;\n new_horz_line = R*horz_line;\n \n % the ellipse\n theta_r = linspace(0,2*pi);\n ellipse_x_r = X0 + a*cos( theta_r );\n ellipse_y_r = Y0 + b*sin( theta_r );\n rotated_ellipse = R * [ellipse_x_r;ellipse_y_r];\n \n % draw\n hold_state = get( axis_handle,'NextPlot' );\n set( axis_handle,'NextPlot','add' );\n plot( new_ver_line(1,:),new_ver_line(2,:),'r' );\n plot( new_horz_line(1,:),new_horz_line(2,:),'r' );\n plot( rotated_ellipse(1,:),rotated_ellipse(2,:),'r' );\n set( axis_handle,'NextPlot',hold_state );\nend\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/3215-fitellipse/fit_ellipse.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012739960733, "lm_q2_score": 0.7905303211371898, "lm_q1q2_score": 0.7476845848640791}} {"text": "function [m_database V_PCA V_Fisher ProjectedImages_Fisher] = FisherfaceCore(T)\n% Use Principle Component Analysis (PCA) and Fisher Linear Discriminant (FLD) to determine the most \n% discriminating features between images of faces.\n%\n% Description: This function gets a 2D matrix, containing all training image vectors\n% and returns 4 outputs which are extracted from training database.\n% Suppose Ti is a training image, which has been reshaped into a 1D vector.\n% Also, P is the total number of MxN training images and C is the number of\n% classes. At first, centered Ti is mapped onto a (P-C) linear subspace by V_PCA\n% transfer matrix: Zi = V_PCA * (Ti - m_database).\n% Then, Zi is converted to Yi by projecting onto a (C-1) linear subspace, so that \n% images of the same class (or person) move closer together and images of difference \n% classes move further apart: Yi = V_Fisher' * Zi = V_Fisher' * V_PCA' * (Ti - m_database)\n%\n% Argument: T - (M*NxP) A 2D matrix, containing all 1D image vectors.\n% All of 1D column vectors have the same length of M*N \n% and 'T' will be a MNxP 2D matrix.\n% \n% Returns: m_database - (M*Nx1) Mean of the training database\n% V_PCA - (M*Nx(P-C)) Eigen vectors of the covariance matrix of the \n% training database\n% V_Fisher - ((P-C)x(C-1)) Largest (C-1) eigen vectors of matrix J = inv(Sw) * Sb\n% ProjectedImages_Fisher - ((C-1)xP) Training images, which are projected onto Fisher linear space\n%\n% See also: EIG\n\n% Original version by Amir Hossein Omidvarnia, October 2007\n% Email: aomidvar@ece.ut.ac.ir \n\n\nClass_number = ( size(T,2) )/2; % Number of classes (or persons)\nClass_population = 2; % Number of images in each class\nP = Class_population * Class_number; % Total number of training images\n\n%%%%%%%%%%%%%%%%%%%%%%%% calculating the mean image \nm_database = mean(T,2); \n\n%%%%%%%%%%%%%%%%%%%%%%%% Calculating the deviation of each image from mean image\nA = T - repmat(m_database,1,P);\n\n%%%%%%%%%%%%%%%%%%%%%%%% Snapshot method of Eigenface algorithm\nL = A'*A; % L is the surrogate of covariance matrix C=A*A'.\n[V D] = eig(L); % Diagonal elements of D are the eigenvalues for both L=A'*A and C=A*A'.\n\n%%%%%%%%%%%%%%%%%%%%%%%% Sorting and eliminating small eigenvalues\nL_eig_vec = [];\nfor i = 1 : P-Class_number \n L_eig_vec = [L_eig_vec V(:,i)];\nend\n\n%%%%%%%%%%%%%%%%%%%%%%%% Calculating the eigenvectors of covariance matrix 'C'\nV_PCA = A * L_eig_vec; % A: centered image vectors\n\n%%%%%%%%%%%%%%%%%%%%%%%% Projecting centered image vectors onto eigenspace\n% Zi = V_PCA' * (Ti-m_database)\nProjectedImages_PCA = [];\nfor i = 1 : P\n temp = V_PCA'*A(:,i);\n ProjectedImages_PCA = [ProjectedImages_PCA temp]; \nend\n\n%%%%%%%%%%%%%%%%%%%%%%%% Calculating the mean of each class in eigenspace\nm_PCA = mean(ProjectedImages_PCA,2); % Total mean in eigenspace\nm = zeros(P-Class_number,Class_number); \nSw = zeros(P-Class_number,P-Class_number); % Initialization os Within Scatter Matrix\nSb = zeros(P-Class_number,P-Class_number); % Initialization of Between Scatter Matrix\n\nfor i = 1 : Class_number\n m(:,i) = mean( ( ProjectedImages_PCA(:,((i-1)*Class_population+1):i*Class_population) ), 2 )'; \n \n S = zeros(P-Class_number,P-Class_number); \n for j = ( (i-1)*Class_population+1 ) : ( i*Class_population )\n S = S + (ProjectedImages_PCA(:,j)-m(:,i))*(ProjectedImages_PCA(:,j)-m(:,i))';\n end\n \n Sw = Sw + S; % Within Scatter Matrix\n Sb = Sb + (m(:,i)-m_PCA) * (m(:,i)-m_PCA)'; % Between Scatter Matrix\nend\n\n%%%%%%%%%%%%%%%%%%%%%%%% Calculating Fisher discriminant basis's\n% We want to maximise the Between Scatter Matrix, while minimising the\n% Within Scatter Matrix. Thus, a cost function J is defined, so that this condition is satisfied.\n[J_eig_vec, J_eig_val] = eig(Sb,Sw); % Cost function J = inv(Sw) * Sb\nJ_eig_vec = fliplr(J_eig_vec);\n\n%%%%%%%%%%%%%%%%%%%%%%%% Eliminating zero eigens and sorting in descend order\nfor i = 1 : Class_number-1 \n V_Fisher(:,i) = J_eig_vec(:,i); % Largest (C-1) eigen vectors of matrix J\nend\n\n%%%%%%%%%%%%%%%%%%%%%%%% Projecting images onto Fisher linear space\n% Yi = V_Fisher' * V_PCA' * (Ti - m_database) \nfor i = 1 : Class_number*Class_population\n ProjectedImages_Fisher(:,i) = V_Fisher' * ProjectedImages_PCA(:,i);\nend", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/17066-fld-based-face-recognition-system/FLD_based Face Recognition System_v2/FisherfaceCore.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9585377272885903, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.7476526170086568}} {"text": "function [out,im] = pyramid (infile,level,outfile)\n% PYRAMID (infile,singvals,outfile)\n% Image compression based on Gaussian Pyramid.\n% infile is input file name present in the current directory\n% level is a positive integer (the scaling factor)\n% outfile is output file name which will be created.\n%\n% It is possble to change the frequency response of the low pass \n% gaussian filter changing the parameter \"varianza\" (see below).\n%\n% Example of use:\n% [out,im]=pyramid('input_image.bmp',3,'output_image.bmp');\n% im will be a double cell array with the 3 resampled layers\n% and out will be the reconstructed image.\n% \n% The input image A can be RGB or GRAYSCALE.\n%\n% RGB case:\n% If A is of class double, all values must be in the range [0,1],\n% and A must be m-by-n-by-3.\n% If A is of class uint16 or uint8, A must be m-by-n-by-3.\n%\n% GRAYSCALE case:\n% If A is of class double, all values must be in the range [0,1], \n% and the number of dimensions of A must be 2. If A is of class\n% uint16 or uint8, the number of dimensions of A must be 2.\n% uint16 or double.\n% \n%\n% References:\n%\n% For more details concernings the algorithm implemented please visit the following links:\n% \n% http://www.cs.ucf.edu/courses/cap6411/lect826h.PDF\n% \n% http://www.wisdom.weizmann.ac.il/~maksimf/ex2/g3.html\n%\n%\n% Please contribute if you find this software useful.\n% Report bugs to luigi.rosa@tiscali.it\n%\n%\n%*****************************************************************\n% Luigi Rosa\n% Via Centrale 27\n% 67042 Civita di Bagno\n% L'Aquila --- ITALY \n% email luigi.rosa@tiscali.it\n% mobile +39 340 3463208 \n% http://utenti.lycos.it/matlab\n%*****************************************************************\n%\n%\nif (exist(infile)==2)\n a = imread(infile);\n figure('Name','Input image');\n imshow(a);\nelse\n warndlg('The file does not exist.',' Warning ');\n im=[];\n out=[];\n return\nend\n\n%------------------------------------\n% The low-pass filter ---------------\n%------------------------------------\n% Gaussian Low Pass Filter ----------\n%------------------------------------\nx=[-16:1:16];\ny=[-16:1:16];\ndimx=size(x,2);\ndimy=size(y,2);\nvarianza=2.3;\nfiltro=zeros(dimx,dimy);\nfor ii=1:dimx\n for jj=1:dimy\n esponente=exp(-(x(ii)^2+y(jj)^2)/(varianza));\n filtro(ii,jj)=esponente;\n end\nend\n% normalization\nfiltro=filtro/sum(sum(filtro)); \n%------------------------------------\n%------------------------------------\n\nif isgray(a)\n \n dvalue = double(a);\n dx = size(dvalue,1);\n dy = size(dvalue,2);\n dmin = min(dx,dy);\n \n red_p = floor(log2(dmin));\n red = min(red_p,level);\n\n im=cell(red+1,1);\n\n % Image compression\n im{1}=dvalue;\n for ii=1:red\n % low-pass filter the image\n filtered = conv2fft(dvalue,filtro,'same');\n % downsampling the image\n sottocampionato = dyaddown(filtered,1,'m');\n % save image\n im{ii+1} = sottocampionato;\n % next step\n dvalue = sottocampionato; \n end\n \n % Image reconstruction\n for ii=1:red\n % upsampling the image\n sovracampionato = dyadup(dvalue,0,'m');\n % low-pass filter the image (there is a scaling factor)\n filtered = 4*conv2fft(sovracampionato,filtro,'same');\n % next step\n dvalue = filtered; \n end\n\n \n \n \n \n if isa(a,'uint8')\n for ii=2:red+1\n testo=strcat('Image at level-',num2str(ii-1));\n figure('Name',testo);\n imshow(uint8(im{ii}));\n pause(0.6);\n end\n figure('Name','Reconstrunction');\n imshow(uint8(dvalue));\n pause(0.6);\n out=uint8(dvalue);\n \n end\n \n if isa(a,'uint16')\n for ii=2:red+1\n testo=strcat('Image at level-',num2str(ii-1));\n figure('Name',testo);\n imshow(uint16(im{ii}));\n pause(0.6);\n end\n figure('Name','Reconstrunction');\n imshow(uint16(dvalue));\n pause(0.6);\n out=uint16(dvalue);\n \n end\n \n if isa(a,'double')\n for ii=2:red+1\n testo=strcat('Image at level-',num2str(ii-1));\n figure('Name',testo);\n imshow(uint32(im{ii}));\n pause(0.6);\n end\n figure('Name','Reconstrunction');\n imshow((dvalue));\n pause(0.6);\n out=uint32(dvalue);\n \n end\n \n imwrite(out, outfile);\n return; \nend\n\n%------------------------------------------------------\nif isrgb(a)\n dvalue = double(a);\n dx = size(dvalue,1);\n dy = size(dvalue,2);\n dmin = min(dx,dy);\n \n red_p = floor(log2(dmin));\n red = min(red_p,level);\n\n im=cell(red+1,1);\n\n % Image compression\n im{1}=dvalue;\n for ii=1:red\n % low-pass filter the image\n filtered_r = conv2fft(dvalue(:,:,1),filtro,'same');\n filtered_g = conv2fft(dvalue(:,:,2),filtro,'same');\n filtered_b = conv2fft(dvalue(:,:,3),filtro,'same');\n % downsampling the image\n sottocampionato_r = dyaddown(filtered_r,1,'m');\n sottocampionato_g = dyaddown(filtered_g,1,'m');\n sottocampionato_b = dyaddown(filtered_b,1,'m');\n % save image\n clear sottocampionato;\n sottocampionato(:,:,1)=sottocampionato_r;\n sottocampionato(:,:,2)=sottocampionato_g;\n sottocampionato(:,:,3)=sottocampionato_b;\n im{ii+1} = sottocampionato;\n % next step\n dvalue = sottocampionato; \n end\n \n % Image reconstruction\n for ii=1:red\n % upsampling the image\n sovracampionato_r = dyadup(dvalue(:,:,1),0,'m');\n sovracampionato_g = dyadup(dvalue(:,:,2),0,'m');\n sovracampionato_b = dyadup(dvalue(:,:,3),0,'m');\n % low-pass filter the image (there is a scaling factor)\n filtered_r = 4*conv2fft(sovracampionato_r,filtro,'same');\n filtered_g = 4*conv2fft(sovracampionato_g,filtro,'same');\n filtered_b = 4*conv2fft(sovracampionato_b,filtro,'same');\n % next step\n clear dvalue;\n dvalue(:,:,1) = filtered_r;\n dvalue(:,:,2) = filtered_g;\n dvalue(:,:,3) = filtered_b; \n end\n\n \n \n \n \n if isa(a,'uint8')\n for ii=2:red+1\n testo=strcat('Image at level-',num2str(ii-1));\n figure('Name',testo);\n imshow(uint8(im{ii}));\n pause(0.6);\n end\n figure('Name','Reconstrunction');\n imshow(uint8(dvalue));\n pause(0.6);\n out=uint8(dvalue);\n \n end\n \n if isa(a,'uint16')\n for ii=2:red+1\n testo=strcat('Image at level-',num2str(ii-1));\n figure('Name',testo);\n imshow(uint16(im{ii}));\n pause(0.6);\n end\n figure('Name','Reconstrunction');\n imshow(uint16(dvalue));\n pause(0.6);\n out=uint16(dvalue);\n \n end\n \n if isa(a,'double')\n for ii=2:red+1\n testo=strcat('Image at level-',num2str(ii-1));\n figure('Name',testo);\n imshow((im{ii}));\n pause(0.6);\n end\n figure('Name','Reconstrunction');\n imshow((dvalue));\n pause(0.6);\n out=(dvalue);\n \n end\n \n imwrite(out, outfile);\n return;\n\nend\n\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/4772-image-compression/pyramid.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299612154571, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.7476480009314841}} {"text": "function [model] = svRegression(X,y, epsilon)\n% Compute sizes\n[n,d] = size(X);\n\n% Add bias variable\nZ = [ones(n,1) X];\n\none = zeros((d+1) + n, 1);\none(d+2:d+1+n) = 1;\n\nA = [Z -eye(n, n);\n -Z -eye(n, n);\n zeros(n,d+1) -eye(n,n)];\n\nb = [y+epsilon; -y+epsilon; zeros(n,1)];\n\nx = linprog(one, A, b);\nw = x(1:d+1);\n\nmodel.w = w;\nmodel.predict = @predict;\n\nend\n\nfunction [yhat] = predict(model,Xhat)\n[t,d] = size(Xhat);\nZhat = [ones(t,1) Xhat];\nyhat = Zhat*model.w;\nend", "meta": {"author": "gudbrandtandberg", "repo": "CPSC540Project", "sha": "45004f9a79a6c58f5266f09dae1c98c17a54028d", "save_path": "github-repos/MATLAB/gudbrandtandberg-CPSC540Project", "path": "github-repos/MATLAB/gudbrandtandberg-CPSC540Project/CPSC540Project-45004f9a79a6c58f5266f09dae1c98c17a54028d/Algorithms/Gudbrand/svRegression.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.925229948845201, "lm_q2_score": 0.8080672181749421, "lm_q1q2_score": 0.7476479909354856}} {"text": "function MISE=GaussKernelGaussMixMISE(n,H,w,mu,P)\n%%GAUSSKERNELGAUSSMIXMISE Given a Gaussian mixture probability density\n% function (PDF) that one is attempting to approximate using a\n% kernel density estimator with Gaussian kernels all having\n% square root covariance matrix H, determine the mean integrated\n% squared error (MISE) of the estimate. The MISE is the expected\n% value of int_{R}(\\hat{f}(x)-f(x))^2dx where \\hat{f}(x) is the\n% kernel estimator based on a set of random samples of the true\n% density f(x) (since it is based on random samples, the mean\n% part is the expected value being taken over all possible\n% samples). This function is useful for assessing different\n% kernel bandwidth estimators (estimators of H) when using\n% Gaussian mixture sample problems.\n%\n%INPUTS: n The number of samples that the kernel-density estimator will\n% use.\n% H The dXd bandwidth matrix used in the kernel density estimator\n% (as one would use in the function kernelApprox).\n% w A numCompX1 or 1XnumComp vector of the weights associated with\n% each of the numComp components of the Gaussian mixture.\n% mu The dXnumComp matrix of the mean of each component of the\n% Gaussian mixture.\n% P The dXdXnumComp set of covariance matrices of the components of\n% the Gaussian mixture.\n%\n%OUTPUTS: MISE The MISE of thekernel estimator with the given number of\n% samples and bandwidth matrix.\n%\n%This function implements the formula for the MISE in an arbitrary number\n%of dimensions in Section 4 of [1].\n%\n%REFERENCES:\n%[1] M. P. Wand and M. C. Jones, \"Comparison of smoothing parameterizations\n% in bivariate kernel density estimation,\" Journal of the American\n% Statistical Association, vol. 88, no. 422, pp. 520-528, Jun. 1993.\n%\n%December 2015 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\n%The number of components in the \nk=size(mu,2);\nd=size(mu,1);\n\n%The definition of the bandwidth used in the paper is the square of what is\n%used here.\nH=H*H';\n\nOmega0=zeros(k,k);\nOmega1=zeros(k,k);\nOmega2=zeros(k,k);\n\nfor l=1:k\n for lp=l:k\n Sigma=P(:,:,l)+P(:,:,lp);\n \n Omega0(l,lp)=GaussianD.PDF(mu(:,l),mu(:,lp),Sigma);\n Omega1(l,lp)=GaussianD.PDF(mu(:,l),mu(:,lp),Sigma+H);\n Omega2(l,lp)=GaussianD.PDF(mu(:,l),mu(:,lp),Sigma+2*H);\n end\nend\n\nMISE=(1/n)*(4*pi)^(-d/2)*1/sqrt(det(H))+w(:)'*((1-1/n)*Omega2-2*Omega1+Omega0)*w(:);\n\nend\n\n%LICENSE:\n%\n%The source code is in the public domain and not licensed or under\n%copyright. The information and software may be used freely by the public.\n%As required by 17 U.S.C. 403, third parties producing copyrighted works\n%consisting predominantly of the material produced by U.S. government\n%agencies must provide notice with such work(s) identifying the U.S.\n%Government material incorporated and stating that such material is not\n%subject to copyright protection.\n%\n%Derived works shall not identify themselves in a manner that implies an\n%endorsement by or an affiliation with the Naval Research Laboratory.\n%\n%RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF THE\n%SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY THE NAVAL\n%RESEARCH LABORATORY FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE ACTIONS\n%OF RECIPIENT IN THE USE OF THE SOFTWARE.\n", "meta": {"author": "USNavalResearchLaboratory", "repo": "TrackerComponentLibrary", "sha": "9f6e329de5be06a371757c4b853200beb6def2d0", "save_path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary", "path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary/TrackerComponentLibrary-9f6e329de5be06a371757c4b853200beb6def2d0/Mathematical_Functions/Statistics/Kernel_Estimation/GaussKernelGaussMixMISE.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.901920681802153, "lm_q2_score": 0.8289388104343893, "lm_q1q2_score": 0.7476370570792501}} {"text": "function value = p14_exact ( dim_num )\n\n%*****************************************************************************80\n%\n%% P14_EXACT returns the exact integral for problem 14.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 19 March 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer DIM_NUM, the spatial dimension.\n%\n% Output, real VALUE, the exact value of the integral.\n%\n value = ( - 1.0 / 3.0 ) * ( 1.0 - ( -1.0 / 2.0 )^dim_num );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/quadrature_test/p14_exact.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.90192067652954, "lm_q2_score": 0.8289388083214156, "lm_q1q2_score": 0.7476370508028419}} {"text": "function [Q,err] = quadgr(fun,a,b,tol,trace,varargin)\n%QUADGR Gauss-Legendre quadrature with Richardson extrapolation.\n% [Q,ERR] = QUADGR(FUN,A,B,TOL) approximates the integral of a function\n% FUN from A to B with an absolute error tolerance TOL. FUN is a function\n% handle and must accept vector arguments. TOL is 1e-6 by default. Q is\n% the integral approximation and ERR is an estimate of the absolute error.\n%\n% QUADGR uses a 12-point Gauss-Legendre quadrature. The error estimate is\n% based on successive interval bisection. Richardson extrapolation\n% accelerates the convergence for some integrals, especially integrals\n% with endpoint singularities.\n%\n% QUADGR(FUN,A,B,TOL,TRACE) with non-zero TRACE displays the\n% extrapolation table.\n%\n% QUADGR can also be used as the quadrature in DBLQUAD and TRIPLEQUAD.\n%\n% Examples:\n% Q = quadgr(@(x) log(x),0,1)\n% [Q,err] = quadgr(@(x) exp(x),0,9999i*pi)\n% [Q,err] = quadgr(@(x) sqrt(4-x.^2),0,2,1e-12)\n% [Q,err] = quadgr(@(x) x.^-0.75,0,1)\n% [Q,err] = quadgr(@(x) 1./sqrt(1-x.^2),-1,1)\n% [Q,err] = quadgr(@(x) exp(-x.^2),-inf,inf,1e-9) % sqrt(pi)\n% [Q,err] = quadgr(@(x) cos(x).*exp(-x),0,inf,1e-9)\n%\n% See also QUAD, QUADGK, DBLQUAD, TRIPLEQUAD\n\n% Author: Jonas Lundgren 2009\n\n% 2009-03-17 First published\n% 2010-04-14 Adapted to DBLQUAD and TRIPLEQUAD (varargin added)\n\nif nargin < 3, help quadgr, return, end\nif nargin < 4 || isempty(tol), tol = 1.e-6; end;\nif nargin < 5 || isempty(trace), trace = 0; end;\n\n% Order limits (required if infinite limits)\nif a == b\n Q = b - a;\n err = b - a;\n return\nelseif a > b\n reverse = true;\n atmp = a;\n a = b;\n b = atmp;\nelse\n reverse = false;\nend\n\n% Infinite limits\nif isinf(a) || isinf(b)\n % Check real limits\n if ~isreal(a) || ~isreal(b) || isnan(a) || isnan(b)\n error('quadgr:inflim','Infinite intervals must be real.')\n end\n % Change of variable\n if isfinite(a) && isinf(b)\n % a to inf\n fun1 = @(t,varargin) fun(a + t./(1-t), varargin{:})./(1-t).^2;\n [Q,err] = quadgr(fun1,0,1,tol,trace,varargin{:});\n elseif isinf(a) && isfinite(b)\n % -inf to b\n fun2 = @(t,varargin) fun(b + t./(1+t), varargin{:})./(1+t).^2;\n [Q,err] = quadgr(fun2,-1,0,tol,trace,varargin{:});\n else % -inf to inf\n fun1 = @(t,varargin) fun(t./(1-t), varargin{:})./(1-t).^2;\n fun2 = @(t,varargin) fun(t./(1+t), varargin{:})./(1+t).^2;\n [Q1,err1] = quadgr(fun1,0,1,tol/2,trace,varargin{:});\n [Q2,err2] = quadgr(fun2,-1,0,tol/2,trace,varargin{:});\n Q = Q1 + Q2;\n err = err1 + err2;\n end\n % Reverse direction\n if reverse\n Q = -Q;\n end\n return \nend\n\n% Gauss-Legendre quadrature (12-point)\nxq = [0.12523340851146894; 0.36783149899818018; 0.58731795428661748; ...\n 0.76990267419430469; 0.9041172563704748; 0.98156063424671924];\nwq = [0.24914704581340288, 0.23349253653835478, 0.20316742672306584, ...\n 0.16007832854334636, 0.10693932599531818, 0.047175336386511842];\nxq = [xq; -xq];\nwq = [wq, wq];\nnq = length(xq);\n\n% Initiate vectors\nmaxit = 17; % Max number of iterations\nQ0 = zeros(maxit,1); \t% Quadrature\nQ1 = zeros(maxit,1); \t% First Richardson extrapolation\nQ2 = zeros(maxit,1); \t% Second Richardson extrapolation\n\n% One interval\nhh = (b - a)/2; % Half interval length\nx = (a + b)/2 + hh*xq; % Nodes\n% Quadrature\nQ0(1) = hh*wq*fun(x,varargin{:});\n\n% Successive bisection of intervals\nfor k = 2:maxit\n \n % Interval bisection\n hh = hh/2;\n x = [x + a; x + b]/2;\n % Quadrature\n Q0(k) = hh*wq*sum(reshape(fun(x,varargin{:}),nq,[]),2);\n \n % Richardson extrapolation\n if k >= 5\n Q1(k) = richardson(Q0,k);\n Q2(k) = richardson(Q1,k);\n elseif k >= 3\n Q1(k) = richardson(Q0,k);\n end\n \n % Estimate absolute error\n if k >= 6\n Qv = [Q0(k), Q1(k), Q2(k)];\n Qw = [Q0(k-1), Q1(k-1), Q2(k-1)];\n elseif k >= 4\n Qv = [Q0(k), Q1(k)];\n Qw = [Q0(k-1), Q1(k-1)];\n else\n Qv = Q0(k);\n Qw = Q0(k-1);\n end\n [err,j] = min(abs(Qv - Qw));\n Q = Qv(j);\n \n % Convergence\n if err < tol || ~isfinite(Q)\n break;\n end \n \nend\n\n% Convergence check\nif ~isfinite(Q)\n warning('quadgr:infnan','Integral approximation is Infinite or NaN.')\nelseif err > tol\n warning('quadgr:maxiter','Max number of iterations reached without convergence.')\nend\n\n% The error estimate should not be zero\nerr = err + 2*eps(Q);\n% Reverse direction\nif reverse\n\tQ = -Q;\nend\n\n% Display convergence\nif trace\n disp(' ')\n disp([Q0(1:k) Q1(1:k) Q2(1:k)])\nend\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nfunction R = richardson(Q,k)\n% Richardson extrapolation with parameter estimation\nif Q(k) ~= Q(k-1)\n c = real((Q(k-1)-Q(k-2))/(Q(k)-Q(k-1))) - 1;\nelse\n c = 1;\nend\n% The lower bound 0.07 admits the singularity x.^-0.9\nc = max(c,0.07);\nR = Q(k) + (Q(k) - Q(k-1))/c;\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/23325-quadgr/quadgr.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436397, "lm_q2_score": 0.8397339696776499, "lm_q1q2_score": 0.7476103095711469}} {"text": "function [ lambda, v, it_num ] = power_method2 ( n, a, x_init, it_max, tol )\n\n%*****************************************************************************80\n%\n%% POWER_METHOD2 applies the power method for possibly complex eigenvalues.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 17 July 2008\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Eric VanDeVelde,\n% Concurrent Scientific Programming,\n% Springer, 1994,\n% ISBN: 0-387-94195-9,\n% LC: QA76.58.V35.\n%\n% Parameters:\n%\n% Input, integer N, the order of the matrix.\n%\n% Input, real A(N,N), the matrix.\n%\n% Input, real X(N), the initial estimate for the eigenvector.\n%\n% Input, integer IT_MAX, the maximum number of iterations to take.\n% 1 <= IT_MAX.\n%\n% Input, real TOL, an error tolerance.\n%\n% Output, complex LAMBDA, the estimate for the eigenvalue.\n%\n% Output, complex V(N), the estimate for the eigenvector.\n%\n% Output, integer IT_NUM, the number of iterations taken.\n%\n it_num = 0;\n%\n% Compute data necessary to start the iteration.\n%\n x(1:n,1) = x_init(1:n);\n pi_xx = x(1:n)' * x(1:n);\n x(1:n) = x(1:n) / pi_xx;\n y(1:n,1) = a(1:n,1:n) * x(1:n);\n pi_xy = x(1:n)' * y(1:n);\n pi_yy = y(1:n)' * y(1:n);\n\n for it = 1 : it_max\n\n if ( pi_yy - pi_xy * pi_xy < tol * tol * pi_yy )\n lambda = pi_xy;\n v(1:n) = y(1:n) / sqrt ( pi_yy );\n return\n end\n\n z(1:n,1) = a(1:n,1:n) * y(1:n);\n\n pi_xz = x(1:n)' * z(1:n);\n pi_yz = y(1:n)' * z(1:n);\n pi_zz = z(1:n)' * z(1:n);\n\n alpha = - ( pi_yz - pi_xy * pi_xz ) / ( pi_yy - pi_xy * pi_xy );\n beta = ( pi_xy * pi_yz - pi_yy * pi_xz ) / ( pi_yy - pi_xy * pi_xy );\n gamma = pi_zz + alpha * alpha * pi_yy + beta * beta ...\n + 2.0 * ( alpha * pi_yz + beta * pi_xz + alpha * beta * pi_xy );\n\n if ( gamma < tol * tol * pi_zz & alpha * alpha < 4.0 * beta )\n\n lambda_real = - alpha / 2.0;\n lambda_imag = sqrt ( 4.0D+00 * beta - alpha * alpha ) / 2.0;\n lambda = lambda_real + lambda_imag * sqrt ( - 1.0 );\n\n v(1:n) = ( lambda * y(1:n) - z(1:n) ) ...\n / sqrt ( beta * pi_yy + alpha * pi_yz + pi_zz );\n\n return\n end\n\n x(1:n) = y(1:n) / sqrt ( pi_yy );\n y(1:n) = z(1:n) / sqrt ( pi_yy );\n\n pi_xy = pi_yz / pi_yy;\n pi_yy = pi_zz / pi_yy;\n\n it_num = it;\n\n end\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'POWER_METHOD2 - Fatal error!\\n' );\n fprintf ( 1, ' Convergence was not reached.\\n' );\n\n error ( 'POWER_METHOD2 - Fatal error!' );\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/power_method/power_method2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220292, "lm_q2_score": 0.8397339656668287, "lm_q1q2_score": 0.7476103011117319}} {"text": "% \u57c3\u7279\u91d1\u65b9\u6cd5\u52a0\u901f\u8fed\u4ee3\u65b9\u6cd5\u6c42\u89e3\u65b9\u7a0b\nclear;\nformat long;\ntol = 1e-10;\nN = 100;\nx0 = 0.5;\nphi = @(x) exp(-x);\n%phi = @(x) (x+1)^(1/3);\n\nfor k = 1 : N\n x1 = phi(x0);\n x2 = phi(x1);\n x2 = x2 - (x2 - x1)^2 / (x2 - 2 * x1 + x0);\n if abs(x2 - x0) < tol\n fprintf('\u65b9\u7a0b\u7684\u6b63\u6839: %10.8f\\n', x1);\n break;\n end\n x0 = x2;\nend\nif k == N\n fprintf('\u8fed\u4ee3\u65b9\u6cd5\u5931\u8d25\\n');\nend\nfprintf('\u8fed\u4ee3\u6b21\u6570: %d\\n', k);", "meta": {"author": "qxr777", "repo": "NumericalAnalysis", "sha": "145e47521459defdcfd6a929702651abe29ba6de", "save_path": "github-repos/MATLAB/qxr777-NumericalAnalysis", "path": "github-repos/MATLAB/qxr777-NumericalAnalysis/NumericalAnalysis-145e47521459defdcfd6a929702651abe29ba6de/\u7b2c\u4e94\u7ae0 \u65b9\u7a0b\u6c42\u6839\u7684\u8fed\u4ee3\u6cd5/example_4_4.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942173896131, "lm_q2_score": 0.8397339716830606, "lm_q1q2_score": 0.747610299135042}} {"text": "function h = huber_pot(t, d)\n%| function h = huber_pot(t, d)\n%| huber potential function\n\nif nargin < 1, ir_usage, end\nif nargin < 2, huber_pot_test, return, end\n\nh = t.^2 / 2;\nii = abs(t) > d;\nh(ii) = d * abs(t(ii)) - d.^2/2;\n\nfunction huber_pot_test\nt = linspace(-9,9,101);\ndelta = 4;\nplot(t, huber_pot(t, delta), '-', delta, huber_pot(delta, delta), 'o')\n", "meta": {"author": "JeffFessler", "repo": "mirt", "sha": "b7f36cc46916821e8bc8502301b1554ebc7efe1d", "save_path": "github-repos/MATLAB/JeffFessler-mirt", "path": "github-repos/MATLAB/JeffFessler-mirt/mirt-b7f36cc46916821e8bc8502301b1554ebc7efe1d/penalty/huber_pot.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894745194281, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.7475818787997909}} {"text": "function mean = extreme_values_mean ( a, b )\n\n%*****************************************************************************80\n%\n%% EXTREME_VALUES_MEAN returns the mean of the Extreme Values PDF.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 09 September 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real A, B, the parameters of the PDF.\n% 0.0 < B.\n%\n% Output, real MEAN, the mean of the PDF.\n%\n mean = a + b * euler_constant ( );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/prob/extreme_values_mean.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8774767874818408, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.7475688127048848}} {"text": "function tinv = t_inv (x, v, mu, sigma)\n% T_INV Inverse of Student's T cumulative distribution function (cdf).\n% X=TINV(P,V,MU,SIGMA) returns the inverse of Student's T cdf with V degrees\n% of freedom, at the values in P, with mean MU and standard deviation\n% SIGMA.\n%\n% The size of X is the common size of P and V. A scalar input\n% functions as a constant matrix of the same size as the other input.\n\n% Copyright (c) 1995-1997, 2005-2007 Kurt Hornik\n\n% This software is distributed under the GNU General Public\n% License (version 3 or later); please refer to the file\n% License.txt, included with the software, for details.\nif nargin < 4\n sigma = 1;\nend\nif nargin < 3\n mu = 0;\nend\nif (~isscalar(mu) || ~isscalar(sigma))\n if ~((size(x,1) == size(mu,1)) && (size(mu,1) == size(sigma,1)))\n error ('norm_inv: x, mu and sigma must be of common size or scalars');\n end\nend\n\n\nx = (x-mu)./sigma;\n\nif (nargin < 2)\n error('must give atleast 2 input arguments')\nend\n\nif (~isscalar(v))\n \n if (size(x,1) ~= size(v,1))\n error ('tinv: x and v must be of common size or scalar');\n end\nend\n\ntinv = zeros(size(x));\n\nk = find( (x<0) || (x > 1) || isnan(x) || (v<0));\nif (any(k))\n tinv(k) = NaN;\nend\n\nk = find ((x == 0) & (v > 0));\nif (any (k))\n tinv(k) = -Inf;\nend\n\nk = find ((x == 1) & (v > 0));\nif (any (k))\n tinv(k) = Inf;\nend\n\nk = find ((x > 0) & (x < 1) & (v > 0) & (v < 10000));\nif (any (k))\n if (isscalar (v))\n tinv(k) = (sign (x(k) - 1/2) ...\n .* sqrt (v .* (1 ./ beta_inv (2*min(x(k),1-x(k)), ...\n v/2,1/2)-1)));\n else\n tinv(k) = (sign(x(k)-1/2) ...\n .* sqrt (v(k).*(1./beta_inv(2*min(x(k), 1-x(k)), ...\n v(k)/2,1/2)-1)));\n end\nend\n\n% For large v, use the quantiles of the standard normal\nk = find ((x > 0) & (x < 1) & (v >= 10000));\nif (any (k))\n tinv(k) = sqrt (2)*erfinv(2*x(k)-1);\nend\n\nend\n\n% inv = sqrt (2) * erfinv (2 * x - 1);", "meta": {"author": "fieldtrip", "repo": "fieldtrip", "sha": "c2039be598a02d86b39aae76bfa7aaa720f9801c", "save_path": "github-repos/MATLAB/fieldtrip-fieldtrip", "path": "github-repos/MATLAB/fieldtrip-fieldtrip/fieldtrip-c2039be598a02d86b39aae76bfa7aaa720f9801c/external/dmlt/external/gpstuff/dist/t_inv.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767810736693, "lm_q2_score": 0.8519528000888387, "lm_q1q2_score": 0.7475688006486535}} {"text": "clf\nhold on;\nx = 0:0.01:8*pi;\ndata = [x', sin(x)'];\nplot(data(:,1), data(:,2));\naxis([0, 8*pi, -3, 3]);\nlegend('original data');\ngrid on;\n\npause;\n\nclf\nhold on;\n\ndata_length = length(data)\nfor idx = 1500:2000\n data(idx,2) = cos(data(idx,1));\nend;\nplot(data(:,1), data(:,2));\naxis([0, 8*pi, -3, 3]);\nlegend('human modified data');\ngrid on;\n\npause;\n\n%in this demo, we only use best_so_far_loc while we plot the figure\nn = 500;\n[best_so_far_dist, best_so_far_loc] = HOTSAX(data(:,2), n, 'nseg 4')\n\n%plot the figure\nhold on;\nif ~isnan(best_so_far_loc)\n plot_x = data(best_so_far_loc:best_so_far_loc+n, 1);\n plot_y = data(best_so_far_loc:best_so_far_loc+n, 2);\n plot(plot_x,plot_y, 'r');\n legend('human modified data', 'anomaly detect');\nend\nhold off;", "meta": {"author": "dsmi-lab-ntust", "repo": "AnomalyDetectionToolbox", "sha": "b9385ba405026f56a008f88c0580b1a18e24b355", "save_path": "github-repos/MATLAB/dsmi-lab-ntust-AnomalyDetectionToolbox", "path": "github-repos/MATLAB/dsmi-lab-ntust-AnomalyDetectionToolbox/AnomalyDetectionToolbox-b9385ba405026f56a008f88c0580b1a18e24b355/Algorithms/distanceBased/HOTSAX/HOTSAX_Example.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425223682086, "lm_q2_score": 0.8128673201042492, "lm_q1q2_score": 0.7475473526113579}} {"text": "function [px, py, gx, gy] = position_3_link(z,P) \n%[px,py,gx,gy] = POSITION_3_LINK(Z,P)\n% \n%FUNCTION: This function computes the cartesian positions\n% of the CoM and tip of each link\n%INPUTS: \n%\n%\n%OUTPUTS: \n% px = [nLink X nTime] position of the end of each link\n% py = [nLink X nTime] position of the end of each link\n% gx = [nLink X nTime] position of the CoM of each link\n% gy = [nLink X nTime] position of the CoM of each link\n% \n%NOTES:\n% This file was automatically generated by writePosition.m\n\ng = P.g ; %gravity\nm1 = P.m(1); % Link 1 mass\nm2 = P.m(2); % Link 2 mass\nm3 = P.m(3); % Link 3 mass\nl1 = P.l(1); % Link 1 length\nl2 = P.l(2); % Link 2 length\nl3 = P.l(3); % Link 3 length\nI1 = P.I(1); % Link 1 moment of inertia about its center of mass\nI2 = P.I(2); % Link 2 moment of inertia about its center of mass\nI3 = P.I(3); % Link 3 moment of inertia about its center of mass\nd1 = P.d(1); % Link 1 distance between center of mass and parent joint\nd2 = P.d(2); % Link 2 distance between center of mass and parent joint\nd3 = P.d(3); % Link 3 distance between center of mass and parent joint\n\nth1 = z(1,:); \nth2 = z(2,:); \nth3 = z(3,:); \n\nnTime = length(th1); \npx = zeros(3,nTime);\npy = zeros(3,nTime);\ngx = zeros(3,nTime);\ngy = zeros(3,nTime);\n\npx(1,:) = l1.*cos(th1);\npy(1,:) = l1.*sin(th1);\ngx(1,:) = d1.*cos(th1);\ngy(1,:) = d1.*sin(th1);\n\npx(2,:) = l1.*cos(th1) + l2.*cos(th2);\npy(2,:) = l1.*sin(th1) + l2.*sin(th2);\ngx(2,:) = d2.*cos(th2) + l1.*cos(th1);\ngy(2,:) = d2.*sin(th2) + l1.*sin(th1);\n\npx(3,:) = l1.*cos(th1) + l2.*cos(th2) + l3.*cos(th3);\npy(3,:) = l1.*sin(th1) + l2.*sin(th2) + l3.*sin(th3);\ngx(3,:) = d3.*cos(th3) + l1.*cos(th1) + l2.*cos(th2);\ngy(3,:) = d3.*sin(th3) + l1.*sin(th1) + l2.*sin(th2);\n\n\nend \n", "meta": {"author": "MatthewPeterKelly", "repo": "dscTutorials", "sha": "e1e97a9be03ec146f88bd6ddd9e06db7ee52e242", "save_path": "github-repos/MATLAB/MatthewPeterKelly-dscTutorials", "path": "github-repos/MATLAB/MatthewPeterKelly-dscTutorials/dscTutorials-e1e97a9be03ec146f88bd6ddd9e06db7ee52e242/LagrangeMechanics/nLinkPendulum/position_3_link.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308165850443, "lm_q2_score": 0.800692004473946, "lm_q1q2_score": 0.7473905915692314}} {"text": "function sigmaEq = equivalentStress(sigma,varargin)\n% von Mises equivalent stress\n%\n% Input\n% sigma - @stressTensor\n%\n% Output\n% s - double\n%\n\ns = sigma.deviatoricStress;\nsigmaEq = sqrt(3/2 * s:s);\n\n% the following code gives the same result\n% is more efficient but less readable\n\n% M = sigma.M;\n% sigmaEq = sqrt(M(1,1,:).^2 + M(2,2,:).^2 + M(3,3,:).^2 ...\n% - M(1,1,:).*M(2,2,:) - M(2,2,:).*M(3,3,:)- M(1,1,:).*M(3,3,:) ...\n% + 3*(M(1,2).^2 + M(1,3).^2 + M(2,3).^2 ));\n", "meta": {"author": "mtex-toolbox", "repo": "mtex", "sha": "f0ce46a720935e9ae8106ef919340534bca1adcb", "save_path": "github-repos/MATLAB/mtex-toolbox-mtex", "path": "github-repos/MATLAB/mtex-toolbox-mtex/mtex-f0ce46a720935e9ae8106ef919340534bca1adcb/TensorAnalysis/@stressTensor/equivalentStress.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9334308110294983, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.7473905826815688}} {"text": "function exact = p44_exact ( )\n\n%*****************************************************************************80\n%\n%% P44_EXACT returns the exact integral for problem 44.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 04 November 2009\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Output, real EXACT, the value of the integral.\n%\n alpha = p44_param_get ( );\n\n exact = ( 20.0 * sin ( 2.0^alpha ) ...\n - 2.0^alpha * cos ( 2.0^alpha ) ...\n + 2.0^alpha * exp ( -20.0 ) ) / ( 400.0 + 4.0^alpha );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_int/p44_exact.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8856314738181874, "lm_q2_score": 0.8438951005915208, "lm_q1q2_score": 0.7473800616848161}} {"text": "function [g,A] = minusOne_v2(f)\n%minusOne Multiplies an input array by (-1)^x+y.\n% [G,A] = minusOne(F) multiplies F by (-1)^x+y to produce G. F can be\n% a 1-D or 2-D array. On the output, G = (-1)^(x+y).*F, and A is the\n% array of values (-1)^(x+y). Output G is floating point with values\n% in the same numerical range as F.\n%\n% Copyright 2002-2020 Gatesmark\n%\n% This function, and other functions in the DIPUM Toolbox, are based \n% on the theoretical and practical foundations established in the \n% book Digital Image Processing Using MATLAB, 3rd ed., Gatesmark \n% Press, 2020.\n%\n% Book website: http://www.imageprocessingplace.com\n% License: https://github.com/dipum/dipum-toolbox/blob/master/LICENSE.txt\n\n% Preliminaries.\n\n% Convert input to floating point for multiplication later.\nf = im2double(f);\n\n% Image size.\n[M,N] = size(f);\n\nx = (0:M - 1)';\ny = 0:N - 1;\n\nA = (-1).^(x + y);\n\n% Multiply input by matrix.\ng = A.*f;\n", "meta": {"author": "dipum", "repo": "dipum-toolbox", "sha": "9ce653c4c0c4b7c56e46194c24bf152db4ab6832", "save_path": "github-repos/MATLAB/dipum-dipum-toolbox", "path": "github-repos/MATLAB/dipum-dipum-toolbox/dipum-toolbox-9ce653c4c0c4b7c56e46194c24bf152db4ab6832/dipum/minusOne.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314768368161, "lm_q2_score": 0.8438950966654774, "lm_q1q2_score": 0.7473800607551944}} {"text": "function geometry_test058 ( )\n\n%*****************************************************************************80\n%\n%% TEST058 tests PLANE_IMP_POINT_DIST_3D, PLANE_IMP_POINT_DIST_SIGNED_3D;\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 07 April 2009\n%\n% Author:\n%\n% John Burkardt\n%\n dim_num = 3;\n ntest = 4;\n%\n% This is the plane Z = 10.\n%\n a = 0.0;\n b = 0.0;\n c = 1.0;\n d = - 10.0;\n\n ptest(1:dim_num,1:ntest) = [ ...\n -12.0, 14.0, 0.0; ...\n 7.0, 8.0, 9.0; ...\n 1.0, 2.0, 10.0; ...\n 0.0, 0.0, 12.0 ]';\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TEST058\\n' );\n fprintf ( 1, ' PLANE_IMP_POINT_DIST_3D computes the distance\\n' );\n fprintf ( 1, ' between an implicit plane and a point in 3D;\\n' );\n fprintf ( 1, ' PLANE_IMP_POINT_DIST_SIGNED 3D computes the\\n' );\n fprintf ( 1, ' signed distance between an implicit plane\\n' );\n fprintf ( 1, ' and a point in 3D.\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' For all tests, we use the implicit plane with\\n' );\n fprintf ( 1, ' (A,B,C,D) = %f %f %f %f\\n', a, b, c, d );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' (X,Y,Z) DISTANCE SIGNED_DISTANCE\\n' );\n fprintf ( 1, '\\n' );\n\n for i = 1 : ntest\n\n p(1:dim_num) = ptest(1:dim_num,i);\n\n dist = plane_imp_point_dist_3d ( a, b, c, d, p );\n\n dist_signed = plane_imp_point_dist_signed_3d ( a, b, c, d, p );\n\n fprintf ( 1, ' %12f %12f %12f %12f %12f\\n', p(1:dim_num), dist, dist_signed );\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/geometry/geometry_test058.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314738181875, "lm_q2_score": 0.8438950947024555, "lm_q1q2_score": 0.7473800564692746}} {"text": "function [J grad] = nnCostFunction(nn_params, ...\n input_layer_size, ...\n hidden_layer_size, ...\n num_labels, ...\n X, y, lambda)\n%NNCOSTFUNCTION Implements the neural network cost function for a two layer\n%neural network which performs classification\n% [J grad] = NNCOSTFUNCTON(nn_params, hidden_layer_size, numn,/_labels, ...\n% X, y, lambda) computes the cost and gradient of the neural network. The\n% parameters for the neural network are \"unrolled\" into the vector\n% nn_params and need to be converted back into the weight matrices. \n% \n% The returned parameter grad should be a \"unrolled\" vector of the\n% partial derivatives of the neural network.\n%\n\n% Reshape nn_params back into the parameters Theta1 and Theta2, the weight matrices\n% for our 2 layer neural network\nTheta1 = reshape(nn_params(1:hidden_layer_size * (input_layer_size + 1)), ...\n hidden_layer_size, (input_layer_size + 1));\n\nTheta2 = reshape(nn_params((1 + (hidden_layer_size * (input_layer_size + 1))):end), ...\n num_labels, (hidden_layer_size + 1));\n\n% Setup some useful variables\nm = size(X, 1);\n \n% You need to return the following variables correctly \nJ = 0;\nTheta1_grad = zeros(size(Theta1));\nTheta2_grad = zeros(size(Theta2));\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: You should complete the code by working through the\n% following parts.\n%\n% Part 1: Feedforward the neural network and return the cost in the\n% variable J. After implementing Part 1, you can verify that your\n% cost function computation is correct by verifying the cost\n% computed in ex4.m\n%\n% Part 2: Implement the backpropagation algorithm to compute the gradients\n% Theta1_grad and Theta2_grad. You should return the partial derivatives of\n% the cost function with respect to Theta1 and Theta2 in Theta1_grad and\n% Theta2_grad, respectively. After implementing Part 2, you can check\n% that your implementation is correct by running checkNNGradients\n%\n% Note: The vector y passed into the function is a vector of labels\n% containing values from 1..K. You need to map this vector into a \n% binary vector of 1's and 0's to be used with the neural network\n% cost function.\n%\n% Hint: We recommend implementing backpropagation using a for-loop\n% over the training examples if you are implementing it for the \n% first time.\n%\n% Part 3: Implement regularization with the cost function and gradients.\n%\n% Hint: You can implement this around the code for\n% backpropagation. That is, you can compute the gradients for\n% the regularization separately and then add them to Theta1_grad\n% and Theta2_grad from Part 2.\n%\n% FORWARD PROPOGATION\na1 = [ones(m,1) X];\nz2 = (a1*Theta1');\na2 = [ones(size(z2,1),1) sigmoid(z2)];\nh_theta = sigmoid(a2*Theta2');\na3 = h_theta;\ny_matrix = eye(num_labels)(y,:);\nJ = (-sum(sum(y_matrix.*log(h_theta))) - sum(sum((1-y_matrix).*(log(1-h_theta)))))/m;\n\n% REGULARIZATION\nregularization_term = (lambda/(2*m))*((sum(sum(Theta1(:,2:end).^2))) + sum(sum(Theta2(:,2:end).^2)));\nJ = J + regularization_term;\n\n% BACK PROPOGATION\nd3 = a3 - y_matrix; % has same dimensions as a3\nd2 = (d3*Theta2).*[ones(size(z2,1),1) sigmoidGradient(z2)]; % has same dimensions as a2\n\nD1 = d2(:,2:end)' * a1; % has same dimensions as Theta1\nD2 = d3' * a2; % has same dimensions as Theta2\n\nTheta1_grad = Theta1_grad + (1/m) * D1;\nTheta2_grad = Theta2_grad + (1/m) * D2;\n\n\n% REGULARIZATION OF THE GRADIENT\n\nTheta1_grad(:,2:end) = Theta1_grad(:,2:end) + (lambda/m)*(Theta1(:,2:end));\nTheta2_grad(:,2:end) = Theta2_grad(:,2:end) + (lambda/m)*(Theta2(:,2:end));\n% -------------------------------------------------------------\n\n% =========================================================================\n\n% Unroll gradients\ngrad = [Theta1_grad(:) ; Theta2_grad(:)];\n\n\nend\n", "meta": {"author": "anirudhjayaraman", "repo": "Machine-Learning", "sha": "084e9c67ac3853f78461f9d0e46c7b41364da481", "save_path": "github-repos/MATLAB/anirudhjayaraman-Machine-Learning", "path": "github-repos/MATLAB/anirudhjayaraman-Machine-Learning/Machine-Learning-084e9c67ac3853f78461f9d0e46c7b41364da481/Andrew Ng Stanford Coursera/Week 05/ex4/nnCostFunction.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582574225517, "lm_q2_score": 0.803173791645582, "lm_q1q2_score": 0.7473196865820119}} {"text": "function X = positive_definite_karcher_mean(A)\n% Computes a Karcher mean of a collection of positive definite matrices.\n%\n% function X = positive_definite_karcher_mean(A)\n%\n% Input: A 3D matrix A of size nxnxm such that each slice A(:,:,k) is a\n% positive definite matrix of size nxn.\n% \n% Output: A positive definite matrix X of size nxn which is a Karcher mean\n% of the m matrices in A, that is, X minimizes the sum of squared\n% Riemannian distances to the matrices in A:\n% f(X) = sum_k=1^m .5*dist^2(X, A(:, :, k))\n% The distance is defined by the natural metric on the set of\n% positive definite matrices: dist(X,Y) = norm(logm(X\\Y), 'fro').\n% \n% This simple example is not the best way to compute Karcher means. Its\n% purpose it to serve as base code to explore other algorithms. In\n% particular, in the presence of large noise, this algorithm seems to not\n% be able to reach points with a very small gradient norm. This may be\n% caused by insufficient accuracy in the gradient computation.\n\n% This file is part of Manopt and is copyrighted. See the license file.\n% \n% Main author: Nicolas Boumal, Sept. 3, 2013\n% Contributors:\n% \n% Change log:\n% \n \n % Generate some random data to test the function if none is given.\n if ~exist('A', 'var') || isempty(A)\n n = 5;\n m = 10;\n A = zeros(n, n, m);\n ref = diag(max(.1, 1+.1*randn(n, 1)));\n for i = 1 : m\n noise = 0.01*randn(n);\n noise = (noise + noise')/2;\n [V D] = eig(ref + noise);\n A(:, :, i) = V*diag(max(.01, diag(D)))*V';\n end\n end\n \n % Retrieve the size of the problem:\n % There are m matrices of size nxn to average.\n n = size(A, 1);\n m = size(A, 3);\n assert(n == size(A, 2), ...\n ['The slices of A must be square, i.e., the ' ...\n\t 'first and second dimensions of A must be equal.']);\n \n % Our search space is the set of positive definite matrices of size n.\n % Notice that this is the only place we specify on which manifold we\n % wish to compute Karcher means. Replacing this factory for another\n % geometry will yield code to compute Karcher means on that other\n % manifold, provided that manifold is equipped with a dist function and\n % a logarithmic map log.\n M = sympositivedefinitefactory(n);\n \n % Define a problem structure, specifying the manifold M, the cost\n % function and its gradient.\n problem.M = M;\n problem.cost = @cost;\n problem.grad = @grad;\n \n % The functions below make many redundant computations. This\n % performance hit can be alleviated by using the caching system. We go\n % for a simple implementation here, as a tutorial example.\n \n % Cost function\n function f = cost(X)\n f = 0;\n for k = 1 : m\n f = f + M.dist(X, A(:, :, k))^2;\n end\n f = f/(2*m);\n end\n\n % Riemannian gradient of the cost function\n function g = grad(X)\n g = M.zerovec(X);\n for k = 1 : m\n % Update g in a linear combination of the form\n % g = g - [something]/m.\n g = M.lincomb(X, 1, g, -1/m, M.log(X, A(:, :, k)));\n end\n end\n \n % Execute some checks on the derivatives for early debugging.\n % These things can be commented out of course.\n % The slopes should agree on part of the plot at least. In this case,\n % it is sometimes necessary to inspect the plot visually to make the\n % call, but it is indeed correct.\n % checkgradient(problem);\n % pause;\n \n % Execute this if you want to force using a proper parallel vector\n % transport. This is not necessary. If you omit this, the default\n % vector transport is the identity map, which is (of course) cheaper\n % and seems to perform well in practice.\n % M.transp = M.paralleltransp;\n \n % Issue a call to a solver. Default options are selected.\n % Our initial guess is the first data point.\n X = trustregions(problem, A(:, :, 1));\n\nend\n", "meta": {"author": "andrewssobral", "repo": "lrslibrary", "sha": "06d457349cb5f1fc56a583cd61af9f1d5150e3a1", "save_path": "github-repos/MATLAB/andrewssobral-lrslibrary", "path": "github-repos/MATLAB/andrewssobral-lrslibrary/lrslibrary-06d457349cb5f1fc56a583cd61af9f1d5150e3a1/libs/manopt/examples/positive_definite_karcher_mean.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213691605411, "lm_q2_score": 0.8311430394931456, "lm_q1q2_score": 0.7472984676373308}} {"text": "function [gd,fnorm]=sgrpdlay(x,fnorm);\n%SGRPDLAY Group delay estimation of a signal.\n%\t[GD,FNORM]=SGRPDLAY(X,FNORM) estimates the group delay of\n%\tsignal X at the normalized frequency(ies) FNORM.\n%\n%\tX : signal in the time-domain.\n%\tFNORM : normalized frequency. By default, FNORM is a \n% linearly spaced vector between -0.5 and 0.5 with\n% length(X) elements.\n%\tGD : computed group delay. When GD equals zero, it means that\n%\t \tthe estimation of the group delay for this frequency was \n%\t\toutside the interval [1 xrow], and therefore meaningless.\n%\n%\tExample : \n%\t N=128; x=amgauss(N,64,30).*fmlin(N,0.1,0.4);\n%\t fnorm=0.1:0.04:0.38; gd=sgrpdlay(x,fnorm); \n%\t t=2:N-1; instf=instfreq(x,t);\n%\t plot(t,instf,gd,fnorm); axis([1 N 0 0.5]); \n\n%\tF. Auger, March 1994, July 1995.\n%\tCopyright (c) 1996 by CNRS (France).\n%\n% This program is free software; you can redistribute it and/or modify\n% it under the terms of the GNU General Public License as published by\n% the Free Software Foundation; either version 2 of the License, or\n% (at your option) any later version.\n%\n% This program is distributed in the hope that it will be useful,\n% but WITHOUT ANY WARRANTY; without even the implied warranty of\n% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n% GNU General Public License for more details.\n%\n% You should have received a copy of the GNU General Public License\n% along with this program; if not, write to the Free Software\n% Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\n\nif (nargin == 0),\n error('At least one parameter required');\nend;\n\n[xrow,xcol] = size(x); \nif (xcol~=1),\n error('x must have only one column');\nend;\nEx=mean(abs(x).^2); \nThreshold=1.0e-6;\n\nif (nargin==1), \n Num=fft(x .* (1:xrow)');\n Den=fft(x);\n ratio=(real(Num./Den) .* (real(Num./Den)>=1) .* (real(Num./Den)<=xrow+3));\n gd=fftshift(ratio);\n if (nargout==2),\n if (rem(xrow,2)==0),\n L=xrow/2;\n fnorm=(-L:L-1)/xrow;\n else\n L=(xrow-1)/2;\n fnorm=(-L:L)/xrow;\n end;\n end;\nelseif (nargin==2),\n [fnormrow,fnormcol] = size(fnorm);\n if (fnormrow~=1),\n error('FNORM must have only one row');\n end;\n expo=exp(-j*2.0*pi*fnorm'*(0:xrow-1));\n Num=expo*(x .* (1:xrow)');\n Den=expo*x; \n gd=(real(Num./Den) .* (real(Num./Den)>=1) .* (real(Num./Den)<=xrow+3));\nend;\n\n", "meta": {"author": "HeLiangHIT", "repo": "time_frequency", "sha": "09c2abe92355ff5cd867bdb169229682e9d7af7c", "save_path": "github-repos/MATLAB/HeLiangHIT-time_frequency", "path": "github-repos/MATLAB/HeLiangHIT-time_frequency/time_frequency-09c2abe92355ff5cd867bdb169229682e9d7af7c/tf_tool_box/tftb-0.2/mfiles/sgrpdlay.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467738423874, "lm_q2_score": 0.849971181358171, "lm_q1q2_score": 0.7472494219500387}} {"text": "%% Performing Gaussian blur\n% I: input image\n% s: standard deviation\n% GI: blurred image\n\nfunction GI = gaussianBlur(I,s)\n\nM = gaussianMask(1,s);\nif max(size(M))==0\n GI=I;\n return;\nend\nM = M/sum(sum(M)); % normalize the gaussian mask\nGI=I;\nfor i=1:(2*s+1)\n GI=BoundMirrorExpand(GI);\nend\nGI = conv2(GI,M,'same');\nfor i=1:(2*s+1)\n GI=BoundMirrorShrink(GI);\nend\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/39553-gmm-hmrf/GMM-HMRF_v1.0/code/color-image/gaussianBlur.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9219218434359676, "lm_q2_score": 0.8104789109591832, "lm_q1q2_score": 0.7471982116574657}} {"text": "%DEMO_WAVELETS Wavelet filter banks\n%\n% This demo exemplifies the use of the wavelet filter bank trees. All \n% representations use \"least asymmetric\" Daubechies wavelet orthonormal\n% filters 'sym8' (8-regular, length 16).\n%\n% .. figure::\n%\n% DWT representation\n%\n% The filter bank tree consists of 11 levels of iterated 2-band basic\n% wavelet filter bank, where only the low-pass output is further \n% decomposed. This results in 12 bands with octave resolution. \n%\n% .. figure::\n%\n% 8-band DWT representation \n%\n% The filter bank tree (effectively) consists of 3 levels of iterated\n% 8-band basic wavelet filter bank resulting in 22 bands. Only the\n% low-pass output is decomposed at each level.\n%\n% .. figure::\n%\n% Full Wavelet filter bank tree representation\n%\n% The filter bank tree depth is 8 and it is fully decomposed meaning\n% both outputs (low-pass and high-pass) of the basic filter bank is\n% plot further. This results in 256 bands linearly covering the \n% frequency axis.\n%\n% .. figure::\n%\n% Full Wavelet filter bank tree representation\n%\n% The same case as before, but symmetric nearly orthogonal basic\n% filter bank is used.\n%\n% .. figure::\n%\n% Full Dual-tree Wavelet filter bank representation\n%\n% This is a 2 times redundant representation using Q-shift dual-tree\n% wavelet filters.\n%\n\n\n% Read the test signal and crop it to the range of interest\n[f,fs]=gspi;\nf=f(10001:100000);\ndr=50;\n \n \nfigure(1);\n[c1,info]=fwt(f,'sym8',11);\nplotwavelets(c1,info,fs,'dynrange',dr);\n\n\n\nfigure(2);\n[c2,info]=wfbt(f,{'sym8',3,'quadband'});\nplotwavelets(c2,info,fs,'dynrange',dr);\n\n\nfigure(3);\n[c3,info]=wfbt(f,{'sym8',8,'full'});\nplotwavelets(c3,info,fs,'dynrange',dr);\n\n\nfigure(4);\n[c4,info]=wfbt(f,{'symorth3',8,'full'});\nplotwavelets(c4,info,fs,'dynrange',dr);\n\nfigure(5);\n[c5,info]=dtwfbreal(f,{'qshift5',8,'full','first','symorth3'});\nplotwavelets(c5,info,fs,'dynrange',dr);\n\n\n\n\n", "meta": {"author": "ltfat", "repo": "ltfat", "sha": "4496a06ad8dddb85cd2e007216b765dc996ef327", "save_path": "github-repos/MATLAB/ltfat-ltfat", "path": "github-repos/MATLAB/ltfat-ltfat/ltfat-4496a06ad8dddb85cd2e007216b765dc996ef327/demos/demo_wavelets.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218327098193, "lm_q2_score": 0.8104789155369047, "lm_q1q2_score": 0.74719820718445}} {"text": "function pendulum()\n% Matlab code for simulating a simple pendulum\n\nP.g = 9.81; %(m/s^2) gravity acceleration\nP.l = 1.0; %(m) length of pendulum \nP.c = 1.0; %(1/s) viscous damping constant\nP.m = 1.0; %(kg) pendulum mass\n\nth0 = 0.5; %(rad) initial angle of pendulum, from -j axis\nw0 = 0.0; %(rad/s) initial angular rate of pendulum\nz0 = [th0;w0]; %Initial state vector\n\ntSpan = [0,4]; %(s) [start, end] times for simulation\ndtMax = 0.01; %(s) maximum allowable time step\n\nnStep = ceil(diff(tSpan)/dtMax); %Number of simulation steps\nt = linspace(tSpan(1),tSpan(2),nStep); %(s) time vector \nz = zeros(2,nStep); % Initialize the state matrix\nz(:,1) = z0;\n\n%Run the simulation, using Euler integration\nfor i=2:nStep\n dt = t(i)-t(i-1);\n zNow = z(:,i-1);\n z(:,i) = zNow + dt*dynamics(zNow,P);\nend\n\n%Generate a plot of the result:\nfigure(1); clf;\nsubplot(2,1,1); plot(t,z(1,:));\nxlabel('Time (s)'); ylabel('Angle (rad)'); \ntitle('Simple Damped Pendulum');\nsubplot(2,1,2); plot(t,z(2,:));\nxlabel('Time (s)'); ylabel('Rate (rad/s)'); \n\nend\n\nfunction dz = dynamics(z,P)\n% Compute the dynamics of a simple damped pendulum:\n\nth = z(1,:); w = z(2,:); %Unpack the state vector\n\n%Dynamics:\ndth = w; \ndw = -(P.g/P.l)*sin(th) - (P.c/(P.m*P.l*P.l))*w;\n\ndz = [dth; dw]; %Pack up state derivative\nend", "meta": {"author": "MatthewPeterKelly", "repo": "dscTutorials", "sha": "e1e97a9be03ec146f88bd6ddd9e06db7ee52e242", "save_path": "github-repos/MATLAB/MatthewPeterKelly-dscTutorials", "path": "github-repos/MATLAB/MatthewPeterKelly-dscTutorials/dscTutorials-e1e97a9be03ec146f88bd6ddd9e06db7ee52e242/SimpleTutorials/pendulum.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218284193595, "lm_q2_score": 0.810478913248044, "lm_q1q2_score": 0.7471982015969723}} {"text": "% By Sherif A. Tawfik, Faculty of Engineering, Cairo University\n% [x,val,status]=IP1(f,A,b,Aeq,beq,lb,ub,M,e)\n% this function solves the following mixed-integer linear programming problem\n% min f*x\n% subject to\n% A*x <=b\n% Aeq * x = beq \n% lb <= x <= ub\n% M is a vector of indeces for the variables that are constrained to be integers\n% e is the integarilty tolerance\n% the return variables are :\n% x : the solution\n% val: value of the objective function at the optimal solution\n% status =1 if successful\n% =0 if maximum number of iterations reached in he linprog function\n% =-1 if there is no solution\n% Example:\n% maximize 17 x1 + 12 x2 \n% subject to\n% \t 10 x1 + 7 x2 <=40\n% x1 + x2 <= 5\n% x1, x2 >=0 and are integers\n% f=[-17, -12]; %take the negative for maximization problems\n% A=[ 10 7; 1 1];\n% B=[40; 5];\n% lb=[0 0];\n% ub=[inf inf];\n% M=[1,2];\n% e=2^-24;\n% [x v s]= IP(f,A,B,[],[],lb,ub,M,e)\n\nfunction [x,val,status]=IP1(f,A,b,Aeq,beq,lb,ub,M,e)\noptions = optimset('display','off');\nbound=inf; % the initial bound is set to +ve infinity\n[x0,val0]=linprog(f,A,b,Aeq,beq,lb,ub,[],options); \n[x,val,status,b]=rec(f,A,b,Aeq,beq,lb,ub,x0,val0,M,e,bound); % a recursive function that processes the BB tree \n\nfunction [xx,val,status,bb]=rec(f,A,b,Aeq,beq,lb,ub,x,v,M,e,bound) \noptions = optimset('display','off');\n% x is an initial solution and v is the corressponding objective function value\n\n% solve the corresponding LP model with the integarily constraints removed\n[x0,val0,status0]=linprog(f,A,b,Aeq,beq,lb,ub,[],options); \n\n% if the solution is not feasible or the value of the objective function is\n% higher than the current bound return with the input intial solution\nif status0<=0 | val0 > bound \n xx=x; val=v; status=status0; bb=bound;\n return;\nend\n\n% if the integer-constraint variables turned to be integers within the\n% input tolerance return\nind=find( abs(x0(M)-round(x0(M)))>e ); \nif isempty(ind)\n status=1; \n if val0 < bound % this solution is better than the current solution hence replace\n x0(M)=round(x0(M));\n xx=x0; \n val=val0;\n bb=val0;\n else\n xx=x; % return the input solution\n val=v;\n bb=bound;\n end\n return\nend\n\n% if we come here this means that the solution of the LP relaxation is\n% feasible and gives a less value than the current bound but some of the\n% integer-constraint variables are not integers. \n% Therefore we pick the first one that is not integer and form two LP problems\n% and solve them recursively by calling the same function (branching)\n\n% first LP problem with the added constraint that Xi <= floor(Xi) , i=ind(1)\nbr_var=M(ind(1));\nbr_value=x(br_var);\nif isempty(A)\n [r c]=size(Aeq);\nelse\n [r c]=size(A);\nend\nA1=[A ; zeros(1,c)];\nA1(end,br_var)=1;\nb1=[b;floor(br_value)];\n\n% second LP problem with the added constraint that Xi >= ceil(Xi) , i=ind(1)\nA2=[A ;zeros(1,c)];\nA2(end,br_var)=-1;\nb2=[b; -ceil(br_value)];\n\n\n% solve the first LP problem\n[x1,val1,status1,bound1]=rec(f,A1,b1,Aeq,beq,lb,ub,x0,val0,M,e,bound);\nstatus=status1;\nif status1 >0 & bound10 & bound2.\n%\n% http://www.petercorke.com\n\nfunction delta = delta2tr(d)\n d = d(:);\n delta = eye(4,4) + [skew(d(4:6)) d(1:3); 0 0 0 0];\n", "meta": {"author": "Allopart", "repo": "rbpf-gmapping", "sha": "affe0adc25fa446fc7af4902d699d92864bdba1b", "save_path": "github-repos/MATLAB/Allopart-rbpf-gmapping", "path": "github-repos/MATLAB/Allopart-rbpf-gmapping/rbpf-gmapping-affe0adc25fa446fc7af4902d699d92864bdba1b/rvctools/robot/delta2tr.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218284193595, "lm_q2_score": 0.8104789086703225, "lm_q1q2_score": 0.7471981973766708}} {"text": "function nuclides\n% Solution for a chain of radionuclides\n% using MATLAB expm \n% $Ekkehard Holzbecher $Date: 2006/28/12 $\n%--------------------------------------------------------------------------\n\nT = 10; % maximum time\nlambda = [1; 0.1; 0.5];% decay rates \nc0 = [1; 0; 0]; % initial concentrations\nq = [0.1; 0; 0]; % source rates\nN = 60; % discretization of time\n\nt = linspace (0,T,N);\nB = -diag(lambda);\nfor i = 2:size(lambda,1)\n B(i,i-1) = lambda(i-1); \nend\nc = c0;\n\nfor i = 2:N\n E = expm(B*t(i));\n c = [c E*c0-(eye(size(B,1))-E)*inv(B)*q];\nend \nplot (t,c');\nlegend ('mother','daughter 1','daughter 2');\ntext (T/2,0.8,'Steady state:'); text (T/2,0.7,num2str(-(inv(B)*q)')); \nxlabel ('time');", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/15646-environmental-modeling/nuclides.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9546474233166329, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.7471667140195097}} {"text": "classdef house\n\nmethods(Static)\n\nfunction [v, beta] = gen(x)\n % Generates the householder reflection vector for a given vector x\n % P = I - beta * v * v' is the householder projection matrix\n % P is an orthogonal projector\n % P *x changes x in such a way that only 1st entry is non-zero\n % GVL4: algorithm 5.1.1\n m = length(x);\n if m == 1\n v = 0; beta = 0; return;\n end\n sigma = x(2:m)' * x(2:m);\n v = [1; x(2:m)];\n if sigma == 0 && x(1) >= 0\n beta = 0;\n elseif sigma == 0 && x(1) < 0\n beta = -2;\n else\n mu = sqrt(x(1)^2 + sigma);\n if x(1) < 0\n v(1) = x(1) - mu;\n else\n v(1) = -sigma /(x(1) + mu);\n end % if\n beta = 2 * v(1)^2 / (sigma + v(1)^2);\n v = v / v(1);\n end % if\nend % func\n\nfunction B = premul(A, v, beta)\n % Efficiently computes B = PA = (I - beta v v') A\n B = A - (beta * v) *(v' * A);\nend % func\n\nfunction B = postmul(A, v, beta)\n % Efficiently computes B = AP = A (I - beta v v')\n B = A - (A*v) * (beta * v)';\nend % func\n\nfunction beta = beta_from_v(v)\n beta = 2/(v'*v);\nend% function\n\nfunction v = from_essential_v(essential)\n v = [zeros(j-1,1); 1; essential];\nend% function\n\nfunction [W, Y] = wy(QF)\n % Let Q be stored in the factored form Q = Q_1 * ... * Q_r\n % where Q_i = I - beta * v * v'\n % This algorithm computes W and Y such that\n % Q = I_r - W * Y';\n % GVL4: algorithm 5.1.2\n [m,r] = size(QF);\n for j=1:r\n % extract j-th v from the factors array\n % The essential part of v\n essential = QF(j+1:m,j);\n % Insert additional zeros and one to complete v\n v = [zeros(j-1,1); 1; essential];\n % Compute beta from v [it is not stored in factors array]\n beta = 2/(v'*v);\n if j==1\n % Initialize W and Y\n Y = v;\n W = beta*v;\n else\n % Update W and Y\n z = beta*(v - W*(Y(j:m,:)'*v(j:m)));\n Y = [Y v];\n W = [W z]; \n end\n end\nend% function\n\nfunction B = wy_premul(A, W, Y)\n % Efficiently computes B = (I - WY') A\n B = A - W*(Y'*A);\nend % func\n\nfunction B = wy_postmul(A, W, Y)\n % Efficiently computes B = A (I - WY')\n B = A - (A*W)*Y';\nend % func\n\n\nfunction [QF, R] = qr(A)\n % Performs A = QR factorization\n % using Householder reflections\n % GVL4: Algorithm 5.2.1\n import spx.la.house;\n [m,n] = size(A);\n for j=1:min(n,m-1)\n % Compute the jth Householder matrix Q{j}...\n [v,beta] = house.gen(A(j:m,j));\n % Update... A = Q_j A\n A(j:m,j:n) = house.premul(A(j:m,j:n), v, beta);\n % Save the essential part of householder vector...\n A(j+1:m,j) = v(2:m-j+1);\n end\n % extract the R component\n R = triu(A(1:n,1:n));\n % extract the Q component in factored form\n QF = tril(A,-1);\nend% function\n\nfunction [QF, R, P] = qr_pivot(A)\n % Householder QR with column pivoting\n % Achieves factorization AP = QR\n % GVL4 : algorithm 5.4.1 \n import spx.la.house;\n [m,n] = size(A);\n % Space for keeping squared norms of columns\n c = zeros(1,n);\n % Compute squared norms of each column\n for j=1:n\n c(j) = A(:,j)'*A(:,j);\n end\n % space for the permutation matrix\n P = 1:n;\n % index of column being processed\n r = 0;\n % Find the index of maximum norm column\n [tau,k] = max(c);\n % The tau > 0 check ensures that we process only till \n % rank of A\n while tau>1e-10 && r0\n % premultiply Q with the householder projector\n Q = Q - (beta*v)*(v'*Q);\n end\n end\nend% function\n\n\nfunction Q = q_back_accum_full(QF)\n % Explicit formation of an orthogonal matrix from its factored form\n % representation. Uses backward accumulation.\n % QF is m x n and \n % Produces an m x m Q that is the product of of Q_{1}...Q_{n}.\n % GVL4: Section 5.2.2\n [m,n] = size(QF);\n % We start with a matrix of size (m-n) x (m -n)\n % If m <= n, then we start with a matrix of size 1 x 1\n Q = eye(max(m-n,1),max(m-n,1));\n % We iterative over columns backwards\n for j=min(n,m-1):-1:1\n % Q_fact(j+1:m,j) is the essential part of the \n % j-th Householder matrix Q_{j}.\n % Get the essential part of householder vector in this column\n essential = QF(j+1:m,j);\n % Extend the vector with 1\n v = [1;essential];\n % Compute beta from the householder vector\n beta = 2/(v'*v);\n % Expand Q with zeros\n k = m-j;\n Q = [1 zeros(1,k);\n zeros(k,1) Q];\n % check for zero changes.\n if norm(essential)>0\n % premultiply with Householder projector\n Q = Q - (beta*v)*(v'*Q);\n end\n end\nend % function\n\nfunction [UF, B, VF] = bidiag(A)\n % Performs bidiagonalization of A = U B V'. \n % U and V are stored in factored forms.\n % GVL4: algorithm 5.4.2\n import spx.la.house;\n [m,n] = size(A);\n % Iterate over columns of A from first to last column.\n % If A is tall, then we can process all columns.\n % If A is square, then we will process m -1 columns\n % If A is wide, we can process all columns.\n for j=1:min(n,m-1)\n % zero out the j-th column\n % Compute the jth Householder vector for U_j\n [u,beta] = house.gen(A(j:m,j));\n % Update... A = U_j A\n A(j:m,j:n) = A(j:m,j:n) - (beta*u)*(u'*A(j:m,j:n));\n % Save the essential part of householder vector...\n A(j+1:m,j) = u(2:m-j+1);\n if j+2<=n\n % zero out the j-th row now\n % Compute the j-th Householder vector for V_j\n [v,beta] = house.gen(A(j,j+1:n)');\n % Update... A = A V_j\n A(j:m,j+1:n) = A(j:m,j+1:n) - (A(j:m,j+1:n)*v)*(beta*v)';\n % Save the essential Householder vector in j-th row\n A(j,j+2:n) = v(2:n-j)'; \n end \n end\n % Extract the diagonal and first super-diagonal\n B = tril(triu(A),1);\n % Extract the subdiagonal lower triangular part\n UF = tril(A,-1);\n % Space for V factors\n VF = zeros(n,n);\n % Extract the factors row by row\n for j=1:n-2\n % j-th row householder vector\n VF(j+2:n,j+1) = A(j,j+2:n)';\n end\nend % function\n\nend % methods \n\nend % classdef\n\n", "meta": {"author": "indigits", "repo": "sparse-plex", "sha": "43cae2978f62938d001baaa03308a2a717ee6c9b", "save_path": "github-repos/MATLAB/indigits-sparse-plex", "path": "github-repos/MATLAB/indigits-sparse-plex/sparse-plex-43cae2978f62938d001baaa03308a2a717ee6c9b/library/+spx/+la/house.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632916317102, "lm_q2_score": 0.8056321959813275, "lm_q1q2_score": 0.747113725109727}} {"text": "function c=ref_dgt_3(f,g,a,M)\n%REF_DGT_3 DGT algorithm 3\n\nL=size(g,1);\nN=L/a;\nb=L/M;\n\n[c,h_a,h_m]=gcd(-a,M);\np=a/c;\nq=M/c;\nd=N/q;\n\nw=zeros(M,N);\n\nif 0\n\n % This version uses the definition.\n\n F=zeros(c,d,p,q);\n G=zeros(c,d,p,q);\n \n for r=0:c-1 \n for s=0:d-1\n for k=0:p-1\n\tfor l=0:q-1\n\t for st=0:d-1\n\t F(r+1,s+1,k+1,l+1)=F(r+1,s+1,k+1,l+1)+f(mod(r+k*M+st*p*M-l*h_a*a,L)+1)*exp(-2*pi*i*s*st/d);\n\t G(r+1,s+1,k+1,l+1)=G(r+1,s+1,k+1,l+1)+g(mod(r+k*M-l*a+st*p*M,L)+1)*exp(-2*pi*i*s*st/d);\n\t end;\n\tend;\n end;\n end;\n end;\n\n for r=0:c-1 \n for l=0:q-1\n for u=0:q-1\n\tfor s=0:d-1\n\t for v=0:d-1\n\t for k=0:p-1\n\t w(r+l*c+1,mod(u+s*q-l*h_a,N)+1)=w(r+l*c+1,mod(u+s*q-l*h_a,N)+1)+...\n\t\t 1/d*F(r+1,v+1,k+1,l+1)*conj(G(r+1,v+1,k+1,u+1))*exp(2*pi*i*v*s/d);\n\t end;\n\t end;\n\tend;\n end;\n end;\n end;\n \n\nelse\n\n % This version uses matrix-vector products and ffts\n\n F=zeros(c,d,p,q);\n G=zeros(c,d,p,q);\n C=zeros(c,d,q,q);\n \n % Set up the matrices\n for r=0:c-1 \n for s=0:d-1\n for k=0:p-1\n\tfor l=0:q-1\n\t F(r+1,s+1,k+1,l+1)=f(mod(r+k*M+s*p*M-l*h_a*a,L)+1);\n\t G(r+1,s+1,k+1,l+1)=sqrt(M*d)*g(mod(r+k*M-l*a+s*p*M,L)+1);\n\tend;\n end;\n end;\n end;\n\n % fft them\n F=dft(F,[],2);\n G=dft(G,[],2);\n \n % Multiply them\n for r=0:c-1 \n for s=0:d-1\n GM=reshape(G(r+1,s+1,:,:),p,q);\n FM=reshape(F(r+1,s+1,:,:),p,q);\n C(r+1,s+1,:,:)=GM'*FM;\n end;\n end;\n\n % Inverse fft\n C=idft(C,[],2);\n\n % Place the result\n for r=0:c-1 \n for l=0:q-1\n for u=0:q-1\n\tfor s=0:d-1\n\t w(r+l*c+1,mod(u+s*q-l*h_a,N)+1)=C(r+1,s+1,u+1,l+1);\n\tend;\n end;\n end;\n end; \n \nend;\n\nc=dft(w);\n\n\n", "meta": {"author": "ltfat", "repo": "ltfat", "sha": "4496a06ad8dddb85cd2e007216b765dc996ef327", "save_path": "github-repos/MATLAB/ltfat-ltfat", "path": "github-repos/MATLAB/ltfat-ltfat/ltfat-4496a06ad8dddb85cd2e007216b765dc996ef327/reference/ref_dgt_3.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632976542184, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.7471137234700435}} {"text": "function [pos, tri] = mesh_icosahedron\n\n% MESH_ICOSAHEDRON returns the vertices and triangle of a 12-vertex icosahedral\n% mesh.\n%\n% Use as\n% [pos, tri] = mesh_icosahedron\n%\n% See also MESH_TETRAHEDRON, MESH_OCTAHEDRON, MESH_SPHERE\n\n% Copyright (C) 2002, Robert Oostenveld\n% Copyright (C) 2019, Robert Oostenveld and Jan-Mathijs Schoffelen\n%\n% This file is part of FieldTrip, see http://www.fieldtriptoolbox.org\n% for the documentation and details.\n%\n% FieldTrip is free software: you can redistribute it and/or modify\n% it under the terms of the GNU General Public License as published by\n% the Free Software Foundation, either version 3 of the License, or\n% (at your option) any later version.\n%\n% FieldTrip is distributed in the hope that it will be useful,\n% but WITHOUT ANY WARRANTY; without even the implied warranty of\n% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n% GNU General Public License for more details.\n%\n% You should have received a copy of the GNU General Public License\n% along with FieldTrip. If not, see .\n%\n\n\ntri = [\n 1 2 3\n 1 3 4\n 1 4 5\n 1 5 6\n 1 6 2\n 2 8 3\n 3 9 4\n 4 10 5\n 5 11 6\n 6 7 2\n 7 8 2\n 8 9 3\n 9 10 4\n 10 11 5\n 11 7 6\n 12 8 7\n 12 9 8\n 12 10 9\n 12 11 10\n 12 7 11\n ];\n\npos = zeros(12, 3);\n\nrho = 0.4*sqrt(5);\nphi = 2*pi*(0:4)/5;\n\npos( 1, :) = [0 0 1]; % top point\n\npos(2:6, 1) = rho*cos(phi)';\npos(2:6, 2) = rho*sin(phi)';\npos(2:6, 3) = rho/2;\n\npos(7:11, 1) = rho*cos(phi - pi/5)';\npos(7:11, 2) = rho*sin(phi - pi/5)';\npos(7:11, 3) = -rho/2;\n\npos(12, :) = [0 0 -1]; % bottom point\n\n% scale all vertices to the unit sphere\npos = pos ./ repmat(sqrt(sum(pos.^2,2)), 1,3);\n", "meta": {"author": "fieldtrip", "repo": "fieldtrip", "sha": "c2039be598a02d86b39aae76bfa7aaa720f9801c", "save_path": "github-repos/MATLAB/fieldtrip-fieldtrip", "path": "github-repos/MATLAB/fieldtrip-fieldtrip/fieldtrip-c2039be598a02d86b39aae76bfa7aaa720f9801c/utilities/private/mesh_icosahedron.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797075998822, "lm_q2_score": 0.8198933425148214, "lm_q1q2_score": 0.747070176095745}} {"text": "function [DVal,totalError,exitCode]=KLDistApproxGaussMix(w1,mu1,P1,w2,mu2,P2,algorithm,param8,w)\n%%KLDISTAPPROXGAUSSMIX Approximate the Kullback-Leibler (KL) divergence\n% (also known as the KL distance or relative entropy) between two\n% multivariate Gaussian mixture distributions. Whereas an explicit\n% solution is available for the KL distance between two Gaussian\n% PDFs, no explicit solution exists between a Gaussian PDF and a\n% Gaussian mixture. Thus, various approximations are necessary.\n% As defined in Chapter 8.5 of [4], the relative entropy between\n% two continuous PDFs, f and g, is\n% D(f||g)=integral_{x} f(x) log(f(x)/g(x)) dx\n% The integral is over an appropriate domain of x, in this case\n% the d-dimensional real space for an n-dimensional state. Note\n% that changing the order of f and g changes the result (the\n% operation is not commutative).\n%\n%INPUTS: w1 The 1Xn1 or n1X1 set of weights of the first Gaussian mixture's\n% components such that all w>=0 and sum(w)=1.\n% mu1 The dXn1 set of mean values of the first Gaussian mixture's\n% components.\n% P1 The dXxdXn1 set of covariance matrices of the first Gaussian\n% mixture's components.\n% w2,mu2,P2 The equivalent of w1, mu1 and P1 for the second mixtures\n% components. There length-n2, dXn2, and dXdXn2 in size.\n% algorithm An optional parameter specifying the algorithm used to obtain\n% the approximation of the KL divergence. Possible values are\n% for:\n% 0 Use adaptive numeric integration to directly evaluate the\n% Kullback-Leiberler divergence integral over a rectangular \n% region that is standard deviations from the means of the\n% distributions. The default number of standard deviations in\n% each direction is 4.5 and can be adjusted by passing a member\n% of param8 named 'numStdDev'. In 1D, the function\n% integral1DAdaptiveCC is used for the integration and the\n% inputs to that function 'RelTol', 'AbsTol', 'NPowMin', and\n% 'NPowMax' can be passed as members of param8 if one wishes to\n% not use the defaults. If higher dimensions, the function\n% integrateUnifCub57Adaptive is used for the numeric\n% integration and the inputs to that function 'maxSearchReg',\n% 'AbsTol', and 'RelTol' can be passed if one wishes to not use\n% the defaults. This approximation can produce negative\n% values, though it is often good.\n% 1 Monte Carlo sampling from Equation 4 of Section 2 of [3].\n% This uses param8 as the number of samples (if given). The\n% default if param8 is not given is 3e3. As the number of\n% samples increases, this method should become increasingly\n% accurate. This approximation can produce negative values.\n% 2 (The default if omitted or an empty matrix is passed) The\n% cubature integration approximation from Equation 8 in Section\n% 3 of [3]. This uses param8 as the cubature points and w as\n% the weights, if provided. If not provided, then\n% fifthOrderCubPoints is used to obtain fifth-order xDim-\n% dimensional cubature points. This approximation can produce\n% negative values.\n% 3 Use the variational upper bound from Section 8 of [3]. This\n% approximation should always be positive. 10 iterations are\n% performed. This bound is typically not zero when the two\n% input PDFs are equal.\n% 4 The variational approximation from Section 7 of [3] (also\n% given in [1]). This approximation can produce negative\n% values.\n% 5 The product of Gaussians approximation in [1] and Section 5\n% of [3]. This approximation can produce negative values.\n% 6 Take the average of algorithms 5 and 4, which tend to be\n% upper and lower bounds.\n% 7 Goldberger's approximation from Equation 2 of [2]. This is\n% also given in Section 6 of [3] as the matched bound\n% approximation. This approximation can produce negative\n% values and is often quite bad with certain classes of\n% distributions.\n% param8 An optional parameter. If algorithm=0, then this is a structure\n% that can take members as described above for algorithm 0. If\n% algorithm=1, then this is the number of samples to use. If\n% algorithm=2, then this is a set of cubature points as a\n% dXnumPoints matrix. For other values of algorithm, this input\n% is not used.\n% w This input is only used if algorithm=2, in which case it is the\n% set of cubature weights (sum(w)=1). that are associated with\n% the cubature points in param8. If param8 is omitted or an empty\n% matrix is passed, then w will be the weights associated with\n% the points from the fifthOrderCubPoints function.\n%\n%%OUTPUTS: val The approximate value of the Kullback-Leibler divergence\n% between the first and the second Gaussian mixture\n% distributions.\n%\n%Some approximations can produce negative values (the true KL divergence\n%can never be negative).\n%\n%EXAMPLE 1:\n%Though many of the algorithms are often cited in the literature, many of\n%the approximations can be quite bad. Here, we consider a 1D example and\n%then the mixture missing a few components and also the moment-matched\n%Gaussian approximation.\n% w1=[0.03,0.18,0.12,0.19,0.02,0.16,0.06,0.1,0.08,0.06];\n% n1=length(w1);\n% mu1=[1.45,2.20,0.67,0.48,1.49,0.91,1.01,1.42,2.77,0.89];\n% P1=[0.0487,0.0305,0.1171,0.0174,0.0295,0.0102, 0.0323, 0.0380, 0.0115, 0.0679];\n% P1=reshape(P1,[1,1,n1]);\n% \n% %The second PDF is the first with the five least-weight components deleted.\n% w2=[0.18,0.12,0.19,0.16,0.1,0.08];\n% w2=w2/sum(w2);\n% n2=length(w2);\n% mu2=[2.20,0.67,0.48,0.91,1.42,2.77];\n% P2=[0.0305,0.1171,0.0174,0.0102,0.0380,0.0115];\n% P2=reshape(P2,[1,1,n2]);\n% \n% %The third PDF is the second PDF with two more components deleted.\n% w3=[0.18,0.12,0.19,0.16];\n% w3=w3/sum(w3);\n% n3=length(w3);\n% mu3=[2.20,0.67,0.48,0.917];\n% P3=[0.0305,0.1171,0.0174,0.0102];\n% P3=reshape(P3,[1,1,n3]);\n% \n% %The fourth PDF is just the Gaussian matching the first two moments of the\n% %original PDF.\n% w4=1;\n% [mu4,P4]=calcMixtureMoments(mu1,w1,P1);\n% \n% DVal=zeros(8,3);\n% for curAlg=0:7\n% DVal(curAlg+1,1)=KLDistApproxGaussMix(w1,mu1,P1,w2,mu2,P2,curAlg);\n% DVal(curAlg+1,2)=KLDistApproxGaussMix(w1,mu1,P1,w3,mu3,P3,curAlg);\n% DVal(curAlg+1,3)=KLDistApproxGaussMix(w1,mu1,P1,w4,mu4,P4,curAlg);\n% end\n% RelErr=abs(bsxfun(@rdivide,bsxfun(@minus,DVal,DVal(1,:)),DVal(1,:)))\n% %The rows of RelErr are the algorithms and the PDF chosen for comparison\n% %against the original PDF is given by the column. The value obtained\n% %through the numeric integration (algorithm 0) is nearly exact, so it is\n% %taken as a basis of comparison for the relative error of the\n% %approximations. It can be seen that some approximations are much worse\n% %than others.\n% %We can visualize the above PDFs.\n% numPoints=500;\n% xVals=linspace(0,3,numPoints);\n% PDFVals1=GaussianMixtureD.PDF(xVals,w1,mu1,P1);\n% PDFVals2=GaussianMixtureD.PDF(xVals,w2,mu2,P2);\n% PDFVals3=GaussianMixtureD.PDF(xVals,w3,mu3,P3);\n% PDFVals4=GaussianMixtureD.PDF(xVals,w4,mu4,P4);\n% figure(1)\n% clf\n% hold on\n% plot(xVals,PDFVals1,'-k','linewidth',4)\n% plot(xVals,PDFVals2,'-r','linewidth',2)\n% plot(xVals,PDFVals3,'--g','linewidth',2)\n% plot(xVals,PDFVals4,'-.b','linewidth',2)\n% legend('10 Elements', '5 Elements', '3 Elements','Matched Gaussian')\n%\n%EXAMPLE 2:\n%Here is an example with bivariare Gaussian mixtures. \n% w1=[0.25;0.5;0.25];\n% mu1=zeros(2,2);\n% mu1(:,1)=[1;-1];\n% mu1(:,2)=[-1;1];\n% mu1(:,3)=[0;0];\n% P1=zeros(2,2,2);\n% P1(:,:,1)=[4/9, 14/45;\n% 14/45,4/9];\n% P1(:,:,2)=[4/9, 0;\n% 0, 4/9];\n% P1(:,:,3)=[2/9, -1/9;\n% -1/9, 3/9];\n% \n% %The second distribution just throws out the first component.\n% w2=w1(2:3);\n% w2=w2/sum(w2);\n% mu2=mu1(:,2:3);\n% P2=P1(:,:,2:3);\n% \n% %The third distribution replaces the original distribution with a single\n% %moment-matched Gaussian.\n% w3=1;\n% [mu3,P3]=calcMixtureMoments(mu1,w1,P1);\n% \n% DVal=zeros(8,2);\n% for curAlg=0:7\n% DVal(curAlg+1,1)=KLDistApproxGaussMix(w1,mu1,P1,w2,mu2,P2,curAlg);\n% DVal(curAlg+1,2)=KLDistApproxGaussMix(w1,mu1,P1,w3,mu3,P3,curAlg);\n% end\n% RelErr=abs(bsxfun(@rdivide,bsxfun(@minus,DVal,DVal(1,:)),DVal(1,:)))\n% %The rows of RelErr are the algorithms and the PDF chosen for comparison\n% %against the original PDF is given by the column. The value obtained\n% %through the numeric integration (algorithm 0) has a few digits of\n% %accuracy, so it is taken as a basis of comparison for the relative\n% %error of the approximations. It can be seen that some approximations are\n% %much worse than others.\n% %We can visualize the above PDFs.\n% figure(1)\n% clf\n% subplot(3,1,1);\n% numPoints=250;\n% vals=linspace(-3,3,numPoints);\n% [X,Y]=meshgrid(vals,vals);\n% points=[X(:)';Y(:)'];\n% PDFVals=GaussianMixtureD.PDF(points,w1,mu1,P1);\n% PDFVals=reshape(PDFVals,numPoints,numPoints);\n% surf(X,Y,PDFVals,'EdgeColor','none')\n% title('Full PDF')\n% %Plot the reduced PDF\n% subplot(3,1,2);\n% numPoints=250;\n% vals=linspace(-3,3,numPoints);\n% [X,Y]=meshgrid(vals,vals);\n% points=[X(:)';Y(:)'];\n% PDFVals=GaussianMixtureD.PDF(points,w2,mu2,P2);\n% PDFVals=reshape(PDFVals,numPoints,numPoints);\n% surf(X,Y,PDFVals,'EdgeColor','none')\n% title('Missing 1 Component')\n% %Plot the Gaussian approximation.\n% subplot(3,1,3);\n% numPoints=250;\n% vals=linspace(-3,3,numPoints);\n% [X,Y]=meshgrid(vals,vals);\n% points=[X(:)';Y(:)'];\n% PDFVals=GaussianMixtureD.PDF(points,w3,mu3,P3);\n% PDFVals=reshape(PDFVals,numPoints,numPoints);\n% surf(X,Y,PDFVals,'EdgeColor','none')\n% title('Gaussian Approximation')\n%\n%REFERENCES:\n%[1] J. L. Durrieu, J. P. Thiran, and F. Kelly, \"Lower and upper bounds for\n% approximation of Kullback-Leibler divergence between Gaussian mixture\n% models,\" in Proceedings of the IEEE International Conference on\n% Acoustics, Speech and Signal Processing, Kyoto, Japan, 25-30 Mar.\n% 2012, pp. 4833-4836.\n%[2] J. Goldberger, S. Gordon, and H. Greenspan, \"An efficient image\n% similarity measure based on approximations of KL-divergence between\n% two Gaussian mixtures,\" in Proceedings of the Ninth IEEE International\n% Conference on Computer Vision, Nice, France, 2003.\n%[3] J. R. Hershey and P. A. Olden, \"Approximating the Kullback Leibler\n% divergence between Gaussian mixture models,\" in Proceedings of the\n% IEEE International Conference on Acoustics, Speech and Signal\n% Processing, Honolulu, HI, 15-20 Apr. 2007.\n%[4] T. M. Cover and J. A. Thomas, Elements of Information Theory, 2nd ed.\n% Hoboken, NJ: Wiley-Interscience, 2006.\n%\n%July 2019 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nif(nargin<7||isempty(algorithm))\n algorithm=2;\nend\n\nd=size(mu1,1);\nn1=length(w1);\nn2=length(w2);\n\ntotalError=[];\nexitCode=0;\nswitch(algorithm)\n case 0%Numeric integration over a bounded region.\n if(nargin>7&&~isempty(param8))\n if(isfield(param8,'numStdDev'))\n numStdDev=param8.numStdDev;\n end\n else\n numStdDev=4.5;\n end\n\n [mu1Merged,P1Merged]=calcMixtureMoments(mu1,w1,P1);\n [mu2Merged,P2Merged]=calcMixtureMoments(mu2,w2,P2);\n\n stdDevStep1=numStdDev*sqrt(diag(P1Merged));\n stdDevStep2=numStdDev*sqrt(diag(P2Merged));\n \n P1Inv=zeros(d,d,n1);\n P1InvDet=zeros(n1,1);\n P2Inv=zeros(d,d,n2);\n P2InvDet=zeros(n2,1);\n for k=1:n1\n P1Inv(:,:,k)=inv(P1(:,:,k));\n P1InvDet(k)=det(P1Inv(:,:,k));\n end\n for k=1:n2\n P2Inv(:,:,k)=inv(P2(:,:,k));\n P2InvDet(k)=det(P2Inv(:,:,k));\n end\n \n upperBounds=max(mu1Merged+stdDevStep1,mu2Merged+stdDevStep2);\n lowerBounds=min(mu1Merged-stdDevStep1,mu2Merged-stdDevStep2);\n\n f=@(x)KLArgGaussMix(x,w1,mu1,P1Inv,P1InvDet,w2,mu2,P2Inv,P2InvDet);\n\n if(d==1)\n %A different integration routine is used for 1D veruss\n %arbitrary dimensional integrals.\n bounds=[lowerBounds;upperBounds];\n\n RelTol=[];\n AbsTol=[];\n NPowMin=[];\n NPowMax=[];\n if(nargin>7&&~isempty(param8))\n if(isfield(param8,'RelTol'))\n RelTol=param8.RelTol;\n end\n \n if(isfield(param8,'AbsTol'))\n AbsTol=param8.AbsTol;\n end\n \n if(isfield(param8,'NPowMin'))\n NPowMin=param8.NPowMin;\n end\n \n if(isfield(param8,'NPowMax'))\n NPowMax=param8.NPowMax;\n end\n end\n\n [DVal,totalError,exitCode]=integral1DAdaptiveCC(f,bounds,RelTol,AbsTol,NPowMin,NPowMax);\n else\n maxSearchReg=[];\n AbsTol=[];\n RelTol=[];\n if(nargin>7&&~isempty(param8))\n if(isfield(param8,'RelTol'))\n RelTol=param8.RelTol;\n end\n \n if(isfield(param8,'AbsTol'))\n AbsTol=param8.AbsTol;\n end\n \n if(isfield(param8,'maxSearchReg'))\n maxSearchReg=param8.maxSearchReg;\n end\n end\n\n [DVal,totalError,exitCode]=integrateUnifCub57Adaptive(f,lowerBounds,upperBounds,maxSearchReg,AbsTol,RelTol);\n end\n case 1%Monte Carlo sampling from Equation 4 of Section 2 of [3].\n if((nargin<8||isempty(param8)))\n numSamp=2e3;\n else\n numSamp=param8;\n end\n \n S1=zeros(d,d,n1);\n S2=zeros(d,d,n2);\n for k=1:n1\n S1(:,:,k)=chol(P1(:,:,k),'lower');\n end\n for k=1:n2\n S2(:,:,k)=chol(P2(:,:,k),'lower');\n end\n \n x1Samp=GaussianMixtureD.randS(numSamp,w1,mu1,S1);\n PDFVals1=GaussianMixtureD.PDFS(x1Samp,w1,mu1,S1);\n \n logVals=log(PDFVals1)-log(GaussianMixtureD.PDFS(x1Samp,w2,mu2,S2));\n %Get rid of points where PDFVals1==0 due to finite precision\n %errors. This probably won't occur. However, eliminating them also\n %gets rid of any unlikely points where both PDFs evaluate to 0 and\n %thus avoids returning NaN values.\n sel=(PDFVals1==0);\n logVals(sel)=0;\n\n DVal=sum(logVals)/numSamp;\n case 2%The cubature integration approximation from Equation 8 in\n %Section 3 of [3].\n if(nargin<8||isempty(param8))\n [xi,w]=fifthOrderCubPoints(d);\n else\n xi=param8;\n end\n\n S1=zeros(d,d,n1);\n S2=zeros(d,d,n2);\n for k=1:n1\n S1(:,:,k)=chol(P1(:,:,k),'lower');\n end\n for k=1:n2\n S2(:,:,k)=chol(P2(:,:,k),'lower');\n end\n \n w=w(:).';\n DVal=0;\n for a=1:n1\n %The component over which the expected value is taken.\n xiCur=transformCubPoints(xi,mu1(:,a),S1(:,:,a));\n\n logVals=log(GaussianMixtureD.PDFS(xiCur,w1,mu1,S1))-log(GaussianMixtureD.PDFS(xiCur,w2,mu2,S2));\n %Get rid of NaN values.\n %logVals(isnan(logVals))=0;\n \n DVal=DVal+w1(a)*sum(logVals.*w);\n end \n case 3%The variational upper bound from Section 8 of [3].\n psi=zeros(n1,n2);\n phi=zeros(n2,n1);\n \n %We start with psi and phi being the same and equal to what would\n %produce the convexity bound:\n for a=1:n1\n for b=1:n2\n psi(a,b)=w1(a)*w2(b);\n phi(b,a)=psi(a,b);\n end\n end\n \n %Get all pairwise KL-divergences.\n DKLg=zeros(n1,n2);\n for a=1:n1\n for b=1:n2\n DKLg(a,b)=KLDistGauss(mu1(:,a),P1(:,:,a),mu2(:,b),P2(:,:,b));\n end\n end\n expnDKLg=exp(-DKLg);\n\n numIter=10;\n for curIter=1:numIter\n %Equation 24 for phi.\n for a=1:n1\n denom=sum(psi(a,:).*expnDKLg(a,:));\n for b=1:n2\n phi(b,a)=w1(a)*psi(a,b)*expnDKLg(a,b)/denom;\n end\n end\n \n %Equation 23 for psi\n for b=1:n2\n denom=sum(phi(b,:));\n for a=1:n1 \n psi(a,b)=w2(b)*phi(b,a)/denom;\n end\n end\n end\n \n %The first term in Equation 22\n term1=0;\n term2=0;\n for a=1:n1\n for b=1:n2\n val=phi(b,a)*log(phi(b,a)/psi(a,b));\n if(isnan(val))\n val=0;\n end\n term1=term1+val;\n\n term2=term2+phi(b,a)*DKLg(a,b);\n end\n end\n\n DVal=term1+term2;\n case 4%The variational approximation from Section 2.3 of [1] and\n %Section 7 of [3].\n\n %Compute the necessary KL divergences.\n DKLf=zeros(n1,n1);\n DKLg=zeros(n1,n2);\n for a=1:n1\n DKLf(a,a)=KLDistGauss(mu1(:,a),P1(:,:,a),mu1(:,a),P1(:,:,a));\n for ap=(a+1):n1\n DKLf(a,ap)=KLDistGauss(mu1(:,a),P1(:,:,a),mu1(:,ap),P1(:,:,ap));\n DKLf(ap,a)=KLDistGauss(mu1(:,ap),P1(:,:,ap),mu1(:,a),P1(:,:,a));\n end\n\n for b=1:n2\n DKLg(a,b)=KLDistGauss(mu1(:,a),P1(:,:,a),mu2(:,b),P2(:,:,b));\n end\n end\n\n %Evaluate the sum in Equation 18 of [1], which is the same as\n %Equation 20 of [3].\n DVal=0;\n w1=w1(:).';\n w2=w2(:).';\n for a=1:n1\n DVal=DVal+w1(a)*(log(sum(w1.*exp(-DKLf(a,:))))-log(sum(w2.*exp(-DKLg(a,:)))));\n end\n case 5%The product of Gaussians approximation in [1] and Section 5 of\n %[3].\n \n P1Inv=zeros(d,d,n1);\n P2Inv=zeros(d,d,n2);\n for k=1:n1\n P1Inv(:,:,k)=inv(P1(:,:,k));\n end\n for k=1:n2\n P2Inv(:,:,k)=inv(P2(:,:,k));\n end\n\n %We have to first compute the z and t terms. The logarithms of the z\n %and t terms are given in Equation 22 in [1]. However, that\n %expression is incorrect; the corrected expression is used here\n\n zaap=zeros(n1,n1);\n tab=zeros(n1,n2);\n for a=1:n1\n for ap=a:n1\n diff=mu1(:,a)-mu1(:,ap);\n Sigmad=inv(P1Inv(:,:,a)+P1Inv(:,:,ap));\n const=sqrt(det(2*pi*Sigmad))/(sqrt(det(2*pi*P1(:,:,a))*det(2*pi*P1(:,:,ap))));\n \n B=P1Inv(:,:,a)*Sigmad*P1Inv(:,:,ap);\n zaap(a,ap)=const*exp(-(1/2)*diff'*B*diff);\n zaap(ap,a)=zaap(a,ap);\n end\n\n for b=1:n2\n diff=mu1(:,a)-mu2(:,b);\n Sigmad=inv(P1Inv(:,:,a)+P2Inv(:,:,b));\n const=sqrt(det(2*pi*Sigmad))/(sqrt(det(2*pi*P1(:,:,a))*det(2*pi*P2(:,:,b))));\n \n B=P1Inv(:,:,a)*Sigmad*P2Inv(:,:,b);\n tab(a,b)=const*exp(-(1/2)*diff'*B*diff);\n end\n end\n \n %Evaluate the sum in Equation 12 of [1], which is the same as\n %Equation 12 of [3].\n DVal=0;\n w1=w1(:).';\n w2=w2(:).';\n for a=1:n1\n DVal=DVal+w1(a)*(log(sum(w1.*zaap(a,:)))-log(sum(w2.*tab(a,:))));\n end\n case 6\n DProd=KLDistApproxGaussMix(w1,mu1,P1,w2,mu2,P2,5);\n DVar=KLDistApproxGaussMix(w1,mu1,P1,w2,mu2,P2,4);\n DVal=(DProd+DVar)/2;\n case 7%Goldberger's approximation from Equation 2 of [2].\n DKLg=zeros(n1,n2);\n for a=1:n1\n for b=1:n2\n DKLg(a,b)=KLDistGauss(mu1(:,a),P1(:,:,a),mu2(:,b),P2(:,:,b));\n end\n end\n \n w2=w2(:).';\n\n %Perform the minimization in Equation 1 of [2], which is also given\n %in Equation 14 of [3] and simultaneously evaluate Equation 2 of\n %[2], which is the same as Equation 15 in [3].\n DVal=0;\n logw2=log(w2);\n for a=1:n1\n minVal=min(DKLg(a,:)-logw2);\n DVal=DVal+w1(a)*(log(w1(a))+minVal);\n end\n otherwise\n error('Unknown algorithm specified.')\nend\nend\n\nfunction val=KLArgGaussMix(x,w1,mu1,P1Inv,P1InvDet,w2,mu2,P2Inv,P2InvDet)\n%%KLSAMPGAUSSMIX The KL divergence is an integral. This evaluates the\n% argument of the integral for the KL divergences between\n% two Gaussian mixtures.\n%\n%July 2019 David F. Crouse, Naval Research Laboratory, Washington D.C.\n\nPDF1=GaussianMixtureD.PDFI(x,w1,mu1,P1Inv,P1InvDet);\nPDF2=GaussianMixtureD.PDFI(x,w2,mu2,P2Inv,P2InvDet);\n\nval=PDF1.*(log(PDF1)-log(PDF2));\nval(isnan(val))=0;\n\nend\n\n%LICENSE:\n%\n%The source code is in the public domain and not licensed or under\n%copyright. The information and software may be used freely by the public.\n%As required by 17 U.S.C. 403, third parties producing copyrighted works\n%consisting predominantly of the material produced by U.S. government\n%agencies must provide notice with such work(s) identifying the U.S.\n%Government material incorporated and stating that such material is not\n%subject to copyright protection.\n%\n%Derived works shall not identify themselves in a manner that implies an\n%endorsement by or an affiliation with the Naval Research Laboratory.\n%\n%RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF THE\n%SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY THE NAVAL\n%RESEARCH LABORATORY FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE ACTIONS\n%OF RECIPIENT IN THE USE OF THE SOFTWARE.\n", "meta": {"author": "USNavalResearchLaboratory", "repo": "TrackerComponentLibrary", "sha": "9f6e329de5be06a371757c4b853200beb6def2d0", "save_path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary", "path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary/TrackerComponentLibrary-9f6e329de5be06a371757c4b853200beb6def2d0/Mathematical_Functions/Statistics/KLDistApproxGaussMix.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797100118214, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.7470701740633064}} {"text": "%AKSHAY GORE\n% email id:akshaygore@live.com\n%MOB NO 9464894829\n%Chandigarh university\n%EDGE DETECTION BASED ON \n% 'average' averaging filter\n% 'disk' circular averaging filter\n% 'gaussian' Gaussian lowpass filter\n% 'laplacian' filter approximating the 2-D Laplacian operator\n% 'log' Laplacian of Gaussian filter\n% 'motion' motion filter\n% 'prewitt' Prewitt horizontal edge-emphasizing filter\n% 'sobel' Sobel horizontal edge-emphasizing filter\n% 'unsharp' unsharp contrast enhancement filter\nfunction EDGE_DETECTION_NEW_2013(userImage)\n% Clean up.\nclc; % Clear the command window.\nclear all;\nclose all; % Close all figures (except those of imtool.)\nworkspace;\nfontSize = 18;\n\nif nargin == 0\n % No image passed in on the command line.\n % Read in one of the standard MATLAB demo images\n % as our original gray scale image and display it.\n promptMessage = sprintf('Which image do you want to use');\n button = questdlg(promptMessage, 'Select Image', 'Coins', 'Cameraman','Coins');\n if strcmp(button, 'Coins')\n grayImage = double(imread('coins.png')); % Cast to double.\n else\n grayImage = double(imread('cameraman.tif')); % Cast to double.\n end\nelse\n % Use the image array passed in on the command line.\n grayImage = double(userImage); % Cast to double.\nend\n% Start timing.\n%startTime = tic;\n\nfigure(1),subplot(2, 3, 1);\nimshow(grayImage, []);\ntitle('Original Image', 'FontSize', fontSize);\nset(gcf, 'Position', get(0,'Screensize')); % Maximize figure.\n\n% Blur the image with a 5 by 5 averaging (box filter) window.\nblurredImage = conv2(grayImage, ones(5,5)/25);\nfigure(1),subplot(2, 3, 2);\nimshow(blurredImage, []);\ntitle('Blurred Image', 'FontSize', fontSize);\n% Perform a variance filter.\n% Output image is the variance of the input image in a 3 by 3 sliding window.\nVarianceFilterFunction = @(x) var(x(:));\nvarianceImage = nlfilter(grayImage, [3 3], VarianceFilterFunction);\n% An alternate way of doing the variance filter is on the next line:\n% varianceImage = reshape(std(im2col(originalImage,[3 3],'sliding')),\n%size(Original Image-2);\nfigure(1),subplot(2, 3, 3);\nimshow(varianceImage, [])\ntitle('Variance Image', 'FontSize', fontSize);\n\n% Compute the square root of the variance image to get the standard deviation.\nstandardDeviationImage = sqrt(varianceImage);\nfigure(1),subplot(2, 3, 4);\nimshow(standardDeviationImage, [])\ntitle('Standard Deviation Image', 'FontSize', fontSize);\n\n% Compute the standard deviation filter with MATLAB's built-in stdfilt() filter.\nstandardDeviationImage2 = stdfilt(grayImage);\nfigure(1),subplot(2, 3, 5);\nimshow(standardDeviationImage2, [])\ntitle('Built-in stdfilt() filter', 'FontSize', fontSize);\n\n% Perform Sobel filter on image in both direction\n% h = fspecial('sobel') returns a 3-by-3 filter h (shown below) thatemphasizes horizontal edges\n% using the smoothing effect by approximating a vertical gradient.\n% If you need to emphasize vertical edges, transpose the filter h'.\n% [ 1 2 1\n% 0 0 0\n% -1 -2 -1 ]\nverticalSobel = fspecial('sobel')';\nsobelImage = imfilter(blurredImage, verticalSobel);\nfigure(2),subplot(3, 3, 1);\nimshow(sobelImage, [])\ntitle('Sobel edge filter', 'FontSize', fontSize);\n%Perform UNSHARP filter\nverticalunsharp = fspecial('unsharp');\nunsharpImage = imfilter(blurredImage, verticalunsharp);\nfigure(2),subplot(3,3,2);\nimshow(unsharpImage, [])\ntitle('Unsharp image', 'FontSize', fontSize);\nset(gcf, 'Position', get(0,'Screensize'));\n%Perform LAPLACIAN filter\nverticallaplacian = fspecial('laplacian');\nlaplacianImage = imfilter(blurredImage, verticallaplacian);\nfigure(2),subplot(3,3,3);\nimshow(laplacianImage, [])\ntitle('Laplacian image', 'FontSize', fontSize);\n%Perform LOG filter\nverticallog = fspecial('log');\nlogImage = imfilter(blurredImage, verticallog);\nfigure(2),subplot(3,3,4);\nimshow(logImage, [])\ntitle('Log image', 'FontSize', fontSize);\n%Perform MOTION FILTER ON IMAGE\nverticalmotion = fspecial('motion');\nmotionImage = imfilter(blurredImage, verticalmotion);\nfigure(2),subplot(3,3,5);\nimshow(motionImage, [])\ntitle('Motion image', 'FontSize', fontSize);\n%PERFORM PREWITT FILTER ON IMAGE\nverticalprewitt = fspecial('prewitt');\nprewittImage = imfilter(blurredImage, verticalprewitt);\nfigure(2),subplot(3,3,6);\nimshow(prewittImage, [])\ntitle('Prewitt image', 'FontSize', fontSize);\n% PERFORM AVERAGE FILTER ON IMAGE\nverticalaverage = fspecial('average');\naverageImage = imfilter(blurredImage, verticalaverage);\nfigure(2),subplot(3,3,7);\nimshow(averageImage, [])\ntitle('Average image', 'FontSize', fontSize);\n%PERFORM DISK FILTER ON IMAGE\nverticaldisk = fspecial('disk');\ndiskImage = imfilter(blurredImage, verticaldisk);\nfigure(2),subplot(3,3,8);\nimshow(diskImage, [])\ntitle('Disk image', 'FontSize', fontSize);\n\n%CHANDIGARH UNIVERSITY\nend\n\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/43343-edgedetection2013-2014/EDGE_DETECTION_NEW_2013.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9111797148356995, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.7470701740084004}} {"text": "%% pdf_Uniform: Uniform Probability Density Function\n%\n% Usage:\n% x = pdf_Uniform(N, range, seed)\n%\n% Inputs:\n% N scalar, number of samples\n% range vector [min max] range of the random variable\n% seed optional, seed for the random number generator\n%\n% Output:\n% x vector with the sampled data\n% if N==0 -> x = range \n%\n% ------------------------------------------------------------------------\n% See also \n%\n% Author : Flavio Cannavo'\n% e-mail: flavio(dot)cannavo(at)gmail(dot)com\n% Release: 1.0\n% Date : 28-01-2011\n%\n% History:\n% 1.0 28-01-2011 First release.\n%%\n\nfunction x = pdf_Uniform(N, range, seed)\n\nif nargin>2\n rand('twister',seed);\nelse\n rand('twister', round(cputime*1000 + 100000*rand));\nend\n\nif N==0\n x = range(:)';\nelse\n x = rand(N,1)*diff(range) + range(1);\nend\n \n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/40759-global-sensitivity-analysis-toolbox/GSAT/pdf_Uniform.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9086179043564154, "lm_q2_score": 0.8221891327004133, "lm_q1q2_score": 0.7470557667388683}} {"text": "function r = gedrnd(v,varargin)\n% Generate random variables from a Generalized Error Distribution (GED) with V degrees of freedom\n%\n% USAGE:\n% R=gedrnd(V)\n% R=gedrnd(V,S1)\n% R=gedrnd(V,S1,S2,S3,...,SN)\n% R=gedrnd(V,[S1 S2 S3 ... SN])\n%\n% INPUTS:\n% V - Degree of freedom parameter. Either scalar or matrix.\n% Sx - [OPTIONAL] Size of output.\n% R will be:\n% 1 by 1 if V is scalar and no S are entered\n% size(V) if V is non-scalar and no S are entered\n% S1 by S1 if V is scalar and only S1 is entered\n% [S1 S2 ... SN] otherwise\n% If V is non-scalar and S are provided, size(V) must equal [S1 S2 ... SN]\n%\n% OUTPUTS:\n% R - GED distributed random variables\n%\n% COMMENTS:\n% V>=1\n% A scalar GED r.v. with variance normalized to 1 has probability\n% density given by:\n% f(x,v) = [v/(lda*2^(1+1/v)*gamma(1/v))]*exp(-0.5*|x/lda|^v)\n% lda = [2^(-2/v)*gamma(1/v)/gamma(3/v)]^0.5\n% If X~GED(v) then abs(X)^v = Y~Gamma(1/v) (cf. Tadikamalla 1980).\n% GAMRND does the computational work.\n%\n% REFERENCES:\n% [1] Tadikamalla (1980), J.Am.Stat.Assoc. (75)\n% [2] Nelson (1991), Econometrica\n%\n% See also GEDPDF, GEDCDF, GEDINV, GEDLL, GAMRND\n\n% Copyright: Ivana Komunjer \n% komunjer@hss.caltech.edu\n% Modifications Copyright:\n% Kevin Sheppard\n% kevin.sheppard@economics.ox.ac.uk\n% Revision: 3 Date: 9/1/2005\n\nif nargin < 1,\n error('Requires at least one input argument.');\nend\n\nv(v<1)=NaN;\n\n[err, errtext, sizeOut] = iscompatible(1,v,varargin{:});\n\nif err\n error(errtext)\nend\n\n% Return NaN if the argument V is outside its limit.\nr = gamrnd(1./v,1,sizeOut);\nr = r.^(1./v);\nrndsgn = 2*((rand(sizeOut)>0.5)-0.5); % generates a random sign -1 or +1\nr = r.*rndsgn;\n\nscalex = (gamma(3./v)./gamma(1./v)).^0.5; % standardizes the obtained values\nr = r./scalex;", "meta": {"author": "bashtage", "repo": "mfe-toolbox", "sha": "9622b6c546bc6d649fd9bf0a36a7fcd53872e04a", "save_path": "github-repos/MATLAB/bashtage-mfe-toolbox", "path": "github-repos/MATLAB/bashtage-mfe-toolbox/mfe-toolbox-9622b6c546bc6d649fd9bf0a36a7fcd53872e04a/distributions/gedrnd.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178895092415, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.7470557584904637}} {"text": "function [M, Mx, My, Mz] = convectionTerm3D(u)\n% This function uses the central difference scheme to discretize a 2D\n% convection term in the form \\grad (u \\phi) where u is a face vactor\n% It also returns the x and y parts of the matrix of coefficient.\n%\n% SYNOPSIS:\n% [M, Mx, My, Mz] = convectionTerm3D(u)\n%\n% PARAMETERS:\n% u - FaceVariable \n%\n% RETURNS:\n%\n%\n% EXAMPLE:\n%\n% SEE ALSO:\n%\n\n% extract data from the mesh structure\nNx = u.domain.dims(1);\nNy = u.domain.dims(2);\nNz = u.domain.dims(3);\nG=reshape((1:(Nx+2)*(Ny+2)*(Nz+2)), Nx+2, Ny+2, Nz+2);\nDXe = repmat(u.domain.cellsize.x(3:end), 1, Ny, Nz);\nDXw = repmat(u.domain.cellsize.x(1:end-2), 1, Ny, Nz);\nDXp = repmat(u.domain.cellsize.x(2:end-1), 1, Ny, Nz);\nDYn = repmat(u.domain.cellsize.y(3:end)', Nx, 1, Nz);\nDYs = repmat(u.domain.cellsize.y(1:end-2)', Nx, 1, Nz);\nDYp = repmat(u.domain.cellsize.y(2:end-1)', Nx, 1, Nz);\nDZ = zeros(1,1,Nz+2);\nDZ(1,1,:) = u.domain.cellsize.z;\nDZf=repmat(DZ(1,1,3:end), Nx, Ny, 1);\nDZb=repmat(DZ(1,1,1:end-2), Nx, Ny, 1);\nDZp=repmat(DZ(1,1,2:end-1), Nx, Ny, 1);\n\n% define the vectors to stores the sparse matrix data\niix = zeros(3*(Nx+2)*(Ny+2)*(Nz+2),1);\njjx = zeros(3*(Nx+2)*(Ny+2)*(Nz+2),1);\nsx = zeros(3*(Nx+2)*(Ny+2)*(Nz+2),1);\niiy = zeros(3*(Nx+2)*(Ny+2)*(Nz+2),1);\njjy = zeros(3*(Nx+2)*(Ny+2)*(Nz+2),1);\nsy = zeros(3*(Nx+2)*(Ny+2)*(Nz+2),1);\niiz = zeros(3*(Nx+2)*(Ny+2)*(Nz+2),1);\njjz = zeros(3*(Nx+2)*(Ny+2)*(Nz+2),1);\nsz = zeros(3*(Nx+2)*(Ny+2)*(Nz+2),1);\nmnx = Nx*Ny*Nz;\tmny = Nx*Ny*Nz; mnz = Nx*Ny*Nz;\n\n% reassign the east, west, north, and south velocity vectors for the\n% code readability\nue = u.xvalue(2:Nx+1,:,:)./(DXp+DXe);\nuw = u.xvalue(1:Nx,:,:)./(DXp+DXw);\nvn = u.yvalue(:,2:Ny+1,:)./(DYp+DYn);\nvs = u.yvalue(:,1:Ny,:)./(DYp+DYs);\nwf = u.zvalue(:,:,2:Nz+1)./(DZp+DZf);\nwb = u.zvalue(:,:,1:Nz)./(DZp+DZb);\n\n% calculate the coefficients for the internal cells\nAE = reshape(ue,mnx,1);\nAW = reshape(-uw,mnx,1);\nAN = reshape(vn,mny,1);\nAS = reshape(-vs,mny,1);\nAF = reshape(wf,mnz,1);\nAB = reshape(-wb,mnz,1);\nAPx = reshape((ue.*DXe-uw.*DXw)./DXp,mnx,1);\nAPy = reshape((vn.*DYn-vs.*DYs)./DYp,mny,1);\nAPz = reshape((wf.*DZf-wb.*DZb)./DZp,mnz,1);\n\n% build the sparse matrix based on the numbering system\nrowx_index = reshape(G(2:Nx+1,2:Ny+1,2:Nz+1),mnx,1); % main diagonal x\niix(1:3*mnx) = repmat(rowx_index,3,1);\nrowy_index = reshape(G(2:Nx+1,2:Ny+1,2:Nz+1),mny,1); % main diagonal y\niiy(1:3*mny) = repmat(rowy_index,3,1);\nrowz_index = reshape(G(2:Nx+1,2:Ny+1,2:Nz+1),mnz,1); % main diagonal z\niiz(1:3*mnz) = repmat(rowz_index,3,1);\njjx(1:3*mnx) = [reshape(G(1:Nx,2:Ny+1,2:Nz+1),mnx,1); reshape(G(2:Nx+1,2:Ny+1,2:Nz+1),mnx,1); reshape(G(3:Nx+2,2:Ny+1,2:Nz+1),mnx,1)];\njjy(1:3*mny) = [reshape(G(2:Nx+1,1:Ny,2:Nz+1),mny,1); reshape(G(2:Nx+1,2:Ny+1,2:Nz+1),mny,1); reshape(G(2:Nx+1,3:Ny+2,2:Nz+1),mny,1)];\njjz(1:3*mnz) = [reshape(G(2:Nx+1,2:Ny+1,1:Nz),mnz,1); reshape(G(2:Nx+1,2:Ny+1,2:Nz+1),mnz,1); reshape(G(2:Nx+1,2:Ny+1,3:Nz+2),mnz,1)];\nsx(1:3*mnx) = [AW; APx; AE];\nsy(1:3*mny) = [AS; APy; AN];\nsz(1:3*mnz) = [AB; APz; AF];\n\n% build the sparse matrix\nkx = 3*mnx;\nky = 3*mny;\nkz = 3*mnz;\nMx = sparse(iix(1:kx), jjx(1:kx), sx(1:kx), (Nx+2)*(Ny+2)*(Nz+2), (Nx+2)*(Ny+2)*(Nz+2));\nMy = sparse(iiy(1:ky), jjy(1:ky), sy(1:ky), (Nx+2)*(Ny+2)*(Nz+2), (Nx+2)*(Ny+2)*(Nz+2));\nMz = sparse(iiz(1:kz), jjz(1:kz), sz(1:kz), (Nx+2)*(Ny+2)*(Nz+2), (Nx+2)*(Ny+2)*(Nz+2));\nM = Mx + My + Mz;\n", "meta": {"author": "simulkade", "repo": "FVTool", "sha": "49f5cb9ee8a5ff0befebd9fa71a99feae7c724d6", "save_path": "github-repos/MATLAB/simulkade-FVTool", "path": "github-repos/MATLAB/simulkade-FVTool/FVTool-49f5cb9ee8a5ff0befebd9fa71a99feae7c724d6/Discretization/convectionTerm3D.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818865, "lm_q2_score": 0.822189123986562, "lm_q1q2_score": 0.7470557567867762}} {"text": "% An example of nonnegative CP decomposition from partial observations\n%% Generate synthetic 4-order tensor\nrand('seed',0); randn('seed',0);\nN1 = 30; N2 = 30; N3 = 30; N4 = 30; % tensor dimension\nR = 10; % tensor rank\n\n% randomly generate factor matrices\nA1 = max(0,randn(N1,R));\nA2 = max(0,randn(N2,R));\nA3 = max(0,randn(N3,R));\nA4 = max(0,randn(N4,R));\n% generate tensor M using the above factor matrices\nM = ktensor({A1,A2,A3,A4});\nM = full((arrange(M)));\n\nsr = 0.4; % percentage of samples\n% randomly choose samples\nknown = randsample(N1*N2*N3*N4,round(sr*N1*N2*N3*N4));\ndata = M.data(known);\n\nsn = 60; % signal to noise\n% -- add noise --\nNoise = max(0,randn(size(data)));\ndata = data + 10^(-sn/20)*norm(data)/norm(Noise)*Noise;\nndim = [N1,N2,N3,N4];\n\n%% Solve problem\n% exact rank works but a rough rank overestimate is also fine\nesr = round(1.25*R); % overestimate of rank\nopts.tol = 1e-4; opts.maxit = 1000;\nt0 = tic;\n[A,Out] = ncpc(data,known,ndim,esr,opts);\ntime = toc(t0);\n\n%% Reporting\nrelerr = norm(full(A)-M)/norm(M);\nfprintf('time = %4.2e, ',time);\nfprintf('solution relative error = %4.2e\\n\\n',relerr);\n\nfigure;\nsemilogy(1:Out.iter, Out.hist_obj,'k-','linewidth',2);\nxlabel('iteration','fontsize',12);\nylabel('objective value','fontsize',12)\n\nfigure;\nsemilogy(1:Out.iter, Out.hist_rel(2,:),'k-','linewidth',2);\nxlabel('iteration','fontsize',12);\nylabel('relative residual','fontsize',12)\n\n%% ", "meta": {"author": "andrewssobral", "repo": "mctc4bmi", "sha": "fbcbcd25654b818646387c3d6a64304fb60e12dd", "save_path": "github-repos/MATLAB/andrewssobral-mctc4bmi", "path": "github-repos/MATLAB/andrewssobral-mctc4bmi/mctc4bmi-fbcbcd25654b818646387c3d6a64304fb60e12dd/algs_tc/NCPC/example_ncpc.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178870347121, "lm_q2_score": 0.8221891327004133, "lm_q1q2_score": 0.7470557524971521}} {"text": "function [E, V] = VBA_dirichlet_moments (a)\n% // VBA toolbox //////////////////////////////////////////////////////////\n%\n% [E, V] = VBA_dirichlet_moments (a)\n% Derives the first- and second-order moments of a Dirichlet density\n%\n% IN:\n% - a: parameters of the Dirichlet distribution (pseudo-counts)\n% OUT:\n% - E: first-order moment (expectation)\n% - V: second-order moment (variance)\n%\n% /////////////////////////////////////////////////////////////////////////\n\n% Let X = (X_1, ..., X_k) ~ Dir(a)\n\n% shorthand\na0 = sum(a);\n\n% First-order moment E[X]\nE = a./a0;\n\n% second order moment Var[X]\nV = (a .* (a0-a)) ./ (a0.^2 * (a0+1)); ", "meta": {"author": "MBB-team", "repo": "VBA-toolbox", "sha": "01ff63f43ef7a6473bc5e3f28dd9ffa58fcfb414", "save_path": "github-repos/MATLAB/MBB-team-VBA-toolbox", "path": "github-repos/MATLAB/MBB-team-VBA-toolbox/VBA-toolbox-01ff63f43ef7a6473bc5e3f28dd9ffa58fcfb414/utils/VBA_dirichlet_moments.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947101574299, "lm_q2_score": 0.7905303285397349, "lm_q1q2_score": 0.7470469786890647}} {"text": "function a = angle(v1,v2,varargin)\n% angle between two vectors\n%\n% Syntax\n% omega = angle(v1,v2)\n% omega = angle(v1,v2,'antipodal')\n% omega = angle(v1,v2,N)\n%\n% Input\n% v1, v2 - @vector3d\n% N - @vector3d normal to plane\n%\n% Output\n% omega - double\n%\n% Options\n% antipodal - include \n\nif nargin == 3 && isa(varargin{1},'vector3d')\n\n N = normalize(varargin{1});\n v1 = normalize(v1 - dot(v1,N,'noSymmetry') .* N);\n v2 = normalize(v2 - dot(v2,N,'noSymmetry') .* N);\n\n a = angle(v1,v2);\n\n ind = dot(N,cross(v1,v2),'noSymmetry')<0;\n a(ind) = 2*pi - a(ind);\n\nelse\n\n a = dot(v1.normalize,v2.normalize,varargin{:});\n\n a = real(acos(a));\n\nend\n", "meta": {"author": "mtex-toolbox", "repo": "mtex", "sha": "f0ce46a720935e9ae8106ef919340534bca1adcb", "save_path": "github-repos/MATLAB/mtex-toolbox-mtex", "path": "github-repos/MATLAB/mtex-toolbox-mtex/mtex-f0ce46a720935e9ae8106ef919340534bca1adcb/geometry/@vector3d/angle.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9449947055100817, "lm_q2_score": 0.7905303285397349, "lm_q1q2_score": 0.7470469750151949}} {"text": "function [ C ] = gsp_ngwft(G,f,g, param)\n%GSP_NGWFT Normalized graph windowed Fourier transform\n% Usage: G = gsp_ngwft(G,f,g, param);\n% G = gsp_ngwft(G,f,g);\n%\n% Input parameters:\n% G : Graph\n% f : Graph signal\n% g : window\n% param : Structure of optional parameter\n% Output parameters:\n% C : Coefficient\n%\n% This function compute the normalized graph windowed Fourier transform\n% of a signal *f* with the window *g*. The function returns a matrix of\n% size N^2*N. \n%\n% *param* a Matlab structure containing the following fields:\n% \n% * *param.verbose* : 0 no log, 1 print main steps, 2 print all steps.\n% By default, it is 1.\n% * *param.lowmemory* : use less memory. By default, it is 1.\n%\n\n% Author : Nathanael Perraudin\n% Testing: test_ngwft\n\n% Optional input arguments\nif nargin<4, param=struct; end\nif ~isfield(param, 'verbose'), param.verbose=1 ; end\nif ~isfield(param, 'lowmemory'), param.lowmemory=1 ; end\n\nif ~isfield(G,'U')\n error(['GSP_NGWFT: You need first to compute the Fourier basis\\n',...\n 'You can do it with the function gsp_compute_fourier_basis']);\nend\n\nif ~param.lowmemory\n % Compute the Frame into a big matrix\n Frame=gsp_ngwft_frame_matrix(G,g,param);\n\n C=Frame'*f;\n\n C=reshape(C,G.N,G.N);\nelse\n % Compute the translate of g\n ghat=G.U'*g;\n Ftrans=sqrt(G.N)*G.U*(repmat(ghat,1,G.N).*G.U');\n C=zeros(G.N);\n for ii=1:G.N\n atoms = (repmat(1./G.U(:,1),1,G.N) .* ...\n G.U.*repmat(Ftrans(:,ii),1,G.N))';\n % normalization\n atoms = atoms./ repmat(sqrt(sum(abs(atoms).^2,2)),1,G.N);\n C(:,ii)=atoms*f;\n end\n \nend\n\n", "meta": {"author": "epfl-lts2", "repo": "gspbox", "sha": "a7d9aac5e239f1bcb37a9bb09998cc161be2732f", "save_path": "github-repos/MATLAB/epfl-lts2-gspbox", "path": "github-repos/MATLAB/epfl-lts2-gspbox/gspbox-a7d9aac5e239f1bcb37a9bb09998cc161be2732f/operators/gsp_ngwft.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8918110339361275, "lm_q2_score": 0.837619959279793, "lm_q1q2_score": 0.7469987219308493}} {"text": "% CAMCALD Camera calibration from data points\n%\n% C = CAMCALD(D) is the camera matrix (3x4) determined by least squares \n% from corresponding world and image-plane points. D is a table \n% of points with rows of the form [X Y Z U V] where (X,Y,Z) is the \n% coordinate of a world point and [U,V] is the corresponding image \n% plane coordinate. \n%\n% [C,E] = CAMCALD(D) as above but E is the maximum residual error after \n% back substitution [pixels]. \n% \n% Notes:\n% - This method assumes no lense distortion affecting the image plane\n% coordinates.\n%\n% See also CentralCamera.\n\n\n\n% Copyright (C) 1993-2011, by Peter I. Corke\n%\n% This file is part of The Machine Vision Toolbox for Matlab (MVTB).\n% \n% MVTB is free software: you can redistribute it and/or modify\n% it under the terms of the GNU Lesser General Public License as published by\n% the Free Software Foundation, either version 3 of the License, or\n% (at your option) any later version.\n% \n% MVTB is distributed in the hope that it will be useful,\n% but WITHOUT ANY WARRANTY; without even the implied warranty of\n% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n% GNU Lesser General Public License for more details.\n% \n% You should have received a copy of the GNU Leser General Public License\n% along with MVTB. If not, see .\n\n\n\nfunction [C, resid] = camcald(XYZ, uv)\n\n if numcols(XYZ) ~= numcols(uv)\n error('must have same number of world and image-plane points');\n end\n\n n = numcols(XYZ);\n if n < 6,\n error('At least 6 points required for calibration');\n end\n%\n% build the matrix as per Ballard and Brown p.482\n%\n% the row pair are one row at this point\n%\n A = [ XYZ' ones(n,1) zeros(n,4) -repmat(uv(1,:)', 1,3).*XYZ' ...\n zeros(n,4) XYZ' ones(n,1) -repmat(uv(2,:)', 1,3).*XYZ' ];\n%\n% reshape the matrix, so that the rows interleave\n%\n A = reshape(A',11, n*2)';\n if rank(A) < 11,\n error('Rank deficient, perhaps points are coplanar or collinear');\n end\n\n B = reshape( uv, 1, n*2)';\n\n C = A\\B; % least squares solution\n resid = max(max(abs(A * C - B)));\n if resid > 1,\n warning('Residual greater than 1 pixel');\n end\n fprintf('maxm residual %f pixels.\\n', resid);\n C = reshape([C;1]',4,3)';\n", "meta": {"author": "petercorke", "repo": "machinevision-toolbox-matlab", "sha": "2d791168c19c5e56acef74d22eafd227b4b58e42", "save_path": "github-repos/MATLAB/petercorke-machinevision-toolbox-matlab", "path": "github-repos/MATLAB/petercorke-machinevision-toolbox-matlab/machinevision-toolbox-matlab-2d791168c19c5e56acef74d22eafd227b4b58e42/camcald.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765210631689, "lm_q2_score": 0.8175744806385542, "lm_q1q2_score": 0.7469986071798613}} {"text": "function [kden,N,K] = density_dir(CIJ)\n%DENSITY Density\n%\n% kden = density_dir(CIJ);\n% [kden,N,K] = density_dir(CIJ);\n%\n% Density is the fraction of present connections to possible connections.\n%\n% Input: CIJ, directed (weighted/binary) connection matrix\n%\n% Output: kden, density\n% N, number of vertices\n% K, number of edges\n%\n% Notes: Assumes CIJ is directed and has no self-connections.\n% Weight information is discarded.\n%\n%\n% Olaf Sporns, Indiana University, 2002/2007/2008\n\nN = size(CIJ,1);\nK = nnz(CIJ);\nkden = K/(N^2-N);\n\n", "meta": {"author": "fieldtrip", "repo": "fieldtrip", "sha": "c2039be598a02d86b39aae76bfa7aaa720f9801c", "save_path": "github-repos/MATLAB/fieldtrip-fieldtrip", "path": "github-repos/MATLAB/fieldtrip-fieldtrip/fieldtrip-c2039be598a02d86b39aae76bfa7aaa720f9801c/external/bct/density_dir.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9136765234137297, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.7469986070710147}} {"text": "function c = tapas_unitsq_sgm_config\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%\n% Contains the configuration for the unit square sigmoid observation model for binary responses\n%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%\n% The unit square sigmoid (ussgm) is the function\n%\n% f(x) = x^zeta/(x^zeta + (1-x)^zeta) = ustapas_sgm(x; zeta),\n%\n% where x is in the unit interval, and zeta > 0 is a parameter that determines the shape of the\n% sigmoid. Since both its argument and value are always in the unit interval, its graph is\n% restricted to the unit square, hence the name unit square sigmoid.\n%\n% In the application here, the ussgm is the probability of observing a decision y=1 (rather than\n% the only alternative y=0) given the current probability mu1hat (or value) of input u=1:\n% \n% p(y=1|mu1hat) = ustapas_sgm(mu1hat; zeta)\n%\n% The parameter zeta regulates the steepness of the sigmoid such that it forms the diagonal of\n% the unit square for zeta=1 and approaches a step function at 0.5 as zeta approaches infinity.\n% Values of 0 < zeta < 1 lead to sigmoids with reverse concavity than usual, but they still\n% represent valid observation models.\n%\n% Zeta can be interpreted as inverse decision noise. To have a shrinkage prior on this, choose a\n% high value. It is estimated log-space since it has a natural lower bound at zero.\n%\n% --------------------------------------------------------------------------------------------------\n% Copyright (C) 2012-2013 Christoph Mathys, TNU, UZH & ETHZ\n%\n% This file is part of the HGF toolbox, which is released under the terms of the GNU General Public\n% Licence (GPL), version 3. You can redistribute it and/or modify it under the terms of the GPL\n% (either version 3 or, at your option, any later version). For further details, see the file\n% COPYING or .\n\n% Config structure\nc = struct;\n\n% Is the decision based on predictions or posteriors? Comment as appropriate.\nc.predorpost = 1; % Predictions\n%c.predorpost = 2; % Posteriors\n\n% Model name\nc.model = 'tapas_unitsq_sgm';\n\n% Sufficient statistics of Gaussian parameter priors\n\n% Zeta\nc.logzemu = log(48);\nc.logzesa = 1;\n\n% Gather prior settings in vectors\nc.priormus = [\n c.logzemu,...\n ];\n\nc.priorsas = [\n c.logzesa,...\n ];\n\n% Model filehandle\nc.obs_fun = @tapas_unitsq_sgm;\n\n% Handle to function that transforms observation parameters to their native space\n% from the space they are estimated in\nc.transp_obs_fun = @tapas_unitsq_sgm_transp;\n\nreturn;\n", "meta": {"author": "translationalneuromodeling", "repo": "tapas", "sha": "604c56843c15411f5bd80190f81d845ac57d8592", "save_path": "github-repos/MATLAB/translationalneuromodeling-tapas", "path": "github-repos/MATLAB/translationalneuromodeling-tapas/tapas-604c56843c15411f5bd80190f81d845ac57d8592/HGF/tapas_unitsq_sgm_config.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765234137297, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.7469986030098043}} {"text": "function [v,r] = dquat2line(dq)\n\n% DQUAT2LINE Transforms a line position dual quaternion into \n% its vector representation (orientation + position).\n%\n% [V,R] = DQUAT2LINE(DQ) transforms the double quaternion\n% representation of a line position (in the euclidean space) into a\n% vector V which represents the line orientation (unitary vector) \n% and a vector R which is the coordinates of the nearest point from\n% the origin belonging to the line (it could be another r, it is\n% NOT unique).\n% DQ is either a vector of size 8 or an array of size 8*N (each\n% column represents a line position dual quaternion) where N is the\n% number of lines. V and R have the same size. They are either a\n% vector of size 3 or an array of size 3*N depending on the input\n% format.\n%\n% See also DQUAT2POS, DQUAT2VEL, DQUAT2LINEVEL, LINE2DQUAT \n\nif nargout < 2 || nargout > 2\n error('DualQuaternion:dquat2line:wrongNumberOfOutputs',...\n 'You specified %d outputs. It should be 2 (see documentation).',nargout);\nend\n\nsdq = size(dq);\nif sdq == [1 8], dq = dq'; sdq = size(dq); end\n\n% wrong format\nif sdq(1) ~= 8 \n error('DualQuaternion:dquat2line:wrongsize',...\n '%d rows in the DQ array. It should be 8.',sdq(1));\nend\n\n% check line position dual quaternion\ntol = 1e-6;\n[maxval,imax] = max(max(abs(dq([1 5],:))));\nif maxval > tol\n warning('DualQuaternion:dquat2line:wrongFormat',...\n 'At least one dual quaternion is not a line position dual quaternion (tol = %.1e).\\n Indices of max values: %d \\n Max value = %.2e',...\n tol,imax,maxval);\nend\n\n% extraction of the line position parameters, v and r\nv = dq(2:4,:);\nw = dq(6:8,:);\n\n% check if the norm of v is unitary (it should be)\nnormv2 = sum(v.^2);\n[maxval2,imax2] = max(normv2);\n[minval2,imin2] = min(normv2);\ni2 = union(imax2,imin2);\nif maxval2 > 1+tol || minval2 < 1-tol\n warning('DualQuaternion:dquat2line:wrongFormatNotUnitary',...\n 'At least one dual quaternion has not a unitary orientation ( is it a line position dual quaternion?) (tol = %.1e).\\n Indices of max values: %d \\n Min and Max value = [%.2e %.2e]',...\n tol,i2,minval2,maxval2);\nend\n% r is the position vector of the point belonging to the line such that\n% this point is the nearest point from the origin (it is orthogonal to the\n% line orientation)\nnormv2 = repmat(normv2,3,1);\nr = cross(v,w)./normv2;\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/39288-dual-quaternion-toolbox/Dual quaternion toolbox v2/dquat2line.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357666736773, "lm_q2_score": 0.8615382129861583, "lm_q1q2_score": 0.7469844450151236}} {"text": "clear all\nclf\n\nprojV=@(x,A)A*inv(A'*A)*A'*x;\nV1=[1 0 0]';\nV2=[1 1 0]';\n\n% Alternating projections.\nx=[0.5 1 1]';\nsubplot(121)\nplot3([0 V1(1)],[0 V1(2)],[0 V1(3)],'-b','LineWidth',2);hold on\nplot3([0 V2(1)],[0 V2(2)],[0 V2(3)],'-b','LineWidth',2);\nplot3(x(1),x(2),x(3),'.k','MarkerSize',20);\nfor i=1:5\n xV1=projV(x,V1);\n h=arrow(x,xV1,'Length',5);\n set(h,'LineStyle',':','EdgeColor','r','FaceColor','r');\n text(xV1(1),xV1(2),xV1(3),['P_{V_1}(x)'])\n x=projV(xV1,V2);\n h=arrow(xV1,x,'Length',5);\n text(x(1),x(2),x(3),['P_{V_2}(P_{V_1}(x))'])\n plot3(x(1),x(2),x(3),'.k','MarkerSize',20);\nend\naxis([0 1 0 1 0 1]);box on;axis equal;axis tight\ntitle('Alternating projections');\n\n% Average Alternating Reflections/DR.\nx=[0.5 1 1]';\nsubplot(122)\nplot3([-1 V1(1)],[0 V1(2)],[0 V1(3)],'-b','LineWidth',2);hold on\nplot3([-1 V2(1)],[-1 V2(2)],[0 V2(3)],'-b','LineWidth',2);\nplot3(x(1),x(2),x(3),'.k','MarkerSize',20);\nfor i=1:5\n xV1=2*projV(x,V1)-x;\n h=arrow(x,xV1,'Length',5);\n set(h,'LineStyle',':','EdgeColor','r','FaceColor','r');\n text(xV1(1),xV1(2),xV1(3),['R_{V_1}(x)'])\n xV2=2*projV(xV1,V2)-xV1;\n h=arrow(xV1,xV2,'Length',5);\n set(h,'LineStyle',':','EdgeColor','r','FaceColor','r');\n text(xV2(1),xV2(2),xV2(3),['R_{V_2}(R_{V_1}(x))'])\n x=(xV2+x)/2;\n arrow(xV2,x,'Length',5);\n text(x(1),x(2),x(3),['(R_{V_2}(R_{V_1}(x))+x)/2'])\n plot3(x(1),x(2),x(3),'.k','MarkerSize',20);\nend\naxis([-1 1 -1 1 -1 1]);box on;axis equal;axis tight\ntitle('Average Alternating Reflections/DR');\n", "meta": {"author": "gpeyre", "repo": "matlab-toolboxes", "sha": "0cd622c988cda6f63f64d35cd7bd096fa578e5c6", "save_path": "github-repos/MATLAB/gpeyre-matlab-toolboxes", "path": "github-repos/MATLAB/gpeyre-matlab-toolboxes/matlab-toolboxes-0cd622c988cda6f63f64d35cd7bd096fa578e5c6/toolbox_optim/tests/test_DRAP3D.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.86153820232079, "lm_q2_score": 0.8670357494949105, "lm_q1q2_score": 0.746984420967704}} {"text": "% read in a sample image -- also see letters.png, bagel.png\nimg = imread('mushroom.png');\nimshow(img);\n\n% the standard skeletonization:\nimshow(bwmorph(img,'skel',inf));\n\n% the new method:\nimshow(bwmorph(skeleton(img)>35,'skel',Inf));\n\n% in more detail:\n[skr,rad] = skeleton(img);\n\n% the intensity at each point is proportional to the degree of evidence\n% that this should be a point on the skeleton:\nimagesc(skr);\ncolormap jet\naxis image off\n\n% skeleton can also return a map of the radius of the largest circle that\n% fits within the foreground at each point:\nimagesc(rad)\ncolormap jet\naxis image off\n\n% thresholding the skeleton can return skeletons of thickness 2,\n% so the call to bwmorph completes the thinning to single-pixel width.\nskel = bwmorph(skr > 35,'skel',inf);\nimshow(skel)\n% try different thresholds besides 35 to see the effects\n\n% anaskel returns the locations of endpoints and junction points\n[dmap,exy,jxy] = anaskel(skel);\nhold on\nplot(exy(1,:),exy(2,:),'go')\nplot(jxy(1,:),jxy(2,:),'ro')\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/11123-better-skeletonization/demo.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.905989822921759, "lm_q2_score": 0.8244619350028204, "lm_q1q2_score": 0.746954122498936}} {"text": "% Signal Processing Q17734\n% https://dsp.stackexchange.com/questions/17734\n% Estimate the Discrete Fourier Series of a Signal with Missing Samples\n% References:\n% 1. aa\n% Remarks:\n% 1. sa\n% TODO:\n% \t1. ds\n% Release Notes\n% - 1.0.001 17/01/2021 Royi Avital RoyiAvital@yahoo.com\n% * First release.\n% - 1.0.000 20/07/2017\n% * First release.\n\n\n%% General Parameters\n\nsubStreamNumberDefault = 79;\nrun('InitScript.m');\n\nfigureIdx = 0;\nfigureCounterSpec = '%04d';\n\ngenerateFigures = OFF;\n\n\n%% Simulation Parameters\n\nnumSamples = 150;\nnumGivenSamples = 120; % Upper)\n disp (['Wrong Lower or Upper values!']);\nend\n\n[MaxV, I]=max(Data);\n[MinV, I]=min(Data);\n\n[R,C]= size(Data);\n\nscaled=(Data-ones(R,1)*MinV).*(ones(R,1)*((Upper-Lower)*ones(1,C)./(MaxV-MinV)))+Lower;\n\nscaled(isnan(scaled)) = 1/sqrt(size(scaled, 1));\n\n\n", "meta": {"author": "zhangqianqianQQ", "repo": "MachineVisionAlgorithm", "sha": "683338f6c3b1aab9fa2b80026915fe936aebf0ee", "save_path": "github-repos/MATLAB/zhangqianqianQQ-MachineVisionAlgorithm", "path": "github-repos/MATLAB/zhangqianqianQQ-MachineVisionAlgorithm/MachineVisionAlgorithm-683338f6c3b1aab9fa2b80026915fe936aebf0ee/\u5206\u7c7b\u7b97\u6cd5/HC_RMG-master/rmg/NewScale.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9059898102301019, "lm_q2_score": 0.8244619306896955, "lm_q1q2_score": 0.7469541081275007}} {"text": "function v = eigenvector_centrality_und(CIJ)\n%EIGENVECTOR_CENTRALITY_UND Spectral measure of centrality\n%\n% v = eigenvector_centrality_und(CIJ)\n%\n% Eigenector centrality is a self-referential measure of centrality:\n% nodes have high eigenvector centrality if they connect to other nodes\n% that have high eigenvector centrality. The eigenvector centrality of\n% node i is equivalent to the ith element in the eigenvector \n% corresponding to the largest eigenvalue of the adjacency matrix.\n%\n% Inputs: CIJ, binary/weighted undirected adjacency matrix.\n%\n% Outputs: v, eigenvector associated with the largest\n% eigenvalue of the adjacency matrix CIJ.\n%\n% Reference: Newman, MEJ (2002). The mathematics of networks.\n%\n% Contributors:\n% Xi-Nian Zuo, Chinese Academy of Sciences, 2010\n% Rick Betzel, Indiana University, 2012\n% Mika Rubinov, University of Cambridge, 2015\n\n% MODIFICATION HISTORY\n% 2010/2012: original (XNZ, RB)\n% 2015: ensure the use of leading eigenvector (MR)\n\n\nn = length(CIJ);\nif n < 1000\n [V,D] = eig(CIJ);\nelse\n [V,D] = eigs(sparse(CIJ));\nend\n[~,idx] = max(diag(D));\nec = abs(V(:,idx));\nv = reshape(ec, length(ec), 1);", "meta": {"author": "fieldtrip", "repo": "fieldtrip", "sha": "c2039be598a02d86b39aae76bfa7aaa720f9801c", "save_path": "github-repos/MATLAB/fieldtrip-fieldtrip", "path": "github-repos/MATLAB/fieldtrip-fieldtrip/fieldtrip-c2039be598a02d86b39aae76bfa7aaa720f9801c/external/bct/eigenvector_centrality_und.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.951142221377825, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.7469401528717988}} {"text": "function quadrule_test16 ( )\n\n%*****************************************************************************80\n%\n%% TEST16 tests GEN_LAGUERRE_EK_COMPUTE and LAGUERRE_SUM.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 23 April 2011\n%\n% Author:\n%\n% John Burkardt\n%\n order_max = 10;\n\n nfunc = func_set ( 'COUNT', 'DUMMY' );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TEST16\\n' );\n fprintf ( 1, ' GEN_LAGUERRE_EK_COMPUTE computes a Gauss-Laguerre rule;\\n' );\n fprintf ( 1, ' LAGUERRE_SUM carries it out.\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Quadrature order will vary.\\n' );\n fprintf ( 1, ' Integrand will vary.\\n' );\n fprintf ( 1, ' The weight function is EXP ( - X ) * X^ALPHA.\\n' );\n fprintf ( 1, '\\n' );\n\n a = 0.0;\n alpha = 2.0;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' The integration interval is [ %f, +oo ).\\n', a );\n fprintf ( 1, ' ALPHA = %f\\n', alpha );\n fprintf ( 1, '\\n' );\n\n for ilo = 1 : 5 : nfunc\n\n ihi = min ( ilo + 4, nfunc );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' ' );\n for i = ilo : ihi\n fprintf ( '%14s', fname(i) );\n end\n fprintf ( 1, '\\n' );\n fprintf ( 1, '\\n' );\n\n for norder = 1 : order_max\n\n fprintf ( 1, ' %2d', norder );\n\n for i = ilo : ihi\n\n func_set ( 'SET', i );\n\n [ xtab, weight ] = gen_laguerre_ek_compute ( norder, alpha );\n\n result(i) = laguerre_sum ( @func, a, norder, xtab, weight );\n\n fprintf ( 1, ' %12f', result(i) );\n\n end\n\n fprintf ( 1, '\\n' );\n\n end\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/quadrule/quadrule_test16.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267898240861, "lm_q2_score": 0.8596637469145054, "lm_q1q2_score": 0.7468988935598754}} {"text": "%% Machine Learning Online Class - Exercise 2: Logistic Regression\n%\n% Instructions\n% ------------\n% \n% This file contains code that helps you get started on the second part\n% of the exercise which covers regularization with logistic regression.\n%\n% You will need to complete the following functions in this exericse:\n%\n% sigmoid.m\n% costFunction.m\n% predict.m\n% costFunctionReg.m\n%\n% For this exercise, you will not need to change any code in this file,\n% or any other files other than those mentioned above.\n%\n\n%% Initialization\nclear ; close all; clc\n\n%% Load Data\n% The first two columns contains the X values and the third column\n% contains the label (y).\n\ndata = load('ex2data2.txt');\nX = data(:, [1, 2]); y = data(:, 3);\n\nplotData(X, y);\n\n% Put some labels \nhold on;\n\n% Labels and Legend\nxlabel('Microchip Test 1')\nylabel('Microchip Test 2')\n\n% Specified in plot order\nlegend('y = 1', 'y = 0')\nhold off;\n\n%% =========== Part 1: Regularized Logistic Regression ============\n% In this part, you are given a dataset with data points that are not\n% linearly separable. However, you would still like to use logistic \n% regression to classify the data points. \n%\n% To do so, you introduce more features to use -- in particular, you add\n% polynomial features to our data matrix (similar to polynomial\n% regression).\n%\n\n% Add Polynomial Features\n\n% Note that mapFeature also adds a column of ones for us, so the intercept\n% term is handled\nX = mapFeature(X(:,1), X(:,2));\n\n% Initialize fitting parameters\ninitial_theta = zeros(size(X, 2), 1);\n\n% Set regularization parameter lambda to 1\nlambda = 1;\n\n% Compute and display initial cost and gradient for regularized logistic\n% regression\n[cost, grad] = costFunctionReg(initial_theta, X, y, lambda);\n\nfprintf('Cost at initial theta (zeros): %f\\n', cost);\n\nfprintf('\\nProgram paused. Press enter to continue.\\n');\npause;\n\n%% ============= Part 2: Regularization and Accuracies =============\n% Optional Exercise:\n% In this part, you will get to try different values of lambda and \n% see how regularization affects the decision coundart\n%\n% Try the following values of lambda (0, 1, 10, 100).\n%\n% How does the decision boundary change when you vary lambda? How does\n% the training set accuracy vary?\n%\n% Initialize fitting parameters\ninitial_theta = zeros(size(X, 2), 1);\n\n% Set regularization parameter lambda to 1 (you should vary this)\nlambda = 1;\n%lambda = 0;\n%lambda = 10;\n%lambda = 100;\n\n% Set Options\noptions = optimset('GradObj', 'on', 'MaxIter', 400);\n\n% Optimize\n[theta, J, exit_flag] = ...\n\tfminunc(@(t)(costFunctionReg(t, X, y, lambda)), initial_theta, options);\n\n% Plot Boundary\nplotDecisionBoundary(theta, X, y);\nhold on;\ntitle(sprintf('lambda = %g', lambda))\n\n% Labels and Legend\nxlabel('Microchip Test 1')\nylabel('Microchip Test 2')\n\nlegend('y = 1', 'y = 0', 'Decision boundary')\nhold off;\n\n% Compute accuracy on our training set\np = predict(theta, X);\n\nfprintf('Train Accuracy: %f\\n', mean(double(p == y)) * 100);\n\n\n", "meta": {"author": "rieder91", "repo": "MachineLearning", "sha": "f6708f216326cb5c9e9e5c3afc912060bfa10486", "save_path": "github-repos/MATLAB/rieder91-MachineLearning", "path": "github-repos/MATLAB/rieder91-MachineLearning/MachineLearning-f6708f216326cb5c9e9e5c3afc912060bfa10486/Exercise 2/ex2/ex2_reg.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637505099167, "lm_q2_score": 0.8688267847293731, "lm_q1q2_score": 0.7468988923039249}} {"text": "function alpha = meshDihedralAngles(vertices, edges, faces)\n%MESHDIHEDRALANGLES Dihedral at edges of a polyhedal mesh\n%\n% ALPHA = meshDihedralAngles(V, E, F)\n% where V, E and F represent vertices, edges and faces of a mesh,\n% computes the dihedral angle between the two adjacent faces of each edge\n% in the mesh. ALPHA is a column array with as many rows as the number of\n% edges. The i-th element of ALPHA corresponds to the i-th edge.\n%\n% Note: the function assumes that the faces are correctly oriented. The\n% face vertices should be indexed counter-clockwise when considering the\n% supporting plane of the face, with the outer normal oriented outwards\n% of the mesh.\n%\n% Example\n% [v, e, f] = createCube;\n% rad2deg(meshDihedralAngles(v, e, f))\n% ans = \n% 90\n% 90\n% 90\n% 90\n% 90\n% 90\n% 90\n% 90\n% 90\n% 90\n% 90\n% 90\n%\n% See also\n% meshes3d, polyhedronMeanBreadth, trimeshMeanBreadth, dihedralAngle, meshEdgeFaces\n%\n\n% ------\n% Author: David Legland\n% e-mail: david.legland@inra.fr\n% Created: 2010-10-04, using Matlab 7.9.0.529 (R2009b)\n% Copyright 2010 INRA - Cepia Software Platform.\n\n% compute normal of each face\nnormals = meshFaceNormals(vertices, faces);\n\n% indices of faces adjacent to each edge\nedgeFaces = meshEdgeFaces(vertices, edges, faces);\n\n% allocate memory for resulting angles\nNe = size(edges, 1);\nalpha = zeros(Ne, 1);\n\n% iterate over edges\nfor i = 1:Ne\n % indices of adjacent faces\n indFace1 = edgeFaces(i, 1);\n indFace2 = edgeFaces(i, 2);\n \n % normal vector of adjacent faces\n normal1 = normals(indFace1, :);\n normal2 = normals(indFace2, :);\n \n % compute dihedral angle of two vectors\n alpha(i) = vectorAngle3d(normal1, normal2);\nend\n\n", "meta": {"author": "rpng", "repo": "lips", "sha": "a97157e586b509c9c2e3e01e64e4347f36d0b63e", "save_path": "github-repos/MATLAB/rpng-lips", "path": "github-repos/MATLAB/rpng-lips/lips-a97157e586b509c9c2e3e01e64e4347f36d0b63e/lips_matlab/matlab/functions/matGeom/meshes3d/meshDihedralAngles.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970811069351, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.7468875213758551}} {"text": "function dist_signed = plane_imp_point_dist_signed_3d ( a, b, c, d, p )\n\n%*****************************************************************************80\n%\n%% PLANE_IMP_POINT_DIST_SIGNED_3D: signed distance ( implicit plane, point) in 3D.\n%\n% Discussion:\n%\n% The implicit form of a plane in 3D is:\n%\n% A * X + B * Y + C * Z + D = 0\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 02 March 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Priamos Georgiades,\n% Signed Distance From Point To Plane,\n% Graphics Gems III,\n% Edited by David Kirk,\n% Academic Press, 1992, pages 233-235, T385.G6973.\n%\n% Parameters:\n%\n% Input, real A, B, C, D, the implicit plane parameters.\n%\n% Input, real P(3), the coordinates of the point.\n%\n% Output, real DIST_SIGNED, the signed distance from \n% the point to the plane.\n%\n dim_num = 3;\n\n norm = sqrt ( a * a + b * b + c * c );\n\n if ( norm == 0.0 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'PLANE_IMP_POINT_DIST_SIGNED_3D - Fatal error!\\n' );\n fprintf ( 1, ' The plane normal vector is null.\\n' );\n error ( 'PLANE_IMP_POINT_DIST_SIGNED_3D - Fatal error!' );\n end\n\n dist_signed = - ( a * p(1) + b * p(2) + c * p(3) + d ) / norm;\n\n if ( d < 0.0 )\n dist_signed = -dist_signed;\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/geometry/plane_imp_point_dist_signed_3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045996818987, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.7468715898925079}} {"text": "function varargout = gradientSpect(f, dn, dim, deriv_order)\n%GRADIENTSPECT Calculate the gradient using a Fourier spectral method.\n%\n% DESCRIPTION:\n% gradientSpect calculates the gradient of an n-dimensional input\n% matrix using the Fourier collocation spectral method. The gradient\n% for singleton dimensions is returned as 0.\n%\n% Examples:\n% 1. 1D Sinusoid:\n%\n% % compute gradient of a 2 period sinusoid\n% x = pi/20:pi/20:4*pi;\n% y = sin(x);\n% dydx = gradientSpect(y, pi/20);\n%\n% % plot gradient and error compared to analytical solution\n% subplot(2, 1, 1), plot(x, cos(x), 'k-', x, dydx, 'bx');\n% axis tight;\n% title('dy/dx');\n% subplot(2, 1, 2), plot(x, cos(x) - dydx, 'k-');\n% axis tight;\n% title('Relative Error');\n%\n% 2. Modified 2D Mathworks gradient example (x and y reversed):\n%\n% [x, y] = meshgrid(-2:.2:2, -2:.2:2);\n% z = x .* exp(-x.^2 - y.^2);\n% [px,py] = gradientSpect(z, [.2, .2]);\n% contour(z), hold on, quiver(py, px), hold off;\n%\n% USAGE:\n% fx = gradientSpect(f, dx)\n% fx = gradientSpect(f, dx, [], deriv_order)\n% fn = gradientSpect(f, dn, dim)\n% fn = gradientSpect(f, dn, dim, deriv_order)\n% [fx, fy] = gradientSpect(f, dn)\n% [fx, fy] = gradientSpect(f, dn, [], deriv_order)\n% [fx, fy, fz, ...] = gradientSpect(f, dn)\n% [fx, fy, fz, ...] = gradientSpect(f, dn, [], deriv_order)\n%\n% INPUTS:\n% f - matrix or vector to find the gradient of\n% dn - array of values for the grid point spacing in each\n% dimension. If a value for dim is given, dn is the\n% spacing in dimension dim.\n% \n% OPTIONAL INPUTS:\n% dim - optional input to specify a single dimension over\n% which to compute the gradient for n-dimension input\n% functions\n% deriv_order - order of the derivative to compute, e.g., use 1 to\n% compute df/dx, 2 to compute df^2/dx^2, etc. \n% (default = 1)\n% \n%\n% OUTPUTS:\n% fx, fy, ... - gradient in the each dimension, where x corresponds\n% to dim = 1, y corresponds to dim = 2 etc \n% \n% ABOUT:\n% author - Bradley Treeby\n% date - 25th January 2012\n% last update - 27th August 2012\n% \n% This function is part of the k-Wave Toolbox (http://www.k-wave.org)\n% Copyright (C) 2009-2014 Bradley Treeby and Ben Cox\n%\n% See also gradient, gradientFD\n\n% This file is part of k-Wave. k-Wave is free software: you can\n% redistribute it and/or modify it under the terms of the GNU Lesser\n% General Public License as published by the Free Software Foundation,\n% either version 3 of the License, or (at your option) any later version.\n% \n% k-Wave is distributed in the hope that it will be useful, but WITHOUT ANY\n% WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n% FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for\n% more details. \n% \n% You should have received a copy of the GNU Lesser General Public License\n% along with k-Wave. If not, see .\n\n% check for user input for deriv_order\nif nargin < 4 || isempty(deriv_order)\n deriv_order = 1;\nelseif ~((deriv_order > 0) && (deriv_order == round(deriv_order)))\n error('input for deriv_order must be an integer > 0');\nend\n\n% check for user input for dim\nif (nargin < 3) || isempty(dim)\n dim = 0;\nend\n\n% get size of the input function\nsz = size(f);\n\n% check if input is 1D or user defined input dimension is given\nif dim || (nargout == 1 && (max(sz) == prod(sz)))\n \n % check if a single dn value is given, if not, extract the required\n % value\n if numel(dn) ~= 1\n dn = dn(dim);\n end\n \n % get the grid size along the specified dimension, or the longest\n % dimension if 1D\n if nargout == 1 && (max(sz) == prod(sz))\n [Nx, dim] = max(sz);\n else\n Nx = sz(dim);\n end\n \n % get the wavenumbers\n kx = getWavenumbers(Nx, dn, dim);\n\n % calculate derivative and assign output \n varargout{1} = ifft( bsxfun(@times, (1i*kx).^deriv_order, fft(f, [], dim)) , [], dim, 'symmetric');\n \nelse\n \n % check for the correct number of dn values\n if length(dn) ~= length(sz)\n error([num2str(length(sz)) ' values for dn must be specified for a ' num2str(length(sz)) '-dimensional input matrix']);\n end\n \n % check for the correct number of outputs\n if nargout ~= length(sz)\n error(['Incorrect number of output arguments for ' num2str(length(sz)) '-dimensional input matrix']);\n end\n\n % calculate the gradient for each non-singleton dimension\n for dim = 1:ndims(f)\n if sz(dim) > 1\n\n % get the wavenumbers\n kx = getWavenumbers(sz(dim), dn(dim), dim);\n\n % calculate derivative and assign output \n varargout{dim} = ifft( bsxfun(@times, (1i*kx).^deriv_order, fft(f, [], dim)) , [], dim, 'symmetric');\n\n else\n % assign the derivate for singleton dimensions to be 0\n varargout{dim} = 0;\n end\n end\nend\n\nfunction kx = getWavenumbers(Nx, dx, dim)\n% subfuction to compute the wavenumber vector\n\n% calculate the wavenumbers\nif rem(Nx, 2) == 0\n % grid dimension has an even number of points\n nx = ((-Nx/2:Nx/2-1)/Nx).';\nelse\n % grid dimension has an odd number of points\n nx = ((-(Nx-1)/2:(Nx-1)/2)/Nx).';\nend\nkx = ifftshift((2*pi/dx).*nx); \n\n% permute to be in the correction direction for use with bsxfun\nif dim == 1\n kx = reshape(kx, Nx, 1);\nelse\n kx = reshape(kx, [ones(1, dim - 1), Nx]);\nend\n", "meta": {"author": "wme7", "repo": "Aero-matlab", "sha": "9430008f2e3b84f28633775a44dff534e780fbac", "save_path": "github-repos/MATLAB/wme7-Aero-matlab", "path": "github-repos/MATLAB/wme7-Aero-matlab/Aero-matlab-9430008f2e3b84f28633775a44dff534e780fbac/K-wave/k-Wave/gradientSpect.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045907347108, "lm_q2_score": 0.8418256532040708, "lm_q1q2_score": 0.7468715841208982}} {"text": "function triangulation_test15 ( )\n\n%*****************************************************************************80\n%\n%% TEST15 tests TRIANGULATION_ORDER3_BOUNDARY_NODE.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 24 August 2006\n%\n% Author:\n%\n% John Burkardt\n%\n dim_num = 2;\n node_num = 36;\n triangle_num = 41;\n\n triangle_node(1:3,1:triangle_num) = [ ...\n 1, 8, 7; ...\n 1, 2, 8; ...\n 2, 9, 8; ...\n 2, 3, 9; ...\n 3, 10, 9; ...\n 3, 4, 10; ...\n 4, 11, 10; ...\n 4, 5, 11; ...\n 5, 12, 11; ...\n 5, 6, 12; ...\n 7, 14, 13; ...\n 7, 8, 14; ...\n 8, 15, 14; ...\n 8, 9, 15; ...\n 11, 18, 17; ...\n 11, 12, 18; ...\n 13, 20, 19; ...\n 13, 14, 20; ...\n 14, 21, 20; ...\n 14, 15, 21; ...\n 15, 22, 21; ...\n 15, 16, 22; ...\n 16, 23, 22; ...\n 16, 17, 23; ...\n 17, 24, 23; ...\n 17, 18, 24; ...\n 19, 26, 25; ...\n 19, 20, 26; ...\n 21, 28, 27; ...\n 21, 22, 28; ...\n 25, 30, 29; ...\n 25, 26, 30; ...\n 26, 31, 30; ...\n 27, 32, 31; ...\n 27, 28, 32; ...\n 29, 34, 33; ...\n 29, 30, 34; ...\n 30, 35, 34; ...\n 30, 31, 35; ...\n 31, 36, 35; ...\n 31, 32, 36 ]';\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TEST15\\n' );\n fprintf ( 1, ' TRIANGULATION_ORDER3_BOUNDARY_NODE determines which\\n' );\n fprintf ( 1, ' nodes lie on the boundary of a triangulation.\\n' );\n\n node_boundary = triangulation_order3_boundary_node ( node_num, ...\n triangle_num, triangle_node );\n\n lvec_print ( node_num, node_boundary, ' Node BN?' );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/triangulation/triangulation_test15.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256393148981, "lm_q2_score": 0.8872045966995028, "lm_q1q2_score": 0.7468715768196752}} {"text": "function y = huber_pos( x, M, t )\n\n%HUBER_POS Monotonic huber penalty function.\n% For a vector X, HUBER_POS(X) computes the monotonic Huber-style function\n% \n% 0 if 0>=X\n% HUBER_POS(X) = X^2 if 0<=X<=1\n% 2*X-1 if X>=1\n%\n% HUBER_POS(X,M) is the monotonic Huber-style penalty function of\n% halfwidth M, M.^2.*HUBER_POS(X./M). M must be real and positive.\n%\n% HUBER_POS(X,M,T) computes the monotonic Huber-style penalty function \n% with halfwidth M and concomitant scale T:\n%\n% HUBER_POS(X,M,T) = T.*HUBER_POS(X./T,M) if T > 0\n% +Inf if T <= 0\n%\n% See the help file for HUBER for information about this usage.\n%\n% For matrices and N-D arrays, the penalty function is applied to each\n% element of X independently. M and T must be compatible with X in the same\n% sense as .*: one must be a scalar, or they must have identical size.\n%\n% Disciplined convex programming information:\n% HUBER_POS is jointly convex in X and T. It is nondecreasing in X and\n% nonincreasing in T. Therefore, when used in CVX specifications, X\n% must be convex and T must be concave (or affine). Both must be real.\n\n%\n% Check arguments\n%\n\nnarginchk(1,3);\nif ~isreal( x ),\n error( 'First argument must be real.' );\nend\nif nargin < 2,\n M = 1;\nelseif ~isreal( M ) || any( M( : ) <= 0 ),\n error( 'Second argument must be real and positive.' );\nend\nif nargin < 3,\n t = 1;\nelseif ~isreal( t ),\n error( 'Third argument must be real.' );\nend\nsz = cvx_size_check( x, M, t );\nif isempty( sz ),\n error( 'Sizes are incompatible.' );\nend\n\n%\n% Compute result\n%\n\ny = max( x, 0 );\nz = min( y, M );\ny = t .* z .* ( 2 * y - z );\nq = t <= 0;\nif nnz( q ),\n if length( t ) == 1,\n y = Inf * ones( sy );\n else\n y( q ) = Inf;\n end\nend\n\n% Copyright 2005-2016 CVX Research, Inc. \n% See the file LICENSE.txt for full copyright information.\n% The command 'cvx_where' will show where this file is located.\n", "meta": {"author": "cvxr", "repo": "CVX", "sha": "a7b46e7840c3ccf3f35df374d2ff3da4eaafc3cd", "save_path": "github-repos/MATLAB/cvxr-CVX", "path": "github-repos/MATLAB/cvxr-CVX/CVX-a7b46e7840c3ccf3f35df374d2ff3da4eaafc3cd/functions/huber_pos.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171068, "lm_q2_score": 0.8418256412990657, "lm_q1q2_score": 0.7468715760693805}} {"text": "function a = pascal3_inverse ( n, alpha )\n\n%*****************************************************************************80\n%\n%% PASCAL3_INVERSE returns the inverse of the PASCAL3 matrix.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 23 October 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the order of A.\n%\n% Input, real ALPHA, the parameter.\n%\n% Output, real A(N,N), the matrix.\n%\n a = zeros ( n, n );\n\n for i = 1 : n\n for j = 1 : n\n\n if ( i == 1 )\n\n if ( j == 1 )\n a(i,j) = 1.0;\n else\n a(i,j) = 0.0;\n end\n\n elseif ( j == 1 )\n\n a(i,j) = - alpha * a(i-1,j);\n\n else\n\n a(i,j) = a(i-1,j-1) - alpha * a(i-1,j);\n\n end\n\n end\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_mat/pascal3_inverse.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8872045817875225, "lm_q2_score": 0.8418256452674008, "lm_q1q2_score": 0.7468715695474756}} {"text": "function op = prox_l1_deadzone( q, epsilon )\n\n%PROX_L1_DEADZONE L1 norm with deadzone [-eps,eps]\n% OP = PROX_L1_DEADZONE( q, eps ) implements the nonsmooth function\n% OP(X) = q*sum_i max(0,x-eps)+max(0,-x-eps) = q*sum_i\n% max(0,|x|-eps)\n% Q is optional; if omitted, Q=1 is assumed. But if Q is supplied,\n% then it must be a positive real scalar (or must be same size as X).\n%\n\n% New March 2 2016\n\nif nargin == 0,\n\tq = 1;\nelseif ~isnumeric( q ) || ~isreal( q ) || any( q(:) < 0 ) || all(q(:)==0) %|| numel( q ) ~= 1\n if q==0\n op = prox_0;\n warning('TFOCS:zeroQ','q=0 so returning the proximal operator for the zero function');\n return;\n else\n error( 'Argument must be positive.' );\n end\nend\n\n% This is Matlab and Octave compatible code\nop = tfocs_prox( @(x)f(q, epsilon,x), @(x,t)prox_f(q, epsilon,x,t) , 'vector' );\nend\n\n% These are now subroutines, that are NOT in the same scope\nfunction v = f(qq,epsilon, x)\n v = sum( qq(:).*max(0,abs(x(:))-epsilon), 1 );\nend\n\nfunction x = prox_f(qq,epsilon, x,t) \n% p = x if |x| tq\n% i.e., if |x|>eps, p = sign(x).*max( |x|-tq, eps )\n tq = t .* qq; \n x = sign(x).*( abs(x).*( abs(x)= epsilon) );\nend\n\n\n\n% TFOCS v1.3 by Stephen Becker, Emmanuel Candes, and Michael Grant.\n% Copyright 2013 California Institute of Technology and CVX Research.\n% See the file LICENSE for full license information.\n", "meta": {"author": "cvxr", "repo": "TFOCS", "sha": "164ada20401cd445930673e42bb3d2a5489f2030", "save_path": "github-repos/MATLAB/cvxr-TFOCS", "path": "github-repos/MATLAB/cvxr-TFOCS/TFOCS-164ada20401cd445930673e42bb3d2a5489f2030/prox_l1_deadzone.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513814471134, "lm_q2_score": 0.8333245953120234, "lm_q1q2_score": 0.7468683197422576}} {"text": "function [ n_data, c, x, fx ] = student_cdf_values ( n_data )\n\n%*****************************************************************************80\n%\n%% STUDENT_CDF_VALUES returns some values of the Student CDF.\n%\n% Discussion:\n%\n% In Mathematica, the function can be evaluated by:\n%\n% Needs[\"Statistics`ContinuousDistributions`\"]\n% dist = StudentTDistribution [ df ]\n% CDF [ dist, x ]\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 02 November 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Milton Abramowitz and Irene Stegun,\n% Handbook of Mathematical Functions,\n% US Department of Commerce, 1964.\n%\n% Stephen Wolfram,\n% The Mathematica Book,\n% Fourth Edition,\n% Wolfram Media / Cambridge University Press, 1999.\n%\n% Parameters:\n%\n% Input/output, integer N_DATA. The user sets N_DATA to 0 before the\n% first call. On each call, the routine increments N_DATA by 1, and\n% returns the corresponding data; when there is no more data, the\n% output value of N_DATA will be 0 again.\n%\n% Output, real C, is usually called the number of \n% degrees of freedom of the distribution. C is typically an \n% integer, but that is not essential. It is required that\n% C be strictly positive.\n%\n% Output, real X, the argument of the function.\n%\n% Output, real FX, the value of the function.\n%\n n_max = 13;\n\n c_vec = [ ...\n 1.0, 2.0, 3.0, 4.0, ...\n 5.0, 2.0, 5.0, 2.0, ...\n 5.0, 2.0, 3.0, 4.0, ...\n 5.0 ];\n\n fx_vec = [ ...\n 0.6000231200328521, ...\n 0.6001080279134390, ...\n 0.6001150934648930, ...\n 0.6000995134721354, ...\n 0.5999341989834830, ...\n 0.7498859393137811, ...\n 0.7500879487671045, ...\n 0.9500004222186464, ...\n 0.9499969138365968, ...\n 0.9900012348724744, ...\n 0.9900017619355059, ...\n 0.9900004567580596, ...\n 0.9900007637471291 ];\n\n x_vec = [ ...\n 0.325, ...\n 0.289, ...\n 0.277, ...\n 0.271, ...\n 0.267, ...\n 0.816, ...\n 0.727, ...\n 2.920, ...\n 2.015, ...\n 6.965, ...\n 4.541, ...\n 3.747, ...\n 3.365 ];\n\n if ( n_data < 0 )\n n_data = 0;\n end\n\n n_data = n_data + 1;\n\n if ( n_max < n_data )\n n_data = 0;\n c = 0.0;\n x = 0.0;\n fx = 0.0;\n else\n c = c_vec(n_data);\n x = x_vec(n_data);\n fx = fx_vec(n_data);\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_values/student_cdf_values.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336202, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.7468683146693841}} {"text": "function [ xtab, ytab, weight ] = hexagon_unit_set ( rule, order )\n\n%*****************************************************************************80\n%\n%% HEXAGON_UNIT_SET sets a quadrature rule inside the unit hexagon in 2D.\n%\n% Integration region:\n%\n% The definition is given in terms of THETA, the angle in degrees of the\n% vector (X,Y). The following six conditions apply, respectively,\n% between the bracketing values of THETA of 0, 60, 120, 180, 240,\n% 300, and 360.\n%\n% 0 <= Y <= - SQRT(3) * X + SQRT(3)\n% 0 <= Y <= SQRT(3)/2\n% 0 <= Y <= SQRT(3) * X + SQRT(3)\n% - SQRT(3) * X - SQRT(3) <= Y <= 0\n% - SQRT(3)/2 <= Y <= 0\n% SQRT(3) * X - SQRT(3) <= Y <= 0\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 18 March 2008\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Abramowitz and Stegun,\n% Handbook of Mathematical Functions,\n% National Bureau of Standards, 1964.\n%\n% Arthur H Stroud,\n% Approximate Calculation of Multiple Integrals,\n% Prentice Hall, 1971.\n%\n% Parameters:\n%\n% Input, integer RULE, the rule desired.\n% 1, 1 point, degree 1;\n% 2, 4 points, degree 3;\n% 3, 7 points, degree 3;\n% 4, 7 points, degree 5;\n%\n% Input, integer ORDER, the order of the desired rule.\n%\n% Output, real XTAB(ORDER), YTAB(ORDER), the abscissase.\n%\n% Output, real WEIGHT(ORDER), the weights.\n%\n if ( rule == 1 )\n\n xtab(1) = 0.0;\n ytab(1) = 0.0;\n weight(1) = 1.0;\n%\n% Stroud rule H2:3-1.\n%\n elseif ( rule == 2 )\n\n a = sqrt ( 5.0 / 12.0 );\n b = 1.0 / 4.0;\n z = 0.0;\n\n xtab(1:4) = [ a, -a, z, z ];\n ytab(1:4) = [ z, z, a, -a ];\n weight(1:4) = [ b, b, b, b ];\n%\n% Stroud rule H2:3-2.\n%\n elseif ( rule == 3 )\n\n a = sqrt ( 3.0 ) / 2.0;\n b = 0.5;\n c = 1.0;\n d = 5.0 / 72.0;\n e = 42.0 / 72.0;\n z = 0.0;\n\n xtab(1:7) = [ z, c, -c, b, -b, b, -b ];\n ytab(1:7) = [ z, z, z, a, a, -a, -a ];\n weight(1:7) = [ e, d, d, d, d, d, d ];\n%\n% Stroud rule H2:5-1.\n%\n elseif ( rule == 4 )\n\n a = sqrt ( 14.0 ) / 5.0;\n b = sqrt ( 14.0 ) / 10.0;\n c = sqrt ( 42.0 ) / 10.0;\n d = 125.0 / 1008.0;\n e = 258.0 / 1008.0;\n z = 0.0;\n\n xtab(1:7) = [ z, a, -a, b, -b, b, -b ];\n ytab(1:7) = [ z, z, z, c, c, -c, -c ];\n weight(1:7) = [ e, d, d, d, d, d, d ];\n\n else\n\n xtab = [];\n ytab = [];\n weight = [];\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'HEXAGON_UNIT_SET - Fatal error!\\n' );\n fprintf ( 1, ' Nonexistent rule number %d requested.\\n', rule );\n error ( 'HEXAGON_UNIT_SET - Fatal error!' );\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/stroud/hexagon_unit_set.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096158798117, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.7468423247292473}} {"text": "% util_checkCloseMatrixElements Check if some rows of the matrix A are too\n% \"similar\". Similar means their Euclidean distance being smaller than\n% tolerance, which if not given is set automatically heuristically\nfunction [res, distances, tolerance] = util_checkCloseMatrixElements(A, tolerance)\n\nC = nan(size(A,1));\nfor i = 1:size(A,1)\n for j = i+1:size(A,1)\n C(i,j) = dist2(A(i,:), A(j,:));%/norm(abs(A(i,:))+abs(A(j,:)));\n end\nend\nnn = C(~isnan(C));\ndistances = C;\nC = C./mean(nn);\nif nargin < 2 || isempty(tolerance)\n tolerance = 0.0001;\nend\n\n%maxDist = dist2(max(A), min(A));\n%C = dist2(A, A);\n%C = C + eye(size(C))*maxDist*2; % Don't care about diagonal (same point)\n%if nargin < 2 || isempty(tolerance)\n% tolerance = (maxDist/mean(sum(A,2).^2))*0.0001;\n% %[~,j]=sort(sum(A,2).^2);\n% %A = A(j,:);\n%end\ntmp = find(C <= tolerance);\nres = [mod(tmp, size(C,1)) ceil(tmp/size(C,1))];\nres(res==0) = size(C,1);\nres = unique(sort(res,2), 'rows');", "meta": {"author": "SheffieldML", "repo": "vargplvm", "sha": "480201fde5ac84ff36e4a9f06d3fafeafa8ef06d", "save_path": "github-repos/MATLAB/SheffieldML-vargplvm", "path": "github-repos/MATLAB/SheffieldML-vargplvm/vargplvm-480201fde5ac84ff36e4a9f06d3fafeafa8ef06d/vargplvm/matlab/utils/util_checkCloseMatrixElements.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096090086367, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.7468423211838862}} {"text": "function tw = trigauss_conversion ( xw, omega )\n\n%*****************************************************************************80\n%\n%% TRIGAUSS_CONVERSION converts Gauss to trigonometric Gauss quadrature.\n%\n% Modified:\n%\n% 19 May 2013\n%\n% Author:\n%\n% Gaspare Da Fies, Alvise Sommariva, Marco Vianello\n%\n% Parameters:\n%\n% Input, real XW(N,2), the points and weights of a Gauss quadrature rule\n% on [-1,+1].\n%\n% Input, real OMEGA, the arc angle, 0 < OMEGA <= PI.\n%\n% Output, real TW(N,2), the angles and weights for the trigonometic\n% quadrature rule over [-OMEGA,+OMEGA].\n%\n tw(:,1) = 2.0 * asin ( sin ( omega / 2.0 ) * xw(:,1) );\n tw(:,2) = xw(:,2);\n\n return\nend\n\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/circle_segment/trigauss_conversion.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9161096090086367, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.7468423211838862}} {"text": "function fem2d_poisson_sparse ( prefix )\n\n%*****************************************************************************80\n%\n%% MAIN is the main routine for FEM2D_POISSON_SPARSE.\n%\n% Discussion:\n%\n% This program uses MATLAB's sparse matrix storage, factorization \n% and solution facilities to compute an approximate solution to\n% the Poisson equation via the finite element method.\n%\n% Three functions are changed from those in the FEM2D_POISSON code:\n% * the main program FEM2D_POISSON is replaced by FEM2D_POISSON_SPARSE.\n% * the routine ASSEMBLE_POISSON is replaced by ASSEMBLE_POISSON_SPARSE.\n% * the routine DIRICHLET_APPLY is replaced by DIRICHLET_APPLY_SPARSE.\n%\n% This program solves the Poisson equation\n%\n% -DEL H(X,Y) DEL U(X,Y) + K(X,Y) * U = F(X,Y)\n%\n% in a triangulated region in the plane.\n%\n% Along the boundary of the region, Dirichlet conditions\n% are imposed:\n%\n% U(X,Y) = G(X,Y)\n%\n% The code uses continuous piecewise linear basis functions on\n% triangles.\n%\n% Problem specification:\n%\n% The user defines the geometry by supplying two data files\n% which list the node coordinates, and list the nodes that make up\n% each element.\n%\n% The user specifies the right hand side of the Dirichlet boundary\n% conditions by supplying a function\n%\n% function node_bc = dirichlet_condition ( node_num, node_xy )\n%\n% The user specifies the coefficient function H(X,Y):\n%\n% function node_h = h_coef ( node_num, node_xy )\n%\n% The user specifies the coefficient function K(X,Y):\n%\n% function node_k = k_coef ( node_num, node_xy )\n%\n% The user specifies the right hand side of the Poisson equation\n% by supplying a routine of the form\n%\n% function node_rhs = rhs ( node_num, node_xy )\n%\n% Usage:\n%\n% fem2d_poisson_sparse ( 'prefix' )\n%\n% where:\n%\n% 'prefix' is the common prefix for the node and element files:\n%\n% * prefix_nodes.txt, the node coordinates.\n% * prefix_elements.txt, the nodes that make up each element.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 15 July 2010\n%\n% Author:\n%\n% John Burkardt\n%\n% Local parameters:\n%\n% Local, real sparse A(:,), the finite element coefficient matrix.\n%\n% Local, integer ELEMENT_NODE[3*ELEMENT_NUM];\n% ELEMENT_NODE(I,J) is the global index of local node I in element J.\n%\n% Local, integer ELEMENT_NUM, the number of elements.\n%\n% Local, integer ELEMENT_ORDER, the element order.\n%\n% Local, real F(NODE_NUM,1), the right hand side.\n%\n% Local, logical NODE_BOUNDARY(NODE_NUM), is TRUE if the node is\n% found to lie on the boundary of the region.\n%\n% Local, integer NODE_CONDITION(NODE_NUM),\n% indicates the condition used to determine the variable at a node.\n% 0, there is no condition (and no variable) at this node.\n% 1, a finite element equation is used;\n% 2, a Dirichlet condition is used.\n% 3, a Neumann condition is used.\n%\n% Local, integer NODE_NUM, the number of nodes.\n%\n% Local, real NODE_R(NODE_NUM), the residual error.\n%\n% Local, real NODE_U(NODE_NUM), the finite element coefficients.\n%\n% Local, real NODE_XY(2,NODE_NUM), the coordinates of nodes.\n%\n% Local, integer QUAD_NUM, the number of quadrature points used for\n% assembly. This is currently set to 3, the lowest reasonable value.\n% Legal values are 1, 3, 4, 6, 7, 9, 13, and for some problems, a value\n% of QUAD_NUM greater than 3 may be appropriate.\n%\n debugging = 0;\n quad_num = 3;\n\n timestamp ( );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'FEM2D_POISSON_SPARSE:\\n' );\n fprintf ( 1, ' MATLAB version\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' A version of FEM2D_POISSON using MATLAB''s \\n' );\n fprintf ( 1, ' sparse matrix storage, factor and solve facilities.\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Finite element solution of the \\n' );\n fprintf ( 1, ' steady Poisson equation on a triangulated region\\n' );\n fprintf ( 1, ' in 2 dimensions.\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' - DEL H(x,y) DEL U(x,y) + K(x,y) * U(x,y) = F(x,y) in the region\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' U(x,y) = G(x,y) on the boundary.\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' The finite element method is used,\\n' );\n fprintf ( 1, ' with triangular elements,\\n' );\n fprintf ( 1, ' which must be a 3 node linear triangle.\\n' );\n%\n% Must have prefix.\n%\n if ( nargin < 1 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'FEM2D_POISSON_SPARSE - Fatal error!\\n' );\n fprintf ( 1, ' Missing \"prefix\", the common filename prefix input.\\n' );\n error ( 'FEM2D_POISSON_SPARSE - Fatal error!\\n' )\n end\n%\n% Create the file names.\n%\n node_filename = strcat ( prefix, '_nodes.txt' );\n element_filename = strcat ( prefix, '_elements.txt' );\n solution_filename = strcat ( prefix, '_values.txt' );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Node file is \"%s\".\\n', node_filename );\n fprintf ( 1, ' Element file is \"%s\".\\n', element_filename );\n%\n% Read the node coordinate file.\n%\n node_xy = load ( node_filename );\n node_xy = node_xy';\n [ dim_num, node_num ] = size ( node_xy );\n\n fprintf ( 1, ' Number of nodes = %d\\n', node_num );\n\n r8mat_transpose_print_some ( dim_num, node_num, node_xy, 1, 1, 2, 10, ...\n ' First 10 nodes' );\n%\n% Read the element description file.\n%\n element_node = load ( element_filename );\n element_node = element_node';\n [ element_order, element_num ] = size ( element_node );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Element order = %d\\n', element_order );\n fprintf ( 1, ' Number of elements = %d\\n', element_num );\n\n if ( element_order ~= 3 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'FEM2D_POISSON_SPARSE - Fatal error!\\n' );\n fprintf ( 1, ' The input triangulation has order %d.\\n', element_order );\n fprintf ( 1, ' However, a triangulation of order 3 is required.' );\n error ( 'FEM2D_POISSON_SPARSE - Fatal error!' );\n end\n\n i4mat_transpose_print_some ( 3, element_num, ...\n element_node, 1, 1, 3, 10, ' First 10 elements' );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Quadrature order = %d\\n', quad_num );\n%\n% Determine which nodes are boundary nodes and which have a\n% finite element unknown. Then set the boundary values.\n%\n node_boundary = triangulation_order3_boundary_node ( node_num, ...\n element_num, element_node );\n%\n% Determine the node conditions.\n% For now, we'll just assume all boundary nodes are Dirichlet.\n%\n node_condition(1:node_num) = 1;\n\n for node = 1 : node_num\n if ( node_boundary(node) )\n node_condition(node) = 2;\n end\n end\n%\n% Determine the element neighbor array, just so we can estimate\n% the nonzeros.\n%\n element_neighbor = triangulation_neighbor_triangles ( ...\n element_order, element_num, element_node );\n%\n% Determine the maximum number of nonzeros.\n%\n [ nz_num, adj_col ] = triangulation_order3_adj_count ( node_num, ...\n element_num, element_node, element_neighbor );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' TRIANGULATION_ORDER3_ADJ_COUNT returns NZ_NUM = %d\\n', ...\n nz_num );\n%\n% Assemble the finite element coefficient matrix A and the right-hand side F.\n%\n [ a, f ] = assemble_poisson_sparse ( node_num, node_xy, ...\n element_num, element_node, quad_num, nz_num );\n\n if ( debugging )\n\n a_copy = full ( a );\n r8mat_print_some ( node_num, node_num, a_copy, 1, 1, 10, 10, ...\n ' Part of Poisson stiffness matrix A:' );\n\n r8vec_print_some ( node_num, f, 1, 10, ...\n ' Part of finite element right hand side vector F:' );\n\n end\n%\n% Adjust the linear system to account for Dirichlet boundary conditions.\n%\n [ a, f ] = dirichlet_apply_sparse ( node_num, node_xy, node_condition, ...\n a, f );\n\n if ( debugging )\n\n a_copy = full ( a );\n r8mat_print_some ( node_num, node_num, a_copy, 1, 1, 10, 10, ...\n ' Part of Matrix A after Dirichlet boundary adjustments:' );\n\n r8mat_print_some ( node_num, 1, f, 1, 1, 10, 1, ...\n ' Part of right hand side after Dirichlet boundary adjustments:' );\n\n end\n%\n% Solve the linear system using MATLAB's sparse solver.\n%\n node_u = a \\ f;\n\n r8vec_print_some ( node_num, node_u, 1, 10, ...\n ' Part of the solution vector:' );\n\n node_r = residual_poisson ( node_num, node_xy, node_condition, ...\n element_num, element_node, quad_num, a, f, node_u );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Maximum absolute residual = %f\\n', ...\n max ( abs ( node_r(1:node_num) ) ) );\n%\n% Write an ASCII file that can be read into MATLAB.\n%\n save ( solution_filename, '-ascii', 'node_u' );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'FEM2D_POISSON_SPARSE:\\n' );\n fprintf ( 1, ' Wrote solution to the file \"%s\"\\n', solution_filename );\n%\n% Terminate.\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'FEM2D_POISSON_SPARSE:\\n' );\n fprintf ( 1, ' Normal end of execution.\\n' );\n fprintf ( 1, '\\n' );\n timestamp ( );\n\n return\nend\nfunction [ a, f ] = assemble_poisson_sparse ( node_num, node_xy, ...\n element_num, element_node, quad_num, nz_num )\n\n%*****************************************************************************80\n%\n%% ASSEMBLE_POISSON_SPARSE assembles the system for the Poisson equation.\n%\n% Discussion:\n%\n% The matrix is stored in MATLAB sparse matrix format.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 15 July 2010\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer NODE_NUM, the number of nodes.\n%\n% Input, real NODE_XY(2,NODE_NUM), the coordinates of nodes.\n%\n% Input, integer ELEMENT_NUM, the number of elements.\n%\n% Input, integer ELEMENT_NODE(3,ELEMENT_NUM);\n% element_NODE(I,J) is the global index of local node I in element J.\n%\n% Input, integer QUAD_NUM, the number of quadrature points used in assembly.\n%\n% Input, integer NZ_NUM, the (maximum) number of nonzeros in the matrix.\n% If set to 0 on input, we hope MATLAB's sparse utility will be able\n% to take over the task of reallocating space as necessary.\n%\n% Output, real sparse A(:,:), the coefficient matrix.\n%\n% Output, real F(NODE_NUM,1), the right hand side.\n%\n% Local parameters:\n%\n% Local, real BI, DBIDX, DBIDY, the value of some basis function\n% and its first derivatives at a quadrature point.\n%\n% Local, real BJ, DBJDX, DBJDY, the value of another basis\n% function and its first derivatives at a quadrature point.\n%\n\n%\n% Initialize the arrays to zero.\n%\n f(1:node_num,1) = 0.0;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'ASSEMBLE_POISSON_SPARSE:\\n' );\n fprintf ( 1, ' Setting up sparse Poisson matrix with NZ_NUM = %d\\n', nz_num );\n\n a = sparse ( [], [], [], node_num, node_num, nz_num );\n%\n% Get the quadrature weights and nodes.\n%\n [ quad_w, quad_xy ] = quad_rule ( quad_num );\n%\n% Add up all quantities associated with the element-th element.\n%\n for element = 1 : element_num\n%\n% Make a copy of the element.\n%\n t3(1:2,1:3) = node_xy(1:2,element_node(1:3,element));\n%\n% Map the quadrature points QUAD_XY to points PHYS_XY in the physical element.\n%\n phys_xy(1:2,1:quad_num) = reference_to_physical_t3 ( t3, quad_num, quad_xy );\n\n area = abs ( triangle_area_2d ( t3 ) );\n\n w(1:quad_num,1) = quad_w(1:quad_num,1) * area;\n\n phys_rhs = rhs ( quad_num, phys_xy );\n phys_h = h_coef ( quad_num, phys_xy );\n phys_k = k_coef ( quad_num, phys_xy );\n%\n% Consider the QUAD-th quadrature point..\n%\n for quad = 1 : quad_num\n%\n% Consider the TEST-th test function.\n%\n% We generate an integral for every node associated with an unknown.\n% But if a node is associated with a boundary condition, we do nothing.\n%\n for test = 1 : 3\n\n i = element_node(test,element);\n\n [ bi, dbidx, dbidy ] = basis_11_t3 ( t3, test, phys_xy(1:2,quad) );\n\n f(i,1) = f(i,1) + w(quad,1) * phys_rhs(quad,1) * bi;\n%\n% Consider the BASIS-th basis function, which is used to form the\n% value of the solution function.\n%\n for basis = 1 : 3\n\n j = element_node(basis,element);\n\n [ bj, dbjdx, dbjdy ] = basis_11_t3 ( t3, basis, phys_xy(1:2,quad) );\n\n a(i,j) = a(i,j) + w(quad,1) * ( ...\n phys_h(quad) * ( dbidx * dbjdx + dbidy * dbjdy ) ...\n + phys_k(quad) * bj * bi );\n\n end\n\n end\n\n end\n\n end\n\n return\nend\nfunction [ qi, dqidx, dqidy ] = basis_11_t3 ( t, i, p )\n\n%*****************************************************************************80\n%\n%% BASIS_11_T3: one basis at one point for the T3 element.\n%\n% Discussion:\n%\n% The routine is given the coordinates of the nodes of a triangle.\n%\n% 3\n% / \\\n% / \\\n% / \\\n% 1-------2\n%\n% It evaluates the linear basis function Q(I)(X,Y) associated with\n% node I, which has the property that it is a linear function\n% which is 1 at node I and zero at the other two nodes.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 14 February 2003\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real T(2,3), the coordinates of the nodes.\n%\n% Input, integer I, the index of the desired basis function.\n% I should be between 1 and 3.\n%\n% Input, real P(2), the coordinates of a point at which the basis\n% function is to be evaluated.\n%\n% Output, real QI, DQIDX, DQIDY, the values of the basis function\n% and its X and Y derivatives.\n%\n area = abs ( t(1,1) * ( t(2,2) - t(2,3) ) ...\n + t(1,2) * ( t(2,3) - t(2,1) ) ...\n + t(1,3) * ( t(2,1) - t(2,2) ) );\n\n if ( area == 0.0 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'BASIS_11_T3 - Fatal error!\\n' );\n fprintf ( 1, ' Element has zero area.\\n' );\n error ( 'BASIS_11_T3 - Fatal error!' );\n end\n\n if ( i < 1 | 3 < i )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'BASIS_11_T3 - Fatal error!\\n' );\n fprintf ( 1, ' Basis index I is not between 1 and 3.\\n' );\n fprintf ( 1, ' I = %d\\n', i );\n error ( 'BASIS_11_T3 - Fatal error!' );\n end\n\n if ( i == 1 )\n ip1 = 2;\n ip2 = 3;\n elseif ( i == 2 )\n ip1 = 3;\n ip2 = 1;\n else\n ip1 = 1;\n ip2 = 2;\n end\n\n qi = ( ( t(1,ip2) - t(1,ip1) ) * ( p(2) - t(2,ip1) ) ...\n - ( t(2,ip2) - t(2,ip1) ) * ( p(1) - t(1,ip1) ) ) / area;\n\n dqidx = - ( t(2,ip2) - t(2,ip1) ) / area;\n dqidy = ( t(1,ip2) - t(1,ip1) ) / area;\n\n return\nend\nfunction [ a, f ] = dirichlet_apply_sparse ( node_num, node_xy, ...\n node_condition, a, f )\n\n%*****************************************************************************80\n%\n%% DIRICHLET_APPLY_SPARSE accounts for Dirichlet boundary conditions.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 14 February 2003\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer NODE_NUM, the number of nodes.\n%\n% Input, real NODE_XY(2,NODE_NUM), the coordinates of nodes.\n%\n% Input, integer NODE_CONDITION(NODE_NUM), reports the condition\n% used to set the unknown associated with the node.\n% 0, unknown.\n% 1, finite element equation.\n% 2, Dirichlet condition;\n% 3, Neumann condition.\n%\n% Input, real sparse A(:,:), the coefficient matrix.\n%\n% Input, real F(NODE_NUM,1), the right hand side.\n%\n% Output, real sparse A(:,:), the coefficient matrix,\n% adjusted for Dirichlet boundary conditions.\n%\n% Output, real F(NODE_NUM), the right hand side, adjusted for\n% Dirichlet boundary conditions.\n%\n node_bc = dirichlet_condition ( node_num, node_xy );\n\n DIRICHLET = 2;\n\n for node = 1 : node_num\n\n if ( node_condition(node) == DIRICHLET )\n\n a(node,:) = 0.0;\n a(node,node) = 1.0;\n\n f(node,1) = node_bc(node);\n\n end\n\n end\n\n return\nend\nfunction isgn = i4col_compare ( m, n, a, i, j )\n\n%*****************************************************************************80\n%\n%% I4COL_COMPARE compares columns I and J of a integer array.\n%\n% Example:\n%\n% Input:\n%\n% M = 3, N = 4, I = 2, J = 4\n%\n% A = (\n% 1 2 3 4\n% 5 6 7 8\n% 9 10 11 12 )\n%\n% Output:\n%\n% ISGN = -1\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 12 June 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer M, N, the number of rows and columns.\n%\n% Input, integer A(M,N), an array of N columns of vectors of length M.\n%\n% Input, integer I, J, the columns to be compared.\n% I and J must be between 1 and N.\n%\n% Output, integer ISGN, the results of the comparison:\n% -1, column I < column J,\n% 0, column I = column J,\n% +1, column J < column I.\n%\n\n%\n% Check.\n%\n if ( i < 1)\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'I4COL_COMPARE - Fatal error!\\n' );\n fprintf ( 1, ' Column index I = %d < 1.\\n', i );\n error ( 'I4COL_COMPARE - Fatal error!' );\n end\n\n if ( n < i )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'I4COL_COMPARE - Fatal error!\\n' );\n fprintf ( 1, ' N = %d < column index I = %d.\\n', n, i );\n error ( 'I4COL_COMPARE - Fatal error!' );\n end\n\n if ( j < 1 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'I4COL_COMPARE - Fatal error!\\n' );\n fprintf ( 1, ' Column index J = %d < 1.\\n', j );\n error ( 'I4COL_COMPARE - Fatal error!' );\n end\n\n if ( n < j )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'I4COL_COMPARE - Fatal error!\\n' );\n fprintf ( 1, ' N = %d < column index J = %d.\\n', n, j );\n error ( 'I4COL_COMPARE - Fatal error!' );\n end\n\n isgn = 0;\n\n if ( i == j )\n return\n end\n\n k = 1;\n\n while ( k <= m )\n\n if ( a(k,i) < a(k,j) )\n isgn = -1;\n return\n elseif ( a(k,j) < a(k,i) )\n isgn = +1;\n return\n end\n\n k = k + 1;\n\n end\n\n return\nend\nfunction a = i4col_sort_a ( m, n, a )\n\n%*****************************************************************************80\n%\n%% I4COL_SORT_A ascending sorts an I4COL.\n%\n% Discussion:\n%\n% In lexicographic order, the statement \"X < Y\", applied to two real\n% vectors X and Y of length M, means that there is some index I, with\n% 1 <= I <= M, with the property that\n%\n% X(J) = Y(J) for J < I,\n% and\n% X(I) < Y(I).\n%\n% In other words, the first time they differ, X is smaller.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 20 February 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer M, the number of rows of A, and the length of\n% a vector of data.\n%\n% Input, integer N, the number of columns of A.\n%\n% Input, integer A(M,N), the array of N columns of M-vectors.\n%\n% Output, integer A(M,N), the columns of A have been sorted in ascending\n% lexicographic order.\n%\n if ( m <= 0 )\n return\n end\n\n if ( n <= 1 )\n return\n end\n%\n% Initialize.\n%\n i = 0;\n indx = 0;\n isgn = 0;\n j = 0;\n%\n% Call the external heap sorter.\n%\n while ( 1 )\n\n [ indx, i, j ] = sort_heap_external ( n, indx, isgn );\n%\n% Interchange the I and J objects.\n%\n if ( 0 < indx )\n\n a = i4col_swap ( m, n, a, i, j );\n%\n% Compare the I and J objects.\n%\n elseif ( indx < 0 )\n\n isgn = i4col_compare ( m, n, a, i, j );\n\n elseif ( indx == 0 )\n\n break\n\n end\n\n end\n\n return\nend\nfunction a = i4col_swap ( m, n, a, i, j )\n\n%*****************************************************************************80\n%\n%% I4COL_SWAP swaps columns I and J of a integer array of column data.\n%\n% Example:\n%\n% Input:\n%\n% M = 3, N = 4, I = 2, J = 4\n%\n% A = (\n% 1 2 3 4\n% 5 6 7 8\n% 9 10 11 12 )\n%\n% Output:\n%\n% A = (\n% 1 4 3 2\n% 5 8 7 6\n% 9 12 11 10 )\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 19 February 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer M, N, the number of rows and columns in the array.\n%\n% Input, integer A(M,N), an array of N columns of length M.\n%\n% Input, integer I, J, the columns to be swapped.\n%\n% Output, integer A(M,N), the array, with columns I and J swapped.\n%\n if ( i < 1 | n < i | j < 1 | n < j )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'I4COL_SWAP - Fatal error!\\n' );\n fprintf ( 1, ' I or J is out of bounds.\\n' );\n fprintf ( 1, ' I = %d\\n', i );\n fprintf ( 1, ' J = %d\\n', j );\n fprintf ( 1, ' N = %d\\n', n );\n error ( 'I4COL_SWAP - Fatal error!' );\n end\n\n if ( i == j )\n return\n end\n\n col(1:m) = a(1:m,i)';\n a(1:m,i) = a(1:m,j);\n a(1:m,j) = col(1:m)';\n\n return\nend\nfunction i4mat_transpose_print_some ( m, n, a, ilo, jlo, ihi, jhi, title )\n\n%*****************************************************************************80\n%\n%% I4MAT_TRANSPOSE_PRINT_SOME prints some of an I4MAT, transposed.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 21 June 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer M, N, the number of rows and columns.\n%\n% Input, integer A(M,N), an M by N matrix to be printed.\n%\n% Input, integer ILO, JLO, the first row and column to print.\n%\n% Input, integer IHI, JHI, the last row and column to print.\n%\n% Input, string TITLE, a title.\n%\n incx = 10;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, '%s\\n', title );\n\n for i2lo = max ( ilo, 1 ) : incx : min ( ihi, m )\n\n i2hi = i2lo + incx - 1;\n i2hi = min ( i2hi, m );\n i2hi = min ( i2hi, ihi );\n\n inc = i2hi + 1 - i2lo;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Row: ' );\n for i = i2lo : i2hi\n fprintf ( 1, '%7d ', i );\n end\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Col\\n' );\n fprintf ( 1, '\\n' );\n\n j2lo = max ( jlo, 1 );\n j2hi = min ( jhi, n );\n\n for j = j2lo : j2hi\n\n fprintf ( 1, '%5d ', j );\n for i2 = 1 : inc\n i = i2lo - 1 + i2;\n fprintf ( 1, '%7d ', a(i,j) );\n end\n fprintf ( 1, '\\n' );\n\n end\n\n end\n\n return\nend\nfunction [ quad_w, quad_xy ] = quad_rule ( quad_num )\n\n%*****************************************************************************80\n%\n%% QUAD_RULE sets the quadrature rule for assembly.\n%\n% Discussion:\n%\n% The quadrature rule is given for a reference element, points (X,Y) such\n% that\n%\n% 0 <= X,\n% 0 <= Y, and\n% X + Y <= 1.\n%\n% ^\n% 1 | *\n% | |\\\n% Y | | \\\n% | | \\\n% 0 | *---*\n% +------->\n% 0 X 1\n%\n% The rules have the following precision:\n%\n% QUAD_NUM Precision\n%\n% 1 1\n% 3 2\n% 4 3\n% 6 4\n% 7 5\n% 9 6\n% 13 7\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 14 February 2003\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer QUAD_NUM, the number of quadrature nodes.\n% Legal values are 1, 3, 4, 6, 7, 9, 13.\n%\n% Output, real QUAD_W(QUAD_NUM,1), the quadrature weights.\n%\n% Output, real QUAD_XY(2,QUAD_NUM), the quadrature nodes.\n%\n if ( quad_num == 1 )\n\n quad_xy(1:2,1:quad_num) = [ 1.0 / 3.0, 1.0 / 3.0 ]';\n\n quad_w(1:quad_num,1) = 1.0;\n\n elseif ( quad_num == 3 )\n\n quad_xy(1:2,1:quad_num) = [ ...\n 0.5, 0.0; ...\n 0.5, 0.5; ...\n 0.0, 0.5 ]';\n\n quad_w(1:quad_num,1) = 1.0 / 3.0;\n\n elseif ( quad_num == 4 )\n\n a = 6.0;\n b = 10.0;\n c = 18.0;\n d = 25.0;\n e = -27.0;\n f = 30.0;\n g = 48.0;\n\n quad_xy(1:2,1:quad_num) = [ ...\n b, b; ...\n c, a; ...\n a, c; ...\n a, a ]' / f;\n\n quad_w(1:quad_num,1) = [ e, d, d, d ]' / g;\n\n elseif ( quad_num == 6 )\n\n a = 0.816847572980459;\n b = 0.091576213509771;\n c = 0.108103018168070;\n d = 0.445948490915965;\n v = 0.109951743655322;\n w = 0.223381589678011;\n\n quad_xy(1:2,1:quad_num) = [\n a, b; ...\n b, a; ...\n b, b; ...\n c, d; ...\n d, c; ...\n d, d ]';\n\n quad_w(1:6,1) = [ v, v, v, w, w, w ]';\n\n elseif ( quad_num == 7 )\n\n a = 1.0 / 3.0;\n b = ( 9.0 + 2.0 * sqrt ( 15.0 ) ) / 21.0;\n c = ( 6.0 - sqrt ( 15.0 ) ) / 21.0;\n d = ( 9.0 - 2.0 * sqrt ( 15.0 ) ) / 21.0;\n e = ( 6.0 + sqrt ( 15.0 ) ) / 21.0;\n u = 0.225;\n v = ( 155.0 - sqrt ( 15.0 ) ) / 1200.0;\n w = ( 155.0 + sqrt ( 15.0 ) ) / 1200.0;\n\n quad_xy(1:2,1:quad_num) = [ ...\n a, a; ...\n b, c; ...\n c, b; ...\n c, c; ...\n d, e; ...\n e, d; ...\n e, e ]';\n\n quad_w(1:quad_num,1) = [ u, v, v, v, w, w, w ]';\n\n elseif ( quad_num == 9 )\n\n a = 0.124949503233232;\n b = 0.437525248383384;\n c = 0.797112651860071;\n d = 0.165409927389841;\n e = 0.037477420750088;\n\n u = 0.205950504760887;\n v = 0.063691414286223;\n\n quad_xy(1:2,1:quad_num) = [ ...\n a, b; ...\n b, a; ...\n b, b; ...\n c, d; ...\n c, e; ...\n d, c; ...\n d, e; ...\n e, c; ...\n e, d ]';\n\n quad_w(1:quad_num,1) = [ u, u, u, v, v, v, v, v, v ]';\n\n elseif ( quad_num == 13 )\n\n h = 1.0 / 3.0;\n a = 0.479308067841923;\n b = 0.260345966079038;\n c = 0.869739794195568;\n d = 0.065130102902216;\n e = 0.638444188569809;\n f = 0.312865496004875;\n g = 0.048690315425316;\n\n w = -0.149570044467670;\n t = 0.175615257433204;\n u = 0.053347235608839;\n v = 0.077113760890257;\n\n quad_xy(1:2,1:quad_num) = [\n h, h; ...\n a, b; ...\n b, a; ...\n b, b; ...\n c, d; ...\n d, c; ...\n d, d; ...\n e, f; ...\n e, g; ...\n f, e; ...\n f, g; ...\n g, e; ...\n g, f ]';\n\n quad_w(1:quad_num,1) = [ w, t, t, t, u, u, u, v, v, v, v, v, v ]';\n\n else\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'QUAD_RULE - Fatal error!\\n' );\n fprintf ( 1, ' No rule is available of order QUAD_NUM = %d\\n', ...\n quad_num );\n error ( 'QUAD_RULE - Fatal error!\\n' );\n\n end\n\n return\nend\nfunction r8mat_print_some ( m, n, a, ilo, jlo, ihi, jhi, title )\n\n%*****************************************************************************80\n%\n%% R8MAT_PRINT_SOME prints out a portion of an R8MAT.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 08 April 2009\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer M, N, the number of rows and columns of the matrix.\n%\n% Input, real A(M,N), an M by N matrix to be printed.\n%\n% Input, integer ILO, JLO, the first row and column to print.\n%\n% Input, integer IHI, JHI, the last row and column to print.\n%\n% Input, string TITLE, a title.\n%\n incx = 5;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, '%s\\n', title );\n\n for j2lo = max ( jlo, 1 ): incx : min ( jhi, n )\n\n j2hi = j2lo + incx - 1;\n j2hi = min ( j2hi, n );\n j2hi = min ( j2hi, jhi );\n\n inc = j2hi + 1 - j2lo;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Col: ' );\n\n for j = j2lo : j2hi\n fprintf ( 1, '%7d ', j );\n end\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Row\\n' );\n\n i2lo = max ( ilo, 1 );\n i2hi = min ( ihi, m );\n\n for i = i2lo : i2hi\n\n fprintf ( 1, '%7d ', i );\n\n for j = j2lo : j2hi\n fprintf ( 1, '%12g ', a(i,j) );\n end\n\n fprintf ( 1, '\\n' );\n\n end\n\n end\n\n return\nend\nfunction r8mat_transpose_print_some ( m, n, a, ilo, jlo, ihi, jhi, title )\n\n%*****************************************************************************80\n%\n%% R8MAT_TRANSPOSE_PRINT_SOME prints some of an R8MAT, transposed.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 23 May 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer M, N, the number of rows and columns.\n%\n% Input, real A(M,N), an M by N matrix to be printed.\n%\n% Input, integer ILO, JLO, the first row and column to print.\n%\n% Input, integer IHI, JHI, the last row and column to print.\n%\n% Input, string TITLE, a title.\n%\n incx = 5;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, '%s\\n', title );\n\n for i2lo = max ( ilo, 1 ) : incx : min ( ihi, m )\n\n i2hi = i2lo + incx - 1;\n i2hi = min ( i2hi, m );\n i2hi = min ( i2hi, ihi );\n\n inc = i2hi + 1 - i2lo;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Row: ' );\n for i = i2lo : i2hi\n fprintf ( 1, '%7d ', i );\n end\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Col\\n' );\n\n j2lo = max ( jlo, 1 );\n j2hi = min ( jhi, n );\n\n for j = j2lo : j2hi\n\n fprintf ( 1, '%5d ', j );\n for i2 = 1 : inc\n i = i2lo - 1 + i2;\n fprintf ( 1, '%12f', a(i,j) );\n end\n fprintf ( 1, '\\n' );\n\n end\n\n end\n\n return\nend\nfunction r8vec_print_some ( n, a, i_lo, i_hi, title )\n\n%*****************************************************************************80\n%\n%% R8VEC_PRINT_SOME prints \"some\" of an R8VEC.\n%\n% Discussion:\n%\n% An R8VEC is a vector of R8 values.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 16 October 2006\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the dimension of the vector.\n%\n% Input, real A(N), the vector to be printed.\n%\n% Input, integer MAX_PRINT, the maximum number of lines to print.\n%\n% Input, string TITLE, a title.\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, '%s\\n', title );\n fprintf ( 1, '\\n' );\n\n for i = max ( 1, i_lo ) : min ( n, i_hi )\n fprintf ( 1, ' %8d %12f\\n', i, a(i) );\n end\n\n return\nend\nfunction phy = reference_to_physical_t3 ( t, n, ref )\n\n%*****************************************************************************80\n%\n%% REFERENCE_TO_PHYSICAL_T3 maps a reference point to a physical point.\n%\n% Discussion:\n%\n% Given the vertices of an order 3 physical triangle and a point\n% (XSI,ETA) in the reference triangle, the routine computes the value\n% of the corresponding image point (X,Y) in physical space.\n%\n% Note that this routine may also be appropriate for an order 6\n% triangle, if the mapping between reference and physical space\n% is linear. This implies, in particular, that the sides of the\n% image triangle are straight and that the \"midside\" nodes in the\n% physical triangle are literally halfway along the sides of\n% the physical triangle.\n%\n% Reference Element T3:\n%\n% |\n% 1 3\n% | |\\\n% | | \\\n% S | \\\n% | | \\\n% | | \\\n% 0 1-----2\n% |\n% +--0--R--1-->\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 14 February 2003\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real T(2,3), the coordinates of the vertices. The vertices are assumed\n% to be the images of (0,0), (1,0) and (0,1) respectively.\n%\n% Input, integer N, the number of objects to transform.\n%\n% Input, real REF(2,N), the coordinates of points in the reference space.\n%\n% Output, real PHY(2,N), the coordinates of the corresponding points in the\n% physical space.\n%\n for i = 1 : 2\n\n phy(i,1:n) = t(i,1) * ( 1.0 - ref(1,1:n) - ref(2,1:n) ) ...\n + t(i,2) * ref(1,1:n) ...\n + t(i,3) * ref(2,1:n);\n end\n\n return\nend\nfunction node_r = residual_poisson ( node_num, node_xy, node_condition, ...\n element_num, element_node, quad_num, a, f, node_u )\n\n%*****************************************************************************80\n%\n%% RESIDUAL_POISSON evaluates the residual for the Poisson equation.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 15 July 2010\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer NODE_NUM, the number of nodes.\n%\n% Input, real NODE_XY(2,NODE_NUM), the\n% coordinates of nodes.\n%\n% Input, integer NODE_CONDITION(NODE_NUM), reports the condition\n% used to set the unknown associated with the node.\n% 0, unknown.\n% 1, finite element equation.\n% 2, Dirichlet condition;\n% 3, Neumann condition.\n%\n% Input, integer ELEMENT_NUM, the number of elements.\n%\n% Input, integer ELEMENT_NODE(3,ELEMENT_NUM);\n% ELEMENT_NODE(I,J) is the global index of local node I in element J.\n%\n% Input, integer QUAD_NUM, the number of quadrature points used in assembly.\n%\n% Input, integer INDX(NODE_NUM), gives the index of the unknown quantity\n% associated with the given node.\n%\n% Workspace, real sparse A(:,:), the NODE_NUM by NODE_NUM\n% coefficient matrix, stored in MATLAB sparse format.\n%\n% Workspace, real F(NODE_NUM,1), the right hand side.\n%\n% Input, real NODE_U(NODE_NUM), the value of the solution\n% at each node.\n%\n% Output, real NODE_R(NODE_NUM), the finite element\n% residual at each node.\n%\n% Local parameters:\n%\n% Local, real BI, DBIDX, DBIDY, the value of some basis function\n% and its first derivatives at a quadrature point.\n%\n% Local, real BJ, DBJDX, DBJDY, the value of another basis\n% function and its first derivatives at a quadrature point.\n%\n\n%\n% Initialize the arrays to zero.\n%\n f(1:node_num,1) = 0.0;\n a(:,:) = 0.0;\n%\n% Get the quadrature weights and nodes.\n%\n [ quad_w, quad_xy ] = quad_rule ( quad_num );\n%\n% The actual values of A and F are determined by summing up\n% contributions from all the elements.\n%\n for element = 1 : element_num\n%\n% Make a copy of the element.\n%\n t3(1:2,1:3) = node_xy(1:2,element_node(1:3,element));\n%\n% Map the quadrature points QUAD_XY to points PHYS_XY in the physical element.\n%\n phys_xy(1:2,1:quad_num) = reference_to_physical_t3 ( t3, quad_num, quad_xy );\n area = abs ( triangle_area_2d ( t3 ) );\n w(1:quad_num) = area * quad_w(1:quad_num);\n\n phys_rhs = rhs ( quad_num, phys_xy );\n phys_h = h_coef ( quad_num, phys_xy );\n phys_k = k_coef ( quad_num, phys_xy );\n%\n% Consider a quadrature point QUAD, with coordinates (X,Y).\n%\n for quad = 1 : quad_num\n%\n% Consider one of the basis functions, which will play the\n% role of test function in the integral.\n%\n% We generate an integral for every node associated with an unknown.\n% But if a node is associated with a boundary condition, we do nothing.\n%\n for test = 1 : 3\n\n i = element_node(test,element);\n\n [ bi, dbidx, dbidy ] = basis_11_t3 ( t3, test, phys_xy(1:2,quad) );\n\n f(i,1) = f(i,1) + w(quad) * phys_rhs(quad) * bi;\n%\n% Consider another basis function, which is used to form the\n% value of the solution function.\n%\n for basis = 1 : 3\n\n j = element_node(basis,element);\n\n [ bj, dbjdx, dbjdy ] = basis_11_t3 ( t3, basis, phys_xy(1:2,quad) );\n\n a(i,j) = a(i,j) + w(quad) * ( ...\n phys_h(quad) * ( dbidx * dbjdx + dbidy * dbjdy ) ...\n + phys_k(quad) * bj * bi );\n\n end\n\n end\n\n end\n\n end\n%\n% Apply boundary conditions.\n%\n [ a, f ] = dirichlet_apply_sparse ( node_num, node_xy, node_condition, a, f );\n%\n% Compute A*U.\n%\n node_r = a * node_u;\n%\n% Set RES = A * U - F.\n%\n node_r(1:node_num) = node_r(1:node_num) - f(1:node_num,1);\n\n return\nend\nfunction [ indx, i, j ] = sort_heap_external ( n, indx, isgn )\n\n%*****************************************************************************80\n%\n%% SORT_HEAP_EXTERNAL externally sorts a list of items into ascending order.\n%\n% Discussion:\n%\n% The actual list of data is not passed to the routine. Hence this\n% routine may be used to sort integers, reals, numbers, names,\n% dates, shoe sizes, and so on. After each call, the routine asks\n% the user to compare or interchange two items, until a special\n% return value signals that the sorting is completed.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 12 February 2010\n%\n% Author:\n%\n% Original FORTRAN77 version by Albert Nijenhuis, Herbert Wilf.\n% MATLAB version by John Burkardt.\n%\n% Reference:\n%\n% Albert Nijenhuis, Herbert Wilf.\n% Combinatorial Algorithms,\n% Academic Press, 1978, second edition,\n% ISBN 0-12-519260-6.\n%\n% Parameters:\n%\n% Input, integer N, the number of items to be sorted.\n%\n% Input, integer INDX, the main communication signal.\n% The user must set INDX to 0 before the first call.\n% Thereafter, the user should set the input value of INDX\n% to the output value from the previous call.\n%\n% Input, integer ISGN, results of comparison of elements I and J.\n% (Used only when the previous call returned INDX less than 0).\n% ISGN <= 0 means I is less than or equal to J;\n% 0 <= ISGN means I is greater than or equal to J.\n%\n% Output, integer INDX, the main communication signal.\n% If INDX is\n%\n% greater than 0, the user should:\n% * interchange items I and J;\n% * call again.\n%\n% less than 0, the user should:\n% * compare items I and J;\n% * set ISGN = -1 if I < J, ISGN = +1 if J < I;\n% * call again.\n%\n% equal to 0, the sorting is done.\n%\n% Output, integer I, J, the indices of two items.\n% On return with INDX positive, elements I and J should be interchanged.\n% On return with INDX negative, elements I and J should be compared, and\n% the result reported in ISGN on the next call.\n%\n persistent i_save;\n persistent j_save;\n persistent k;\n persistent k1;\n persistent n1;\n\n if ( isempty ( i_save ) )\n i_save = -1;\n end\n\n if ( isempty ( j_save ) )\n j_save = -1;\n end\n%\n% INDX = 0: This is the first call.\n%\n if ( indx == 0 )\n\n k = floor ( n / 2 );\n k1 = k;\n n1 = n;\n%\n% INDX < 0: The user is returning the results of a comparison.\n%\n elseif ( indx < 0 )\n\n if ( indx == -2 )\n\n if ( isgn < 0 )\n i_save = i_save + 1;\n end\n\n j_save = k1;\n k1 = i_save;\n indx = -1;\n i = i_save;\n j = j_save;\n return;\n end\n\n if ( 0 < isgn )\n indx = 2;\n i = i_save;\n j = j_save;\n return;\n end\n\n if ( k <= 1 )\n\n if ( n1 == 1 )\n i_save = 0;\n j_save = 0;\n indx = 0;\n else\n i_save = n1;\n n1 = n1 - 1;\n j_save = 1;\n indx = 1;\n end\n\n i = i_save;\n j = j_save;\n return;\n\n end\n\n k = k - 1;\n k1 = k;\n%\n% 0 < INDX, the user was asked to make an interchange.\n%\n elseif ( indx == 1 )\n\n k1 = k;\n\n end\n\n while ( 1 )\n\n i_save = 2 * k1;\n\n if ( i_save == n1 )\n j_save = k1;\n k1 = i_save;\n indx = -1;\n i = i_save;\n j = j_save;\n return;\n elseif ( i_save <= n1 )\n j_save = i_save + 1;\n indx = -2;\n i = i_save;\n j = j_save;\n return;\n end\n\n if ( k <= 1 )\n break;\n end\n\n k = k - 1;\n k1 = k;\n\n end\n\n if ( n1 == 1 )\n i_save = 0;\n j_save = 0;\n indx = 0;\n i = i_save;\n j = j_save;\n else\n i_save = n1;\n n1 = n1 - 1;\n j_save = 1;\n indx = 1;\n i = i_save;\n j = j_save;\n end\n\n return\nend\nfunction timestamp ( )\n\n%*****************************************************************************80\n%\n%% TIMESTAMP prints the current YMDHMS date as a timestamp.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 14 February 2003\n%\n% Author:\n%\n% John Burkardt\n%\n t = now;\n c = datevec ( t );\n s = datestr ( c, 0 );\n fprintf ( 1, '%s\\n', s );\n\n return\nend\nfunction area = triangle_area_2d ( t )\n\n%*****************************************************************************80\n%\n%% TRIANGLE_AREA_2D computes the area of a triangle in 2D.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 14 February 2003\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real T(2,3), the triangle vertices.\n%\n% Output, real AREA, the absolute area of the triangle.\n%\n area = 0.5 * abs ( ...\n t(1,1) * ( t(2,2) - t(2,3) ) ...\n + t(1,2) * ( t(2,3) - t(2,1) ) ...\n + t(1,3) * ( t(2,1) - t(2,2) ) );\n\n return\nend\nfunction triangle_neighbor = triangulation_neighbor_triangles ( ...\n triangle_order, triangle_num, triangle_node )\n\n%*****************************************************************************80\n%\n%% TRIANGULATION_NEIGHBOR_TRIANGLES determines triangle neighbors.\n%\n% Discussion:\n%\n% A triangulation of a set of nodes can be completely described by\n% the coordinates of the nodes, and the list of nodes that make up\n% each triangle. However, in some cases, it is necessary to know\n% triangle adjacency information, that is, which triangle, if any,\n% is adjacent to a given triangle on a particular side.\n%\n% This routine creates a data structure recording this information.\n%\n% The primary amount of work occurs in sorting a list of 3 * TRIANGLE_NUM\n% data items.\n%\n% This routine was modified to use columns instead of rows.\n%\n% Example:\n%\n% The input information from TRIANGLE_NODE:\n%\n% Triangle Nodes\n% -------- ---------------\n% 1 3 4 1\n% 2 3 1 2\n% 3 3 2 8\n% 4 2 1 5\n% 5 8 2 13\n% 6 8 13 9\n% 7 3 8 9\n% 8 13 2 5\n% 9 9 13 7\n% 10 7 13 5\n% 11 6 7 5\n% 12 9 7 6\n% 13 10 9 6\n% 14 6 5 12\n% 15 11 6 12\n% 16 10 6 11\n%\n% The output information in TRIANGLE_NEIGHBOR:\n%\n% Triangle Neighboring Triangles\n% -------- ---------------------\n%\n% 1 -1 -1 2\n% 2 1 4 3\n% 3 2 5 7\n% 4 2 -1 8\n% 5 3 8 6\n% 6 5 9 7\n% 7 3 6 -1\n% 8 5 4 10\n% 9 6 10 12\n% 10 9 8 11\n% 11 12 10 14\n% 12 9 11 13\n% 13 -1 12 16\n% 14 11 -1 15\n% 15 16 14 -1\n% 16 13 15 -1\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 07 September 2009\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer TRIANGLE_ORDER, the order of the triangles.\n%\n% Input, integer TRIANGLE_NUM, the number of triangles.\n%\n% Input, integer TRIANGLE_NODE(TRIANGLE_ORDER,TRIANGLE_NUM), the nodes that\n% make up each triangle.\n%\n% Output, integer TRIANGLE_NEIGHBOR(3,TRIANGLE_NUM), the three triangles\n% that are direct neighbors of a given triangle. TRIANGLE_NEIGHBOR(1,I) is\n% the index of the triangle which touches side 1, defined by nodes 2 and 3,\n% and so on. TRIANGLE_NEIGHBOR(1,I) is negative if there is no neighbor\n% on that side. In this case, that side of the triangle lies on the\n% boundary of the triangulation.\n%\n\n%\n% Step 1.\n% From the list of nodes for triangle T, of the form: (I,J,K)\n% construct the three neighbor relations:\n%\n% (I,J,3,T) or (J,I,3,T),\n% (J,K,1,T) or (K,J,1,T),\n% (K,I,2,T) or (I,K,2,T)\n%\n% where we choose (I,J,3,T) if I < J, or else (J,I,3,T)\n%\n col = zeros ( 4, triangle_order * triangle_num );\n\n for tri = 1 : triangle_num\n\n i = triangle_node(1,tri);\n j = triangle_node(2,tri);\n k = triangle_node(3,tri);\n\n if ( i < j )\n col(1:4,1+3*(tri-1)) = [ i, j, 3, tri ]';\n else\n col(1:4,1+3*(tri-1)) = [ j, i, 3, tri ]';\n end\n\n if ( j < k )\n col(1:4,2+3*(tri-1)) = [ j, k, 1, tri ]';\n else\n col(1:4,2+3*(tri-1)) = [ k, j, 1, tri ]';\n end\n\n if ( k < i )\n col(1:4,3+3*(tri-1)) = [ k, i, 2, tri ]';\n else\n col(1:4,3+3*(tri-1)) = [ i, k, 2, tri ]';\n end\n\n end\n%\n% Step 2. Perform an ascending dictionary sort on the neighbor relations.\n% We only intend to sort on rows 1 and 2; the routine we call here\n% sorts on rows 1 through 4 but that won't hurt us.\n%\n% What we need is to find cases where two triangles share an edge.\n% Say they share an edge defined by the nodes I and J. Then there are\n% two columns of COL that start out ( I, J, ?, ? ). By sorting COL,\n% we make sure that these two columns occur consecutively. That will\n% make it easy to notice that the triangles are neighbors.\n%\n col = i4col_sort_a ( 4, 3*triangle_num, col );\n%\n% Step 3. Neighboring triangles show up as consecutive columns with\n% identical first two entries. Whenever you spot this happening,\n% make the appropriate entries in TRIANGLE_NEIGHBOR.\n%\n triangle_neighbor(1:3,1:triangle_num) = -1;\n\n icol = 1;\n\n while ( 1 )\n\n if ( 3 * triangle_num <= icol )\n break\n end\n\n if ( col(1,icol) ~= col(1,icol+1) || col(2,icol) ~= col(2,icol+1) )\n icol = icol + 1;\n continue\n end\n\n side1 = col(3,icol);\n tri1 = col(4,icol);\n side2 = col(3,icol+1);\n tri2 = col(4,icol+1);\n\n triangle_neighbor(side1,tri1) = tri2;\n triangle_neighbor(side2,tri2) = tri1;\n\n icol = icol + 2;\n\n end\n\n return\nend\nfunction [ adj_num, adj_col ] = triangulation_order3_adj_count ( node_num, ...\n tri_num, triangle_node, triangle_neighbor )\n\n%*****************************************************************************80\n%\n%% TRIANGULATION_ORDER3_ADJ_COUNT counts adjacencies in a triangulation.\n%\n% Discussion:\n%\n% This routine is called to count the adjacencies, so that the\n% appropriate amount of memory can be set aside for storage when\n% the adjacency structure is created.\n%\n% The triangulation is assumed to involve 3-node triangles.\n%\n% Two nodes are \"adjacent\" if they are both nodes in some triangle.\n% Also, a node is considered to be adjacent to itself.\n%\n% Diagram:\n%\n% 3\n% s |\\\n% i | \\\n% d | \\\n% e | \\ side 2\n% | \\\n% 3 | \\\n% | \\\n% 1-------2\n%\n% side 1\n%\n% The local node numbering\n%\n%\n% 21-22-23-24-25\n% |\\ |\\ |\\ |\\ |\n% | \\| \\| \\| \\|\n% 16-17-18-19-20\n% |\\ |\\ |\\ |\\ |\n% | \\| \\| \\| \\|\n% 11-12-13-14-15\n% |\\ |\\ |\\ |\\ |\n% | \\| \\| \\| \\|\n% 6--7--8--9-10\n% |\\ |\\ |\\ |\\ |\n% | \\| \\| \\| \\|\n% 1--2--3--4--5\n%\n% A sample grid.\n%\n%\n% Below, we have a chart that summarizes the adjacency relationships\n% in the sample grid. On the left, we list the node, and its neighbors,\n% with an asterisk to indicate the adjacency of the node to itself\n% (in some cases, you want to count this self adjacency and in some\n% you don't). On the right, we list the number of adjancencies to\n% lower-indexed nodes, to the node itself, to higher-indexed nodes,\n% the total number of adjacencies for this node, and the location\n% of the first and last entries required to list this set of adjacencies\n% in a single list of all the adjacencies.\n%\n% N Adjacencies Below Self Above Total First Last\n%\n% -- -- -- -- -- -- -- -- -- -- -- -- --- 0\n% 1: * 2 6 0 1 2 3 1 3\n% 2: 1 * 3 6 7 1 1 3 5 4 8\n% 3: 2 * 4 7 8 1 1 3 5 9 13\n% 4: 3 * 5 8 9 1 1 3 5 14 18\n% 5: 4 * 9 10 1 1 2 4 19 22\n% 6: 1 2 * 7 11 2 1 2 5 23 27\n% 7: 2 3 6 * 8 11 12 3 1 3 7 28 34\n% 8: 3 4 7 * 9 12 13 3 1 3 7 35 41\n% 9: 4 5 8 * 10 13 14 3 1 3 7 42 48\n% 10: 5 9 * 14 15 2 1 2 5 49 53\n% 11: 6 7 * 12 16 2 1 2 5 54 58\n% 12: 7 8 11 * 13 16 17 3 1 3 7 59 65\n% 13: 8 9 12 * 14 17 18 3 1 3 7 66 72\n% 14: 9 10 13 * 15 18 19 3 1 3 7 73 79\n% 15: 10 14 * 19 20 2 1 2 5 80 84\n% 16: 11 12 * 17 21 2 1 2 5 85 89\n% 17: 12 13 16 * 18 21 22 3 1 3 7 90 96\n% 18: 13 14 17 * 19 22 23 3 1 3 7 97 103\n% 19: 14 15 18 * 20 23 24 3 1 3 7 104 110\n% 20: 15 19 * 24 25 2 1 2 5 111 115\n% 21: 16 17 * 22 2 1 1 4 116 119\n% 22: 17 18 21 * 23 3 1 1 5 120 124\n% 23: 18 19 22 * 24 3 1 1 5 125 129\n% 24: 19 20 23 * 25 3 1 1 5 130 134\n% 25: 20 24 * 2 1 0 3 135 137\n% -- -- -- -- -- -- -- -- -- -- -- -- 138 ---\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 14 February 2003\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters\n%\n% Input, integer NODE_NUM, the number of nodes.\n%\n% Input, integer TRI_NUM, the number of triangles.\n%\n% Input, integer TRIANGLE_NODE(3,TRI_NUM), lists the nodes that\n% make up each triangle, in counterclockwise order.\n%\n% Input, integer TRIANGLE_NEIGHBOR(3,TRI_NUM), for each side of\n% a triangle, lists the neighboring triangle, or -1 if there is\n% no neighbor.\n%\n% Output, integer ADJ_NUM, the number of adjacencies.\n%\n% Output, integer ADJ_COL(NODE_NUM+1). Information about column J is stored\n% in entries ADJ_COL(J) through ADJ_COL(J+1)-1 of ADJ.\n%\n triangle_order = 3;\n adj_num = 0;\n%\n% Set every node to be adjacent to itself.\n%\n adj_col(1:node_num) = 1;\n%\n% Examine each triangle.\n%\n for triangle = 1 : tri_num\n\n n1 = triangle_node(1,triangle);\n n2 = triangle_node(2,triangle);\n n3 = triangle_node(3,triangle);\n%\n% Add edge (1,2) if this is the first occurrence,\n% that is, if the edge (1,2) is on a boundary (TRIANGLE2 <= 0)\n% or if this triangle is the first of the pair in which the edge\n% occurs (TRIANGLE < TRIANGLE2).\n%\n triangle2 = triangle_neighbor(1,triangle);\n\n if ( triangle2 < 0 | triangle < triangle2 )\n adj_col(n1) = adj_col(n1) + 1;\n adj_col(n2) = adj_col(n2) + 1;\n end\n%\n% Add edge (2,3).\n%\n triangle2 = triangle_neighbor(2,triangle);\n\n if ( triangle2 < 0 | triangle < triangle2 )\n adj_col(n2) = adj_col(n2) + 1;\n adj_col(n3) = adj_col(n3) + 1;\n end\n%\n% Add edge (3,1).\n%\n triangle2 = triangle_neighbor(3,triangle);\n\n if ( triangle2 < 0 | triangle < triangle2 )\n adj_col(n1) = adj_col(n1) + 1;\n adj_col(n3) = adj_col(n3) + 1;\n end\n\n end\n%\n% We used ADJ_COL to count the number of entries in each column.\n% Convert it to pointers into the ADJ array.\n%\n adj_col(2:node_num+1) = adj_col(1:node_num);\n\n adj_col(1) = 1;\n for i = 2 : node_num+1\n adj_col(i) = adj_col(i-1) + adj_col(i);\n end\n\n adj_num = adj_col(node_num+1) - 1;\n\n return\nend\nfunction node_boundary = triangulation_order3_boundary_node ( node_num, ...\n triangle_num, triangle_node )\n\n%*****************************************************************************80\n%\n%% TRIANGULATION_ORDER3_BOUNDARY_NODE indicates which nodes are on the boundary.\n%\n% Discussion:\n%\n% This routine is given a triangulation, an abstract list of sets of\n% of nodes. It is assumed that the nodes in each triangle are listed\n% in a counterclockwise order, although the routine should work\n% if the nodes are consistently listed in a clockwise order as well.\n%\n% It is assumed that each edge of the triangulation is either\n% * an INTERIOR edge, which is listed twice, once with positive\n% orientation and once with negative orientation, or;\n% * a BOUNDARY edge, which will occur only once.\n%\n% This routine should work even if the region has holes - as long\n% as the boundary of the hole comprises more than 3 edges!\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 14 February 2003\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer NODE_NUM, the number of nodes.\n%\n% Input, integer TRIANGLE_NUM, the number of triangles.\n%\n% Input, integer TRIANGLE_NODE(3,TRIANGLE_NUM),\n% the nodes that make up the triangles. These should be listed\n% in counterclockwise order.\n%\n% Output, logical NODE_BOUNDARY(NODE_NUM), is TRUE if the node\n% is on a boundary edge.\n%\n m = 2;\n n = 3 * triangle_num;\n%\n% Set up the edge array.\n%\n edge(1:2, 1: triangle_num) = triangle_node(1:2,1:triangle_num);\n edge(1:2, triangle_num+1:2*triangle_num) = triangle_node(2:3,1:triangle_num);\n edge(1, 2*triangle_num+1:3*triangle_num) = triangle_node(3, 1:triangle_num);\n edge(2, 2*triangle_num+1:3*triangle_num) = triangle_node(1, 1:triangle_num);\n%\n% In each column, force the smaller entry to appear first.\n%\n e1(1:n) = min ( edge(1:2,1:n) );\n e2(1:n) = max ( edge(1:2,1:n) );\n\n edge(1,1:n) = e1(1:n);\n edge(2,1:n) = e2(1:n);\n%\n% Ascending sort the column array.\n%\n edge = i4col_sort_a ( m, n, edge );\n%\n% Records which appear twice are internal edges and can be ignored.\n%\n node_boundary(1:node_num) = 0;\n\n i = 0;\n\n while ( i < 3 * triangle_num )\n\n i = i + 1;\n\n if ( i == 3 * triangle_num )\n node_boundary(edge(1:m,i)) = 1;\n elseif ( all ( edge(1:m,i) == edge(1:m,i+1) ) )\n i = i + 1;\n else\n node_boundary(edge(1:m,i)) = 1;\n end\n\n end\n\n return\nend\n\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/fem2d_poisson_sparse/fem2d_poisson_sparse.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.916109606718245, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.7468423131479527}} {"text": "function geometry_test20701 ( )\n\n%*****************************************************************************80\n%\n%% TEST20701 tests TRIANGLE_INRADIUS_2D;\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 14 February 2003\n%\n% Author:\n%\n% John Burkardt\n%\n dim_num = 2;\n\n t = [ ...\n 0.0, 1.0; ...\n 0.0, 0.0; ...\n 1.0, 0.0 ]';\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TEST20701\\n' );\n fprintf ( 1, ' For a triangle in 2D,\\n' );\n fprintf ( 1, ' TRIANGLE_INRADIUS_2D computes the inradius.\\n' );\n\n r8mat_transpose_print ( dim_num, 3, t, ' Triangle vertices:' );\n\n r = triangle_inradius_2d ( t );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Incircle radius is %f\\n', r );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/geometry/geometry_test20701.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972616934408, "lm_q2_score": 0.8577681013541611, "lm_q1q2_score": 0.7467705602069145}} {"text": "%KSOBEL Sobel edge detector\n%\n% K = KSOBEL() is the Sobel x-derivative kernel:\n% 1/8 |1 0 -1|\n% |2 0 -2|\n% |1 0 -1|\n%\n% Notes::\n% - This kernel is an effective vertical-edge detector\n% - The y-derivative (horizontal-edge) kernel is K'\n%\n% See also ISOBEL.\n\n\n\n% Copyright (C) 1993-2011, by Peter I. Corke\n%\n% This file is part of The Machine Vision Toolbox for Matlab (MVTB).\n% \n% MVTB is free software: you can redistribute it and/or modify\n% it under the terms of the GNU Lesser General Public License as published by\n% the Free Software Foundation, either version 3 of the License, or\n% (at your option) any later version.\n% \n% MVTB is distributed in the hope that it will be useful,\n% but WITHOUT ANY WARRANTY; without even the implied warranty of\n% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n% GNU Lesser General Public License for more details.\n% \n% You should have received a copy of the GNU Leser General Public License\n% along with MVTB. If not, see .\n\nfunction k = ksobel\n\n k = [ 1 0 -1\n 2 0 -2\n 1 0 -1] / 8;\n", "meta": {"author": "petercorke", "repo": "machinevision-toolbox-matlab", "sha": "2d791168c19c5e56acef74d22eafd227b4b58e42", "save_path": "github-repos/MATLAB/petercorke-machinevision-toolbox-matlab", "path": "github-repos/MATLAB/petercorke-machinevision-toolbox-matlab/machinevision-toolbox-matlab-2d791168c19c5e56acef74d22eafd227b4b58e42/ksobel.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9241418241572634, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.7467687130458764}} {"text": "function Corr = tapas_Cov2Corr(Cov)\n% Converts a covariance matrix into a correlation matrix\n%\n% --------------------------------------------------------------------------------------------------\n% Copyright (C) 2013 Christoph Mathys, TNU, UZH & ETHZ\n%\n% This file is part of the HGF toolbox, which is released under the terms of the GNU General Public\n% Licence (GPL), version 3. You can redistribute it and/or modify it under the terms of the GPL\n% (either version 3 or, at your option, any later version). For further details, see the file\n% COPYING or .\n\n% Check if Cov is symmetric\nif any(any(Cov'~=Cov))\n error('tapas:hgf:Cov2Corr:MatNotSymm', 'Input matrix is not symmetric.');\nend\n\n% Check if Cov is positive semi-definite\nif any(isinf(Cov(:))) || any(isnan(Cov(:))) || any(eig(Cov)<0)\n error('tapas:hgf:Cov2Corr:MatNotPosDef', 'Input matrix is not positive semi-definite.');\nend\n\nsdev = sqrt(diag(Cov));\nNorm = sdev * sdev';\nCorr = Cov./Norm;\n\nreturn;\n", "meta": {"author": "translationalneuromodeling", "repo": "tapas", "sha": "604c56843c15411f5bd80190f81d845ac57d8592", "save_path": "github-repos/MATLAB/translationalneuromodeling-tapas", "path": "github-repos/MATLAB/translationalneuromodeling-tapas/tapas-604c56843c15411f5bd80190f81d845ac57d8592/HGF/tapas_Cov2Corr.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9241418199787564, "lm_q2_score": 0.8080672204860316, "lm_q1q2_score": 0.7467687118051364}} {"text": "function [Xrls,yrls,s]=RLSreg(y,X)\n%Syntax: [Xrls,yrls,s]=RLSreg(y,X)\n%_______________________________\n%\n% Calculates the Reweighted Least Squares (RLS) regression data points\n% and the scale parameter from the LMS regression.\n%\n% Xrls is the X values matrix to be taken into account for RLS.\n% yrls is the y values vector to be taken into account for RLS.\n% s is RLS scale parameter.\n% y is the vector of the dependent variable.\n% X is the data matrix of the independent variable.\n%\n% Reference:\n% Rousseeuw PJ, Leroy AM (1987): Robust regression and outlier detection. Wiley.\n%\n%\n% Alexandros Leontitsis\n% Institute of Mathematics and Statistics\n% University of Kent at Canterbury\n% Canterbury\n% Kent, CT2 7NF\n% U.K.\n%\n% University e-mail: al10@ukc.ac.uk (until December 2002)\n% Lifetime e-mail: leoaleq@yahoo.com\n% Homepage: http://www.geocities.com/CapeCanaveral/Lab/1421\n%\n% Sep 3, 2001.\n\nif nargin<1 | isempty(y)==1\n error('Not enough input arguments.');\nend\n\n% Estimate the LMS values\nif nargin<2 | isempty(X)==1\n LMSout=LMSreg(y);\n X=(1:length(y))';\nelse\n LMSout=LMSreg(y,X);\nend\n\n% p is the number of parameters to be estimated\np=size(X,2)+1;\n\n% Calculate the residuals\nr=y-LMSout;\n\n% Estimate the preliminary scale parameter\ns=LMSsca(r,0,p);\n\n% Take into account a data point, if its residual is relatively small\nw=find(abs(r/s)<=2.5);\nXrls=X(w,:);\nyrls=y(w);\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/801-lms-toolbox/RLSreg.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418241572634, "lm_q2_score": 0.808067204308405, "lm_q1q2_score": 0.7467687002312294}} {"text": "%computes the correlation (matrix) sequence given a stable ss description\nfunction [corrmat]=ss2corr_v000(A, Q, C, P0, dt, crind)\n\nnout=size(C,1);\nnout=nout*(nout+1)/2;\nnst=size(A,1);\ncorrmat=zeros(nout,length(crind));\n\n%compute the initial covariance\nif (isempty(P0))\n %check whether system is stable or not\n eigenval=eig(A);\n if (~isempty(find(eigenval>=1,1)))\n disp('A is not stable');\n eigenval\n return;\n else\n %Use lyapunov eq.\n P0=dlyap(A,Q);\n end\nend\n\n%convert the discrete time into cont\ncrcind=crind*dt;\n[Ac, Qc]=dc2dc_v000(A, Q, [], dt, 1,[]);\n\n%compute the covariances\nfor in=1:length(crind)\n sr_a=crcind(in);\n Ad=expm(Ac*abs(sr_a));\n %[Ad, Qd]=dc2dc_v000(Ac, Qc, [], abs(crcind(in)), 0,[]);\n if (sr_a>0)\n mx_a=C*(Ad*P0)*C';\n elseif (sr_a<0)\n mx_a=C*(P0*Ad')*C';\n else\n mx_a=C*P0*C';\n end\n corrmat(:,in)=mat2vec(mx_a);\nend\n\n\nfunction vec=mat2vec(mat)\nnrow=size(mat,1);\nnout=nrow*(nrow+1)/2;\nvec=zeros(nout,1);\nlb=1;\nub=nrow;\nfor in=1:size(mat,1)\n vec(lb:ub)=diag(mat,in-1);\n lb=ub+1;\n ub=ub+nrow-in;\nend\n\n \n \n", "meta": {"author": "JzHuai0108", "repo": "ekfmonoslam", "sha": "443f6be744732453cdb90679abcaf5c962a6295e", "save_path": "github-repos/MATLAB/JzHuai0108-ekfmonoslam", "path": "github-repos/MATLAB/JzHuai0108-ekfmonoslam/ekfmonoslam-443f6be744732453cdb90679abcaf5c962a6295e/instk/Common/ss2corr_v000.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418199787564, "lm_q2_score": 0.8080672066194945, "lm_q1q2_score": 0.7467686989904895}} {"text": "% generate the Companion matrix of the polynomials f \n% \n% Syntax: >> C = CompanionMatrix(f)\n% \n% Input: f --- (string or coefficient vector) polynomial\n% \n% Output: C --- (matrix) The companion matrix\n% \n% Example: >> CompanionMatrix('x^4 + 2*x^3 + 3*x^2 + 4*x+5')\n% \n% ans =\n% \n% -2 -3 -4 -5\n% 1 0 0 0\n% 0 1 0 0\n% 0 0 1 0\n", "meta": {"author": "zarathustr", "repo": "LibQPEP", "sha": "99e5c23e746ace0bac4a86742c31db6fcf7297ba", "save_path": "github-repos/MATLAB/zarathustr-LibQPEP", "path": "github-repos/MATLAB/zarathustr-LibQPEP/LibQPEP-99e5c23e746ace0bac4a86742c31db6fcf7297ba/MATLAB/homotopy/CompanionMatrix.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418116217418, "lm_q2_score": 0.8080672135527631, "lm_q1q2_score": 0.7467686986447835}} {"text": "function res = fact1(x)\nif x > 0\n res = x * fact1(x-1);\nelse\n res = 1;\nend", "meta": {"author": "101Hub", "repo": "Matlab101", "sha": "07273f68f1147a110443aeb121fa10962234f298", "save_path": "github-repos/MATLAB/101Hub-Matlab101", "path": "github-repos/MATLAB/101Hub-Matlab101/Matlab101-07273f68f1147a110443aeb121fa10962234f298/assets/\u300aMatlab\u7f16\u7a0b\u300b\u6e90\u7801/chap7/fact1.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9032942119105695, "lm_q2_score": 0.8267117962054049, "lm_q1q2_score": 0.7467639804305325}} {"text": "% Compute the error of a pose-pose constraint\n% x1 3x1 vector (x,y,theta) of the first robot pose\n% x2 3x1 vector (x,y,theta) of the second robot pose\n% z 3x1 vector (x,y,theta) of the measurement\n%\n% You may use the functions v2t() and t2v() to compute\n% a Homogeneous matrix out of a (x, y, theta) vector\n% for computing the error.\n%\n% Output\n% e 3x1 error of the constraint\n% A 3x3 Jacobian wrt x1\n% B 3x3 Jacobian wrt x2\nfunction [e, A, B] = linearize_pose_pose_constraint(x1, x2, z)\n\n % TODO compute the error and the Jacobians of the error\n X1 = v2t(x1);\n X2 = v2t(x2);\n Z = v2t(z);\n e = t2v(Z\\(X1\\X2));\n \n Rij = Z(1:3,1:3);\n Ri = X1(1:3,1:3);\n\n thi = atan2(Ri(2,1),Ri(1,1));\n thij = atan2(Rij(2,1),Rij(1,1));\n \n xi = x1(1);\n yi = x1(2);\n xj = x2(1);\n yj = x2(2);\n\n% A = [-Rij'*Ri' 0 0; 0 -Rij'*Ri' 0; 0 0 -1];\n% B = [Rij'*Ri' 0 0; 0 Rij'*Ri' 0; 0 0 1];\n\n A = [-cos(thi)*cos(thij)+sin(thi)*sin(thij) -sin(thi)*cos(thij)-cos(thi)*sin(thij) 0; cos(thi)*sin(thij)+sin(thi)*cos(thij) sin(thi)*sin(thij)-cos(thi)*cos(thij) 0; 0 0 -1];\n\n A(1:2,3) = [cos(thij)*(-sin(thi)*(xj-xi)+cos(thi)*(yj-yi))+sin(thij)*(-cos(thi)*(xj-xi)-sin(thi)*(yj-yi)); -sin(thij)*(-sin(thi)*(xj-xi)+cos(thi)*(yj-yi))+cos(thij)*(-cos(thi)*(xj-xi)-sin(thi)*(yj-yi))];\n\n B = [cos(thi)*cos(thij)-sin(thi)*sin(thij) sin(thi)*cos(thij)+cos(thi)*sin(thij) 0; -cos(thi)*sin(thij)-sin(thi)*cos(thij) -sin(thi)*sin(thij)+cos(thi)*cos(thij) 0; 0 0 1];\n\nend;\n", "meta": {"author": "kiran-mohan", "repo": "SLAM-Algorithms-Octave", "sha": "e0254ad38cfca2170b2af68c96c183df77c76252", "save_path": "github-repos/MATLAB/kiran-mohan-SLAM-Algorithms-Octave", "path": "github-repos/MATLAB/kiran-mohan-SLAM-Algorithms-Octave/SLAM-Algorithms-Octave-e0254ad38cfca2170b2af68c96c183df77c76252/8_GraphSLAM/octave/linearize_pose_pose_constraint.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.953966093674472, "lm_q2_score": 0.7826624890918021, "lm_q1q2_score": 0.7466334773844456}} {"text": "%\n% Example #1 Best-Fit Circle\n%\n%{\n\n% pseudo-data setting\nt=-pi:.01:pi; \nx=sin(t);\ny=cos(t); \nxn=.05*randn(1,629);\nyn=.05*randn(1,629); \nx=x+xn;\ny=y+yn;\n\n% additional data for objective function\nmydata.x=x;\nmydata.y=y;\n\nds(1,'circlefit',mydata,10,3,-10,10,2000)\n\n\nplot(x,y,'o','markersize',2);\nhold on\nplotcircle(globalminimizer(1),globalminimizer(2),globalminimizer(3),'r')\ndaspect([1 1 1])\nshg\n\n\n\n%}\nfunction out=circlefit(X,mydata)\n\nxdata=mydata.x;\nydata=mydata.y;\n\n[N,~]=size(X);\nout=ones(N,1); % pre-memory\nfor i=1:N\n x=X(i,:);\n a=x(1);\n b=x(2);\n r=x(3);\n \n out(i)=sum(abs((xdata-a).^2+(ydata-b).^2-repmat(r.^2,[size(xdata,1),1])));\nend\n\n% out---> Nx1 sized, where N:size of superorganism (i.e., population size; pattern-matrix size)\n\n\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/43390-differential-search-algorithm-a-modernized-particle-swarm-optimization-algorithm/circlefit.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533107374444, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.7466079082353655}} {"text": "function [Rob,Sen,Lmk,Obs,Frm,Fac] = solveGraphQR(Rob,Sen,Lmk,Obs,Frm,Fac,options)\n\n% SOLVEGRAPHQR Solves the SLAM graph using QR decomposition.\n% [Rob,Sen,Lmk,Obs,Frm,Fac] = SOLVEGRAPHQR(Rob,Sen,Lmk,Obs,Frm,Fac)\n% solves the graph-SLAM problem using QR decomposition of the\n% Hessian matrix. \n%\n% IMPORTANT NOTE: This method is illustrative and constitutes the\n% motivation for this toolbox. One can achieve better performances, both\n% in computing time and possibly in robustness and accuracy, by using\n% Matlab's built-in nonlinear optimization tools, such as LSQNONLIN.\n% \n% See courseSLAM.pdf in the documentation for details about the QR\n% decomposition for solving the graph-SLAM problem.\n%\n% See also SOLVEGRAPHCHOLESKY, ERRORSTATEJACOBIANS, UPDATESTATES,\n% COMPUTEERROR, COMPUTERESIDUAL, COLAMD, '\\', MLDIVIDE, LSQNONLIN.\n\n% Copyright 2015- Joan Sola @ IRI-UPC-CSIC.\n\nglobal Map\n\n% Control of iterations and exit conditions\nn_iter = options.niterations; % exit criterion of number of iterations\ntarget_dres = options.target_dres; % exit criterion for error variation\ntarget_res = options.target_res; % exit criterion for current residual\nres_old = 1e10; % last iteration's error\n\n% Map states range\nMap.mr = find(Map.used);\n% Map factors range\nerrs = [Fac.err];\nMap.fr = 1:sum([errs.size]);\n\nfor it = 1:n_iter\n \n % Compute Jacobians for projection onto the manifold\n [Frm,Lmk] = errorStateJacobians(Frm,Lmk);\n \n % Build Hessian A and rhs vector b, in global Map\n Fac = buildProblem(Rob,Sen,Lmk,Obs,Frm,Fac);\n \n if it == 1 % do this only once:\n \n % Column permutation\n p = colamd(Map.A(Map.fr,Map.mr))';\n \n % Permutated map range\n pr = Map.mr(p);\n Map.pr = pr;\n \n end\n \n % Decomposition\n [Map.d, Map.R] = qr(Map.A(Map.fr,pr), Map.b(Map.fr), 0);\n \n % Solve for dx and reorder:\n % - dx is Map.x(mr)\n % - reordered dx is Map.x(pr)\n Map.x(pr) = -Map.R\\Map.d; % solve for dx;\n \n % NOTE: Matlab is able to do all the reordering and QR factorization\n % for you. If you just use the operator '\\', as in 'dx = -A\\b', Matlab\n % will reorder A, then factor it to get R and d, then solve the\n % factored problem, then reorder back the result into dx. Use the\n % following line to accomplish this, and comment out the code from line\n % 'if it == 1' until here:\n %\n % Map.x(Map.mr) = -Map.A(Map.fr,Map.mr)\\Map.b(Map.fr);\n \n % Update nominal states\n [Rob,Lmk,Frm] = updateStates(Rob,Lmk,Frm);\n \n % Check resulting errors\n [res, err_max] = computeResidual(Rob,Sen,Lmk,Obs,Frm,Fac);\n dres = res - res_old;\n res_old = res;\n \n % Test and exit\n if ( ( -dres <= target_dres ) || (err_max <= target_res) ) %&& ( abs(derr) < target_derr) )\n break;\n end\n \nend\n\n% Compute full covariance matrix.\nMap.P(pr,pr) = inv(full(Map.R))*inv(full(Map.R))';\n\nend\n\nfunction Fac = buildProblem(Rob,Sen,Lmk,Obs,Frm,Fac)\n\n% BUILDPROBLEM Build least squares problem's matrix A and vector b \n% Fac = BUILDPROBLEM(Rob,Sen,Lmk,Obs,Frm,Fac) Builds the least squares\n% problem's matrix A and vector b for a solution using sparse QR\n% factorization of A.\n\nglobal Map\n\n\n% Reset Hessian and rhs vector\nMap.A(Map.fr,Map.mr) = 0;\nMap.b(Map.fr) = 0;\n\n% Iterate all factors\nfacCount = 1;\nfor fac = find([Fac.used])\n \n % Extract some pointers\n rob = Fac(fac).rob;\n sen = Fac(fac).sen;\n lmk = Fac(fac).lmk;\n frames = Fac(fac).frames;\n \n % Compute factor error, info mat, and Jacobians\n [Fac(fac), e, ~, Wsqrt, J1, J2, r1, r2] = computeError(...\n Rob(rob), ...\n Sen(sen), ...\n Lmk(lmk), ...\n Obs(sen,lmk), ...\n Frm(frames), ...\n Fac(fac));\n \n % row band matrix size\n m = numel(e);\n mr = (facCount : facCount + m - 1);\n \n % Update A and b\n Map.A(mr,r1) = Wsqrt * J1;\n Map.A(mr,r2) = Wsqrt * J2;\n \n Map.b(mr,1) = Wsqrt * e;\n\n % Advance to next row band\n facCount = facCount + m;\n\nend\n\nend\n\n\n\n\n% ========== End of function - Start GPL license ==========\n\n\n% # START GPL LICENSE\n\n%---------------------------------------------------------------------\n%\n% This file is part of SLAMTB, a SLAM toolbox for Matlab.\n%\n% SLAMTB is free software: you can redistribute it and/or modify\n% it under the terms of the GNU General Public License as published by\n% the Free Software Foundation, either version 3 of the License, or\n% (at your option) any later version.\n%\n% SLAMTB is distributed in the hope that it will be useful,\n% but WITHOUT ANY WARRANTY; without even the implied warranty of\n% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n% GNU General Public License for more details.\n%\n% You should have received a copy of the GNU General Public License\n% along with SLAMTB. If not, see .\n%\n%---------------------------------------------------------------------\n\n% SLAMTB is Copyright:\n% Copyright (c) 2008-2010, Joan Sola @ LAAS-CNRS,\n% Copyright (c) 2010-2013, Joan Sola,\n% Copyright (c) 2014-2015, Joan Sola @ IRI-UPC-CSIC,\n% SLAMTB is Copyright 2009\n% by Joan Sola, Teresa Vidal-Calleja, David Marquez and Jean Marie Codol\n% @ LAAS-CNRS.\n% See on top of this file for its particular copyright.\n\n% # END GPL LICENSE\n\n", "meta": {"author": "joansola", "repo": "slamtb", "sha": "b4767f6bf38bceed205abb85f1aed12422c9a972", "save_path": "github-repos/MATLAB/joansola-slamtb", "path": "github-repos/MATLAB/joansola-slamtb/slamtb-b4767f6bf38bceed205abb85f1aed12422c9a972/InterfaceLevel/solveGraphQR.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533126145178, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.7466079075209568}} {"text": "function phi=sinCosConformLat2EllipsLat(sinChi,cosChi,f)\n%%SINCOSCONFORMLAT2ELLIPSLAT Given the sine and cosine of a conformal\n% latitude, determine an ellipsoidal (geodetic) latitude. A\n% conformal latitude is a latitude in terms of a sphere that is\n% conformal with regard to the ellipsoid. That is, the\n% transformation from the ellipsoid to the sphere preserves\n% angles. This is such that the angle of intersection between\n% any two lines on the ellipsoid is the same as the corresponding\n% angle on the sphere.\n%\n%INPUTS: sinChi The real sine of the conformal latitude. This can be a\n% scalar or a matrix of values to convert.\n% cosChi The real cosine of the conformal latitude. This can be a\n% scalar or a matrix of values to convert. This has to be the\n% same size as sinChi.\n% f The flattening factor of the reference ellipsoid. If this\n% argument is omitted, the value in Constants.WGS84Flattening\n% is used. This function is only accurate for values from 0\n% to about 0.999. Typically, this will be close to zero, as\n% in Constants.WGS84Flattening.\n%\n%OUTPUTS: phi The ellipsoidal latitudes in radians. This is the same size\n% as sinChi and cosChi.\n%\n%Conformal latitudes are discussed in Chapter 3 of [1]. This function\n%implements the fixed-point iteration that is described in Section 2.9 of\n%[2]. Smaller values of f lead to faster convergence. The maximum number of\n%iterations in the function, which is typically never obtained, is set to\n%be able to convert unusually large values of f up to about 0.999. A\n%different fixed point iteration when given the conformal latitude itself\n%is given in [3].\n%\n%REFERENCES:\n%[1] J. P. Snyder, \"Map projections- a working manual,\" U.S. Geological\n% Survey, Tech. Rep. 1395, 1987.\n%[2] Office of Geomatics, \"National geospatial-intelligence agency\n% standardization document: Implementation practice: The universal\n% grids and the transverse mercator and polar stereographic\n% map projections,\" 25 Mar. 2014. [Online]. Available:\n% http://earth-info.nga.mil/GandG/publications/NGA_SIG_0012_2_0_0_UTMUPS/NGA.SIG.0012_2.0.0_UTMUPS.pdf\n%[3] Weisstein, Eric W. \"Conformal Latitude.\" From MathWorld--A Wolfram Web\n% Resource. http://mathworld.wolfram.com/ConformalLatitude.html\n%\n%July 2017 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nif(nargin<3||isempty(f))\n f=Constants.WGS84Flattening;\nend\n\n%The first numerical eccentricity of the ellipsoid.\ne=sqrt(2*f-f^2);\n\nN=numel(sinChi);\nphi=zeros(size(sinChi));\n\nfor curPoint=1:N\n s=sinChi(curPoint);\n %It should converge in 7 or fewer iterations for\n %f=Constants.WGS84Flattening. The upper bound of 5e7 should be enough for\n %f=0.999.\n for curIter=1:3e7\n P=exp(e*atanh(e*s));\n term1=(1+sinChi(curPoint))*P*P;\n term2=(1-sinChi(curPoint));\n\n sNew=(term1-term2)/(term1+term2);\n\n if(abs(s-sNew)<=eps(s))\n break\n end\n s=sNew;\n end\n P=exp(e*atanh(e*s));\n c=(1/2)*((1+s)/P+(1-s)*P)*cosChi(curPoint);\n phi(curPoint)=atan2(s,c);\nend\n\nend\n\n%LICENSE:\n%\n%The source code is in the public domain and not licensed or under\n%copyright. The information and software may be used freely by the public.\n%As required by 17 U.S.C. 403, third parties producing copyrighted works\n%consisting predominantly of the material produced by U.S. government\n%agencies must provide notice with such work(s) identifying the U.S.\n%Government material incorporated and stating that such material is not\n%subject to copyright protection.\n%\n%Derived works shall not identify themselves in a manner that implies an\n%endorsement by or an affiliation with the Naval Research Laboratory.\n%\n%RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF THE\n%SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY THE NAVAL\n%RESEARCH LABORATORY FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE ACTIONS\n%OF RECIPIENT IN THE USE OF THE SOFTWARE.\n", "meta": {"author": "USNavalResearchLaboratory", "repo": "TrackerComponentLibrary", "sha": "9f6e329de5be06a371757c4b853200beb6def2d0", "save_path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary", "path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary/TrackerComponentLibrary-9f6e329de5be06a371757c4b853200beb6def2d0/Coordinate_Systems/Latitude_Conversion/sinCosConformLat2EllipsLat.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802507195635, "lm_q2_score": 0.8128673201042493, "lm_q1q2_score": 0.7466025799710906}} {"text": "function det = r8pbl_det ( n, mu, a_lu )\n\n%*****************************************************************************80\n%\n%% R8PBL_DET computes the determinant of a matrix factored by R8PBL_FA.\n%\n% Discussion:\n%\n% The R8PBL storage format is for a symmetric positive definite band matrix.\n%\n% To save storage, only the diagonal and lower triangle of A is stored,\n% in a compact diagonal format that preserves columns.\n%\n% The diagonal is stored in row 1 of the array.\n% The first subdiagonal in row 2, columns 1 through MU.\n% The second subdiagonal in row 3, columns 1 through MU-1.\n% The MU-th subdiagonal in row MU+1, columns 1 through 1.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 22 February 2004\n%\n% Author:\n%\n% MATLAB version by John Burkardt.\n%\n% Reference:\n%\n% Dongarra, Bunch, Moler, Stewart,\n% LINPACK User's Guide,\n% SIAM, Philadelphia, 1979.\n%\n% Parameters:\n%\n% Input, integer N, the order of the matrix.\n% N must be positive.\n%\n% Input, integer MU, the upper (and lower) bandwidth.\n% MU must be nonnegative, and no greater than N-1.\n%\n% Input, real A_LU(MU+1,N), the LU factors from R8PBL_FA.\n%\n% Output, real DET, the determinant of the matrix.\n%\n det = prod ( a_lu(1,1:n).^2 );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/linplus/r8pbl_det.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9184802395624257, "lm_q2_score": 0.8128673178375734, "lm_q1q2_score": 0.7466025688199208}} {"text": "function [ x, seed ] = hyperball01_sample ( m, n, seed )\n\n%*****************************************************************************80\n%\n%% HYPERBALL01_SAMPLE uniformly samples the unit hyperball in M dimensions.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 05 January 2014\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Russell Cheng,\n% Random Variate Generation,\n% in Handbook of Simulation,\n% edited by Jerry Banks,\n% Wiley, 1998, pages 168.\n%\n% Reuven Rubinstein,\n% Monte Carlo Optimization, Simulation, and Sensitivity \n% of Queueing Networks,\n% Krieger, 1992,\n% ISBN: 0894647644,\n% LC: QA298.R79.\n%\n% Parameters:\n%\n% Input, integer M, the spatial dimension.\n%\n% Input, integer N, the number of points.\n%\n% Input/output, integer SEED, a seed for the random \n% number generator.\n%\n% Output, real X(M,N), the points.\n%\n x = randn ( m, n );\n norm = ones ( 1, m ) * ( x.^2 );\n norm = sqrt ( norm );\n for i = 1 : m\n x(i,1:n) = x(i,1:n) ./ norm(1:n);\n end\n\n for j = 1 : n\n r = rand ( 1, 1 );\n x(1:m,j) = r ^ ( 1.0 / m ) * x(1:m,j);\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/hyperball_integrals/hyperball01_sample.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802350995702, "lm_q2_score": 0.8128673201042492, "lm_q1q2_score": 0.7466025672741085}} {"text": "function b = NormalizeArray(a)\n% Normalizes array a. This means that the minimum value will become 0 and\n% the maximum value 1.\n%\n% a: Input array.\n%\n% b: Normalized output array\n%\n% Jasper Uijlings - 2013\n\nminVal = min(a(:));\nmaxVal = max(a(:));\n\ndiffVal = maxVal - minVal;\n\nb = a - minVal;\nif diffVal ~= 0\n b = b ./ diffVal;\nend\n", "meta": {"author": "zouchuhang", "repo": "LayoutNet", "sha": "95293bfb8ff787dd3b02c8a52a147a703024980f", "save_path": "github-repos/MATLAB/zouchuhang-LayoutNet", "path": "github-repos/MATLAB/zouchuhang-LayoutNet/LayoutNet-95293bfb8ff787dd3b02c8a52a147a703024980f/matlab/panoContext_code/Toolbox/SelectiveSearchCodeIJCV/Dependencies/NormalizeArray.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9184802395624257, "lm_q2_score": 0.8128673155708975, "lm_q1q2_score": 0.7466025667380239}} {"text": "function z = polyval2(p,x,y)\n% POLYVAL2 \n% ---------\n%\n% Evaluate a 2D polynomial\n% By SS Rogers (2006)\n%\n% Usage\n% ------\n% Z = POLYVAL2(P,X,Y) returns the value of a 2D polynomial P evaluated at (X,Y). P\n% is a vector of length (N+1)*(N+2)/2 containing the polynomial coefficients in\n% ascending powers:\n%\n% P = [p00 p10 p01 p20 p11 p02 p30 p21 p12 p03...]\n%\n% e.g. For a 3rd order fit, polyval2.m evaluates the matrix equation:\n%\n% Z = V*P or\n%\n% 2 2 3 2 2 3\n% Z = [1 x y x xy y x x y x y y ] [p00\n% p10\n% p01\n% p20\n% p11\n% p02\n% p30\n% p21\n% p12\n% p03]\n%\n% *Note:* P is not in the format of standard Matlab 1D polynomials.\n%\n% X and Y should be vectors; the polynomial is evaluated at all\n% points (X,Y).\n%\n% Class support for inputs P,X,Y:\n% float: double, single\n\nx=x(:);\ny=y(:);\nlx=length(x);\nly=length(y);\nlp=length(p);\npts=lx*ly;\n\ny=y*ones(1,lx);\nx=ones(ly,1)*x';\nx = x(:);\ny = y(:);\n\nn=(sqrt(1+8*length(p))-3)/2;\n% Check input is a vector\nif ~(isvector(p) || mod(n,1)==0 || lx==ly)\n error('MATLAB:polyval2:InvalidP',...\n 'P must be a vector of length (N+1)*(N+2)/2, where N is order. X and Y must be same size.');\nend\n\n% Construct weighted Vandermonde matrix.\nV=zeros(pts,lp);\nV(:,1) = ones(pts,1);\nordercolumn=1;\nfor order = 1:n\n for ordercolumn=ordercolumn+(1:order)\n V(:,ordercolumn) = x.*V(:,ordercolumn-order);\n end\n ordercolumn=ordercolumn+1;\n V(:,ordercolumn) = y.*V(:,ordercolumn-order-1);\nend\n\nz=V*p';\nz=reshape(z,ly,lx);", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/13719-2d-weighted-polynomial-fitting-and-evaluation/polyfitweighted2/polyval2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465170505205, "lm_q2_score": 0.7981867825403177, "lm_q1q2_score": 0.7465812270048474}} {"text": "function [Mout, RHSout] = combineBC2D(BC, Meq, RHSeq)\n%COMBINEBC This function combines the boundary condition equations with the\n%main physical model equations, and delivers the matrix of coefficient and\n%RHS to be solved for the internal cells.\n%\n% SYNOPSIS:\n% [Mout, RHSout] = combineBC2D(BC, Meq, RHSeq)\n%\n% PARAMETERS:\n%\n%\n% RETURNS:\n%\n%\n% EXAMPLE:\n%\n% SEE ALSO:\n%\n\n% extract data from the mesh structure\nNxy = BC.domain.dims;\nNx = Nxy(1); Ny = Nxy(2);\nG=reshape(1:(Nx+2)*(Ny+2), Nx+2, Ny+2);\ndx = BC.domain.cellsize.x;\ndy = BC.domain.cellsize.y;\n\n% define the RHS column vector\nms = size(Meq);\nM = Meq;\nRHS = RHSeq;\n\n% Assign values to the boundary condition matrix and the RHS vector based\n% on the BC structure\n% top boundary\nj=Ny+2;\ni=2:Nx+1;\ntop = reshape(sub2ind(ms, G(i,j-1), G(i,j-1)), Nx,1); % top boundary cells\ntopN = reshape(sub2ind(ms, G(i,j-1), G(i,j)), Nx, 1); % north cells to top boundary cells\nM(top) = M(top)-((BC.top.b/2 - BC.top.a/dy(end))./(BC.top.b/2 + BC.top.a/dy(end))).*M(topN);\nRHS(G(i,j-1)) = RHS(G(i,j-1))-M(topN).*BC.top.c./(BC.top.b/2 + BC.top.a/dy(end));\n\n% Bottom boundary\nj=1;\ni=2:Nx+1;\nbottom = reshape(sub2ind(ms, G(i,j+1), G(i,j+1)), Nx,1); % bottom boundary cells\nbottomS = reshape(sub2ind(ms, G(i,j+1), G(i,j)), Nx, 1); % south cells to bottom boundary cells\nM(bottom) = M(bottom)-((BC.bottom.b/2 + BC.bottom.a/dy(1))./(BC.bottom.b/2 - BC.bottom.a/dy(1))).*M(bottomS);\nRHS(G(i,j+1)) = RHS(G(i,j+1))-M(bottomS).*BC.bottom.c./(BC.bottom.b/2 - BC.bottom.a/dy(1));\n\n% Right boundary\ni=Nx+2;\nj=2:Ny+1;\nright = reshape(sub2ind(ms, G(i-1,j), G(i-1,j)), Ny,1); % right boundary cells\nrightE = reshape(sub2ind(ms, G(i-1,j), G(i,j)), Ny, 1); % east cells to right boundary cells\nM(right) = M(right)-((BC.right.b/2 - BC.right.a/dx(end))./(BC.right.b/2 + BC.right.a/dx(end)))'.*M(rightE);\nRHS(G(i-1,j)) = RHS(G(i-1,j))-M(rightE).*(BC.right.c./(BC.right.b/2 + BC.right.a/dx(end)))';\n\n% Left boundary\ni = 1;\nj=2:Ny+1;\nleft = reshape(sub2ind(ms, G(i+1,j), G(i+1,j)), Ny,1); % left boundary cells\nleftW = reshape(sub2ind(ms, G(i+1,j), G(i,j)), Ny, 1); % west cells to left boundary cells\nM(left) = M(left)-((BC.left.b/2 + BC.left.a/dx(1))./(BC.left.b/2 - BC.left.a/dx(1)))'.*M(leftW);\nRHS(G(i+1,j)) = RHS(G(i+1,j))-M(leftW).*(BC.left.c./(BC.left.b/2 - BC.left.a/dx(1)))';\n\nMout = M(G(2:end-1,2:end-1), G(2:end-1,2:end-1));\nRHSout = RHS(reshape(G(2:end-1,2:end-1),Nx*Ny,1));\n", "meta": {"author": "simulkade", "repo": "FVTool", "sha": "49f5cb9ee8a5ff0befebd9fa71a99feae7c724d6", "save_path": "github-repos/MATLAB/simulkade-FVTool", "path": "github-repos/MATLAB/simulkade-FVTool/FVTool-49f5cb9ee8a5ff0befebd9fa71a99feae7c724d6/Boundary/combineBC2D.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465134460243, "lm_q2_score": 0.798186775339273, "lm_q1q2_score": 0.746581217392314}} {"text": "function Distance = CalDistance(PopObj,RefPoint)\n% Calculate the distance between each solution to each adjusted reference\n% point\n\n%------------------------------- Copyright --------------------------------\n% Copyright (c) 2023 BIMK Group. You are free to use the PlatEMO for\n% research purposes. All publications which use this platform or any code\n% in the platform should acknowledge the use of \"PlatEMO\" and reference \"Ye\n% Tian, Ran Cheng, Xingyi Zhang, and Yaochu Jin, PlatEMO: A MATLAB platform\n% for evolutionary multi-objective optimization [educational forum], IEEE\n% Computational Intelligence Magazine, 2017, 12(4): 73-87\".\n%--------------------------------------------------------------------------\n \n N = size(PopObj,1);\n NR = size(RefPoint,1);\n\n %% Adjust the location of each reference point\n index=find(sum(PopObj.^2,2)==0);\n if ~isempty(index)\n PopObj(index,:)=PopObj(index,:)+1e-06*rand(size(PopObj(index,:)));\n end\n Cosine = 1 - pdist2(PopObj,RefPoint,'cosine');%The cosine of the individual and the reference point in the population, N*NR\n NormR = sqrt(sum(RefPoint.^2,2)); %NR*1\n NormP = sqrt(sum(PopObj.^2,2)); %N*1\n d1 = repmat(NormP,1,NR).*Cosine; %N*NR\n d2 = repmat(NormP,1,NR).*sqrt(1-Cosine.^2); %N*NR\n [~,nearest] = min(d2,[],1); %1*NR\n RefPoint = RefPoint.*repmat(d1(N.*(0:NR-1)+nearest)'./NormR,1,size(RefPoint,2));\n \n %% Calculate the distance between each solution to each point\n Distance = pdist2(PopObj,RefPoint);\nend", "meta": {"author": "BIMK", "repo": "PlatEMO", "sha": "c5b5b7c37a9bb42689a5ac2a0d638d9c4f5693d5", "save_path": "github-repos/MATLAB/BIMK-PlatEMO", "path": "github-repos/MATLAB/BIMK-PlatEMO/PlatEMO-c5b5b7c37a9bb42689a5ac2a0d638d9c4f5693d5/PlatEMO/Algorithms/Multi-objective optimization/EDN-ARMOEA/CalDistance.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404077216356, "lm_q2_score": 0.8031737963569014, "lm_q1q2_score": 0.7465021807572925}} {"text": "function [ x, y, z, w ] = ld0194 ( )\n\n%*****************************************************************************80\n%\n%% LD0194 computes the 194 point Lebedev angular grid.\n%\n% Modified:\n%\n% 14 September 2010\n%\n% Author:\n%\n% Dmitri Laikov\n%\n% Reference:\n%\n% Vyacheslav Lebedev, Dmitri Laikov,\n% A quadrature formula for the sphere of the 131st\n% algebraic order of accuracy,\n% Russian Academy of Sciences Doklady Mathematics,\n% Volume 59, Number 3, 1999, pages 477-481.\n%\n% Parameters:\n%\n% Output, real X(N), Y(N), Z(N), W(N), the coordinates\n% and weights of the points.\n%\n n = 0;\n x = zeros(194,1);\n y = zeros(194,1);\n z = zeros(194,1);\n w = zeros(194,1);\n a = 0.0;\n b = 0.0;\n v = 0.1782340447244611E-02;\n [ n, x, y, z, w ] = gen_oh ( 1, n, a, b, v, x, y, z, w );\n v = 0.5716905949977102E-02;\n [ n, x, y, z, w ] = gen_oh ( 2, n, a, b, v, x, y, z, w );\n v = 0.5573383178848738E-02;\n [ n, x, y, z, w ] = gen_oh ( 3, n, a, b, v, x, y, z, w );\n a = 0.6712973442695226;\n v = 0.5608704082587997E-02;\n [ n, x, y, z, w ] = gen_oh ( 4, n, a, b, v, x, y, z, w );\n a = 0.2892465627575439;\n v = 0.5158237711805383E-02;\n [ n, x, y, z, w ] = gen_oh ( 4, n, a, b, v, x, y, z, w );\n a = 0.4446933178717437;\n v = 0.5518771467273614E-02;\n [ n, x, y, z, w ] = gen_oh ( 4, n, a, b, v, x, y, z, w );\n a = 0.1299335447650067;\n v = 0.4106777028169394E-02;\n [ n, x, y, z, w ] = gen_oh ( 4, n, a, b, v, x, y, z, w );\n a = 0.3457702197611283;\n v = 0.5051846064614808E-02;\n [ n, x, y, z, w ] = gen_oh ( 5, n, a, b, v, x, y, z, w );\n a = 0.1590417105383530;\n b = 0.8360360154824589;\n v = 0.5530248916233094E-02;\n [ n, x, y, z, w ] = gen_oh ( 6, n, a, b, v, x, y, z, w );\n \n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/sphere_lebedev_rule/ld0194.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403999037782, "lm_q2_score": 0.8031737987125612, "lm_q1q2_score": 0.7465021766676396}} {"text": "function const_pts = rectQAM_const(M)\n% \n\n% M-PAM bit/symbol ordering\n[bo so] = PAM_Gray_Code;\n\nk = log2(M);\nI = 2^ceil(k/2);\nQ = 2^floor(k/2);\n\n% Produce PAM constellation points for in-phase and quadrature\nI_t = -(I-1):2:I-1;\nQ_t = Q-1:-2:-(Q-1);\n\n% Re-order based on the PAM Gray mapping\nfor i=1:length(I_t)\n I_pts(so{log2(I)}(i)+1) = I_t(i);\nend\nfor i=1:length(Q_t)\n Q_pts(so{log2(Q)}(i)+1) = Q_t(i);\nend\n\nfor i=0:M-1\n MSBs = floor(i/I);\n LSBs = i-MSBs*I;\n QAM_I(i+1) = I_pts(LSBs+1);\n QAM_Q(i+1) = Q_pts(MSBs+1);\nend\n\nconst_pts=complex(QAM_I,QAM_Q);", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/22316-communication-systems-reference-curves/QAM_BER/_oldmyQAM_const.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9294403999037784, "lm_q2_score": 0.803173791645582, "lm_q1q2_score": 0.7465021700993036}} {"text": "%% Author: epokh\n%% Website: www.epokh.org/drupy\n%% This software is under GPL\n\n%%Function description:\n%%Transformation of the end effector frame following the Euler angles\n%%in closed form\n%%input: rotation angles along y,z,y axis expressed in degrees\n\nfunction [EulerMat]=Euler(fi1,theta,fi2)\n\nEulerMat=[cosd(fi1)*cosd(theta)*cosd(fi2)-sind(fi1)*sind(fi2),-cosd(fi1)*cosd(theta)*sind(fi2)-sind(fi1)*cosd(fi2),cosd(fi1)*sind(theta),0;\n sind(fi1)*cosd(theta)*cosd(fi2)+cosd(fi1)*sind(fi2),-sind(fi1)*cosd(theta)*sind(fi2)+cosd(fi1)*cosd(fi2),sind(fi1)*sind(theta),0;\n -sind(theta)*cosd(fi2),sind(theta)*sind(fi2),cosd(theta),0;\n 0 ,0 ,0 ,1;];\n \n \n\nend", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/14886-robotic-toolbox/Euler.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.960361158630024, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.7464885952806832}} {"text": "% Test file for fractional calculus.\n\nfunction pass = test_fracInt(pref)\n\nif ( nargin == 0 ) \n pref = chebfunpref();\nend\n\ntol = 100*pref.chebfuneps;\ndom = [0, 1];\n\n% Test values:\nxx = linspace(dom(1)+.1, dom(2)-.1, 10)';\n\n%% Polynomials\nx = chebfun('x', dom);\nq = sqrt(2)/2;\nk = 1;\nfor n = [1, 4]\n \n U = diff(x.^n, q);\n tru = gamma(n+1)./gamma(n+1-q)*chebfun(@(x) x.^(n-q), dom, 'exps', [n-q, 0]); \n \n err(k) = norm(tru(xx) - U(xx), inf);\n tol(k) = 10*eps*vscale(U)*hscale(U);\n k = k + 1;\n \nend\n\n%% Exponential\nu = chebfun('exp(x)', dom);\ntrueC = chebfun('erf(sqrt(x)).*exp(x) + 1./sqrt(pi*x)', dom, 'exps', [-.5 0]);\ntrueRL = chebfun('erf(sqrt(x)).*exp(x)', dom, 'exps', [.5, 0]);\n\n% RL\nU = diff(u, .5, 'Caputo');\nerr(3) = norm(trueRL(xx) - U(xx), inf);\ntol(3) = 10*eps*vscale(U)*hscale(U);\n\n% Caputo\nU = diff(u, .5, 'RL');\nerr(4) = norm(trueC(xx) - U(xx), inf);\ntol(4) = 1e2*eps*vscale(U)*hscale(U);\n \n\n%% Integrate twice:\nxx = linspace(-sqrt(2)*pi+.1, pi-.1, 10).';\nf = chebfun(@sin, [-sqrt(2)*pi, pi]);\nF = cumsum(f);\nG = fracInt(fracInt(f, .3), .7);\nerr(5) = norm(feval(F, xx) - feval(G, xx), inf);\ntol(5) = 10*eps*vscale(G)*hscale(G);\n\n%% Differentiate twice:\nxx = linspace(-sqrt(2)*pi+.1, pi-.1, 10)';\nf = chebfun(@sin, [-sqrt(2)*pi, pi]);\nF = diff(f);\nG = fracDiff(fracDiff(f, .3), .7);\nerr(6) = norm(feval(F, xx) - feval(G, xx), inf);\ntol(6) = 1e2*eps*vscale(G)*hscale(G);\n\n%% Test quasimatrix support\nx = chebfun('x', [0 1]);\nV = cheb2quasi(vander(x, 5));\nF = diff(V, .5);\nerr(7) = 0;\nfor k = 1:numel(V)\n err(7) = err(7) + norm(diff(V(:,k), .5) - F(:,k));\nend\ntol(7) = 10*eps;\n\n%%\npass = err < tol;\n\nend\n", "meta": {"author": "chebfun", "repo": "chebfun", "sha": "8c49396a55e46ddd57a1d108c6a8f32e37536d54", "save_path": "github-repos/MATLAB/chebfun-chebfun", "path": "github-repos/MATLAB/chebfun-chebfun/chebfun-8c49396a55e46ddd57a1d108c6a8f32e37536d54/tests/chebfun/test_fracCalc.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297914570319, "lm_q2_score": 0.8289388167733099, "lm_q1q2_score": 0.7464840997995076}} {"text": "function [xECEF,MInv]=ENU2ECEF(plhOrigin,xENU,a,f)\n%%ENU2ECEF Convert from a local East-North-Up (ENU) Cartesian cooridnate\n% system to an Earth-centered Earth-fixed (ECEF) Cartesian\n% coordinate system. The alignment of the coordinate axes with the\n% reference ellipsoid is the one used in common standards such as\n% that used by the DoD's WGS-84 standard and the International\n% Earth Rotation and Reference Systems Service's (IERS)\n% international terrestrial reference frame (ITRF). The global\n% ECEF z-axis is North.\n%\n%INPUTS: plhOrigin A 3X1 point in [latitude;longitude; ellipsoidal height]\n% coordinates with respect to a reference ellipsoid\n% parameterized by a and f, derving as the origin of the local\n% ENU coordinate system. Latitude and longitude are given in\n% radians North and East.\n% xENU A 3XnumPts collection of 3D Cartesian points in the local ENU\n% coordinate system that should be converted to a global ECEF\n% coordinate system.\n% a The semi-major axis of the reference ellipsoid. If this\n% argument is omitted, the value in\n% Constants.WGS84SemiMajorAxis is used.\n% f The flattening factor of the reference ellipsoid. If this\n% argument is omitted, the value in Constants.WGS84Flattening\n% is used.\n%\n%OUTPUTS: xECEF A 3XnumPts matrix of the points in xENU converted to ECEF\n% coordinates.\n% MInv A rotation matrix such that rotates a point from ENU to\n% ECEF coordinates.\n%\n%The ENU coordinate system is a common local tangent plane cooridnate\n%system. Here, we take \"up\" to be that described by a reference ellipsoid\n%and not true gravitational \"up\". This limits the accuracy of the local\n%coordinate system.\n%\n%The conversions are mentioned in [1].\n%\n%EXAMPLE:\n%Here, we convert 3 points in a local ENU tangent-plane coordinate system\n%to ECEF and then to ellipsoidal coordinates. In the ENU coordinate system,\n%the points are offset in the North, East, and up directions. One will see\n%that in ellipsoidal coordinates, as compared to the origin, there are\n%respective offsets in latitude (with no change in longitude), longitude\n%(with no change in latitude) and heigh (with no change in latitude or\n%longitude).\n% lat=19.7241*(pi/180);\n% lon=-155.0868*(pi/180);\n% height=0;\n% plhPoint=[lat;lon;height];%Around Hilo, Hawaii.\n% xENU=[0, 1e3, 0;\n% 1e3, 0, 0;\n% 0, 0, 1e3];\n% xECEF=ENU2ECEF(plhPoint,xENU);\n% latLonHeight=Cart2Ellipse(xECEF);\n% diffVals=bsxfun(@minus,latLonHeight,plhPoint);\n% %Convert angles to degrees\n% diffVals(1:2,:)=diffVals(1:2,:)*(180/pi);\n% %One can see the change in latitude on the first point, the change in\n% %longitude on the second point, and no change in laittude or longitude in\n% %the third point.\n% diffVals(1:2,:)\n% %The change in height with the third point is the full kilometer. The\n% %changes with the other points is just due to the tangent point\n% %approximation and are much smaller.\n% diffVals(3,:)\n%\n%REFERENCES:\n%[1] D. F. Crouse, \"Simulating aerial targets in 3D accounting for the\n% Earth's curvature,\" Journal of Advances in Information Fusion, vol.\n% 10, no. 1, Jun. 2015.\n%\n%September 2020 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nif(nargin<3||isempty(a))\n a=Constants.WGS84SemiMajorAxis;\nend\n\nif(nargin<4||isempty(f))\n f=Constants.WGS84Flattening;\nend\n\nMInv=getENUAxes(plhOrigin,false,a,f);\noriginCart=ellips2Cart(plhOrigin,a,f);\n\nnumPts=size(xENU,2);\nxECEF=zeros(3,numPts);\nfor k=1:numPts\n xECEF(:,k)=xENU(1,k)*MInv(:,1)+xENU(2,k)*MInv(:,2)+xENU(3,k)*MInv(:,3);\nend\n\n%Correct for the origin shift.\nxECEF=bsxfun(@plus,xECEF,originCart);\nend\n\n%LICENSE:\n%\n%The source code is in the public domain and not licensed or under\n%copyright. The information and software may be used freely by the public.\n%As required by 17 U.S.C. 403, third parties producing copyrighted works\n%consisting predominantly of the material produced by U.S. government\n%agencies must provide notice with such work(s) identifying the U.S.\n%Government material incorporated and stating that such material is not\n%subject to copyright protection.\n%\n%Derived works shall not identify themselves in a manner that implies an\n%endorsement by or an affiliation with the Naval Research Laboratory.\n%\n%RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF THE\n%SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY THE NAVAL\n%RESEARCH LABORATORY FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE ACTIONS\n%OF RECIPIENT IN THE USE OF THE SOFTWARE.\n", "meta": {"author": "USNavalResearchLaboratory", "repo": "TrackerComponentLibrary", "sha": "9f6e329de5be06a371757c4b853200beb6def2d0", "save_path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary", "path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary/TrackerComponentLibrary-9f6e329de5be06a371757c4b853200beb6def2d0/Coordinate_Systems/ENU2ECEF.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9005297834483234, "lm_q2_score": 0.8289388125473628, "lm_q1q2_score": 0.746484089355187}} {"text": "function [invA]=invltod(A,n)\n\n\n\n\n\n\n% computes the inverse of a n*n lower triangular matrix with ones on the main diagonal\n% uses result (XXX) from Appendix (XXX)\n\n\n% first obtain the B matrix from A\nB=sparse(tril(A,-1));\n\n% compute the summation term\nsumm=sparse(n,n);\nprodt=speye(n);\nfor ii=1:n-1\nprodt=prodt*B;\nsumm=summ+(-1)^ii*prodt;\nend\n\n% compute the inverse of A\ninvA=full(speye(n)+summ);\n\n\n\n", "meta": {"author": "european-central-bank", "repo": "BEAR-toolbox", "sha": "f33aae80c40f7a2e78a54de99b2ce3663f59aa75", "save_path": "github-repos/MATLAB/european-central-bank-BEAR-toolbox", "path": "github-repos/MATLAB/european-central-bank-BEAR-toolbox/BEAR-toolbox-f33aae80c40f7a2e78a54de99b2ce3663f59aa75/tbx/bear/+bear/invltod.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9005297807787538, "lm_q2_score": 0.8289388125473628, "lm_q1q2_score": 0.7464840871422771}} {"text": "function buckling_spring_theta ( l_num, theta_num )\n\n%*****************************************************************************80\n%\n%% BUCKLING_SPRING_THETA plots LAMBDA(L,THETA) and MU(L,THETA) lines for fixed L.\n%\n% Discussion:\n%\n% This routine fixes L and plots LAMBDA and MU as functions of THETA.\n%\n% Usage:\n%\n% buckling_spring_theta ( l_num, theta_num )\n%\n% * l_num is the number of L values along each THETA line;\n% * theta_num is the number of THETA lines to draw.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 30 October 2008\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer L_NUM, the number of values of L,\n% which controls the smoothness of each line.\n% A value of 101 is plenty.\n%\n% Input, integer THETA_NUM, the number of values of THETA, \n% which sets the number of lines to be drawn.\n% A value of 101 is plenty.\n%\n l_lo = 0.25;\n l_hi = 1.75;\n\n theta_lo = - 3 * pi / 8;\n theta_hi = + 3 * pi / 8;\n\n for j = 1 : l_num\n\n if ( l_num == 1 )\n L = 0.5 * ( l_lo + l_hi );\n else\n L = ( ( l_num - j ) * l_lo ...\n + ( j - 1 ) * l_hi ) ...\n / ( l_num - 1 );\n end\n\n for i = 1 : theta_num\n\n if ( theta_num == 1 )\n theta = 0.5 * ( theta_lo + theta_hi );\n else\n theta = ( ( theta_num - i ) * theta_lo ...\n + ( i - 1 ) * theta_hi ) ...\n / ( theta_num - 1 );\n end\n\n lambda(i,j) = ( 1 - L ) * cos ( theta ) + theta * sin ( theta ) / 4 / L;\n mu(i,j) = - theta * cos ( theta ) / 2 / L + 2 * ( 1 - L ) * sin ( theta );\n\n end\n\n end\n\n plot ( lambda, mu )\n%\n% Limit the plot range.\n% Suppress this command to see the whole plot.\n%\n axis ( [ 0.1 0.9 -0.07 0.07 ] );\n%\n% Label the plot.\n%\n xlabel ( '\\lambda(L,\\theta)' );\n ylabel ( '\\mu(L,\\theta)' );\n title ( 'Each line is a fixed value of L' );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/buckling_spring/buckling_spring_theta.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278726384089, "lm_q2_score": 0.8459424431344437, "lm_q1q2_score": 0.7464831904696654}} {"text": "% DOC\n%\n% Files\n% afemdoc - Adaptive Finite Element Method\n% amgdoc - ALGEBRAIC MULTIGRID METHOD\n% amgdoctest1 - AMG TEST I: DIFFERENT MESHES\n% amgdoctest2 - AMG TEST II: Different boundary conditions\n% amgdoctest3 - AMG TEST III: Robustness to time discretization\n% amgtest - test algebraic mutligrid solver\n% amgtest2 - AMG TEST II: Different boundary conditions\n% auxstructuredoc - Auxiliary Mesh Data Structure\n% bddoc - Data Structure: Boundary Conditions\n% bisectdoc - Bisection in Two Dimensions\n% coarsenAMGdoc - Coarsening for Algebraic Multigrid\n% coarsendoc - COARSENING in TWO DIMENSIONS\n% coloringdoc - Coloring Vertices of a Graph\n% dof3edgedoc - Data Structure: Lowest Order Edge Element\n% dofdoc - Data Sturcture for Degree of Freedom (DOF) \n% dofedgedoc - Dofedge in Two Dimensions\n% dofP2doc - Data Structure: P2 Quadratic Element\n% fastcoding - Vectorization\n% femcontent - Finite Element Methods\n% femdoc - Finite Element Methods\n% ifem - Display HTML documentation in the MATLAB web browser.\n% introduction - Introduction of iFEM\n% Maxwell1doc - Equation: Maxwell Equation Discretized by Edge Element\n% Maxwell1testdoc - Edge Element Discretization of Maxwell Equations: Linear Element\n% Maxwell2doc - Equation: Maxwell equation Quadratic Element in 3D\n% Maxwell2testdoc - Edge Element Discretization of Maxwell Equations\n% Maxwelldoc - Equation: Maxwell Equation Discretized by Edge Element\n% MaxwellNeumanBCdoc - Local Labeling of DOFs\n% Maxwelltestdoc - Edge Element Discretization of Maxwell Equations\n% meshamrdoc - Adaptive Mesh Refinement/Coarsening\n% meshbasicdoc - Basic Data Structure representing a Mesh\n% meshdoc - Mesh\n% meshoptdoc - Mesh Smoothing and Optimization\n% mgdoc - MULTIGRID on BISECTION GRIDS\n% mixFEMsolverdoc - Mixed FEM solver\n% Poisson3BDM1doc - Equation: Poisson Equation Discretized by $BDM_1$ Element in 3D\n% Poisson3RT0doc - Equation: Poisson Equation Discretized by $RT_0$ Element in 3D\n% PoissonBDM1doc - Equation: Poisson Equation Discretized by $BDM_1$ Element in 2D\n% PoissonRT0doc - Equation: Poisson Equation Discretized by $RT_0$ Element in 2D\n% sc3doc - Simplicial Complex in Three Dimensions\n% scdoc - Simplicial Complex in Three Dimensions\n% simplicialcomplexdoc - Simplicial Complex in 3D\n% solverdoc - Multigrid Method\n% sparsematrixdoc - Vectorization using Sparse Matrices\n% uniformrefine3doc - 3-D Red Refinement\n", "meta": {"author": "wme7", "repo": "Aero-matlab", "sha": "9430008f2e3b84f28633775a44dff534e780fbac", "save_path": "github-repos/MATLAB/wme7-Aero-matlab", "path": "github-repos/MATLAB/wme7-Aero-matlab/Aero-matlab-9430008f2e3b84f28633775a44dff534e780fbac/iFEM/doc/Contents.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424295406088, "lm_q2_score": 0.8824278618165526, "lm_q1q2_score": 0.7464831693194192}} {"text": "function [h_1d,h_2d] = create_h(sigma_h, size_h, opt, mode)\n\nif sigma_h > opt.M || sigma_h > opt.N\n error('blur kernel must be smaller than image');\nend\n\nif mode == 1\n x = linspace(-size_h/2, size_h/2, size_h);\n h_1d = exp(-x.^2 / (2 * sigma_h^2)); % 1D Guassian filter kernel\n h_1d = h_1d / sum(h_1d); % normalize\n h_2d = kron(h_1d',h_1d);\nelseif mode == 2\n h_2d = ones(size_h,size_h) / (size_h*size_h);\nend\n", "meta": {"author": "thomas-koehler", "repo": "SupER", "sha": "d8c6f2e4b26db002ff55bc2beba18639f1d0bb49", "save_path": "github-repos/MATLAB/thomas-koehler-SupER", "path": "github-repos/MATLAB/thomas-koehler-SupER/SupER-d8c6f2e4b26db002ff55bc2beba18639f1d0bb49/matlab/algorithms/SRAlgorithms/BayesianVSR/functions/create_h.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9473810525948928, "lm_q2_score": 0.7879311931529758, "lm_q1q2_score": 0.746471083141616}} {"text": "% Generate Figure 6 of the \"Deep Scattering Spectrum\" paper.\n\n% Load the signal.\nx = wavread('chord_signal.wav');\n\n% Prepare the filters and scattering operators.\nfilt_opt.filter_type = {'gabor_1d','morlet_1d'};\nfilt_opt.B = [4 4];\nfilt_opt.Q = 4*filt_opt.B; \nfilt_opt.J = T_to_J([256 32768],filt_opt);\n\nscat_opt.oversampling = 3;\nscat_opt.M = 2;\n\nWop = wavelet_factory_1d(length(x), filt_opt, scat_opt);\n\n% Compute scattering coefficients.\n[S, U] = scat(x, Wop);\n\n% Renormalize coefficients.\nepsilon = 1e-3;\nS = renorm_scat(S, epsilon);\nS = renorm_1st(S, x, Wop{2}, epsilon);\n\nS = resample_scat(S, 8, false);\nU = resample_scat(U, 6, false);\n\n% Compute the logarithm.\nS = log_scat(S, 1e-3);\nU = log_scat(U, 1e-3);\n\n% Display scalogram U{2}, first-order coefficients S{2} and second-order\n% coefficients S{3} for j1 = 58.\nfigure(6);\nclf;\nset(gcf,'Units','pixels','Position',[200 200 560 420]);\nscattergram(U{2}, [], S{2}, [], S{3}, 58);\nsubplot(3,1,1);\nset(gca,'XTick',[],'YTick',[]);\nsubplot(3,1,2);\nset(gca,'XTick',[],'YTick',[]);\nsubplot(3,1,3);\nset(gca,'XTick',[],'YTick',[]);\ncolormap(jet);\n\n", "meta": {"author": "scatnet", "repo": "scatnet", "sha": "59d935afa20359845282a3518134e24244862c1f", "save_path": "github-repos/MATLAB/scatnet-scatnet", "path": "github-repos/MATLAB/scatnet-scatnet/scatnet-59d935afa20359845282a3518134e24244862c1f/papers/DSS/DSS_Figure6.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.938124016006303, "lm_q2_score": 0.7956580976404297, "lm_q1q2_score": 0.7464259699263751}} {"text": "% test the spherical compression scheme\n\nsampling_type = 'random';\n% sampling_type = 'uniform';\n\ndata_type = 'syntetic';\n% data_type = 'real';\n\nn = 1500;\nk = 2; % number of vanishing moments.\ndir = 1;\n\nswitch sampling_type\n case 'random'\n pos = randn(3,n);\n d = sqrt( pos(1,:).^2+pos(2,:).^2+pos(3,:).^2 );\n pos(1,:) = pos(1,:)./d;\n pos(2,:) = pos(2,:)./d;\n pos(3,:) = pos(3,:)./d;\n case 'uniform'\n [pos,L,diam] = sphere_sampling(n);\nend\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% compute some function\nswitch data_type\n case 'syntetic'\n v = pos(1,:).^2 - pos(2,:).*pos(3,:);\n v = v(:);\n v = rescale(v);\n v = cos(10*v);\n % list for compression plot\n m_list = [1,2,5,10,15];\n case 'real'\n sampling_type = 'real';\n load('data/data_lenglet.mat');\n% [pos,face] = gen_base_mesh('oct');\n% [pos,face] = subdivide_sphere(pos,face,2); pos = pos'; \n v = ADC24_36_14(:);\n pos = grad_81';\n % symmetrize the data\n pos = [pos,-pos];\n v = [v;v];\n n = length(v);\n v = rescale(v);\n % list for compression plot\n m_list = [5,10,20,40,70];\nend\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% compute clustering\nclear options;\noptions.ptmax = k^2;\noptions.part_type = 'kmeans';\n[part,B,G] = dichotomic_grouping(pos,options);\n% plot\nclf;\nsubplot(1,2,1);\nplot_spherical_partition(pos,part);\ntitle('Clustering of sampling locations');\n\nsubplot(1,2,2);\nplot_spherical_function(pos,v);\ntitle('Function to transform (interpolated)');\nsaveas(gcf, ['function_',data_type, '_clustering_', sampling_type], 'png');\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% perform transform\nclear options;\noptions.part_type = 'kmeans';\n[w,info,part] = perform_alpert_transform_nd(v,pos,k, 1, options);\n% try reconstruction just to check the transform is bijective ...\noptions.part = part;\nv1 = perform_alpert_transform_nd(w,pos,k, -1,options);\nnorm(v-v1, 'fro') % should be 0\n\ncv = rev_sort_abs(v);\ncw = rev_sort_abs(w);\ncv = l2error(v);\ncw = l2error(w);\n\na = (1:n/2)';\nx = log2(a);\ny1 = cv(a);\ny2 = cw(a);\n\n% reglin\nfiton = a;\nA = a;\nB = y2;\naa = log2(A(fiton));\nbb = log2(B(fiton));\n[coef,S] = polyfit(aa,bb,1);\ndisp( sprintf('----> 1D Alpert transform, decreasing=%.4f', coef(1)) );\nreglin = log2(a)*coef(1)+coef(2);\n\n\nclf;\nhold on;\nplot( x, log2(y1), x, log2(y2), x, reglin, 'b:' );\naxis tight;\nlegend('Original error decreasing', 'Transformed error decreasing');\nhold off;\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% perform reconstruction\nclf;\nsubplot(2,3,1);\nplot_spherical_function(pos,v);\ntitle('Original function');\ns = 1;\n\nfor m = m_list\n s = s+1;\n w1 = keep_biggest(w, round(n*m/100) );\n % backward transform\n v1 = perform_alpert_transform_nd(w1,pos,k, -1,part);\n subplot(2,3,s);\n plot_spherical_function(pos,v1);\n err = round( 100*norm(v-v1, 'fro')^2/norm(v, 'fro')^2 ); % RMS error in %\n title(sprintf('%.1f %% of coef, err=%d%%', m, err ));\nend\n\nsaveas(gcf, ['compression_',data_type, '_clustering_', sampling_type], 'png');", "meta": {"author": "gpeyre", "repo": "matlab-toolboxes", "sha": "0cd622c988cda6f63f64d35cd7bd096fa578e5c6", "save_path": "github-repos/MATLAB/gpeyre-matlab-toolboxes", "path": "github-repos/MATLAB/gpeyre-matlab-toolboxes/matlab-toolboxes-0cd622c988cda6f63f64d35cd7bd096fa578e5c6/toolbox_alpert/tests/test_spherical.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.938124016006303, "lm_q2_score": 0.7956580976404296, "lm_q1q2_score": 0.746425969926375}} {"text": "% book : Signals and Systems Laboratory with MATLAB \n% authors : Alex Palamides & Anastasia Veloni\n\n\n%Fourier Transfrom and inverse Fourier Transfrom of various functions \n% the order of the operations is a little different \n%from the order that they appear on the book \n\n\n%F{exp(-t^2)}\nsyms t w\nx=exp(-t^2);\nfourier(x)\n\nint(x*exp(-j*w*t),t,-inf,inf)\n\n\n%F^-1{1/(1+j*w)}\nX=1/(1+j*w);\nifourier(X)\n\nX=1/(1+j*w);\nifourier(X,t)\n\nsyms n\nX=1/(1+j*w);\nifourier(X,n)\n\n\n%F{exp(-t)*u(t)}\nsyms t w\nx=exp(-t)*heaviside(t);\nX=fourier(x,w)\n\n\n%F{1}\nx=1;\nfourier(x,w)\nsyms s\nfourier(x,s)\nfourier(x)\n\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/28762-signals-and-systems-laboratory-with-matlab-m-files/M-FILES/6/c62.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240142763572, "lm_q2_score": 0.7956580976404296, "lm_q1q2_score": 0.7464259685499296}} {"text": "% Compute the closeness centrality for every vertex: 1/sum(dist to all other nodes)\n%\n% INPUTs: adjacency matrix, nxn\n% OUTPUTs: vector of closeness centralities, nx1\n%\n% Source: social networks literature (example: Wasserman, Faust, \"Social Networks Analysis\")\n% Other routines used: simpleDijkstra.m \n% GB: last updated, Sep 28, 2012\n\nfunction C=closeness(adj)\n\nC=zeros(length(adj),1); % initialize closeness vector\n\nfor i=1:length(adj); C(i)=1/sum( simpleDijkstra(adj,i) ); end", "meta": {"author": "aeolianine", "repo": "octave-networks-toolbox", "sha": "e70f79eb62a54ef96934d900830f9177caf732c9", "save_path": "github-repos/MATLAB/aeolianine-octave-networks-toolbox", "path": "github-repos/MATLAB/aeolianine-octave-networks-toolbox/octave-networks-toolbox-e70f79eb62a54ef96934d900830f9177caf732c9/closeness.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9441768651485395, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.7464004380864094}} {"text": "clear all\n\nnInst = 500;\nnVars = 200;\nX = randn(nInst,nVars);\nw = randn(nVars,1);\ny = sign(X*w + randn(nInst,1));\n\nw_init = zeros(nVars,1);\nfunObj = @(w)LogisticLoss(w,X,y);\n\nfprintf('\\nRunning Steepest Descent\\n');\noptions.Method = 'sd';\nminFunc(@LogisticLoss,w_init,options,X,y);\npause;\n\nfprintf('\\nRunning Cyclic Steepest Descent\\n');\noptions.Method = 'csd';\nminFunc(@LogisticLoss,w_init,options,X,y);\npause;\n\nfprintf('\\nRunning Conjugate Gradient\\n');\noptions.Method = 'cg';\nminFunc(@LogisticLoss,w_init,options,X,y);\npause;\n\nfprintf('\\nRunning Scaled Conjugate Gradient\\n');\noptions.Method = 'scg';\nminFunc(@LogisticLoss,w_init,options,X,y);\npause;\n\nfprintf('\\nRunning Preconditioned Conjugate Gradient (Diagonal preconditioner)\\n');\noptions.Method = 'pcg';\noptions.precFunc = @LogisticDiagPrecond;\nminFunc(@LogisticLoss,w_init,options,X,y);\npause;\n\nfprintf('\\nRunning Preconditioned Conjugate Gradient (L-BFGS preconditioner)\\n');\noptions.Method = 'pcg';\noptions.precFunc = [];\nminFunc(@LogisticLoss,w_init,options,X,y);\npause;\n\nfprintf('\\nRunning Hessian-Free Newton w/ numerical Hessian-Vector products\\n');\noptions.Method = 'newton0';\nminFunc(@LogisticLoss,w_init,options,X,y);\npause;\n\nfprintf('\\nRunning Preconditioned Hessian-Free Newton w/ numerical Hessian-Vector products (Diagonal preconditioner)\\n');\noptions.Method = 'pnewton0';\noptions.precFunc = @LogisticDiagPrecond;\nminFunc(@LogisticLoss,w_init,options,X,y);\npause;\n\nfprintf('\\nRunning Preconditioned Hessian-Free Newton w/ numerical Hessian-Vector products (L-BFGS preconditioner)\\n');\noptions.Method = 'pnewton0';\noptions.precFunc = [];\nminFunc(@LogisticLoss,w_init,options,X,y);\npause;\n\nfprintf('\\nRunning Hessian-Free Newton w/ analytic Hessian-Vector products\\n');\noptions.Method = 'newton0';\noptions.HvFunc = @LogisticHv;\nminFunc(@LogisticLoss,w_init,options,X,y);\npause;\n\nfprintf('\\nRunning Preconditioned Hessian-Free Newton w/ analytic Hessian-Vector products (Diagonal preconditioner)\\n');\noptions.Method = 'pnewton0';\noptions.HvFunc = @LogisticHv;\noptions.precFunc = @LogisticDiagPrecond;\nminFunc(@LogisticLoss,w_init,options,X,y);\npause;\n\nfprintf('\\nRunning Preconditioned Hessian-Free Newton w/ analytic Hessian-Vector products (L-BFGS preconditioner)\\n');\noptions.Method = 'pnewton0';\noptions.precFunc = [];\noptions.HvFunc = @LogisticHv;\nminFunc(@LogisticLoss,w_init,options,X,y);\npause;", "meta": {"author": "zouchuhang", "repo": "LayoutNet", "sha": "95293bfb8ff787dd3b02c8a52a147a703024980f", "save_path": "github-repos/MATLAB/zouchuhang-LayoutNet", "path": "github-repos/MATLAB/zouchuhang-LayoutNet/LayoutNet-95293bfb8ff787dd3b02c8a52a147a703024980f/matlab/minFunc_2012/logisticExample/example_minFunc_LR.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768541530197, "lm_q2_score": 0.7905303137346446, "lm_q1q2_score": 0.7464004247345764}} {"text": "function K=kronSym(A,B)\n%%KRONSYM Take the symmetric Kronecker product of the matrices A and B. The\n% standard Kronecker product of two real, square matrices A and B,\n% one can write the following relation with respect to any real\n% square matrix S:\n% kron(A,B)*vec(S)==vec(B*S*A')\n% However, the symmetric Kronecker product is such that for any two\n% real square matrices A and B and a square SYMMETRIC matrix S, one\n% can write\n% kronSym(A,B)*vech(S,sqrt(2))==vech((1/2)*(B*S*A'+A*S*B'),sqrt(2))\n% Whereas is A and B are nXn, the standard kronecker product is\n% n^2Xn^2, the symmetric Kronecker product is\n% (n*(n+1)/2)X(n*(n+1)/2).\n%\n%INPUTS: A, B Two real nXn matrices. They need not be square.\n%\n%OUTPUTS: K The (n*(n+1)/2)X(n*(n+1)/2) symmetric Kronecker product of A\n% and B.\n%\n%Symmetric Kronecker products are discussed in the appendix of [1], where\n%they play a role in the implementation of a semidefinite programming\n%algorithm.\n%\n%The symmetric Kronecker product is implemented by noting that in the\n%identity\n%kronSym(A,B)*vech(S,sqrt(2))==vech((1/2)*(B*S*A'+A*S*B'),sqrt(2)), if S is\n%a symmetric matrix where on or below the main diagonal there is only a\n%single nonzero element, then one effectively selects a column of\n%kronSym(A,B). To get an unscaled column of kronSym(A,B), the nonzero\n%element should be 1 if it is on the main diagonal and it should be\n%1/sqrt(2) for elements below (and above) the main diagonal due to the\n%sqrt(2) scaling in the vech command. Basically, a simple implementation\n%would be \n% n=size(A,1);\n% prodDim=n*(n+1)/2;\n% \n% K=zeros(prodDim,prodDim);\n% SelMat=zeros(n,n);\n% for curEl=1:prodDim\n% [row,col]=vechInd2Sub(n,curEl);\n% if(row==col)\n% SelMat(row,col)=1;\n% else%row>col\n% SelMat(row,col)=1/sqrt(2);\n% SelMat(col,row)=1/sqrt(2);\n% end\n% K(:,curEl)=vech((1/2)*(B*SelMat*A'+A*SelMat*B'),sqrt(2));\n% \n% SelMat(row,col)=0;\n% SelMat(col,row)=0;\n% end\n%However, that is rather slow. Thus, this implementation tries to directly\n%write the elements of the output matrix K. \n%\n%REFERENCES:\n%[1] F. Alizadeh, J.-P. A. Haeberly, and M. L. Overton, \"Primal-dual\n% interior-point methods for semidefinite programming: Convergence\n% rates, stability and numerical results,\" SIAM Journal on Optimization,\n% vol. 8, no. 3, pp. 746-768, 1998.\n%\n%February 2016 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\n%The columns of K are indexed using (i1,i2) and the rows are indexed using\n%(j1,j2).\nn=size(A,1);\nprodDim=n*(n+1)/2;\n\nK=zeros(prodDim,prodDim);\nsqrt2=sqrt(2);\ndblSqrt2=2*sqrt2;\nfor i1=1:n\n col=i1+(i1-1)*(2*n-i1)/2;\n for j1=1:n\n row=j1+(j1-1)*(2*n-j1)/2;\n \n K(row,col)=(A(j1,i1)*B(j1,i1)+B(j1,i1)*A(j1,i1))/2;\n for j2=(j1+1):n\n row=row+1;\n \n K(row,col)=(A(j1,i1)*B(j2,i1)+B(j1,i1)*A(j2,i1))/sqrt2;\n end\n end\n \n for i2=(i1+1):n\n col=col+1;\n for j1=1:n\n row=j1+(j1-1)*(2*n-j1)/2;\n \n K(row,col)=(A(j1,i1)*B(j1,i2)+A(j1,i2)*B(j1,i1)+B(j1,i1)*A(j1,i2)+B(j1,i2)*A(j1,i1))/dblSqrt2; \n for j2=(j1+1):n\n row=row+1;\n \n K(row,col)=(A(j1,i1)*B(j2,i2)+A(j1,i2)*B(j2,i1)+B(j1,i1)*A(j2,i2)+B(j1,i2)*A(j2,i1))/2;\n end\n end\n end\nend\nend\n\n%LICENSE:\n%\n%The source code is in the public domain and not licensed or under\n%copyright. The information and software may be used freely by the public.\n%As required by 17 U.S.C. 403, third parties producing copyrighted works\n%consisting predominantly of the material produced by U.S. government\n%agencies must provide notice with such work(s) identifying the U.S.\n%Government material incorporated and stating that such material is not\n%subject to copyright protection.\n%\n%Derived works shall not identify themselves in a manner that implies an\n%endorsement by or an affiliation with the Naval Research Laboratory.\n%\n%RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF THE\n%SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY THE NAVAL\n%RESEARCH LABORATORY FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE ACTIONS\n%OF RECIPIENT IN THE USE OF THE SOFTWARE.\n", "meta": {"author": "USNavalResearchLaboratory", "repo": "TrackerComponentLibrary", "sha": "9f6e329de5be06a371757c4b853200beb6def2d0", "save_path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary", "path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary/TrackerComponentLibrary-9f6e329de5be06a371757c4b853200beb6def2d0/Mathematical_Functions/Basic_Matrix_Operations/kronSym.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772318846386, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.7463857002453699}} {"text": "function linplus_test195 ( )\n\n%*****************************************************************************80\n%\n%% TEST195 tests R8CI_EVAL.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 14 March 2009\n%\n% Author:\n%\n% John Burkardt\n%\n n = 5;\n seed = 123456789;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TEST195\\n' );\n fprintf ( 1, ' R8CI_EVAL finds the eigenvalues of\\n' );\n fprintf ( 1, ' a real circulant system.\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Matrix order N = %d\\n', n );\n%\n% Set the matrix.\n%\n [ a, seed ] = r8ci_random ( n, seed );\n\n r8ci_print ( n, a, ' The circulant matrix:' );\n\n lambda = r8ci_eval ( n, a );\n\n c8vec_print ( n, lambda, ' The eigenvalues:' );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/linplus/linplus_test195.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8740772417253255, "lm_q2_score": 0.8539127473751341, "lm_q1q2_score": 0.7463856988997519}} {"text": "function m = nanmean(x,dim)\n%NANMEAN Mean value, ignoring NaNs.\n% M = NANMEAN(X) returns the sample mean of X, treating NaNs as missing\n% values. For vector input, M is the mean value of the non-NaN elements\n% in X. For matrix input, M is a row vector containing the mean value of\n% non-NaN elements in each column. For N-D arrays, NANMEAN operates\n% along the first non-singleton dimension.\n%\n% NANMEAN(X,DIM) takes the mean along dimension DIM of X.\n%\n% See also MEAN, NANMEDIAN, NANSTD, NANVAR, NANMIN, NANMAX, NANSUM.\n\n% Copyright 1993-2004 The MathWorks, Inc.\n% $Revision: 1.1.8.1 $ $Date: 2010/03/16 00:15:50 $\n\n% Find NaNs and set them to zero\nnans = isnan(x);\nx(nans) = 0;\n\nif nargin == 1 % let sum deal with figuring out which dimension to use\n % Count up non-NaNs.\n n = sum(~nans);\n n(n==0) = NaN; % prevent divideByZero warnings\n % Sum up non-NaNs, and divide by the number of non-NaNs.\n m = sum(x) ./ n;\nelse\n % Count up non-NaNs.\n n = sum(~nans,dim);\n n(n==0) = NaN; % prevent divideByZero warnings\n % Sum up non-NaNs, and divide by the number of non-NaNs.\n m = sum(x,dim) ./ n;\nend\n\n", "meta": {"author": "marianux", "repo": "ecg-kit", "sha": "c8e3de47c54a9214138143676d2aa546b0540dd2", "save_path": "github-repos/MATLAB/marianux-ecg-kit", "path": "github-repos/MATLAB/marianux-ecg-kit/ecg-kit-c8e3de47c54a9214138143676d2aa546b0540dd2/common/wavedet/nanmean.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772351648677, "lm_q2_score": 0.8539127529517044, "lm_q1q2_score": 0.7463856981720465}} {"text": "function s_factor_cell = generate_s_factor(omega, grid3d, m, R)\n% For example, s_factor_cell{Axis.x, GT.dual} is the s-factor multiplied to Ex\n% (or eps_ww).\n\nchkarg(istypesizeof(omega, 'complex'), '\"omega\" should be complex.');\nchkarg(istypesizeof(grid3d, 'Grid3d'), '\"grid3d\" should be instance of Grid3d.');\n\nif nargin < 3 % no m\n\tm = 4;\nend\nchkarg(istypeof(m, 'real') && all(m(:) >= 1), 'element of \"m\" should be real and at least 1.0.');\nchkarg(isexpandable2mat(m, Axis.count, Sign.count), ...\n\t'\"m\" should be scalar, length-%d vector, or %d-by-%d matrix.', Axis.count, Axis.count, Sign.count);\nm = expand2mat(m, Axis.count, Sign.count);\n\nif nargin < 4 % no R\n\tR = exp(-16); % R = exp(-16) ~= 1e-7\nend\nchkarg(istypeof(R, 'real') && all(R(:) > 0) && all(R(:) <= 1), ...\n\t'element of \"R\" should be real and between 0.0 and 1.0.');\nchkarg(isexpandable2mat(R, Axis.count, Sign.count), ...\n\t'\"R\" should be scalar, length-%d vector, or %d-by-%d matrix.', Axis.count, Axis.count, Sign.count);\nR = expand2mat(R, Axis.count, Sign.count);\nlnR = log(R); % log() is the natural logarithm\n\ns_factor_cell = cell(Axis.count, GT.count);\nfor w = Axis.elems\n\tNw = grid3d.N(w);\n\n\tlpml = grid3d.lpml(w,:); % locations of PML interfaces\n\tLpml = grid3d.Lpml(w,:); % thicknesses of PML\n\n\tfor g = GT.elems\n\t\tl = grid3d.l{w, g}; % length(l) == Nw, rather than Nw+1.\n\t\tind_pml = {l < lpml(Sign.n), l > lpml(Sign.p)}; % indices of locatiotns indise PML\n\n\t\ts_factor = ones(1, Nw);\n\t\tfor s = Sign.elems\n\t\t\ts_factor(ind_pml{s}) = calc_s_factor(omega, abs(lpml(s) - l(ind_pml{s})), Lpml(s), m(w,s), lnR(w,s));\n\t\tend\n\t\t\t\t\n\t\ts_factor_cell{w,g} = s_factor;\n\tend\t\nend\n\n\nfunction s_factor = calc_s_factor(omega, depth, Lpml, m, lnR)\n% assert(Lpml > 0);\n\nsigma_max = -(m+1) * lnR/(2*Lpml); % -(m+1) ln(R)/(2 eta Lpml), where eta = 1 in the unit of eta_0\nsigma = sigma_max * (depth/Lpml).^m;\n\nkappa_max = 1;\nkappa = 1 + (kappa_max-1) * (depth/Lpml).^m;\n\nma = m;\namax = 0;\na = amax * (1 - depth/Lpml).^ma;\n\ns_factor = kappa + sigma ./ (a + 1i*omega); % s = kappa + sigma/(a + i omega eps), where eps = 1 in the unit of eps_0\n", "meta": {"author": "wsshin", "repo": "maxwellfdfd", "sha": "f7d583813781694c8a6f0533a91f56c2a78a9ee5", "save_path": "github-repos/MATLAB/wsshin-maxwellfdfd", "path": "github-repos/MATLAB/wsshin-maxwellfdfd/maxwellfdfd-f7d583813781694c8a6f0533a91f56c2a78a9ee5/io/generate_s_factor.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.89330940889474, "lm_q2_score": 0.8354835452961425, "lm_q1q2_score": 0.7463453119897788}} {"text": "function [C, sigma] = dataset3Params(X, y, Xval, yval)\n %% EX6PARAMS returns your choice of C and sigma for Part 3 of the exercise\n %where you select the optimal (C, sigma) learning parameters to use for SVM\n %with RBF kernel\n % [C, sigma] = EX6PARAMS(X, y, Xval, yval) returns your choice of C and \n % sigma. You should complete this function to return the optimal C and \n % sigma based on a cross-validation set.\n %\n\n % ====================== YOUR CODE HERE ======================\n % Instructions: Fill in this function to return the optimal C and sigma\n % learning parameters found using the cross validation set.\n % You can use svmPredict to predict the labels on the cross\n % validation set. For example, \n % predictions = svmPredict(model, Xval);\n % will return the predictions on the cross validation set.\n %\n % Note: You can compute the prediction error using \n % mean(double(predictions ~= yval))\n %\n c_values = [0.01, 0.03, 0.1, 0.3, 1, 3, 10, 30];\n sigma_values = c_values(:);\n best_accuracy = 0.0;\n \n for i = 1 : length(c_values)\n \n for j = 1 : length(sigma_values)\n \n % test this grid entry on our validation set \n test_C = c_values(i);\n test_sigma = sigma_values(j);\n model = svmTrain(X, y, test_C, @(x1, x2) gaussianKernel(x1, x2, test_sigma));\n predictions = svmPredict(model, Xval);\n accuracy = sum(predictions == yval) / length(yval);\n \n % is this the best performing so far?\n if accuracy > best_accuracy\n best_accuracy = accuracy;\n C = test_C;\n sigma = test_sigma;\n end\n end \n end\n \n fprintf('Best hyperparameters were C = %f, sigma = %f => best cv acc = %f\\n', ...\n C, sigma, best_accuracy);\n \nend\n", "meta": {"author": "worldveil", "repo": "coursera-ml", "sha": "94e205b01ec3a47c0d777943194d12fa130f4685", "save_path": "github-repos/MATLAB/worldveil-coursera-ml", "path": "github-repos/MATLAB/worldveil-coursera-ml/coursera-ml-94e205b01ec3a47c0d777943194d12fa130f4685/svm/code/dataset3Params.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093946927837, "lm_q2_score": 0.8354835432479661, "lm_q1q2_score": 0.7463452982946228}} {"text": "function [xpeak, ypeak, max_f] = findpeak(f,subpixel)\n%FINDPEAK Find extremum of matrix.\n% [XPEAK,YPEAK,MAX_F] = FINDPEAK(F,SUBPIXEL) finds the extremum of F,\n% MAX_F, and its location (XPEAK, YPEAK). F is a matrix. MAX_F is the maximum\n% absolute value of F, or an estimate of the extremum if a subpixel\n% extremum is requested.\n%\n% SUBPIXEL is a boolean that controls if FINDPEAK attempts to estimate the\n% extremum location to subpixel precision. If SUBPIXEL is false, FINDPEAK\n% returns the coordinates of the maximum absolute value of F and MAX_F is\n% max(abs(F(:))). If SUBPIXEL is true, FINDPEAK fits a 2nd order\n% polynomial to the 9 points surrounding the maximum absolute value of\n% F. In this case, MAX_F is the absolute value of the polynomial evaluated\n% at its extremum.\n%\n% Note: Even if SUBPIXEL is true, there are some cases that result\n% in FINDPEAK returning the coordinates of the maximum absolute value\n% of F:\n% * When the maximum absolute value of F is on the edge of matrix F.\n% * When the coordinates of the estimated polynomial extremum would fall\n% outside the coordinates of the points used to constrain the estimate.\n\n% Copyright 1993-2004 The MathWorks, Inc.\n% \n\n% get absolute peak pixel\n[max_f, imax] = max(abs(f(:)));\n[ypeak, xpeak] = ind2sub(size(f),imax(1));\n \nif ~subpixel || ...\n xpeak==1 || xpeak==size(f,2) || ypeak==1 || ypeak==size(f,1) % on edge\n return % return absolute peak\n \nelse\n % fit a 2nd order polynomial to 9 points \n % using 9 pixels centered on irow,jcol \n u = f(ypeak-1:ypeak+1, xpeak-1:xpeak+1);\n u = u(:);\n x = [-1 -1 -1 0 0 0 1 1 1]';\n y = [-1 0 1 -1 0 1 -1 0 1]'; \n\n % u(x,y) = A(1) + A(2)*x + A(3)*y + A(4)*x*y + A(5)*x^2 + A(6)*y^2\n X = [ones(9,1), x, y, x.*y, x.^2, y.^2];\n \n % u = X*A\n A = X\\u;\n\n % get absolute maximum, where du/dx = du/dy = 0\n x_offset = (-A(3)*A(4)+2*A(6)*A(2)) / (A(4)^2-4*A(5)*A(6));\n y_offset = -1 / ( A(4)^2-4*A(5)*A(6))*(A(4)*A(2)-2*A(5)*A(3));\n\n if abs(x_offset)>1 || abs(y_offset)>1\n % adjusted peak falls outside set of 9 points fit,\n return % return absolute peak\n end\n \n % return only one-tenth of a pixel precision\n x_offset = round(10*x_offset)/10;\n y_offset = round(10*y_offset)/10; \n \n xpeak = xpeak + x_offset;\n ypeak = ypeak + y_offset; \n \n % Calculate extremum of fitted function\n max_f = [1 x_offset y_offset x_offset*y_offset x_offset^2 y_offset^2] * A;\n max_f = abs(max_f);\n \nend\n", "meta": {"author": "zhouyuanzxcv", "repo": "Hyperspectral", "sha": "f32dcca86677f8d37596376f57e9c733058f8cff", "save_path": "github-repos/MATLAB/zhouyuanzxcv-Hyperspectral", "path": "github-repos/MATLAB/zhouyuanzxcv-Hyperspectral/Hyperspectral-f32dcca86677f8d37596376f57e9c733058f8cff/REG/reg_fft/findpeak.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588052782737, "lm_q2_score": 0.8397339676722393, "lm_q1q2_score": 0.7463209578599639}} {"text": "function area = polygonArea3d(poly, varargin)\n%POLYGONAREA3D Area of a 3D polygon\n%\n% AREA = polygonArea3d(POLY)\n% POLY is given as a N-by-3 array of vertex coordinates. The resulting\n% area is positive.\n% Works also for polygons given as a cell array of polygons.\n%\n% Example\n% % area of a simple 3D square \n% poly = [10 30 20;20 30 20;20 40 20;10 40 20];\n% polygonArea3d(poly)\n% ans =\n% 100\n%\n% % Area of a 3D mesh\n% [v f] = createCubeOctahedron;\n% polygons = meshFacePolygons(v, f);\n% areas = polygonArea3d(polygons);\n% sum(areas)\n% ans =\n% 18.9282\n%\n% See also\n% polygons3d, triangleArea3d, polygonArea, polygonCentroid3d\n\n% ------\n% Author: David Legland\n% e-mail: david.legland@grignon.inra.fr\n% Created: 2012-02-24, using Matlab 7.9.0.529 (R2009b)\n% Copyright 2012 INRA - Cepia Software Platform.\n\n% HISTORY\n% 2013-08-20 add support for multiple polygons\n\n% Check multiple polygons\nif iscell(poly) || sum(sum(isnan(poly))) > 0\n % split the polygons into a cell array\n polygons = splitPolygons3d(poly);\n nPolys = length(polygons);\n \n % compute area of each polygon\n area = zeros(nPolys, 1);\n for i = 1:nPolys\n area(i) = polygonArea3d(polygons{i});\n end\n \n return;\nend\n\n% put the first vertex at origin (reducing computation errors for polygons\n% far from origin)\nv0 = poly(1, :);\npoly = bsxfun(@minus, poly, v0);\n\n% indices of next vertices\nN = size(poly, 1);\niNext = [2:N 1];\n\n% compute cross-product of each elementary triangle formed by origin and\n% two consecutive vertices\ncp = cross(poly, poly(iNext,:), 2);\n\n% choose one of the triangles as reference for the normal direction\nvn = vectorNorm(cp);\n[tmp, ind] = max(vn); %#ok\ncpRef = cp(ind,:);\n\n% compute the sign of the area of each triangle\n% (need to compute the sign explicitely, as the norm of the cross product\n% does not keep orientation within supporting plane)\nsign_i = sign(dot(cp, repmat(cpRef, N, 1), 2));\n\n% compute area of each triangle, using sign correction\narea_i = vectorNorm3d(cp) .* sign_i;\n\n% sum up individual triangles area\narea = sum(area_i) / 2;\n", "meta": {"author": "rpng", "repo": "lips", "sha": "a97157e586b509c9c2e3e01e64e4347f36d0b63e", "save_path": "github-repos/MATLAB/rpng-lips", "path": "github-repos/MATLAB/rpng-lips/lips-a97157e586b509c9c2e3e01e64e4347f36d0b63e/lips_matlab/matlab/functions/matGeom/geom3d/polygonArea3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588052782736, "lm_q2_score": 0.8397339676722393, "lm_q1q2_score": 0.7463209578599638}} {"text": "function [ Velocity_top_lid ] = CreateLidVelocity( alpha,N )\n%CREATEALPHAINPUT creates a parabolic velcoity input on the top lid with\n%amplitude alpha\n\n% form the grid if not already done it\npersistent Grid \n\nif isempty(Grid)\n [Grid]=CollocationGrid_q(N); % the computational grid\nend\n\nVelocity_top_lid = alpha*(1-Grid.x.^2).^2;\n\nend\n\n", "meta": {"author": "arbabiha", "repo": "KoopmanMPC_for_flowcontrol", "sha": "4581c284bed5420fee7a7e9a58590fe93a196c97", "save_path": "github-repos/MATLAB/arbabiha-KoopmanMPC_for_flowcontrol", "path": "github-repos/MATLAB/arbabiha-KoopmanMPC_for_flowcontrol/KoopmanMPC_for_flowcontrol-4581c284bed5420fee7a7e9a58590fe93a196c97/thehood/CreateLidVelocity.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8887587993853655, "lm_q2_score": 0.8397339716830606, "lm_q1q2_score": 0.7463209564761415}} {"text": "%% OPT01_RUN\n%\n% Modified:\n%\n% 09 January 2008\n%\n %---------------------------------------------------------------------\n % Running the first testcase, from D+S, pp. 100, 202; x_* = [2;-1].\n % This should finish in 10 iterations for Newton's method and in\n % 12 iterations for BFGS.\n %---------------------------------------------------------------------\n\n fprintf('---------------------------------------------------------\\n')\n fprintf('Running testcase_1: exact solution (2,-1)\\n')\n fprintf('---------------------------------------------------------\\n')\n\n fname = 'opt01_fgh';\n\n options = [];\n options.verbose = 0;\n options.step_tolerance = 1.e-11;\n options.gradient_tolerance = 1.e-11;\n options.max_iterations = 15;\n\n x0 = [ 1; 1];\n%\n% Run with Newton method.\n% \n fprintf('Newton method:\\n')\n options.method = 'newton';\n options.globalization = 'none';\n\n x = entrust(fname, x0, options);\n\n fprintf('Newton method produced (%10.7e,%10.7e)\\n\\n',x(1),x(2))\n f = opt01_fgh ( x, 'f' );\n fprintf('Value of F(X) = %f\\n', f );\n%\n% Run with secant method.\n% \n fprintf('Secant method:\\n')\n options.method = 'secant';\n options.initial_hessian = [ 14., -4. ; -4. 4. ];\n x = entrust(fname, x0, options);\n fprintf('BFGS method produced (%10.7e,%10.7e)\\n\\n',x(1),x(2))\n f = opt01_fgh ( x, 'f' );\n fprintf('Value of F(X) = %f\\n', f );\n %---------------------------------------------------------------------\n % Test Gauss-Newton strategies.\n %---------------------------------------------------------------------\n fprintf('---------------------------------------------------------\\n')\n fprintf('Running testcase_1 as least squares problem: \\n')\n fprintf('Exact solution (2,-1)\\n')\n fprintf('---------------------------------------------------------\\n')\n\n fname = 'opt01_rj';\n options = [];\n options.verbose = 0;\n options.method = 'gauss_newton';\n options.step_tolerance = 1.e-15;\n options.globalization = 'none';\n options.gradient_tolerance = 1.e-10;\n options.max_iterations = 40;\n\n x0 = [1,1]; \n\n x = entrust(fname, x0, options );\n\n fprintf('Gauss-Newton produced (%10.7e, %10.7e)\\n\\n',x(1),x(2))\n [ res, jac ] = opt01_rj ( x, 'f' );\n fprintf('Norm of RES(X) = %f\\n', norm ( res ) );\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/entrust/opt01_run.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853655, "lm_q2_score": 0.8397339676722393, "lm_q1q2_score": 0.7463209529114887}} {"text": "function cpu_timing ( n )\n\n%*****************************************************************************80\n%\n%% CPU_TIMING measures execution time with CPUTIME.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 14 March 2008\n%\n% Author:\n%\n% John Burkardt\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'CPU_TIMING:\\n' );\n fprintf ( 1, ' MATLAB has a built in command called CPUTIME,\\n' );\n fprintf ( 1, ' which measures the CPU time elapsed so far.\\n' );\n fprintf ( 1, ' The difference of two readings measures the work done lately.\\n' );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TASK #1:\\n' )\n fprintf ( 1, ' Multiply two random dense matices of order N\\n' );\n fprintf ( 1, ' using MATLAB''s A*B operation.\\n' );\n \n A = rand ( n, n );\n B = rand ( n, n );\n\n t1 = cputime ( );\n C = A * B;\n t2 = cputime ( );\n\n f = n * n * n;\n w = f / 1000000;\n s = t2 - t1;\n r = w / s;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' MegaFLOPs = %d\\n', w );\n fprintf ( 1, ' Elapsed CPU time = %f\\n', s );\n fprintf ( 1, ' Rate = %f\\n', r );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TASK #2:\\n' )\n fprintf ( 1, ' Multiply two random dense matices of order N\\n' );\n fprintf ( 1, ' using explicit loops.\\n' );\n \n A = rand ( n, n );\n B = rand ( n, n );\n\n t1 = cputime ( );\n for i = 1 : n\n for k = 1 : n\n C(i,k) = 0;\n for j = 1 : n\n C(i,k) = C(i,k) + A(i,j) * B(j,k);\n end\n end\n end\n t2 = cputime ( );\n\n f = n * n * n;\n w = f / 1000000;\n s = t2 - t1;\n r = w / s;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' MegaFLOPs = %d\\n', w );\n fprintf ( 1, ' Elapsed CPU time = %f\\n', s );\n fprintf ( 1, ' Rate = %f\\n', r );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/matlab/cpu_timing.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587817066391, "lm_q2_score": 0.8397339716830606, "lm_q1q2_score": 0.7463209416307144}} {"text": "% ****** See nozzle.m for instructions ******\n% Program to extrapolate the data points from nozzle design and make a\n% uniform grid spacing in the x-direction\n% Change nothing... simply run this script\n\n\n% Find the minimum spacing given by the method of characteristics\n% and set as the dx value\ndx = 0;\nfor i=1: size(noz,1)-1\n len = noz(i+1,1) - noz(i,1);\n if (len < dx || i == 1)\n dx = len;\n end\nend\n\n% Explicitly give the dx value here\ndx = max(noz(:,1))/ceil(max(noz(:,1))/dx);\nn = max(noz(:,1))/dx;\n\n% len = max(noz(:,1));\n% n = 50; % Note # of points is actually n+1 \n% dx = len/n\n\n% Pick m points in y as some factor of x points\nyfactor = .8;\nm = ceil(yfactor*n);\n\n% Make uniform x-distribution of points\nxmax = 0;\ni = 1;\nwhile xmax < max(noz(:,1))\n xmax = dx*(i-1);\n x(i,1:m) = xmax;\n i = i+1;\nend\n\n\n% Make the y-points and extrapolate linearly from closest points to fit\n% the nozzle geometry\n\n% Initialize and assign last value\ny(1:size(x,1),1:size(x,2)) = 0;\ny(1,size(y,2)) = noz(1,size(noz,2));\ny(size(y,1),size(y,2)) = noz(size(noz,1),size(noz,2));\nfor i = 1 : size(x,1)-1\n \n j = 1;\n while x(i,1) >= noz(j,1)\n x1 = noz(j,1);\n x2 = noz(j+1,1);\n y1 = noz(j,2);\n y2 = noz(j+1,2);\n j = j + 1;\n end\n \n slope = (y2 - y1)/(x2 - x1);\n y(i,size(y,2)) = y1 + slope*(x(i,1)-x1);\n \n %Fill in mesh\n dy = y(i,size(y,2))/(size(y,2)-1);\n for k = 1: size(y,2)\n y(i,k) = dy*(k-1);\n end\n \nend\n\n%Fill in mesh\ndy = y(size(y,1),size(y,2))/(size(y,2)-1);\nfor k = 1: size(y,2)\n y(size(y,1),k) = dy*(k-1);\nend\n \n'Mesh done'\n\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/14682-2-d-nozzle-design/noz_mesh.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896824119663, "lm_q2_score": 0.8104789086703225, "lm_q1q2_score": 0.7462806169161433}} {"text": "function cvx_optval = det_rootn( X )\n\n%DET_ROOTN nth-root of the determinant of an SPD matrix.\n% For a square matrix X, DET_ROOTN(X) returns\n% POW(DET(X),1/(size(X,1))\n% if X is symmetric (real) or Hermitian (complex) and positive semidefinite,\n% and -Inf otherwise.\n%\n% This function can be used in many convex optimization problems that call for\n% LOG(DET(X)) instead. For example, if the objective function contains nothing\n% but LOG(DET(X)), it can be replaced with DET_ROOTN(X), and the same optimal \n% point will be produced.\n%\n% Disciplined convex programming information:\n% DET_ROOTN is concave and nonmonotonic; therefore, when used in\n% CVX specifications, its argument must be affine.\n\nerror( nargchk( 1, 1, nargin ) );\nif ndims( X ) > 2 || size( X, 1 ) ~= size( X, 2 ),\n error( 'Second argument must be a square matrix.' );\nend\nerr = X - X';\nX = 0.5 * ( X + X' );\nif norm( err, 'fro' ) > 8 * eps * norm( X, 'fro' ),\n cvx_optval = -Inf;\nelse\n [R,p] = chol(X);\n if p > 0,\n cvx_optval = geo_mean(eig(full(X)));\n else\n cvx_optval = geo_mean(diag(R)).^2;\n end\nend\n\n% Copyright 2010 Michael C. Grant and Stephen P. Boyd. \n% See the file COPYING.txt for full copyright information.\n% The command 'cvx_where' will show where this file is located.\n", "meta": {"author": "goodshawn12", "repo": "REST", "sha": "e34ce521fcb36e7813357a9720072dd111edf797", "save_path": "github-repos/MATLAB/goodshawn12-REST", "path": "github-repos/MATLAB/goodshawn12-REST/REST-e34ce521fcb36e7813357a9720072dd111edf797/dependencies/BCILAB/dependencies/cvx-1.21.b795/functions/det_rootn.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896845856297, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.7462806123551733}} {"text": "function yc = pwl_approx_1d ( nd, xd, yd, nc, xc )\n\n%*****************************************************************************80\n%\n%% PWL_APPROX_1D determines the control values for a PWL approximant.\n%\n% Discussion:\n%\n% The piecewise linear approximant is defined by NC control pairs \n% (XC(I),YC(I)) and approximates ND data pairs (XD(I),YD(I)).\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 10 October 2012\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer ND, the number of data points.\n% ND must be at least 1.\n%\n% Input, real XD(ND,1), the data points.\n%\n% Input, real YD(ND,1), the data values.\n%\n% Input, integer NC, the number of control points.\n% NC must be at least 1.\n%\n% Input, real XC(NC,1), the control points.\n%\n% Output, real YC(NC,1), the control values.\n%\n\n%\n% Define the NDxNC linear system that determines the control values.\n%\n a = pwl_approx_1d_matrix ( nd, xd, yd, nc, xc );\n%\n% Solve the system.\n%\n yc = a \\ yd;\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/pwl_approx_1d/pwl_approx_1d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896802383028, "lm_q2_score": 0.8104788995148791, "lm_q1q2_score": 0.746280606724197}} {"text": "% peq.m - Parametric EQ with matching gain at Nyquist frequency\n% Author: Sophocles J. Orfanidis, \n% Usage: [b, a] = peq(G0, G, w0, Dw, NdB)\n%\n% G0 = reference gain at DC in dB\n% G = boost/cut gain in dB\n% GB = bandwidth gain in dB\n%\n% w0 = center frequency in Hz\n% Dw = bandwidth in Hz\n% NdB = amount of db less than the peak/notch gain as the bandwidth frequencies \n% b = [b0, b1, b2] = numerator coefficients\n% a = [1, a1, a2] = denominator coefficients\n\n% Modified by Arvind using the equations from IIR Filter Design Chapter in\n% the book\nfunction [b, a, beta] = peq(G0, G, w0, Dw, NdB)\n\n%Convert from Decibels to real values\nGB = G * NdB;\nG = (10^(G/20));\nGB = (10^(GB/20));\nG0 = (10^(G0/20));\n\n%Convert absolute frequencies to rads/sec\n%w0 = w0*2*pi/fs;\n%Dw = Dw*2*pi/fs;\n\nbeta = sqrt((GB^2-G0^2)/(G^2-GB^2)) * tan(Dw/2);\nb = [(G0+G*beta)/(1+beta) -(2*G0*cos(w0))/(1+beta) (G0-G*beta)/(1+beta)];\na = [1 -(2*cos(w0))/(1+beta) (1-beta)/(1+beta)];\n\n\n%***********************\n% double beta;\n% \n% beta = sqrt((GB[0]^2-G0[0]^2)/(G^2[0]-GB[0]^2)) * tan(Dw[0]/2)\n% Num[0] = (G0[0]+G[0]*beta)/(1+beta);\n% Num[1] = -(2*G0[0]*cos(w0[0]))/(1+beta) ;\n% Num[2] = (G0[0]-G[0]*beta)/(1+beta);\n% \n% Den[0] = 1;\n% Den[1] = -(2*cos(w0[0]))/(1+beta);\n% Den[2] = (1-beta)/(1+beta);\n%*************************\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/1963-3-band-parametric-equalizer/peq.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037262250325, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.7462600986201664}} {"text": "%% Transform Compression JPEG\n\n% JPEG Baseline Encoder\n\n% Jorge Calderon \n% University Of Antioquia\n% Created: November 2012\n% Modified: January 2013\n% Copyright 2012\n% All rights reserved\n\n%% Clean Workplace\n\nclear all;\nclose all;\nclc;\n\n%% Initialize Variables\n\ncheck = 0;\nstream=[];\n\nDCTQ=[...\n 16 11 10 16 24 40 51 61;...\n 12 12 14 19 26 58 60 55;...\n 14 13 16 24 40 57 69 56;...\n 14 17 22 29 51 87 80 62;...\n 18 22 37 56 68 109 103 77;...\n 24 36 55 64 81 194 113 92;...\n 49 64 78 87 103 121 120 101;...\n 72 92 95 98 112 100 103 99];\n\nz=[...\n 9 2 3 10 17 25 18 11 4 5 12 19 26 ...\n 33 41 34 27 20 13 6 7 14 21 28 35 ...\n 42 49 57 50 43 36 29 22 15 8 16 23 ...\n 30 37 44 51 58 59 52 45 38 31 24 32 ...\n 39 46 53 60 61 54 47 40 48 55 62 63 56 64];\n\n%% Read Image\n\nwhile check<1\n [img_in pathname]=uigetfile({'*.bmp;*.tif','Image(*.bmp,*.tif)'},'Select Uncompressed Image','Multiselect','off');\n if img_in>0\n cd(pathname)\n image = double(imread(img_in));\n [row, col, dim] = size(image);\n if col 0, compute and print knots and weights. Print moments check.\n% = 0, compute knots and weights.\n% < 0, compute and print knots and weights.\n%\n% Output, real T(NT), the knots.\n%\n% Output, real WTS(NT), the weights.\n%\n\n%\n% Compute the Gauss quadrature formula.\n%\n [ t, wts ] = cdgqf ( nt, kind, alpha, beta );\n%\n% Exit if no print required.\n%\n if ( lo == 0 )\n return\n end\n\n key = 1;\n mop = 2 * nt;\n m = mop + 1;\n mmex = max ( 2 * nt + 3, 1 );\n%\n% All knots have multiplicity = 1.\n%\n mlt = zeros(nt,1);\n mlt(1:nt) = 1;\n%\n% NDX(I) = I.\n%\n ndx = ( 1 : nt );\n\n w = zeros(m,1);\n\n chkqfs ( t, wts, mlt, nt, nt, ndx, key, mop, mmex, ...\n kind, alpha, beta, lo, w );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/toms655/cgqfs.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070035949657, "lm_q2_score": 0.8198933403143929, "lm_q1q2_score": 0.7460266925529367}} {"text": "function learningConvergence\n\nk = 10;\niter = 1:200;\n\nlblRate = LowerBoundLipshitzFirstOrder(iter);\nlbscRate = lowerBoundStronglyConvexFirstOrder(iter,k);\nsRate = subgradientConvergence(iter);\nnRate = stronglyConvexNesterovConvergence(iter,k);\nqRate = quadraticConvergence(iter,1/k);\nlgRate = LipschitzGradientConvergence(iter);\nscRate = stronglyConvexGradientConvergence(iter,k);\n\ncolors = {\n [0.9290, 0.6940, 0.1250];\t \t\n [0, 0.4470, 0.7410];\n \t[0.8500, 0.3250, 0.0980];\n [0, 0.4470, 0.7410];\n [0.8500, 0.3250, 0.0980];\n \t[0.4940, 0.1840, 0.5560];\t \t\n \t[0.4660, 0.6740, 0.1880];\t \t\n \t[0.3010, 0.7450, 0.9330]};\nstyle = {'-';'--';'--';'-';'-';'-';'-';}; \n\nrates = [sRate;lblRate;lbscRate;lgRate;scRate;nRate;qRate];\n\nfigure(1)\nsubplot(1,2,1);\nhold on\nfor i = 1:size(rates,1)\n plot(iter,rates(i,:),'Color',colors{i},'LineStyle',style{i});\nend\nlegend('Subgradient','LowerBound Lipshitz','LowerBound Strongly Convex', 'Lipschitz Diff Gradient','StronglyConvex Diff Gradient','Strongly Convex Diff Nesterov','Quadratic Diff')\n\nfigure(1)\nsubplot(1,2,2);\nhold on\nfor i = 1:size(rates,1)\nh = plot(iter,rates(i,:),'Color',colors{i},'LineStyle',style{i});\nset(gca,'yscale','log');\nend\n\n\nlegend('Subgradient','LowerBound Lipshitz','LowerBound Strongly Convex', 'Lipschitz Diff Gradient','StronglyConvex Diff Gradient','Strongly Convex Diff Nesterov','Quadratic Diff')\n\n\nend\n\nfunction rate = subgradientConvergence(x)\n\nrate = 1./sqrt(x);\n\nend\n\nfunction rate = LowerBoundLipshitzFirstOrder(x)\n\nrate = 1./(x + 1).^2;\n\nend\n\n\n\nfunction rate = LipschitzGradientConvergence(x)\n\nrate = 1./(x + 1);\n\nend\n\nfunction rate = stronglyConvexGradientConvergence(x,k)\n\nrate = (((k) - 1)/((k)+1)).^(x);\nend\n\n\nfunction rate = quadraticConvergence(x,k)\n\nrate = k.^(2.^x);\n\nend\n\n\nfunction rate = lowerBoundStronglyConvexFirstOrder(x,k)\n\nrate = ((sqrt(k) - 1)/(sqrt(k) + 1)).^(2*x);\n\nend\n\n\nfunction rate = stronglyConvexNesterovConvergence(x,k)\n\nrate = ((sqrt(k) - 1)/(sqrt(k)+1)).^(x);\n\nend", "meta": {"author": "SwanLab", "repo": "Swan", "sha": "f8355f3561bb1a1603f56b3676873147d22a511e", "save_path": "github-repos/MATLAB/SwanLab-Swan", "path": "github-repos/MATLAB/SwanLab-Swan/Swan-f8355f3561bb1a1603f56b3676873147d22a511e/ImageProcessing/Old/learningConvergence.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070084811306, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.746026690552515}} {"text": "function E = bryant2angular(rpy)\n% Jacobian of Omega in terms of rolldot, pitchdot and yawdot\n% \"Bryant Angle Representation\"\n% http://www.u.arizona.edu/~pen/ame553/Hallway/CAAMS/CAAMS_15.pdf\n\nroll = rpy(1); %x-axis\npitch = rpy(2); %y-axis\nyaw = rpy(3); %z-axis\n\n% paul's version\n% E = [ cos(yaw)*cos(pitch), -sin(yaw), 0;\n% sin(yaw)*cos(pitch), cos(yaw), 0;\n% -sin(pitch), 0, 1];\n\n% bryant angle version\nE = [ cos(roll)*cos(yaw), sin(yaw), 0;\n -cos(pitch)*sin(yaw), cos(yaw), 0;\n sin(pitch), 0, 1];\n\nend\n \n\n", "meta": {"author": "rpng", "repo": "lips", "sha": "a97157e586b509c9c2e3e01e64e4347f36d0b63e", "save_path": "github-repos/MATLAB/rpng-lips", "path": "github-repos/MATLAB/rpng-lips/lips-a97157e586b509c9c2e3e01e64e4347f36d0b63e/lips_matlab/matlab/functions/lips/bryant2angular.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.912436167620237, "lm_q2_score": 0.8175744673038222, "lm_q1q2_score": 0.7459845136908564}} {"text": "function value = r8_lgmc ( x )\n\n%*****************************************************************************80\n%\n%% R8_LGMC evaluates the log gamma correction factor for an R8 argument.\n%\n% Discussion:\n%\n% For 10 <= X, compute the log gamma correction factor so that\n%\n% log ( gamma ( x ) ) = log ( sqrt ( 2 * pi ) )\n% + ( x - 0.5 ) * log ( x ) - x\n% + r8_lgmc ( x )\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 28 September 2011\n%\n% Author:\n%\n% Original FORTRAN77 version by Wayne Fullerton.\n% MATLAB version by John Burkardt.\n%\n% Reference:\n%\n% Wayne Fullerton,\n% Portable Special Function Routines,\n% in Portability of Numerical Software,\n% edited by Wayne Cowell,\n% Lecture Notes in Computer Science, Volume 57,\n% Springer 1977,\n% ISBN: 978-3-540-08446-4,\n% LC: QA297.W65.\n%\n% Parameters:\n%\n% Input, real X, the argument.\n%\n% Output, real VALUE, the correction factor.\n%\n persistent algmcs\n persistent nalgm\n persistent xbig\n persistent xmax\n\n if ( isempty ( nalgm ) )\n\n algmcs = [ ...\n +0.1666389480451863247205729650822, ...\n -0.1384948176067563840732986059135E-04, ...\n +0.9810825646924729426157171547487E-08, ...\n -0.1809129475572494194263306266719E-10, ...\n +0.6221098041892605227126015543416E-13, ...\n -0.3399615005417721944303330599666E-15, ...\n +0.2683181998482698748957538846666E-17, ...\n -0.2868042435334643284144622399999E-19, ...\n +0.3962837061046434803679306666666E-21, ...\n -0.6831888753985766870111999999999E-23, ...\n +0.1429227355942498147573333333333E-24, ...\n -0.3547598158101070547199999999999E-26, ...\n +0.1025680058010470912000000000000E-27, ...\n -0.3401102254316748799999999999999E-29, ...\n +0.1276642195630062933333333333333E-30 ]';\n\n nalgm = r8_inits ( algmcs, 15, r8_mach ( 3 ) );\n xbig = 1.0 / sqrt ( r8_mach ( 3 ) );\n xmax = exp ( min ( log ( r8_mach ( 2 ) / 12.0 ), ...\n - log ( 12.0 * r8_mach ( 1 ) ) ) );\n end\n\n if ( x < 10.0 )\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'R8_LGMC - Fatal error!\\n' );\n fprintf ( 1, ' X must be at least 10.\\n' );\n error ( 'R8_LGMC - Fatal error!' )\n\n elseif ( x < xbig )\n\n value = r8_csevl ( 2.0 * ( 10.0 / x ) ...\n * ( 10.0 / x ) - 1.0, algmcs, nalgm ) / x;\n\n elseif ( x < xmax )\n\n value = 1.0 / ( 12.0 * x );\n\n else\n\n value = 0.0;\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/fn/r8_lgmc.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122313857378, "lm_q2_score": 0.822189134878876, "lm_q1q2_score": 0.7459822585880623}} {"text": "function [ a, q, lambda, seed ] = r8symm_test ( n, lambda_mean, lambda_dev, ...\n seed )\n\n%*****************************************************************************80\n%\n%% R8SYMM_TEST determines a symmetric matrix with a certain eigenstructure.\n%\n% Discussion:\n%\n% An R8SYMM is a real symmetric matrix stored using full storage, and\n% using R8 arithmetic.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 21 February 2012\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the order of the matrix.\n%\n% Input, real LAMBDA_MEAN, the mean value of the normal\n% distribution from which the eigenvalues will be chosen.\n%\n% Input, real LAMBDA_DEV, the standard deviation of the normal\n% distribution from which the eigenvalues will be chosen.\n%\n% Input/output, integer SEED, a seed for the random\n% number generator.\n%\n% Output, real A(N,N), the test matrix.\n%\n% Output, real Q(N,N), the eigenvector matrix.\n%\n% Output, real LAMBDA(N), the eigenvalue vector.\n%\n \n%\n% Choose the eigenvalues LAMBDA.\n%\n [ lambda, seed ] = r8vec_normal ( n, lambda_mean, lambda_dev, seed );\n%\n% Get a random orthogonal matrix Q.\n%\n [ q, seed ] = r8mat_orth_uniform ( n, seed );\n%\n% Set A = Q * Lambda*I * Q'.\n%\n a = q * diag ( lambda ) * q';\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_eigen/r8symm_test.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122213606241, "lm_q2_score": 0.822189134878876, "lm_q1q2_score": 0.7459822503455228}} {"text": "function a=v_polygonarea(p)\n%V_POLYGONAREA Calculate the area of a polygon\n%\n% Inputs:\n% P(n,2) is the polygon vertices\n%\n% Outputs:\n% A is teh area of teh polygon\n%\n% The area is positive if the vertices go anti-clockwise around the polygon.\n%\n\n% Copyright (C) Mike Brookes 2009\n% Version: $Id: v_polygonarea.m 10865 2018-09-21 17:22:45Z dmb $\n%\n% VOICEBOX is a MATLAB toolbox for speech processing.\n% Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html\n%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% This program is free software; you can redistribute it and/or modify\n% it under the terms of the GNU General Public License as published by\n% the Free Software Foundation; either version 2 of the License, or\n% (at your option) any later version.\n%\n% This program is distributed in the hope that it will be useful,\n% but WITHOUT ANY WARRANTY; without even the implied warranty of\n% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n% GNU General Public License for more details.\n%\n% You can obtain a copy of the GNU General Public License from\n% http://www.gnu.org/copyleft/gpl.html or by writing to\n% Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\np(end+1,:)=p(1,:); % append an extra point\na=0.5*sum((p(1:end-1,1)-p(2:end,1)).*(p(1:end-1,2)+p(2:end,2)),1);\nif ~nargout\n plot(p(:,1),p(:,2),'b-');\n mnx=[1.05 -0.05;-0.05 1.05]*[min(p);max(p)];\n set(gca,'xlim',mnx(:,1)','ylim',mnx(:,2)');\n title(sprintf('Area = %.2g',a));\nend\n", "meta": {"author": "ImperialCollegeLondon", "repo": "sap-voicebox", "sha": "28f2654b7584f724277ec81de533debe28ff51ac", "save_path": "github-repos/MATLAB/ImperialCollegeLondon-sap-voicebox", "path": "github-repos/MATLAB/ImperialCollegeLondon-sap-voicebox/sap-voicebox-28f2654b7584f724277ec81de533debe28ff51ac/voicebox/v_polygonarea.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.907312226373181, "lm_q2_score": 0.822189123986562, "lm_q1q2_score": 0.7459822445840629}} {"text": "% Figure 3.30e Feedback Control of Dynamic Systems, 5e\n% Franklin, Powell, Emami\n%\n\nclf;\nnum=1;\na=.5;\n\nzeta =1;\nden2=[1/(zeta*a) 1];\nden1=[1 2*zeta 1];\nden=conv(den1,den2);\nt=0:.1:10;\ny1=step(num,den,t);\n\nzeta =.7;\nden2=[1/(zeta*a) 1];\nden1=[1 2*zeta 1];\nden=conv(den1,den2);\ny2=step(num,den,t);\n\nzeta =.5;\nden2=[1/(zeta*a) 1];\nden1=[1 2*zeta 1];\nden=conv(den1,den2);\ny3=step(num,den,t);\n\naxis([1 10 .1 .9])\nplot(t,y1,'-',t,y2,'--',t,y3,'-.'),grid\ntitle('Fig. 3.30e Step response with extra pole, \\alpha= .5')\nxlabel('\\omega_n t')\nylabel('y(t)')\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/9907-feedback-control-of-dynamic-systems-fifth-ed/fig3_30e.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122238669026, "lm_q2_score": 0.822189123986562, "lm_q1q2_score": 0.745982242523428}} {"text": "function [G]=gsp_low_stretch_tree(k)\n%GSP_LOW_STRETCH_TREE Initialize a low stretch tree\n% Usage: G = gsp_low_stretch_tree(k);\n% G = gsp_low_stretch_tree();\n%\n% Input parameters:\n% k : 2^k points on each side of the grid of vertices. (default 6)\n% Output parameters:\n% G : Graph structure.\n%\n% 'gsp_create_low_stretch_tree(k)' initializes a graph structure containing\n% the weighted adjacency matrix (G.W), the number of vertices (G.N), the \n% plotting coordinates (G.coords), the plotting coordinate limits \n% (G.limits), and the root of a low stretch tree on a grid of points.\n% There are $2^k$ points on each side of the grid, and therefore $2^{2k}$ \n% total vertices. The edge weights are all equal to 1.\n%\n% Example:::\n%\n% G = gsp_low_stretch_tree(3);\n% paramplot.show_edges = 1;\n% gsp_plot_graph(G,paramplot);\n%\n% See also: gsp_graph\n\n\n% Author : David I Shuman, Nathanael Perraudin\n\nif nargin < 1\n k = 6; \nend\n\nii=[2 3 1 1 4 3];\njj=[1 1 2 3 3 4];\n\nXCoords=[1, 2, 1, 2];\nYCoords=[1, 1, 2, 2];\n\nfor p=2:k\n % create the indicies of the weight matrice\n ii_new=[ii,ii+4^(p-1),ii+2*4^(p-1),ii+3*4^(p-1)];\n ii_new_middle=[4^(p-1),4^(p-1),4^(p-1)+(4^p+2)/3,5/3*4^(p-1)+1/3,4^(p-1)+(4^p+2)/3,3*4^(p-1)+1];\n ii=[ii_new,ii_new_middle];\n\n jj_new=[jj,jj+4^(p-1),jj+2*4^(p-1),jj+3*4^(p-1)]; \n jj_new_middle=[5/3*4^(p-1)+1/3,4^(p-1)+(4^p+2)/3,3*4^(p-1)+1,4^(p-1),4^(p-1),4^(p-1)+(4^p+2)/3];\n jj=[jj_new,jj_new_middle];\n \n % Create Coords\n YCoords=repmat(YCoords,1,2);\n YCoords_new=[YCoords,YCoords+2^(p-1)];\n YCoords=YCoords_new;\n\n XCoords_new=[XCoords,XCoords+2^(p-1)];\n XCoords=repmat(XCoords_new,1,2);\nend\n\nG.W=sparse(ii,jj,ones(size(ii)));\nG.coords=[XCoords',YCoords'];\n\nG.limits=[0,2^k+1,0,2^k+1];\nG.N=(2^k)^2;\nG.root=4^(k-1);\n\nG.plotting.edge_width=1.25;\nG.plotting.vertex_size=75;\n\nG.type = 'low strech tree';\n\nG = gsp_graph_default_parameters(G);\n\n\nend\n", "meta": {"author": "epfl-lts2", "repo": "gspbox", "sha": "a7d9aac5e239f1bcb37a9bb09998cc161be2732f", "save_path": "github-repos/MATLAB/epfl-lts2-gspbox", "path": "github-repos/MATLAB/epfl-lts2-gspbox/gspbox-a7d9aac5e239f1bcb37a9bb09998cc161be2732f/graphs/gsp_low_stretch_tree.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312221360624, "lm_q2_score": 0.8221891261650247, "lm_q1q2_score": 0.7459822424393389}} {"text": "function determ = aegerter_determinant ( n )\n\n%*****************************************************************************80\n%\n%% AEGERTER_DETERMINANT returns the determinant of the AEGERTER matrix.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 13 October 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the number of rows and columns of A.\n%\n% Output, real DETERM, the determinant.\n%\n determ = ( n - ( ( n - 1 ) * n * ( 2 * n - 1 ) ) / 6 );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_mat/aegerter_determinant.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9230391643039738, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.7458776897656355}} {"text": "function [t0,t1,t2]=calculateInterpolationTimes(L,v,a)\n%% About:\n% calculates the times of the acceleration, stable motion, deceleration\n\n%% Arreguments:\n% L: length of the curve (mm).\n% v: linear velocity of eef on the the curve (mm/sec).\n% a: linear acceleration of eef on the the curve (mm/sec2).\n\n%% Return values:\n% t0; time for acceleration.\n% t1: time for acceleration, constant velocity.\n% t2: time for acceleration, constant velocity and for deceleration\n\n% Copy right: Mohammad SAFEEA\n% 16th-Oct-2017\n\ntaw=v/a;\n\nif(L>a*taw*taw)\n t0=taw;\n deltat=(L-a*taw*taw)/v;\n t1=t0+deltat;\n t2=t1+taw;\nelse\n taw1=(L/a)^0.5;\n t0=taw1;\n t1=taw1;\n t2=2*taw1;\nend\n\nend\n\n", "meta": {"author": "Modi1987", "repo": "KST-Kuka-Sunrise-Toolbox", "sha": "9299bed2b46058aeb4105d7fbff6d2290ce68bba", "save_path": "github-repos/MATLAB/Modi1987-KST-Kuka-Sunrise-Toolbox", "path": "github-repos/MATLAB/Modi1987-KST-Kuka-Sunrise-Toolbox/KST-Kuka-Sunrise-Toolbox-9299bed2b46058aeb4105d7fbff6d2290ce68bba/realTimeControlDrawEllipse/calculateInterpolationTimes.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9230391558355999, "lm_q2_score": 0.8080672227971211, "lm_q1q2_score": 0.7458776871890723}} {"text": "function y=rdct(x,n,a,b)\n%RDCT Discrete cosine transform of real data Y=(X,N,A,B)\n% Data is truncated/padded to length N.\n%\n% This routine is equivalent to multiplying by the matrix\n%\n% rdct(eye(n)) = diag([sqrt(2)*B/A repmat(2/A,1,n-1)]) * cos((0:n-1)'*(0.5:n)*pi/n)\n%\n% Default values of the scaling factors are A=sqrt(2N) and B=1 which\n% results in an orthogonal matrix. Other common values are A=1 or N and/or B=1 or sqrt(2). \n% If b~=1 then the columns are no longer orthogonal.\n%\n% see IRDCT for the inverse transform\n\n% BUG: in line 51 we should do chopping after transform and not before\n\nfl=size(x,1)==1;\nif fl x=x(:); end\n[m,k]=size(x);\nif nargin<2 n=m;\nend\nif nargin<4 b=1; \n if nargin<3 a=sqrt(2*n);\n end\n end\nif n>m x=[x; zeros(n-m,k)];\nelseif n,\n% \n%\n% If you use this code for your research, please cite the following two papers:\n%\n% (1) B.D. Fulcher and N.S. Jones, \"hctsa: A Computational Framework for Automated\n% Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017).\n% DOI: 10.1016/j.cels.2017.10.001\n%\n% (2) B.D. Fulcher, M.A. Little, N.S. Jones, \"Highly comparative time-series\n% analysis: the empirical structure of time series and their methods\",\n% J. Roy. Soc. Interface 10(83) 20130048 (2013).\n% DOI: 10.1098/rsif.2013.0048\n%\n% This function is free software: you can redistribute it and/or modify it under\n% the terms of the GNU General Public License as published by the Free Software\n% Foundation, either version 3 of the License, or (at your option) any later\n% version.\n%\n% This program is distributed in the hope that it will be useful, but WITHOUT\n% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n% FOR A PARTICULAR PURPOSE. See the GNU General Public License for more\n% details.\n%\n% You should have received a copy of the GNU General Public License along with\n% this program. If not, see .\n% ------------------------------------------------------------------------------\n\n%-------------------------------------------------------------------------------\n%% Set defaults:\nif nargin < 2 || isempty(tau)\n tau = 'ac';\nend\n\n%-------------------------------------------------------------------------------\n% Can set the time lag, tau, to be 'ac' or 'mi':\nif strcmp(tau,'ac')\n tau = CO_FirstCrossing(y,'ac',0,'discrete');\n % tau is first zero crossing of the autocorrelation function\nelseif strcmp(tau,'mi')\n tau = CO_FirstMin(y,'mi');\n % tau is the first minimum of the automutual information function\nend\nif isnan(tau)\n error('No valid setting for time delay. (Is the time series too short?)');\nend\n\n%-------------------------------------------------------------------------------\n% Compute trev quantities:\n\nyn = y(1:end-tau);\nyn1 = y(1+tau:end); % yn, tau steps ahead\n\n% The trev expression used in TSTOOL:\nout.raw = mean((yn1-yn).^3)/(mean((yn1-yn).^2))^(3/2);\n\n% The magnitude\nout.abs = abs(out.raw);\n\n% The numerator\nout.num = mean((yn1-yn).^3);\nout.absnum = abs(out.num);\n\n% The denominator\nout.denom = (mean((yn1-yn).^2))^(3/2);\n\nend\n", "meta": {"author": "benfulcher", "repo": "hctsa", "sha": "919f2aed7cc8e1a3a03304c1ade573fa664c73f8", "save_path": "github-repos/MATLAB/benfulcher-hctsa", "path": "github-repos/MATLAB/benfulcher-hctsa/hctsa-919f2aed7cc8e1a3a03304c1ade573fa664c73f8/Operations/CO_trev.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009549929797, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.7458569809959179}} {"text": "function best_weights = GetBestMixingWeight(stand_dev_of_variables)\n% Best mixing of random variables with common mean\n% and built-in constraint\n% best_weights = GetBestMixingWeight(stand_dev_of_variables)\n%\n% Input argument\n% stand_dev_of_variables: standard deviation of each variable\n%\n% Output argument\n% best_weights: best set of weights for mixing random variables\n\n% Copyright 2016 Google Inc. All Rights Reserved.\n% Author: hidekik@google.com (Hideki Kawahara)\n\nnarginchk(1, 1);\nn_variables = length(stand_dev_of_variables);\nH = ones(n_variables - 1, n_variables - 1) * ...\n stand_dev_of_variables(n_variables) ^ 2;\nH = H + diag(stand_dev_of_variables(1 : n_variables - 1) .^ 2);\nv = ones(n_variables - 1, 1) * stand_dev_of_variables(n_variables) ^ 2;\na = H \\ v;\nbest_weights = [a; 1 - sum(a)];\nend\n", "meta": {"author": "google", "repo": "yang_vocoder", "sha": "45787d4bbbb5b36617424b95c19430ced277db23", "save_path": "github-repos/MATLAB/google-yang_vocoder", "path": "github-repos/MATLAB/google-yang_vocoder/yang_vocoder-45787d4bbbb5b36617424b95c19430ced277db23/GetBestMixingWeight.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966702001758, "lm_q2_score": 0.7879312031126512, "lm_q1q2_score": 0.745853053213254}} {"text": "function [LS,LD,I] = isolines(V,F,S,iso)\n % ISOLINES compute a list of isolines for a scalar field S defined on the\n % mesh (V,F)\n %\n % [LS,LD,I] = isolines(V,F,S,iso)\n %\n % Inputs:\n % V #V by dim list of vertex positions\n % F #F by 3 list of triangle indices\n % S #V list of scalar values defined on V\n % iso #iso list of iso values\n % Outputs:\n % LS #L by dim list of isoline start positions\n % LD #L by dim list of isoline destination positions\n % I #L list of indices into iso revealing corresponding iso value\n %\n % alternative: tracing isolines should result in smaller plot data (every\n % vertex only appears once\n %\n % Example:\n % iso = linspace(min(S),max(S),10);\n % [LS,LD] = isolines(V,F,S,iso);\n % colormap(jet(numel(iso)-1));\n % tsurf(F,V,'CData',S,fphong);\n % hold on;\n % plot([LS(:,1) LD(:,1)]',[LS(:,2) LD(:,2)]', ...\n % 'Color','k','LineWidth',10);\n % hold off;\n %\n\n % make sure iso is a ROW vector\n iso = iso(:)';\n % number of isolines\n niso = numel(iso);\n\n % number of domain positions\n n = size(V,1);\n % number of dimensions\n dim = size(V,2);\n\n % number of faces\n m = size(F,1);\n\n % Rename for convenience\n S1 = S(F(:,1),:);\n S2 = S(F(:,2),:);\n S3 = S(F(:,3),:);\n\n % t12(i,j) reveals parameter t where isovalue j falls on the line from\n % corner 1 to corner 2 of face i\n t12 = bsxfun(@rdivide,bsxfun(@minus,iso,S1),S2-S1);\n t23 = bsxfun(@rdivide,bsxfun(@minus,iso,S2),S3-S2);\n t31 = bsxfun(@rdivide,bsxfun(@minus,iso,S3),S1-S3);\n\n % replace values outside [0,1] with NaNs\n t12( (t12<-eps)|(t12>(1+eps)) ) = NaN;\n t23( (t23<-eps)|(t23>(1+eps)) ) = NaN;\n t31( (t31<-eps)|(t31>(1+eps)) ) = NaN;\n\n % masks for line \"parallel\" to 12\n l12 = ~isnan(t23) & ~isnan(t31);\n l23 = ~isnan(t31) & ~isnan(t12);\n l31 = ~isnan(t12) & ~isnan(t23);\n\n % find non-zeros (lines) from t23 to t31\n [F12,I12,~] = find(l12);\n [F23,I23,~] = find(l23);\n [F31,I31,~] = find(l31);\n % indices directly into t23 and t31 corresponding to F12 and I12\n %ti12 = sub2ind(size(l12),F12,I12);\n %ti23 = sub2ind(size(l23),F23,I23);\n %ti31 = sub2ind(size(l31),F31,I31);\n % faster sub2ind\n ti12 = F12+(I12-1)*size(l12,1);\n ti23 = F23+(I23-1)*size(l23,1);\n ti31 = F31+(I31-1)*size(l31,1);\n\n % compute actual position values\n LS = [ ...\n ... % average of vertex positions between 2 and 3\n bsxfun(@times,1-t23(ti12), V(F(F12,2),:)) + ...\n bsxfun(@times, t23(ti12), V(F(F12,3),:)) ...\n ; ... % average of vertex positions between 2 and 3\n bsxfun(@times,1-t31(ti23), V(F(F23,3),:)) + ...\n bsxfun(@times, t31(ti23), V(F(F23,1),:)) ...\n ;... % average of vertex positions between 2 and 3\n bsxfun(@times,1-t12(ti31), V(F(F31,1),:)) + ...\n bsxfun(@times, t12(ti31), V(F(F31,2),:)) ...\n ];\n LD = [...\n ... % hcat with average of vertex positions between 3 and 1\n bsxfun(@times,1-t31(ti12), V(F(F12,3),:)) + ...\n bsxfun(@times, t31(ti12), V(F(F12,1),:)) ...\n ;... % hcat with average of vertex positions between 3 and 1\n bsxfun(@times,1-t12(ti23), V(F(F23,1),:)) + ...\n bsxfun(@times, t12(ti23), V(F(F23,2),:)) ...\n ;... % hcat with average of vertex positions between 3 and 1\n bsxfun(@times,1-t23(ti31), V(F(F31,2),:)) + ...\n bsxfun(@times, t23(ti31), V(F(F31,3),:)) ...\n ];\n\n % I is just concatenation of each I12\n I = [I12;I23;I31];\n\nend\n", "meta": {"author": "alecjacobson", "repo": "gptoolbox", "sha": "a0cb37d8edbcfb1e3587f793df8f24c76a2d7305", "save_path": "github-repos/MATLAB/alecjacobson-gptoolbox", "path": "github-repos/MATLAB/alecjacobson-gptoolbox/gptoolbox-a0cb37d8edbcfb1e3587f793df8f24c76a2d7305/mesh/isolines.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505428129514, "lm_q2_score": 0.8244619285331332, "lm_q1q2_score": 0.7458499311761116}} {"text": "%% SQUARESTOKE Stokes equations on the unit square\n%\n% SQUARESTOKE computes P2-P1 approximations of the Stokes equations in\n% the unit square on a sequence of meshes obtained by uniform refinement.\n% It plots the approximation error (pressue in L2 norm and velocity in H1\n% norm) vs the number of dof.\n% \n% See also StokesP2P1, collidingflow, squarePoisson \n%\n% Copyright (C) Long Chen. See COPYRIGHT.txt for details.\n\nclose all; clear all;\n%% Set up\nmaxIt = 4;\nN = zeros(maxIt,1); erru = zeros(maxIt,1); errp = zeros(maxIt,1);\n\n%% Generate initial mesh\n[node,elem] = squaremesh([0 1 0 1], 0.25);\nbdFlag = setboundary(node,elem,'Dirichlet');\n\n%% PDE and options\npde = Stokesdata2;\n\n%% Finite Element Method \nfor k = 1:maxIt\n % solve the equation\n [u,p,edge,A] = StokesP2P1(node,elem,pde,bdFlag);\n N(k) = length(u)+length(p);\n if N(k) < 2e3 % show solution for small size\n figure(1); showresult(node,elem,p); \n end\n % compute error\n uI = pde.exactu([node; (node(edge(:,1),:)+node(edge(:,2),:))/2]);\n erru(k) = sqrt((u-uI(:))'*A*(u-uI(:)));\n errp(k) = getL2error(node,elem,pde.exactp,p);\n % refine mesh\n [node,elem,bdFlag] = uniformrefine(node,elem,bdFlag);\nend\n\n%% Plot convergence rates\nfigure(2); clf;\nshowrate2(N,erru,2,'-*','||Du_I-Du_h||',N,errp,2,'k-+','|| p - p_h||');", "meta": {"author": "wme7", "repo": "Aero-matlab", "sha": "9430008f2e3b84f28633775a44dff534e780fbac", "save_path": "github-repos/MATLAB/wme7-Aero-matlab", "path": "github-repos/MATLAB/wme7-Aero-matlab/Aero-matlab-9430008f2e3b84f28633775a44dff534e780fbac/iFEM/example/2D/squareStokes.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505351008904, "lm_q2_score": 0.8244619350028204, "lm_q1q2_score": 0.745849930670617}} {"text": "% IMSHAPES Generation of images representing geometric shapes\n% Version 1.1 01-Jul-2011 .\n%\n% This module contains several function for creating synthetic images of\n% common shapes, in 2D (ellipses, rectangles...), or in 3D (balls and\n% ellipsoids, cuboids, torus...).\n% Such discrete representation can be used as phantom to test and / or\n% validate algorithms of binary images measurements.\n%\n% Requires the 'geom2d', the 'geom3d', and the 'imFilters' toolboxes.\n% \n% Shapes 2D:\n% discretePoints - Discretize a set of points\n% discreteDisc - Discretize a disc\n% discreteEllipse - Discretize a planar ellipse\n% discreteSquare - Discretize a planar square\n% discreteRectangle - Discretize a planar rectangle\n% discreteCapsule - Discretize a planar capsule\n% discretePolygon - Discretize a planar polygon\n% discretePolyline - Discretize a planar polyline\n% discreteHalfPlane - Discretize a half plane\n% discreteParabola - Discretize a planar parabola\n% discreteEgg - Discretize a planar egg\n% discreteStarfish - Discretize a starfish curve\n% discreteTrefoil - Discretize a trefoil curve\n% discreteCurve - Discretize a planar curve\n%\n% Shapes 3D:\n% discreteBall - Discretize a 3D Ball\n% discreteHalfBall - discretize a 3D half-ball\n% discreteEllipsoid - discretize a 3D ellipsoid\n% discreteCuboid - discretize a 3D cuboid\n% discreteCube - discretize a 3D cube\n% discreteTorus - Discretize a 3D Torus\n% discreteCylinder - Discretize a 3D cylinder\n% discreteCapsule3d - Create binary image of a 3D capsule\n% discreteReuleauxRevol - Discretize the revolution of a Reuleaux triangle\n% discreteSphereEighth - Discretize a 3D sphere eighth\n%\n% Tessellations:\n% imPointsInfluenceZones - Maps influence zones of a set of 2D/3D points\n% imvoronoi2d - Generate a 2D voronoi image from a set of points\n% imvoronoi3d - generate a 3D voronoi image from a set of points\n% dilatedVoronoi - Simulate a 'thick' voronoi tesselation\n% imAWVoronoi - generate Additively Weighted Voronoi Diagram image\n% imPowerDiagram - Power diagramm of a set of points\n%\n%\n% Author: David Legland\n% e-mail: david.legland@inra.fr\n% http://github.com/mattools/matImage\n% Copyright 2009 INRA - Cepia Software Platform.\n\nhelp('imShapes');\n\n\n", "meta": {"author": "mattools", "repo": "matImage", "sha": "94d892c7beac0db32daadf2646ce37f58e894caf", "save_path": "github-repos/MATLAB/mattools-matImage", "path": "github-repos/MATLAB/mattools-matImage/matImage-94d892c7beac0db32daadf2646ce37f58e894caf/matImage/imShapes/Contents.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711794579722, "lm_q2_score": 0.8774767922879693, "lm_q1q2_score": 0.7458299840880033}} {"text": "section_initializeVariablesAndSettings;\n\n%% read images\ntargetFile = {'tomo.img', 'lena.bmp', 'bridge.img'}; % images\nimageChoice = 1;\ntargetFile1 = strcat(targetFolder, '\\', char(targetFile(imageChoice)));\nimage1 = readImage(targetFile1, 1); \n\nimageChoice = 2;\ntargetFile2 = strcat(targetFolder, '\\', char(targetFile(imageChoice)));\nimage2 = readImage(targetFile2, 1); \n\n%% process\nimage1InGray = setImageToGray( image1 );\nimage2InGray = setImageToGray( image2 );\n% adjust the size \nnewSize = [350 350];\nimage1InGray = imresize(image1InGray, newSize);\nimage2InGray = imresize(image2InGray, newSize);\n\n% perform fft2, obtain magnitude and phase information\n[image1InGray_fft_amplitudeOnly, image1InGray_fft_phaseOnly] = FFT_image( image1InGray );\n[image2InGray_fft_amplitudeOnly, image2InGray_fft_phaseOnly] = FFT_image( image2InGray );\n\n% interleaved the 2 FFT2 results\nimage1_amplitudeOnlyWithImage2_phaseOnly = image1InGray_fft_amplitudeOnly.*image2InGray_fft_phaseOnly;\nimage2_amplitudeOnlyWithImage1_phaseOnly = image2InGray_fft_amplitudeOnly.*image1InGray_fft_phaseOnly;\n% take only the real parts\nimage1_amplitudeWithImage2_phase_realOnly = real(ifft2(image1_amplitudeOnlyWithImage2_phaseOnly));\nimage2_amplitudeWithImage1_phase_realOnly = real(ifft2(image2_amplitudeOnlyWithImage1_phaseOnly));\n\n% recover image 1\nimageInGray_InSpatialDomain = IFFT_image(image1InGray_fft_amplitudeOnly, image1InGray_fft_phaseOnly);\n\n% display the FFT2 interleaved\nsection_plotResults;\n% results commentary\nsection_resultsReporting;\n\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/29671-importance-of-image-phase-information-demo/usage_phaseObserve.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767810736693, "lm_q2_score": 0.8499711775577736, "lm_q1q2_score": 0.7458299728887915}} {"text": "function [w] = projectSimplex(v)\n% Computest the minimum L2-distance projection of vector v onto the probability simplex\nnVars = length(v);\nmu = sort(v,'descend');\nsm = 0;\nfor j = 1:nVars\n sm = sm+mu(j);\n if mu(j) - (1/j)*(sm-1) > 0\n row = j;\n sm_row = sm;\n end\nend\ntheta = (1/row)*(sm_row-1);\nw = max(v-theta,0);", "meta": {"author": "rbgirshick", "repo": "voc-dpm", "sha": "c0b88564bd668bcc6216bbffe96cb061613be768", "save_path": "github-repos/MATLAB/rbgirshick-voc-dpm", "path": "github-repos/MATLAB/rbgirshick-voc-dpm/voc-dpm-c0b88564bd668bcc6216bbffe96cb061613be768/external/minConf/minConf/projectSimplex.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9343951607140233, "lm_q2_score": 0.7981867825403177, "lm_q1q2_score": 0.7458218669515694}} {"text": "function [] = test_hexagram_shape\n\nr1 = 2;\nr2 = 1;\n\nn = 6;\nt = linspace(0, 2*pi, n+1);\nx1 = r1 *[cos(t); sin(t) ];\n\nt2 = t +pi /n;\nx2 = r2 *[cos(t2); sin(t2) ];\n\nm = 2 *n +1;\nx(:, 1:2:m) = x1;\nx(:, 2:2:m) = x2(:, 1:n);\n\nax = gca;\nplotmd(ax, x)\naxis(ax, 'equal')", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/37640-export-figure-to-3d-interactive-pdf/fig2u3d/examples/test_hexagram_shape.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625107731765, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.7458145826282991}} {"text": "function [C,T]=hungarian(A)\n% HUNGARIAN - Solve the assignment problem using the Hungarian method.\n% \n% Usage: >> [C,T]=hungarian(A)\n%\n% Inputs:\n% A - a square (correlation/distance/cost) matrix.\n% C - the optimal assignment (closest row/col pairs)\n% T - the total (minimized) cost of the optimal assignment. \n%\n% Author: Niclas Borlin, 1996\n\n% Adapted from the FORTRAN IV code in Carpaneto and Toth, \"Algorithm 548:\n% Solution of the assignment problem [H]\", ACM Transactions on\n% Mathematical Software, 6(1):104-111, 1980.\n%\n% v1.0 96-06-14. Niclas Borlin, niclas@cs.umu.se.\n% Department of Computing Science, Ume University,\n% Sweden.\n%\n% NOTE: A substantial effort was put into this code. If you use it for a\n% publication or otherwise, please include an acknowledgement and notify\n% me by email. /Niclas\n\n[m,n]=size(A);\n\nif (m~=n)\n error('HUNGARIAN: Cost matrix must be square!');\nend\n\n% Save original cost matrix.\norig=A;\n\n% Reduce matrix.\nA=hminired(A);\n\n% Do an initial assignment.\n[A,C,U]=hminiass(A);\n\n% Repeat while we have unassigned rows.\nwhile (U(n+1))\n % Start with no path, no unchecked zeros, and no unexplored rows.\n LR=zeros(1,n);\n LC=zeros(1,n);\n CH=zeros(1,n);\n RH=[zeros(1,n) -1];\n \n % No labelled columns.\n SLC=[];\n \n % Start path in first unassigned row.\n r=U(n+1);\n % Mark row with end-of-path label.\n LR(r)=-1;\n % Insert row first in labelled row set.\n SLR=r;\n \n % Repeat until we manage to find an assignable zero.\n while (1)\n % If there are free zeros in row r\n if (A(r,n+1)~=0)\n % ...get column of first free zero.\n l=-A(r,n+1);\n \n % If there are more free zeros in row r and row r in not\n % yet marked as unexplored..\n if (A(r,l)~=0 && RH(r)==0)\n % Insert row r first in unexplored list.\n RH(r)=RH(n+1);\n RH(n+1)=r;\n \n % Mark in which column the next unexplored zero in this row\n % is.\n CH(r)=-A(r,l);\n end\n else\n % If all rows are explored..\n if (RH(n+1)<=0)\n % Reduce matrix.\n [A,CH,RH]=hmreduce(A,CH,RH,LC,LR,SLC,SLR);\n end\n \n % Re-start with first unexplored row.\n r=RH(n+1);\n % Get column of next free zero in row r.\n l=CH(r);\n % Advance \"column of next free zero\".\n CH(r)=-A(r,l);\n % If this zero is last in the list..\n if (A(r,l)==0)\n % ...remove row r from unexplored list.\n RH(n+1)=RH(r);\n RH(r)=0;\n end\n end\n \n % While the column l is labelled, i.e. in path.\n while (LC(l)~=0)\n % If row r is explored..\n if (RH(r)==0)\n % If all rows are explored..\n if (RH(n+1)<=0)\n % Reduce cost matrix.\n [A,CH,RH]=hmreduce(A,CH,RH,LC,LR,SLC,SLR);\n end\n \n % Re-start with first unexplored row.\n r=RH(n+1);\n end\n \n % Get column of next free zero in row r.\n l=CH(r);\n \n % Advance \"column of next free zero\".\n CH(r)=-A(r,l);\n \n % If this zero is last in list..\n if(A(r,l)==0)\n % ...remove row r from unexplored list.\n RH(n+1)=RH(r);\n RH(r)=0;\n end\n end\n \n % If the column found is unassigned..\n if (C(l)==0)\n % Flip all zeros along the path in LR,LC.\n [A,C,U]=hmflip(A,C,LC,LR,U,l,r);\n % ...and exit to continue with next unassigned row.\n break;\n else\n % ...else add zero to path.\n \n % Label column l with row r.\n LC(l)=r;\n \n % Add l to the set of labelled columns.\n SLC=[SLC l];\n \n % Continue with the row assigned to column l.\n r=C(l);\n \n % Label row r with column l.\n LR(r)=l;\n \n % Add r to the set of labelled rows.\n SLR=[SLR r];\n end\n end\nend\n\n% Calculate the total cost.\nT=sum(orig(logical(sparse(C,1:size(orig,2),1))));\n\n\nfunction A=hminired(A)\n%HMINIRED Initial reduction of cost matrix for the Hungarian method.\n%\n%B=assredin(A)\n%A - the unreduced cost matris.\n%B - the reduced cost matrix with linked zeros in each row.\n\n% v1.0 96-06-13. Niclas Borlin, niclas@cs.umu.se.\n\n[m,n]=size(A);\n\n% Subtract column-minimum values from each column.\ncolMin=min(A);\nA=A-colMin(ones(n,1),:);\n\n% Subtract row-minimum values from each row.\nrowMin=min(A')';\nA=A-rowMin(:,ones(1,n));\n\n% Get positions of all zeros.\n[i,j]=find(A==0);\n\n% Extend A to give room for row zero list header column.\nA(1,n+1)=0;\nfor k=1:n\n % Get all column in this row. \n cols=j(k==i)';\n % Insert pointers in matrix.\n A(k,[n+1 cols])=[-cols 0];\nend\n\n\nfunction [A,C,U]=hminiass(A)\n%HMINIASS Initial assignment of the Hungarian method.\n%\n%[B,C,U]=hminiass(A)\n%A - the reduced cost matrix.\n%B - the reduced cost matrix, with assigned zeros removed from lists.\n%C - a vector. C(J)=I means row I is assigned to column J,\n% i.e. there is an assigned zero in position I,J.\n%U - a vector with a linked list of unassigned rows.\n\n% v1.0 96-06-14. Niclas Borlin, niclas@cs.umu.se.\n\n[n,np1]=size(A);\n\n% Initialize return vectors.\nC=zeros(1,n);\nU=zeros(1,n+1);\n\n% Initialize last/next zero \"pointers\".\nLZ=zeros(1,n);\nNZ=zeros(1,n);\n\nfor i=1:n\n % Set j to first unassigned zero in row i.\n\tlj=n+1;\n\tj=-A(i,lj);\n\n % Repeat until we have no more zeros (j==0) or we find a zero\n\t% in an unassigned column (c(j)==0).\n \n\twhile (C(j)~=0)\n\t\t% Advance lj and j in zero list.\n\t\tlj=j;\n\t\tj=-A(i,lj);\n\t\n\t\t% Stop if we hit end of list.\n\t\tif (j==0)\n\t\t\tbreak;\n\t\tend\n\tend\n\n\tif (j~=0)\n\t\t% We found a zero in an unassigned column.\n\t\t\n\t\t% Assign row i to column j.\n\t\tC(j)=i;\n\t\t\n\t\t% Remove A(i,j) from unassigned zero list.\n\t\tA(i,lj)=A(i,j);\n\n\t\t% Update next/last unassigned zero pointers.\n\t\tNZ(i)=-A(i,j);\n\t\tLZ(i)=lj;\n\n\t\t% Indicate A(i,j) is an assigned zero.\n\t\tA(i,j)=0;\n\telse\n\t\t% We found no zero in an unassigned column.\n\n\t\t% Check all zeros in this row.\n\n\t\tlj=n+1;\n\t\tj=-A(i,lj);\n\t\t\n\t\t% Check all zeros in this row for a suitable zero in another row.\n\t\twhile (j~=0)\n\t\t\t% Check the in the row assigned to this column.\n\t\t\tr=C(j);\n\t\t\t\n\t\t\t% Pick up last/next pointers.\n\t\t\tlm=LZ(r);\n\t\t\tm=NZ(r);\n\t\t\t\n\t\t\t% Check all unchecked zeros in free list of this row.\n\t\t\twhile (m~=0)\n\t\t\t\t% Stop if we find an unassigned column.\n\t\t\t\tif (C(m)==0)\n\t\t\t\t\tbreak;\n\t\t\t\tend\n\t\t\t\t\n\t\t\t\t% Advance one step in list.\n\t\t\t\tlm=m;\n\t\t\t\tm=-A(r,lm);\n\t\t\tend\n\t\t\t\n\t\t\tif (m==0)\n\t\t\t\t% We failed on row r. Continue with next zero on row i.\n\t\t\t\tlj=j;\n\t\t\t\tj=-A(i,lj);\n\t\t\telse\n\t\t\t\t% We found a zero in an unassigned column.\n\t\t\t\n\t\t\t\t% Replace zero at (r,m) in unassigned list with zero at (r,j)\n\t\t\t\tA(r,lm)=-j;\n\t\t\t\tA(r,j)=A(r,m);\n\t\t\t\n\t\t\t\t% Update last/next pointers in row r.\n\t\t\t\tNZ(r)=-A(r,m);\n\t\t\t\tLZ(r)=j;\n\t\t\t\n\t\t\t\t% Mark A(r,m) as an assigned zero in the matrix . . .\n\t\t\t\tA(r,m)=0;\n\t\t\t\n\t\t\t\t% ...and in the assignment vector.\n\t\t\t\tC(m)=r;\n\t\t\t\n\t\t\t\t% Remove A(i,j) from unassigned list.\n\t\t\t\tA(i,lj)=A(i,j);\n\t\t\t\n\t\t\t\t% Update last/next pointers in row r.\n\t\t\t\tNZ(i)=-A(i,j);\n\t\t\t\tLZ(i)=lj;\n\t\t\t\n\t\t\t\t% Mark A(r,m) as an assigned zero in the matrix . . .\n\t\t\t\tA(i,j)=0;\n\t\t\t\n\t\t\t\t% ...and in the assignment vector.\n\t\t\t\tC(j)=i;\n\t\t\t\t\n\t\t\t\t% Stop search.\n\t\t\t\tbreak;\n\t\t\tend\n\t\tend\n\tend\nend\n\n% Create vector with list of unassigned rows.\n\n% Mark all rows have assignment.\nr=zeros(1,n);\nrows=C(C~=0);\nr(rows)=rows;\nempty=find(r==0);\n\n% Create vector with linked list of unassigned rows.\nU=zeros(1,n+1);\nU([n+1 empty])=[empty 0];\n\n\nfunction [A,C,U]=hmflip(A,C,LC,LR,U,l,r)\n%HMFLIP Flip assignment state of all zeros along a path.\n%\n%[A,C,U]=hmflip(A,C,LC,LR,U,l,r)\n%Input:\n%A - the cost matrix.\n%C - the assignment vector.\n%LC - the column label vector.\n%LR - the row label vector.\n%U - the \n%r,l - position of last zero in path.\n%Output:\n%A - updated cost matrix.\n%C - updated assignment vector.\n%U - updated unassigned row list vector.\n\n% v1.0 96-06-14. Niclas Borlin, niclas@cs.umu.se.\n\nn=size(A,1);\n\nwhile (1)\n % Move assignment in column l to row r.\n C(l)=r;\n \n % Find zero to be removed from zero list..\n \n % Find zero before this.\n m=find(A(r,:)==-l);\n \n % Link past this zero.\n A(r,m)=A(r,l);\n \n A(r,l)=0;\n \n % If this was the first zero of the path..\n if (LR(r)<0)\n % remove row from unassigned row list and return.\n U(n+1)=U(r);\n U(r)=0;\n return;\n else\n \n % Move back in this row along the path and get column of next zero.\n l=LR(r);\n \n % Insert zero at (r,l) first in zero list.\n A(r,l)=A(r,n+1);\n A(r,n+1)=-l;\n \n % Continue back along the column to get row of next zero in path.\n r=LC(l);\n end\nend\n\n\nfunction [A,CH,RH]=hmreduce(A,CH,RH,LC,LR,SLC,SLR)\n%HMREDUCE Reduce parts of cost matrix in the Hungerian method.\n%\n%[A,CH,RH]=hmreduce(A,CH,RH,LC,LR,SLC,SLR)\n%Input:\n%A - Cost matrix.\n%CH - vector of column of 'next zeros' in each row.\n%RH - vector with list of unexplored rows.\n%LC - column labels.\n%RC - row labels.\n%SLC - set of column labels.\n%SLR - set of row labels.\n%\n%Output:\n%A - Reduced cost matrix.\n%CH - Updated vector of 'next zeros' in each row.\n%RH - Updated vector of unexplored rows.\n\n% v1.0 96-06-14. Niclas Borlin, niclas@cs.umu.se.\n\nn=size(A,1);\n\n% Find which rows are covered, i.e. unlabelled.\ncoveredRows=LR==0;\n\n% Find which columns are covered, i.e. labelled.\ncoveredCols=LC~=0;\n\nr=find(~coveredRows);\nc=find(~coveredCols);\n\n% Get minimum of uncovered elements.\nm=min(min(A(r,c)));\n\n% Subtract minimum from all uncovered elements.\nA(r,c)=A(r,c)-m;\n\n% Check all uncovered columns..\nfor j=c\n % ...and uncovered rows in path order..\n for i=SLR\n % If this is a (new) zero..\n if (A(i,j)==0)\n % If the row is not in unexplored list..\n if (RH(i)==0)\n % ...insert it first in unexplored list.\n RH(i)=RH(n+1);\n RH(n+1)=i;\n % Mark this zero as \"next free\" in this row.\n CH(i)=j;\n end\n % Find last unassigned zero on row I.\n row=A(i,:);\n colsInList=-row(row<0);\n if (length(colsInList)==0)\n % No zeros in the list.\n l=n+1;\n else\n l=colsInList(row(colsInList)==0);\n end\n % Append this zero to end of list.\n A(i,l)=-j;\n end\n end\nend\n\n% Add minimum to all doubly covered elements.\nr=find(coveredRows);\nc=find(coveredCols);\n\n% Take care of the zeros we will remove.\n[i,j]=find(A(r,c)<=0);\n\ni=r(i);\nj=c(j);\n\nfor k=1:length(i)\n % Find zero before this in this row.\n lj=find(A(i(k),:)==-j(k));\n % Link past it.\n A(i(k),lj)=A(i(k),j(k));\n % Mark it as assigned.\n A(i(k),j(k))=0;\nend\n\nA(r,c)=A(r,c)+m;\n", "meta": {"author": "sccn", "repo": "eeglab", "sha": "36d3982a63cde83fb279ab465b7a026ec2807c0a", "save_path": "github-repos/MATLAB/sccn-eeglab", "path": "github-repos/MATLAB/sccn-eeglab/eeglab-36d3982a63cde83fb279ab465b7a026ec2807c0a/functions/miscfunc/hungarian.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625050654264, "lm_q2_score": 0.8006920068519378, "lm_q1q2_score": 0.7458145824881695}} {"text": "% this function calculate the PSNR\n\nfunction [PeakSNR, Mean2err]=psnr(OriginalImage, DegradedImage)\nOriginalImage=double(OriginalImage);\nDegradedImage=double(DegradedImage);\n[N,M] = size(OriginalImage);\nImax = max(max(DegradedImage));\nSumOfDiff2 = sum(sum((OriginalImage-DegradedImage).*(OriginalImage-DegradedImage)));\nMean2err=SumOfDiff2./(M*N);\nsdf=Imax^2./(Mean2err);\nif sdf ==0\n sdf=1;\nend\n\nPeakSNR = 10*log10(sdf);\n\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/25244-distortionless-data-hiding-based-on-integer-wavelet-transform/Distortionless Data Hiding/psnr.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625107731764, "lm_q2_score": 0.8006919949619793, "lm_q1q2_score": 0.7458145759832687}} {"text": "function [ vX, mX ] = SolveLsL1Admm( vX, mA, vY, paramLambda, sSolverParams )\n% ----------------------------------------------------------------------------------------------- %\n%[ vX ] = SolveProxTvAdmm( vY, mD, paramLambda, numIterations )\n% Solves the L1 Norm Regualrized Least Squares using Alternating\n% Direction Method of Multipliers (ADMM) Method.\n% Basically solves the problem given by:\n% $$ \\arg \\min_{ x \\in \\mathbb{R}^{n} } \\frac{1}{2} {\\left\\| A x - y \\right|}_{2}^{2} + \\lambda {\\left\\| x \\right\\|}_{1} $$\n% Input:\n% - vX - Optimization Vector.\n% The vector to be optimized. Initialization of\n% the iterative process.\n% Structure: Vector (n X 1).\n% Type: 'Single' / 'Double'.\n% Range: (-inf, inf).\n% - mA - Input Matirx.\n% The model matrix.\n% Structure: Matrix (m X n).\n% Type: 'Single' / 'Double'.\n% Range: (-inf, inf).\n% - vY - Measurements Vector.\n% The model known data.\n% Structure: Vector (m X 1).\n% Type: 'Single' / 'Double'.\n% Range: (-inf, inf).\n% - paramLambda - Parameter Lambda.\n% The L1 Regularization parameter.\n% Structure: Scalar.\n% Type: 'Single' / 'Double'.\n% Range: (0, inf).\n% - paramRho - The Rho Parameter.\n% Sets the weight of the equality constraint.\n% Structure: Scalar.\n% Type: 'Single' / 'Double'.\n% Range (0, inf).\n% - numIterations - Number of Iterations.\n% Number of iterations of the algorithm.\n% Structure: Scalar.\n% Type: 'Single' / 'Double'.\n% Range {1, 2, ...}.\n% Output:\n% - vX - Output Vector.\n% Structure: Vector (n X 1).\n% Type: 'Single' / 'Double'.\n% Range: (-inf, inf).\n% References\n% 1. Wikipedia ADMM - https://en.wikipedia.org/wiki/Augmented_Lagrangian_method#Alternating_direction_method_of_multipliers.\n% Remarks:\n% 1. Using vanilla ADMM with no optimization of the parameter or\n% smoothing.\n% 2. For high values of `paramLambda` it will require many iterations.\n% Known Issues:\n% 1. C\n% TODO:\n% 1. D\n% Release Notes:\n% - 1.0.000 05/08/2021 Royi Avital\n% * First release version.\n% ----------------------------------------------------------------------------------------------- %\n\narguments\n vX (:, 1) {mustBeFloat, mustBeReal}\n mA (:, :) {mustBeFloat, mustBeReal}\n vY (:, 1) {mustBeFloat, mustBeReal}\n paramLambda (1, 1) {mustBeFloat, mustBeReal, mustBePositive}\n sSolverParams.paramRho (1, 1) {mustBeNumeric, mustBeReal, mustBePositive} = 5\n sSolverParams.numIterations (1, 1) {mustBeNumeric, mustBeReal, mustBePositive, mustBeInteger} = 100\nend\n\nMAT_TYPE_SKINNY = 1;\nMAT_TYPE_FAT = 2;\n\nif(size(mA, 1) >= size(mA, 2))\n matType = MAT_TYPE_SKINNY;\nelse\n matType = MAT_TYPE_FAT;\nend\n\nparamRho = sSolverParams.paramRho;\nnumIterations = sSolverParams.numIterations;\n\nmX = zeros(size(mA, 2), numIterations);\n\n% Caching facotirzation\nmC = MatrixFactorize(mA, paramRho, matType);\nvAy = mA.' * vY;\n\nvZ = ProxL1(vX, paramLambda / paramRho);\nvU = vX - vZ;\n\nmX(:, 1) = vX;\n\nfor ii = 2:numIterations\n \n vQ = vAy + (paramRho * (vZ - vU));\n \n % Matrix Inversion Lemma\n switch(matType)\n case(MAT_TYPE_SKINNY)\n vX = mC \\ vQ;\n case(MAT_TYPE_FAT)\n vX = (vQ / paramRho) - ((mA.' * (mC \\ (mA * vQ))) / (paramRho * paramRho));\n end\n \n vZ = ProxL1(vX + vU, paramLambda / paramRho);\n vU = vU + vX - vZ;\n \n mX(:, ii) = vX;\n \nend\n\n\nend\n\n\nfunction [ mC ] = MatrixFactorize( mA, paramRho, matType )\n\nMAT_TYPE_SKINNY = 1;\nMAT_TYPE_FAT = 2;\n\nswitch(matType)\n case(MAT_TYPE_SKINNY)\n mI = speye(size(mA, 2)); \n mC = decomposition((mA.' * mA) + (paramRho * mI), 'chol');\n case(MAT_TYPE_FAT)\n mI = speye(size(mA, 1));\n mC = decomposition(mI + ((1 / paramRho) * (mA * mA.')), 'chol');\nend\n\n\nend\n\n\nfunction [ vX ] = ProxL1( vX, lambdaFactor )\n\n% Soft Thresholding\nvX = max(vX - lambdaFactor, 0) + min(vX + lambdaFactor, 0);\n\n\nend\n\n", "meta": {"author": "RoyiAvital", "repo": "StackExchangeCodes", "sha": "d2a934616995fa8a9f4df1ca29029402435b9e6f", "save_path": "github-repos/MATLAB/RoyiAvital-StackExchangeCodes", "path": "github-repos/MATLAB/RoyiAvital-StackExchangeCodes/StackExchangeCodes-d2a934616995fa8a9f4df1ca29029402435b9e6f/SignalProcessing/Q76626/SolveLsL1Admm.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693702514737, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.7457835006930069}} {"text": "function c = roots_to_i4poly ( n, x )\n\n%*****************************************************************************80\n%\n%% ROOTS_TO_I4POLY converts polynomial roots to polynomial coefficients.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 16 April 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the number of roots specified.\n%\n% Input, integer X(N), the roots.\n%\n% Output, integer C(1:N+1), the coefficients of the polynomial.\n%\n\n%\n% Initialize C to (0, 0, ..., 0, 1).\n% Essentially, we are setting up a divided difference table.\n%\n c(1:n) = 0;\n c(n+1) = 1;\n%\n% Convert to standard polynomial form by shifting the abscissas\n% of the divided difference table to 0.\n%\n for j = 1 : n\n for i = 1 : n+1-j\n c(n-i) = c(n-i) - x(n+1-i-j+1) * c(n-i+1);\n end\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/subpak/roots_to_i4poly.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220292, "lm_q2_score": 0.8376199694135332, "lm_q1q2_score": 0.7457282224533793}} {"text": "%DELTA2TR Convert differential motion to SE(3) homogeneous transform\n%\n% T = DELTA2TR(D) is a homogeneous transform (4x4) representing differential \n% motion D (6x1). \n%\n% The vector D=(dx, dy, dz, dRx, dRy, dRz) represents infinitessimal translation\n% and rotation, and is an approximation to the instantaneous spatial velocity \n% multiplied by time step.\n%\n% Reference::\n% - Robotics, Vision & Control: Second Edition, P. Corke, Springer 2016; p67.\n%\n% See also tr2delta, SE3.delta.\n\n% Copyright (C) 1993-2019 Peter I. Corke\n%\n% This file is part of The Spatial Math Toolbox for MATLAB (SMTB).\n% \n% Permission is hereby granted, free of charge, to any person obtaining a copy\n% of this software and associated documentation files (the \"Software\"), to deal\n% in the Software without restriction, including without limitation the rights\n% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies\n% of the Software, and to permit persons to whom the Software is furnished to do\n% so, subject to the following conditions:\n%\n% The above copyright notice and this permission notice shall be included in all\n% copies or substantial portions of the Software.\n%\n% THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR \n% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\n% FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n% COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\n% IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n% CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n%\n% https://github.com/petercorke/spatial-math\n\nfunction delta = delta2tr(d)\n d = d(:);\n delta = eye(4,4) + [skew(d(4:6)) d(1:3); 0 0 0 0];\n", "meta": {"author": "petercorke", "repo": "spatialmath-matlab", "sha": "6eeff4a79f14286705560b84f1fe72e0b7e0e7f7", "save_path": "github-repos/MATLAB/petercorke-spatialmath-matlab", "path": "github-repos/MATLAB/petercorke-spatialmath-matlab/spatialmath-matlab-6eeff4a79f14286705560b84f1fe72e0b7e0e7f7/delta2tr.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8902942261220292, "lm_q2_score": 0.8376199592797929, "lm_q1q2_score": 0.7457282134313689}} {"text": "function cg_test023 ( )\n\n%*****************************************************************************80\n%\n%% CG_TEST023 tests R83S_CG.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 09 July 2014\n%\n% Author:\n%\n% John Burkardt\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'CG_TEST023\\n' );\n fprintf ( 1, ' Test R83S_CG, applying CG to an R83S matrix.\\n' );\n\n n = 10;\n%\n% Let A be the -1 2 -1 matrix.\n%\n a = r83s_dif2 ( n, n );\n%\n% Choose a random solution.\n%\n seed = 123456789;\n [ x1, seed ] = r8vec_uniform_01 ( n, seed );\n%\n% Compute the corresponding right hand side.\n%\n b = r83s_mv ( n, n, a, x1 );\n%\n% Call the CG routine.\n%\n x2 = ones ( n, 1 );\n x2 = r83s_cg ( n, a, b, x2 );\n%\n% Compute the residual.\n%\n r = r83s_resid ( n, n, a, x2, b );\n r_norm = r8vec_norm ( n, r );\n%\n% Compute the error.\n%\n e_norm = r8vec_diff_norm ( n, x1, x2 );\n%\n% Report.\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Number of variables N = %d\\n', n );\n fprintf ( 1, ' Norm of residual ||Ax-b|| = %g\\n', r_norm );\n fprintf ( 1, ' Norm of error ||x1-x2|| = %g\\n', e_norm );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/cg/cg_test023.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220292, "lm_q2_score": 0.8376199572530449, "lm_q1q2_score": 0.7457282116269669}} {"text": "function X = PQRFFT (x, N, ifn)\n% Calculate the DFT of a real N-point sequence or the inverse\n% DFT corresponding to a real N-point sequence.\n% ifn > 0, forward transform\n% input x(n) - N real values\n% output X(k) - The first N/2+1 points are the real\n% parts of the transform, the next N/2-1 points\n% are the imaginary parts of the transform. However\n% the imaginary part for the first point and the\n% middle point which are known to be zero are not\n% stored.\n% ifn < 0, inverse transform\n% input X(k) - The first N/2+1 points are the real\n% parts of the transform, the next N/2-1 points\n% are the imaginary parts of the transform. However\n% the imaginary part for the first point and the\n% middle point which are known to be zero are not\n% stored. \n% output x(n) - N real values\n\n% P. Kabal $Revision: 1.1 $ $Date: 2003/12/07 13:34:11 $\n\nif (ifn > 0)\n X = fft (x, N);\n XR = real(X(0+1:N/2+1));\n XI = imag(X(1+1:N/2-1+1));\n X = [XR XI];\nelse\n xR = [x(0+1:N/2+1)];\n xI = [0 x(N/2+1+1:N-1+1) 0];\n x = complex ([xR xR(N/2-1+1:-1:1+1)], [xI -xI(N/2-1+1:-1:1+1)]);\n X = real (ifft (x, N));\nend\n", "meta": {"author": "stephencwelch", "repo": "Perceptual-Coding-In-Python", "sha": "2993f57570663768c02745019185091a23f021fe", "save_path": "github-repos/MATLAB/stephencwelch-Perceptual-Coding-In-Python", "path": "github-repos/MATLAB/stephencwelch-Perceptual-Coding-In-Python/Perceptual-Coding-In-Python-2993f57570663768c02745019185091a23f021fe/PEAQPython/PQevalAudioMATLAB/PQevalAudio/Misc/PQRFFT.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107966642556, "lm_q2_score": 0.7956581073313275, "lm_q1q2_score": 0.7456993686443671}} {"text": "%% this is an implementation of kalman filter using belief propagation.\n% author: Shuang Wang\n% email: shw070@ucsd.edu\n% Division of Biomedical Informatics, University of California, San Diego.\n\nclear;\naddpath(genpath('.'));\n%%\n% x_k = A x_t-1 + q; N(0, V_Q);\n% y_k = B x_k + w; N(0, V_W);\n% x_1 ~ N(mu_0, V_0);\n\n%% generating fake data.\ns = RandStream('mt19937ar','Seed',4);\nRandStream.setGlobalStream(s);\nT = 40;\nx = zeros(2, T);\ny = zeros(2, T);\nd_y = size(y, 1);\nd_x = size(x, 1);\nmu_0 = [4; 4];\nV_0 = [1, 0\n 0, 1];\nV_Q = [0.1, 0\n 0, 0.3];\nV_W = [0.05, 0\n 0, 0.1];\nA = [ 1, 0.04\n 0.02, 1];\nB = [1, 0\n 0, 1];\n\n x(:, 1) = mvnrnd(mu_0, V_0, 1)';\n y(:, 1) = B * x(:, 1) + mvnrnd([0, 0], V_W, 1)';\n for t = 2:T\n x(:, t) = A * x(:, t-1) + mvnrnd([0, 0], V_Q, 1)';\n y(:, t) = B * x(:, t) + mvnrnd([0, 0], V_W, 1)';\n end\n \n[msg, varNode_x, factorNode_x, factorNode_y, belief] = initializeMessage(T, mu_0, V_0, d_x, y, B, V_W);\n \nfor bp_iter = 1:2*T\n %% variable node update\n for i = 1:T\n if (i < T)\n msg{varNode_x{i}.backwardNeighborMsgID}.toFactorNode ...\n = GaussianMultiply(msg{varNode_x{i}.forwardNeighborMsgID}.toVarNode,...\n msg{varNode_x{i}.lowerNeighborMsgID}.toVarNode);\n \n msg{varNode_x{i}.forwardNeighborMsgID}.toFactorNode ...\n = GaussianMultiply(msg{varNode_x{i}.backwardNeighborMsgID}.toVarNode,...\n msg{varNode_x{i}.lowerNeighborMsgID}.toVarNode);\n else\n msg{varNode_x{i}.backwardNeighborMsgID}.toFactorNode = msg{varNode_x{i}.lowerNeighborMsgID}.toVarNode;\n end\n end\n \n %% factor node update\n for i = 2:T\n msg{factorNode_x{i}.forwardNeighborMsgID}.toVarNode.mu ...\n = A * msg{factorNode_x{i}.backwardNeighborMsgID}.toFactorNode.mu;\n if(~isempty(msg{factorNode_x{i}.backwardNeighborMsgID}.toFactorNode.V))\n msg{factorNode_x{i}.forwardNeighborMsgID}.toVarNode.V ...\n = A * msg{factorNode_x{i}.backwardNeighborMsgID}.toFactorNode.V * (A') + V_Q;\n msg{factorNode_x{i}.forwardNeighborMsgID}.toVarNode.iV = [];\n else\n msg{factorNode_x{i}.forwardNeighborMsgID}.toVarNode.V = [];\n tmp_iAtiviA = (A')\\msg{factorNode_x{i}.backwardNeighborMsgID}.toFactorNode.iV/A;\n msg{factorNode_x{i}.forwardNeighborMsgID}.toVarNode.iV ...\n = tmp_iAtiviA -(eye(d_x) + tmp_iAtiviA*V_Q)\\tmp_iAtiviA*V_Q*tmp_iAtiviA;\n end\n msg{factorNode_x{i}.backwardNeighborMsgID}.toVarNode.mu ...\n = A\\msg{factorNode_x{i}.forwardNeighborMsgID}.toFactorNode.mu;\n if(~isempty(msg{factorNode_x{i}.forwardNeighborMsgID}.toFactorNode.V))\n msg{factorNode_x{i}.backwardNeighborMsgID}.toVarNode.iV = [];\n msg{factorNode_x{i}.backwardNeighborMsgID}.toVarNode.V ...\n = A\\(msg{factorNode_x{i}.forwardNeighborMsgID}.toFactorNode.V + V_Q)/(A');\n else\n tmp_iv = msg{factorNode_x{i}.forwardNeighborMsgID}.toFactorNode.iV;\n msg{factorNode_x{i}.backwardNeighborMsgID}.toVarNode.V = [];\n msg{factorNode_x{i}.backwardNeighborMsgID}.toVarNode.iV ...\n = (A')*(tmp_iv -(eye(d_x) + tmp_iv*V_Q)\\tmp_iv*V_Q*tmp_iv)*A;\n end\n end\nend % bp_iter\n\n%% update belief\nfor i = 1:T\n belief{i} = GaussianMultiply(msg{varNode_x{i}.backwardNeighborMsgID}.toFactorNode,...\n msg{varNode_x{i}.backwardNeighborMsgID}.toVarNode);\n mu_tmp_sm(:,i) = belief{i}.mu;\nend\n%%\nfigure(1); clf;\nplot(x(1, :), x(2, :), '.'); hold on;\nplot(y(1, :), y(2, :), 'ro'); hold on;\nplot(mu_tmp_sm(1, :), mu_tmp_sm(2, :), 'g*'); hold on;\nh = legend('Hidden state', 'observation', 'kalman smoother');\nset(h, 'box', 'off', 'location', 'best');\nfprintf('SAD:x_z = %f\\n', sum(abs((y(:) - x(:)))));\nfprintf('SAD:kf_sm_z = %f\\n', sum(abs((mu_tmp_sm(:) - x(:)))));", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/39661-implementations-of-kalman-filter-using-both-message-passing-algorithm-and-standard-matrix-operations/BP_kalmanFilter/Demo_KalmanFilter_BP.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088025362857, "lm_q2_score": 0.803173791645582, "lm_q1q2_score": 0.7456736181302029}} {"text": "% AUTHOR : CHANDAN KUMAR\n% SUBJECT: COMPUTER GRAPHICS AND SOLID MODELLING.\n% TITLE : LINE CLIPPING ALGORITHM (CYRUS BECK )\n% DATE : 31/08/09\nfunction lineclip()\nclc, clear all;\nx = input('Give coord[ x0 y0 x1 y1]: ');\nv = input('Give Viewport coord[vx0 vy0 vx1 vy1]: '); \nd = [(x(3)-x(1)) (x(4)-x(2)) -(x(3)-x(1)) -(x(4)-x(2))]; \nfor i = 1:4\n if (i==1)||(i==3)\n j =1;\n else\n j =2;\n end\n t(i) = (v(i)-x(j))/d(j);\nend\ntl = min(t(1),t(3));\nti = max(t(2),t(4));\n \nz(1) = x(1) +d(1)*ti ; % x coord of clipped line\nz(3) = x(1) +d(1)*tl ; % end X coord of clipped line\nz(2) = x(2) +d(2)*ti ;\nz(4) = x(2) +d(2)*tl ;\n\nplot([z(1) z(3)] ,[z(2) z(4)],'r-','LineWidth',2); % Plots Clipped line\nhold on,grid on\nplot([v(1) v(1)] ,[v(2) v(4)],'b-','LineWidth',2); % Plots Viewport\nplot([x(1) z(3)],[x(2) z(4)],'k-'); % Plots Unclipped line\nlegend('Clipped line','Viewport','Unclipped line',3)\nplot([z(1) x(3)],[z(2) x(4)],'k-'); % Plots Unclipped line\nplot([v(1) v(3)] ,[v(2) v(2)],'b-','LineWidth',2); % Plots Viewport\nplot([v(3) v(3)] ,[v(2) v(4)],'b-','LineWidth',2); % Plots Viewport\nplot([v(1) v(3)] ,[v(4) v(4)],'b-','LineWidth',2); % Plots Viewport\naxis([v(1)-1 v(3)+1 v(2)-1 v(4)+1]);\ntitle('Line clipping by Cyrus Beck algorithm')", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/25528-line-clipping/lineclip.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087946129329, "lm_q2_score": 0.8031737892899222, "lm_q1q2_score": 0.7456736095793585}} {"text": "function ival = c8mat_is_column_orthogonal ( m, n, a )\n\n%*****************************************************************************80\n%\n%% C8MAT_IS_COLUMN_ORTHOGONAL checks if a complex matrix is column orthogonal.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 08 October 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer M, N, the row and column dimensions \n% of the matrix. M and N must be positive.\n%\n% Input, complex A(M,N), the matrix.\n%\n% Output, integer IVAL:\n% -1, the matrix is not column orthogonal.\n% 1, the matrix is column orthogonal.\n%\n tol = 0.0001;\n ival = 1;\n\n for j1 = 1 : n\n\n for j2 = j1+1 : n\n\n deviation = abs ( a(1:m,j1)' * a(1:m,j2) );\n deviation_max = max ( deviation_max, deviation );\n\n end\n\n end\n\n if ( deviation_max < tol )\n ival = +1;\n else\n ival = -1;\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_mat/c8mat_is_column_orthogonal.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8947894576856561, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.7456500645673032}} {"text": "function a = myiswt2(swc, lo_r, hi_r)\n% ISWT2 Inverse discrete stationary wavelet transform 2-D.\n% ISWT2 performs a multilevel 2-D stationary wavelet\n% reconstruction using either a specific orthogonal wavelet\n% ('wname', see WFILTERS for more information) or specific\n% reconstruction filters (Lo_r and Hi_r).\n%\n% Filters lo_r and hi_r must be normalized by dividing by sqrt(2)\n% (necessary for implmentation of Stationary Discrete WT)\n%\n% For X = MYISWT2(swc,Lo_r,Hi_r)\n% swc contains H(1:N) V(1:N) D(1:N) A(N)\n% lo_r is the reconstruction low-pass filter.\n% hi_r is the reconstruction high-pass filter.\n%\n% See also IDWT2, SWT2, WAVEREC2.\n\n% based on iswt2.m\n% Sathish Ramani, October 11, 2009\n\n%% Set DWT_Mode to 'per'.\nold_modeDWT = dwtmode('status','nodisp');\nmodeDWT = 'per';\ndwtmode(modeDWT,'nodisp');\n\n%% Load coefficients\nn = (size(swc, 3)-1)/3; %% Number of levels\nh = swc(:,:,1:n);\nv = swc(:,:,n+1:2*n);\nd = swc(:,:,2*n+1:3*n);\na = swc(:,:,3*n+1);\n\n[rx, cx, dump] = size(h);\nfor k = n:-1:1\n\tstep = 2^(k-1);\n\tlast = step;\n\tfor first1 = 1:last\n\t\tiRow = first1:step:rx;\n\t\tlR = length(iRow);\n\t\tfor first2 = 1:last\n\t\t\tiCol = first2:step:cx;\n\t\t\tlC = length(iCol);\n\t\t\tsR = iRow;\n\t\t\tsC = iCol;\n\t\t\ta(iRow,iCol) = idwt2LOC(a(sR,sC), h(sR,sC,k), v(sR,sC,k), d(sR,sC,k), ...\n\t\t\t\tlo_r, hi_r, [lR lC]);\n\t\tend\n\tend\nend\n\n% Restore DWT_Mode.\ndwtmode(old_modeDWT, 'nodisp');\n\n\n%===============================================================%\n% INTERNAL FUNCTIONS\n%===============================================================%\nfunction y = idwt2LOC(a, h, v, d, lo_r, hi_r, sy)\n\ny = upconvLOC(a,lo_r,lo_r,sy) ... % Approximation\n\t+ upconvLOC(h,hi_r,lo_r,sy) ... % Horizontal Detail\n\t+ upconvLOC(v,lo_r,hi_r,sy) ... % Vertical Detail\n\t+ upconvLOC(d,hi_r,hi_r,sy); % Diagonal Detail\n\n%---------------------------------------------------------------%\nfunction y = upconvLOC(x, f1, f2, s)\n\nlf = length(f1);\n% y = dyadup(x,'mat',0,1);\ny = x;\ny = wextend('2D', 'per', y, [lf/2,lf/2]);\ny = wconv2('col', y, f1);\ny = wconv2('row', y, f2);\ny = wkeep2(y, s, [lf lf]);\n%===============================================================%\n", "meta": {"author": "JeffFessler", "repo": "mirt", "sha": "b7f36cc46916821e8bc8502301b1554ebc7efe1d", "save_path": "github-repos/MATLAB/JeffFessler-mirt", "path": "github-repos/MATLAB/JeffFessler-mirt/mirt-b7f36cc46916821e8bc8502301b1554ebc7efe1d/penalty/myiswt2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894520743981, "lm_q2_score": 0.8333245953120233, "lm_q1q2_score": 0.7456500580393648}} {"text": "% This is material illustrating the methods from the book\n% Financial Modelling - Theory, Implementation and Practice with Matlab\n% source\n% Wiley Finance Series\n% ISBN 978-0-470-74489-5\n%\n% Date: 02.05.2012\n%\n% Authors: Joerg Kienitz\n% Daniel Wetterau\n%\n% Please send comments, suggestions, bugs, code etc. to\n% kienitzwetterau_FinModelling@gmx.de\n%\n% (C) Joerg Kienitz, Daniel Wetterau\n% \n% Since this piece of code is distributed via the mathworks file-exchange\n% it is covered by the BSD license \n%\n% This code is being provided solely for information and general \n% illustrative purposes. The authors will not be responsible for the \n% consequences of reliance upon using the code or for numbers produced \n% from using the code. \n\nfunction pathS = MC_BS(S0,r,d,T,sigma,NTime,NSim,NBatches)\n%\n% Path discretization in a Black-Scholes model\n%\n% S0 spot price\n% K the strike price\n% r the riskless rate\n% d the dividend yield\n% sigma the volatility\n% T the maturity\n% NTime number of timesteps\n% NSim number of simulations\n% NBatches number of batches\n\nDelta = T/NTime; % The discretisation step\n\npathS = zeros(NSim,NTime+1,NBatches);\nlnS1 = zeros(NSim,NTime+1); % init the logspot price path\nlnS1(:,1)=log(S0*exp(-d*T)); % adjust due to dividend yield\n\nomega = (r-d-0.5*sigma^2) * Delta;\n\nfor l = 1:NBatches\n dW = randn(NSim,NTime); % precompute all randoms\n\n for i=2:NTime+1\n lnS1(:,i) = lnS1(:,i-1) + omega + sigma* sqrt(Delta)*dW(:,i-1);\n end\n pathS(:,:,l) = exp(lnS1);\nend\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/37618-monte-carlo-simulation-and-derivatives-pricing/StandardMonteCarlo/MC_BS.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026641072386, "lm_q2_score": 0.8128673178375735, "lm_q1q2_score": 0.7456453562181117}} {"text": "function npartitions = partn_enum ( n, nmax )\n\n%*****************************************************************************80\n%\n%% PARTN_ENUM enumerates the partitions of N with maximum element NMAX.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 26 January 2011\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Donald Kreher, Douglas Simpson,\n% Combinatorial Algorithms,\n% CRC Press, 1998,\n% ISBN: 0-8493-3988-X,\n% LC: QA164.K73.\n%\n% Parameters:\n%\n% Input, integer N, the integer to be partitioned.\n% Normally N must be positive, but for this routine any\n% N is allowed.\n%\n% Input, integer NMAX, the maximum element in the partition.\n% Normally, 1 <= NMAX <= N is required,\n% but for this routine any value of NMAX is allowed.\n%\n% Output, integer NPARTITIONS is the number of partitions of N\n% with maximum element NMAX.\n%\n if ( n <= 0 )\n\n npartitions = 0;\n\n elseif ( nmax <= 0 || n < nmax )\n\n npartitions = 0;\n\n else\n\n offset = 1;\n\n p = npart_table ( n, nmax );\n\n npartitions = p(n+offset,nmax+offset);\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/combo/partn_enum.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809303, "lm_q2_score": 0.8418256532040708, "lm_q1q2_score": 0.7455472888627616}} {"text": "function value = sphere_unit_monomial_nd ( n, p )\n\n%*****************************************************************************80\n%\n%% SPHERE_UNIT_MONOMIAL_ND integrates a monomial on a unit sphere in ND.\n%\n% Integration region:\n%\n% Points X(1:N) such that\n%\n% Sum ( X(1:N)**2 ) == 1\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 21 May 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Gerald Folland,\n% How to Integrate a Polynomial Over a Sphere,\n% American Mathematical Monthly,\n% Volume 108, May 2001, pages 446-448.\n%\n% Parameters:\n%\n% Input, integer N, the dimension of the space.\n%\n% Input, integer P(N), the exponents of X(1) through X(N) in the monomial.\n% The exponents P(N) must be nonnegative.\n%\n% Output, real SPHERE_UNIT_MONOMIAL_ND, the integral of\n% X1**P(1)*X2**P(2)*...*XN**P(N) over the unit sphere.\n%\n for i = 1 : n\n if ( mod ( p(i), 2 ) == 1 )\n value = 0.0E+00;\n return\n end\n end\n\n temp = 0.0E+00;\n arg2 = 0.0E+00;\n\n for i = 1 : n\n arg1 = ( p(i) + 1 ) / 2.0E+00;\n temp = temp + gammaln ( arg1 );\n arg2 = arg2 + arg1;\n end\n temp = temp - gammaln ( arg2 );\n\n value = 2.0E+00 * exp ( temp );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/stroud/sphere_unit_monomial_nd.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314738181875, "lm_q2_score": 0.8418256452674008, "lm_q1q2_score": 0.7455472869161148}} {"text": "%% Machine Learning Online Class - Exercise 1: Linear Regression\n\n% Instructions\n% ------------\n% \n% This file contains code that helps you get started on the\n% linear exercise. You will need to complete the following functions \n% in this exericse:\n%\n% warmUpExercise.m\n% plotData.m\n% gradientDescent.m\n% computeCost.m\n% gradientDescentMulti.m\n% computeCostMulti.m\n% featureNormalize.m\n% normalEqn.m\n%\n% For this exercise, you will not need to change any code in this file,\n% or any other files other than those mentioned above.\n%\n% x refers to the population size in 10,000s\n% y refers to the profit in $10,000s\n%\n\n%% Initialization\nclear ; close all; clc\n\n%% ==================== Part 1: Basic Function ====================\n% Complete warmUpExercise.m \nfprintf('Running warmUpExercise ... \\n');\nfprintf('5x5 Identity Matrix: \\n');\nwarmUpExercise()\n\n%fprintf('Program paused. Press enter to continue.\\n');\n%pause;\n\n\n%% ======================= Part 2: Plotting =======================\nfprintf('Plotting Data ...\\n')\ndata = load('ex1data1.txt');\nX = data(:, 1); y = data(:, 2);\nm = length(y); % number of training examples\n\n% Plot Data\n% Note: You have to complete the code in plotData.m\nplotData(X, y);\n\n%fprintf('Program paused. Press enter to continue.\\n'); pause;\n\n%% =================== Part 3: Gradient descent ===================\nfprintf('Running Gradient Descent ...\\n')\n\nX = [ones(m, 1), data(:,1)]; % Add a column of ones to x\ntheta = zeros(2, 1); % initialize fitting parameters\n\n% Some gradient descent settings\niterations = 1500;\nalpha = 0.01;\n\n% compute and display initial cost\ncomputeCost(X, y, theta)\n\n% run gradient descent\ntheta = gradientDescent(X, y, theta, alpha, iterations);\n\n% print theta to screen\nfprintf('Theta found by gradient descent: ');\nfprintf('%f %f \\n', theta(1), theta(2));\n\n% Plot the linear fit\nhold on; % keep previous plot visible\nplot(X(:,2), X*theta, '-')\nlegend('Training data', 'Linear regression')\nhold off % don't overlay any more plots on this figure\n\n% Predict values for population sizes of 35,000 and 70,000\npredict1 = [1, 3.5] *theta;\nfprintf('For population = 35,000, we predict a profit of %f\\n',...\n predict1*10000);\npredict2 = [1, 7] * theta;\nfprintf('For population = 70,000, we predict a profit of %f\\n',...\n predict2*10000);\n\n%fprintf('Program paused. Press enter to continue.\\n'); pause;\n\n%% ============= Part 4: Visualizing J(theta_0, theta_1) =============\nfprintf('Visualizing J(theta_0, theta_1) ...\\n')\n\n% Grid over which we will calculate J\ntheta0_vals = linspace(-10, 10, 100);\ntheta1_vals = linspace(-1, 4, 100);\n\n% initialize J_vals to a matrix of 0's\nJ_vals = zeros(length(theta0_vals), length(theta1_vals));\n\n% Fill out J_vals\nfor i = 1:length(theta0_vals)\n for j = 1:length(theta1_vals)\n\t t = [theta0_vals(i); theta1_vals(j)]; \n\t J_vals(i,j) = computeCost(X, y, t);\n end\nend\n\n\n% Because of the way meshgrids work in the surf command, we need to \n% transpose J_vals before calling surf, or else the axes will be flipped\nJ_vals = J_vals';\n% Surface plot\nfigure;\nsurf(theta0_vals, theta1_vals, J_vals)\nxlabel('\\theta_0'); ylabel('\\theta_1');\n\n% Contour plot\nfigure;\n% Plot J_vals as 15 contours spaced logarithmically between 0.01 and 100\ncontour(theta0_vals, theta1_vals, J_vals, logspace(-2, 3, 20))\nxlabel('\\theta_0'); ylabel('\\theta_1');\nhold on;\nplot(theta(1), theta(2), 'rx', 'MarkerSize', 10, 'LineWidth', 2);\n", "meta": {"author": "worldveil", "repo": "coursera-ml", "sha": "94e205b01ec3a47c0d777943194d12fa130f4685", "save_path": "github-repos/MATLAB/worldveil-coursera-ml", "path": "github-repos/MATLAB/worldveil-coursera-ml/coursera-ml-94e205b01ec3a47c0d777943194d12fa130f4685/linear-regression/code/ex1.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314617436728, "lm_q2_score": 0.8418256412990657, "lm_q1q2_score": 0.7455472732369963}} {"text": "function p = predictOneVsAll(all_theta, X)\n%PREDICT Predict the label for a trained one-vs-all classifier. The labels \n%are in the range 1..K, where K = size(all_theta, 1). \n% p = PREDICTONEVSALL(all_theta, X) will return a vector of predictions\n% for each example in the matrix X. Note that X contains the examples in\n% rows. all_theta is a matrix where the i-th row is a trained logistic\n% regression theta vector for the i-th class. You should set p to a vector\n% of values from 1..K (e.g., p = [1; 3; 1; 2] predicts classes 1, 3, 1, 2\n% for 4 examples) \n\nm = size(X, 1);\nnum_labels = size(all_theta, 1);\n\n% You need to return the following variables correctly \np = zeros(size(X, 1), 1);\n\n% Add ones to the X data matrix\nX = [ones(m, 1) X];\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Complete the following code to make predictions using\n% your learned logistic regression parameters (one-vs-all).\n% You should set p to a vector of predictions (from 1 to\n% num_labels).\n%\n% Hint: This code can be done all vectorized using the max function.\n% In particular, the max function can also return the index of the \n% max element, for more information see 'help max'. If your examples \n% are in rows, then, you can use max(A, [], 2) to obtain the max \n% for each row.\n% \n\nfor c = 1:m\n\tone_example = X(c,:);\n\t[max_value, max_index] = max(all_theta * one_example');\n\tp(c,1) = max_index;\n\n% =========================================================================\n\n\nend\n", "meta": {"author": "sfvsfv", "repo": "Mathematical-modeling", "sha": "cef1a3688246851f067777b3599b1b3831d3d948", "save_path": "github-repos/MATLAB/sfvsfv-Mathematical-modeling", "path": "github-repos/MATLAB/sfvsfv-Mathematical-modeling/Mathematical-modeling-cef1a3688246851f067777b3599b1b3831d3d948/matlab\u5434\u6069\u8fbe\u673a\u5668\u5b66\u4e60/machine-learning-ex3/ex3/predictOneVsAll.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256313782276, "lm_q2_score": 0.8856314677809304, "lm_q1q2_score": 0.7455472695331082}} {"text": "function h = qq_plot(varargin)\n% Quantile-quantile plot with patch option\n%\n% QQ_PLOT(Y) displays a quantile-quantile plot of the sample quantiles of\n% Y versus theoretical quantiles from a normal distribution. If the\n% distribution of Y is normal, the plot will be close to linear.\n% \n% QQ_PLOT(X,Y) displays a quantile-quantile plot of two samples. If the\n% samples come from the same distribution, the plot will be linear.\n% \n% The inputs X and Y should be numeric and have an equal number of\n% elements; every element is treated as a member of the sample.\n% \n% The plot displays the sample data with the plot symbol 'x'.\n% Superimposed on the plot is a dashed straight line connecting the first\n% and third quartiles.\n% \n% QQ_PLOT(...,MODE) allows the appearance of the plot to be configured.\n% With MODE='line' (default), the plot appears as described above. With\n% MODE='patch', the data are plotted as a patch object, with the area\n% bound by the x-distribution and the linear fit shaded grey. With\n% mode='both' the two appearances are combined.\n% \n% QQ_PLOT(...,MODE,METHOD) and QQ_PLOT(...,[],METHOD) allows the method\n% for calculating the quartiles, used for the fit line, to be specified.\n% The default is 'R-8'. Type 'help quantile2' for more information. The\n% latter form of the function call uses the default mode.\n% \n% H = QQ_PLOT(...) returns a two- or three-element vector of handles to\n% the plotted object. The nature of the handles depends upon the mode. In\n% all cases, the first handle is to the sample data, the second handle is\n% to the fit line. With MODE='patch' or MODE='both', there is third\n% handle to the patch object.\n% \n% Example\n% \n% % Display Q-Q plots for the rand and randn functions\n% figure\n% subplot(2,1,1)\n% qq_plot(rand(20),'patch')\n% subplot(2,1,2)\n% h = qq_plot(randn(20),'patch');\n% set(h(3),'FaceColor','r') % change fill color\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% LICENSE FILE:\n% -----------------------------------------------------------------------\n% Copyright (c) 2015, Christopher Hummersone\n% All rights reserved.\n% \n% Redistribution and use in source and binary forms, with or without\n% modification, are permitted provided that the following conditions are\n% met:\n% \n% * Redistributions of source code must retain the above copyright\n% notice, this list of conditions and the following disclaimer.\n% * Redistributions in binary form must reproduce the above copyright\n% notice, this list of conditions and the following disclaimer in\n% the documentation and/or other materials provided with the distribution\n% \n% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE\n% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\n% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n% POSSIBILITY OF SUCH DAMAGE.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n% ==========================================================\n% Last changed: $Date: 2015-05-20 16:28:56 +0100 (Wed, 20 May 2015) $\n% Last committed: $Revision: 380 $\n% Last changed by: $Author: ch0022 $\n% ==========================================================\n\n %% determine X and Y\n\n IXn = cellfun(@(x) isnumeric(x) & ~isempty(x),varargin);\n\n switch sum(IXn)\n case 0\n error('No input data specified')\n case 1\n % compare to normal distrbution\n Y = get_input_sample(varargin,IXn);\n p = (.5:length(Y))/length(Y);\n X = sqrt(2)*erfinv(2*p - 1);\n x_label = 'Standard normal quantiles';\n y_label = 'Sample quantiles';\n case 2\n % compare to input data distribution\n Y = get_input_sample(varargin,find(IXn,1,'last'));\n X = get_input_sample(varargin,find(IXn,1,'first'));\n assert(isequal(size(X),size(Y)),'Input data must be the same size')\n x_label = 'X quantiles';\n y_label = 'Y quantiles';\n otherwise\n error('Unknown input specified')\n end\n\n %% determine mode and method\n\n % find inputs\n IXc = cellfun(@(x) ischar(x) | isempty(x),varargin);\n switch sum(IXc)\n case 0\n mode = [];\n method = [];\n case 1\n mode = varargin{IXc};\n method = [];\n case 2\n mode = varargin{find(IXc,1,'first')};\n method = varargin{find(IXc,1,'last')};\n otherwise\n error('Unknown string specified')\n end\n\n % defaults\n if isempty(mode)\n mode = 'line';\n end\n if isempty(method)\n method = 'R-8';\n end\n\n %% calculate fit to first and third quartile\n\n % quartiles\n q1x = quantile2(X,.25,[],method);\n q3x = quantile2(X,.75,[],method);\n q1y = quantile2(Y,.25,[],method);\n q3y = quantile2(Y,.75,[],method);\n\n % slope\n slope = (q3y-q1y)./(q3x-q1x);\n centerx = (q1x+q3x)/2;\n centery = (q1y+q3y)/2;\n\n % fit\n maxx = max(X);\n minx = min(X);\n maxy = centery + slope.*(maxx - centerx);\n miny = centery - slope.*(centerx - minx);\n\n % lines\n X_fit = linspace(minx,maxx,length(X));\n Y_fit = linspace(miny,maxy,length(X));\n\n %% plot data\n\n hold on\n\n if strcmpi(mode,'patch') || strcmpi(mode,'both')\n Hp = patch([X fliplr(X_fit)],[Y fliplr(Y_fit)],[0.5 0.5 0.5]);\n set(Hp,'edgecolor','none')\n else\n Hp = NaN;\n end\n\n switch lower(mode)\n case 'line'\n linestyle = 'xk';\n case 'patch'\n linestyle = '-k';\n case 'both'\n linestyle = 'xk';\n otherwise\n error('Unknown mode specified')\n end\n\n H = plot(X,Y,linestyle,X_fit,Y_fit,'--k');\n\n hold off\n\n % axis labels\n xlabel(x_label)\n ylabel(y_label)\n\n box on; axis tight\n set(gca,'layer','top')\n\n % return handle\n if nargout>0\n h = H;\n if isobject(Hp) || ishandle(Hp)\n h = [h; Hp];\n end\n end\n\nend\n\nfunction Z = get_input_sample(z,IX)\n%GET_INPUT_SAMPLE get sample, order, and convert to vector\n Z = z{IX};\n Z = sort(Z(:))';\nend\n", "meta": {"author": "brainstorm-tools", "repo": "brainstorm3", "sha": "a892cfaabde1eaa2f9a3ac015c05b73f3739433a", "save_path": "github-repos/MATLAB/brainstorm-tools-brainstorm3", "path": "github-repos/MATLAB/brainstorm-tools-brainstorm3/brainstorm3-a892cfaabde1eaa2f9a3ac015c05b73f3739433a/external/other/qq_plot.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256313782276, "lm_q2_score": 0.8856314632529872, "lm_q1q2_score": 0.7455472657213696}} {"text": "function gb=gabor_fn(bw,gamma,psi,lambda,theta)\n% bw = bandwidth, (1)\n% gamma = aspect ratio, (0.5)\n% psi = phase shift, (0)\n% lambda= wave length, (>=2)\n% theta = angle in rad, [0 pi)\n \nsigma = lambda/pi*sqrt(log(2)/2)*(2^bw+1)/(2^bw-1);\nsigma_x = sigma;\nsigma_y = sigma/gamma;\n\nsz=fix(8*max(sigma_y,sigma_x));\nif mod(sz,2)==0, sz=sz+1;end\n\n% alternatively, use a fixed size\n% sz = 60;\n \n[x y]=meshgrid(-fix(sz/2):fix(sz/2),fix(sz/2):-1:fix(-sz/2));\n% x (right +)\n% y (up +)\n\n% Rotation \nx_theta=x*cos(theta)+y*sin(theta);\ny_theta=-x*sin(theta)+y*cos(theta);\n \ngb=exp(-0.5*(x_theta.^2/sigma_x^2+y_theta.^2/sigma_y^2)).*cos(2*pi/lambda*x_theta+psi);\nimshow(gb/2+0.5);", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/23253-gabor-filter/Gabor Filter/gabor_fn.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741268224331, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.7455440226562653}} {"text": "function F = tempCompCurve(x,Tdata)\n%% Calculate Temperature Curve given Resistor and Thermistor Values\n% Copyright (c) 2012, MathWorks, Inc.\n%% Input voltage\nVin = 1.1;\n\n%% Thermistor Calculations\n% Values in x: R1 R2 R3 R4 RTH1(T_25degc) Beta1 RTH2(T_25degc) Beta2\n% Thermistors are represented by:\n% Room temperature is 25degc: T_25\n% Standard value is at 25degc: RTHx_25\n% RTHx is the thermistor resistance at various temperature\n% RTH(T) = RTH(T_25degc) / exp (Beta * (T-T_25)/(T*T_25)))\nT_25 = 298.15;\nT_off = 273.15;\nBeta1 = x(6);\nBeta2 = x(8);\nRTH1 = x(5) ./ exp(Beta1 * ((Tdata+T_off)-T_25)./((Tdata+T_off)*T_25));\nRTH2 = x(7) ./ exp(Beta2 * ((Tdata+T_off)-T_25)./((Tdata+T_off)*T_25));\n\n%% Define equivalent circuits for parallel R's and RTH's\nR1_eq = x(1)*RTH1./(x(1)+RTH1);\nR3_eq = x(3)*RTH2./(x(3)+RTH2);\n\n%% Calculate voltages at Point B\nF = Vin * (R3_eq + x(4))./(R1_eq + x(2) + R3_eq + x(4));", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/35810-optimal-component-selection-using-the-mixed-integer-genetic-algorithm/Thermistor_MixedIntegerGA/tempCompCurve.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9658995762509215, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.7455233024255357}} {"text": "% Isoparametric Formulation Implementation\n% clear memory\nclear all\n\n%% Physical Parameters\n% numberElements: number of elements\nnumberElements = 6; \n\n% Initial Area\nA = 12.5e-4; % m^2\n\n% Modulus of elasticity\nE = 2e11; % N/m^2\n\n% Length of bar\nLtotal = 1.5; % m \n\n%% Exact solutions\nxx = 0:0.1:1.5;\ndisplacements_exact = (40000*xx.^3/3-45000)/(E*A);\nstress_exact = (40000*xx.^2)/A;\n\nfigure(3)\n\n% Displacements\nsubplot(1,2,1); hold on;\nplot(xx,displacements_exact,'-r'); \n\n% Stress\nsubplot(1,2,2); hold on;\n\nplot(xx,stress_exact,'-r'); \n\ntest = [1 2 4 8];\nfor numberElements = test\n\n% Build nodes coordinates and middle points,\ndelta_x = Ltotal/numberElements;\ni = 0:numberElements; \nx = delta_x*i';x_mid = (x(2:end)-x(1:end-1))/2 + x(1:end-1);\n\n% Length of each element\nL = x(2:end)-x(1:end-1); \n \n%% Build Elements\n% numberNodes: number of nodes\nnumberNodes = numberElements + 1;\n\n% generation of coordinates and connectivities\nelementNodes = zeros(numberElements,2); \nelementNodes(1,:) = [1,2]; \nfor i = 2:numberElements \n elementNodes(i,:) = elementNodes(i-1,:) + 1; \nend\nnodeCoordinates = x;\n\n% for structure:\n % displacements: displacement vector\n % force : force vector\n % stiffness: stiffness matrix\nforce=zeros(numberNodes,1);\nstiffness=zeros(numberNodes,numberNodes); \n% computation of the system stiffness matrix and force vector\nfor e=1:numberElements; \n % elementDof: element degrees of freedom (Dof)\n elementDof=elementNodes(e,:) ;\n detJacobian=L(e)/2;\n invJacobian=1/detJacobian;\n ngp = 2;\n [w,xi]=gauss1d(ngp);\n xc=0.5*(nodeCoordinates(elementDof(1))+nodeCoordinates(elementDof(2)));\n for ip=1:ngp;\n [shape,naturalDerivatives]=shapeFunctionL2(xi(ip)); \n B=naturalDerivatives*invJacobian;\n stiffness(elementDof,elementDof)=...\n stiffness(elementDof,elementDof)+ B'*B*w(ip)*detJacobian*E*A;\n force(elementDof) = force(elementDof)+...\n -80000*(xc+detJacobian*xi(ip))*shape'*detJacobian*w(ip);\n end\nend \n \n%% BCs and solution\n% prescribed dofs\nprescribedDof = find(nodeCoordinates == 1.5); % fixed at node x = 1.5 m\n% solution\nGDof=numberNodes;\ndisplacements=solution(GDof,prescribedDof,stiffness,force);\n% output displacements/reactions\noutputDisplacementsReactions(displacements,stiffness, ...\n numberNodes,prescribedDof,force)\n\n%% Stress\nstress = zeros(numberElements,1);\nfor e=1:numberElements; \n stress(elementNodes(e,:)) = E*B*displacements(elementNodes(e,:));\nend\n\n\n%% plot figures\n\nswitch numberElements\n case 1\n line='r*--';\n case 2\n line='g*--';\n case 4\n line='k*--';\n case 8\n line='m*--';\nend\n\n% Displacements\nsubplot(1,2,1); plot(nodeCoordinates,displacements,line)\n\n% Stress\nsubplot(1,2,2); stairs(nodeCoordinates,stress,line)\n\nend %end for\nsubplot(1,2,1); legend('Exact','NEL=1','NEL=2','NEL=4','NEL=8',2); hold off\nsubplot(1,2,2); legend('Exact','NEL=1','NEL=2','NEL=4','NEL=8',2); hold off", "meta": {"author": "wme7", "repo": "Aero-matlab", "sha": "9430008f2e3b84f28633775a44dff534e780fbac", "save_path": "github-repos/MATLAB/wme7-Aero-matlab", "path": "github-repos/MATLAB/wme7-Aero-matlab/Aero-matlab-9430008f2e3b84f28633775a44dff534e780fbac/FEM/BarIsoParametric/HWproblem2dIso.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133498259924, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.7454508759407814}} {"text": "% \n% Implementation of Bertsekas' auction algorithm [1] for a very fast \n% solution of the linear assignment problem, i.e. it is able \n% to solve a 1000-by-1000 problem in ~1.5s.\n%\n% In practice, with respect to running time, the auction algorithm \n% outperforms the Kuhn-Munkres (or Hungarian) algorithm significantly. \n% The auction algorithm has average run-time complexity O(N^2*log(N)) and \n% worst-case complexity O(N^3), whereas the Kuhn-Munkres algorithm has \n% average- and worst-case complexity O(N^3).\n%\n% Note that only global optima are found for integer-valued benefit matrices. \n% For real-valued benefit matrices a scaling of the values needs to be applied\n% by multiplication with a large number. This scaling factor depends on the\n% desired accuracy, as the global solution is found for the integral part\n% of the benefit matrix, whilst there is no guarantee that the fractional part \n% of the benefits are properly taken into account. However, in practical cases \n% it seems advantageous to not round the resulting benefit matrix and retain \n% the fractional parts in the benefit matrix. Also note that larger scalings \n% of the benefit matrix increase the run-time, so a problem-specific trade-off \n% between runtime and accuracy must be chosen.\n%\n% Runtime can be slightly decreased by installing the FastSet library,\n% available on \n% http://www.levmuchnik.net/Content/ProgrammingTips/MatLab/FastSet/FastSet.html\n%\n% Input:\n% A N-by-N benefit matrix (higher\n% values indicate a better match)\n% [epsilon] Initial value of epsilon (optional)\n% [epsilonDecreaseFactor] Decreas factor of epsilon\n% (optional)\n%\n% Output:\n% assignments Resulting assignments\n% [prices] Prices used during auctions\n% (optional)\n%\n% Example: See the function test() below for a usage example.\n% Typically only the benefit matrix A is given as input and the\n% first output argument is relevant. epsilon and\n% epsilonDecreaseFactor can be used to heuristically adapt\n% runtime. The example below can also be used for testing\n% whether a sufficient amount of scaling has been performed.\n% This is done by solving the assignment problem using CVX\n% (available on http://cvxr.com/cvx/download/ ) and comparing\n% its result to the solution with the auction algorithm.\n% \n%\n% [1]\tBertsekas, D.P. 1998. Network Optimization Continuous and Discrete Models.\n%\n% Implementation by Florian Bernard ( f.bernardpi [at] gmail [dot] com )\n%\n% Created on 25/07/2014\n\nfunction [assignments, prices] = ...\n assignmentProblemAuctionAlgorithm(A, epsilon, epsilonDecreaseFactor)\n\nN = size(A,1);\nassignments = nan(N,1);\nprices = ones(N,1);\n\n% check which unique function we use\nif ( exist('fast_unique', 'file') ) \n % requires FastSet, available on \n % http://www.levmuchnik.net/Content/ProgrammingTips/MatLab/FastSet/FastSet.html\n uniqueFcn = @fast_unique;\nelse\n uniqueFcn = @unique;\nend\n\n% heuristic for setting epsilon\nA = A*(N+1);\nif ( ~exist('epsilon', 'var') || isempty(epsilon) )\n maxAbsA = max(abs(A(:)));\n epsilon = maxAbsA/25;\n% if ( sum(abs(A(:)) > 0.0001) > 0.7*N*N ) % non-sparse\n% ...\n% else\n% epsilon = 0.5*((N*maxVal)/5 + N*maxVal); % see page 260 in [1]\n% end\nend\n\nif ( ~exist('epsilonDecreaseFactor', 'var') )\n epsilonDecreaseFactor = 0.2;\nend\n\nwhile (epsilon >= 1) \n % the outer loop performs epsilon-scaling in order to speed up execution\n % time. In particular, an updated prices array is computed in each\n % round, which speeds up further rounds with lower values of epsilon.\n assignments = nan(N,1);\n while (any(isnan(assignments)))\n %% forward-auction algorithm\n %% bidding phase\n % find unassigned indices\n unassignedIdx = find(isnan(assignments));\n nUnassigned = numel(unassignedIdx);\n \n % find best and second best objects\n AijMinusPj = bsxfun(@minus, A(unassignedIdx,:), prices');\n\n [~,viIdx] = max(AijMinusPj, [], 2);\n\n for i=1:nUnassigned \n AijMinusPj(i,viIdx(i)) = -inf;\n end\n wi = max(AijMinusPj, [], 2);\n \n % compute bids\n bids = nan(nUnassigned,1);\n for i=1:nUnassigned \n bids(i) = A(unassignedIdx(i),viIdx(i)) - wi(i) + epsilon;\n end\n \n \n %% assignment phase\n objectsThatHaveBeenBiddedFor = uniqueFcn(viIdx);\n for uniqueObjIdx=1:numel(objectsThatHaveBeenBiddedFor)\n currObject = objectsThatHaveBeenBiddedFor(uniqueObjIdx);\n personssWhoGaveBidsForJ = find(viIdx==currObject);\n \n [prices(currObject), idx] = max(bids(personssWhoGaveBidsForJ));\n personWithHighestBid = unassignedIdx(personssWhoGaveBidsForJ(idx));\n \n % remove previous assignment and store new assignment (the person\n % with highest bid)\n assignments(assignments==currObject) = nan;\n assignments(personWithHighestBid) = currObject;\n \n end\n end\n epsilon = epsilon * epsilonDecreaseFactor; % refine epsilon\nend\nend\n\nfunction test()\nN = 1000;\n\nX = rand(N,3);\nreference = rand(N,3);\n\nA = X*reference';\n%% Apply Auction algorithm\ntic\n % scale A such that the integer version of A has sufficient accuracy\n % if S1 and P are not equal, the scaling factor needs to be increased\n scalingFactor = 10^6;\n Ascaled = A*scalingFactor;\n\n [assignments] = assignmentProblemAuctionAlgorithm(Ascaled);\n\n % create permutation matrix from assignments\n linIdx = sub2ind(size(A),assignments',1:size(A,1));\n P = sparse(size(A,1),size(A,2));\n P(linIdx) = 1;\ntoc\n\n%% Use CVX for checking correctness of result\n% (Useful in particular for non-integer matrices A)\n% Note that this is really slow as CVX needs to create the canonical form\n% of the LP before it can call Gurobi. Creating the canonical form by hand\n% and directly calling Gurobi is much faster.\nE = ones(N,1);\n\ntic\n cvx_begin % quiet\n cvx_solver gurobi % uncomment this line if Gurobi is not available\n variable S1(N,N) nonnegative;\n maximize (trace(S1*A));\n S1*E==E;\n E'*S1==E';\n cvx_end\ntoc\n\n% check if results are equal\nif ( sum(sum(full(S1)~=full(P))) == 0 )\n disp('Correct results using Auction algorithm');\nelse\n error('Incorrect results using Auction algorithm. You probably need to scale A by a larger factor!');\nend\nend\n", "meta": {"author": "OshriHalimi", "repo": "unsupervised_learning_of_dense_shape_correspondence", "sha": "440643d633a6db3f947ac71a247c8083cb3aeadc", "save_path": "github-repos/MATLAB/OshriHalimi-unsupervised_learning_of_dense_shape_correspondence", "path": "github-repos/MATLAB/OshriHalimi-unsupervised_learning_of_dense_shape_correspondence/unsupervised_learning_of_dense_shape_correspondence-440643d633a6db3f947ac71a247c8083cb3aeadc/Tools/PMF/assignmentProblemAuctionAlgorithm.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.8633916099737806, "lm_q1q2_score": 0.7454450782428992}} {"text": "function [C, sigma] = dataset3Params(X, y, Xval, yval)\n%DATASET3PARAMS returns your choice of C and sigma for Part 3 of the exercise\n%where you select the optimal (C, sigma) learning parameters to use for SVM\n%with RBF kernel\n% [C, sigma] = DATASET3PARAMS(X, y, Xval, yval) returns your choice of C and \n% sigma. You should complete this function to return the optimal C and \n% sigma based on a cross-validation set.\n%\n\n% You need to return the following variables correctly.\nC = 1;\nsigma = 0.3;\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Fill in this function to return the optimal C and sigma\n% learning parameters found using the cross validation set.\n% You can use svmPredict to predict the labels on the cross\n% validation set. For example, \n% predictions = svmPredict(model, Xval);\n% will return the predictions on the cross validation set.\n%\n% Note: You can compute the prediction error using \n% mean(double(predictions ~= yval))\n%\n\nC_s = [0.01, 0.03, 0.1, 0.3, 1, 3, 10, 30];\nsigma_s = C_s ;\nl = length(C_s);\nscores = zeros(l);\nfor i = 1:l\n for j = 1:l\n C = C_s(i);\n sigma = sigma_s(j);\n model= svmTrain(X, y, C, @(x1, x2) gaussianKernel(x1, x2, sigma));\n predictions = svmPredict(model, Xval);\n scores(i, j) = mean(double(predictions ~= yval));\n end\nend\n\ns = scores;\n[~, j] = min(min(s));\n[~, temp] = min(s);\ni = temp(j);\nC = C_s(i);\nsigma = sigma_s(j);\n% =========================================================================\n\nend\n", "meta": {"author": "JY-112553", "repo": "machine-learning", "sha": "db9c6e5a5175739821acd97787453472b8f46cac", "save_path": "github-repos/MATLAB/JY-112553-machine-learning", "path": "github-repos/MATLAB/JY-112553-machine-learning/machine-learning-db9c6e5a5175739821acd97787453472b8f46cac/machine-learning-ex6/ex6/dataset3Params.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382236515259, "lm_q2_score": 0.865224091265267, "lm_q1q2_score": 0.7454236266491838}} {"text": "function [SNR] = bvpsnr(BVP, FS, HR, PlotTF)\n%BVPSNR Estimates the signal-to-noise ratio of the blood volume pulse\n% signal. Adapted from the method by G. de Haan, TBME, 2013.\n% SNR calculated as the ratio (in dB) of power contained within +/- 0.1 Hz\n% of the reference heart rate frequency and +/- 0.2 of its first\n% harmonic and sum of all other power between 0.5 and 4 Hz.\n% Adapted from the method by G. de Haan, TBME, 2013\n%\n% Inputs:\n% BVP = A BVP timeseries.\n% FS = The sample rate of the BVP time series (Hz/fps).\n% HR = The reference heart rate (Hz/fps).\n% PlotTF = Boolean to turn plotting results on or off.\n%\n% Outputs:\n% SNR = Blood Volume Pulse Signal-to-Noise Ratio.\n%\n% Daniel McDuff, Ethan Blackford, January 2019\n% Copyright (c)\n% Licensed under the MIT License and the RAIL AI License.\n\nHR_F=HR/60;\n\nNyquistF = FS/2;\nFResBPM = 0.5; %resolution (bpm) of bins in power spectrum used to determine PR and SNR\nN = (60*2*NyquistF)/FResBPM; %number of bins in power spectrum\n\n%% Construct Periodogram\n[Pxx,F] = periodogram(BVP,hamming(length(BVP)),N,FS);\nGTMask1 = (F >= HR_F-0.1)&(F <= HR_F+0.1);\nGTMask2 = (F >= HR_F*2-0.2)&(F <= HR_F*2+0.2);\nSPower = sum(Pxx(GTMask1|GTMask2));\nFMask2 = (F >= 0.5)&(F <= 4);\nAllPower = sum(Pxx(FMask2));\nSNR = pow2db(SPower/(AllPower-SPower));\n\n%% Optionally plot the power spectrum and regions used to calculate the SNR\nif(PlotTF)\n % Plot spower spectrum and SNR regions\n figure\n plot(F,pow2db(Pxx))\n title('Power Spectrum and SNR Regions')\n xlabel('Frequency (Hz)')\n ylabel('Power (dB)')\n xlim([0.5 4])\n ylimreg=ylim;\n hold on\n \n % HR peak\n %line([HR_F,HR_F],ylim,'Color','magenta','LineStyle','-.')\n \n % HR peak region\n line([HR_F-0.1,HR_F-0.1],ylim,'Color','red','LineStyle','--')\n line([HR_F+0.1,HR_F+0.1],ylim,'Color','red','LineStyle','--')\n \n % First harmonic\n line([HR_F*2-0.2,HR_F*2-0.2],ylim,'Color','red','LineStyle','--')\n line([HR_F*2+0.2,HR_F*2+0.2],ylim,'Color','red','LineStyle','--')\n \n % Overall power region\n line([0.5,0.5],ylim,'Color','black','LineStyle','-')\n line([4,4],ylim,'Color','black','LineStyle','-')\n \n % Adjust axes\n xlim([0 4.5])\n ylim(ylimreg);\nend\n\nend\n\n", "meta": {"author": "danmcduff", "repo": "iphys-toolbox", "sha": "65deeb46aea80c04009fe304a6612e4ef1497f08", "save_path": "github-repos/MATLAB/danmcduff-iphys-toolbox", "path": "github-repos/MATLAB/danmcduff-iphys-toolbox/iphys-toolbox-65deeb46aea80c04009fe304a6612e4ef1497f08/tools/bvpsnr.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92522995296862, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.7453950323211332}} {"text": "function geometry_test1895 ( )\n\n%*****************************************************************************80\n%\n%% TEST1895 tests SPHERE_UNIT_AREA_ND, SPHERE_UNIT_AREA_VALUES.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 22 May 2005\n%\n% Author:\n%\n% John Burkardt\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TEST1895:\\n' );\n fprintf ( 1, ' SPHERE_UNIT_AREA_ND evaluates the area of the unit\\n' );\n fprintf ( 1, ' sphere in N dimensions.\\n' );\n fprintf ( 1, ' SPHERE_UNIT_AREA_VALUES returns some test values.\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' DIM_NUM Exact Computed\\n' );\n fprintf ( 1, ' Area Area\\n' );\n fprintf ( 1, '\\n' );\n\n n_data = 0;\n\n while ( 1 )\n\n [ n_data, dim_num, area ] = sphere_unit_area_values ( n_data );\n\n if ( n_data == 0 )\n break\n end\n\n area2 = sphere_unit_area_nd ( dim_num );\n\n fprintf ( 1, ' %6d %10f %10f\\n', dim_num, area, area2 );\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/geometry/geometry_test1895.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357735451835, "lm_q2_score": 0.8596637577007394, "lm_q1q2_score": 0.7453592311468198}} {"text": "function result = intersect2(cell)\n\n% PURPOSE:\n% This function finds the common elements of several 1D numeric arrays \n% of the same or different sizes and returns an array consisting of only \n% those elements.\n%\n% INPUT:\n% The input variable \"cell\" has to be a cell array, with each cell\n% occupied by an 1D numeric array. For example, if you want to find the \n% intersection (common elements) of the following three arrays\n% a = [ 1 3 4 6 8 9 ];\n% b = [ 3 1 0 8 6 4 ];\n% c = [ 7 8 1 9 3 4 ];,\n% you need to first put all of them into a cell array, i.e.\n% cell = {a, b, c};\n% Then you could use \"cell\" as the input variable to this function, i.e.\n% result = intersect2(cell);\n% \n% OUTPUT:\n% The output of this function is simply an array consisting of elements\n% that are common to all the arrays stored in \"cell\". For the particular\n% case in the example above, the output would be\n% result = [ 1 3 4 8 ];\n% Also note that the numbers in the result are sorted in ascending order.\n\nn = max(size(cell));\n\nif n == 2\n result = intersect(cell{1, 1}, cell{1, 2});\nelseif (n > 2 && rem(n,2) == 0)\n for i = 1:(n/2)\n intersections{1, i} = intersect(cell{1, i}, cell{1, n-i+1});\n end\nelseif (n > 2 && rem(n,2) == 1)\n for i = 1:((n-1)/2)\n intersections{1, i} = intersect(cell{1, i}, cell{1, n-i+1});\n end\n intersections{1, i+1} = cell{1, (n+1)/2}; \nelse\n error('You need at least two arrays as inputs');\nend\n\nif n > 2\n result = intersect2(intersections);\nend", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/19359-intersect2/intersect2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357666736773, "lm_q2_score": 0.8596637541053281, "lm_q1q2_score": 0.7453592221222848}} {"text": "function numgrad = computeNumericalGradient(J, theta)\n% numgrad = computeNumericalGradient(J, theta)\n% theta: a vector of parameters\n% J: a function that outputs a real-number. Calling y = J(theta) will return the\n% function value at theta. \n \n% Initialize numgrad with zeros\nnumgrad = zeros(size(theta));\n\n%% ---------- YOUR CODE HERE --------------------------------------\n% Instructions: \n% Implement numerical gradient checking, and return the result in numgrad. \n% (See Section 2.3 of the lecture notes.)\n% You should write code so that numgrad(i) is (the numerical approximation to) the \n% partial derivative of J with respect to the i-th input argument, evaluated at theta. \n% I.e., numgrad(i) should be the (approximately) the partial derivative of J with \n% respect to theta(i).\n% \n% Hint: You will probably want to compute the elements of numgrad one at a time. \n\nepsilon = 1e-4;\n\nfor i =1:length(numgrad)\n oldT = theta(i);\n theta(i)=oldT+epsilon;\n pos = J(theta);\n theta(i)=oldT-epsilon;\n neg = J(theta);\n numgrad(i) = (pos-neg)/(2*epsilon);\n theta(i)=oldT;\n if mod(i,100)==0\n fprintf('Done with %d\\n',i);\n end;\nend;\n\n%% ---------------------------------------------------------------\nend", "meta": {"author": "xuzhenqi", "repo": "cnn", "sha": "3b505ad0fc3bbb0cc5331d109702b6921fef2cb2", "save_path": "github-repos/MATLAB/xuzhenqi-cnn", "path": "github-repos/MATLAB/xuzhenqi-cnn/cnn-3b505ad0fc3bbb0cc5331d109702b6921fef2cb2/DebugTools/computeNumericalGradient.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357666736772, "lm_q2_score": 0.8596637505099167, "lm_q1q2_score": 0.7453592190049344}} {"text": "function p = predict(theta, X)\n%PREDICT Predict whether the label is 0 or 1 using learned logistic \n%regression parameters theta\n% p = PREDICT(theta, X) computes the predictions for X using a \n% threshold at 0.5 (i.e., if sigmoid(theta'*x) >= 0.5, predict 1)\n\nm = size(X, 1); % Number of training examples\n\n% You need to return the following variables correctly\np = zeros(m, 1);\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Complete the following code to make predictions using\n% your learned logistic regression parameters. \n% You should set p to a vector of 0's and 1's\n%\n\nfor i=1:m,\n\tif sigmoid(X(i,:)*theta) >= 0.5,\n\t\tp(i) = 1;\n\telse\n\t\tp(i) = 0;\n\tend;\nend;\n\n% =========================================================================\n\n\nend\n", "meta": {"author": "UtkarshPathrabe", "repo": "Machine-Learning-Stanford-University-Coursera", "sha": "0e5855855b5ddd475775b75bad69b47c2ebe84ef", "save_path": "github-repos/MATLAB/UtkarshPathrabe-Machine-Learning-Stanford-University-Coursera", "path": "github-repos/MATLAB/UtkarshPathrabe-Machine-Learning-Stanford-University-Coursera/Machine-Learning-Stanford-University-Coursera-0e5855855b5ddd475775b75bad69b47c2ebe84ef/Programming Exercises/machine-learning-ex2/ex2/predict.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637361282706, "lm_q2_score": 0.867035763237924, "lm_q1q2_score": 0.7453592035819404}} {"text": "function gZ = vrate(Z,s)\n% PURPOSE: Compute the year-on-year rate of growth of a vector time series\n% ------------------------------------------------------------------------\n% SYNTAX: gZ = vrate(Z,s);\n% ------------------------------------------------------------\n% OUTPUT: gZ: nxk --> yoy rate of growth. First s obs are NaN\n% ------------------------------------------------------------\n% INPUT: Z: nxk --> vector time series to be filtered\n% s: 1x1 --> number of periods per year\n% ------------------------------------------------------------\n% LIBRARY: rate\n% -----------------------------------------------------------------------\n\n% written by:\n% Enrique M. Quilis\n% Macroeconomic Research Department\n% Ministry of Economy and Competitiveness\n% \n\n% Version 1.1 [August 2006]\n\n[n,k] = size(Z);\n\n% Preallocation\ngZ = NaN * ones(n,k);\n\n% Basic loop\nfor j=1:k\n gz = rate(Z(:,j),s);\n gZ(:,j) = gz;\nend\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/39770-temporal-disaggregation-library/vrate.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9196425289753969, "lm_q2_score": 0.8104789063814617, "lm_q1q2_score": 0.7453508711458614}} {"text": "function ds = dsegment ( p, pv )\n\n%*****************************************************************************80\n%\n%% DSEGMENT computes the distance of points to line segments.\n%\n% Discussion:\n%\n% This is a pure MATLAB version of the DSEGMENT routine.\n% Normally, the authors of DISTMESH recommend using a faster procedure\n% in which a MATLAB MEX interface is used to call a compiled C code.\n% But if that is not possible, you can fall back on this slower\n% version.\n%\n% Note that the line segments are defined by successive pairs of\n% vertices. In the very common case that the vertices represent\n% a polygon, it is necessary that the list be extended by repeating\n% the first vertex at the end; otherwise the definition of the\n% polygon, and the distance computation, will be incomplete.\n%\n% Licensing:\n%\n% (C) 2004 Per-Olof Persson. \n% See COPYRIGHT.TXT for details.\n%\n% Parameters:\n%\n% Input, real P(NP,2), a set of points.\n%\n% Input, real PV(NVS,2), a set of vertices. Sequential\n% pairs define NVS-1 line segments.\n%\n% Output, real DS(NP,NVS-1); DS(I,J) is the (unsigned) distance\n% of point P(I,:) from line segment PV(J,:)--PV(J+1,:).\n%\n nvs = size ( pv, 1 );\n np = size ( p, 1 );\n\n ds = zeros ( np,nvs-1);\n\n for iv = 1 : nvs-1\n for ip = 1 : np\n\n v(1:2) = [ pv(iv+1,1) - pv(iv,1), pv(iv+1,2) - pv(iv,2) ];\n\n w(1:2) = [ p(ip,1) - pv(iv,1), p(ip,2) - pv(iv,2) ];\n\n c1 = v * w';\n c2 = v * v';\n\n if ( c1 <= 0.0 )\n ds(ip,iv) = sqrt ( sum ( ( p(ip,1:2) - pv(iv,1:2) ).^2 ) );\n elseif ( c2 <= c1 )\n ds(ip,iv) = sqrt ( sum ( ( p(ip,1:2) - pv(iv+1,1:2) ).^2 ) );\n else\n ds(ip,iv) = sqrt ( sum ( ( p(ip,1:2) ...\n - pv(iv,1:2) - c1 / c2 * v(1:2) ).^2 ) );\n end\n\n end \n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/distmesh/dsegment.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213880824791, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.745316613873207}} {"text": "%wrap - Set radian angles in range [0,2pi] or [-pi,pi].\n%\n% USAGE\n%\n% y = wrap(x,range)\n%\n% x angles in radians\n% range optional: 1 for [-pi,pi] (default)\n% 2 for [0,2pi]\n%\n% SEE ALSO\n%\n% See also isradians.\n%\n\n% Copyright (C) 2010-2011 by Micha\u00ebl Zugaro\n%\n% This program is free software; you can redistribute it and/or modify\n% it under the terms of the GNU General Public License as published by\n% the Free Software Foundation; either version 3 of the License, or\n% (at your option) any later version.\n\nfunction y = wrap(x,range)\n\n% Check number of parameters\nif nargin < 1,\n error('Incorrect number of parameters (type ''help wrap'' for details).');\nend\n\nif nargin < 2,\n\trange = 1;\nend\n\nif ~isa(x,'double'), y = []; return; end\n\n% Determine angle in [0,2*pi]\ny = mod(x,2*pi);\n\n% Change range if necessary\nif range == 1,\n\tchange = y > pi;\n\ty(change) = y(change)-2*pi;\nend\n", "meta": {"author": "fieldtrip", "repo": "fieldtrip", "sha": "c2039be598a02d86b39aae76bfa7aaa720f9801c", "save_path": "github-repos/MATLAB/fieldtrip-fieldtrip", "path": "github-repos/MATLAB/fieldtrip-fieldtrip/fieldtrip-c2039be598a02d86b39aae76bfa7aaa720f9801c/external/neuroscope/private/wrap.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8991213826762114, "lm_q2_score": 0.8289388040954684, "lm_q1q2_score": 0.7453166036922827}} {"text": "function sine_transform_test01 ( )\n\n%*****************************************************************************80\n%\n%% SINE_TRANSFORM_TEST01 demonstrates that the transform is its own inverse.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 19 February 2012\n%\n% Author:\n%\n% John Burkardt\n%\n n = 10;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'SINE_TRANSFORM_TEST01:\\n' );\n fprintf ( 1, ' SINE_TRANSFORM_DATA does a sine transform of data\\n' );\n fprintf ( 1, ' defined by a vector.\\n' );\n fprintf ( 1, '\\n' ); \n fprintf ( 1, ' Demonstrate that the transform is its own inverse.\\n' );\n fprintf ( 1, ' Let R be a random N vector.\\n' );\n fprintf ( 1, ' Let S be the transform of D.\\n' );\n fprintf ( 1, ' Let T be the transform of E.\\n' );\n fprintf ( 1, ' Then R and T will be equal.\\n' );\n\n% r = rand ( n, 1 );\n seed = 123456789;\n [ r, seed ] = r8vec_uniform_01 ( n, seed );\n s = sine_transform_data ( n, r );\n t = sine_transform_data ( n, s );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' I R(I) S(I) T(I)\\n' );\n fprintf ( 1, '\\n' );\n\n for i = 1 : n\n fprintf ( 1, ' %4d %10f %10f %10f\\n', i, r(i), s(i), t(i) );\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/sine_transform/sine_transform_test01.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267830311354, "lm_q2_score": 0.8577681031721324, "lm_q1q2_score": 0.7452519016657628}} {"text": "%%%\n%> @brief computes the homogeneous transformation A of the pose vector v\n%> @param v pose vector\n%> @return A homogeneous transformation\n%> @author Giorgio Grisetti\n%%%\nfunction A = v2t(v)\n% V2T vector to homogeneous transformation\nc = cos(v(3));\ns = sin(v(3));\nA = [c, -s, v(1);\n s, c, v(2);\n 0 0 1];\nend", "meta": {"author": "versatran01", "repo": "graphslam", "sha": "c09bb80285e7356897b5cb39f236f84731bc976f", "save_path": "github-repos/MATLAB/versatran01-graphslam", "path": "github-repos/MATLAB/versatran01-graphslam/graphslam-c09bb80285e7356897b5cb39f236f84731bc976f/lsslam/v2t.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9621075690244281, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.7452325417520554}} {"text": "function [colatitude, longitude, r] = AMICO_Cart2sphere(x, y, z)\n\tr = sqrt(x.^2 + y.^2 + z.^2);\n\tlongitude = atan2(y, x);\n\tcolatitude = atan2(sqrt(x.^2 + y.^2), z);\nend\n", "meta": {"author": "qMRLab", "repo": "qMRLab", "sha": "036ff20b47e939877f746940a969494b55911636", "save_path": "github-repos/MATLAB/qMRLab-qMRLab", "path": "github-repos/MATLAB/qMRLab-qMRLab/qMRLab-036ff20b47e939877f746940a969494b55911636/External/AMICO/AMICO_matlab/kernels/AMICO_Cart2sphere.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9553191309994467, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.7451421347708012}} {"text": "function [A,B,D,E,I]=mdds(X)\n% gets A, B, D, E & I arrays for magnet driver\nN=2;U=3;M=1;Y=1;\nA1=zeros(U+N);B2=zeros(U+N,N+M);\n%\n% X = [R1 R2 R3 C1 C2]\n%\nR1=X(1);R2=X(2);R3=X(3);C1=X(4);C2=X(5);\n%\n% V1 V2 V3 iC1 iC2 column labels for A1\n% 1 2 3 4\t5\n%\nA1(1,1)=-1/R1;A1(1,4)=-1;A1(1,5)=-1; % From 1st equation\nA1(2,1)=1/R2;A1(2,2)=-1/R2;A1(2,4)=-1; % 2nd equation\nA1(3,3)=1;A1(3,4)=-R3;A1(3,5)=-R3; % V3 - iC1*R3 - iC2*R3 = 0\nA1(4,2)=1;A1(4,3)=-1; % V2 - V3 = E1\nA1(5,1)=1;A1(5,3)=-1; % V1 - V3 = E2\n%\nE1=1;E2=1;Ein=1;\n% E1 E2 Ein Column labels for B2\n% 1 2 3\nB2(4,1)=E1;\nB2(5,2)=E2;\nB2(1,3)=-Ein/R1;\n%\nP=diag([C1 C2]);\n%\n% Template statements (same for every circuit):\nV=A1\\B2;H=V(U+1:U+N,1:N+M);I=eye(N);\nAB=P\\H;A=AB(1:N,1:N);B=AB(1:N,N+1:N+M);\nD=V(Y:Y,1:N);E=V(Y:Y,N+1:N+M);\n\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/2435-shortcut-state-space-circuit-analysis/Matlab_Files/mdds.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9688561694652215, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.7451281324997501}} {"text": "function order_num = tetrahedron_ncc_order_num ( rule )\n\n%*****************************************************************************80\n%\n%% TETRAHEDRON_NCC_ORDER_NUM returns the order of an NCC rule for the tetrahedron.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 30 January 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Peter Silvester,\n% Symmetric Quadrature Formulae for Simplexes,\n% Mathematics of Computation,\n% Volume 24, Number 109, January 1970, pages 95-100.\n%\n% Parameters:\n%\n% Input, integer RULE, the index of the rule.\n%\n% Output, integer ORDER_NUM, the order (number of points) of the rule.\n%\n suborder_num = tetrahedron_ncc_suborder_num ( rule );\n\n suborder(1:suborder_num) = tetrahedron_ncc_suborder ( rule, suborder_num );\n\n order_num = sum ( suborder(1:suborder_num) );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/tetrahedron_ncc_rule/tetrahedron_ncc_order_num.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8807970779778824, "lm_q2_score": 0.845942439250491, "lm_q1q2_score": 0.7451036286293148}} {"text": "%TEST_SmoothAbs\n%\n% This script plots the output of SmoothAbs for a few values of alpha, over\n% the domain [-1,1]\n%\n% Written by Matthew Kelly\n% October 2013\n% Cornell University\n%\n\nt = linspace(-1,1,1000);\nalpha = [0.02,0.1,0.5];\nN=length(alpha);\n\nfigure(104); clf; hold on;\nfor i=1:N\n x1 = SmoothAbs(t,alpha(i));\n\n subplot(N,1,i); hold on;\n plot(t,x1,'b-','LineWidth',2)\n plot(t,abs(t),'k:')\n title(['Alpha = ' num2str(alpha(i))],'FontSize',14);\nend", "meta": {"author": "MatthewPeterKelly", "repo": "dscTutorials", "sha": "e1e97a9be03ec146f88bd6ddd9e06db7ee52e242", "save_path": "github-repos/MATLAB/MatthewPeterKelly-dscTutorials", "path": "github-repos/MATLAB/MatthewPeterKelly-dscTutorials/dscTutorials-e1e97a9be03ec146f88bd6ddd9e06db7ee52e242/smoothing/exponentialSmoothing/TEST_SmoothAbs.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511579973931, "lm_q2_score": 0.8705972717658209, "lm_q1q2_score": 0.7451016831901489}} {"text": "%GETDERIVKERNELS Returns filter coefficients for computing spatial image derivatives\n%\n% [kx, ky] = cv.getDerivKernels('OptionName', optionValue, ...)\n%\n% ## Output\n% * __kx__ Output matrix of row filter coefficients. It has the type `KType`.\n% * __ky__ Output matrix of column filter coefficients. It has the type\n% `KType`.\n%\n% ## Options\n% * __Dx__ Derivative order in respect of x. default 1\n% * __Dy__ Derivative order in respect of y. default 1\n% * __KSize__ Aperture size. It can be 'Scharr', 1, 3, 5, or 7. default 3.\n% * __Normalize__ Flag indicating whether to normalize (scale down) the filter\n% coefficients or not. Theoretically, the coefficients should have the\n% `denominator = 2^(KSize*2-Dx-Dy-2)`. If you are going to filter\n% floating-point images, you are likely to use the normalized kernels. But\n% if you compute derivatives of an 8-bit image, store the results in a\n% 16-bit image, and wish to preserve all the fractional bits, you may want\n% to set `Normalize=false`. default false\n% * __KType__ Type of filter coefficients. It can be `single` or `double`.\n% default `single`\n%\n% The function computes and returns the filter coefficients for spatial image\n% derivatives. When `KSize='Scharr'`, the Scharr 3x3 kernels are generated\n% (see cv.Scharr). Otherwise, Sobel kernels are generated (see cv.Sobel). The\n% filters are normally passed to cv.sepFilter2D.\n%\n% See also: cv.sepFilter2D, cv.getDerivKernels, cv.getStructuringElement\n%\n", "meta": {"author": "kyamagu", "repo": "mexopencv", "sha": "d29007b2a484d0fd92e6e941dc5fd4750014fa6a", "save_path": "github-repos/MATLAB/kyamagu-mexopencv", "path": "github-repos/MATLAB/kyamagu-mexopencv/mexopencv-d29007b2a484d0fd92e6e941dc5fd4750014fa6a/+cv/getDerivKernels.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8558511469672594, "lm_q2_score": 0.8705972751232808, "lm_q1q2_score": 0.7451016764608306}} {"text": "% M-File showing that the RA method of creating the A & B arrays\n% gives the same results using the conventional method.\n% File: c:\\M_files\\short_updates\\Matlab_Files\\RAconvention.m\n% 02/16/07\n% See Word file UsingGarray1.doc for background explanations.\nclear;clc; \n% unit suffixes\nu=1e-6;K=1e3;m=1e-3;u=1e-6;p=1e-12;\n% component values\nR1=5*K;R2=1*K;R3=10*K;\nC1=0.1*u;C2=400*p;\nEin=1; % Unity input for (normalized) transfer function\n%\n% Form W, Q, S, and P arrays: \n%\nW=[1+R3/R1 1+R3/R1;R2 0];Q=[0 -1/R1;-1 1];S=[Ein/R1;0];P=diag([C1 C2]);\n%\n% Get A & B arrays using RA method:\n%\nC=inv(W*P);A=C*Q;B=C*S;\n% Display A & B in Command window:\ndisp('RA Method')\ndisp(' ')\nA\nB\ndisp(' ')\n% Using conventional method:\n%\ndisp('Conventional method')\ndisp(' ')\nA=[-1/(R2*C1) 1/(R2*C1);1/(R2*C2) (1/(R1+R3)+1/R2)/C2]\nB=[0;(1/(R1+R3))/C2]\n%\n\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/2435-shortcut-state-space-circuit-analysis/Matlab_Files/RAconvention.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067211996142, "lm_q2_score": 0.7905303112671295, "lm_q1q2_score": 0.7450801316812926}} {"text": "function [q]=zn2fpd(input)\n% [q]=zn2fpd(input)\n% Ziegler-Nichols controller for 2nd order processes\n% This function computes parameters of the controller (q0, q1, q2, q3, q4).\n% Controller is based on forward rectangular method of discretization\n% replacing derivation by a four-point difference.\n% Transfer function of the controller is as follows:\n%\n% q0 + q1*z^-1 + q2*z^-2 + q3*z^-3 + q4*z^-4\n% G(z^-1) = --------------------------------------------\n% 1 - z^-1\n%\n% Transfer function of the controlled system is:\n%\n% b1*z^-1 + b2*z^-2 \n% Gs(z^-1) = -----------------------\n% 1 + a1*z^-1 + a2*z^-2\n%\n% Input: input ... input parameters\n% input(1) ... a1\n% input(2) ... b1\n% input(3) ... a2\n% input(4) ... b2\n% input(5) ... sample time T0\n% Output: qp ... controller parameters \n% qp(1) ... q0\n% qp(2) ... q1\n% qp(3) ... q2\n% qp(4) ... p1\n% qp(5) ... p2\n\na1 = input(1);\nb1 = input(2);\na2 = input(3);\nb2 = input(4);\nT0 = input(5);\n\n% compute ultimate gain and frequency\n[Kpu, Tu] = ultim([b1 b2],[a1 a2],T0);\n\nKp = 0.6*Kpu;\nTi = Tu/2;\nTd = Tu/8;\n\nq0 = Kp*(1 + T0/Ti + Td/(6*T0));\nq1 = Kp*(-1 + Td/(3*T0));\nq2 = Kp*(-Td/T0);\nq3 = Kp*(Td/(3*T0));\nq4 = Kp*(Td/(6*T0));\n\nq=[q0;q1;q2;q3;q4];", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/8381-stcsl-standard-version/zn2fpd.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9585377320263431, "lm_q2_score": 0.7772998611746911, "lm_q1q2_score": 0.7450712460347797}} {"text": "%GENDATH Generation of Highleyman classes\n% \n% A = GENDATH(N,LABTYPE)\n%\n% INPUT\n% N Number of objects (optional; default: [50,50])\n% LABTYPE Label type (optional; default: 'crisp')\n%\n% OUTPUT\n% A Generated dataset\n%\n% DESCRIPTION\n% Generation of a 2-dimensional 2-class dataset A of N objects\n% according to Highleyman. \n%\n% The two Highleyman classes are defined by \n% 1: Gauss([1 1],[1 0; 0 0.25]).\n% 2: Gauss([2 0],[0.01 0; 0 4]).\n% Class priors are P(1) = P(2) = 0.5 \n%\n% If N is a vector of sizes, exactly N(I) objects are generated\n% for class I, I = 1,2.\n%\n% LABTYPE defines the desired label type: 'crisp' or 'soft'. In the \n% latter case true posterior probabilities are set for the labels.\n%\n% Defaults: N = [50,50], LABTYPE = 'crisp'.\n% \n% EXAMPLES\n% PREX_PLOTC, PREX_CLEVAL\n%\n% SEE ALSO (PRTools Guide)\n% DATASETS, GAUSS, PRDATASETS\n\n% Copyright: R.P.W. Duin, duin@ph.tn.tudelft.nl\n% Faculty of Applied Sciences, Delft University of Technology\n% P.O. Box 5046, 2600 GA Delft, The Netherlands\n\n% $Id: gendath.m,v 1.5 2009/01/27 13:01:42 duin Exp $\n\nfunction A = gendath(N,labtype)\n\n\t\t\n\tif nargin < 1, N = [50, 50]; end\n\tif nargin < 2, labtype = 'crisp'; end\n\n\tGA = [1 0; 0 0.25];\n\tGB = [0.01 0; 0 4];\n\tG = cat(3,GA,GB);\n\tp = [0.5 0.5];\n\tN = genclass(N,p);\n\tU = prdataset([1 1; 2 0],[1 2]','prior',p);\n\tU = setprior(U,p);\n\tA = gendatgauss(N,U,G);\n\tA = setname(A,'Highleyman Dataset');\n\n\tswitch labtype\n\t case 'crisp'\n\t ;\n\t case 'soft'\n\t W = nbayesc(U,cat(3,GA,GB));\n\t targets = A*W*classc;\n\t A = setlabtype(A,'soft',targets);\n\t otherwise\n\t error(['Label type ' labtype ' not supported'])\n\tend\n\n\treturn\n", "meta": {"author": "marianux", "repo": "ecg-kit", "sha": "c8e3de47c54a9214138143676d2aa546b0540dd2", "save_path": "github-repos/MATLAB/marianux-ecg-kit", "path": "github-repos/MATLAB/marianux-ecg-kit/ecg-kit-c8e3de47c54a9214138143676d2aa546b0540dd2/common/prtools/gendath.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8872045937171067, "lm_q2_score": 0.83973396967765, "lm_q1q2_score": 0.7450158353983126}} {"text": "function [EC,ec,degij] = edge_nei_overlap_bd(CIJ)\n%EDGE_NEI_OVERLAP_BD overlap amongst neighbors of two adjacent nodes\n%\n% [EC,ec,degij] = edge_nei_bd(CIJ);\n%\n% This function determines the neighbors of two nodes that are linked by \n% an edge, and then computes their overlap. Connection matrix must be\n% binary and directed. Entries of 'EC' that are 'inf' indicate that no\n% edge is present. Entries of 'EC' that are 0 denote \"local bridges\",\n% i.e. edges that link completely non-overlapping neighborhoods. Low\n% values of EC indicate edges that are \"weak ties\".\n%\n% If CIJ is weighted, the weights are ignored. Neighbors of a node can be\n% linked by incoming, outgoing, or reciprocal connections.\n%\n% Inputs: CIJ, directed (binary/weighted) connection matrix\n% \n% Outputs: EC, edge neighborhood overlap matrix\n% ec, edge neighborhood overlap per edge, in vector format\n% degij, degrees of node pairs connected by each edge\n%\n% Reference:\n%\n% Easley and Kleinberg (2010) Networks, Crowds, and Markets. \n% Cambridge University Press, Chapter 3\n%\n% Olaf Sporns, Indiana University, 2012\n\n[ik,jk,ck] = find(CIJ);\nlel = length(ck);\nN = size(CIJ,1);\n\n[~,~,deg] = degrees_dir(CIJ);\n\nec = zeros(1,lel);\ndegij = zeros(2,lel);\nfor e=1:lel\n neiik = setdiff(union(find(CIJ(ik(e),:)),find(CIJ(:,ik(e))')),[ik(e) jk(e)]);\n neijk = setdiff(union(find(CIJ(jk(e),:)),find(CIJ(:,jk(e))')),[ik(e) jk(e)]);\n ec(e) = length(intersect(neiik,neijk))/length(union(neiik,neijk));\n degij(:,e) = [deg(ik(e)) deg(jk(e))];\nend;\n\nff = find(CIJ);\nEC = 1./zeros(N);\nEC(ff) = ec; %#ok\n\n\n", "meta": {"author": "fieldtrip", "repo": "fieldtrip", "sha": "c2039be598a02d86b39aae76bfa7aaa720f9801c", "save_path": "github-repos/MATLAB/fieldtrip-fieldtrip", "path": "github-repos/MATLAB/fieldtrip-fieldtrip/fieldtrip-c2039be598a02d86b39aae76bfa7aaa720f9801c/external/bct/edge_nei_overlap_bd.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171067, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.7450158282814744}} {"text": "function MD = mahalanobis(x,m,P)\n\n% MAHALANOBIS Mahalanobis distance\n% MD = MAHALANOBIS(X,M,P) computes the Mahalanobis distance from a point\n% X to a Gaussian of mean M and covariance P:\n%\n% MD = sqrt((X-M)'*inv(P)*(X-M));\n%\n% See also NEES.\n\n% Copyright 2008-2009 Joan Sola @ LAAS-CNRS.\n\nMD = sqrt((x-m)'/P*(x-m));\n\n\n\n% ========== End of function - Start GPL license ==========\n\n\n% # START GPL LICENSE\n\n%---------------------------------------------------------------------\n%\n% This file is part of SLAMTB, a SLAM toolbox for Matlab.\n%\n% SLAMTB is free software: you can redistribute it and/or modify\n% it under the terms of the GNU General Public License as published by\n% the Free Software Foundation, either version 3 of the License, or\n% (at your option) any later version.\n%\n% SLAMTB is distributed in the hope that it will be useful,\n% but WITHOUT ANY WARRANTY; without even the implied warranty of\n% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n% GNU General Public License for more details.\n%\n% You should have received a copy of the GNU General Public License\n% along with SLAMTB. If not, see .\n%\n%---------------------------------------------------------------------\n\n% SLAMTB is Copyright:\n% Copyright (c) 2008-2010, Joan Sola @ LAAS-CNRS,\n% Copyright (c) 2010-2013, Joan Sola,\n% Copyright (c) 2014-2015, Joan Sola @ IRI-UPC-CSIC,\n% SLAMTB is Copyright 2009 \n% by Joan Sola, Teresa Vidal-Calleja, David Marquez and Jean Marie Codol\n% @ LAAS-CNRS.\n% See on top of this file for its particular copyright.\n\n% # END GPL LICENSE\n\n", "meta": {"author": "joansola", "repo": "slamtb", "sha": "b4767f6bf38bceed205abb85f1aed12422c9a972", "save_path": "github-repos/MATLAB/joansola-slamtb", "path": "github-repos/MATLAB/joansola-slamtb/slamtb-b4767f6bf38bceed205abb85f1aed12422c9a972/Math/mahalanobis.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582593509315, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.7450104843337921}} {"text": "% test for ti quicunx\n\nname = 'turbulence';\nname = 'lena';\nn = 256;\nM = load_image(name);\nM = rescale( crop(M,n) );\nJmax = log2(n)-1;\nJmin = Jmax-5;\n\n% boundary conditions\noptions.bound = 'per';\noptions.bound = 'sym';\n% vanishing moments\nvm = 6;\noptions.primal_vm = vm;\noptions.dual_vm = vm;\n\n% transform\ndisp('Computing forward transform');\nMW = perform_quicunx_wavelet_transform_ti(M,Jmin,options);\ndisp('Computing backward transform');\nM1 = perform_quicunx_wavelet_transform_ti(MW,Jmin,options);\ndisp(['Error=' num2str(norm(M-M1,'fro')/norm(M,'fro')) ' (should be 0).']);\n\nrep = 'results/quincunx/';\nif not(exist(rep))\n mkdir(rep);\nend\n\n% display dual wavelets\nclf;\nfor j=7:12\n MW = MW*0;\n MW(end/2,end/2,j) = 1;\n M1 = perform_quicunx_wavelet_transform_ti(MW,Jmin,options);\n imageplot(M1, '', 4,3,j);\n % save\n if j>6\n warning off;\n% imwrite(rescale(M1), [rep 'quincunx-wavelet-' num2string_fixeddigit(j,2) '.png'], 'png');\n warning on;\n clf;\n surf(M1);\n shading interp; colormap jet(256)\n view(-20,50); axis tight; axis off;\n camlight;\n saveas(gcf, [rep 'quincunx-wavelet-vm' num2str(vm) '-' num2string_fixeddigit(j,2) '.png'], 'png');\n end\nend", "meta": {"author": "gpeyre", "repo": "matlab-toolboxes", "sha": "0cd622c988cda6f63f64d35cd7bd096fa578e5c6", "save_path": "github-repos/MATLAB/gpeyre-matlab-toolboxes", "path": "github-repos/MATLAB/gpeyre-matlab-toolboxes/matlab-toolboxes-0cd622c988cda6f63f64d35cd7bd096fa578e5c6/toolbox_wavelets/tests/test_quincunx_ti.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582632076909, "lm_q2_score": 0.8006919925839875, "lm_q1q2_score": 0.7450104807840023}} {"text": "function [x, funVal, ValueL]=LeastR(A, y, z, opts)\n%\n%%\n% Function LeastR\n% Least Squares Loss with the L1-norm Regularization\n%\n%% Problem\n%\n% min 1/2 || A x - y||^2 + 1/2 rsL2 * ||x||_2^2 + z * ||x||_1\n%\n% By default, rsL2=0.\n% When rsL2 is nonzero, this corresponds to the well-know elastic net.\n%\n%% Input parameters:\n%\n% A- Matrix of size m x n\n% A can be a dense matrix\n% a sparse matrix\n% or a DCT matrix\n% y - Response vector (of size mx1)\n% z - L_1 norm regularization parameter (z >=0)\n% opts- Optional inputs (default value: opts=[])\n%\n%% Output parameters:\n% x- Solution\n% funVal- Function value during iterations\n%\n%% Copyright (C) 2009-2010 Jun Liu, and Jieping Ye\n%\n% You are suggested to first read the Manual.\n%\n% For any problem, please contact with Jun Liu via j.liu@asu.edu\n%\n% Last modified on February 18, 2010.\n%\n%% Related papers\n%\n% [1] Jun Liu and Jieping Ye, Efficient Euclidean Projections\n% in Linear Time, ICML 2009.\n%\n% [2] Jun Liu and Jieping Ye, Sparse Learning with Efficient Euclidean\n% Projections onto the L1 Ball, Technical Report ASU, 2008.\n%\n%% Related functions\n% \n% sll_opts, initFactor, pathSolutionLeast\n% LeastC, nnLeastR, nnLeastC, \n%\n%%\n\n%% Verify and initialize the parameters\n%%\n\n% Verify the number of input parameters\nif (nargin <3)\n error('\\n Inputs: A, y and z should be specified!\\n');\nelseif (nargin==3)\n opts=[];\nend\n\n% Get the size of the matrix A\n[m,n]=size(A);% m -- sample size,n -- feature dimension%******************************\n\n% Verify the length of y\n%if(size(y,1) ~=m)%********************************\nif (length(y) ~=m)\n error('\\n Check the length of y!\\n');\nend\n\n% Verify the value of z\nif (z<0)\n error('\\n z should be nonnegative!\\n');\nend\n\n% run sll_opts to set default values (flags)\nopts=sll_opts(opts);\n\n%% Detailed initialization\n%% Normalization\n\n% Please refer to sll_opts for the definitions of mu, nu and nFlag\n%\n% If .nFlag =1, the input matrix A is normalized to\n% A= ( A- repmat(mu, m,1) ) * diag(nu)^{-1}\n%\n% If .nFlag =2, the input matrix A is normalized to\n% A= diag(nu)^{-1} * ( A- repmat(mu, m,1) )\n%\n% Such normalization is done implicitly\n% This implicit normalization is suggested for the sparse matrix\n% but not for the dense matrix\n%\n\nif (opts.nFlag~=0)\n if (isfield(opts,'mu'))\n mu=opts.mu;\n if(size(mu,2)~=n)\n error('\\n Check the input .mu');\n end\n else\n mu=mean(A,1);\n end\n\n if (opts.nFlag==1)\n if (isfield(opts,'nu'))\n nu=opts.nu;\n if(size(nu,1)~=n)\n error('\\n Check the input .nu!');\n end\n else\n nu=(sum(A.^2,1)/m).^(0.5); nu=nu';\n end\n else % .nFlag=2\n if (isfield(opts,'nu'))\n nu=opts.nu;\n if(size(nu,1)~=m)\n error('\\n Check the input .nu!');\n end\n else\n nu=(sum(A.^2,2)/n).^(0.5);\n end\n end\n\n ind_zero=find(abs(nu)<= 1e-10); nu(ind_zero)=1;\n % If some values in nu is typically small, it might be that,\n % the entries in a given row or column in A are all close to zero.\n % For numerical stability, we set the corresponding value to 1.\nend\n\nif (~issparse(A)) && (opts.nFlag~=0)\n fprintf('\\n -----------------------------------------------------');\n fprintf('\\n The data is not sparse or not stored in sparse format');\n fprintf('\\n The code still works.');\n fprintf('\\n But we suggest you to normalize the data directly,');\n fprintf('\\n for achieving better efficiency.');\n fprintf('\\n -----------------------------------------------------');\nend\n\n%% Starting point initialization\n\n% compute AT y\nif (opts.nFlag==0)\n ATy=A'*y; %A-->mxn;y-->mxk****************************\nelseif (opts.nFlag==1)\n ATy=A'*y - sum(y) * mu'; ATy=ATy./nu;\nelse\n invNu=y./nu; ATy=A'*invNu-sum(invNu)*mu';\nend\n\n% process the regularization parameter\n\n% L2 norm regularization\nif isfield(opts,'rsL2')\n rsL2=opts.rsL2;\n if (rsL2<0)\n error('\\n opts.rsL2 should be nonnegative!');\n end\nelse\n rsL2=0;\nend\n\n% L1 norm regularization\nif (opts.rFlag==0)\n lambda=z;\nelse % z here is the scaling factor lying in [0,1]\n if (z<0 || z>1)\n error('\\n opts.rFlag=1, and z should be in [0,1]');\n end\n\n lambda_max=max(abs(ATy));\n lambda=z*lambda_max;\n\n rsL2=rsL2*lambda_max; % the input rsL2 is a ratio of lambda_max\nend\n\n% initialize a starting point\nif opts.init==2\n %x=zeros(n,k);%*************************************\n x=zeros(n,1);\nelse\n if isfield(opts,'x0')\n x=opts.x0;\n if (length(x)~=n)\n error('\\n Check the input .x0');\n end\n else\n x=ATy; % if .x0 is not specified, we use ratio*ATy,\n % where ratio is a positive value\n end\nend\n\n% compute A x\nif (opts.nFlag==0)\n Ax=A* x;\nelseif (opts.nFlag==1)\n invNu=x./nu; mu_invNu=mu * invNu;\n Ax=A*invNu -repmat(mu_invNu, m, 1);\nelse\n Ax=A*x-repmat(mu*x, m, 1); Ax=Ax./nu;\nend\n\nif (opts.init==0) % If .init=0, we set x=ratio*x by \"initFactor\"\n % Please refer to the function initFactor for detail\n\n x_norm=sum(abs(x)); x_2norm=x'*x;%*****************************corresponding to L1norm,Fnorm\n if x_norm>=1e-6\n ratio=initFactor(x_norm, Ax, y, lambda,'LeastR', rsL2, x_2norm);\n x=ratio*x; Ax=ratio*Ax;\n end\nend\n\n%% The main program\n\n%% The Armijo Goldstein line search scheme + accelearted gradient descent\nif (opts.mFlag==0 && opts.lFlag==0)\n \n bFlag=0; % this flag tests whether the gradient step only changes a little\n\n L=1 + rsL2;\n % We assume that the maximum eigenvalue of A'A is over 1\n\n % assign xp with x, and Axp with Ax\n xp=x; Axp=Ax; xxp=zeros(n,1);\n\n % alphap and alpha are used for computing the weight in forming search point\n alphap=0; alpha=1;\n\n for iterStep=1:opts.maxIter\n % --------------------------- step 1 ---------------------------\n % compute search point s based on xp and x (with beta)\n beta=(alphap-1)/alpha; s=x + beta* xxp;\n\n % --------------------------- step 2 ---------------------------\n % line search for L and compute the new approximate solution x\n\n % compute the gradient (g) at s\n As=Ax + beta* (Ax-Axp);\n\n % compute AT As\n if (opts.nFlag==0)\n ATAs=A'*As;\n elseif (opts.nFlag==1)\n ATAs=A'*As - sum(As) * mu'; ATAs=ATAs./nu;\n else\n invNu=As./nu; ATAs=A'*invNu-sum(invNu)*mu';\n end\n\n % obtain the gradient g\n g=ATAs-ATy + rsL2 * s;%************************** +rsL2*s*inv(sigma)\n\n % copy x and Ax to xp and Axp\n xp=x; Axp=Ax;\n\n while (1)\n % let s walk in a step in the antigradient of s to get v\n % and then do the l1-norm regularized projection\n v=s-g/L;\n\n % L1-norm regularized projection\n x=sign(v).*max(abs(v)-lambda / L,0);\n\n v=x-s; % the difference between the new approximate solution x\n % and the search point s\n\n % compute A x\n if (opts.nFlag==0)\n Ax=A* x;\n elseif (opts.nFlag==1)\n invNu=x./nu; mu_invNu=mu * invNu;\n Ax=A*invNu -repmat(mu_invNu, m, 1);\n else\n Ax=A*x-repmat(mu*x, m, 1); Ax=Ax./nu;\n end\n\n Av=Ax -As;\n r_sum=v'*v; l_sum=Av'*Av;\n \n if (r_sum <=1e-20)\n bFlag=1; % this shows that, the gradient step makes little improvement\n break;\n end\n\n % the condition is ||Av||_2^2 <= (L - rsL2) * ||v||_2^2\n if(l_sum <= r_sum * (L-rsL2))\n break;\n else\n L=max(2*L, l_sum/r_sum + rsL2);\n % fprintf('\\n L=%5.6f',L);\n end\n end\n\n ValueL(iterStep)=L;\n \n % --------------------------- step 3 ---------------------------\n % update alpha and alphap, and check whether converge\n alphap=alpha; alpha= (1+ sqrt(4*alpha*alpha +1))/2;\n\n xxp=x-xp; Axy=Ax-y;\n funVal(iterStep)=Axy'* Axy/2 + rsL2/2 * x'*x + sum(abs(x)) * lambda;\n \n if (bFlag)\n % fprintf('\\n The program terminates as the gradient step changes the solution very small.');\n break;\n end\n\n switch(opts.tFlag)\n case 0\n if iterStep>=2\n if (abs( funVal(iterStep) - funVal(iterStep-1) ) <= opts.tol)\n break;\n end\n end\n case 1\n if iterStep>=2\n if (abs( funVal(iterStep) - funVal(iterStep-1) ) <=...\n opts.tol* funVal(iterStep-1))\n break;\n end\n end\n case 2\n if ( funVal(iterStep)<= opts.tol)\n break;\n end\n case 3\n norm_xxp=sqrt(xxp'*xxp);\n if ( norm_xxp <=opts.tol)\n break;\n end\n case 4\n norm_xp=sqrt(xp'*xp); norm_xxp=sqrt(xxp'*xxp);\n if ( norm_xxp <=opts.tol * max(norm_xp,1))\n break;\n end\n case 5\n if iterStep>=opts.maxIter\n break;\n end\n end\n end\nend\n\n%% Reformulated problem + Nemirovski's scheme\n\n% .mFlag=1, and .lFlag=0\n% refomulate the problem as the constrained convex optimization\n% problem, and then apply Armijo Goldstein line search scheme\n\n% Problem:\n% min 1/2 || A x - y||^2 + 1/2 rsL2 * ||x||_2^2 + z * t' * 1\n% s.t. |x| <= t\n\nif(opts.mFlag==1 && opts.lFlag==0) \n \n bFlag=0; % this flag tests whether the gradient step only changes a little\n \n L=1 + rsL2;\n % We assume that the maximum eigenvalue of A'A is over 1\n\n % assign xp with x, and Axp with Ax\n xp=x; Axp=Ax; xxp=zeros(n,1);\n t=abs(x); tp=t; \n % t is the upper bound of absolute value of x\n\n % alphap and alpha are used for computing the weight in forming search point\n alphap=0; alpha=1;\n\n for iterStep=1:opts.maxIter\n % --------------------------- step 1 ---------------------------\n % compute search point s based on xp and x (with beta)\n beta=(alphap-1)/alpha; s=x + beta* xxp; s_t= t + beta * (t -tp);\n\n % --------------------------- step 2 ---------------------------\n % line search for L and compute the new approximate solution x\n\n % compute the gradient (g) at s\n As=Ax + beta* (Ax-Axp);\n\n % compute AT As\n if (opts.nFlag==0)\n ATAs=A'*As;\n elseif (opts.nFlag==1)\n ATAs=A'*As - sum(As) * mu'; ATAs=ATAs./nu;\n else\n invNu=As./nu; ATAs=A'*invNu-sum(invNu)*mu';\n end\n\n % obtain the gradient g\n g=ATAs-ATy + rsL2 * s;\n\n % copy x and Ax to xp and Axp\n xp=x; Axp=Ax;\n tp=t;\n\n while (1)\n % let s walk in a step in the antigradient of s to get v\n % and then do the l1-norm regularized projection\n \n u=s-g/L;\n v= s_t - lambda / L;\n \n % projection\n [x, t]=ep1R(u, v, n);\n\n v=x-s; % the difference between the new approximate solution x\n % and the search point s\n \n v_t=t-s_t;\n\n % compute A x\n if (opts.nFlag==0)\n Ax=A* x;\n elseif (opts.nFlag==1)\n invNu=x./nu; mu_invNu=mu * invNu;\n Ax=A*invNu -repmat(mu_invNu, m, 1);\n else\n Ax=A*x-repmat(mu*x, m, 1); Ax=Ax./nu;\n end\n\n Av=Ax -As;\n r_sum=v'*v + v_t'*v_t; l_sum=Av'*Av + v'*v * rsL2;\n \n if (r_sum <=1e-20)\n bFlag=1; % this shows that, the gradient step makes little improvement\n break;\n end\n \n % the condition is ||Av||_2^2 + rsL2 * ||v||_2^2\n % <= L * (||v||_2^2 + ||v_t|| _2^2 )\n if(l_sum <= r_sum * L)\n break;\n else\n L=max(2*L, l_sum/r_sum);\n % fprintf('\\n L=%5.6f',L);\n end\n end\n \n ValueL(iterStep)=L;\n\n % --------------------------- step 3 ---------------------------\n % update alpha and alphap, and check whether converge\n alphap=alpha; alpha= (1+ sqrt(4*alpha*alpha +1))/2;\n\n xxp=x-xp; Axy=Ax-y;\n funVal(iterStep)=Axy'* Axy/2 + rsL2/2 * x'*x + sum(t) * lambda;\n \n if (bFlag)\n % fprintf('\\n The program terminates as the gradient step changes the solution very small.');\n break;\n end\n\n switch(opts.tFlag)\n case 0\n if iterStep>=2\n if (abs( funVal(iterStep) - funVal(iterStep-1) ) <= opts.tol)\n break;\n end\n end\n case 1\n if iterStep>=2\n if (abs( funVal(iterStep) - funVal(iterStep-1) ) <=...\n opts.tol* funVal(iterStep-1))\n break;\n end\n end\n case 2\n if ( funVal(iterStep)<= opts.tol)\n break;\n end\n case 3\n norm_xxp=sqrt(xxp'*xxp + norm(t-tp)^2);\n if ( norm_xxp <=opts.tol)\n break;\n end\n case 4\n norm_xp=sqrt(xp'*xp + tp'*tp); norm_xxp=sqrt(xxp'*xxp+ norm(t-tp)^2);\n if ( norm_xxp <=opts.tol * max(norm_xp,1))\n break;\n end\n case 5\n if iterStep>=opts.maxIter\n break;\n end\n end\n end\n \nend\n\n\n%% adaptive line search\n\n% .mFlag=1, and .lFlag=1\n% refomulate the problem as the constrained convex optimization\n% problem, and then apply adaptive line search scheme\n\n% Problem:\n% min 1/2 || A x - y||^2 + 1/2 rsL2 * ||x||_2^2 + z * t' * 1\n% s.t. |x| <= t\n\nif(opts.mFlag==1 && opts.lFlag==1)\n \n bFlag=0; % this flag tests whether the gradient step only changes a little\n\n L=1 + rsL2;\n % We assume that the maximum eigenvalue of A'A is over 1\n \n gamma=1;\n % we shall set the value of gamma = L,\n % where L is appropriate for the starting point\n\n xp=x; Axp=Ax;\n % store x and Ax\n xxp=zeros(n,1);\n % the difference of x and xp \n t=abs(x); tp=t;\n % t is the upper bound of absolute value of x\n \n % compute AT Ax\n if (opts.nFlag==0)\n ATAx=A'*Ax;\n elseif (opts.nFlag==1)\n ATAx=A'*Ax - sum(Ax) * mu'; ATAx=ATAx./nu;\n else\n invNu=Ax./nu; ATAx=A'*invNu-sum(invNu)*mu';\n end\n \n % We begin the adaptive line search in the following\n %\n % Note that, in the line search, L and beta are changing\n \n for iterStep=1:opts.maxIter\n\n ATAxp=ATAx;\n % store ATAx to ATAxp\n\n if (iterStep~=1)\n % compute AT Ax\n if (opts.nFlag==0)\n ATAx=A'*Ax;\n elseif (opts.nFlag==1)\n ATAx=A'*Ax - sum(Ax) * mu'; ATAx=ATAx./nu;\n else\n invNu=Ax./nu; ATAx=A'*invNu-sum(invNu)*mu';\n end\n end\n\n %--------- Line Search for L begins\n while (1)\n if (iterStep~=1)\n alpha= (-gamma+ sqrt(gamma*gamma + 4* L * gamma)) / (2*L);\n beta= (gamma - gamma* alphap) / (alphap * gamma + alphap* L * alpha);\n % beta is the coefficient for generating search point s\n\n s=x + beta* xxp; s_t= t + beta * (t -tp);\n As=Ax + beta* (Ax-Axp);\n ATAs=ATAx + beta * (ATAx- ATAxp);\n % compute the search point s, A * s, and A' * A * s\n else\n alpha= (-1+ sqrt(5)) / 2;\n beta=0; s=x; s_t=t; As=Ax; ATAs=ATAx;\n end\n\n g=ATAs-ATy + rsL2 * s;\n % compute the gradient g\n \n % let s walk in a step in the antigradient of s \n u=s-g/L;\n v= s_t - lambda / L;\n\n % projection\n [xnew, tnew]=ep1R(u,v,n);\n\n v=xnew-s; % the difference between the new approximate solution x\n % and the search point s\n v_t=tnew-s_t;\n \n % compute A xnew\n if (opts.nFlag==0)\n Axnew=A* xnew;\n elseif (opts.nFlag==1)\n invNu=xnew./nu; mu_invNu=mu * invNu;\n Axnew=A*invNu -repmat(mu_invNu, m, 1);\n else\n Axnew=A*xnew-repmat(mu*xnew, m, 1); Axnew=Axnew./nu;\n end\n\n Av=Axnew -As;\n r_sum=v'*v + v_t'*v_t; l_sum=Av'*Av + v'*v * rsL2;\n \n if (r_sum <=1e-20)\n bFlag=1; % this shows that, the gradient step makes little improvement\n break;\n end\n \n % the condition is ||Av||_2^2 + rsL2 * ||v||_2^2\n % <= L * (||v||_2^2 + ||v_t|| _2^2 )\n if(l_sum <= r_sum * L)\n break;\n else\n L=max(2*L, l_sum/r_sum);\n % fprintf('\\n L=%5.6f',L);\n end\n end\n %--------- Line Search for L ends\n\n gamma=L* alpha* alpha; alphap=alpha;\n % update gamma, and alphap\n \n ValueL(iterStep)=L;\n\n tao=L * r_sum / l_sum;\n if (tao >=5)\n L=L*0.8;\n end\n % decrease the value of L\n\n xp=x; x=xnew; xxp=x-xp;\n Axp=Ax; Ax=Axnew;\n % update x and Ax with xnew and Axnew \n tp=t; t=tnew;\n % update tp and t \n \n Axy=Ax-y;\n funVal(iterStep)=Axy' * Axy/2 + rsL2/2 * x'*x + lambda * sum(t);\n % compute function value\n \n if (bFlag)\n % fprintf('\\n The program terminates as the gradient step changes the solution very small.');\n break;\n end\n\n switch(opts.tFlag)\n case 0\n if iterStep>=2\n if (abs( funVal(iterStep) - funVal(iterStep-1) ) <= opts.tol)\n break;\n end\n end\n case 1\n if iterStep>=2\n if (abs( funVal(iterStep) - funVal(iterStep-1) ) <=...\n opts.tol* funVal(iterStep-1))\n break;\n end\n end\n case 2\n if ( funVal(iterStep)<= opts.tol)\n break;\n end\n case 3\n norm_xxp=sqrt(xxp'*xxp+ norm(t-tp)^2);\n if ( norm_xxp <=opts.tol)\n break;\n end\n case 4\n norm_xp=sqrt(xp'*xp + tp'*tp); norm_xxp=sqrt(xxp'*xxp+ norm(t-tp)^2);\n if ( norm_xxp <=opts.tol * max(norm_xp,1))\n break;\n end\n case 5\n if iterStep>=opts.maxIter\n break;\n end\n end\n end\nend\n\n\n%%\nif(opts.mFlag==0 && opts.lFlag==1)\n error('\\n The function does not support opts.mFlag=0 & opts.lFlag=1!');\nend", "meta": {"author": "zzstefan", "repo": "BrainNetClass", "sha": "556cda9516429a964100e1ac0bace4258194b4a1", "save_path": "github-repos/MATLAB/zzstefan-BrainNetClass", "path": "github-repos/MATLAB/zzstefan-BrainNetClass/BrainNetClass-556cda9516429a964100e1ac0bace4258194b4a1/Toolbox/SLEP_package_4.1/SLEP/functions/L1/L1R/LeastR.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218412907381, "lm_q2_score": 0.8080672227971212, "lm_q1q2_score": 0.7449748219278151}} {"text": "% StackExchange Mathematics Q1909139\n% https://math.stackexchange.com/questions/1909139\n% Projection of a Symmetric Matrix onto the Probability Simplex\n% References:\n% 1. \n% Remarks:\n% 1. B\n% TODO:\n% \t1. C\n% Release Notes\n% - 1.0.000 17/06/2021\n% * First release.\n\n\n%% General Parameters\n\nsubStreamNumberDefault = 79;\n\nrun('InitScript.m');\n\nfigureIdx = 0;\nfigureCounterSpec = '%04d';\n\ngenerateFigures = ON;\n\n\n%% Simulation Parameters\n\nnumRows = 4;\n\n\n%% Generate Data\n\nmY = randn(numRows, numRows);\n% mY = mY + mY.';\n\nvI = zeros(numRows * numRows, 1);\nvI(1:(numRows + 1):(numRows ^ 2)) = 1;\n\nhObjFun = @(mX) 0.5 * sum((mX(:) - mY(:)) .^ 2);\n\n\n%% Solution by CVX\n\nsolverString = 'CVX';\n\n% cvx_solver('SDPT3'); % 500, Very Good!\n% cvx_solver('Gurobi');\n\nhRunTime = tic();\n\ncvx_begin('quiet')\n % cvx_precision('best');\n variable mX(numRows, numRows) symmetric;\n minimize( (0.5 * sum_square(mX(:) - mY(:))) );\n subject to\n % mX symmetric(numRows); %= 0;\ncvx_end\n\nrunTime = toc(hRunTime);\n\nDisplayRunSummary(solverString, hObjFun, mX, runTime, cvx_status);\n\nsCvxSol.vXCvx = mX(:);\nsCvxSol.cvxOptVal = hObjFun(mX);\n\n\n%% Solution by Orthogonal Projection onto the Intersection of Convex Sets\n\nhP1 = @(vX) reshape((reshape(vX, numRows, numRows) + reshape(vX, numRows, numRows).') / 2, 1, numRows * numRows);\nhP2 = @(vX) max(vX, 0); %= 0\nhP3 = @(vX) (vX .* ~vI) + ((vX - ((sum(vX .* vI) - 1) / numRows)) .* vI); %1, error('Covariance is defined for 1d data only.'), end\np = exp(hyp(1));\nsf2 = exp(2*hyp(2));\n\n% precompute distances\nif dg % vector kxx\n K = zeros(size(x,1),1);\nelse\n if xeqz % symmetric matrix Kxx\n K = repmat(x,1,n) - repmat(x',n,1);\n else % cross covariances Kxz\n K = repmat(x,1,size(z,1)) - repmat(z',n,1);\n end\nend\n\nK = 2*pi*K/p;\nif nargin<4 % covariances\n K = sf2*cos(K);\nelse % derivatives\n if i==1\n K = sf2*sin(K).*K;\n elseif i==2\n K = 2*sf2*cos(K);\n else\n error('Unknown hyperparameter')\n end\nend", "meta": {"author": "benfulcher", "repo": "hctsa", "sha": "919f2aed7cc8e1a3a03304c1ade573fa664c73f8", "save_path": "github-repos/MATLAB/benfulcher-hctsa", "path": "github-repos/MATLAB/benfulcher-hctsa/hctsa-919f2aed7cc8e1a3a03304c1ade573fa664c73f8/Toolboxes/gpml/cov/covCos.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218284193595, "lm_q2_score": 0.808067204308405, "lm_q1q2_score": 0.7449747944817249}} {"text": "function R = ProjectToSO3(mat)\n% *** CHAPTER 3: RIGID-BODY MOTIONS ***\n% Takes mat: A matrix near SO(3) to project to SO(3).\n% Returns R representing the closest rotation matrix that is in SO(3).\n% This function uses singular-value decomposition (see\n% http://hades.mech.northwestern.edu/index.php/Modern_Robotics_Linear_Algebra_Review)\n% and is only appropriate for matrices close to SO(3).\n% Example Inputs:\n% \n% clear; clc;\n% mat = [ 0.675, 0.150, 0.720;\n% 0.370, 0.771, -0.511;\n% -0.630, 0.619, 0.472];\n% R = ProjectToSO3(mat)\n% \n% Output:\n% R =\n% 0.6790 0.1489 0.7189\n% 0.3732 0.7732 -0.5127\n% -0.6322 0.6164 0.4694\n\n[U, S, V] = svd(mat);\nR = U * V';\nif det(R) < 0\n % In this case the result may be far from mat.\n R = [R(:, 1: 2); -R(:, 3)];\nend\nend", "meta": {"author": "ShuoYangRobotics", "repo": "QuadrupedSim", "sha": "8427715395b63bddb77329e66f7484e529998445", "save_path": "github-repos/MATLAB/ShuoYangRobotics-QuadrupedSim", "path": "github-repos/MATLAB/ShuoYangRobotics-QuadrupedSim/QuadrupedSim-8427715395b63bddb77329e66f7484e529998445/mr/ProjectToSO3.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850057480347, "lm_q2_score": 0.795658104908603, "lm_q1q2_score": 0.7449627533278218}} {"text": "% Compute the frequency range of the mel filterbank\n% Inputs:\n% start_freq: the lowerest linear frequency included in the calculation\n% linear_samp: sampling frequency\n% N_mel: number of mel banks used\n% Output: \n% bin_lower_edge: the lower edge linear frequency of each mel bank\n% bin_upper_edge: the upper edge linear frequency of each mel bank\n\nfunction [bin_lower_edge, bin_upper_edge] = mel_bank_range(start_freq, linear_samp, N_mel)\n\n% get the mel version of start frequency and linear sampling rate\nstart_mel = linear2mel(start_freq);\nsamp_mel = linear2mel(linear_samp/2);\n\n% slow implementation\nif 0\n for i=1:N_mel\n % find the lower edge linear frequency of the bank\n tmp_mel = (i-1)*(samp_mel-start_mel) / (N_mel+1);\n bin_lower_edge(i) = mel2linear(tmp_mel+start_mel);\n % find the upper edge linear frequency of the bank\n tmp_mel = (i+1)*(samp_mel-start_mel) / (N_mel+1);\n bin_upper_edge(i) = mel2linear(tmp_mel+start_mel);\n end\nelse\n % fast implementation\n i=1:N_mel;\n % find the lower edge linear frequency of the bank\n tmp_mel = (i-1)*(samp_mel-start_mel) / (N_mel+1);\n bin_lower_edge = mel2linear(tmp_mel+start_mel);\n % find the upper edge linear frequency of the bank\n tmp_mel = (i+1)*(samp_mel-start_mel) / (N_mel+1);\n bin_upper_edge = mel2linear(tmp_mel+start_mel);\nend\n", "meta": {"author": "singaxiong", "repo": "SignalGraph", "sha": "e86d973556ae8796a05ee2adbd665f47c8525a21", "save_path": "github-repos/MATLAB/singaxiong-SignalGraph", "path": "github-repos/MATLAB/singaxiong-SignalGraph/SignalGraph-e86d973556ae8796a05ee2adbd665f47c8525a21/signal/feature/mel_bank_range.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797075998822, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.7449572782344196}} {"text": "function r = dirrand(m,n)\n% DIRRAND - Uniform Dirichlet random vectors\n%\n% R = DIRRAND(M) returns vector of length M chosen from\n% Dirichlet(1,...,1) distribution.\n% R = DIRRAND(M,N) returns N such vectors in MxN matrix.\n%\n% References: Gelman, Carlin, Stern, Dunson, Vehtari & Rubin (2013),\n% Bayesian Data Analysis, third edition, p. 583.\n%\n% Copyright (c) 1998-2004 Aki Vehtari\n\n% This software is distributed under the GNU General Public \n% License (version 3 or later); please refer to the file \n% License.txt, included with the software, for details.\n\nif nargin < 2\n n=1;\nend\n\n% Generate random numbers from Gamma(1,1) distribution...\nr=rand(m,n);\nr=-reallog(r);\n% ...and scale sum to unity\nrs=sum(r);\nfor i1=1:m\n r(i1,:)=r(i1,:)./rs;\nend\n", "meta": {"author": "gpstuff-dev", "repo": "gpstuff", "sha": "114937ec0a201306489a66cbba38283e722fb998", "save_path": "github-repos/MATLAB/gpstuff-dev-gpstuff", "path": "github-repos/MATLAB/gpstuff-dev-gpstuff/gpstuff-114937ec0a201306489a66cbba38283e722fb998/dist/dirrand.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797124237605, "lm_q2_score": 0.8175744695262777, "lm_q1q2_score": 0.7449572700279622}} {"text": "%% doubleContraction\n% Below is a demonstration of the features of the |doubleContraction| function\n\n%%\nclear; close all; clc;\n\n%% Syntax\n% |C=doubleContraction(A,B,subContract);|\n\n%% Description \n% This function performs a double contraction of two tensors |A| and |B| to\n% produce the output tensor |C|. The tensors are either both 3x3 second\n% order tensors or |A| is a 4th order 3x3x3x3 tensor. The optional 3rd\n% input |subContract| defines the indices to contract over for 4th order\n% tensors e.g. |subContract=[1 2]| would contract over the first 2 indices.\n% \n\n%% Examples \n% \n\n%% Double contraction of a 2nd-order and a 2nd-order tensor\n\n%%\n% Creating an example tensor. Here a tensor |A| with all zeros except for\n% the 3,3 component is created. Next a tensor |B| which, through double\n% contraction, can \"pick out\" this scalar value is created. Finally the\n% double contraction is performed illustrating this process. \n\n%Create example tensor A\nA=zeros(3,3); A(3,3)=pi; %Zeros with Azz=A33=pi\nR=euler2DCM([0.25*pi 0.25*pi 0]); %Rotation matrix\nA=R*A*R' %Rotated version of A\n\n% Create 'structure' tensor example B\nb=[0 0 1]*R.'; %Rotated Z vector\nB=b.'*b %Rotated \"structure\" tensor for vector b\n\n%%\n% Double contraction using |doubleContraction|\ns=doubleContraction(A,B)\n\n%% Double contraction of a 4th-order and a 2nd-order tensor\n\n%%\n% Example for Hooke's law of linear elasticity\n\n%Creating the 4th order linear elastic stiffness tensor\nI=eye(3,3); %The 2nd order identity tensor\nII1=dyadicProduct(I,I,1); %4th order base tensor 1 \nII3=dyadicProduct(I,I,3); %4th order base tensor 3\n\n%Parameters for Hooke's law\nmu=1; %The shear modulus\nlambda=5; %The lambda lame parameter\n\n%Compose stiffness tensor\nC=lambda.*II1+2.*mu.*II3; \n\n%Create strain tensor\nE=rand(3,3); E=E*E'\n\n%%\n% Double contraction using |doubleContraction|\nsubContract=[3 4];\nS=doubleContraction(C,E,subContract)\n\n%% Using symbolic variables\n\n%%\n% Example for Hooke's law of linear elasticity\n\n%Creating the 4th order linear elastic stiffness tensor\nI=eye(3,3); %The 2nd order identity tensor\nII1=dyadicProduct(I,I,1); %4th order base tensor 1 \nII3=dyadicProduct(I,I,3); %4th order base tensor 3\n\n%Parameters for Hooke's law\ntry\n syms mu lambda\ncatch\n mu=1; %The shear modulus\n lambda=5; %The lambda lame parameter\nend\n%Compose stiffness tensor\nC=lambda.*II1+2.*mu.*II3;\n\n%Display Voigt mapped version\nc=voigtMap(C)\n\n%Create strain tensor\nsyms E1_1 E2_2 E3_3 E1_2 E1_3 E2_3;\nE=[E1_1 E1_2 E1_3;...\n E1_2 E2_2 E2_3;...\n E1_3 E2_3 E3_3]\n\n%%\n% Double contraction using |doubleContraction|\n\nsubContract=[3 4];\nS=doubleContraction(C,E,subContract)\n\n%%\n% \n% <>\n% \n% _*GIBBON*_ \n% \n% \n% _Kevin Mattheus Moerman_, \n%% \n% _*GIBBON footer text*_ \n% \n% License: \n% \n% GIBBON: The Geometry and Image-based Bioengineering add-On. A toolbox for\n% image segmentation, image-based modeling, meshing, and finite element\n% analysis.\n% \n% Copyright (C) 2006-2022 Kevin Mattheus Moerman and the GIBBON contributors\n% \n% This program is free software: you can redistribute it and/or modify\n% it under the terms of the GNU General Public License as published by\n% the Free Software Foundation, either version 3 of the License, or\n% (at your option) any later version.\n% \n% This program is distributed in the hope that it will be useful,\n% but WITHOUT ANY WARRANTY; without even the implied warranty of\n% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n% GNU General Public License for more details.\n% \n% You should have received a copy of the GNU General Public License\n% along with this program. If not, see .\n", "meta": {"author": "gibbonCode", "repo": "GIBBON", "sha": "8178520664a6148db939eaea87e75b3cba4f2b4f", "save_path": "github-repos/MATLAB/gibbonCode-GIBBON", "path": "github-repos/MATLAB/gibbonCode-GIBBON/GIBBON-8178520664a6148db939eaea87e75b3cba4f2b4f/docs/HELP_doubleContraction.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797051879431, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.744957268162255}} {"text": "function c = martin_phase(N)\n% phase colormap as found in a tool from Martin Uecker (muecker@gwdg.de)\n\n if nargin < 1\n N = 64;\n end\n\n\nphase = linspace(0,2*pi,N);\n\nc = zeros(N,3);\nc(:,1) = sin(phase);\nc(:,2) = sin(phase + 120 * pi/180);\nc(:,3) = sin(phase + 240 * pi/180);\n\nc = (c + 1)/2;\n\nend\n\n\n\n", "meta": {"author": "leoliuf", "repo": "MRiLab", "sha": "5cdcf1f7b67759700685d3a26ffeb70e55325567", "save_path": "github-repos/MATLAB/leoliuf-MRiLab", "path": "github-repos/MATLAB/leoliuf-MRiLab/MRiLab-5cdcf1f7b67759700685d3a26ffeb70e55325567/External/arrayShow/supportFunctions/martin_phase.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8962513786759491, "lm_q2_score": 0.8311430520409023, "lm_q1q2_score": 0.7449131062685947}} {"text": "% Fast community finding algorithm by M. Newman\n% Source: \"Fast algorithm for detecting community \n% structure in networks\", Mark Newman\n%\n% INPUTs: adjacency matrix, nxn\n% OUTPUTs: sequential group (cluster) formation, \n% modularity metric for each cluster breakdown\n%\n% Other functions used: numEdges.m\n% Note: To save the plot generated in this routine:\n% uncomment \"print newmanCommFast_example.pdf\"\n%\n% GB: last updated, Oct 12 2012\n\nfunction [groups_hist,Q]=newmanCommFast(adj)\n\ngroups={};\ngroups_hist={}; % a list of groups at each step\nQ=[];\nn=size(adj,1); % number of vertices\ngroups_hist{1}={};\n\nfor i=1:n\n groups{i}=i; % each node starts out as one community\n groups_hist{1}{i}=i;\nend\n\nQ(1) = Qfn(groups,adj);\n\nfor s=1:n-1 % all possible iterations\n \n \n dQ=zeros(length(groups));\n\n for i=1:length(groups)\n for j=i+1:length(groups)\n group_i=groups{i};\n group_j=groups{j};\n \n dQ(i,j)=0; % default\n \n % check if connected\n connected=0;\n if sum(sum(adj([group_i group_j],[group_i group_j])))>sum(sum(adj(group_i,group_i)))+sum(sum(adj(group_j,group_j)))\n\tconnected=1;\n end\n \n if connected && not(isempty(group_i)) && not(isempty(group_j))\n\t% join groups i and j?\n\tdQ(i,j)=deltaQ(groups,adj,i,j);\n end\n \n end\n end\n \n \n % pick max nonzero dQ\n dQ(find(dQ==0))=-Inf; \n [minv,minij]=max(dQ(:));\n \n [mini,minj]=ind2sub([size(dQ,1),size(dQ,1)],minij); % i and j corresponding to min dQ\n groups{mini}=sort([groups{mini} groups{minj}]);\n groups{minj}=groups{length(groups)}; % swap minj with last group\n groups=groups(1:length(groups)-1);\n \n groups_hist{length(groups_hist)+1}=groups; % save current snapshot\n Q(length(Q)+1) = Qfn(groups,adj);\n \nend % end of all iterations\n\nnum_modules=[];\nfor g=1:length(groups_hist)\n num_modules=[num_modules length(groups_hist{g})];\nend\n\nset(gcf,'Color',[1 1 1],'Colormap',jet);\nplot(num_modules,Q,'ko-')\nxlabel('number of modules / communities')\nylabel('modularity metric, Q')\n\n% print newmanCommFast_example.pdf\n\n\nfunction dQ=deltaQ(groups,adj,i,j)\n\n% computing the delta Q between two community configurations\n% dQ = 2(e_ij - ai*aj) or (Q_groups_(i,j)_merged - Q_original)\n% inputs: current community assignments: groups, adjacency matrix, i,j to be joined\n% outputs: delta Q value (real number)\n\n% $$$ Q1=Qfn(groups,adj);\n% $$$ groups{i}=[groups{i} groups{j}];\n% $$$ groups{j}=groups{length(groups)};\n% $$$ groups=groups(1:length(groups)-1);\n% $$$ Q2=Qfn(groups,adj);\n% $$$ dQ = Q2-Q1;\n\n% alternative dQ = 2(e_ij - ai*aj) from paper;\nnedges=numEdges(adj); % compute the total number of edges\ne_ii = numEdges( adj(groups{i},groups{i}) ) / nedges;\ne_jj = numEdges( adj(groups{j},groups{j}) ) / nedges;\ne_ij = numEdges( adj([groups{i} groups{j}],[groups{i} groups{j}]) ) / nedges - e_ii - e_jj;\n\na_i=sum(sum(adj(groups{i},:)))/nedges-e_ii;\na_j=sum(sum(adj(groups{j},:)))/nedges-e_jj;\n\ndQ = 2*(e_ij-a_i*a_j);\n\n\n\nfunction Q=Qfn(modules,adj) % ....... same as modularityMetric.m ........\n\n% Computing the modularity for the final module break-down\n% Defined as: Q=sum_over_modules_i (eii-ai^2) (eq 5) in Newman and Girvan.\n% eij = fraction of edges that connect community i to community j\n% ai=sum_j (eij)\n\nnedges=numEdges(adj); % compute the total number of edges\n\nQ = 0;\nfor m=1:length(modules) \n\n e_mm=numEdges(adj(modules{m},modules{m}))/nedges;\n a_m=sum(sum(adj(modules{m},:)))/nedges - e_mm; % counting e_mm only once\n \n Q = Q + (e_mm - a_m^2);\nend", "meta": {"author": "aeolianine", "repo": "octave-networks-toolbox", "sha": "e70f79eb62a54ef96934d900830f9177caf732c9", "save_path": "github-repos/MATLAB/aeolianine-octave-networks-toolbox", "path": "github-repos/MATLAB/aeolianine-octave-networks-toolbox/octave-networks-toolbox-e70f79eb62a54ef96934d900830f9177caf732c9/newmanCommFast.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513759047848, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.7449131002167129}} {"text": "function [ num_int, pi ] = plane_imp_triangle_int_3d ( a, b, c, d, t )\n\n%*****************************************************************************80\n%\n%% PLANE_IMP_TRIANGLE_INT_3D: intersection ( implicit plane, triangle ) in 3D.\n%\n% Discussion:\n%\n% The implicit form of a plane in 3D is:\n%\n% A * X + B * Y + C * Z + D = 0\n%\n% There may be 0, 1, 2 or 3 points of intersection returned.\n%\n% If two intersection points are returned, then the entire line\n% between them comprises points of intersection.\n%\n% If three intersection points are returned, then all points of\n% the triangle intersect the plane.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 12 May 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real T(3,3), the vertices of the triangle.\n%\n% Input, real A, B, C, D, the implicit plane parameters.\n%\n% Output, integer NUM_INT, the number of intersection points returned.\n%\n% Output, real PI(3,3), the intersection points.\n%\n dim_num = 3;\n num_int = 0;\n pi = [];\n%\n% Compute the signed distances between the vertices and the plane.\n%\n dist1 = a * t(1,1) + b * t(2,1) + c * t(3,1) + d;\n dist2 = a * t(1,2) + b * t(2,2) + c * t(3,2) + d;\n dist3 = a * t(1,3) + b * t(2,3) + c * t(3,3) + d;\n%\n% Consider any zero distances.\n%\n if ( dist1 == 0.0 )\n num_int = num_int + 1;\n pi(1:dim_num,num_int) = t(1:dim_num,1);\n end\n\n if ( dist2 == 0.0 )\n num_int = num_int + 1;\n pi(1:dim_num,num_int) = t(1:dim_num,2);\n end\n\n if ( dist3 == 0.0 )\n num_int = num_int + 1;\n pi(1:dim_num,num_int) = t(1:dim_num,3);\n end\n%\n% If 2 or 3 of the nodes intersect, we're already done.\n%\n if ( 2 <= num_int )\n return\n end\n%\n% If one node intersects, then we're done unless the other two\n% are of opposite signs.\n%\n if ( num_int == 1 )\n\n if ( dist1 == 0.0 )\n\n [ num_int, pi ] = plane_imp_triangle_int_add_3d ( t(1:dim_num,2), t(1:dim_num,3), ...\n dist2, dist3, num_int, pi );\n\n elseif ( dist2 == 0.0 )\n\n [ num_int, pi ] = plane_imp_triangle_int_add_3d ( t(1:dim_num,1), t(1:dim_num,3), ...\n dist1, dist3, num_int, pi );\n\n elseif ( dist3 == 0.0 )\n\n [ num_int, pi ] = plane_imp_triangle_int_add_3d ( t(1:dim_num,1), t(1:dim_num,2), ...\n dist1, dist2, num_int, pi );\n\n end\n\n return\n\n end\n%\n% All nodal distances are nonzero, and there is at least one\n% positive and one negative.\n%\n if ( dist1 * dist2 < 0.0 & dist1 * dist3 < 0.0 )\n\n [ num_int, pi ] = plane_imp_triangle_int_add_3d ( t(1:dim_num,1), t(1:dim_num,2), ...\n dist1, dist2, num_int, pi );\n\n [ num_int, pi ] = plane_imp_triangle_int_add_3d ( t(1:dim_num,1), t(1:dim_num,3), ...\n dist1, dist3, num_int, pi );\n\n elseif ( dist2 * dist1 < 0.0 & dist2 * dist3 < 0.0 )\n\n [ num_int, pi ] = plane_imp_triangle_int_add_3d ( t(1:dim_num,2), t(1:dim_num,1), ...\n dist2, dist1, num_int, pi );\n\n [ num_int, pi ] = plane_imp_triangle_int_add_3d ( t(1:dim_num,2), t(1:dim_num,3), ...\n dist2, dist3, num_int, pi );\n\n elseif ( dist3 * dist1 < 0.0 & dist3 * dist2 < 0.0 )\n\n [ num_int, pi ] = plane_imp_triangle_int_add_3d ( t(1:dim_num,3), t(1:dim_num,1), ...\n dist3, dist1, num_int, pi );\n\n [ num_int, pi ] = plane_imp_triangle_int_add_3d ( t(1:dim_num,3), t(1:dim_num,2), ...\n dist3, dist2, num_int, pi );\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/geometry/plane_imp_triangle_int_3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513675912912, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.7449130989299824}} {"text": "%\n% Polynomial power h = f^k\n%\n% Syntax: >> h = PolynomialPower(f,k)\n% or >> h = ppower(f,k)\n%\n% Input: f --- (string) polynomial\n% k --- (integer) exponent\n%\n% Output: h --- (string) polynomial f^k if k is nonnegative\n%\n% Example: >> PolynomialPower('x*y+1',3)\n%\n% ans =\n%\n% 1 + 3*x*y + 3*x^2*y^2 + x^3*y^3\n", "meta": {"author": "zarathustr", "repo": "LibQPEP", "sha": "99e5c23e746ace0bac4a86742c31db6fcf7297ba", "save_path": "github-repos/MATLAB/zarathustr-LibQPEP", "path": "github-repos/MATLAB/zarathustr-LibQPEP/LibQPEP-99e5c23e746ace0bac4a86742c31db6fcf7297ba/MATLAB/homotopy/ppower.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8962513731336202, "lm_q2_score": 0.8311430436757313, "lm_q1q2_score": 0.7449130941648308}} {"text": "function x=logistic(n,level,a,x0)\n%Syntax: x=logistic(n,level,a,x0)\n%________________________________\n%\n% Simulation of the Quadratic map.\n% x'=ax(1-x)\n%\n% x is the simulated time series.\n% n is the number of the simulated points.\n% level is the noise standard deviation divided by the standard deviation of the\n% noise-free time series. We assume Gaussian noise with zero mean.\n% a is the parameter.\n% x0 is the initial value for x.\n%\n%\n% Reference:\n%\n% May R M (1976): Simple mathematical modelswith very complicated dynamics. \n% Nature 261: 459-467\n%\n%\n% Alexandros Leontitsis\n% Department of Education\n% University of Ioannina\n% 45110 - Dourouti\n% Ioannina\n% Greece\n% \n% University e-mail: me00743@cc.uoi.gr\n% Lifetime e-mail: leoaleq@yahoo.com\n% Homepage: http://www.geocities.com/CapeCanaveral/Lab/1421\n%\n% 17 Nov 2001\n\nif nargin<1 | isempty(n)==1\n n=500;\nelse\n % n must be scalar\n if sum(size(n))>2\n error('n must be scalar.');\n end\n % n must be positive\n if n<0\n error('n must be positive.');\n end\n % n must be an integer\n if round(n)-n~=0\n error('n must be an integer.');\n end\nend\n\nif nargin<2 | isempty(level)==1\n level=0;\nelse\n % level must be a scalar\n if sum(size(level))>2\n error('level must be scalar.');\n end\n % level must be positive\n if level<0\n error('level must be positive.');\n end\nend\n\nif nargin<3 | isempty(a)==1\n a=4;\nelse\n % a must be scalar\n if sum(size(a))>2\n error('a must be scalar.');\n end\nend\n\nif nargin<4 | isempty(x0)==1\n x0=0.1;\nelse\n % x0 must be scalar\n if sum(size(x0))>2\n error('x0 must be scalar.');\n end\nend\n\n\n% Initialize\nx(1,1)=a*x0*(1-x0);\n\n% Simulate\nfor i=2:n\n x(i,1)=a*x(i-1,1)*(1-x(i-1,1));\nend\n\n% Add normal white noise\nx=x+randn(n,1)*level*std(x);\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/1597-chaotic-systems-toolbox/logistic.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513620489619, "lm_q2_score": 0.8311430478583169, "lm_q1q2_score": 0.7449130887005421}} {"text": "function [gradf, err] = tapas_riddersgradient(f, x, varargin)\n% Calculates the gradient of the function f at point x according to Ridders' method:\n%\n% Ridders, CJF. (1982). Accurate computation of F'(x) and F'(x) F''(x). Advances in Engineering\n% Software, 4(2), 75-6.\n%\n% INPUT:\n% f Function handle of a real function of n real variables which are passed as\n% *one* vector with n elements\n% x Point at which to differentiate f\n%\n% OUTPUT:\n% gradf Gradient of f at x (row vector)\n% err Error estimates (row vector)\n%\n% OPTIONS:\n% Optionally, the third argument of the function can be a structure containing further\n% settings for Ridder's method.\n%\n% varargin{1}.init_h Initial finite difference (default: 1)\n% varargin{1}.div Divisor used to reduce h on each step (default: 1.2)\n% varargin{1}.min_steps Minimum number of steps in h (default: 3)\n% varargin{1}.max_steps Maximum number of steps in h (default: 100)\n% varargin{1}.tf Terminate if last step worse than preceding by a factor of tf\n% (default: 2)\n%\n% --------------------------------------------------------------------------------------------------\n% Copyright (C) 2012-2013 Christoph Mathys, TNU, UZH & ETHZ\n%\n% This file is released under the terms of the GNU General Public Licence (GPL), version 3. You can\n% redistribute it and/or modify it under the terms of the GPL (either version 3 or, at your option,\n% any later version). For further details, see the file COPYING or .\n\n n = length(x);\n\n % Defaults\n options.init_h = 1;\n options.div = 1.2;\n options.min_steps = 3;\n options.max_steps = 100;\n options.tf = 2;\n gradf = NaN(1,n);\n err = NaN(1,n);\n \n % Overrides\n if nargin > 2\n options_ovr = varargin{1};\n\n if isfield(options_ovr,'init_h')\n options.init_h = options_ovr.init_h;\n end\n \n if isfield(options_ovr,'div')\n options.div = options_ovr.div;\n end\n \n if isfield(options_ovr,'min_steps')\n options.min_steps = options_ovr.min_steps;\n end\n \n if isfield(options_ovr,'max_steps')\n options.max_steps = options_ovr.max_steps;\n end\n \n if isfield(options_ovr,'tf')\n options.tf = options_ovr.tf;\n end\n end\n \n % Check if f and x match\n try\n f(x);\n catch err\n error('tapas:hgf:ridders:CannotEvalFun', 'Function cannot be evaluated at differentiation point.');\n end\n \n % Loop through argument variables\n for i = 1:n\n \n % Construct filehandle to be passed to riddersdiff\n fxih = @(xi) fxi(f,x,i,xi);\n \n % Calculate derivative\n [gradf(i), err(i)] = tapas_riddersdiff(fxih,x(i),options);\n end\nend\n\nfunction fxi = fxi(f,x,i,xi)\n xx = x;\n xx(i) = xi;\n fxi = f(xx);\nend\n", "meta": {"author": "translationalneuromodeling", "repo": "tapas", "sha": "604c56843c15411f5bd80190f81d845ac57d8592", "save_path": "github-repos/MATLAB/translationalneuromodeling-tapas", "path": "github-repos/MATLAB/translationalneuromodeling-tapas/tapas-604c56843c15411f5bd80190f81d845ac57d8592/HGF/tapas_riddersgradient.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473846343393, "lm_q2_score": 0.8539127603871312, "lm_q1q2_score": 0.7449085632296031}} {"text": "function triangle_svg_test01 ( )\n\n%*****************************************************************************80\n%\n%% TRIANGLE_SVG_TEST01 calls TRIANGLE_SVG to plot a triangle and some points.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 20 April 2014\n%\n% Author:\n%\n% John Burkardt\n%\n p_num = 13;\n p = [ ...\n 0.333333333333333, 0.333333333333333; ...\n 0.479308067841923, 0.260345966079038; ...\n 0.260345966079038, 0.479308067841923; ...\n 0.260345966079038, 0.260345966079038; ...\n 0.869739794195568, 0.065130102902216; ...\n 0.065130102902216, 0.869739794195568; ...\n 0.065130102902216, 0.065130102902216; ...\n 0.638444188569809, 0.312865496004875; ...\n 0.638444188569809, 0.048690315425316; ...\n 0.312865496004875, 0.638444188569809; ...\n 0.312865496004875, 0.048690315425316; ...\n 0.048690315425316, 0.638444188569809; ...\n 0.048690315425316, 0.312865496004875 ]';\n t = [ ...\n 0.0, 0.0; ...\n 1.0, 0.0; ... \n 0.0, 1.0 ]';\n\n plot_filename = 'test01.svg';\n\n triangle_svg ( plot_filename, t, p_num, p );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/triangle_svg/triangle_svg_test01.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473813156294, "lm_q2_score": 0.8539127529517044, "lm_q1q2_score": 0.7449085539094393}} {"text": "function outsig=rampup(L,wintype)\n%RAMPUP Rising ramp function\n% Usage: outsig=rampup(L);\n%\n% `rampup(L)` will return a rising ramp function of length *L*. The\n% ramp is a sinusoide starting from zero and ending at one. The ramp\n% is centered such that the first element is always 0 and the last\n% element is not quite 1, such that the ramp fits with following ones.\n%\n% `rampup(L,wintype)` will use another window for ramping. This may be any\n% of the window types from |firwin|. Please see the help on |firwin| for\n% more information. The default is to use a piece of the Hann window.\n%\n% See also: rampdown, rampsignal, firwin\n\ncomplainif_argnonotinrange(nargin,1,2,mfilename);\n\nif nargin==1\n wintype='hann';\nend;\n \nwin=firwin(wintype,2*L,'inf');\noutsig=win(L+1:2*L);\n\n", "meta": {"author": "ltfat", "repo": "ltfat", "sha": "4496a06ad8dddb85cd2e007216b765dc996ef327", "save_path": "github-repos/MATLAB/ltfat-ltfat", "path": "github-repos/MATLAB/ltfat-ltfat/ltfat-4496a06ad8dddb85cd2e007216b765dc996ef327/sigproc/rampup.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.7449085531063679}} {"text": "function geometry_test1745 ( )\n\n%*****************************************************************************80\n%\n%% TEST1745 tests R8MAT_SOLVE.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 22 May 2005\n%\n% Author:\n%\n% John Burkardt\n%\n n = 3;\n nrhs = 2;\n\n a = [ ...\n 1.0, 4.0, 7.0; ...\n 2.0, 5.0, 8.0; ...\n 3.0, 6.0, 0.0; ...\n 14.0, 32.0, 23.0; ...\n 7.0, 16.0, 7.0 ]';\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TEST1745\\n' );\n fprintf ( 1, ' R8MAT_SOLVE solves linear systems.\\n' );\n fprintf ( 1, '\\n' );\n%\n% Print out the matrix to be inverted.\n%\n r8mat_print ( n, n+nrhs, a, ' The linear system:' );\n%\n% Solve the systems.\n%\n [ a, info ] = r8mat_solve ( n, nrhs, a );\n \n if ( info ~= 0 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' The input matrix was singular.\\n' );\n fprintf ( 1, ' The solutions could not be computed.\\n' );\n return\n end\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' The computed solutions:\\n' );\n fprintf ( 1, '\\n' );\n for i = 1 : n\n for j = 1 : nrhs\n fprintf ( 1, ' %12f', a(i,n+j) );\n end\n fprintf ( 1, '\\n' );\n end\n \n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/geometry/geometry_test1745.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.872347368040789, "lm_q2_score": 0.8539127548105611, "lm_q1q2_score": 0.7449085441954526}} {"text": "function [ r c ] = corner_ST( img,ptNum )\n%[ r c ] = corner_ST( img )\n%\tFind corner points in image using Shi-Tomasi method\n% IMG should be gray.R and C are the coordinates of corners(col vec)\n\nimg = im2double(img);\nh1 = fspecial('gauss',[6 6],1.5);\nhd = imfilter(h1,[-1 1],'rep');\nhd = hd(1:5,1:5); % use the HOG gradient\n% hd = [-1 0 1];\nimgdx = imfilter(img,hd,'rep');\nimgdy = imfilter(img,hd','rep');\n\nker = fspecial('gauss',[5 5],1.5); % weight of the patch\nimgdx2 = imfilter(imgdx.^2,ker,'rep');\nimgdxdy = imfilter(imgdx.*imgdy,ker,'rep');\nimgdy2 = imfilter(imgdy.^2,ker,'rep');\n\nA = zeros(2,2,numel(img));\nA(1,1,:) = imgdx2(:);\nA(1,2,:) = imgdxdy(:);\nA(2,1,:) = imgdxdy(:);\nA(2,2,:) = imgdy2(:);\nev = real(eig2(A));\n\nevTh = .1;\nminEv = min(ev,[],2);\nminEv = reshape(minEv,size(img));\nR = (minEv > evTh*max(max(minEv)));\n% fis(R)\n\nRmax = ordfilt2(minEv,9,ones(3));\nRcorner = (minEv == Rmax) & R; % non-maximal suppression\n% fis(Rcorner)\nI = find(Rcorner);\n\nif exist('ptNum','var') && nnz(Rcorner) > ptNum\n\tselEvs = minEv(I); % find the ptNum corners with the largest ev\n\t[~,I1] = sort(selEvs,'descend');\n\tI = I(I1(1:ptNum));\nend\n[r c] = ind2sub(size(img),I); % points' positions\n\nend\n\nfunction ev = eig2(a) % eigenvalue of a 2*2 matrix\nb = -(a(1,1,:)+a(2,2,:));\ndetA = a(1,1,:).*a(2,2,:)-a(1,2,:).*a(2,1,:);\ndelta = b.^2-4*detA;\nev = [-b+sqrt(delta),-b-sqrt(delta)]/2; \nev = reshape(ev,2,[])'; % N-by-2\nend", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/30822-lucas-kanade-tracker-with-pyramid-and-iteration/LK Tracker/corner_ST.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.905989822921759, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.7448949847697769}} {"text": "function [logbf,t] = spm_bms_ttest (y,prior)\n% Log Bayes Factor against null for one sample t-test\n% FORMAT [logbf,t] = spm_bms_ttest (y,prior)\n% \n% y [N x 1] data vector\n% prior 'jzs' (default), 'unit'\n%\n% logbf Log Bayes Factor \n% t t-statistic\n%\n% Default prior is 'jzs'. The different priors are described in\n% [1] Rouder et al. (2009) Psych Bull Rev, 16(2),225-237.\n%\n% These tests consider the quantity d = mean / standard deviation. \n% The unit information prior, 'unit', uses a zero mean unit variance \n% Gaussian prior over d (the prior variance of d, sig_d^2, is unity).\n%\n% The (Jeffreys-Zellner-Snow) JZS prior, 'jzs', uses a Cauchy over d \n% and an inverse chi^2 over sig_d^2.\n%_______________________________________________________________________\n% Copyright (C) 2014 Wellcome Trust Centre for Neuroimaging\n\n% Will Penny\n% $Id: spm_bms_ttest.m 6038 2014-06-04 15:22:42Z will $\n\ntry \n pr=prior;\ncatch\n pr='jzs';\nend\n\nN=length(y);\nm=mean(y);\ns=std(y);\nsem=s/sqrt(N);\nt=m/sem;\nv=N-1;\n\nswitch pr,\n case 'unit',\n rs=1;\n case 'jzs',\n logbf = jzs_logbf(t,v,N);\n return\n otherwise\n disp('Unknown prior in bayes_ttest');\n return\nend\n\n% For Unit Information prior, 'unit':\n%\n% The minimum value of logbf obtains when t=0\n% This minimum value is logbf=-0.5*log(1+N*r)\n% For r=1 logbf=-3 can be gotten with N=405 samples.\n\n% See note 5 at end of [1]\nt2=t^2;\nnr=1+N*rs^2;\nlog_num=-0.5*N*log(1+t2/v);\nlog_denom1=-0.5*log(nr);\nlog_denom2=-0.5*N*log(1+t2/(nr*v));\n\nlogbf=log_num-log_denom1-log_denom2;\nlogbf=-logbf;\n\n\n%-------------------------------------------------------\nfunction [logbf] = jzs_logbf(t,v,N)\n% JZS Log Bayes factor \n%\n% See equation (1) in \n% Rouder et al. (2009) Psych Bull Rev, 16(2),225-237.\n\nt2=t^2;\nnum=(1+t2/v)^(-0.5*(v+1));\n\ngmax=1000;\ndenom=quad(@(g)jzs_integrand(g,t2,N,v),0,gmax);\n\nlogbf=log(num/denom);\nlogbf=-logbf;\n\n%--------------------------------------------------------\nfunction [j] = jzs_integrand(g,t2,N,v)\n\nng=1+N*g;\nt1=ng.^(-0.5);\nt2=(1+t2./(ng*v)).^(0.5*(v+1));\nt3=(2*pi)^(-0.5)*(g.^(-1.5)).*exp(-1./(2*g));\nj=t1.*t2.*t3;\n", "meta": {"author": "spm", "repo": "spm12", "sha": "3085dac00ac804adb190a7e82c6ef11866c8af02", "save_path": "github-repos/MATLAB/spm-spm12", "path": "github-repos/MATLAB/spm-spm12/spm12-3085dac00ac804adb190a7e82c6ef11866c8af02/spm_bms_ttest.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765210631689, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.7448587908811505}} {"text": "function [R,S]=rga(G)\n% RGA Relative Gain Array\n% \n% R=rga(G) returns the Relative Gain Array, R based on the gain matrix, G.\n%\n% For square matrix, G, R is the normal RGA, defined as follows:\n% R = inv(G') .* G \n% If G is nonsquare, R is the so called General RGA:\n% R = pinv(G') .* G\n% \n% The RGA is a very useful tool for control structure design. For a square\n% system (the number of inputs equals to the number of output), the RGA can\n% be used to find input-output pairs (one input to control one output).\n% There are many publications on how to pair input and output using the\n% RGA. The basic rule is:\n% 1. Avoid input and output pairs which have negative relative gains.\n% 2. Avoid input and output pairs which have large relative gains.\n% 3. Select input and output pairs which have the relative gain close to 1.\n% \n% Interestingly, if the RGA is repeatedly calculated based on R, i.e.\n%\n% R = rga(R);\n% \n% Eventualy, the RGA will converge to a selection (0,1)-matrix. With the\n% second output, \n%\n% [R,S] = rga(G) produces a selection matrix, S based on the repeated RGA.\n%\n% where S is (0,1) matrix with the same dimension as G. Each row and each\n% column of S have only one element of 1, but all others are 0. The element\n% of 1 indicates which input (column) should be used to pair which output\n% (row).\n% Note: The selection matrix, S, is only a recommendation. It may not\n% satisfy the rules stated above and may not be appropriate for some\n% systems.\n%\n% For nonsquare systems, the general RGA can also be used to select inputs\n% if the number of inputs is larger than the number of outputs, or to\n% choose outputs, if the system has more outputs than inputs. The second\n% output in this case gives the input (output) effectiveness, E.\n%\n% [R,E] = rga(G)\n%\n% Where E is a column vector corresponding to the input (output). Inputs\n% (outputs) with largest input (output) effectiveness are recommented to be\n% selected for the control system.\n%\n% By Yi Cao at Cranfield University on 7th March 2008\n%\n% References:\n%\n% 1. Bristol, E.H., On a new measure of interactions for multivariable process\n% control. IEEE Trans. Automatic Control, AC-11:133-134, 1966.\n% 2. Cao, Y and Rossiter, D, An input pre-screening technique for control\n% structure selection, Computers and Chemical Engineering, 21(6), pp.\n% 563-569, 1997.\n \n% Examples:\n%\n% Example 1: A random 5 x 5 matrix\n%{\nG = randn(5);\n[R,S] = rga(G)\n%}\n% Example 2: A random 5 x 10 matrix for input selection\n%{\nG = randn(5,10);\n[R,IE] = rga(G)\n%}\n% Example 3: A random 10 x 5 matrix for output selection\n%{\nG = randn(10,5);\n[R,OE] = rga(G)\n%}\n%\n\n\n% Check input and output\nerror(nargchk(1,1,nargin));\nerror(nargoutchk(0,2,nargout));\n\n% The RGA\nR=pinv(G.').*G;\nif nargout<2\n return\nend\n\n[m,n]=size(G);\n% The square case\nif n==m\n S=R;\n while norm(round(S)-S)>1e-9\n S(S<0)=0;\n S = inv(S.').*S;\n end\n return\nend\n\n% The nonsquare case\nS = sqrt(sum(R))';\nif m>n\n S = sqrt(sum(R,2));\nend\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/19096-relative-gain-array/rga.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765281148513, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.7448587884267801}} {"text": "%% LSHAPESTOKES Poiseuille flow in a L-shaped domain\n%\n% Stokes equations on the square [-1,1]^2. \n%\n% Reference: page 237 in Finite Elements and Fast Iterative Solvers with\n% Applications in Incompressible Fluid Dynamics. by Howard C. Elman, David\n% J. Silvester, and Andrew J. Wathen.\n%\n% See also squareStokes, StokesP2P1\n%\n% Copyright (C) Long Chen. See COPYRIGHT.txt for details.\n\nclose all; clear all;\n%% Parameters\nmaxIt = 4; N = zeros(maxIt,1); \nerru = zeros(maxIt,1); errp = zeros(maxIt,1);\n\n%% Generate an initial mesh \n[node,elem] = squaremesh([-1 1 -1 1], 0.25);\nbdFlag = setboundary(node,elem,'Dirichlet');\n\n%% PDE and options\npde = Stokesdata1;\n\n%% Finite Element Method \nfor k = 1:maxIt\n % solve the equation\n [u,p,edge,A] = StokesP2P1(node,elem,pde,bdFlag);\n N(k) = length(u)+length(p);\n if N(k) < 2e3 % show solution for small size\n figure(1); showresult(node,elem,p); \n end\n % compute error\n uI = pde.exactu([node; (node(edge(:,1),:)+node(edge(:,2),:))/2]);\n erru(k) = sqrt((u-uI(:))'*A*(u-uI(:)));\n errp(k) = getL2error(node,elem,pde.exactp,p);\n % refine mesh\n [node,elem,bdFlag] = uniformrefine(node,elem,bdFlag);\nend\n\n%% Plot convergence rates\nfigure(2); clf;\nshowrate2(N,erru,2,'-*','||Du_I-Du_h||',N,errp,2,'k-+','|| p - p_h||');", "meta": {"author": "wme7", "repo": "Aero-matlab", "sha": "9430008f2e3b84f28633775a44dff534e780fbac", "save_path": "github-repos/MATLAB/wme7-Aero-matlab", "path": "github-repos/MATLAB/wme7-Aero-matlab/Aero-matlab-9430008f2e3b84f28633775a44dff534e780fbac/iFEM/example/2D/LshapeStokes.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765210631688, "lm_q2_score": 0.8152324915965391, "lm_q1q2_score": 0.7448587867795848}} {"text": "function p=legendrep(m,x)\n% function which construct Legendre polynomial Pm(x)\n% where M is the degree of polynomial and X is the variable. \n% Result - P is the char string that should be evaluated EVAL(P)\n% Example:\n% P=legendrep(2,'cos(theta)') will produce\n% P='(3*cos(theta).^2 -1)/2' which then can be evaluated as\n% theta=0.3; P=legendrep(2,'cos(theta)'); Lp=eval(P); produce\n% Lp = 0.8690\n% For Matlab R14 the following example can be used:\n% x=-5:.1:5; p=legendrep(5,'x .*cos(x)'); xp = eval(p); \n% figure; plot(x, xp, 'r.-'); grid\n\n%% References: \n% Gradshteyn, Ryzhik \"Table of Integrals Series and Products\", 6th ed., p.973\n% \n%__________________________________________________\n% \tSergei Koptenko, Resonant Medical Inc., Toronto \n%\tsergei.koptenko@resonantmedical.com \n%______________March/30/2004_______________________\n%%\nswitch m\ncase 0\n p='1'; return\ncase 1\n p=x; return\ncase 2\n p=['(3*' x '.^2 -1)/2']; return\ncase 3\n p=['(5*' x '.^3 - 3 *' x ')/2']; return\ncase 4\n p=['(35 *' x '.^4 - 30 * ' x '.^2 + 3)/8']; return\ncase 5\n p=['( 63 * ' x '.^5 - 70 * ' x '.^3 + 15 *' x ' )/8']; return\ncase 6\n p=['(231 *' x '.^6 - 315 * ' x '.^4 + 105 * ' x '.^2 -5)/16']; return\n case 7\n p=['(429 * ' x '.^7 - 693 * ' x '.^5 +315 * ' x '.^3 -35 *' x ' )/16']; return\ncase 8\n p=['(6435 *' x '.^8 -12012 *' x '.^6 + 6930 * ' x '.^4 -1260 * ' x '.^2 +35)/128']; return\ncase 9\n p=['(12155 * ' x '.^9 -25740 * ' x '.^7 +18018 * ' x '.^5 -4620 * ' x '.^3 +315 *' x ' )/128'];\n return\ncase 10\n p=['(46189 *' x '.^10 -109395 *' x '.^8 +90090 *' x '.^6 -30030 * ' x '.^4 +3465 * ' x '.^2 -63)/256'];\n return\ncase 11\n p=['(88179 * ' x '.^11 -230945 * ' x '.^9 +218790 * ' x '.^7 -90090 * ' x '.^5 +15015 * ' x '.^3 -693 *' x ' )/256'];\n return \ncase 12\n p=['(676039 *' x '.^12 -1939938 *' x '.^10 +2078505 *' x '.^8 -1021020 *' x '.^6 +225225 * ' x '.^4 -18018 * ' x '.^2 +231)/1024'];\n return\n \notherwise\n iii=m-10; %shift counter \n pp=strvcat(legendrep(11,x),legendrep(12,x)); % get last two members\n for ii=3:1:iii, % Begin construct from 13th member \n p_ii=[num2str(1/(ii)) ' * (' num2str(2*ii-1) ' * ' x '.*(' ...\n deblank(pp(ii-1,:)) ')-' num2str(ii-1) '.*(' deblank(pp(ii-2,:)) '))'];\n pp=strvcat(pp, p_ii);\n end\np=deblank(pp(iii,:)); % remove traiing blanks\n return\nend\n\nreturn\n\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/4710-legendre-polynomial-pmx/legendrep.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.913676530465412, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.7448587862414677}} {"text": "function [A,b] = parallax(n)\n%PARALLAX Stellar parallax problem with 28 fixed, real observations.\n%\n% [A,b] = parallax(n)\n%\n% Stellar parallax problem with 28 fixed, real observations.\n%\n% The underlying problem is a Fredholm integral equation of the\n% first kind with kernel\n% K(s,t) = (1/sigma*sqrt(2*pi))*exp(-0.5*((s-t)/sigma)^2) ,\n% and it is discretized by means of a Galerkin method with n\n% orthonormal basis functions. The right-hand side consists of\n% a measured distribution function of stellar parallaxes, and its\n% length is fixed, m = 26. The exact solution, which represents\n% the true distribution of stellar parallaxes, in not known.\n\n% Reference: W. M. Smart, \"Stellar Dynamics\", Cambridge University Press,\n% 1938; p. 30.\n\n% Discretized by Galerkin method with orthonormal box functions;\n% 2-D integration is done by means of the computational molecule:\n% 1 4 1\n% 4 16 4\n% 1 4 1\n\n% Per Christian Hansen, IMM, 09/16/92.\n\n% Initialization.\na = 0; b = 0.1; m = 26; sigma = 0.014234;\nhs = 0.130/m; hx = (b-a)/n; hsh = hs/2; hxh = hx/2;\nss = (-0.03 + [0:m-1]'*hs)*ones(1,n);\nxx = ones(m,1)*(a + [0:n-1]*hx);\n\n% Set up the matrix.\nA = 16*exp(-0.5*((ss+hsh - xx-hxh)/sigma).^2);\nA = A + 4*(exp(-0.5*((ss+hsh - xx )/sigma).^2) + ...\n exp(-0.5*((ss+hsh - xx-hx )/sigma).^2) + ...\n exp(-0.5*((ss - xx-hxh)/sigma).^2) + ...\n exp(-0.5*((ss+hs - xx-hxh)/sigma).^2));\nA = A + (exp(-0.5*((ss - xx )/sigma).^2) + ...\n exp(-0.5*((ss+hs - xx )/sigma).^2) + ...\n exp(-0.5*((ss - xx-hx )/sigma).^2) + ...\n exp(-0.5*((ss+hs - xx-hx )/sigma).^2));\nA = sqrt(hs*hx)/(36*sigma*sqrt(2*pi))*A;\n\n% Set up the normalized right-hand side.\nb = [3;7;7;17;27;39;46;51;56;50;43;45;43;32;33;29;...\n 21;12;17;13;15;12;6;6;5;5]/(sqrt(hs)*640);", "meta": {"author": "goodshawn12", "repo": "REST", "sha": "e34ce521fcb36e7813357a9720072dd111edf797", "save_path": "github-repos/MATLAB/goodshawn12-REST", "path": "github-repos/MATLAB/goodshawn12-REST/REST-e34ce521fcb36e7813357a9720072dd111edf797/dependencies/BCILAB/dependencies/SIFT-private/external/regu/regu/parallax.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765163620469, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7448587808962949}} {"text": "function [Y, spectrum] = sllle_wg(G, d)\n%SLLLE_WG Solves the Locally Linear Embedding from weight graph\n%\n% $ Syntax $\n% - Y = sllle_wg(G, d)\n% - [Y, spectrum] = sllle_wg(G, d)\n%\n% $ Arguments $\n% - G: The weights graph\n% - d: The dimension of the embedding\n% - Y: The sample coordinates in the embedded space\n% - spectrum: The spectrum of the embeded space dimensions\n%\n% $ Description $\n% - Y = sllle_wg(G, d) solves the locally linear embedding from\n% a given weight graph. G should be a graph of n nodes, where\n% the edge value from i-th node to j-th node, means the weights\n% on the i-th sample in constructing the j-th sample, (or the\n% construction of i-th sample to the j-th sample). \n% Y is solved by taking the eigenvectors of (I - W)(I - W)^T, \n% corresponding to the (d+1) smallest eigenvalues, and discarding \n% the smallest one. In our output, the dimension is sorted in the \n% ascending order of eigenvalues.\n%\n% - [Y, spectrum] = sllle_wg(G, d) also returns the spectrum of the\n% corresponding dimensions, a column vector of the corresponding\n% eigenvalues.\n%\n% $ Remarks $\n% - The dimension d should be strictly less than n.\n%\n% $ History $\n% - Created by Dahua Lin, on Sep 11st, 2006\n%\n\n%% parse and verify input\n\nif nargin < 2\n raise_lackinput('sllle_wg', 2);\nend\n\ngi = slgraphinfo(G, {'square'});\nif ~gi.valued\n error('sltoolbox:invalidarg', 'The graph G should be a valued graph');\nend\nif isnumeric(G)\n W = G;\nelse\n W = sladjmat(G, 'sparse', true);\nend\n\nn = gi.n;\nif d >= n\n error('sltoolbox:invalidarg', 'd should be strictly less than n');\nend\n\n%% compute\n\nif issparse(W)\n M = speye(n) - W;\nelse\n M = eye(n) - W;\nend\nclear W;\nM = M * M';\n\n[spectrum, Y] = slsymeig(M, d+1, 'ascend');\nclear M;\nspectrum = spectrum(2:d+1);\nY = Y(:, 2:d+1);\nY = Y';\n\n\n", "meta": {"author": "lmthang", "repo": "nmt.hybrid", "sha": "50d5c025f18ed280ff0fd2e2adce327f4170a2c3", "save_path": "github-repos/MATLAB/lmthang-nmt.hybrid", "path": "github-repos/MATLAB/lmthang-nmt.hybrid/nmt.hybrid-50d5c025f18ed280ff0fd2e2adce327f4170a2c3/code/wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/manifold/sllle_wg.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765234137297, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.7448587804927073}} {"text": "function [ img_ihs] = rgb2ihs( img_rgb )\nr=img_rgb(:,:,1);\ng=img_rgb(:,:,2);\nb=img_rgb(:,:,3);\n\n% rgb\u05eaihs\nI=1/sqrt(3).*r+1/sqrt(3).*g+1/sqrt(3).*b;\nv1=1/sqrt(6).*r+1/sqrt(6).*g-2/sqrt(6).*b;\nv2=1/sqrt(2).*r-1/sqrt(2).*g;\nimg_ihs=cat(3,I,v1,v2);\nend\n\n", "meta": {"author": "thfylsty", "repo": "Classic-and-state-of-the-art-image-fusion-methods", "sha": "5d9457df396f1ea6921e1b9b3703995205940862", "save_path": "github-repos/MATLAB/thfylsty-Classic-and-state-of-the-art-image-fusion-methods", "path": "github-repos/MATLAB/thfylsty-Classic-and-state-of-the-art-image-fusion-methods/Classic-and-state-of-the-art-image-fusion-methods-5d9457df396f1ea6921e1b9b3703995205940862/DDcGAN-master/PET-MRI image fusion/rgb2ihs.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9390248140158416, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.7447461614174463}} {"text": "function cnt = countcover(sz,blocksize,stepsize)\n%COUNTCOVER Covering of signal samples by blocks\n% CNT = COUNTCOVER(SZ,BLOCKSIZE,STEPSIZE) assumes a p-dimensional signal\n% of size SZ=[N1 N2 ... Np] covered by (possibly overlapping) blocks of\n% size BLOCKSIZE=[M1 M2 ... Mp]. The blocks start at position (1,1,..,1)\n% and are shifted between them by steps of size STEPSIZE=[S1 S2 ... Sp].\n% COUNTCOVER returns a matrix the same size as the signal, containing in\n% each entry the number of blocks covering that sample.\n%\n% See also IM2COLSTEP, COL2IMSTEP, IM2COL.\n\n\n% Ron Rubinstein\n% Computer Science Department\n% Technion, Haifa 32000 Israel\n% ronrubin@cs\n%\n% August 2008\n\n\ncnt = ones(sz);\nfor k = 1:length(sz)\n \n % this code is modified from function NDGRID, so it computes one\n % output argument of NDGRID at a time (to conserve memory)\n ids = (1:sz(k))';\n s = sz; s(k) = [];\n ids = reshape(ids(:,ones(1,prod(s))),[length(ids) s]);\n ids = permute(ids,[2:k 1 k+1:length(sz)]);\n \n cnt = cnt .* max( min(floor((ids-1)/stepsize(k)),floor((sz(k)-blocksize(k))/stepsize(k))) - ...\n max(ceil((ids-blocksize(k))/stepsize(k)),0) + 1 , 0 );\nend\n", "meta": {"author": "tiepvupsu", "repo": "DICTOL", "sha": "1a0361aa35c32d70525d06910d0e9b87997ff246", "save_path": "github-repos/MATLAB/tiepvupsu-DICTOL", "path": "github-repos/MATLAB/tiepvupsu-DICTOL/DICTOL-1a0361aa35c32d70525d06910d0e9b87997ff246/LCKSVD/ksvdbox/private/countcover.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942014971872, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.7447316774511572}} {"text": "function [x1,x2,nS]=bracket(S,x0,d,problem,stepsize)\n% Bracket the minimum (or maximum) of the objective function\n% in the search direction.\n%\n% [x1,x2,nS]=bracket(S,x0,d,problem,stepsize)\n%\n% S: objective function\n% x0: initial point\n% d: search direction vector\n% problem: (-1): minimum (default), (1): maximum\n% stepsize: initial stepsize (default = 0.01*norm(d))\n% [x1,x2]: unsorted lower and upper limits\n% nS: number of objective function evaluations\n\n% Copyright (c) 2001 by LASIM-DEQUI-UFRGS\n% $Revision: 1.0 $ $Date: 2001/07/04 21:45:10 $\n% Argimiro R. Secchi (arge@enq.ufrgs.br)\n\n if nargin < 3,\n error('bracket requires three input arguments');\n end\n if nargin < 4,\n problem=-1;\n end\n if nargin < 5,\n stepsize=0.01*norm(d);\n end\n\n d=d(:);\n x0=x0(:);\n j=0; nS=1;\n y0=feval(S,x0)*problem;\n \n while j < 2,\n x=x0+stepsize*d;\n y=feval(S,x)*problem;\n nS=nS+1;\n \n if y0 >= y,\n stepsize=-stepsize;\n j=j+1;\n else\n while y0 < y,\n stepsize=2*stepsize;\n y0=y;\n x=x+stepsize*d;\n y=feval(S,x)*problem;\n nS=nS+1;\n end \n j=1;\n break;\n end\n end\n \n x2=x;\n x1=x0+stepsize*(j-1)*d;\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/15072-unconstrained-optimization-using-powell/bracket.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278726384089, "lm_q2_score": 0.8438950966654772, "lm_q1q2_score": 0.7446765548805016}} {"text": "clear; clc;\n% P2.4\nx = [1,-2,4,6,-5,8,10];\nn = [-4:2];\n\n% P2.4a\n[x11,n11] = sigshift(x,n,-2);\n[x12,n12] = sigshift(x,n,4);\n[x1,n1] = sigadd(3*x11,n11,x12,n12);\n[x1,n1] = sigadd(x1,n1,-2*x,n);\n[xe,xo,m] = evenodd(x1,n1);\nfigure(1);\nsubplot(2,2,1); stem(n1,x1,'ko'); title('Original Sequence')\nxlabel('n'); ylabel('x(n)');\nsubplot(2,2,2); stem(m,xe,'ko'); title('Even Part')\nxlabel('n'); ylabel('xe(n)');\nsubplot(2,2,4); stem(m,xo,'ko'); title('Odd Part')\nxlabel('n'); ylabel('xo(n)');\n\n% P2.4b\n[x21,n21] = sigshift(x,n,-5);\n[x22,n22] = sigshift(x,n,-4);\n[x2,n2] = sigadd(5*x21,n21,4*x22,n22);\n[x2,n2] = sigadd(x2,n2,3*x,n);\n[xe,xo,m] = evenodd(x2,n2);\nfigure(2);\nsubplot(2,2,1); stem(n2,x2,'ko'); title('Original Sequence')\nxlabel('n'); ylabel('x(n)');\nsubplot(2,2,2); stem(m,xe,'ko'); title('Even Part')\nxlabel('n'); ylabel('xe(n)');\nsubplot(2,2,4); stem(m,xo,'ko'); title('Odd Part')\nxlabel('n'); ylabel('xo(n)');\n\n% P2.4c\n[x31,n31] = sigshift(x,n,-4);\n[x32,n32] = sigshift(x,n,1);\n[x33,n33] = sigmult(x31,n31,x32,n32);\n[x31,n31] = sigfold(x,n); [x31,n31] = sigshift(x31,n31,2);\n[x32,n32] = sigmult(x31,n31,x,n);\n[x3,n3] = sigadd(x33,n33,x32,n32);\n[xe,xo,m] = evenodd(x3,n3);\nfigure(3);\nsubplot(2,2,1); stem(n3,x3,'ko'); title('Original Sequence')\nxlabel('n'); ylabel('x(n)');\nsubplot(2,2,2); stem(m,xe,'ko'); title('Even Part')\nxlabel('n'); ylabel('xe(n)');\nsubplot(2,2,4); stem(m,xo,'ko'); title('Odd Part')\nxlabel('n'); ylabel('xo(n)');\n\n% P2.4d\n[x41,n41] = sigshift(x,n,-2);\nx42 = cos(0.1*pi*n);\n[x42,n42] = sigmult(x42,n,x41,n41);\nx43 = 2*exp(0.5*n);\n[x41,n41] = sigmult(x43,n,x,n);\n[x4,n4] = sigadd(x42,n42,x41,n41);\n[xe,xo,m] = evenodd(x4,n4);\nfigure(4);\nsubplot(2,2,1); stem(n4,x4,'ko'); title('Original Sequence')\nxlabel('n'); ylabel('x(n)');\nsubplot(2,2,2); stem(m,xe,'ko'); title('Even Part')\nxlabel('n'); ylabel('xe(n)');\nsubplot(2,2,4); stem(m,xo,'ko'); title('Odd Part')\nxlabel('n'); ylabel('xo(n)');\n\n% P2.4e\nx5 = zeros(size(n));\nfor k = 1:5,\n [x51,n51] = sigshift(x,n,k);\n x52 = n.*x51;\n x5 = sigadd(x5,n51,x52,n51);\nend\n[xe,xo,m] = evenodd(x5,n51);\nfigure(5);\nsubplot(2,2,1); stem(n51,x5,'ko'); title('Original Sequence')\nxlabel('n'); ylabel('x(n)');\nsubplot(2,2,2); stem(m,xe,'ko'); title('Even Part')\nxlabel('n'); ylabel('xe(n)');\nsubplot(2,2,4); stem(m,xo,'ko'); title('Odd Part')\nxlabel('n'); ylabel('xo(n)');", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/16323-ingle-proakis-chapter-2-solutions/P204.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096204605946, "lm_q2_score": 0.8128673269042767, "lm_q1q2_score": 0.744675578335095}} {"text": "function x = inv_digamma(y,niter)\n% INV_DIGAMMA Inverse of the digamma function.\n%\n% inv_digamma(y) returns x such that digamma(x) = y.\n\n% a different algorithm is provided by Paul Fackler:\n% http://www.american.edu/academic.depts/cas/econ/gaussres/pdf/loggamma.src\n\n% Newton iteration to solve digamma(x)-y = 0\nx = exp(y)+1/2;\ni = find(y <= -2.22);\nx(i) = -1./(y(i) - digamma(1));\n\n% never need more than 5 iterations\nif nargin < 2\n niter = 5;\nend\nfor iter = 1:niter\n x = x - (digamma(x)-y)./trigamma(x);\nend\nreturn\n\n% test\ny = -3:0.01:0.1;\nx = digamma(inv_digamma(y));\nmax(abs(x-y))\nmax(abs(x-y)./inv_digamma(y))\n", "meta": {"author": "FuzhenZhuang", "repo": "Transfer-Learning-Toolkit", "sha": "24b5323b354aee844b8b7df9fcad17fdfb191dc4", "save_path": "github-repos/MATLAB/FuzhenZhuang-Transfer-Learning-Toolkit", "path": "github-repos/MATLAB/FuzhenZhuang-Transfer-Learning-Toolkit/Transfer-Learning-Toolkit-24b5323b354aee844b8b7df9fcad17fdfb191dc4/utilities/TLLibrary64/LR/fastfit/inv_digamma.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.91610961358942, "lm_q2_score": 0.8128673110375457, "lm_q1q2_score": 0.7446755582140769}} {"text": "function [rVectECI, vVectECI] = getInertialVectFromFixedFrameVect(ut, rVectECEF, bodyInfo, vVectECEF)\n%getInertialVectFromFixedFrameVect Summary of this function goes here\n% Detailed explanation goes here\n numElems = length(ut);\n\n spinAngle = getBodySpinAngle(bodyInfo, ut);\n \n cSA = reshape(cos(spinAngle),1,1,numElems);\n sSA = reshape(sin(spinAngle),1,1,numElems);\n zero = zeros(1,1,numElems);\n one = zero + 1;\n \n% R = [cos(spinAngle) -sin(spinAngle) 0;\n% sin(spinAngle) cos(spinAngle) 0;\n% 0 0 1];\n\n R = [cSA, -sSA, zero;\n sSA, cSA, zero;\n zero, zero, one];\n \n rVectECEF = reshape(rVectECEF,3,1,numElems);\n% rVectECI = R * rVectECEF;\n rVectECI = mtimesx(R,rVectECEF);\n rVectECI = reshape(rVectECI,3,numElems);\n \n rotRateRadSec = 2*pi/bodyInfo.rotperiod;\n omegaRI = repmat([0;0;rotRateRadSec],1,1,numElems);\n vVectECEF = reshape(vVectECEF,3,1,numElems);\n% vVectECI = R*(vVectECEF + cross(omegaRI, rVectECEF));\n vVectECI = mtimesx(R,(vVectECEF + cross(omegaRI, rVectECEF)));\n vVectECI = reshape(vVectECI,3,numElems);\nend\n\n", "meta": {"author": "Arrowstar", "repo": "ksptot", "sha": "2b414440d3b167ba2294f56dafce0f465c07f982", "save_path": "github-repos/MATLAB/Arrowstar-ksptot", "path": "github-repos/MATLAB/Arrowstar-ksptot/ksptot-2b414440d3b167ba2294f56dafce0f465c07f982/helper_methods/astrodynamics/fixed_frame/getInertialVectFromFixedFrameVect.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545348152283, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.7445939017263137}} {"text": "function [LIFT] = Lift2D()\n\n% function [LIFT] = Lift2D()\n% Purpose : Compute surface to volume lift term for DG formulation\n\nGlobals2D;\nEmat = zeros(Np, Nfaces*Nfp);\n\n% face 1\nfaceR = r(Fmask(:,1));\nV1D = Vandermonde1D(N, faceR); \nmassEdge1 = inv(V1D*V1D');\nEmat(Fmask(:,1),1:Nfp) = massEdge1;\n\n% face 2\nfaceR = r(Fmask(:,2));\nV1D = Vandermonde1D(N, faceR);\nmassEdge2 = inv(V1D*V1D');\nEmat(Fmask(:,2),Nfp+1:2*Nfp) = massEdge2;\n\n% face 3\nfaceS = s(Fmask(:,3));\nV1D = Vandermonde1D(N, faceS); \nmassEdge3 = inv(V1D*V1D');\nEmat(Fmask(:,3),2*Nfp+1:3*Nfp) = massEdge3;\n\n% inv(mass matrix)*\\I_n (L_i,L_j)_{edge_n}\nLIFT = V*(V'*Emat);\nreturn\n", "meta": {"author": "wme7", "repo": "Aero-matlab", "sha": "9430008f2e3b84f28633775a44dff534e780fbac", "save_path": "github-repos/MATLAB/wme7-Aero-matlab", "path": "github-repos/MATLAB/wme7-Aero-matlab/Aero-matlab-9430008f2e3b84f28633775a44dff534e780fbac/JSHesthaven&TWarburton/Codes2D/Lift2D.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947055100816, "lm_q2_score": 0.7879311931529758, "lm_q1q2_score": 0.7445908058358035}} {"text": "function [ num_int, pint ] = halfspace_imp_triangle_int_3d ( a, b, c, d, t )\n\n%*****************************************************************************80\n%\n%% HALFSPACE_IMP_TRIANGLE_INT_3D: intersection ( implicit halfspace, triangle ) in 3D.\n%\n% Discussion:\n%\n% The implicit form of a half-space in 3D may be described as the set\n% of points (X,Y,Z) on or \"above\" an implicit plane:\n%\n% 0 <= A * X + B * Y + C * Z + D\n%\n% The triangle is specified by listing its three vertices.\n%\n% The intersection may be described by the number of vertices of the\n% triangle that are included in the halfspace, and by the location of\n% points between vertices that separate a side of the triangle into\n% an included part and an unincluded part.\n%\n% 0 vertices, 0 separators (no intersection)\n% 1 vertex, 0 separators (point intersection)\n% 2 vertices, 0 separators (line intersection)\n% 3 vertices, 0 separators (triangle intersection)\n%\n% 1 vertex, 2 separators, (intersection is a triangle)\n% 2 vertices, 2 separators, (intersection is a quadrilateral).\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 08 May 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real A, B, C, D, the parameters that define the\n% implicit plane, which in turn define the implicit halfspace.\n%\n% Input, real T(3,3), the vertices of the triangle.\n%\n% Output, integer NUM_INT, the number of intersection points returned,\n% which will always be between 0 and 4.\n%\n% Output, real PINT(3,4), the coordinates of the NUM_INT\n% intersection points. The points will lie in sequence on the triangle.\n% Some points will be vertices, and some may be separators.\n%\n\n%\n% Compute the signed distances between the vertices and the plane.\n%\n dist1 = a * t(1,1) + b * t(2,1) + c * t(3,1) + d;\n dist2 = a * t(1,2) + b * t(2,2) + c * t(3,2) + d;\n dist3 = a * t(1,3) + b * t(2,2) + c * t(3,3) + d;\n%\n% Now we can find the intersections.\n%\n [ num_int, pint ] = halfspace_triangle_int_3d ( t, dist1, dist2, dist3 );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/geometry/halfspace_imp_triangle_int_3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418241572635, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.7445184007249466}} {"text": "% ======================================================== % \n% Files of the Matlab programs included in the book: %\n% Xin-She Yang, Nature-Inspired Metaheuristic Algorithms, %\n% Second Edition, Luniver Press, (2010). www.luniver.com %\n% ======================================================== % \n\n% -------------------------------------------------------- %\n% Firefly Algorithm for constrained optimization using %\n% for the design of a spring (benchmark) % \n% by Xin-She Yang (Cambridge University) Copyright @2009 %\n% -------------------------------------------------------- %\n\nfunction fa_ndim\n% parameters [n N_iteration alpha betamin gamma]\npara=[20 500 0.5 0.2 1];\n\nhelp fa_ndim.m\n\n% Simple bounds/limits for d-dimensional problems\nd=15;\nLb=zeros(1,d);\nUb=2*ones(1,d);\n\n% Initial random guess\nu0=Lb+(Ub-Lb).*rand(1,d);\n\n[u,fval,NumEval]=ffa_mincon(@cost,u0,Lb,Ub,para);\n\n% Display results\nbestsolution=u\nbestojb=fval\ntotal_number_of_function_evaluations=NumEval\n\n%%% Put your own cost/objective function here --------%%%\n%% Cost or Objective function\n function z=cost(x)\n% Exact solutions should be (1,1,...,1) \nz=sum((x-1).^2);\n\n%%% End of the part to be modified -------------------%%%\n\n%%% --------------------------------------------------%%%\n%%% Do not modify the following codes unless you want %%%\n%%% to improve its performance etc %%%\n% -------------------------------------------------------\n% ===Start of the Firefly Algorithm Implementation ======\n% Lb = lower bounds/limits\n% Ub = upper bounds/limits\n% para == optional (to control the Firefly algorithm)\n% Outputs: nbest = the best solution found so far\n% fbest = the best objective value\n% NumEval = number of evaluations: n*MaxGeneration\n% Optional:\n% The alpha can be reduced (as to reduce the randomness)\n% ---------------------------------------------------------\n\n% Start FA\nfunction [nbest,fbest,NumEval]...\n =ffa_mincon(fhandle,u0, Lb, Ub, para)\n% Check input parameters (otherwise set as default values)\nif nargin<5, para=[20 500 0.25 0.20 1]; end\nif nargin<4, Ub=[]; end\nif nargin<3, Lb=[]; end\nif nargin<2,\ndisp('Usuage: FA_mincon(@cost,u0,Lb,Ub,para)');\nend\n\n% n=number of fireflies\n% MaxGeneration=number of pseudo time steps\n% ------------------------------------------------\n% alpha=0.25; % Randomness 0--1 (highly random)\n% betamn=0.20; % minimum value of beta\n% gamma=1; % Absorption coefficient\n% ------------------------------------------------\nn=para(1); MaxGeneration=para(2);\nalpha=para(3); betamin=para(4); gamma=para(5);\n\n% Total number of function evaluations\nNumEval=n*MaxGeneration;\n\n% Check if the upper bound & lower bound are the same size\nif length(Lb) ~=length(Ub),\n disp('Simple bounds/limits are improper!');\n return\nend\n\n% Calcualte dimension\nd=length(u0);\n\n% Initial values of an array\nzn=ones(n,1)*10^100;\n% ------------------------------------------------\n% generating the initial locations of n fireflies\n[ns,Lightn]=init_ffa(n,d,Lb,Ub,u0);\n\n% Iterations or pseudo time marching\nfor k=1:MaxGeneration, %%%%% start iterations\n\n% This line of reducing alpha is optional\n alpha=alpha_new(alpha,MaxGeneration);\n\n% Evaluate new solutions (for all n fireflies)\nfor i=1:n,\n zn(i)=fhandle(ns(i,:));\n Lightn(i)=zn(i);\nend\n\n% Ranking fireflies by their light intensity/objectives\n[Lightn,Index]=sort(zn);\nns_tmp=ns;\nfor i=1:n,\n ns(i,:)=ns_tmp(Index(i),:);\nend\n\n%% Find the current best\nnso=ns; Lighto=Lightn;\nnbest=ns(1,:); Lightbest=Lightn(1);\n\n% For output only\nfbest=Lightbest;\n\n% Move all fireflies to the better locations\n[ns]=ffa_move(n,d,ns,Lightn,nso,Lighto,nbest,...\n Lightbest,alpha,betamin,gamma,Lb,Ub);\n\nend %%%%% end of iterations\n\n% -------------------------------------------------------\n% ----- All the subfunctions are listed here ------------\n% The initial locations of n fireflies\nfunction [ns,Lightn]=init_ffa(n,d,Lb,Ub,u0)\n % if there are bounds/limits,\nif length(Lb)>0,\n for i=1:n,\n ns(i,:)=Lb+(Ub-Lb).*rand(1,d);\n end\nelse\n % generate solutions around the random guess\n for i=1:n,\n ns(i,:)=u0+randn(1,d);\n end\nend\n\n% initial value before function evaluations\nLightn=ones(n,1)*10^100;\n\n% Move all fireflies toward brighter ones\nfunction [ns]=ffa_move(n,d,ns,Lightn,nso,Lighto,...\n nbest,Lightbest,alpha,betamin,gamma,Lb,Ub)\n% Scaling of the system\nscale=abs(Ub-Lb);\n\n% Updating fireflies\nfor i=1:n,\n% The attractiveness parameter beta=exp(-gamma*r)\n for j=1:n,\n r=sqrt(sum((ns(i,:)-ns(j,:)).^2));\n % Update moves\nif Lightn(i)>Lighto(j), % Brighter and more attractive\n beta0=1; beta=(beta0-betamin)*exp(-gamma*r.^2)+betamin;\n tmpf=alpha.*(rand(1,d)-0.5).*scale;\n ns(i,:)=ns(i,:).*(1-beta)+nso(j,:).*beta+tmpf;\n end\n end % end for j\n\nend % end for i\n\n% Check if the updated solutions/locations are within limits\n[ns]=findlimits(n,ns,Lb,Ub);\n\n% This function is optional, as it is not in the original FA\n% The idea to reduce randomness is to increase the convergence,\n% however, if you reduce randomness too quickly, then premature\n% convergence can occur. So use with care.\nfunction alpha=alpha_new(alpha,NGen)\n% alpha_n=alpha_0(1-delta)^NGen=10^(-4);\n% alpha_0=0.9\ndelta=1-(10^(-4)/0.9)^(1/NGen);\nalpha=(1-delta)*alpha;\n\n% Make sure the fireflies are within the bounds/limits\nfunction [ns]=findlimits(n,ns,Lb,Ub)\nfor i=1:n,\n % Apply the lower bound\n ns_tmp=ns(i,:);\n I=ns_tmpUb;\n ns_tmp(J)=Ub(J);\n % Update this new move\n ns(i,:)=ns_tmp;\nend\n\n%% ==== End of Firefly Algorithm implementation ======\n\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/29693-firefly-algorithm/fa_ndim.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418199787564, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.7445183952022536}} {"text": "% Fig. 8.19 Feedback Control of Dynamic Systems, 5e \n% Franklin, Powell, Emami\n%\n\nclear all;\nclose all;\n\nnumGs=1;\ndenGs=[1 0 0]; % s^2\n\nnumDs=.81*[1 .2];\ndenDs=[1 2];\n\nnumC=conv(numGs,numDs);\ndenC=conv(denGs,denDs);\n\n[numCL,denCL]=feedback(numC,denC,1,1);\ndamp(denCL)\n\ntf=30;\nt=0:.2:tf;\ny=step(numCL,denCL,t);\n\naxis([0 30 0 1.5])\nplot(t,y),grid\nhold on\n\n% discrete designs\n\nT=1;\n[numGz,denGz]=c2dm(numGs,denGs,T,'zoh');\n\nnumDz1=[.389 -.319];\ndenDz1=[1 -.135];\n\nnumDz2=.374*[1 -.85];\ndenDz2=[1 0];\n\nnumz1=conv(numGz,numDz1);\ndenz1=conv(denGz,denDz1);\n\nnumz2=conv(numGz,numDz2);\ndenz2=conv(denGz,denDz2);\n\n[numCLz1,denCLz1]=feedback(numz1,denz1,1,1);\n[numCLz2,denCLz2]=feedback(numz2,denz2,1,1);\n\nddamp(denCLz1,T)\nddamp(denCLz2,T)\n\nN=tf/T+1;\ntd=0:1:tf;\nyd1=dstep(numCLz1,denCLz1,N);\nyd2=dstep(numCLz2,denCLz2,N);\nplot(td,yd1,'-',td,yd1,'*')\nplot(td,yd2,'-',td,yd2,'o')\ntext(10,.55,'----------- continuous design')\ntext(10,.75,'*----*----* discrete equivalent design')\ntext(10,.65,'o----o----o discrete design')\ntitle('Fig. 8.19 Step responses of the various design methods')\nxlabel('Time (sec)')\nylabel('Plant output')\nhold off\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/9907-feedback-control-of-dynamic-systems-fifth-ed/fig8_19.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418158002491, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.7445183875232072}} {"text": "%% OCR of hand-written digits using HoG and SVM\n%\n% In this tutorial, we will build an SVM classifer to recognize\n% hand-written digits (0 to 9), using Histogram of Oriented Gradients (HOG)\n% as feature vectors.\n%\n% For additional resources, see this\n% .\n%\n% Sources:\n%\n% * \n% * \n% * \n%\n\nfunction svm_hog_ocr_digits_demo()\n %% Data\n % Load MNIST handwritten digits (5000 images)\n % (params in this demo are hardcoded assuming 20x20 images)\n [imgs, labels, img] = load_mnist_digits();\n assert(numel(imgs)==5000 && isequal(size(imgs{1}),[20 20]));\n\n %%\n % Show a portion of the big image\n imshow(img(1:350,1:450))\n %imtool(img)\n\n %%\n % Show a sample of an image before and after deskew is applied\n figure\n subplot(121), imshow(imgs{1}), title('original')\n subplot(122), imshow(deskew(imgs{1})), title('deskewed')\n\n %% HoG\n % choose an HoG implementation to use: OpenCV, MATLAB, or a simple custom one\n HOG_ALG = 'opencv';\n HOG_ALG = validatestring(HOG_ALG, {'custom', 'matlab', 'opencv'});\n\n %%\n % HoG features are stored in a matrix, one row per image\n switch HOG_ALG\n case 'custom'\n nbins = 16; % number of bins to quantize gradient angles\n nfeats = 4 * nbins; % feature length\n case 'matlab'\n opts = {'CellSize',[10 10], 'BlockSize',[2 2], ...\n 'NumBins',9, 'UseSignedOrientation',true};\n nfeats = numel(extractHOGFeatures(imgs{1}, opts{:}));\n case 'opencv'\n % create HOG object\n opts = {'WinSize',[20 20], 'BlockSize',[10 10], ...\n 'BlockStride',[5 5], 'CellSize',[10 10], ...\n 'NBins',9, 'SignedGradient',true};\n %opts = [opts, 'GammaCorrection',false];\n hog = cv.HOGDescriptor(opts{:});\n nfeats = numel(hog.compute(imgs{1}));\n display(hog)\n end\n descs = zeros(numel(imgs), nfeats, 'single');\n\n %%\n % Process images and compute HOG descriptors for each\n tic\n disp('Extracting...')\n for i=1:numel(imgs)\n % deskew image\n img = deskew(imgs{i});\n %img = cv.threshold(img, 'Otsu');\n\n % compute HOG descriptors flattened as a vector\n switch HOG_ALG\n case 'custom'\n descs(i,:) = my_hog(img, nbins);\n case 'matlab'\n descs(i,:) = extractHOGFeatures(img, opts{:});\n case 'opencv'\n d = hog.compute(img).'; % returns a matrix, one row per window\n descs(i,:) = d(:);\n end\n end\n toc\n\n %% Classification\n % Create multi-class linear SVM classifier\n svm = cv.SVM();\n svm.Type = 'C_SVC';\n svm.KernelType = 'Linear';\n svm.C = 0.5; % or do a trainAuto grid search to find optimal C\n display(svm)\n\n %%\n % split data samples and corresponding labels\n labels = int32(labels(:));\n N = 2500; % fix(numel(labels)/2)\n whos descs labels\n if ~mexopencv.isOctave() && mexopencv.require('stats')\n % train/test split\n tabulate(labels(1:N))\n tabulate(labels(N+1:end))\n end\n\n %%\n % use half as training data\n tic\n disp('Training...')\n svm.train(descs(1:N,:), labels(1:N));\n toc\n\n %%\n % the other half for testing\n tic\n disp('Testing...')\n yhat = svm.predict(descs(N+1:end,:));\n toc\n %TODO: https://savannah.gnu.org/bugs/?50716\n\n %%\n % performance on test set\n acc = nnz(yhat == labels(N+1:end));\n confmat = accumarray([labels(N+1:end), yhat]+1, 1);\n display(confmat)\n fprintf('Accuracy = %f%%\\n', (acc/N)*100);\n\n %%\n % Show some of the wrong predictions\n idx = (yhat ~= labels(N+1:end));\n fprintf('Number of wrong predictions = %d / %d\\n', nnz(idx), N);\n figure\n idx = find(idx, 3*3, 'first');\n for i=1:numel(idx)\n ii = idx(i);\n subplot(3,3,i), imshow(imgs{ii+N})\n title(sprintf('%d \\\\rightarrow %d', labels(ii+N), yhat(ii)))\n end\nend\n\n%% Helper functions\n\nfunction [imgs, labels, img] = load_mnist_digits()\n % Load MNIST handwritten digits, one big image\n fname = fullfile(mexopencv.root(), 'test', 'digits.png');\n if exist(fname, 'file') ~= 2\n disp('Downloading image...')\n url = 'https://cdn.rawgit.com/opencv/opencv/3.2.0/samples/data/digits.png';\n urlwrite(url, fname);\n end\n img = cv.imread(fname, 'Grayscale',true);\n\n % split it into 5000 small images (500 from each 0:9 digits),\n % each image is 20x20 pixels\n [h,w] = size(img);\n imgs = mat2cell(img, ones(1,50)*h/50, ones(1,100)*w/100);\n imgs = reshape(imgs', 500, [])'; % cell array of size 10x500\n labels = repmat((0:9)', 1, 500); % each row is one digit\nend\n\nfunction img = deskew(img)\n % deskew image using its second order moments\n sz = 20;\n m = cv.moments(img);\n if abs(m.mu02) > 0.2 % 0.01\n skew = m.mu11 / m.mu02;\n M = [1 skew -0.5*sz*skew; 0 1 0];\n img = cv.warpAffine(img, M, 'DSize',[sz sz], 'WarpInverse',true);\n end\nend\n\nfunction histo = my_hog(img, nbins)\n % this is a simplified implementation of HoG descriptors\n % (fixed 10x10 cells, 1 block, no overlapping, no block normalization)\n\n % number of orientation histogram bins\n if nargin < 2, nbins = 16; end\n\n % compute image gradient (its magnitude and direction)\n gx = cv.Sobel(img, 'DDepth','single', 'XOrder',1, 'YOrder',0);\n gy = cv.Sobel(img, 'DDepth','single', 'XOrder',0, 'YOrder',1);\n mag = hypot(gx, gy);\n ang = atan2(gy, gx) + pi; % directions in [0,2*pi] (signed gradient)\n\n % quantize directions into 16 bins\n bins = fix((nbins-1) * ang/(2*pi)) + 1; % bin indices in [1,16] inclusive\n\n % divide 20x20 image into 4 10x10 cells, and in each,\n % accumulate gradient magnitudes inside each direction bin\n % (binned orientations each weighted by its magnitude contribution)\n bb = mat2cell(bins, [10 10], [10 10]);\n mm = mat2cell(mag, [10 10], [10 10]);\n histo = cell(size(bb));\n for i=1:numel(bb)\n H = accumarray(bb{i}(:), mm{i}(:), [nbins 1]);\n if false && any(H)\n % transform histogram to space with Hellinger metric\n H = sqrt(H ./ sum(H));\n H = H ./ norm(H);\n end\n histo{i} = H;\n end\n\n % stack features from cells into one tall vector of length 4*16\n histo = cat(1, histo{:});\nend\n", "meta": {"author": "kyamagu", "repo": "mexopencv", "sha": "d29007b2a484d0fd92e6e941dc5fd4750014fa6a", "save_path": "github-repos/MATLAB/kyamagu-mexopencv", "path": "github-repos/MATLAB/kyamagu-mexopencv/mexopencv-d29007b2a484d0fd92e6e941dc5fd4750014fa6a/samples/svm_hog_ocr_digits_demo.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297887874625, "lm_q2_score": 0.8267117962054048, "lm_q1q2_score": 0.744478599224957}} {"text": "function a = laguerre ( n )\n\n%*****************************************************************************80\n%\n%% LAGUERRE returns the LAGUERRE matrix.\n%\n% Example:\n%\n% N = 8\n%\n% 1 . . . . . . .\n% 1 -1 . . . . . .\n% 2 -4 1 . . . . . / 2\n% 6 -18 9 -1 . . . . / 6\n% 24 -96 72 -16 1 . . . / 24\n% 120 -600 600 -200 25 -1 . . / 120\n% 720 -4320 5400 -2400 450 -36 1 . / 720\n% 5040 -35280 52920 -29400 7350 -882 49 -1 / 5040\n%\n% Properties:\n%\n% A is generally not symmetric: A' /= A.\n%\n% A is lower triangular.\n%\n% The columns of A alternate in sign.\n%\n% A(I,1) = 1\n% A(I,I) = (-1)^(I-1) / (I-1)!.\n%\n% LAMBDA(I) = (-1)^(I-1) / (I-1)!.\n%\n% det ( A ) = product ( 1 <= I <= N ) (-1)^(I-1) / (I-1)!\n%\n% The I-th row contains the coefficients of the Laguerre\n% polynomial of degree I-1.\n%\n% The family of matrices is nested as a function of N.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 23 October 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Milton Abramowitz, Irene Stegun,\n% Handbook of Mathematical Functions,\n% US Department of Commerce, 1964.\n%\n% Parameters:\n%\n% Input, integer N, the order of A.\n%\n% Output, real A(N,N), the matrix.\n%\n a = zeros ( n, n );\n\n if ( n <= 0 )\n a = [];\n return\n end\n\n a(1,1) = 1.0;\n\n if ( n == 1 )\n return\n end\n\n a(2,1) = 1.0;\n a(2,2) = -1.0;\n\n if ( n == 2 )\n return\n end\n\n for i = 3 : n\n for j = 1 : n\n if ( j == 1 )\n a(i,j) = ( ( 2 * i - 3 ) * a(i-1,j) ...\n + ( - i + 2 ) * a(i-2,j) ) ...\n / ( i - 1 );\n else\n a(i,j) = ( ( 2 * i - 3 ) * a(i-1,j) ...\n - ( 1 ) * a(i-1,j-1) ...\n + ( - i + 2 ) * a(i-2,j) ) ...\n / ( i - 1 );\n end\n end\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_mat/laguerre.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297754396141, "lm_q2_score": 0.8267118026095991, "lm_q1q2_score": 0.7444785939573009}} {"text": "% function thetaOpt = StochasticGradientDescent (gradFunc, theta0, maxiter)\n% runs gradient descent until convergence, returning the optimal parameters thetaOpt.\n%\n% Inputs:\n% gradFunc function handle to a function [cost, grad] = gradFunc(theta, i)\n% that computes the LR cost / objective function and the gradient \n% of the negative log likelihood of the ith data instance, given \n% parameters theta.\n% theta0 initial value of theta to start gradient descent from.\n% maxIter number of iterations to run SGD for.\n%\n% Output:\n% thetaOpt optimal value of theta.\n%\n%\n% Note - function handles may be new to some of you. Briefly, function handles\n% are a way of passing a function to another function as an argument. The\n% syntax for calling a function handle is exactly the same as for calling any\n% other function. \n%\n% For more information, refer to the official documentation:\n% Matlab - http://www.mathworks.com/help/techdoc/matlab_prog/f2-38133.html\n% Octave - http://www.gnu.org/software/octave/doc/interpreter/Function-Handles.html\n%\n% Copyright (C) Daphne Koller, Stanford Univerity, 2012\n\n\nfunction thetaOpt = StochasticGradientDescent (gradFunc, theta0, maxIter)\n\n % The grader will accept all answers that are near enough\n % to the optimal value, so don't worry about being off by one \n % iteration etc.\n \n thetaOpt = zeros(size(theta0));\n\n %%%%%%%%%%%%%%\n %%% Student code\n for i = 1:maxIter\n\t [cost, grad] = gradFunc(theta0,i);\n\t theta0 = theta0 - (0.1)*(grad)/(1+sqrt(i));\n end\n thetaOpt = theta0;\n %%%%%%%%%%%\n\nend\n\n", "meta": {"author": "anhncs", "repo": "Probabilistic-Graphical-Models", "sha": "7fd4ef255db59ecbfe1a134cadbc4be5ca839894", "save_path": "github-repos/MATLAB/anhncs-Probabilistic-Graphical-Models", "path": "github-repos/MATLAB/anhncs-Probabilistic-Graphical-Models/Probabilistic-Graphical-Models-7fd4ef255db59ecbfe1a134cadbc4be5ca839894/7.CRF Learning for OCR/StochasticGradientDescent.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297807787537, "lm_q2_score": 0.8267117855317474, "lm_q1q2_score": 0.7444785829921166}} {"text": "function z = mutInfo(x, y)\n% Compute mutual information I(x,y) of two discrete variables x and y.\n% Input:\n% x, y: two integer vector of the same length \n% Output:\n% z: mutual information z=I(x,y)\n% Written by Mo Chen (sth4nth@gmail.com).\nassert(numel(x) == numel(y));\nn = numel(x);\nx = reshape(x,1,n);\ny = reshape(y,1,n);\n\nl = min(min(x),min(y));\nx = x-l+1;\ny = y-l+1;\nk = max(max(x),max(y));\n\nidx = 1:n;\nMx = sparse(idx,x,1,n,k,n);\nMy = sparse(idx,y,1,n,k,n);\nPxy = nonzeros(Mx'*My/n); %joint distribution of x and y\nHxy = -dot(Pxy,log2(Pxy));\n\nPx = nonzeros(mean(Mx,1));\nPy = nonzeros(mean(My,1));\n\n% entropy of Py and Px\nHx = -dot(Px,log2(Px));\nHy = -dot(Py,log2(Py));\n% mutual information\nz = Hx+Hy-Hxy;\nz = max(0,z);", "meta": {"author": "PRML", "repo": "PRMLT", "sha": "baac49f643db6b39e75307d3b21307b32b29a7a9", "save_path": "github-repos/MATLAB/PRML-PRMLT", "path": "github-repos/MATLAB/PRML-PRMLT/PRMLT-baac49f643db6b39e75307d3b21307b32b29a7a9/chapter01/mutInfo.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422213778251, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.7444233239986211}} {"text": "clear; clc;\n\n%% DFT filter bank\nN = 8; % number of subbands\nK = 16; % overlapping factor\nL = 2*K*N; % length of analysis filters\n\nhopt = fir1(L-1,1/N); % prototype filter\n[H,F] = make_bank_DFT(hopt,N);\nH = sqrt(N)*H; % analysis section\nF = sqrt(N)*F; % synthesis section\n\n%% signals in the DFT filter bank\nxn = sin(2*pi*0.01*(0:1000));\nITER = length(xn);\nyn = zeros(ITER,1);\nx = zeros(length(H),1);\nb = zeros(length(F),1);\n\n%% analysis and synthesis filter banks implementation\nfor n = 1:ITER\n x = [xn(n); x(1:end-1)];\n % block transformation is performed once for every N input samples\n if mod(n,N) == 0\n x_D = H.'*x;\n % =====================\n % insert subband processing here\n % =====================\n b = F*x_D + b;\n end\n yn(n) = real(b(1));\n b = [b(2:end); 0];\nend\n\n%% plot input and output signal\nfigure;\nplot(0:length(xn)-1, xn); hold on;\nplot(0:length(yn)-1, yn, 'r:');\nxlabel('Time index, n'); ylabel('Amplitude');\n\n\n%{\n %% plot frequency response\nDFTpoint = 4096;\n[Hz,w] = FreqResp(H, DFTpoint); \nHz = Hz.';\nfigure;\nsubplot(3,1,[1 2]); hold on;\nfor k = 1:N\n if mod(k,2) == 0\n plot(w/pi,20*log10(abs(Hz(k,:))));\n else\n plot(w/pi,20*log10(abs(Hz(k,:))),':');\n end\nend\ntitle('frequency response'); \n%}\n", "meta": {"author": "CharlesThaCat", "repo": "acoustic-interference-cancellation", "sha": "edb394499ea6f9c96445a3e9613bd64a854c289e", "save_path": "github-repos/MATLAB/CharlesThaCat-acoustic-interference-cancellation", "path": "github-repos/MATLAB/CharlesThaCat-acoustic-interference-cancellation/acoustic-interference-cancellation-edb394499ea6f9c96445a3e9613bd64a854c289e/Subband processing/Book/After reading Chapter 2 -- Design Analysis & Synthesis Filter bank/DFTFilterBank.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.918480252950991, "lm_q2_score": 0.8104789178257654, "lm_q1q2_score": 0.7444088814560544}} {"text": "%% runCoordinateDescent.m\n\n% This test file implements the Coordinate Descent solver. The code builds\n% a synthetic formulation of the Phase Retrieval problem, b = |Ax| and\n% computes an estimate to x. The code finally plots a convergence curve\n% and also makes a scatter plot of the true vs recovered solution.\n\n% PAPER TITLE:\n% Coordinate Descent Algorithms for Phase Retrieval\n\n% ARXIV LINK:\n% https://arxiv.org/abs/1706.03474\n\n\n% 1) Each test script starts out by defining the length of the unknown\n% signal, n and the number of measurements, m. These mesurements can be\n% made complex by setting the isComplex flag to be true.\n%\n% 2) We then build the test problem by invoking the function\n% 'buildTestProblem' which generates random gaussian measurements according\n% to the user's choices in step(1). The function returns the measurement \n% matrix 'A', the true signal 'xt' and the measurements 'b0'.\n%\n% 3) We set the options for the PR solver. For example, the maximum\n% number of iterations, the tolerance value, the algorithm and initializer\n% of choice. These options are controlled by setting the corresponding\n% entries in the 'opts' struct. Please see the user guide for a complete \n% list of options.\n%\n% 4) We solve the phase retrieval problem by running the following line \n% of code:\n% >> [x, outs, opts] = solvePhaseRetrieval(A, A', b0, n, opts)\n% This solves the problem using the algorithm and initialization scheme\n% specified by the user in the struct 'opts'.\n%\n% 5) Determine the optimal phase rotation so that the recovered solution\n% matches the true solution as well as possible.\n%\n% 6) Report the relative reconstruction error. Plot residuals (a measure\n% of error) against the number of iterations and plot the real part of the \n% recovered signal against the real part of the original signal.\n\n\n% PhasePack by Rohan Chandra, Ziyuan Zhong, Justin Hontz, Val McCulloch,\n% Christoph Studer, & Tom Goldstein \n% Copyright (c) University of Maryland, 2017\n%% -----------------------------START----------------------------------\n\n\nclc\nclear\nclose all\n\nn = 100; % Dimension of unknown vector\nm = 8 * n; % Number of measurements\nisComplex = true; % If the signal and measurements are complex\n\n%% Build a random test problem\nfprintf('Building test problem...\\n');\n[A, xt, b0] = buildTestProblem(m, n, isComplex);\n\n% Options\nopts = struct;\nopts.initMethod = 'Truncatedspectral';\n% opts.initMethod = 'optimalspectral';\nopts.algorithm = 'CoordinateDescent';\nopts.isComplex = isComplex;\nopts.maxIters = 500000;\nopts.tol = 1e-6;\nopts.verbose = 2;\n\n\n%% Try to recover x\nfprintf('Running algorithm...\\n');\n[x, outs, opts] = solvePhaseRetrieval(A, A', b0, n, opts);\n\n%% Determine the optimal phase rotation so that the recovered solution\n% matches the true solution as well as possible. \nalpha = (x'*xt)/(x'*x);\nx = alpha * x;\n\n%% Determine the relative reconstruction error. If the true signal was \n% recovered, the error should be very small - on the order of the numerical\n% accuracy of the solver.\nreconError = norm(xt-x)/norm(xt);\nfprintf('relative recon error = %d\\n', reconError);\n\n% Plot a graph of error(definition depends on if opts.xt is provided) versus\n% the number of iterations.\nplotErrorConvergence(outs, opts)\n\n% Plot a graph of the recovered signal x against the true signal xt.\nplotRecoveredVSOriginal(x,xt);\n\n\n\n", "meta": {"author": "tomgoldstein", "repo": "phasepack-matlab", "sha": "aac4525b2c53ad2e7005f70ace46b4a1bde4c6d9", "save_path": "github-repos/MATLAB/tomgoldstein-phasepack-matlab", "path": "github-repos/MATLAB/tomgoldstein-phasepack-matlab/phasepack-matlab-aac4525b2c53ad2e7005f70ace46b4a1bde4c6d9/examples/runCoordinateDescent.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9184802440252811, "lm_q2_score": 0.8104789086703225, "lm_q1q2_score": 0.7444088658128613}} {"text": "function pass = test_intops(pref)\n% Test integral operators\n% Toby Driscoll 28 May 2009\n% Nick Hale 6 Jan 2012\n\n% NOTE: Taken from V4 test chebop_intops.\n\nif ( nargin == 0 )\n pref = cheboppref();\nend\ntol = 1e-10;\n\n% From http://en.wikipedia.org/wiki/Integro-differential_equation\nd = [0 5];\nx = chebfun('x', d);\nN = chebop(@(u) diff(u) + 2*u + 5*cumsum(u), d);\nN.bc = @(x,u) u(0);\nu = mldivide(N, 1, pref);\nu_exact = 0.5*exp(-x).*sin(2*x);\nerr(1) = norm(u - u_exact);\n\n% Fredholm\nd = [0, 1];\nx = chebfun(@(x) x, d);\nK = @(x,y) sin(2*pi*(x-y));\nA = chebop(@(x,u) u + fred(K,u), d);\nu = x.*exp(x);\nf = A*u;\nerr(2) = norm(u - mldivide(A, f, pref));\n\n% Volterra\nd = [0, pi];\nx = chebfun(@(x) x, d);\nK = @(x,y) x.*y;\nA = chebop(@(x,u) u - volt(K,u), d);\nf = x.^2.*cos(x) + (1-x).*sin(x);\nu = mldivide(A, f, pref);\nerr(3) = norm( u - sin(x) );\nerr(4) = norm( A*u - f );\n\npass = err < tol;\n\n%%\n% From #2122\nK = @(x,t) exp(t.*(x-t));\nN = chebop(@(x,y) diff(y) + y - x.*(1+2*x).*volt(K, y) - 1 - 2*x);\nN.lbc = 1;\ny = N\\0;\npass(5) = norm(N.op(y)) + abs(y(0)-1);\n\n%%\n% From #2179\nK = @(x,y) exp(-(x-y));\nA = chebop(@(x,u) diff(u) + fred(K,u));\nA.lbc = 0; \nu = A\\1;\npass(6) = norm(A*u - 1, inf) < tol;\n\n%%\n% From https://groups.google.com/forum/#!topic/chebfun-users/0dpsggp1RyA . \n% Also, see #2210.\n\nL = chebop(@(u) diff(u)+sum(u), [0 1]);\nL.lbc = 1; \nu = L\\0;\npass(7) = norm(u - (1- 2*chebfun('x',[0 1])/3), inf) < tol;\n\n%%\n% From #2185 \nA = chebop(@(x,u) diff(u,2) + sin(2*pi*x)*u + sum(u).*u);\nA.bc = 'periodic'; \nu = A\\1;\npass(8) = norm(A*u-1) < tol;\n\nf = chebfun(@(x) sin(5*pi*x));\nK = @(x,y) cos(-pi*(x-y));\nA = chebop(@(x,u) 1/25*diff(u,2) + fred(K, u));\nA.bc = 'periodic'; \nu = A\\f;\npass(9) = norm(A*u-f) < tol;\n\n\n%%\n% From #2360.\nK = @(x,y) 1+0*x;\nN = chebop(@(x,u) - u + exp(x) + 1/3*x*(1-exp(3*x)) + x*volt(K, u^3), [0, 1]);\nu = N\\0;\npass(10) = norm(u-chebfun(@exp, [0 1])) < tol;\n\nend\n\n", "meta": {"author": "chebfun", "repo": "chebfun", "sha": "8c49396a55e46ddd57a1d108c6a8f32e37536d54", "save_path": "github-repos/MATLAB/chebfun-chebfun", "path": "github-repos/MATLAB/chebfun-chebfun/chebfun-8c49396a55e46ddd57a1d108c6a8f32e37536d54/tests/chebop/test_intops.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802440252811, "lm_q2_score": 0.8104789086703225, "lm_q1q2_score": 0.7444088658128613}} {"text": "function K = covMaterniso(d, hyp, x, z, i)\n\n% Matern covariance function with nu = d/2 and isotropic distance measure. For\n% d=1 the function is also known as the exponential covariance function or the \n% Ornstein-Uhlenbeck covariance in 1d. The covariance function is:\n%\n% k(x^p,x^q) = sf^2 * f( sqrt(d)*r ) * exp(-sqrt(d)*r)\n%\n% with f(t)=1 for d=1, f(t)=1+t for d=3 and f(t)=1+t+t\u00b2/3 for d=5.\n% Here r is the distance sqrt((x^p-x^q)'*inv(P)*(x^p-x^q)), P is ell times\n% the unit matrix and sf2 is the signal variance. The hyperparameters are:\n%\n% hyp = [ log(ell)\n% log(sf) ]\n%\n% Copyright (c) by Carl Edward Rasmussen and Hannes Nickisch, 2010-09-10.\n%\n% See also COVFUNCTIONS.M.\n\nif nargin<3, K = '2'; return; end % report number of parameters\nif nargin<4, z = []; end % make sure, z exists\nxeqz = isempty(z); dg = strcmp(z,'diag'); % determine mode\n\nell = exp(hyp(1));\nsf2 = exp(2*hyp(2));\nif all(d~=[1,3,5]), error('only 1, 3 and 5 allowed for d'), end % degree\n\nswitch d\n case 1, f = @(t) 1; df = @(t) 1; % df(t) = f(t)-f'(t)\n case 3, f = @(t) 1 + t; df = @(t) t;\n case 5, f = @(t) 1 + t.*(1+t/3); df = @(t) t.*(1+t)/3;\nend\n m = @(t,f) f(t).*exp(-t); dm = @(t,f) df(t).*exp(-t).*t;\n\n% precompute distances\nif dg % vector kxx\n K = zeros(size(x,1),1);\nelse\n if xeqz % symmetric matrix Kxx\n K = sq_dist(sqrt(d)/ell*x');\n else % cross covariances Kxz\n K = sq_dist(sqrt(d)/ell*x',sqrt(d)/ell*z');\n end\nend\n\nif nargin<5 % covariances\n K = sf2*m(sqrt(K),f);\nelse % derivatives\n if i==1\n K = sf2*dm(sqrt(K),f);\n elseif i==2\n K = 2*sf2*m(sqrt(K),f);\n else\n error('Unknown hyperparameter')\n end\nend", "meta": {"author": "benfulcher", "repo": "hctsa", "sha": "919f2aed7cc8e1a3a03304c1ade573fa664c73f8", "save_path": "github-repos/MATLAB/benfulcher-hctsa", "path": "github-repos/MATLAB/benfulcher-hctsa/hctsa-919f2aed7cc8e1a3a03304c1ade573fa664c73f8/Toolboxes/gpml/cov/covMaterniso.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802395624257, "lm_q2_score": 0.8104789086703225, "lm_q1q2_score": 0.7444088621958111}} {"text": "function p = mvnormpdfln(x, m, S, V)\n% MVNORMPDFLN log of multivariate normal density.\n% See MVNORMPDF for argument description.\n\nlog2pi = 1.83787706640935;\n[d, n] = size(x);\nif nargin == 1\n dx = x;\nelseif isempty(m)\n dx = x;\nelse\n % m specified\n sz = size(m);\n if sz(1) ~= d\n error('rows(m) ~= rows(x)')\n end\n nm = sz(2);\n if nm == 1\n dx = x - repmat(m,1,n);\n elseif n == 1\n dx = repmat(x,1,nm) - m;\n elseif nm == n\n dx = x - m;\n else\n error('incompatible number of columns in x and m')\n end\nend\nif nargin < 3\n % unit variance\n p = -0.5*(d*log2pi + col_sum(dx.*dx));\n return\nend\nhave_inv = 0;\nif nargin == 3\n % standard deviation given\n if d == 1\n dx = dx./S;\n p = (-log(S) -0.5*log2pi) - 0.5*(dx.*dx);\n return;\n end\n if S(2,1) ~= 0\n error('S is not upper triangular')\n end\n if any(size(S) ~= [d d])\n error('S is not the right size')\n end\nelse\n if ischar(V)\n if strcmp(V,'inv')\n % inverse stddev given\n iS = S;\n have_inv = 1;\n else\n error('unknown directive')\n end\n elseif ischar(S) \n if strcmp(S,'inv')\n % inverse variance given\n if d == 1\n\tiS = sqrt(V);\n else\n\tiS = chol(V);\n end\n have_inv = 1;\n else\n error('unknown directive')\n end\n else\n % variance given\n if d == 1\n S = sqrt(V);\n else\n S = chol(V);\n end\n end\nend\nif have_inv\n if d == 1\n dx = iS .* dx;\n logdetiS = log(iS);\n else\n dx = iS*dx;\n logdetiS = sum(log(diag(iS)));\n end\nelse\n if d == 1\n dx = dx./S;\n logdetiS = -log(S);\n else\n dx = solve_tril(S',dx);\n %dx = S'\\dx;\n logdetiS = -sum(log(diag(S)));\n end\nend\np = (logdetiS -0.5*d*log2pi) -0.5*col_sum(dx.*dx);\n", "meta": {"author": "andrewssobral", "repo": "lrslibrary", "sha": "06d457349cb5f1fc56a583cd61af9f1d5150e3a1", "save_path": "github-repos/MATLAB/andrewssobral-lrslibrary", "path": "github-repos/MATLAB/andrewssobral-lrslibrary/lrslibrary-06d457349cb5f1fc56a583cd61af9f1d5150e3a1/libs/+lightspeed/mvnormpdfln.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802350995702, "lm_q2_score": 0.8104789109591832, "lm_q1q2_score": 0.7444088606810343}} {"text": "% Local Regression and Likelihood, Figure 6.1.\n%\n% Derivative (local slope) estimation, for the Old Faithful Geyser Data.\n% The 'deriv' argument specifies derivative estimation,\n% 'deriv',1 First-order derivative.\n% 'deriv',[1 1] Second-order derivative.\n% 'deriv',2 For bivariate fits, partial deriv. wrt second variable.\n% 'deriv',[1 2] Mixed second-order derivative.\n%\n% Density estimation is done on the log-scale. That is, the estimate\n% is of g(x) = log(f(x)), where f(x) is the density.\n%\n% The relation between derivatives is therefore\n% f'(x) = f(x)g'(x) = g'(x)exp(g(x)).\n% To estimate f'(x), we must estimate g(x) and g'(x) (fit1 and fit2 below),\n% evaluate on a grid of points (p1 and p2), and apply the back-transformation.\n%\n% Disclaimer: I don't consider derivative estimation from noisy data\n% to be a well-defined problem. Use at your own risk.\n%\n% Author: Catherine Loader\n%\n% NEED: m argument passed to lfmarg().\n\nload geyser;\nfit1 = locfit(geyser,'alpha',[0.1 0.6],'ll',1,'ur',6);\nfit2 = locfit(geyser,'alpha',[0.1 0.6],'ll',1,'ur',6,'deriv',1);\nz = lfmarg(fit1);\np1 = predict(fit1,z);\np2 = predict(fit2,z);\nfigure('Name','fig6_1: slope estimation: Old faithful data' );\nplot(z{1},p2.*exp(p1));\nxlabel('Eruption Duration (Minutes)');\nylabel('Density Derivative');\n", "meta": {"author": "buzsakilab", "repo": "buzcode", "sha": "2d700a38b3c2a860ad1333be90f14d7a37a72815", "save_path": "github-repos/MATLAB/buzsakilab-buzcode", "path": "github-repos/MATLAB/buzsakilab-buzcode/buzcode-2d700a38b3c2a860ad1333be90f14d7a37a72815/externalPackages/chronux_2_12/locfit/Book/fig6_1.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802395624257, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.7444088579912643}} {"text": "function pyramid_exactness ( quad_filename, degree_max )\n\n%*****************************************************************************80\n%\n%% MAIN is the main program for PYRAMID_EXACTNESS.\n%\n% Discussion:\n%\n% This program investigates the polynomial exactness of a quadrature\n% rule for the pyramid.\n%\n% The integration region is:\n% \n% - ( 1 - Z ) <= X <= 1 - Z\n% - ( 1 - Z ) <= Y <= 1 - Z\n% 0 <= Z <= 1.\n%\n% When Z is zero, the integration region is a square lying in the (X,Y) \n% plane, centered at (0,0,0) with \"radius\" 1. As Z increases to 1, the \n% radius of the square diminishes, and when Z reaches 1, the square has \n% contracted to the single point (0,0,1).\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 28 July 2009\n%\n% Author:\n%\n% John Burkardt\n%\n timestamp ( );\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'PYRAMID_EXACTNESS\\n' );\n fprintf ( 1, ' MATLAB version\\n' );\n fprintf ( 1, ' Investigate the polynomial exactness of\\n' );\n fprintf ( 1, ' a quadrature rule for the pyramid.\\n' );\n%\n% Get the quadrature file root name:\n%\n if ( 1 <= nargin )\n\n else\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'PYRAMID_EXACTNESS:\\n' );\n\n quad_filename = input ( ' Enter the \"root\" name of the quadrature files.' );\n\n end\n%\n% Create the names of:\n% the quadrature X file;\n% the quadrature W file;\n%\n quad_x_filename = strcat ( quad_filename, '_x.txt' );\n quad_w_filename = strcat ( quad_filename, '_w.txt' );\n%\n% The second command line argument is the maximum degree.\n%\n if ( 2 <= nargin )\n\n else\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'PYRAMID_EXACTNESS:\\n' );\n\n degree_max = input ( ' Please enter the maximum total degree to check.' );\n\n end\n%\n% Summarize the input.\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'PYRAMID_EXACTNESS: User input:\\n' );\n fprintf ( 1, ' Quadrature rule X file = \"%s\".\\n', quad_x_filename );\n fprintf ( 1, ' Quadrature rule W file = \"%s\".\\n', quad_w_filename );\n fprintf ( 1, ' Maximum total degree to check = %d', degree_max );\n%\n% Read the X file.\n%\n [ dim_num, order ] = r8mat_header_read ( quad_x_filename );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Spatial dimension = %d\\n', dim_num );\n fprintf ( 1, ' Number of points = %d\\n', order );\n\n if ( dim_num ~= 3 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'PYRAMID_EXACTNESS - Fatal error!\\n' );\n fprintf ( 1, ' The quadrature abscissas must be 3 dimensional.\\n' );\n error ( 'PYRAMID_EXACTNESS - Fatal error!' );\n end\n\n x = r8mat_data_read ( quad_x_filename, dim_num, order );\n%\n% Read the W file.\n%\n [ dim_num2, order2 ] = r8mat_header_read ( quad_w_filename );\n\n if ( dim_num2 ~= 1 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'PYRAMID_EXACTNESS - Fatal error!\\n' );\n fprintf ( 1, ' The quadrature weight file should have exactly\\n');\n fprintf ( 1, ' one value on each line.\\n' );\n error ( 'PYRAMID_EXACTNESS - Fatal error!' );\n end\n\n if ( order2 ~= order )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'PYRAMID_EXACTNESS - Fatal error!\\n' );\n fprintf ( 1, ' The quadrature weight file should have exactly\\n' );\n fprintf ( 1, ' the same number of lines as the abscissa file.\\n' );\n error ( 'PYRAMID_EXACTNESS - Fatal error!' );\n end\n\n w = r8mat_data_read ( quad_w_filename, 1, order );\n%\n% Explore the monomials.\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Error Degree Exponents\\n' );\n fprintf ( 1, '\\n' );\n\n for degree = 0 : degree_max\n\n expon = [];\n more = 0;\n h = 0;\n t = 0;\n\n while ( 1 )\n\n [ expon, more, h, t ] = comp_next ( degree, dim_num, expon, more, h, t );\n\n v = monomial_value ( dim_num, order, expon, x );\n\n quad = pyra_unit_volume ( ) * w(1:order) * v(1:order)';\n\n exact = pyra_unit_monomial ( expon );\n\n quad_error = abs ( quad - exact );\n\n fprintf ( 1, ' %24.16f %2d ', quad_error, degree );\n for dim = 1 : dim_num\n fprintf ( 1, '%3d', expon(dim) );\n end\n fprintf ( 1, '\\n' );\n\n if ( ~more )\n break\n end\n\n end\n\n fprintf ( 1, '\\n' );\n\n end\n%\n% Terminate.\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'PYRAMID_EXACTNESS:\\n' );\n fprintf ( 1, ' Normal end of execution.\\n' );\n fprintf ( 1, '\\n' );\n timestamp ( );\n\n return\nend\nfunction [ a, more, h, t ] = comp_next ( n, k, a, more, h, t )\n\n%*****************************************************************************80\n%\n%% COMP_NEXT computes the compositions of the integer N into K parts.\n%\n% Discussion:\n%\n% A composition of the integer N into K parts is an ordered sequence\n% of K nonnegative integers which sum to N. The compositions (1,2,1)\n% and (1,1,2) are considered to be distinct.\n%\n% The routine computes one composition on each call until there are no more.\n% For instance, one composition of 6 into 3 parts is\n% 3+2+1, another would be 6+0+0.\n%\n% On the first call to this routine, set MORE = FALSE. The routine\n% will compute the first element in the sequence of compositions, and\n% return it, as well as setting MORE = TRUE. If more compositions\n% are desired, call again, and again. Each time, the routine will\n% return with a new composition.\n%\n% However, when the LAST composition in the sequence is computed \n% and returned, the routine will reset MORE to FALSE, signaling that\n% the end of the sequence has been reached.\n%\n% This routine originally used a SAVE statement to maintain the\n% variables H and T. I have decided that it is safer\n% to pass these variables as arguments, even though the user should\n% never alter them. This allows this routine to safely shuffle\n% between several ongoing calculations.\n%\n% There are 28 compositions of 6 into three parts. This routine will\n% produce those compositions in the following order:\n%\n% I A\n% - ---------\n% 1 6 0 0\n% 2 5 1 0\n% 3 4 2 0\n% 4 3 3 0\n% 5 2 4 0\n% 6 1 5 0\n% 7 0 6 0\n% 8 5 0 1\n% 9 4 1 1\n% 10 3 2 1\n% 11 2 3 1\n% 12 1 4 1\n% 13 0 5 1\n% 14 4 0 2\n% 15 3 1 2\n% 16 2 2 2\n% 17 1 3 2\n% 18 0 4 2\n% 19 3 0 3\n% 20 2 1 3\n% 21 1 2 3\n% 22 0 3 3\n% 23 2 0 4\n% 24 1 1 4\n% 25 0 2 4\n% 26 1 0 5\n% 27 0 1 5\n% 28 0 0 6\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 02 July 2008\n%\n% Author:\n%\n% FORTRAN77 original version by Albert Nijenhuis and Herbert Wilf\n% MATLAB version by John Burkardt.\n%\n% Reference:\n%\n% Albert Nijenhuis, Herbert Wilf,\n% Combinatorial Algorithms for Computers and Calculators,\n% Second Edition,\n% Academic Press, 1978,\n% ISBN: 0-12-519260-6,\n% LC: QA164.N54.\n%\n% Parameters:\n%\n% Input, integer N, the integer whose compositions are desired.\n%\n% Input, integer K, the number of parts in the composition.\n%\n% Input, integer A(K), the previous composition. On the first call,\n% with MORE = FALSE, set A = []. Thereafter, A should be the \n% value of A output from the previous call.\n%\n% Input, logical MORE. The input value of MORE on the first\n% call should be FALSE, which tells the program to initialize.\n% On subsequent calls, MORE should be TRUE, or simply the\n% output value of MORE from the previous call.\n%\n% Input, integer H, T, two internal parameters needed for the\n% computation. The user may need to initialize these before the\n% very first call, but these initial values are not important.\n% The user should not alter these parameters once the computation\n% begins.\n%\n% Output, integer A(K), the next composition.\n%\n% Output, logical MORE, will be TRUE unless the composition \n% that is being returned is the final one in the sequence.\n%\n% Output, integer H, T, the updated values of the two internal \n% parameters.\n%\n if ( ~more )\n\n t = n;\n h = 0;\n a(1) = n;\n a(2:k) = 0;\n\n else\n \n if ( 1 < t )\n h = 0;\n end\n\n h = h + 1;\n t = a(h);\n a(h) = 0;\n a(1) = t - 1;\n a(h+1) = a(h+1) + 1;\n\n end\n\n more = ( a(k) ~= n );\n\n return\nend\nfunction column_num = file_column_count ( input_file_name )\n\n%*****************************************************************************80\n%\n%% FILE_COLUMN_COUNT counts the columns in the first line of a file.\n%\n% Discussion:\n%\n% The file is assumed to be a simple text file.\n%\n% Most lines of the file are presumed to consist of COLUMN_NUM words,\n% separated by spaces. There may also be some blank lines, and some \n% comment lines, which have a \"#\" in column 1.\n%\n% The routine tries to find the first non-comment non-blank line and\n% counts the number of words in that line.\n%\n% If all lines are blanks or comments, it goes back and tries to analyze\n% a comment line.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 21 February 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, string INPUT_FILE_NAME, the name of the file.\n%\n% Output, integer COLUMN_NUM, the number of columns in the file.\n%\n FALSE = 0;\n TRUE = 1;\n%\n% Open the file.\n%\n input_unit = fopen ( input_file_name );\n\n if ( input_unit < 0 ) \n fprintf ( 1, '\\n' );\n fprintf ( 1, 'FILE_COLUMN_COUNT - Error!\\n' );\n fprintf ( 1, ' Could not open the file \"%s\".\\n', input_file_name );\n error ( 'FILE_COLUMN_COUNT - Error!' );\n end\n%\n% Read one line, but skip blank lines and comment lines.\n% Use FGETL so we drop the newline character!\n%\n got_one = FALSE;\n\n while ( 1 )\n\n line = fgetl ( input_unit );\n\n if ( line == -1 )\n break;\n end\n\n if ( s_len_trim ( line ) == 0 )\n\n elseif ( line(1) == '#' )\n\n else\n got_one = TRUE;\n break;\n end\n\n end\n\n fclose ( input_unit );\n\n if ( got_one == FALSE ) \n fprintf ( 1, '\\n' );\n fprintf ( 1, 'FILE_COLUMN_COUNT - Warning!\\n' );\n fprintf ( 1, ' The file does not seem to contain any data.\\n' );\n column_num = -1;\n return;\n end\n\n column_num = s_word_count ( line );\n\n return\nend\nfunction row_num = file_row_count ( input_file_name )\n\n%*****************************************************************************80\n%\n%% FILE_ROW_COUNT counts the number of row records in a file.\n%\n% Discussion:\n%\n% Each input line is a \"RECORD\".\n%\n% The records are divided into three groups:\n% \n% * BLANK LINES (nothing but blanks)\n% * COMMENT LINES (begin with a '#')\n% * DATA RECORDS (anything else)\n%\n% The value returned by the function is the number of data records.\n%\n% By the way, if the MATLAB routine FGETS is used, instead of\n% FGETL, then the variable LINE will include line termination \n% characters, which means that a blank line would not actually\n% have zero characters.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 31 December 2006\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, string INPUT_FILE_NAME, the name of the input file.\n%\n% Output, integer ROW_NUM, the number of rows found. \n%\n input_unit = fopen ( input_file_name );\n\n if ( input_unit < 0 ) \n fprintf ( 1, '\\n' );\n fprintf ( 1, 'FILE_ROW_COUNT - Error!\\n' );\n fprintf ( 1, ' Could not open the file \"%s\".\\n', input_file_name );\n error ( 'FILE_ROW_COUNT - Error!' );\n end\n\n blank_num = 0;\n comment_num = 0;\n row_num = 0;\n \n record_num = 0;\n\n while ( 1 )\n\n line = fgetl ( input_unit );\n\n if ( line == -1 )\n break;\n end\n\n record_num = record_num + 1;\n record_length = s_len_trim ( line );\n \n if ( record_length <= 0 )\n blank_num = blank_num + 1;\n elseif ( line(1) == '#' )\n comment_num = comment_num + 1;\n else\n row_num = row_num + 1;\n end\n\n end\n\n fclose ( input_unit );\n\n return\nend\nfunction value = monomial_value ( dim_num, point_num, expon, x )\n\n%*****************************************************************************80\n%\n%% MONOMIAL_VALUE evaluates a monomial.\n%\n% Discussion:\n%\n% This routine evaluates a monomial of the form\n%\n% product ( 1 <= dim <= dim_num ) x(dim)^expon(dim)\n%\n% where the exponents are nonnegative integers. Note that\n% if the combination 0^0 is encountered, it should be treated\n% as 1.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 05 May 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer DIM_NUM, the spatial dimension.\n%\n% Input, integer POINT_NUM, the number of points at which the\n% monomial is to be evaluated.\n%\n% Input, integer EXPON(DIM_NUM), the exponents.\n%\n% Input, real X(DIM_NUM,POINT_NUM), the point coordinates.\n%\n% Output, real VALUE(POINT_NUM), the value of the monomial.\n%\n value(1:point_num) = 1.0;\n\n for dim = 1 : dim_num\n if ( 0 ~= expon(dim) )\n value(1:point_num) = value(1:point_num) .* x(dim,1:point_num).^expon(dim);\n end\n end\n\n return\nend\nfunction value = pyra_unit_monomial ( expon )\n\n%*****************************************************************************80\n%\n%% PYRA_UNIT_MONOMIAL: monomial integral in a unit pyramid.\n%\n% Discussion:\n%\n% This routine returns the integral of\n%\n% product ( 1 <= I <= 3 ) X(I)^EXPON(I)\n%\n% over the unit pyramid.\n%\n% The unit pyramid is defined as:\n%\n% - ( 1 - Z ) <= X <= 1 - Z\n% - ( 1 - Z ) <= Y <= 1 - Z\n% 0 <= Z <= 1.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 12 April 2008\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Arthur Stroud,\n% Approximate Calculation of Multiple Integrals,\n% Prentice Hall, 1971,\n% ISBN: 0130438936,\n% LC: QA311.S85.\n%\n% Parameters:\n%\n% Input, integer EXPON(3), the exponents.\n%\n% Output, real VALUE, the integral of the monomial.\n%\n value = 0.0;\n\n if ( mod ( expon(1), 2 ) == 0 && mod ( expon(2), 2 ) == 0 )\n\n i_hi = 2 + expon(1) + expon(2);\n\n for i = 0 : i_hi\n value = value + r8_mop ( i ) * r8_choose ( i_hi, i ) / ( i + expon(3) + 1 );\n end\n\n value = value * 2.0 / ( expon(1) + 1 ) * 2.0 / ( expon(2) + 1 );\n\n end\n\n return\nend\nfunction value = pyra_unit_volume ( )\n\n%*****************************************************************************80\n%\n%% PYRA_UNIT_VOLUME_3D returns the volume of a unit pyramid.\n%\n% Discussion:\n%\n% A pyramid with square base can be regarded as the upper half of a\n% 3D octahedron.\n%\n% The integration region:\n%\n% - ( 1 - Z ) <= X <= 1 - Z\n% - ( 1 - Z ) <= Y <= 1 - Z\n% 0 <= Z <= 1.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 31 March 2008\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Output, real VALUE, the volume of the pyramid.\n%\n value = 4.0 / 3.0;\n\n return\nend\nfunction value = r8_choose ( n, k )\n\n%*****************************************************************************80\n%\n%% R8_CHOOSE computes the binomial coefficient C(N,K).\n%\n% Discussion:\n%\n% The value is calculated in such a way as to avoid overflow and\n% roundoff. The calculation is done in integer arithmetic.\n%\n% The formula used is:\n%\n% C(N,K) = N! / ( K! * (N-K)! )\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 31 March\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% ML Wolfson, HV Wright,\n% Algorithm 160:\n% Combinatorial of M Things Taken N at a Time,\n% Communications of the ACM,\n% Volume 6, Number 4, April 1963, page 161.\n%\n% Parameters:\n%\n% Input, integer N, K, are the values of N and K.\n%\n% Output, real VALUE, the number of combinations of N\n% things taken K at a time.\n%\n mn = min ( k, n - k );\n\n if ( mn < 0 )\n value = 0;\n elseif ( mn == 0 )\n value = 1;\n else\n mx = max ( k, n - k );\n value = mx + 1;\n for i = 2 : mn\n value = ( value * ( mx + i ) ) / i;\n end\n end\n\n return\nend\nfunction value = r8_mop ( i )\n\n%*****************************************************************************80\n%\n%% R8_MOP returns the I-th power of -1 as an R8 value.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 07 November 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer I, the power of -1.\n%\n% Output, real R8_MOP, the I-th power of -1.\n%\n if ( mod ( i, 2 ) == 0 )\n value = + 1.0;\n else\n value = - 1.0;\n end\n\n return\nend\nfunction table = r8mat_data_read ( input_filename, m, n )\n\n%*****************************************************************************80\n%\n%% R8MAT_DATA_READ reads data from an R8MAT file.\n%\n% Discussion:\n%\n% An R8MAT is an array of R8's.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 27 January 2006\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, string INPUT_FILENAME, the name of the input file.\n%\n% Input, integer M, N, the number of rows and columns of data.\n%\n% Output, real TABLE(M,N), the point coordinates.\n%\n table = zeros ( m, n );\n%\n% Build up the format string for reading M real numbers.\n%\n string = ' ';\n\n for i = 0 : m\n string = strcat ( string, ' %f' );\n end\n\n input_unit = fopen ( input_filename );\n\n if ( input_unit < 0 ) \n fprintf ( 1, '\\n' );\n fprintf ( 1, 'R8MAT_DATA_READ - Error!\\n' );\n fprintf ( 1, ' Could not open the file.\\n' );\n error ( 'R8MAT_DATA_READ - Error!' );\n end\n\n i = 0;\n\n while ( i < n )\n\n line = fgets ( input_unit );\n\n if ( line == -1 )\n break;\n end\n\n if ( line(1) == '#' )\n\n elseif ( s_len_trim ( line ) == 0 )\n \n else\n\n [ x, count ] = sscanf ( line, string );\n\n if ( count == m )\n i = i + 1;\n table(1:m,i) = x(1:m);\n end\n\n end\n\n end\n\n fclose ( input_unit );\n\n return\nend\nfunction [ m, n ] = r8mat_header_read ( input_filename )\n\n%*****************************************************************************80\n%\n%% R8MAT_HEADER_READ reads the header from an R8MAT file.\n%\n% Discussion:\n%\n% An R8MAT is an array of R8's.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 22 October 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, string INPUT_FILENAME, the name of the input file.\n%\n% Output, integer M, the spatial dimension.\n%\n% Output, integer N, the number of points.\n%\n m = file_column_count ( input_filename );\n\n if ( m <= 0 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'R8MAT_HEADER_READ - Fatal error!\\n' );\n fprintf ( 1, ' There was some kind of I/O problem while trying\\n' );\n fprintf ( 1, ' to count the number of data columns in\\n' );\n fprintf ( 1, ' the file %s.\\n', input_filename );\n end\n\n n = file_row_count ( input_filename );\n\n if ( n <= 0 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'R8MAT_HEADER_READ - Fatal error!\\n' );\n fprintf ( 1, ' There was some kind of I/O problem while trying\\n' );\n fprintf ( 1, ' to count the number of data rows in\\n' );\n fprintf ( 1, ' the file %s\\n', input_filename );\n end\n\n return\nend\nfunction len = s_len_trim ( s )\n\n%*****************************************************************************80\n%\n%% S_LEN_TRIM returns the length of a character string to the last nonblank.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 14 June 2003\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, string S, the string to be measured.\n%\n% Output, integer LEN, the length of the string up to the last nonblank.\n%\n len = length ( s );\n\n while ( 0 < len )\n if ( s(len) ~= ' ' )\n return\n end\n len = len - 1;\n end\n\n return\nend\nfunction word_num = s_word_count ( s )\n\n%*****************************************************************************80\n%\n%% S_WORD_COUNT counts the number of \"words\" in a string.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 30 January 2006\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, string S, the string to be examined.\n%\n% Output, integer WORD_NUM, the number of \"words\" in the string.\n% Words are presumed to be separated by one or more blanks.\n%\n FALSE = 0;\n TRUE = 1;\n\n word_num = 0;\n s_length = length ( s );\n\n if ( s_length <= 0 )\n return;\n end\n\n blank = TRUE;\n\n for i = 1 : s_length\n\n if ( s(i) == ' ' )\n blank = TRUE;\n elseif ( blank == TRUE )\n word_num = word_num + 1;\n blank = FALSE;\n end\n\n end\n\n return\nend\nfunction timestamp ( )\n\n%*****************************************************************************80\n%\n%% TIMESTAMP prints the current YMDHMS date as a timestamp.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 19 April 2009\n%\n% Author:\n%\n% John Burkardt\n%\n t = now;\n c = datevec ( t );\n s = datestr ( c, 0 );\n fprintf ( 1, '%s\\n', s );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/pyramid_exactness/pyramid_exactness.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802373309982, "lm_q2_score": 0.8104788995148792, "lm_q1q2_score": 0.7444088519781924}} {"text": "nj = 10000;\nms = 210;\nmt = 210;\n\nxj = sort((rand(nj,1)*2-1)*pi);\nyj = sort((rand(nj,1)*2-1)*pi);\ncj = randn(nj,1)+1i*randn(nj,1);\n\neps=1e-12;\n\n\niflag = +1;\n\ntic\nfk = dirft2d1(nj,xj,yj,cj,iflag,ms,mt);\ntoc\n\ntic\nfk1 = nufft2d1(nj,xj,yj,cj,iflag,eps,ms,mt);\ntoc\n\nabs_error=norm(fk-fk1,2)\nrel_error=norm(fk-fk1,2)/norm(fk,2)\n\n\niflag = -1;\n\ntic\nfk = dirft2d1(nj,xj,yj,cj,iflag,ms,mt);\ntoc\n\ntic\nfk1 = nufft2d1(nj,xj,yj,cj,iflag,eps,ms,mt);\ntoc\n\nabs_error=norm(fk-fk1,2)\nrel_error=norm(fk-fk1,2)/norm(fk,2)\n", "meta": {"author": "SwanLab", "repo": "Swan", "sha": "f8355f3561bb1a1603f56b3676873147d22a511e", "save_path": "github-repos/MATLAB/SwanLab-Swan", "path": "github-repos/MATLAB/SwanLab-Swan/Swan-f8355f3561bb1a1603f56b3676873147d22a511e/gypsilabModified/openEbd/libGgNufft2D/test_2d1.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541643004809, "lm_q2_score": 0.7905303112671295, "lm_q1q2_score": 0.7444061596104479}} {"text": "function y = gaussian_response(rect_size, sigma)\n%GAUSSIAN_RESPONSE create the (fixed) target response of the correlation filter response\n [i1, i2] = circ_grid(rect_size(1), rect_size(2));\n y = exp(-(i1.^2 + i2.^2) / (2 * sigma^2));\nend\n", "meta": {"author": "bertinetto", "repo": "cfnet", "sha": "971e7922b7f0f9140e0d995b598e8d97dece277c", "save_path": "github-repos/MATLAB/bertinetto-cfnet", "path": "github-repos/MATLAB/bertinetto-cfnet/cfnet-971e7922b7f0f9140e0d995b598e8d97dece277c/src/util/gaussian_response.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9643214450208031, "lm_q2_score": 0.7718434873426302, "lm_q1q2_score": 0.744305227044141}} {"text": "function loglik = RicianLogLik(meas, signals, sig)\n% Computes the log likelihood of the measurements given the model signals\n% for the Rician noise model.\n%\n% loglik = RicianLogLik(meas, signals, sig) returns the likelihood of\n% measuring meas given the signals and the noise standard deviation sig. \n%\n% meas are the measurements\n%\n% signals are computed from a model\n%\n% sig is the standard deviation of the Gaussian distributions underlying\n% the Rician distribution.\n%\n% author: Daniel C Alexander (d.alexander@ucl.ac.uk)\n%\n\nsumsqsc = (signals.^2 + meas.^2)./(2*sig.^2);\nscp = meas.*signals./(sig.^2);\nlb0 = logbesseli0(scp);\nlogliks = - 2*log(sig) - sumsqsc + log(signals) + lb0;\nloglik = sum(logliks);\n", "meta": {"author": "qMRLab", "repo": "qMRLab", "sha": "036ff20b47e939877f746940a969494b55911636", "save_path": "github-repos/MATLAB/qMRLab-qMRLab", "path": "github-repos/MATLAB/qMRLab-qMRLab/qMRLab-036ff20b47e939877f746940a969494b55911636/External/NODDI_toolbox_v1.0/models/RicianLogLik.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533126145178, "lm_q2_score": 0.798186775339273, "lm_q1q2_score": 0.7442719027502049}} {"text": "function N = nees(x,m,P)\n\n% NEES Normalized Estimation Error Squared.\n% N = NEES(X,M,P) computes the Normalized Estimation Error Squared given\n% true state X and a Gaussian estimate of mean M and covariance P:\n%\n% NEES = (X-M)'*inv(P)*(X-M);\n%\n% See also MAHALANOBIS.\n\n% Copyright 2008-2009 Joan Sola @ LAAS-CNRS.\n\nN = (x-m)'/P*(x-m);\n\n\n\n% ========== End of function - Start GPL license ==========\n\n\n% # START GPL LICENSE\n\n%---------------------------------------------------------------------\n%\n% This file is part of SLAMTB, a SLAM toolbox for Matlab.\n%\n% SLAMTB is free software: you can redistribute it and/or modify\n% it under the terms of the GNU General Public License as published by\n% the Free Software Foundation, either version 3 of the License, or\n% (at your option) any later version.\n%\n% SLAMTB is distributed in the hope that it will be useful,\n% but WITHOUT ANY WARRANTY; without even the implied warranty of\n% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n% GNU General Public License for more details.\n%\n% You should have received a copy of the GNU General Public License\n% along with SLAMTB. If not, see .\n%\n%---------------------------------------------------------------------\n\n% SLAMTB is Copyright:\n% Copyright (c) 2008-2010, Joan Sola @ LAAS-CNRS,\n% Copyright (c) 2010-2013, Joan Sola,\n% Copyright (c) 2014-2015, Joan Sola @ IRI-UPC-CSIC,\n% SLAMTB is Copyright 2009 \n% by Joan Sola, Teresa Vidal-Calleja, David Marquez and Jean Marie Codol\n% @ LAAS-CNRS.\n% See on top of this file for its particular copyright.\n\n% # END GPL LICENSE\n\n", "meta": {"author": "joansola", "repo": "slamtb", "sha": "b4767f6bf38bceed205abb85f1aed12422c9a972", "save_path": "github-repos/MATLAB/joansola-slamtb", "path": "github-repos/MATLAB/joansola-slamtb/slamtb-b4767f6bf38bceed205abb85f1aed12422c9a972/Math/nees.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533126145178, "lm_q2_score": 0.7981867681382279, "lm_q1q2_score": 0.7442718960355666}} {"text": "% This demo compares exponential vs hyperbolic temporal discounting.\n% This script simulates an agent making choices between two options, which\n% differ in terms of the expected reward and temporal horizons, under both\n% an hyperbolic and an exponantial temporal discounting model.\n% The choice data are then inverted using these two models. NB: in both\n% models, the discount factor and the behavioural temperature are unknown.\n% The effect of simulating the data under each model onto the log-Bayes\n% factor (comparison between hyperbolic vs exponential models) is assessed\n% using Monte-Carlo simulations. \n\nclear all\nclose all\n\nmodels = {'hyperbolic','exponential'};\n\n% initialize simulations\nntrials = 128;\ng_fname = @g_discounting;\nphi = [1;-1];\nin.ind.logk = 1; % index of discount factor (phi)\nin.ind.logb = 2; % index of behavioural temperature (phi)\nin.ind.t = [1;3]; % index of temporal horizon (u)\nin.ind.R = [2;4]; % index of expected reward (u)\n\n\n\n% Build options and dim structures for model inversion\ndim.n_theta = 0;\ndim.n_phi = 2;\ndim.n = 0;\ndim.p = 1;\ndim.n_t = ntrials;\noptions.inG = in;\noptions.dim = dim;\noptions.sources = struct('type',1 ,'out', 1); % one binomial observation;\noptions.DisplayWin = 0;\n\n% Build time series of hidden states and observations\nNmcmc = 16;\nnm = length(models);\np = cell(nm,nm,Nmcmc);\no = cell(nm,nm,Nmcmc);\nF = zeros(nm,nm,Nmcmc);\nfor ii=1:Nmcmc\n R = exp(randn(2,ntrials));\n t = exp(randn(2,ntrials));\n u = zeros(4,ntrials);\n u(in.ind.t,:) = t;\n u(in.ind.R,:) = R;\n for i=1:nm\n options.inG.model = models{i};\n [y,x,x0,eta,e] = VBA_simulate (ntrials,[],g_fname,[],phi,u,[],[],options);\n % Call inversion routine\n for j=1:nm\n options.inG.model = models{j};\n [p{i,j,ii},o{i,j,ii}] = VBA_NLStateSpaceModel(y,u,[],g_fname,dim,options);\n F(i,j,ii) = o{i,j,ii}.F;\n end\n end\nend\n\n\nhf = figure('color',[1 1 1]);\nha = axes('parent',hf);\ndF = F(:,1,:) - F(:,2,:);\nmdF = mean(dF,3);\nvdF = var(dF,[],3)./Nmcmc;\nplotUncertainTimeSeries(mdF,vdF,[],ha);\nset(ha,'xlim',[0,3],'xtick',[1,2],'xticklabels',models)\nxlabel(ha,'type of simulated data')\nylabel(ha,['log p(y|',models{1},') - log p(y|',models{2},')'])\nbox(ha,'off')\n\n\n\n\n", "meta": {"author": "MBB-team", "repo": "VBA-toolbox", "sha": "01ff63f43ef7a6473bc5e3f28dd9ffa58fcfb414", "save_path": "github-repos/MATLAB/MBB-team-VBA-toolbox", "path": "github-repos/MATLAB/MBB-team-VBA-toolbox/VBA-toolbox-01ff63f43ef7a6473bc5e3f28dd9ffa58fcfb414/demos/3_behavioural/demo_discounting.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465134460243, "lm_q2_score": 0.7956581049086031, "lm_q1q2_score": 0.7442160343213329}} {"text": "function [ error_per_image ] = compute_eye_corner_error( ground_truth_all, detected_points_all )\nnum_of_images = size(ground_truth_all,3);\nnum_of_points = size(ground_truth_all,1);\n\nerror_per_image = zeros(num_of_images,1);\n\nfor i =1:num_of_images\n detected_points = detected_points_all(:,:,i);\n ground_truth_points = ground_truth_all(:,:,i);\n interocular_distance = norm(ground_truth_points(37,:)-ground_truth_points(46,:));\n %interocular_distance = norm(mean(ground_truth_points(37:42,:))-mean(ground_truth_points(43:48,:)));\n sum=0;\n for j=1:num_of_points\n sum = sum+norm(detected_points(j,:)-ground_truth_points(j,:));\n end\n error_per_image(i) = sum/(num_of_points*interocular_distance);\nend\nend\n\n", "meta": {"author": "jiankangdeng", "repo": "MenpoBenchmark", "sha": "7425b6d5571e3bda1943cb2d6838ed187c2c3a64", "save_path": "github-repos/MATLAB/jiankangdeng-MenpoBenchmark", "path": "github-repos/MATLAB/jiankangdeng-MenpoBenchmark/MenpoBenchmark-7425b6d5571e3bda1943cb2d6838ed187c2c3a64/Evaluation/300W/util/compute_eye_corner_error.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9353465152482724, "lm_q2_score": 0.7956581000631541, "lm_q1q2_score": 0.7442160312231324}} {"text": "% Figure 10.11 Feedback Control of Dynamic Systems, 6e\n% Franklin, Powell, Emami\n%\n% fig10_11.m is a script to generate Fig. 10.11 \n% the frequency response of the notch network\nclf;\nnnotch=[1/.81 0 1] ;\ndnotch=[1/625 2/25 1];\n% define frequency range\nw=logspace(-1,1);\nw(36)=1;\nsubplot(211)\nw=logspace(-1,1);\nw(24)=0.89;\n% compute Bode\n[magn phn]=bode(nnotch,dnotch,w);\n% phn=php-360*ones(phn);\nmagn1=[magn, ones(size(magn))];\nsubplot(211); loglog(w,magn1); grid;\nxlabel('\\omega (rad/sec)');\nylabel('Magnitude');\ntitle('Fig. 10.11 Bode plot of a notch filter')\nsubplot(212); semilogx(w,phn); grid;\nxlabel('\\omega (rad/sec)');\nylabel('Phase (deg)');\n%Bode grid\nbodegrid", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/26412-feedback-control-of-dynamic-systems-6th-edition-prentice-hall-2010/fig10_11.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9353465062370313, "lm_q2_score": 0.7956580903722561, "lm_q1q2_score": 0.7442160149889179}} {"text": "function fd1d_heat_explicit_test03 ( )\n\n%*****************************************************************************80\n%\n%% FD1D_HEAT_EXPLICIT_TEST03 does a simple test problem.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 30 January 2012\n%\n% Author:\n%\n% John Burkardt\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'FD1D_HEAT_EXPLICIT_TEST03:\\n' );\n fprintf ( 1, ' Compute an approximate solution to the time-dependent\\n' );\n fprintf ( 1, ' one dimensional heat equation:\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' dH/dt - K * d2H/dx2 = f(x,t)\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Run a simple test case.\\n' );\n%\n% Heat coefficient.\n%\n k = k_test03 ( );\n%\n% X_NUM is the number of equally spaced nodes to use between 0 and 1.\n%\n x_num = 21;\n x_min = -5.0;\n x_max = +5.0;\n dx = ( x_max - x_min ) / ( x_num - 1 );\n x = linspace ( x_min, x_max, x_num );\n%\n% T_NUM is the number of equally spaced time points between 0 and 10.0.\n%\n t_num = 81;\n t_min = 0.0;\n t_max = 4.0;\n dt = ( t_max - t_min ) / ( t_num - 1 );\n t = linspace ( t_min, t_max, t_num );\n%\n% Get the CFL coefficient.\n%\n cfl = fd1d_heat_explicit_cfl ( k, t_num, t_min, t_max, x_num, x_min, x_max );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Number of X nodes = %d\\n', x_num );\n fprintf ( 1, ' X interval is [%f,%f]\\n', x_min, x_max );\n fprintf ( 1, ' X spacing is %f\\n', dx );\n fprintf ( 1, ' Number of T values = %d\\n', t_num );\n fprintf ( 1, ' T interval is [%f,%f]\\n', t_min, t_max );\n fprintf ( 1, ' T spacing is %f\\n', dt );\n fprintf ( 1, ' Constant K = %g\\n', k );\n fprintf ( 1, ' CFL coefficient = %g\\n', cfl );\n%\n% Running the code produces an array H of temperatures H(t,x),\n% and vectors x and t.\n%\n\n hmat = zeros ( x_num, t_num );\n\n for j = 1 : t_num\n if ( j == 1 )\n h = ic_test03 ( x_num, x, t(j) );\n h = bc_test03 ( x_num, x, t(j), h );\n else\n h = fd1d_heat_explicit ( x_num, x, t(j-1), dt, cfl, @rhs_test03, @bc_test03, h );\n end\n hmat(1:x_num,j) = h(1:x_num);\n end\n%\n% Plot the data.\n%\n figure ( 3 )\n [ tmat, xmat ] = meshgrid ( t, x );\n mesh ( tmat, xmat, hmat );\n title ( 'H(X,T) for TEST03 computed by FD1D\\_HEAT\\_EXPLICIT' );\n xlabel ( '<-- Time -->' );\n ylabel ( '<-- X -->' );\n zlabel ( '<-- H(X,T) -->' );\n%\n% Write the data to files.\n%\n r8mat_write ( 'h_test03.txt', x_num, t_num, hmat );\n r8vec_write ( 't_test03.txt', t_num, t );\n r8vec_write ( 'x_test03.txt', x_num, x );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' H(X,T) written to \"h_test03.txt\"\\n' );\n fprintf ( 1, ' T values written to \"t_test03.txt\"\\n' );\n fprintf ( 1, ' X values written to \"x_test3.txt\"\\n' );\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/fd1d_heat_explicit/fd1d_heat_explicit_test03.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392786908831, "lm_q2_score": 0.8418256452674008, "lm_q1q2_score": 0.7442069362256801}} {"text": "function krn = spm_smoothkern(fwhm,x,t)\n% Generate a Gaussian smoothing kernel\n% FORMAT krn = spm_smoothkern(fwhm,x,t)\n% fwhm - full width at half maximum\n% x - position\n% t - either 0 (nearest neighbour) or 1 (linear).\n% [Default: 1]\n%\n% krn - value of kernel at position x\n%__________________________________________________________________________\n%\n% For smoothing images, one should really convolve a Gaussian with a sinc\n% function. For smoothing histograms, the kernel should be a Gaussian\n% convolved with the histogram basis function used. This function returns\n% a Gaussian convolved with a triangular (1st degree B-spline) basis \n% function (by default). A Gaussian convolved with a hat function (0th \n% degree B-spline) can also be returned.\n%\n% Note that the convolution kernel returned by this function differ from\n% the ones that other packages currently use for Gaussian smoothing -\n% particularly when the FWHM is small compared with the voxel dimensions.\n% The fact that SPM does it differently from other software does not mean\n% that it is wrong.\n%__________________________________________________________________________\n% Copyright (C) 2005-2011 Wellcome Trust Centre for Neuroimaging\n\n% John Ashburner\n% $Id: spm_smoothkern.m 7460 2018-10-29 15:55:12Z john $\n\n\nif nargin<3, t = 1; end\n\n% Variance from FWHM\ns = (fwhm/sqrt(8*log(2)))^2+eps;\n\n% The simple way to do it. Not good for small FWHM\n% krn = (1/sqrt(2*pi*s))*exp(-(x.^2)/(2*s));\n\nif t==0\n % Gaussian convolved with 0th degree B-spline\n % int(exp(-((x+t))^2/(2*s))/sqrt(2*pi*s),t= -0.5..0.5)\n w1 = 1/sqrt(2*s);\n krn = 0.5*(erf(w1*(x+0.5))-erf(w1*(x-0.5)));\n krn(krn<0) = 0;\n\nelseif t==1\n % Gaussian convolved with 1st degree B-spline\n % int((1-t)*exp(-((x+t))^2/(2*s))/sqrt(2*pi*s),t= 0..1)\n % +int((t+1)*exp(-((x+t))^2/(2*s))/sqrt(2*pi*s),t=-1..0)\n w1 = 0.5*sqrt(2/s);\n w2 = -0.5/s;\n w3 = sqrt(s/2/pi);\n krn = 0.5*(erf(w1*(x+1)).*(x+1) + erf(w1*(x-1)).*(x-1) - 2*erf(w1*x ).* x)...\n +w3*(exp(w2*(x+1).^2) + exp(w2*(x-1).^2) - 2*exp(w2*x.^2));\n krn(krn<0) = 0;\n\nelse\n error('Only defined for nearest neighbour and linear interpolation.');\n % This should probably be based on https://arxiv.org/pdf/1608.05854.pdf:\n % Martin TB, Prunet S, Drissen L. Optimal fitting of Gaussian-apodized\n % or under-resolved emission lines in Fourier transform spectra\n % providing new insights on the velocity structure of NGC 6720. Monthly\n % Notices of the Royal Astronomical Society. 2016 Sep 14;463(4):4223-38.\n % (thanks for the pointer Guillaume).\nend\n\n", "meta": {"author": "spm", "repo": "spm12", "sha": "3085dac00ac804adb190a7e82c6ef11866c8af02", "save_path": "github-repos/MATLAB/spm-spm12", "path": "github-repos/MATLAB/spm-spm12/spm12-3085dac00ac804adb190a7e82c6ef11866c8af02/spm_smoothkern.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404057671714, "lm_q2_score": 0.8006920044739461, "lm_q1q2_score": 0.7441955015327942}} {"text": "% rouwenhorst approximates and AR(1) process with a Markov chain\n% \n% ::\n% \n% [Thetai,y]=rouwenhorst(mu,rho,sigma)\n% [Thetai,y]=rouwenhorst(mu,rho,sigma,N)\n% [Thetai,y]=rouwenhorst(mu,rho,sigma,N,p)\n% [Thetai,y]=rouwenhorst(mu,rho,sigma,N,p,q)\n% \n% Args:\n% \n% mu (numeric): unconditonal mean of the ar(1) process\n% rho [numeric): autoregressive coefficient\n% sigma (numeric): standard deviation of the shock\n% N (numeric | {2}): number of states of the markov chain\n% p (numeric | {.5*(1+rho)}): first parameter of the procedure\n% q (numeric | {.5*(1+rho)}): second parameter of the procedure\n% \n% Returns:\n% :\n% \n% - **Thetai** [numeric] : NxN transition matrix\n% - **y** [numeric] : vector of nodes or states\n% \n% Note:\n% \n% - The process is assumed to be of the form\n% x_t-mu=rho*(x_{t-1}-mu)+sigma*error_term where error_term ~ N(0,1)\n% \n% Reference:\n% \n% - Karen A. Kopecky, Richard M. H. Suen (2010): \"Finite state\n% Markov-chain approximations to highly persistent processes\". Review of\n% Economic Dynamics 13, pp 701-714\n% \n%", "meta": {"author": "jmaih", "repo": "RISE_toolbox", "sha": "1b2edfa27830c6d522f9d7d2335d33c3e4d84285", "save_path": "github-repos/MATLAB/jmaih-RISE_toolbox", "path": "github-repos/MATLAB/jmaih-RISE_toolbox/RISE_toolbox-1b2edfa27830c6d522f9d7d2335d33c3e4d84285/m/+ar1_approximation/rouwenhorst.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404096760998, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.7441954980320372}} {"text": "function dist = distance(x1,y1,x2,y2)\n%This function calculates the distance between any two cartesian \n%coordinates.\n% Copyright 2009-2010 The MathWorks, Inc.\ndist=sqrt((x1-x2)^2 + (y1-y2)^2);\n", "meta": {"author": "Mesywang", "repo": "Motion-Planning-Algorithms", "sha": "e8211b1b5ce219978403b2bd3dbc7162c325a89b", "save_path": "github-repos/MATLAB/Mesywang-Motion-Planning-Algorithms", "path": "github-repos/MATLAB/Mesywang-Motion-Planning-Algorithms/Motion-Planning-Algorithms-e8211b1b5ce219978403b2bd3dbc7162c325a89b/Astar/A_star/distance.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404096760996, "lm_q2_score": 0.8006919925839875, "lm_q1q2_score": 0.7441954936116338}} {"text": "% SOSDEMO4 --- Matrix Copositivity\n% Section 3.4 of SOSTOOLS User's Manual\n% \n\nclear; echo on;\nsyms x1 x2 x3 x4 x5;\nvartable = [x1; x2; x3; x4; x5];\n\n% The matrix under consideration\nJ = [1 -1 1 1 -1;\n -1 1 -1 1 1;\n 1 -1 1 -1 1;\n 1 1 -1 1 -1;\n -1 1 1 -1 1];\n\n% =============================================\n% First, initialize the sum of squares program\n\nprog = sosprogram(vartable); % No decision variables.\n\n% =============================================\n% Next, define SOSP constraints\n\n% Constraint : r(x)*J(x) - p(x) = 0\nJ = [x1^2 x2^2 x3^2 x4^2 x5^2]*J*[x1^2; x2^2; x3^2; x4^2; x5^2];\nr = x1^2 + x2^2 + x3^2 + x4^2 + x5^2;\n\nprog = sosineq(prog,r*J);\n\n% =============================================\n% And call solver\nprog = sossolve(prog);\n\n% =============================================\n% Program is feasible. The matrix J is copositive.\n\necho off\n\n\n\n\n\n", "meta": {"author": "yu-jiang", "repo": "radpbook", "sha": "88b9fa7d0a541099cdd1ac29383c89e087d1d895", "save_path": "github-repos/MATLAB/yu-jiang-radpbook", "path": "github-repos/MATLAB/yu-jiang-radpbook/radpbook-88b9fa7d0a541099cdd1ac29383c89e087d1d895/tools/SOSTOOLS.300/SOSTOOLS.300/demos/sosdemo4.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403979493139, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.7441954886424936}} {"text": "% KM_DEMO_KDE Kernel density estimation demo.\n%\n% Author: Steven Van Vaerenbergh (steven *at* gtas.dicom.unican.es), 2013\n%\n% This file is part of the Kernel Methods Toolbox for MATLAB.\n% https://github.com/steven2358/kmbox\n\nclose all\nclear\n\n%% PARAMETERS\n\nN1 = 100; % number of data in data set 1\nm1 = -1; % mean value\ns1 = 0.1; % variance \n\nN2 = 500; % number of data in data set 2\nm2 = 2; % mean value\ns2 = 0.5; % variance \n\nsigma = 0.1; % bandwidth\nnsteps = 100; % number of abscis points in kde\n\n%% PROGRAM\ntic\n\nx1 = m1 + sqrt(s1)*randn(N1,1);\nx2 = m2 + sqrt(s2)*randn(N2,1);\nx = [x1;x2];\n\n[xx,pp] = km_kde(x,sigma,nsteps,1.2);\n\ntoc\n%% OUTPUT\n\nfigure;\n\n[n,h] = hist(x,100);\nbar(h,n/sum(n),'b','EdgeColor','b')\n\nhold on\nplot(xx,pp,'r','LineWidth',3);\n\nlegend('histogram','KDE')\n", "meta": {"author": "epfl-lasa", "repo": "ML_toolbox", "sha": "61cc1245a2abe0c86a737d7b48bd645b28ffebee", "save_path": "github-repos/MATLAB/epfl-lasa-ML_toolbox", "path": "github-repos/MATLAB/epfl-lasa-ML_toolbox/ML_toolbox-61cc1245a2abe0c86a737d7b48bd645b28ffebee/methods/toolboxes/kmbox/demo/km_demo_kde.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952921073471, "lm_q2_score": 0.8289388125473629, "lm_q1q2_score": 0.7441344694688223}} {"text": "function fx = edcheb ( x, coef, npl )\n\n%*****************************************************************************80\n%\n%% EDCHEB evaluates the derivative of a Chebyshev series at a point.\n%\n% Discussion:\n%\n% This routine evaluates the derivative of a Chebyshev series \n% at a point in [-1,+1].\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 21 September 2011\n%\n% Author:\n%\n% Original FORTRAN77 version by Roger Broucke.\n% MATLAB version by John Burkardt.\n%\n% Reference:\n%\n% Roger Broucke,\n% Algorithm 446:\n% Ten Subroutines for the Manipulation of Chebyshev Series,\n% Communications of the ACM,\n% October 1973, Volume 16, Number 4, pages 254-256.\n%\n% Parameters:\n%\n% Input, real ( kind = 8 ) X, the evaluation point.\n% -1 <= X <= +1.\n%\n% Input, real ( kind = 8 ) COEF(NPL), the Chebyshev series.\n%\n% Input, integer ( kind = 4 ) NPL, the number of terms in the \n% Chebyshev series.\n%\n xjp2 = 0.0;\n xjpl = 0.0;\n bjp2 = 0.0;\n bjpl = 0.0;\n n = npl - 1;\n\n for k = 1 : n\n j = npl - k;\n dj = j;\n xj = 2.0 * coef(j+1) * dj + xjp2;\n bj = 2.0 * x * bjpl - bjp2 + xj;\n bf = bjp2;\n bjp2 = bjpl;\n bjpl = bj;\n xjp2 = xjpl;\n xjpl = xj;\n end\n\n fx = 0.5 * ( bj - bf );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/toms446/edcheb.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952866333483, "lm_q2_score": 0.8289388040954683, "lm_q1q2_score": 0.7441344573439863}} {"text": "function prob = LogisticRegressionTest(data, model)\n\nprob = 1 ./ (1 + exp(- (model.w(1:end-1)' * data.feat) - model.w(end)));\n% prob = 1 ./ (1 + exp(- (model.w' * data.feat)));", "meta": {"author": "flyers", "repo": "drone-tracking", "sha": "c42e1833acfb858ac8f4ec69fa04ab02ac4c19ad", "save_path": "github-repos/MATLAB/flyers-drone-tracking", "path": "github-repos/MATLAB/flyers-drone-tracking/drone-tracking-c42e1833acfb858ac8f4ec69fa04ab02ac4c19ad/trackers/HOG_LR/ObservationModel/LogisticRegressionTest.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.957277806109987, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.74409191073343}} {"text": "function pass = test_dst(pref)\n\nif ( nargin == 0 )\n pref = chebfunpref();\nend\n\n% TODO: include more extensive tests.\n\nn = 15;\nseedRNG(42)\nR = rand(n);\n\ntol = 50*eps;\n\nfor k = 1:8\n pass(k) = norm(chebfun.idst(chebfun.dst(R,1),1) - R) < tol;\nend\n\nN = 15; \nx = rand(N, 2); \ntol = 100*eps;\n\n% DST-I\nDST1 = sin(pi/(N+1)*((0:N-1)+1)'*((0:N-1)+1));\ny = DST1 * x;\npass(9) = norm( y - chebfun.dst(x, 1) ) < tol; \n\n% DST-II\nDST2 = sin(pi/N*((0:N-1)+1)'*((0:N-1)+1/2));\ny = DST2 * x; \npass(10) = norm( y - chebfun.dst(x, 2) ) < tol; \n\n% DST-III\nDST3 = sin(pi/N*((0:N-1)+1/2)' * ((0:N-1)+1));\nDST3(:, end) = .5*DST3(:, end); \ny = DST3 * x; \npass(11) = norm( y - chebfun.dst(x, 3) ) < tol; \n\n% DST-IV\nDST4 = sin(pi/N*((0:N-1)+1/2)'*((0:N-1)+1/2));\ny = DST4 * x; \npass(12) = norm( y - chebfun.dst(x, 4) ) < 10*tol; \n\n% DST-V\nDST5 = sin(pi/(N+1/2)*((0:N-1)+1)'*((0:N-1)+1));\ny = DST5 * x; \npass(13) = norm( y - chebfun.dst(x, 5) ) < 10*tol; \n\n% DST-VI\nDST6 = sin(pi/(N+1/2)*((0:N-1)+1)'*((0:N-1)+1/2));\ny = DST6 * x; \npass(14) = norm( y - chebfun.dst(x, 6) ) < 10*tol;\n\n% DST-VII\nDST7 = sin(pi/(N+1/2)*((0:N-1)+1/2)'*((0:N-1)+1));\ny = DST7 * x; \npass(15) = norm( y - chebfun.dst(x, 7) ) < 10*tol;\n\n% DST-VIII\nDST8 = sin(pi/(N+1/2)*((0:N-1)+1/2)'*((0:N-1)+1/2));\ny = DST8 * x; \npass(16) = norm( y - chebfun.dst(x, 8) ) < 10*tol;\n\n% IDST-I \ny = DST1 \\ x;\npass(17) = norm( y - chebfun.idst(x, 1) ) < tol; \n\n% IDST-II\ny = DST2 \\ x; \npass(18) = norm( y - chebfun.idst(x, 2) ) < tol; \n\n% IDST-III\ny = DST3 \\ x; \npass(19) = norm( y - chebfun.idst(x, 3) ) < tol; \n\n% IDST-IV\ny = DST4 \\ x; \npass(20) = norm( y - chebfun.idst(x, 4) ) < tol; \n\n% IDST-V\ny = DST5 \\ x;\npass(21) = norm( y - chebfun.idst(x, 5) ) < tol; \n\n% IDST-VI\ny = DST6 \\ x; \npass(22) = norm( y - chebfun.idst(x, 6) ) < tol; \n\n% IDST-VII\ny = DST7 \\ x; \npass(23) = norm( y - chebfun.idst(x, 7) ) < tol; \n\n% % IDST-VIII\npass(24) = true;\n% y = DST8 \\ x; \n% pass(24) = norm( y - chebfun.idst(x, 8) ) < tol; \n\n% Check complex inputs \nc = rand(10,1) + 1i*rand(10,1); \nfor j = 1:8\n v1 = chebfun.dst(c, j);\n v2 = chebfun.dst(real(c),j) + 1i*chebfun.dst(imag(c),j);\n pass(24+j) = norm(v1 - v2) < tol; \nend\nend\n", "meta": {"author": "chebfun", "repo": "chebfun", "sha": "8c49396a55e46ddd57a1d108c6a8f32e37536d54", "save_path": "github-repos/MATLAB/chebfun-chebfun", "path": "github-repos/MATLAB/chebfun-chebfun/chebfun-8c49396a55e46ddd57a1d108c6a8f32e37536d54/tests/chebfun/test_dst.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9572778000158575, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.7440918961194157}} {"text": " function Distance=DistanceToBorder(Position,Corner_position)\n\n% Position=FullNeuronBehaviorDataSet.FullNeuronBehaviorMatrix{1,1}(:,2:3);\n% Corner_position=FullNeuronBehaviorDataSet.EBC_results{1,4}.QP;\n%%\n for i=1:1:size(Position,1)\n\n Position_now=[squeeze(Position(i,:)),0];\n V1=[Corner_position(1,:),0];\n V2=[Corner_position(2,:),0];\n V3=[Corner_position(3,:),0];\n V4=[Corner_position(4,:),0];\n\n a = V1 - V2;\n b = Position_now - V2;\n d1 = norm(cross(a,b)) /norm(a);\n\n\n a = V2 - V3;\n b = Position_now - V3;\n d2 = norm(cross(a,b)) /norm(a);\n\n\n a = V3 - V4;\n b = Position_now - V4;\n d3 = norm(cross(a,b)) /norm(a);\n\n\n a = V4 - V1;\n b = Position_now - V1;\n d4 = norm(cross(a,b)) /norm(a);\n\n Distance(i)=min([d1,d2,d3,d4]);\n end\n\n\n end", "meta": {"author": "kavli-ntnu", "repo": "MINI2P_toolbox", "sha": "83311a49baea69ecf027e19390e608fd4eaeae8d", "save_path": "github-repos/MATLAB/kavli-ntnu-MINI2P_toolbox", "path": "github-repos/MATLAB/kavli-ntnu-MINI2P_toolbox/MINI2P_toolbox-83311a49baea69ecf027e19390e608fd4eaeae8d/Analysis/+SpatialTuning_BNT/DistanceToBorder.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9539660976007596, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.7440867880904793}} {"text": "function x = error_f_inverse ( y )\n\n%*****************************************************************************80\n%\n%% ERROR_F_INVERSE inverts the error function ERF.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 05 August 2010\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real Y, the value of the error function.\n%\n% Output, real X, the value such that ERROR_F(X) = Y.\n%\n z = ( y + 1.0 ) / 2.0;\n\n x = normal_01_cdf_inv ( z );\n\n x = x / sqrt ( 2.0 );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/prob/error_f_inverse.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8774767810736693, "lm_q2_score": 0.8479677660619633, "lm_q1q2_score": 0.7440720258182818}} {"text": "function backtrack_binary_rc_test01 ( )\n\n%*****************************************************************************80\n%\n%% BACKTRACK_BINARY_RC_TEST01 seeks binary powers that have a given sum.\n%\n% Discussion:\n%\n% We consider the binary powers 1, 2, 4, ... 2^(n-1).\n%\n% We wish to select some of these powers, so that the sum is equal\n% to a given target value. We are actually simply seeking the binary\n% representation of an integer.\n%\n% A partial solution is acceptable if it is less than the target value.\n%\n% We list the powers in descending order, so that the bactracking\n% procedure makes the most significant choices first, thus quickly\n% eliminating many unsuitable choices.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 31 December 2013\n%\n% Author:\n%\n% John Burkardt\n%\n n = 8;\n test_num = 3;\n targets = [ 73, 299, -3 ];\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'BACKTRACK_BINARY_RC_TEST01\\n' );\n fprintf ( 1, ' Use BACKBIN_RC to find the binary expansion of\\n' );\n fprintf ( 1, ' an integer between 0 and 255.\\n' );\n fprintf ( 1, ' The choices are 0/1 for the 8 digits.\\n' );\n\n for test = 1 : test_num\n\n target = targets(test);\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' TARGET = %d\\n', target );\n call_num = 0;\n reject = 0;\n n2 = -1;\n choice = [];\n\n while ( 1 )\n\n [ n2, choice ] = backbin_rc ( n, reject, n2, choice );\n call_num = call_num + 1;\n\n if ( n2 == -1 )\n fprintf ( 1, ' Termination without solution.\\n' );\n break\n end\n%\n% Evaluate the integer determined by the choices.\n%\n factor = 1;\n for i = n : -1 : n2 + 1\n factor = factor * 2;\n end\n\n result = 0;\n for i = 1 : n2\n result = result * 2 + choice(i);\n end\n\n result = result * factor;\n%\n% If the integer is too big, then we reject it, and\n% all the related integers formed by making additional choices.\n%\n reject = ( target < result );\n%\n% If we hit the target, then in this case, we can exit because\n% the solution is unique.\n%\n if ( result == target )\n break\n end\n\n end\n\n fprintf ( 1, ' Number of calls = %d\\n', call_num );\n fprintf ( 1, ' Binary search space = %d\\n', 2 ^ n );\n fprintf ( 1, ' ' );\n for i = 1 : n\n fprintf ( 1, '%2d', choice(i) );\n end\n fprintf ( 1, '\\n' );\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/backtrack_binary_rc/backtrack_binary_rc_test01.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677583778258, "lm_q2_score": 0.8774767858797979, "lm_q1q2_score": 0.7440720231510717}} {"text": "function legendre_polynomial_test04 ( )\n\n%*****************************************************************************80\n%\n%% LEGENDRE_POLYNOMIAL_TEST04 tests P_QUADRATURE_RULE.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 13 March 2012\n%\n% Author:\n%\n% John Burkardt\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'LEGENDRE_POLYNOMIAL_TEST04:\\n' );\n fprintf ( 1, ' P_QUADRATURE_RULE computes the quadrature rule\\n' );\n fprintf ( 1, ' associated with P(n,x)\\n' );\n\n n = 5;\n [ x, w ] = p_quadrature_rule ( n );\n\n r8vec2_print ( n, x, w, ' X W' );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Use the quadrature rule to estimate:\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Q = Integral ( -1 <= X < +1 ) X^E dx\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' E Q_Estimate Q_Exact\\n' );\n fprintf ( 1, '\\n' );\n\n for e = 0 : 2 * n - 1\n if ( e == 0 )\n f = ones ( n, 1 );\n else\n f = x .^ e;\n end\n q = w' * f;\n q_exact = p_integral ( e );\n fprintf ( 1, ' %2d %14g %14g\\n', e, q, q_exact );\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/legendre_polynomial/legendre_polynomial_test04.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677430095496, "lm_q2_score": 0.877476800298183, "lm_q1q2_score": 0.7440720218920914}} {"text": "function test07()\n% function test07()\n%\n% Computes a robust mean of angles\n%\n\n% This file is part of Manopt: www.manopt.org.\n% Original author: Nicolas Boumal, Dec. 30, 2012.\n% Contributors: \n% Change log: \n \n % Generate the data\n N = 250;\n theta_true = pi*(2*rand(1)-1);\n thetas = zeros(N,1);\n p_true = .25;\n for i = 1 : N\n if rand(1) < p_true\n thetas(i) = theta_true + .3*randn(1);\n else\n thetas(i) = pi*(2*rand(1)-1);\n end\n end\n X = [cos(thetas') ; sin(thetas)'];\n \n % Pick the manifold\n problem.M = spherefactory(2);\n\n % Parameters\n p = p_true;\n kappa = 3;\n c2 = besseli(0, 2*kappa);\n \n % Define the problem cost function\n problem.cost = @cost;\n function [val store] = cost(x, store)\n \n if ~isfield(store, 'fi')\n store.fi = (p/c2)*exp(2*kappa*X'*x);\n end\n fi = store.fi;\n \n val = -sum(log(fi + (1-p)));\n \n end\n\n % And its gradient\n problem.grad = @grad;\n function [g store] = grad(x, store)\n \n if ~isfield(store, 'fi')\n store.fi = (p/c2)*exp(2*kappa*X'*x);\n end\n fi = store.fi;\n \n g = -X*(2*kappa*(fi./(fi+(1-p))));\n g = g - (x'*g)*x;\n \n end\n \n % Check differentials consistency.\n % checkgradient(problem);\n\n % Solve with trust-regions and FD approximation of the Hessian\n warning('off', 'manopt:getHessian:approx');\n \n % Test many random initial guess\n% best_cost = inf;\n% best_x = [];\n% for i = 1 : 5\n% [x cst] = trustregions(problem);\n% if cst < best_cost\n% best_cost = cst;\n% best_x = x;\n% end\n% end\n% theta_found = angle(best_x(1)+1i*best_x(2));\n\n % Do a histogram of the data and select the initial guess as the peak\n [freqs, bins] = hist(thetas, 30);\n [~, ind] = max(freqs);\n x0 = [cos(bins(ind)) ; sin(bins(ind))];\n x = trustregions(problem, x0);\n theta_found = angle(x(1)+1i*x(2));\n \n fprintf('True theta: %g\\nHist theta: %g\\nFound theta: %g\\n', theta_true, angle(x0(1)+1i*x0(2)), theta_found);\n \n subplot(2,1,1);\n hist(thetas, 30);\n xlim([-pi pi]);\n \n th = linspace(-pi, pi);\n fth = zeros(size(th));\n for i = 1 : length(th)\n fth(i) = cost([cos(th(i));sin(th(i))], struct());\n end\n subplot(2,1,2);\n plot(th, -fth);\n xlim([-pi pi]);\n \n% keyboard;\n \nend\n", "meta": {"author": "NicolasBoumal", "repo": "manopt", "sha": "b8b54a6af8b965f7ae572972ba0d15787427744b", "save_path": "github-repos/MATLAB/NicolasBoumal-manopt", "path": "github-repos/MATLAB/NicolasBoumal-manopt/manopt-b8b54a6af8b965f7ae572972ba0d15787427744b/tests/test07.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767778695834, "lm_q2_score": 0.847967764140929, "lm_q1q2_score": 0.7440720214156573}} {"text": "function outputarray = linarray(start,spacing,numpoints)\n% outputarray = linarray(start,spacing,numpoints)\n% \n% The function linarray generates an row vector based on a start value, a\n% spacing, and a number of points. For example: linarray(1,.1,5) returns:\n% [1.0000 1.1000 1.2000 1.3000 1.4000]\n%\n% 3/2/11 (c) James F. Mack\n\noutputarray = [start:spacing:start+(numpoints-1)*spacing];", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/36124-linarray-alternative-to-linspace/linarray.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8774767874818408, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.7440720194525628}} {"text": "%GENREGSIN Generate sinusoidal regression data\n%\n% X = GENDATSIN(N,SIGMA)\n%\n% INPUT\n% N Number of objects to generate\n% SIGMA Standard deviation of the noise\n%\n% OUTPUT\n% X Regression dataset\n%\n% DESCRIPTION\n% Generate an artificial regression dataset [X,Y] with:\n%\n% y = sin(4x) + noise. \n%\n% where noise is Gaussian distributed with standard deviation sigma.\n%\n% X = GENDATSIN(100)\n% generates 100 x,y pairs with data and default noise (sigma = 0.1).\n%\n% x = (0:0.01:1)';\n% y = genregsin(x,0);\n% generates the true function along the x-axis, with zero noise.\n%\n% SEE ALSO (PRTools Guide)\n% GENDATR, GENDATSINC\n\n% Copyright: D.M.J. Tax, D.M.J.Tax@37steps.com\n% Faculty EWI, Delft University of Technology\n% P.O. Box 5031, 2600 GA Delft, The Netherlands\nfunction x = gendatsin(nrx,noise)\nif nargin<2\n noise = 0.1;\nend\n\nif (length(nrx)>1)\n x = nrx;\n nrx = size(x);\n x = sin(4*x) + noise*randn(nrx);\nelse\n x = rand(nrx,1);\n y = sin(4*x) + noise*randn(nrx,1);\nend\nx = gendatr(x,y);\n\nreturn\n\n", "meta": {"author": "marianux", "repo": "ecg-kit", "sha": "c8e3de47c54a9214138143676d2aa546b0540dd2", "save_path": "github-repos/MATLAB/marianux-ecg-kit", "path": "github-repos/MATLAB/marianux-ecg-kit/ecg-kit-c8e3de47c54a9214138143676d2aa546b0540dd2/common/prtools/gendatsin.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9207896671963206, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.744059940639507}} {"text": "function [rhsHx, rhsHy, rhsHz, rhsEx, rhsEy, rhsEz] = MaxwellRHS3D(Hx,Hy,Hz,Ex,Ey,Ez)\n\n% function [rhsHx, rhsHy, rhsHz, rhsEx, rhsEy, rhsEz] = MaxwellRHS3D(Hx,Hy,Hz,Ex,Ey,Ez)\n% Purpose : Evaluate RHS flux in 3D Maxwell equations\n\nGlobals3D;\n\n% storage for field differences at faces\ndHx = zeros(Nfp*Nfaces,K); dHy = dHx; dHz = dHx; \ndEx = zeros(Nfp*Nfaces,K); dEy = dEx; dEz = dEx; \n\n% form field differences at faces\ndHx(:) = Hx(vmapP)-Hx(vmapM); dEx(:) = Ex(vmapP)-Ex(vmapM);\t\ndHy(:) = Hy(vmapP)-Hy(vmapM); \tdEy(:) = Ey(vmapP)-Ey(vmapM);\t\ndHz(:) = Hz(vmapP)-Hz(vmapM); dEz(:) = Ez(vmapP)-Ez(vmapM); \n\n% make boundary conditions all reflective (Ez+ = -Ez-)\ndHx(mapB) = 0; dEx(mapB) = -2*Ex(vmapB); \ndHy(mapB) = 0; dEy(mapB) = -2*Ey(vmapB); \ndHz(mapB) = 0; dEz(mapB) = -2*Ez(vmapB);\n\nalpha=1; % => full upwinding\n\nndotdH = nx.*dHx + ny.*dHy + nz.*dHz;\nndotdE = nx.*dEx + ny.*dEy + nz.*dEz;\n\nfluxHx = -ny.*dEz + nz.*dEy + alpha*(dHx - ndotdH.*nx); \nfluxHy = -nz.*dEx + nx.*dEz + alpha*(dHy - ndotdH.*ny); \nfluxHz = -nx.*dEy + ny.*dEx + alpha*(dHz - ndotdH.*nz); \n\nfluxEx = ny.*dHz - nz.*dHy + alpha*(dEx - ndotdE.*nx); \nfluxEy = nz.*dHx - nx.*dHz + alpha*(dEy - ndotdE.*ny); \nfluxEz = nx.*dHy - ny.*dHx + alpha*(dEz - ndotdE.*nz); \n\n% evaluate local spatial derivatives\n[curlHx,curlHy,curlHz] = Curl3D(Hx,Hy,Hz);\n[curlEx,curlEy,curlEz] = Curl3D(Ex,Ey,Ez);\n\n% calculate Maxwell's right hand side\nrhsHx = -curlEx + LIFT*(Fscale.*fluxHx/2);\nrhsHy = -curlEy + LIFT*(Fscale.*fluxHy/2);\nrhsHz = -curlEz + LIFT*(Fscale.*fluxHz/2);\n\nrhsEx = curlHx + LIFT*(Fscale.*fluxEx/2);\nrhsEy = curlHy + LIFT*(Fscale.*fluxEy/2);\nrhsEz = curlHz + LIFT*(Fscale.*fluxEz/2);\nreturn;\n", "meta": {"author": "wme7", "repo": "Aero-matlab", "sha": "9430008f2e3b84f28633775a44dff534e780fbac", "save_path": "github-repos/MATLAB/wme7-Aero-matlab", "path": "github-repos/MATLAB/wme7-Aero-matlab/Aero-matlab-9430008f2e3b84f28633775a44dff534e780fbac/JSHesthaven&TWarburton/Codes3D/MaxwellRHS3D.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240177362488, "lm_q2_score": 0.7931059414036511, "lm_q1q2_score": 0.744031732240083}} {"text": "% OPTIMZE_LOGISTIC -- finds the optimal parameters of a logistic function\n% \n% ::\n% \n% \n% ab=optimize_logistic(x1,p1,x2,p2)\n% \n% ab=optimize_logistic(x1,p1,x2,p2,op)\n% \n% Args:\n% \n% - **x1,x2** [scalars] : points at which to evaluate the logistic\n% \n% - **p1,p2** [scalars] : probability values for x1 and x2\n% \n% - **op** [{'+'}|'-'] : decides whether b is to be multiplied by 1 or by\n% -1 in the evaluation the logistic function.\n% \n% Returns:\n% :\n% \n% - **ab** [vector] : optimized parameters of the logistic function\n% \n% Note:\n% \n% The function has the form f(x,a,b)=a/(a+exp(b*x)) so that f(x1,a,b)=p1\n% and f(x2,a,b)=p2\n% \n% Example:\n% \n% See also:\n%", "meta": {"author": "jmaih", "repo": "RISE_toolbox", "sha": "1b2edfa27830c6d522f9d7d2335d33c3e4d84285", "save_path": "github-repos/MATLAB/jmaih-RISE_toolbox", "path": "github-repos/MATLAB/jmaih-RISE_toolbox/RISE_toolbox-1b2edfa27830c6d522f9d7d2335d33c3e4d84285/m/+utils/+smooth_transition/optimize_logistic.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810421953309, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.7439864713268819}} {"text": "function D = EuDist2(fea_a,fea_b,bSqrt)\n% Euclidean Distance matrix\n% D = EuDist(fea_a,fea_b)\n% fea_a: nSample_a * nFeature\n% fea_b: nSample_b * nFeature\n% D: nSample_a * nSample_a\n% or nSample_a * nSample_b\n\n\nif ~exist('bSqrt','var')\n bSqrt = 1;\nend\n\n\nif (~exist('fea_b','var')) | isempty(fea_b)\n [nSmp, nFea] = size(fea_a);\n\n aa = sum(fea_a.*fea_a,2);\n ab = fea_a*fea_a';\n \n aa = full(aa);\n ab = full(ab);\n\n if bSqrt\n D = sqrt(repmat(aa, 1, nSmp) + repmat(aa', nSmp, 1) - 2*ab);\n D = real(D);\n else\n D = repmat(aa, 1, nSmp) + repmat(aa', nSmp, 1) - 2*ab;\n end\n \n D = max(D,D');\n D = D - diag(diag(D));\n D = abs(D);\nelse\n [nSmp_a, nFea] = size(fea_a);\n [nSmp_b, nFea] = size(fea_b);\n \n aa = sum(fea_a.*fea_a,2);\n bb = sum(fea_b.*fea_b,2);\n ab = fea_a*fea_b';\n\n aa = full(aa);\n bb = full(bb);\n ab = full(ab);\n\n if bSqrt\n D = sqrt(repmat(aa, 1, nSmp_b) + repmat(bb', nSmp_a, 1) - 2*ab);\n D = real(D);\n else\n D = repmat(aa, 1, nSmp_b) + repmat(bb', nSmp_a, 1) - 2*ab;\n end\n \n D = abs(D);\nend\n\n", "meta": {"author": "andrewssobral", "repo": "lrslibrary", "sha": "06d457349cb5f1fc56a583cd61af9f1d5150e3a1", "save_path": "github-repos/MATLAB/andrewssobral-lrslibrary", "path": "github-repos/MATLAB/andrewssobral-lrslibrary/lrslibrary-06d457349cb5f1fc56a583cd61af9f1d5150e3a1/algorithms/nmf/LNMF/EuDist2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037221561136, "lm_q2_score": 0.8031738010682209, "lm_q1q2_score": 0.7439828814677669}} {"text": "function g = p42_g ( n, x )\n\n%*****************************************************************************80\n%\n%% P42_G evaluates the gradient for problem 42.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 03 March 2002\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the number of variables.\n%\n% Input, real X(N), the values of the variables.\n%\n% Output, real G(N), the gradient of the objective function.\n%\n g = zeros ( n, 1 );\n\n g(1) = 2.0 * ( x(1) - x(2) ) / ( 1.0 + ( x(1) - x(2) )^2 )^2;\n\n g(2) = 2.0 * ( x(2) - x(1) ) / ( 1.0 + ( x(1) - x(2) )^2 )^2 ...\n - 0.5 * pi * x(3) * cos ( 0.5 * pi * x(2) * x(3) );\n\n g(3) = - 0.5 * pi * x(2) * cos ( 0.5 * pi * x(2) * x(3) );\n\n if ( x(2) ~= 0.0 )\n\n arg = ( x(1) + 2.0 * x(2) + x(3) ) / x(2);\n term = exp ( - arg^2 );\n\n g(1) = g(1) + 2.0 * term * ( x(1) + 2.0 * x(2) + x(3) ) / x(2)^2;\n g(2) = g(2) - 2.0 * term * ( x(1) + 2.0 * x(2) + x(3) ) ...\n * ( x(1) + x(3) ) / x(2)^3;\n g(3) = g(3) + 2.0 * term * ( x(1) + 2.0 * x(2) + x(3) ) / x(2)^2;\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_opt/p42_g.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070035949657, "lm_q2_score": 0.8175744806385542, "lm_q1q2_score": 0.7439167458935372}} {"text": "function [se_within, stats] = barplot_get_within_ste(dat,varargin)\n% :Usage:\n% ::\n%\n% [se_within, stats] = barplot_get_within_ste(dat)\n%\n% Compute within-subjects standard errors \n%\n% :Note: The old version of this used average s.e.'s for contrasts\n% of interest, which depend on contrast scaling and are less appropriate\n% for use as error bars.\n%\n% The new version as of 12/10 uses the Loftus & Masson 1994 method and has\n% been checked against the data in that paper.\n%\n% See help below for the L & M data and additional\n% code for getting the ANOVA decomposition.\n%\n% Useful for barplots of conditions when calculating within-subject SEs\n%\n% :Examples:\n% ::\n%\n% %% data from Loftus & Masson, Table 2\n%\n% mtx = [1 10 13 13 12.00\n% 2 6 8 8 7.33\n% 3 11 14 14 13.00\n% 4 22 23 25 23.33\n% 5 16 18 20 18.00\n% 6 15 17 17 16.33\n% 7 1 1 4 2.00\n% 8 12 15 17 14.67\n% 9 9 12 12 11.00\n% 10 8 9 12 9.67];\n%\n% dat = mtx(:, 2:4); % data from Loftus & Masson, Table 2\n%\n% [se_within, stats] = barplot_get_within_ste(dat)\n% fprintf('Within ste: %3.2f, 95%% CI: mean +/- %3.2f\\n', se_within, stats.ci);\n%\n% Extra stuff from ANOVA table\n%\n% Mean square for condition: Variance of condition means * sample\n% size...average squared variance accounted for by condition means\n% ::\n%\n% [n, k] = size(dat); \n% MS_cond = var( mean(dat) - mean(dat(:)) ) * n;\n%\n% MS_subject = var( mean(dat') - mean(dat(:)) ) * k;\n%\n% datv = dat(:);\n% MS_total = scale(datv, 1)' * scale(datv, 1);\n\n% notes: 6/3/2018 - tor added wh_omit line to omit all-NaN cases and\n% row-wise replacement to make error bars robust to presence of NaNs in\n% data. Previously returned NaN/zero error bars in presence of NaNs\n\nif nargin > 1 && ~isempty(varargin{1})\n \n covs = varargin{1};\n\n if size(covs,1) ~= size(dat,1), error('Covs and dat must have same no. of observations.'); end\n \n disp('Warning: covariates are no longer removed for within-subject SE bars.');\n \nend\n\n% remove cases with all NaN values\n% otherwise, these cases could influence calculations and interfere with\n% scaling below.\nwh_omit = all(isnan(dat), 2); dat(wh_omit, :) = []; \n\n% Replace remaining NaNs with row means \nm = nanmean(dat')';\nm = repmat(m, 1, size(dat, 2));\nwh = isnan(dat);\ndat(wh) = m(wh);\n\n% number of subjects and conditions\n[n, k] = size(dat); \n\ndf_s = n - 1; % degrees of freedom for subjects\ndf_c = k - 1; % degrees of freedom for conditions\ndf_sxc = df_s * df_c; % degrees of freedom for subj x condition\n\n% within-subject, within-condition errors\nerrs = scale(scale(dat, 1)', 1)';\n\n% Sums of squared errors\nSS_sxc = errs(:)' * errs(:);\n\n% Mean squared error, accounting for reduced df due to estimating marginal means\nMS_sxc = SS_sxc / df_sxc;\n\nse_within = sqrt(MS_sxc / n);\n\nci = se_within * tinv(1 - (.05 / 2), df_sxc);\n\nstats.se_within = se_within;\nstats.ci = ci;\nstats.ci_descrip = '95% confidence interval';\nstats.SS_sxc = SS_sxc;\nstats.MS_sxc = MS_sxc;\n\n% Extra stuff from ANOVA table\n% ---------------------------------------------------------------\n% Mean square for condition: Variance of condition means * sample\n% size...average squared variance accounted for by condition means\nstats.MS_cond = var( mean(dat) - mean(dat(:)) ) * n;\n\nstats.MS_subject = var( mean(dat') - mean(dat(:)) ) * k;\n\ndatv = dat(:);\nstats.MS_total = scale(datv, 1)' * scale(datv, 1);\n\nreturn\n\n\n\n", "meta": {"author": "canlab", "repo": "CanlabCore", "sha": "af242e120f0480c4feaeea90471c015a14f1f60e", "save_path": "github-repos/MATLAB/canlab-CanlabCore", "path": "github-repos/MATLAB/canlab-CanlabCore/CanlabCore-af242e120f0480c4feaeea90471c015a14f1f60e/CanlabCore/Statistics_tools/barplot_get_within_ste.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122213606241, "lm_q2_score": 0.8198933425148214, "lm_q1q2_score": 0.7438992498759096}} {"text": "% ^ Matrix power.\n% Z = X^y is X to the y power if y is a scalar and X is square. If y\n% is an integer greater than one, the power is computed by repeated\n% squaring. For other values of y the calculation involves\n% eigenvalues and eigenvectors.\n% \n% Z = x^Y is x to the Y power if Y is a square matrix and x is a scalar.\n% Computed using eigenvalues and eigenvectors.\n% \n% Z = X^Y, where both X and Y are matrices, is an error.\n% \n% C = MPOWER(A,B) is called for the syntax 'A ^ B' when A or B is an\n% object.\n% \n% See also POWER.\n%\n% Reference page in Doc Center\n% doc mpower\n%\n% Other functions named mpower\n%\n% codistributed/mpower gpuArray/mpower sym/mpower ts/mpower\n%", "meta": {"author": "jmaih", "repo": "RISE_toolbox", "sha": "1b2edfa27830c6d522f9d7d2335d33c3e4d84285", "save_path": "github-repos/MATLAB/jmaih-RISE_toolbox", "path": "github-repos/MATLAB/jmaih-RISE_toolbox/RISE_toolbox-1b2edfa27830c6d522f9d7d2335d33c3e4d84285/classes/time_series/@ts/mpower.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.907312226373181, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.7438992479962447}} {"text": "%DEMO_AUDITORYFILTERBANK Construct an auditory filterbank\n%\n% In this file we construct a uniform filterbank using a the impulse\n% response of a 4th order gammatone for each channel. The center frequencies\n% are equidistantly spaced on an ERB-scale, and the width of the filter are\n% choosen to match the auditory filter bandwidth as determined by Moore.\n%\n% Each channel is subsampled by a factor of 8 (a=8), and to generate a\n% nice plot, 4 channels per Erb has been used.\n%\n% The filterbank covers only the positive frequencies, so we must use\n% |filterbankrealdual| and |filterbankrealbounds|.\n%\n% .. figure:: \n%\n% Classic spectrogram \n%\n% A classic spectrogram of the spoken sentense. The dynamic range has\n% been set to 50 dB, to highlight the most important features.\n%\n% .. figure:: \n%\n% Auditory filterbank representation\n%\n% Auditory filterbank representation of the spoken sentense using\n% gammatone filters on an Erb scale. The dynamic range has been set to\n% 50 dB, to highlight the most important features.\n%\n% See also: freqtoaud, audfiltbw, gammatonefir, ufilterbank, filterbankrealdual\n%\n% References: glasberg1990daf\n\n\n% Use part of the 'cocktailparty' spoken sentense.\nf=cocktailparty;\nf=f(20001:80000,:);\nfs=44100;\na=8;\nchannels_per_erb=2;\nfilterlength=5000;\ndynrange_for_plotting=50;\n\n% Determine minimal transform length\nLs=length(f);\nL=ceil(filterlength/a)*a;\n\n% Number of channels, slightly less than 1 ERB(Cambridge) per channel.\nM=ceil(freqtoerb(fs/2)*channels_per_erb);\n\n% Compute center frequencies.\nfc=erbspace(0,fs/2,M);\n\n%% --------------- display classic spectrogram -------------------\nfigure(1);\nsgram(f,fs,dynrange_for_plotting);\n\n\n%% --------------- Gammatone filters ----------------------------\n\nif 1\n\ng_gam=gammatonefir(fc,fs,filterlength,'peakphase');\n\n% In production code, it is not necessary to call 'filterbankrealbounds',\n% this is just for veryfying the setup.\ndisp('Frame bound ratio for gammatone filterbank, should be close to 1 if the filters are choosen correctly.');\nfilterbankrealbounds(g_gam,a,L)\n\n% Create reconstruction filters\ngd_gam=filterbankrealdual(g_gam,a,L);\n\n% Analysis transform\ncoef_gam=ufilterbank(f,g_gam,a);\n\n% Synthesis transform\nr_gam=2*real(ifilterbank(coef_gam,gd_gam,a,Ls));\n\ndisp('Relative error in reconstruction, should be close to zero.');\nnorm(f-r_gam)/norm(f)\n\nfigure(2);\nplotfilterbank(coef_gam,a,fc,fs,dynrange_for_plotting,'audtick');\n\nF = frame('ufilterbankreal',g_gam,a,M);\nc2 = frana(F,f); \nLs=length(f);\n\n[r_iter,relres,iter] = frsyniter(F,c2,Ls);\ndisp('Relative error in interative reconstruction, should be close to zero.');\nnorm(f-r_iter)/norm(f)\n\nend;\n", "meta": {"author": "ltfat", "repo": "ltfat", "sha": "4496a06ad8dddb85cd2e007216b765dc996ef327", "save_path": "github-repos/MATLAB/ltfat-ltfat", "path": "github-repos/MATLAB/ltfat-ltfat/ltfat-4496a06ad8dddb85cd2e007216b765dc996ef327/demos/demo_auditoryfilterbank.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312221360624, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.743899241890007}} {"text": "%% Introduction to *wavelet_layer_2d*\n% *wavelet_layer_2d* is computing the wavelet transform coefficient from \n% the coefficient of the previous layer. It should be applied iteratively\n% to an input signal.\n%\n%% Usage\n% [A, V] = *wavelet_layer_2d*(U, filters, options), documentation is given in\n% \n%\n%% Description\n% It is possible to create some wavelet filters with wavelet_factory_2d for \n% instance. The filters size have to be adapted to the size of the input\n% signal $x$. \nclear; close all; \n\nx = mandrill;\n\n% Create $ U[\\empty]x $\nU{1}.signal{1} = x;\nU{1}.meta.j = zeros(0,1);\nU{1}.meta.q = zeros(0,1);\nU{1}.meta.resolution=0;\nfilters = morlet_filter_bank_2d(size(x));\n\n% A corresponds to the output scattering coefficients, and V to the wavelet\n% coefficients.\n[A, V] = wavelet_layer_2d(U{1}, filters);\n\ncolormap gray\nsubplot(121)\nimagesc(real(V.signal{1}))\naxis off\ntitle('Real part of the first wavelet transform coefficient');\nsubplot(122)\nimagesc(imag(V.signal{1}))\naxis off\ntitle('Imaginary part of the first wavelet transform coefficient');\n\n\n%% Options\n% The options are the same as in *wavelet_2d*.\n", "meta": {"author": "scatnet", "repo": "scatnet", "sha": "59d935afa20359845282a3518134e24244862c1f", "save_path": "github-repos/MATLAB/scatnet-scatnet", "path": "github-repos/MATLAB/scatnet-scatnet/scatnet-59d935afa20359845282a3518134e24244862c1f/demo/core/demo_wavelet_layer_2d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312213841788, "lm_q2_score": 0.8198933315126792, "lm_q1q2_score": 0.7438992337288879}} {"text": "function d = p08_fd ( p )\n\n%*****************************************************************************80\n%\n%% P08_FD is a signed distance function for problem 08.\n%\n% Licensing:\n%\n% (C) 2004 Per-Olof Persson. \n% See COPYRIGHT.TXT for details.\n%\n% Modified:\n%\n% 06 February 2006\n%\n% Parameters:\n%\n% Input, real P, one or more points.\n%\n% Output, real D, the signed distance of each point to the boundary of the region.\n%\n g1 = dcircle ( p, 0, 0, 1 );\n g2 = drectangle ( protate ( p, pi/12 ), -1, 1, 0, 1 );\n g3 = drectangle ( protate ( p, -pi/12 ), -1, 1, -1, 0 );\n g4 = drectangle ( protate ( pshift ( p, -0.9, 0 ), -pi/4 ), 0, 0.2, 0, 0.2 );\n g5 = dcircle ( p, 0.6, 0, 0.1 );\n\n d = ddiff ( ddiff ( ddiff ( ddiff ( g1, g2 ), g3 ), g4 ), g5 );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/distmesh/p08_fd.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361604769414, "lm_q2_score": 0.8152324960856177, "lm_q1q2_score": 0.7438476086243941}} {"text": "function param = copulaparam(type,tau)\n%COPULAPARAM Copula parameter, given Kendall's rank correlation.\n% RHO = COPULAPARAM('Gaussian',TAU) returns the linear correlation\n% parameter RHO corresponding to a Gaussian copula having Kendall's rank\n% correlation TAU. If TAU is a scalar correlation coefficient, RHO is a\n% scalar correlation coefficient corresponding to a bivariate copula. If\n% TAU is a P-by-P correlation matrix, RHO is a P-by-P correlation matrix\n% corresponding to a P-variate copula.\n%\n% RHO = COPULAPARAM('t',TAU) returns the linear correlation parameter RHO\n% corresponding to a t copula having Kendall's rank correlation TAU. If\n% TAU is a scalar correlation coefficient, RHO is a scalar correlation\n% coefficient corresponding to a bivariate copula. If TAU is a P-by-P\n% correlation matrix, RHO is a P-by-P correlation matrix corresponding to\n% a P-variate copula.\n% \n% ALPHA = COPULAPARAM(TYPE,TAU) returns the copula parameter ALPHA\n% corresponding to a bivariate Archimedean copula having Kendall's rank\n% correlation TAU. TYPE is one of 'Clayton', 'Frank', or 'Gumbel'.\n%\n% Example:\n% % Determine the linear correlation coefficient corresponding to a\n% % bivariate Gaussian copula having a rank correlation of -0.5\n% tau = -0.5\n% rho = copulaparam('gaussian',tau)\n%\n% % Generate dependent beta random values using that copula\n% u = copularnd('gaussian',rho,100)\n% b = betainv(u,2,2)\n%\n% % Verify that those pairs have a sample rank correlation approximately\n% % equal to tau\n% tau_sample = kendall(b)\n\n% Written by Peter Perkins, The MathWorks, Inc.\n% Revision: 1.0 Date: 2003/09/05\n% This function is not supported by The MathWorks, Inc.\n%\n% Requires MATLAB R13.\n\nif nargin < 2\n error('Requires two input arguments.');\nend\n\nswitch lower(type)\ncase {'gaussian' 't'}\n if ((numel(tau) == 1) && (tau < -1 | 1 < tau)) || ((numel(tau) ~= 1) && ~iscor(tau))\n error('TAU must be a correlation coefficient between -1 and 1, or a positive semidefinite correlation matrix.');\n end\n param = sin(tau.*pi./2);\n \ncase {'clayton' 'frank' 'gumbel'}\n if (numel(tau) ~= 1) || (tau < -1 | 1 < tau)\n error('TAU must be a correlation coefficient between -1 and 1.');\n end\n switch lower(type)\n case 'clayton'\n if tau < 0\n error('TAU must be nonnegative for the Clayton copula.');\n end\n param = 2*tau ./ (1-tau);\n case 'frank'\n if tau == 0\n param = 0;\n elseif abs(tau) < 1\n % There's no closed form for alpha in terms of tau, so alpha has to be\n % determined numerically.\n warn = warning('off','MATLAB:fzero:UndeterminedSyntax');\n param = fzero(@frankRootFun,sign(tau),[],tau);\n warning(warn);\n else\n param = sign(tau).*Inf;\n end\n case 'gumbel'\n if tau < 0\n error('TAU must be nonnegative for the Gumbel copula.');\n end\n param = 1 ./ (1-tau);\n end\n \notherwise\n error('Unrecognized copula type: ''%s''',type);\nend\n\n\nfunction err = frankRootFun(alpha,targetTau)\nif abs(alpha) < realmin\n tau = 0;\nelse\n tau = 1 + 4 .* (debye1(alpha)-1) ./ alpha;\nend\nerr = tau - targetTau;\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/15449-copula-generation-and-estimation/copulaparam.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361652391386, "lm_q2_score": 0.8152324848629215, "lm_q1q2_score": 0.7438476022666982}} {"text": "function asset_path_test ( )\n\n%*****************************************************************************80\n%\n%% ASSET_PATH_TEST tests ASSET_PATH.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 12 February 2012\n%\n% Author:\n%\n% John Burkardt\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'ASSET_PATH_TEST:\\n' );\n fprintf ( 1, ' Demonstrate the simulation of an asset price path.\\n' );\n\n s0 = 2.0;\n mu = 0.1;\n sigma = 0.3;\n n = 100;\n t0 = 0.0;\n t1 = 1.0;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' The asset price at time 0, S0 = %f\\n', s0 );\n fprintf ( 1, ' The asset expected growth rate MU = %f\\n', mu );\n fprintf ( 1, ' The asset volatility SIGMA = %f\\n', sigma );\n fprintf ( 1, ' The expiry date T1 = %f\\n', t1 );\n fprintf ( 1, ' The number of time steps N = %d\\n', n );\n\n s = asset_path ( s0, mu, sigma, t1, n );\n%\n% Plot.\n%\n figure ( 1 )\n t = ( linspace ( t0, t1, n + 1 ) )';\n plot ( t, s )\n grid on\n xlabel ( '<-- Time -->' )\n ylabel ( '<-- Value --> ' )\n title ( 'Simulated asset path' )\n%\n% Print a little.\n%\n r8vec_print_part ( n + 1, s, 10, ' Partial results:' );\n%\n% Write to a file.\n%\n output_filename = 'asset_path.txt';\n\n r8vec_write ( output_filename, n + 1, s );\n \n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Full results written to \"%s\".\\n', output_filename );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/black_scholes/asset_path_test.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007393, "lm_q2_score": 0.8652240860523328, "lm_q1q2_score": 0.7438017890689362}} {"text": "function x = r8vec_chebyspace ( n, a, b )\n\n%*****************************************************************************80\n%\n%% R8VEC_CHEBYSPACE creates a vector of Chebyshev spaced values in [A,B].\n%\n% Discussion:\n%\n% An R8VEC is a vector of R8's.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 08 June 2011\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the number of entries in the vector.\n%\n% Input, real A, B, the first and last entries.\n%\n% Output, real X(N,1), a vector of Chebyshev spaced data.\n%\n x = zeros ( n, 1 );\n\n if ( n == 1 )\n\n x(1) = ( a + b ) / 2.0;\n\n else\n\n for i = 1 : n\n\n theta = ( n - i ) * pi / ( n - 1 );\n\n c = cos ( theta );\n\n if ( mod ( n, 2 ) == 1 )\n if ( 2 * i - 1 == n )\n c = 0.0;\n end\n end\n\n x(i) = ( ( 1.0 - c ) * a ...\n + ( 1.0 + c ) * b ) ...\n / 2.0;\n\n end\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/r8lib/r8vec_chebyspace.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422644, "lm_q2_score": 0.822189123986562, "lm_q1q2_score": 0.7437938351957574}} {"text": "function [ mO ] = ApplyLocalLinearKernel( mI, filterRadius, regFctr )\n% ----------------------------------------------------------------------------------------------- %\n%[ mOutputImage ] = ApplyLocalLinearFilter( mInputImage, filterRadius, regFctr )\n% Applying Linear Edge Preserving Smoothing Filter based on Local Linear (Affine) model.\n% Input:\n% - mI - Input Image.\n% Structure: Image Matrix (Single Channel).\n% Type: 'Single' / 'Double'.\n% Range: [0, 1].\n% - filterRadius - Filter Radius.\n% The filter radius.\n% Structure: Scalar.\n% Type: 'Single' / 'Double'.\n% Range: {1, 2, ...}.\n% - regFctr - Regularization Factor.\n% Regularize the local covariance (Variance).\n% Structure: Scalar.\n% Type: 'Single' / 'Double'.\n% Range: (0, inf).\n% Output:\n% - mO - Output Image.\n% Structure: Image Matrix (Single Channel).\n% Type: 'Single' / 'Double'.\n% Range: [0, 1].\n% References:\n% 1. \"Guided Image Filtering\".\n% Remarks:\n% 1. This is basically estimating the Linear Function (Affine)\n% parameters for the Local Window. Namely, the ouput is a Linear\n% combination of the input Window and a DC Factor. The final step is\n% aggregation (Uniform) off all estimations of the parameters.\n% 2. Prefixes:\n% - 'v' - Vector.\n% - 'm' - Matrix.\n% - 't' - Tensor (Multi Dimension Matrix)\n% - 's' - Struct.\n% - 'c' - Cell Array.\n% 3. The calculation of the Local Variance might be negative due to\n% numerical diffuculties. If artifacts appear, this might be the\n% casue. Usually using matrices of type 'double' solves it.\n% 4. This implemnetation is `ApplyGuidedFilter` where the Guiding Image\n% is the Input Image.\n% 5. Speed otimizzation can be achived by wiser use of 'mNumEffPixels'.\n% Instead of dividing by it calculate its reciprocal once. Moreover,\n% it can be used only once in the aggregation process.\n% TODO:\n% 1. Create Multi Variable Linear Model.\n% 2. Some speed potimization could be made (Taking advantage of 'mNumEffPixels').\n% Release Notes:\n% - 1.0.000 05/01/2016 Royi Avital\n% * First release version\n% ----------------------------------------------------------------------------------------------- %\n\nFALSE = 0;\nTRUE = 1;\n\nOFF = 0;\nON = 1;\n\nBORDER_TYPE_CONSTANT = 1;\nBORDER_TYPE_CIRCULAR = 2;\nBORDER_TYPE_REPLICATE = 3;\nBORDER_TYPE_SYMMETRIC = 4;\n\nnumRows = size(mI, 1);\nnumCols = size(mI, 2);\n\nborderType = BORDER_TYPE_CONSTANT;\nborderValue = 0;\nnormalizeFlag = OFF;\n\nmNumEffPixels = ApplyBoxFilter(ones([numRows, numCols]), filterRadius, borderType, borderValue, normalizeFlag);\n\nmLocalMean = ApplyBoxFilter(mI, filterRadius, borderType, borderValue, normalizeFlag) ./ mNumEffPixels;\nmLocalMeanSquare = ApplyBoxFilter((mI .* mI), filterRadius, borderType, borderValue, normalizeFlag) ./ mNumEffPixels;\nmLocalCovariance = mLocalMeanSquare - (mLocalMean .* mLocalMean);\n\nmO = zeros([numRows, numCols]);\n\nfor jj = 1:numCols\n for ii = 1:numRows\n % The coordinate i, j are set.\n \n sumWeights = 0;\n \n % Running on the Neighborhood of the pixel\n for ll = -filterRadius:filterRadius\n for kk = -filterRadius:filterRadius\n \n jRowIdx = ii + kk;\n jColIdx = jj + ll;\n \n if((jColIdx >= 1) && (jColIdx <= numCols) && (jRowIdx >= 1) && (jRowIdx <= numRows))\n % Valid Pixel\n numPixels = 0;\n jPixelWeight = 0;\n \n % Running on Wk Window\n for nn = -filterRadius:filterRadius\n for mm = -filterRadius:filterRadius\n \n % K Index\n kRowIdx = jRowIdx + mm;\n kColIdx = jColIdx + nn;\n \n if((kColIdx >= 1) && (kColIdx <= numCols) && (kRowIdx >= 1) && (kRowIdx <= numRows) && (abs(kColIdx - jj) <= filterRadius) && (abs(kRowIdx - ii) <= filterRadius))\n \n numPixels = numPixels + 1;\n \n % Weight\n jPixelWeight = jPixelWeight + 1 + (((mI(ii, jj) - mLocalMean(kRowIdx, kColIdx)) * (mI(jRowIdx, jColIdx) - mLocalMean(kRowIdx, kColIdx))) / (mLocalCovariance(kRowIdx, kColIdx) + regFctr));\n end\n end\n end\n \n % jPixelWeight = jPixelWeight / (numPixels * numPixels);\n mO(ii, jj) = mO(ii, jj) + (jPixelWeight * mI(jRowIdx, jColIdx));\n \n sumWeights = sumWeights + jPixelWeight;\n \n end\n end\n end\n \n mO(ii, jj) = mO(ii, jj) / sumWeights;\n \n end\nend\n\n\n\nend\n\n", "meta": {"author": "RoyiAvital", "repo": "StackExchangeCodes", "sha": "d2a934616995fa8a9f4df1ca29029402435b9e6f", "save_path": "github-repos/MATLAB/RoyiAvital-StackExchangeCodes", "path": "github-repos/MATLAB/RoyiAvital-StackExchangeCodes/StackExchangeCodes-d2a934616995fa8a9f4df1ca29029402435b9e6f/SignalProcessing/Q42415/ApplyLocalLinearKernel.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.8221891327004132, "lm_q1q2_score": 0.7437938346243838}} {"text": "function scMove(Pos1,length,LinCol)\n%scMove : Move along the transmission line on smith chart to transform impedance\n%\n%\n% SYNOPSIS:\n% Transform a point to another one as one moves along a lossless transmission line on\n% smith chart.\n%\n% See also scDraw, scInv, scConCirc, scMatchCirc\n% \n% SYNTAX:\n% scMove(Pos1, length, Direction, LinCol)\n%\n% INPUT ARGUMENTS:\n% Pos1 : Starting point coordinates [r x] normalized\n% length : Length of the transmission line normalized to wavelength\n% LinCol : Color of the end-ray emanating from origin\n% Direction : Towards(+1) or away from the generator(-1) %%%%TO BE INCORPORATED YET.\n%\n% OUTPUT ARGUMENT:\n% none\n%\n% EXAMPLE:\n% The Command sequence \n% scDraw;\n% scMove([2 3],.3)\n% will draw a blank smith chart and will plot the point\n% corresponding to impedance (2+j*3)*Z_L and its transformed value\n% after moving 0.3*lambda towards the generator along the\n% transmission line\n%\n% Mohammad Ashfaq - (31-05-2000)\n% Mohammad Ashfaq - (13-04-2006) Modified (example included)\n%\n\nif nargin == 2\n LinCol = 'm';\nend\n\n r1 = Pos1(1);\n x1 = Pos1(2);\n [u1, v1] = scPOI(r1,x1);\n\n % MARK STARTING POINT\n scRay(Pos1);\n\n r = sqrt(u1^2+v1^2);\n Theta1 = atan2(v1,u1);\n length1 = (1-Theta1/pi)/4;\n length2 = length1 + length;\n Theta2 = (1-4*length2)*pi;\n u2 = r * cos(Theta2);\n v2 = r * sin(Theta2);\n\n % MARK END POINT\n plot(u2, v2,'r*')\n\n Theta2d = Theta2*180/pi;\n if (Theta2d<-180)\n Theta2d = 360 + Theta2d;\n elseif (Theta2d>180)\n Theta2d = 360 - Theta2d;\n end\n length2 = length2-floor(length2/.5)*.5;\n \n plot([0 u2],[0 v2],LinCol);\n plot([1.25*cos(Theta2) u2],[1.25*sin(Theta2) v2],'k');\n string = ['\\theta=', num2str(Theta2d,'%3.2f'), ' l/\\lambda=', num2str(length2, '%0.3f')];\n \n if abs(Theta2d)>90\n Theta2d = Theta2d+180;\n h = text(1.25*cos(Theta2),1.25*sin(Theta2), string);\n set(h,'rotation', Theta2d, 'Fontsize', 8, 'HorizontalAlignment','right');\n else\n h = text(1.25*cos(Theta2),1.25*sin(Theta2), string);\n set(h,'rotation', Theta2d, 'Fontsize', 8);\n end\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/324-smithchart/scMove.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595163, "lm_q2_score": 0.8221891283434876, "lm_q1q2_score": 0.7437938306828888}} {"text": "function C= train_QDA(xTr, yTr, varargin)\n%TRAIN_QDA - Quadratic Discriminant Analysis \n%\n%Synopsis:\n% C = train_QDA(XTR, YTR)\n% C = train_QDA(XTR, YTR, PRIOR)\n%\n%Arguments:\n% XTR: DOUBLE [NxM] - Data matrix, with N feature dimensions, and M\n% training points/examples. \n% YTR: INT [CxM] - Class membership labels of points in X_TR. C by M matrix\n% of training labels, with C representing the number of\n% classes and M the number of training examples/points.\n% Y_TR(i,j)==1 if the point j belongs to class i.\n% PRIOR: DOUBLE - (default ones(nClasses, 1)/nClasses): Empirical class\n% priors\n%\n%Returns:\n% C: STRUCT - Trained classifier structure, with the hyperplane given by\n% fields C.w, C.b and C.sq\n%\n%See also:\n% APPLY_QDA\n\n\nif size(yTr,1)==1,\n nClasses= 2;\n clInd{1}= find(yTr==-1);\n clInd{2}= find(yTr==1);\n N= [length(clInd{1}) length(clInd{2})];\nelse\n nClasses= size(yTr,1);\n clInd= cell(nClasses,1);\n N= zeros(nClasses, 1);\n for ci= 1:nClasses,\n clInd{ci}= find(yTr(ci,:));\n N(ci)= length(clInd{ci});\n end\nend\n\nif nargin==2\n priorP= ones(nClasses,1)/nClasses;\nelse\n priorP= varargin{1};\nend\nif isequal(priorP, '*')\n priorP = N/sum(N);\nend\n \nd= size(xTr,1);\nC.w= zeros(d, nClasses);\nC.b= zeros(1, nClasses);\nC.sq= zeros(d, d, nClasses);\nfor ci= 1:nClasses,\n cli= clInd{ci};\n C.w(:,ci)= mean(xTr(:,cli), 2);\n yc= xTr(:,cli) - C.w(:,ci)*ones(1,N(ci));\n Sq= yc*yc';\n C.sq(:,:,ci)= Sq / (N(ci)-1);\nend\nC.b= zeros(1, nClasses);\nfor ci= 1:nClasses,\n S= C.sq(:,:,ci);\n S= pinv(S);\n C.sq(:,:,ci)= -0.5*S;\n C.b(ci)= -0.5*C.w(:,ci)' * S*C.w(:,ci) + ...\n 0.5*log(max([det(S),realmin])) + log(priorP(ci));\n C.w(:,ci)= S*C.w(:,ci);\nend\nC.b=C.b';\n\nif nClasses==2,\n sq(:,:)= C.sq(:,:,2) - C.sq(:,:,1);\n C.sq= sq;\n C.w= C.w(:,2)-C.w(:,1);\n C.b= C.b(2) - C.b(1);\nend\n", "meta": {"author": "bbci", "repo": "bbci_public", "sha": "2e6fe9481537dcfee702e74544191dcf737f02ce", "save_path": "github-repos/MATLAB/bbci-bbci_public", "path": "github-repos/MATLAB/bbci-bbci_public/bbci_public-2e6fe9481537dcfee702e74544191dcf737f02ce/classification/train_QDA.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.822189123986562, "lm_q1q2_score": 0.7437938267413937}} {"text": "function pde = Stokesdata0\n\n%\nnu = 1;\npde = struct('f',@f,'g',@g,'exactp', @exactp, ...\n 'exactu', @exactu,'g_D', @g_D, 'nu', nu);\n\n function z = f(p) \n x = p(:,1); y = p(:,2);\n z(:,1) = -4*pi^2*(2*cos(2*pi*x)-1).*sin(2*pi*y)+x.^2;\n z(:,2) = 4*pi^2*(2*cos(2*pi*y)-1).*sin(2*pi*x);\n end\n\n function z = g(p)\n z = zeros(size(p,1),1);\n end\n\n function z = exactu(p)\n x = p(:,1); y = p(:,2);\n z(:,1) = (1-cos(2*pi*x)).*sin(2*pi*y); \n z(:,2) = -(1-cos(2*pi*y)).*sin(2*pi*x);\n end\n\n function z = exactp(p)\n x = p(:,1); % y = p(:,2);\n z = 1/3*x.^3;\n end\n\n function z = g_D(p) % Dirichlet boundary condition\n z = exactu(p);\n end\nend", "meta": {"author": "lyc102", "repo": "ifem", "sha": "29f31c812001ca8d93dad08e67208ca60e8716d4", "save_path": "github-repos/MATLAB/lyc102-ifem", "path": "github-repos/MATLAB/lyc102-ifem/ifem-29f31c812001ca8d93dad08e67208ca60e8716d4/data/Stokesdata0.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897459384732, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.7437228176579035}} {"text": "function b = isPointOnLine(point, line, varargin)\n%ISPOINTONLINE Test if a point belongs to a line.\n%\n% B = isPointOnLine(POINT, LINE)\n% with POINT being [xp yp], and LINE being [x0 y0 dx dy].\n% Returns 1 if point lies on the line, 0 otherwise.\n%\n% If POINT is an N-by-2 array of points, B is a N-by-1 array of booleans.\n%\n% If LINE is a N-by-4 array of line, B is a 1-by-N array of booleans.\n%\n% B = isPointOnLine(POINT, LINE, TOL)\n% Specifies the tolerance used for testing location on 3D line. Default value is 1e-14.\n%\n% See also \n% lines2d, points2d, isPointOnEdge, isPointOnRay, isLeftOriented\n%\n\n% ------\n% Author: David Legland \n% E-mail: david.legland@inrae.fr\n% Created: 2003-10-31\n% Copyright 2003-2022 INRA - TPV URPOI - BIA IMASTE\n\n% extract computation tolerance\ntol = 1e-14;\nif ~isempty(varargin)\n tol = varargin{1};\nend\n\n% test if lines are colinear, using third coordinate of 3D cross-product\n% same test as:\n% b = abs((xp-x0).*dy-(yp-y0).*dx)./hypot(dx, dy).^2 < tol;\nb = bsxfun(...\n @rdivide, abs(...\n bsxfun(@times, bsxfun(@minus, point(:,1), line(:,1)'), line(:,4)') - ...\n bsxfun(@times, bsxfun(@minus, point(:,2), line(:,2)'), line(:,3)')), ...\n (line(:,3).^2 + line(:,4).^2)') < tol;\n\n", "meta": {"author": "mattools", "repo": "matGeom", "sha": "1fd2c937064be1ee1f4fd09fbfdf96145ebe5271", "save_path": "github-repos/MATLAB/mattools-matGeom", "path": "github-repos/MATLAB/mattools-matGeom/matGeom-1fd2c937064be1ee1f4fd09fbfdf96145ebe5271/matGeom/geom2d/isPointOnLine.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.879146761176671, "lm_q2_score": 0.845942439250491, "lm_q1q2_score": 0.7437075556089618}} {"text": "function prob_test1486 ( )\n\n%*****************************************************************************80\n%\n%% TEST1486 tests UNIFORM_01_MEAN, *_SAMPLE, *_VARIANCE.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 14 February 2003\n%\n% Author:\n%\n% John Burkardt\n%\n nsample = 1000;\n seed = 123456789;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TEST1486\\n' );\n fprintf ( 1, ' For the Uniform 01 PDF:\\n' );\n fprintf ( 1, ' UNIFORM_01_MEAN computes mean;\\n' );\n fprintf ( 1, ' UNIFORM_01_SAMPLE samples;\\n' );\n fprintf ( 1, ' UNIFORM_01_VARIANCE computes variance.\\n' );\n\n mean = uniform_01_mean ( );\n variance = uniform_01_variance ( );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' PDF mean = %14f\\n', mean );\n fprintf ( 1, ' PDF variance = %14f\\n', variance );\n\n for i = 1 : nsample\n [ x(i), seed ] = uniform_01_sample ( seed );\n end\n\n mean = r8vec_mean ( nsample, x );\n variance = r8vec_variance ( nsample, x );\n xmax = max ( x(1:nsample) );\n xmin = min ( x(1:nsample) );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Sample size = %6d\\n', nsample );\n fprintf ( 1, ' Sample mean = %14f\\n', mean );\n fprintf ( 1, ' Sample variance = %14f\\n', variance );\n fprintf ( 1, ' Sample maximum = %14f\\n', xmax );\n fprintf ( 1, ' Sample minimum = %14f\\n', xmin );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/prob/prob_test1486.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467611766711, "lm_q2_score": 0.8459424353665382, "lm_q1q2_score": 0.7437075521943975}} {"text": "function [gradISE,gradJhr,gradJrr]=GaussMixISEMeanGrads(w1,mu1,P1,w2,mu2,P2,PDFVals12,PDFVals22)\n%%GAUSSMIXISEMEANGRADS Compute the gradient of the non-normalized\n% integrated squared error (ISE) between two Gaussian mixture\n% PDFs with respect to the mean vectors of the individual\n% components of the second Gaussian mixture. This gradient\n% can arise when optimizing over the ISE with respect to the\n% means.\n%\n%INPUTS: w1 The N1X1 or 1XN1 vector of weights for the first Gaussian\n% mixture. All w1>0 and sum(w1)=1.\n% mu1 The xDimXN1 set of mean vectors for the first Gaussian mixture\n% distribution.\n% P1 The xDimXxDimXN1 set of positive definite covariance matrices\n% for the first Gaussian mixture distirbution.\n% w2, mu2, P2, The length N2, xDimXN2, and xDimXxDimXN2 set of weights,\n% mean vectors and positive-definite covariance matrices for the\n% second Gaussian mixture distribution.\n% PDFVals12 A matrix such that the value in element (i,j) is\n% N(mu1(:,i);mu2(:,j),P1(:,:,i)+P2(:,:,j)), where N indicates the\n% multivariate Gaussian PDF evaluated at the first argument with\n% the second and third arguments being the mean and covarince\n% matrix. This parameter is returned by computeGaussMixISE.\n% PDFVals22 A matrix such that the value in element (i,j) is\n% N(mu2(:,i);mu2(:,j),P2(:,:,i)+P2(:,:,j)). This parameter is\n% returned by computeGaussMixISE.\n%\n%OUTPUTS: gradISE The xDimXn2 set of derivatives of the ISE with respect to\n% the elements of q (the square roots of w2).\n% gradJhr, gradJrr In Chapter 3 of [1], the ISE is expressed in terms of\n% Jhr and Jrr terms. These are the xDimXn2 gradients of\n% those terms.\n%\n%Formule for gradJhr and gradJrr are Equation 3.34 in Section 3.3.3.2 of\n%[1]. They relate to the ISE via Equation 3.20. See the function\n%computeGaussMixISE to compute the ISE.\n%\n%EXAMPLE 1:\n%In this example with a scalar random variable, we verify that the gradient\n%obtained from this function is consistent with numerical differentiation.\n% w1=[0.03,0.18,0.12,0.19,0.02,0.16,0.06,0.1,0.08,0.06];\n% n1=length(w1);\n% mu1=[1.45,2.20,0.67,0.48,1.49,0.91,1.01,1.42,2.77,0.89];\n% P1=[0.0487,0.0305,0.1171,0.0174,0.0295,0.0102, 0.0323, 0.0380, 0.0115, 0.0679];\n% P1=reshape(P1,[1,1,n1]);\n% \n% %The second PDF is the first with the five least-weight components deleted.\n% w2=[0.18,0.12,0.19,0.16,0.1,0.08];\n% w2=w2/sum(w2);\n% n2=length(w2);\n% mu2=[2.20,0.67,0.48,0.91,1.42,2.77];\n% P2=[0.0305,0.1171,0.0174,0.0102,0.0380,0.0115];\n% P2=reshape(P2,[1,1,n2]);\n% \n% [ISEVal,PDFVals12,PDFVals22]=computeGaussMixISE(w1,mu1,P1,w2,mu2,P2);\n% \n% epsVal=1e-8;\n% gradISENumDiff=zeros(1,n2);\n% for j=1:n2\n% muCur=mu2;\n% muCur(1,j)=muCur(1,j)+epsVal;\n% \tISEValCur=computeGaussMixISE(w1,mu1,P1,w2,muCur,P2);\n% gradISENumDiff(1,j)=(ISEValCur-ISEVal)/epsVal;\n% end\n% gradISE=GaussMixISEMeanGrads(w1,mu1,P1,w2,mu2,P2,PDFVals12,PDFVals22);\n% RelErr=max(abs((gradISENumDiff-gradISE)./gradISENumDiff))\n%The relative error will be about 5.4042e-6, which indicates good numeric\n%agreement.\n%\n%EXAMPLE 2:\n%In this example with a bivariate distribution, we verify that the gradient\n%obtained from this function is consistent with numerical differentiation.\n% w1=[0.25;0.5;0.25];\n% mu1=zeros(2,2);\n% mu1(:,1)=[1;-1];\n% mu1(:,2)=[-1;1];\n% mu1(:,3)=[0;0];\n% P1=zeros(2,2,2);\n% P1(:,:,1)=[4/9, 14/45;\n% 14/45,4/9];\n% P1(:,:,2)=[4/9, 0;\n% 0, 4/9];\n% P1(:,:,3)=[2/9, -1/9;\n% -1/9, 3/9];\n% \n% %The second distribution just throws out the first component.\n% w2=w1(2:3);\n% w2=w2/sum(w2);\n% mu2=mu1(:,2:3);\n% P2=P1(:,:,2:3);\n% \n% n2=length(w2);\n% [ISEVal,PDFVals12,PDFVals22]=computeGaussMixISE(w1,mu1,P1,w2,mu2,P2);\n% \n% numDim=size(mu1,1);\n% epsVal=1e-8;\n% gradISENumDiff=zeros(numDim,n2);\n% for curDim=1:numDim\n% for j=1:n2\n% muCur=mu2;\n% muCur(curDim,j)=muCur(curDim,j)+epsVal;\n% ISEValCur=computeGaussMixISE(w1,mu1,P1,w2,muCur,P2);\n% gradISENumDiff(curDim,j)=(ISEValCur-ISEVal)/epsVal;\n% end\n% end\n% gradISE=GaussMixISEMeanGrads(w1,mu1,P1,w2,mu2,P2,PDFVals12,PDFVals22);\n% RelErr=max(max(abs((gradISENumDiff-gradISE)./gradISENumDiff)))\n%The relative error will be about 1.2876e-7, which indicates good numeric\n%agreement.\n%\n%REFERENCES:\n%[1] J. L. Williams, \"Gaussian mixture reduction for tracking multiple\n% maneuvering targets in clutter,\" Master's thesis, Air Force Institute\n% of Technology, Mar. 2003. [Online].\n% Available: http://www.dtic.mil/srch/doc?collection=t3&id=ADA415317\n%\n%May 2019 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nNh=length(w1);\nNr=length(w2);\nxDim=size(mu1,1);\n\n%The formulae for the gradient of Jhr and Jrr are given in Equation 3.34 of\n%Section 3.3.3.2 of [1].\ngradJhr=zeros(xDim,Nr);\ngradJrr=zeros(xDim,Nr);\n\nfor j=1:Nr\n for i=1:Nh\n gradJhr(:,j)=gradJhr(:,j)+(P1(:,:,i)+P2(:,:,j))\\(mu2(:,j)-mu1(:,i))*PDFVals12(i,j)*w1(i);\n end\n gradJhr(:,j)=-w2(j)*gradJhr(:,j);\nend\n\nfor j=1:Nr\n for i=1:Nr\n gradJrr(:,j)=gradJrr(:,j)+(P2(:,:,i)+P2(:,:,j))\\(mu2(:,j)-mu2(:,i))*PDFVals22(i,j)*w2(i);\n end\n gradJrr(:,j)=-2*w2(j)*gradJrr(:,j);\nend\n\ngradISE=gradJrr-2*gradJhr;\nend\n\n%LICENSE:\n%\n%The source code is in the public domain and not licensed or under\n%copyright. The information and software may be used freely by the public.\n%As required by 17 U.S.C. 403, third parties producing copyrighted works\n%consisting predominantly of the material produced by U.S. government\n%agencies must provide notice with such work(s) identifying the U.S.\n%Government material incorporated and stating that such material is not\n%subject to copyright protection.\n%\n%Derived works shall not identify themselves in a manner that implies an\n%endorsement by or an affiliation with the Naval Research Laboratory.\n%\n%RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF THE\n%SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY THE NAVAL\n%RESEARCH LABORATORY FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE ACTIONS\n%OF RECIPIENT IN THE USE OF THE SOFTWARE.\n", "meta": {"author": "USNavalResearchLaboratory", "repo": "TrackerComponentLibrary", "sha": "9f6e329de5be06a371757c4b853200beb6def2d0", "save_path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary", "path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary/TrackerComponentLibrary-9f6e329de5be06a371757c4b853200beb6def2d0/Clustering_and_Mixture_Reduction/GaussMixISEMeanGrads.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894745194283, "lm_q2_score": 0.8311430499496096, "lm_q1q2_score": 0.7436980529148861}} {"text": "% VAR - variance of memory mapped underlying array\n%\n% Author: Arnaud Delorme, SCCN, INC, UCSD, Nov. 2008\n\n% Copyright (C) 2008 Arnaud Delorme, SCCN, INC, UCSD\n%\n% This file is part of EEGLAB, see http://www.eeglab.org\n% for the documentation and details.\n%\n% Redistribution and use in source and binary forms, with or without\n% modification, are permitted provided that the following conditions are met:\n%\n% 1. Redistributions of source code must retain the above copyright notice,\n% this list of conditions and the following disclaimer.\n%\n% 2. Redistributions in binary form must reproduce the above copyright notice,\n% this list of conditions and the following disclaimer in the documentation\n% and/or other materials provided with the distribution.\n%\n% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE\n% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\n% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF\n% THE POSSIBILITY OF SUCH DAMAGE.\n\nfunction sumval = var(obj,flag,dim)\n \n if nargin < 2\n flag = 0;\n end\n if nargin < 3\n dim = 1;\n end\n \n meanvalsq = mean(obj,dim).^2;\n \n sumval = 0;\n s1 = size(obj);\n ss.type = '()';\n ss.subs(1:length(s1)) = { ':' };\n for index = 1:s1(dim)\n ss.subs{dim} = index;\n tmpdata = subsref(obj, ss);\n sumval = sumval + tmpdata.*tmpdata - meanvalsq;\n end\n if isempty(flag) || flag == 0\n sumval = sumval/(size(obj,dim)-1);\n else sumval = sumval/size(obj,dim);\n end\n", "meta": {"author": "sccn", "repo": "eeglab", "sha": "36d3982a63cde83fb279ab465b7a026ec2807c0a", "save_path": "github-repos/MATLAB/sccn-eeglab", "path": "github-repos/MATLAB/sccn-eeglab/eeglab-36d3982a63cde83fb279ab465b7a026ec2807c0a/functions/@mmo/var.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8947894745194281, "lm_q2_score": 0.8311430436757312, "lm_q1q2_score": 0.7436980473010857}} {"text": "function [n,V,p] = affine_fit(X,W)\n %Computes the plane that fits best (lest square of the normal distance\n %to the plane) a set of sample points.\n %INPUTS:\n %\n %X: a N by 3 matrix where each line is a sample point\n %\n %OUTPUTS:\n %\n %n : a unit (column) vector normal to the plane\n %V : a 3 by 2 matrix. The columns of V form an orthonormal basis of the\n %plane\n %p : a point belonging to the plane\n %\n %NB: this code actually works in any dimension (2,3,4,...)\n %Author: Adrien Leygue\n %Date: August 30 2013\n\n if nargin<2\n W = 1/size(X,1)*ones(size(X,1),1);\n end\n W = W(:)./sum(W);\n \n %the mean of the samples belongs to the plane\n p = sum(bsxfun(@times,W,X));\n \n %The samples are reduced:\n R = bsxfun(@times,bsxfun(@minus,X,p),W);\n %Computation of the principal directions if the samples cloud\n [V,D] = eig(R'*R);\n %Extract the output from the eigenvectors\n n = V(:,1);\n V = V(:,2:end);\nend\n\n% Copyright (c) 2013, Adrien Leygue\n% All rights reserved.\n% \n% Redistribution and use in source and binary forms, with or without\n% modification, are permitted provided that the following conditions are\n% met:\n% \n% * Redistributions of source code must retain the above copyright\n% notice, this list of conditions and the following disclaimer.\n% * Redistributions in binary form must reproduce the above copyright\n% notice, this list of conditions and the following disclaimer in\n% the documentation and/or other materials provided with the distribution\n% \n% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE\n% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\n% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n% POSSIBILITY OF SUCH DAMAGE.\n", "meta": {"author": "alecjacobson", "repo": "gptoolbox", "sha": "a0cb37d8edbcfb1e3587f793df8f24c76a2d7305", "save_path": "github-repos/MATLAB/alecjacobson-gptoolbox", "path": "github-repos/MATLAB/alecjacobson-gptoolbox/gptoolbox-a0cb37d8edbcfb1e3587f793df8f24c76a2d7305/external/affine_fit.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894604912848, "lm_q2_score": 0.8311430436757312, "lm_q1q2_score": 0.7436980356416919}} {"text": "function B = barymat(y, x, w, s, r, doFlip)\n%BARYMAT Barycentric Interpolation Matrix.\n% BARYMAT(Y, X, W), where Y is a column vector of length M and X and W are\n% column and row vectors of length N, respectively, returns the M*N matrix\n% which interpolates data from the grid X to the grid Y using the 2nd-kind\n% barycentric interpolation formula with barycentric weights W. If W is not\n% supplied it is assumed to be the weights for polynomial interpolation at a\n% 2nd-kind Chebyshev grid: W(j) = (-1)^j, W([1, N]) = 0.5*W([1, N]).\n%\n% BARYMAT(Y, X, W, S, R) is the same, where S = acos(Y) and R = acos(X). The\n% purpose of this is that Y(j) - X(k) can be more accurately computed in this\n% 'theta space'. This is sometimes referred to as the 'trig trick' in spectral\n% collocation. BARYMAT(Y, X, W, S, R, 1) also performs the 'flipping trick', \n% which takes advantage of the fact that the smaller entries in R and S can be\n% computed more accurately. Note that X and Y should be symmetric about zero\n% for this work, and it is assumed that S and R are sorted in descending\n% order.\n\n% Copyright 2017 by The University of Oxford and The Chebfun Developers.\n% See http://www.chebfun.org/ for Chebfun information.\n\nif ( isempty(y) || isempty(x) )\n % Nothing to do here!\n B = []; \n return\nend\n\nif ( size(x, 2) > 1 || size(y, 2) > 1 )\n error('CHEBFUN:barymat:dims', 'Inputs should be column vectors.');\nend\n\n% Obtain lengths of inputs:\nN = length(x);\nM = length(y);\n\n% Nothing to do here!\nif ( M == N && all(x == y) ) \n B = eye(N); \n return\nend\n \n% Default to the Chebyshev barycentric weights:\nif ( nargin < 3 || isempty(w) ) \n w = ones(1, N); \n w(2:2:end) = -1; \n w([1, N]) = 0.5*w([1, N]);\nelse\n % Ensure w is a row vector:\n w = reshape(w, 1, N);\nend\n\n% Repmat(Y-X'):\nif ( nargin < 5 )\n B = bsxfun(@minus, y, x.'); \nelse\n % Use the 'trig trick' that y-x = cos(s)-cos(r) = 2*sin((s+r)/2)*sin((r-s)/2).\n B = 2*bsxfun(@(r, s) sin((s+r)/2).* sin((r-s)/2), r.', s);\nend\n\n% Construct the matrix:\nif ( M >= 500 && N >= 1000 ) % <-- Experimentally determined.\n % Testing shows BSXFUN is faster in this regime\n B = bsxfun(@rdivide, w, B); % w(k)/(y(j)-x(k))\n B = bsxfun(@rdivide, B, sum(B, 2)); % Normalisation.\nelse\n % Else use FOR loops\n for k = 1:N\n B(:,k) = w(k)./B(:,k); % w(k)/(y(j)-x(k))\n end\n c = 1./sum(B, 2); % Normalisation.\n for j = 1:M\n B(j,:) = B(j,:)*c(j);\n end\nend\n\n% Where points coincide there will be division by zeros (as with bary.m).\n% Replace these entries with the identity:\nB(isnan(B)) = 1;\n\n% Flipping trick:\nif ( nargin > 5 && doFlip )\n ii = logical(rot90(tril(ones(M, N)), 2)); \n ii = fliplr(ii);\n rot90D = rot90(B, 2);\n B(ii) = rot90D(ii);\n B(isnan(B)) = 1;\nend\n\nend\n", "meta": {"author": "chebfun", "repo": "chebfun", "sha": "8c49396a55e46ddd57a1d108c6a8f32e37536d54", "save_path": "github-repos/MATLAB/chebfun-chebfun", "path": "github-repos/MATLAB/chebfun-chebfun/chebfun-8c49396a55e46ddd57a1d108c6a8f32e37536d54/barymat.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894576856559, "lm_q2_score": 0.8311430415844384, "lm_q1q2_score": 0.7436980314385462}} {"text": "%CORRECTMATCHES Refines coordinates of corresponding points\n%\n% [newPoints1, newPoints2] = cv.correctMatches(F, points1, points2)\n%\n% ## Input\n% * __F__ 3x3 fundamental matrix.\n% * __points1__ first set of 2D points. A numeric Nx2/Nx1x2/1xNx2 array or a\n% cell array of 2-element vectors `{[x,y], ...}` (floating-point precision).\n% * __points2__ second set of 2D points. Same size and type as `points1`.\n%\n% ## Output\n% * __newPoints1__ The optimized `points1`. Similar in shape to `points1`\n% (either Nx2/1xNx2 numeric array or cell array of 2D points).\n% * __newPoints2__ The optimized `points2`.\n%\n% The function implements the Optimal Triangulation Method (see [Hartley2004]\n% for details). For each given point correspondence `points1[i] <-> points2[i]`,\n% and a fundamental matrix `F`, it computes the corrected correspondences\n% `newPoints1[i] <-> newPoints2[i]` that minimize the geometric error:\n%\n% d(points1[i], newPoints1[i])^2 + d(points2[i], newPoints2[i])^2\n%\n% (where `d(a,b)` is the geometric distance between points `a` and `b`)\n% subject to the epipolar constraint\n%\n% newPoints2' * F * newPoints1 = 0\n%\n% ## References\n% [Hartley2004]:\n% > R.I. Hartley and A. Zisserman. \"Multiple View Geometry in Computer Vision\"\n% > Cambridge University Press, 2004.\n%\n% See also: cv.findFundamentalMat\n%\n", "meta": {"author": "kyamagu", "repo": "mexopencv", "sha": "d29007b2a484d0fd92e6e941dc5fd4750014fa6a", "save_path": "github-repos/MATLAB/kyamagu-mexopencv", "path": "github-repos/MATLAB/kyamagu-mexopencv/mexopencv-d29007b2a484d0fd92e6e941dc5fd4750014fa6a/+cv/correctMatches.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009480320036, "lm_q2_score": 0.8128673201042492, "lm_q1q2_score": 0.7436930817876117}} {"text": "function jac = p17_jac ( neqn, t, y )\n\n%*****************************************************************************80\n%\n%% P17_JAC evaluates the jacobian for problem p17.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 23 February 2013\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer NEQN, the number of equations.\n%\n% Input, real T, Y(NEQN), the arguments of the jacobian.\n%\n% Output, real JAC(NEQN,NEQN), the jacobian matrix.\n%\n jac = zeros ( neqn, neqn );\n\n d = ( sqrt ( ( y(1).^2 + y(2).^2 ) ) ).^5;\n\n jac(1,3) = 1.0;\n jac(2,4) = 1.0;\n jac(3,1) = ( 2.0 * y(1).^2 - y(2).^2 ) / d;\n jac(3,2) = 3.0 * y(1) * y(2) / d;\n jac(4,1) = 3.0 * y(1) * y(2) / d;\n jac(4,2) = ( - y(1).^2 + 2.0 * y(2).^2 ) / d;\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_ode/p17_jac.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.914900950352329, "lm_q2_score": 0.8128673178375734, "lm_q1q2_score": 0.7436930815999445}} {"text": "% [PYR, INDICES] = buildSCFpyrLevs(LODFT, LOGRAD, XRCOS, YRCOS, ANGLE, HEIGHT, NBANDS)\n%\n% Recursive function for constructing levels of a steerable pyramid. This\n% is called by buildSCFpyr, and is not usually called directly.\n\n% Original code: Eero Simoncelli, 5/97.\n% Modified by Javier Portilla to generate complex bands in 9/97.\n\nfunction [pyr,pind] = buildSCFpyrLevs(lodft,log_rad,Xrcos,Yrcos,angle,ht,nbands);\n\nif (ht <= 0)\n\n lo0 = ifft2(ifftshift(lodft));\n pyr = real(lo0(:));\n pind = size(lo0);\n\nelse\n\n bands = zeros(prod(size(lodft)), nbands);\n bind = zeros(nbands,2);\n\n% log_rad = log_rad + 1;\n Xrcos = Xrcos - log2(2); % shift origin of lut by 1 octave.\n\n lutsize = 1024;\n Xcosn = pi*[-(2*lutsize+1):(lutsize+1)]/lutsize; % [-2*pi:pi]\n order = nbands-1;\n %% divide by sqrt(sum_(n=0)^(N-1) cos(pi*n/N)^(2(N-1)) )\n %% Thanks to Patrick Teo for writing this out :)\n const = (2^(2*order))*(factorial(order)^2)/(nbands*factorial(2*order));\n\n%\n% Ycosn = sqrt(const) * (cos(Xcosn)).^order;\n%\n % analityc version: only take one lobe\n alfa=\tmod(pi+Xcosn,2*pi)-pi;\n Ycosn = 2*sqrt(const) * (cos(Xcosn).^order) .* (abs(alfa) 2\n [UC, jitter] = jitChol(A);\n else\n UC = jitChol(A);\n end\nend\n\nld = 2*sum(log(diag(UC)));\n", "meta": {"author": "SheffieldML", "repo": "GPmat", "sha": "4b5914a38ecbad9fb7a13a3392970bfc28c9d911", "save_path": "github-repos/MATLAB/SheffieldML-GPmat", "path": "github-repos/MATLAB/SheffieldML-GPmat/GPmat-4b5914a38ecbad9fb7a13a3392970bfc28c9d911/ndlutil/logdet.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009503523291, "lm_q2_score": 0.8128673110375457, "lm_q1q2_score": 0.7436930753785929}} {"text": "function [J grad] = nnCostFunction(nn_params, ...\n input_layer_size, ...\n hidden_layer_size, ...\n num_labels, ...\n X, y, lambda)\n%NNCOSTFUNCTION Implements the neural network cost function for a two layer\n%neural network which performs classification\n% [J grad] = NNCOSTFUNCTON(nn_params, hidden_layer_size, num_labels, ...\n% X, y, lambda) computes the cost and gradient of the neural network. The\n% parameters for the neural network are \"unrolled\" into the vector\n% nn_params and need to be converted back into the weight matrices. \n% \n% The returned parameter grad should be a \"unrolled\" vector of the\n% partial derivatives of the neural network.\n%\n\n% Reshape nn_params back into the parameters Theta1 and Theta2, the weight matrices\n% for our 2 layer neural network\nTheta1 = reshape(nn_params(1:hidden_layer_size * (input_layer_size + 1)), ...\n hidden_layer_size, (input_layer_size + 1));\n\nTheta2 = reshape(nn_params((1 + (hidden_layer_size * (input_layer_size + 1))):end), ...\n num_labels, (hidden_layer_size + 1));\n\n% Setup some useful variables\nm = size(X, 1);\n \n% You need to return the following variables correctly \nJ = 0;\nTheta1_grad = zeros(size(Theta1));\nTheta2_grad = zeros(size(Theta2));\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: You should complete the code by working through the\n% following parts.\n%\n% Part 1: Feedforward the neural network and return the cost in the\n% variable J. After implementing Part 1, you can verify that your\n% cost function computation is correct by verifying the cost\n% computed in ex4.m\n\n\n% Add ones to the X data matrix\nX = [ones(m, 1) X];\n% Convert y from (1-10) class into num_labels vector\nyd = eye(num_labels);\ny = yd(y,:);\n \n%%% Map from Layer 1 to Layer 2\na1=X;\n% Coverts to matrix of 5000 examples x 26 thetas\nz2=X*Theta1';\n% Sigmoid function converts to p between 0 to 1\na2=sigmoid(z2);\n\n%%% Map from Layer 2 to Layer 3\n% Add ones to the h1 data matrix\na2=[ones(m, 1) a2];\n% Converts to matrix of 5000 exampls x num_labels \nz3=a2*Theta2';\n% Sigmoid function converts to p between 0 to 1\na3=sigmoid(z3);\n\n% Compute cost\n%logisf=(-y)'*log(a3)-(1-y)'*log(1-a3);\nlogisf=(-y).*log(a3)-(1-y).*log(1-a3); % Becos y is now a matrix, so use dot product, unlike above\n%J=((1/m).*sum(sum(logisf)));\t% This line is correct if there is no regularization\n% Try with ...\n% J=((1/m).*sum((logisf))); \n% That will give J in 10 columns (it has summed m samples), so need to sum again\n\n%% Regularized cost\nTheta1s=Theta1(:,2:end);\nTheta2s=Theta2(:,2:end);\nJ=((1/m).*sum(sum(logisf)))+(lambda/(2*m)).*(sum(sum(Theta1s.^2))+sum(sum(Theta2s.^2)));\n\n\n% Part 2: Implement the backpropagation algorithm to compute the gradients\n% Theta1_grad and Theta2_grad. You should return the partial derivatives of\n% the cost function with respect to Theta1 and Theta2 in Theta1_grad and\n% Theta2_grad, respectively. After implementing Part 2, you can check\n% that your implementation is correct by running checkNNGradients\n%\n% Note: The vector y passed into the function is a vector of labels\n% containing values from 1..K. You need to map this vector into a \n% binary vector of 1's and 0's to be used with the neural network\n% cost function.\n%\n% Hint: We recommend implementing backpropagation using a for-loop\n% over the training examples if you are implementing it for the \n% first time.\n%\n% Set all the D to zeros\ntridelta_1=0;\ntridelta_2=0;\n\n% Compute delta, tridelta and big D\n\tdelta_3=a3-y;\n z2=[ones(m,1) z2];\n\tdelta_2=delta_3*Theta2.*sigmoidGradient(z2);\n delta_2=delta_2(:,2:end);\n\ttridelta_1=tridelta_1+delta_2'*a1; % Same size as Theta1_grad (25x401)\n tridelta_2=tridelta_2+delta_3'*a2; % Same size as Theta2_grad (10x26)\n\tTheta1_grad=(1/m).*tridelta_1;\n Theta2_grad=(1/m).*tridelta_2;\n %Theta1_grad=0;\n\t%Theta2_grad=0;\n%end\n\n\n% Part 3: Implement regularization with the cost function and gradients.\n%\n% Hint: You can implement this around the code for\n% backpropagation. That is, you can compute the gradients for\n% the regularization separately and then add them to Theta1_grad\n% and Theta2_grad from Part 2.\n%\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n% -------------------------------------------------------------\n\n% =========================================================================\n\n% Unroll gradients\ngrad = [Theta1_grad(:) ; Theta2_grad(:)];\n\n\nend\n", "meta": {"author": "yhyap", "repo": "machine-learning-coursera", "sha": "fb33f0ad54ff2104660c86b0d26456b15029a798", "save_path": "github-repos/MATLAB/yhyap-machine-learning-coursera", "path": "github-repos/MATLAB/yhyap-machine-learning-coursera/machine-learning-coursera-fb33f0ad54ff2104660c86b0d26456b15029a798/mlclass-ex4/nnCostFunction.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391621868804, "lm_q2_score": 0.8056321959813275, "lm_q1q2_score": 0.7436300672093812}} {"text": "function [model, L] = ppcaVb(X, q, prior)\n% Perform variatioanl Bayeisan inference for probabilistic PCA model. \n% Input:\n% X: d x n data matrix\n% q: dimension of target space\n% Output:\n% model: trained model structure\n% L: variantional lower bound\n% Reference: \n% Pattern Recognition and Machine Learning by Christopher M. Bishop \n% Written by Mo Chen (sth4nth@gmail.com).\n[m,n] = size(X);\nif nargin < 3\n a0 = 1e-4;\n b0 = 1e-4;\n c0 = 1e-4;\n d0 = 1e-4;\nelse\n a0 = prior.a;\n b0 = prior.b;\n c0 = prior.c;\n d0 = prior.d;\nend\n\nif nargin < 2\n q = m-1;\nend\ntol = 1e-6;\nmaxIter = 500;\nL = -inf(1,maxIter);\n\nmu = mean(X,2);\nXo = bsxfun(@minus, X, mu);\ns = dot(Xo(:),Xo(:));\nI = eye(q);\n% init parameters\na = a0+m/2;\nc = c0+m*n/2;\nEalpha = 1e-4;\nEbeta = 1e-4;\nEW = rand(q,m); \nEWo = bsxfun(@minus,EW,mean(EW,2));\nEWW = EWo*EWo'/m+EW*EW';\nfor iter = 2:maxIter \n% q(z)\n LZ = I+Ebeta*EWW;\n V = inv(chol(LZ)); % inv(LZ) = V*V';\n EZ = LZ\\EW*Xo*Ebeta;\n EZZ = n*(V*V')+EZ*EZ';\n KLZ = n*sum(log(diag(V))); % KLZ = 0.5*n*log(det(inv(LZ)));\n% q(w)\n LW = diag(Ealpha)+Ebeta*EZZ;\n V = inv(chol(LW)); % inv(LW) = V*V'; \n EW = LW\\EZ*Xo'*Ebeta;\n EWW = m*(V*V')+EW*EW';\n KLW = m*sum(log(diag(V))); % KLW = 0.5*n*log(det(inv(LW)));\n% q(alpha)\n b = b0+diag(EWW)/2;\n Ealpha = a./b;\n KLalpha = -sum(a*log(b));\n% q(beta)\n WZ = EW'*EZ;\n d = d0+(s-2*dot(Xo(:),WZ(:))+dot(EWW(:),EZZ(:)))/2;\n Ebeta = c/d;\n KLbeta = -c*log(d);\n% q(mu)\n% Emu = Ebeta/(lambda+n*Ebeta)*sum(X-WZ,2);\n\n% lower bound\n L(iter) = KLalpha+KLbeta+KLW+KLZ;\n if L(iter)-L(iter-1) < tol*abs(L(iter-1)); break; end \nend\nL = L(2:iter);\n\nmodel.Z = EZ;\nmodel.W = EW;\nmodel.apha = Ealpha;\nmodel.beta = Ebeta;\nmodel.a = a;\nmodel.b = b;\nmodel.c = c;\nmodel.d = d;\nmodel.mu = mu;", "meta": {"author": "PRML", "repo": "PRMLT", "sha": "baac49f643db6b39e75307d3b21307b32b29a7a9", "save_path": "github-repos/MATLAB/PRML-PRMLT", "path": "github-repos/MATLAB/PRML-PRMLT/PRMLT-baac49f643db6b39e75307d3b21307b32b29a7a9/chapter12/ppcaVb.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391685381605, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.743630065864836}} {"text": "function ellipse_t = ellFit(x,y,axis_handle,colorStr)\n% Finds the best fit to an ellipse for the given set of points.\n% http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=3215&objectType=File \n%\n% Format: ellipse_t = ellFit( x,y, [axis_handle])\n%\n% Input: x,y - a set of points in 2 column vectors. AT LEAST 5 points are needed !\n% axis_handle - optional. a handle to an axis, at which the estimated ellipse \n% will be drawn along with it's axes\n%\n% Output: ellipse_t - structure that defines the best fit to an ellipse\n% a - sub axis (radius) of the X axis of the non-tilt ellipse\n% b - sub axis (radius) of the Y axis of the non-tilt ellipse\n% phi - orientation in radians of the ellipse (tilt)\n% X0 - center at the X axis of the non-tilt ellipse\n% Y0 - center at the Y axis of the non-tilt ellipse\n% X0_in - center at the X axis of the tilted ellipse\n% Y0_in - center at the Y axis of the tilted ellipse\n% long_axis - size of the long axis of the ellipse\n% short_axis - size of the short axis of the ellipse\n% status - status of detection of an ellipse\n%\n% Note: if an ellipse was not detected (but a parabola or hyperbola), then\n% an empty structure is returned\n%\n% Example: (Verify recovery)\n% a = 1.45; b = 3.2; theta = 0.15; radSpacing = 0.05;\n% [x,y] = ellipsePoints(a,b,theta,radSpacing);\n% figure(1), plot(x,y,'-'); axis equal\n% ellS = ellFit(x,y);\n% [ellS.a, ellS.b, ellS.phi]\n% [a, b, theta] \n%\n% a = 1.45; b = 3.2; theta = pi/5; radSpacing = 0.05;\n% [x,y] = ellipsePoints(a,b,theta,radSpacing);\n% figure(1), plot(x,y,'-'); axis equal\n% for ii=1:10\n% ellS = ellFit(x + randn(size(x))/5, y + randn(size(y))/5);\n% aHat(ii) = ellS.a; bHat(ii) = ellS.b; thetaHat(ii) = ellS.phi;\n% end\n% [mean(aHat), mean(bHat), mean(thetaHat)]\n%\n% ellS = ellFit(x,y,figure(1));\n\n%\n% =====================================================================================\n% Ellipse Fit using Least Squares criterion\n% =====================================================================================\n% We will try to fit the best ellipse to the given measurements. the mathematical\n% representation of use will be the CONIC Equation of the Ellipse which is:\n% \n% Ellipse = a*x^2 + b*x*y + c*y^2 + d*x + e*y + f = 0\n% \n% The fit-estimation method of use is the Least Squares method (without any weights)\n% The estimator is extracted from the following equations:\n%\n% g(x,y;A) := a*x^2 + b*x*y + c*y^2 + d*x + e*y = f\n%\n% where:\n% A - is the vector of parameters to be estimated (a,b,c,d,e)\n% x,y - is a single measurement\n%\n% We will define the cost function to be:\n%\n% Cost(A) := (g_c(x_c,y_c;A)-f_c)'*(g_c(x_c,y_c;A)-f_c)\n% = (X*A+f_c)'*(X*A+f_c) \n% = A'*X'*X*A + 2*f_c'*X*A + N*f^2\n%\n% where:\n% g_c(x_c,y_c;A) - vector function of ALL the measurements\n% each element of g_c() is g(x,y;A)\n% X - a matrix of the form: [x_c.^2, x_c.*y_c, y_c.^2, x_c, y_c ]\n% f_c - is actually defined as ones(length(f),1)*f\n%\n% Derivation of the Cost function with respect to the vector of parameters \"A\" yields:\n%\n% A'*X'*X = -f_c'*X = -f*ones(1,length(f_c))*X = -f*sum(X)\n%\n% Which yields the estimator:\n%\n% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n% | A_least_squares = -f*sum(X)/(X'*X) ->(normalize by -f) = sum(X)/(X'*X) |\n% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%\n% (We will normalize the variables by (-f) since \"f\" is unknown and can be accounted for later on)\n% \n% NOW, all that is left to do is to extract the parameters from the Conic Equation.\n% We will deal the vector A into the variables: (A,B,C,D,E) and assume F = -1;\n%\n% Recall the conic representation of an ellipse:\n% \n% A*x^2 + B*x*y + C*y^2 + D*x + E*y + F = 0\n% \n% We will check if the ellipse has a tilt (=orientation). The orientation is present\n% if the coefficient of the term \"x*y\" is not zero. If so, we first need to remove the\n% tilt of the ellipse.\n%\n% If the parameter \"B\" is not equal to zero, then we have an orientation (tilt) to the ellipse.\n% we will remove the tilt of the ellipse so as to remain with a conic representation of an \n% ellipse without a tilt, for which the math is more simple:\n%\n% Non tilt conic rep.: A`*x^2 + C`*y^2 + D`*x + E`*y + F` = 0\n%\n% We will remove the orientation using the following substitution:\n% \n% Replace x with cx+sy and y with -sx+cy such that the conic representation is:\n% \n% A(cx+sy)^2 + B(cx+sy)(-sx+cy) + C(-sx+cy)^2 + D(cx+sy) + E(-sx+cy) + F = 0\n%\n% where: c = cos(phi) , s = sin(phi)\n%\n% and simplify...\n%\n% x^2(A*c^2 - Bcs + Cs^2) + xy(2A*cs +(c^2-s^2)B -2Ccs) + ...\n% y^2(As^2 + Bcs + Cc^2) + x(Dc-Es) + y(Ds+Ec) + F = 0\n%\n% The orientation is easily found by the condition of (B_new=0) which results in:\n% \n% 2A*cs +(c^2-s^2)B -2Ccs = 0 ==> phi = 1/2 * atan( b/(c-a) )\n% \n% Now the constants c=cos(phi) and s=sin(phi) can be found, and from them\n% all the other constants A`,C`,D`,E` can be found.\n%\n% A` = A*c^2 - B*c*s + C*s^2 D` = D*c-E*s\n% B` = 2*A*c*s +(c^2-s^2)*B -2*C*c*s = 0 E` = D*s+E*c \n% C` = A*s^2 + B*c*s + C*c^2\n%\n% Next, we want the representation of the non-tilted ellipse to be as:\n%\n% Ellipse = ( (X-X0)/a )^2 + ( (Y-Y0)/b )^2 = 1\n%\n% where: (X0,Y0) is the center of the ellipse\n% a,b are the ellipse \"radiuses\" (or sub-axis)\n%\n% Using a square completion method we will define:\n% \n% F`` = -F` + (D`^2)/(4*A`) + (E`^2)/(4*C`)\n%\n% Such that: a`*(X-X0)^2 = A`(X^2 + X*D`/A` + (D`/(2*A`))^2 )\n% c`*(Y-Y0)^2 = C`(Y^2 + Y*E`/C` + (E`/(2*C`))^2 )\n%\n% which yields the transformations:\n% \n% X0 = -D`/(2*A`)\n% Y0 = -E`/(2*C`)\n% a = sqrt( abs( F``/A` ) )\n% b = sqrt( abs( F``/C` ) )\n%\n% And finally we can define the remaining parameters:\n%\n% long_axis = 2 * max( a,b )\n% short_axis = 2 * min( a,b )\n% Orientation = phi\n%\n%\n\nif notDefined('colorStr');\n colorStr = 'r';\nend\n% initialize\norientation_tolerance = 1e-3;\n\n% empty warning stack\nwarning( '' );\n\n% prepare vectors, must be column vectors\nx = x(:);\ny = y(:);\n\n% remove bias of the ellipse - to make matrix inversion more accurate. (will be added later on).\nmean_x = mean(x);\nmean_y = mean(y);\nx = x-mean_x;\ny = y-mean_y;\n\n% the estimation for the conic equation of the ellipse\nX = [x.^2, x.*y, y.^2, x, y ];\na = sum(X)/(X'*X);\n\n% check for warnings\nif ~isempty( lastwarn )\n disp( 'stopped because of a warning regarding matrix inversion' );\n ellipse_t = [];\n return\nend\n\n% extract parameters from the conic equation\n[a,b,c,d,e] = deal( a(1),a(2),a(3),a(4),a(5) );\n\n% remove the orientation from the ellipse\nif ( min(abs(b/a),abs(b/c)) > orientation_tolerance )\n \n orientation_rad = 1/2 * atan( b/(c-a) );\n cos_phi = cos( orientation_rad );\n sin_phi = sin( orientation_rad );\n [a,b,c,d,e] = deal(...\n a*cos_phi^2 - b*cos_phi*sin_phi + c*sin_phi^2,...\n 0,...\n a*sin_phi^2 + b*cos_phi*sin_phi + c*cos_phi^2,...\n d*cos_phi - e*sin_phi,...\n d*sin_phi + e*cos_phi );\n [mean_x,mean_y] = deal( ...\n cos_phi*mean_x - sin_phi*mean_y,...\n sin_phi*mean_x + cos_phi*mean_y );\nelse\n orientation_rad = 0;\n cos_phi = cos( orientation_rad );\n sin_phi = sin( orientation_rad );\nend\n\n% check if conic equation represents an ellipse\ntest = a*c;\nswitch (1)\ncase (test>0), status = '';\ncase (test==0), status = 'Parabola found'; warning( 'fit_ellipse: Did not locate an ellipse' );\ncase (test<0), status = 'Hyperbola found'; warning( 'fit_ellipse: Did not locate an ellipse' );\nend\n\n% if we found an ellipse return it's data\nif (test>0)\n \n % make sure coefficients are positive as required\n if (a<0), [a,c,d,e] = deal( -a,-c,-d,-e ); end\n \n % final ellipse parameters\n X0 = mean_x - d/2/a;\n Y0 = mean_y - e/2/c;\n F = 1 + (d^2)/(4*a) + (e^2)/(4*c);\n [a,b] = deal( sqrt( F/a ),sqrt( F/c ) ); \n long_axis = 2*max(a,b);\n short_axis = 2*min(a,b);\n\n % rotate the axes backwards to find the center point of the original TILTED ellipse\n R = [ cos_phi sin_phi; -sin_phi cos_phi ];\n P_in = R * [X0;Y0];\n X0_in = P_in(1);\n Y0_in = P_in(2);\n \n % pack ellipse into a structure\n ellipse_t = struct( ...\n 'a',a,...\n 'b',b,...\n 'phi',orientation_rad,...\n 'X0',X0,...\n 'Y0',Y0,...\n 'X0_in',X0_in,...\n 'Y0_in',Y0_in,...\n 'long_axis',long_axis,...\n 'short_axis',short_axis,...\n 'status','' );\nelse\n % report an empty structure\n ellipse_t = struct( ...\n 'a',[],...\n 'b',[],...\n 'phi',[],...\n 'X0',[],...\n 'Y0',[],...\n 'X0_in',[],...\n 'Y0_in',[],...\n 'long_axis',[],...\n 'short_axis',[],...\n 'status',status );\nend\n\n% check if we need to plot an ellipse with it's axes.\nif (nargin>2) && ~isempty( axis_handle ) && (test>0)\n \n % rotation matrix to rotate the axes with respect to an angle phi\n R = [ cos_phi sin_phi; -sin_phi cos_phi ];\n \n % the axes\n ver_line = [ [X0 X0]; Y0+b*[-1 1] ];\n horz_line = [ X0+a*[-1 1]; [Y0 Y0] ];\n new_ver_line = R*ver_line;\n new_horz_line = R*horz_line;\n \n % the ellipse\n theta_r = linspace(0,2*pi);\n ellipse_x_r = X0 + a*cos( theta_r );\n ellipse_y_r = Y0 + b*sin( theta_r );\n rotated_ellipse = R * [ellipse_x_r;ellipse_y_r];\n \n % draw\n hold_state = get( axis_handle,'NextPlot' );\n set( axis_handle,'NextPlot','add' );\n% plot( new_ver_line(1,:),new_ver_line(2,:),colorStr );\n% plot( new_horz_line(1,:),new_horz_line(2,:),colorStr );\n plot( rotated_ellipse(1,:),rotated_ellipse(2,:),colorStr );\n set( axis_handle,'NextPlot',hold_state );\nend\n", "meta": {"author": "vistalab", "repo": "vistasoft", "sha": "7f0102c696c091c858233340cc7e1ab02f064d4c", "save_path": "github-repos/MATLAB/vistalab-vistasoft", "path": "github-repos/MATLAB/vistalab-vistasoft/vistasoft-7f0102c696c091c858233340cc7e1ab02f064d4c/mrBOLD/Stats/ellipse/ellFit.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391685381605, "lm_q2_score": 0.8056321866478978, "lm_q1q2_score": 0.7436300637110557}} {"text": "% Flush out the MATLAB.\nclose all;\nclc;\nclear all;\n\n\n% Read the desired image file.\nImageData=imread('BC.jpg');\n\n\n% Calculate the number of pixels.\nNoOfPixel=size(ImageData,1)*size(ImageData,2);\n\n\n% Display the original image.\nfigure,imshow(ImageData);\ntitle(' Original Image without Histogram: ');\n\n\n% Histogram image implementation.\nHistogramImage=uint8(zeros(size(ImageData,1),size(ImageData,2)));\n\nFrequency=zeros(256,1);\n\nProbabilityFrequency=zeros(256,1);\n\nProbabilityC=zeros(256,1);\n\nCumulative=zeros(256,1);\n\nOutputZeros=zeros(256,1);\n\n\n% Cumulative histogram for each and every pixel og image.\nfor a=1:size(ImageData,1)\n \n for b=1:size(ImageData,2) \n FinalValue=ImageData(a,b);\n \n Frequency(FinalValue+1)=Frequency(FinalValue+1)+1;\n \n ProbabilityFrequency(FinalValue+1)=Frequency(FinalValue+1)/NoOfPixel;\n end\n \nend\n\nFinalSum=0;\n\nNumberBin=255;\n\n\n% Distributation probability for each and every pixel.\nfor a=1:size(ProbabilityFrequency) \n FinalSum=FinalSum+Frequency(a);\n \n Cumulative(a)=FinalSum;\n \n ProbabilityC(a)=Cumulative(a)/NoOfPixel;\n \n OutputZeros(a)=round(ProbabilityC(a)*NumberBin);\nend\n\n\n% Final calculation.\nfor a=1:size(ImageData,1)\n \n for b=1:size(ImageData,2) \n HistogramImage(a,b)=OutputZeros(ImageData(a,b)+1);\n end\n \nend\n\n\n% Display the output image.\nfigure,imshow(HistogramImage);\ntitle(' Final Image with Histogram: ');", "meta": {"author": "zhangqianqianQQ", "repo": "MachineVisionAlgorithm", "sha": "683338f6c3b1aab9fa2b80026915fe936aebf0ee", "save_path": "github-repos/MATLAB/zhangqianqianQQ-MachineVisionAlgorithm", "path": "github-repos/MATLAB/zhangqianqianQQ-MachineVisionAlgorithm/MachineVisionAlgorithm-683338f6c3b1aab9fa2b80026915fe936aebf0ee/\u589e\u5f3a\u7b97\u6cd5/Histogram-Equalization-Logarithmic-Mapping-Image-Rotation-Gaussian-Averaging-Filter-Median-Filter-master/HistogramEqualization/HistogramEqualization.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391643039738, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.743630062453639}} {"text": "% Calculate the log mel filter bank from waveform\n% Author: Xiao Xiong\n% Created: 4 Feb 2005\n% Last modified: 4 Feb 2005\n \nfunction [fbank] = wav2fbank(x, fs, frame_shift, nMel)\nif nargin < 2\n fs = 8000;\nend\nif nargin < 3\n frame_shift = 0.01;\nend\nif nargin<4\n nMel = 23;\nend\n\nabsX = wav2abs(x,fs,frame_shift);\nfbank = log (abs2Mel(absX, fs, nMel));\n", "meta": {"author": "singaxiong", "repo": "SignalGraph", "sha": "e86d973556ae8796a05ee2adbd665f47c8525a21", "save_path": "github-repos/MATLAB/singaxiong-SignalGraph", "path": "github-repos/MATLAB/singaxiong-SignalGraph/SignalGraph-e86d973556ae8796a05ee2adbd665f47c8525a21/signal/feature/wav2fbank.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9230391558355999, "lm_q2_score": 0.8056321796478255, "lm_q1q2_score": 0.7436300470161232}} {"text": "function [ fa ] = gsp_cfa( T,fs )\n%GSP_CFA Create frequency axis\n% Usage: fa = gsp_cfa(N);\n% fa = gsp_cfa(N,fs);\n%\n% Input parameters:\n% N : Number of samples\n% fs : Sampling frequency (default 1)\n% Ouput parameters:\n% fa : Frequency axis\n% \n% This function create a normalized frequency axis corresponding to the\n% frequency of the function fft.\n%\n\n% Author: Nathanael Perraudin\n\nif nargin<2\n fs = 1;\nend\n\nif mod(T,2)\n fa = linspace(-0.5+1/(2*T),0.5-1/(2*T),T);\nelse\n fa = linspace(-0.5,0.5-1/T,T);\nend\n\nfa = fa*fs;\n\nfa = ifftshift(fa);\nfa = fa(:);\n\nend\n", "meta": {"author": "epfl-lts2", "repo": "gspbox", "sha": "a7d9aac5e239f1bcb37a9bb09998cc161be2732f", "save_path": "github-repos/MATLAB/epfl-lts2-gspbox", "path": "github-repos/MATLAB/epfl-lts2-gspbox/gspbox-a7d9aac5e239f1bcb37a9bb09998cc161be2732f/utils/gsp_cfa.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9019206870747658, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.7435992651594933}} {"text": "function determ = herndon_determinant ( n )\n\n%*****************************************************************************80\n%\n%% HERNDON_DETERMINANT returns the determinant of the Herndon matrix.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 11 October 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the order of A.\n%\n% Output, real DETERM, the determinant.\n%\n determ = 6.0 / ( ( n + 1 ) * n * ( 5 - 2 * n ) );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_mat/herndon_determinant.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.90192067652954, "lm_q2_score": 0.8244619285331332, "lm_q1q2_score": 0.7435992603554528}} {"text": "function p = predictOneVsAll(all_theta, X)\n%PREDICT Predict whether the label is 0 or 1 using learned logistic \n%regression parameters all_theta\n% p = PREDICT(all_theta, X) computes the predictions for X using a \n% threshold at 0.5 (i.e., if sigmoid(all_theta'*x) >= 0.5, predict 1)\n\nm = size(X, 1);\nnum_labels = size(all_theta, 1);\n\n% You need to return the following variables correctly \np = zeros(size(X, 1), 1);\n\n% Add ones to the X data matrix\nX = [ones(m, 1) X];\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Complete the following code to make predictions using\n% your learned logistic regression parameters (one-vs-all).\n% You should set p to a vector of predictions (from 1 to\n% num_labels).\n%\n% Hint: This code can be done all vectorized using the max function.\n% In particular, the max function can also return the index of the \n% max element, for more information see 'help max'. If your examples \n% are in rows, then, you can use max(A, [], 2) to obtain the max \n% for each row.\n% \n \n% Coverts to matrix of 5000 examples vs. num_lables (each sample has num_labels of corresponding prob\nz=X*all_theta';\n% Sigmoid function converts to p between 0 to 1\nh=sigmoid(z);\n\n% pval returns the highest value in each row, while p returns the position in each row\n[pval, p]=max(h,[],2); \n\n% Later in ex3 file, the p will be used to match the y and predict the training accuracy\n% =========================================================================\n\n\nend\n", "meta": {"author": "yhyap", "repo": "machine-learning-coursera", "sha": "fb33f0ad54ff2104660c86b0d26456b15029a798", "save_path": "github-repos/MATLAB/yhyap-machine-learning-coursera", "path": "github-repos/MATLAB/yhyap-machine-learning-coursera/machine-learning-coursera-fb33f0ad54ff2104660c86b0d26456b15029a798/mlclass-ex3/predictOneVsAll.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267626522814, "lm_q2_score": 0.8558511506439708, "lm_q1q2_score": 0.7435863845262312}} {"text": "function p = predict(theta, X)\n%PREDICT Predict whether the label is 0 or 1 using learned logistic \n%regression parameters theta\n% p = PREDICT(theta, X) computes the predictions for X using a \n% threshold at 0.5 (i.e., if sigmoid(theta'*x) >= 0.5, predict 1)\n\nm = size(X, 1); % Number of training examples\n\n% You need to return the following variables correctly\np = zeros(m, 1);\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Complete the following code to make predictions using\n% your learned logistic regression parameters. \n% You should set p to a vector of 0's and 1's\n%\n\n\nh = sigmoid(X*theta);\nids = find(h>=0.5);\np(ids) = 1;\nids = find(h<0.5);\np(ids) = 0;\n\n\n\n\n\n% =========================================================================\n\n\nend\n", "meta": {"author": "1094401996", "repo": "machine-learning-coursera", "sha": "e53d1021a08b0f2ab7e0840d9807ab14e24ea9bb", "save_path": "github-repos/MATLAB/1094401996-machine-learning-coursera", "path": "github-repos/MATLAB/1094401996-machine-learning-coursera/machine-learning-coursera-e53d1021a08b0f2ab7e0840d9807ab14e24ea9bb/problem_sets/ex2/predict.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.868826769445233, "lm_q2_score": 0.8558511396138365, "lm_q1q2_score": 0.7435863807567106}} {"text": "function determ = wilk21_determinant ( n )\n\n%*****************************************************************************80\n%\n%% WILK21_DETERMINANT computes the determinant of the WILK21 matrix.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 22 November 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the order of the matrix.\n%\n% Output, real DETERM, the determinant.\n%\n d = zeros ( n, 1 );\n\n for i = 1 : n\n d(i) = round ( abs ( i - ( n + 1 ) / 2 ) );\n end\n\n determ_nm1 = d(n);\n\n if ( n == 1 )\n determ = determ_nm1;\n return\n end\n\n determ_nm2 = determ_nm1;\n determ_nm1 = d(n-1) * d(n) - 1.0;\n\n if ( n == 2 )\n determ = determ_nm1;\n return\n end\n\n for i = n - 2 : -1 : 1\n\n determ = d(i) * determ_nm1 - determ_nm2;\n\n determ_nm2 = determ_nm1;\n determ_nm1 = determ;\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_mat/wilk21_determinant.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511322604134, "lm_q2_score": 0.8688267677469952, "lm_q1q2_score": 0.7435863729144211}} {"text": "function turnDir=turnOrientation(v1,v2,v3)\n%%TURNORIENTATION Given 3 two-dimensional vertices in order, determine\n% whether they form a left turn (go counterclockwise).\n% Such a determination is necessary for determining\n% whether a polygon is convex and plays a role in\n% finding the convex hull of a set of points.\n% \n%INPUTS: v1, v2, v3 A set of 3 2XN matrices, of N vertex sets in the order\n% [x;y] These are 2-dimensional vertices in order,\n% whereby one wishes to determine whether the angle\n% v1-v2-v3 is going counterclockwise (left) or clockwise\n% (right) for each set of vertices.\n%\n%OUTPUTS: turnDir An NX1 vector where the ith element is is 1 if the ith\n% set of vertices form a counterclockwise angle, -1 if\n% they are going clockwise and 0 if they are collinear or\n% if two of them coincide.\n% \n%An implementation is given ehre in Matlab. However, the implementation in\n%C++ might be more accurate, assuming that one's compilter implements the\n%long double datatype as an IEEE-754 souble extended precision datatype.\n%A notable exception is Microsoft's Visual Studio (as of 2017), which maps\n%long doubles to doubles (64 bits rather than the 80-bit size of Intel/\n%AMD floating point registers) as noted in \n%https://docs.microsoft.com/en-us/cpp/c-language/type-long-double\n%Additionally, the function exactSignOfSumCPP is used to provide the sign\n%of an error-free sum. Unfortunately, since the IEEE-754 double extended\n%precision datatype only provides a 64-bit mantissa, which is not much of\n%an extension over the 54-bit mantissa of a standard double precision\n%floating point number, and is not enough to assure no finite precision\n%rounding in the products that go into the sum, one cannot guarantee zero\n%finite precision errors in this function. On the other hand, if the\n%inputs are single-precision (promoted to doubles, since the function does\n%not take singles) floating point numbers, the result is exact.\n%\n%The cross product rule for 3D vectors a and b says that\n%norm(cross(a,b))=norm(a)*norm(b)*sin(theta)\n%where theta is the positive angle between the vectors. However, If the\n%vectors are 2D, (set the z-components to zero), then the cross product\n%only have one nonzero component in the z-direction and that component is\n%equal to det([a,b]) (for 2D a and b). The interesting thing now, is that\n%the sign of the determinant will tell you whether the subsequent vectors\n%are going counterclockwise or clockwise. This function returns -1 if the\n%vectors are going counterclockwise, 0 if they are exactly collinear and 1\n%if they are clockwise.\n%\n%The Matlab implementation can be used without a compilation. The compiled\n%version of the algorithm can be obtained using the \n%CompileCLibraries function.\n%\n%The algorithm is run in Matlab using the command format\n%turnDir=turnOrientation(v1,v2,v3);\n%\n%December 2014 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\n S=zeros(6,1);\n S(1)=v3(1)*v1(2);\n S(2)=v1(1)*v2(2);\n S(3)=v2(1)*v3(2);\n S(4)=-v3(1)*v2(2);\n S(5)=-v1(1)*v3(2);\n S(6)=-v2(1)*v1(2);\n\n turnDir=exactSignOfSum(S);\nend\n\n%LICENSE:\n%\n%The source code is in the public domain and not licensed or under\n%copyright. The information and software may be used freely by the public.\n%As required by 17 U.S.C. 403, third parties producing copyrighted works\n%consisting predominantly of the material produced by U.S. government\n%agencies must provide notice with such work(s) identifying the U.S.\n%Government material incorporated and stating that such material is not\n%subject to copyright protection.\n%\n%Derived works shall not identify themselves in a manner that implies an\n%endorsement by or an affiliation with the Naval Research Laboratory.\n%\n%RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF THE\n%SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY THE NAVAL\n%RESEARCH LABORATORY FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE ACTIONS\n%OF RECIPIENT IN THE USE OF THE SOFTWARE.\n", "meta": {"author": "USNavalResearchLaboratory", "repo": "TrackerComponentLibrary", "sha": "9f6e329de5be06a371757c4b853200beb6def2d0", "save_path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary", "path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary/TrackerComponentLibrary-9f6e329de5be06a371757c4b853200beb6def2d0/Mathematical_Functions/Geometry/turnOrientation.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.931462503162843, "lm_q2_score": 0.7981867801399695, "lm_q1q2_score": 0.7434810562206657}} {"text": "\nclear all\nclose all\n\nd1=3;\nd2=5;\nN=100;\n\ndisp('Model order selection');\n\n%m=min([d1,d2])\nm=3;\n\n% Generate true factor matrices\nW1=10*randn(d1,m);\nW2=10*randn(d2,m);\n\n% Observation noise covariance\nsig=1;\nE1=sig*randn(d1,N);\nE2=sig*randn(d2,N);\n\nif m==0\n X1=E1;\n X2=E2;\nelse\n Z=randn(m,N);\n X1=W1*Z+E1;\n X2=W2*Z+E2;\nend\n\nfor i=1:4,\n CVA = spm_cva_prob (X1,X2,i-1);\n L(i)=CVA.L;\n bic(i)=CVA.bic;\n aic(i)=CVA.aic;\nend\nfigure\nplot([0:3],L);\nhold on\nplot([0:3],bic,'r');\nplot([0:3],aic,'g');\nxlabel('Number of Canonical Vectors');\nlegend('LogLike','BIC','AIC');\n\n\n", "meta": {"author": "spm", "repo": "spm12", "sha": "3085dac00ac804adb190a7e82c6ef11866c8af02", "save_path": "github-repos/MATLAB/spm-spm12", "path": "github-repos/MATLAB/spm-spm12/spm12-3085dac00ac804adb190a7e82c6ef11866c8af02/toolbox/mlm/demo_cva_order.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.934395157060208, "lm_q2_score": 0.7956581073313276, "lm_q1q2_score": 0.7434590821660837}} {"text": "function xycoords = latlon2xy(latlon,centerpoint)\n % convert lat,lon list into x,y given a lat-lon centerpoint\n %\n %This function will take coordinates given in latitude and longitude\n %and convert them to and x,y coordinate system with x pointing east, y\n %pointing north.\n \n %The zero point will be set at the point given in centerpoint, where\n %centerpoint is entered as [lat lon].\n \n \n \n lat = latlon(:,1);\n lon = latlon(:,2);\n \n \n \n %Defining the y and x coordinates of each lat and lon\n \n y = deg2km(lat - centerpoint(1));\n \n x = deg2km(lon - centerpoint(2)).*cosd(lat);\n \n %Outputting a vector with column1 = x coords, column2 = y coords\n \n xycoords = [x(:) y(:)];\nend\n\n\n", "meta": {"author": "CelsoReyes", "repo": "zmap7", "sha": "3895fcb3ca3073608abe22ca71960eb082fd0d9a", "save_path": "github-repos/MATLAB/CelsoReyes-zmap7", "path": "github-repos/MATLAB/CelsoReyes-zmap7/zmap7-3895fcb3ca3073608abe22ca71960eb082fd0d9a/src/thomas/etas/latlon2xy2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9343951625409307, "lm_q2_score": 0.7956580903722561, "lm_q1q2_score": 0.7434590706803907}} {"text": "function out = nsamdf_nonlinear_measure(data,fs,winLenRel,shiftLenRel,lagRel,degree,doPlot)\n% nsamdf_nonlinear_measure computes the nonlinearity measure L through nsAMDF\n% (nonlinear average magnitude difference function), developed by:\n%\n% Ozkurt et al. (2020), \"Identification of nonlinear features in cortical and\n% subcortical signals of Parkinson's Disease patients via a novel efficient\n% measure\", Neuroimage.\n%\n% Please refer to and cite this paper if you utilize this function in your work.\n%\n%---INPUTS:\n%\n% data = One dimensional input time-series (it can be raw, but it is a good idea to low-pass filter it to get rid of high frequency nuisance)\n% For the neural data (LFP, MEG) in the aferomentioned paper, we\n% low-passed the raw data for 40 Hz. The data should be long enough for proper estimation of nonlinearity.\n%\n% winlen = window length (a long enough segment is important to estimate the nonlinearity)\n% We chose the window length as 14 sec., i.e., winlen = 14*fs\n%\n% shiftlen = This amounts to window length - overlap length btw windows\n% We chose it as half the window length, i.e., shiftlen = 0.5*winlen\n%\n% lag = TMaximum lag for nsAMDF, we chose it as 1 sec, i.e., lag = fs.\n%\n% fs = sampling frequency of the data\n%\n% degree = The chosen degree p should ideally be large enough to capture the highest order of nonlinearity within the data.\n% We chose p=7 for in our case of Parkinsonian data in the paper.\n%\n% doPlot = true to plot nsAMDF sequences, otherwise just assign it false\n%\n%---OUTPUTS:\n%\n% L: nonlinearity measure\n%\n% s2: normalized nsAMDF for the degree 2\n%\n% sd: normalized nsAMDF for the chosen degree greater than 2\n%\n%\n% Required subfunctions are NormedSingleCurveLengthWindowed.m & NormedSingleCurveLength.m\n%\n%\n% Authored by Tolga Esat Ozkurt, 2020. (tolgaozkurt@gmail.com)\n\n\n%-------------------------------------------------------------------------------\n% Set defaults:\n\nif nargin < 2\n fs = 1;\nend\nif nargin < 3\n winLenRel = 14;\nend\nwindowLength = winLenRel*fs;\nif nargin < 4\n shiftLenRel = 0.5;\nend\nshiftLength = shiftLenRel*windowLength;\nif nargin < 5\n lagRel = 1;\nend\nlag = fs*lagRel;\nif nargin < 6\n degree = 7;\nend\nif nargin < 7\n doPlot = false\nend\n\n%-------------------------------------------------------------------------------\n% nsAMDF for p=2:\ns2 = NormedSingleCurveLengthWindowed(data,windowLength,shiftLength,lag,fs,2);\nout.s2 = s2 ./ max(s2); % normalized\n\n% nsAMDF for p=degree:\nsd = NormedSingleCurveLengthWindowed(data,windowLength,shiftLength,lag,fs,degree);\nout.sd = sd ./ max(sd); % normalized\n\n% If you like, you can bandpass filter s2 and sd for the specific frequency band\n% of nonlinear effect both to compute L and plot them as such\n\nout.L = norm(s2 - sd);\n\n%-------------------------------------------------------------------------------\nif doPlot\n figure\n plot(s2,'b')\n hold on\n plot(sd,'g')\nend\n\nend\n", "meta": {"author": "benfulcher", "repo": "hctsa", "sha": "919f2aed7cc8e1a3a03304c1ade573fa664c73f8", "save_path": "github-repos/MATLAB/benfulcher-hctsa", "path": "github-repos/MATLAB/benfulcher-hctsa/hctsa-919f2aed7cc8e1a3a03304c1ade573fa664c73f8/Toolboxes/nsamdf/nsamdf_nonlinear_measure.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026505426832, "lm_q2_score": 0.8104789178257654, "lm_q1q2_score": 0.7434544595305401}} {"text": "% dimension of ambient space\nn = 6;\n% number of subspaces = number of clusters\nns = 2;\n% dimensions of individual subspaces 1 and 2\nd1 = 2;\nd2 = 2;\n% number of signals in individual subspaces\ns1 = 10;\ns2 = 10;\n% total number of signals\nS = s1 + s2;\n% A random basis for first subspace;\nbasis1 = randn(n,d1);\n% coefficients for s1 vectors chosen randomly in subspace 1\ncoeffs1 = randn(d1,s1);\n% Random signals from first subspace\nX1 = basis1 * coeffs1;\n% A random basis for second subspace\nbasis2 = randn(n,d2);\n% coefficients for s2 vectors chosen randomly in subspace 2\ncoeffs2 = randn(d2,s2);\n% Random signals from first subspace\nX2 = basis2 * coeffs2;\n% Prepare the overall set of signals\nX = [X1 X2];\n% ground through clustering data\ntrue_labels = [1*ones(s1,1) ; 2*ones(s2,1)];\n% the largest dimension amongst all subspaces\nK = max(d1, d2);\nX = spx.norm.normalize_l2(X);\nC = spx.fast.gomp_spr(X, K, 2);\n\nsolver = spx.pursuit.single.OrthogonalMatchingPursuit(X, K);\nC2 = zeros(S, S);\nfor s=1:S\n solver.IgnoredAtom = s;\n result = solver.solve(X(:, s));\n C2(:, s) = result.z;\nend\nmax(C2 - C)\nmax(abs(X - X * C))\n", "meta": {"author": "indigits", "repo": "sparse-plex", "sha": "43cae2978f62938d001baaa03308a2a717ee6c9b", "save_path": "github-repos/MATLAB/indigits-sparse-plex", "path": "github-repos/MATLAB/indigits-sparse-plex/sparse-plex-43cae2978f62938d001baaa03308a2a717ee6c9b/experiments/ssc_gomp/ex_gomp_spr_2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026528034426, "lm_q2_score": 0.810478913248044, "lm_q1q2_score": 0.743454457163682}} {"text": "function r = invwishrand(S,nu);\n%INVWISHRND Random matrices from inverse Wishard distribution.\n%\n% R = INVWISHRAND(S,N) returns a matrix of random numbers chosen \n% from the central inverse Wishard distribution with parameters S and NU.\n%\n% S is a symmetric positive definite scale matrix\n% NU is degrees of freedom\n%\n% Note: E[R]=S*nu/(nu-k-1)\n%\n%\tSee also WISHRAND\n%\n% Copyright (c) 1999 Aki Vehtari\n\n% This software is distributed under the GNU General Public \n% License (version 3 or later); please refer to the file \n% License.txt, included with the software, for details.\n\nif nargin < 2\n error('Requires two input arguments.'); \nend;\n\n[d d2] = size(S);\nif d ~= d2\n error('Matrix S must be square');\nend\n\n[t,p]=chol(S);\nif p < 0\n error('Matrix S must be positive definite.');\nend\n\nr=inv(wishrand(inv(S),nu));\n", "meta": {"author": "gpstuff-dev", "repo": "gpstuff", "sha": "114937ec0a201306489a66cbba38283e722fb998", "save_path": "github-repos/MATLAB/gpstuff-dev-gpstuff", "path": "github-repos/MATLAB/gpstuff-dev-gpstuff/gpstuff-114937ec0a201306489a66cbba38283e722fb998/dist/invwishrand.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9173026573249612, "lm_q2_score": 0.8104789063814616, "lm_q1q2_score": 0.7434544545295432}} {"text": "function y = sphere_characteristic ( m, n, x )\n\n%*****************************************************************************80\n%\n%% SPHERE_CHARACTERISTIC evaluates the characteristic function of a sphere.\n%\n% Discussion:\n%\n% The dimension of the sphere is arbitrary, and set by the input value M.\n%\n% The sphere is assumed to have center at the origin and radius 1.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 05 May 2013\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer M, the spatial dimension.\n%\n% Input, integer N, the number of points to check.\n%\n% Input, real X(M,N), the coordinates of points to be checked.\n%\n% Output, real Y(N,1), is 1 if the point is inside, 0 otherwise.\n%\n y = sqrt ( sum ( x.^2, 1 ) );\n\n y = y';\n\n y = ( y < 1.0 );\n\n return\nend\n\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/hypersphere_surface/sphere_characteristic.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8539127380808499, "lm_q2_score": 0.8705972818382005, "lm_q1q2_score": 0.7434141087002032}} {"text": "% \u9ad8\u65af\u6d88\u53bb\u6cd5 Gaussian_Elimination\nfunction [x] = my_ge(A, b)\n\n[m,n]=size(A);\nif (m~=n)\n fprintf('\\n Error: A \u4e0d\u662f\u65b9\u9635!\\n'); return; \nend\n\nm = zeros(n);\n%\u6d88\u5143\u8fc7\u7a0b\nfor k = 1:n-1\n for i = k+1:n\n m(i,k) = A(i,k)/A(k,k);\n A(i,:) = A(i,:) - m(i,k) * A(k,:);\n b(i) = b(i) - m(i,k) * b(k);\n end\nend\n%\u56de\u4ee3\u8fc7\u7a0b\nx(n) = b(n)/A(n,n);\nfor k = n-1 : -1 : 1\n summary = 0;\n for j = k+1 : n\n summary = summary + A(k,j) * x(j);\n end\n x(k) = (b(k) - summary) / A(k,k);\nend\n ", "meta": {"author": "qxr777", "repo": "NumericalAnalysis", "sha": "145e47521459defdcfd6a929702651abe29ba6de", "save_path": "github-repos/MATLAB/qxr777-NumericalAnalysis", "path": "github-repos/MATLAB/qxr777-NumericalAnalysis/NumericalAnalysis-145e47521459defdcfd6a929702651abe29ba6de/\u7b2c\u516d\u7ae0 \u7ebf\u6027\u65b9\u7a0b\u7ec4\u7684\u76f4\u63a5\u6cd5/my_ge.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966762263736, "lm_q2_score": 0.785308578375437, "lm_q1q2_score": 0.7433704901022472}} {"text": "function [ lat, long ] = xy2latlong( x, y, ref_lat, ref_long )\n% converts cartesian coordinates x,y (in km) to lat/long\n% ref_lat and ref_long is the geodetic reference point for plane approximation of the earth surface\n\nearth_circumf = 40074;\n\nlat = (y * 360 / earth_circumf) + ref_lat;\nlong = ( (x*360) / (earth_circumf * cos(ref_lat*pi/180)) ) + ref_long;\n\nend\n\n", "meta": {"author": "DC9ST", "repo": "tdoa-evaluation-rtlsdr", "sha": "3e7791adca1179b0a0be715b240caa0ad01d09c7", "save_path": "github-repos/MATLAB/DC9ST-tdoa-evaluation-rtlsdr", "path": "github-repos/MATLAB/DC9ST-tdoa-evaluation-rtlsdr/tdoa-evaluation-rtlsdr-3e7791adca1179b0a0be715b240caa0ad01d09c7/functions/xy2latlong.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9465966702001758, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.7433704877479771}} {"text": "function pass = test_kron(pref) \n% Test the chebfun/kron() command. \n\nif ( nargin < 1 ) \n pref = chebfunpref(); \nend \n\ntol = 200*pref.cheb2Prefs.chebfun2eps;\n\n%% Kronecker products resulting in CHEBFUN2 objects\n\n% Rank 1 chebfun2 \nf = chebfun(@(x) x.^2, pref);\ng = chebfun(@(y) sin(y), pref);\n \nh1 = chebfun2(@(x,y) x.^2.*sin(y));\nh2 = chebfun2(@(x,y) y.^2.*sin(x)); \n\npass(1) = (norm(h1 - kron(f', g)) < tol);\npass(2) = (norm(h2 - kron(f, g')) < tol); \npass(3) = (norm(h1 - g*f') < tol); \npass(4) = (norm(h2 - f*g') < tol); \n\n% Different domain in x and y \nd = [-2 pi -pi 2];\nf = chebfun(@(x) x.^2, d(1:2), pref);\ng = chebfun(@(y) sin(y), d(3:4), pref);\n \nh1 = chebfun2(@(x,y) x.^2.*sin(y), d);\nh2 = chebfun2(@(x,y) y.^2.*sin(x), [d(3:4) d(1:2)]); \n\npass(5) = ( norm(h1 - kron(f', g)) < tol); \npass(6) = (norm(h2 - kron(f, g')) < tol);\npass(7) = ( norm(h1 - g*f') < tol);\npass(8) = (norm(h2 - f*g') < tol); \n\n% Quasimatrices and rank 4 chebfun2\nx = chebfun('x', [-1 1], pref);\nF = [1 x x.^2 x.^4]; \nG = [1 cos(x) sin(x) x.^5]; \n\nh1 = chebfun2(@(x,y) 1 + x.*cos(y) + x.^2.*sin(y) + x.^4.*y.^5);\nh2 = chebfun2(@(x,y) 1 + y.*cos(x) + y.^2.*sin(x) + y.^4.*x.^5);\n\npass(9) = (norm(h1 - kron(F', G)) < tol); \npass(10) = (norm(h2 - kron(F, G')) < tol); \npass(11) = (norm(h1 - G*F') < tol); \npass(12) = (norm(h2 - F*G') < tol); \n\n% Different domains and quasimatrices \nx = chebfun('x',[-2 1], pref); \ny = chebfun('x',[-1 1], pref); \nd = [-2 1 -1 1]; \nF = [1 x x.^2 x.^4]; \nG = [1 cos(y) sin(y) y.^5]; \nh1 = chebfun2(@(x,y) 1 + x.*cos(y) + x.^2.*sin(y) + x.^4.*y.^5,d);\nh2 = chebfun2(@(x,y) 1 + y.*cos(x) + y.^2.*sin(x) + y.^4.*x.^5,[d(3:4) d(1:2)]);\n\npass(13) = (norm(h1 - kron(F', G)) < tol); \npass(14) = (norm(h2 - kron(F, G')) < tol); \npass(15) = (norm(h1 - G*F') < tol);\npass(16) = (norm(h2 - F*G') < tol);\n\nend\n", "meta": {"author": "chebfun", "repo": "chebfun", "sha": "8c49396a55e46ddd57a1d108c6a8f32e37536d54", "save_path": "github-repos/MATLAB/chebfun-chebfun", "path": "github-repos/MATLAB/chebfun-chebfun/chebfun-8c49396a55e46ddd57a1d108c6a8f32e37536d54/tests/chebfun/test_kron.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088064979619, "lm_q2_score": 0.8006920044739461, "lm_q1q2_score": 0.743369508246117}} {"text": "function[varargout]=instmom(varargin)\n%INSTMOM Univariate and multivariate instantaneous moments.\n% don't need this because it really doesn't seep things up much from \n% using anatrans and instmome\n%\n% [A,OMEGA,UPSILON]=INSTMOM(X), where X is an analytic signal, computes \n% the amplitude A, instantaneous *radian* frequency OMEGA, and \n% instantaneous bandwidth assuming a unit sample rate. \n%\n% X is an array with the first dimension being \"time\". Thus, X can be a \n% matrix of analytic signals oriented as column vectors, or a 2- or 3-D \n% wavelet transform such as output by WAVETRANS.\n%\n% The output arrays are the same size as X. \n%\n% The instantaneous frequency, bandwidth, and curvature are defined as\n%\n% A = abs X\n% OMEGA = d/dt Im ln X = d/dt arg X\n% UPSILON = d/dt Re ln X = d/dt ln abs X \n% \n% where i=SQRT(-1) as usual.\n%\n% INSTMOM(X,DIM) computes the moments along dimension DIM, instead of \n% the default of computing the moments along the rows (DIM=1).\n%\n% For details, see \n% \n% Lilly & Olhede (2010), \"Bivariate instantaneous frequency and \n% bandwidth\", IEEE Trans. Sig. Proc., 58 (2), 591--603.\n% _____________________________________________________________________\n% \n% Sample interval\n%\n% INSTMOM(DT,...) uses sample interval DT, where DT is a scalar, for \n% computing time derivatives. DT=1 is the default.\n% _____________________________________________________________________\n% \n% Joint instantaneous moments\n%\n% INSTMOM can also calculate the joint instananeous moments of \n% multivariate signals, as defined in Lilly and Olhede (2010).\n%\n% [JA,JOMEGA,JUPSILON]=INSTMOM(X1,X2,...,XN,DIM) returns the *joint*\n% instantaneous moments calculated across the N signals X1,X2,... XN, \n% based on the univariate instantaneous moments along dimension DIM.\n%\n% The joint instantaneous amplitude JA is the root-mean-square of the \n% component amplitudes across dimension JDIM, while JOMEGA is power-\n% weighted average of the component instantaneous frequencies.\n%\n% For details and for the definition of the joint instantaneous bandwidth \n% JUPSILON, see Lilly and Olhede (2010).\n%\n% [JA,JOMEGA,JUPSILON]=INSTMOM(X,DIM,JDIM) also works, where the joint\n% instantaneous moments are calculated across dimensions JDIM of X.\n%\n% The joint instantaneous moments JA, JOMEGA, and JUPSILON then have the \n% same size as X, except along dimension JDIM where they have only one \n% entry. Note that DIM is no longer optional when JDIM is used.\n% _____________________________________________________________________\n% \n% Instantaneous curvature\n%\n% INSTMOM can also return the next-higher order instantaneous moment, \n% which is more rarely encountered. \n%\n% [A,OMEGA,UPSILON,XI]=INSTMOM(X) returns the instantaneous curvature XI,\n% defined as\n%\n% XI = d^2/dt^2 abs X / abs X + i d^2/dt^2 arg X\n% = UPSILON^2 + d/dt UPSILON + i d/dt OMEGA\n%\n% Similarly [JA,JOMEGA,JUPSILON,JXI]=INSTMOM(X,DIM,JDIM) returns the\n% joint instantaneous curvature JXI for the multivariate signal X.\n% \n% For details on the univariate and joint instantaneous curvature, see \n%\n% Lilly and Olhede (2012a), \"Analysis of modulated multivariate \n% oscillations\", IEEE Trans. Sig. Proc., 60 (2), 600--612. \n% _____________________________________________________________________\n%\n% Boundary conditions\n%\n% The first and last points must be treated differently, as the central \n% difference is not defined there. Three different methods can be used.\n%\n% INSTMOM(...,STR) specifies the method: STR= 'endpoint' (the default),\n% 'periodic', or 'nans'. See VDIFF for details. \n% _____________________________________________________________________\n%\n% 'instmom --f' generates some sample figures.\n%\n% Usage: [a,om]=instmom(x);\n% [a,om,up,xi]=instmom(dt,x);\n% [a,om,up,xi]=instmom(dt,x,dim);\n% [a,om,up,xi]=instmom(dt,x1,x2,x3,x4,dim);\n% [a,om,up,xi]=instmom(dt,x,dim,jdim);\n% __________________________________________________________________\n% This is part of JLAB --- type 'help jlab' for more information\n% (C) 2007--2019 J.M. Lilly --- type 'help jlab_license' for details\n\n\n% _____________________________________________________________________\n%\n% Higher-order modulation functions\n%\n% [OMEGA,RHO1,...RHON]=INSTMOM(X) also outputs the higher-order \n% instantaneous modulation functions. RHO1 is identical to the\n% bandwidth, and RHO2 is called the curvature.\n%\n% For details see \n%\n% Lilly and Olhede (2010). On the analytic wavelet transform.\n%\n% Note that the modulation functions are defined in their non-normalized \n% form, that is, not divided by powers of the instananeous frequency, \n% unlike in Lilly and Olhede (2010).\n%\n% _____________________________________________________________________\n\n\nif strcmpi(varargin{1}, '--t')\n instmom_test,return\nelseif strcmpi(varargin{1}, '--f')\n type makefigs_instmom\n makefigs_instmom;\n return\nend\n\nif length(varargin{1})==1\n dt=varargin{1};\n varargin=varargin(2:end);\nelse\n dt=1;\nend\n\n \nstr='endpoint';\ndim=1;\njdim=[];\nfor i=1:4\n if ischar(varargin{end})\n str=varargin{end};\n varargin=varargin(1:end-1);\n else\n if length(varargin{end})==1\n if length(varargin{end-1})==1 \n dim=varargin{end-1};\n jdim=varargin{end};\n varargin=varargin(1:end-2);\n else\n dim=varargin{end};\n varargin=varargin(1:end-1);\n end\n end\n end\nend\n\n\n\n\nN=length(varargin);\nif N==1\n x=varargin{1};\nelse\n jdim=lnsd(varargin{1})+1;\n sizex1=size(varargin{1});\n sizex1=sizex1(1:jdim-1);\n x=zeros([sizex1 N]);\n for i=1:N\n x=vindexinto(x,varargin{i},i,jdim);\n end\nend\n\n%Note: there are different ways to reasonably define the instantaneous\n%frequency as a vdiff of the signal. These differ greatly actually. \n%Diffing the unwrapped angle seems to give the best results. If you take \n%the Im of the diffed log, you will break the wavelet phase algorithm!\n\n%You definitely don't want to just do diff(x). This differences the real\n%and imaginary parts separately, which are themselves rapidly varying.\n \nom=vdiff(unwrap(angle(x),[],dim),dim,str)./dt;\nup=vdiff(log(abs(x)),dim,str)./dt; \neta=om-sqrt(-1)*up;\n\nvarargout{1}=abs(x);\nvarargout{2}=om;\nnmax=nargout-2;\n\n%I prefer this version, though difference is minor\n%if nmax>=1\n% varargout(3)=frac(1,abs(x)).*vdiff(vdiff(abs(x),1,str),1,str)./dt./dt+sqrt(-1)*vdiff(om,1,str)./dt; \n%end\n\nif nmax>=1\n etadiff=cell(nmax,1); \n polyargs=cell(nmax,1);\n bcell=cell(nmax,1);\n\n etadiff{1}=vdiff(eta,dim,str)./dt;\n polyargs{1}=up;\n\n for n=2:nmax\n etadiff{n}=vdiff(etadiff{n-1},dim,str)./dt;\n polyargs{n}=sqrt(-1)*etadiff{n-1};\n end\n\n temp=bellpoly(polyargs);\n for n=1:length(temp)\n varargout{n+2}=temp{n};\n end\nend\n\n%When JDIM is input, this tells me to output joint quantities\nif ~isempty(jdim)\n if nargout==1\n varargout{1}=jointmom(x,jdim); \n elseif nargout==2\n [varargout{1},varargout{2}]=jointmom(x,varargout{2},jdim);\n elseif nargout==3\n [varargout{1},varargout{2},varargout{3}]=jointmom(x,varargout{2},varargout{3},jdim);\n elseif nargout==4\n [varargout{1},varargout{2},varargout{3},varargout{4}]=jointmom(x,varargout{2},varargout{3},varargout{4},jdim);\n end\nend\n\n\nfunction[varargout]=jointmom(varargin)\n%JOINTMOM Joint instantaneous frequency, bandwidth, and curvature.\n%\n% OMEGAX=JOINTMOM(X,OMEGA,DIM) where X is an array of multiple analytic\n% signals and OMEGA is an array of their instantaneous frequencies, gives\n% the joint instaneous frequency OMEGAX averaged over dimension DIM.\n%\n% X is presumed to have time oriented in rows. The output matrix OMEGAX\n% are the same size as X except along dimension DIM, where the output\n% matrices will have length one. X and OMEGA are the same size.\n% \n% [OMEGAX,UPSILONX]=JOINTMOM(X,UPSILON,DIM) also works, where UPSILON \n% are the individual bandwidths, and UPSILONX is the joint quantity. \n% UPSILON is the same size as X and OMEGA.\n%\n% Finally [OMEGAX,UPSILONX,XIX]=JOINTMOM(X,UPSILON,XI,DIM) also returns \n% the joint instantaneous curvature XIX given individual curvatures XI.\n%\n% For details, see \n% \n% Lilly & Olhede (2010), \"Bivariate instantaneous frequency and \n% bandwidth\", IEEE Trans. Sig. Proc., 58 (2), 591--603.\n% \n% See also INSTMOM.\n%\n% Usage: [a,om]=jointmom(x,om,dim);\n% [a,om,up]=jointmom(x,om,up,dim);\n% [a,om,up,xi]=jointmom(x,om,xi,dim);\n% __________________________________________________________________\n% This is part of JLAB --- type 'help jlab' for more information\n% (C) 2009--2014 J.M. Lilly --- type 'help jlab_license' for details\n \n\n\ndim=varargin{end};\nx=varargin{1};\nvarargin=varargin(2:end-1);\n\n\nif ~isempty(varargin)\n om=varargin{1};\nend\nif length(varargin)>1\n upsilon=varargin{2};\nend\nif length(varargin)>2\n xi=varargin{3};\nend\n\nvarargout{1}=sqrt(vmean(abs(x).^2,dim));\nif nargout>1\n varargout{2}=vmean(om,dim,squared(x));\n ombar=vrep(varargout{2},size(x,dim),dim);\nend\nif nargout>2\n varargout{3}=sqrt(vmean(abs(upsilon+sqrt(-1)*(om-ombar)).^2,dim,squared(x)));\nend\nif nargout>3\n varargout{4}=sqrt(vmean(abs(xi+2*sqrt(-1)*upsilon.*(om-ombar)-(om-ombar).^2).^2,dim,squared(x)));\nend\nif nargout>4\n error('Sorry, INSTMOM only outputs the first two deviation vectors for joint moments.')\nend\n\n\nfunction[]=instmom_test\n\nload npg2006\nuse npg2006\n\n[a1,om1,up1,c1]=instmom(cv);\n[a2,om2,up2,c2]=instmom(permute(cv,[2 1]),2);\n\nreporttest('INSTMOM moments computed along different dimensions match', aresame([om1 up1 c1],[om2(:) up2(:) c2(:)])); \njointmom_test;\n\nfunction[]=jointmom_test\nload solomon\nuse solomon\n\n[x,z]=anatrans(x,z);\n\n[ax,omx,upx]=instmom(x);\n[az,omz,upz]=instmom(z);\n\nombar=frac(abs(x).^2.*omx+abs(z).^2.*omz,abs(x).^2+abs(z).^2);\nupbar=sqrt(frac(abs(x).^2.*(upx.^2+(omx-ombar).^2)+abs(z).^2.*(upz.^2+(omz-ombar).^2),abs(x).^2+abs(z).^2));\n\n[a,om,up]=instmom([x z],1,2);\n\nreporttest('INSTMOM joint moments using Solomon Islands frequency',aresame(om,ombar,1e-8))\nreporttest('INSTMOM joint moments using Solomon Islands bandwidth',aresame(up,upbar,1e-8))\n\n[a2,om2,up2]=instmom(x,z,1);\n\nreporttest('INSTMOM joint moments alternate form',aresame([a om up],[a2 om2 up2]))\n\n\n\n", "meta": {"author": "jonathanlilly", "repo": "jLab", "sha": "9f32f63e647209bc1cb81c8713deb954857f1919", "save_path": "github-repos/MATLAB/jonathanlilly-jLab", "path": "github-repos/MATLAB/jonathanlilly-jLab/jLab-9f32f63e647209bc1cb81c8713deb954857f1919/jRidges/instmom.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213664574069, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.7433142379512783}} {"text": "function pdf_discrete_test ( )\n\n%*****************************************************************************80\n%\n%% PDF_DISCRETE_TEST tests PDF_DISCRETE_VALUE.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 12 May 2013\n%\n% Author:\n%\n% John Burkardt\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'PDF_DISCRETE_TEST\\n' );\n fprintf ( 1, ' PDF_DISCRETE_VALUE evaluates the PDF associated with a\\n' );\n fprintf ( 1, ' discrete histogram.\\n' );\n%\n% Set up the discrete histogram from sample data.\n%\n s_num = 6;\n s_min = 0.0;\n s_max = 10.0;\n s = [ 0.0, 2.0, 2.0, 4.0, 5.0, 8.0 ];\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' S_MIN = %g\\n', s_min );\n fprintf ( 1, ' S_MAX = %g\\n', s_max );\n r8vec_print ( s_num, s, ' Sample data:' );\n\n [ x_num, x, y ] = setup_discrete ( s_num, s, s_min, s_max );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Discrete histogram data:\\n' );\n fprintf ( 1, '\\n' );\n for i = 1 : x_num\n fprintf ( 1, ' %10.6g %10.6g\\n', x(i), y(i) );\n end\n%\n% Evaluate the discrete PDF.\n%\n v_num = 21;\n v = linspace ( s_min, s_max, v_num );\n pdf = pdf_discrete_value ( x_num, x, y, v_num, v );\n r8vec2_print ( v_num, v, pdf, ' Discrete PDF table:' );\n%\n% Plot the discrete PDF.\n%\n plot ( v, pdf, 'bo-', 'Linewidth', 3 )\n grid on\n xlabel ( '<--- X --->' )\n ylabel ( '<--- PDF(X) --->' )\n title ( 'Discrete PDF function' )\n\n filename = 'pdf_discrete_test.png';\n print ( '-dpng', filename )\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Discrete PDF plotted as \"%s\".\\n', filename );\n\n return\nend\n\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/histogram_discrete/pdf_discrete_test.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951182587159, "lm_q2_score": 0.8807970826714614, "lm_q1q2_score": 0.7433003582429648}} {"text": "function geometry_test035 ( )\n\n%*****************************************************************************80\n%\n%% TEST035 tests LINE_IMP_POINT_DIST_2D.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 14 February 2003\n%\n% Author:\n%\n% John Burkardt\n%\n dim_num = 2;\n ntest = 3;\n\n atest = [ 2.0, 2.0, 2.0 ];\n btest = [ 5.0, 5.0, 5.0 ];\n ctest = [ 3.0, 3.0, 3.0 ];\n ptest = [ ...\n 0.0, 6.0; ...\n 0.0, 5.0; ...\n 0.0, 4.0 ]';\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TEST035\\n' );\n fprintf ( 1, ' LINE_IMP_POINT_DIST_2D finds the distance from\\n' );\n fprintf ( 1, ' a point X Y to a line A * X + B * Y + C = 0.\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' X Y A B C DIST\\n' );\n fprintf ( 1, '\\n' );\n\n for i = 1 : ntest\n\n a = atest(i);\n b = btest(i);\n c = ctest(i);\n p(1:dim_num) = ptest(1:dim_num,i);\n\n dist = line_imp_point_dist_2d ( a, b, c, p );\n\n fprintf ( 1, ' %8f %8f %8f %8f %8f %8f\\n', ...\n p(1:dim_num), a, b, c, dist );\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/geometry/geometry_test035.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970779778824, "lm_q2_score": 0.8438951064805861, "lm_q1q2_score": 0.7433003439079342}} {"text": "%BIPOLAR returns an M-by-3 matrix containing a blue-red colormap, in\n%\tin which red stands for positive, blue stands for negative,\n%\tand white stands for 0.\n%\n% Usage: cmap = bipolar(M, lo, hi, contrast); or cmap = bipolar;\n%\n% cmap: output M-by-3 matrix for BIPOLAR colormap.\n% M:\t number of shades in the colormap. By default, it is the\n%\t same length as the current colormap.\n% lo:\t the lowest value to represent.\n% hi:\t the highest value to represent.\n%\n% Inspired from the LORETA PASCAL program:\n%\thttp://www.unizh.ch/keyinst/NewLORETA\n%\n% jimmy@rotman-baycrest.on.ca\n%\n%----------------------------------------------------------------\nfunction cmap = bipolar(M, lo, hi, contrast)\n\n if ~exist('contrast','var')\n contrast = 128;\n end\n\n if ~exist('lo','var')\n lo = -1;\n end\n\n if ~exist('hi','var')\n hi = 1;\n end\n\n if ~exist('M','var')\n cmap = colormap;\n M = size(cmap,1);\n end\n\n steepness = 10 ^ (1 - (contrast-1)/127);\n pos_infs = 1e-99;\n neg_infs = -1e-99;\n\n doubleredc = [];\n doublebluec = [];\n\n if lo >= 0\t\t% all positive\n\n if lo == 0\n lo = pos_infs;\n end\n\n for i=linspace(hi/M, hi, M)\n t = exp(log(i/hi)*steepness);\n doubleredc = [doubleredc; [(1-t)+t,(1-t)+0,(1-t)+0]];\n end\n\n cmap = doubleredc;\n\n elseif hi <= 0\t% all negative\n\n if hi == 0\n hi = neg_infs;\n end\n\n for i=linspace(abs(lo)/M, abs(lo), M)\n t = exp(log(i/abs(lo))*steepness);\n doublebluec = [doublebluec; [(1-t)+0,(1-t)+0,(1-t)+t]];\n end\n\n cmap = flipud(doublebluec);\n\n else\n\n if hi > abs(lo)\n maxc = hi;\n else\n maxc = abs(lo);\n end\n\n for i=linspace(maxc/M, hi, round(M*hi/(hi-lo)))\n t = exp(log(i/maxc)*steepness);\n doubleredc = [doubleredc; [(1-t)+t,(1-t)+0,(1-t)+0]];\n end\n\n for i=linspace(maxc/M, abs(lo), round(M*abs(lo)/(hi-lo)))\n t = exp(log(i/maxc)*steepness);\n doublebluec = [doublebluec; [(1-t)+0,(1-t)+0,(1-t)+t]];\n end\n\n cmap = [flipud(doublebluec); doubleredc];\n\n end\n\n return;\t\t\t\t\t% bipolar\n\n", "meta": {"author": "CoSMoMVPA", "repo": "CoSMoMVPA", "sha": "5de75a1b4bef89b082d39d69e2b99d7f894ad717", "save_path": "github-repos/MATLAB/CoSMoMVPA-CoSMoMVPA", "path": "github-repos/MATLAB/CoSMoMVPA-CoSMoMVPA/CoSMoMVPA-5de75a1b4bef89b082d39d69e2b99d7f894ad717/external/NIfTI_20140122/bipolar.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970842359876, "lm_q2_score": 0.8438950966654774, "lm_q1q2_score": 0.7433003405439993}} {"text": "function d = distance(u, v)\n% Euclidean distance between u and v\n%\n% :Usage:\n% ::\n%\n% d = distance(u, v)\n%\n% :Inputs:\n%\n% **u** and **v:**\n% should be column vectors or matrices in k-dim space, where k is\n% the number of columns of u and v.\n%\n% if u is a single row, replicates u to size(v,1)\n\nif size(u,1) < size(v,1)\n u = repmat(u,size(v,1),1);\n if size(u,1) < size(v,1), error('Inputs must have same number of rows, or one row for 1st input!'),end\nend\n\ndelt = u - v;\nd = (sum(delt .^ 2,2)) .^.5;\n\nreturn\n\n", "meta": {"author": "canlab", "repo": "CanlabCore", "sha": "af242e120f0480c4feaeea90471c015a14f1f60e", "save_path": "github-repos/MATLAB/canlab-CanlabCore", "path": "github-repos/MATLAB/canlab-CanlabCore/CanlabCore-af242e120f0480c4feaeea90471c015a14f1f60e/CanlabCore/Misc_utilities/distance.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8807970779778824, "lm_q2_score": 0.8438951025545426, "lm_q1q2_score": 0.7433003404498866}} {"text": "function geometry_test179 ( )\n\n%*****************************************************************************80\n%\n%% TEST179 tests SOCCER_SIZE_3D and SOCCER_SHAPE_3D.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 22 May 2005\n%\n% Author:\n%\n% John Burkardt\n%\n dim_num = 3;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TEST179\\n' );\n fprintf ( 1, ' For the truncated icosahedron, or soccer ball,\\n' );\n fprintf ( 1, ' SOCCER_SIZE_3D returns dimension information;\\n' );\n fprintf ( 1, ' SOCCER_SHAPE_3D returns face and order information.\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' We will use this information to compute the\\n' );\n fprintf ( 1, ' areas and centers of each face.\\n' );\n\n [ point_num, edge_num, face_num, face_order_max ] = soccer_size_3d ( );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Number of points = %d\\n', point_num );\n fprintf ( 1, ' Number of edges = %d\\n', edge_num );\n fprintf ( 1, ' Number of faces = %d\\n', face_num );\n fprintf ( 1, ' Maximum face order = %d\\n', face_order_max );\n\n [ point_coord, face_order, face_point ] = soccer_shape_3d ( ...\n point_num, face_num, face_order_max );\n%\n% Compute the area of each face.\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Face Order Area\\n' );\n fprintf ( 1, '\\n' );\n\n for i = 1 : face_num\n\n for j = 1 : face_order(i)\n k = face_point(j,i);\n v(1:dim_num,j) = point_coord(1:dim_num,k);\n end\n\n [ area, normal ] = polygon_area_3d ( face_order(i), v );\n\n fprintf ( 1, ' %6d %5d %8f\\n', i, face_order(i), area );\n\n end\n%\n% Find the center of each face.\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Face Center\\n' );\n fprintf ( 1, '\\n' );\n\n for i = 1 : face_num\n\n vave(1:dim_num) = 0.0;\n\n for j = 1 : face_order(i)\n k = face_point(j,i);\n vave(1:dim_num) = vave(1:dim_num) + point_coord(1:dim_num,k)';\n end\n\n vave(1:dim_num) = vave(1:dim_num) / face_order(i);\n\n fprintf ( 1, ' %6d %10f %10f %10f\\n', i, vave(1:dim_num) );\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/geometry/geometry_test179.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970779778824, "lm_q2_score": 0.8438951005915208, "lm_q1q2_score": 0.7433003387208628}} {"text": "%RPY2R Roll-pitch-yaw angles to SO(3) rotation matrix\n%\n% R = RPY2R(ROLL, PITCH, YAW, OPTIONS) is an SO(3) orthonornal rotation\n% matrix (3x3) equivalent to the specified roll, pitch, yaw angles angles.\n% These correspond to rotations about the Z, Y, X axes respectively. If\n% ROLL, PITCH, YAW are column vectors (Nx1) then they are assumed to\n% represent a trajectory and R is a three-dimensional matrix (3x3xN), where\n% the last index corresponds to rows of ROLL, PITCH, YAW.\n%\n% R = RPY2R(RPY, OPTIONS) as above but the roll, pitch, yaw angles are\n% taken from the vector (1x3) RPY=[ROLL,PITCH,YAW]. If RPY is a matrix\n% (Nx3) then R is a three-dimensional matrix (3x3xN), where the last index\n% corresponds to rows of RPY which are assumed to be [ROLL,PITCH,YAW].\n%\n% Options::\n% 'deg' Compute angles in degrees (radians default)\n% 'xyz' Rotations about X, Y, Z axes (for a robot gripper)\n% 'zyx' Rotations about Z, Y, X axes (for a mobile robot, default)\n% 'yxz' Rotations about Y, X, Z axes (for a camera)\n% 'arm' Rotations about X, Y, Z axes (for a robot arm)\n% 'vehicle' Rotations about Z, Y, X axes (for a mobile robot)\n% 'camera' Rotations about Y, X, Z axes (for a camera)\n%\n% Note::\n% - Toolbox rel 8-9 has XYZ angle sequence as default.\n% - ZYX order is appropriate for vehicles with direction of travel in the X\n% direction. XYZ order is appropriate if direction of travel is in the Z\n% direction.\n% - 'arm', 'vehicle', 'camera' are synonyms for 'xyz', 'zyx' and 'yxz'\n% respectively.\n%\n% See also TR2RPY, EUL2TR.\n\n% Copyright (C) 1993-2019 Peter I. Corke\n%\n% This file is part of The Spatial Math Toolbox for MATLAB (SMTB).\n% \n% Permission is hereby granted, free of charge, to any person obtaining a copy\n% of this software and associated documentation files (the \"Software\"), to deal\n% in the Software without restriction, including without limitation the rights\n% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies\n% of the Software, and to permit persons to whom the Software is furnished to do\n% so, subject to the following conditions:\n%\n% The above copyright notice and this permission notice shall be included in all\n% copies or substantial portions of the Software.\n%\n% THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR \n% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\n% FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n% COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\n% IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n% CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n%\n% https://github.com/petercorke/spatial-math\n\nfunction R = rpy2r(roll, varargin)\n opt.order = {'zyx', 'xyz', 'yxz', 'arm', 'vehicle', 'camera'};\n opt.deg = false;\n [opt,args] = tb_optparse(opt, varargin);\n \n % unpack the arguments\n if numcols(roll) == 3\n\t\tpitch = roll(:,2);\n\t\tyaw = roll(:,3);\n\t\troll = roll(:,1);\n\telseif nargin >= 3\n pitch = args{1};\n yaw = args{2};\n else\n error('SMTB:rpy2r:badarg', 'bad arguments')\n end\n\n % optionally convert from degrees\n if opt.deg\n d2r = pi/180.0;\n roll = roll * d2r;\n pitch = pitch * d2r;\n yaw = yaw * d2r;\n end\n\n switch opt.order\n case {'xyz', 'arm'}\n % XYZ order\n if numrows(roll) == 1\n R = rotx(yaw) * roty(pitch) * rotz(roll);\n else\n R = zeros(3,3,numrows(roll));\n for i=1:numrows(roll)\n R(:,:,i) = rotx(yaw(i)) * roty(pitch(i)) * rotz(roll(i));\n end\n end\n case {'zyx', 'vehicle'}\n % ZYX order\n if numrows(roll) == 1\n R = rotz(yaw) * roty(pitch) * rotx(roll);\n else\n R = zeros(3,3,numrows(roll));\n for i=1:numrows(roll)\n R(:,:,i) = rotz(yaw(i)) * roty(pitch(i)) * rotx(roll(i));\n end\n end\n \n case {'yxz', 'camera'}\n % YXZ order\n if numrows(roll) == 1\n R = roty(yaw) * rotx(pitch) * rotz(roll);\n else\n R = zeros(3,3,numrows(roll));\n for i=1:numrows(roll)\n R(:,:,i) = roty(yaw(i)) * rotx(pitch(i)) * rotz(roll(i));\n end\n end\n end\nend\n", "meta": {"author": "petercorke", "repo": "spatialmath-matlab", "sha": "6eeff4a79f14286705560b84f1fe72e0b7e0e7f7", "save_path": "github-repos/MATLAB/petercorke-spatialmath-matlab", "path": "github-repos/MATLAB/petercorke-spatialmath-matlab/spatialmath-matlab-6eeff4a79f14286705560b84f1fe72e0b7e0e7f7/rpy2r.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.880797068590724, "lm_q2_score": 0.8438951064805861, "lm_q1q2_score": 0.7433003359861572}} {"text": "%------------------------------- getting ready ----------------------------\nclc\nclear all\nclose all\n%--------------------------------------------------------------------------\n\nglobal A E\ntol = 0.001;\nmax = 20;\ninit = 0;\nxn = init*ones(2,78); % estimation for initial trejctory for states\npn = init*ones(2,78); % estimation for initial trejctory for co-states\ncheck = [0.01:0.01:0.78];\n\nfor loop = 1:max\n xh1 = [0 0 1 0]; % initial conditions for homogeneous solution1\n xh2 = [0 0 0 1]; % initial conditions for homogeneous solution2\n xp0 = [0.05 0 0 0]; % initial conditions for particular solution0\n a = 0;\n b = 0.01;\n for I=1:78\n t = [xn(:,I)' pn(:,I)'];\n pointer = 100*loop+I\n clc\n A = calculate_matrix(t); \n x1 = [-2*(t(1)+0.25)+(t(2)+0.5)*exp(25*t(1)/(t(1)+2))-(t(1)+0.25)^2*t(3)/0.2 0.5-t(2)-(t(2)+0.5)*exp(25*t(1)/(t(1)+2))];\n x2 = [-2*t(1)+2*t(3)-t(3)*(t(2)+0.5)*(50/(t(1)+2)^2)*exp(25*t(1)/(t(1)+2))+t(3)^2*(t(1)+0.25)/0.2+t(4)*(t(2)+0.5)*(50/(t(1)+2)^2)*exp(25*t(1)/(t(1)+2)) -2*t(2)-t(3)*exp(25*t(1)/(t(1)+2))+t(4)*(1+exp(25*t(1)/(t(1)+2)))]; \n e1 = [x1 x2]';\n e2 = A*t';\n E = e1 - e2;\n \n clear t1 c\n x0 = [xp0 xh1 xh2]';\n [t1,c] = ode45('stirred_model', [a b], x0);\n\n L = length(t1);\n X1p(I) = c(L,1);\n X2p(I) = c(L,2);\n P1p(I) = c(L,3);\n P2p(I) = c(L,4);\n xp0 = [X1p(I) X2p(I) P1p(I) P2p(I)];\n \n X11h(I) = c(L,5);\n X12h(I) = c(L,6);\n P11h(I) = c(L,7);\n P12h(I) = c(L,8);\n xh1 = [X11h(I) X12h(I) P11h(I) P12h(I)]; \n \n X21h(I) = c(L,9 );\n X22h(I) = c(L,10);\n P21h(I) = c(L,11);\n P22h(I) = c(L,12);\n xh2 = [X21h(I) X22h(I) P21h(I) P22h(I)]; \n\n \n % simulation time for next interval of integrtion\n a = b;\n b = b + 0.01;\n \n end\n \n % calculting constant to satisfy boudary condition\n B1 = [0 0]'-[P1p(78) P2p(78)]';\n ph1 = [P11h(78) P12h(78)]';\n ph2 = [P21h(78) P22h(78)]';\n A1 = [ph1 ph2];\n const = A1\\B1;\n \n % calculation of states and costates\n state = [X1p;X2p] + [const(1)*X11h;const(1)*X12h]+[const(2)*X21h;const(2)*X22h];\n costate = [P1p;P2p] + [const(1)*P11h;const(1)*P12h]+[const(2)*P21h;const(2)*P22h];\n test = terminate(state,xn,costate,pn);\n fprintf('Terminate Check = %f\\n',test);\n const\n pause\n clc\n if test < tol\n break\n end\n\n xn = state;\n pn = costate;\n \nend\n\nplot(check,state,'-');\ntitle('Optimal Trejctory');\ngrid on\n%--------------------------------------------------------------------------\nfor j = 1:78\n u(j) = 0.5*costate(1,j)*(state(1,j)+0.25);\n intg(j) = state(1,j)^2+state(2,j)^2+0.1*u(j)^2;\nend\nfigure\nplot(check,u);\ntitle('U^*');\ngrid on\nJ = integrate(check,intg);\nfprintf('Optimal Cost = %f\\n',J);", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/13406-quasi-linearization-for-optimal-control-trajectory/QL/script_stirred.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693674025231, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.7432705860912112}} {"text": "function [f, lineSegs, theta] = fov(A, pref)\n%FOV Field of values (numerical range) of matrix A.\n% F = FOV(A), where A is a square matrix, returns a CHEBFUN F with domain [0\n% 2*pi]. The image F([0 pi]) is a curve describing the extreme points of the\n% boundary of the field of values A, a convex region in the complex plane. \n%\n% For a generic matrix, the boundary of the field of values is smooth and all\n% boundary points are extreme points. If A is normal, the field of values is\n% the convex hull of the eigenvalues of A, so the extreme points consist only\n% of the eigenvalues and hence F has one constant piece for each eigenvalue,\n% so it is not continuous on [0, 2*pi].\n% \n% The numerical abscissa of A is equal to max(real(F)), though this is much\n% better computed as max(real(eig(A + A')))/2.\n%\n% The algorithm used is that of C. R. Johnson, Numerical determination of the\n% field of values of a general complex matrix, SIAM J. Numer. Anal. 15 (1978),\n% 595-602.\n%\n% F = FOV(A, PREF) allows the preferences in the CHEBFUNPREF structure PREF to\n% be used in constructing F. Note that PREF.splitting will always be set to\n% TRUE by FOV and the domain will always be [0, 2*pi].\n%\n% [F, LINESEGS, THETA] = FOV(A) also returns a quasimatrix LINESEGS whose\n% columns are CHEBFUN objects defining the line segments connecting up the\n% extreme points and a vector THETA specifying the values in [0, 2*pi] where\n% the discontinuities in F occur.\n%\n% Example 1 (smooth boundary)\n% A = randn(5);\n% F = fov(A);\n% hold off, plot(F, '-b')\n% e = eig(A);\n% hold on, plot(e, '*k'), hold off, axis equal\n%\n% Example 2 (boundary has a corner)\n% A = [0 1 0 ; 0 0 0 ; 0 0 1];\n% [F, lineSegs] = fov(A);\n% plot(F, '-b'), hold on\n% plot(lineSegs, '-r')\n% e = eig(A);\n% plot(complex(e), '*k'), hold off, axis equal\n\n% Copyright 2017 by The University of Oxford and The Chebfun Developers.\n% See http://www.chebfun.org/ for Chebfun information.\n\nif ( nargin < 2 )\n % Obtain preferences:\n pref = chebfunpref();\nend\n\n% Set splitting to 'on' and the domain to [0, 2*pi].\npref.splitting = true;\npref.domain = [0, 2*pi];\n\n% Construct a CHEBFUN of the FOV curve, and try to merge any unnecessary\n% breakpoints out of the result:\nf = chebfun(@(theta) fovCurve(theta, A), pref);\nf = merge(f);\n\nif ( nargout == 1 )\n return\nend\n\n%% LINESEGS - implemented by Michael Overton\n% Look for possible discontinuities at any break points. The boundary of the\n% field of values may have corners, but it is continuous: hence the need\n% sometimes for linear interpolation connecting up the sets of extreme points.\n\nends = f.domain; % Break points are between 0 and 2*pi.\ndelta = 1e-14; % Must be bigger than machine precision but not much \n % bigger: if it is too small spurious line segments will\n % have tiny length, which hardly matters. \nif ( any(diff(ends) < delta) )\n delta = min(diff(ends))/3;\nend\nm = length(ends) - 1; % Number of pieces\n\n% Get the values to the left and right of break points. The first break point is\n% zero, which wraps around to 2*pi and needs special treatment. Exclude the\n% right end point 2*pi.\nlVal = feval(f, ends(1:end-1), 'left'); % Values to left of break points.\nlVal(1) = feval(f, ends(end), 'left'); % Value to left of 2*pi.\nrVal = feval(f, ends(1:end-1), 'right'); % Values to right of break points.\n\n% Determine which points correspond to discontinuities:\ntol = 10*delta*max(abs([lVal, rVal]), [], 2);\ndiscont = abs(lVal - rVal) > tol;\n\n% Define additional CHEBFUNs for the line segments joining discontinuities.\n% (First idea was to do this by inserting tiny intervals with steep slopes into\n% the CHEBFUN f, but this leads to loss of accuracy.) Each column of lineSegs\n% represents a line in the complex plane connecting the points lVal(j) and\n% rVal(j) to each other, along with the corresponding theta value in [0,2*pi].\ntheta = ends(discont);\nlineSegs = chebfun([lVal(discont) ; rVal(discont)], [-1 1], 'tech', @chebtech2);\n\nend\n\nfunction z = fovCurve(theta, A)\nz = NaN(size(theta));\nfor j = 1:length(theta)\n r = exp(1i*theta(j));\n B = r*A;\n H = (B + B')/2;\n [X, D] = eig(H);\n [ignored, k] = max(diag(D));\n v = X(:,k);\n z(j) = v'*A*v/(v'*v);\nend\nend\n\n", "meta": {"author": "chebfun", "repo": "chebfun", "sha": "8c49396a55e46ddd57a1d108c6a8f32e37536d54", "save_path": "github-repos/MATLAB/chebfun-chebfun", "path": "github-repos/MATLAB/chebfun-chebfun/chebfun-8c49396a55e46ddd57a1d108c6a8f32e37536d54/fov.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8723473813156294, "lm_q2_score": 0.8519528038477825, "lm_q1q2_score": 0.7431987974411212}} {"text": "function [all_theta] = oneVsAll(X, y, num_labels, lambda)\n%ONEVSALL trains multiple logistic regression classifiers and returns all\n%the classifiers in a matrix all_theta, where the i-th row of all_theta \n%corresponds to the classifier for label i\n% [all_theta] = ONEVSALL(X, y, num_labels, lambda) trains num_labels\n% logisitc regression classifiers and returns each of these classifiers\n% in a matrix all_theta, where the i-th row of all_theta corresponds \n% to the classifier for label i\n\n% Some useful variables\nm = size(X, 1);\nn = size(X, 2);\n\n% You need to return the following variables correctly \nall_theta = zeros(num_labels, n + 1);\n\n% Add ones to the X data matrix\nX = [ones(m, 1) X];\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: You should complete the following code to train num_labels\n% logistic regression classifiers with regularization\n% parameter lambda. \n%\n% Hint: theta(:) will return a column vector.\n%\n% Hint: You can use y == c to obtain a vector of 1's and 0's that tell use \n% whether the ground truth is true/false for this class.\n%\n% Note: For this assignment, we recommend using fmincg to optimize the cost\n% function. It is okay to use a for-loop (for c = 1:num_labels) to\n% loop over the different classes.\n%\n% fmincg works similarly to fminunc, but is more efficient when we\n% are dealing with large number of parameters.\n%\n% Example Code for fmincg:\n%\n% % Set Initial theta\n% initial_theta = zeros(n + 1, 1);\n% \n% % Set options for fminunc\n% options = optimset('GradObj', 'on', 'MaxIter', 50);\n% \n% % Run fmincg to obtain the optimal theta\n% % This function will return theta and the cost \n% [theta] = ...\n% fmincg (@(t)(lrCostFunction(t, X, (y == c), lambda)), ...\n% initial_theta, options);\n%\n\n\ninitial_theta = zeros(n + 1, 1);\noptions = optimset('GradObj', 'on', 'MaxIter', 50);\n\n\nfor c=1:num_labels\n \n y1 = (y==c);\n [theta] = ...\n\tfmincg(@(t)(lrCostFunction(t, X, y1, lambda)), initial_theta, options);\n\n all_theta(c,:) = theta;\n\n \n \n \n \nend;\n\n\n\n\n\n\n\n% =========================================================================\n\n\nend\n", "meta": {"author": "1094401996", "repo": "machine-learning-coursera", "sha": "e53d1021a08b0f2ab7e0840d9807ab14e24ea9bb", "save_path": "github-repos/MATLAB/1094401996-machine-learning-coursera", "path": "github-repos/MATLAB/1094401996-machine-learning-coursera/machine-learning-coursera-e53d1021a08b0f2ab7e0840d9807ab14e24ea9bb/problem_sets/ex3/oneVsAll.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.8519528057272543, "lm_q1q2_score": 0.7431987934259048}} {"text": "function bezedit(alpha, haxes, color, varargin)\n % BEZEDIT Draw and edit Bezier polynomial by dragging control points\n %\n % BEZEDIT(ALPHA) draws the graph of a 1D Bezier polynomial or\n % arbitrary degree. Draggable control points are also shown. As the\n % control points are moved, the graph is updated. \n %\n % Written by Brian G. Buss\n \n if nargin<2 \n figure;\n haxes = gca;\n set(gca, 'XLim', [-0.2 1.2]);\n end\n if nargin<3\n color = 'b';\n end\n \n s = 0:0.01:1;\n line(s, bezier_vec(alpha, s), 'LineStyle', ':', 'Color', color, 'Parent', haxes);\n hline=line(s, bezier_vec(alpha, s), 'LineStyle', '-', 'Color', color, 'Parent', haxes, varargin{:});\n \n \n for k=1:length(alpha)\n hpoints(k)=impoint(haxes, [(k-1)/5 alpha(k)]);\n setPositionConstraintFcn(hpoints(k), makeConstrainToRectFcn('impoint', [(k-1)/5 (k-1)/5], [-inf inf]));\n addNewPositionCallback(hpoints(k), @(pos)update(haxes));\n setColor(hpoints(k), color);\n \n hcmenu = get(hpoints(k), 'uicontextmenu');\n exportmenu = uimenu(hcmenu, 'Label', 'Export', 'Callback', @(a,b)export(haxes));\n set(hpoints(k), 'uicontextmenu', hcmenu);\n end\n \n setappdata(haxes, 'alpha', alpha);\n setappdata(haxes, 'impoints', hpoints);\n setappdata(haxes, 'hline', hline);\nend\n\nfunction update(haxes)\n hpoints = getappdata(haxes, 'impoints');\n hline = getappdata(haxes, 'hline');\n \n alpha = zeros(1, length(hpoints));\n for k=1:length(hpoints)\n pos = getPosition(hpoints(k));\n alpha(k) = pos(2);\n end\n \n s = 0:0.01:1;\n set(hline, 'YData', bezier_vec(alpha, s));\nend\n\nfunction export(haxes)\n hpoints = getappdata(haxes, 'impoints');\n hline = getappdata(haxes, 'hline');\n \n alpha = zeros(1, length(hpoints));\n for k=1:length(hpoints)\n pos = getPosition(hpoints(k));\n alpha(k) = pos(2);\n end\n \n name=inputdlg('Enter variable name:', 'Save Bezier parameters to base workspace', 1);\n while (~isvarname(name{1}) && ~isempty(name))\n name=inputdlg(sprintf('''%s'' is not a valid variable name.\\nEnter variable name:', name{1}), 'Save Bezier parameters to workspace', 1);\n end\n if isvarname(name{1})\n assignin('base',name{1},alpha);\n end \nend\n\nfunction y = bezier_vec(alpha, s)\n y = zeros(size(alpha,1), size(s,2));\n for k=1:length(s)\n y(:,k) = bezier(alpha, s(k));\n end\nend\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/43504-graphical-editor-for-1d-bezier-polynomials/bezedit.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.851952809486198, "lm_q2_score": 0.8723473697001441, "lm_q1q2_score": 0.7431987924639328}} {"text": "function [Q fcnEvals iter] = adaptiveSimpson(fcn, a, b, varargin)\n% adaptiveSimpson - Numerically evaluate integral, adaptive Simpson quadrature. \n%\n% function [Q fcnEvals iter] = adaptiveSimpson(fcn, a, b, varargin)\n%\n% (c) Matthias Conrad and Nils Papenberg (2007-08-03)\n% \n% Authors: \n% Matthias Conrad (e-mail: conrad@tiaco.de)\n% Nils Papenberg (e-mail: papenber@math.uni-luebeck.de)\n%\n% Version:\n%\t\tRelease date: 2008-08-12 Version: 1.2\n% MATLAB Version 7.5.0.338 (R2007b)\n%\n% Description:\n% The adaptive Simpson algorithm programmed in an iterative not recursive\n% manner\n%\n% Input arguments:\n% fcn - function to be integrated\n% a - first point of interval\n% b - final point of interval\n% #varargin - further options of algorithm\n% tol - tolerance accuracy of quadrature [ 1e-6 ]\n% parts - initial number of partitions [ 2 ]\n% maxFcnEvals - maximal number of function evaluations allowed [ 20000 ]\n% maxParts - maximal number of partitions allowed [ 8000 ]\n%\n% Output arguments:\n% Q - numerical integral of function fcn on [a,b]\n% fcnEvals - number of function evaluations\n% iter - number of iterations\n%\n% Details:\n% This function behavior is similar to of Matlab integrated function \"quadv\".\n% \n% Example:\n% Q = adaptiveSimpson(@(x) [-cos(50*x); sin(x)], 0, pi, 'tol', 1e-6)\n%\n% References:\n% [1] Gander, W. & Gautschi, W. Adaptive Quadrature - Revisited\n% Eidgenoessische technische Hochschule Zuerich, 2000.\n\n% check scalar limits of interval\nif ~isscalar(a) || ~isscalar(b)\n error('Matlab:adaptiveSimpson:Limits',...\n 'The limits of integration must be scalars.');\nend\n\n% default values\ntol = 1e-6; parts = 2; maxFcnEvals = 20000; maxParts = 8000;\n\n% rewrite default options if needed\nfor j = 1 : length(varargin) / 2\n eval([varargin{2 * j - 1},'=varargin{',int2str(2 * j),'};']);\nend\n\n% initial values, termination constant (incl. quadr factor 15), parts of interval and integral value\ntol = 15 * tol; m = parts; parts = 4 * parts + 1; Q = 0;\niter = 0; fcnEvals = 0; maxResolution = 0; minH = eps(b - a) / 1024;\npoleWarning = 0;\n\n% check if interval has infinite boundaries, in case substitute function\nif ~isfinite(a) || ~isfinite(b)\n warning('Matlab:adaptiveSimpson:infiniteInterval',...\n 'The integral has an infinite interval; proceed with a substitution of function on finite interval.')\n if ~isfinite(a) && isfinite(b)\n [Q fcnEvals iter] = adaptiveSimpson(fcn, 0, b, varargin);\n fcn = @(t) infiniteLeft(t, fcn);\n a = 0; b = 1;\n elseif isfinite(a) && ~isfinite(b)\n [Q fcnEvals iter] = adaptiveSimpson(fcn, a, 0, varargin);\n fcn = @(t) infiniteRight(t, fcn);\n a = 0; b = 1;\n else\n fcn = @(t) infiniteBoth(t, fcn);\n a = - pi / 2; b = pi / 2;\n end\nend\n\n% choice of initial evaluation points\nt = [a + (b - a) / m * (kron(ones(1,m), [0, 0.27158, 0.72842]) + kron(0: m - 1, [1 1 1])), b];\nH = diff(t);\nt = [t(1:end-1); t(1:end-1) + H/4; t(1:end-1) + H/2; t(1:end-1) + 3 * H/4;];\nt = [t(:);b]';\n\n% initialize equidistant mesh and dimension of fcn\ny = fcn(t); fcnEvals = fcnEvals + length(y); n = size(y,1);\n\n% avoid infinities at start point of interval\nif any(~isfinite(y(:,1)))\n y(:,1) = fcn(a + eps(superiorfloat(a,b)) * (b - a));\n fcnEvals = fcnEvals + 1;\n poleWarning = 1;\nend\n\n% avoid infinities at end point of interval\nif any(~isfinite(y(:, end)))\n y(:, end) = fcn(b - eps(superiorfloat(a,b)) * (b - a));\n fcnEvals = fcnEvals + 1;\n poleWarning = 1;\nend\n\n% poles at initial points\nif ~isempty(find(~isfinite(max(abs(y))))), poleWarning = 1; end\n\n% initialize interval boundaries and values\nA = t(1:4:end-1); yA = y(:, 1:4:end-1);\nB = t(5:4:end); yB = y(:, 5:4:end);\nC = t(3:4:end-1); yC = y(:, 3:4:end-1);\nD = t(2:4:end-1); yD = y(:, 2:4:end-1);\nE = t(4:4:end-1); yE = y(:, 4:4:end-1);\n\n% adaptive Simpson iteration\nwhile 1\n\n % number of iteration\n iter = iter + 1;\n\n % Simpson formulas (on rough and fine grid)\n Q1 = kron(H, ones(n,1)) / 6 .* (yA + 4 * yC + yB);\n Q2 = kron(H, ones(n,1)) / 12 .* (yA + 4 * yD + 2 * yC + 4 * yE + yB);\n\n % difference of Simpson formulas\n diffQ = Q2 - Q1; diffQ(find(isnan(diffQ))) = 0;\n\n % intervals which do not fulfill termination criterion\n idx = find(max(abs(diffQ), [], 1) > tol);\n\n % intervals fulfill termination criterion\n idxQ = setdiff(1:length(A), idx);\n\n % check stop criterions\n STOP1 = isempty(idx); % check regular termination\n STOP2 = fcnEvals > maxFcnEvals; % check maximal function evaluations\n STOP3 = 2 * length(idx) > maxParts; % check maximal partition\n\n % regular termination\n if STOP1\n Q = Q + sum(Q2 + diffQ / 15, 2);\n break\n end\n\n % check if maximal resolution reached\n idxH = find(abs(H) < minH);\n if ~isempty(idxH)\n Q = Q + sum(Q2(idxH) + diffQ(idxH) / 15, 2);\n idx = setdiff(idx, idxH);\n idxQ = setdiff(idxQ, idxH);\n maxResolution = 1;\n % termination criterion\n if isempty(idx), break, end\n end\n\n % maximal function evaluations reached\n if STOP2\n warning('Matlab:adaptiveSimpson:MaxEvaluations',...\n 'The maximal number of function evaluations reached; singularity likely.')\n Q = Q + sum(Q2 + diffQ / 15, 2);\n break\n end\n\n % maximal partition reached\n if STOP3\n warning('Matlab:adaptiveSimpson:parts',...\n 'The maximal number of parts reached.')\n Q = Q + sum(Q2 + diffQ / 15, 2);\n break\n end\n\n % update quadrature value\n Q = Q + sum(Q2(:,idxQ) + diffQ(:,idxQ) / 15, 2);\n\n % update A, B, and C\n t = zeros(1, 2*length(idx));\n t(1:2:end) = A(idx); t(2:2:end) = C(idx); A = t;\n t(1:2:end) = C(idx); t(2:2:end) = B(idx); B = t;\n t(1:2:end) = D(idx); t(2:2:end) = E(idx); C = t;\n\n % update yA, yB, and yC\n y = zeros(n, 2*length(idx));\n y(:,1:2:end) = yA(:,idx); y(:,2:2:end) = yC(:,idx); yA = y;\n y(:,1:2:end) = yC(:,idx); y(:,2:2:end) = yB(:,idx); yB = y;\n y(:,1:2:end) = yD(:,idx); y(:,2:2:end) = yE(:,idx); yC = y;\n\n % update interval length\n H = B - A;\n\n % update D and E by interval bisection\n D = (A + H / 4); E = (A + 3 * H / 4);\n\n % calculate yD and yE\n y = fcn([D,E]); fcnEvals = fcnEvals + 4 * length(idx);\n\n % poles at new points\n if ~isempty(find(~isfinite(max(abs(y))))), poleWarning = 1; end\n\n % assign new values ob yD and yE\n yD = y(:,1:end/2); yE = y(:,end/2+1: end);\n\nend\n\n% display warnings\nif any(~isfinite(Q))\n warning('Matlab:adaptiveSimpson:Infinite',...\n 'The Quadrature of the function reached infinity or is Not-a-Number.')\nend\nif maxResolution\n warning('Matlab:adaptiveSimpson:MaxResolution',...\n 'The maximal resolution of partial interval reached; singularity likely.')\nend\nif poleWarning\n warning('Matlab:adaptiveSimpson:PoleDetection',...\n 'A detection of a pole; singularity likely.')\nend\n\nreturn\n\n% substitute function interval [-inf, 0] on [0, 1]\nfunction f = infiniteLeft(t, fcn)\nf = fcn(log(t));\nf = f ./ kron(ones(size(f,1),1), t);\nreturn\n\n% substitute function interval [0, inf] on [0, 1]\nfunction f = infiniteRight(t, fcn)\nf = fcn(-log(t));\nf = f ./ kron(ones(size(f,1),1), t);\nreturn\n\n% substitute function interval [-inf, inf] on [-pi / 2, pi / 2]\nfunction f = infiniteBoth(t, fcn)\nf = fcn(tan(t));\nf = f ./ kron(ones(size(f,1),1), cos(t).^2);\nreturn", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/21013-iterative-adaptive-simpson-and-lobatto-quadrature/adaptiveSimpson.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473680407889, "lm_q2_score": 0.8519527963298946, "lm_q1q2_score": 0.7431987795733739}} {"text": "function [ ] = bz_piTickLabel(axis,discretization)\n%bz_piTickLabel(axis) changes tick labels to 0 pi, 2pi, etc.\n%\n%%\nif ~exist('discretization','var')\n discretization = 1;\nend\n\nswitch axis\n case 'x'\n limits = xlim(gca)./pi;\n case 'y'\n limits = ylim(gca)./pi;\nend\nwhichtick = [axis,'tick'];\nwhichticklabel = [axis,'ticklabel'];\n\nticks = round(limits(1):discretization:limits(2),1);\nfor ll = 1:length(ticks)\n labels{ll} = [num2str(ticks(ll)),'\\pi'];\nend\n \nset(gca,whichtick,ticks.*pi)\nset(gca,whichticklabel,labels)\n\n\nend\n\n", "meta": {"author": "buzsakilab", "repo": "buzcode", "sha": "2d700a38b3c2a860ad1333be90f14d7a37a72815", "save_path": "github-repos/MATLAB/buzsakilab-buzcode", "path": "github-repos/MATLAB/buzsakilab-buzcode/buzcode-2d700a38b3c2a860ad1333be90f14d7a37a72815/visualization/bz_piTickLabel.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8918110396870287, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.7431680755877625}} {"text": "function [imgw, imgwr, map] = tpswarp(img, outDim, Zp, Zs, interp)\n%\n% Description: Thin-Plane spline warping of the input image (img) to\n% output image (imgw). The warping is defined by a set of reference points\n% (Zp=[Xp Yp]) on the [img] image and a set of corresponding points (Zs)\n% on the (imgw) image. The warping will translate Zp in img to Zs in imgw.\n%\n% Input:\n% img - input image\n% outDim - Output canvas ([W H])\n% Zp - landmark in img\n% Zs - landmark in canvas\n% interp.method - interpolation mode('nearest', 'invdist', 'none')\n% interp.radius - Max radius for nearest neighbor interpolation or\n% Radius of inverse weighted interpolation\n% interp.power - power for inverse weighted interpolation\n%\n% Output:\n% imgw - warped image with no holes\n% imgwr - warped image with holes\n% map - Map of the canvas with 0 indicating holes and 1 indicating pixel\n%\n% Reference:\n% F.L. Bookstein, \"Principal Warps: Thin-Plate splines and the\n% decomposition of deformations\", IEEE Transaction on Pattern Analysis and\n% Machine Intelligence, Vol. 11, No. 6, June 1989\n%\n% Author: Fitzgerald J Archibald\n% Date: 07-Apr-09\n\n%% Initialization\nNPs = size(Zp,1); % number of landmark points\n\nimgH = size(img,1); % height\nimgW = size(img,2); % width\n\noutH = outDim(2);\noutW = outDim(1);\n\n% landmark in input\nXp = Zp(:,1)';\nYp = Zp(:,2)';\n\n% landmark in output (homologous)\nXs = Zs(:,1)';\nYs = Zs(:,2)';\n\n%% Algebra of Thin-plate splines\n\n% Compute thin-plate spline mapping [W|a1 ax ay] using landmarks\n[wL]=computeWl(Xp, Yp, NPs);\nwY = [Xs(:) Ys(:); zeros(3,2)]; % Y = ( V| 0 0 0)' where V = [G] where G is landmark homologous (nx2) ; Y is col vector of length (n+3)\nwW = inv(wL)*wY; % (W|a1 ax ay)' = inv(L)*Y\n\n% Thin-plate spline mapping (Map all points in the plane)\n% f(x,y) = a1 + ax * x + ay * y + SUM(wi * U(|Pi-(x,y)|)) for i = 1 to n\n[Xw, Yw]=tpsMap(wW, imgH, imgW, Xp, Yp, NPs);\n\n%% Warping\n\n% input grid for warping\n[X Y] = meshgrid(1:imgH,1:imgW); % HxW\n\n% Nearest neighbor or inverse distance weighted based interpolation\n[imgw,imgwr,map] = interp2d(X(:), Y(:), img, Xw, Yw, outH, outW, interp);\n\nreturn\n\n%% [L] = [[K P];[P' 0]]\n% np - number of landmark points\n% (xp, yp) - coordinate of landmark points\nfunction [wL]=computeWl(xp, yp, np)\n\nrXp = repmat(xp(:),1,np); % 1xNp to NpxNp\nrYp = repmat(yp(:),1,np); % 1xNp to NpxNp\n\nwR = sqrt((rXp-rXp').^2 + (rYp-rYp').^2); % compute r(i,j)\n\nwK = radialBasis(wR); % compute [K] with elements U(r)=r^2 * log (r^2)\nwP = [ones(np,1) xp(:) yp(:)]; % [P] = [1 xp' yp'] where (xp',yp') are n landmark points (nx2)\nwL = [wK wP;wP' zeros(3,3)]; % [L] = [[K P];[P' 0]]\n\nreturn\n\n\n%% Mapping: f(x,y) = a1 + ax * x + ay * y + SUM(wi * U(|Pi-(x,y)|)) for i = 1 to n\n% np - number of landmark points\n% (xp, yp) - coordinate of landmark points\nfunction [Xw, Yw]=tpsMap(wW, imgH, imgW, xp, yp, np)\n\n[X Y] = meshgrid(1:imgH,1:imgW); % HxW\nX=X(:)'; % convert to 1D array by reading columnwise (NWs=H*W)\nY=Y(:)'; % convert to 1D array (NWs)\nNWs = length(X); % total number of points in the plane\n\n% all points in plane\nrX = repmat(X,np,1); % Np x NWs\nrY = repmat(Y,np,1); % Np x NWs\n\n% landmark points\nrxp = repmat(xp(:),1,NWs); % 1xNp to Np x NWs\nryp = repmat(yp(:),1,NWs); % 1xNp to Np x NWs\n\n% Mapping Algebra\nwR = sqrt((rxp-rX).^2 + (ryp-rY).^2); % distance measure r(i,j)=|Pi-(x,y)|\n\nwK = radialBasis(wR); % compute [K] with elements U(r)=r^2 * log (r^2)\nwP = [ones(NWs,1) X(:) Y(:)]'; % [P] = [1 x' y'] where (x',y') are n landmark points (nx2)\nwL = [wK;wP]'; % [L] = [[K P];[P' 0]]\n\nXw = wL*wW(:,1); % [Pw] = [L]*[W]\nYw = wL*wW(:,2); % [Pw] = [L]*[W]\n\nreturn\n\n%% k=(r^2) * log(r^2)\nfunction [ko]=radialBasis(ri)\n\nr1i = ri;\nr1i(find(ri==0))=realmin; % Avoid log(0)=inf\nko = 2*(ri.^2).*log(r1i);\n\nreturn\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/24315-warping-using-thin-plate-splines/tpsWarp/tpswarp.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045996818986, "lm_q2_score": 0.8376199633332891, "lm_q1q2_score": 0.7431402842546774}} {"text": "function prob_test011 ( )\n\n%*****************************************************************************80\n%\n%% TEST011 tests BETA, GAMMA.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 15 April 2009\n%\n% Author:\n%\n% John Burkardt\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TEST011\\n' );\n fprintf ( 1, ' BETA evaluates the Beta function;\\n' );\n fprintf ( 1, ' GAMMA evaluates the Gamma function.\\n' );\n\n a = 2.2;\n b = 3.7;\n\n beta1 = beta ( a, b );\n beta2 = gamma ( a ) * gamma ( b ) / gamma ( a + b );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Argument A = %14f\\n', a );\n fprintf ( 1, ' Argument B = %14f\\n', b );\n fprintf ( 1, ' Beta(A,B) = %14f\\n', beta1 );\n fprintf ( 1, ' (Expected value = 0.0454 )\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Gamma(A)*Gamma(B)/Gamma(A+B) = %14f\\n', beta2 );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/prob/prob_test011.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171068, "lm_q2_score": 0.837619961306541, "lm_q1q2_score": 0.7431402774603084}} {"text": "function jac = p30_jac ( neqn, t, y )\n\n%*****************************************************************************80\n%\n%% P30_JAC evaluates the jacobian for problem p30.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 23 February 2013\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer NEQN, the number of equations.\n%\n% Input, real T, Y(NEQN), the arguments of the jacobian.\n%\n% Output, real JAC(NEQN,NEQN), the jacobian matrix.\n%\n jac = zeros ( neqn, neqn );\n\n csum = 0.0;\n for i = 1 : 19\n csum = csum + i.^(4.0/3.0);\n end\n\n pprime = 0.0;\n for i = 1 : 19\n pprime = pprime + ( 4.0 / 3.0 ) * r8_cube_root ( t - i );\n end\n\n jac(1,1) = pprime / csum;\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_ode/p30_jac.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8872045877523147, "lm_q2_score": 0.8376199613065411, "lm_q1q2_score": 0.7431402724640797}} {"text": "function [H] = rotate(f)\n\n% ROTATE returns the homogenous coordinate transformation matrix\n% corresponding to a rotation around the x, y and z-axis. The direction of\n% the rotation is according to the right-hand rule.\n%\n% Use as\n% [H] = rotate(R)\n% where\n% R [rx, ry, rz] in degrees\n% H corresponding homogenous transformation matrix\n%\n% Note that the order in which the rotations are performs matters. The\n% rotation is first done around the z-axis, then the y-axis and finally the\n% x-axis.\n\n% Copyright (C) 2000-2005, Robert Oostenveld\n%\n% This program is free software; you can redistribute it and/or modify\n% it under the terms of the GNU General Public License as published by\n% the Free Software Foundation; either version 2 of the License, or\n% (at your option) any later version.\n%\n% This program is distributed in the hope that it will be useful,\n% but WITHOUT ANY WARRANTY; without even the implied warranty of\n% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n% GNU General Public License for more details.\n%\n% You should have received a copy of the GNU General Public License\n% along with this program; if not, write to the Free Software\n% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n\n% This file is part of FieldTrip, see http://www.fieldtriptoolbox.org\n% for the documentation and details.\n%\n% FieldTrip is free software: you can redistribute it and/or modify\n% it under the terms of the GNU General Public License as published by\n% the Free Software Foundation, either version 3 of the License, or\n% (at your option) any later version.\n%\n% FieldTrip is distributed in the hope that it will be useful,\n% but WITHOUT ANY WARRANTY; without even the implied warranty of\n% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n% GNU General Public License for more details.\n%\n% You should have received a copy of the GNU General Public License\n% along with FieldTrip. If not, see .\n%\n% $Id$\n\nif numel(f)~=3\n ft_error('incorrect input vector');\nend\n\n% convert degrees to radians\nf = f*pi/180;\n\n% get the individual angles (in radians)\nrx = f(1);\nry = f(2);\nrz = f(3);\n\n% precompute the sin/cos values of the angles\ncX = cos(rx);\ncY = cos(ry);\ncZ = cos(rz);\nsX = sin(rx);\nsY = sin(ry);\nsZ = sin(rz);\n\n% according to Roger Woods' http://bishopw.loni.ucla.edu/AIR5/homogenous.html\n% it should be this, but I cannot reproduce his rotation matrix\n% H = eye(4,4);\n% H(1,1) = cZ*cY + sZ*sX*sY;\n% H(1,2) = sZ*cY - cZ*sX*sY;\n% H(1,3) = cX*sY;\n% H(2,1) = -sZ*cX;\n% H(2,2) = cZ*cX;\n% H(2,3) = sX;\n% H(3,1) = sZ*sX*cY - cZ*sY;\n% H(3,2) = -cZ*sX*cY - sZ*sY;\n% H(3,3) = cX*cY;\n\n% instead, the following rotation matrix does work according my\n% expectations. It rotates according to the right hand rule and first\n% rotates around z, then y and then x axis\nH = [\n cZ*cY, -sZ*cY, sY, 0\n cZ*sY*sX+sZ*cX, -sZ*sY*sX+cZ*cX, -cY*sX, 0\n -cZ*sY*cX+sZ*sX, sZ*sY*cX+cZ*sX, cY*cX, 0\n 0, 0, 0, 1\n];\n\nif 0\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% The following code can be used to construct the combined rotation matrix\n% for either xyz or zyx ordering (using the MATLAB symbolic math toolbox)\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n syms sX sY sZ cX cY cZ\n % this is for only rotating around x\n Rx = [\n 1 0 0 0\n 0 cX -sX 0\n 0 sX cX 0\n 0 0 0 1\n ];\n % this is for only rotating around y\n Ry = [\n cY 0 sY 0\n 0 1 0 0\n -sY 0 cY 0\n 0 0 0 1\n ];\n % this is for only rotating around z\n Rz = [\n cZ -sZ 0 0\n sZ cZ 0 0\n 0 0 1 0\n 0 0 0 1\n ];\n % combine them\n Rzyx = Rz * Ry * Rx % rotate around x, y, then z\n Rxyz = Rx * Ry * Rz % rotate around z, y, then x\nend\n", "meta": {"author": "spm", "repo": "spm12", "sha": "3085dac00ac804adb190a7e82c6ef11866c8af02", "save_path": "github-repos/MATLAB/spm-spm12", "path": "github-repos/MATLAB/spm-spm12/spm12-3085dac00ac804adb190a7e82c6ef11866c8af02/external/fieldtrip/inverse/private/rotate.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425399873763, "lm_q2_score": 0.8080672112416737, "lm_q1q2_score": 0.7431329826268086}} {"text": "clear all;\naddpath('../lib');\n\n%% lets plot 3 cycles of 50Hz AC voltage\nf = 50;\nVm = 10;\nphi = 0;\n\n% generate the signal\nt = [0:0.0001:3/f];\nth = 2*pi*f*t;\nv = Vm*sin(th+phi);\n\n%% plot now\nplt = Plot(t*1E3, v);\n\nplt.XLabel = 'Time, t (ms)'; % xlabel\nplt.YLabel = 'Voltage, V (V)'; %ylabel\nplt.YTick = [-10, 0, 10]; %[tick1, tick2, .. ]\nplt.YLim = [-11, 11]; % [min, max]\nplt.XMinorTick = 'off'; % 'on' or 'off'\nplt.Colors = {[1, 0, 0], [0, 0, 1]}; %[red, green, blue]\n\nplt.FontName = 'Times';\n\n% Save? comment the following line if you do not want to save\nplt.export('plotVoltSomeOther.tiff'); \n\n ", "meta": {"author": "masumhabib", "repo": "PlotPub", "sha": "2359dea0ca741a9541d569ea42e7ba1b1445e5f2", "save_path": "github-repos/MATLAB/masumhabib-PlotPub", "path": "github-repos/MATLAB/masumhabib-PlotPub/PlotPub-2359dea0ca741a9541d569ea42e7ba1b1445e5f2/examples_class/plotSomeOther.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.919642528975397, "lm_q2_score": 0.8080672066194945, "lm_q1q2_score": 0.7431329694776366}} {"text": "function [rhsQ] = CurvedEulerRHS2D(Q, time, SolutionBC, fluxtype)\n\n% function [rhsQ] = CurvedEulerRHS2D(Q, time, SolutionBC, fluxtype)\n% Purpose: compute right hand side residual for the compressible Euler \n% gas dynamics equations\n\nGlobals2D;\n\n% 1.1 Interpolate solution to cubature nodes \ncQ = zeros(cub.Ncub, K, 4);\nfor n=1:4, cQ(:,:,n) = cub.V*Q(:,:,n); end;\n\n% 1.2 Evaluate flux function at cubature nodes\ngamma = 1.4;\n[F,G,rho,u,v,p] = EulerFluxes2D(cQ, gamma);\n\n% 1.3 Compute volume terms (dphidx, F) + (dphidy, G)\nrhsQ = zeros(Np, K, 4);\nfor n=1:4\n ddr = (cub.Dr')*(cub.W.*(cub.rx.*F(:,:,n) + cub.ry.*G(:,:,n)));\n dds = (cub.Ds')*(cub.W.*(cub.sx.*F(:,:,n) + cub.sy.*G(:,:,n)));\n rhsQ(:,:,n) = ddr + dds;\nend\n\n% 2.1 SURFACE TERMS (using Gauss nodes on element faces)\nnx = gauss.nx; ny = gauss.ny; \nmapW = gauss.mapW; mapI = gauss.mapI; mapO = gauss.mapO; mapB = gauss.mapB; mapC = gauss.mapC;\n\n% 2.2 Interpolate solution to Gauss surface nodes\ngQM = zeros(gauss.NGauss*Nfaces, K, 4); gQP = zeros(gauss.NGauss*Nfaces, K, 4);\nfor n=1:4\n gQ = gauss.interp*Q(:,:,n);\n gQM(:,:,n) = gQ(gauss.mapM); gQP(:,:,n) = gQ(gauss.mapP);\nend \n\n% 2.3 Apply boundary conditions to '+' traces\nif(~isempty(SolutionBC))\n gQP = feval(SolutionBC, gauss.x, gauss.y, gauss.nx, gauss.ny, gauss.mapI, ...\n gauss.mapO, gauss.mapW, gauss.mapC, gQP, time);\nend\n\n% 2.4 Evaluate surface flux functions with stabilization\nswitch fluxtype\n case {'LF'}\n [flux] = EulerLF2D (nx, ny, gQM, gQP, gamma); \n case {'Roe'}\n [flux] = EulerRoe2D(nx, ny, gQM, gQP, gamma); \n case {'HLL'}\n [flux] = EulerHLL2D(nx, ny, gQM, gQP, gamma); \n case {'HLLC'}\n [flux] = EulerHLLC2D(nx, ny, gQM, gQP, gamma); \nend\n\n% 2.5 Compute surface integral terms\nfor n=1:4\n rhsQ(:,:,n) = rhsQ(:,:,n) - gauss.interp'*(gauss.W.*flux(:,:,n));\nend\n\n% 3.1 Multiply by inverse mass matrix\nfor n=1:4\n % 3.1.a Multiply straight sided elements by inverse mass matrix\n rhsQ(:,straight, n) = V*V'*(rhsQ(:,straight, n)./J(:,straight));\n\n % 3.1.b Multiply curvilinear elements by custom inverse mass matrices\n Ncurved = length(curved);\n for m=1:Ncurved\n k = curved(m);\n mmCHOL = cub.mmCHOL(:,:,k);\n rhsQ(:,k,n) = mmCHOL\\(mmCHOL'\\rhsQ(:,k,n));\n end\nend\nreturn;\n", "meta": {"author": "wme7", "repo": "Aero-matlab", "sha": "9430008f2e3b84f28633775a44dff534e780fbac", "save_path": "github-repos/MATLAB/wme7-Aero-matlab", "path": "github-repos/MATLAB/wme7-Aero-matlab/Aero-matlab-9430008f2e3b84f28633775a44dff534e780fbac/JSHesthaven&TWarburton/CFD2D/CurvedEulerRHS2D.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299653388754, "lm_q2_score": 0.803173801068221, "lm_q1q2_score": 0.7431204681234429}} {"text": "\nfunction [A, AH, normA] = MakeTransforms(type, N, params)\n\n% [A, AH] = MakeTransforms(type, N, params)\n% with A AH = I\n%\n% INPUT\n% N : signal length\n% type : type of transform can be 'DFT' or 'STFT'\n% params : parameters for transform\n%\n% For DFT, params = [Nfft]\n% Nfft = number of DFT coefficients, Nfft >= N\n% Nfft/N is over-sampling factor\n%\n% For STFT, params = [R, Nfft]\n% R = length of frame\n% Nfft = number of DFT coefficients, Nfft >= R\n%\n% For DCT, params = [Ndct]\n% Ndct = number of DCT coefficients, Ndct >= N\n% Ndct/N is over-sampling factor\n%\n% For STDCT, params = [R, Ndct]\n% R = length of frame\n% Ndct = number of DCT coefficients, Ndct >= R\n%\n% OUTPUT\n% A, AH : function handles for transform\n% AH is the conjugate transpose of A\n% Note: input to AH must be a row vector of length N\n\n% DFT : Discrete Fourier transform with zero-padding\n% STFT : Short-time Fourier transform\n% DCT : Discrete cosine transform with zero-padding\n% STDCT : Short-time DCT\n\nswitch type\n case '2D-CDWT'\n [Faf, Fsf] = FSfarras;\n [af, sf] = dualfilt1;\n AH = @(x) cplxdual2D(x,params(1),Faf,af);\n A = @(x) icplxdual2D(x,params(1),Fsf,sf);\n \n normA = 1;\n \n case 'DWT'\n [h0, h1, g0, g1] = daubf(params(2)); % Get filters\n AH = @(x) udwt(x, params(1), h0, h1);\n A = @(x) iudwt(x, params(1), g0, g1);\n normA = 1;\n case '2D-DWT'\n [Faf, Fsf] = FSfarras;\n [af, sf] = dualfilt1;\n AH = @(x) dualtree2D(x,params(1), Faf, af);\n A = @(x) idualtree2D(x,params(1), Fsf, sf);\n \n normA = 1;\n case 'DFT'\n\n % over-sampled DFT (oversampling factor = Nfft/N)\n Nfft = params(1);\n truncate = @(x, N) x(1:N);\n AH = @(x) fft(x, Nfft)/sqrt(Nfft);\n A = @(X) truncate(ifft(X), N)*sqrt(Nfft);\n \n normA = sqrt(N/Nfft);\n\n case 'STFT'\n \n R = params(1);\n M = params(2);\n K = params(3);\n Nfft = params(4);\n AH = @(x) pSTFT2(x, R, M, K, Nfft);\n A = @(x) ipSTFT2(x,R,M,K,N); \n\n normA = sqrt(R/(M*Nfft));\n\n case 'DCT'\n\n % over-sampled DFT (oversampling factor = Nfft/N)\n Ndct = params(1);\n truncate = @(x, N) x(1:N);\n AH = @(x) dct(x, Ndct);\n A = @(X) truncate(idct(X), N);\n \n normA = sqrt(N/Ndct);\n \n case 'STDCT'\n \n R = params(1);\n M = params(2);\n K = params(3);\n Ndct = params(4);\n AH = @(x) stdct(x, R,M,K, Ndct);\n A = @(x) istdct(x, R,M,K, N); \n\n normA = sqrt(R/(2*Ndct));\n\nend\n\n% x = randn(1, N); % assuming row vector ! ! !\n% \n% % Verify perfect reconstruction property of transform 1 (A*AH = I)\n% c = AH(x);\n% err = x - A(c)';\n% re = max(abs(err(:))); % should be zero\n% fprintf('Reconstruction error = %f\\n', re)\n% \n% % Verify Parseval energy identity\n% E = sum(abs(x(:)).^2);\n% E1 = sum(abs(c(:)).^2); % should be unity\n% fprintf('Energy ratio = %f\\n', E/E1)\n\n", "meta": {"author": "thomaskuestner", "repo": "CS_MoCo_LAB", "sha": "a26e8e483624b2e4ee669e7a069ba9c74d2d2e4b", "save_path": "github-repos/MATLAB/thomaskuestner-CS_MoCo_LAB", "path": "github-repos/MATLAB/thomaskuestner-CS_MoCo_LAB/CS_MoCo_LAB-a26e8e483624b2e4ee669e7a069ba9c74d2d2e4b/reconstruction/matlab/CS_LAB_matlab/utils/utils_Proximal/Denoising/MakeTransforms.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299570920387, "lm_q2_score": 0.8031738034238807, "lm_q1q2_score": 0.7431204636793266}} {"text": "function [power] = VBA_power(type, alpha, Estat, dof)\n% // VBA toolbox //////////////////////////////////////////////////////////\n%\n% [power] = VBA_power(type, alpha, Estat, dof)\n% Statistical power of a t- or F-test\n%\n% IN:\n% - type: type of test. Can be set to 't' or 'F'.\n% - alpha: statistical significance level\n% - Estat: expected effect size (z-score for a t-test, F value for an\n% F-test)\n% - dof: degrees of freedom\n%\n% OUT:\n% - power: ensuing statistical power\n%\n% /////////////////////////////////////////////////////////////////////////\n\n% ensure numerical stability\ndof(isinf(dof)) = 1e8;\ndof(dof==0) = 1e-8;\n\nswitch type\n case 't'\n tcritic = VBA_spm_invTcdf (1 - alpha, dof);\n power = 1 - VBA_spm_Tcdf (tcritic - Estat, dof);\n case 'F'\n Fcritic = VBA_spm_invFcdf (1 - alpha, dof(1), dof(2));\n power = 1-VBA_ncfcdf (Fcritic, dof(1), dof(2), Estat); \n otherwise\n disp('*** VBA_power: ''type'' argument can only be ''t'' or ''F''')\n power = [];\n return\nend\n\n", "meta": {"author": "MBB-team", "repo": "VBA-toolbox", "sha": "01ff63f43ef7a6473bc5e3f28dd9ffa58fcfb414", "save_path": "github-repos/MATLAB/MBB-team-VBA-toolbox", "path": "github-repos/MATLAB/MBB-team-VBA-toolbox/VBA-toolbox-01ff63f43ef7a6473bc5e3f28dd9ffa58fcfb414/utils/VBA_power.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133565584851, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.7430300099205636}} {"text": "function lorenza\n% Lorenz convection model \n\nsigma = 16; rho = 45.92; beta = 4; % parameters \nN = 1000; % no. of time steps\nspan = 0.05; % inner iteration span\nAbsTol = 1.e-5; % absolute tolerance for ODE solver\nRelTol = 1.e-5; % relative tolerance for ODE solver\n\nH = figure; set(H,'DefaultLineLineWidth',1.0);\noptions = odeset('RelTol',RelTol,'AbsTol',ones(1,3)*AbsTol);\nu0 = [1;1;1];\nfor i = 1:N\n [t,u] = ode45(@lornz,[0 span],u0,odeset,beta,rho,sigma);\n hold on; \n plot(u(:,1),u(:,2),'r'); \n u0 = u(end,:); \nend\n\ntitle('Attractor of Lorenz System');\nxlabel('Component 1'); ylabel('Component 2');\naxis off; hold off;\n\nfunction dydt = lornz(t,y,beta,rho,sigma)\ndydt = [sigma*(y(2)-y(1)); rho*y(1)-y(2)-y(1)*y(3); y(1)*y(2)-beta*y(3)];", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/15646-environmental-modeling/lorenza.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133498259924, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.7430299976405729}} {"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% intlinear.m\n%\n%[A,B] = intlinear(x,y)\n%\n% Does de linear regression (least mean squares) for given (x,y).\n% Returns A and B, with meaning y = A + B*x.\n\nfunction [A,B] = intlinear(x,y)\n\nmx = mean(x); my = mean(y);\nmx2 = mean(x.^2); my2 = mean(y.^2);\nmxy = mean(x.*y);\nA = (mx2*my-mx*mxy)/(mx2-mx^2);\nB = (mxy - (mx*my))/(mx2-mx^2);\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/11392-acmus-room-acoustic-parameters/intlinear.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.952574122783325, "lm_q2_score": 0.7799928900257127, "lm_q1q2_score": 0.7430010429934738}} {"text": "function cond = condition_sample1 ( n, a, m )\n\n%*****************************************************************************80\n%\n%% CONDITION_SAMPLE1 estimates the L1 condition number of a matrix.\n%\n% Discussion:\n%\n% A naive sampling method is used.\n%\n% Only \"forward\" sampling is used, that is, we only look at results\n% of the form y=A*x.\n%\n% Presumably, solving systems A*y=x would give us a better idea of\n% the inverse matrix.\n%\n% Moreover, a power sequence y1 = A*x, y2 = A*y1, ... and the same for\n% the inverse might work better too.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 04 October 2012\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the dimension of the matrix.\n%\n% Input, real A(N,N), the matrix.\n%\n% Input, integer M, the number of samples to use.\n%\n% Output, real COND, an estimate of the L1 condition number.\n%\n a_norm = 0.0;\n ainv_norm = 0.0;\n seed = 123456789;\n\n for i = 1 : m\n\n [ x, seed ] = r8vec_uniform_unit ( n, seed );\n x_norm = norm ( x, 1 );\n ax = a * x;\n ax_norm = norm ( ax, 1 );\n\n if ( ax_norm == 0.0 )\n cond = 0.0;\n return\n end\n\n a_norm = max ( a_norm, ax_norm / x_norm );\n ainv_norm = max ( ainv_norm, x_norm / ax_norm );\n\n end\n\n cond = a_norm * ainv_norm;\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/condition/condition_sample1.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772286044094, "lm_q2_score": 0.8499711775577735, "lm_q1q2_score": 0.7429404512733251}} {"text": "function pass = test_hermpoly( prefs ) \n% Test the HERMPOLY command. \n\nif ( nargin < 1 ) \n prefs = chebfunpref(); \nend\ntol = 1e6*prefs.techPrefs.chebfuneps;\n\n% Physicists' Hermite polynomials\nh0 = hermpoly(0); \nerr = norm( h0 - chebfun(@(x) 1+0*x, [-inf,inf] ) );\npass(1) = err < tol;\n\nh1 = hermpoly(1); \nerr = norm( h1 - chebfun(@(x) 2*x, [-inf,inf] ) );\npass(2) = err < tol;\n\nh2 = hermpoly(2); \nerr = norm( h2 - chebfun(@(x) 4*x.^2-2, [-inf,inf] ) );\npass(3) = err < tol;\n\nh3 = hermpoly(3); \nx = linspace(-1,1);\nerr = norm( feval(h3,x) - 8*x.^3+12*x );\npass(4) = err < tol;\n\nh4 = hermpoly(4); \nx = linspace(-1,1);\nerr = norm( feval(h4,x) - (16*x.^4-48*x.^2+12) );\npass(5) = err < tol;\n\nh5 = hermpoly(5); \nx = linspace(-1,1);\nerr = norm( feval(h5,x) - (32*x.^5-160*x.^3+120*x) );\npass(6) = err < 10*tol;\n\nh6 = hermpoly(6); \nx = linspace(-1,1);\nerr = norm( feval(h6,x) - (64*x.^6-480*x.^4+720*x.^2-120) );\npass(7) = err < 100*tol;\n\n% probabilists' Hermite polynomials:\nh0 = hermpoly(0, 'prob'); \nerr = norm( h0 - chebfun(@(x) 1+0*x, [-inf,inf] ) );\npass(8) = err < tol;\n\nh1 = hermpoly(1, 'prob'); \nerr = norm( h1 - chebfun(@(x) x, [-inf,inf] ) );\npass(9) = err < tol;\n\nh2 = hermpoly(2, 'prob');\ng2 = chebfun(@(x) x.^2-1, [-inf,inf] );\nerr = norm( h2 - chebfun(@(x) x.^2-1, [-inf,inf] ) );\npass(10) = err < tol;\n\nh3 = hermpoly(3, 'prob'); \nx = linspace(-1,1);\nerr = norm( feval(h3,x) - (x.^3-3*x) );\npass(11) = err < tol;\n\nh4 = hermpoly(4, 'prob'); \nx = linspace(-1,1);\nerr = norm( feval(h4,x) - (x.^4-6*x.^2+3) );\npass(12) = err < tol;\n\nh5 = hermpoly(5, 'prob'); \nx = linspace(-1,1);\nerr = norm( feval(h5,x) - (x.^5-10*x.^3+15*x) );\npass(13) = err < tol;\n\nh6 = hermpoly(6, 'prob'); \nx = linspace(-1,1);\nnorm( feval(h6,x) - (x.^6-15*x.^4+45*x.^2-15) );\npass(14) = err < 10*tol;\n", "meta": {"author": "chebfun", "repo": "chebfun", "sha": "8c49396a55e46ddd57a1d108c6a8f32e37536d54", "save_path": "github-repos/MATLAB/chebfun-chebfun", "path": "github-repos/MATLAB/chebfun-chebfun/chebfun-8c49396a55e46ddd57a1d108c6a8f32e37536d54/tests/misc/test_hermpoly.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336202, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.74293754330806}} {"text": "function b = r8pbu_ml ( n, mu, a_lu, x )\n\n%*****************************************************************************80\n%\n%% R8PBU_ML multiplies a vector times a matrix that was factored by R8PBU_FA.\n%\n% Discussion:\n%\n% The R8PBU storage format is for a symmetric positive definite band matrix.\n%\n% To save storage, only the diagonal and upper triangle of A is stored,\n% in a compact diagonal format that preserves columns.\n%\n% The diagonal is stored in row MU+1 of the array.\n% The first superdiagonal in row MU, columns 2 through N.\n% The second superdiagonal in row MU-1, columns 3 through N.\n% The MU-th superdiagonal in row 1, columns MU+1 through N.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 21 February 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the order of the matrix.\n% N must be positive.\n%\n% Input, integer MU, the number of superdiagonals of the matrix.\n% MU must be at least 0 and no more than N-1.\n%\n% Input, real A_LU(MU+1,N), the matrix, as factored by R8PBU_FA.\n%\n% Input, real X(N), the vector to be multiplied by A.\n%\n% Output, real B(N), the product A * x.\n%\n b(1:n) = x(1:n);\n%\n% Multiply U * X = Y.\n%\n for k = 1 : n\n\n ilo = max ( 1, k - mu );\n for i = ilo : k - 1\n b(i) = b(i) + a_lu(mu+1+i-k,k) * b(k);\n end\n\n b(k) = a_lu(mu+1,k) * b(k);\n\n end\n%\n% Multiply L * Y = B.\n%\n for k = n : -1 : 1\n\n jhi = min ( k + mu, n );\n for j = k + 1 : jhi\n b(j) = b(j) + a_lu(mu+1+k-j,j) * b(k);\n end\n\n b(k) = a_lu(mu+1,k) * b(k);\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/linplus/r8pbu_ml.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513648201267, "lm_q2_score": 0.8289388040954683, "lm_q1q2_score": 0.7429375345229271}} {"text": "% This function compute the instantaneous frequency from phase spectrogram\n% Input: \n% phase: D x T matrix of phase spectrogram, where D is FFT-bin number and\n% T is number of frames. \n% Output: \n% instantaneous frequency of the size size as phase. \n% The implementation is based on equation (3) of \n% Krawczyk, Martin, and Timo Gerkmann. \"STFT Phase Reconstruction in \n% Voiced Speech for an Improved Single-Channel Speech Enhancement.\" (2014).\n%\n% Author: Xiong Xiao, Nanyang Tech. Univ., Singapore. \n% Created: 06 Jan 2015\n% Last modified: 06 Jan 2015\n%\nfunction [instan_freq] = comp_instan_freq(phase)\n\nphase_delta = phase(:,2:end) - phase(:,1:end-1);\nphase_delta = [phase(:,1) phase_delta];\n\n[dim, nFr] = size(phase_delta);\n\nphase_delta_vec = reshape(phase_delta, dim*nFr, 1);\nphase_delta_vec = get_principal_value(phase_delta_vec);\ninstan_freq = reshape(phase_delta_vec, dim, nFr);\n\n\n\nif 0 \n subplot(3,1,1); imagesc(phase); title('Phase'); colorbar;\n subplot(3,1,2); imagesc(phase_delta); title('Phase delta');colorbar;\n subplot(3,1,3); imagesc(instan_freq); title('Phase delta principal value - Instantaneous frequency');colorbar;\nend\n\nend\n\nfunction phase_delta_vec = get_principal_value(phase_delta_vec)\nidx = find(phase_delta_vec>pi);\nphase_delta_vec(idx) = phase_delta_vec(idx) - 2*pi;\n\nidx = find(phase_delta_vec<-pi);\nphase_delta_vec(idx) = phase_delta_vec(idx) + 2*pi;\n\nend\n", "meta": {"author": "singaxiong", "repo": "SignalGraph", "sha": "e86d973556ae8796a05ee2adbd665f47c8525a21", "save_path": "github-repos/MATLAB/singaxiong-SignalGraph", "path": "github-repos/MATLAB/singaxiong-SignalGraph/SignalGraph-e86d973556ae8796a05ee2adbd665f47c8525a21/signal/phase/comp_instan_freq.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898305367525, "lm_q2_score": 0.8198933403143929, "lm_q1q2_score": 0.7428150284496488}} {"text": "% GAUSSIAN_DLOGPDF_COV - The gradient of the log pdf of a multivariate\n% normal distribution with respect to the covariance\n% matrix.\n%\n% Computes the gradient of the logarithm of the multivariate normal\n% probability density function N(Y|MU,COV), where Y is the random variable,\n% MU is the mean and COV is the covariance. The gradient is evaluated with\n% respect to the covariance matrix COV and returned in matrix form.\n%\n% d(LOG(N(Y|MU,COV))) / dCOV\n%\n% Usage:\n%\n% DX = GAUSSIAN_DLOGPDF_COV(INVCOV_Y, INVCOV_MU, INVCOV)\n%\n% where\n%\n% INVCOV_Y : INV(COV)*Y\n% INVCOV_MU : INV(COV)*MU\n% INVCOV : INV(COV)\n%\n% Letting the user to compute the terms allows greater efficiency and\n% flexibility.\n\n% Last modified 2010-11-19\n% Copyright (c) Jaakko Luttinen\n\nfunction dx = gaussian_dlogpdf_cov(invCov_y, invCov_mu, invCov)\n\n% $$$ if nargin == 3\n% $$$ y = varargin{1};\n% $$$ mu = varargin{2};\n% $$$ L = varargin{3};\n% $$$ invCov_y = linsolve_chol(L, y, 'lower');\n% $$$ invCov_mu = linsolve_chol(L, mu, 'lower');\n% $$$ invCov = linsolve_chol(L, eye(size(L)), 'lower');\n% $$$ end\n\ndx = - 0.5 * invCov ...\n + 0.5 * (invCov_y * invCov_y' - ...\n invCov_y * invCov_mu' - ...\n invCov_mu * invCov_y' + ...\n invCov_mu * invCov_mu');\n\n\n", "meta": {"author": "jluttine", "repo": "matlab", "sha": "63406c7782b0869948f06e1dbc594460c165d24e", "save_path": "github-repos/MATLAB/jluttine-matlab", "path": "github-repos/MATLAB/jluttine-matlab/matlab-63406c7782b0869948f06e1dbc594460c165d24e/distributions/gaussian_dlogpdf_cov.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012655937033, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.7427458544375495}} {"text": "function [ x, w ] = bashforth_set ( n )\n\n%*****************************************************************************80\n%\n%% BASHFORTH_SET sets abscissas and weights for Adams-Bashforth quadrature.\n%\n% Discussion:\n%\n% Adams-Bashforth quadrature formulas are normally used in solving\n% ordinary differential equations, and are not really suitable for\n% general quadrature computations. However, an Adams-Bashforth formula\n% is equivalent to approximating the integral of F(Y(X)) between X(M)\n% and X(M+1), using an explicit formula that relies only on known values\n% of F(Y(X)) at X(M-N+1) through X(M). For this reason, the formulas\n% have been included here.\n%\n% Suppose the unknown function is denoted by Y(X), with derivative\n% F(Y(X)), and that approximate values of the function are known at a\n% series of X values, which we write as X(1), X(2), ..., X(M). We write\n% the value Y(X(1)) as Y(1) and so on.\n%\n% Then the solution of the ODE Y'=F(X,Y) at the next point X(M+1) is\n% computed by:\n%\n% Y(M+1) = Y(M) + Integral ( X(M) < X < X(M+1) ) F(Y(X)) dX\n% = Y(M) + H * Sum ( 1 <= I <= N ) W(I) * F(Y(M+1-I)) approximately.\n%\n% In the documentation that follows, we replace F(Y(X)) by F(X).\n%\n% The integral:\n%\n% Integral ( 0 <= X <= 1 ) F(X) dX.\n%\n% The quadrature rule:\n%\n% Sum ( 1 <= I <= N ) W(I) * F ( 1 - I ),\n%\n% The Adams-Bashforth formulas require equally spaced data.\n%\n% Here is how the formula is applied in the case with non-unit spacing:\n%\n% Integral ( A <= X <= A+H ) F(X) dX =\n% H * Sum ( 1 <= I <= N ) W(I) * F ( A - (I-1)*H ),\n% approximately.\n%\n% The reference lists the second coefficient of the order 8 Adams-Bashforth\n% formula as\n% w(2) = -1162169.0 / 120960.0\n% but this should be\n% w(2) = -1152169.0 / 120960.0\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 28 April 2006\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Milton Abramowitz, Irene Stegun,\n% Handbook of Mathematical Functions,\n% National Bureau of Standards, 1964.\n%\n% Jean Lapidus, John Seinfeld,\n% Numerical Solution of Ordinary Differential Equations,\n% Academic Press, 1971.\n%\n% Daniel Zwillinger, editor,\n% Standard Mathematical Tables and Formulae,\n% 30th Edition,\n% CRC Press, 1996.\n%\n% Parameters:\n%\n% Input, integer N, the order. \n% N should be between 1 and 10, or 12, 14, 16, 18 or 20.\n%\n% Output, real X(N), the abscissas.\n%\n% Output, real W(N), the weights.\n% W(1) is the weight at X = 0, W(2) the weight at X = -1,\n% and so on. The weights are rational, and should sum to 1. Some\n% weights may be negative.\n%\n x = zeros ( n, 1 );\n w = zeros ( n, 1 );\n\n if ( n == 1 )\n\n w(1) = 1.0;\n\n elseif ( n == 2 )\n\n d = 2.0;\n\n w(1) = 3.0 / d;\n w(2) = - 1.0 / d;\n\n elseif ( n == 3 )\n\n d = 12.0;\n\n w(1) = 23.0 / d;\n w(2) = - 16.0 / d;\n w(3) = 5.0 / d;\n\n elseif ( n == 4 )\n\n d = 24.0;\n\n w(1) = 55.0 / d;\n w(2) = - 59.0 / d;\n w(3) = 37.0 / d;\n w(4) = - 9.0 / d;\n\n elseif ( n == 5 )\n\n d = 720.0;\n\n w(1) = 1901.0 / d;\n w(2) = - 2774.0 / d;\n w(3) = 2616.0 / d;\n w(4) = - 1274.0 / d;\n w(5) = 251.0 / d;\n\n elseif ( n == 6 )\n\n d = 1440.0;\n\n w(1) = 4277.0 / d;\n w(2) = - 7923.0 / d;\n w(3) = 9982.0 / d;\n w(4) = - 7298.0 / d;\n w(5) = 2877.0 / d;\n w(6) = - 475.0 / d;\n\n elseif ( n == 7 )\n\n d = 60480.0;\n\n w(1) = 198721.0 / d;\n w(2) = - 447288.0 / d;\n w(3) = 705549.0 / d;\n w(4) = - 688256.0 / d;\n w(5) = 407139.0 / d;\n w(6) = - 134472.0 / d;\n w(7) = 19087.0 / d;\n\n elseif ( n == 8 )\n\n d = 120960.0;\n\n w(1) = 434241.0 / d;\n w(2) = - 1152169.0 / d;\n w(3) = 2183877.0 / d;\n w(4) = - 2664477.0 / d;\n w(5) = 2102243.0 / d;\n w(6) = - 1041723.0 / d;\n w(7) = 295767.0 / d;\n w(8) = - 36799.0 / d;\n\n elseif ( n == 9 )\n \n d = 3628800.0;\n\n w(1) = 14097247.0 / d;\n w(2) = -43125206.0 / d;\n w(3) = 95476786.0 / d;\n w(4) = -139855262.0 / d;\n w(5) = 137968480.0 / d;\n w(6) = -91172642.0 / d;\n w(7) = 38833486.0 / d;\n w(8) = -9664106.0 / d;\n w(9) = 1070017.0 / d;\n \n elseif ( n == 10 )\n \n d = 7257600.0;\n\n w( 1) = 30277247.0 / d;\n w( 2) = -104995189.0 / d;\n w( 3) = 265932680.0 / d;\n w( 4) = -454661776.0 / d;\n w( 5) = 538363838.0 / d;\n w( 6) = -444772162.0 / d;\n w( 7) = 252618224.0 / d;\n w( 8) = -94307320.0 / d;\n w( 9) = 20884811.0 / d;\n w(10) = -2082753.0 / d;\n \n elseif ( n == 12 )\n \n d = 958003200.0;\n\n w( 1) = 4527766399.0 / d;\n w( 2) = -19433810163.0 / d;\n w( 3) = 61633227185.0 / d;\n w( 4) = -135579356757.0 / d;\n w( 5) = 214139355366.0 / d;\n w( 6) = -247741639374.0 / d;\n w( 7) = 211103573298.0 / d;\n w( 8) = -131365867290.0 / d;\n w( 9) = 58189107627.0 / d;\n w(10) = -17410248271.0 / d;\n w(11) = 3158642445.0 / d;\n w(12) = -262747265.0 / d;\n \n elseif ( n == 14 )\n \n d = 5230697472000.0;\n\n w( 1) = 27511554976875.0 / d;\n w( 2) = -140970750679621.0 / d;\n w( 3) = 537247052515662.0 / d;\n w( 4) = -1445313351681906.0 / d;\n w( 5) = 2854429571790805.0 / d;\n w( 6) = -4246767353305755.0 / d;\n w( 7) = 4825671323488452.0 / d;\n w( 8) = -4204551925534524.0 / d;\n w( 9) = 2793869602879077.0 / d;\n w(10) = -1393306307155755.0 / d;\n w(11) = 505586141196430.0 / d;\n w(12) = -126174972681906.0 / d;\n w(13) = 19382853593787.0 / d;\n w(14) = -1382741929621.0 / d;\n \n elseif ( n == 16 )\n \n d = 62768369664000.0;\n\n w( 1) = 362555126427073.0 / d;\n w( 2) = -2161567671248849.0 / d;\n w( 3) = 9622096909515337.0 / d;\n w( 4) = -30607373860520569.0 / d;\n w( 5) = 72558117072259733.0 / d;\n w( 6) = -131963191940828581.0 / d;\n w( 7) = 187463140112902893.0 / d;\n w( 8) = -210020588912321949.0 / d;\n w( 9) = 186087544263596643.0 / d;\n w(10) = -129930094104237331.0 / d;\n w(11) = 70724351582843483.0 / d;\n w(12) = -29417910911251819.0 / d;\n w(13) = 9038571752734087.0 / d;\n w(14) = -1934443196892599.0 / d;\n w(15) = 257650275915823.0 / d;\n w(16) = -16088129229375.0 / d;\n \n elseif ( n == 18 )\n \n d = 64023737057280000.0;\n\n w( 1) = 401972381695456831.0 / d;\n w( 2) = -2735437642844079789.0 / d;\n w( 3) = 13930159965811142228.0 / d;\n w( 4) = -51150187791975812900.0 / d;\n w( 5) = 141500575026572531760.0 / d;\n w( 6) = -304188128232928718008.0 / d;\n w( 7) = 518600355541383671092.0 / d;\n w( 8) = -710171024091234303204.0 / d;\n w( 9) = 786600875277595877750.0 / d;\n w(10) = -706174326992944287370.0 / d;\n w(11) = 512538584122114046748.0 / d;\n w(12) = -298477260353977522892.0 / d;\n w(13) = 137563142659866897224.0 / d;\n w(14) = -49070094880794267600.0 / d;\n w(15) = 13071639236569712860.0 / d;\n w(16) = -2448689255584545196.0 / d;\n w(17) = 287848942064256339.0 / d;\n w(18) = -15980174332775873.0 / d;\n \n elseif ( n == 20 )\n \n d = 102181884343418880000.0;\n\n w( 1) = 691668239157222107697.0 / d;\n w( 2) = -5292843584961252933125.0 / d;\n w( 3) = 30349492858024727686755.0 / d;\n w( 4) = -126346544855927856134295.0 / d;\n w( 5) = 399537307669842150996468.0 / d;\n w( 6) = -991168450545135070835076.0 / d;\n w( 7) = 1971629028083798845750380.0 / d;\n w( 8) = -3191065388846318679544380.0 / d;\n w( 9) = 4241614331208149947151790.0 / d;\n w(10) = -4654326468801478894406214.0 / d;\n w(11) = 4222756879776354065593786.0 / d;\n w(12) = -3161821089800186539248210.0 / d;\n w(13) = 1943018818982002395655620.0 / d;\n w(14) = -970350191086531368649620.0 / d;\n w(15) = 387739787034699092364924.0 / d;\n w(16) = -121059601023985433003532.0 / d;\n w(17) = 28462032496476316665705.0 / d;\n w(18) = -4740335757093710713245.0 / d;\n w(19) = 498669220956647866875.0 / d;\n w(20) = -24919383499187492303.0 / d;\n \n else\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'BASHFORTH_SET - Fatal error!\\n' );\n fprintf ( 1, ' Illegal value of N = %d\\n', n );\n fprintf ( 1, ' Legal values are 1 through 10,\\n' );\n fprintf ( 1, ' or 12, 14, 16, 18 or 20.\\n' );\n error ( 'BASHFORTH_SET - Fatal error!' );\n\n end\n\n for i = 1 : n\n x(i) = 1 - i;\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/quadrule/bashforth_set.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218327098193, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.7427299063067956}} {"text": "function r=rot4y(theta)\n % r = rot4y(theta)\n %\n % roty produces a 4x4 rotation matrix representing\n % a rotation by theta radians about the y axis.\n %\n %\tArgument definitions:\n %\n %\ttheta = rotation angle in radians\n c = cos(theta);\n s = sin(theta);\n r = [c 0 s 0;\n 0 1 0 0;\n -s 0 c 0;\n 0 0 0 1];\n", "meta": {"author": "CelsoReyes", "repo": "zmap7", "sha": "3895fcb3ca3073608abe22ca71960eb082fd0d9a", "save_path": "github-repos/MATLAB/CelsoReyes-zmap7", "path": "github-repos/MATLAB/CelsoReyes-zmap7/zmap7-3895fcb3ca3073608abe22ca71960eb082fd0d9a/zmap_deprecated/eztool/rot4y.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765281148513, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.7426977929218824}} {"text": "function [ftAllNew,transMdl] = ftTrans_itl(ft,maSrc,target,maLabeled,param)\n%Wrapper of the Information-Theoretical Learning (ITL) algorithm\n% \n%\tA feaure-level transfer learning (domain adaptation) algorithm which\n% learns a domain-invariant subspace. Application scope:\n%\t+ two discrete domains (source and target)\n%\t+ labeled source domain\n%\t+ unlabeled target domain\n%\t+ label type: classification\n%\n% ftAll:\tAll samples in all domains. n-by-m matrix, n is the number of \n%\tsamples, m is the dimension of features.\n% maSrc:\tn-by-1 logical vector, maSrc(i)=true if i is from the source\n%\tdomain, 0 if target domain.\n% target:\tThe class labels of the source domain, nsrc-by-1 matrix, nsrc \n%\tis the number of source\tsamples. target(i)=j if the i'th sample is from\n%\tthe j'th class.\n% maLabeled:\tMask for the labeled samples. n-by-1 matrix, must be the\n% same with maSrc.\n% \n% param: Struct of hyper-parameters, please see the first cell of this\n%\tprogram (\"default parameters\") for details. You can set parameter p to \n%\tx by setting param.p = x. For parameters that are not set, default \n%\tvalues will be used.\n% \n% ftAllNew:\tAll samples in the learned subspace.\n% transMdl:\tA struct containing the model, transMdl.W is the projection\n%\tmatrix.\n% \n%\tThe ftProc_pca_tr function is a part of the PRTools toolbox.\n%\tNotice from the author of the paper: for practice use, you need to \n% properly preprocess the data and tune lambda and d.\n% \n% ref: Y. Shi and F. Sha, \"Information-theoretical learning of discriminative\n% clusters for unsupervised domain adaptation,\" in ICML, 2012.\n% \n% Copyright 2016 Ke YAN, Tsinghua Univ. http://yanke23.com , xjed09@gmail.com\n\naddpath infometric_0.1\n\n%% default parameters\npcaCoef = 0; % see ftProc_pca_tr\nlambda = 1; % regularization parameter\n\ndefParam\n\n%% sort samples\nif any(maSrc~=maLabeled)\n\terror('maLabeled must be the same with maSrc')\nend\n\nftSrc = ft(maSrc,:);\nftTar = ft(~maSrc,:);\n\n%% compute\n[~,pcaModelS] = ftProc_pca_tr(ftSrc,[],struct('pcaCoef',pcaCoef));\n[~,pcaModelT] = ftProc_pca_tr(ftTar,[],struct('pcaCoef',pcaCoef));\nd = min(size(pcaModelS.W_prj,2),size(pcaModelT.W_prj,2));\nW_prjT = pcaModelT.W_prj(:,1:d);\n\nL = infometric(W_prjT, ftSrc, target, ftTar, lambda);\n\n%% project the samples\nftAllNew = zeros(size(ft,1),d);\nftAllNew(maSrc,:) = ftSrc*L;\nftAllNew(~maSrc,:) = ftTar*L;\ntransMdl.L = L;\n\nend", "meta": {"author": "viggin", "repo": "domain-adaptation-toolbox", "sha": "2a991816a0ac39043b526c2b0cbe01bc844d8890", "save_path": "github-repos/MATLAB/viggin-domain-adaptation-toolbox", "path": "github-repos/MATLAB/viggin-domain-adaptation-toolbox/domain-adaptation-toolbox-2a991816a0ac39043b526c2b0cbe01bc844d8890/ftTrans_itl.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765210631688, "lm_q2_score": 0.8128673269042767, "lm_q1q2_score": 0.742697791331817}} {"text": "function v = lpp_value ( m, n, o, x )\n\n%*****************************************************************************80\n%\n%% LPP_VALUE evaluates a Legendre Product Polynomial at several points X.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 07 September 2014\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer M, the spatial dimension.\n%\n% Input, integer N, the number of evaluation points.\n%\n% Input, integer O(M,1), the degree of the polynomial factors.\n% 0 <= O(*).\n%\n% Input, real X(M,N), the evaluation points.\n%\n% Output, real VALUE(N,1), the value of the Legendre Product Polynomial\n% of degree O at the points X.\n%\n v = ones ( n, 1 );\n\n for i = 1 : m\n\n vi = lp_value ( n, o(i), x(i,1:n) );\n\n v(1:n) = v(1:n) .* vi(1:n);\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/legendre_product_polynomial/lpp_value.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765234137297, "lm_q2_score": 0.8128673246376008, "lm_q1q2_score": 0.7426977911715027}} {"text": "function pdf = burr_pdf ( x, a, b, c, d )\n\n%*****************************************************************************80\n%\n%% BURR_PDF evaluates the Burr PDF.\n%\n% Discussion:\n%\n% PDF(X)(A,B,C,D) = ( C * D / B ) * ( ( X - A ) / B )**( - C - 1 )\n% * ( 1 + ( ( X - A ) / B )**( - C ) )**( - D - 1 )\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 08 October 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% M E Johnson,\n% Multivariate Statistical Simulation,\n% Wiley, New York, 1987.\n%\n% Parameters:\n%\n% Input, real X, the argument of the PDF.\n% A <= X\n%\n% Input, real A, B, C, D, the parameters of the PDF.\n% 0 < B,\n% 0 < C.\n%\n% Output, real PDF, the value of the PDF.\n%\n if ( x <= a )\n pdf = 0.0;\n else\n\n y = ( x - a ) / b;\n\n pdf = ( c * d / b ) * y^( - c - 1.0 ) * ( 1.0 + y^( -c ) )^( - d - 1.0 );\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/prob/burr_pdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308036221031, "lm_q2_score": 0.7956580927949806, "lm_q1q2_score": 0.7426917729660486}} {"text": "function C1 = C1f(epsi)\n%C1F Evaluate C_{1,k}\n%\n% C1 = C1F(EPSI) evaluates C_{1,l} using Eq. (18). EPSI is a K x 1\n% array and C1 is a K x 6 array.\n\n nC1 = 6;\n C1 = zeros(length(epsi), nC1);\n eps2 = epsi.^2;\n d = epsi;\n C1(:,1) = d.*((6-eps2).*eps2-16)/32;\n d = d.*epsi;\n C1(:,2) = d.*((64-9*eps2).*eps2-128)/2048;\n d = d.*epsi;\n C1(:,3) = d.*(9*eps2-16)/768;\n d = d.*epsi;\n C1(:,4) = d.*(3*eps2-5)/512;\n d = d.*epsi;\n C1(:,5) = -7*d/1280;\n d = d.*epsi;\n C1(:,6) = -7*d/2048;\nend\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/39108-geodesics-on-an-ellipsoid-of-revolution/geographiclib-matlab/private/C1f.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172615983308, "lm_q2_score": 0.7826624738835051, "lm_q1q2_score": 0.7426819314733107}} {"text": "\nclear all\nclose all\n%Setting variables to parameters\nimg=imread('synthetic1.png');\nif length(size(img))==3 %generalized to rgb images\n\timg=rgb2gray(img);\nend\nimg= double(img);\n\np=0;\nphi=1; % for 1.5 octave bandwidth\nK = sqrt(2*log(2))*((2^phi+1)/(2^phi-1)); % for phi denoting spatial freq bandwidth\n%{ admissible phi for simple and complex cells found 2 b in [0.5 2.5] }\n\nw0_deg=[8 16 32 64 128];\n%w0_deg=[8 16 32];\ntheta_deg=[0 22.5 45 67.5 90 112.5 135 157.5];\n%theta_deg=[0 22.5];\n\nw0=[8 16 32 64 128].*(pi/180);\n%w0=[8 16 32].*(pi/180);\ntheta=[0 22.5 45 67.5 90 112.5 135 157.5].*(pi/180);\n%theta=[0 22.5].*(pi/180);\n\nlen_w0=length(w0);\nlen_theta=length(theta);\n\nk=1;\nfor i=1:1:len_w0\n\tfor j=1:1:len_theta\n\t\tgrid_size=2^(i-1)\n\t\t[gabor_even, gabor_odd]=gabor_filter_new(img,K,w0(i),theta(j),p,grid_size);\n\n\t\tsze = size(gabor_even,3);\n\t\t% gabor_even_store(:,:,k:1:k+sze-1)=gabor_even;\n\t\t% gabor_odd_store(:,:,k:1:k+sze-1)=gabor_odd;\n\n\t\tstr_title=strcat('angle:',num2str(theta_deg(j)),' freq:', num2str(w0_deg(i)));\n\n\t\tfor n=1:1:sze\n\t\t\timg_filtd_even(:,:,1)=normalize(conv2(gabor_even(:,:,n),img,'same'));\n\t\t\timg_filtd_odd(:,:,1)= normalize(conv2(gabor_odd(:,:,n),img,'same'));\n\t\t\timg_filtd_even_coeff(1)=sum(sum(img_filtd_even(:,:,1).^2));\n\t\t\timg_filtd_odd_coeff(1)=sum(sum(img_filtd_odd(:,:,1).^2));\n\t\t\timg_filtd_coeff(k+n-1)=sqrt(img_filtd_even_coeff(1) + img_filtd_odd_coeff(1));\n\t\tend\n\t\t% clear img_filtd_even;\n\t\t% clear img_filtd_odd;\n\t\t% clear img_filtd_even_coeff;\n\t\t% clear img_filtd_odd_coeff;\n\t\t% figure;\n\t\t% subplot(1,2,1)\n\t\t% imshow(gabor_even(:,:,n),[])\n\t\t% title(str_title);\n\t\t% subplot(1,2,2)\n\t\t% imshow(img_filtd_even(:,:,k+n-1),[])\n\t\t% title('even filtered img')\n\t\t%\n\t\t%\n\t\t% figure;\n\t\t% subplot(1,2,1)\n\t\t% imshow(gabor_odd(:,:,n),[])\n\t\t% title(str_title);\n\t\t% subplot(1,2,2)\n\t\t% imshow(img_filtd_odd(:,:,k+n-1),[])\n\t\t% title('odd filtered img')\n\t\tk=k+sze;\n\tend\nend\n\n\n\nfigure;\nplot(0:1:(k-2),img_filtd_coeff,'ro')\nhold on\nplot(0:1:(k-2),img_filtd_coeff,'g')\nxlabel('w0:theta'); ylabel('image contrast energy');grid on;\ntitle('Image Contrast Energy computed Quadrature pair-wise')\n\n% contrast energy of filtered image computed quadrature pair-wise for\n% every orientation and freq.\n\n\n\n", "meta": {"author": "vistalab", "repo": "vistasoft", "sha": "7f0102c696c091c858233340cc7e1ab02f064d4c", "save_path": "github-repos/MATLAB/vistalab-vistasoft", "path": "github-repos/MATLAB/vistalab-vistasoft/vistasoft-7f0102c696c091c858233340cc7e1ab02f064d4c/mrBOLD/Analysis/retinotopyModel/GaborTools/gabor_decompostion2_new2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582593509315, "lm_q2_score": 0.7981867873410141, "lm_q1q2_score": 0.7426794887862321}} {"text": "function w = MakeSineWindow(boxlen,sigma)\n% MakeSineWindow -- Make a nice window out of the IteratedSine function.\n% Inputs\n% boxlen abscissa values for window evaluation -boxlen <= t < boxlen \n% sigma scale of the window, controls the size of the\n% effective support \n% Outputs\n% w values of the window\n% See Also\n% IteratedSine\n%\n% By Emmanuel Candes, 2003-2004\n \n ix = ((-boxlen:(boxlen -1)) + .5)./boxlen;\n w = IteratedSineWindow(ix./sigma);\n", "meta": {"author": "thomaskuestner", "repo": "CS_MoCo_LAB", "sha": "a26e8e483624b2e4ee669e7a069ba9c74d2d2e4b", "save_path": "github-repos/MATLAB/thomaskuestner-CS_MoCo_LAB", "path": "github-repos/MATLAB/thomaskuestner-CS_MoCo_LAB/CS_MoCo_LAB-a26e8e483624b2e4ee669e7a069ba9c74d2d2e4b/reconstruction/matlab/CS_LAB_matlab/utils/utils_TRAFO/CurveLab-2.1.3/fdct_usfft_matlab/Windows/IteratedSine/MakeSineWindow.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.930458253565792, "lm_q2_score": 0.7981867801399695, "lm_q1q2_score": 0.7426794774683388}} {"text": "function w = cplxdual3D(x, J, Faf, af)\n\n% 3D Complex Dual-Tree Discrete Wavelet Transform\n%\n% USAGE:\n% w = cplxdual3D(x, J, Faf, af)\n% INPUT:\n% x - 3D array\n% J - number of stages\n% Faf - first stage filters\n% af - filters for remaining stages\n% OUPUT:\n% w{j}{m}{n}{p}{d} - wavelet coefficients\n% j = 1..J, m = 1..2, n = 1..2, p = 1..2, d = 1..7\n% w{J+1}{m}{n}{d} - lowpass coefficients\n% m = 1..2, n = 1..2, p = 1..2, d = 1..7\n% EXAMPLE:\n% x = rand(64,64,64);\n% J = 3;\n% [Faf, Fsf] = FSfarras;\n% [af, sf] = dualfilt1;\n% w = cplxdual3D(x, J, Faf, af);\n% y = icplxdual3D(w, J, Fsf, sf);\n% err = x - y;\n% max(max(max(abs(err))))\n%\n% WAVELET SOFTWARE AT POLYTECHNIC UNIVERSITY, BROOKLYN, NY\n% http://taco.poly.edu/WaveletSoftware/\n\n% normalization\nx = x/sqrt(8);\n\nfor m = 1:2\n for n = 1:2\n for p = 1:2\n [lo w{1}{m}{n}{p}] = afb3D(x, Faf{m}, Faf{n}, Faf{p});\n for j = 2:J\n [lo w{j}{m}{n}{p}] = afb3D(lo, af{m}, af{n}, af{p});\n end\n w{J+1}{m}{n}{p} = lo;\n end\n end\nend\n\nfor j = 1:J\n for m = 1:7\n [w{j}{1}{1}{1}{m} w{j}{2}{2}{1}{m} w{j}{2}{1}{2}{m} w{j}{1}{2}{2}{m}] = ...\n pm4(w{j}{1}{1}{1}{m}, w{j}{2}{2}{1}{m}, w{j}{2}{1}{2}{m}, w{j}{1}{2}{2}{m});\n [w{j}{2}{2}{2}{m} w{j}{1}{1}{2}{m} w{j}{1}{2}{1}{m} w{j}{2}{1}{1}{m}] = ...\n pm4(w{j}{2}{2}{2}{m}, w{j}{1}{1}{2}{m}, w{j}{1}{2}{1}{m}, w{j}{2}{1}{1}{m});\n end\nend\n\n\n\n", "meta": {"author": "thomaskuestner", "repo": "CS_MoCo_LAB", "sha": "a26e8e483624b2e4ee669e7a069ba9c74d2d2e4b", "save_path": "github-repos/MATLAB/thomaskuestner-CS_MoCo_LAB", "path": "github-repos/MATLAB/thomaskuestner-CS_MoCo_LAB/CS_MoCo_LAB-a26e8e483624b2e4ee669e7a069ba9c74d2d2e4b/reconstruction/matlab/CS_LAB_matlab/utils/utils_TRAFO/DTCWT/cplxdual3D.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582477806521, "lm_q2_score": 0.7981867825403176, "lm_q1q2_score": 0.7426794750841403}} {"text": "% SENSE_recon_demo.m\n% - demonstrates use of SENSE_recon.m, which implements the SENSE\n% reconstruction\n% - figure shows how Tikhonov regularization mitigates the increase in error\n% as noise variance increases \n% - applies complex AWGN to kspace\n% \n% 2012-06-08, Mai Le\n\n\n% number of coils\nnc = 4; \n% factor of undersampling\nnp = 2;\n% dimension to undersample\nreduced_dim = 1;\nregularizer1 = 'none';\nregularizer2 = 'tikhonov';\nfigs = 0;\n\nimage = double(imread('./data/mri/brainweb_t1.jpg','jpg'));\n\ndims = size(image);\n% introduce planar phase\n[xx,yy] = ndgrid(-dims(1)/2:dims(1)/2-1,-dims(2)/2:dims(2)/2-1);\nph_max = pi/5;\nph = ph_max*xx/(dims(1)/2)+ph_max*yy/(dims(2)/2);\nimage = image.*exp(1i*ph);\n\n% generate sensitivity maps\nsmap = mri_sensemap_sim('nx',dims(1),'ny',dims(2),'ncoil',nc);\n\nim_rep = repmat(image,[1 1 nc]);\n\n% apply sensitivity maps\nmapped_im = im_rep.*smap;\n\n% throw away k-space data\nim_fft = [];\nreduced_fft = [];\nfor ii = 1:nc\n im_fft(:,:,ii) = fft2(mapped_im(:,:,ii));\n if (reduced_dim == 1)\n reduced_fft(:,:,ii) = im_fft(1:np:end,:,ii);\n else\n reduced_fft(:,:,ii) = im_fft(:,1:np:end,ii);\n end\nend\n%% perform SENSE reconstruction for varying levels of noise\nsigmas = 0:25:150;\nfor ii = 1:length(sigmas)\n % introduce complex AWGN\n sigma = sigmas(ii);\n noisy_reduced_fft = reduced_fft + sigma*randn(size(reduced_fft)) + i*sigma*randn(size(reduced_fft));\n \n % SENSE reconstruction\n recon_im1(:,:,ii) = SENSE_recon(smap, noisy_reduced_fft, reduced_dim, np, regularizer1, figs);\n recon_im2(:,:,ii) = SENSE_recon(smap, noisy_reduced_fft, reduced_dim, np, regularizer2, figs);\n \n error1(ii) = sqrt((sum(sum((real(image)-real(recon_im1(:,:,ii))).^2))+sum(sum((imag(image)-imag(recon_im1(:,:,ii))).^2)))/prod(dims));\n error2(ii) = sqrt((sum(sum((real(image)-real(recon_im2(:,:,ii))).^2))+sum(sum((imag(image)-imag(recon_im2(:,:,ii))).^2)))/prod(dims)) ;\nend\n%% plot error as a function of noise variance\nfigure; plot(sigmas.^2, error1,'k');\nhold on; plot(sigmas.^2, error2, 'r'); legend('no regularization', 'tikhonov');\nxlabel('variance of complex AWGN in kspace');\nylabel('RMS error in reconstructed images');\ntitle('effect of Tikhonov regularization on noisy SENSE reconstruction')\n%% plot reconstructed image at sigma(ii)\nii = 4; % change as desired\nfigure; subplot(331); imshow(real(image),[]); colorbar; \ntitle('real of original image');\nsubplot(332); imshow(imag(image),[]); colorbar; \ntitle(['imag of original image, noise variance: ' num2str(sigmas(ii).^2)]);\nsubplot(334); imshow(real(recon_im1(:,:,ii)),[]); colorbar;\ntitle('real of recon image, no reg');\nsubplot(335); imshow(imag(recon_im1(:,:,ii)),[]); colorbar;\ntitle('imag of recon image, no reg');\nsubplot(336); imshow(abs(real(image)-real(recon_im1(:,:,ii)))+abs(imag(image)-imag(recon_im1(:,:,ii))),[]); colorbar;\ntitle('abs(differences), no reg');\nsubplot(337); imshow(real(recon_im2(:,:,ii)),[]); colorbar;\ntitle('real of recon image, Tikhonov');\nsubplot(338); imshow(imag(recon_im2(:,:,ii)),[]); colorbar;\ntitle('imag of recon image, Tikhonov');\nsubplot(339); imshow(abs(real(image)-real(recon_im2(:,:,ii)))+abs(imag(image)-imag(recon_im2(:,:,ii))),[]); colorbar;\ntitle('abs(differences), Tikhonov');", "meta": {"author": "JeffFessler", "repo": "mirt", "sha": "b7f36cc46916821e8bc8502301b1554ebc7efe1d", "save_path": "github-repos/MATLAB/JeffFessler-mirt", "path": "github-repos/MATLAB/JeffFessler-mirt/mirt-b7f36cc46916821e8bc8502301b1554ebc7efe1d/contrib/le-mai-sense/old/SENSE_recon_demo.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942171172603, "lm_q2_score": 0.8221891283434876, "lm_q1q2_score": 0.7426786850093533}} {"text": "function [ table ] = integerparttable(nfinal )\n%Calculates a table of integer partions using numbers l.t. or e.t. k\n%(or equivilently using k nonnegative integers which can be zero)\n%Just calls with the largest value which has to recurrsively call all other\n%possible values. \n%\n%this table states with first row \"ways to partition 0\" and first column\n%\"using only numbers <=0\", this gives the one in the top left, these two\n%rows are essentially a definition limit to finish the reccurance relation.\n%Row k+1 column j+1 contains the ways to partition k \n% using integers <= j (or equivilently j integers >= 0)\n%\n%to obtain the partitions of nfinal using numbers g.e. 2 and l.e. k do\n% [1;table(2:nfinal,k+1)-table(1:nfinal-1,k+1)]\n%\n%use of 32 bit integers means this is only good up to 2^32-1= 4294967295, \n%for larger values change to 64 bit or dp\n% Scales as ~ exp(pi*sqrt(2*n/3))/(4*n*sqrt(3)) for n>>1 and k>n\n\n%Author: David Holdaway\n%Last update: 27/04/2012\n\nintpart(1,nfinal,1,1); %clears table\n\nfor n = 2:nfinal\n intpart(uint32(n),uint32(n));\nend\ntable = intpart(1,nfinal,2); %gets table\n\nfor n = 1:nfinal\n table(n+1,n+1:nfinal+1) = table(n+1,n+1); \nend\nend\n\nfunction p = intpart(k,n,gettable,cleartable) %#ok\npersistent table\nif nargin == 4\n table = uint32(zeros(n+1)); %clears\n% table(1,:) = uint32(ones(1,1+n)); %n=0\n% table(2,2:n+1) = uint32(ones(1,n)); %n=1 k>1\n% table(:,2) = uint32(ones(n+1,1)); %k=0\n table(1,:) = uint32(1); %n=0\n table(2,2:n+1) = uint32(1); %n=1 k>1\n table(:,2) = uint32(1); %k=0\n p = 0; return\nend\nif nargin == 3\n p = table; return\nend\nk = uint32(k);\nn = uint32(n);\nif n < 0\n p = uint32(0); return\nend\nif k < 0\n p = uint32(0); return\nend\nif table(n+1,k+1) ~= 0\n p = table(n+1,k+1); return\nend\n\nif n==0\n p = uint32(0); return\nend\n\n table(n+1,k+1) = intpart(k,n-k) + intpart(k-1,n);\n p = table(n+1,k+1);\n for lp = n+2:length(table)\n table(n+1,lp) = table(n+1,n+1);\n end\n\nend\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/36437-integer-partition-generator/integerparttable.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942119105695, "lm_q2_score": 0.8221891261650247, "lm_q1q2_score": 0.7426786787606757}} {"text": "function u = SB_ATV(g,mu)\n% Split Bregman Anisotropic Total Variation Denoising\n%\n% u = arg min_u 1/2||u-g||_2^2 + mu*ATV(u)\n% \n% g : noisy image\n% mu: regularisation parameter\n% u : denoised image\n%\n% Refs:\n% *Goldstein and Osher, The split Bregman method for L1 regularized problems\n% SIAM Journal on Imaging Sciences 2(2) 2009\n% *Micchelli et al, Proximity algorithms for image models: denoising\n% Inverse Problems 27(4) 2011\n%\n% Benjamin Tr\u00e9moulh\u00e9ac\n% University College London\n% b.tremoulheac@cs.ucl.ac.uk\n% April 2012\ng = g(:);\nn = length(g);\n[B Bt BtB] = DiffOper(sqrt(n));\nb = zeros(2*n,1);\nd = b;\nu = g;\nerr = 1;k = 1;\ntol = 1e-3;\nlambda = 1;\nwhile err > tol\n fprintf('it. %g ',k);\n up = u;\n [u,~] = cgs(speye(n)+BtB, g-lambda*Bt*(b-d),1e-5,100); \n Bub = B*u+b;\n d = max(abs(Bub)-mu/lambda,0).*sign(Bub);\n b = Bub-d;\n err = norm(up-u)/norm(u);\n fprintf('err=%g \\n',err);\n k = k+1;\nend\nfprintf('Stopped because norm(up-u)/norm(u) <= tol=%.1e\\n',tol);\nend\n\nfunction [B Bt BtB] = DiffOper(N)\nD = spdiags([-ones(N,1) ones(N,1)], [0 1], N,N+1);\nD(:,1) = [];\nD(1,1) = 0;\nB = [ kron(speye(N),D) ; kron(D,speye(N)) ];\nBt = B';\nBtB = Bt*B;\nend\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/36278-split-bregman-method-for-total-variation-denoising/SplitBregmanTVdenoising/SB_ATV.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032941962904956, "lm_q2_score": 0.8221891239865619, "lm_q1q2_score": 0.742678663950228}} {"text": "function bg = ball_grid ( n, r, c, ng )\n\n%*****************************************************************************80\n%\n%% BALL_GRID computes grid points inside a ball.\n%\n% Discussion:\n%\n% The grid is defined by specifying the radius and center of the ball,\n% and the number of subintervals N into which the horizontal radius\n% should be divided. Thus, a value of N = 2 will result in 5 points\n% along that horizontal line.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 03 September 2010\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the number of subintervals.\n%\n% Input, real R, the radius of the ball.\n%\n% Input, real C(3), the coordinates of the center of the ball.\n%\n% Input, integer NG, the number of grid points, as determined by\n% BALL_GRID_COUNT.\n%\n% Output, real BG(3,NG), the grid points inside the ball.\n%\n bg = zeros ( 3, ng );\n\n p = 0;\n\n for i = 0 : n\n x = c(1) + r * 2 * i / ( 2 * n + 1 );\n \n for j = 0 : n\n y = c(2) + r * 2 * j / ( 2 * n + 1 );\n \n for k = 0 : n\n\n z = c(3) + r * 2 * k / ( 2 * n + 1 );\n\n if ( r * r < ( x - c(1) ).^2 ...\n + ( y - c(2) ).^2 ...\n + ( z - c(3) ).^2 )\n break\n end\n p = p + 1;\n bg(1:3,p) = [ x, y, z ]';\n if ( 0 < i )\n p = p + 1;\n bg(1:3,p) = [ 2 * c(1) - x, y, z ]';\n end\n if ( 0 < j )\n p = p + 1;\n bg(1:3,p) = [ x, 2 * c(2) - y, z ]';\n end\n if ( 0 < k )\n p = p + 1;\n bg(1:3,p) = [ x, y, 2 * c(3) - z ]';\n end\n if ( 0 < i && 0 < j )\n p = p + 1;\n bg(1:3,p) = [ 2 * c(1) - x, 2 * c(2) - y, z ]';\n end\n if ( 0 < i && 0 < k )\n p = p + 1;\n bg(1:3,p) = [ 2 * c(1) - x, y, 2 * c(3) - z ]';\n end\n if ( 0 < j && 0 < k )\n p = p + 1;\n bg(1:3,p) = [ x, 2 * c(2) - y, 2 * c(3) - z ]';\n end\n if ( 0 < i && 0 < j && 0 < k )\n p = p + 1;\n bg(1:3,p) = [ 2 * c(1) - x, 2 * c(2) - y, 2 * c(3) - z ]';\n end\n end\n end\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/ball_grid/ball_grid.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757870046160257, "lm_q2_score": 0.8479677583778257, "lm_q1q2_score": 0.7426391431206817}} {"text": "function dif = r8mat_diff_frobenius ( m, n, a, b )\n\n%*****************************************************************************80\n%\n%% R8MAT_DIFF_FROBENIUS: Frobenius norm of the difference of two R8MAT's.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 19 June 2012\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer M, the number of rows in A.\n%\n% Input, integer N, the number of columns in A.\n%\n% Input, real A(M,N), B(M,N), the matrices for which we\n% are to compute the Frobenius norm of the difference.\n%\n% Output, real DIF, the Frobenius norm of A-B.\n%\n dif = sqrt ( sum ( sum ( ( a(1:m,1:n) - b(1:m,1:n) ).^2 ) ) );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/r8lib/r8mat_diff_frobenius.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8757869981319863, "lm_q2_score": 0.8479677602988602, "lm_q1q2_score": 0.7426391393048426}} {"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%% EUROPEAN OPTION PRICER (RUN SCRIPT)\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Descritpion: Script to Price European options in Regime Switching Diffusion Models\n% using the PROJ method\n% Author: Justin Kirkby\n% References: (1) Efficient Option Pricing By Frame Duality with The Fast\n% Fourier Transform, SIAM J. Financial Math., 2015\n% (2) A unified approach to Bermudan and Barrier options under stochastic\n% volatility models with jumps. J. Economic Dynamics and Control, 2017\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n[folder, name, ext] = fileparts(which( mfilename('fullpath')));\ncd(folder);\naddpath('../')\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%% Step 1) CHOOSE CONTRACT/GENERAL PARAMETERS\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\ncall = 1; %For call use 1 (else, its a put)\nS_0 = 100; %Initial price\nW = 100; %Strike %NOTE: no error handling in place for extreme values of W (increase grid if strike falls outside)\nr = .05; %Interest rate\nq = .00; %dividend yield\nT = 1; %Time (in years)\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%% Step 2) CHOOSE MODEL PARAMETERS \n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n% Transition Matrix (dictates how the regimes transition)\nQ = [-1 0.5 0.5;\n 0.5 -1 0.5; \n 0.5 0.5 -1]; \n\nsigma_vec = [0.15 0.25 0.35]; % Volatility in each state\n\ninitial_state = 1;\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%% Step 3) CHOOSE PROJ PARAMETERS\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\norder = 3; %Choose spline order from { 0,1,2,3} => {Haar, Linear, Quadratic, Cubic}, Haar is least accurate\nlogN = 8; %Uses N = 2^logN gridpoint \nL1 = 8; % determines grid witdth (usually set L1 = 8 to 15 for Levy)\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%% PRICE\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nalpha = L1*sqrt(T)*max(sigma_vec); % Choose grid width based on the largest volatility\nN = 2^logN; % grid roughly centered on [- alph, alph]\n\ntic\nprice = PROJ_RegimeSwitching_European(order, N, alpha, r, q, T, S_0, W, call, Q, sigma_vec, initial_state);\ntoc\n\nfprintf('%.8f \\n', price)\n\n", "meta": {"author": "jkirkby3", "repo": "PROJ_Option_Pricing_Matlab", "sha": "3859a390f395e452ad61440f95a5714dd8fb4d90", "save_path": "github-repos/MATLAB/jkirkby3-PROJ_Option_Pricing_Matlab", "path": "github-repos/MATLAB/jkirkby3-PROJ_Option_Pricing_Matlab/PROJ_Option_Pricing_Matlab-3859a390f395e452ad61440f95a5714dd8fb4d90/PROJ/REGIME_SWITCHING/European_Options/Script_EuropeanOptions.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067195846918, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.7426304511573592}} {"text": "%Program for SVD-based Image Quality Measure\n\n%Program Description\n% This program outputs a graphical & numerical image quality measure\n% based on Singular Value Decomposition.\n% For details on the implementation, please refer\n% Aleksandr Shnayderman, Alexander Gusev, and Ahmet M. Eskicioglu,\n% \"An SVD-Based Grayscale Image Quality Measure for Local and Global Assessment\",\n% IEEE TRANSACTIONS ON IMAGE PROCESSING, VOL. 15, NO. 2, FEBRUARY 2006.\n%\n%Parameters\n% refImg - Input Reference Gray Image\n% distImg - Input Distorted Gray Image\n% blkSize - Window size for block processing\n% graMeasure - Graphical Image quality measure\n% scaMeasure - Numerical Image quality measure\n%\n%Author : Athi Narayanan S\n%Student, M.E, EST,\n%K.S.R College of Engineering\n%Erode, Tamil Nadu, India.\n%s_athi1983@yahoo.co.in\n%http://sites.google.com/site/athisnarayanan/\n\nfunction [graMeasure, scaMeasure] = SVDQualityMeasure(refImg, distImg, blkSize)\n\nk = size(refImg, 1);\n\nblkx = blkSize;\nblky = blkSize;\n\nblockwise1 = MatDec(refImg,blkx);\nblockwise2 = MatDec(distImg,blkx);\n[blkx blky imgx imgy] = size(blockwise1);\ngraMeasure = zeros(imgx,imgy);\nblockwise1 = double(blockwise1);\nblockwise2 = double(blockwise2);\n\nfor i=1:imgx\n for j=1:imgy\n temp_in_image = blockwise1(:,:,i,j);temp_in_image=temp_in_image(:);\n original_img = reshape(temp_in_image,blkx,blky);\n temp_dist_image = blockwise2(:,:,i,j);temp_dist_image=temp_dist_image(:);\n distorted_img = reshape(temp_dist_image,blkx,blky);\n graMeasure(i,j) = sqrt(sum((svd(original_img)-svd(distorted_img)).^2));\n end\nend\n\ngraMeasure = round((graMeasure/max(max(graMeasure)))*255);\ngraMeasure = uint8(graMeasure);\n\nscaMeasure = sum(sum(abs(graMeasure-median(median(graMeasure)))))/((k/blkx).^2);\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/25271-svd-based-image-quality-measure/SVDBasedImageQualityMeasure/SVDQualityMeasure.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362849986365571, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.7425732112910354}} {"text": "% Fig. 6.26 Feedback Control of Dynamic Systems, 6e \n% Franklin, Powell, Emami\n%\n\nclear all;\n%close all;\nclf\n\nnum=1;\nden=conv([1 0],[1 2 1]);\nw=logspace(-2,3,100);\n[re,im]=nyquist(num,den,w);\nplot(re,im,re,-im);\naxis([-2 2 -2 2]);\naxis('square')\nxlabel('Re(G(s))');\nylabel('Im(G(s))');\ntitle('Fig. 6.26 Nyquist plot');\nnicegrid;\nhold on\nii=[11 21 47 61];\nplot(re(ii),im(ii),'*');\nplot(-.5,0,'*')\nhold off\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/26412-feedback-control-of-dynamic-systems-6th-edition-prentice-hall-2010/fig6_26.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.936285002192296, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.7425732003751652}} {"text": "function krn = spm_smoothkern(fwhm,x,t)\n% Generate a Gaussian smoothing kernel\n% FORMAT krn = smoothing_kernel(fwhm,x,t)\n% fwhm - full width at half maximum\n% x - position\n% t - either 0 (nearest neighbour) or 1 (linear).\n% if only two arguments are passed, then a value\n% of one is assumed.\n% krn - value of kernel at position x\n%\n% For smoothing images, one should really convolve a Gaussian\n% with a sinc function. For smoothing histograms, the\n% kernel should be a Gaussian convolved with the histogram\n% basis function used. This function returns a Gaussian\n% convolved with a triangular (1st degree B-spline) basis\n% function (by default). A Gaussian convolved with a hat\n% function (0th degree B-spline) can also be returned.\n%_______________________________________________________________________\n% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging\n\n% John Ashburner\n% $Id$\n\n\nif nargin<3, t = 1; end;\n\n% Variance from FWHM\ns = (fwhm/sqrt(8*log(2)))^2+eps;\n\n% The simple way to do it. Not good for small FWHM\n% krn = (1/sqrt(2*pi*s))*exp(-(x.^2)/(2*s));\n\nif t==0\n % Gaussian convolved with 0th degree B-spline\n % int(exp(-((x+t))^2/(2*s))/sqrt(2*pi*s),t= -0.5..0.5)\n w1 = 1/sqrt(2*s);\n krn = 0.5*(erf(w1*(x+0.5))-erf(w1*(x-0.5)));\n krn(krn<0) = 0;\n\nelseif t==1\n % Gaussian convolved with 1st degree B-spline\n % int((1-t)*exp(-((x+t))^2/(2*s))/sqrt(2*pi*s),t= 0..1)\n % +int((t+1)*exp(-((x+t))^2/(2*s))/sqrt(2*pi*s),t=-1..0)\n w1 = 0.5*sqrt(2/s);\n w2 = -0.5/s;\n w3 = sqrt(s/2/pi);\n krn = 0.5*(erf(w1*(x+1)).*(x+1) + erf(w1*(x-1)).*(x-1) - 2*erf(w1*x ).* x)...\n +w3*(exp(w2*(x+1).^2) + exp(w2*(x-1).^2) - 2*exp(w2*x.^2));\n krn(krn<0) = 0;\n\nelse\n error('Only defined for nearest neighbour and linear interpolation.');\n % If anyone knows a nice formula for a sinc function convolved with a\n % a Gaussian, then that could be quite useful.\nend;\nreturn;\n\n", "meta": {"author": "fieldtrip", "repo": "fieldtrip", "sha": "c2039be598a02d86b39aae76bfa7aaa720f9801c", "save_path": "github-repos/MATLAB/fieldtrip-fieldtrip", "path": "github-repos/MATLAB/fieldtrip-fieldtrip/fieldtrip-c2039be598a02d86b39aae76bfa7aaa720f9801c/external/spm8/spm_smoothkern.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850021922959, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.742573200375165}} {"text": "function [ mX ] = ProjectSymmetricMatrixSet( mX )\n% ----------------------------------------------------------------------------------------------- %\n% [ mX ] = ProjectSymmetricMatrixSet( mX )\n% Projecting the input matrix into the Convex Set of Symmetric Matrices.\n% Input:\n% - mX - Input Matrix.\n% Structure: Matrix.\n% Type: 'Single' / 'Double'.\n% Range: (-inf, inf).\n% Output:\n% - mX - Output Matrix.\n% Symmteirc Matrix which is the orthogonal projection\n% of the input matrix.\n% Structure: Matrix.\n% Type: 'Single' / 'Double'.\n% Range: (-inf, inf).\n% References\n% 1. h\n% Remarks:\n% 1. a\n% TODO:\n% 1. U.\n% Release Notes:\n% - 1.0.000 15/08/2018 Royi Avital\n% * First release version.\n% ----------------------------------------------------------------------------------------------- %\n\nFALSE = 0;\nTRUE = 1;\n\nOFF = 0;\nON = 1;\n\nmX = (mX.' + mX) / 2;\n\n\nend\n\n", "meta": {"author": "RoyiAvital", "repo": "StackExchangeCodes", "sha": "d2a934616995fa8a9f4df1ca29029402435b9e6f", "save_path": "github-repos/MATLAB/RoyiAvital-StackExchangeCodes", "path": "github-repos/MATLAB/RoyiAvital-StackExchangeCodes/StackExchangeCodes-d2a934616995fa8a9f4df1ca29029402435b9e6f/Mathematics/Q1891878/ProjectSymmetricMatrixSet.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853654, "lm_q2_score": 0.8354835289107307, "lm_q1q2_score": 0.7425433380609493}} {"text": "% DEMO_fitSpline.m\n%\n% Fit a spline to data, which can then be evaluated by ppval\n\n\ntSpan = [0,10];\nnData = 100;\nnKnot = 10;\n\ntData = linspace(tSpan(1),tSpan(2),nData);\nxData = sin(tData);\nyData = cos(tData);\n\ntKnot = linspace(tSpan(1),tSpan(2),nKnot);\n\npp = fitSpline(tData, [xData;yData], tKnot);\n\nzSpline = ppval(pp,tData);\n\nfigure(15); clf; \n\nsubplot(2,1,1); hold on;\nplot(tData,xData,'ko')\nplot(tData,zSpline(1,:),'b-')\nlegend('data','spline');\n\nsubplot(2,1,2); hold on;\nplot(tData,yData,'ko')\nplot(tData,zSpline(2,:),'b-')\nlegend('data','spline');", "meta": {"author": "MatthewPeterKelly", "repo": "dscTutorials", "sha": "e1e97a9be03ec146f88bd6ddd9e06db7ee52e242", "save_path": "github-repos/MATLAB/MatthewPeterKelly-dscTutorials", "path": "github-repos/MATLAB/MatthewPeterKelly-dscTutorials/dscTutorials-e1e97a9be03ec146f88bd6ddd9e06db7ee52e242/pwPoly/DEMO_fitSpline.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995482, "lm_q2_score": 0.8354835289107307, "lm_q1q2_score": 0.7425433282140931}} {"text": "function [A,Q] = lti_disc(F,L,Q,dt)\n% LTI_DISC Equivalent discrete-time solution of an LTI SDE\n%\n% Syntax:\n% [A,Q] = lti_disc(F,L,Qc,dt)\n%\n% In:\n% F - NxN Feedback matrix\n% L - NxL Noise effect matrix (optional, default identity)\n% Qc - LxL Diagonal Spectral Density (optional, default zeros)\n% dt - Time step (optional, default 1)\n%\n% Out:\n% A - Transition matrix\n% Q - Discrete process covariance matrix\n%\n% Description:\n% Equivalent discrete-time solution of an LTI SDE of form\n%\n% dx/dt = F x + L w,\n%\n% where w(t) is a white-noise process with spectral density Qc.\n% Results in the following model:\n%\n% x[k] = A x[k-1] + q, q ~ N(0,Q).\n%\n% Can be used for integrating the model exactly over time steps, \n% which are multiples of dt.\n%\n% Copyright: \n% 2019 - Simo S\u00e4rkk\u00e4 and Arno Solin\n%\n% License:\n% This software is provided under the MIT License. See the accompanying \n% LICENSE file for details.\n\n % Check number of arguments and defaults\n if nargin < 1\n error('Too few arguments');\n end\n if nargin < 2\n L = [];\n end\n if nargin < 3\n Q = [];\n end\n if nargin < 4\n dt = [];\n end\n if isempty(L)\n L = eye(size(F,1));\n end\n if isempty(Q)\n Q = zeros(size(F,1),size(F,1));\n end\n if isempty(dt)\n dt = 1;\n end\n\n % Closed-form integration of the transition matrix\n A = expm(F*dt);\n\n % Closed-form integration of the covariance matrix\n n = size(F,1);\n Phi = [F L*Q*L'; zeros(n,n) -F'];\n AB = expm(Phi*dt)*[zeros(n,n);eye(n)];\n Q = AB(1:n,:)*A'; % A' = inv(AB((n+1):(2*n),:));", "meta": {"author": "AaltoML", "repo": "SDE", "sha": "91111b0f1849ef0a0540c683bb2cf454ab4f2aff", "save_path": "github-repos/MATLAB/AaltoML-SDE", "path": "github-repos/MATLAB/AaltoML-SDE/SDE-91111b0f1849ef0a0540c683bb2cf454ab4f2aff/matlab/lti_disc.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273633016692236, "lm_q2_score": 0.8006920092299293, "lm_q1q2_score": 0.7425323852996317}} {"text": "clc;\nclose all;\nclearvars;\nrng('default');\nn = 10;\n% Let's get a symmetric positive definite matrix\nA = gallery('gcdmat', n);\n% Compute its Cholesky decomposition\nL = chol(A, 'lower')\nb = randn(n, 1);\n% solve the problem\nx = L \\b\nx = spx.la.tris.forward_row(L, b)\n", "meta": {"author": "indigits", "repo": "sparse-plex", "sha": "43cae2978f62938d001baaa03308a2a717ee6c9b", "save_path": "github-repos/MATLAB/indigits-sparse-plex", "path": "github-repos/MATLAB/indigits-sparse-plex/sparse-plex-43cae2978f62938d001baaa03308a2a717ee6c9b/examples/linear_algebra/triangular/ex_forward_row_1.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632916317103, "lm_q2_score": 0.8006920092299293, "lm_q1q2_score": 0.742532377262675}} {"text": "%% Gauss Laguerre Quadrature\n% solution for class exercise:\n\nclear\nclc\nclose all\n\n%% Aproximate solution\n% Tau(m) is a function of m.\n\nm=5.5 % Exponent value of f(x).\nn=9; % number of points used to compute approximate solution.\n\n[x w]=GaussLaguerre(n,0); % built in function to generate weight and points\n\n% Initalizing row vectors:\nl=length(x);\nf=zeros(1,l);\nt=zeros(1,l);\n\nfor i=1:l\n f(i)=x(i)^(m-1);\n t(i)=w(i)*f(i);\nend\n\nGamma=sum(t)\n\n%% Exact Solution\n% Gamma=(m-1)! \n% Carefull! m can only be an integer number!\n\nGamma2=factorial(floor(m)-1) \n% I'm using a round to the floor in case m is a rational number.\n\n%% Exact solution of the Gamma function\n% this time using the Matlab's gamma function.\n\nGamma3=gamma(m)\n", "meta": {"author": "wme7", "repo": "Aero-matlab", "sha": "9430008f2e3b84f28633775a44dff534e780fbac", "save_path": "github-repos/MATLAB/wme7-Aero-matlab", "path": "github-repos/MATLAB/wme7-Aero-matlab/Aero-matlab-9430008f2e3b84f28633775a44dff534e780fbac/NumericalMethods/GLaguerre_Prob.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632936392131, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.7425323722542799}} {"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Solve the following exercises:\n% A) Cart and pendulum.\n% Simulate a cart and pendulum system. Then, try to control it\n% using a P controller.\n%\n% Help: Function prototype\n% [y, t] = runge_kutta(f, y0, [t0 tfinal], timestep)\n% where f is the function being integrated as dy/dt = f(t, y).\n% y0 are the initial conditions\n% t0: initial time\n% tfinal: final time.\n% h: time step for the calculations.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nfunction cart_and_pendulum_controlled()\nclose all;\n\n%uncomment to execute each of the exercises\nexerciseA()%\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Simulate a cart and pendulum\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nfunction exerciseA()\nglobal L \nL = 0.8; % m length of the pendulum\nt0 = 0;\ntfinal = 10;\n[t, x] = runge_kutta(@fcart_and_pendulum, [0 0 0.01 0.01]', [t0 tfinal], 0.01);\nx = x(:, 1:length(t)); \n\n% animate the system\nclose all\nfigure\nfor i=1:length(t)\n %cart position\n posx_cart = x(1,i);\n posy_cart = 0;\n \n theta = x(3,i);\n %pendulum position \n posx_pend = L*sin(theta) + posx_cart;\n posy_pend = L*cos(theta);\n plot(posx_cart, posy_cart, 'rs', 'MarkerSize', 30), hold on\n plot(posx_pend, posy_pend, 'bo', 'MarkerSize', 12)\n xlim([-5 5])\n ylim([-0.9 0.9])\n line([posx_cart posx_pend], [posy_cart posy_pend])\n pause(0.05); \n hold off\nend\n% plot results\nfigure\nplot(t, x(1,:), 'r'), hold\nplot(t, x(2,:), 'g')\nplot(t, x(3,:), 'b') \nplot(t, x(4,:), 'k')\nlegend('Position x (m)', 'Speed xd (m/s)', '\\theta (rad)', '\\thetad (rad/s)')\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Helper function to solve a constant acceleration on x axis on a ramp.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nfunction xd = fcart_and_pendulum(t, x)\n% We must return the solution of\n% [dx1/dt; dx2/dt]\nglobal L\nM = 5; % kg mass of the cart\nm = 5; % kg mass of the pendulum (centered at the tip)\ng = 9.81; %m/s^ 2\n\n% Computing a simple P controller\nref = 0; % theta reference\ntheta = x(3); \nerror = ref-theta;\nk = 1000;\n% the control action!\nF = k*error;\n% if F > 20\n% F=20;\n% elseif F<-20\n% F=-20\n% end\n\n% compute xdd and thetadd to simulate the system\nnum = F + m*sin(x(3))*(g*cos(x(3)) - L*x(4)^2);\nden = M + m*(1-cos(x(3))^2);\nxdd = num/den;\n\nnum = F + g*(M+m)*tan(x(3))-m*L*x(4)^2*sin(x(3));\nden = L*((M+m)/cos(x(3)) - m*cos(x(3)));\nthetadd = num/den;\n\nxd(1) = x(2);\nxd(2) = xdd;\nxd(3) = x(4);\nxd(4) = thetadd;\nxd = xd(:);\n\n\n\n\n\n\n", "meta": {"author": "4rtur1t0", "repo": "ARTE", "sha": "6e836f3156bb36af63b70bd93375c8ff4ee643c4", "save_path": "github-repos/MATLAB/4rtur1t0-ARTE", "path": "github-repos/MATLAB/4rtur1t0-ARTE/ARTE-6e836f3156bb36af63b70bd93375c8ff4ee643c4/exercises/control/cart_and_pendulum_controlled.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096135894201, "lm_q2_score": 0.8104789109591832, "lm_q1q2_score": 0.7424875219411914}} {"text": "function [out, bestL] = Peubseparate(k, d, PeCh, e)\n%Excess-distortion probability for the transmission of a Gaussian source\n%over a Gaussian channel as achieved by a separated scheme - optimized with respect to the number of\n%messages allowable between the channel encoder and the channel decoder (2^L)\n\n%PeCh - array of channel error probabilities\n%k - source blocklength\n%d - target distortion\n%e - excess distortion probability\n\n%outputs: \n%out - the excess distortion probability\n%bestL - the optimal length of messages exchanged between the encoder and\n%the decoder\n\n%\n% Created in 2012 by Victoria Kostina (vkostina@caltech.edu)\n%\n\nKbig = 20;\ntol = 1e-3;\n\nout = Inf;\nbestL = NaN;\nfor L = find(PeCh <= e)\n cur = PeubSource(L, k, d) + PeCh(L);\n if out > cur\n out = cur;\n bestL = L;\n end\nend\n%fprintf('ASeparate: k = %i, Peub = %f\\n', k, out);\n\n function out = PeubSource(L, k, d)\n %achievability via sphere covering\n \n r0 = sqrt( max( 0, 1 - d) );\n a = r0 - sqrt(d);\n b = r0 + sqrt(d);\n \n out = chi2cdf((a^2 + tol)*k, k) + 1 - chi2cdf((b^2 - tol)*k, k)... %nontypical source realization\n + quad(@Pes, a^2 + tol, b^2- tol); %source error\n \n function out = logPdball(x)\n %x - distance squared from the origin (x*k central chi square k)\n cosa = (r0^2 + x - d)./(2*r0.*sqrt(x));\n sina = (1 - cosa.^2).^(1/2);\n out = loggamma(k/2+1, 'LB') - loggamma((k-1)/2 +1, 'UB')- .5*log(pi)-log(k) + (k-1)*log(sina);\n end\n \n function out = Pes(x)\n %source error conditioned on the distance squared from the origin (x*k central chi square k)\n if k < Kbig\n out = (1 - exp(logPdball(x))).^exp(L);\n else\n out = exp( - exp( logPdball(x) + L));\n end\n out = out.*chi2pdf(k*x, k).*k;\n end\n end\nend\n\n\n\n", "meta": {"author": "yp-mit", "repo": "spectre", "sha": "57af76799e4eb43aa707cc13c4c5220d281e0b78", "save_path": "github-repos/MATLAB/yp-mit-spectre", "path": "github-repos/MATLAB/yp-mit-spectre/spectre-57af76799e4eb43aa707cc13c4c5220d281e0b78/jscc/GMS-AWGN/Peubseparate.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096067182449, "lm_q2_score": 0.8104789086703224, "lm_q1q2_score": 0.7424875142754014}} {"text": "%==============================================================================\n% Copyright (C) 2005, Jan Modersitzki and Nils Papenberg, see copyright.m,\n% this file is part of the FLIRT Package, all rights reserved;\n% http://www.math.uni-luebeck.de/SAFIR/FLIRT-MATLAB.html\n%==============================================================================\n% function [B,Bstr] = getDiffusiveMatrix(Omega,m);\n% generates the elastic matrix B for the domain Omega with resolution m,\n% by default, mu = 1, lambda = 0;\n%==============================================================================\nfunction [B,Bstr] = getDiffusiveMatrixStg(Omega,m)\n\nBstr = 'diffusive-stg';\nh = Omega./m;\n\nd11 = spdiags(ones(m(1),1)*[-1,1],[0,1],m(1),m(1)+1)/h(1);\nd12 = spdiags(ones(m(2)-1,1)*[-1,1],[0,1],m(2)-1,m(2))/h(2);\nd21 = spdiags(ones(m(1)-1,1)*[-1,1],[0,1],m(1)-1,m(1))/h(1);\nd22 = spdiags(ones(m(2),1)*[-1,1],[0,1],m(2),m(2)+1)/h(2);\n\nD11 = sparse(kron(speye(m(2)),d11));\nD12 = sparse(kron(d12,speye(m(1)+1)));\nD21 = sparse(kron(speye(m(2)+1),d21));\nD22 = sparse(kron(d22,speye(m(1))));\n\n\n% build the diffusive operator \n%\n% | \\nabla 0 |\n% B = | |\n% | 0 \\nabla |\n% | |\n% B[U] = [\\partial_1 U1,\\partial_2 U1, \\partial_1 U2,\\partial_2 U2]\n\nn1 = (m(1)+1)*m(2);\nn2 = m(1)*(m(2)+1);\nj1 = size(D11,1);\nj2 = size(D12,1);\nj3 = size(D21,1);\nj4 = size(D22,1);\n\nB = [ D11,sparse(j1,n2);\n D12,sparse(j2,n2);\n sparse(j3,n1),D21;\n sparse(j4,n1),D22]; \nreturn;\n%==============================================================================\n", "meta": {"author": "vistalab", "repo": "vistasoft", "sha": "7f0102c696c091c858233340cc7e1ab02f064d4c", "save_path": "github-repos/MATLAB/vistalab-vistasoft", "path": "github-repos/MATLAB/vistalab-vistasoft/vistasoft-7f0102c696c091c858233340cc7e1ab02f064d4c/mrBOLD/Analysis/RetinotopyModelFit/Version10/solvers/getDiffusiveMatrixStg.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096112990283, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.742487513794335}} {"text": "function bubblesort_complexity ( )\n\n%*****************************************************************************80\n%\n%% BUBBLESORT_COMPLEXITY measures the complexity of the bubblesort algorithm.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 23 December 2012\n%\n% Author:\n%\n% John Burkardt\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'BUBBLESORT_COMPLEXITY\\n' );\n fprintf ( 1, ' How does the time requirement increase with vector length\\n' );\n fprintf ( 1, ' for the bubblesort algorithm?\\n' );\n%\n% Get some data for N = 1 : 200.\n% Do the loop twice to avoid startup anomalies.\n%\n for i = 1 : 2\n\n data_size = zeros ( 200, 1 );\n data_time = zeros ( 200, 1 );\n\n for n = 1 : 200\n a = rand ( n, 1 );\n tic;\n a_heap = r8vec_sort_bubble_a ( n, a );\n data_size(n) = n;\n data_time(n) = toc;\n end\n\n end\n\n figure ( 1 )\n plot ( data_size, data_time, 'r-' )\n grid on\n xlabel ( 'Vector length N' );\n ylabel ( 'Elapsed time T' );\n title ( 'T(N), time to heap sort a vector of length N' );\n\n filename = 'bubblesort_1to200.png';\n print ( '-dpng', filename );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Plot saved as \"%s\".\\n', filename );\n%\n% Get some data for N = 1, 2, 4, ..., 2^12.\n% Do the loop twice to avoid startup anomalies.\n%\n for i = 1 : 2\n\n data_size = zeros ( 13, 1 );\n data_time = zeros ( 13, 1 );\n\n n = 1;\n\n for nlog = 0 : 12\n a = rand ( n, 1 );\n tic;\n a_heap = r8vec_sort_bubble_a ( n, a );\n data_size(nlog+1) = n;\n data_time(nlog+1) = toc;\n n = n * 2;\n end\n\n end\n\n figure ( 2 )\n loglog ( data_size, data_time, 'r-o' )\n grid on\n xlabel ( 'Vector length N' );\n ylabel ( 'Elapsed time T' );\n title ( 'T(N), time to heap sort a vector of length N' );\n\n filename = 'bubblesort_powersoftwo.png';\n print ( '-dpng', filename );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Plot saved as \"%s\".\\n', filename );\n!\n! Terminate.\n!\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'BUBBLESORT_COMPLEXITY\\n' );\n fprintf ( 1, ' Normal end of execution.\\n' );\n\n return\nend\nfunction a = r8vec_sort_bubble_a ( n, a )\n\n%*****************************************************************************80\n%\n%% R8VEC_SORT_BUBBLE_A ascending sorts an R8VEC using bubble sort.\n%\n% Discussion:\n%\n% Bubble sort is simple to program, but inefficient. It should not\n% be used for large arrays.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 24 February 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the number of entries in the array.\n%\n% Input, real A(N), an unsorted array.\n%\n% Output, real A(N), the array has been sorted.\n%\n for i = 1 : n-1\n for j = i + 1 : n\n if ( a(j) < a(i) )\n t = a(i);\n a(i) = a(j);\n a(j) = t;\n end\n end\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/complexity/bubblesort_complexity.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619263765707, "lm_q2_score": 0.9005297881200701, "lm_q1q2_score": 0.742452523872958}} {"text": "function [ x, seed ] = triangle01_sample ( n, seed )\n\n%*****************************************************************************80\n%\n%% TRIANGLE01_SAMPLE samples the interior of the unit triangle in 2D.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 13 January 2014\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Reuven Rubinstein,\n% Monte Carlo Optimization, Simulation, and Sensitivity\n% of Queueing Networks,\n% Krieger, 1992,\n% ISBN: 0894647644,\n% LC: QA298.R79.\n%\n% Parameters:\n%\n% Input, integer N, the number of points.\n%\n% Input/output, integer SEED, a seed for the random\n% number generator.\n%\n% Output, real X(2,N), the points.\n%\n m = 2;\n\n for j = 1 : n\n\n [ e, seed ] = r8vec_uniform_01 ( m + 1, seed );\n\n e(1:m+1) = - log ( e(1:m+1) );\n\n x(1:m,j) = e(1:m) / sum ( e(1:m+1) );\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/triangle_monte_carlo/triangle01_sample.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8840392817460333, "lm_q2_score": 0.8397339636614178, "lm_q1q2_score": 0.7423578100929894}} {"text": "function npartitions = npart_enum ( n, npart )\n\n%*****************************************************************************80\n%\n%% NPART_ENUM enumerates the number of partitions of N with NPART parts.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 25 January 2011\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Donald Kreher, Douglas Simpson,\n% Combinatorial Algorithms,\n% CRC Press, 1998,\n% ISBN: 0-8493-3988-X,\n% LC: QA164.K73.\n%\n% Parameters:\n%\n% Input, integer N, the integer to be partitioned.\n% Normally N must be positive, but for this routine any\n% N is allowed.\n%\n% Input, integer NPART, the number of parts of the partition.\n% Normally, 1 <= NPART <= N is required,\n% but for this routine any value of NPART is allowed.\n%\n% Output, integer NPARTITIONS is the number of partitions of N\n% with NPART parts.\n%\n if ( n <= 0 )\n\n npartitions = 0;\n\n elseif ( npart <= 0 || n < npart )\n\n npartitions = 0;\n\n else\n\n offset = 1;\n\n p = npart_table ( n, npart );\n\n npartitions = p(n+offset,npart+offset);\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/combo/npart_enum.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392695254319, "lm_q2_score": 0.839733963661418, "lm_q1q2_score": 0.7423577998309355}} {"text": "function [x_max y_max A]=crit_interp_g(y,x);\n%fits a gaussian to three points: y=[y(x(1)) y(x(2)) y(x(3))]. Returns the \n%position (x_max) and value (y_max) of the interpolated critical point \n%(peak or trough). Things go sideways (complex) if y is mixed sign and\n%rounding errors can cause spurious complex results if y is negative.\n%If x is omitted, it is assumed to be [-1 0 1].\n%y=A(1)*exp(-A(2)*(x-A(3)).^2)\n\n% Copyright Travis Wiens 2009 travis.mlfx@nutaksas.com\n\nif nargin<2\n x=[-1 0 1];\nend\n\nlny=log(y);\n\n%lny=1/denom*(a*x^2+b*x+c)\na =(x(3) * (lny(2) - lny(1)) + x(2) * (lny(1) - lny(3)) + x(1) * (lny(3) - lny(2)));\nb =(x(3)*x(3) * (lny(1) - lny(2)) + x(2)*x(2) * (lny(3) - lny(1)) + x(1)*x(1) * (lny(2) - lny(3)));\nc =(x(2) * x(3) * (x(2) - x(3)) * lny(1) + x(3) * x(1) * (x(3) - x(1)) * lny(2) + x(1) * x(2) * (x(1) - x(2)) * lny(3));\n\n%y=A*exp(-B*(x-C)^2);\nC=-b/(2*a);\nx_max=C;\n\nif nargout>1\n denom = (x(1) - x(2)) * (x(1) - x(3)) * (x(2) - x(3));\n A=exp(c/denom-b*b/(4*a*denom));\n y_max=A;\n if nargout>2\n B=-a/denom;\n A=[A B C];\n end\nend\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/24465-peak-interpolation/peak_interp_0_01/crit_interp_g.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248157222395, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.7423275914457503}} {"text": "function M = specialeuclideanfactory(n, k)\n% Returns a manifold structure to optimize over the special Euclidean group\n% \n% function M = specialeuclideanfactory(n)\n% function M = specialeuclideanfactory(n, k)\n%\n% The special Euclidean group (the manifold of rigid transformations):\n% This is a product manifold of the rotations group SO(n) and the\n% translation group R^n, copied k times.\n%\n% Points on the manifold are represented as structures X with two fields.\n% X.R is a 3D array of size nxnxk such that each slice X.R(:, :, i)\n% corresponds to a rotation matrix (orthogonal with determinant 1).\n% X.t is a matrix of size nxk such that each column X.t(:, i) corresponds\n% to a translation vector.\n%\n% Tangent vectors are represented as structures with the same fields. Note\n% that rotational components of the tangent vectors are represented in the\n% Lie algebra, i.e., each slice Xdot.R(:, :, i) is a skew-symmetric matrix.\n% Use M.tangent2ambient(X, Xdot) to obtain a representation in the ambient\n% space.\n%\n% This is a description of SE(n)^k with the induced metric from the\n% embedding space (R^nxn)^k x (R^n)^k, i.e., this manifold is a Riemannian\n% submanifold of the embedding Euclidean space with the usual inner\n% product.\n%\n% By default, k = 1.\n%\n% This is a test geometry: it may not be the \"appropriate\" geometry to give\n% to SE(n).\n%\n% See rotationsfactory and euclideanfactory for details.\n%\n% See also: rotationsfactory euclideanfactory\n\n% This file is part of Manopt: www.manopt.org.\n% Original author: Nicolas Boumal, Sep. 23, 2014.\n% Contributors: \n% Change log:\n\n \n if ~exist('k', 'var') || isempty(k)\n k = 1;\n end\n \n elements = struct();\n elements.R = rotationsfactory(n, k);\n elements.t = euclideanfactory(n, k);\n \n M = productmanifold(elements);\n\nend\n", "meta": {"author": "MIT-SPARK", "repo": "GlobalOptimizationTutorial", "sha": "ae1e947a846ca9199d9a3579409d73f4f7fa4ccf", "save_path": "github-repos/MATLAB/MIT-SPARK-GlobalOptimizationTutorial", "path": "github-repos/MATLAB/MIT-SPARK-GlobalOptimizationTutorial/GlobalOptimizationTutorial-ae1e947a846ca9199d9a3579409d73f4f7fa4ccf/SE-Sync/manopt/manopt/manifolds/specialeuclidean/specialeuclideanfactory.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248191350352, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.742327589509553}} {"text": "function quadrule_test25 ( )\n\n%*****************************************************************************80\n%\n%% TEST25 tests LEGENDRE_SET_SQRTX2_01.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 19 October 2009\n%\n% Author:\n%\n% John Burkardt\n%\n order_max = 20;\n\n a = 0.0;\n b = 1.0;\n\n nsub = 1;\n\n xlo = 0.0;\n xhi = 1.0;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TEST25\\n' );\n fprintf ( 1, ' LEGENDRE_SET_SQRTX2_01 sets up Gauss-Legendre\\n' );\n fprintf ( 1, ' quadrature over [0,1] with weight function 1/SQRT(X);\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' The integration interval is [%f, %f]\\n', a, b );\n fprintf ( 1, ' Number of subintervals is %d\\n', nsub );\n fprintf ( 1, ' Quadrature order will vary.\\n' );\n fprintf ( 1, ' Integrand will vary.\\n' );\n\n nfunc = func_set ( 'COUNT', 'DUMMY' );\n\n for ilo = 1 : 5 : nfunc\n\n ihi = min ( ilo + 4, nfunc );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' ' );\n for i = ilo : ihi\n fprintf ( '%14s', fname(i) );\n end\n fprintf ( 1, '\\n' );\n fprintf ( 1, '\\n' );\n\n for iexp = 0 : 3\n\n norder = 2^iexp;\n\n fprintf ( 1, ' %2d', norder );\n\n for i = ilo : ihi\n\n func_set ( 'SET', i );\n\n [ xtab, weight ] = legendre_set_sqrtx2_01 ( norder );\n\n result = 0.0;\n for j = 1 : norder\n result = result + weight(j) * func ( xtab(j) );\n end\n\n fprintf ( 1, ' %12f', result );\n\n end\n\n fprintf ( 1, '\\n' );\n\n end\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/quadrule/quadrule_test25.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767906859264, "lm_q2_score": 0.8459424411924673, "lm_q1q2_score": 0.7422948584025842}} {"text": "%% rand_angle\n% Below is a demonstration of the features of the |rand_angle| function\n\n%%\nclear; close all; clc;\n\n%% Syntax\n% |a=rand_angle(siz);|\n\n%% Description \n% This function generates a matrix or array of uniformly distributed random\n% angles (of the size siz) in the range [0 2*pi]. The function operates by\n% first creating angles in the range 0-pi/2. The angles are next converted\n% to unit vectors in the unit circle. The X and Y components of these\n% vectors are next independantly and randomly negated. This negating or\n% flipping operation causes the vectors to uniformly but randomly span the\n% entire cirle. Nexts the vectors are converted to an angle in the range [0\n% 2*pi]. \n\n%%\n% Plot settings for examples\nmarkerSize=25; \nlineWidth=3; \nfontSize=35;\n\n%% Examples \n% \n\nsiz=[500,1]; %Size of desired output\na=rand_angle(siz); % The random angles\n\n%%\n\ncFigure; hold on; \nxlabel('Angles'); ylabel('Count');\nhistogram(a,linspace(0,2*pi,6));\nset(gca,'FontSize',fontSize);\ndrawnow; \n\n%% \n% Visualization\n\n%Create circle coordinates to visualize circle curve\nt=linspace(0,2*pi,100)';\nvc=[cos(t) sin(t)];\nN=[cos(a) sin(a)];\n\ncFigure; hold on; \nhp1=plotV(vc,'b-','LineWidth',lineWidth);\nhp2=plotV(N,'k.','MarkerSize',markerSize);\naxis tight; axis equal; box on; grid on; \nview(2);\nset(gca,'FontSize',fontSize);\nlegend([hp1 hp2],{'Circle boundary','Uniformly distributed points on circle'},'Location','NorthOutside');\ndrawnow; \n\n%%\n% \n% <>\n% \n% _*GIBBON*_ \n% \n% \n% _Kevin Mattheus Moerman_, \n%% \n% _*GIBBON footer text*_ \n% \n% License: \n% \n% GIBBON: The Geometry and Image-based Bioengineering add-On. A toolbox for\n% image segmentation, image-based modeling, meshing, and finite element\n% analysis.\n% \n% Copyright (C) 2006-2022 Kevin Mattheus Moerman and the GIBBON contributors\n% \n% This program is free software: you can redistribute it and/or modify\n% it under the terms of the GNU General Public License as published by\n% the Free Software Foundation, either version 3 of the License, or\n% (at your option) any later version.\n% \n% This program is distributed in the hope that it will be useful,\n% but WITHOUT ANY WARRANTY; without even the implied warranty of\n% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n% GNU General Public License for more details.\n% \n% You should have received a copy of the GNU General Public License\n% along with this program. If not, see .\n", "meta": {"author": "gibbonCode", "repo": "GIBBON", "sha": "8178520664a6148db939eaea87e75b3cba4f2b4f", "save_path": "github-repos/MATLAB/gibbonCode-GIBBON", "path": "github-repos/MATLAB/gibbonCode-GIBBON/GIBBON-8178520664a6148db939eaea87e75b3cba4f2b4f/docs/HELP_rand_angle.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767810736693, "lm_q2_score": 0.8459424373085146, "lm_q1q2_score": 0.7422948468630897}} {"text": "function y = convolve2(x, m, shape, tol)\n%CONVOLVE2 Two dimensional convolution.\n% Y = CONVOLVE2(X, M) performs the 2-D convolution of matrices X and\n% M. If [mx,nx] = size(X) and [mm,nm] = size(M), then size(Y) =\n% [mx+mm-1,nx+nm-1]. Values near the boundaries of the output array are\n% calculated as if X was surrounded by a border of zero values.\n%\n% Y = CONVOLVE2(X, M, SHAPE) where SHAPE is a string returns a\n% subsection of the 2-D convolution with size specified by SHAPE:\n%\n% 'full' - (default) returns the full 2-D convolution,\n% 'same' - returns the central part of the convolution\n% that is the same size as X (using zero padding),\n% 'valid' - returns only those parts of the convolution\n% that are computed without the zero-padded\n% edges, size(Y) = [mx-mm+1,nx-nm+1] when\n% size(X) > size(M),\n% 'wrap' - as for 'same' except that instead of using\n% zero-padding the input X is taken to wrap round as\n% on a toroid.\n% 'reflect' - as for 'same' except that instead of using\n% zero-padding the input X is taken to be reflected\n% at its boundaries.\n%\n% CONVOLVE2 is fastest when mx > mm and nx > nm - i.e. the first\n% argument is the input and the second is the mask.\n%\n% If the rank of the mask M is low, CONVOLVE2 will decompose it into a\n% sum of outer product masks, each of which is applied efficiently as\n% convolution with a row vector and a column vector, by calling CONV2.\n% The function will often be faster than CONV2 or FILTER2 (in some\n% cases much faster) and will produce the same results as CONV2 to\n% within a small tolerance.\n%\n% Y = CONVOLVE2(... , TOL) where TOL is a number in the range 0.0 to\n% 1.0 computes the convolution using a reduced-rank approximation to\n% M, provided this will speed up the computation. TOL limits the\n% relative sum-squared error in the effective mask; that is, if the\n% effective mask is E, the error is controlled such that\n%\n% sum(sum( (M-E) .* (M-E) ))\n% -------------------------- <= TOL\n% sum(sum( M .* M ))\n%\n% See also CONV2, FILTER2.\n\n% Copyright David Young, Feb 2002, revised Jan 2005, Jan 2009, Apr 2011\n\n% Deal with optional arguments\nerror(nargchk(2,4,nargin));\nif nargin < 3\n shape = 'full'; % shape default as for CONV2\n tol = 0;\nelseif nargin < 4\n if isnumeric(shape)\n tol = shape;\n shape = 'full';\n else\n tol = 0;\n end\nend;\n\n% Set up to do the wrap & reflect operations, not handled by conv2\nif ismember(shape, {'wrap' 'reflect'})\n x = extendarr(x, m, shape);\n shape = 'valid';\nend\n\n% do the convolution itself\ny = doconv(x, m, shape, tol);\nend\n\n%-----------------------------------------------------------------------\n\nfunction y = doconv(x, m, shape, tol)\n% Carry out convolution\n[mx, nx] = size(x);\n[mm, nm] = size(m);\n\n% If the mask is bigger than the input, or it is 1-D already,\n% just let CONV2 handle it.\nif mm > mx || nm > nx || mm == 1 || nm == 1\n y = conv2(x, m, shape);\nelse\n % Get svd of mask\n if mm < nm; m = m'; end % svd(..,0) wants m > n\n [u,s,v] = svd(m, 0);\n s = diag(s);\n rank = trank(m, s, tol);\n if rank*(mm+nm) < mm*nm % take advantage of low rank\n if mm < nm; t = u; u = v; v = t; end % reverse earlier transpose\n vp = v';\n % For some reason, CONV2(H,C,X) is very slow, so use the normal call\n y = conv2(conv2(x, u(:,1)*s(1), shape), vp(1,:), shape);\n for r = 2:rank\n y = y + conv2(conv2(x, u(:,r)*s(r), shape), vp(r,:), shape);\n end\n else\n if mm < nm; m = m'; end % reverse earlier transpose\n y = conv2(x, m, shape);\n end\nend\nend\n\n%-----------------------------------------------------------------------\n\nfunction r = trank(m, s, tol)\n% Approximate rank function - returns rank of matrix that fits given\n% matrix to within given relative rms error. Expects original matrix\n% and vector of singular values.\nif tol < 0 || tol > 1\n error('Tolerance must be in range 0 to 1');\nend\nif tol == 0 % return estimate of actual rank\n tol = length(m) * max(s) * eps;\n r = sum(s > tol);\nelse\n ss = s .* s;\n t = (1 - tol) * sum(ss);\n r = 0;\n sm = 0;\n while sm < t\n r = r + 1;\n sm = sm + ss(r);\n end\nend\nend\n\n%-----------------------------------------------------------------------\n\nfunction y = extendarr(x, m, shape)\n% Extend x so as to wrap around on both axes, sufficient to allow a\n% \"valid\" convolution with m to return the cyclical convolution.\n% We assume mask origin near centre of mask for compatibility with\n% \"same\" option.\n\n[mx, nx] = size(x);\n[mm, nm] = size(m);\n\nmo = floor((1+mm)/2); no = floor((1+nm)/2); % reflected mask origin\nml = mo-1; nl = no-1; % mask left/above origin\nmr = mm-mo; nr = nm-no; % mask right/below origin\n\nif strcmp(shape, 'wrap')\n y = exindex(x, 1-ml:mx+mr, 1-nl:nx+nr, 'circular');\nelse\n y = exindex(x, 1-ml:mx+mr, 1-nl:nx+nr, 'symmetric');\nend\n\nend\n\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/22619-fast-2-d-convolution/convolve2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382094310355, "lm_q2_score": 0.8615382129861583, "lm_q1q2_score": 0.742248089372509}} {"text": "function pass = test_nonlinSys1Breaks_US(pref)\n% Test 2x2 system (sin/cos). This is pecewiseificaion of the test\n% test_nonlinearSystem1\n%\n% Asgeir Birkisson, April 2014.\n\nif ( nargin == 0 )\n pref = cheboppref;\nend\n\ntol = 1e-10;\n\nd = [-pi 0 pi];\nx = chebfun('x',d);\nf = [ 0*x ; 0*x ];\n\n%% Piecewise (ultraS):\npref.discretization = @ultraS;\n\nA = chebop(@(x,u,v) [u - diff(v,2) + u.^2; diff(u) + sin(v)],d);\nA.lbc = @(u,v) u-1;\nA.rbc = @(u,v) [v-1/2; diff(v)];\n\nu = mldivide(A, f, pref);\nu1 = u{1}; u2 = u{2};\n\n% Want to check BCs as well.\nbcFunLeft = A.lbc(u1,u2);\nbcFunRight = chebfun(A.rbc(u1,u2));\n\n% And check that we're continuous over breakpoint\nu1jump = jump(u1, 0);\nu2jump = jump(u2, 0);\n\npass(1) = norm( chebfun(A(x, u1, u2))) < tol;\npass(2) = norm(bcFunLeft(d(1))) < tol && norm(bcFunRight(d(end))) < tol;\npass(3) = norm(u1jump) < tol && norm(u2jump) < tol;\n\nend\n", "meta": {"author": "chebfun", "repo": "chebfun", "sha": "8c49396a55e46ddd57a1d108c6a8f32e37536d54", "save_path": "github-repos/MATLAB/chebfun-chebfun", "path": "github-repos/MATLAB/chebfun-chebfun/chebfun-8c49396a55e46ddd57a1d108c6a8f32e37536d54/tests/chebop/test_nonlinSys1Breaks_US.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418199787564, "lm_q2_score": 0.803173791645582, "lm_q1q2_score": 0.7422464895705867}} {"text": "function fx2 = p03_fx2 ( x )\n\n%*****************************************************************************80\n%\n%% P03_FX2 evaluates the second derivative of the function for problem 3.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 07 May 2011\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real X, the abscissa.\n%\n% Output, real FX2, the second derivative of the function at X.\n%\n fx2 = exp ( - x ) * ( x - 2.0 );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_zero/p03_fx2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8596637433190939, "lm_q2_score": 0.8633916099737806, "lm_q1q2_score": 0.7422264633803594}} {"text": "% This routine do:\n% 1. Discretize schrodinger equation over the specified set of points:\n% v(x)=2m*V(x)/hbar^2; ee=2m*E/hbar^2.\n% [ d^2 2m ] 2m*E\n% [ - ----- + ------ V(x) ] phi(x) = ------ phi(x)\n% [ d x^2 hbar^2 ] hbar^2\n%\n% 2. Find eigen values and eigen vectors.\n% 3. Plot the found eigen values and eigen vectors.\n%\n% Usage:\n% [ee,ev] = qm1d_fast(NPTS,NSTM,a,b,f_pot_handle)\n% NPTS - number of points for discretization of schrodinger equation\n% NSTM - number of eigen values and eigen vector to find\n% a - the start point of te interval for x\n% b - the end point of the interval for y\n% f_pot_handle - handle to function which defines the potential\n%\n% Examples:\n%\n% 1. Harmonic oscillator - symetric at x=L/2\n% NPTS=1000;\n% NSTM=5;\n% L=10d0;\n% f_pot = @(x) {4d0*(x-L/2).^2}; \n% qm1d_fast(NPTS,NSTM,0,L,f_pot);\n% \n% 2. Harmonic oscillator - symetric at x=0\n% NPTS=1000;\n% NSTM=5;\n% L=10d0;\n% f_pot = @(x) {4d0*x.^2}; \n% qm1d_fast(NPTS,NSTM,-L/2,L/2,f_pot);\n%\n% 3. Barrier - defined with heaviside function\n% NPTS=1000;\n% NSTM=5;\n% L=100d0;\n% bb=3d0;\n% aa=1d0;\n% f_pot = @(x) {heaviside(x-aa)-heaviside(x-bb)};\n% qm1d_fast(NPTS,NSTM,0,L,f_pot);\n%\n% If you don't have heaviside defined in your Matlab version define this function as:\n% function [y]=heaviside(x)\n% y=zeros(1,length(x))\n% ipos = find(x>0);\n% y(ipos)=1;\n%\n% 4.Barrier\n% NPTS=1000;\n% NSTM=5;\n% L=100d0;\n% bb=3d0;\n% aa=1d0;\n% pot_dat = [zeros(1,int16(aa/L*NPTS)), ones(1,int16((bb-aa)/L*NPTS)), zeros(1,int16((L-bb)/L*NPTS))];\n% f_pot = @(x) {pot_dat(int16(x/L*(NPTS-1)))};\n% qm1d_fast(NPTS,NSTM,0,L,f_pot);\n% \n% 5. Harmonic oscillator - with potential defined in file\n% Define the potential in file: \n% NPTS=1000;\n% L=10d0;\n% dx=L/(NPTS-1);\n% pot_dat=[[0:NPTS-1]*dx; 4d0*([0:NPTS-1]-((NPTS-1)/2)).^2*dx^2]';\n% save('pot.dat','-ascii','pot_dat');\n% clear\n%\n% pot_dat=load('pot.dat');\n% f_pot = @(x) {spline(pot_dat(:,1),pot_dat(:,2),x)};\n% %It is not obligatory the NPTS to be the same as the number of points for the potential\n% NPTS=10000; \n% NSTM=5;\n% L=10d0;\n% qm1d_fast(NPTS,NSTM,0,L,f_pot);\n%\n%\n% See also: http://iffwww.iff.kfa-juelich.de/~ekoch/DFT/qm1d.html\nfunction [ee,ev] = qm1d_fast(NPTS,NSTM,a,b,f_pot_handle)\n%pot_dat=load(pot_filename);\nj=1:NPTS; % indexes for main diagonal\nL=b-a;\nh=L/(NPTS-1); % space step\nx=j*h+a;\nV=cell2mat(f_pot_handle(x));\n\nmain_diag=2/h^2+V(j);\nsub_diag=-1/h^2*ones(1,NPTS-1);\n\n[ee,ev] = trideigs(main_diag,sub_diag,'I',1,NSTM);\n\n% average spacing of energy levels (for adjusting scale of ev)\nde0=(ee(NSTM)-ee(1))/(NSTM-1);\n\n% plot potential\nplot(x,V(j),'r'); hold on;\n\n% plot eign vectors\nde=0.15*sqrt(NPTS)*de0;\nfor n=1:NSTM\n plot(x,ee(n)+de*ev(:,n)); hold on;\n plot(x,ones(length(j),1)*ee(n)); hold on;\nend\n\n% set up plotting options\nxlim([0 NPTS]*h+a); ylim([min(V) ee(NSTM)+de0]);\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/42735-matlab-version-of-qm1d-1d-schr%C3%B6dinger-equation-solver/qm1d_fast.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9184802507195636, "lm_q2_score": 0.8080672066194945, "lm_q1q2_score": 0.7421937705341307}} {"text": "%% CUBESTOKES Stokes equations on the unit cube\n%\n% SQUARESTOKE computes CR-P0 approximations of the Stokes equations in\n% the unit cube.\n%\n% Added by Shuhao Cao. Apr, 2020.\n%\n% Copyright (C) Long Chen. See COPYRIGHT.txt for details.\n\nclose all; clear;\n\n%% Set up\nmaxIt = 4;\nN = zeros(maxIt,1); \nh = zeros(maxIt,1);\nerruH1 = zeros(maxIt,1);\nerruL2 = zeros(maxIt,1);\nerrp = zeros(maxIt,1);\n\n%% Generate initial mesh\n[node,elem] = cubemesh([-0.5,0.5,-0.5,0.5,-0.5,0.5],0.25);\nbdFlag = setboundary3(node,elem,'Dirichlet');\n\n%% PDE and options\npde.exactu = @(p)[(1-cos(2*pi*p(:,1))).*sin(2*pi*p(:,2)).*sin(pi*p(:,3)),... \n -(1-cos(2*pi*p(:,2))).*sin(2*pi*p(:,1)).*sin(pi*p(:,3)), 0*p(:,3)];\npde.f = @(p) [-pi^2*(9*cos(2*pi*p(:,1))-5).*sin(2*pi*p(:,2)).*sin(pi*p(:,3))+ p(:,1).^2,... \n pi^2*(9*cos(2*pi*p(:,2))-5).*sin(2*pi*p(:,1)).*sin(pi*p(:,3)), 0*p(:,3)];\npde.g = @(p) zeros(size(p,1),1);\npde.exactp = @(p) p(:,1).^3/3;\npde.g_D = @(p) pde.exactu(p);\n% solver\noption.solver = 'diag'; % diagonal preconditioner\n\n%% Finite Element Method \nfor k = 1:maxIt\n \n [soln,eqn] = Stokes3CRP0(node,elem,bdFlag,pde,option);\n uh = soln.u;\n uhvec = reshape(uh,size(uh,1)/3,3);\n ph = soln.p;\n N(k) = length(uh)+length(ph);\n h(k) = 1./((size(node,1)).^(1/3)-1);\n % compute error;\n uI = pde.exactu((node(eqn.face(:,1),:)+node(eqn.face(:,2),:)+node(eqn.face(:,3),:))/3);\n erruH1(k) = sqrt((uh-uI(:))'*eqn.A*(uh-uI(:)));\n erruL2(k) = getL2error3(node,elem,pde.exactu,uhvec);\n errp(k) = getL2error3(node,elem,pde.exactp,ph);\n fprintf('Number of Dof %d \\n', N(k));\n \n if k < maxIt\n [node,elem,bdFlag] = uniformrefine3(node,elem,bdFlag); \n end \nend\n\n%% Plot convergence rates and display error\nfigure(2);\nshowrateh3(h,erruH1,1,'-*','| u_I-u_h |_1',...\n h,erruL2,1,'-*','|| u-u_h ||',...\n h,errp,1,'-+','|| p-p_h||');\n\nfprintf('\\n');\ndisp('Table: Error')\ncolname = {'#Dof','h','|u_I-u_h|_1','||u-u_h||','||p-p_h||'};\ndisptable(colname,N,[],h,'%0.3e',erruH1,'%0.5e',erruL2,'%0.5e',errp,'%0.5e');\n", "meta": {"author": "lyc102", "repo": "ifem", "sha": "29f31c812001ca8d93dad08e67208ca60e8716d4", "save_path": "github-repos/MATLAB/lyc102-ifem", "path": "github-repos/MATLAB/lyc102-ifem/ifem-29f31c812001ca8d93dad08e67208ca60e8716d4/example/fem/Stokes/cubeStokes.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952893703477, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.7421352832041525}} {"text": "function [ p4, flag ] = line_exp_perp_2d ( p1, p2, p3 )\n\n%*****************************************************************************80\n%\n%% LINE_EXP_PERP_2D computes a line perpendicular to a line and through a point.\n%\n% Discussion:\n%\n% The explicit form of a line in 2D is:\n%\n% ( P1, P2 ) = ( (X1,Y1), (X2,Y2) ).\n%\n% The input point P3 should NOT lie on the line (P1,P2). If it\n% does, then the output value P4 will equal P3.\n%\n% P1-----P4-----------P2\n% |\n% |\n% P3\n%\n% P4 is also the nearest point on the line (P1,P2) to the point P3.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 31 July 2009\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real P1(2,1), P2(2,1), two points on the line.\n%\n% Input, real P3(2,1), a point (presumably not on the\n% line (P1,P2)), through which the perpendicular must pass.\n%\n% Output, real P4(2,1), a point on the line (P1,P2),\n% such that the line (P3,P4) is perpendicular to the line (P1,P2).\n%\n% Output, logical FLAG, is TRUE if the value could not be computed.\n%\n dim_num = 2;\n\n bot = sum ( ( p2(1:dim_num,1) - p1(1:dim_num,1) ).^2 );\n\n if ( bot == 0.0 )\n p4(1:2,1) = Inf;\n flag = 1;\n end\n%\n% (P3-P1) dot (P2-P1) = Norm(P3-P1) * Norm(P2-P1) * Cos(Theta).\n%\n% (P3-P1) dot (P2-P1) / Norm(P3-P1)**2 = normalized coordinate T\n% of the projection of (P3-P1) onto (P2-P1).\n%\n t = sum ( ( p1(1:dim_num,1) - p3(1:dim_num,1) ) ...\n .* ( p1(1:dim_num,1) - p2(1:dim_num,1) ) ) / bot;\n\n p4(1:dim_num,1) = p1(1:dim_num,1) + t * ( p2(1:dim_num,1) - p1(1:dim_num,1) );\n flag = 0;\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/geometry/line_exp_perp_2d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357735451835, "lm_q2_score": 0.8558511506439707, "lm_q1q2_score": 0.7420535644381304}} {"text": "function a = maxij ( m, n )\n\n%*****************************************************************************80\n%\n%% MAXIJ returns the MAXIJ matrix.\n%\n% Discussion:\n%\n% This matrix is occasionally known as the \"Boothroyd MAX\" matrix.\n%\n% Formula:\n%\n% A(I,J) = max(I,J)\n%\n% Example:\n%\n% N = 5\n%\n% 1 2 3 4 5\n% 2 2 3 4 5\n% 3 3 3 4 5\n% 4 4 4 4 5\n% 5 5 5 5 5\n%\n% Properties:\n%\n% A is integral, therefore det ( A ) is integral, and \n% det ( A ) * inverse ( A ) is integral.\n%\n% A is symmetric: A' = A.\n%\n% Because A is symmetric, it is normal.\n%\n% Because A is normal, it is diagonalizable.\n%\n% The inverse of A is tridiagonal.\n%\n% The family of matrices is nested as a function of N.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 16 October 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Robert Gregory, David Karney,\n% Example 3.13,\n% A Collection of Matrices for Testing Computational Algorithms,\n% Wiley, 1969, page 42,\n% LC: QA263.G68.\n%\n% Parameters:\n%\n% Input, integer M, N, the number of rows and columns \n% of the matrix.\n%\n% Output, real A(M,N), the matrix.\n%\n for i = 1 : m\n for j = 1 : n\n a(i,j) = max ( i, j );\n end\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_mat/maxij.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357666736773, "lm_q2_score": 0.8558511506439708, "lm_q1q2_score": 0.742053558557144}} {"text": "function OUT = MovSum(DATA,window)\n% =======================================================================\n% Moving sum of the vector (or matrix) DATA (T obs x N variables). If \n% DATA is a matrix moving sum is computed down each column.\n% =======================================================================\n% OUT = MovAvg(DATA,window)\n% -----------------------------------------------------------------------\n% INPUT\n% DATA: T observations x N variables\n% window: window of the moving sum \n%------------------------------------------------------------------------\n% OUPUT\n% OUT: T observations x N variables matrix (the first windows-1 \n% obseravations are NaN)\n% =======================================================================\n% Ambrogio Cesa Bianchi, March 2015\n% ambrogio.cesabianchi@gmail.com\n\nif nargin<2, error('Not enough input.'), end\nif window<=0, error('window must be positive.'), end\nif (window~=floor(window)), error('window must be an integer.'), end\n\nif min(size(DATA))==1,\n DATA = DATA(:); % forces DATA to be a column vector\nend\n\n[nobs,nvar] = size(DATA);\nif window>nobs,\n error('window must not be greater than the length of DATA.')\nend\n\ntemp=[];\nfor row=1:(nobs-window+1),\n temp = [temp; sum(DATA(row:(row+window-1),:))];\nend\n\nOUT = temp;\nOUT = [nan(window-1,nvar); OUT]; % add nans to make conformable to original \n", "meta": {"author": "ambropo", "repo": "VAR-Toolbox", "sha": "9fe5d763da307cdded2827851325766b3a7c60e1", "save_path": "github-repos/MATLAB/ambropo-VAR-Toolbox", "path": "github-repos/MATLAB/ambropo-VAR-Toolbox/VAR-Toolbox-9fe5d763da307cdded2827851325766b3a7c60e1/OldVersions/v2dot0/Stats/MovSum.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357735451835, "lm_q2_score": 0.8558511432905481, "lm_q1q2_score": 0.74205355806245}} {"text": "function lattice_rule_test01 ( )\n\n%*****************************************************************************80\n%\n%% LATTICE_RULE_TEST01 tests FIBONACCI_LATTICE_Q;\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 18 November 2008\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Ian Sloan, Stephen Joe,\n% Lattice Methods for Multiple Integration,\n% Oxford, 1994, page 78-80, page 145.\n%\n dim_num = 2;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'LATTICE_RULE_TEST01\\n' );\n fprintf ( 1, ' FIBONACCI_LATTICE_Q applies a Fibonacci lattice rule\\n' );\n fprintf ( 1, ' to integrate a function over the unit square.\\n' );\n fprintf ( 1, ' These Fibonacci rules are only available in 2D.\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' The spatial dimension DIM_NUM = %d\\n', dim_num );\n\n a(1:dim_num) = 0.0;\n b(1:dim_num) = 1.0;\n\n exact = e_01_2d ( dim_num, a, b );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' K M EXACT ESTIMATE ERROR\\n' );\n fprintf ( 1, '\\n' );\n\n for k = 3 : 18\n\n quad = fibonacci_lattice_q ( k, @f_01_2d );\n\n error = abs ( exact - quad );\n m = fibonacci ( k );\n\n fprintf ( 1, ' %8d %8d %10.6f %10.6f %10.6e\\n', k, m, exact, quad, error );\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/lattice_rule/lattice_rule_test01.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021707, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.7420535510822371}} {"text": "function prob_test082 ( )\n\n%*****************************************************************************80\n%\n%% TEST082 tests GEOMETRIC_MEAN, *_SAMPLE, *_VARIANCE.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 29 January 2009\n%\n% Author:\n%\n% John Burkardt\n%\n nsample = 1000;\n seed = 123456789;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'PROB_TEST082\\n' );\n fprintf ( 1, ' For the Geometric PDF:\\n' );\n fprintf ( 1, ' GEOMETRIC_MEAN computes the mean;\\n' );\n fprintf ( 1, ' GEOMETRIC_SAMPLE samples;\\n' );\n fprintf ( 1, ' GEOMETRIC_VARIANCE computes the variance.\\n' );\n\n a = 0.25;\n\n check = geometric_check ( a );\n\n if ( ~check );\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'PROB_TEST082 - Fatal error!\\n' );\n fprintf ( 1, ' The parameters are not legal.\\n' );\n return\n end\n\n mean = geometric_mean ( a );\n variance = geometric_variance ( a );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' PDF parameter A = %14f\\n', a );\n fprintf ( 1, ' PDF mean = %14f\\n', mean );\n fprintf ( 1, ' PDF variance = %14f\\n', variance );\n\n for i = 1 : nsample\n [ x(i), seed ] = geometric_sample ( a, seed );\n end\n\n mean = i4vec_mean ( nsample, x );\n variance = i4vec_variance ( nsample, x );\n xmax = max ( x(1:nsample) );\n xmin = min ( x(1:nsample) );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Sample size = %6d\\n', nsample );\n fprintf ( 1, ' Sample mean = %14f\\n', mean );\n fprintf ( 1, ' Sample variance = %14f\\n', variance );\n fprintf ( 1, ' Sample maximum = %6d\\n', xmax );\n fprintf ( 1, ' Sample minimum = %6d\\n', xmin );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/prob/prob_test082.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.867035752930664, "lm_q2_score": 0.8558511469672594, "lm_q1q2_score": 0.7420535436073301}} {"text": "function p = predictOneVsAll(all_theta, X)\n%PREDICT Predict the label for a trained one-vs-all classifier. The labels \n%are in the range 1..K, where K = size(all_theta, 1). \n% p = PREDICTONEVSALL(all_theta, X) will return a vector of predictions\n% for each example in the matrix X. Note that X contains the examples in\n% rows. all_theta is a matrix where the i-th row is a trained logistic\n% regression theta vector for the i-th class. You should set p to a vector\n% of values from 1..K (e.g., p = [1; 3; 1; 2] predicts classes 1, 3, 1, 2\n% for 4 examples) \n\nm = size(X, 1);\nnum_labels = size(all_theta, 1);\n\n% You need to return the following variables correctly \np = zeros(size(X, 1), 1);\n\n% Add ones to the X data matrix\nX = [ones(m, 1) X];\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Complete the following code to make predictions using\n% your learned logistic regression parameters (one-vs-all).\n% You should set p to a vector of predictions (from 1 to\n% num_labels).\n%\n% Hint: This code can be done all vectorized using the max function.\n% In particular, the max function can also return the index of the \n% max element, for more information see 'help max'. If your examples \n% are in rows, then, you can use max(A, [], 2) to obtain the max \n% for each row.\n% \n% temp = (X*all_theta');\n% p(:) = max(temp,[],2); \n\nh_theta = sigmoid(X * all_theta');\np = max(h_theta, [], 2);\n\n% temp is of dimension 5000x10\n\n% Dimention of X: 5000x401\n% Dimension of all_theta: 10x401\n% Dimension of X*all_theta': 5000x10 \n\n% =========================================================================\n\n\nend\n", "meta": {"author": "anirudhjayaraman", "repo": "Machine-Learning", "sha": "084e9c67ac3853f78461f9d0e46c7b41364da481", "save_path": "github-repos/MATLAB/anirudhjayaraman-Machine-Learning", "path": "github-repos/MATLAB/anirudhjayaraman-Machine-Learning/Machine-Learning-084e9c67ac3853f78461f9d0e46c7b41364da481/Andrew Ng Stanford Coursera/Week 04/ex3/predictOneVsAll.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357529306639, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.7420535404194898}} {"text": "% This is small script that demonstrate the computation of extrinsic \n% parameters using 3D structures.\n% This test was build from data provided by Daniel Small (thank you Daniel!)\n\n\n%-- Image points (in pixels):\n\nx = [479.5200 236.0800\n 608.4100 415.3700\n 461.0000 40.0000\n 451.4800 308.7000\n 373.9900 314.8900\n 299.3200 319.1300\n 231.5500 321.3700\n 443.7300 282.9200\n 378.3600 288.3000\n 314.6900 292.7400\n 255.4700 296.2300]';\n\n\n% 3D world coordinates:\n\nX = [ 0 0 0\n 54.0000 0 0\n 0 0 40.5000\n 27.0000 -8.4685 -2.3750\n 27.0000 -18.4685 -2.3750\n 27.0000 -28.4685 -2.3750\n 27.0000 -38.4685 -2.3750\n 17.0000 -8.4685 -2.3750\n 17.0000 -18.4685 -2.3750\n 17.0000 -28.4685 -2.3750\n 17.0000 -38.4685 -2.3750]';\n\n\n%------------ Intrinsic parameters:\n%--- focal:\nfc = [ 395.0669 357.1178 ]';\n%--- Principal point:\ncc = [ 380.5387 230.5278 ]';\n%--- Distortion coefficients:\nkc = [-0.2601 0.0702 -0.0019 -0.0003 0]';\n%--- Skew coefficient:\nalpha_c = 0;\n\n%----- Computation of the pose of the object in space\n%----- (or the rigid motion between world reference frame and camera ref. frame)\n[om,T,R] = compute_extrinsic(x,X,fc,cc,kc,alpha_c);\n\n%--- Try to reproject the structure to see if the computed pose makes sense:\nx2 = project_points2(X_1,omckk,Tckk,fc,cc,kc,alpha_c);\n\n\n% Graphical output:\nfigure(2);\nplot(x(1,:),x(2,:),'r+');\nhold on;\nplot(x2(1,:),x2(2,:),'go');\nhold off;\naxis('equal');\naxis('image');\ntitle('red crosses: data, green circles: reprojected structure -- IT WORKS!!!');\nxlabel('x');\nylabel('y');\n\n", "meta": {"author": "JzHuai0108", "repo": "ekfmonoslam", "sha": "443f6be744732453cdb90679abcaf5c962a6295e", "save_path": "github-repos/MATLAB/JzHuai0108-ekfmonoslam", "path": "github-repos/MATLAB/JzHuai0108-ekfmonoslam/ekfmonoslam-443f6be744732453cdb90679abcaf5c962a6295e/EKF_monoSLAM_1pRANSAC/matlab_code/matlabcalibration2ourcalibration/TOOLBOX_calib/small_test_script.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533069832974, "lm_q2_score": 0.7956581024858785, "lm_q1q2_score": 0.7419140288910129}} {"text": "function gauss_seidel_test01 ( )\n\n%*****************************************************************************80\n%\n%% GAUSS_SEIDEL_TEST01 tests GAUSS_SEIDEL1.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 06 June 2011\n%\n% Author:\n%\n% John Burkardt\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'GAUSS_SEIDEL_TEST01:\\n' );\n\n it_num = 400;\n n = 20;\n\n x_exact = ( 1 : n )';\n a = dif2 ( n );\n b = a * x_exact;\n\n x = zeros ( n, 1 ); \n x_plot(1:n,1) = x;\n\n step = 1 : it_num + 1;\n e = nan ( it_num+1, 1 );\n xm = nan ( it_num+1, 1 );\n\n e(1,1) = ( norm ( a * x - b ) ).^2;\n\n for it = 1 : it_num\n\n x_new = gauss_seidel1 ( n, a, b, x );\n\n e(it+1,1) = ( norm ( a * x_new - b ) ).^2;\n x_plot(1:n,it+1) = x_new;\n%\n% Display the error.\n%\n figure ( 1 )\n plot ( step, log ( e ), 'm-*' )\n title ( 'Log (Error^2)' )\n xlabel ( 'Step' )\n ylabel ( 'Error' )\n grid\n%\n% Display the motion.\n%\n xm(it,1) = sum ( ( x_new(:) - x(:) ).^2 ) / n;\n\n figure ( 2 )\n plot ( step, log ( xm ), 'm-*' )\n title ( 'Log (Average generator motion)' )\n xlabel ( 'Step' )\n ylabel ( 'Energy' )\n grid\n%\n% Update the solution\n%\n x = x_new;\n\n end\n%\n% Plot the evolution of the locations of the generators.\n%\n figure ( 3 )\n\n y = ( 0 : it_num );\n for k = 1 : n\n plot ( x_plot(k,1:it_num+1), y )\n hold on;\n end\n grid on\n hold off;\n\n title ( 'Generator evolution.' );\n xlabel ( 'Generator positions' );\n ylabel ( 'Iterations' ); \n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/gauss_seidel/gauss_seidel_test01.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942377652497, "lm_q2_score": 0.8333246015211008, "lm_q1q2_score": 0.7419040909222588}} {"text": "function value = r4_sin_deg ( x )\n\n%*****************************************************************************80\n%\n%% R4_SIN_DEG evaluates the sine of an R4 argument in degrees.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 25 September 2011\n%\n% Author:\n%\n% Original FORTRAN77 version by Wayne Fullerton.\n% MATLAB version by John Burkardt.\n%\n% Reference:\n%\n% Wayne Fullerton,\n% Portable Special Function Routines,\n% in Portability of Numerical Software,\n% edited by Wayne Cowell,\n% Lecture Notes in Computer Science, Volume 57,\n% Springer 1977,\n% ISBN: 978-3-540-08446-4,\n% LC: QA297.W65.\n%\n% Parameters:\n%\n% Input, real X, the argument in degrees.\n%\n% Output, real VALUE, the sine of X.\n%\n raddeg = 0.017453292519943296;\n\n value = sin ( raddeg * x );\n\n if ( mod ( x, 90.0 ) == 0.0 )\n\n n = floor ( abs ( x ) / 90.0 + 0.5 );\n n = mod ( n, 2 );\n\n if ( n == 0 )\n value = 0.0;\n elseif ( value < 0.0 )\n value = - 1.0;\n else\n value = + 1.0;\n end\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/fn/r4_sin_deg.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436397, "lm_q2_score": 0.8333245891029457, "lm_q1q2_score": 0.7419040750151562}} {"text": "% FDLA and FMMC solutions for an 8-node, 13-edge graph\n% S. Boyd, et. al., \"Convex Optimization of Graph Laplacian Eigenvalues\"\n% ICM'06 talk examples (www.stanford.edu/~boyd/cvx_opt_graph_lapl_eigs.html)\n% Written for CVX by Almir Mutapcic 08/29/06\n% (figures are generated)\n%\n% In this example we consider a graph described by the incidence matrix A.\n% Each edge has a weight W_i, and we optimize various functions of the\n% edge weights as described in the referenced paper; in particular,\n%\n% - the fastest distributed linear averaging (FDLA) problem (fdla.m)\n% - the fastest mixing Markov chain (FMMC) problem (fmmc.m)\n%\n% Then we compare these solutions to the heuristics listed below:\n%\n% - maximum-degree heuristic (max_deg.m)\n% - constant weights that yield fastest averaging (best_const.m)\n% - Metropolis-Hastings heuristic (mh.m)\n\n% small example (incidence matrix A)\nA = [ 1 0 0 1 0 0 0 0 0 0 0 0 0;\n -1 1 0 0 1 1 0 0 0 0 0 0 1;\n 0 -1 1 0 0 0 0 0 -1 0 0 0 0;\n 0 0 -1 0 0 -1 0 0 0 -1 0 0 0;\n 0 0 0 -1 0 0 -1 1 0 0 0 0 0;\n 0 0 0 0 0 0 1 0 0 0 1 0 0;\n 0 0 0 0 0 0 0 -1 1 0 -1 1 -1;\n 0 0 0 0 -1 0 0 0 0 1 0 -1 0];\n\n% x and y locations of the graph nodes\nxy = [ 1 2 3 3 1 1 2 3 ; ...\n 3 2.5 3 2 2 1 1.5 1 ]';\n\n% Compute edge weights: some optimal, some based on heuristics\n[n,m] = size(A);\n\n[ w_fdla, rho_fdla ] = fdla(A);\n[ w_fmmc, rho_fmmc ] = fmmc(A);\n[ w_md, rho_md ] = max_deg(A);\n[ w_bc, rho_bc ] = best_const(A);\n[ w_mh, rho_mh ] = mh(A);\n\ntau_fdla = 1/log(1/rho_fdla);\ntau_fmmc = 1/log(1/rho_fmmc);\ntau_md = 1/log(1/rho_md);\ntau_bc = 1/log(1/rho_bc);\ntau_mh = 1/log(1/rho_mh);\n\nfprintf(1,'\\nResults:\\n');\nfprintf(1,'FDLA weights:\\t\\t rho = %5.4f \\t tau = %5.4f\\n',rho_fdla,tau_fdla);\nfprintf(1,'FMMC weights:\\t\\t rho = %5.4f \\t tau = %5.4f\\n',rho_fmmc,tau_fmmc);\nfprintf(1,'M-H weights:\\t\\t rho = %5.4f \\t tau = %5.4f\\n',rho_mh,tau_mh);\nfprintf(1,'MAX_DEG weights:\\t rho = %5.4f \\t tau = %5.4f\\n',rho_md,tau_md);\nfprintf(1,'BEST_CONST weights:\\t rho = %5.4f \\t tau = %5.4f\\n',rho_bc,tau_bc);\n\n% Plot results\nfigure(1), clf\nplotgraph(A,xy,w_fdla);\ntext(0.55,1.05,'FDLA optimal weights')\n\nfigure(2), clf\nplotgraph(A,xy,w_fmmc);\ntext(0.55,1.05,'FMMC optimal weights')\n\nfigure(3), clf\nplotgraph(A,xy,w_md);\ntext(0.5,1.05,'Max degree optimal weights')\n\nfigure(4), clf\nplotgraph(A,xy,w_bc);\ntext(0.5,1.05,'Best constant optimal weights')\n\nfigure(5), clf\nplotgraph(A,xy,w_mh);\ntext(0.46,1.05,'Metropolis-Hastings optimal weights')\n", "meta": {"author": "cvxr", "repo": "CVX", "sha": "a7b46e7840c3ccf3f35df374d2ff3da4eaafc3cd", "save_path": "github-repos/MATLAB/cvxr-CVX", "path": "github-repos/MATLAB/cvxr-CVX/CVX-a7b46e7840c3ccf3f35df374d2ff3da4eaafc3cd/examples/graph_laplacian/small_example.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436395, "lm_q2_score": 0.8333245891029456, "lm_q1q2_score": 0.741904075015156}} {"text": "function value = monomial_value ( dim_num, point_num, x, expon )\n\n%*****************************************************************************80\n%\n%% MONOMIAL_VALUE evaluates a monomial.\n%\n% Discussion:\n%\n% This routine evaluates a monomial of the form\n%\n% product ( 1 <= dim <= dim_num ) x(dim)^expon(dim)\n%\n% where the exponents are nonnegative integers. Note that\n% if the combination 0^0 is encountered, it should be treated\n% as 1.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 26 August 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer DIM_NUM, the spatial dimension.\n%\n% Input, integer POINT_NUM, the number of points at which the\n% monomial is to be evaluated.\n%\n% Input, real X(DIM_NUM,POINT_NUM), the point coordinates.\n%\n% Input, integer EXPON(DIM_NUM), the exponents.\n%\n% Output, real VALUE(POINT_NUM), the value of the monomial.\n%\n value(1,1:point_num) = 1.0;\n \n for dim = 1 : dim_num\n if ( 0 ~= expon(dim) )\n value(1,1:point_num) = value(1,1:point_num) .* ( x(dim,1:point_num).^expon(dim) );\n end\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/sandia_sparse/monomial_value.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267898240861, "lm_q2_score": 0.8539127566694178, "lm_q1q2_score": 0.7419022791669262}} {"text": "function y = sqrt_cordic ( x, n )\n\n%*****************************************************************************80\n%\n%% SQRT_CORDIC returns the square root of a value using the CORDIC method.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 21 June 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real X, the number whose square root is desired.\n%\n% Input, integer N, the number of iterations to take.\n% This is essentially the number of binary digits of accuracy.\n%\n% Output, real Y, the approximate square root of X.\n%\n if ( x < 0.0 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'SQRT_CORDIC - Fatal error!\\n' );\n fprintf ( 1, ' X < 0.\\n' );\n error ( 'SQRT_CORDIC - Fatal error!' )\n end\n\n if ( x == 0.0 )\n y = 0.0;\n return\n end\n\n if ( x == 1.0 )\n y = 1.0;\n return\n end\n\n poweroftwo = 1.0;\n\n if ( x < 1.0 )\n\n while ( x <= poweroftwo * poweroftwo )\n poweroftwo = poweroftwo / 2.0;\n end\n\n y = poweroftwo;\n\n elseif ( 1.0 < x )\n\n while ( poweroftwo * poweroftwo <= x )\n poweroftwo = 2.0 * poweroftwo;\n end\n\n y = poweroftwo / 2.0;\n\n end\n\n for i = 1 : n\n poweroftwo = poweroftwo / 2.0;\n if ( ( y + poweroftwo ) * ( y + poweroftwo ) <= x )\n y = y + poweroftwo;\n end\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/cordic/sqrt_cordic.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267830311355, "lm_q2_score": 0.8539127529517043, "lm_q1q2_score": 0.74190227013629}} {"text": "function h = compute_histogram_rbf(f, sigma, x, options)\n\n% compute_histogram_rbf - parzen windows density estimation\n%\n% h = compute_histogram_rbf(f, sigma, x);\n%\n% f is the signal, h is an estimate of the histogram, \n% where h(i) is the density of the estimation around value x(i).\n%\n% sigma is the bandwidth used to estimate the histogram (approx. size of\n% the bins).\n%\n% If f is (n,2) matrix, then a joint histogram is estimated.\n%\n% Copyright (c) 2007 Gabriel Peyre\n\noptions.null = 0;\n \n\nif size(f,1)nb_max\n h = zeros(n);\n niter = ceil(p/nb_max);\n for i=1:niter\n progressbar(i,niter);\n sel = (i-1)*nb_max+1:min(i*nb_max,p);\n h = h + compute_histogram_rbf_2d( f(sel,:) , sigma, x, options);\n end\n h = h/sum(h(:));\n return;\nend\n\n% hx is of size p x n x n\nhx = repmat( f(:,1), [1 n n]) - repmat( reshape(x(:,1),[1 n 1]),[p 1 n] );\nhy = repmat( f(:,2), [1 n n]) - repmat( reshape(x(:,2),[1 1 n]),[p n 1] );\nh = exp( -(hx.^2/(2*sigma(1)^2)+hy.^2/(2*sigma(2)^2)) );\nif renormalize\n d = repmat( sum(sum(h,2),3), [1 n n] );\n d(d= 1 - eps \n k = k - 1;\n log_sum_Pr = my_logsumexp([log_sum_Pr log_b{n+1}(k+1)+(n-k)*log(3)+log_Pr(k+1)]); \n end\n d = 1 - eps - (exp(log_sum_Pr) - exp(log_b{n+1}(k+1)+(n-k)*log(3)+log_Pr(k+1))); \n M1 = my_logsumexp(log_b{n+1}(k+2:n+1)+(n-(k+1:n))*log(3));\n M2 = log(d) - log_Pr(k+1);\n R(i) = 1/n*my_logsumexp([M1 M2]);\n end\nend\n\n", "meta": {"author": "yp-mit", "repo": "spectre", "sha": "57af76799e4eb43aa707cc13c4c5220d281e0b78", "save_path": "github-repos/MATLAB/yp-mit-spectre", "path": "github-repos/MATLAB/yp-mit-spectre/spectre-57af76799e4eb43aa707cc13c4c5220d281e0b78/lossless-sc/p2p_optimum.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403999037784, "lm_q2_score": 0.7981867801399695, "lm_q1q2_score": 0.7418670401312024}} {"text": "% Get the freq. and amp. parameters of a spectral peak by quandratic fitting\n%\n% Octave compatible\n% \n% Inputs\n% S : The spectrum containing the peak to fit\n% fs : [Hz] The sampling frequency\n% index : The peak position where the parabola has to be fit\n% [zp] : the zero padding factor used for the DFT computation\n% (used for the Abe & Smith corrections)\n% [wintype]: The window type used for the DFT computation\n% wintype=2 => Hann\n%\n% Outputs\n% freq : [Hz] The frequency parameter\n% amp : The amplitude parameter (linear scale)\n%\n% Copyright (c) 2012 University of Crete - Computer Science Department\n% \n% License\n% This file is under the LGPL license, you can\n% redistribute it and/or modify it under the terms of the GNU Lesser General \n% Public License as published by the Free Software Foundation, either version 3 \n% of the License, or (at your option) any later version. This file is\n% distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; \n% without even the implied warranty of MERCHANTABILITY or FITNESS FOR A \n% PARTICULAR PURPOSE. See the GNU Lesser General Public License for more\n% details.\n%\n% This function is part of the Covarep project: http://covarep.github.io/covarep\n%\n% Author\n% Gilles Degottex \n%\n\nfunction [freq amp p] = spec_fit_freq_amp(S, fs, index, zp, wintype)\n\n if index<=1\n freq = index;\n amp = log(abs(S(1)));\n return\n elseif index>=length(S)\n freq = index;\n amp = log(abs(S(end)));\n return\n end\n\n % fit a parabola in log amplitudes\n y1 = log(abs(S(index-1)));\n y2 = log(abs(S(index)));\n y3 = log(abs(S(index+1)));\n A = (y3-y2)/2 + (y1-y2)/2;\n B = -( y1 - y2 - A );\n C = y1 - A + B;\n p = [A B C];\n\n % max abscissa\n di = -p(2)/(2*p(1));\n\n % max amplitude\n logamp = p(1)*di*di + p(2)*di + p(3);\n\n if nargin>3 && ~isempty(zp)\n % Use Abe & Smith corrections\n if wintype==2;\n c0=0.247560; c1=0.084372; c2=-0.090608; c3=-0.055781; % Hann\n else\n error('Unknown correction terms for the given window for Abe&Smith corrections');\n end\n delta = di;\n\n % Frequency correction\n ksi = c0*zp^(-2) + c1*zp^(-4); % (3)\n di = delta + ksi*(delta-0.5)*(delta+0.5)*delta; % (1)\n\n % Amplitude correction\n ita = c2*zp^(-4) + c3*zp^(-6); % (4)\n logamp = logamp + ita*di^2; % (2)\n end\n\n freq = index + di;\n freq = (freq-1)*(fs/length(S));\n\n amp = exp(logamp);\nreturn\n\n", "meta": {"author": "covarep", "repo": "covarep", "sha": "5a2be5d6b776f14a0b275c69fde90eb13849e60d", "save_path": "github-repos/MATLAB/covarep-covarep", "path": "github-repos/MATLAB/covarep-covarep/covarep-5a2be5d6b776f14a0b275c69fde90eb13849e60d/sinusoidal/private/spec_fit_freq_amp.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403999037782, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.7418670334382603}} {"text": "% MAIN.m -- Lesson 1 -- Simple Plot\n%\n% This script performs a simulation of the cart as it passively moves from\n% some initial state.\n%\n% The purpose of this lesson is to learn how use ode45 to generate data for\n% a simulation, and then plot the state of the system to see what is going\n% on.\n%\n\nclc; clear;\n\n%%%% Initial State\nz0 = [\n 0.0; %horizontal position\n (pi/180)*80; %pendulum angle (wrt gravity)\n 0.3; %horizontal velocity\n 0.5]; %pendulum angular rate\n\n%%%% Physical Parameters\np.m1 = 1.0; % (kg) Cart mass\np.m2 = 0.3; % (kg) pole mass\np.g = 9.81; % (m/s^2) gravity \np.l = 0.5; % (m) pendulum (pole) length \n\n%%%% Time vector\nt = linspace(0,2,250); %Simulation time stamps\n\n%%%% Function Handle\ndynFun = @(t,z)( cartPoleDynamics(z, p) );\n\n%%%% Simulate the system!\noptions = odeset(...\n 'RelTol',1e-8, ...\n 'AbsTol',1e-8);\n[~, z] = ode45(dynFun, t, z0, options); % <-- This is the key line!\nz = z';\n\n%%%% Unpack the state:\nx = z(1,:);\nq = z(2,:);\ndx = z(3,:);\ndq = z(4,:);\n\n%%%% Plots:\nfigure(1); clf;\n\nsubplot(2,2,1);\nplot(t,x)\nylabel('x')\ntitle('Position')\n\nsubplot(2,2,2);\nplot(t,q)\nylabel('q')\ntitle('Angle')\n\nsubplot(2,2,3);\nplot(t,dx)\nylabel('dx')\ntitle('Velocity')\n\nsubplot(2,2,4);\nplot(t,dq)\nylabel('dq')\ntitle('Angle Rate')\n\n\n\n\n", "meta": {"author": "MatthewPeterKelly", "repo": "dscTutorials", "sha": "e1e97a9be03ec146f88bd6ddd9e06db7ee52e242", "save_path": "github-repos/MATLAB/MatthewPeterKelly-dscTutorials", "path": "github-repos/MATLAB/MatthewPeterKelly-dscTutorials/dscTutorials-e1e97a9be03ec146f88bd6ddd9e06db7ee52e242/MatlabAnimationTutorial/1_simple_plot/MAIN.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465080392797, "lm_q2_score": 0.7931059536292271, "lm_q1q2_score": 0.7418288842322605}} {"text": "\n\nclear all; close all;\nI=imread('rice.png'); \nI=im2double(I); \t\t\nM=2*size(I,1);\nN=2*size(I,2);\nu=-M/2:(M/2-1);\nv=-N/2:(N/2-1);\n[U,V]=meshgrid(u, v);\nD=sqrt(U.^2+V.^2);\nD0=30;\nn=6;\nH=1./(1+(D0./D).^(2*n));\nJ=fftshift(fft2(I, size(H, 1), size(H, 2))); \nK=J.*H;\nL=ifft2(ifftshift(K));\nL=L(1:size(I,1), 1:size(I, 2));\nfigure;\nsubplot(121);\nimshow(I);\nsubplot(122);\nimshow(L);\n\n", "meta": {"author": "HuangCongQing", "repo": "Algorithms_MathModels", "sha": "e15b0e9053b11f08b5ce1e3492c4acb444409c8b", "save_path": "github-repos/MATLAB/HuangCongQing-Algorithms_MathModels", "path": "github-repos/MATLAB/HuangCongQing-Algorithms_MathModels/Algorithms_MathModels-e15b0e9053b11f08b5ce1e3492c4acb444409c8b/\u300aMATLAB\u56fe\u50cf\u5904\u7406\u300b\u6e90\u6587\u4ef6/\u672c\u4e66\u6e90\u6587\u4ef6/chap5/chap5_27.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465062370313, "lm_q2_score": 0.7931059511841119, "lm_q1q2_score": 0.7418288805158565}} {"text": "function determ = chow_determinant ( alpha, beta, n )\n\n%*****************************************************************************80\n%\n%% CHOW_DETERMINANT returns the determinant of the CHOW matrix.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 25 October 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real ALPHA, the ALPHA value. A typical value is 1.0.\n%\n% Input, real BETA, the BETA value. A typical value is 0.0.\n%\n% Input, integer N, the order of A.\n%\n% Output, real DETERM, the determinant.\n%\n determ = 1.0;\n\n k = n - floor ( n / 2 );\n\n for i = 1 : k\n angle = i * pi / ( n + 2 );\n determ = determ * ( beta + 4.0 * alpha * ( cos ( angle ) )^2 );\n end\n\n determ = determ * beta^( n - k );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_mat/chow_determinant.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8856314858927012, "lm_q2_score": 0.8376199653600372, "lm_q1q2_score": 0.7418226145352027}} {"text": "%% Simulating Pole Figure data\n%\n%%\n% Simulating pole figure data from a given ODF is useful to investigate\n% pole figure to ODF reconstruction routines. Let us start with a model ODF\n% given as the superposition of 6 components.\n\ncs = crystalSymmetry('orthorhombic');\nmod1 = orientation.byAxisAngle(xvector,45*degree,cs);\nmod2 = orientation.byAxisAngle(yvector,65*degree,cs);\nmodel_odf = 0.5*uniformODF(cs) + ...\n 0.05*fibreODF(Miller(1,0,0,cs),xvector,'halfwidth',10*degree) + ...\n 0.05*fibreODF(Miller(0,1,0,cs),yvector,'halfwidth',10*degree) + ...\n 0.05*fibreODF(Miller(0,0,1,cs),zvector,'halfwidth',10*degree) + ...\n 0.05*unimodalODF(mod1,'halfwidth',15*degree) + ...\n 0.3*unimodalODF(mod2,'halfwidth',25*degree);\n\n%%\n\nplot(model_odf,'sections',6,'silent','sigma')\n\n%%\n% In order to simulate pole figure data, the following parameters have to be\n% specified\n%\n% # an arbitrary \n% # a list of \n% # a grid of \n% # superposition coefficients (optional)\n% # the magnitude of error (optional)\n%\n%%\n% The list of \n\nh = [Miller(1,1,1,cs),Miller(1,1,0,cs),Miller(1,0,1,cs),Miller(0,1,1,cs),...\n Miller(1,0,0,cs),Miller(0,1,0,cs),Miller(0,0,1,cs)];\n\n%%\n% The of specimen directions\n\nr = regularS2Grid('resolution',5*degree);\n\n%%\n% Now the pole figures can be simulated using the command\n% . \n\npf = calcPoleFigure(model_odf,h,r)\n\n%%\n% Add some noise to the data. Here we assume that the mean intensity is 1000.\n\npf = noisepf(pf,1000);\n\n%%\n% Plot the simulated pole figures.\n\nplot(pf)\n\n\n%% ODF Estimation from Pole Figure Data\n%\n% From these simulated pole figures we can now estimate an ODF,\n\nodf = calcODF(pf)\n\n\n%%\n% which can be plotted,\n\nplot(odf,'sections',6,'silent','sigma')\n\n\n%%\n% and compared to the original model ODF.\n\ncalcError(odf,model_odf,'resolution',5*degree)\n\n\n%% Exploration of the relationship between estimation error and number of pole figures\n%\n% For a more systematic analysis of the estimation error, we vary the number\n% of pole figures used for ODF estimation from 1 to 7 and calculate for any\n% number of pole figures the approximation error. Furthermore, we also\n% apply ghost correction and compare the approximation error to the\n% previous reconstructions.\n\ne = [];\nfor i = 1:pf.numPF\n\n odf = calcODF(pf({1:i}),'silent','NoGhostCorrection');\n e(i,1) = calcError(odf,model_odf,'resolution',2.5*degree);\n odf = calcODF(pf({1:i}),'silent');\n e(i,2) = calcError(odf,model_odf,'resolution',2.5*degree);\n\nend\n\n%% \n% Plot the error in dependency of the number of single orientations.\n\nclose all;\nplot(1:pf.numPF,e,'LineWidth',2)\nylim([0.07 0.32])\nxlabel('Number of Pole Figures');\nylabel('Reconstruction Error');\nlegend({'Without Ghost Correction','With Ghost Correction'});\n", "meta": {"author": "mtex-toolbox", "repo": "mtex", "sha": "f0ce46a720935e9ae8106ef919340534bca1adcb", "save_path": "github-repos/MATLAB/mtex-toolbox-mtex", "path": "github-repos/MATLAB/mtex-toolbox-mtex/mtex-f0ce46a720935e9ae8106ef919340534bca1adcb/doc/PoleFigureAnalysis/PoleFigureSimulation.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314828740729, "lm_q2_score": 0.8376199633332891, "lm_q1q2_score": 0.7418226102117874}} {"text": "%% Generate an Airy Pattern and add noise.\nN=65;\nxrange=[-1 1];\nx=linspace(xrange(1),xrange(2),N);\n[xx, yy]=meshgrid(x);\n[theta, rr]=cart2pol(xx,yy);\nAiryPattern=jinc(rr).^2;\nAiryPattern=uint16((2^10-1)*AiryPattern);\nNoisyPattern=imnoise(AiryPattern,'poisson');\n\n%% Filter and Interpolate.\nxs=x(2)-x(1);\nfcut=2; % The Fourier transform of the Airy Pattern (chinese hat) cuts-off at 2 in frequency domain.\n%gaussorder=500;\nAiryFiltI1=opticalLowpassInterpolation(AiryPattern,xs,fcut,1);\nAiryFiltI2=opticalLowpassInterpolation(AiryPattern,xs,fcut,2);\nAiryFiltI3=opticalLowpassInterpolation(AiryPattern,xs,fcut,3);\nNoisyFiltI1=opticalLowpassInterpolation(NoisyPattern,xs,fcut,1);\nNoisyFiltI2=opticalLowpassInterpolation(NoisyPattern,xs,fcut,2);\nNoisyFiltI3=opticalLowpassInterpolation(NoisyPattern,xs,fcut,3);\nfigure(1); clf; colormap jet;\nset(1,'defaultaxesfontsize',16);\nimagecat(x,x,AiryPattern,AiryFiltI1,AiryFiltI2,AiryFiltI3,NoisyPattern,NoisyFiltI1,NoisyFiltI2,NoisyFiltI3,'link','equal');\n\n%% Compare line profiles along X.\n\n% Function handles to extract the midprofile and generate xaxis.\nxprof=@(img) img(floor(0.5*size(img,1))+1,:);\nxaxis=@(img,xrange) linspace(xrange(1),xrange(2),size(img,2));\n\n% Profiles from airy pattern.\nAiryProfiles=cellfun(@(img) xprof(img),...\n {AiryPattern,AiryFiltI1,AiryFiltI2,AiryFiltI3},...\n 'UniformOutput',false);\nAiryAxis=cellfun(@(img) xaxis(img,xrange),...\n {AiryPattern,AiryFiltI1,AiryFiltI2,AiryFiltI3},...\n 'UniformOutput',false);\n\n% Profiles from noisy pattern.\nNoisyProfiles=cellfun(@(img) xprof(img),...\n {NoisyPattern,NoisyFiltI1,NoisyFiltI2,NoisyFiltI3},...\n 'UniformOutput',false);\nNoisyAxis=cellfun(@(img) xaxis(img,xrange),...\n {NoisyPattern,NoisyFiltI1,NoisyFiltI2,NoisyFiltI3},...\n 'UniformOutput',false);\n\n\nfigure(2); clf; set(2,'defaultaxesfontsize',16);\nplot(AiryAxis{1},AiryProfiles{1},AiryAxis{2},AiryProfiles{2},...\n AiryAxis{3},AiryProfiles{3},AiryAxis{4},AiryProfiles{4},...\n 'LineWidth',2);\nlegend('Airy','AiryFiltInterpolation1','AiryFiltInterpolation2','AiryFiltInterpolation3');\n\nsnapnow;\n\nfigure(3); clf; set(3,'defaultaxesfontsize',16);\nplot(NoisyAxis{1},NoisyProfiles{1},NoisyAxis{2},NoisyProfiles{2},...\n NoisyAxis{3},NoisyProfiles{3},NoisyAxis{4},NoisyProfiles{4},...\n 'LineWidth',2);\nlegend('Noisy','NoisyFiltInterpolation1','NoisyFiltInterpolation2','NoisyFiltInterpolation3');\nsnapnow;", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/40207-filter-noise-and-interpolate-microscopy-images-in-frequency-domain/opticalLowPassInterpolation27Feb2013/ImageProcessing/TestBench_opticalLowpassInterpolation_Airy.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896715436483, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.7418178008255719}} {"text": "clearvars;\nclose all;\n% clc;\n\nrng default;\n\nM = 300;\nN = 1000;\nK = 60;\n\nA = randn(M, N);\nx0 = zeros(N,1);\n\npermutation = randperm(N);\nindices = permutation(1:K);\n% non-zero entries\nx0(indices) = randn(K,1);\n\nb0 = A * x0;\n% noise variance\nsigma = 0.1;\ne = sigma * randn(M, 1);\n% add noise\nb = b0 + e;\n\n% orthonormalize the rows of A\n% perform QR decomposition of rows of A\n[Q, R] = qr(A', 0);\n% keep the orthogonal rows\nA = Q';\n% change b accordingly to the new coordinates\nb = R'\\b;\n\noptions.verbose = 0;\noptions.max_iterations = 200;\noptions.tolerance = 5e-3;\nsolver = spx.pursuit.single.L1_ADMM_YZ(A, options);\nmu = sigma;\nx = solver.solve_bpdn_l2(b, mu);\n\nr = x - x0;\nmax_diff = max(abs(r));\nrel_error = norm(x-x0) /norm(x0);\niterations = solver.details.iterations(1);\nelapsed_time = solver.details.elapsed_times(1);\nfprintf('Iterations: %d, Relative error: %e, max diff: %.4f, time: %.4f seconds\\n', ...\n iterations, rel_error, max_diff, elapsed_time);\n\nprint = 1;\nif print\n subplot(211);\n stem(x0, '.');\n subplot(212);\n stem(x, '.');\n figure;\n iterations = solver.details.iterations(1);\n iters = 1:iterations;\n primal_objectives = solver.details.primal_objectives(iters, 1);\n dual_objectives = solver.details.dual_objectives(iters, 1);\n plot(iters, primal_objectives);\n hold on;\n plot(iters, dual_objectives);\n xlabel('Iterations');\n ylabel('Objective Value');\n legend({'Primal Objective', 'Dual Objective'});\n grid on;\nend\n\ncvx = 0;\nif cvx\n% time to compare with a CVX implementation\ncvx_solver = spx.pursuit.single.BasisPursuit(A, b);\ntstart = tic;\nx = cvx_solver.solve_lasso(1/(2*mu));\nelapsed_time = toc(tstart);\nr = x - x0;\nmax_diff = max(abs(r));\nrel_error = norm(x-x0) /norm(x0);\nfprintf('Relative error: %e, max diff: %.4f, time: %.4f seconds\\n', ...\n rel_error, max_diff, elapsed_time);\nend", "meta": {"author": "indigits", "repo": "sparse-plex", "sha": "43cae2978f62938d001baaa03308a2a717ee6c9b", "save_path": "github-repos/MATLAB/indigits-sparse-plex", "path": "github-repos/MATLAB/indigits-sparse-plex/sparse-plex-43cae2978f62938d001baaa03308a2a717ee6c9b/experiments/admm/basis_pursuit/test_bpdn_admm_gaussian_dict.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896671963207, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.7418177973232248}} {"text": "function result=mcdregres(x,y,varargin)\n\n%MCDREGRES is a robust multivariate regression method. It can handle multiple\n% response variables. The estimates are based on the robust MCD estimator of \n% location and scatter (see mcdcov.m). The explanatory variables should be \n% low-dimensional, otherwise robust principal component regression (rpcr.m) \n% or robust partial least squares (rsimpls.m) should be applied.\n%\n% The MCD regression method is described in \n% Rousseeuw, P.J., Van Aelst, S., Van Driessen, K, Agullo, J. (2004),\n% \"Robust multivariate regression\", Technometrics, 46, pp 293-305.\n%\n% Required input arguments:\n% x : Data matrix of the explanatory variables\n% (n observations in rows, p variables in columns)\n% y : Data matrix of the response variables\n% (n observations in rows, q variables in columns)\n%\n% Optional input arguments: \n% alpha : (1-alpha) measures the amount of contamination the algorithm should \n% resist. Any value between 0.5 and 1 may be specified. (default = 0.75)\n% h : The quantile of observations whose covariance determinant will \n% be minimized. Any value between n/2 and n may be specified.\n% The default value is 0.75*n.\n% ntrial : The number of random trial subsamples that are drawn for \n% large datasets. (default = 500)\n% plots : If equal to one, a menu is shown which allows to draw a regression\n% outlier map. (default)\n% If the input argument 'classic' is equal to one, the classical\n% plot is drawn as well.\n% If 'plots' is equal to zero, all plots are suppressed.\n% See also makeplot.m\n% classic : If equal to one, classical multivariate linear regression \n% is performed as well, see mlr.m. (default = 0)\n%\n% Input arguments for advanced users:\n% Hsets : Instead of random trial h-subsets (default, Hsets = []), Hsets makes it possible to give certain\n% h-subsets as input. Hsets is a matrix that contains the indices of the observations of one\n% h-subset as a row.\n%\n% I/O: result=mcdregres(x,y,'alpha',0.75,'ntrial',500,'plots',1,'classic',0);\n% The user should only give the input arguments that have to change their default value.\n% The name of the input arguments needs to be followed by their value.\n% The order of the input arguments is of no importance.\n% \n% Example: result=mcdregres(x,y,'plots',0,'alpha',0.70)\n%\n% The output is a structure which contains\n% result.slope : Robust slope (matrix)\n% result.int : Robust intercept (vector)\n% result.fitted : Robust prediction matrix\n% result.res : Robust residuals\n% result.cov : Estimated variance-covariance matrix of the residuals \n% result.rsquared : Robust R-squared value\n% result.h : The quantile h used throughout the algorithm\n% result.Hsubsets : A structure that contains Hopt and Hfreq:\n% Hopt : The subset of h points whose covariance matrix has minimal determinant, \n% ordered following increasing robust distances.\n% Hfreq : The subset of h points which are the most frequently selected during the whole\n% algorithm.\n% result.rd : Robust scores distances in x-space\n% result.resd : Residual distances (when there are several response variables).\n% If univariate regression is performed, it contains the standardized residuals.\n% result.cutoff : Cutoff values for the score and residual distances\n% result.weights : The observations with weight one are used in the reweighting, \n% the other observations have zero weight.\n% result.flag : The observations whose residual distance is larger than result.cutoff.resd\n% (bad leverage points/vertical outliers) can be considered as outliers and receive \n% a flag equal to zero.\n% The regular observations, including the good leverage points, \n% receive a flag 1.\n% result.class : 'MCDREG'\n% result.classic : If the input argument 'classic' is equal to one, this structure\n% contains results of classical multivariate regression (see also mlr.m). \n%\n% This function is part of LIBRA: the Matlab Library for Robust Analysis,\n% available at: \n% http://wis.kuleuven.be/stat/robust.html\n%\n% Original S-PLUS code by Katrien Vandriessen, implemented in MATLAB by Sabine Verboven \n% Version date : 12/02/2004\n% Last update: 04/08/2006\n\n%%%%%%%%%%%%%%%%\n% INITIALIZATION\n%\nintercept=ones(length(x),1);\ngeg=[x,y];\n[n,m]=size(geg);\nalfa=0.75;\nhdefault=min(floor(2*floor((n+m+1)/2)-n+2*(n-floor((n+m+1)/2))*alfa),n);\n\nif nargin < 3\n options.alpha=alfa;\n options.h=hdefault;\n options.ntrial=500;\n options.plots=1;\n options.classic=0;\n options.Hsets=[];\nelse\n default=struct('alpha',alfa,'h',hdefault,'ntrial',500,'plots',1,'classic',0,'Hsets',[]);\n list=fieldnames(default);\n options=default;\n IN=length(list);\n i=1; \n counter=1;\n % \n if nargin>2\n %\n %placing inputfields in array of strings\n %\n for j=1:nargin-2\n if rem(j,2)~=0\n chklist{i}=varargin{j};\n i=i+1;\n end\n end \n dummy=sum(strcmp(chklist,'h')+2*strcmp(chklist,'alpha'));\n switch dummy\n case 0 %no input for alpha or h so take on the default values \n options.alpha=0.75;\n options.h=floor(options.alpha*n);\n case 3\n error('Both input arguments alpha and h are provided. Only one is required.')\n end\n %\n %Checking which default parameters have to be changed\n % and keep them in the structure 'options'.\n %\n while counter<=IN \n index=strmatch(list(counter,:),chklist,'exact');\n if ~isempty(index) %in case of similarity\n for j=1:nargin-2 %searching the index of the accompanying field\n if rem(j,2)~=0 %fieldnames are placed on odd index\n if strcmp(chklist{index},varargin{j})\n I=j;\n end\n end\n end\n options=setfield(options,chklist{index},varargin{I+1});\n index=[];\n end\n counter=counter+1;\n end\n if dummy==1\n options.alpha=options.h/n;\n elseif dummy==2\n options.h=floor(options.alpha*n);\n end\n Hsets = options.Hsets;\n end\nend\n%%%%%%%%\n% MAIN %\n[mcd_res, mcd_raw]=mcdcov(geg,'h',options.h,'plots',0,'Hsets',options.Hsets);\noptions.h = mcd_res.h;\n\n%in case of an exact fit, the calculations stop at this point.\nif ~isempty(mcd_res.plane)\n disp('Warning (mcdregres): The MCD covariance matrix is singular. See also mcdcov.m.')\n result=mcd_res;\n return\nend\n\nmcdreg.Hsubsets.Hopt = mcd_res.Hsubsets.Hopt;\nmcdreg.Hsubsets.Hfreq = mcd_res.Hsubsets.Hfreq;\n\nrewcovmcd=mcd_res.cov; %one-step reweighted covariance matrix\nrewcenmcd=mcd_res.center; %one-step reweighted location\nq=size(y,2);\np=size(x,2);\n\n%initializing reweighted location and reweighted scatter (paragraph 5.1 of paper)\nrewtmcdx=rewcenmcd(1:p)'; %column vectors!!!\nrewtmcdy=rewcenmcd((p+1):m)';\n\nrewsmcdx=rewcovmcd(1:p,1:p);\nrewsmcdxy=rewcovmcd(1:p,(p+1):m);\nrewsmcdyx=rewsmcdxy';\nrewsmcdy=rewcovmcd((p+1):m,(p+1):m);\n\ncovyy=rewsmcdy;\ncovxx = rewsmcdx;\ncovxy = rewsmcdxy;\ncovyx = rewsmcdyx;\nmcdreg.Sigma = [covxx, covxy ; covyx, covyy];\nmcdreg.Mu = [rewtmcdx;rewtmcdy];\n\n%reweighted beta and alpha (the columnvector [\\beta^L ; \\alpha^L])\nrewbetamcd=[inv(rewsmcdx)*rewsmcdxy; (rewtmcdy-(rewsmcdyx*inv(rewsmcdx)*rewtmcdx))'];\n\n%calculation of the reweighted weights based on \n%the residuals calculated with the reweighted beta-coefficients \nrewweights=zeros(n,1);\nweights=zeros(n,1);\nrewfitted=[x,intercept]*rewbetamcd(1:(p+1),:);\nrewresid=y-rewfitted; %(r_i^L)\nrewE=rewsmcdy-rewbetamcd(1:p,1:q)'*rewsmcdx*rewbetamcd(1:p,1:q); %reweighted scatter (\\Sigma_eps^L)\nfor j=1:n\n if (sqrt(rewresid(j,1:q)*inv(rewE)*rewresid(j,1:q)')) <= sqrt(chi2inv(0.99,q))\n rewweights(j)=1;\n end\nend\n\n%regression reweighting part based on the reweighted observations. (paragraph 5.3 of paper)\nrewclasscov=cov(geg(rewweights==1,:));\nrewclasscenter=mean(geg(rewweights==1,:));\n\nrewtmcdx=rewclasscenter(1:p)';\nrewtmcdy=rewclasscenter((p+1):m)';\n\nrewsmcdx=rewclasscov(1:p,1:p);\nrewsmcdxy=rewclasscov(1:p,(p+1):m);\nrewsmcdyx=rewsmcdxy';\nrewsmcdy=rewclasscov((p+1):m,(p+1):m);\n\n%regression reweighted coefficients beta and alpha ([\\beta^{RL} \\alpha^{RL}])\nrewbetamcdrew=[inv(rewsmcdx)*rewsmcdxy; (rewtmcdy-(rewsmcdyx*inv(rewsmcdx)*rewtmcdx))'];\n%regression reweighted scatter (\\Sigma_eps^{RL}])\nrewE2=rewsmcdy-rewbetamcdrew(1:p,1:q)'*rewsmcdx*rewbetamcdrew(1:p,1:q);\nrewfittedrew=[x,intercept]*rewbetamcdrew(1:(p+1),:);\nrewresidrew=y-rewfittedrew;\n\n%%%%%%%%%%%%%%%%%\n%OUTPUT STRUCTURE\n%\nmcdreg.covyy=rewsmcdy; %regression and location reweighted covariance matrix of responses\nmcdreg.covxx = rewsmcdx;\nmcdreg.covxy = rewsmcdxy;\nmcdreg.covyx = rewsmcdyx;\nmcdreg.Sigmarew = [mcdreg.covxx, mcdreg.covxy ; mcdreg.covyx, mcdreg.covyy];\nmcdreg.Murew = [rewtmcdx;rewtmcdy];\n\nmcdreg.x=x;\nmcdreg.y=y;\nmcdreg.coeffs=rewbetamcdrew; %regression and location reweighted coefficients\nmcdreg.cov=rewE2; %scatter matrix based on location and regression reweighting\nmcdreg.fitted=rewfittedrew; %estimated respons(es);\nmcdreg.res=rewresidrew; %regression and location reweighted residuals\n\nif(intercept)\n mcdreg.interc=1;\nelse\n mcdreg.interc=0;\nend\n\n% Robust distances in x-space = x-distances (rd) needed in diagnostic regression plot\nif (-log(det(mcd_res.cov))/m) > 50\n mcdreg.rd='singularity';\nelse\n mcdreg.rd=sqrt(libra_mahalanobis(mcdreg.x,rewcenmcd(1:p),'cov',rewcovmcd(1:p,1:p)))';\nend\n\n% Robust residual distances (resd) needed in diagnostic regression plot \nif q>1\n if (-log(det(mcd_res.cov))/m)>50\n mcdreg.resd='singularity';\n disp('Warning (mcdregres): A singularity ')\n else\n cen=zeros(q,1)';\n [nn,pp]=size(rewresidrew);\n mcdreg.resd=sqrt(libra_mahalanobis(rewresidrew,cen,'cov',mcdreg.cov))'; %robust distances of residuals\n end\nelse\n mcdreg.covarRes=sqrt(mcdreg.cov);\n mcdreg.resd=rewresidrew(:,1)/mcdreg.covarRes; %standardized residuals \nend\n\n% cutoff values \nmcdreg.cutoff.rd=sqrt(chi2inv(0.975,p)); \nmcdreg.cutoff.resd=sqrt(chi2inv(0.975,q));\nmcdreg.flag=(abs(mcdreg.resd)<=mcdreg.cutoff.resd);\n\n% robust multivariate Rsquared\nmcdreg.weights=rewweights;\nYw=y(mcdreg.weights==1,:);\ncYw=mcenter(Yw);\nres=rewresidrew(mcdreg.weights==1,:);\nmcdreg.rsquared=1-(det(res'*res)/det(cYw'*cYw));\nmcdreg.class='MCDREG';\n\n\nif options.classic\n mcdreg.classic=mlr(x,y,'plots',0);\nelse\n mcdreg.classic=0;\nend\n\nresult=struct('slope',{mcdreg.coeffs(1:p,:)}, 'int',{mcdreg.coeffs(p+1,:)}, ...\n 'fitted',{mcdreg.fitted},'res',{mcdreg.res},'cov',{mcdreg.cov},'rsquared',{mcdreg.rsquared},...\n 'h',{options.h},'Hsubsets',{mcdreg.Hsubsets},'rd', {mcdreg.rd},'resd',{mcdreg.resd},'cutoff',{mcdreg.cutoff},...\n 'weights',{mcdreg.weights},'flag',{mcdreg.flag'},'class',{mcdreg.class},'classic',{mcdreg.classic},...\n 'Mu',{mcdreg.Mu},'Sigma',{mcdreg.Sigma},'Murew',{mcdreg.Murew},'Sigmarew',{mcdreg.Sigmarew});\n\ntry\n if options.plots & options.classic\n makeplot(result,'classic',1)\n elseif options.plots\n makeplot(result) \n end\ncatch %output must be given even if plots are interrupted \n %> delete(gcf) to get rid of the menu \nend", "meta": {"author": "marianux", "repo": "ecg-kit", "sha": "c8e3de47c54a9214138143676d2aa546b0540dd2", "save_path": "github-repos/MATLAB/marianux-ecg-kit", "path": "github-repos/MATLAB/marianux-ecg-kit/ecg-kit-c8e3de47c54a9214138143676d2aa546b0540dd2/common/LIBRA/mcdregres.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896715436483, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.7418177922314463}} {"text": "% Wrapper around Matlab's histc function with some modifications\n%\n% This function assigns each input value a bin number according to specified\n% limits of values and width of each bin.\n% Vector of bin edges is created out of specified limits and bin width. Value\n% x(i) is assigned to bin k if edges(k) <= x(i) < edges(k+1). So far this is\n% exactly what Matlab's function histc does. The difference comes in the last bin.\n% Condition of assignment for the last bin is edges(end-1) <= x(i) <= edges(end).\n%\n% USAGE\n% [bins, nBins, edges] = helpers.bin(x, limits, binWidth)\n% x 1D vector of values that should be binned.\n% limits [min_x max_x] limit values that define bins. These need not be equal to\n% min(x) and max(x). Values of x that equal to min_x or max_x are all\n% included in the final histogram.\n% binWidth width of each individual bin. Used to create edges vector.\n% bins Vector of assigned bin numbers to x. length(bins) == length(x).\n% Values outside of limits are assigned to NaN.\n% nBins Number of bins.\n% edges Edge values of bins.\n%\nfunction [bins, nBins, edges] = bin(x, limits, binWidth)\n nBins = ceil((limits(2) - limits(1)) / binWidth);\n\n edges = limits(1):binWidth:limits(2);\n if length(edges) == nBins\n edges(end+1) = limits(2);\n end\n\n ind = (x == edges(end)); % find indices of values that according to mathematics should be\n % assigned to bin nBins+1\n [~, bins] = histc(x, edges);\n bins(ind) = nBins;\n bins(bins > nBins) = nan;\n bins(bins == 0) = nan;\nend\n", "meta": {"author": "kavli-ntnu", "repo": "MINI2P_toolbox", "sha": "83311a49baea69ecf027e19390e608fd4eaeae8d", "save_path": "github-repos/MATLAB/kavli-ntnu-MINI2P_toolbox", "path": "github-repos/MATLAB/kavli-ntnu-MINI2P_toolbox/MINI2P_toolbox-83311a49baea69ecf027e19390e608fd4eaeae8d/Analysis/+helpers/bin.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122163480666, "lm_q2_score": 0.8175744673038222, "lm_q1q2_score": 0.7417953019590209}} {"text": "function [v s] = ricefit(mudat, vr)\n%RICEFIT Estimate parameters for Rice/Rician distribution from data.\n% Uses simple moment-matching approach, with numerical optimisation.\n% [v s] = ricefit(dat) estimates v and s from samples in dat\n% [v s] = ricefit(mu, vr) estimates v and s from given mean and variance\n%\n% R ~ Rice(v, s) if R = sqrt(X^2 + Y^2), where X ~ N(v*cos(a), s^2) and\n% Y ~ N(v*sin(a), s^2) are independent normal distributions (any real a).\n% Note that v and s are *not* the mean and standard deviation of R!\n%\n% Reference: http://en.wikipedia.org/wiki/Rice_distribution (!)\n%\n% Example:\n% % Sample data, fit model, compare expected, fitted & observed moments\n% V = 5; S = 4; N = 1000;\n% [MN VR] = ricestat(V, S) % expected mean and variance\n% r = ricernd(V*ones(1, N), S);\n% [v s] = ricefit(dat) % fitted Rician distribution parameters\n% [mn vr] = ricestat(v, s) % fitted mean and variance\n% mean(dat), var(dat) % observed mean and variance\n%\n% See also RICEPDF, RICERND, RICESTAT\n\n% Missing (?) 'See also's RICECDF, RICEINV, RICELIKE\n\n% Inspired by normfit from the MATLAB statistics toolbox\n% Copyright 2008 Ged Ridgway (Ged at cantab dot net)\n\nif nargin == 1\n dat = mudat;\n mu = mean(dat(:));\n vr = var(dat(:));\nelse\n mu = mudat;\nend\n\n% Optimise cost based on difference of mu and vr from ricestat(v, s) as a \n% function of v and s, using mu and sqrt(vr) as initial values for v and s\ncost = @(x) moment_cost(x(1), x(2), mu, vr);\nx = fminsearch(cost, [mu sqrt(vr)]);\nif nargout == 1\n v = x;\nelse\n v = x(1);\n s = x(2);\nend\n\nfunction cost = moment_cost(v, s, MU, VR)\n% Very naive approach...\n% Not clear how to wait relative errors in mean and variance...\n[mu vr] = ricestat(v, s);\ncost = norm([mu - MU; vr - VR;]);\n", "meta": {"author": "qMRLab", "repo": "qMRLab", "sha": "036ff20b47e939877f746940a969494b55911636", "save_path": "github-repos/MATLAB/qMRLab-qMRLab", "path": "github-repos/MATLAB/qMRLab-qMRLab/qMRLab-036ff20b47e939877f746940a969494b55911636/External/rician/ricefit.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122138417878, "lm_q2_score": 0.8175744695262777, "lm_q1q2_score": 0.7417953019264123}} {"text": "function euler = dcm2euler(DCMbn)\n% dcm2euler: converts from body-to-nav DCM to Euler angles.\n%\n% INPUT\n% DCMbn, 3x3 body-to-nav DCM.\n%\n% OUTPUT\n% euler, 3x1 Euler angles [roll pitch yaw] (rad, rad, rad).\n%\n% Copyright (C) 2014, Rodrigo Gonzalez, all rights reserved.\n% \n% This file is part of NaveGo, an open-source MATLAB toolbox for\n% simulation of integrated navigation systems.\n%\n% NaveGo is free software: you can redistribute it and/or modify\n% it under the terms of the GNU Lesser General Public License (LGPL)\n% version 3 as published by the Free Software Foundation.\n%\n% This program is distributed in the hope that it will be useful,\n% but WITHOUT ANY WARRANTY; without even the implied warranty of\n% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n% GNU Lesser General Public License for more details.\n%\n% You should have received a copy of the GNU Lesser General Public\n% License along with this program. If not, see\n% .\n%\n% References:\n% \tTitterton, D.H. and Weston, J.L. (2004). Strapdown\n% Inertial Navigation Technology (2nd Ed.). Institution\n% of Engineering and Technology, USA. Eq. 11.4. Eq. 3.66, p. 46.\n%\n% R. Gonzalez, J. Giribet, and H.D. Pati\u00f1o,. An approach to\n% benchmarking of loosely coupled low-cost navigation systems,\n% Mathematical and Computer Modelling of Dynamical Systems, vol. 21,\n% issue 2, pp. 272-287. Eq. 15.\n%\n% Version: 002\n% Date: 2016/11/26\n% Author: Rodrigo Gonzalez \n% URL: https://github.com/rodralez/navego\n\nphi = atan( DCMbn(3,2) ./ DCMbn(3,3) ); % roll\ntheta = -asin( DCMbn(3,1) ); % pitch\npsi = atan2( DCMbn(2,1), DCMbn(1,1) ); % yaw\n\neuler = [phi theta psi];\n\nend\n", "meta": {"author": "rodralez", "repo": "NaveGo", "sha": "3de9a74ab1597be13255d4649892e68aeff9a8b7", "save_path": "github-repos/MATLAB/rodralez-NaveGo", "path": "github-repos/MATLAB/rodralez-NaveGo/NaveGo-3de9a74ab1597be13255d4649892e68aeff9a8b7/conversions/dcm2euler.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070158103778, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.7417857636202659}} {"text": "function [bandwidth,density,X,Y]=kde2d(data,n,MIN_XY,MAX_XY)\n% fast and accurate state-of-the-art\n% bivariate kernel density estimator\n% with diagonal bandwidth matrix.\n% The kernel is assumed to be Gaussian.\n% The two bandwidth parameters are\n% chosen optimally without ever\n% using/assuming a parametric model for the data or any \"rules of thumb\".\n% Unlike many other procedures, this one\n% is immune to accuracy failures in the estimation of\n% multimodal densities with widely separated modes (see examples).\n% INPUTS: data - an N by 2 array with continuous data\n% n - size of the n by n grid over which the density is computed\n% n has to be a power of 2, otherwise n=2^ceil(log2(n));\n% the default value is 2^8;\n% MIN_XY,MAX_XY- limits of the bounding box over which the density is computed;\n% the format is:\n% MIN_XY=[lower_Xlim,lower_Ylim]\n% MAX_XY=[upper_Xlim,upper_Ylim].\n% The dafault limits are computed as:\n% MAX=max(data,[],1); MIN=min(data,[],1); Range=MAX-MIN;\n% MAX_XY=MAX+Range/4; MIN_XY=MIN-Range/4;\n% OUTPUT: bandwidth - a row vector with the two optimal\n% bandwidths for a bivaroate Gaussian kernel;\n% the format is:\n% bandwidth=[bandwidth_X, bandwidth_Y];\n% density - an n by n matrix containing the density values over the n by n grid;\n% density is not computed unless the function is asked for such an output;\n% X,Y - the meshgrid over which the variable \"density\" has been computed;\n% the intended usage is as follows:\n% surf(X,Y,density)\n% Example (simple Gaussian mixture)\n% clear all\n% % generate a Gaussian mixture with distant modes\n% data=[randn(500,2);\n% randn(500,1)+3.5, randn(500,1);];\n% % call the routine\n% [bandwidth,density,X,Y]=kde2d(data);\n% % plot the data and the density estimate\n% contour3(X,Y,density,50), hold on\n% plot(data(:,1),data(:,2),'r.','MarkerSize',5)\n%\n% Example (Gaussian mixture with distant modes):\n%\n% clear all\n% % generate a Gaussian mixture with distant modes\n% data=[randn(100,1), randn(100,1)/4;\n% randn(100,1)+18, randn(100,1);\n% randn(100,1)+15, randn(100,1)/2-18;];\n% % call the routine\n% [bandwidth,density,X,Y]=kde2d(data);\n% % plot the data and the density estimate\n% surf(X,Y,density,'LineStyle','none'), view([0,60])\n% colormap hot, hold on, alpha(.8)\n% set(gca, 'color', 'blue');\n% plot(data(:,1),data(:,2),'w.','MarkerSize',5)\n%\n% Example (Sinusoidal density):\n%\n% clear all\n% X=rand(1000,1); Y=sin(X*10*pi)+randn(size(X))/3; data=[X,Y];\n% % apply routine\n% [bandwidth,density,X,Y]=kde2d(data);\n% % plot the data and the density estimate\n% surf(X,Y,density,'LineStyle','none'), view([0,70])\n% colormap hot, hold on, alpha(.8)\n% set(gca, 'color', 'blue');\n% plot(data(:,1),data(:,2),'w.','MarkerSize',5)\n%\n% Reference:\n% Kernel density estimation via diffusion\n% Z. I. Botev, J. F. Grotowski, and D. P. Kroese (2010)\n% Annals of Statistics, Volume 38, Number 5, pages 2916-2957.\nglobal N A2 I\nif nargin<2\n n=2^8;\nend\nn=2^ceil(log2(n)); % round up n to the next power of 2;\nN=size(data,1);\nif nargin<3\n MAX=max(data,[],1); MIN=min(data,[],1); Range=MAX-MIN;\n MAX_XY=MAX+Range/2; MIN_XY=MIN-Range/2;\nend\nscaling=MAX_XY-MIN_XY;\nif N<=size(data,2)\n error('data has to be an N by 2 array where each row represents a two dimensional observation')\nend\ntransformed_data=(data-repmat(MIN_XY,N,1))./repmat(scaling,N,1);\n%bin the data uniformly using regular grid;\ninitial_data=ndhist(transformed_data,n);\n% discrete cosine transform of initial data\na= dct2d(initial_data);\n% now compute the optimal bandwidth^2\n I=(0:n-1).^2; A2=a.^2;\n t_star=root(@(t)(t-evolve(t)),N);\np_02=func([0,2],t_star);p_20=func([2,0],t_star); p_11=func([1,1],t_star);\nt_y=(p_02^(3/4)/(4*pi*N*p_20^(3/4)*(p_11+sqrt(p_20*p_02))))^(1/3);\nt_x=(p_20^(3/4)/(4*pi*N*p_02^(3/4)*(p_11+sqrt(p_20*p_02))))^(1/3);\n% smooth the discrete cosine transform of initial data using t_star\na_t=exp(-(0:n-1)'.^2*pi^2*t_x/2)*exp(-(0:n-1).^2*pi^2*t_y/2).*a; \n% now apply the inverse discrete cosine transform\nif nargout>1\n density=idct2d(a_t)*(numel(a_t)/prod(scaling));\n\tdensity(density<0)=eps; % remove any negative density values\n [X,Y]=meshgrid(MIN_XY(1):scaling(1)/(n-1):MAX_XY(1),MIN_XY(2):scaling(2)/(n-1):MAX_XY(2));\nend\nbandwidth=sqrt([t_x,t_y]).*scaling; \nend\n%#######################################\nfunction [out,time]=evolve(t)\nglobal N\nSum_func = func([0,2],t) + func([2,0],t) + 2*func([1,1],t);\ntime=(2*pi*N*Sum_func)^(-1/3);\nout=(t-time)/time;\nend\n%#######################################\nfunction out=func(s,t)\nglobal N\nif sum(s)<=4\n Sum_func=func([s(1)+1,s(2)],t)+func([s(1),s(2)+1],t); const=(1+1/2^(sum(s)+1))/3;\n time=(-2*const*K(s(1))*K(s(2))/N/Sum_func)^(1/(2+sum(s)));\n out=psi(s,time);\nelse\n out=psi(s,t);\nend\n\nend\n%#######################################\nfunction out=psi(s,Time)\nglobal I A2\n% s is a vector\nw=exp(-I*pi^2*Time).*[1,.5*ones(1,length(I)-1)];\nwx=w.*(I.^s(1));\nwy=w.*(I.^s(2));\nout=(-1)^sum(s)*(wy*A2*wx')*pi^(2*sum(s));\nend\n%#######################################\nfunction out=K(s)\nout=(-1)^s*prod((1:2:2*s-1))/sqrt(2*pi);\nend\n%#######################################\nfunction data=dct2d(data)\n% computes the 2 dimensional discrete cosine transform of data\n% data is an nd cube\n[nrows,ncols]= size(data);\nif nrows~=ncols\n error('data is not a square array!')\nend\n% Compute weights to multiply DFT coefficients\nw = [1;2*(exp(-i*(1:nrows-1)*pi/(2*nrows))).'];\nweight=w(:,ones(1,ncols));\ndata=dct1d(dct1d(data)')';\n function transform1d=dct1d(x)\n\n % Re-order the elements of the columns of x\n x = [ x(1:2:end,:); x(end:-2:2,:) ];\n\n % Multiply FFT by weights:\n transform1d = real(weight.* fft(x));\n end\nend\n%#######################################\nfunction data = idct2d(data)\n% computes the 2 dimensional inverse discrete cosine transform\n[nrows,ncols]=size(data);\n% Compute wieghts\nw = exp(i*(0:nrows-1)*pi/(2*nrows)).';\nweights=w(:,ones(1,ncols));\ndata=idct1d(idct1d(data)');\n function out=idct1d(x)\n y = real(ifft(weights.*x));\n out = zeros(nrows,ncols);\n out(1:2:nrows,:) = y(1:nrows/2,:);\n out(2:2:nrows,:) = y(nrows:-1:nrows/2+1,:);\n end\nend\n%#######################################\nfunction binned_data=ndhist(data,M)\n% this function computes the histogram\n% of an n-dimensional data set;\n% 'data' is nrows by n columns\n% M is the number of bins used in each dimension\n% so that 'binned_data' is a hypercube with\n% size length equal to M;\n[nrows,ncols]=size(data);\nbins=zeros(nrows,ncols);\nfor i=1:ncols\n [dum,bins(:,i)] = histc(data(:,i),[0:1/M:1],1);\n bins(:,i) = min(bins(:,i),M);\nend\n% Combine the vectors of 1D bin counts into a grid of nD bin\n% counts.\nbinned_data = accumarray(bins(all(bins>0,2),:),1/nrows,M(ones(1,ncols)));\nend\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nfunction t=root(f,N)\n% try to find smallest root whenever there is more than one\nN=50*(N<=50)+1050*(N>=1050)+N*((N<1050)&(N>50));\ntol=10^-12+0.01*(N-50)/1000;\nflag=0;\nwhile flag==0\n try\n t=fzero(f,[0,tol]);\n flag=1;\n catch\n tol=min(tol*2,.1); % double search interval\n end\n if tol==.1 % if all else fails\n t=fminbnd(@(x)abs(f(x)),0,.1); flag=1;\n end\nend\nend\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "meta": {"author": "acerbilab", "repo": "vbmc", "sha": "54ba2cdd6c11d2595b9613557da14573abbb7b92", "save_path": "github-repos/MATLAB/acerbilab-vbmc", "path": "github-repos/MATLAB/acerbilab-vbmc/vbmc-54ba2cdd6c11d2595b9613557da14573abbb7b92/utils/kde2d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070060380482, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.7417857515689014}} {"text": "function [weight] = create_gc_weights(xDim, yDim, zDim, xVar, yVar, zVar)\n% NeuroSLAM System Copyright (C) 2018-2019 \n% NeuroSLAM: A Brain inspired SLAM System for 3D Environments\n%\n% Fangwen Yu (www.yufangwen.com), Jianga Shang, Youjian Hu, Michael Milford(www.michaelmilford.com) \n%\n% The NeuroSLAM V1.0 (MATLAB) was developed based on the OpenRatSLAM (David et al. 2013). \n% The RatSLAM V0.3 (MATLAB) developed by David Ball, Michael Milford and Gordon Wyeth in 2008.\n% \n% Reference:\n% Ball, David, Scott Heath, Janet Wiles, Gordon Wyeth, Peter Corke, and Michael Milford.\n% \"OpenRatSLAM: an open source brain-based SLAM system.\" Autonomous Robots 34, no. 3 (2013): 149-176.\n% \n% This program is free software: you can redistribute it and/or modify\n% it under the terms of the GNU General Public License as published by\n% the Free Software Foundation, either version 3 of the License, or\n% (at your option) any later version.\n% \n% This program is distributed in the hope that it will be useful,\n% but WITHOUT ANY WARRANTY; without even the implied warranty of\n% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n% GNU General Public License for more details.\n% \n% You should have received a copy of the GNU General Public License\n% along with this program. If not, see .\n\n\n % Creates a 3D normalised distributio of size dimension^3 with a variance of var.\n\n xDimCentre = floor(xDim / 2) + 1;\n yDimCentre = floor(yDim / 2) + 1;\n zDimCentre = floor(zDim / 2) + 1;\n\n weight = zeros(xDim, yDim, zDim);\n \n for z = 1 : zDim \n for x = 1 : xDim\n for y = 1 : yDim\n weight(x,y,z) = 1/(xVar*sqrt(2*pi))*exp((-(x - xDimCentre) ^ 2) / (2 * xVar ^ 2)) ...\n * 1/(yVar*sqrt(2*pi))*exp((-(y - yDimCentre) ^ 2) / (2 * yVar ^ 2)) ...\n * 1/(zVar*sqrt(2*pi))*exp((-(z - zDimCentre) ^ 2) / (2 * zVar ^ 2)); \n end\n end\n end\n\n % ensure that it is normalised\n total = sum(sum(sum(weight)));\n weight = weight./total; \n\nend", "meta": {"author": "cognav", "repo": "NeuroSLAM", "sha": "07c0d895f6aa472f07aa03e19c9cc86ab2fea9ac", "save_path": "github-repos/MATLAB/cognav-NeuroSLAM", "path": "github-repos/MATLAB/cognav-NeuroSLAM/NeuroSLAM-07c0d895f6aa472f07aa03e19c9cc86ab2fea9ac/01_conjunctive_pose_cells_network/3d_grid_cells_network/create_gc_weights.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.909907001151883, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.7417857435008968}} {"text": "function [normal,normalf] = compute_normal(vertex,face)\n\n% compute_normal - compute the normal of a triangulation\n%\n% [normal,normalf] = compute_normal(vertex,face);\n%\n% normal(i,:) is the normal at vertex i.\n% normalf(j,:) is the normal at face j.\n%\n% Copyright (c) 2004 Gabriel Peyr\ufffd\n\n[vertex,face] = check_face_vertex(vertex,face);\n\nnface = size(face,2);\nnvert = size(vertex,2);\nnormal = zeros(3, nvert);\n\n% unit normals to the faces\nnormalf = crossp( vertex(:,face(2,:))-vertex(:,face(1,:)), ...\n vertex(:,face(3,:))-vertex(:,face(1,:)) );\nd = sqrt( sum(normalf.^2,1) ); d(d0)0)\n% w - Shape parameter (w>0)\n% F - PDF of Beta distribution with shape parameters [v,w] at points x\n%__________________________________________________________________________\n%\n% spm_Bpdf implements the Probability Density Function for Beta distributions.\n%\n% Definition:\n%--------------------------------------------------------------------------\n% The PDF of the Beta distribution shape parameters v & w, defined\n% for positive integer degrees of freedom v>0 & w>0, and for x in\n% [0,1] is given by: (See Evans et al., Ch5)\n%\n% x^(v-1) * (1-x)^(w-1)\n% f(x) = -----------------------\n% beta(v,w)\n%\n% Variate relationships:\n%--------------------------------------------------------------------------\n% Many: See Evans et al., Ch5\n%\n% Algorithm:\n%--------------------------------------------------------------------------\n% Direct computation using logs and MATLAB's implementation of the log\n% beta function (betaln).\n%\n% References:\n%--------------------------------------------------------------------------\n% Evans M, Hastings N, Peacock B (1993)\n% \"Statistical Distributions\"\n% 2nd Ed. Wiley, New York\n%\n% Abramowitz M, Stegun IA, (1964)\n% \"Handbook of Mathematical Functions\"\n% US Government Printing Office\n%\n% Press WH, Teukolsky SA, Vetterling AT, Flannery BP (1992)\n% \"Numerical Recipes in C\"\n% Cambridge\n%__________________________________________________________________________\n% Copyright (C) 1999-2011 Wellcome Trust Centre for Neuroimaging\n\n% Andrew Holmes\n% $Id: spm_Bpdf.m 4182 2011-02-01 12:29:09Z guillaume $\n\n\n%-Format arguments, note & check sizes\n%--------------------------------------------------------------------------\nif nargin<3, error('Insufficient arguments'), end\n\nad = [ndims(x);ndims(v);ndims(w)];\nrd = max(ad);\nas = [[size(x),ones(1,rd-ad(1))];...\n [size(v),ones(1,rd-ad(2))];...\n [size(w),ones(1,rd-ad(3))]];\nrs = max(as);\nxa = prod(as,2)>1;\nif sum(xa)>1 && any(any(diff(as(xa,:)),1))\n error('non-scalar args must match in size');\nend\n\n%-Computation\n%--------------------------------------------------------------------------\n%-Initialise result to zeros\nf = zeros(rs);\n\n%-Only defined for x in [0,1] & strictly positive v & w.\n% Return NaN if undefined.\nmd = ( x>=0 & x<=1 & v>0 & w>0 );\nif any(~md(:))\n f(~md) = NaN;\n warning('Returning NaN for out of range arguments');\nend\n\n%-Special cases: x=0 & x=1\nf(md & x==0 & v<1) = Inf;\nf(md & x==1 & w<1) = Inf;\n\n%-Non-zero where defined & x in (0,1)\nQ = find( md & x>0 & x<1 );\nif isempty(Q), return, end\nif xa(1), Qx=Q; else Qx=1; end\nif xa(2), Qv=Q; else Qv=1; end\nif xa(3), Qw=Q; else Qw=1; end\n\n%-Compute\nf(Q) = exp((v(Qv)-1).*log(x(Qx)) + (w(Qw)-1).*log(1-x(Qx)) -betaln(v(Qv),w(Qw)));\n", "meta": {"author": "spm", "repo": "spm12", "sha": "3085dac00ac804adb190a7e82c6ef11866c8af02", "save_path": "github-repos/MATLAB/spm-spm12", "path": "github-repos/MATLAB/spm-spm12/spm12-3085dac00ac804adb190a7e82c6ef11866c8af02/spm_Bpdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789457685656, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.7417257048618469}} {"text": "function value = r8_shi ( x )\n\n%*****************************************************************************80\n%\n%% R8_SHI evaluates the hyperbolic sine integral Shi of an R8 argument.\n%\n% Discussion:\n%\n% Shi ( x ) = Integral ( 0 <= t <= x ) sinh ( t ) dt / t\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 28 September 2011\n%\n% Author:\n%\n% Original FORTRAN77 version by Wayne Fullerton.\n% MATLAB version by John Burkardt.\n%\n% Reference:\n%\n% Wayne Fullerton,\n% Portable Special Function Routines,\n% in Portability of Numerical Software,\n% edited by Wayne Cowell,\n% Lecture Notes in Computer Science, Volume 57,\n% Springer 1977,\n% ISBN: 978-3-540-08446-4,\n% LC: QA297.W65.\n%\n% Parameters:\n%\n% Input, real X, the argument.\n%\n% Output, real VALUE, the hyperbolic sine integral\n% Shi evaluated at X.\n%\n persistent nshi\n persistent shics\n persistent xsml\n\n if ( isempty ( nshi ) )\n\n shics = [ ...\n 0.0078372685688900950695200984317332, ...\n 0.0039227664934234563972697574427225, ...\n 0.0000041346787887617266746747908275, ...\n 0.0000000024707480372882742135145302, ...\n 0.0000000000009379295590763630457157, ...\n 0.0000000000000002451817019520867353, ...\n 0.0000000000000000000467416155257592, ...\n 0.0000000000000000000000067803072389, ...\n 0.0000000000000000000000000007731289, ...\n 0.0000000000000000000000000000000711 ]';\n\n nshi = r8_inits ( shics, 10, 0.1 * r8_mach ( 3 ) );\n xsml = sqrt ( r8_mach ( 3 ) );\n\n end\n\n absx = abs ( x );\n\n if ( absx <= xsml )\n value = x;\n elseif ( absx <= 0.375 )\n value = x * ( 1.0 + r8_csevl ( 128.0 * x * x / 9.0 - 1.0, shics, nshi ) );\n else\n value = 0.5 * ( r8_ei ( x ) + r8_e1 ( x ) );\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/fn/r8_shi.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422645, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.7417169512658316}} {"text": "function [am,em]=v_lpcrr2am(rr);\n%V_LPCRR2AM Convert autocorrelation coefs to ar coef matrix [AM,EM]=(RR)\n%AM is a 3-dimensional matrix of size (p+1,p+1,nf) where p is the lpc order\n%and nf the number of frames.\n%The matrix AM(:,:,*) is upper triangular with 1's on the main diagonal\n%and contains the lpc coefficients for all orders from p down to 0.\n%\n%For lpc order p+1-r, AM(r,r:p+1,*), AM(p+1:-1:r,p+1,*) and EM(*,r) contain\n%the lpc coefficients, reflection coefficients and the residual energy respectively.\n%\n%If A=am(:,:,*), R=toeplitz(rr(*,:)) and E=diag(em(*,:)), then\n% A*R*A'=E; inv(R)=A'*(1/E)*A; A*R is lower triangular with the same diagonal as E\n%\n% This routine is equivalent to: c=chol(inv(toeplitz(rr))); d=diag(c).^-1; em=d.^2; am=diag(d)*c\n\n% Copyright (C) Mike Brookes 1997\n% Version: $Id: v_lpcrr2am.m 10865 2018-09-21 17:22:45Z dmb $\n%\n% VOICEBOX is a MATLAB toolbox for speech processing.\n% Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html\n%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% This program is free software; you can redistribute it and/or modify\n% it under the terms of the GNU General Public License as published by\n% the Free Software Foundation; either version 2 of the License, or\n% (at your option) any later version.\n%\n% This program is distributed in the hope that it will be useful,\n% but WITHOUT ANY WARRANTY; without even the implied warranty of\n% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n% GNU General Public License for more details.\n%\n% You can obtain a copy of the GNU General Public License from\n% http://www.gnu.org/copyleft/gpl.html or by writing to\n% Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n[nf,p1]=size(rr);\np=p1-1;\np2=p1+1;\nam=zeros(nf,p1,p1);\nem=zeros(nf,p1);\nam(:,p1,p1)=1;\nem(:,p1)=rr(:,1);\nar=ones(nf,p1);\nar(:,2) = -rr(:,2)./rr(:,1);\ne = rr(:,1).*(ar(:,2).^2-1);\nfor n = 2:p\n q=p2-n;\n em(:,q)=-e;\n am(:,q:p1,q)=ar(:,1:n);\n k = (rr(:,n+1)+sum(rr(:,n:-1:2).*ar(:,2:n),2)) ./ e;\n ar(:,2:n) = ar(:,2:n)+k(:,ones(1,n-1)).*ar(:,n:-1:2);\n ar(:,n+1) = k;\n e = e.*(1-k.^2);\nend\nem(:,1)=-e;\nam(:,:,1)=ar;\nam=permute(am,[3 2 1]);\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "sap-voicebox", "sha": "28f2654b7584f724277ec81de533debe28ff51ac", "save_path": "github-repos/MATLAB/ImperialCollegeLondon-sap-voicebox", "path": "github-repos/MATLAB/ImperialCollegeLondon-sap-voicebox/sap-voicebox-28f2654b7584f724277ec81de533debe28ff51ac/voicebox/v_lpcrr2am.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595163, "lm_q2_score": 0.8198933315126791, "lm_q1q2_score": 0.7417169368632185}} {"text": "function out = proj_hyperplane_box(x,a,b,l,u)\n%PROJ_HYPERPLANE_BOX computes the orthogonal projection onto the intersection of a hyperplane and a box {x:=b,l<=x<=u}\n%\n% Usage:\n% out = PROJ_HYPERPLANE_BOX(x,a,b,[l],[u])\n% ===========================================\n% Input:\n% x - point to be projected (vector/matrix)\n% a - vector/matrix\n% b - scalar\n% l - lower bound (vector/matrix/scalar) [default: -inf]\n% u - upper bound (vector/matrix/scalar) [default: inf]\n% ===========================================\n% Assumptions:\n% The intersection of the hyperplane and the box is nonempty\n% ===========================================\n% Output:\n% out - projection vector\n\n% This file is part of the FOM package - a collection of first order methods for solving convex optimization problems\n% Copyright (C) 2017 Amir and Nili Beck\n% \n% This program is free software: you can redistribute it and/or modify\n% it under the terms of the GNU General Public License as published by\n% the Free Software Foundation, either version 3 of the License, or\n% (at your option) any later version.\n% \n% This program is distributed in the hope that it will be useful,\n% but WITHOUT ANY WARRANTY; without even the implied warranty of\n% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n% GNU General Public License for more details.\n% \n% You should have received a copy of the GNU General Public License\n% along with this program. If not, see .\n\nif (nargin < 3)\n error ('usage: proj_hyperplane_box(x,a,b,[l],[u])') ;\nend\n\nif (nargin < 5)\n %upper bound is not given, setting to defalut value :inf\n u = inf ;\nend\nif ((nargin < 4) || (isempty( l)))\n %lower bound is not given, setting to defalut value :-inf\n l = -inf;\nend\n\n%checking that sum (l) < b < sum (u)\n\n\nsumlb = trace(a'*((l .* (sign(a)>0)) + (u .* (sign(a)<0)))) ;\nsumub = trace(a'*((u .* (sign(a)>0)) + (l .* (sign(a)<0)))) ;\n\nif ((sumlb > b) || (any(any(l > u))) || (sumub < b))\n error('Set is infeasible') ;\nend\n\n%solve with equality\n%defining f on lambda - to be used by the bisetion\n\neps = 1e-10 ;\n\nf= @(lam) trace(a'*min(max(x-lam*a,l),u))-b;\nlambda_min = -1;\nwhile(f(lambda_min)<0)\n lambda_min = lambda_min *2 ;\nend\n\nlambda_max = 1;\nwhile(f(lambda_max)>0)\n lambda_max = lambda_max *2 ;\nend\n\nfinal_lam = bisection(f,lambda_min,lambda_max,eps) ;\nout= min(max(x-final_lam*a,l),u) ;\n", "meta": {"author": "hiroyuki-kasai", "repo": "SGDLibrary", "sha": "d19a12559c79c3726683243885b15f982f4bec3d", "save_path": "github-repos/MATLAB/hiroyuki-kasai-SGDLibrary", "path": "github-repos/MATLAB/hiroyuki-kasai-SGDLibrary/SGDLibrary-d19a12559c79c3726683243885b15f982f4bec3d/tool/FOM_prox functions/proj_hyperplane_box.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972751232809, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.7417077928360446}} {"text": "function [ n_data, x, fx ] = bessel_j1_values ( n_data )\n\n%*****************************************************************************80\n%\n%% BESSEL_J1_VALUES returns some values of the J1 Bessel function.\n%\n% Discussion:\n%\n% In Mathematica, the function can be evaluated by:\n%\n% BesselJ[1,x]\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 12 August 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Milton Abramowitz and Irene Stegun,\n% Handbook of Mathematical Functions,\n% US Department of Commerce, 1964.\n%\n% Stephen Wolfram,\n% The Mathematica Book,\n% Fourth Edition,\n% Wolfram Media / Cambridge University Press, 1999.\n%\n% Parameters:\n%\n% Input/output, integer N_DATA. The user sets N_DATA to 0 before the\n% first call. On each call, the routine increments N_DATA by 1, and\n% returns the corresponding data; when there is no more data, the\n% output value of N_DATA will be 0 again.\n%\n% Output, real X, the argument of the function.\n%\n% Output, real FX, the value of the function.\n%\n n_max = 21;\n\n fx_vec = [ ...\n 0.3275791375914652E+00, ... \n 0.6604332802354914E-01, ... \n -0.3390589585259365E+00, ... \n -0.5767248077568734E+00, ... \n -0.4400505857449335E+00, ... \n 0.0000000000000000E+00, ... \n 0.4400505857449335E+00, ... \n 0.5767248077568734E+00, ... \n 0.3390589585259365E+00, ... \n -0.6604332802354914E-01, ... \n -0.3275791375914652E+00, ... \n -0.2766838581275656E+00, ... \n -0.4682823482345833E-02, ... \n 0.2346363468539146E+00, ... \n 0.2453117865733253E+00, ... \n 0.4347274616886144E-01, ... \n -0.1767852989567215E+00, ... \n -0.2234471044906276E+00, ... \n -0.7031805212177837E-01, ... \n 0.1333751546987933E+00, ... \n 0.2051040386135228E+00 ];\n\n x_vec = [ ...\n -5.0E+00, ...\n -4.0E+00, ...\n -3.0E+00, ...\n -2.0E+00, ...\n -1.0E+00, ...\n 0.0E+00, ...\n 1.0E+00, ...\n 2.0E+00, ...\n 3.0E+00, ...\n 4.0E+00, ...\n 5.0E+00, ...\n 6.0E+00, ...\n 7.0E+00, ...\n 8.0E+00, ...\n 9.0E+00, ...\n 10.0E+00, ...\n 11.0E+00, ...\n 12.0E+00, ...\n 13.0E+00, ...\n 14.0E+00, ...\n 15.0E+00 ];\n\n if ( n_data < 0 )\n n_data = 0;\n end\n\n n_data = n_data + 1;\n\n if ( n_max < n_data )\n n_data = 0;\n x = 0.0;\n fx = 0.0;\n else\n x = x_vec(n_data);\n fx = fx_vec(n_data);\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_values/bessel_j1_values.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972549785203, "lm_q2_score": 0.8519528038477825, "lm_q1q2_score": 0.7417077724011332}} {"text": "function [sampleLabels, groupCodingLengths] = coding_seg(W, epsilon, affine )\n\n% coding_seg.m\n%\n% Implements an agglomerative segmentation algorithm which attempts to\n% minimize the number of bits needed to code the segmented vectors upto\n% distortion epsilon^2. This method is described in detail in Ma, et. al.,\n% Segmentation of Multivariate Mixed Data via Lossy Coding and Compression,\n% PAMI 2007.\n%\n% Run test_coding_seg.m, included in this package, for a demonstration. \n%\n% Inputs:\n% W - [ w1 | w2 | ... | wm ], the data matrix. \n% The columns are the input data vectors. \n%\n% epsilon - sqrt of the allowable distortion, \n% E[ \\| \\hat{w_i} - w_i \\|^2 ]\n%\n% affine - boolean, if true the algorithm uses the coding length for\n% nonzero-mean data, derived in Appendix II of the paper.\n%\n% Outputs:\n% sampleLabels - 1 x m list whose i-th entry is the group assignment of\n% the i-th data vector w_i. Groups are indexed\n% sequentially, starting from 1. \n%\n% Dependencies:\n% coding_length.m\n%\n% Feb '06, last revision Jan '07\n% Questions? John Wright -- jnwright@uiuc.edu\n\n% Copyright 2007, University of Illinois. All rights reserved. \n\n VERBOSE = 0;\n\n epsilon2 = epsilon^2;\n\n % n - dimension \n % m - number of samples\n [n,m] = size(W);\n\n % initially treat each sample as its own group\n sampleLabels = 1:m;\n curGroupCount = m;\n\n % compute the coding length of each of the initial groups\n squaredNormW = sum(W.^2,1);\n if affine\n groupCodingLengths = n * log2(1 + (squaredNormW/epsilon2))/ 2 + log2(m);\n else\n groupCodingLengths = (n + 1) * log2(1 + (n / epsilon2)*squaredNormW)/ 2 + log2(m);\n end\n\n if VERBOSE\n disp(' Computing initial table.');\n end\n\n % entropyChange is a matrix whose ij-th element is the entropy lost by\n % merging groups i and j into one group.\n delta_L_matrix = ones(m);\n\n for groupIndex1 = 1 : m-1\n for groupIndex2 = groupIndex1+1 : m\n L1 = groupCodingLengths(groupIndex1);\n L2 = groupCodingLengths(groupIndex2);\n L_union = coding_length(W(:, [groupIndex1 groupIndex2]),epsilon2,m,affine);\n delta_L_matrix(groupIndex1, groupIndex2) = L_union - L1 - L2;\n end;\n end;\n\n if VERBOSE\n disp(' Starting merging process');\n end\n\n while curGroupCount > 1 \n\n if mod( curGroupCount, 50 ) == 0 && VERBOSE\n disp([' Group count: ' num2str(curGroupCount)]);\n end\n\n % Find the best two groups to merge together\n [temp minIndex]=min(delta_L_matrix);\n [min_delta_L minIndex2]=min(temp);\n minIndex1=minIndex(minIndex2);\n\n % If this does not decrease the coding length, we are done\n if ( min_delta_L > 0 )\n break;\n end;\n\n % Merging groups with labels minIndex1 and minIndex2\n if (minIndex1 > minIndex2)\n temp = minIndex1;\n minIndex1 = minIndex2;\n minIndex2 = temp;\n end\n\n if (minIndex2 ~= curGroupCount)\n % First make the group to merge have the last label\n\n % Change the sample labels of the group minIndex2 to be the last\n % label.\n sampleLabels(sampleLabels == curGroupCount) = -1;\n sampleLabels(sampleLabels == minIndex2) = curGroupCount;\n sampleLabels(sampleLabels == -1) = minIndex2;\n\n % Swap the entropy of groups minIndex2 and the last group. \n [groupCodingLengths(minIndex2), groupCodingLengths(curGroupCount)] = ...\n swap(groupCodingLengths(minIndex2), groupCodingLengths(curGroupCount));\n\n delta_L_matrix = swap_matrix(delta_L_matrix, minIndex2, curGroupCount);\n\n end\n\n % Now we can assume the last group is the group to be merged \n sampleLabels(sampleLabels == curGroupCount) = minIndex1;\n groupCodingLengths(curGroupCount) = [];\n groupCodingLengths(minIndex1) = coding_length(W(:, sampleLabels == minIndex1),epsilon2,m,affine);\n delta_L_matrix = delta_L_matrix(1:end-1, 1:end-1);\n\n curGroupCount = curGroupCount - 1; \n\n for groupIndex2 = [1:minIndex1-1 minIndex1+1:curGroupCount],\n i = min(minIndex1, groupIndex2); j = max(minIndex1, groupIndex2); \n L1 = groupCodingLengths(i);\n L2 = groupCodingLengths(j);\n L_union = coding_length(W(:, (sampleLabels == i) | (sampleLabels == j)) ,epsilon2,m,affine);\n delta_L_matrix(i, j) = L_union - L1 - L2; \n end;\n end;\n\n %codingLength = sum(groupCodingLengths);\n\n if VERBOSE\n disp([' Final group count: ' num2str(curGroupCount)]);\n end\n\nend\n% If A is an upper triangular matrix where A(m,n) = f(x_m,x_n) for m < n\n% relabel so that the roles of x_i and x_j are swapped.\nfunction A = swap_matrix(A, i, j)\n[A(1:i-1, i), A(1:i-1, j)] = swap(A(1:i-1, i), A(1:i-1, j));\n[A(i, i+1:j-1), A(i+1:j-1, j)] = swap(A(i, i+1:j-1), A(i+1:j-1, j));\n[A(i, j+1:end), A(j, j+1:end)] = swap(A(i, j+1:end), A(j, j+1:end));\nend\n\n% swap the values of x and y\nfunction [y, x] = swap(x,y)\nend", "meta": {"author": "SuTanTank", "repo": "VideoStitchingViaShakinessRemoving", "sha": "701145c6d319d9dd54b534c8f3498aaeabe9f269", "save_path": "github-repos/MATLAB/SuTanTank-VideoStitchingViaShakinessRemoving", "path": "github-repos/MATLAB/SuTanTank-VideoStitchingViaShakinessRemoving/VideoStitchingViaShakinessRemoving-701145c6d319d9dd54b534c8f3498aaeabe9f269/Stitching-1.1.0/tracks/helpers/coding_seg.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361676202372, "lm_q2_score": 0.8128673155708975, "lm_q1q2_score": 0.7416895382032597}} {"text": "function out = proj_simplex(x,r,eq_flag)\n%PROJ_SIMPLEX computes the orthogonal projection onto the r-simplex {x:sum(x)=r,x>=0} \n% or r-full simplex {x:sum(x)<=r,x>=0}\n%\n% Usage: \n% out = PROJ_SIMPLEX(x,[r],[eq_flag])\n% =============================================================\n% Input:\n% x - point to be projected (vector/matrix)\n% r - a positive scalar [default: 1]\n% eq_flag - a flag that determines whether the projection is onto the r-simplex ('eq') or \n% the r-full simplex ('ineq') [defualt: 'eq']\n% ==============================================================\n% Assumptions:\n% r > 0\n% ==============================================================\n% Output:\n% out - projection vector\n\n% This file is part of the FOM package - a collection of first order methods for solving convex optimization problems\n% Copyright (C) 2017 Amir and Nili Beck\n% \n% This program is free software: you can redistribute it and/or modify\n% it under the terms of the GNU General Public License as published by\n% the Free Software Foundation, either version 3 of the License, or\n% (at your option) any later version.\n% \n% This program is distributed in the hope that it will be useful,\n% but WITHOUT ANY WARRANTY; without even the implied warranty of\n% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n% GNU General Public License for more details.\n% \n% You should have received a copy of the GNU General Public License\n% along with this program. If not, see .\n\n%reading the user x and setting defalut values when reqired.\nif (nargin < 1)\n error ('usage: proj_simplex(x,r,[eq_flag])') ;\nend\n\nif (( nargin < 3) || (isempty(eq_flag)) )\n %eq_flag is not given, setting to default value: true\n eq_flag = 'eq' ;\nend\n\nif ((nargin < 2) || (isempty(r)))\n %r is not given, setting to default value: 1\n r = 1 ;\nend\n\nif (r < 0) \n error('Set is infeasible') ;\nend\n\nif (strcmp(eq_flag,'eq') == 1)\n %call proj_hyperplane_box\n out = proj_hyperplane_box(x,ones(size(x)),r,0) ; \nelse\n if (strcmp(eq_flag,'ineq') == 1)\n %call proj_halfspace_box\n out = proj_halfspace_box(x,ones(size(x)),r,0) ;\n else\n error('usage: proj_simplex(x,r,[eq_flag]) - eq_flag should be either eq or ineq') ;\n end\nend\n\n", "meta": {"author": "hiroyuki-kasai", "repo": "SGDLibrary", "sha": "d19a12559c79c3726683243885b15f982f4bec3d", "save_path": "github-repos/MATLAB/hiroyuki-kasai-SGDLibrary", "path": "github-repos/MATLAB/hiroyuki-kasai-SGDLibrary/SGDLibrary-d19a12559c79c3726683243885b15f982f4bec3d/tool/FOM_prox functions/proj_simplex.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361652391386, "lm_q2_score": 0.8128673155708975, "lm_q1q2_score": 0.7416895362677425}} {"text": "% Convert a stroke [x,y,t] such that it is uniformly sampled\n% in time. This is done by linear interpolation in time\n%\n% Input\n% stk: [n x 2] for x and y\n% time: [n x 1] for time coordinate\n% tint: [scalar] time interval (in milliseconds)\n%\n% Output\n% unif_stk: [k x 2] new stroke x and y \n% unif_t: [k x 1] uniform time interval\n%\nfunction [unif_stk,unif_t] = uniform_time_lerp(stk,time,tint)\n\n mint = min(time);\n maxt = max(time);\n \n unif_t = mint:tint:maxt;\n % make sure we don't leave out the last point\n if unif_t(end) ~= maxt \n unif_t = [unif_t maxt]; \n end \n nt = length(unif_t);\n \n unif_stk = zeros(length(unif_t),2);\n for i=1:nt\n ti = unif_t(i);\n \n diff = time-ti;\n if any(diff==0)\n sel = stk(diff==0,:); \n unif_stk(i,:) = mean(sel,1);\n continue\n end\n \n % find the point before and after in time\n indx_gt = find(diff>0,1,'first');\n indx_lt = find(diff<0,1,'last');\n \n x_gt = stk(indx_gt,:);\n x_lt = stk(indx_lt,:);\n t_gt = time(indx_gt);\n t_lt = time(indx_lt); \n \n % Compute the linear interpolation\n frac = (ti - t_lt) ./ (t_gt - t_lt);\n assert(frac<=1);\n unif_stk(i,:) = (1-frac).*x_lt + frac.*x_gt;\n end\n\nend", "meta": {"author": "brendenlake", "repo": "BPL", "sha": "2c7f679bb0055f29cbade7ef099897c3342bcb79", "save_path": "github-repos/MATLAB/brendenlake-BPL", "path": "github-repos/MATLAB/brendenlake-BPL/BPL-2c7f679bb0055f29cbade7ef099897c3342bcb79/data/uniform_time_lerp.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361557147438, "lm_q2_score": 0.8128673178375734, "lm_q1q2_score": 0.7416895305938702}} {"text": "function tanh_prime = tanh_prime(a)\n %a = tanh(input);\n tanh_prime = (1-a.^2);\nend", "meta": {"author": "jacoxu", "repo": "STC2", "sha": "34a28c5a8cf2d6e1db300d32f271f6522db3bde5", "save_path": "github-repos/MATLAB/jacoxu-STC2", "path": "github-repos/MATLAB/jacoxu-STC2/STC2-34a28c5a8cf2d6e1db300d32f271f6522db3bde5/software/RecNN/tools/tanh_prime.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9263037343628703, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.7416839872104806}} {"text": "function pass = test_nonlinSys1Breaks_C1(pref)\n% Test 2x2 system (sin/cos). This is pecewiseificaion of the test\n% test_nonlinearSystem1\n%\n% Asgeir Birkisson, April 2014.\n\nif ( nargin == 0 )\n pref = cheboppref;\nend\n\ntol = 1e-10;\n\nd = [-pi 0 pi];\nx = chebfun('x',d);\nf = [ 0*x ; 0*x ];\n\n%% Piecewise (chebcolloc1):\npref.discretization = @chebcolloc1;\n\nA = chebop(@(x,u,v) [u - diff(v,2) + u.^2; diff(u) + sin(v)],d);\nA.lbc = @(u,v) u-1;\nA.rbc = @(u,v) [v-1/2; diff(v)];\n\nu = mldivide(A, f, pref);\nu1 = u{1}; u2 = u{2};\n\n% Want to check BCs as well.\nbcFunLeft = A.lbc(u1,u2);\nbcFunRight = chebfun(A.rbc(u1,u2));\n\n% And check that we're continuous over breakpoint\nu1jump = jump(u1, 0);\nu2jump = jump(u2, 0);\n\npass(1) = norm( chebfun(A(x, u1, u2))) < tol;\npass(2) = norm(bcFunLeft(d(1))) < tol && norm(bcFunRight(d(end))) < tol;\npass(3) = norm(u1jump) < tol && norm(u2jump) < tol;\n\nend\n", "meta": {"author": "chebfun", "repo": "chebfun", "sha": "8c49396a55e46ddd57a1d108c6a8f32e37536d54", "save_path": "github-repos/MATLAB/chebfun-chebfun", "path": "github-repos/MATLAB/chebfun-chebfun/chebfun-8c49396a55e46ddd57a1d108c6a8f32e37536d54/tests/chebop/test_nonlinSys1Breaks_C1.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037221561135, "lm_q2_score": 0.8006920068519376, "lm_q1q2_score": 0.7416839862475981}} {"text": "%GRAD_AND_DIV\n% Generates pressure gradient matrices Pu, Pv and divergence matrix D\n% Vectorized matrix generation by evaluation of stencil coefficients\n% Output: Pu, Pv, Du, Dv\n\nJ= length(dx); K = length(dy);\n\n%.................Pressure gradient matrix Pu ....................\n\n% \t | 0 |\n% Stencil: [Pu] = |p1 p2 0 |\n% \t | 0 |\n\n% Indexing convention in staggered grid:\n% +--k+1--+ \n% | |\n% j jk j+1\n% | |\n% +---k---+ \ntic\np2 = 1./DXU(1,:)'; p1 = zeros(size(p2)); p1(1:J) = -p2(2:J+1); \nPuu = spdiags([p1 p2],[-1;0], J+1, J); Pu = kron(speye(K),Puu);\n\n%......................Boundary corrections....................................\nfor seg = 1:length(ybc(1,:))\n if (ybc(1,seg) == 1)|(ybc(1,seg) == 2) % No-slip or inflow at left boundary\n k = 1+kseg(seg):kseg(seg+1); Pu(1+(k-1)*(J+1),:) = 0;\n end\n if (ybc(2,seg) == 1)|(ybc(2,seg) == 2) % No-slip or inflow at right boundary\n k = 1+kseg(seg):kseg(seg+1); Pu(k*(J+1),:) = 0; \n end\nend\ntijd = toc; disp(['Breakdown of grad_and_div time'])\ndisp([' Pu time = ',num2str(tijd)])\n\n%.................Pressure gradient matrix Pv ....................\n\n% \t | 0 |\n% Stencil: [Pv] = |0 p2 0|\n% \t | p1 |\n\ntic\npp1 = zeros(size(XV)); pp2 = pp1; \t\t% Diagonals of Pv\npp1(2:K+1,:) = -1./DYV(2:K+1,:); \tpp2 = -pp1;\npp2(1,:) = 1./DYV(1,:); \t\tpp2(K+1,:) = 0;\n\n%......................Boundary corrections....................................\nfor seg = 1:length(xbc(1,:))\n if (xbc(1,seg) == 1)|(xbc(1,seg) == 2) % No-slip or inflow at lower boundary\n j = 1+jseg(seg):jseg(seg+1); \tpp1(1,j) = 0; pp2(1,j) = 0; \n end\n if (xbc(2,seg) == 1)|(xbc(2,seg) == 2) % No-slip or inflow at upper boundary\n j = 1+jseg(seg):jseg(seg+1);\tpp1(K+1,j) = 0; pp2(K+1,j) = 0; \n end\nend\nn = J*(K+1); p1 = reshape(pp1',n,1); p2 = reshape(pp2',n,1);\np1 = [p1(J+1:n); zeros(J,1)];\t\t% Shift to accomodate spdiags\nPv = spdiags([p1 p2],[-J;0], n,n-J);\ntijd = toc; disp([' Pv time = ',num2str(tijd)])\n\n%.................u divergence matrix Du ....................\n\n%\t\t | 0 |\n% Stencil: [Du] = |0 p1 p2| \n%\t\t | 0 |\n\ntic\nDuu = spdiags([-ones(J,1) ones(J,1)], [0;1], J,J+1);\nDu = kron(spdiags(dy',0,K,K),Duu);\ntijd = toc; disp([' Du time = ',num2str(tijd)])\n\n%.................v divergence matrix Dv ....................\n\n%\t\t | p2 |\n% Stencil: [Dv] = |0 p1 0| \n%\t\t | 0 |\n\ntic\nDvv = spdiags([-ones(K,1) ones(K,1)], [0;1], K,K+1);\nDv = kron(Dvv,spdiags(dx',0,J,J));\ntijd = toc; disp([' Dv time = ',num2str(tijd)])\n\nclear pp1 pp2 p1 p2 Puu Duu Dvv \t\t\t% Save storage\n", "meta": {"author": "wme7", "repo": "Aero-matlab", "sha": "9430008f2e3b84f28633775a44dff534e780fbac", "save_path": "github-repos/MATLAB/wme7-Aero-matlab", "path": "github-repos/MATLAB/wme7-Aero-matlab/Aero-matlab-9430008f2e3b84f28633775a44dff534e780fbac/cfdbook/chap6.5/grad_and_div.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037241905732, "lm_q2_score": 0.8006920044739461, "lm_q1q2_score": 0.7416839856738313}} {"text": "% predicting numerical values using Linear Regression\nclear all;\nformat long\ndisp('===== Linear Regression ====');\ndisp('Reading featur vector');\n\n\n\nIndices = crossvalind('Kfold', 1107, 10);\nfigure;\n\nsubplot(3,2,1);\n\nfor feat = 1:3\n MSEarray =[];\n elapsedarray =[];\n for crossvalidateIter = 1:10\n (fprintf('%d',crossvalidateIter));\n featurs = csvread('data\\productsdesc.csv');\n num_data = size(featurs,1); %5000;\n %disp(sprintf('Number of datapoints %d',num_data))\n \n possiblefeaturizations = {'bernouli', 'tfidf','multinomial'};\n %featurization = 'bernouli'%'tfidf'%'tfidf'%'multinomial'%'tfidf' %'multinomial'; % 'bernouli', 'tfidf'\n featurization = possiblefeaturizations{feat};\n \n \n featurs = featurs(:,2:size(featurs,2));\n if strcmp(featurization,'multinomial')\n %just pass\n elseif strcmp(featurization,'bernouli')\n featurs = bernoulli(featurs);\n elseif strcmp(featurization,'tfidf')\n featurs = tfidf(featurs);\n end\n \n size_training = floor(.9*num_data);\n \n \n trainingset = featurs(Indices~=crossvalidateIter,:);\n testset = featurs(Indices==crossvalidateIter,:);\n \n \n %disp('Splitting up data into training/test sets');\n [num,txt,raw] = xlsread('data\\productsratings.csv');\n \n responsevals = num;\n \n \n responsevals_training = responsevals(Indices~=crossvalidateIter,:);\n responsevals_test = responsevals(Indices==crossvalidateIter,:);\n \n %disp('Linear Regression');\n % \n \n tic;\n \n predictions = [];\n actual = [];\n for i =1:3\n a = responsevals_training(:,i);\n b = responsevals_test(:,i)';\n regresscoeff = regress(a, trainingset);\n C2 = (regresscoeff'*(testset'));\n predictions = [predictions, C2'];\n actual = [actual, b'];\n end\n \n \n MSE = mean(sum(((predictions-actual).^2)'))\n elapsed = toc;\n MSEarray = [MSEarray MSE];\n elapsedarray = [elapsedarray elapsed];\n \n end\n featurization = possiblefeaturizations{feat}\n fprintf('Avergae MSE for Linear Regression is %0.10f\\n', mean(MSEarray));\n subplot(3,2,feat*2-1)\n plot(MSEarray,'-o');\n title(strcat('MSE for Linear Regression (',featurization,') ', sprintf(' avergae MSE = %0.10f\\n', mean(MSEarray))));\n xlabel('10 fold cross-validation (iteration no)')\n ylabel('MSE')\n subplot(3,2,feat*2)\n plot(elapsedarray,'-o');\n title(strcat('Elapsed time for Linear Regression (',featurization, ') ' , sprintf(' avergae elapsed time = %0.10f\\n', mean(elapsedarray))));\n xlabel('10 fold cross-validation (iteration no)')\n ylabel('Elapsed Time')\n drawnow;\nend\n\n\n\n", "meta": {"author": "faridani", "repo": "MatlabNLP", "sha": "e18e8bc44ecbc8bb6aa57312c1ee22930f805a6f", "save_path": "github-repos/MATLAB/faridani-MatlabNLP", "path": "github-repos/MATLAB/faridani-MatlabNLP/MatlabNLP-e18e8bc44ecbc8bb6aa57312c1ee22930f805a6f/sandboxes/siamak sandbox/multivariate6D/product_linearRegression_adjusted_generalized_crossvalidation.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240177362486, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.7416154833223826}} {"text": "N = 15; % Set N as an odd number;\nw0 = 0.4*pi;\nn0 = floor(N/2);\nhn = zeros(1,N);\nfor i = 1:length(hn)\n if i == n0\n hn(i) = w0/pi;\n else\n hn(i) = sin(w0*(i-n0))/(pi*(i-n0));\n end;\nend;\nsubplot(3,1,1);stem(hn);title('h[n]');\n \nNp = 1000;\nhn = [hn,zeros(1, Np-length(hn))];%zero padding\n[w,y] = calculateDiscreteFourierTransform(hn);\n \nsubplot(3,1,2);plot(w,abs(y)),title('\u5e45\u5ea6\u8c31');\nsubplot(3,1,3);plot(w,angle(y)),title('\u76f8\u4f4d\u8c31');\n", "meta": {"author": "VipaiLab", "repo": "Signals-and-Systems-course", "sha": "a48269b0247359ab746cb42bb55c984ed850e437", "save_path": "github-repos/MATLAB/VipaiLab-Signals-and-Systems-course", "path": "github-repos/MATLAB/VipaiLab-Signals-and-Systems-course/Signals-and-Systems-course-a48269b0247359ab746cb42bb55c984ed850e437/\u4fe1\u53f7\u4e0e\u7cfb\u7edfMATLAB\u7a0b\u5e8f\u793a\u4f8b/8. FIR\u6570\u5b57\u6ee4\u6ce2\u5668\u8bbe\u8ba1\u7a0b\u5e8f/showhn.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240108164657, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.741615473222414}} {"text": "function geometry_test2062 ( )\n\n%*****************************************************************************80\n%\n%% TEST2062 tests TRIANGLE_AREA_HERON;\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 14 February 2003\n%\n% Author:\n%\n% John Burkardt\n%\n dim_num = 3;\n\n t = [ ...\n 1.0, 0.0, 0.0; ...\n 0.0, 1.0, 0.0; ...\n 0.0, 0.0, 1.0 ]';\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TEST2062\\n' );\n fprintf ( 1, ' For a triangle in any dimension,\\n' );\n fprintf ( 1, ' TRIANGLE_AREA_HERON computes the area;\\n' );\n\n r8mat_transpose_print ( dim_num, 3, t, ' Triangle vertices:' );\n\n for j = 1 : 3\n\n s(j) = 0.0;\n\n jp1 = mod ( j, 3 ) + 1;\n\n for i = 1 : dim_num\n s(j) = s(j) + ( t(i,j) - t(i,jp1) ).^2;\n end\n\n s(j) = sqrt ( s(j) );\n\n end\n\n r8vec_print ( 3, s, ' Side lengths:' );\n\n area = triangle_area_heron ( s );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' The area is %f\\n', area );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/geometry/geometry_test2062.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206659843131, "lm_q2_score": 0.8221891348788759, "lm_q1q2_score": 0.741549372095022}} {"text": "function x = Adj_USFFT(n,y,omega,D,L,center)\n% USFFT_simple -- 1d adjoint unequispaced Fourier transform\n% Usage:\n% x = USFFT(n,y,omega,D,L,center)\n% Inputs:\n% n length of output x\n% y\t vector of length m, \n% omega vector of sampled frequencies (length m)\n% center 0 for unbiased FT, 1 otherwise\n% Outputs:\n% x vector of length n\n% Description:\n% Evaluates the adjoint of the FT\n% \n% If center = 0, \n%\n% x(t) = sum_{k} exp(i omega_k t) y(k), -n/2 <= t < n/2\n%\n% If center = 1, \n%\n% x(t) = sum_{k} exp(i omega_k t) y(k), 0 <= t < n\n% \n% See Also\n% USFFT, USFT_simple, Evaluate_FT\n% Notes:\n% To work properly, D*n must be even\n%\n% By Emmanuel candes, 2003-2004\n\n if nargin < 6,\n center = 0;\n end\n \n if nargin < 5,\n L = 4;\n end\n \n if nargin < 4,\n D = 16;\n end\n \n n2 = n/2;\n N = D*n; N2 = N/2;\n m = length(omega);\n \n if rem(L,2) == 1,\n L = L + 1;\n end\n \n % Nearest point calculations\n \n near_index = round(N *omega/(2*pi));\n row = near_index + N/2 + 1;\n \n delta = omega - 2*pi*near_index/N; \n \n % Make matrix y(k) * delta(k)^l, l = 0, 1, ..., L-1\n \n FA = repmat(y(:),1,L); \n for l = 2:L;\n FA(:,l) = FA(:,l-1) .* delta/(l-1);\n end\n \n % Sum entries corresponding to the same index \n \n F = zeros(N,L);\n for k = 1:m,\n F(row(k),:) = F(row(k),:) + FA(k,:);\n end\n \n % Take IFFT along columns\n X = ifft_mid0(F) * N; \n X = X((N2-n2+1):(N2+n2),:);\n \n t = -n2:(n2-1);\n tp = ones(n,L); \n \n for k = 2:L;\n tp(:,k) = tp(:,k-1) .* (i*t.');\n end\t\n \n x = sum(X.*tp,2);\n \n", "meta": {"author": "thomaskuestner", "repo": "CS_MoCo_LAB", "sha": "a26e8e483624b2e4ee669e7a069ba9c74d2d2e4b", "save_path": "github-repos/MATLAB/thomaskuestner-CS_MoCo_LAB", "path": "github-repos/MATLAB/thomaskuestner-CS_MoCo_LAB/CS_MoCo_LAB-a26e8e483624b2e4ee669e7a069ba9c74d2d2e4b/reconstruction/matlab/CS_LAB_matlab/utils/utils_TRAFO/CurveLab-2.1.3/fdct_usfft_matlab/USFFT/Adj_USFFT.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009619539554, "lm_q2_score": 0.8104789086703225, "lm_q1q2_score": 0.74150793318587}} {"text": "function imden=den2d_block(x,qmf,thd,L,sigma)\n\nif (exist('x')~=1), \terror('Provide input image'); \t\tend;\nif (exist('qmf')~=1), \tqmf = MakeONFilter('Symmlet',6); \tend;\nif (exist('thd')~=1), \tthd = 4.5;\t\t\t\tend;\n\n[nx ny] = size(x);\nif nx~=ny\n\tdisp('Matrix must be square');\n\treturn;\nend\n\nn \t= nx;\nJ\t= nextpow2(n);\nif (exist('L')~=1), \tL = floor(sqrt(2*J)); \t\tend; % Size of block.\nscale \t= floor(log2(L)); % Coarsest scale L#2^Jc matches the size of the block.\n\n% wc=FWT2_PO(x,scale,qmf);\nwc = x;\n\nfor j = 0:J-1-scale\n HH = wc(2^(J-j-1)+1 : 2^(J-j), 2^(J-j-1)+1 : 2^(J-j));\n HH = block_partition(HH,L);\n %HHmask = sqrt(sum(HH.^2)) >= thd*L*sigma;\n HHmask = max(1-thd*log(n)*sigma^2./sum(HH.^2),0);\n HH = HH .* repmat(HHmask,L*L,1);\n HH = invblock_partition(HH,2^(J-j-1),L);\n wc(2^(J-j-1)+1 : 2^(J-j), 2^(J-j-1)+1 : 2^(J-j)) = HH;\n \n HL = wc(2^(J-j-1)+1 : 2^(J-j), 1 : 2^(J-j-1));\n HL = block_partition(HL,L);\n %HLmask = sqrt(sum(HL.^2)) >= thd*L*sigma;\n HLmask = max(1-thd*log(n)*sigma^2./sum(HL.^2),0);\n HL = HL .* repmat(HLmask,L*L,1);\n HL = invblock_partition(HL,2^(J-j-1),L);\n wc(2^(J-j-1)+1 : 2^(J-j), 1 : 2^(J-j-1)) = HL;\n \n LH = wc(1 : 2^(J-j-1), 2^(J-j-1)+1 : 2^(J-j));\n LH = block_partition(LH,L);\n %LHmask = sqrt(sum(LH.^2)) >= thd*L*sigma;\n LHmask = max(1-thd*log(n)*sigma^2./sum(LH.^2),0);\n LH = LH .* repmat(LHmask,L*L,1);\n LH = invblock_partition(LH,2^(J-j-1),L);\n wc(1 : 2^(J-j-1), 2^(J-j-1)+1 : 2^(J-j)) = LH;\nend\n\nimden = IWT2_PO(wc,scale,qmf);\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nfunction out = block_partition(x,L)\n\nn \t= length(x);\nnblocks = floor(n/L);\n\nout = [];\nfor i=0:nblocks-1\n out = [out x(i*L+1:(i+1)*L,:)];\nend\n\nout = reshape(out(:),L^2,nblocks^2);\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nfunction out = invblock_partition(x,n,L)\n\nnblocks = floor(n/L);\n\nbuf = reshape(x,L,L*nblocks^2);\n\nout = [];\nfor i=0:nblocks-1\n out = [out;buf(:,i*L*nblocks+1:(i+1)*L*nblocks)];\nend\n\n\n", "meta": {"author": "gpeyre", "repo": "matlab-toolboxes", "sha": "0cd622c988cda6f63f64d35cd7bd096fa578e5c6", "save_path": "github-repos/MATLAB/gpeyre-matlab-toolboxes", "path": "github-repos/MATLAB/gpeyre-matlab-toolboxes/matlab-toolboxes-0cd622c988cda6f63f64d35cd7bd096fa578e5c6/toolbox_wavelets/tests/den2d_block.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009457116781, "lm_q2_score": 0.8104789109591832, "lm_q1q2_score": 0.7415079221159278}} {"text": "function [Xt xfm] = perspective_xfm(X,Y)\n% perspective_xfm - 2D perspective transformation\n%\n% Xt = perspective_xfm(X,Y)\n%\n% X,Y : input matrix (nx2) giving the each points (n) coordinates\n% Xt : X transformed to match Y\n% xfm : tranformation matrices (3x3 and 1x3)\n%\n% 2008/03 SOD: after A Plane Measuring Device by A. Criminisi, I. Reid, and\n% A. Zisserman\n\n% input check\nif ~exist('X','var') || isempty(X), error('Need X'); end\nif ~exist('Y','var') || isempty(Y), error('Need Y'); end\nif ~all(size(X) == size(Y)), error('X and Y need to be the same size'); end\n\n% some variables needed\nn = size(Y,1);\nmy1 = ones(n,1);\nmy0 = zeros(n,3);\n\n% compute xfm\nB = [ X my1 my0 -X(:,1).*Y(:,1) -X(:,2).*Y(:,1) ...\n my0 X my1 -X(:,1).*Y(:,2) -X(:,2).*Y(:,2)];\nB = reshape (B', 8 , n*2)';\n\nD = reshape (Y', n*2 , 1 );\nl = inv(B' * B) * B' * D;\nA = reshape([l(1:6)' 0 0 1 ],3,3)';\nC = [l(7:8)' 1];\n\n\n% now transform\nX = [X my1]';\nXt = ((A*X) ./ (ones(3,1)*(C*X)))';\nXt = Xt(:,1:2);\n\n% xfm matrices\nxfm = [A;C];\nreturn\n\n\n", "meta": {"author": "vistalab", "repo": "vistasoft", "sha": "7f0102c696c091c858233340cc7e1ab02f064d4c", "save_path": "github-repos/MATLAB/vistalab-vistasoft", "path": "github-repos/MATLAB/vistalab-vistasoft/vistasoft-7f0102c696c091c858233340cc7e1ab02f064d4c/mrBOLD/Analysis/retinotopyModel/EyeTrack/perspective_xfm.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009549929797, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.7415079212619031}} {"text": "% SQRT_COV - Factorizes a positive semi-definite symmetric matrix.\n%\n% V = SQRT_COV(A)\n%\n% The matrix A must be positive semi-definite and symmetric. The resulting\n% matrix V is such that V*V'=A. \n\n% Last modified 2011-10-20\n% Copyright (c) Jaakko Luttinen (jaakko.luttinen@aalto.fi)\n\nfunction V = sqrt_cov(A)\n\n[L,D] = ldl(A);\nD(D<0) = 0;\nV = L * sqrt(D);\n", "meta": {"author": "jluttine", "repo": "matlab", "sha": "63406c7782b0869948f06e1dbc594460c165d24e", "save_path": "github-repos/MATLAB/jluttine-matlab", "path": "github-repos/MATLAB/jluttine-matlab/matlab-63406c7782b0869948f06e1dbc594460c165d24e/matrix_computations/sqrt_cov.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9149009549929797, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.7415079212619031}} {"text": "function [C_tri]=transitivity_bu(A)\n%TRANSITIVITY_BU Transitivity\n%\n% T = transitivity_bu(A);\n%\n% Transitivity is the ratio of 'triangles to triplets' in the network.\n% (A classical version of the clustering coefficient).\n%\n% Input: A binary undirected connection matrix\n%\n% Output: T transitivity scalar\n%\n% Reference: e.g. Humphries et al. (2008) Plos ONE 3: e0002051\n%\n%\n% Alexandros Goulas, Maastricht University, 2010\n\n C_tri = trace(A^3) / (sum(sum(A^2)) - trace(A^2));\n\nreturn;", "meta": {"author": "fieldtrip", "repo": "fieldtrip", "sha": "c2039be598a02d86b39aae76bfa7aaa720f9801c", "save_path": "github-repos/MATLAB/fieldtrip-fieldtrip", "path": "github-repos/MATLAB/fieldtrip-fieldtrip/fieldtrip-c2039be598a02d86b39aae76bfa7aaa720f9801c/external/bct/transitivity_bu.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9473810466522863, "lm_q2_score": 0.7826624738835051, "lm_q1q2_score": 0.7414795936832227}} {"text": "function [ x, seed ] = pareto_sample ( a, b, seed )\n\n%*****************************************************************************80\n%\n%% PARETO_SAMPLE samples the Pareto PDF.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 19 September 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real A, B, the parameters of the PDF.\n% 0.0 < A.\n% 0.0 < B.\n%\n% Input, integer SEED, a seed for the random number generator.\n%\n% Output, real X, a sample of the PDF.\n%\n% Output, integer SEED, an updated seed for the random number generator.\n%\n [ cdf, seed ] = r8_uniform_01 ( seed );\n\n x = pareto_cdf_inv ( cdf, a, b );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/prob/pareto_sample.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8807970842359877, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.7414775790295524}} {"text": "function [lambda_vec, error_train, error_val] = ...\n validationCurve(X, y, Xval, yval)\n%VALIDATIONCURVE Generate the train and validation errors needed to\n%plot a validation curve that we can use to select lambda\n% [lambda_vec, error_train, error_val] = ...\n% VALIDATIONCURVE(X, y, Xval, yval) returns the train\n% and validation errors (in error_train, error_val)\n% for different values of lambda. You are given the training set (X,\n% y) and validation set (Xval, yval).\n%\n\n% Selected values of lambda (you should not change this)\nlambda_vec = [0 0.001 0.003 0.01 0.03 0.1 0.3 1 3 10]';\n\n% You need to return these variables correctly.\nerror_train = zeros(length(lambda_vec), 1);\nerror_val = zeros(length(lambda_vec), 1);\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Fill in this function to return training errors in \n% error_train and the validation errors in error_val. The \n% vector lambda_vec contains the different lambda parameters \n% to use for each calculation of the errors, i.e, \n% error_train(i), and error_val(i) should give \n% you the errors obtained after training with \n% lambda = lambda_vec(i)\n%\n% Note: You can loop over lambda_vec with the following:\n%\n% for i = 1:length(lambda_vec)\n% lambda = lambda_vec(i);\n% % Compute train / val errors when training linear \n% % regression with regularization parameter lambda\n% % You should store the result in error_train(i)\n% % and error_val(i)\n% ....\n% \n% end\n%\n%\n\n\nfor i=1:length(lambda_vec)\n [theta] = trainLinearReg(X,y,lambda_vec(i));\n [error_train(i),~] = linearRegCostFunction(X,y,theta,0);\n [error_val(i),~] = linearRegCostFunction(Xval,yval,theta,0);\nend;\n\n\n\n\n\n\n\n% =========================================================================\n\nend\n", "meta": {"author": "1094401996", "repo": "machine-learning-coursera", "sha": "e53d1021a08b0f2ab7e0840d9807ab14e24ea9bb", "save_path": "github-repos/MATLAB/1094401996-machine-learning-coursera", "path": "github-repos/MATLAB/1094401996-machine-learning-coursera/machine-learning-coursera-e53d1021a08b0f2ab7e0840d9807ab14e24ea9bb/problem_sets/ex5/validationCurve.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256313782276, "lm_q2_score": 0.8807970748488297, "lm_q1q2_score": 0.7414775536507121}} {"text": "function [A, C, Z] = ldsPca(X, k, m)\n% Subspace method for learning linear dynamic system.\n% Input:\n% X: d x n data matrix\n% k: dimension of hidden variable\n% m: stacking order for the Hankel matrix\n% Output:\n% A: k x k transition matrix\n% C: k x d emission matrix\n% Z: k x n latent variable\n% Y: d x n reconstructed data\n% reference: Bayesian Reasoning and Machine Learning (BRML) chapter 24.5.3 p.507\n% Written by Mo Chen (sth4nth@gmail.com).\n[d,n] = size(X);\nH = reshape(X(:,hankel(1:m,m:n)),d*m,[]);\n[U,S,V] = svd(H,'econ');\nC = U(1:d,1:k);\nZ = S(1:k,1:k)*V(:,1:k)';\nA = Z(:,2:end)/Z(:,1:end-1); % estimated transition\n% Y = C*Z; % reconstructions", "meta": {"author": "PRML", "repo": "PRMLT", "sha": "baac49f643db6b39e75307d3b21307b32b29a7a9", "save_path": "github-repos/MATLAB/PRML-PRMLT", "path": "github-repos/MATLAB/PRML-PRMLT/PRMLT-baac49f643db6b39e75307d3b21307b32b29a7a9/chapter13/LDS/ldsPca.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768557238084, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.7414701961638309}} {"text": "function [lList,rList]=genAllLRBinTreesAlt(n)\n%%GENALLLRBINTREESALT Generate representations of all binary trees having n\n% nodes. l(0+1) gives the root node index. l(i+1) and\n% r(i) then give the left and right descendents of node\n% i. If there is a zero, then there is no descendent.\n% The structure of the (left-right) relationships is\n% what is unique, not the specific nodes. That is, the\n% identity of the root node does not really matter. For\n% example, node 1 will never have a left neighbor and\n% node 4 will never have a right neighbor. However,\n% independent of node labels, all binary trees are\n% formed. The format of the output differs from the\n% function genAllLRBinTrees.\n%\n%INPUTS: n The number of nodes that will be in the trees. n>=1.\n%\n%OUTPUTS: lList The (n+1)XnumTrees lists of left links, where lList(i+1,k)\n% is the left link of node i in tree k with lList(0+1,k)\n% being the root.\n% rList The nXnumTrees lists of right links.\n%\n%This function implements Algorithm L of Section 7.2.1.6 of [1]. The number\n%of binary trees is CatalanNumber(n).\n%\n%EXAMPLE:\n%To recreate the list of links in Table 3 of Section 7.2.1.6 of [1], one\n%can use\n% [lList,rList]=genAllLRBinTreesAlt(4)\n%\n%REFERENCES:\n%[1] D. E. Knuth, The Art of Computer Programming. Vol. 4A: Combinatorial\n% Algorithms, Part I, Boston: Addison-Wesley, 2011.\n%\n%October 2018 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nnumBinTrees=CatalanNumber(n);\n\n%Allocate space\nlList=zeros(n+1,numBinTrees);\nrList=zeros(n,numBinTrees);\nkList=zeros(n,numBinTrees);\n\nk=zeros(n,1);\no=zeros(n+1,1);\nl=zeros(n+1,1);\nr=zeros(n,1);\n\n%Step L1\nl((1:n)+1)=0;\nr(1:(n-1))=2:n;\nk(1:n)=0:(n-1);\no((1:n)+1)=-1;\nl(0+1)=1;\no(0+1)=1;\nr(n)=0;\n\nfor curTree=1:numBinTrees\n %Step L2\n lList(:,curTree)=l;\n rList(:,curTree)=r;\n kList(:,curTree)=k;\n j=n;\n p=0; \n \n while(1)\n %Step L3\n if(o(j+1)>0)\n m=l(j+1);\n\n if(m~=0)\n %Step L5 \n if(j==0)\n return;\n end\n l(j+1)=r(m);\n r(m)=j;\n k(j)=m;\n x=k(m);\n if(x==0)\n l(p+1)=m;\n else\n r(x)=m;\n end\n break;\n else\n %p=j;\n o(j+1)=-o(j+1);\n j=j-1;\n continue;\n end\n else%o(j+1)<0\n m=k(j);\n\n if(m~=0)\n %Step L4\n r(m)=l(j+1);\n l(j+1)=m;\n x=k(m);\n k(j)=x;\n if(x==0)\n l(p+1)=j;\n else\n r(x)=j;\n end\n break;\n else\n p=j;\n o(j+1)=-o(j+1);\n j=j-1;\n continue;\n end\n end\n end\nend\nend\n\n%LICENSE:\n%\n%The source code is in the public domain and not licensed or under\n%copyright. The information and software may be used freely by the public.\n%As required by 17 U.S.C. 403, third parties producing copyrighted works\n%consisting predominantly of the material produced by U.S. government\n%agencies must provide notice with such work(s) identifying the U.S.\n%Government material incorporated and stating that such material is not\n%subject to copyright protection.\n%\n%Derived works shall not identify themselves in a manner that implies an\n%endorsement by or an affiliation with the Naval Research Laboratory.\n%\n%RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF THE\n%SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY THE NAVAL\n%RESEARCH LABORATORY FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE ACTIONS\n%OF RECIPIENT IN THE USE OF THE SOFTWARE.\n", "meta": {"author": "USNavalResearchLaboratory", "repo": "TrackerComponentLibrary", "sha": "9f6e329de5be06a371757c4b853200beb6def2d0", "save_path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary", "path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary/TrackerComponentLibrary-9f6e329de5be06a371757c4b853200beb6def2d0/Mathematical_Functions/Combinatorics/genAllLRBinTreesAlt.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473779969194, "lm_q2_score": 0.849971181358171, "lm_q1q2_score": 0.7414701314307445}} {"text": "function varargout = slogfrac(varargin)\n%logfrac\n%\n% y = SLOGFRAC(x)\n%\n% Computes/declares log(1 + x(1)/x(2))\n\nswitch class(varargin{1})\n case 'double'\n x = varargin{1}; \n % Safe version with defined negative values (helps fmincon when\n % outside feasible region) \n if all(x==0)\n varargout{1} = log(2);% ?definition...\n elseif x(1)==0\n varargout{1} = log(1);\n else\n aux = 1 + (x(1)./(x(2)+sqrt(eps)));\n if aux <= 0\n varargout{1} = -15;\n else\n varargout{1} = log(1 + (x(1)./(x(2)+sqrt(eps))));\n end\n \n end\n \n case 'sdpvar'\n if min(size(varargin{1}))>1\n error('SLOGFRAC only defined for vector arguments');\n else\n varargout{1} = yalmip('define',mfilename,varargin{1});\n end\n\n case 'char' \n \n operator = CreateBasicOperator('callback');\n operator.range = [-inf inf];\n operator.domain = [-inf inf];\n operator.bounds = @bounds; \n operator.derivative = @(x) ([1./(x(1)+x(2)+sqrt(eps));1./(x(1)+x(2)+sqrt(eps))-(x(2)+sqrt(eps)).^-1]);\n \n varargout{1} = [];\n varargout{2} = operator;\n varargout{3} = varargin{3};\n\n otherwise\n error(['SDPVAR/' upper(mfilename) ' called with weird argument']);\nend\n\nfunction [L,U] = bounds(xL,xU)\n\n% Derive bounds on x1/x2\nz = [xL(1)./xL(2) xU(1)./xL(2) xL(1)./xU(2) xU(1)./xU(2)];\nfL = min(z);\nfU = max(z);\n\nif fL <= -1\n L = -inf;\nelse\n L = log(1 + fL);\nend\nif fU <= -1\n U = -inf;\nelse\n U = log(1 + fU);\nend\n\n\n", "meta": {"author": "yalmip", "repo": "YALMIP", "sha": "f6d5a6d4222a4d722de30bffb43cae4b3e13b860", "save_path": "github-repos/MATLAB/yalmip-YALMIP", "path": "github-repos/MATLAB/yalmip-YALMIP/YALMIP-f6d5a6d4222a4d722de30bffb43cae4b3e13b860/operators/slogfrac.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391706552536, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.7413608727069397}} {"text": "function [kf] = ext_kalman_filter(F, G, H, u, Q, R, time, last_measure, kf, P)\n\n%EXT_KALMAN_FILTER - This is the extended Kalman filter.\n%\n% Synthax: \n%\n% Inputs:\n% uu - state variables, delta, wind\n% kf.x_prev - previous a posteriori state estimate\n% kf.P_prev - previous a posteriori estimate covariance\n% last_measure- (time, sensor measure)\n% P - parameters\n% \n% Outputs:\n% kf.x - a priori/a posteriori state estimate\n% kf.P - a priori/a posteriori estimate covariance\n% kf.z_res - post-fit residual\n\n% A -> F\n% B -> G\n% C -> H\n\n% Q - covariance of the zero-mean Gaussian noise on x_dot\n% R - covariance of the zero-mean Gaussian noise on y\n\ntime_m = last_measure(:,1);\nz_m = last_measure(:,2);\n\n% prediction (a priori)\nkf.x = F * kf.x_prev + G * u; % a priori state estimate\nkf.P = F * kf.P_prev * (F') + Q; % a priori estimate covariance\n\n% update (a posteriori)\nif time - time_m < P.dt\n kf.z_tilde = z_m - H*kf.x; % innovation (a priori residual)\n S = R + H*kf.P*(H'); % innovation covariance\n K = kf.P*(H')/S; % optimal kalman gain\n kf.x = kf.x + K*kf.z_tilde; % a posteriori state estimate\n kf.P = kf.P - K*S*(K'); % a posteriori estimate covariance\nend\n\nkf.z_res = z_m - H*kf.x; % a posteriori residual\n\nend\n\n", "meta": {"author": "lis-epfl", "repo": "swarmlab", "sha": "3574deddd2e4fdcc5696d08f93d6e888f45c8ecc", "save_path": "github-repos/MATLAB/lis-epfl-swarmlab", "path": "github-repos/MATLAB/lis-epfl-swarmlab/swarmlab-3574deddd2e4fdcc5696d08f93d6e888f45c8ecc/estimation/ext_kalman_filter.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109713976399, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.7413138051531791}} {"text": "function ellipsoid_monte_carlo_test01 ( )\n\n%*****************************************************************************80\n%\n%% ELLIPSOID_MONTE_CARLO_TEST01 uses ELLIPSOID_SAMPLE on a 2D ellipse centered at (0,0).\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 14 August 2014\n%\n% Author:\n%\n% John Burkardt\n%\n m = 2;\n\n a = [ ...\n 9.0, 1.0;\n 1.0, 4.0 ]';\n e_test = [ ...\n 0, 0;\n 1, 0;\n 0, 1;\n 2, 0;\n 1, 1;\n 0, 2;\n 3, 0 ]';\n r = 2.0;\n v = [ 0.0, 0.0 ]';\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'ELLIPSOID_MONTE_CARLO_TEST01\\n' );\n fprintf ( 1, ' Use ELLIPSOID_SAMPLE to estimate integrals\\n' );\n fprintf ( 1, ' in a 2D ellipse x'' * A * x <= r^2.\\n' );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Ellipsoid radius R = %g\\n', r );\n r8vec_print ( m, v, ' Ellipsoid center V:' );\n r8mat_print ( m, m, a, ' Ellipsoid matrix A:' );\n\n volume = ellipsoid_volume ( m, a, v, r );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Ellipsoid volume = %g\\n', volume );\n\n seed = 123456789;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' N 1 X Y ' );\n fprintf ( 1, ' X^2 XY Y^2 X^3\\n' );\n fprintf ( 1, '\\n' );\n\n n = 1;\n\n while ( n <= 65536 )\n\n [ x, seed ] = ellipsoid_sample ( m, n, a, v, r, seed );\n\n fprintf ( 1, ' %8d', n );\n\n for j = 1 : 7\n\n e(1:m) = e_test(1:m,j);\n\n value = monomial_value ( m, n, e, x );\n\n result = volume * sum ( value(1:n) ) / n;\n\n fprintf ( 1, ' %14.6g', result );\n\n end\n\n fprintf ( 1, '\\n' );\n\n n = 2 * n;\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/ellipsoid_monte_carlo/ellipsoid_monte_carlo_test01.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762114, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.7412913452685836}} {"text": "%% Author: epokh\n%% Website: www.epokh.org/drupy\n%% This software is under GPL\n\nfunction [Mdh]=DHmatrix(theta,d,a,alpha)\n%%output: DH matrix\n%%input: DH parameters:\n%%theta: rotation along x(n) axis\n%%d: traslation along z(n) axis\n%%a: translation along x(n+1) axis\n%%alpha: rotation along x(n+1) axis\n%%all angles expressed in degrees\n\nMdh=[cosd(theta) -sind(theta)*cosd(alpha) sind(theta)*sind(alpha) a*cosd(theta);\n sind(theta) cosd(theta)*cosd(alpha) -cosd(theta)*sind(alpha) a*sind(theta);\n 0,sind(alpha),cosd(alpha),d;\n 0,0,0,1];\n\n\nend", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/14886-robotic-toolbox/DHmatrix.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9407897492587141, "lm_q2_score": 0.7879311931529758, "lm_q1q2_score": 0.7412775896395075}} {"text": "function disk_monte_carlo_test01 ( )\n\n%*****************************************************************************80\n%\n%% DISK_MONTE_CARLO_TEST01 uses DISK01_SAMPLE with an increasing number of points.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 03 January 2014\n%\n% Author:\n%\n% John Burkardt\n%\n e_test = [ ...\n 0, 0; ...\n 2, 0; ...\n 0, 2; ...\n 4, 0; ...\n 2, 2; ...\n 0, 4; ...\n 6, 0 ]';\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'DISK_MONTE_CARLO_TEST01\\n' );\n fprintf ( 1, ' Use DISK01_SAMPLE to estimate integrals in the unit disk.\\n' );\n\n seed = 123456789;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' N 1 X^2 Y^2 ' );\n fprintf ( 1, ' X^4 X^2Y^2 Y^4 X^6\\n' );\n fprintf ( 1, '\\n' );\n\n n = 1;\n\n while ( n <= 65536 )\n\n [ x, seed ] = disk01_sample ( n, seed );\n\n fprintf ( 1, ' %8d', n );\n for j = 1 : 7\n\n e(1:2) = e_test(1:2,j);\n\n value = monomial_value ( 2, n, e, x );\n\n result(j) = disk01_area ( ) * sum ( value(1:n) ) / n;\n fprintf ( 1, ' %14.6g', result(j) );\n end\n fprintf ( 1, '\\n' );\n\n n = 2 * n;\n\n end\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Exact' );\n for j = 1 : 7\n\n e(1:2) = e_test(1:2,j);\n\n result(j) = disk01_monomial_integral ( e );\n fprintf ( 1, ' %14.6g', result(j) );\n end\n\n fprintf ( 1, '\\n' );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/disk_monte_carlo/disk_monte_carlo_test01.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045907347107, "lm_q2_score": 0.8354835391516132, "lm_q1q2_score": 0.7412448314185947}} {"text": "function res = Fspikernel(seqS,seqT,N,lam,mu,p)\n\n%spikernel kernel function\n%\n% This code implements the spikernel function, defined in:\n% Spikernels: Embedding Spiking Neurons in Inner-Product Spaces\n% Lavi Shpigelman, Yoram Singer, Rony Paz and Eilon Vaadia\n% Advances in Neural Information Processing Systems (NIPS) 15\n% MIT Press, Cambridge, MA, 2003.\n%\n% res= Fspikernel (seqS,seqT,N,lam,mu,p)\n%\n% returns res = K(seqS,seqT) = sum_{i=1}^N p^i K_i(seqS,seqT) where the kernel parameters are:\n%\n% Inputs\n% seqS and seqT are the two sequences to be compared.\n% Each row of these sequences is one 'letter' in the sequence (must be of same length)\n% Their column lengths are the sequence lengths (can be of different length).\n% N = max subsequence lengths (the kernel compares subsequences of lengths 1 to N and returns a sum of kernels)\n% lam=\\lambda parameter from article\n% mu=\\mu parameter from article\n% p= the q prarameter in the article - the parameter that is used in the sum of kernels to weigh them differently\n%\n% This implementation assumes that the function d(x,y) is the squared \\ell_2 norm\n%\n\n% ------------- parameter check -------------------------\nlens=size(seqS,1);\nlent=size(seqT,1);\nq=size(seqS,2);\n\nif (q~=size(seqT,2))\n error('the dimesions of the sequence letters in seqS and seqT must be the same')\nend\nif (length(N)~=1)\n error('N should be a scalar value');\nend\nif (length(lam)~=1)\n error('lam should be a scalar value');\nend\nif (length(mu)~=1)\n error('mu should be a scalar value');\nend\nif (length(p)~=1)\n error('p should be a scalar value');\nend\n% --------------------------------------------------------\n\ndmu = mu.^(0.5*( repmat( sum( seqS.^2, 2), 1, lent) + ...\n ( repmat( sum(seqT.^2, 2), 1, lens))' - 2*seqS*seqT'))';\n\nres = fspike( N, p, lam, dmu);\n", "meta": {"author": "canlab", "repo": "CanlabCore", "sha": "af242e120f0480c4feaeea90471c015a14f1f60e", "save_path": "github-repos/MATLAB/canlab-CanlabCore", "path": "github-repos/MATLAB/canlab-CanlabCore/CanlabCore-af242e120f0480c4feaeea90471c015a14f1f60e/CanlabCore/External/spider/functions/Fspikernel.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026573249612, "lm_q2_score": 0.8080672204860316, "lm_q1q2_score": 0.7412422086490321}} {"text": "function [yi, ypi] = hermint(x, y, yp, xi, c)\n\n% HERMINT 1-D piecewise hermite interpolation\n% HERMINT(X,Y,YP,XI,C) interpolates to find YI, the values of\n% the underlying function Y at the points in the array XI,\n% using piecewise hermite interpolation. X and Y must be\n% vectors of length N.\n%\n% C specifies the number of data points to use in the\n% interpolation. The default is to use all points.\n%\n% [YI,YPI] = HERMINT() also returns the interpolated derivative\n% of the underlying function Y at points XI.\n\n% Joe Henning - Fall 2011\n\nif (nargin < 5)\n c = 0;\nend\n\nn = length(x);\n\nif (n < c)\n fprintf('??? Bad c input to hermint ==> c <= length(x)\\n');\n yi = [];\n ypi = [];\n return\nend\n\nfor i = 1:length(xi)\n % Find the right place in the table by means of a bisection.\n klo = 1;\n khi = n;\n while (khi-klo > 1)\n k = fix((khi+klo)/2.0);\n if (x(k) > xi(i))\n khi = k;\n else\n klo = k;\n end\n end\n \n h = x(khi) - x(klo);\n if (h == 0.0)\n fprintf('??? Bad x input to hermint ==> x values must be distinct\\n');\n yi(i) = NaN;\n ypi(i) = NaN;\n continue;\n end\n \n isiny = 0;\n for k = 1:n\n if (xi(i) == x(k))\n yi(i) = y(k);\n ypi(i) = yp(k);\n isiny = 1;\n break\n end\n end\n \n if (isiny)\n continue\n end\n\n % Evaluate hermite polynomial\n yi(i) = 0;\n ypi(i) = 0;\n if (c == 0)\n for k = 1:n\n f = 0;\n g = 0;\n h = 1;\n \n for m = 1:n\n if (k ~= m)\n f = f + 1/(x(k)-x(m));\n h = h*(xi(i)-x(m))/(x(k)-x(m));\n end\n end\n \n for m = 1:n\n if (k ~= m)\n g = g + h/(xi(i)-x(m));\n end\n end\n \n a = h*h;\n b = 2*h*g;\n u = xi(i) - x(k);\n \n b1 = a*u;\n b2 = b*u + a;\n a1 = a - 2*f*b1;\n a2 = b - 2*f*b2;\n \n yi(i) = yi(i) + a1*y(k) + b1*yp(k);\n ypi(i) = ypi(i) + a2*y(k) + b2*yp(k);\n end\n else\n if (mod(c,2) == 0) % even\n c2 = c/2;\n if (klo < c2)\n klo = c2;\n end\n if (klo > n-c2)\n klo = n-c2;\n end\n khi = klo + 1;\n for k = klo-(c2-1):klo+c2\n f = 0;\n g = 0;\n h = 1;\n \n for m = klo-(c2-1):klo+c2\n if (k ~= m)\n f = f + 1/(x(k)-x(m));\n h = h*(xi(i)-x(m))/(x(k)-x(m));\n end\n end\n \n for m = klo-(c2-1):klo+c2\n if (k ~= m)\n g = g + h/(xi(i)-x(m));\n end\n end\n \n a = h*h;\n b = 2*h*g;\n u = xi(i) - x(k);\n \n b1 = a*u;\n b2 = b*u + a;\n a1 = a - 2*f*b1;\n a2 = b - 2*f*b2;\n \n yi(i) = yi(i) + a1*y(k) + b1*yp(k);\n ypi(i) = ypi(i) + a2*y(k) + b2*yp(k);\n end\n else % odd\n c2 = floor(c/2);\n if (klo < c2+1)\n klo = c2+1;\n end\n if (klo > n-c2)\n klo = n-c2;\n end\n khi = klo + 1;\n for k = klo-c2:klo+c2\n f = 0;\n g = 0;\n h = 1;\n \n for m = klo-c2:klo+c2\n if (k ~= m)\n f = f + 1/(x(k)-x(m));\n h = h*(xi(i)-x(m))/(x(k)-x(m));\n end\n end\n \n for m = klo-c2:klo+c2\n if (k ~= m)\n g = g + h/(xi(i)-x(m));\n end\n end\n \n a = h*h;\n b = 2*h*g;\n u = xi(i) - x(k);\n \n b1 = a*u;\n b2 = b*u + a;\n a1 = a - 2*f*b1;\n a2 = b - 2*f*b2;\n \n yi(i) = yi(i) + a1*y(k) + b1*yp(k);\n ypi(i) = ypi(i) + a2*y(k) + b2*yp(k);\n end\n end\n end\nend\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/36800-interpolation-utilities/hermint.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026528034426, "lm_q2_score": 0.8080672204860316, "lm_q1q2_score": 0.7412422049953412}} {"text": "function [evects,evals] = pca(X)\n% [evects,evals] = pca(X)\n%\n% finds principal components of \n%\n% input: \n% X dxn matrix (each column is a dx1 input vector)\n% \n% output: \n% evects columns are principal components (leading from left->right)\n% evals corresponding eigenvalues\n%\n% See also applypca\n%\n% copyright by Kilian Q. Weinberger, 2006\n\n[d,N] = size(X);\n\nmm = mean(X,2);\nX = X - mm*ones(1,N); % remove mean from data\n\ncc = cov(X',1); % compute covariance \n[cvv,cdd] = eig(cc); % compute eignvectors\n[zz,ii] = sort(diag(-cdd)); % sort according to eigenvalues\nevects = cvv(:,ii); % pick leading eigenvectors\ncdd = diag(cdd); % extract eigenvalues\nevals = cdd(ii); % sort eigenvalues\n\n\n", "meta": {"author": "zhunzhong07", "repo": "IDE-baseline-Market-1501", "sha": "8be027b5e45adce1d8ea381cc5a17ec20ed521e5", "save_path": "github-repos/MATLAB/zhunzhong07-IDE-baseline-Market-1501", "path": "github-repos/MATLAB/zhunzhong07-IDE-baseline-Market-1501/IDE-baseline-Market-1501-8be027b5e45adce1d8ea381cc5a17ec20ed521e5/market_evaluation/KISSME/toolbox/lib/LMNN/pca.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9173026482819238, "lm_q2_score": 0.8080672066194946, "lm_q1q2_score": 0.7412421886218389}} {"text": "function b = r8blt_vxm ( n, ml, a, x )\n\n%*****************************************************************************80\n%\n%% R8BLT_VXM multiplies a vector by a R8BLT matrix.\n%\n% Discussion:\n%\n% The R8BLT storage format is appropriate for a banded lower triangular matrix.\n% The matrix is assumed to be zero below the ML-th subdiagonal.\n% The matrix is stored in an ML+1 by N array, in which the diagonal\n% appears in the first row, followed by successive subdiagonals.\n% Columns are preserved.\n%\n% Example:\n%\n% N = 5, ML = 2\n%\n% A11 0 0 0 0\n% A21 A22 0 0 0\n% A31 A32 A33 0 0\n% 0 A42 A43 A44 0\n% 0 0 A53 A54 A55\n% --- ---\n% ---\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 23 March 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the order of the matrix.\n%\n% Input, integer ML, the lower bandwidth.\n%\n% Input, real A(ML+1,N), the R8BLT matrix.\n%\n% Input, real X(N), the vector to be multiplied by A.\n%\n% Output, real B(N), the product X*A.\n%\n b(1:n) = 0.0;\n\n for i = 1 : n\n jlo = max ( 1, i - ml );\n jhi = i;\n for j = jlo : jhi\n b(j) = b(j) + x(i) * a(i-j+1,j);\n end\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/linplus/r8blt_vxm.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379297, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.7412225560141066}} {"text": "function [ o, x, w ] = en_r2_03_2 ( n )\n\n%*****************************************************************************80\n%\n%% EN_R2_03_2 implements the Stroud rule 3.2 for region EN_R2.\n%\n% Discussion:\n%\n% The rule has order O = 2^N.\n%\n% The rule has precision P = 3.\n%\n% EN_R2 is the entire N-dimensional space with weight function\n%\n% w(x) = exp ( - x1^2 - x2^2 ... - xn^2 ) \n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 19 January 2010\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Arthur Stroud,\n% Approximate Calculation of Multiple Integrals,\n% Prentice Hall, 1971,\n% ISBN: 0130438936,\n% LC: QA311.S85.\n%\n% Parameters:\n%\n% Input, integer N, the spatial dimension.\n%\n% Output, integer O, the order.\n%\n% Output, real X(N,O), the abscissas.\n%\n% Output, real W(O), the weights.\n%\n o = 2^n;\n volume = sqrt ( pi^n );\n\n a = volume / o;\n r = sqrt ( 1 / 2 );\n\n x = zeros ( n, o );\n w = zeros ( o, 1 );\n\n k = 0;\n%\n% 2^N points.\n%\n k = k + 1;\n x(1:n,k) = - r;\n w(k) = a;\n more = 1;\n\n while ( more )\n more = 0;\n for i = n : -1 : 1\n if ( x(i,k) < 0.0 )\n k = k + 1;\n x(1:n,k) = x(1:n,k-1);\n x(i,k) = + r;\n x(i+1:n,k) = - r;\n w(k) = a;\n more = 1;\n break;\n end\n end\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/stroud/en_r2_03_2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888303, "lm_q2_score": 0.8311430415844385, "lm_q1q2_score": 0.7412225496036998}} {"text": "function [sMin,sMax,s0]=projEllipseOntoLine(z,A,gammaVal,x0,v)\n%%PROJELLIPSEONTOLINE Determine the orthogonal projection of an ellipse or\n% ellipsoid onto a line.\n%\n%INPUTS: z The numDimX1 center of the ellipsoid.\n% A A numDimXnumDim symmetric, positive definite matrix that\n% specifies the size and shape of the ellipse or ellipsoid, where\n% a point zp is on the ellipse/ellipsoid if\n% (zp-z)'*A*(zp-z)=gammaVal.\n% gammaVal The threshold for declaring a point to be in the ellipsoid. If\n% an empty matrix is passed, the default value of 1 is used.\n% x0,v Two numDimX1 vectors that specify the line. A point y is on the\n% line if y=x0+s*v, where s is a scalar quantity.\n%\n%OUTPUTS: sMin,sMax The range of values of s on the line y=x0+s*v onto\n% which the ellipsoid is orthogonally projected. These\n% are scalar quantities.\n%\n%The mathematics for projecting an ellipsoid onto a line are described in\n%Section 12 of [1].\n%\n%EXAMPLE:\n% A=[1,0;\n% 0,10];\n% M=[0.413074198133900, 0.910697373904216;\n% -0.910697373904216, 0.413074198133900];%A rotation matrix\n% A=M*A*M';\n% z=[5;6];\n% x0=[0;0];\n% v=[1;2];\n% [sMin,sMax,s0]=projEllipseOntoLine(z,A,[],x0,v);\n% figure(1)\n% clf\n% hold on\n% axis([-0.5, 7.5, 2, 10])%Same size in x and y\n% axis square\n% drawEllipse(z,A,1,'b','linewidth',2)\n% %Draw a segment of the line.\n% xStart=x0+v;\n% xEnd=x0+5*v;\n% plot([xStart(1);xEnd(1)],[xStart(2);xEnd(2)],'-k','linewidth',4)\n% %Draw the segment of the orthogonal projection onto the line.\n% xStart=x0+sMin*v;\n% xEnd=x0+sMax*v;\n% plot([xStart(1);xEnd(1)],[xStart(2);xEnd(2)],'-r','linewidth',2)\n% %Draw the line from the center of the ellipse to the place on the line onto\n% %which it is orthogonally projected.\n% xS0=x0+s0*v;\n% plot([z(1);xS0(1)],[z(2);xS0(2)],'--c')\n%\n%REFERENCES:\n%[1] S. B. Pope, \"Algorithms for ellipsoids,\" Cornell University, Tech.\n% Rep. FDA-08-01, Feb. 2008. [Online].\n% Available: https://tcg.mae.cornell.edu/pubs/Pope_FDA_08.pdf\n%\n%May 2016 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nif(isempty(gammaVal))\n gammaVal=1; \nend\n\nA=A/gammaVal;\n\nL=chol(A,'lower');\n\ns0=v'*(z-x0)/(v'*v);\nw=norm(L\\v/(v'*v));\n\nsMin=s0+w;\nsMax=s0-w;\nend\n\n%LICENSE:\n%\n%The source code is in the public domain and not licensed or under\n%copyright. The information and software may be used freely by the public.\n%As required by 17 U.S.C. 403, third parties producing copyrighted works\n%consisting predominantly of the material produced by U.S. government\n%agencies must provide notice with such work(s) identifying the U.S.\n%Government material incorporated and stating that such material is not\n%subject to copyright protection.\n%\n%Derived works shall not identify themselves in a manner that implies an\n%endorsement by or an affiliation with the Naval Research Laboratory.\n%\n%RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF THE\n%SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY THE NAVAL\n%RESEARCH LABORATORY FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE ACTIONS\n%OF RECIPIENT IN THE USE OF THE SOFTWARE.\n", "meta": {"author": "USNavalResearchLaboratory", "repo": "TrackerComponentLibrary", "sha": "9f6e329de5be06a371757c4b853200beb6def2d0", "save_path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary", "path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary/TrackerComponentLibrary-9f6e329de5be06a371757c4b853200beb6def2d0/Mathematical_Functions/Geometry/projEllipseOntoLine.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110368115781, "lm_q2_score": 0.8311430520409023, "lm_q1q2_score": 0.7412225469793365}} {"text": "function [MBox] = MBoxtest(X,alpha)\n% Multivariate Statistical Testing for the Homogeneity of Covariance Matrices by the Box's M. \n%\n% Syntax: function [MBox] = MBoxtest(X,alpha) \n% \n% Inputs:\n% X - data matrix (Size of matrix must be n-by-(1+p); sample=column 1, variables=column 2:p). \n% alpha - significance level (default = 0.05). \n% Output:\n% MBox - the Box's M statistic.\n% Chi-sqr. or F - the approximation statistic test.\n% df's - degrees' of freedom of the approximation statistic test.\n% P - observed significance level.\n% \n% If the groups sample-size is at least 20 (sufficiently large), Box's M test\n% takes a Chi-square approximation; otherwise it takes an F approximation.\n%\n% Example: For a two groups (g = 2) with three independent variables (p = 3), we \n% are interested to test the homogeneity of covariances matrices with a \n% significance level = 0.05. The two groups have the same sample-size\n% n1 = n2 = 5.\n% Group\n% --------------------------------------- \n% 1 2\n% ---------------------------------------\n% x1 x2 x3 x1 x2 x3\n% ---------------------------------------\n% 23 45 15 277 230 63\n% 40 85 18 153 80 29\n% 215 307 60 306 440 105\n% 110 110 50 252 350 175\n% 65 105 24 143 205 42\n% ---------------------------------------\n%\n% Total data matrix must be:\n% X=[1 23 45 15;1 40 85 18;1 215 307 60;1 110 110 50;1 65 105 24;\n% 2 277 230 63;2 153 80 29;2 306 440 105;2 252 350 175;2 143 205 42];\n%\n% Calling on Matlab the function: \n% MBoxtest(X,0.05)\n%\n% Answer is:\n%\n% ------------------------------------------------------------\n% MBox F df1 df2 P\n% ------------------------------------------------------------\n% 27.1622 2.6293 6 463 0.0162\n% ------------------------------------------------------------\n% Covariance matrices are significantly different.\n%\n\n% Created by A. Trujillo-Ortiz and R. Hernandez-Walls\n% Facultad de Ciencias Marinas\n% Universidad Autonoma de Baja California\n% Apdo. Postal 453\n% Ensenada, Baja California\n% Mexico.\n% atrujo@uabc.mx\n% And the special collaboration of the post-graduate students of the 2002:2\n% Multivariate Statistics Course: Karel Castro-Morales, Alejandro Espinoza-Tenorio,\n% Andrea Guia-Ramirez, Raquel Muniz-Salazar, Jose Luis Sanchez-Osorio and\n% Roberto Carmona-Pina.\n% November 2002.\n%\n% To cite this file, this would be an appropriate format:\n% Trujillo-Ortiz, A., R. Hernandez-Walls, K. Castro-Morales, A. Espinoza-Tenorio, A. Guia-Ramirez\n% and R. Carmona-Pina. (2002). MBoxtest: Multivariate Statistical Testing for the Homogeneity of \n% Covariance Matrices by the Box's M. A MATLAB file. [WWW document]. URL http://www.mathworks.com/\n% matlabcentral/fileexchange/loadFile.do?objectId=2733&objectType=FILE\n%\n% References:\n% \n% Stevens, J. (1992), Applied Multivariate Statistics for Social Sciences. 2nd. ed.\n% New-Jersey:Lawrance Erlbaum Associates Publishers. pp. 260-269.\n \nif nargin < 1, \n error('Requires at least one input arguments.'); \nend;\n\nif nargin < 2, \n alpha = 0.05; %(default)\nend; \n\nif (alpha <= 0 | alpha >= 1)\n fprintf('Warning: significance level must be between 0 and 1\\n');\n return;\nend;\n\ng = max(X(:,1)); %Number of groups.\n\nn = []; %Vector of groups-size.\nindice = X(:,1);\nfor i = 1:g\n Xe = find(indice==i);\n eval(['X' num2str(i) '= X(Xe,2);']);\n eval(['n' num2str(i) '= length(X' num2str(i) ') ;'])\n eval(['xn= n' num2str(i) ';'])\n n = [n,xn];\nend;\n\n[f,c] = size(X);\nX = X(:,2:c);\n\n[N,p]=size(X);\nr=1; \nr1=n(1);\nbandera=2;\nfor k=1:g\n if n(k)>=20;\n bandera=1;\n end\nend\n%Partition of the group covariance matrices.\nfor k=1:g\n eval(['S' num2str(k) '=cov(X(r:r1,:));';]);\n if k= alpha\n disp('Covariance matrices are not significantly different.');\n else\n disp('Covariance matrices are significantly different.');\n end\nelse\n%To obtain the F approximation we first define Co, which combined to the before C value\n%are used to estimate the denominator degrees of freedom (v2); resulting two possible cases. \nCo=(((p-1)*(p+2))/(6*(g-1)))*(suma2-(1/(deno^2)));\n if Co-(C^2)>= 0;\n\tv1=(p*(p+1)*(g-1))/2; %Numerator degrees of freedom.\n v21=fix((v1+2)/(Co-(C^2))); %Denominator degrees of freedom.\n F1=MB*((1-C-(v1/v21))/v1); %F approximation.\n P1=1-fcdf(F1,v1,v21); %Significance value associated to the observed F statistic.\ndisp(' ')\n ;\nfprintf('------------------------------------------------------------\\n');\ndisp(' MBox F df1 df2 P')\nfprintf('------------------------------------------------------------\\n');\nfprintf('%10.4f%11.4f%11.i%14.i%13.4f\\n',MB,F1,v1,v21,P1);\nfprintf('------------------------------------------------------------\\n'); \n if P1 >= alpha\n disp('Covariance matrices are not significantly different.');\n else\n disp('Covariance matrices are significantly different.');\n end\n \n else \n v1=(p*(p+1)*(g-1))/2; %Numerator degrees of freedom.\n v22=fix((v1+2)/((C^2)-Co)); %Denominator degrees of freedom.\n b=v22/(1-C-(2/v22));\n F2=(v22*MB)/(v1*(b-MB)); %F approximation.\n P2=1-fcdf(F2,v1,v22); %Significance value associated to the observed F statistic.\ndisp(' ') \n ;\nfprintf('------------------------------------------------------------\\n');\ndisp(' MBox F df1 df2 P')\nfprintf('------------------------------------------------------------\\n');\nfprintf('%10.4f%11.4f%11.i%14.i%13.4f\\n',MB,F2,v1,v22,P2);\nfprintf('------------------------------------------------------------\\n');\n \n if P2 >= alpha\n disp('Covariance matrices are not significantly different.');\n else\n disp('Covariance matrices are significantly different.');\n end\n end\nend\n", "meta": {"author": "goodshawn12", "repo": "REST", "sha": "e34ce521fcb36e7813357a9720072dd111edf797", "save_path": "github-repos/MATLAB/goodshawn12-REST", "path": "github-repos/MATLAB/goodshawn12-REST/REST-e34ce521fcb36e7813357a9720072dd111edf797/dependencies/BCILAB/dependencies/SIFT-private/external/MBoxtest/MBoxtest.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110368115781, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.7412225432492606}} {"text": "%................................................................\n\n% MATLAB codes for Finite Element Analysis\n% problem16vibrations.m\n% Timoshenko beam in free vibrations\n% AJM Ferreira 2008\n% modified by Manuel Diaz, 2013.07.25\n\n% clear memory\nclear all\n\n% E; modulus of elasticity\n% G; shear modulus\n% I: second moments of area\n% L: length of beam\n% thickness: thickness of beam\n<<<<<<< HEAD\nE=30e6; poisson = 0.30;L = 1;thickness=0.01;\n=======\nE=10e7; poisson = 0.30;L = 3;thickness=0.001;\n>>>>>>> 47f4967135b009f9128c106a6744c97a2ffd18ce\nI=thickness^3/12;\nEI=E*I;\nkapa=5/6;\nrho=1;\nA=1*thickness;\n% \n\nP = 0; % uniform pressure\n%P = -1; % uniform pressure\n% constitutive matrix\nG=E/2/(1+poisson);\nC=[ EI 0; 0 kapa*A*G];\n\n% mesh\n<<<<<<< HEAD\nnumberElements = 50; \n=======\nnumberElements = 40; \n>>>>>>> 47f4967135b009f9128c106a6744c97a2ffd18ce\nnodeCoordinates=linspace(0,L,numberElements+1);\nxx=nodeCoordinates';x=xx';\nfor i=1:size(nodeCoordinates,2)-1\n elementNodes(i,1)=i; \n elementNodes(i,2)=i+1\nend\n% generation of coordinates and connectivities\nnumberNodes=size(xx,1);\n\n% GDof: global number of degrees of freedom\nGDof=2*numberNodes; \n\n% computation of the system stiffness, force, mass\n[stiffness,force,mass]=...\n formStiffnessMassTimoshenkoBeam(GDof,numberElements,...\n elementNodes,numberNodes,xx,C,P,rho,I,thickness);\n\n% boundary conditions (simply-supported at both bords)\n%fixedNodeW =[1 ; numberNodes];\n%fixedNodeTX=[]; \n% boundary conditions (clamped at both bords)\n%fixedNodeW =[1 ; numberNodes];\n%fixedNodeTX=[1 ; numberNodes];\n% boundary conditions (cantilever)\n%fixedNodeW =[1];\n%fixedNodeTX=[1];\n<<<<<<< HEAD\n% Free-free\n%fixedNodeW =[];\n%fixedNodeTX=[];\n=======\n% Free-Free conditions\nfixedNodeW =[];\nfixedNodeTX=[];\n>>>>>>> 47f4967135b009f9128c106a6744c97a2ffd18ce\nprescribedDof=[fixedNodeW; fixedNodeTX+numberNodes];\n\n% solution (optional*)\ndisplacements=solution(GDof,prescribedDof,stiffness,force);\n\n% output displacements/reactions (optional*)\noutputDisplacementsReactions(displacements,stiffness,...\n GDof,prescribedDof)\n\n% free vibration problem\nactiveDof=setdiff([1:GDof]',[prescribedDof]);\nmodeNumber=4;\n\n[V,D]=eig(stiffness(activeDof,activeDof),...\n mass(activeDof,activeDof));\nD = diag(sqrt(D)*L*L*sqrt(rho*A/E/I));\n[D,ii] = sort(D); \n\nV1=zeros(GDof,1);\nV1(activeDof,1:modeNumber)=V(:,1:modeNumber);\n!\n% drawing eigenmodes\ndrawEigenmodes1D(modeNumber,numberNodes,V1,xx,x)\n\n\n \n\n \n\n\n\n", "meta": {"author": "wme7", "repo": "Aero-matlab", "sha": "9430008f2e3b84f28633775a44dff534e780fbac", "save_path": "github-repos/MATLAB/wme7-Aero-matlab", "path": "github-repos/MATLAB/wme7-Aero-matlab/Aero-matlab-9430008f2e3b84f28633775a44dff534e780fbac/FEM/Timoshenko_beam/Timoshenko.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314624993576758, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.7411256780056512}} {"text": "% Figure 4.16 Feedback Control of Dynamic Systems, 6e\n% Franklin, Powell, Emami\n%% script to generate Figure 4.16(a), 4.16 (b)\n% case I, P control by reaction curve data.\n% First, input the plant model and compute the reaction curve.\nsysp=tf(1,[600 70 1])\nset(sysp,'td', 5)\n\n% From the curve, kp = 6.92 for proportional control\nsysdP = tf(6.92,1)\n% To get the closed loop response, we must use a pade approximation to the\n% delay\nsyspade=pade(sysp,3);\nsysforward=syspade*sysdP;\nsysback=tf(1,1)\nsyscl=feedback(sysforward,sysback)\nfigure(1)\nclf\nstep(syscl)\ntitle('Figure 4.16a Closed loop response using Reaction Curve data')\ngtext('P')\nhold on\n%case II, PI control\n%kp = 6.22, TI=43.3\nsysdPI=6.22*tf([43.3 1],[43.3 0])\nsysforward=syspade*sysdPI;\nsyscl=feedback(sysforward,sysback)\nstep(syscl)\ngtext('PI')\nnicegrid\n%\nsysdP = tf(6.92/3,1)\n% To get the closed loop response, we must use a pade approximation to the\n% delay\nsyspade=pade(sysp,3);\nsysforward=syspade*sysdP;\nsysback=tf(1,1)\nsyscl=feedback(sysforward,sysback)\nfigure(2)\nclf\nstep(syscl)\ntitle('Figure 4.16b Closed loop response using Reaction Curve data')\ngtext('P')\nhold on\n%case II, PI control\n%kp = 6.22, TI=43.3\nsysdPI=(6.22/3)*tf([43.3 1],[43.3 0])\nsysforward=syspade*sysdPI;\nsyscl=feedback(sysforward,sysback)\nstep(syscl)\ngtext('PI')\nnicegrid;\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/26412-feedback-control-of-dynamic-systems-6th-edition-prentice-hall-2010/fig4_16.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951607140233, "lm_q2_score": 0.7931059609645724, "lm_q1q2_score": 0.7410743718587415}} {"text": "function [logml log10ml ml]=mmlikdata(X,y,n,T,q,sigma,beta0,omega0,betabar)\n\n\n% function [logml log10ml ml]=bear.mmlik(X,y,n,T,q,sigma,omega0,beta0,betabar)\n% computes the marginal likelihood for a Minesota prior, by implementing algorithm XXX\n% inputs: - matrix 'X': matrix of regressors for the VAR model (defined in 1.1.8)\n% - vector 'y': vectorised regressands for the VAR model (defined in 1.1.12)\n% - integer 'n': number of endogenous variables in the BVAR model (defined p 7 of technical guide)\n% - integer 'T': number of sample time periods (defined p 7 of technical guide)\n% - integer 'q': total number of coefficients to estimate for the BVAR model (defined p 7 of technical guide)\n% - matrix 'sigma': 'true' variance-covariance matrix of VAR residuals, for the original Minnesota prior\n% - vector 'beta0': vector of prior values for beta (defined in 1.3.4)\n% - matrix 'omega0': prior covariance matrix for the VAR coefficients (defined in 1.3.8)\n% - vector 'betabar': posterior mean vector (defined in 1.3.18)\n% outputs: - scalar 'logml': base e log of the marginal likelihood (defined in 1.2.9)\n% - scalar 'log10ml': base 10 log of the marginal likelihood (defined in 1.2.9)\n% - scalar 'ml': marginal likelihood (defined in 1.2.9)\n\n\n\n% compute the constant part of the marginal likelihood\ntemp1=(-n*T/2)*log(2*pi)+(-T/2)*log(det(sigma));\n\n% compute the log determinant part\n% create the square root matrix of omega0\n% because omega0 is diagonal, this is simply the square root of the diagonal terms of omega0\nFomega=spdiags(diag(omega0).^0.5,0,q,q);\n% compute the inverse of sigma\nC=chol(bear.nspd(sigma));\ninvC=C\\speye(n);\ninvsigma=invC*invC';\n% compute the product\nproduct=Fomega'*kron(invsigma,X'*X)*Fomega;\n% compute the eigenvalues of the product\nif n == 1\n eigenvalues=eig(full(product));\nelse\n eigenvalues=eig(product);\nend\n% now compute the full determinant term\ntemp2=(-1/2)*log(prod(diag(eye(q)+diag(eigenvalues))));\n\n% compute the final term\n% first compute the inverse of omega0, which is a diagonal matrix (hence simply invert element wise the diagonal terms)\ninvomega0=spdiags(1./diag(omega0),0,q,q);\n% compute the inverse of omegabar\ninvomegabar=invomega0+kron(invsigma,X'*X);\n% now compute the whole matrix sum\nsumm=beta0'*invomega0*beta0-betabar'*invomegabar*betabar+y'*kron(invsigma,speye(T))*y;\n% finally, compute the whole exponential term\ntemp3=-0.5*summ;\n\n% compute the marginal likelihood\nlogml=real(temp1+temp2+temp3);\nlog10ml=logml/log(10);\nml=exp(logml);\n\n\n\n\n\n\n\n\n\n", "meta": {"author": "european-central-bank", "repo": "BEAR-toolbox", "sha": "f33aae80c40f7a2e78a54de99b2ce3663f59aa75", "save_path": "github-repos/MATLAB/european-central-bank-BEAR-toolbox", "path": "github-repos/MATLAB/european-central-bank-BEAR-toolbox/BEAR-toolbox-f33aae80c40f7a2e78a54de99b2ce3663f59aa75/tbx/bear/+bear/mmlikdata.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951607140232, "lm_q2_score": 0.7931059511841119, "lm_q1q2_score": 0.7410743627199264}} {"text": "function f = flops_solve_tri(n,m,k)\n% FLOPS_SOLVE_TRI Flops for triangular left division.\n% FLOPS_SOLVE_TRI(T,b) returns the number of flops for solve_tri(T,b).\n% FLOPS_SOLVE_TRI(n,m,k) returns the number of flops for \n% solve_tril(tril(rand(n,m)),rand(n,k)).\n%\n% Example: (n=2,m=2,k=1)\n% [g;h] = [a 0; b c]\\[e; f] has\n% g = e/a\n% h = (f - b*g)/c\n% which is 2 multiply+add and 2 divisions = 18 flops.\n\nif nargin == 2\n\tT = n;\n\tb = m;\n f = flops_solve_tri(rows(T),cols(T),cols(b));\n return;\nend\nif n ~= m\n\terror('n ~= m case is not implemented');\nend\n% lower triangular case:\n% number of multiplies+adds is\n% sum(i=1..n) sum(k=1..i-1) 2 = sum(i=1..n) 2*(i-1) = n^2-n\n% number of divides is n\nf = (n*n + n*(flops_div-1))*k;\n", "meta": {"author": "andrewssobral", "repo": "lrslibrary", "sha": "06d457349cb5f1fc56a583cd61af9f1d5150e3a1", "save_path": "github-repos/MATLAB/andrewssobral-lrslibrary", "path": "github-repos/MATLAB/andrewssobral-lrslibrary/lrslibrary-06d457349cb5f1fc56a583cd61af9f1d5150e3a1/libs/+lightspeed/flops_solve_tri.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951661947456, "lm_q2_score": 0.7931059438487662, "lm_q1q2_score": 0.7410743602126085}} {"text": "function [ Ix, Iy, Iz, It ] = imageDerivatives3D( image1, image2 )\n%This fucntion computes 3D derivatives between two 3D images. \n%\n% Description :\n%\n% There are four derivatives here; three along X, Y, Z axes and one along\n% timeline axis.\n%\n% -image1, image2 : two subsequent images or frames\n% -dx, dy, dz : vectors along X, Y and Z axes respectively\n% -dt : vectors along timeline axis\n% -Ix, Iy, Iz : derivatives along X, Y and Z axes respectively\n% -It : derivatives along timeline axis\n%\n% Author : Mohammad Mustafa\n% By courtesy of The University of Nottingham and \n% Mirada Medical Limited, Oxford, UK\n%\n% Published under a Creative Commons Attribution-Non-Commercial-Share Alike\n% 3.0 Unported Licence http://creativecommons.org/licenses/by-nc-sa/3.0/\n% \n% June 2012\n\n\ndx=zeros(2,2,2);\ndx(:,:,1)=[-1 1; -1 1 ]; dx(:,:,2)=[-1 1; -1 1 ];\ndx=0.25*dx;\n\ndy=zeros(2,2,2);\ndy(:,:,1)=[-1 -1; 1 1 ]; dy(:,:,2)=[-1 -1; 1 1 ];\ndy=0.25*dy;\n\ndz=zeros(2,2,2);\ndz(:,:,1)=[-1 -1; -1 -1 ]; dz(:,:,2)=[1 1; 1 1 ];\ndz=0.25*dz;\n\ndt=ones(2,2,2);\ndt=0.25*dt;\n\n% Computing derivatives\nIx = 0.5 * (convn(image1,dx) + convn(image2,dx) );\nIy = 0.5 * (convn(image1,dy) + convn(image2,dy) );\nIz = 0.5 * (convn(image1,dz) + convn(image2,dz) );\nIt = 0.5 * (convn(image1,dt) - convn(image2,dt) );\n\n% Adjusting sizes\nIx=Ix(1:size(Ix,1)-1, 1:size(Ix,2)-1, 1:size(Ix,3)-1);\nIy=Iy(1:size(Iy,1)-1, 1:size(Iy,2)-1, 1:size(Iy,3)-1);\nIz=Iz(1:size(Iz,1)-1, 1:size(Iz,2)-1, 1:size(Iz,3)-1);\nIt=It(1:size(It,1)-1, 1:size(It,2)-1, 1:size(It,3)-1);\n\n\nend\n\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/37170-lucas-kanade-optical-flow-method-for-3-d-images/LK3D/imageDerivatives3D.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088045171238, "lm_q2_score": 0.798186787341014, "lm_q1q2_score": 0.7410436410166346}} {"text": "function [] = mc_test_pdfs(MM,VV,desired_steps)\n% Function tests and plots the Gaussian mixture in the desired simulation\n% steps. \n%\n%% Syntax\n% mc_test_pdfs(MM,VV,desired_steps)\n%\n%% Description\n% Function tests and plots the Gaussian mixture described by the vector of Gaussian\n% means and variances in the desired simulation steps.\n%\n% Input: \n% * MM ... the matrix of mean values of Gaussian components, the matrix of dimensions \n% ksteps x Nsamples\n% * VV ... the matrix of associated variances of Gaussian components \n% * desired_steps ... the vector with indices of steps, where we want to test\n% the distributions \n%\n% See Also:\n% demo_example_gp_simulation\n% \n% Examples: \n% demo_example_gp_simulation\n% \n\n%% \n% * Written by K. Azman, 2007.\n%\n\n% variables \nMM = MM'; \nVV = VV'; \n\nNsamples = size(MM,1); \nmu = mean(MM);\ns2 = mean(VV) + mean((MM-repmat(mu,Nsamples,1)).^2);\nmu = mu';\ns2 = s2';\n\n% \"calculation\"\nSTD = sqrt(VV);\nXwide = 200; % resolution = no. of samples between xmin and xmax\nXmin = min(MM-4*STD);\nXmax = max(MM+4*STD);\ndX = (Xmax-Xmin)/(Xwide-1);\n\n% XX,YY ... matrices for storing the GP model's pdfs\n% XX(:,k) ... yvalues at time step k\n% YY(:,k) ... density values at time step k and coresponding y values in XX(:,k)\n% sum(YY(:,k)) = 1 for all k-s\nXX = zeros(Xwide,size(VV,2));\nYY = zeros(size(XX));\n\n\n% for desired steps\nfor jj = 1:length(desired_steps)\n kk = desired_steps(jj);\n XX(:,kk) = Xmin(kk):dX(kk):Xmax(kk);\n % ... and for every realisation\n ytemp = zeros(size(YY,1),1);\n\n for ii=1:Nsamples\n ytemp = normpdf(XX(:,kk), MM(ii,kk), STD(ii,kk));\n YY(:,kk) = YY(:,kk) + ytemp;\n end\n YY(:,kk) = YY(:,kk)/Nsamples;\n \n yapprox = normpdf(XX(:,kk),mu(kk),sqrt(s2(kk)));\n\n % plot pdfs \n figure(10000+kk);\n\n plot(XX(:,kk),YY(:,kk),'Color',[0.6 0.6 0.6],'LineWidth',4);\n hold on;\n plot(XX(:,kk),yapprox,'LineStyle','--','Color',[0 0 1],'LineWidth',4);\n for ii=1:Nsamples\n ytemp = normpdf(XX(:,kk), MM(ii,kk), STD(ii,kk));\n plot(XX(:,kk),ytemp,'Color',[0.9 0.9 0.9]);\n end \n plot(XX(:,kk),YY(:,kk),'Color',[0.6 0.6 0.6],'LineWidth',4);\n plot(XX(:,kk),yapprox,'LineStyle','--','Color',[0 0 1],'LineWidth',4);\n hold off;\n grid; \n legend('true','GP approx','samples')\n\n\n title(strcat(['test MC pdfs, simul step=', num2str(kk)]));\n\n\n disp('press sth to continue'); \n pause;\n\n \nend\n", "meta": {"author": "Dynamic-Systems-and-GP", "repo": "GPdyn", "sha": "343c20a28a0f95f488db4a086c43fafab5423bda", "save_path": "github-repos/MATLAB/Dynamic-Systems-and-GP-GPdyn", "path": "github-repos/MATLAB/Dynamic-Systems-and-GP-GPdyn/GPdyn-343c20a28a0f95f488db4a086c43fafab5423bda/gpdyn-utilities/mc_test_pdfs.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278788223264, "lm_q2_score": 0.8397339736884711, "lm_q1q2_score": 0.7410046691769608}} {"text": "function gray = rgb_to_gray ( rgb, equal )\n\n%*****************************************************************************80\n%\n%% RGB_TO_GRAY returns a grayscale version of an RGB image.\n%\n% Discussion:\n%\n% An RGB image is an (M,N,3) array.\n%\n% A grayscale image is an (M,N) array.\n%\n% A grayscale version of an RGB image can be made by averaging\n% the RGB components of each pixel.\n%\n% A more sophisticated approach uses the luminance function:\n%\n% GRAY = 0.2126 * R + 0.7152 * G + 0.0722 * B\n%\n% which attempts to better model the contributions to brightness\n% of the different colors.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 26 February 2011\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, uint8 RGB(M,N,3), the original data.\n%\n% Input, logical EQUAL, is TRUE (1) if the R, G and B channels\n% are to be assigned equal weight. EQUAL is FALSE by default.\n%\n% Output, uint8 GRAY(M,N), the grayscale version of the data.\n%\n if ( nargin < 1 )\n error ( 'RGB_TO_GRAY - Fatal error! Missing RGB input argument.' )\n end\n\n if ( nargin < 2 )\n equal = 0;\n end\n\n if ( equal )\n v = [ 1, 1, 1 ]' / 3;\n else\n v = [ 0.2126, 0.7152, 0.0722 ]';\n end\n%\n% This is really a matrix multiply, but the obvious equation\n% gray = rgb * v\n% is illegal according to MATLAB.\n%\n gray = uint8 ( double ( rgb(:,:,1) ) * v(1) ...\n + double ( rgb(:,:,2) ) * v(2) ...\n + double ( rgb(:,:,3) ) * v(3) );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/image_rgb_to_gray/rgb_to_gray.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8824278540866547, "lm_q2_score": 0.8397339696776499, "lm_q1q2_score": 0.7410046448663166}} {"text": "function yp = p15_fun ( neqn, t, y )\n\n%*****************************************************************************80\n%\n%% P15_FUN evaluates the function for problem P15.\n%\n% Discussion:\n%\n% 30 equations.\n%\n% This system models the motion of the five outer planets of the\n% solar system.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 18 February 2013\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Wayne Enright, John Pryce,\n% Algorithm 648,\n% ACM Transactions on Mathematical Software,\n% Volume 13, Number 1, pages 28-34.\n%\n% Parameters:\n%\n% Input, integer NEQN, the number of equations.\n%\n% Input, real T, Y(NEQN), the arguments of the derivative\n% function.\n%\n% Output, real YP(NEQN), the value of the derivative function.\n%\n yp = zeros ( neqn, 1 );\n\n m = zeros ( 5, 1 );\n k2 = p15_param ( 'GET', 'K2', [] );\n m0 = p15_param ( 'GET', 'M0', [] );\n m(1) = p15_param ( 'GET', 'M1', [] );\n m(2) = p15_param ( 'GET', 'M2', [] );\n m(3) = p15_param ( 'GET', 'M3', [] );\n m(4) = p15_param ( 'GET', 'M4', [] );\n m(5) = p15_param ( 'GET', 'M5', [] );\n i = 0;\n for l = 3 : 3 : 15\n i = i + 1;\n p = y(l-2).^2 + y(l-1).^2 + y(l).^2;\n r(i) = 1.0 / ( p * sqrt ( p ) );\n j = 0;\n for ll = 3 : 3 : 15\n j = j + 1;\n if ( ll ~= l )\n p = ( y(l-2) - y(ll-2) ).^2 + ( y(l-1) - y(ll-1) ).^2 ...\n + ( y(l) - y(ll) ).^2;\n q(i,j) = 1.0 / ( p * sqrt ( p ) );\n q(j,i) = q(i,j);\n end\n end\n end\n i3 = 0;\n for i = 1 : 5\n i3 = i3 + 3;\n for ll = i3-2 : i3\n mm = ll - i3;\n yp(ll) = y(ll+15);\n p = 0.0;\n for j = 1 : 5\n mm = mm + 3;\n if ( j ~= i )\n p = p + m(j) ...\n * ( y(mm) * ( q(i,j) - r(j) ) - y(ll) * q(i,j) );\n end\n end\n yp(ll+15) = k2 * ( - ( m0 + m(i) ) * y(ll) * r(i) + p );\n end\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_ode/p15_fun.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513675912913, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.740941579866203}} {"text": "function [x, w, v] = radaupts(n, alp, bet)\n%RADAUPTS Gauss-Jacobi-Radau quadrature nodes and weights.\n% RADAUPTS(N) returns N Legendre-Radau points X in [-1,1).\n%\n% [X, W] = RADAUPTS(N) returns also a row vector W of weights for\n% Gauss-Legendre-Lobatto quadrature.\n%\n% [X, W, V] = RADAUPTS(N) returns additionally a column vector V of weights in\n% the barycentric formula corresponding to the points X. The weights are scaled\n% so that max(abs(V)) = 1.\n%\n% [...] = RADUAPTS(N, ALP, BET) is similar, but for the Gauss-Jacobi-Radau\n% nodes and weights. Here ALP and BET should be scalars > -1.\n%\n% In each case, N should be a positive integer.\n%\n% See also CHEBPTS, LEGPTS, JACPTS, LEGPOLY, JACPOLY, LOBPTS.\n\n% Copyright 2017 by The University of Oxford and The Chebfun Developers.\n% See http://www.chebfun.org/ for Chebfun information.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Developer note:\n% The approach used here is to observe that the Gauss-Radau points are\n% precisely the roots of (1+x)P^(0,1)_{n-2}(x), which can be obtained from\n% JACPTS. A similar identity [NIST, (18.9.5) and (18.9.17)] is used for the\n% computation of the quadrature weights from those of JACPTS, and the missing\n% barycentric weights are determined by enforcing the interpolation of f(x) =\n% x at x = 0.\n%\n% x_j = roots of (1+x)P^(0,1)_{n-2}(x)\n% w_j = { 2/n^2 : x_j = -1\n% { 1/(1-x_j) * 1/[d/dx P_{n-1}(x_j)]^2 : otherwise\n%\n% (Note that the weights for n-1 point Gauss-Jacobi with a = 0, b = 1 satisfy \n% u_j = C/(1-x_j^2)/[d/dx P^(0,1)_{n-1}(x_j)]^2)\n%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n% TODO: Scaled domains?\n\nif ( nargin < 3 )\n % Default to Gauss-Legendre-Lobatto:\n alp = 0; bet = 0;\nend\n\n%% Trivial cases:\nif ( n == 1 )\n x = -1;\n w = 2^(1+alp+bet)*beta(1+alp,1+bet);\n v = 1;\n return\nend\n\n%% Call JACPTS():\n[xi, w, v] = jacpts(n-1, alp, bet+1);\n\n%% Nodes:\nx = [-1 ; xi];\n\n%% Quadrature weights:\nwi = w./(1 + xi.');\nif ( alp == 0 && bet == 0 )\n w = [2/n^2, wi];\nelse\n % See Walter Gautschi, \"Gauss\u2013Radau formulae for Jacobi and Laguerre\n % weight functions\", Mathematics and Computers in Simulation, (2000).\n w = [2^(alp+bet+1)*beta(bet+1,n)*beta(alp+n,bet+1)*(bet+1), wi];\nend\n\n%% Barycentric weights:\nv = v./(1 + xi);\nv = v/max(abs(v));\nv1 = -sum(v);\nv = [v1 ; v];\n\nend\n\n", "meta": {"author": "chebfun", "repo": "chebfun", "sha": "8c49396a55e46ddd57a1d108c6a8f32e37536d54", "save_path": "github-repos/MATLAB/chebfun-chebfun", "path": "github-repos/MATLAB/chebfun-chebfun/chebfun-8c49396a55e46ddd57a1d108c6a8f32e37536d54/radaupts.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513703624557, "lm_q2_score": 0.826711791935942, "lm_q1q2_score": 0.7409415764173894}} {"text": "function [a1, b1, c1, a2, b2, c2] = aaad(A, B, C)\n%AAAD gives both solutions to the angle-angle-angle problem, in degrees.\n%\n% AAAD(A, B, C) will result in NaNs if the existence condition \n% |pi - |A|-|B|| <= |C| <= pi - ||A| - |B||\n% is not met. \n%\n% See also AAAD.\n\n% Rody P.S. Oldenhuis\n% Delft University of Technology\n% oldenhuis@gmail.com\n%\n% Crated : 23/Feb/2009\n% Last edited: 30/Nov/2012\n \n % find both solutions by calling aaa directly\n r2d = 180/pi; \n d2r = 1/r2d; \n [a1, b1, c1, a2, b2, c2] = aaa(A*d2r, B*d2r, C*d2r);\n [a1, b1, c1, a2, b2, c2] = deal(a1*r2d, b1*r2d, c1*r2d, a2*r2d, b2*r2d, c2*r2d);\n \nend", "meta": {"author": "vigente", "repo": "gerardus", "sha": "4d7c5195b826967781f1bb967872410e66b7cd3d", "save_path": "github-repos/MATLAB/vigente-gerardus", "path": "github-repos/MATLAB/vigente-gerardus/gerardus-4d7c5195b826967781f1bb967872410e66b7cd3d/matlab/ThirdPartyToolbox/SphericalTrigToolbox/aaad.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425399873764, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.7408936261327475}} {"text": "function [xr,Yr]=noisergeo(x,dim,tau,r,q,p,theta)\n%Syntax: [xr,Yr]=noisergeo(x,dim,tau,r,q,p,theta)\n%________________________________________________\n%\n% Noise reduction by Local Geometric Projection.\n%\n% xr is the vector/matrix with the cleaned time series.\n% Yr is the phase space of the last cleaned xr.\n% x is the time series.\n% dim is the embedding dimension.\n% tau is the time delay.\n% r can be either\n% real defining the neighborhood range.\n% integer defining the number of nearest neighbors.\n% q can take one of the following values\n% 'wAV' for the weighted average.\n% [an integer from 0 to dim-1] for the local geometric projection.\n% 'mod' for the adaptive selection of the local neighborhood dimensions.\n% p defines the norm.\n% theta is the correction paprameter [0,1]\n% 1: full correction.\n% 0: no correction.\n%\n%\n% References:\n%\n% Kantz H, Schreiber T, Hoffmann I, Buzug T, Pfister G, Flepp L G, Simonet\n% J, Badii R, Brun E (1993): Nonlinear noise reduction: A case study on\n% experimental data. Physical Review E 48: 1529-1538\n%\n% Leontitsis A., Bountis T., Pange J. (2004): An adaptive way for improving\n% noise reduction using local geometric projection. CHAOS 14(6): 106-110\n%\n%\n% Alexandros Leontitsis\n% Department of Education\n% University of Ioannina\n% Ioannina\n% Greece\n%\n% University e-mail: me00743@cc.uoi.gr\n% Lifetime e-mail: leoaleq@yahoo.com\n% Homepage: http://www.geocities.com/CapeCanaveral/Lab/1421\n%\n% 14 Jul 2001\n\nif nargin<1 | isempty(x)==1\n error('You should provide a time series.');\nelse\n % x must be a vector\n if min(size(x))>1\n error('Invalid time series.');\n end\n x=x(:);\n % n is the time series length\n n=length(x);\nend\n\nif nargin<2 | isempty(dim)==1\n dim=2;\nelse\n % dim must be either a scalar or a vector\n if min(size(dim))>1\n error('dim must be a scalar or a vector.');\n end\n % dim must be an integer\n if round(dim)-dim~=0\n error('dim must be an integer.');\n end\n % dim values must be above 1\n if any(dim<1)==1\n error('dim values must be above 1');\n end\nend\n\nif nargin<3 | isempty(tau)==1\n tau=1;\nelse\n % tau must be either a scalar or a vector\n if min(size(tau))>1\n error('tau must be a scalar or a vector.');\n end\n % tau must be an integer\n if round(tau)-tau~=0\n error('tau must be an integer.');\n end\n % tau values must be above 1\n if any(tau<1)==1\n error('tau values must be above 1');\n end\nend\n\nif nargin<4 | isempty(r)==1\n r=dim+1;\nelse\n % r must be either a scalar or a vector\n if min(size(r))>1\n error('r must be a scalar or a vector.');\n end\n % r values must be above 0\n if any(r<=0)==1\n error('r values must be greater than 0');\n end\nend\n\nif nargin<5 | isempty(q)==1\n q=1;\nend\n\nif nargin<6 | isempty(p)==1\n p=2;\nelse\n % p must be either a scalar or a vector\n if min(size(p))>1\n error('p must be a scalar or a vector.');\n end\nend\n\nif nargin<7 | isempty(theta)==1\n theta=1;\nelse\n % theta must be either a scalar or a vector\n if min(size(theta))>1\n error('theta must be a scalar or a vector.');\n end\n % theta must be above 0 and bellow 1\n if theta<0 | theta>1\n error('theta must be above 0 and bellow 1.')\n end\nend\n\n% Only one of dim, tau, r, p or theta should be vector\nl=[length(dim),length(tau),length(r),length(p),length(theta)];\nif length(find(l>1))>1\n error('Only one of dim, tau, r, p, or theta should be vector.');\nend\n\n% Make the phase-space\n[Y,T]=phasespace(x,dim,tau);\n\n\nm=max(l);\ndim=ones(1,m).*dim;\ntau=ones(1,m).*tau;\nr=ones(1,m).*r;\np=ones(1,m).*p;\ntheta=ones(1,m).*theta;\n\nfor i=1:m\n \n % Initialize Yr\n Yr=zeros(T,dim(i));\n \n % For every phase-space point\n for j=1:T\n \n % Locate the j-th point\n y=Y(j,:);\n \n % Check neighborhood or neighbors\n if mod(r(i),floor(r(i)))==0\n lock=Knearest(y,Y,r(end)+1,p(i));\n else\n lock=radnearest(y,Y,T,r(i),p(i));\n lock(find(j==lock))=[];\n end\n \n if isempty(lock)==1\n Yr(j,:)=y;\n elseif q=='wAV'\n % The calculations for the weighted average\n Ynearest=Y(lock,:);\n w=[];\n for k=1:length(lock)\n w(k)=norm(y-Ynearest(k,:))/2/r(i);\n w(k)=exp(-w(k)^2);\n Ynearest(k,:)=Ynearest(k,:)*w(k);\n end\n Yr(j,:)=sum(Ynearest)/sum(w);\n else\n % All the neighboring points have equal weight\n if length(lock)\n return;\nend\n\nif isempty(x),\n return;\nend\n\n% solve for parameters a, b, and c in the least-squares sense by\n% using the backslash operator\nabc = [x y ones(length(x),1)] \\ -(x.^2+y.^2);\na = abc(1); b = abc(2); c = abc(3);\n\n% calculate the location of the center and the radius\nxc = -a/2;\nyc = -b/2;\nradius = sqrt((xc^2+yc^2)-c);\n\n% display the calculated center\nh(1) = plot(xc,yc,[color 'x'],'LineWidth',2);\nh(2) = text(xc,yc,sprintf(' (%.1f, %.1f)',xc,yc),'Color',color,'FontWeight','bold');\n\n% plot the entire circle\ntheta = 0:0.01:2*pi;\n\n% use parametric representation of the circle to obtain coordinates\n% of points on the circle\nXfit = radius*cos(theta) + xc;\nYfit = radius*sin(theta) + yc;\n\nh(3) = plot(Xfit, Yfit,[color '-'],'LineWidth',2);\n\nmessage = sprintf('The estimated radius is %2.3f pixels', radius);\nh(4) = text(15,15,message,'Color',color,'FontWeight','bold','BackgroundColor','k');", "meta": {"author": "kristinbranson", "repo": "JAABA", "sha": "5d778a23e3e7cf272df9a89a72b1b66d94f535d7", "save_path": "github-repos/MATLAB/kristinbranson-JAABA", "path": "github-repos/MATLAB/kristinbranson-JAABA/JAABA-5d778a23e3e7cf272df9a89a72b1b66d94f535d7/misc/fitcircle_manual.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107949104866, "lm_q2_score": 0.7905303260722198, "lm_q1q2_score": 0.7408935552989914}} {"text": "% Nonnegativity Constrained Least Squares with Multiple Righthand Sides \n% using Block Principal Pivoting method\n%\n% This software solves the following problem: given A and B, find X such that\n% minimize || AX-B ||_F^2 where X>=0 elementwise.\n%\n% Reference:\n% Jingu Kim and Haesun Park. Fast Nonnegative Matrix Factorization: An Activeset-like Method and Comparisons,\n% SIAM Journal on Scientific Computing, 33(6), pp. 3261-3281, 2011.\n%\n% Written by Jingu Kim (jingu.kim@gmail.com)\n% School of Computational Science and Engineering,\n% Georgia Institute of Technology\n%\n% Note that this algorithm assumes that the input matrix A has full column rank.\n% This code comes with no guarantee or warranty of any kind. \n% Please send bug reports, comments, or questions to Jingu Kim.\n%\n% Modified Feb-20-2009\n% Modified Mar-13-2011: numChol and numEq\n%\n% \n% A : input matrix (m x n) (by default), or A'*A (n x n) if isInputProd==1\n% B : input matrix (m x k) (by default), or A'*B (n x k) if isInputProd==1\n% isInputProd : (optional, default:0) if turned on, use (A'*A,A'*B) as input instead of (A,B)\n% init : (optional) initial value for X\n% \n% X : the solution (n x k)\n% Y : A'*A*X - A'*B where X is the solution (n x k)\n% success : 0 for success, 1 for failure.\n% Failure could only happen on a numericall very ill-conditioned problem.\n% numChol : number of unique cholesky decompositions done\n% numEqs : number of systems of linear equations solved\n\nfunction [ X,Y,success,numChol,numEq ] = nnlsm_blockpivot( A, B, isInputProd, init )\n if nargin<3, isInputProd=0;, end\n if isInputProd\n AtA = A;, AtB = B;\n else\n AtA = A'*A;, AtB = A'*B;\n end\n\n if size(AtA,1)==1\n X = AtB/AtA; X(X<0) = 0;\n Y = AtA*X - AtB;\n numChol = 1; numEq = size(AtB,2); success = 1;\n return\n end\n \n [n,k]=size(AtB);\n MAX_BIG_ITER = n*5;\n % set initial feasible solution\n X = zeros(n,k);\n if nargin<4\n Y = - AtB;\n PassiveSet = false(n,k);\n numChol = 0;\n numEq = 0;\n else\n PassiveSet = (init > 0);\n [ X,numChol,numEq] = normalEqComb(AtA,AtB,PassiveSet);\n Y = AtA * X - AtB;\n end\n % parameters\n pbar = 3;\n P = zeros(1,k);, P(:) = pbar;\n Ninf = zeros(1,k);, Ninf(:) = n+1;\n\n NonOptSet = (Y < 0) & ~PassiveSet;\n InfeaSet = (X < 0) & PassiveSet;\n NotGood = sum(NonOptSet)+sum(InfeaSet);\n NotOptCols = NotGood > 0;\n\n bigIter = 0;, success=0;\n while(~isempty(find(NotOptCols)))\n bigIter = bigIter+1;\n if ((MAX_BIG_ITER >0) && (bigIter > MAX_BIG_ITER)) % set max_iter for ill-conditioned (numerically unstable) case\n success = 1;, break\n end\n\n Cols1 = NotOptCols & (NotGood < Ninf);\n Cols2 = NotOptCols & (NotGood >= Ninf) & (P >= 1);\n Cols3Ix = find(NotOptCols & ~Cols1 & ~Cols2);\n if ~isempty(find(Cols1))\n P(Cols1) = pbar;,Ninf(Cols1) = NotGood(Cols1);\n PassiveSet(NonOptSet & repmat(Cols1,n,1)) = true;\n PassiveSet(InfeaSet & repmat(Cols1,n,1)) = false;\n end\n if ~isempty(find(Cols2))\n P(Cols2) = P(Cols2)-1;\n PassiveSet(NonOptSet & repmat(Cols2,n,1)) = true;\n PassiveSet(InfeaSet & repmat(Cols2,n,1)) = false;\n end\n if ~isempty(Cols3Ix)\n for i=1:length(Cols3Ix)\n Ix = Cols3Ix(i);\n toChange = max(find( NonOptSet(:,Ix)|InfeaSet(:,Ix) ));\n if PassiveSet(toChange,Ix)\n PassiveSet(toChange,Ix)=false;\n else\n PassiveSet(toChange,Ix)=true;\n end\n end\n end\n [ X(:,NotOptCols),tempChol,tempEq ] = normalEqComb(AtA,AtB(:,NotOptCols),PassiveSet(:,NotOptCols));\n numChol = numChol + tempChol;\n numEq = numEq + tempEq;\n X(abs(X)<1e-12) = 0; % One can uncomment this line for numerical stability.\n Y(:,NotOptCols) = AtA * X(:,NotOptCols) - AtB(:,NotOptCols);\n Y(abs(Y)<1e-12) = 0; % One can uncomment this line for numerical stability.\n \n % check optimality\n NotOptMask = repmat(NotOptCols,n,1);\n NonOptSet = NotOptMask & (Y < 0) & ~PassiveSet;\n InfeaSet = NotOptMask & (X < 0) & PassiveSet;\n NotGood = sum(NonOptSet)+sum(InfeaSet);\n NotOptCols = NotGood > 0;\n end\nend\n", "meta": {"author": "hiroyuki-kasai", "repo": "NMFLibrary", "sha": "ed44132dfe1b5495df685006b42259f0bd16bea3", "save_path": "github-repos/MATLAB/hiroyuki-kasai-NMFLibrary", "path": "github-repos/MATLAB/hiroyuki-kasai-NMFLibrary/NMFLibrary-ed44132dfe1b5495df685006b42259f0bd16bea3/solver/nnls/nnlsm_blockpivot.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107914029486, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.7408935502135945}} {"text": "function cvt_test14 ( )\n\n%*****************************************************************************80\n%\n%% CVT_TEST14 generates a 10 point CVT on [0,1].\n%\n% Discussion:\n%\n% Generate 10 CVT points on the interval [0,1].\n% We expect them to be at 1/20, 3/20, 5/20, ..., 19/20.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 14 September 2010\n%\n% Author:\n%\n% John Burkardt\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TEST14\\n' );\n fprintf ( 1, ' Generate a CVT in the interval [0,1] using 10 points.\\n' );\n fprintf ( 1, ' Exact answer: { 0.05, 0.15, 0.25, ..., 0.85, 0.95 }\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' It turns out that, for a fixed number of points N,\\n' );\n fprintf ( 1, ' a 1D problem will converge much more slowly than for\\n' );\n fprintf ( 1, ' cases where the dimension is higher.\\n' );\n\n dim_num = 1;\n n = 10;\n batch = 10000;\n init = 1;\n init_string = 'uniform';\n it_max = 50;\n it_fixed = 1;\n sample = 1;\n sample_num = 100000;\n sample_string = 'uniform';\n seed = 123456789;\n r = [];\n\n seed_init = seed;\n\n [ r, seed, it_num, it_diff, energy ] = cvt ( dim_num, n, batch, init, ...\n sample, sample_num, it_max, it_fixed, seed, r );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Dimension DIM_NUM = %12d\\n', dim_num );\n fprintf ( 1, ' Number of points N = %12d\\n', n );\n fprintf ( 1, ' Initial SEED = %12d\\n', seed_init );\n fprintf ( 1, ' Current SEED = %12d\\n', seed );\n fprintf ( 1, ' INIT = \"%s\".\\n', init_string );\n fprintf ( 1, ' Max iterations IT_MAX = %12d\\n', it_max );\n fprintf ( 1, ' IT_FIXED (fixed samples) = %12d\\n', it_fixed );\n fprintf ( 1, ' Iterations IT_NUM = %12d\\n', it_num );\n fprintf ( 1, ' Difference IT_DIFF = %14f\\n', it_diff );\n fprintf ( 1, ' CVT ENERGY = %14f\\n', energy );\n fprintf ( 1, ' SAMPLE = \"%s\".\\n', sample_string );\n fprintf ( 1, ' Samples SAMPLE_NUM = %12d\\n', sample_num );\n fprintf ( 1, ' Sampling BATCH size = %12d\\n', batch );\n fprintf ( 1, ' EPSILON (unit roundoff) = %12e\\n', eps );\n \n r = sort ( r );\n\n r8mat_transpose_print ( dim_num, n, r, ' Generators (rows):' );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/cvt/cvt_test14.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757870046160258, "lm_q2_score": 0.8459424353665381, "lm_q1q2_score": 0.7408653915472464}} {"text": "%% Spherical Functions\n%\n%%\n% By a variable of type @S2Fun it is possible to represent an entire\n% function on the two dimensional sphere. A typical example of such a\n% function is the pole density function of a given ODF with respect to a\n% fixed crystal direction.\n\n% the famouse Santa Fe orientation distribution function\nodf = SantaFe;\n\n% the (100) pole density function\npdf = odf.calcPDF(Miller(1,0,0,odf.CS))\n\n%%\n% Since, the variable |pdf| stores all information about this function we\n% may evaluate it for any direction |r|\n\n% take a random direction\nr = vector3d.rand;\n\n% and evaluate the pdf at this direction\npdf.eval(r)\n\n%%\n% We may also plot the function in any spherical projection\n\nplot(pdf)\n\n%%\n% or find its local maxima\n\n[~,localMax] = max(pdf,'numLocal',12)\n\nannotate(localMax)\n\n%%\n% A complete list of operations that can be performed with spherical\n% functions can be found in section .\n%\n\n\n%% Representation of Spherical Functions\n%\n% In MTEX there exist different ways for representing spherical functions\n% internally. \n%\n% || harmonic expansion || @S2FunHarmonic ||\n% || finite elements || @S2FunTri ||\n% || function handle || @S2FunHandle ||\n% || Bingham distribution || @BinghamS2 ||\n%\n% All representations allow for the same operations which are specified for\n% the abstact class @S2Fun. In particular it is possible\n% to calculate with spherical functions as with ordinary numbers, i.e., you\n% can add, multiply arbitrary functions, take the mean, integrate them or\n% compute gradients.\n%\n%% Generalizations of Spherical Functions\n%\n% || spherical vector fields || @S2VectorField ||\n% || spherical axis fields || @S2AxisField ||\n% || radial spherical functions || @S2Kernel ||\n% || symmetric spherical functions || @S2FunHarmonicSym ||\n%\n", "meta": {"author": "mtex-toolbox", "repo": "mtex", "sha": "f0ce46a720935e9ae8106ef919340534bca1adcb", "save_path": "github-repos/MATLAB/mtex-toolbox-mtex", "path": "github-repos/MATLAB/mtex-toolbox-mtex/mtex-f0ce46a720935e9ae8106ef919340534bca1adcb/doc/SphericalFunctions/S2FunConcept.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8757869786798664, "lm_q2_score": 0.8459424431344437, "lm_q1q2_score": 0.7408653764097791}} {"text": "function [cc,c0]=v_lpcar2cc(ar,np)\n%V_LPCAR2CC LPC: Convert AR filter to complex cepstrum [CC,C0]=(AR,NP)\n%\n% Inputs: ar(nf,n+1) AR coefficients, one frame per row\n% np Number of cepstral coefficients to calculate [n]\n%\n% Outputs: cc(nf,np) Complex cepstral coefficients, excluding c(0)\n% c0(nf,1) Coefficient c(0)\n%\n% The \"complex cepstral coefficients\", cc(n), are the inverse discrete-time Fourier transform\n% of the log of the complex-valued spectrum. The cc(n) are real-valued and, for n<0, cc(n)=0.\n% The \"real cepstral coeffcients\", rc(n), are the inverse discrete-time Fourier transform\n% of the log of the magnitude spectrum; rc(0)=cc(0) and rc(n)=0.5*cc(n) for n~=0.\n\n% Copyright (C) Mike Brookes 1998-2014\n% Version: $Id: v_lpcar2cc.m 10865 2018-09-21 17:22:45Z dmb $\n%\n% VOICEBOX is a MATLAB toolbox for speech processing.\n% Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html\n%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% This program is free software; you can redistribute it and/or modify\n% it under the terms of the GNU General Public License as published by\n% the Free Software Foundation; either version 2 of the License, or\n% (at your option) any later version.\n%\n% This program is distributed in the hope that it will be useful,\n% but WITHOUT ANY WARRANTY; without even the implied warranty of\n% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n% GNU General Public License for more details.\n%\n% You can obtain a copy of the GNU General Public License from\n% http://www.gnu.org/copyleft/gpl.html or by writing to\n% Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n[nf,p1]=size(ar);\np=p1-1;\nif (nargin<2) np=p; end\ncc=zeros(nf,np);\nif any(ar(:,1)~=1)\n c0=-log(ar(:,1));\n ar=ar./ar(:,ones(1,p1));\nelse\n c0=zeros(nf,1);\nend\ncm=(1:np).^(-1);\nif np>p\n xm=-(1:p);\n nz=np-p;\n for k=1:nf\n cc(k,:)=filter(1,ar(k,:),[ar(k,2:p1).*xm zeros(1,nz)]).*cm;\n end\nelse\n p1=np+1;\n xm=-(1:np);\n for k=1:nf\n cc(k,:)=filter(1,ar(k,:),ar(k,2:p1).*xm).*cm;\n end\nend\nif ~nargout\n v_lpccc2pf(cc,[],[],c0);\nend\n", "meta": {"author": "ImperialCollegeLondon", "repo": "sap-voicebox", "sha": "28f2654b7584f724277ec81de533debe28ff51ac", "save_path": "github-repos/MATLAB/ImperialCollegeLondon-sap-voicebox", "path": "github-repos/MATLAB/ImperialCollegeLondon-sap-voicebox/sap-voicebox-28f2654b7584f724277ec81de533debe28ff51ac/voicebox/v_lpcar2cc.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869819218865, "lm_q2_score": 0.8459424373085145, "lm_q1q2_score": 0.7408653740500686}} {"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%Function (ldiv) : calculate inverse Z-transform by long division \n% Author : Tamer mohamed samy abdelazim Mellik\n% Contact information : \n%Department of Electrical & Computer Engineering,\n%University of Calgary,\n%2500 University Drive N.W. ,\n%Calgary, AB T2N 1N4 ,\n%Canada .\n% email :abdelasi@enel.ucalgary.ca \n% email : tabdelaz@ucalgary.ca\n% Webpage : http://www.enel.ucalgary.ca/~abdelasi/\n% Date : 2-5-2002\n% Version : 1.0.0\n%Example\n% This function like deconv but it help if the numerator less or equal degree of denominator\n% if you have this function (It must arranged in terms of minus power of Z):\n% 1\n% G(z)= ----------------- \n% -1 -2\n% ( 5 - Z - 3 Z )\n% and you want to calculate long division or inverse Z transform :\n% The numerator is a=[1] and the denominator is b= [5 -1 -3 ]\n% call the function ldiv(a,b) to get the funresult 20 items (default)\n% another example :\n% -2 -3 \n% ( 5 - 3 Z + 4 Z )\n% G(z)----------------- \n% -1 -2\n% (5 - Z - 3 Z )\n% a=[5 0 -3 4] , b= [5 -1 -3 ] and you want the funresult 100 terms !\n% ldiv(a,b,100) \n% Note : The author doesn't have any responsibility for any harm caused by the use of this file\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nfunction funresult=ldiv(a,b,N)\n%a numerator\n%b denominator\n%default order of the filter == 20\nfunresult=[];\nif nargin < 3\n if nargin > 1\n N=20;\n else\n disp('Usage: M = ldiv(a,b,N)')\n disp('a:numerator , b denominator and N is the order of the resultant filter')\n return\n end \nend\n\nif size(a) < 1\n disp('Error: numerator must at least have one element not empty')\n return\nend\nif size(b) < 1\n disp('Error: denominator must at least have one element not empty')\n return\nend\n\nif b(1)==0\n disp('Error: The first element of denominator must have nonzero value')\n return\nend\nif size(b) < 2\n funresult=a./b;\n for i =length(funresult)+1:N\n funresult(i)=0;\n end\n return\nend\n\n\nfor i = length(a)+1:N\n a(i)=0;\nend\nfor i = 1 : N\n funresult(i)=a(1)/b(1);\n if length(a)>1\n for k= 2:length(b)\n if k > length(a)\n a(k)=0;\n end\n a(k)=a(k)-funresult(length(funresult))*b(k);\n end\n\n for i = 1:length(a)-1\n a(i)=a(i+1);\n end\n a=a(1:length(a)-1);\n end\nend\n\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/1752-calculates-inverse-z-transform-by-long-division/ldiv.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869786798664, "lm_q2_score": 0.8459424314825853, "lm_q1q2_score": 0.7408653662052334}} {"text": "function a = frank_inverse ( n )\n\n%*****************************************************************************80\n%\n%% FRANK_INVERSE returns the inverse of the FRANK matrix.\n%\n% Formula:\n%\n% if ( I = J-1 )\n% A(I,J) = -1\n% elseif ( I = J )\n% if ( I = 1 )\n% A(I,J) = 1\n% else\n% A(I,J) = N + 2 - I\n% elseif ( J < I )\n% A(I,J) = - (N+1-I) * A(I-1,J)\n% else\n% A(I,J) = 0\n%\n% Example:\n%\n% N = 5\n%\n% 1 -1 0 0 0\n% -4 5 -1 0 0\n% 12 -15 4 -1 0\n% -24 30 -8 3 -1\n% 24 -30 8 -3 2\n%\n% Properties:\n%\n% A is generally not symmetric: A' /= A.\n%\n% A is lower Hessenberg.\n%\n% det ( A ) = 1.\n%\n% A is unimodular.\n%\n% A is integral: int ( A ) = A.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 15 October 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the order of A.\n%\n% Output, real A(N,N), the matrix.\n%\n a = zeros ( n, n );\n\n for i = 1 : n\n for j = 1 : n\n\n if ( i == j-1 )\n a(i,j) = - 1.0;\n elseif ( i == j )\n if ( i == 1 )\n a(i,j) = 1.0;\n else\n a(i,j) = ( n + 2 - i );\n end\n elseif ( j < i )\n a(i,j) = - ( n + 1 - i ) * a(i-1,j);\n else\n a(i,j) = 0.0;\n end\n\n end\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_mat/frank_inverse.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869786798663, "lm_q2_score": 0.8459424295406088, "lm_q1q2_score": 0.7408653645044755}} {"text": "function [detJ,J] = dtiJacobian(inData)\n%\n% [detJ,J] = dtiJacobian(inData)\n%\n% Computes the Jacobian (J) and the determinant of the Jacobian (detJ)\n% given an XxYxZx3 or Nx3 input array. The array is assumed to represent a\n% vector field. The Jacobian is a useful metric for interpreting\n% deformations. E.g., abs(detJ) represents the local volume change for a\n% deformation field.\n%\n% HISTORY:\n% 2008.06.25 RFD wrote it.\n\nsz = size(inData);\n\nif((numel(sz)~=4 && numel(sz)~=2) || sz(end)~=3)\n error('inData must be XxYxZx3 or Nx3.');\nend\n\n% Approximate the Jacobian of the input array using grad.\n\nif(numel(sz)==2)\n inData = reshape(inData,[1 1 1 sz(1) sz(2)]);\nend\n\ndim = size(inData);\nJ = zeros(dim(1),dim(2),dim(3),3,3);\n\nfor(ii=1:3)\n [gradX,gradY,gradZ] = gradient(inData(:,:,:,ii),1); \n J(:,:,:,ii,1) = gradX; \n J(:,:,:,ii,2) = gradY; % Or Y,X,Z?\n J(:,:,:,ii,3) = gradZ;\nend\n% Compute the determinant of J\n% det(J) for a 3x3 [a b c; d e f; g h i] is: (aei+bfg+cdh)-(gec+hfa+idb)\n% a=1,1; b=1,2; c=1,3; d=2,1; e=2,2; f=2,3; g=3,1; h=3,2; i=3,3;\ndetJ = J(:,:,:,1,1).*J(:,:,:,2,2).*J(:,:,:,3,3) ...\n + J(:,:,:,1,2).*J(:,:,:,2,3).*J(:,:,:,3,1) ...\n + J(:,:,:,1,3).*J(:,:,:,2,1).*J(:,:,:,3,2) ...\n - J(:,:,:,3,1).*J(:,:,:,2,2).*J(:,:,:,1,3) ...\n - J(:,:,:,3,2).*J(:,:,:,2,3).*J(:,:,:,1,1) ...\n - J(:,:,:,3,3).*J(:,:,:,2,1).*J(:,:,:,1,2);\n \nif(numel(sz)==2)\n J = squeeze(J);\n detJ = squeeze(detJ);\nend\nreturn;", "meta": {"author": "vistalab", "repo": "vistasoft", "sha": "7f0102c696c091c858233340cc7e1ab02f064d4c", "save_path": "github-repos/MATLAB/vistalab-vistasoft", "path": "github-repos/MATLAB/vistalab-vistasoft/vistasoft-7f0102c696c091c858233340cc7e1ab02f064d4c/mrDiffusion/tensor/dtiJacobian.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299632771662, "lm_q2_score": 0.8006920116079209, "lm_q1q2_score": 0.740824240496317}} {"text": "function ref = randref(low, high, N)\n\n% Create roughly N random integers between between\n% low and high. Each value is unique, the values\n% are monotonically increasing.\n% These integer values can be used as reference indices\n% for statistical purposes\n% -1 for N means : return low:high\n%\n% length(randref(low, high, N)) will not be exactly equal to N !!!\n\nnarginchk(3,3);\n\nif (high<=low)\n\terror('Cannot create random indices when upper limit is smaller than lower limit');\nend\n\nif N < 1 | N > high-low\n ref = low:high;\n return\nend\n\nm_target = (high-low) / N;\n\nif m_target < 10\n m = (0.99+log10(m_target)) * m_target;\n N = ceil(1.5 * N); % calculate more indices than necesary\nelse\n m = 1.99 * m_target;\n N = ceil(1.2*N); % calculate more indices than necesary\nend\n\nref = cumsum([low ; ceil(rand(N,1)*m)]); % compute indices\nref = ref(find(ref <= high)); % remove out of range indices \n", "meta": {"author": "benfulcher", "repo": "hctsa", "sha": "919f2aed7cc8e1a3a03304c1ade573fa664c73f8", "save_path": "github-repos/MATLAB/benfulcher-hctsa", "path": "github-repos/MATLAB/benfulcher-hctsa/hctsa-919f2aed7cc8e1a3a03304c1ade573fa664c73f8/Toolboxes/OpenTSTOOL/tstoolbox/utils/randref.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299570920387, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.7408242267431784}} {"text": "function [newProj, rectGrid] = gridding(cg, proj )\n\nindexT = 1:cg.nt;\nindexS = 1:cg.ns;\n\nws = (cg.ns+1)/2;\nwt = (cg.nt+1)/2;\n\ncoordT = (indexT - wt) * cg.dt;\ncoordS = (indexS - ws) * cg.ds;\nd = cg.dsd;\nr = cg.dso;\n\nmatrix = zeros(cg.nt, cg.ns);\n%create matrix\nfor i = 1:1:cg.ns\n\tmatrix(:,i) = coordT .* sqrt(r^2-coordS(i)^2) / d;\nend\n\n%find the maximum value\nupperLimit = max(max(matrix));\nlowerLimit = min(min(matrix)); % should just be -max\n\n%create new grid in the vertical direction\nnew_dt = (upperLimit-lowerLimit)/cg.nt; % original\n%new_dt = cg.dt;\nrectGrid = lowerLimit+(upperLimit-lowerLimit)/cg.nt:new_dt:upperLimit;\nrectGrid = rectGrid'; % 1d set of \"t\" samples we want\n\n%must also loop over the projection angles\nnewProj = zeros(cg.ns, numel(rectGrid), cg.na);\nfor j = 1:1:cg.na\n\tfor i = 1:1:cg.ns\n\t\tnewProj(i,:,j) = ...\n\t\tinterp1(matrix(:,i), proj(i,:,j), rectGrid, 'linear', 'extrap');\n\tend\nend\n\nend % gridding()\n", "meta": {"author": "JeffFessler", "repo": "mirt", "sha": "b7f36cc46916821e8bc8502301b1554ebc7efe1d", "save_path": "github-repos/MATLAB/JeffFessler-mirt", "path": "github-repos/MATLAB/JeffFessler-mirt/mirt-b7f36cc46916821e8bc8502301b1554ebc7efe1d/contrib/handy-greg/t-fdk/arch/gridding.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299570920387, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.7408242223428001}} {"text": "function chi = RoadInclination_Arkussinus(z_I_Ground_m,l_WheelbaseFB_m,w_TrackFB_m,phiz_IK_rad)\n%% Computation of Road Angles from Street Profile in Inertial Frame\n% Input parameters:\n% phiz_IK_rad [rad] Euler-Angle around z-Axis from Inertial Reference Frame I to Vehicle Fixed Reference Frame K [Psi]\n% w_TrackFB_m [m] Track width at Front and Rear Axle [w_TrackF_m w_TrackR_m]\n% l_WheelbaseFB_m [m] Wheelbase from Cog to Front and Rear Axle [l_WheelbaseF_m l_WheelbaseR_m]\n% z_I_Ground_m [m] Input Vector with z-Profile of Street in Inertial Coordinate System at the Axle Locations [x1 x2 x3 x4] [3x4]\n% Output parameters:\n% Y [rad] Approximated Cardan Angles from Inertial Reference Frame to Road Fixed Reference Frame [chi_x chi_y Psi] [3x1]\n\n%% Computation of Road Angles\n% Inclination Angle in x-direction for negative z-road-profile\nchi_y = -asin( 0.5*((z_I_Ground_m(1)+z_I_Ground_m(2))-(z_I_Ground_m(3)+z_I_Ground_m(4)))/sum(abs(l_WheelbaseFB_m)) );\n% Inclination Angle in y-direction for negative z-road-profile\nchi_x = -asin( 0.5*((z_I_Ground_m(1)+z_I_Ground_m(3))-(z_I_Ground_m(2)+z_I_Ground_m(4)))/mean(abs(w_TrackFB_m)) );\n\n%% Output Parameters\nchi = [chi_x;chi_y;phiz_IK_rad];\n\n", "meta": {"author": "TUMFTM", "repo": "sim_vehicle_dynamics", "sha": "df2ae95dbeb6f8e4591f31ee378acac8e812f358", "save_path": "github-repos/MATLAB/TUMFTM-sim_vehicle_dynamics", "path": "github-repos/MATLAB/TUMFTM-sim_vehicle_dynamics/sim_vehicle_dynamics-df2ae95dbeb6f8e4591f31ee378acac8e812f358/vehicle_model/vehicledynamics/src/RoadInclination_Arkussinus.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9632305349799242, "lm_q2_score": 0.7690802476562641, "lm_q1q2_score": 0.7408015783924359}} {"text": "%%***************************************************************\n%% logcheby: logarithmic Chebyshev approximation problem. \n%% SDP formulation. \n%% minimize t \n%% x,t\n%% such that 1/t <= (x'*B(i,:))/f(i) <= t, i = 1:p.\n%% \n%% B = pxm matrix, f = p-vector, p > m.\n%%\n%% Ref: Vanderberghe & Boyd. \n%%--------------------------------------------------------------\n%% [blk,Avec,C,b,X0,y0,Z0,obj,x] = logcheby(B,f,feas,solve);\n%%\n%% B = pxm matrix (p > m).\n%% f = px1 vector, [B(:,j)./f must be positive for each j] \n%% feas = 1 if want feasible starting point\n%% = 0 if otherwise.\n%% solve = 0 if just want initialization. \n%% = 1 if want to solve the problem. \n%%\n%% SDPT3: version 3.0 \n%% Copyright (c) 1997 by\n%% K.C. Toh, M.J. Todd, R.H. Tutuncu\n%% Last modified: 2 Feb 01\n%%***************************************************************\n\n function [blk,Avec,C,b,X0,y0,Z0,objval,x] = logcheby(B,f,feas,solve);\n \n if (nargin < 4); solve = 0; end; \n if (nargin < 3); feas = 1; end; \n\n if ~isreal(B); error('B must be real'); end;\n\n [p,m] = size(B); \n blk{1,1} = 's'; blk{1,2} = 2*ones(1,p); \n blk{2,1} = 'l'; blk{2,2} = p; \n\n E = zeros(p,m); \n for j = [1:m]; E(:,j) = B(:,j)./f; end;\n if any(E < 1e-10);\n error(' B(:,j)./f must have all entry positive'); \n end;\n for i = [1:p]; beta(i) = sum(E(i,:)); end; \n%%\n temp = zeros(2*p+1,1);\n temp(2:2:2*p) = ones(p,1); \n C{1,1} = spdiags(temp,1,2*p,2*p); C{1,1} = C{1,1} + C{1,1}'; \n C{2,1} = zeros(p,1); \n b = [zeros(m,1); 1];\n\n A = cell(2,m+1); \n temp = zeros(2*p,1);\n for k = 1:m\n temp(1:2:2*p-1) = -E(:,k);\n A{1,k} = spdiags(temp,0,2*p,2*p); \n A{2,k} = E(:,k);\n end;\n temp = zeros(2*p,1);\n temp(2:2:2*p) = ones(p,1); \n A{1,m+1} = spdiags(temp,0,2*p,2*p); \n A{2,m+1} = ones(p,1);\n%%\n Avec = svec(blk,A,ones(size(blk,1),1)); \n if (feas == 1); \n X0{1,1} = speye(2*p)/(2*p);\n X0{2,1} = ones(p,1)/(2*p); \n y0 = [ones(m,1); -1.1*max(beta)]/min(beta);\n Z0 = ops(C,'-',Atyfun(blk,Avec,[],[],y0));\n elseif (feas == 0);\n [X0,y0,Z0] = infeaspt(blk,Avec,C,b);\n end; \n if (solve)\n [obj,X,y,Z] = sqlp(blk,Avec,C,b,[],X0,y0,Z0);\n objval = -mean(obj);\n x = y(1:m);\n else\n objval = []; x = [];\n end \n%%***************************************************************\n", "meta": {"author": "goodshawn12", "repo": "REST", "sha": "e34ce521fcb36e7813357a9720072dd111edf797", "save_path": "github-repos/MATLAB/goodshawn12-REST", "path": "github-repos/MATLAB/goodshawn12-REST/REST-e34ce521fcb36e7813357a9720072dd111edf797/dependencies/BCILAB/dependencies/cvx-1.21.b795/sdpt3/Examples/logcheby.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.908617906830944, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.7407348360161655}} {"text": "% Script file: ode45_test1.m\n%\n% Purpose: \n% This program solves a differential equation of the\n% form dy/dt + 2 * y = 0, with the initial condition \n% y(0) = 1.\n%\n% Record of revisions:\n% Date Programmer Description of change\n% ==== ========== =====================\n% 03/15/07 S. J. Chapman Original code \n%\n% Define variables:\n% odefun_handle -- Handle to function that defines the derivative\n% tspan -- Duration to solve equation for\n% yo -- Initial condition for equation\n% t -- Array of solution times \n% y -- Array of solution values\n\n% Get a handle to the function that defines the\n% derivative.\nodefun_handle = @fun1;\n\n% Solve the equation over the period 0 to 5 seconds\ntspan = [0 5];\n\n% Set the initial conditions\ny0 = 1;\n\n% Call the differential equation solver.\n[t,y] = ode45(odefun_handle,tspan,y0);\n\n% Plot the result\nfigure(1);\nplot(t,y,'b-','LineWidth',2);\ngrid on;\ntitle('\\bfSolution of Differential Equation');\nxlabel('\\bfTime (s)');\nylabel('\\bf\\ity''');\n\n\n", "meta": {"author": "101Hub", "repo": "Matlab101", "sha": "07273f68f1147a110443aeb121fa10962234f298", "save_path": "github-repos/MATLAB/101Hub-Matlab101", "path": "github-repos/MATLAB/101Hub-Matlab101/Matlab101-07273f68f1147a110443aeb121fa10962234f298/assets/\u300aMatlab\u7f16\u7a0b\u300b\u6e90\u7801/chap7/ode45_test1.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9086178994073576, "lm_q2_score": 0.8152324848629214, "lm_q1q2_score": 0.7407348279247882}} {"text": "%% Machine Learning Online Class\n% Exercise 1: Linear regression with multiple variables\n%\n% Instructions\n% ------------\n%\n% This file contains code that helps you get started on the\n% linear regression exercise.\n%\n% You will need to complete the following functions in this\n% exericse:\n%\n% warmUpExercise.m\n% plotData.m\n% gradientDescent.m\n% computeCost.m\n% gradientDescentMulti.m\n% computeCostMulti.m\n% featureNormalize.m\n% normalEqn.m\n%\n% For this part of the exercise, you will need to change some\n% parts of the code below for various experiments (e.g., changing\n% learning rates).\n%\n\n%% Initialization\n\n%% ================ Part 1: Feature Normalization ================\n\n%% Clear and Close Figures\nclear ; close all; clc\n\nfprintf('Loading data ...\\n');\n\n%% Load Data\ndata = load('ex1data2.txt');\nX = data(:, 1:2);\ny = data(:, 3);\nm = length(y);\n\n% Print out some data points\nfprintf('First 10 examples from the dataset: \\n');\nfprintf(' x = [%.0f %.0f], y = %.0f \\n', [X(1:10,:) y(1:10,:)]');\n\nfprintf('Program paused. Press enter to continue.\\n');\npause;\n\n% Scale features and set them to zero mean\nfprintf('Normalizing Features ...\\n');\n\n[X mu sigma] = featureNormalize(X);\n\n% Add intercept term to X\nX = [ones(m, 1) X];\n\n\n%% ================ Part 2: Gradient Descent ================\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: We have provided you with the following starter\n% code that runs gradient descent with a particular\n% learning rate (alpha).\n%\n% Your task is to first make sure that your functions -\n% computeCost and gradientDescent already work with\n% this starter code and support multiple variables.\n%\n% After that, try running gradient descent with\n% different values of alpha and see which one gives\n% you the best result.\n%\n% Finally, you should complete the code at the end\n% to predict the price of a 1650 sq-ft, 3 br house.\n%\n% Hint: By using the 'hold on' command, you can plot multiple\n% graphs on the same figure.\n%\n% Hint: At prediction, make sure you do the same feature normalization.\n%\n\nfprintf('Running gradient descent ...\\n');\n\n% Choose some alpha value\nalpha = 0.01;\nnum_iters = 400;\n\n% Init Theta and Run Gradient Descent\ntheta = zeros(3, 1);\n[theta, J_history] = gradientDescentMulti(X, y, theta, alpha, num_iters);\n\n% Plot the convergence graph\nfigure;\nplot(1:numel(J_history), J_history, '-b', 'LineWidth', 2);\nxlabel('Number of iterations');\nylabel('Cost J');\n\n% Display gradient descent's result\nfprintf('Theta computed from gradient descent: \\n');\nfprintf(' %f \\n', theta);\nfprintf('\\n');\n\n% Estimate the price of a 1650 sq-ft, 3 br house\n% ====================== YOUR CODE HERE ======================\n% Recall that the first column of X is all-ones. Thus, it does\n% not need to be normalized.\n\nx = [1 1650 3]';\nprice = theta' * x;\n\n% ============================================================\n\nfprintf(['Predicted price of a 1650 sq-ft, 3 br house ' ...\n '(using gradient descent):\\n $%f\\n'], price);\n\nfprintf('Program paused. Press enter to continue.\\n');\npause;\n\n%% ================ Part 3: Normal Equations ================\n\nfprintf('Solving with normal equations...\\n');\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: The following code computes the closed form\n% solution for linear regression using the normal\n% equations. You should complete the code in\n% normalEqn.m\n%\n% After doing so, you should complete this code\n% to predict the price of a 1650 sq-ft, 3 br house.\n%\n\n%% Load Data\ndata = csvread('ex1data2.txt');\nX = data(:, 1:2);\ny = data(:, 3);\nm = length(y);\n\n% Add intercept term to X\nX = [ones(m, 1) X];\n\n% Calculate the parameters from the normal equation\ntheta = normalEqn(X, y);\n\n% Display normal equation's result\nfprintf('Theta computed from the normal equations: \\n');\nfprintf(' %f \\n', theta);\nfprintf('\\n');\n\n\n% Estimate the price of a 1650 sq-ft, 3 br house\n% ====================== YOUR CODE HERE ======================\n\nx = [1 1650 3]';\nprice = theta' * x;\n\n% ============================================================\n\nfprintf(['Predicted price of a 1650 sq-ft, 3 br house ' ...\n '(using normal equations):\\n $%f\\n'], price);\n\n", "meta": {"author": "zsiciarz", "repo": "ml-coursera", "sha": "54208ee72b88f1dc3c9235e644a47f618b80441c", "save_path": "github-repos/MATLAB/zsiciarz-ml-coursera", "path": "github-repos/MATLAB/zsiciarz-ml-coursera/ml-coursera-54208ee72b88f1dc3c9235e644a47f618b80441c/octave/ex1/ex1_multi.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744761936435, "lm_q2_score": 0.9059898241909247, "lm_q1q2_score": 0.7407141559496664}} {"text": "function [ xout, yout ] = quaerotate ( xin, yin )\n\n%*****************************************************************************80\n%\n%% QUAEROTATE applies a rotation.\n%\n% Licensing:\n%\n% This code is distributed under the GNU GPL license.\n%\n% Modified:\n%\n% 26 June 2014\n%\n% Author:\n%\n% Original FORTRAN77 version by Hong Xiao, Zydrunas Gimbutas.\n% This MATLAB version by John Burkardt.\n%\n% Reference:\n%\n% Hong Xiao, Zydrunas Gimbutas,\n% A numerical algorithm for the construction of efficient quadrature\n% rules in two and higher dimensions,\n% Computers and Mathematics with Applications,\n% Volume 59, 2010, pages 663-676.\n%\n% Parameters:\n%\n% Input, real XIN, YIN, the coordinates of the point.\n%\n% Output, real XOUT, YOUT, the coordinates of the point\n% after rotation.\n%\n\n%\n% Initialize the matrix of rotation.\n%\n theta = 2.0 * pi / 3.0;\n a11 = cos ( theta );\n a22 = cos ( theta );\n a12 = - sin ( theta );\n a21 = -a12;\n%\n% Apply the rotation matrix to the input vector.\n%\n xout = a11 * xin + a12 * yin;\n yout = a21 * xin + a22 * yin;\n\n return\nend", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/triangle_symq_rule/quaerotate.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898102301019, "lm_q2_score": 0.8175744695262777, "lm_q1q2_score": 0.7407141384950886}} {"text": "% Convert a stroke [x,y] such that it is uniformly sampled in space.\n%\n% Input\n% stk : [n x 2] stroke\n% dint : target distance between poitns\n%\n% Output\n% yi : [m x 2] interpolated stroke\n%\n\n%%\nfunction stk_yi = uniform_space_lerp(stk,dint)\n\n %% return if stroke is too short\n n = size(stk,1);\n if n==1\n stk_yi = stk;\n return;\n end\n \n %% compute distance between each point\n dist = zeros(n,1);\n tormv = false(n,1);\n for i=2:n \n x1 = stk(i,:);\n x2 = stk(i-1,:);\n dist(i) = norm(x1-x2);\n tormv(i) = dist(i) < 1e-4;\n end\n \n %% remove points that are too close\n dist(tormv) = [];\n stk(tormv,:) = [];\n \n %% return if stroke is too short\n n = size(stk,1);\n if n==1\n stk_yi = stk;\n return;\n end\n \n %% cumulative distance\n cumdist = cumsum(dist);\n start_dist = cumdist(1);\n end_dist = cumdist(end);\n x = cumdist(:);\n \n %% \n nint = round(end_dist/dint);\n nint = max(nint,2); \n xi = linspace(start_dist,end_dist,nint);\n stk_yi = interp1(x,stk,xi); \n \n bool_viz = false;\n if bool_viz\n figure\n hold on \n plot(stk_yi(:,1),stk_yi(:,2),'b.','MarkerSize',18); \n plot(stk(:,1),stk(:,2),'r.','MarkerSize',6); \n xlim([0 105]);\n ylim([-105 0]);\n end\n \n\nend", "meta": {"author": "brendenlake", "repo": "BPL", "sha": "2c7f679bb0055f29cbade7ef099897c3342bcb79", "save_path": "github-repos/MATLAB/brendenlake-BPL", "path": "github-repos/MATLAB/brendenlake-BPL/BPL-2c7f679bb0055f29cbade7ef099897c3342bcb79/data/uniform_space_lerp.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797172476384, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.7406682169577844}} {"text": "function jac = p18_jac ( neqn, t, y )\n\n%*****************************************************************************80\n%\n%% P18_JAC evaluates the jacobian for problem p18.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 23 February 2013\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer NEQN, the number of equations.\n%\n% Input, real T, Y(NEQN), the arguments of the jacobian.\n%\n% Output, real JAC(NEQN,NEQN), the jacobian matrix.\n%\n jac = zeros ( neqn, neqn );\n\n d = ( sqrt ( ( y(1).^2 + y(2).^2 ) ) ).^5;\n\n jac(1,3) = 1.0;\n jac(2,4) = 1.0;\n jac(3,1) = ( 2.0 * y(1).^2 - y(2).^2 ) / d;\n jac(3,2) = 3.0 * y(1) * y(2) / d;\n jac(4,1) = 3.0 * y(1) * y(2) / d;\n jac(4,2) = ( - y(1).^2 + 2.0 * y(2).^2 ) / d;\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_ode/p18_jac.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9111797075998823, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.7406682091154387}} {"text": "%% csapsPar\n% Below is a demonstration of the features of the |csapsPar| function\n\n%%\nclear; close all; clc;\n\n%% Syntax\n% |p=csapsPar(varargin);|\n\n%% Description \n% This function aims to compute the cubic smoothing spline parameter p for\n% the MATLAB csaps function. The input features the curve vertices V and\n% the parameter pw. The smoothing parameter p is derived using:\n% \n% p=1./(1+(((h.^3)/6)*f));\n%\n% Where h is the point spacing (derived from V) and f is defined as: \n%\n% f=(1/pw)-1; \n% \n% See also MATLAB's csaps documentation: \n% \n% The interesting range for p is close to 1./(1+((h.^3)/6)). The following\n% form is used introducing the factor f: p=1./(1+(((h.^3)/6)*f)). By using\n% f=10 we obtain p=1./(1+((h.^3)/60)) which should result in a close\n% following of the data. If instead f=0.1 is used, leading to\n% p=1./(1+((h.^3)/0.6)), a smoother result is obtained.\n\n%% Examples \n% \n\n%%\n% Create saw-tooth example curve\nV=[0 0 0; 1 2 0; 2 0 0; 3 -2 0; 4 0 0];\n\nn1=2;\nn2=2*n1; \n[V1]=subCurve(V,n1);\n[V2]=subCurve(V,n2);\n\n%%\n% Computing p parameters for the cubic smoothing spline based resampling\n\npw=0.5;\n\np1=csapsPar(V1,pw)\np2=csapsPar(V2,pw)\n\n% Resample curves using smoothing parameters\nn=100;\nV1f=evenlySampleCurve(V1,n,p1,0);\nV2f=evenlySampleCurve(V2,n,p2,0);\n\n%%\n% Visualizing curves\n\ncFigure; \nsubplot(1,2,1); hold on; \ntitle(['Input curve with ',num2str(size(V1,1)),' points'])\nplotV(V1,'k.-','LineWidth',1,'MarkerSize',25);\nplotV(V1f,'b-','LineWidth',3);\naxis tight; axis equal; grid on; box on; \n\nsubplot(1,2,2); hold on; \ntitle(['Input curve with ',num2str(size(V2,1)),' points'])\nplotV(V2,'k.-','LineWidth',1,'MarkerSize',25);\nplotV(V2f,'r-','LineWidth',3);\naxis tight; axis equal; grid on; box on; \n\ndrawnow; \n\n%%\n% \n% <>\n% \n% _*GIBBON*_ \n% \n% \n% _Kevin Mattheus Moerman_, \n%% \n% _*GIBBON footer text*_ \n% \n% License: \n% \n% GIBBON: The Geometry and Image-based Bioengineering add-On. A toolbox for\n% image segmentation, image-based modeling, meshing, and finite element\n% analysis.\n% \n% Copyright (C) 2006-2022 Kevin Mattheus Moerman and the GIBBON contributors\n% \n% This program is free software: you can redistribute it and/or modify\n% it under the terms of the GNU General Public License as published by\n% the Free Software Foundation, either version 3 of the License, or\n% (at your option) any later version.\n% \n% This program is distributed in the hope that it will be useful,\n% but WITHOUT ANY WARRANTY; without even the implied warranty of\n% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n% GNU General Public License for more details.\n% \n% You should have received a copy of the GNU General Public License\n% along with this program. If not, see .\n", "meta": {"author": "gibbonCode", "repo": "GIBBON", "sha": "8178520664a6148db939eaea87e75b3cba4f2b4f", "save_path": "github-repos/MATLAB/gibbonCode-GIBBON", "path": "github-repos/MATLAB/gibbonCode-GIBBON/GIBBON-8178520664a6148db939eaea87e75b3cba4f2b4f/docs/HELP_csapsPar.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797027760039, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.7406681969328696}} {"text": "function [W,fun,iter] = wLassomtl(X,y,XtX,Xty,lambda,W0,tol,maxiter,L,Lflag)\n% Lasso Multi-Task Learning\n% min_W ||XW - Y||_F^2 + \\sum_i lambda_ij*|W^ij|\n% By Nesterov's method\n% ------------------------------- Input ---------------------------------------------\n% X: block diagonal data matrix whose i-th block (n_i*d) is the data matrix of the i-th task\n% y: \\sum_i{n_i}*1 vector; response vector which is stacked by the reponses of all tasks\n% XtX: X'*X\n% Xty: X'*y\n% lambda: regularized parameter (vector)\n% W0: d*m matrix; starting point of W \n% tol: stopping tolerance\n% maxiter: maximum iterative steps\n% Lflag: estimate the upper bound of Lipschitz constant if nonzero, zero otherwise \n%\n% ------------------------------- Output -------------------------------------------\n%\n% W: output weight\n% fun: function values\n% iter: iterative steps \n%\n% -----------------------------------------------------------------------------------\n\nW = W0;\n[d,m] = size(W); % d: dimension, m: the number of tasks\n\nWn = W;\nt_new = 1; \nfun = zeros(maxiter+1,1);\n\n% Initial function value\nfun(1) = norm(X*W(:) - y)^2 + wL1norm(W,lambda);\ncount = 0;\nfor iter = 1:maxiter\n W_old = W;\n t_old = t_new;\n gradvec = 2*(XtX*Wn(:) - Xty);\n gradmat = reshape(gradvec,d,m);\n % If we estimate the upper bound of Lipschitz constant, no line search\n % is needed.\n if Lflag\n W = proximalwL1norm(Wn - gradmat/L, lambda/L);\n else\n % line search \n for inneriter = 1:20\n W = proximalwL1norm(Wn - gradmat/L, lambda/L);\n dW = W - Wn;\n if 2*(dW(:)'*XtX*dW(:)) <= L*sum(sum((dW.*dW)))\n break;\n else\n L = L*2;\n end\n end\n end\n fun(iter+1) = norm(X*W(:) - y)^2 + wL1norm(W,lambda);\n % stopping condition\n if abs(fun(iter) - fun(iter+1))/fun(iter+1) < tol\n count = count + 1;\n else\n count = 0;\n end\n if count >= 1\n break;\n end\n\n % Update the coefficient\n t_new = (1+sqrt(1+4*t_old^2))/2;\n Wn = W + (t_old-1)/t_new*(W - W_old);\n \nend\n\n\n", "meta": {"author": "jiayuzhou", "repo": "MALSAR", "sha": "fb9751594983df020ddc4f7e4a40520ee7c37989", "save_path": "github-repos/MATLAB/jiayuzhou-MALSAR", "path": "github-repos/MATLAB/jiayuzhou-MALSAR/MALSAR-fb9751594983df020ddc4f7e4a40520ee7c37989/MALSAR/functions/msmtfl/wLassomtl.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111796979521253, "lm_q2_score": 0.8128673155708975, "lm_q1q2_score": 0.7406681950770453}} {"text": "function stroud_test322 ( )\n\n%*****************************************************************************80\n%\n%% TEST322 tests SPHERE_CAP_AREA_3D, SPHERE_CAP_AREA_ND.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 06 April 2009\n%\n% Author:\n%\n% John Burkardt\n%\n dim_num = 3;\n ntest = 12;\n r = 1.0;\n center = [ 0.0, 0.0, 0.0 ];\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TEST322\\n' );\n fprintf ( 1, ' SPHERE_CAP_AREA_3D computes the volume of a\\n' );\n fprintf ( 1, ' 3D spherical cap, defined by a plane that cuts the\\n' );\n fprintf ( 1, ' sphere to a thickness of H units.\\n' );\n fprintf ( 1, ' SPHERE_CAP_AREA_ND computes the volume of an\\n' );\n fprintf ( 1, ' ND spherical cap, defined by a plane that cuts the\\n' );\n fprintf ( 1, ' sphere to a thickness of H units.\\n' );\n\n area1 = sphere_area_3d ( r );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Area of the total sphere in 3D = %f\\n', area1 );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' R H Cap Cap\\n' );\n fprintf ( 1, ' area_3d area_nd\\n' );\n fprintf ( 1, '\\n' );\n\n for i = 0 : ntest + 1\n\n h = 2.0 * r * i / ntest;\n\n area1 = sphere_cap_area_3d ( r, h );\n\n area2 = sphere_cap_area_nd ( dim_num, r, h );\n\n fprintf ( 1, ' %12.6f %12.6f %12,6f %12.6f\\n', r, h, area1, area2 );\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/stroud/stroud_test322.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382094310355, "lm_q2_score": 0.8596637577007394, "lm_q1q2_score": 0.7406331745222506}} {"text": "function I=getNextCombo(I,n,startVal)\n%%GETNEXTCOMBO Return the next combination in lexicographic order given the\n% current combination. If the final combination in the\n% sequence has been reached, then an empty matrix is returned.\n% The first element in the combination is the least\n% significant element for defining the lexicographic order.\n%\n%INPUTS: I The rX1 or 1Xr current combination of r elements. The next\n% combination in lexicographic order is desired. The first element\n% is the least significant and one begins with I=[0;1;2;...;r-1]\n% is startVal=0 and I=[1;2;3;...;r] if startVal=1.\n% n The number of items from which r items are chosen for\n% combinations. The elements of I can range from 0 to n-1. if\n% startVal=0 or they range from 1 to n if startVal=1.\n% startVal This is zero or 1, indicating which value the value at which the\n% elements in I can start. The default if omitted or an empty\n% matrix is passed is 0.\n%\n%OUTPUTS: I The next combination in the lexicographic sequence, or an empty\n% matrix if the final combination in the lexicographic ordering\n% is provided.\n%\n%This function can be useful for generating combinations when used in a\n%loop. It is more computationally efficient than sequentially unranking the\n%combinations. If the final combination is put in, an empty matrix will be\n%returned.\n%\n%The algorithm is from [1], with an option to start at 0 instead of 1.\n%\n%REFERENCES:\n%[1] C. J. Mifsud, \"Algorithm 154: Combination in lexicographical order,\" \n% Communications of the ACM, vol. 6, no. 3 pp. 103, Mar. 1963.\n% modified to start from zero instead of one.\n%\n%September 2013 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nif(nargin<3||isempty(startVal))\n startVal=0; \nend\n\nif(startVal==0)\n r=length(I);\n if(I(r) 1\n initial_solution = true;\n ydata = no_dims;\n no_dims = size(ydata, 2);\n else\n initial_solution = false;\n end\n \n % Compute joint probabilities\n D = D / max(D(:)); % normalize distances\n P = d2p(D .^ 2, perplexity, 1e-5); % compute affinities using fixed perplexity\n \n % Run t-SNE\n if initial_solution\n ydata = tsne_p(P, labels, ydata);\n else\n ydata = tsne_p(P, labels, no_dims);\n end\n ", "meta": {"author": "tobyma2020", "repo": "cluster", "sha": "c9c3706523859f8c34f9741be94fb2dd89fa4cc0", "save_path": "github-repos/MATLAB/tobyma2020-cluster", "path": "github-repos/MATLAB/tobyma2020-cluster/cluster-c9c3706523859f8c34f9741be94fb2dd89fa4cc0/dr/drtoolbox/techniques/tsne_d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942014971871, "lm_q2_score": 0.8198933381139646, "lm_q1q2_score": 0.7406048981645169}} {"text": "function [oHDev] = calculateHDEV(tau,sPeriod,readings)\n%Overlapping Hadamard (ADEV) function that uses phase error or time error values\n%input argument is readings already grouped as tau values. tau is the\n%desired gate or tau time needed for calculating overlap. \n%sPeriod is used to determine the overlap\n\nN = numel(readings); %get the reading count\nn = tau / sPeriod; %calculate averaging factor\nn = floor(n); %make sure this is an integer\nconst = 1/(6*(N - (3*n))*tau^2); %calculate the const mult 1/(2*(N - (2*n))*tau^2)\n%sum from i=1 to N-(3*n) (Xi+3m - 3Xi+2m + 3Xi+m - Xi)^2\nsum = 0; %variable to store summation calculation\n\n\n%loop for performing summation\nfor i = 1:(N-(3*n))\n sum = sum + (readings(i+(3*n)) - (3*readings(i+(2*n))) + (3*readings(i+n)) - readings(i))^2; \nend\n\noHDev = sqrt(const*sum); %square root for Allan Dev", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/31319-stability-analyzer-53230a/Stability Analyzer 2.0/calculateHDEV.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133498259924, "lm_q2_score": 0.7879311956428946, "lm_q1q2_score": 0.7405870495291125}} {"text": "function J2=numDiff2(x,f,fDim,N,epsilon)\n%%NUMDIFF2 Numerically compute the second derivatives using central\n% difference formulae based on Lagrange interpolating polynomials.\n% The algorithm is made to alert (and not crash) in the event that\n% f fails. Specifically, if f returns an empty matrix or it any of\n% the components of f are NaNs, then the numDiff function will\n% terminate early, returning an empty matrix to indicate failure.\n% The function only computes second derivatives, not considering\n% cross terms (it does not find a Hessian matrix). Use numDiffHess\n% to get a Hessian matrix with cross terms.\n%\n%INPUTS: x The xDimX1 vector or scalar point at which the second derivative\n% of the (possibly vector) function is desired.\n% f The scalar or vector function that is to be differentiated. The\n% function f must take x as its parameter and its output should be\n% a scalar or a column vector.\n% fDim The dimensionality of the output of f.\n% N A number >=1 specifying the order of the second derivative\n% approximation. Values for n=1 through 3 are explicitly coded in.\n% For values 3 and above, the coefficients of the second\n% derivative of the Lagrange interpolating polynomial are\n% explicitly solved. If omitted, a value of N=1 is used.\n% epsilon A scalar or xDimX1 vector quantity specifying the finite step\n% size used for numerical differentiation. If a scalar value is\n% given, that value is used for differentiating with respect to\n% elements of xDim. If an xDimX1 value is given, then the\n% corresponding element of epsilon is used to differentiate each\n% element of x. If epsilon is omitted, then\n% epsilon=max(1e-5*x,1e-7); is used.\n%\n%OUTPUTS: J2 A fDimXxDim matrix of second derivatives. Each column is the\n% derivative vector of f with respect to the corresponding\n% element of x. If at any point the function f returned a NaN or\n% an empty matrix, J2 will be an empty matrix.\n%\n%The function is similar to the numDiff function. Central-difference\n%numerical differentiation is discussed in terms of Lagrange interpolating\n%polynomials in Chapter 4.1 of [1]. The Lagrange interpolating polynomials\n%themselves are discussed in Chapter 3 of [1]. In general, the coefficients\n%of the interpolating polynomial for first derivative central difference\n%numerical differentiation come from Equation 4.2, which expresses them in\n%terms of the first derivative of a Lagrange interpolating polynomial. This\n%function just extends the concept by using the second-derivative\n%coefficients.\n%\n%REFERENCES:\n%[1] R. L. Burden and J. D. Faires, Numerical Analysis, 9th ed. Boston, MA:\n% Brooks/ Cole, 2011.\n%\n%April 2015 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nif(nargin<4)\n N=1; \nend\n\nswitch(N)\n case 1\n a=[1; -2; 1];\n case 2\n a=[-1/12; 4/3; -5/2; 4/3; -1/12];\n case 3\n a=[1/90; -3/20; 3/2; -49/18; 3/2; -3/20; 1/90];\n otherwise\n [~,~,d2Li]=LagrangeInterpPoly(-N:1:N);\n a=d2Li(end,:);\nend\n\nxDim=size(x,1);\n\nif(nargin<5)\n %If epsilon is not specified, then use some ad-hoc default value\n epsilon=max(1e-5*x,1e-7);\nend\n\nif(isscalar(epsilon))\n epsilon=repmat(epsilon,[xDim,1]); \nend\n\nJ2=zeros(fDim,xDim);\nfor curEl=1:xDim\n epsCur=epsilon(curEl);\n \n curIdx=1;\n for curP=-N:1:N\n xP=x;\n xP(curEl)=xP(curEl)+curP*epsCur;\n fxP=f(xP);\n if(isempty(fxP)||any(isnan(fxP)))\n J2=[];\n return;\n end\n J2(:,curEl)=J2(:,curEl)+a(curIdx)*fxP;\n curIdx=curIdx+1;\n end\n J2(:,curEl)=J2(:,curEl)/(epsCur^2);\nend\n\nend\n\n%LICENSE:\n%\n%The source code is in the public domain and not licensed or under\n%copyright. The information and software may be used freely by the public.\n%As required by 17 U.S.C. 403, third parties producing copyrighted works\n%consisting predominantly of the material produced by U.S. government\n%agencies must provide notice with such work(s) identifying the U.S.\n%Government material incorporated and stating that such material is not\n%subject to copyright protection.\n%\n%Derived works shall not identify themselves in a manner that implies an\n%endorsement by or an affiliation with the Naval Research Laboratory.\n%\n%RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF THE\n%SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY THE NAVAL\n%RESEARCH LABORATORY FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE ACTIONS\n%OF RECIPIENT IN THE USE OF THE SOFTWARE.\n", "meta": {"author": "USNavalResearchLaboratory", "repo": "TrackerComponentLibrary", "sha": "9f6e329de5be06a371757c4b853200beb6def2d0", "save_path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary", "path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary/TrackerComponentLibrary-9f6e329de5be06a371757c4b853200beb6def2d0/Mathematical_Functions/numDiff2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511616741042, "lm_q2_score": 0.8652240756264638, "lm_q1q2_score": 0.740503030233312}} {"text": "function r8sm_print ( m, n, a, u, v, title )\n\n%*****************************************************************************80\n%\n%% R8SM_PRINT prints a R8SM matrix.\n%\n% Discussion:\n%\n% The R8SM storage format is used for an M by N Sherman Morrison matrix B,\n% which is defined by an M by N matrix A, an M vector U, and\n% an N vector V, by B = A - U * V'\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 07 April 2006\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer M, N, the number of rows and columns of the matrix.\n%\n% Input, real A(M,N), the R8SM matrix.\n%\n% Input, real U(M), V(N), the R8SM vectors.\n%\n% Input, string TITLE, a title to be printed.\n%\n r8sm_print_some ( m, n, a, u, v, 1, 1, m, n, title );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/linplus/r8sm_print.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8652240756264639, "lm_q2_score": 0.8558511524823263, "lm_q1q2_score": 0.7405030222803646}} {"text": "function bohach2_test ( )\n\n%*****************************************************************************80\n%\n%% BOHACH2_TEST works with the Bohachevsky function #2.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 21 December 2011\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Zbigniew Michalewicz,\n% Genetic Algorithms + Data Structures = Evolution Programs,\n% Third Edition,\n% Springer Verlag, 1996,\n% ISBN: 3-540-60676-9,\n% LC: QA76.618.M53.\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'BOHACH2_TEST:\\n' );\n fprintf ( 1, ' Test COORDINATE_SEARCH with the Bohachevsky function #2.\\n' );\n n = 2;\n\n x = [ 0.6, 1.3 ];\n r8vec_print ( n, x, ' Initial point X0:' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' F(X0) = %g\\n', bohach2 ( x ) );\n\n flag = 0;\n x = coordinate_search ( x, @bohach2, flag );\n r8vec_print ( n, x, ' Estimated minimizer X1:' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' F(X1) = %g\\n', bohach2 ( x ) );\n%\n% Demonstrate correct minimizer.\n%\n x = [ 0.0, 0.0 ];\n r8vec_print ( n, x, ' Correct minimizer X*:' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' F(X*) = %g\\n', bohach2 ( x ) );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/coordinate_search/bohach2_test.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240686758841, "lm_q2_score": 0.8558511451289037, "lm_q1q2_score": 0.7405030099693446}} {"text": "function fn = facenormals( V,F )\n%FACENORMALS Compute face normals of triangular mesh\n% V - nverts by 3 matrix containing vertex positions\n% F - ntri by 3 matrix containing triangle vertex indices\n\n% Get the triangle vertices\nv1 = F(:, 1);\nv2 = F(:, 2);\nv3 = F(:, 3);\n\n% Compute the edge vectors\ne1s = V(v2, :) - V(v1, :);\ne2s = V(v3, :) - V(v1, :);\n\n% Compute cross products between edge vectors\nfn = cross(e1s, e2s, 2);\n\n% Normalise face normals to unit length\nnorms = sqrt(fn(:,1).^2+fn(:,2).^2+fn(:,3).^2);\nfn=fn./repmat(norms,[1 3]);\n\nend\n\n", "meta": {"author": "waps101", "repo": "3DMM_edges", "sha": "848e9775c0581ae97469eacad60dfe3943c30707", "save_path": "github-repos/MATLAB/waps101-3DMM_edges", "path": "github-repos/MATLAB/waps101-3DMM_edges/3DMM_edges-848e9775c0581ae97469eacad60dfe3943c30707/utils/facenormals.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8933094060543488, "lm_q2_score": 0.8289388104343893, "lm_q1q2_score": 0.7404988364045428}} {"text": "function [ output_maps ] = max_pooling( input_maps)\n%POOLING Summary of this function goes here\n% Detailed explanation goes here\n \n orig_rows = size(input_maps,1);\n orig_cols = size(input_maps,2);\n \n pooled_rows = ceil(orig_rows / 2);\n pooled_cols = ceil(orig_cols / 2);\n\n up_to_rows_out = floor(orig_rows / 2);\n up_to_cols_out = floor(orig_cols / 2);\n\n if(mod(orig_cols,2) == 0)\n up_to_cols = orig_cols;\n else\n up_to_cols = orig_cols - 1;\n end\n \n if(mod(orig_rows,2) == 0)\n up_to_rows = orig_rows;\n else\n up_to_rows = orig_rows - 1;\n end\n \n output_maps = zeros(pooled_rows, pooled_cols, size(input_maps,3));\n for i=1:size(input_maps,3)\n temp = im2col(input_maps(1:up_to_rows,1:up_to_cols,i), [2,2], 'distinct');\n max_val = max(temp);\n output_maps(1:up_to_rows_out,1:up_to_cols_out,i) = reshape(max_val, up_to_rows_out, up_to_cols_out); \n end\n \n % A bit of a hack for non-even number of rows or columns\n if(mod(orig_cols,2) ~= 0)\n for i=1:size(input_maps,3)\n temp = im2col(input_maps(1:up_to_rows,end,i), [2,1], 'distinct');\n max_val = max(temp);\n output_maps(1:up_to_rows_out,end,i) = max_val; \n end \n end\n\n if(mod(orig_rows,2) ~= 0)\n for i=1:size(input_maps,3)\n temp = im2col(input_maps(end, 1:up_to_cols,i), [1,2], 'distinct');\n max_val = max(temp);\n output_maps(end, 1:up_to_cols_out,i) = max_val; \n end \n end\n \n if(mod(orig_cols,2) ~= 0 && mod(orig_rows,2) ~= 0)\n output_maps(end,end,:) = input_maps(end,end,:);\n end\n \n\n \nend\n\n", "meta": {"author": "TadasBaltrusaitis", "repo": "OpenFace", "sha": "3d4b5cf8d96138be42bed229447f36cbb09a5a29", "save_path": "github-repos/MATLAB/TadasBaltrusaitis-OpenFace", "path": "github-repos/MATLAB/TadasBaltrusaitis-OpenFace/OpenFace-3d4b5cf8d96138be42bed229447f36cbb09a5a29/matlab_version/face_detection/mtcnn/max_pooling.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094060543488, "lm_q2_score": 0.8289387998695209, "lm_q1q2_score": 0.7404988269668464}} {"text": "function prob_test035 ( )\n\n%*****************************************************************************80\n%\n%% TEST035 tests CHI_SQUARE_NONCENTRAL_MEAN, ***_SAMPLE, ***_VARIANCE.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 15 April 2009\n%\n% Author:\n%\n% John Burkardt\n%\n nsample = 1000;\n seed = 123456789;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TEST035\\n' );\n fprintf ( 1, ' For the noncentral chi square PDF:\\n' );\n fprintf ( 1, ' CHI_SQUARE_NONCENTRAL_SAMPLE samples.\\n' );\n\n a = 3.0;\n b = 2.0;\n\n check = chi_square_noncentral_check ( a, b );\n\n if ( ~check );\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TEST035 - Fatal error!\\n' );\n fprintf ( 1, ' The parameters are not legal.\\n' );\n return\n end\n\n mean = chi_square_noncentral_mean ( a, b );\n variance = chi_square_noncentral_variance ( a, b );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' PDF parameter A = %14f\\n', a );\n fprintf ( 1, ' PDF parameter B = %14f\\n', b );\n fprintf ( 1, ' PDF mean = %14f\\n', mean );\n fprintf ( 1, ' PDF variance = %14f\\n', variance );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Initial seed = %12d\\n', seed );\n\n for i = 1 : nsample\n [ x(i), seed ] = chi_square_noncentral_sample ( a, b, seed );\n end\n\n mean = r8vec_mean ( nsample, x );\n variance = r8vec_variance ( nsample, x );\n xmax = max ( x(1:nsample) );\n xmin = min ( x(1:nsample) );\n\n fprintf ( 1, ' Final seed = %12d\\n', seed );\n fprintf ( 1, ' Sample size = %6d\\n', nsample );\n fprintf ( 1, ' Sample mean = %14f\\n', mean );\n fprintf ( 1, ' Sample variance = %14f\\n', variance );\n fprintf ( 1, ' Sample maximum = %14f\\n', xmax );\n fprintf ( 1, ' Sample minimum = %14f\\n', xmin );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/prob/prob_test035.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818408, "lm_q2_score": 0.8438951005915208, "lm_q1q2_score": 0.7404983618387125}} {"text": "function [C,numberOfOverlapPixels] = normxcorr2_general(varargin)\n%NORMXCORR2_GENERAL Normalized two-dimensional cross-correlation.\n% [C,numberOfOverlapPixels] = NORMXCORR2_GENERAL(TEMPLATE,A) computes the\n% normalized cross-correlation of matrices TEMPLATE and A. The resulting\n% matrix C contains correlation coefficients and its values may range\n% from -1.0 to 1.0.\n%\n% [C,numberOfOverlapPixels] =\n% NORMXCORR2_GENERAL(TEMPLATE,A,requiredNumberOfOverlapPixels) sets to 0\n% all locations in C computed from positions where A and T overlap less\n% than requiredNumberOfOverlapPixels.\n% Larger values of requiredNumberOfOverlapPixels zero-out pixels on a\n% larger border around C. \n% Thus, larger values remove less stable computations but also limit the\n% capture range. \n% If the template is smaller than the image and it is desired that the\n% computation only be carried out when the template is fully overlapping\n% the image, requiredNumberOfOverlapPixels should be set to\n% numel(template).\n% The default is set to 0, meaning no modifications to C.\n%\n% Limitations of normxcorr2:\n% The documentation of normxcorr2 states that, \"The matrix A must be\n% larger than the matrix TEMPLATE for the normalization to be\n% meaningful.\" It is implemented following the details of the paper \"Fast\n% Normalized Cross-Correlation\", by J. P. Lewis, Industrial Light &\n% Magic. This approach assumes the template is small relative to the\n% image and proceeds to calculate the normalization across the entire\n% template. This leads to correct computations wherever the template is\n% wholly overlapping with the image, but the computation is incorrect in\n% the borders of the output (the border size is proportional to the\n% template size). This problem is therefore worse for larger templates\n% to the point that, when the template is the same size as the image, the\n% only correct value is at the center pixel (where the images are fully\n% overlapping). Thus, if normxcorr2 is used for such things as\n% registering images of the same size, the result will be incorrect.\n% \n% The new normxcorr2_general:\n% normxcorr2_general is more general than normxcorr2 in that it gives\n% correct results everywhere regardless of the relative size of A and\n% TEMPLATE. It accomplishes this by computing the normalized correlation\n% only in the overlap regions between the two matrices. Thus, the result\n% is correct for all locations of correlation. The result is the same as\n% if the NCC were carried out in the spatial domain (which would take a\n% long time to compute for large matrices).\n% \n% Class Support\n% -------------\n% The input matrices can be numeric. The output matrix C is double.\n%\n% Example\n% -------\n% This example correlates an input with itself using normxcorr2 (the\n% built-in Matlab version) and normxcorr2_general (the general version).\n% Because the template is not small compared with the input image (they\n% are the same size in this case), the output of normxcorr2.m is\n% incorrect for most pixels. On the other hand, the general version is\n% correct at all locations, which can be easily verified analytically or\n% visually.\n% \n% Note that the image processing toolbox (IPT) is needed to run this\n% example since normxcorr2 is part of that toolbox. However,\n% normxcorr2_general does not require the IPT.\n% \n% input = repmat([1:6 5:-1:1],11,1);\n% normxcorr2_output = normxcorr2(input,input);\n% normxcorr2_general_output = normxcorr2_general(input,input);\n% figure;\n% subplot(2,2,1), imagesc(input); title('Input pattern');\n% subplot(2,2,3), imagesc(normxcorr2_output); title('Output of Matlab built-in normxcorr2');\n% subplot(2,2,4), imagesc(normxcorr2_general_output); title('Output of normxcorr2\\_general');\n%\n% See also NORMXCORR2.\n%\n% References: Dirk Padfield. \"Masked FFT registration\". In Proc. Computer\n% Vision and Pattern Recognition, 2010.\n%\n% Author: Dirk Padfield, GE Global Research, padfield@research.ge.com\n%\n\n% Input-output specs\n% ------------------\n% T: 2-D, real, full matrix\n% logical, uint8, uint16, or double\n% no NaNs, no Infs\n% prod(size(T)) >= 2\n%\n% A: 2-D, real, full matrix\n% logical, uint8, uint16, or double\n% no NaNs, no Infs\n% prod(size(A)) >= 2\n%\n% C: double\n\n[T, A, requiredNumberOfOverlapPixels] = ParseInputs(varargin{:});\n\nsizeA = size(A);\nsizeT = size(T);\n\n% Find the number of pixels used for the calculation as the two images are\n% correlated. The size of this image will be the same as the correlation\n% image. \nnumberOfOverlapPixels = local_sum(ones(sizeA),sizeT(1),sizeT(2));\n\nlocal_sum_A = local_sum(A,sizeT(1),sizeT(2));\nlocal_sum_A2 = local_sum(A.*A,sizeT(1),sizeT(2));\n\n% Note: diff_local_sums should be nonnegative, but it may have negative\n% values due to round off errors. Below, we use max to ensure the radicand\n% is nonnegative.\ndiff_local_sums_A = ( local_sum_A2 - (local_sum_A.^2)./ numberOfOverlapPixels );\nclear local_sum_A2;\ndenom_A = max(diff_local_sums_A,0); \nclear diff_local_sums_A;\n\n% Flip T in both dimensions so that its correlation can be more easily\n% handled.\nrotatedT = rot90(T,2);\nlocal_sum_T = local_sum(rotatedT,sizeA(1),sizeA(2));\nlocal_sum_T2 = local_sum(rotatedT.*rotatedT,sizeA(1),sizeA(2));\nclear rotatedT;\n\ndiff_local_sums_T = ( local_sum_T2 - (local_sum_T.^2)./ numberOfOverlapPixels );\nclear local_sum_T2;\ndenom_T = max(diff_local_sums_T,0); \nclear diff_local_sums_T;\n\ndenom = sqrt(denom_T .* denom_A);\nclear denom_T denom_A;\n\nxcorr_TA = xcorr2_fast(T,A);\nclear A T;\nnumerator = xcorr_TA - local_sum_A .* local_sum_T ./ numberOfOverlapPixels;\nclear xcorr_TA local_sum_A local_sum_T;\n\n% denom is the sqrt of the product of positive numbers so it must be\n% positive or zero. Therefore, the only danger in dividing the numerator\n% by the denominator is when dividing by zero. We know denom_T~=0 from\n% input parsing; so denom is only zero where denom_A is zero, and in these\n% locations, C is also zero.\nC = zeros(size(numerator));\ntol = 1000*eps( max(abs(denom(:))) );\ni_nonzero = find(denom > tol);\nC(i_nonzero) = numerator(i_nonzero) ./ denom(i_nonzero);\nclear numerator denom;\n\n% Remove the border values since they result from calculations using very\n% few pixels and are thus statistically unstable.\n% By default, requiredNumberOfOverlapPixels = 0, so C is not modified.\nif( requiredNumberOfOverlapPixels > max(numberOfOverlapPixels(:)) )\n error(['ERROR: requiredNumberOfOverlapPixels ' num2str(requiredNumberOfOverlapPixels) ...\n ' must not be greater than the maximum number of overlap pixels ' ...\n num2str(max(numberOfOverlapPixels(:))) '.']);\nend\nC(numberOfOverlapPixels < requiredNumberOfOverlapPixels) = 0;\n\n\n%-------------------------------\n% Function local_sum\n%\nfunction local_sum_A = local_sum(A,m,n)\n\n% This algorithm depends on precomputing running sums.\n\n% If m,n are equal to the size of A, a faster method can be used for\n% calculating the local sum. Otherwise, the slower but more general method\n% can be used. The faster method is more than twice as fast and is also\n% less memory intensive. \nif( m == size(A,1) && n == size(A,2) )\n s = cumsum(A,1);\n c = [s; repmat(s(end,:),m-1,1) - s(1:end-1,:)];\n s = cumsum(c,2);\n clear c;\n local_sum_A = [s, repmat(s(:,end),1,n-1) - s(:,1:end-1)];\nelse\n % Break the padding into parts to save on memory.\n B = zeros(size(A,1)+2*m,size(A,2));\n B(m+1:m+size(A,1),:) = A;\n s = cumsum(B,1);\n c = s(1+m:end-1,:)-s(1:end-m-1,:);\n d = zeros(size(c,1),size(c,2)+2*n);\n d(:,n+1:n+size(c,2)) = c;\n s = cumsum(d,2);\n local_sum_A = s(:,1+n:end-1)-s(:,1:end-n-1);\nend\n\n\n%-------------------------------\n% Function xcorr2_fast\n%\nfunction cross_corr = xcorr2_fast(T,A)\n\nT_size = size(T);\nA_size = size(A);\noutsize = A_size + T_size - 1;\n\n% Figure out when to use spatial domain vs. freq domain\nconv_time = time_conv2(T_size,A_size); % 1 conv2\nfft_time = 3*time_fft2(outsize); % 2 fft2 + 1 ifft2\n\nif (conv_time < fft_time)\n cross_corr = conv2(rot90(T,2),A);\nelse\n cross_corr = freqxcorr(T,A,outsize);\nend\n\n\n%-------------------------------\n% Function freqxcorr\n%\nfunction xcorr_ab = freqxcorr(a,b,outsize)\n \n% Find the next largest size that is a multiple of a combination of 2, 3,\n% and/or 5. This makes the FFT calculation much faster.\noptimalSize(1) = FindClosestValidDimension(outsize(1));\noptimalSize(2) = FindClosestValidDimension(outsize(2));\n\n% Calculate correlation in frequency domain\nFa = fft2(rot90(a,2),optimalSize(1),optimalSize(2));\nFb = fft2(b,optimalSize(1),optimalSize(2));\nxcorr_ab = real(ifft2(Fa .* Fb));\n\nxcorr_ab = xcorr_ab(1:outsize(1),1:outsize(2));\n\n\n%-------------------------------\n% Function time_conv2\n%\nfunction time = time_conv2(obssize,refsize)\n\n% time a spatial domain convolution for 10-by-10 x 20-by-20 matrices\n\n% a = ones(10);\n% b = ones(20);\n% mintime = 0.1;\n\n% t1 = cputime;\n% t2 = t1;\n% k = 0;\n% while (t2-t1) 3 )\n error('ERROR: The number of arguments must be either 2 or 3. Please see the documentation for details.');\nend\n\nT = varargin{1};\nA = varargin{2};\n\nif( nargin == 3 )\n requiredNumberOfOverlapPixels = varargin{3};\nelse\n requiredNumberOfOverlapPixels = 0;\nend\n\n% The following requires the image processing toolbox, so it is commented\n% out here for generality.\n%iptcheckinput(T,{'logical','numeric'},{'real','nonsparse','2d','finite'},mfilename,'T',1)\n%iptcheckinput(A,{'logical','numeric'},{'real','nonsparse','2d','finite'},mfilename,'A',2)\n\ncheckSizesTandA(T,A)\n\n% See geck 342320. If either A or T has a minimum value which is negative, we\n% need to shift the array so all values are positive to ensure numerically\n% robust results for the normalized cross-correlation.\nA = shiftData(A);\nT = shiftData(T);\n\ncheckIfFlat(T);\n\n%-----------------------------------------------------------------------------\nfunction B = shiftData(A)\n\nB = double(A);\n\nis_unsigned = isa(A,'uint8') || isa(A,'uint16') || isa(A,'uint32');\nif ~is_unsigned\n \n min_B = min(B(:)); \n \n if min_B < 0\n B = B - min_B;\n end\n \nend\n\n%-----------------------------------------------------------------------------\nfunction checkSizesTandA(T,A)\n\nif numel(T) < 2\n eid = sprintf('Images:%s:invalidTemplate',mfilename);\n msg = 'TEMPLATE must contain at least 2 elements.';\n error(eid,'%s',msg);\nend\n\n%-----------------------------------------------------------------------------\nfunction checkIfFlat(T)\n\nif std(T(:)) == 0\n eid = sprintf('Images:%s:sameElementsInTemplate',mfilename);\n msg = 'The values of TEMPLATE cannot all be the same.';\n error(eid,'%s',msg);\nend\n\n%-----------------------------------------------------------------------------\nfunction [newNumber] = FindClosestValidDimension(n)\n\n% Find the closest valid dimension above the desired dimension. This\n% will be a combination of 2s, 3s, and 5s.\n\n% Incrementally add 1 to the size until\n% we reach a size that can be properly factored.\nnewNumber = n;\nresult = 0;\nnewNumber = newNumber - 1;\nwhile( result ~= 1 )\n newNumber = newNumber + 1;\n result = FactorizeNumber(newNumber);\nend\n\n%-----------------------------------------------------------------------------\nfunction [n] = FactorizeNumber(n)\n\nfor ifac = [2 3 5]\n while( rem(n,ifac) == 0 )\n n = n/ifac;\n end\nend", "meta": {"author": "kavli-ntnu", "repo": "MINI2P_toolbox", "sha": "83311a49baea69ecf027e19390e608fd4eaeae8d", "save_path": "github-repos/MATLAB/kavli-ntnu-MINI2P_toolbox", "path": "github-repos/MATLAB/kavli-ntnu-MINI2P_toolbox/MINI2P_toolbox-83311a49baea69ecf027e19390e608fd4eaeae8d/Analysis/+SpatialTuning_BNT/normxcorr2_general.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767842777552, "lm_q2_score": 0.8438950986284991, "lm_q1q2_score": 0.7404983574122944}} {"text": "function [shortestPaths, totalCosts] = kShortestPath(netCostMatrix, source, destination, k_paths)\n% Function kShortestPath(netCostMatrix, source, destination, k_paths) \n% returns the K first shortest paths (k_paths) from node source to node destination\n% in the a network of N nodes represented by the NxN matrix netCostMatrix.\n% In netCostMatrix, cost of 'inf' represents the 'absence' of a link \n% It returns \n% [shortestPaths]: the list of K shortest paths (in cell array 1 x K) and \n% [totalCosts] : costs of the K shortest paths (in array 1 x K)\n%==============================================================\n% Meral Shirazipour\n% This function is based on Yen's k-Shortest Path algorithm (1971)\n% This function calls a slightly modified function dijkstra() \n% by Xiaodong Wang 2004.\n% * netCostMatrix must have positive weights/costs\n%==============================================================\n% DATE : December 9 decembre 2009 \n% Last Updated: August 2 2010; January 6 2011; August 2 2011\n% ----Changes April 2 2010:----\n% 1-previous version(9/12/2009)did not handle some exceptions which should\n% have returned empty matrices for the return values (added lines 20 and 29)\n% 2-includes the changes proposed by Darren Rowland\n% ----Changes January 6 2011:----\n% 1-fixed a bug reported by Babak Zafari that prevented from finding ALL\n% the shortest paths in large networks\n%==============================================================\nif source > size(netCostMatrix,1) || destination > size(netCostMatrix,1)\n warning('The source or destination node are not part of netCostMatrix');\n shortestPaths=[];\n totalCosts=[];\nelse\n %---------------------INITIALIZATION---------------------\n k=1;\n [path cost] = dijkstra(netCostMatrix, source, destination);\n %P is a cell array that holds all the paths found so far:\n if isempty(path)\n shortestPaths=[];\n totalCosts=[];\n else\n path_number = 1; \n P{path_number,1} = path; P{path_number,2} = cost; \n current_P = path_number;\n %X is a cell array of a subset of P (used by Yen's algorithm below):\n size_X=1; \n X{size_X} = {path_number; path; cost};\n\n %S path_number x 1\n S(path_number) = path(1); %deviation vertex is the first node initially\n\n %***********************\n % K = 1 is the shortest path returned by dijkstra():\n shortestPaths{k} = path ;\n totalCosts(k) = cost;\n %***********************\n\n %--------------------------------------------------------\n while (k < k_paths && size_X ~= 0 )\n %remove P from X\n for i=1:length(X)\n if X{i}{1} == current_P\n size_X = size_X - 1;\n X(i) = [];%delete cell\n break;\n end\n end\n\n %---------------------------------------\n P_ = P{current_P,1}; %P_ is current P, just to make is easier for the notations\n\n %Find w in (P_,w) in set S, w was the dev vertex used to found P_\n w = S(current_P);\n for i = 1: length(P_)\n if w == P_(i)\n w_index_in_path = i;\n end\n end\n\n\n for index_dev_vertex= w_index_in_path: length(P_) - 1 %index_dev_vertex is index in P_ of deviation vertex\n temp_netCostMatrix = netCostMatrix;\n %------\n %Remove vertices in P before index_dev_vertex and there incident edges\n for i = 1: index_dev_vertex-1\n v = P_(i);\n temp_netCostMatrix(v,:)=inf;\n temp_netCostMatrix(:,v)=inf;\n end\n %------\n %remove incident edge of v if v is in shortestPaths (K) U P_ with similar sub_path to P_....\n SP_sameSubPath=[];\n index =1;\n SP_sameSubPath{index}=P_;\n for i = 1: length(shortestPaths)\n if length(shortestPaths{i}) >= index_dev_vertex\n if P_(1:index_dev_vertex) == shortestPaths{i}(1:index_dev_vertex)\n index = index+1;\n SP_sameSubPath{index}=shortestPaths{i};\n end\n end \n end \n v_ = P_(index_dev_vertex);\n for j = 1: length(SP_sameSubPath)\n next = SP_sameSubPath{j}(index_dev_vertex+1);\n temp_netCostMatrix(v_,next)=inf; \n end\n %------\n\n %get the cost of the sub path before deviation vertex v\n sub_P = P_(1:index_dev_vertex);\n cost_sub_P=0;\n for i = 1: length(sub_P)-1\n cost_sub_P = cost_sub_P + netCostMatrix(sub_P(i),sub_P(i+1));\n end\n\n %call dijkstra between deviation vertex to destination node \n [dev_p c] = dijkstra(temp_netCostMatrix, P_(index_dev_vertex), destination);\n if ~isempty(dev_p)\n path_number = path_number + 1;\n P{path_number,1} = [sub_P(1:end-1) dev_p] ; %concatenate sub path- to -vertex -to- destination\n P{path_number,2} = cost_sub_P + c ;\n\n S(path_number) = P_(index_dev_vertex);\n\n size_X = size_X + 1; \n X{size_X} = {path_number; P{path_number,1} ;P{path_number,2} };\n else\n %warning('k=%d, isempty(p)==true!\\n',k);\n end \n end\n %---------------------------------------\n %Step necessary otherwise if k is bigger than number of possible paths\n %the last results will get repeated !\n if size_X > 0\n shortestXCost= X{1}{3}; %cost of path\n shortestX= X{1}{1}; %ref number of path\n for i = 2 : size_X\n if X{i}{3} < shortestXCost\n shortestX= X{i}{1};\n shortestXCost= X{i}{3};\n end\n end\n current_P = shortestX;\n %******\n k = k+1;\n shortestPaths{k} = P{current_P,1};\n totalCosts(k) = P{current_P,2};\n %******\n else\n %k = k+1;\n end\n end\n end\nend\n%--------------------------------------------------------\n\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/32513-k-shortest-path-yens-algorithm/MATLAB_kShortestPath_Yen's algorithm/kShortestPath.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8840392878563336, "lm_q2_score": 0.8376199653600372, "lm_q1q2_score": 0.7404889576711341}} {"text": "function cc_grids_animate ( )\n\n%*****************************************************************************80\n%\n%% CC_GRIDS_ANIMATE displays a sequence of merged 2D Clenshaw-Curtis grids.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 15 November 2006\n%\n% Author:\n%\n% John Burkardt\n%\n fprintf ( 1, '\\n' );\n timestamp ( );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'CC_GRIDS_ANIMATE:\\n' );\n fprintf ( 1, ' MATLAB version\\n' );\n fprintf ( 1, ' Display a sequence of merged 2D Clenshaw-Curtis grids.\\n' );\n\n dim_num = 2;\n \n while ( 1 )\n \n fprintf ( 1, '\\n' );\n order_max_1d = input ( 'Enter the maximum orders [A,B] or RETURN to exit;' );\n \n if ( isempty ( order_max_1d ) )\n break\n end\n\n points_old = [];\n points_old_num = 0;\n\n points = [];\n order_nd = 0;\n \n for order = 1 : max ( order_max_1d(1:2) )\n\n if ( 0 < order_nd )\n points_old(1:2,points_old_num+1:points_old_num+order_nd) = points(1:2,1:order_nd);\n points_old_num = points_old_num + order_nd;\n end\n\n clf\n%\n% We have to name the axes in order to control the grid.\n%\n axes_handle = axes;\n%\n% Compute the new points and plot them in red.\n%\n order_1d(1:2) = min ( order, order_max_1d(1:2) );\n order_nd = prod ( order_1d(1:2) );\n \n points = cc_grid ( dim_num, order_1d, order_nd );\n\n handle_new = scatter ( points(1,:), points(2,:), 'r', 'filled' );\n%\n% Plot the old points in blue.\n%\n hold on\n\n if ( 0 < points_old_num )\n handle_old = scatter ( points_old(1,:), points_old(2,:), 'b', 'filled' );\n end\n%\n% Force the plotting region to be square, not rectangular.\n%\n axis square\n%\n% Request grid lines.\n%\n grid on\n%\n% Specify the location of the grid lines, and suppress labeling.\n%\n set ( axes_handle, 'xtick', [ -1, -.75, -.5, -.25, 0, .25, .50, .75, 1] );\n set ( axes_handle, 'xticklabel', [] );\n set ( axes_handle, 'ytick', [ -1, -.75, -.5, -.25, 0, .25, .50, .75, 1] );\n set ( axes_handle, 'yticklabel', [] );\n%\n% Make the plotting region slightly bigger than the data.\n%\n axis ( [ -1.1, 1.1, -1.1, 1.1 ] )\n%\n% Title\n%\n s = sprintf ( '%dx%d Clenshaw-Curtis Grid', order_1d(1), order_1d(2) );\n title ( s );\n\n fprintf ( 1, '+%dx%d Clenshaw-Curtis Grid, Press return\\n', ...\n order_1d(1), order_1d(2) );\n\n pause\n\n hold off\n \n end\n\n fprintf ( 1, 'Press return to CLEAR the grid!\\n' );\n pause\n clf\n\n end\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'CC_GRIDS_ANIMATE:\\n' );\n fprintf ( 1, ' Normal end of execution.\\n' );\n\n fprintf ( 1, '\\n' );\n timestamp ( );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/cc_display/cc_grids_animate.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392756357327, "lm_q2_score": 0.8376199653600371, "lm_q1q2_score": 0.7404889474349148}} {"text": "function [X, y] = face_gen(num, noise)\n\nn1=floor(0.05*num);\nn3=floor(0.15*num);\nn4=floor(0.75*num);\n\ninterval1=1.25; interval2=1.25;\n% left eye\nm = [-interval1,interval2];\nC = 0.5*noise*eye(2);\nx1 = mvnrnd(m,C,n1);\ny1 = 1+zeros(n1,1);\n% right eye\nm = [interval1,interval2];\nx2 = mvnrnd(m,C,n1);\ny2 = 2+zeros(n1,1);\n\n% nose \nx3=zeros(n3,2);\nr=1.5;\nt=(5/4*pi):pi/(2*n3-1):(7/4*pi); % \u00cf\u00c2\u00b0\u00eb\u00d4\u00b2\nx3(:, 1) = r.*cos(t)'+randn(n3,1)*noise;\nx3(:, 2) = r.*sin(t)'+randn(n3,1)*noise;\ny3 = 3+zeros(n3,1);\n\n% face\nupright = 0.5;\nx4=zeros(n4,2);\nr = 3;\ncurve = 2.5;\nt = unifrnd(0,0.8,[1,n4]);\nx4(:, 1) = r.*sin(curve*pi*t) + noise*randn(1,n4);\nx4(:, 2) = r.*cos(curve*pi*t) + noise*randn(1,n4)+upright;;\ny4 = 4+zeros(n4,1);\n\nX = [x1;x2;x3;x4];\ny = [y1;y2;y3;y4];\n", "meta": {"author": "CHLWR", "repo": "KDD2019_K-Multiple-Means", "sha": "3b015fe1f6206ed204f90253d859dd9d9e6e3163", "save_path": "github-repos/MATLAB/CHLWR-KDD2019_K-Multiple-Means", "path": "github-repos/MATLAB/CHLWR-KDD2019_K-Multiple-Means/KDD2019_K-Multiple-Means-3b015fe1f6206ed204f90253d859dd9d9e6e3163/funs/face_gen.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9559813451206063, "lm_q2_score": 0.7745833737577158, "lm_q1q2_score": 0.7404872555529585}} {"text": "function [x, y, z] = pol2cart(th, r, z)\n%POL2CART Transform polar to Cartesian coordinates for CHEBFUN2 objects.\n%\n% [X,Y] = POL2CART(TH,R) transforms corresponding elements of data stored in\n% polar coordinates (angle TH, radius R) to Cartesian coordinates X,Y. The\n% arrays TH and R must the same size (or either can be scalar). TH must be in\n% radians.\n% \n% [X,Y,Z] = POL2CART(TH,R,Z) transforms corresponding elements of data stored\n% in cylindrical coordinates (angle TH, radius R, height Z) to Cartesian\n% coordinates X,Y,Z. The arrays TH, R, and Z must be the same size (or any of\n% them can be scalar). TH must be in radians.\n% \n% See also SPH2CART.\n\n% Copyright 2017 by The University of Oxford and The Chebfun Developers. \n% See http://www.chebfun.org/ for Chebfun information.\n\n% Polar coordinates:\nx = r .* cos( th );\ny = r .* sin( th );\n\nend\n", "meta": {"author": "chebfun", "repo": "chebfun", "sha": "8c49396a55e46ddd57a1d108c6a8f32e37536d54", "save_path": "github-repos/MATLAB/chebfun-chebfun", "path": "github-repos/MATLAB/chebfun-chebfun/chebfun-8c49396a55e46ddd57a1d108c6a8f32e37536d54/@chebfun2/pol2cart.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9219218305645895, "lm_q2_score": 0.8031738034238807, "lm_q1q2_score": 0.7404634631140679}} {"text": "function result = mp(Dict, x, options)\n% Matching Pursuit\n if nargin < 3\n options = struct;\n end\n if isa(Dict, 'spx.dict.Operator')\n dict = Dict;\n elseif ismatrix(Dict)\n dict = spx.dict.MatrixOperator(Dict); \n else\n error('Unsupported operator.');\n end\n [m, n] = size(dict);\n\n % halting criteria\n stop_on_r_norm = false;\n stop_on_iterations = false;\n max_iterations = n;\n max_residual_norm = 0;\n if isfield(options, 'max_iterations')\n stop_on_iterations = true;\n max_iterations = options.max_iterations;\n end\n if isfield(options, 'max_residual_norm')\n stop_on_r_norm = true;\n max_residual_norm = options.max_residual_norm;\n end\n\n Gamma = [];\n r = x;\n z = zeros(n, 1);\n iter = 0;\n % norm of signal being reconstructed\n x_norm = norm(x);\n while true \n h = dict.apply_ctranspose(r);\n [~, index] = max(abs(h));\n coeff = h(index);\n z(index) = z(index) + coeff;\n r = r - coeff*dict.column(index);\n r_norm = norm(r);\n iter = iter + 1;\n if stop_on_iterations\n if iter >= max_iterations\n break;\n end\n end\n if stop_on_r_norm\n if r_norm < max_residual_norm\n break;\n end\n end\n if r_norm / x_norm < 1e-6\n % we have reached exact exact recovery\n break;\n end\n if iter > 4*n\n % we have reached highest number of iterations.\n break;\n end\n end\n result.z = z;\n result.r = r;\n result.iterations = iter;\n result.support = find(z);\nend\n", "meta": {"author": "indigits", "repo": "sparse-plex", "sha": "43cae2978f62938d001baaa03308a2a717ee6c9b", "save_path": "github-repos/MATLAB/indigits-sparse-plex", "path": "github-repos/MATLAB/indigits-sparse-plex/sparse-plex-43cae2978f62938d001baaa03308a2a717ee6c9b/library/+spx/+pursuit/+single/mp.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297807787537, "lm_q2_score": 0.8221891392358015, "lm_q1q2_score": 0.7404058053146885}} {"text": "function [ ptab, b, c, d, eps, ierror ] = least_set_old ( ...\n ntab, xtab, ytab, ndeg )\n\n%*****************************************************************************80\n%\n%% LEAST_SET_OLD constructs the least squares polynomial approximation to data.\n%\n% Discussion:\n%\n% The least squares polynomial is not returned directly as a simple\n% polynomial. Instead, it is represented in terms of a set of\n% orthogonal polynomials appopriate for the given data. This makes\n% the computation more accurate, but means that the user can not\n% easily evaluate the computed polynomial. Instead, the routine \n% LEAST_EVAL should be used to evaluate the least squares polynomial\n% at any point. (However, the value of the least squares polynomial\n% at each of the data points is returned as part of this computation.)\n%\n%\n% A discrete unweighted inner product is used, so that\n%\n% ( F(X), G(X) ) = sum ( 1 <= I <= NTAB ) F(XTAB(I)) * G(XTAB(I)).\n%\n% The least squares polynomial is determined using a set of\n% orthogonal polynomials PHI. These polynomials can be defined\n% recursively by:\n%\n% PHI(0)(X) = 1\n% PHI(1)(X) = X - B(1)\n% PHI(I)(X) = ( X - B(I) ) * PHI(I-1)(X) - D(I) * PHI(I-2)(X)\n%\n% The array B(1:NDEG) contains the values\n%\n% B(I) = ( X*PHI(I-1), PHI(I-1) ) / ( PHI(I-1), PHI(I-1) )\n%\n% The array D(2:NDEG) contains the values\n%\n% D(I) = ( PHI(I-1), PHI(I-1) ) / ( PHI(I-2), PHI(I-2) )\n%\n% Using this basis, the least squares polynomial can be represented as\n%\n% P(X)(I) = sum ( 0 <= I <= NDEG ) C(I) * PHI(I)(X)\n%\n% The array C(0:NDEG) contains the values\n%\n% C(I) = ( YTAB(I), PHI(I) ) / ( PHI(I), PHI(I) )\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 16 May 2004\n%\n% Author:\n%\n% MATLAB version by John Burkardt.\n%\n% Reference:\n%\n% Gisela Engeln-Muellges and Frank Uhlig,\n% Numerical Algorithms with C, pages 191-193.\n% Springer, 1996.\n%\n% Parameters:\n%\n% Input, integer NTAB, the number of data points.\n%\n% Input, real XTAB(NTAB), the X data. The values in XTAB\n% should be distinct, and in increasing order.\n%\n% Input, real YTAB(NTAB), the Y data values corresponding\n% to the X data in XTAB.\n%\n% Input, integer NDEG, the degree of the polynomial which the\n% program is to use. NDEG must be at least 1, and less than or \n% equal to NTAB-1.\n%\n% Output, real PTAB(NTAB), the value of the least squares polynomial \n% at the points XTAB(1:NTAB).\n%\n% Output, real B(1:NDEG), C(1:NDEG+1), D(1:NDEG-1), arrays containing \n% data about the polynomial.\n%\n% Output, real EPS, the root-mean-square discrepancy of the\n% polynomial fit.\n%\n% Output, integer IERROR, error flag.\n% zero, no error occurred;\n% nonzero, an error occurred, and the polynomial could not be computed.\n%\n ierror = 0;\n C_OFFSET = 1;\n D_OFFSET = -1;\n%\n% Check NDEG.\n%\n if ( ndeg < 1 )\n ierror = 1;\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'LEAST_SET_OLD - Fatal error!\\n' );\n fprintf ( 1, ' NDEG < 1.\\n' );\n error ( 'LEAST_SET_OLD - Fatal error!' );\n end\n\n if ( ntab <= ndeg )\n ierror = 1;\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'LEAST_SET_OLD - Fatal error!\\n' );\n fprintf ( 1, ' NTAB <= NDEG.\\n' );\n error ( 'LEAST_SET_OLD - Fatal error!' );\n end\n%\n% Check that the abscissas are strictly increasing.\n%\n for i = 1 : ntab-1\n if ( xtab(i+1) <= xtab(i) )\n ierror = 1;\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'LEAST_SET_OLD - Fatal error!\\n' );\n fprintf ( 1, ' XTAB must be strictly increasing, but\\n' );\n fprintf ( 1, ' XTAB(%d) = %f\\n', i, xtab(i) );\n fprintf ( 1, ' XTAB(%d) = %f\\n', i+1, xtab(i+1) );\n error ( 'LEAST_SET_OLD - Fatal error!' );\n end\n end\n\n i0l1 = 0;\n i1l1 = ntab;\n%\n% The polynomial is of degree at least 0.\n%\n y_sum = sum ( ytab(1:ntab) );\n rn0 = ntab;\n c(0+C_OFFSET) = y_sum / ntab;\n\n ptab(1:ntab) = y_sum / ntab;\n\n if ( ndeg == 0 )\n eps = sum ( ( ptab(1:ntab) - ytab(1:ntab) ).^2 );\n eps = sqrt ( eps / ntab );\n b = [];\n d = [];\n return;\n end\n%\n% The polynomial is of degree at least 1.\n%\n b(1) = sum ( xtab(1:ntab) ) / ntab;\n\n s = 0.0E+00;\n sum2 = 0.0E+00;\n for i = 1 : ntab\n ztab(i1l1+i) = xtab(i) - b(1);\n s = s + ztab(i1l1+i)^2;\n sum2 = sum2 + ztab(i1l1+i) * ( ytab(i) - ptab(i) );\n end\n\n rn1 = s;\n c(1+C_OFFSET) = sum2 / s;\n\n for i = 1 : ntab\n ptab(i) = ptab(i) + c(1+C_OFFSET) * ztab(i1l1+i);\n end\n\n if ( ndeg == 1 )\n eps = sum ( ( ptab(1:ntab) - ytab(1:ntab) ).^2 );\n eps = sqrt ( eps / ntab );\n d = [];\n return;\n end\n\n ztable(1:ntab) = 1.0;\n\n mdeg = 2;\n k = 2;\n\n while ( 1 )\n\n d(k+D_OFFSET) = rn1 / rn0;\n\n sum2 = 0.0;\n for i = 1 : ntab\n sum2 = sum2 + xtab(i) * ztab(i1l1+i) * ztab(i1l1+i);\n end\n\n b(k) = sum2 / rn1;\n\n s = 0.0;\n sum2 = 0.0;\n for i = 1 : ntab\n ztab(i0l1+i) = ( xtab(i) - b(k) ) * ztab(i1l1+i) ...\n - d(k+D_OFFSET) * ztab(i0l1+i);\n s = s + ztab(i0l1+i) * ztab(i0l1+i);\n sum2 = sum2 + ztab(i0l1+i) * ( ytab(i) - ptab(i) );\n end\n\n rn0 = rn1;\n rn1 = s;\n \n c(k+C_OFFSET) = sum2 / rn1;\n\n it = i0l1;\n i0l1 = i1l1;\n i1l1 = it;\n\n for i = 1 : ntab\n ptab(i) = ptab(i) + c(k+C_OFFSET) * ztab(i1l1+i);\n end\n \n if ( ndeg <= mdeg )\n break;\n end\n\n mdeg = mdeg + 1;\n k = k + 1;\n\n end\n%\n% Compute the RMS error.\n%\n eps = sum ( ( ptab(1:ntab) - ytab(1:ntab) ).^2 );\n eps = sqrt ( eps / ntab );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/spline/least_set_old.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297834483234, "lm_q2_score": 0.822189134878876, "lm_q1q2_score": 0.7404058035860386}} {"text": "function julian = jed_to_yearcount_julian ( jed )\n\n%*****************************************************************************80\n%\n%% JED_TO_YEARCOUNT_JULIAN converts a JED to a Julian year count.\n%\n% Discussion:\n%\n% An average year in the Julian calendar is exactly 365.25 days long.\n% This calculation counts the number of average Julian years from\n% the beginning of the year 2000.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 25 June 2012\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real JED, the Julian Ephemeris Date.\n%\n% Output, real JULIAN, the Julian year.\n%\n year_length = 365.25;\n\n jed_epoch = epoch_to_jed_y2k ( );\n\n julian = 2000.0 + ( jed - jed_epoch ) / year_length;\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/calpak/jed_to_yearcount_julian.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9005297807787537, "lm_q2_score": 0.8221891327004132, "lm_q1q2_score": 0.7404057994293767}} {"text": "function face_normal = stla_face_normal_compute ( node_num, face_num, ...\n node_xyz, face_node )\n\n%*****************************************************************************80\n%\n%% STLA_FACE_NORMAL_COMPUTE computes normal vectors for an ASCII StereoLithography file.\n%\n% Discussion:\n%\n% This routine computes the normal vector to each triangular face\n% in the STLA solid. If the nodes of each triangular face are\n% listed in counterclockwise order (as seen from outside the solid),\n% then the normal vectors will be properly outward facing.\n%\n% The normal vectors will have unit Euclidean norm.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 24 September 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% 3D Systems, Inc,\n% Stereolithography Interface Specification,\n% October 1989.\n%\n% Parameters:\n%\n% Input, integer NODE_NUM, the number of nodes.\n%\n% Input, integer FACE_NUM, the number of faces.\n%\n% Input, real NODE_XYZ(3,NODE_NUM), the node coordinates.\n%\n% Input, integer FACE_NODE(3,FACE_NUM), the nodes making faces.\n%\n% Input, integer FACE_MAX, the maximum number of faces.\n%\n% Output, real FACE_NORMAL(3,FACE_NUM), the normal vector at each face.\n%\n for face = 1 : face_num\n\n n1 = face_node(1,face);\n n2 = face_node(2,face);\n n3 = face_node(3,face);\n\n v1(1:3) = node_xyz(1:3,n2) - node_xyz(1:3,n1);\n v2(1:3) = node_xyz(1:3,n3) - node_xyz(1:3,n1);\n\n face_normal(1:3,face) = r8vec_cross_3d ( v1, v2 );\n\n norm = sqrt ( sum ( ( face_normal(1:3,face) ).^2 ) );\n\n if ( norm ~= 0.0 )\n face_normal(1:3,face) = face_normal(1:3,face) / norm;\n end\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/stla_io/stla_face_normal_compute.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.900529786117893, "lm_q2_score": 0.8221891261650248, "lm_q1q2_score": 0.7404057979338472}} {"text": "function a_inverse = r8ut_inverse ( n, a )\n\n%*****************************************************************************80\n%\n%% R8UT_INVERSE computes the inverse of a R8UT matrix.\n%\n% Discussion:\n%\n% The R8UT storage format is used for an M by N upper triangular \n% matrix. The format stores all M*N entries, even those which are zero.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 18 March 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% A Nijenhuis and H Wilf,\n% Combinatorial Algorithms,\n% Academic Press, 1978, second edition,\n% ISBN 0-12-519260-6\n%\n% Parameters:\n%\n% Input, integer N, the order of the matrix.\n%\n% Input, real A(N,N), the R8UT matrix to be inverted.\n%\n% Output, real A_INVERSE(N,N), the inverse of the upper triangular matrix.\n%\n\n%\n% Check.\n%\n for i = 1 : n\n if ( a(i,i) == 0.0 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'R8UT_INVERSE - Fatal error!\\n' );\n fprintf ( 1, ' Zero diagonal element.\\n' );\n error ( 'R8UT_INVERSE - Fatal error!' );\n end\n end\n\n a_inverse(1:n,1:n) = a(1:n,1:n);\n\n for j = n : -1 : 1\n\n for i = n : -1 : 1\n\n if ( j < i )\n\n a_inverse(i,j) = 0.0;\n\n elseif ( i == j )\n\n a_inverse(i,j) = 1.0 / a_inverse(i,j);\n\n elseif ( i < j )\n\n a_inverse(i,j) = - ( a_inverse(i,i+1:j) * a_inverse(i+1:j,j) ) ...\n / a_inverse(i,i);\n\n end\n\n end\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/wishart/r8ut_inverse.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297754396141, "lm_q2_score": 0.8221891239865619, "lm_q1q2_score": 0.7404057871925116}} {"text": "function gqn_sparse_test ( )\n\n%*****************************************************************************80\n%\n%% GQN_SPARSE_TEST uses the GQN function to build a sparse grid.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 25 May 2014\n%\n% Author:\n%\n% Original MATLAB version by Florian Heiss, Viktor Winschel.\n% This MATLAB version by John Burkardt.\n%\n% Local parameters:\n%\n% Local, integer D, the spatial dimension.\n%\n d = 5;\n trueval = hermite_integral ( d );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'GQN_SPARSE_TEST:\\n' );\n fprintf ( 1, ' GQN sparse grid:\\n' );\n fprintf ( 1, ' Gauss quadrature, Hermite weight over (-oo,+oo).\\n' );\n fprintf ( 1, ' Exact integral is %g\\n', trueval );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' D Level Nodes SG estimate MC estimate\\n' );\n fprintf ( 1, ' SG error MC error\\n' );\n fprintf ( 1, '\\n' );\n\n for k = 1 : 8\n%\n% Compute sparse grid estimate.\n%\n [ x, w ] = nwspgr ( 'gqn', d, k );\n [ n, ~ ] = size ( x );\n fx = hermite_integrand ( d, n, x );\n sgappr = w' * fx;\n sgerror = sqrt ( ( sgappr - trueval ) .^ 2 ) / trueval;\n%\n% Average 1000 Monte Carlo estimates.\n%\n sim = zeros(1000,1);\n for r = 1 : 1000\n x = randn ( n, d );\n fx = hermite_integrand ( d, n, x );\n sim(r) = mean ( fx );\n end\n simappr = mean ( sim );\n simerror = sqrt ( mean ( ( sim - trueval ) .^ 2 ) ) / trueval;\n\n fprintf ( ' %2d %2d %6d %10.5g %10.5g\\n', ...\n d, k, n, sgappr, simappr );\n fprintf ( ' %10.5g %10.5g\\n', ...\n sgerror, simerror );\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/sparse_grid_hw/gqn_sparse_test.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.867035752930664, "lm_q2_score": 0.8539127566694178, "lm_q1q2_score": 0.7403728899159676}} {"text": "% Elmore delay sizing for a straight wire (GP)\n% Boyd, \"Problems in VLSI design\" (Lecture)\n% Written for CVX by Almir Mutapcic 02/08/06\n%\n% We consider the problem of finding optimal width profile\n% for a straight wire segmented into N parts. We want to\n% minimize the Elmore delay, subject to limits on wire width\n% and the total area. We use a pi-model for each wire segment.\n% Problem can be formulated as GP:\n%\n% minimize D\n% s.t. w_min <= w <= w_max\n% area <= Amax\n%\n% where variables are widths w (and arrival times T that are used\n% to formulate the overall delay D expression).\n%\n% Important: We label root node as 1, and all the other nodes as\n% node_label_in_the_paper + 1 (due to Matlab's convention).\n% Also label nodes with increasing numbers downstream.\n\n%********************************************************************\n% user supplied data (problem constants and tree topology)\n%********************************************************************\nN = 10+1; % number of segments (including the root node which is labeled as 1)\n\n% parent node array for the straight wire\n% specifies which node is a unique parent for node i (always have a tree)\nparent = [0:N-1];\n\n% problem constants\nRsource = 0.1;\nl = 1*ones(N-1,1);\nalpha = 1*ones(N-1,1);\nbeta = 1*ones(N-1,1);\ngamma = 1*ones(N-1,1);\n\n% load capacitance at each node\nCload = [0; ones(N-1,1)];\n\n% minimum and maximum width and area specification\nWmin = 1;\nWmax = 10;\nAmax = 50;\n\n%********************************************************************\n% derived data (computed from user's data)\n%********************************************************************\n% compute children cell array (evaluate who are children for each node)\nchildren = cell(N,1);\nleafs = [];\nfor node = [1:N]\n children{node} = find(parent == node);\n if isempty(children{node})\n leafs(end+1) = node; % leafs have no children\n end\nend\n\n%********************************************************************\n% optimization\n%********************************************************************\n\ndisp('Generating the tradeoff curve...')\nDarray = []; widths = [];\nfor Amax = [10.05 10.5 11 12:2:20 22.5 25:5:60]\n fprintf( 'Amax = %5.2f: ', Amax );\n cvx_begin gp quiet\n % optimization variables\n variable w(N-1) % wire width\n variable T(N) % arrival time (Elmore delay to node i)\n\n % objective is the critical Elmore delay\n minimize( max( T(leafs) ) )\n subject to\n\n % wire segment resistance is inversely proportional to widths\n R = alpha.*l./w;\n R = [Rsource; R];\n\n % wire segment capacitance is an affine function of widths\n C_bar = beta.*l.*w + gamma.*l;\n C_bar = [0; C_bar];\n\n % compute common capacitances for each node (C_tilde in GP tutorial)\n C_tilde = cvx( zeros(N,1) );\n for node = [1:N]\n C_tilde(node,1) = Cload(node);\n for k = parent(node)\n if k > 0; C_tilde(node,1) = C_tilde(node,1) + C_bar(k); end;\n end\n for k = children{node}\n C_tilde(node,1) = C_tilde(node,1) + C_bar(k);\n end\n end\n\n % now compute total downstream capacitances\n C_total = C_tilde;\n for node = N:-1:1\n for k = children{node}\n C_total(node,1) = C_total(node,1) + C_total(k,1);\n end\n end\n\n % generate Elmore delay constraints\n R(1)*C_total(1) <= T(1,1);\n for node = 2:N\n R(node)*C_total(node) + T(parent(node),1) <= T(node,1);\n end\n\n % collect all the constraints\n sum(w.*l) <= Amax;\n Wmin <= w <= Wmax;\n cvx_end\n % display and store computed values\n fprintf('delay = %3.2f\\n',cvx_optval);\n Darray = [Darray cvx_optval];\n widths = [widths w];\nend\n\n% indices of four taper designs on the tradeoff curve\nAmax = [10.05 10.5 11 12:2:20 22.5 25:5:60];\nA11ind = find(Amax == 11);\nA20ind = find(Amax == 20);\nA35ind = find(Amax == 35);\nA50ind = find(Amax == 50);\n\n% plot the tradeoff curve\nfigure, clf\nplot(Darray,Amax, ...\n Darray(A11ind),Amax(A11ind),'ro',...\n Darray(A20ind),Amax(A20ind),'ro',...\n Darray(A35ind),Amax(A35ind),'ro',...\n Darray(A50ind),Amax(A50ind),'ro');\nxlabel('Elmore delay D'); ylabel('Amax');\ndisp('Optimal tradeoff curve plotted.')\n\n% plot four taper designs\nfigure, clf\nw1 = widths(:,A50ind);\nw2 = widths(:,A35ind);\nw3 = widths(:,A20ind);\nw4 = widths(:,A11ind);\nplot_four_tapers(w1,w2,w3,w4);\n", "meta": {"author": "cvxr", "repo": "CVX", "sha": "a7b46e7840c3ccf3f35df374d2ff3da4eaafc3cd", "save_path": "github-repos/MATLAB/cvxr-CVX", "path": "github-repos/MATLAB/cvxr-CVX/CVX-a7b46e7840c3ccf3f35df374d2ff3da4eaafc3cd/examples/circuit_design/elmore_straight_wire.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582632076909, "lm_q2_score": 0.795658104908603, "lm_q1q2_score": 0.7403266584003815}} {"text": "function [lImFea] = extr_lIm_fea( lIm )\n\n[nrow, ncol] = size(lIm);\n\nlImFea = zeros([nrow, ncol, 4]);\n\n% first order gradient filters\nhf1 = [-1,0,1];\nvf1 = [-1,0,1]';\n \nlImFea(:, :, 1) = conv2(lIm, hf1, 'same');\nlImFea(:, :, 2) = conv2(lIm, vf1, 'same');\n\n% second order gradient filters\nhf2 = [1,0,-2,0,1];\nvf2 = [1,0,-2,0,1]';\n \nlImFea(:, :, 3) = conv2(lIm,hf2,'same');\nlImFea(:, :, 4) = conv2(lIm,vf2,'same');\n\n", "meta": {"author": "thomas-koehler", "repo": "SupER", "sha": "d8c6f2e4b26db002ff55bc2beba18639f1d0bb49", "save_path": "github-repos/MATLAB/thomas-koehler-SupER", "path": "github-repos/MATLAB/thomas-koehler-SupER/SupER-d8c6f2e4b26db002ff55bc2beba18639f1d0bb49/matlab/algorithms/SRAlgorithms/ScSR/extr_lIm_fea.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.930458253565792, "lm_q2_score": 0.7956581024858785, "lm_q1q2_score": 0.7403266484744825}} {"text": "function Lms = gallager_ach(Ns, delta, epsil)\n% computes gallager's achievability bound for BSC \n%\n% We use it in the form \n%\n% P_e \\le M^s ( Sum_y [ Sum_x Q(x) W(y|x)^{1/1+s} ]^(1+s) )^n\n%\n% Note: we then conclude that from (M, P_e) code with AVG P_e \n% we can get (M/2, 2 P_e) code with MAXIMAL. Thus we must take P_e = epsil/2 and then \n% subtract 1 bit from gallager's result\n% \n\nLms = [];\n\nfor n = Ns;\n\n\tf = @(x) -( log2(epsil/2) ./ x + n - n .* (1+x) ./ x .* log2( delta.^(1./(1+x)) + (1-delta).^(1./(1+x))));\n\n\t[lambda f] = fminbnd(f, 0, 1);\n\n\t% Cut half of the codewords\n\n\tlogm = -f-1;\n\n\tdisp(sprintf('--- Gallager: n=%d, best_lambda = %g, log M >= %g', n, lambda, logm));\n\n\tif ( lambda <= 0 ) || (lambda >= 1)\n\t\tdisp(sprintf('------- WARNING: lambda on the boundary! params: n=%d, delta=%g, epsil=%g', n, delta, epsil));\n\tend\n\tLms = [Lms logm];\nend\n", "meta": {"author": "yp-mit", "repo": "spectre", "sha": "57af76799e4eb43aa707cc13c4c5220d281e0b78", "save_path": "github-repos/MATLAB/yp-mit-spectre", "path": "github-repos/MATLAB/yp-mit-spectre/spectre-57af76799e4eb43aa707cc13c4c5220d281e0b78/bsc/gallager_ach.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.933430812881347, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.7403095395618569}} {"text": "function [ x, obj_val ] = QCQP_UB( H_wave,y_wave,N,l,u,x1)\n%UNTITLED9 Summary of this function goes here\n% Detailed explanation goes here\nQ = 2*H_wave*H_wave.';\nf = -2*H_wave*y_wave;\nc = y_wave.'*y_wave;\nA = zeros(N,2*N);\nfor ii = 1:N\n A(ii,ii) = cos((l(ii)+u(ii))/2);\n A(ii,ii+N) = sin((l(ii)+u(ii))/2); %Linear Constraint\nend\n\n\nfunction [y,grady] = quadobj(x,Q,f,c) %Objective Function\n y = 1/2*x.'*Q*x+f.'*x+c;\n if nargout>1\n grady = Q*x + f;\n end\nend\n\nfunction [y_con,yeq,grady,gradyeq] = quadconstr(x) %Nonlinear Constraint\n for nn = 1:N\n yeq(nn) = x(nn)^2+x(nn+N)^2 - 1;\n end\n y_con = [];\n if nargout>2\n gradyeq = zeros(length(x),N);\n for nn = 1:N\n gradyeq(nn,nn) = 2*x(nn);\n gradyeq(nn+N,nn) = 2*x(nn+N);\n end\n end\n grady = [];\nend\n\nAcon = -A;\n\nfor ii = 1:N\n b(ii) = -cos((u(ii)-l(ii))/2);\nend\n\n\n\n% options = optimoptions(@fmincon,'Algorithm','sqp',...\n% 'SpecifyObjectiveGradient',true,'SpecifyConstraintGradient',true,...\n% 'Display','off','OptimalityTolerance',1e-6,'MaxIterations',400);\n\noptions = optimoptions('fmincon','Algorithm','sqp', 'GradObj','on');\n\n\nfun = @(x)quadobj(x,Q,f,c);\nnonlconstr = @(x)quadconstr(x);\n% x1 = ones(2*N,1);\nx = fmincon(fun,x1,Acon,b,[],[],[],[],nonlconstr,options);\nobj_val = objval_func(x,H_wave,y_wave);\nend\n\n", "meta": {"author": "yuanhao-cui", "repo": "Must-Reading-on-ISAC", "sha": "34cd6615c52ebca121428a979e756c608b195040", "save_path": "github-repos/MATLAB/yuanhao-cui-Must-Reading-on-ISAC", "path": "github-repos/MATLAB/yuanhao-cui-Must-Reading-on-ISAC/Must-Reading-on-ISAC-34cd6615c52ebca121428a979e756c608b195040/Codes/Fan2018TSP/Codes for DFRC Waveform Design/Constant Modulus/QCQP_UB.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308091776496, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.7403095252127034}} {"text": "% GET ROTATION MATRIX FROM QUATERNION\nfunction [R] = R_q(q)\n% This function defines the equivalent rotation matrix from the\n% provided quaternion. (Associated block \"Quaternion to DCM\")\n% INPUT:\n% q - The quaternion rotation\n% OUTPUT:\n% R_AB - The rotation matrix through A to B\n% R_BA - The reverse rotation matrix from B to A\n\nassert(numel(q) == 4,'Input quaternion has wrong dimensions');\n\nR = zeros(3,3);\n% Normalise the quaternion\nq = unit(q); \n\n% SAME AS THE ROBOTICS TOOL BOX....\nR(1,1) = q(1)^2 + q(2)^2 - q(3)^2 - q(4)^2; \nR(1,2) = 2*(q(2)*q(3) - q(1)*q(4));\nR(1,3) = 2*(q(1)*q(3) + q(2)*q(4));\nR(2,1) = 2*(q(2)*q(3) + q(1)*q(4));\nR(2,2) = q(1)^2 - q(2)^2 + q(3)^2 - q(4)^2;\nR(2,3) = 2*(q(3)*q(4) - q(1)*q(2));\nR(3,1) = 2*(q(2)*q(4) - q(1)*q(3));\nR(3,2) = 2*(q(1)*q(2) + q(3)*q(4));\nR(3,3) = q(1)^2 - q(2)^2 - q(3)^2 + q(4)^2;\nend", "meta": {"author": "douthwja01", "repo": "OpenMAS", "sha": "962f321f82167db78066b2c88c783423ecc3b73a", "save_path": "github-repos/MATLAB/douthwja01-OpenMAS", "path": "github-repos/MATLAB/douthwja01-OpenMAS/OpenMAS-962f321f82167db78066b2c88c783423ecc3b73a/environment/common/R_q.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308036221032, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.7403095185242206}} {"text": "%\n% This code calculates the interevent distances and the correlation integral\n% of a subset selected with the sampling sphere. The code is called from circlefd.m.\n% Francesco Pacchiani 1/2000\n%\n% Calculation of the 3D distances between all possible pairs\n% (combination of n epicenters taken 2 at a time) of earthquakes of\n% the given dataset.\n%\n%\n% Variables\n%\nN = size(E,1);\t\t\t\t% N= # of events in the catalogue; E= Earthquake catalogue\npairdist = []; \t\t\t% pairdist= Vector of interevent distances\nj = nchoosek(N,2);\t\t\t% j= # of interevent distances calculated\npairdist = zeros(j,1);\nk = 0;\n%E.Latitude= (max(Da(:,2))+min(Da(:,2)))/2;\n\n\nHo_Wb = waitbar(0,'Calculating the fractal dimension D');\nHf_Cfig = gcf;\nHf_child = get(groot,'children');\nset(Hf_child,'pointer','watch','papertype','A4');\n%\n%\n% Calculation of the interevent distances in 2D plus the depths differences.\n%\n%\nfor i = 1:(N-1)\n\n lon1 = repmat(E(i,1), [(N-i),1]);\n lat1 = repmat(E(i,2), [(N-i),1]);\n\n lon2 = E((i+1):end, 1);\n lat2 = E((i+1):end, 2);\n\n pairdist(k+1:k + size(lon1, 1)) = distance(lat1,lon1,lat2,lon2);\n\n k = k + size(lon1,1);\n\n waitbar((0.75/(N-1))*i, Ho_Wb);\n\nend\n\nclear i j k;\n%\n%\n% Conversion of the interevent distances from degrees to kilometers and calculates\n% the interevent distances in three dimensions.\n%\n%\nif dtokm == 1\n pairdist = pairdist.*111;\nend\n%\n%\n% Calculation of the correlation integral using as input the\n% pair distances computed above.\n%\n%\n% Variables\n%\nd = 2;\t\t\t\t\t\t%d = the dimension of the embedding volume.\nrmax = max(pairdist);\nrmin = min(pairdist);\n\nif rmin == 0\n rmin = 0.01;\nend\n\nlrmin = log10(rmin);\nlrmax = log10(max(pairdist));\n\n%u = (log10(rmin):0.15:log10(rmax))';\n%\n% Defining the distance vector r in order that on the\n% log-log graph all the points plot at equal distances from one another.\n%\nr = (logspace(lrmin, lrmax, 50))';\n%r = zeros(size(u,1),1);\n%r = 10.^u;\n%\n%\ncorint = [];\t\t\t\t\t\t% corint= Vector of ?cumulative? correlation integral values for increasing interevent radius\ncorint = zeros(size(r,1),1);\nk = 1;\n\nfor i = 1:size(r,1)\n\n j = [];\n j = pairdist < r(i);\n corint (k,1) = (2/(N*(N-1)))*sum(j);\n k = k + 1;\n waitbar(0.75 + (0.25/size(r,1))*i,Ho_Wb);\n\nend\n\nclear i j k;\nclose(Ho_Wb);\nHf_child = get(groot,'children');\nset(Hf_child,'pointer','arrow');\n%\n%\ndofd = 'fd';\n", "meta": {"author": "CelsoReyes", "repo": "zmap7", "sha": "3895fcb3ca3073608abe22ca71960eb082fd0d9a", "save_path": "github-repos/MATLAB/CelsoReyes-zmap7", "path": "github-repos/MATLAB/CelsoReyes-zmap7/zmap7-3895fcb3ca3073608abe22ca71960eb082fd0d9a/zmap_deprecated/orphaned/src/fractal/pdc2circle.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273633016692236, "lm_q2_score": 0.7981867849406659, "lm_q1q2_score": 0.7402091322313185}} {"text": "function [x, c, funVal, ValueL]=sgLogisticR(A, y, z, opts)\n%\n%%\n% Function sgLogisticR\n% Logistic Loss with the \n% sparse group Lasso Regularization\n%\n%% Problem\n%\n% min f(x,c) = - sum_i weight_i * log (p_i) \n% + z_1 \\|x\\|_1 + z_2 * sum_j w_j ||x_{G_j}||\n%\n% a_i denotes a training sample,\n% and a_i' corresponds to the i-th row of the data matrix A\n%\n% y_i (either 1 or -1) is the response\n% \n% p_i= 1/ (1+ exp(-y_i (x' * a_i + c) ) ) denotes the probability\n%\n% G_j's are nodes with tree structure\n%\n% For this special case, \n% we have L1 for each element\n% and the L2 for the non-overlapping group \n%\n% The tree overlapping group information is contained in\n% opts.ind, which is a 3 x nodes matrix, where nodes denotes the number of\n% nodes of the tree.\n% opts.ind(1,:) contains the starting index\n% opts.ind(2,:) contains the ending index\n% opts.ind(3,:) contains the corresponding weight (w_j)\n%\n%% Input parameters:\n%\n% A- Matrix of size m x n\n% A can be a dense matrix\n% a sparse matrix\n% or a DCT matrix\n% y - Response vector (of size mx1)\n% z - Regularization parameter (z >=0)\n% opts- Optional inputs (default value: opts=[])\n% !!We require that opts.ind is specified.!!\n%\n%% Output parameters:\n% x- The obtained weight of size n x 1\n% c- The obtained intercept (scalar)\n% funVal- Function value during iterations\n%\n%% Copyright (C) 2009-2010 Jun Liu, and Jieping Ye\n%\n% You are suggested to first read the Manual.\n%\n% For any problem, please contact with Jun Liu via j.liu@asu.edu\n%\n% Last modified on February 19, 2010.\n%\n%% Related papers\n%\n% [1] Jun Liu and Jieping Ye, Moreau-Yosida Regularization for \n% Grouped Tree Structure Learning, NIPS 2010\n%\n%% Related functions:\n%\n% sll_opts\n%\n%%\n\n%% Verify and initialize the parameters\n%%\nif (nargin <4)\n error('\\n Inputs: A, y, z, and opts (.ind) should be specified!\\n');\nend\n\n[m,n]=size(A);\n\nif (length(y) ~=m)\n error('\\n Check the length of y!\\n');\nend\n\nif (z(1)<0 || z(2)<0)\n error('\\n z should be nonnegative!\\n');\nend\n\nlambda1=z(1);\nlambda2=z(2);\n\nopts=sll_opts(opts); % run sll_opts to set default values (flags)\n\n% restart the program for better efficiency\n% this is a newly added function\nif (~isfield(opts,'rStartNum'))\n opts.rStartNum=opts.maxIter;\nelse\n if (opts.rStartNum<=0)\n opts.rStartNum=opts.maxIter;\n end\nend\n\n%% Detailed initialization\n%% Normalization\n\n% Please refer to the function 'sll_opts'\n% for the definitions of mu, nu and nFlag\n%\n% If .nFlag =1, the input matrix A is normalized to\n% A= ( A- repmat(mu, m,1) ) * diag(nu)^{-1}\n%\n% If .nFlag =2, the input matrix A is normalized to\n% A= diag(nu)^{-1} * ( A- repmat(mu, m,1) )\n%\n% Such normalization is done implicitly.\n% This implicit normalization is suggested for the sparse matrix,\n% but not for the dense matrix.\n%\n\nif (opts.nFlag~=0)\n if (isfield(opts,'mu'))\n mu=opts.mu;\n if(size(mu,2)~=n)\n error('\\n Check the input .mu');\n end\n else\n mu=mean(A,1);\n end\n \n if (opts.nFlag==1)\n if (isfield(opts,'nu'))\n nu=opts.nu;\n if(size(nu,1)~=n)\n error('\\n Check the input .nu!');\n end\n else\n nu=(sum(A.^2,1)/m).^(0.5); nu=nu';\n end\n else % .nFlag=2\n if (isfield(opts,'nu'))\n nu=opts.nu;\n if(size(nu,1)~=m)\n error('\\n Check the input .nu!');\n end\n else\n nu=(sum(A.^2,2)/n).^(0.5);\n end\n end\n \n ind_zero=find(abs(nu)<= 1e-10); nu(ind_zero)=1;\n % If some values in nu is typically small, it might be that,\n % the entries in a given row or column in A are all close to zero.\n % For numerical stability, we set the corresponding value to 1.\nend\n\nif (~issparse(A)) && (opts.nFlag~=0)\n fprintf('\\n -----------------------------------------------------');\n fprintf('\\n The data is not sparse or not stored in sparse format');\n fprintf('\\n The code still works.');\n fprintf('\\n But we suggest you to normalize the data directly,');\n fprintf('\\n for achieving better efficiency.');\n fprintf('\\n -----------------------------------------------------');\nend\n\n%% Group & Others \n\n% Initialize ind \nif (~isfield(opts,'ind'))\n error('\\n In sgLogisticR, the field .ind should be specified');\nelse\n ind=opts.ind;\n \n if (size(ind,1)~=3)\n error('\\n Check opts.ind');\n end\nend\n\n% The parameter 'weight' contains the weight for each training sample.\n% See the definition of the problem above.\n% The summation of the weights for all the samples equals to 1.\nif (isfield(opts,'sWeight'))\n sWeight=opts.sWeight;\n \n if ( length(sWeight)~=2 || sWeight(1) <=0 || sWeight(2) <= 0)\n error('\\n Check opts.sWeight, which contains two positive values');\n end\n \n % we process the weight, so that the summation of the weights for all\n % the samples is 1.\n \n p_flag=(y==1); % the indices of the postive samples\n m1=sum(p_flag) * sWeight(1); % the total weight for the positive samples\n m2=sum(~p_flag) * sWeight(2); % the total weight for the positive samples\n \n weight(p_flag,1)=sWeight(1)/(m1+m2);\n weight(~p_flag,1)=sWeight(2)/(m1+m2);\nelse\n weight=ones(m,1)/m; % if not specified, we apply equal weight\nend\n\n\n%% Starting point initialization\n\np_flag=(y==1); % the indices of the postive samples\nm1=sum(weight(p_flag)); % the total weight for the positive samples\nm2=1-m1; % the total weight for the positive samples\n\n% process the regularization parameter\nif (opts.rFlag==0)\n lambda=z;\nelse % z here is the scaling factor lying in [0,1]\n if (lambda1<0 || lambda1>1 || lambda2<0 || lambda2>1)\n error('\\n opts.rFlag=1, and z should be in [0,1]');\n end\n \n % we compute ATb for computing lambda_max, when the input z is a ratio\n \n b(p_flag,1)=m2; b(~p_flag,1)=-m1;\n b=b.*weight;\n \n % compute AT b\n if (opts.nFlag==0)\n ATb =A'*b;\n elseif (opts.nFlag==1)\n ATb= A'*b - sum(b) * mu'; ATb=ATb./nu;\n else\n invNu=b./nu; ATb=A'*invNu-sum(invNu)*mu';\n end\n \n % compute lambda1_max\n temp=abs(ATb);\n lambda1_max=max(temp);\n \n lambda1=lambda1*lambda1_max;\n \n % compute lambda2_max(lambda_1)\n temp=max(temp-lambda1,0);\n \n if ( min(ind(3,:))<=0 )\n error('\\n In this case, lambda2_max = inf!');\n end\n lambda2_max=computeLambda2Max(temp,n,ind,size(ind,2));\n \n lambda2=lambda2*lambda2_max; \nend\n\n% initialize a starting point\nif opts.init==2\n x=zeros(n,1); c=log(m1/m2);\nelse\n if isfield(opts,'x0')\n x=opts.x0;\n if (length(x)~=n)\n error('\\n Check the input .x0');\n end\n else\n x=zeros(n,1);\n end\n \n if isfield(opts,'c0')\n c=opts.c0;\n else\n c=log(m1/m2);\n end\nend\n\n% compute A x\nif (opts.nFlag==0)\n Ax=A* x;\nelseif (opts.nFlag==1)\n invNu=x./nu; mu_invNu=mu * invNu;\n Ax=A*invNu -repmat(mu_invNu, m, 1);\nelse\n Ax=A*x-repmat(mu*x, m, 1); Ax=Ax./nu;\nend\n\n%% The main program\n\nif (opts.mFlag==0 && opts.lFlag==0)\n \n bFlag=0; % this flag tests whether the gradient step only changes a little\n \n L=1/m; % the intial guess of the Lipschitz continuous gradient\n \n weighty=weight.*y;\n % the product between weight and y\n \n % assign xp with x, and Axp with Ax\n xp=x; Axp=Ax; xxp=zeros(n,1);\n cp=c; ccp=0; \n \n %% The Armijo Goldstein line search schemes + accelearted gradient descent\n \n alphap=0; alpha=1;\n \n for iterStep=1:opts.maxIter\n % --------------------------- step 1 ---------------------------\n % compute search point s based on xp and x (with beta)\n beta=(alphap-1)/alpha; s=x + beta* xxp; sc=c + beta* ccp;\n \n % --------------------------- step 2 ---------------------------\n % line search for L and compute the new approximate solution x\n \n % compute As=A*s\n As=Ax + beta* (Ax-Axp);\n \n % aa= - diag(y) * (A * s + sc)\n aa=- y.*(As+ sc);\n \n % fun_s is the logistic loss at the search point\n bb=max(aa,0);\n fun_s= weight' * ( log( exp(-bb) + exp(aa-bb) ) + bb );\n \n % compute prob=[p_1;p_2;...;p_m]\n prob=1./( 1+ exp(aa) );\n \n % b= - diag(y.* weight) * (1 - prob)\n b= -weighty.*(1-prob);\n \n gc=sum(b); % the gradient of c\n \n % compute g= AT b, the gradient of x\n if (opts.nFlag==0)\n g=A'*b;\n elseif (opts.nFlag==1)\n g=A'*b - sum(b) * mu'; g=g./nu;\n else\n invNu=b./nu; g=A'*invNu-sum(invNu)*mu';\n end\n \n % copy x and Ax to xp and Axp\n xp=x; Axp=Ax;\n cp=c; \n \n while (1)\n % let s walk in a step in the antigradient of s to get v\n % and then do the L1/Lq-norm regularized projection\n v=s-g/L; c= sc- gc/L;\n \n % tree overlapping group Lasso projection\n ind_work(1:2,:)=[ [-1, -1]', ind(1:2,:) ];\n ind_work(3,:)=[ lambda1/L, ind(3,:) * (lambda2 / L) ];\n \n x=altra(v, n, ind_work, size(ind_work,2));\n \n v=x-s; % the difference between the new approximate solution x\n % and the search point s\n \n % compute A x\n if (opts.nFlag==0)\n Ax=A* x;\n elseif (opts.nFlag==1)\n invNu=x./nu; mu_invNu=mu * invNu;\n Ax=A*invNu -repmat(mu_invNu, m, 1);\n else\n Ax=A*x-repmat(mu*x, m, 1); Ax=Ax./nu;\n end\n \n % aa= - diag(y) * (A * x + c)\n aa=- y.*(Ax+ c);\n \n % fun_x is the logistic loss at the new approximate solution\n bb=max(aa,0);\n fun_x= weight'* ( log( exp(-bb) + exp(aa-bb) ) + bb );\n \n r_sum= (v'*v + (c-sc)^2) / 2;\n l_sum=fun_x - fun_s - v'* g - (c-sc)* gc;\n \n if (r_sum <=1e-20)\n bFlag=1; % this shows that, the gradient step makes little improvement\n break;\n end\n \n % the condition is fun_x <= fun_s + v'* g + c * gc\n % + L/2 * (v'*v + (c-sc)^2 )\n if(l_sum <= r_sum * L)\n break;\n else\n L=max(2*L, l_sum/r_sum);\n %fprintf('\\n L=%e, r_sum=%e',L, r_sum);\n end\n end\n \n % --------------------------- step 3 ---------------------------\n % update alpha and alphap, and check whether converge\n alphap=alpha; alpha= (1+ sqrt(4*alpha*alpha +1))/2;\n \n ValueL(iterStep)=L;\n % store values for L\n \n xxp=x-xp; ccp=c-cp;\n funVal(iterStep)=fun_x;\n \n % compute the regularization part\n ind_work(1:2,:)=[ [-1, -1]', ind(1:2,:) ];\n ind_work(3,:)=[ lambda1, ind(3,:) * lambda2 ];\n tree_norm=treeNorm(x, n, ind_work, size(ind_work,2));\n \n % function value = loss + regularizatioin\n funVal(iterStep)=fun_x + tree_norm; \n \n if (bFlag)\n % fprintf('\\n The program terminates as the gradient step changes the solution very small.');\n break;\n end\n \n switch(opts.tFlag)\n case 0\n if iterStep>=2\n if (abs( funVal(iterStep) - funVal(iterStep-1) ) <= opts.tol)\n break;\n end\n end\n case 1\n if iterStep>=2\n if (abs( funVal(iterStep) - funVal(iterStep-1) ) <=...\n opts.tol* funVal(iterStep-1))\n break;\n end\n end\n case 2\n if ( funVal(iterStep)<= opts.tol)\n break;\n end\n case 3\n norm_xxp=sqrt(xxp'*xxp);\n if ( norm_xxp <=opts.tol)\n break;\n end\n case 4\n norm_xp=sqrt(xp'*xp); norm_xxp=sqrt(xxp'*xxp);\n if ( norm_xxp <=opts.tol * max(norm_xp,1))\n break;\n end\n case 5\n if iterStep>=opts.maxIter\n break;\n end\n end\n \n % restart the program every opts.rStartNum\n if (~mod(iterStep, opts.rStartNum))\n alphap=0; alpha=1;\n xp=x; Axp=Ax; xxp=zeros(n,1); L =L/2;\n end\n end \nelse\n error('\\n The function does not support opts.mFlag neq 0 & opts.lFlag neq 0!');\nend\n", "meta": {"author": "thomaskuestner", "repo": "CS_MoCo_LAB", "sha": "a26e8e483624b2e4ee669e7a069ba9c74d2d2e4b", "save_path": "github-repos/MATLAB/thomaskuestner-CS_MoCo_LAB", "path": "github-repos/MATLAB/thomaskuestner-CS_MoCo_LAB/CS_MoCo_LAB-a26e8e483624b2e4ee669e7a069ba9c74d2d2e4b/reconstruction/matlab/CS_LAB_matlab/utils/utils_SLEP/SLEP/functions/sgLasso/sgLogisticR.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.927363299661721, "lm_q2_score": 0.7981867825403177, "lm_q1q2_score": 0.7402091284029616}} {"text": "function [DisS, dis] = DistanceSum_MPP(X, Y, configure)\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%\n% Define the weighted distance of two point processes' instances\n%\n% Reference:\n% Iwayama, Koji, Yoshito Hirata, and Kazuyuki Aihara. \n% \"Definition of distance for nonlinear time series analysis \n% of marked point process data.\" \n% Physics Letters A 381.4 (2017): 257-262.\n%\n% Provider:\n% Hongteng Xu @ Georgia Tech\n% June 13, 2017\n%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\ndis = zeros(length(configure.weight),1);\nDisS = 0;\nfor i = 1:length(configure.weight)\n dis(i) = Distance_MPP(X, Y, configure.M, configure.id{i});\n DisS = DisS + configure.weight(i) * dis(i);\nend\n \n\n", "meta": {"author": "HongtengXu", "repo": "Hawkes-Process-Toolkit", "sha": "2548a41c7418b8edef3261ab4479cee4e8eaf071", "save_path": "github-repos/MATLAB/HongtengXu-Hawkes-Process-Toolkit", "path": "github-repos/MATLAB/HongtengXu-Hawkes-Process-Toolkit/Hawkes-Process-Toolkit-2548a41c7418b8edef3261ab4479cee4e8eaf071/Analysis/DistanceSum_MPP.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.927363293639213, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.7402091146918958}} {"text": "function emap = snakeMap(f,varargin)\n%SNAKEMAP Computes an edge map for use in the snake iterative algorithm.\n% EMAP = SNAKEMAP(F,T,SIG,NSIG,ORDER) computes the edge map, EMAP, of\n%\t input image F. If only F is provided in the input, EMAP will equal\n%\t the magnitude of the gradient of F (see Chpapter 3) without\n%\t thresholding. If T is also provided, EMAP is thresholded so that, at\n%\t any point, EMAP = 1 if EMAP > T; it is zero otherwise. If T is the\n%\t string 'auto', thresholding is done automatically by function edge.\n%\t Otherwise, T is expected to be a number in the range [0,1]. No\n%\t smoothing filter is applied. If all inputs are provided, the\n%\t magnitude of the gradient is thresholded and filtered using a\n%\t Gaussian kernel of size NSIG*SIG-by-NSIG*SIG where SIG is the\n%\t standard deviation and NISG is an integer giving the number of\n%\t standard deviations we want the kernel size to be. The function\n%\t adjusts the kernel size to be the odd size closest to the specified\n%\t size. ORDER is a character string with the following possible\n%\t values: If order = 'before' then image F is filtered before the map\n%\t (magnitude of the gradient) is computed. If order = 'after'\n%\t filtering is performed on the edge map after it is computed. If\n%\t ORDER = 'both' filtering is performed on the image first, and then\n%\t after the edge map is computed. If ORDER = 'none', no filtering is\n%\t performed. This is the default. Gradients are computed using the\n%\t Sobel kernels.\n%\n% Copyright 2002-2020 Gatesmark\n%\n% This function, and other functions in the DIPUM Toolbox, are based \n% on the theoretical and practical foundations established in the \n% book Digital Image Processing Using MATLAB, 3rd ed., Gatesmark \n% Press, 2020.\n%\n% Book website: http://www.imageprocessingplace.com\n% License: https://github.com/dipum/dipum-toolbox/blob/master/LICENSE.txt\n\n% PRELIMINARIES.\n% Scale image to the floating point intensity range [0,1].\nf = im2double(f); \n% Set defaults.\nthresholding = true;\nfiltering = true;\nif nargin == 1\n\t% Only one input. No thresholding.\n\tthresholding = false;\n\t% No filtering will be done.\n\tfiltering = false;\nelseif numel(varargin) == 1\n\t% Only two inputs.\n\tT = varargin{1};\n\tfiltering = false;\nelseif numel(varargin) == 4\n\tT = varargin{1};\n\tsig = varargin{2};\n\tnsig = varargin{3};\n\torder = varargin{4}; \nelse\n\t% Filtering is expected, but not enough inputs were provided.\n\terror('No enough inputs to define the filtering operation.')\nend\n\n% FILTER THE INPUT IMAGE. \n% If filtering is called for, form the Gaussian lowpass kernel.\nif filtering\n\t% Form Gaussian kernel using function fspecial.\n\tkernelSize = floor(nsig*sig);\n\t% Find the closest odd number of kernelSize.\n\tif iseven(kernelSize)\n kernelSize = kernelSize + 1;\n\tend\n\t% Gaussian kernel.\n\tw = fspecial('gaussian',kernelSize,sig);\nend\n% Check to see if filtering is to be done here.\nif filtering\n\tif isequal(order,'before') || isequal(order,'both')\n f = im2double(imfilter(f,w,'conv','symmetric'));\n\tend\nend\n\n% COMPUTE THE EDGE MAP. We use function edge to compute the gradient\n% image. Because thresholding is done as part of the function, we have\n% to determine at this point if thresholding is to be done and, if so,\n% whether 'auto' was specified or not. Either way, the resulting map is\n% thinned automatically by function edge.\nif thresholding\n\tif isequal(T,'auto')\n emap = double(edge(f,'sobel'));\n else\n emap = double(edge(f,'sobel',T));\n\tend\nelse\n % No thresholding; use edge with a 0 threshold.\n\temap = double(edge(f,'sobel',0));\nend\nif min(emap(:)) == max(emap(:))\n error('Threshold is too low/high. All values of emap are equal')\nend\n\n% FILTER EDGE MAP.\n% Check to see if filtering was specified.\nif filtering\n\t% If order is 'after', or 'both' then filter the edge map now.\n\tif isequal(order,'after') || isequal(order,'both')\n emap = imfilter(im2double(intensityScaling(emap)),...\n w,'conv','symmetric');\n\tend\nend\n \n% SCALE THE EDGE MAP TO THE FULL RANGE [0,1].\nemap = intensityScaling(emap);\n\n", "meta": {"author": "dipum", "repo": "dipum-toolbox", "sha": "9ce653c4c0c4b7c56e46194c24bf152db4ab6832", "save_path": "github-repos/MATLAB/dipum-dipum-toolbox", "path": "github-repos/MATLAB/dipum-dipum-toolbox/dipum-toolbox-9ce653c4c0c4b7c56e46194c24bf152db4ab6832/dipum/snakeFunctions/snakeMap.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528094861981, "lm_q2_score": 0.8688267694452331, "lm_q1q2_score": 0.7401994071856837}} {"text": "%\n% Multiply polynomials, polynomial matrices and numeric matrices\n% h = f1 * f2 * ... * fk\n%\n% Syntax: (ptimes is the shortened alias for PolynomialTimes)\n% >> p = PolynomialTimes(f,g)\n% >> p = PolynomialTimes(f, g, h) %\n% Input: f, g, h, ... --- (string/numeric/cell/matrix) \n% polynomials, numeric matrices and/or polynomial cells,\n% so that the multiplication is well-defined.\n%\n% Output: p --- (string) product of the input polynomials\n%\n% Example:\n%\n% >> PolynomialTimes(3,[1 5; -2 4],'x+y',{'y-1';'x+z'})\n%\n% ans =\n%\n% '-3*x + 15*x^2 - 3*y + 18*x*y + 3*y^2 + 15*x*z + 15*y*z'\n% '6*x + 12*x^2 + 6*y + 6*x*y - 6*y^2 + 12*x*z + 12*y*z'\n%\n", "meta": {"author": "zarathustr", "repo": "LibQPEP", "sha": "99e5c23e746ace0bac4a86742c31db6fcf7297ba", "save_path": "github-repos/MATLAB/zarathustr-LibQPEP", "path": "github-repos/MATLAB/zarathustr-LibQPEP/LibQPEP-99e5c23e746ace0bac4a86742c31db6fcf7297ba/MATLAB/homotopy/PolynomialTimes.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9489172601537141, "lm_q2_score": 0.7799928900257127, "lm_q1q2_score": 0.7401487161425766}} {"text": "% Minimum-phase spectrum of a given spectrum using the complex cepstrum\n%\n% Description\n% Compute the minimum-phase spectrum of a given spectrum X by dropping the\n% negative quefrencies of X.\n%\n% Input\n% X : The spectrum to convert (full DFT length)\n%\n% Output\n% M : The corresponding minimum-phase spectrum\n% lM : The log minimum-phase spectrum\n%\n% References\n% [1] Alan V. Oppenheim and Ronald W. Schafer, \"Digital Signal Processing\",\n% Prentice-Hall, 2nd edition, 1978.\n% Note that this 2nd edition contains a chapter about complex cepstrum which\n% has been removed in the 3rd edition (and possibly came back in the 4th ed.)\n%\n% Copyright (c) 2011 University of Crete - Computer Science Department (UOC-CSD)\n%\n% License\n% This file is under the LGPL license, you can\n% redistribute it and/or modify it under the terms of the GNU Lesser General \n% Public License as published by the Free Software Foundation, either version 3 \n% of the License, or (at your option) any later version. This file is\n% distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; \n% without even the implied warranty of MERCHANTABILITY or FITNESS FOR A \n% PARTICULAR PURPOSE. See the GNU Lesser General Public License for more\n% details.\n%\n% This function is part of the Covarep project: http://covarep.github.io/covarep\n%\n% Author\n% Gilles Degottex \n%\n\nfunction [M lM] = spec2minphasespec(X)\n\n X = X(:).';\n\n rcc = ifft(log(abs(X))); % Compute the real cepstrum\n\n if mod(length(X),2)==0\n % For even DFT length\n lM = fft([rcc(1),2*rcc(2:end/2),rcc(end/2+1)], length(X));% [1]\n else\n % For odd DFT length\n lM = fft([rcc(1),2*rcc(2:(end-1)/2+1)], length(X)); % [1]\n end\n\n M = exp(lM);\n\nreturn\n", "meta": {"author": "covarep", "repo": "covarep", "sha": "5a2be5d6b776f14a0b275c69fde90eb13849e60d", "save_path": "github-repos/MATLAB/covarep-covarep", "path": "github-repos/MATLAB/covarep-covarep/covarep-5a2be5d6b776f14a0b275c69fde90eb13849e60d/misc/spec2minphasespec.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953003183444, "lm_q2_score": 0.8244619328462579, "lm_q1q2_score": 0.7401156024074642}} {"text": "function pers=ordinal_persistence(S)\n% ORDINAL_PERSISTENCE computes the persistence of an ordered multilayer partition\n%\n% Version: 2.2.0\n% Date: Thu 11 Jul 2019 12:25:42 CEST\n%\n% pers = ORDINAL_PERSISTENCE(S) with a single multilayer partition or a\n% cell of multilayer partitions S (with S{i} the ith multilayer partition\n% of cell S) computes the \"persistence\" of ordered multilayer partitions. The\n% output pers is a vector such that pers(i) is the persistence of multilayer\n% partition S{i} (stored as an N*T matrix where N is the number of nodes in\n% each layer and T is the number of layers). For a multilayer partition with\n% ordered layers, the value of persistence is the number of nodes that do\n% not change community assignments between consecutive layers (see Bazzi\n% et al. 2016 for more detail). Ordinal persistence varies between 0 and 1.\n% Ordinal persistence is related to the multilayer quality function\n% developed in Mucha et al. 2010 when one uses ordinal interlayer coupling.\n%\n% References:\n%\n% Mucha, Peter J., Thomas Richardson, Kevin Macon, Mason A. Porter, and\n% Jukka-Pekka Onnela. \"Community Structure in Time-Dependent,\n% Multiscale, and Multiplex Networks,\" Science 328, 876-878 (2010).\n%\n% Bazzi, Marya, Mason A. Porter, Stacy Williams, Mark McDonald, Daniel\n% J. Fenn, and Sam D. Howison. \"Community Detection in Temporal Multilayer\n% Networks, with an Application to Correlation Networks\", MMS: A SIAM\n% Interdisciplinary Journal 14, 1-41 (2016).\n\n\nif ~iscell(S)\n S={S};\nend\n\n[N,T]=size(S{1});\npers=zeros(length(S),1);\nfor i=1:length(S)\n pers(i)=sum(sum(S{i}(:,1:end-1)==S{i}(:,2:end)))/(N*(T-1));\nend\n\nend\n", "meta": {"author": "GenLouvain", "repo": "GenLouvain", "sha": "5688f219baa726988a2faa19cf00d63159fa4ff9", "save_path": "github-repos/MATLAB/GenLouvain-GenLouvain", "path": "github-repos/MATLAB/GenLouvain-GenLouvain/GenLouvain-5688f219baa726988a2faa19cf00d63159fa4ff9/HelperFunctions/ordinal_persistence.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8976953003183443, "lm_q2_score": 0.8244619220634456, "lm_q1q2_score": 0.7401155927277842}} {"text": "%%***********************************************************\n%% lmiexamp2: generate SDP data for the following LMI problem\n%%\n%% max -Tr(P)\n%% s.t. A1*P + P*A1' + B*diag(d)*B' <= 0\n%% A2*P + P*A2' + B*diag(d)*B' <= 0\n%% -d <= 0 \n%% sum(d) = 1\n%%***********************************************************\n%% Here is an example on how to use this function to \n%% find an optimal P. \n%%\n%% A1 = [-1 0 0; 0 -2 0; 1 1 -1];\n%% A2 = A1 + 0.1*A1'; \n%% B = [1 2; 3 4; 5 6]; \n%%\n%% [blk,Avec,C,b] = lmiexamp2(A1,A2,B);\n%% [obj,X,y,Z] = sqlp(blk,Avec,C,b);\n%% n = size(A1,2); N = n*(n+1)/2; dlen = size(B,2); \n%% P = smat(blk(1,:),y(1:N)); \n%% d = y(N+[1:dlen]); \n%%*****************************************************************\n%% SDPT3: version 4.0\n%% Copyright (c) 1997 by\n%% Kim-Chuan Toh, Michael J. Todd, Reha H. Tutuncu\n%% Last Modified: 16 Sep 2004\n%%*****************************************************************\n\n function [blk,Avec,C,b] = lmiexamp2(A1,A2,B); \n\n%%\n n1 = size(A1,2); n2 = size(A2,2); \n if (n1 ~= n2); error('lmiexamp2: A1, A2 not compatible'); end; \n%% \n n = n1; \n I = speye(n); \n blk{1,1} = 's'; blk{1,2} = n;\n Avec{1,1} = lmifun(A1,I,B);\n C{1,1} = sparse(n,n); \n%%\n blk{2,1} = 's'; blk{2,2} = n;\n Avec{2,1} = lmifun(A2,I,B);\n C{2,1} = sparse(n,n); \n%%\n%% and constraints: -d <= 0\n%%\n N = n*(n+1)/2; dlen = size(B,2); \n blk{3,1} = 'l'; blk{3,2} = dlen;\n Avec{3,1} = [sparse(dlen,N) -speye(dlen,dlen)]; \n C{3,1} = zeros(dlen,1); \n%%\n%% add in the constraint: sum(d) = 1\n%%\n blk{4,1} = 'u'; blk{4,2} = 1;\n Avec{4,1} = sparse([zeros(1,N) ones(1,dlen)]); \n C{4,1} = 1; \n%%\n blktmp{1,1} = 's'; blktmp{1,2} = n; \n b = [-svec(blktmp,I); zeros(dlen,1)]; \n%%**********************************************************\n\n", "meta": {"author": "yu-jiang", "repo": "radpbook", "sha": "88b9fa7d0a541099cdd1ac29383c89e087d1d895", "save_path": "github-repos/MATLAB/yu-jiang-radpbook", "path": "github-repos/MATLAB/yu-jiang-radpbook/radpbook-88b9fa7d0a541099cdd1ac29383c89e087d1d895/tools/SDPT3-4.0/SDPT3-4.0/Examples/lmiexamp2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952948443461, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.7401155920865532}} {"text": "function lambdamax = tvdiplmax(y)\n% Calculate the value of lambda so that if lambda >= lambdamax, the TVD\n% functional solved by TVDIP is minimized by the trivial constant\n% solution x = mean(y). This can then be used to determine a useful range\n% of values of lambda, for example.\n%\n% Usage:\n% lambdamax = tvdiplmax(y)\n%\n% Input arguments:\n% - y Original signal to denoise, size N x 1.\n%\n% Output arguments:\n% - lambdamax Value of at which x = mean(y) is the output of the TVDIP\n% function.\n%\n% (c) Max Little, 2010. Based around code originally written by \n% S.J. Kim, K. Koh, S. Boyd and D. Gorinevsky. If you use this code for\n% your research, please cite:\n% M.A. Little, Nick S. Jones (2010)\n% \"Sparse Bayesian Step-Filtering for High-Throughput Analysis of Molecular\n% Machine Dynamics\", in 2010 IEEE International Conference on Acoustics,\n% Speech and Signal Processing, 2010, ICASSP 2010 Proceedings.\n%\n% This code is released under the terms of GNU General Public License as\n% published by the Free Software Foundation; version 2 or later.\n\nerror(nargchk(1,1,nargin));\ny = y(:);\nN = length(y);\nM = N - 1;\n\n% Construct sparse operator matrices\nI1 = speye(M,M);\nO1 = spalloc(M,1,M);\nD = [I1 O1]-[O1 I1];\n\nDDT = D*D';\nDy = D*y;\n\nlambdamax = max(abs(DDT\\Dy));\n\n", "meta": {"author": "beckel", "repo": "nilm-eval", "sha": "83a2cd5fb911299cc267bd9998636934af781915", "save_path": "github-repos/MATLAB/beckel-nilm-eval", "path": "github-repos/MATLAB/beckel-nilm-eval/nilm-eval-83a2cd5fb911299cc267bd9998636934af781915/Matlab/lib/TVDIP/tvdiplmax.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695292107347, "lm_q2_score": 0.824461928533133, "lm_q1q2_score": 0.7401155917659376}} {"text": "function [ x, w ] = legendre_ek_compute ( n )\n\n%*****************************************************************************80\n%\n%% LEGENDRE_EK_COMPUTE: Legendre quadrature rule by the Elhay-Kautsky method.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 19 April 2011\n%\n% Author:\n%\n% Original FORTRAN77 version by Sylvan Elhay, Jaroslav Kautsky.\n% MATLAB version by John Burkardt.\n%\n% Reference:\n%\n% Sylvan Elhay, Jaroslav Kautsky,\n% Algorithm 655: IQPACK, FORTRAN Subroutines for the Weights of\n% Interpolatory Quadrature,\n% ACM Transactions on Mathematical Software,\n% Volume 13, Number 4, December 1987, pages 399-415.\n%\n% Parameters:\n%\n% Input, integer N, the order.\n%\n% Output, real X(N), the abscissas.\n%\n% Output, real W(N), the weights.\n%\n\n%\n% Define the zero-th moment.\n%\n zemu = 2.0;\n%\n% Define the Jacobi matrix.\n%\n bj = zeros ( n, 1 );\n\n for i = 1 : n\n bj(i) = ( i * i ) / ( 4 * i * i - 1 );\n end\n bj(1:n) = sqrt ( bj(1:n) );\n\n x = zeros ( n, 1 );\n\n w = zeros ( n, 1 );\n w(1) = sqrt ( zemu );\n%\n% Diagonalize the Jacobi matrix.\n%\n [ x, w ] = imtqlx ( n, x, bj, w );\n\n w(1:n) = w(1:n).^2;\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/quadrule/legendre_ek_compute.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952811593495, "lm_q2_score": 0.8244619220634456, "lm_q1q2_score": 0.7401155769319224}} {"text": "function b = r8ge_ml ( n, a_lu, pivot, x, job )\n\n%*****************************************************************************80\n%\n%% R8GE_ML computes A * x or A' * x, using R8GE_FA factors.\n%\n% Discussion:\n%\n% The R8GE storage format is used for a general M by N matrix. A storage \n% space is made for each logical entry. The two dimensional logical\n% array is mapped to a vector, in which storage is by columns.\n%\n% It is assumed that R8GE_FA has overwritten the original matrix\n% information by LU factors. R8GE_ML is able to reconstruct the\n% original matrix from the LU factor data.\n%\n% R8GE_ML allows the user to check that the solution of a linear\n% system is correct, without having to save an unfactored copy\n% of the matrix.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 27 March 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the order of the matrix.\n% N must be positive.\n%\n% Input, real A_LU(N,N), the LU factors from R8GE_FA.\n%\n% Input, integer PIVOT(N), the pivot vector computed by R8GE_FA.\n%\n% Input, real X(N), the vector to be multiplied.\n%\n% Input, integer JOB, specifies the operation to be done:\n% JOB = 0, compute A * x.\n% JOB nonzero, compute A' * X.\n%\n% Output, real B(N), the result of the multiplication.\n%\n b(1:n) = x(1:n);\n\n if ( job == 0 )\n%\n% Y = U * X.\n%\n for j = 1 : n\n b(1:j-1) = b(1:j-1) + a_lu(1:j-1,j)' * b(j);\n b(j) = a_lu(j,j) * b(j);\n end\n%\n% B = PL * Y = PL * U * X = A * x.\n%\n for j = n-1 : -1 : 1\n\n b(j+1:n) = b(j+1:n) - a_lu(j+1:n,j)' * b(j);\n k = pivot(j);\n\n if ( k ~= j )\n t = b(k);\n b(k) = b(j);\n b(j) = t;\n end\n\n end\n\n else\n%\n% Y = (PL)' * X:\n%\n for j = 1 : n-1\n\n k = pivot(j);\n\n if ( k ~= j )\n t = b(k);\n b(k) = b(j);\n b(j) = t;\n end\n\n b(j) = b(j) - sum ( b(j+1:n) * a_lu(j+1:n,j) );\n\n end\n%\n% B = U' * Y = ( PL * U )' * X = A' * X.\n%\n for i = n : -1 : 1\n b(i+1:n) = b(i+1:n) + b(i) * a_lu(i,i+1:n);\n b(i) = b(i) * a_lu(i,i);\n end\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/linplus/r8ge_ml.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467738423873, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.7400883054077447}} {"text": "function [z,e]=exactPairMult(xIn,yIn)\n%%EXACTPAIRMULT Calculate the product of the floating point double values\n% x and y such that the result z+e (if added with infinite\n% precision) is exactly the product x*y, where z is the\n% floating point product and e is the part of the result that\n% cannot be expressed exactly. This is implemented for x and\n% y being floating point doubles.\n%\n%INPUTS xIn, yIn Two real arrays of sizes that can be added.\n%\n%OUTPUTS: z The real product x.*y as limited by floating point precision.\n% e The real error such that if done with inifite precision\n% (z+e)==x*y. This does not necessarily hold when numbers become\n% denormalized.\n%\n%This function implements Dekker's algorithm, which is given as Mul12 in\n%[1]. Note that additional scaling is performed for the instance where\n%Dekker's algorithm might result in an overflow. That is when x or y is\n%above 2^(1023 (maximum exponent) -53 (mantissa length))=2^970.\n%\n%The output pair (z,e) can be considered to be a \"doublelength\" floating\n%point number, as defined in [1]. This means that\n%abs(e)<=abs(z+e)*2^(-t)/(1+2^(-t)) (considering exact arithmetic), where t\n%is the number of bits in the mantissa of the floating point number. Here,\n%that is 53.\n%\n%Note that this assumes that the processor rounding mode has been set to\n%round to \"nearest,\" which is the default in Matlab, but which can be\n%changed using the function setProcRoundingMode.\n%\n%EXAMPLE:\n%Consider the product\n% [z,e]=exactPairMult(1+2^50,1+2^(-15))\n%One will get z=1.125934266580993e+15 and e=3.051757812500000e-05.\n%The exact value of the product can be found to be\n%1125934266580993.000030517578125\n%If one adds z and e exactly, one gets precisely that result.\n%\n%REFERENCES:\n%[1] T. J. Dekker, \"A Floating Point Technique for Extending the Available\n% Precision,\" Numerische Mathematik, vol. 18, no. 3, Jun. 1971, pp.\n% 224-242.\n%\n%November 2018 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nif(~isa(xIn,'double')||~isa(yIn,'double'))\n error('This function is only implemented for x and y being double floating point values.')\nend\n\nif(isempty(xIn)||isempty(yIn))\n %Returning empty matrices if one input is an empty matrix is consistent\n %with what Matlab does when trying to multiply an empty matrix with\n %something.\n z=[];\n e=[];\n return\nend\n\n%This is 2^(1023 (maximum exponent) -53)=2^970\nmaxUnscaled=9.9792015476735990582818635651842e291;\ntwo53=9007199254740992;%2^53;\ntwom53=1.1102230246251565404236316680908e-16;%2^(-53)\n\nisScalX=isscalar(xIn);\nisScalY=isscalar(yIn);\n\nif(xor(isScalX,isScalY))\n %If one is scalar and the other is not.\n if(isScalX)\n dims=size(yIn);\n xIn=repmat(xIn,dims);\n else\n dims=size(xIn);\n yIn=repmat(yIn,dims);\n end\nelse\n %If neither is scalar or both are scalar, assume that they are the same\n %size.\n dims=size(xIn);\nend\n\nz=zeros(dims);\ne=zeros(dims);\nnumEl=numel(z);\n\nfor curEl=1:numEl\n x=xIn(curEl);\n y=yIn(curEl);\n if(x>maxUnscaled)\n x=x*twom53;\n invScalFactX=two53;\n else\n invScalFactX=1;\n end\n\n if(y>maxUnscaled)\n y=y*twom53;\n invScalFactY=two53;\n else\n invScalFactY=1;\n end\n invScalFact=invScalFactX*invScalFactY;\n\n [zCur,eCur]=exactPairMultPrescaled(x,y);\n\n z(curEl)=zCur*invScalFact;\n e(curEl)=eCur*invScalFact;\nend\nend\n\nfunction [z,e]=exactPairMultPrescaled(x,y)\n %The double mantissa is 53 bits (including the implicit one).\n const=134217729;%This is 2^ceil(53/2)+1=2^27+1\n \n p=x*const;\n hx=(x-p)+p;\n tx=x-hx;\n p=y*const;\n hy=(y-p)+p;\n ty=y-hy;\n p=hx*hy;\n q=(hx*ty)+(tx*hy);\n z=p+q;\n e=p-z+q+tx*ty;\n\nend\n\n%LICENSE:\n%\n%The source code is in the public domain and not licensed or under\n%copyright. The information and software may be used freely by the public.\n%As required by 17 U.S.C. 403, third parties producing copyrighted works\n%consisting predominantly of the material produced by U.S. government\n%agencies must provide notice with such work(s) identifying the U.S.\n%Government material incorporated and stating that such material is not\n%subject to copyright protection.\n%\n%Derived works shall not identify themselves in a manner that implies an\n%endorsement by or an affiliation with the Naval Research Laboratory.\n%\n%RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF THE\n%SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY THE NAVAL\n%RESEARCH LABORATORY FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE ACTIONS\n%OF RECIPIENT IN THE USE OF THE SOFTWARE.\n", "meta": {"author": "USNavalResearchLaboratory", "repo": "TrackerComponentLibrary", "sha": "9f6e329de5be06a371757c4b853200beb6def2d0", "save_path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary", "path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary/TrackerComponentLibrary-9f6e329de5be06a371757c4b853200beb6def2d0/Mathematical_Functions/Accurate_Arithmetic/exactPairMult.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972616934408, "lm_q2_score": 0.8499711756575749, "lm_q1q2_score": 0.7399825780458392}} {"text": "function [ bool ] = gsp_test_duality_coefficient( gcoeff,hcoeff,tol )\n%GSP_TEST_DUALITY_COEFFICIENT Test if the coefficient are from dual filters\n% Usage: bool = gsp_test_duality_coefficient( gcoeff,hcoeff );\n% bool = gsp_test_duality_coefficient( gcoeff,hcoeff,tol );\n%\n% Input parameters:\n% gcoeff : coefficient of the filter 1 (matrix $N$ x $M$ )\n% hcoeff : coefficinet of the filter 2 (matrix $N$ x $M$ )\n% tol : tolerance for the test (default 1e-5)\n%\n% Ouput paramters:\n% bool : boolean \n%\n% This function test if two discrete filterbanks are dual. Each filter is\n% a column in the matrix *gcoeff* or *hcoeff*. $M$ is the number of\n% filters and $N$ the number of coefficients (size of the graph signal).\n%\n\n% Author: Nathanael Perraudin\n% Date : 13 july 2014\n% testing: test_dual\n\nif nargin<3\n tol = 1e-5;\nend\n\nv = sum(gcoeff.*hcoeff,2);\nA = min(v);\nB = max(v);\nbool = ( (A-B) / ((A+B)/2) ) < tol;\n\nend\n\n", "meta": {"author": "epfl-lts2", "repo": "gspbox", "sha": "a7d9aac5e239f1bcb37a9bb09998cc161be2732f", "save_path": "github-repos/MATLAB/epfl-lts2-gspbox", "path": "github-repos/MATLAB/epfl-lts2-gspbox/gspbox-a7d9aac5e239f1bcb37a9bb09998cc161be2732f/filters/gsp_test_duality_coefficient.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8705972616934408, "lm_q2_score": 0.8499711699569786, "lm_q1q2_score": 0.7399825730829157}} {"text": "function prob_test026 ( )\n\n%*****************************************************************************80\n%\n%% TEST026 tests BURR_CDF, BURR_CDF_INV, BURR_PDF.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 15 April 2009\n%\n% Author:\n%\n% John Burkardt\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TEST026\\n' );\n fprintf ( 1, ' For the Burr PDF:\\n' );\n fprintf ( 1, ' BURR_CDF evaluates the CDF;\\n' );\n fprintf ( 1, ' BURR_CDF_INV inverts the CDF.\\n' );\n fprintf ( 1, ' BURR_PDF evaluates the PDF;\\n' );\n\n a = 1.0;\n b = 2.0;\n c = 3.0;\n d = 2.0;\n\n check = burr_check ( a, b, c, d );\n\n if ( ~check );\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TEST026 - Fatal error!\\n' );\n fprintf ( 1, ' The parameters are not legal.\\n' );\n return\n end\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' PDF parameter A = %14f\\n', a );\n fprintf ( 1, ' PDF parameter B = %14f\\n', b );\n fprintf ( 1, ' PDF parameter C = %14f\\n', c );\n fprintf ( 1, ' PDF parameter D = %14f\\n', d );\n\n seed = 123456789;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' X PDF CDF CDF_INV\\n' );\n fprintf ( 1, '\\n' );\n\n for i = 1 : 10\n\n [ x, seed ] = burr_sample ( a, b, c, d, seed );\n\n pdf = burr_pdf ( x, a, b, c, d );\n\n cdf = burr_cdf ( x, a, b, c, d );\n\n x2 = burr_cdf_inv ( cdf, a, b, c, d );\n\n fprintf ( 1, ' %14f %14f %14f %14f\\n', x, pdf, cdf, x2 );\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/prob/prob_test026.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942377652497, "lm_q2_score": 0.8311430520409023, "lm_q1q2_score": 0.7399618699906384}} {"text": "function value = problem4 ( x, h, epsilon, o )\n\n%*****************************************************************************80\n%\n%% PROBLEM4 evaluates problem data for problem 4.\n%\n% Discussion:\n%\n% case # 4: u_anl = x-1/4.......................................x<0.5\n% x-1/2.......................................x>0.5 \n% \n% w_anl = 0...................................x<0.5-epsilon\n% -2/epsilon^2(-1/4(log(epsilon)-\n% log(1/2-v)))....................0.5-epsilon0.5+epsilon\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 28 February 2012\n%\n% Parameters:\n%\n% Input, real X(:), the evaluation points.\n%\n% Input, real H, the discretization parameter.\n%\n% Input, real EPSILON, the nonlocalization parameter.\n%\n% Input, string O, the option:\n% 'U', evaluate the exact solution.\n% 'D', evaluate the derivative of the exact solution.\n% 'F', evaluate the right hand side.\n% 'L', evaluate the lifting function.\n%\n if ( o == 'u' )\n value = (x-1/4).*(x<0.5) + (x-1/2).*(x>=0.5);\n elseif ( o == 'd' )\n value = zeros ( size ( x ) );\n elseif ( o == 'f' )\n epsilon2 = epsilon * epsilon;\n value = (x<0.5-epsilon).*0 + ...\n (x>=0.5-epsilon & x<0.5).*(-2)/epsilon2.*(-1/4* (log(epsilon)-log(1/2-x))) + ...\n (x>0.5 & x<0.5+epsilon).*2/epsilon2.*(1/4*(log(x-1/2)-log(epsilon))) + ...\n (x>=0.5+epsilon).*0;\n elseif ( o == 'l' )\n value = (x<=0).*(x-1/4) + ...\n (x>0 & x<=h).* (1/4).*(x./h-1)+ ...\n (x>h & x< 1-h).* 0 * epsilon + ...\n (x>=1-h & x<=1).* (1/2).*(1. + (x-1)./h) + ...\n (x>1).*(x-1/2);\n else\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'PROBLEM4 - Fatal error!\\n' );\n fprintf ( 1, ' Unrecognized option O = \"%s\"\\n', o );\n error ( 'PROBLEM4 - Fatal error!\\n' );\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/peridynamics_1d_steady/problem4.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220294, "lm_q2_score": 0.8311430562234877, "lm_q1q2_score": 0.7399618640371883}} {"text": "function spline_test17 ( )\n\n%*****************************************************************************80\n%\n%% TEST17 tests SPLINE_CUBIC_SET, SPLINE_CUBIC_VAL.\n%\n% Discussion:\n%\n% For boundary condition 0, the spline should come very close within\n% the interpolation interval.\n%\n% For conditions 1 and 2, the spline should be essentially exactly equal\n% to the data, inside and outside the interpolation interval.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 01 February 2009\n%\n% Author\n%\n% John Burkardt\n%\n n = 11;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TEST17\\n' );\n fprintf ( 1, ' SPLINE_CUBIC_SET sets up a cubic spline;\\n' );\n fprintf ( 1, ' SPLINE_CUBIC_VAL evaluates it.\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Cubic data, unevenly spaced knots.\\n' );\n\n for i = 1 : n\n t(i) = ( ( i - 1 ) / ( n - 1 ) )^2;\n end\n\n for i = 1 : n\n y(i) = fcube ( t(i) );\n end\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' The data to be interpolated:\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Number of data values = %d\\n', n );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' T Y\\n' );\n fprintf ( 1, '\\n' );\n\n for i = 1 : n\n fprintf ( 1, '%14f %14f\\n', t(i), y(i) );\n end\n%\n% Try boundary condition types 0, 1 and 2.\n%\n for k = 0 : 2\n\n if ( k == 0 )\n\n ibcbeg = 0;\n ybcbeg = 0.0E+00;\n\n ibcend = 0;\n ybcend = 0.0E+00;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Boundary condition 0 at both ends:\\n' );\n fprintf ( 1, ' Spline is quadratic in boundary intervals.\\n' );\n\n elseif ( k == 1 )\n\n ibcbeg = 1;\n ybcbeg = fpcube ( t(1) );\n\n ibcend = 1;\n ybcend = fpcube ( t(n) );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Boundary condition 1 at both ends:\\n' );\n fprintf ( 1, ' Y''(left) = %f\\n', ybcbeg );\n fprintf ( 1, ' Y''(right) = %f\\n', ybcend );\n\n elseif ( k == 2 )\n\n ibcbeg = 2;\n ybcbeg = fppcube ( t(1) );\n\n ibcend = 2;\n ybcend = fppcube ( t(n) );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Boundary condition 2 at both ends:\\n' );\n fprintf ( 1, ' YP\"(left) = %f\\n', ybcbeg );\n fprintf ( 1, ' YP\"(right) = %f\\n', ybcend );\n\n end\n\n ypp = spline_cubic_set ( n, t, y, ibcbeg, ybcbeg, ibcend, ybcend );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' SPLINE\"(T), F\"(T):\\n' );\n fprintf ( 1, '\\n' );\n for i = 1: n\n fprintf ( 1, '%14f %14f\\n', ypp(i), fppcube(t(i)) );\n end\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' T, SPLINE(T), F(T)\\n' );\n fprintf ( 1, '\\n' );\n\n for i = 0 : n\n\n if ( i == 0 )\n jhi = 1;\n elseif ( i < n )\n jhi = 2;\n else\n jhi = 2;\n end\n\n for j = 1 : jhi\n\n if ( i == 0 )\n tval = t(1) - 1.0E+00;\n elseif ( i < n )\n tval = ( ( jhi - j + 1 ) * t(i) ...\n + ( j - 1 ) * t(i+1) ) ...\n / ( jhi );\n else\n if ( j == 1 )\n tval = t(n);\n else\n tval = t(n) + 1.0E+00;\n end\n end\n\n [ yval, ypval, yppval ] = spline_cubic_val ( n, t, y, ypp, tval );\n\n fprintf ( 1, '%14f %14f %14f\\n', tval, yval, fcube ( tval ) );\n\n end\n end\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/spline/spline_test17.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942348544447, "lm_q2_score": 0.831143045767024, "lm_q1q2_score": 0.7399618619857453}} {"text": "function chebyshev_polynomial_test17 ( )\n\n%*****************************************************************************80\n%\n%% TEST17 tests T_TRIPLE_PRODUCT_INTEGRAL.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 25 April 2012\n%\n% Author:\n%\n% John Burkardt\n%\n test_num = 20;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'CHEBYSHEV_POLYNOMIAL_TEST17:\\n' );\n fprintf ( 1, ' T_TRIPLE_PRODUCT_INTEGRAL computes the triple integral\\n' );\n fprintf ( 1, ' Tijk = integral ( -1 <= x <= 1 ) T(i,x) T(j,x) T(k,x) / sqrt ( 1-x^2) dx\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' I J K Tijk Tijk\\n' );\n fprintf ( 1, ' computed exact\\n' );\n fprintf ( 1, '\\n' );\n\n n = 15;\n [ x, w ] = t_quadrature_rule ( n );\n\n seed = 123456789;\n\n for test = 1 : test_num\n [ i, seed ] = i4_uniform ( 2, 6, seed );\n [ j, seed ] = i4_uniform ( 1, 3, seed );\n [ k, seed ] = i4_uniform ( 0, 4, seed );\n fx1 = t_triple_product_integral ( i, j, k );\n fx2 = 0.0;\n for l = 1 : n\n ti = t_polynomial_value ( i, x(l) );\n tj = t_polynomial_value ( j, x(l) );\n tk = t_polynomial_value ( k, x(l) );\n fx2 = fx2 + w(l) * ti * tj * tk;\n end\n fprintf ( 1, ' %2d %2d %2d %14.6g %14.6g\\n', i, j, k, fx1, fx2 );\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/chebyshev_polynomial/chebyshev_polynomial_test17.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220291, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.7399618565897248}} {"text": "function [ num1, num2 ] = myconvert( str )\n% Function to convert the vector string to numbers\n% By Kyriakos Tsourapas\n% You may contact me through the Mathworks site\n% University of Essex 2002\n\n\n% CREATE THE NUMBERS FROM THE STRING\nsign1 = str(1);\nintpart1 = sprintf('%d%d', str(2:3));\ndecpart1 = sprintf('%d%d%d%d%d%d%d%d%d%d', str(4:13));\nsign2 = str(14);\nintpart2 = sprintf('%d%d', str(15:16));\ndecpart2 = sprintf('%d%d%d%d%d%d%d%d%d%d', str(17:26));\n\n% CONVERT THEM TO DECIMAL FROM BINARY\nnum1 = bin2dec(intpart1) + bin2dec(decpart1)/1000;\nnum2 = bin2dec(intpart2) + bin2dec(decpart2)/1000;\n\nif sign1 == 1\n num1 = - num1;\nend\n\nif sign2 == 1\n num2 = - num2;\nend", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/1339-simple-hill-climbing/myconvert.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436397, "lm_q2_score": 0.8311430415844384, "lm_q1q2_score": 0.7399618558427181}} {"text": "function hypercube_grid_test02 ( )\n\n%*****************************************************************************80\n%\n%% HYPERCUBE_GRID_TEST02 tests HYPERCUBE_GRID on a five dimensional example.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 28 August 2014\n%\n% Author:\n%\n% John Burkardt\n%\n m = 5;\n\n a = [ 0.0, 0.0, 0.0, 0.0, 0.0 ];\n b = [ 1.0, 1.0, 1.0, 1.0, 1.0 ];\n c = [ 1, 2, 3, 4, 5 ];\n ns = [ 2, 2, 2, 2, 2 ];\n\n n = prod ( ns(1:m) );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'HYPERCUBE_GRID_TEST02\\n' );\n fprintf ( 1, ' Create a grid using HYPERCUBE_GRID.\\n' );\n fprintf ( 1, ' Use a two point grid in each dimension.\\n' );\n fprintf ( 1, ' Use a different centering option in each dimension.\\n' );\n fprintf ( 1, ' Spatial dimension M = %d\\n', m );\n fprintf ( 1, ' Number of grid points N = %d\\n', n );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' I NS C A B\\n' );\n fprintf ( 1, '\\n' );\n for i = 1 : m\n fprintf ( 1, ' %4d %4d %4d %8.4f %8.4f\\n', i, ns(i), c(i), a(i), b(i) );\n end\n\n x = hypercube_grid ( m, n, ns, a, b, c );\n r8mat_transpose_print ( m, n, x, ' Grid points:' );\n\n return\nend\n\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/hypercube_grid/hypercube_grid_test02.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430478583168, "lm_q2_score": 0.8902942246666267, "lm_q1q2_score": 0.7399618553800772}} {"text": "function fd1d_advection_diffusion_steady ( )\n\n%*****************************************************************************80\n%\n%% FD1D_ADVECTION_DIFFUSION_STEADY solves steady advection diffusion equation.\n%\n% Discussion:\n%\n% The steady advection diffusion equation has the form:\n%\n% v ux - k * uxx = 0\n%\n% where V (the advection velocity) and K (the diffusivity) are positive \n% constants, posed in the region\n%\n% a = 0 < x < 1 = b\n%\n% with boundary conditions\n%\n% u(0) = 0, u(1) = 1.\n%\n% The discrete solution is unreliable when dx > 2 * k / v / ( b - a ).\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 02 May 2014\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Charles Hall, Thomas Porsching,\n% Numerical Analysis of Partial Differential Equations,\n% Prentice-Hall, 1990,\n% ISBN: 013626557X,\n% LC: QA374.H29.\n%\n timestamp ( );\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'FD1D_ADVECTION_DIFFUSION_STEADY:\\n' );\n fprintf ( 1, ' MATLAB version\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Solve the 1D steady advection diffusion equation:\\n' );\n fprintf ( 1, ' v du/dx - k d2u/dx2 = 0\\n' );\n fprintf ( 1, ' with constant, positive velocity V and diffusivity K,\\n' );\n fprintf ( 1, ' over the interval:\\n' );\n fprintf ( 1, ' 0.0 <= x <= 1.0\\n' );\n fprintf ( 1, ' with boundary conditions:\\n' );\n fprintf ( 1, ' u(0) = 0, u(1) = 1.\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Use finite differences:\\n' );\n fprintf ( 1, ' d u/dx = (u(x+dx)-u(x-dx))/2/dx\\n' );\n fprintf ( 1, ' d2u/dx2 = (u(x+dx)-2u(x)+u(x-dx))/dx^2\\n' );\n%\n% Physical constants.\n%\n v = 1.0;\n k = 0.05;\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Diffusivity K = %g\\n', k );\n fprintf ( 1, ' Constant velocity V = %g\\n', v );\n%\n% Spatial discretization.\n%\n nx = 41;\n a = 0.0;\n b = 1.0;\n dx = ( b - a ) / ( nx - 1 );\n x = ( linspace ( a, b, nx ) )';\n\n fprintf ( 1, ' Number of nodes NX = %d\\n', nx );\n fprintf ( 1, ' DX = %g\\n', dx );\n fprintf ( 1, ' Maximum safe DX is %g\\n', 2 * k / v / ( b - a ) );\n%\n% Set up linear system corresponding to boundary conditions and\n% advection-diffusion equation.\n%\n A = sparse ( nx, nx );\n f = zeros ( nx, 1 );\n\n A(1,1) = 1.0;\n f(1) = 0.0;\n\n for i = 2 : nx - 1\n A(i,i-1) = - v / dx / 2.0 - k / dx / dx;\n A(i,i) = + 2.0 * k / dx / dx;\n A(i,i+1) = + v / dx / 2.0 - k / dx / dx;\n f(i) = 0.0;\n end\n\n A(nx,nx) = 1.0;\n f(nx) = 1.0;\n%\n% Solve linear system for U.\n%\n u = A \\ f;\n%\n% The exact solution to the differential equation is known.\n%\n r = v * ( b - a ) / k;\n w = ( 1.0 - exp ( r * x ) ) / ( 1.0 - exp ( r ) );\n%\n% Plot discrete solution U (dots) and exact solution W (line).\n%\n hold on\n plot ( x, w, 'b-', 'LineWidth', 2 );\n plot ( x, u, 'r.', 'LineWidth', 2, 'Markersize', 20 );\n\n grid on\n xlabel ( '<--X-->', 'Fontsize', 16 );\n ylabel ( '<--U(X)-->', 'Fontsize', 16 );\n title ( 'Solution of Steady Advection-Diffusion Equation', 'Fontsize', 24);\n hold off\n\n filename = 'fd1d_advection_diffusion_steady.png';\n print ( '-dpng', filename );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Saving plot as \"%s\".\\n', filename );\n%\n% Terminate.\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'FD1D_ADVECTION_DIFFUSION_STEADY\\n' );\n fprintf ( 1, ' Normal end of execution.\\n' );\n fprintf ( 1, '\\n' );\n timestamp ( );\n\n return\nend\nfunction timestamp ( )\n\n%*****************************************************************************80\n%\n%% TIMESTAMP prints the current YMDHMS date as a timestamp.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 14 February 2003\n%\n% Author:\n%\n% John Burkardt\n%\n t = now;\n c = datevec ( t );\n s = datestr ( c, 0 );\n fprintf ( 1, '%s\\n', s );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/fd1d_advection_diffusion_steady/fd1d_advection_diffusion_steady.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942232112239, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.7399618541704293}} {"text": "function lp=dir_lpdf(x,a)\n%DIR_LPDF Log probability density function of uniform Dirichlet\n% distribution\n%\n% Description:\n% LP = DIR_LPDF(X, A) returns the lpdf of Dirichlet distribution \n% with A at X\n%\n% Copyright (c) 2000 Aki Vehtari\n\n% This software is distributed under the GNU General Public \n% License (version 3 or later); please refer to the file \n% License.txt, included with the software, for details.\n\n\nlp=gammaln(sum(a))-sum(gammaln)+sum(log(x).^(a-1));\n", "meta": {"author": "gpstuff-dev", "repo": "gpstuff", "sha": "114937ec0a201306489a66cbba38283e722fb998", "save_path": "github-repos/MATLAB/gpstuff-dev-gpstuff", "path": "github-repos/MATLAB/gpstuff-dev-gpstuff/gpstuff-114937ec0a201306489a66cbba38283e722fb998/dist/dir_lpdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9184802395624259, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.7399572480778476}} {"text": "% EX_LAPLACE_ISO_PLATE: solve the Poisson problem in one quarter of a plate with a hole, discretized with NURBS (isoparametric approach).\n\n% 1) PHYSICAL DATA OF THE PROBLEM\nclear problem_data \n% Physical domain, defined as NURBS map given in a text file\nproblem_data.geo_name = 'geo_plate_with_hole.txt';\n\n% Type of boundary conditions for each side of the domain\nproblem_data.nmnn_sides = [3 4];\nproblem_data.drchlt_sides = [1 2];\n\n% Physical parameters\nproblem_data.c_diff = @(x, y) ones(size(x));\n\n% Source and boundary terms\nproblem_data.f = @(x, y) zeros(size(x));\nproblem_data.g = @test_plate_mixed_bc_g_nmnn;\nproblem_data.h = @(x, y, ind) exp(x).*sin(y);\n\n% Exact solution (optional)\nproblem_data.uex = @(x, y) exp(x).*sin (y);\nproblem_data.graduex = @(x, y) cat (1, ...\n reshape (exp(x).*sin(y), [1, size(x)]), ...\n reshape (exp(x).*cos(y), [1, size(x)]));\n\n% 2) CHOICE OF THE DISCRETIZATION PARAMETERS\nclear method_data \nmethod_data.degree = [3 3]; % Degree of the splines\nmethod_data.regularity = [2 2]; % Regularity of the splines\nmethod_data.nsub = [8 8]; % Number of subdivisions\nmethod_data.nquad = [4 4]; % Points for the Gaussian quadrature rule\n\n% 3) CALL TO THE SOLVER\n[geometry, msh, space, u] = solve_laplace_iso (problem_data, method_data);\n\n% 4) POST-PROCESSING\n% 4.1) EXPORT TO PARAVIEW\n\noutput_file = 'Plate_NRB_Deg3_Reg2_Sub8';\n\nvtk_pts = {linspace(0, 1, 21), linspace(0, 1, 21)};\nfprintf ('The result is saved in the file %s \\n \\n', output_file);\nsp_to_vtk (u, space, geometry, vtk_pts, output_file, 'u')\n\n% 4.2) PLOT IN MATLAB. COMPARISON WITH THE EXACT SOLUTION\n\n[eu, F] = sp_eval (u, space, geometry, vtk_pts);\n[X, Y] = deal (squeeze(F(1,:,:)), squeeze(F(2,:,:)));\nsubplot (1,2,1)\nsurf (X, Y, eu)\ntitle ('Numerical solution'), axis tight\nsubplot (1,2,2)\nsurf (X, Y, problem_data.uex (X,Y))\ntitle ('Exact solution'), axis tight\n\n% Display errors of the computed solution in the L2 and H1 norm\n[error_h1, error_l2] = ...\n sp_h1_error (space, msh, u, problem_data.uex, problem_data.graduex)\n\n%!demo\n%! ex_laplace_iso_plate\n\n%!test\n%! problem_data.geo_name = 'geo_plate_with_hole.txt';\n%! problem_data.nmnn_sides = [3 4];\n%! problem_data.drchlt_sides = [1 2];\n%! problem_data.c_diff = @(x, y) ones(size(x));\n%! problem_data.f = @(x, y) zeros(size(x));\n%! problem_data.g = @test_plate_mixed_bc_g_nmnn;\n%! problem_data.h = @(x, y, ind) exp(x).*sin(y);\n%! problem_data.uex = @(x, y) exp(x).*sin (y);\n%! problem_data.graduex = @(x, y) cat (1, ...\n%! reshape (exp(x).*sin(y), [1, size(x)]), ...\n%! reshape (exp(x).*cos(y), [1, size(x)]));\n%! method_data.degree = [3 3]; % Degree of the splines\n%! method_data.regularity = [2 2]; % Regularity of the splines\n%! method_data.nsub = [8 8]; % Number of subdivisions\n%! method_data.nquad = [4 4]; % Points for the Gaussian quadrature rule\n%! [geometry, msh, space, u] = solve_laplace_iso (problem_data, method_data);\n%! [error_h1, error_l2] = sp_h1_error (space, msh, u, problem_data.uex, problem_data.graduex);\n%! assert (msh.nel, 128)\n%! assert (space.ndof, 231)\n%! assert (error_h1, 6.16178098362953e-04, 1e-16)\n%! assert (error_l2, 4.44336164898602e-05, 1e-16)", "meta": {"author": "rafavzqz", "repo": "geopdes", "sha": "3bfa57b1a38bd4da3148536c9f67cce81afce701", "save_path": "github-repos/MATLAB/rafavzqz-geopdes", "path": "github-repos/MATLAB/rafavzqz-geopdes/geopdes-3bfa57b1a38bd4da3148536c9f67cce81afce701/geopdes/inst/examples/base/ex_laplace_iso_plate.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.918480237330998, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.7399572377075668}} {"text": "function D=distMat(P1, P2)\n%\n% Euclidian distances between vectors\n% each vector is one row\n \nif nargin == 2\n P1 = double(P1);\n P2 = double(P2);\n \n X1=repmat(sum(P1.^2,2),[1 size(P2,1)]);\n X2=repmat(sum(P2.^2,2),[1 size(P1,1)]);\n R=P1*P2';\n D=real(sqrt(X1+X2'-2*R));\nelse\n P1 = double(P1);\n\n % each vector is one row\n X1=repmat(sum(P1.^2,2),[1 size(P1,1)]);\n R=P1*P1';\n D=X1+X1'-2*R;\n D = real(sqrt(D));\nend\n\n\n", "meta": {"author": "willard-yuan", "repo": "hashing-baseline-for-image-retrieval", "sha": "822837884bdb5d44e297015d05ad081cea695a56", "save_path": "github-repos/MATLAB/willard-yuan-hashing-baseline-for-image-retrieval", "path": "github-repos/MATLAB/willard-yuan-hashing-baseline-for-image-retrieval/hashing-baseline-for-image-retrieval-822837884bdb5d44e297015d05ad081cea695a56/utils/distMat.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9241418241572635, "lm_q2_score": 0.8006920044739461, "lm_q1q2_score": 0.7399529696026883}} {"text": "function [y,L] = mdwt(x,h,L);\n% [y,L] = mdwt(x,h,L);\n%\n% Function computes the discrete wavelet transform y for a 1D or 2D input\n% signal x using the scaling filter h.\n%\n% Input:\n%\tx : finite length 1D or 2D signal (implicitly periodized)\n% h : scaling filter\n% L : number of levels. In the case of a 1D signal, length(x) must be\n% divisible by 2^L; in the case of a 2D signal, the row and the\n% column dimension must be divisible by 2^L. If no argument is\n% specified, a full DWT is returned for maximal possible L.\n%\n% Output:\n% y : the wavelet transform of the signal \n% (see example to understand the coefficients)\n% L : number of decomposition levels\n%\n% 1D Example:\n% x = makesig('LinChirp',8);\n% h = daubcqf(4,'min');\n% L = 2;\n% [y,L] = mdwt(x,h,L)\n%\n% 1D Example's output and explanation:\n%\n% y = [1.1097 0.8767 0.8204 -0.5201 -0.0339 0.1001 0.2201 -0.1401]\n% L = 2\n%\n% The coefficients in output y are arranged as follows\n%\n% y(1) and y(2) : Scaling coefficients (lowest frequency)\n% y(3) and y(4) : Band pass wavelet coefficients\n% y(5) to y(8) : Finest scale wavelet coefficients (highest frequency)\n%\n% 2D Example:\n%\n% load test_image \n% h = daubcqf(4,'min');\n% L = 1;\n% [y,L] = mdwt(test_image,h,L);\n%\n% 2D Example's output and explanation:\n%\n% The coefficients in y are arranged as follows.\n%\n% .------------------.\n% | | |\n% | 4 | 2 |\n% | | |\n% | L,L | H,L |\n% | | |\n% --------------------\n% | | |\n% | 3 | 1 |\n% | | |\n% | L,H | H,H |\n% | | |\n% `------------------'\n% \n% where \n% 1 : High pass vertically and high pass horizontally\n% 2 : Low pass vertically and high pass horizontally\n% 3 : High pass vertically and low pass horizontally\n% 4 : Low pass vertically and Low pass horizontally \n% (scaling coefficients)\n%\n%\n%\n%\n% See also: midwt, mrdwt, mirdwt\n%\n\n%File Name: mdwt.m\n%Last Modification Date: 08/07/95\t15:13:25\n%Current Version: mdwt.m\t2.4\n%File Creation Date: Wed Oct 19 10:51:58 1994\n%Author: Markus Lang \n%\n%Copyright (c) 2000 RICE UNIVERSITY. All rights reserved.\n%Created by Markus Lang, Department of ECE, Rice University. \n%\n%This software is distributed and licensed to you on a non-exclusive \n%basis, free-of-charge. Redistribution and use in source and binary forms, \n%with or without modification, are permitted provided that the following \n%conditions are met:\n%\n%1. Redistribution of source code must retain the above copyright notice, \n% this list of conditions and the following disclaimer.\n%2. Redistribution in binary form must reproduce the above copyright notice, \n% this list of conditions and the following disclaimer in the \n% documentation and/or other materials provided with the distribution.\n%3. All advertising materials mentioning features or use of this software \n% must display the following acknowledgment: This product includes \n% software developed by Rice University, Houston, Texas and its contributors.\n%4. Neither the name of the University nor the names of its contributors \n% may be used to endorse or promote products derived from this software \n% without specific prior written permission.\n%\n%THIS SOFTWARE IS PROVIDED BY WILLIAM MARSH RICE UNIVERSITY, HOUSTON, TEXAS, \n%AND CONTRIBUTORS AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, \n%BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS \n%FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RICE UNIVERSITY \n%OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, \n%EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, \n%PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; \n%OR BUSINESS INTERRUPTIONS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, \n%WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR \n%OTHERWISE), PRODUCT LIABILITY, OR OTHERWISE ARISING IN ANY WAY OUT OF THE \n%USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n%\n%For information on commercial licenses, contact Rice University's Office of \n%Technology Transfer at techtran@rice.edu or (713) 348-6173\n%\n%Change History:\n% \n%Modification #1\n%Mon Aug 7 11:42:11 CDT 1995\n%Rebecca Hindman \n%Added L to function line so that it can be displayed as an output\n%\n%Change History:\n% \n%Modification #1\n%Thu Mar 2 13:07:11 CDT 2000\n%Ramesh Neelamani\n%Revamped the help file\n%\n\n\n\n", "meta": {"author": "thomaskuestner", "repo": "CS_MoCo_LAB", "sha": "a26e8e483624b2e4ee669e7a069ba9c74d2d2e4b", "save_path": "github-repos/MATLAB/thomaskuestner-CS_MoCo_LAB", "path": "github-repos/MATLAB/thomaskuestner-CS_MoCo_LAB/CS_MoCo_LAB-a26e8e483624b2e4ee669e7a069ba9c74d2d2e4b/reconstruction/matlab/CS_LAB_matlab/utils/utils_WaveletRice/mdwt.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418178895028, "lm_q2_score": 0.8006920092299293, "lm_q1q2_score": 0.7399529689793455}} {"text": "clear all, close all, clc\n\nn = 1000;\nq = n/4;\nX = zeros(n,n);\nX(q:(n/2)+q,q:(n/2)+q) = 1;\n\nsubplot(2,2,1), imshow(X); colormap gray, axis off\n\nY = imrotate(X,10,'bicubic'); % rotate 10 degrees\nY = Y - Y(1,1);\nnY = size(Y,1);\nstartind = floor((nY-n)/2);\nXrot = Y(startind:startind+n-1, startind:startind+n-1);\nsubplot(2,2,2), imshow(Xrot); colormap gray, axis off\n\n[U,S,V] = svd(X); % svd well-aligned square\n[U,S,V] = svd(Xrot); % svd rotated square\n\nsubplot(2,2,3), semilogy(diag(S),'-ko')\nylim([1.e-16 1.e4]), grid on\nset(gca,'YTick',[1.e-16 1.e-12 1.e-8 1.e-4 1. 1.e4])\nset(gca,'XTick',[0 250 500 750 1000])\n\nsubplot(2,2,4), semilogy(diag(S),'-ko')\nylim([1.e-16 1.e4]), grid on\nset(gca,'YTick',[1.e-16 1.e-12 1.e-8 1.e-4 1. 1.e4])\nset(gca,'XTick',[0 250 500 750 1000])", "meta": {"author": "dynamicslab", "repo": "databook_matlab", "sha": "d390d39d18489a4804ee87a143ae8db8a1f3010b", "save_path": "github-repos/MATLAB/dynamicslab-databook_matlab", "path": "github-repos/MATLAB/dynamicslab-databook_matlab/databook_matlab-d390d39d18489a4804ee87a143ae8db8a1f3010b/CH01/CH01_SEC07_2_production.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418199787564, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.7399529640593895}} {"text": "function h = histc2( A, edges, wtMask )\n% Multidimensional histogram count with weighted values.\n%\n% Creates a histogram h of the values in A [n x nd], with edges as\n% specified. If nd==1, that is when A is a vector, the resulting histogram\n% h is a vector of length nBins, where nBins=length(edges)-1. h(q) contains\n% the weighted count of values v in A such that edges(q) <= v < edges(q+1).\n% h(nBins) additionally contains the weighted count of values in A such\n% that v==edges(nBins+1) -- which is different then how histc treates the\n% boundary condition. Finally, h is normalized so that sum(h(:))==1.\n%\n% It usually makes sense to specify edges explicitly, especially if\n% different histograms are going to be compared. In general, edges must\n% have monotonically non-decreasing values. Also, if the exact bounds are\n% unknown then it is convenient to set the first element in edges to -inf\n% and the last to inf. If h = histc2( A, nBins, ...), edges are\n% automatically generated and have bins equally spaced between min(A) and\n% max(A). That is the edges vector is generated by:\n% edges = linspace( min(A)-eps, max(A)+eps, nBins+1 );\n%\n% If nd>1, that is when A is a 2d matrix instead of a vector, the created\n% histogram is multi-dimensional with dimensions nBins^nd, where each bin\n% h(q1,...,qnd) contains the the weighted count of vectors v in A such that\n% edges{k}(qk) <= v(k) < edges{k}(qk+1), for k=1,...,nd. Note that if nd>1\n% edges may be a cell vector where each element is a vector of edges or a\n% scalar nBins as before.\n%\n% Each value in A may optionally have an associated weight given by wtMask,\n% which should have the same number of elements as A. If not specified, the\n% default is wtMask=ones(n,1).\n%\n% USAGE\n% h = histc2( A, edges, [wtMask] )\n%\n% INPUTS\n% A - [n x nd] 2D numeric array\n% edges - quantization bounds, see above\n% wtMask - [] length [n] vector of weights\n%\n% OUTPUTS\n% h - nd histogram [nBins^nd]\n%\n% EXAMPLE - 1D histograms\n% A=filterGauss([1000 1000],[],[],0); A=A(:); n=length(A);\n% h1 = histc2( A, 25 ); figure(1); bar(h1);\n% h2 = histc2( A, 25, ones(n,1) ); figure(2); bar(h2);\n% h3 = histc2( A, 25, A ); figure(3); bar(h3);\n%\n% EXAMPLE - 2D histograms\n% A=filterGauss([1000 1000],[],[],0); A=A(:); n=length(A);\n% h=histc2( [A A], 25 ); figure(1); im(h); % decreasing along diag\n% h=histc2( [A A], 25, A ); figure(2); im(h); % constant along diag\n%\n% See also HISTC, ASSIGNTOBINS, BAR\n%\n% Piotr's Computer Vision Matlab Toolbox Version 2.0\n% Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com]\n% Licensed under the Simplified BSD License [see external/bsd.txt]\n\nif( nargin<3 ); wtMask=[]; end;\nif( ~isa(A,'double') ); A=double(A); end;\nif( ~ismatrix(A) ); error('A must be a 2 dim array'); end;\n[n,nd] = size(A);\nif( ~isempty(wtMask) && n~=numel(wtMask) )\n error( 'wtMask must have n elements (A is nxnd)' ); end\n\nif( nd==1 )\n % if nBins given instead of edges calculate edges\n if(length(edges)==1)\n edges = linspace(min(A)-eps,max(A)+eps,edges+1);\n end\n\n % create 1d histogram\n if(isempty(wtMask))\n h = histc( A, edges );\n h(end-1) = h(end-1)+h(end);\n h = h(1:end-1); h = h / sum(h);\n else\n h = histc2c( A, wtMask, edges );\n h = h / sum(h);\n end\n\nelse\n % if nBins given instead of edges calculate edges per dimension\n if( ~iscell(edges ) )\n edges=repmat({edges},[1 nd]);\n elseif( length(edges)~=nd )\n error( 'Illegal dimensions for edges' );\n end\n for i=1:length( edges );\n if(length(edges{i})==1)\n edges{i}=linspace(min(A(:,i))-eps,max(A(:,i))+eps,edges{i}+1);\n end\n end\n\n % create multidimensional histogram\n if( isempty(wtMask) ); wtMask=ones(1,n); end;\n h = histc2c( A, wtMask, edges{:} );\n h = h / sum(h(:));\nend\n\n", "meta": {"author": "pdollar", "repo": "toolbox", "sha": "e87332637bbe8e8b92dd487c87567d9628404523", "save_path": "github-repos/MATLAB/pdollar-toolbox", "path": "github-repos/MATLAB/pdollar-toolbox/toolbox-e87332637bbe8e8b92dd487c87567d9628404523/images/histc2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314738181875, "lm_q2_score": 0.8354835432479661, "lm_q1q2_score": 0.7399305217575377}} {"text": "function [E,v] = km_kpca(X,m,ktype,kpar)\n% KM_KPCA performs kernel principal component analysis (KPCA) on a data set\n% X.\n% Input:\t- X: data matrix in column format (each data point is a row)\n%\t\t\t- m: the number of principal components to return. If m is \n%\t\t\tsmaller than 1, it is interpreted as the fraction of the signal\n%\t\t\tenergy that is to be contained within the returned principal\n%\t\t\tcomponents.\n%\t\t\t- ktype: string representing kernel type.\n%\t\t\t- kpar: vector containing the kernel parameters.\n% Output:\t- E: matrix containing the principal components.\n%\t\t\t- v: array containing the eigenvalues.\n%\t\t\t- Xep: projections of Xe on principal directions\n% USAGE: [E,v] = km_kpca(X,m,ktype,kpar)\n%\n% Author: Steven Van Vaerenbergh (steven *at* gtas.dicom.unican.es), 2010.\n%\n% This file is part of the Kernel Methods Toolbox for MATLAB.\n% https://github.com/steven2358/kmbox\n\nn = size(X,1);\n\nK = km_kernel(X,X,ktype,kpar);\n[E,V] = eig(K);\nv = diag(V);\t% eigenvalues\n[v,ind] = sort(v,'descend');\nv = v(1:m);\nE = E(:,ind(1:m));\t% principal components\nfor i=1:m\n\tE(:,i) = E(:,i)/sqrt(n*v(i));\t% normalization\nend\n", "meta": {"author": "epfl-lasa", "repo": "ML_toolbox", "sha": "61cc1245a2abe0c86a737d7b48bd645b28ffebee", "save_path": "github-repos/MATLAB/epfl-lasa-ML_toolbox", "path": "github-repos/MATLAB/epfl-lasa-ML_toolbox/ML_toolbox-61cc1245a2abe0c86a737d7b48bd645b28ffebee/methods/toolboxes/kmbox/lib/km_kpca.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248123094437, "lm_q2_score": 0.7879312056025699, "lm_q1q2_score": 0.7398869524537068}} {"text": "function dz = dynamics_3_link(~,z,P) \n%DZ = DYNAMICS_3_LINK(T,Z,P)\n% \n%FUNCTION: This function computes the dynamics of a 3\n% link pendulum, and is designed to be called from ode45.\n% The model allows for arbitrary mass and inertia for each\n% link, but no friction or actuation\n% \n%INPUTS: \n% t = time. Dummy input for ode45. Not used.\n% z = [6 X nTime] matrix of states\n% P = struct of parameters\n%OUTPUTS: \n% dz = [6 X nTime] matrix of state derivatives\n% \n%NOTES:\n% This file was automatically generated by writeDynamics.m\n\ng = P.g ; %gravity\nm1 = P.m(1); % Link 1 mass\nm2 = P.m(2); % Link 2 mass\nm3 = P.m(3); % Link 3 mass\nl1 = P.l(1); % Link 1 length\nl2 = P.l(2); % Link 2 length\nl3 = P.l(3); % Link 3 length\nI1 = P.I(1); % Link 1 moment of inertia about its center of mass\nI2 = P.I(2); % Link 2 moment of inertia about its center of mass\nI3 = P.I(3); % Link 3 moment of inertia about its center of mass\nd1 = P.d(1); % Link 1 distance between center of mass and parent joint\nd2 = P.d(2); % Link 2 distance between center of mass and parent joint\nd3 = P.d(3); % Link 3 distance between center of mass and parent joint\n\nnTime = size(z,2);\ndz = zeros(size(z)); \nM = zeros(3,3,nTime);\nf = zeros(3,nTime);\n\nth1 = z(1,:); \nth2 = z(2,:); \nth3 = z(3,:); \n\ndth1 = z(4,:); \ndth2 = z(5,:); \ndth3 = z(6,:); \n\ndz(1,:) = dth1; \ndz(2,:) = dth2; \ndz(3,:) = dth3; \n\nM(1,1,:) = - I1 - d1.^2.*m1 - l1.^2.*m2 - l1.^2.*m3;\nM(1,2,:) = - d2.*l1.*m2.*cos(th1 - th2) - l1.*l2.*m3.*cos(th1 - th2);\nM(1,3,:) = -d3.*l1.*m3.*cos(th1 - th3);\nM(2,1,:) = - d2.*l1.*m2.*cos(th1 - th2) - l1.*l2.*m3.*cos(th1 - th2);\nM(2,2,:) = - I2 - d2.^2.*m2 - l2.^2.*m3;\nM(2,3,:) = -d3.*l2.*m3.*cos(th2 - th3);\nM(3,1,:) = -d3.*l1.*m3.*cos(th1 - th3);\nM(3,2,:) = -d3.*l2.*m3.*cos(th2 - th3);\nM(3,3,:) = - I3 - d3.^2.*m3;\n\nf(1,:) = - d1.*g.*m1.*cos(th1) - g.*l1.*m2.*cos(th1) - g.*l1.*m3.*cos(th1) - d2.*dth2.^2.*l1.*m2.*sin(th1 - th2) - d3.*dth3.^2.*l1.*m3.*sin(th1 - th3) - dth2.^2.*l1.*l2.*m3.*sin(th1 - th2);\nf(2,:) = d2.*dth1.^2.*l1.*m2.*sin(th1 - th2) - g.*l2.*m3.*cos(th2) - d2.*g.*m2.*cos(th2) - d3.*dth3.^2.*l2.*m3.*sin(th2 - th3) + dth1.^2.*l1.*l2.*m3.*sin(th1 - th2);\nf(3,:) = d3.*dth1.^2.*l1.*m3.*sin(th1 - th3) - d3.*g.*m3.*cos(th3) + d3.*dth2.^2.*l2.*m3.*sin(th2 - th3);\n\nfor i=1:nTime \n MM = M(:,:,i); ff = f(:,i); \n dz(4:6,i) = -MM \\ ff;\nend \n\nend \n", "meta": {"author": "MatthewPeterKelly", "repo": "dscTutorials", "sha": "e1e97a9be03ec146f88bd6ddd9e06db7ee52e242", "save_path": "github-repos/MATLAB/MatthewPeterKelly-dscTutorials", "path": "github-repos/MATLAB/MatthewPeterKelly-dscTutorials/dscTutorials-e1e97a9be03ec146f88bd6ddd9e06db7ee52e242/LagrangeMechanics/nLinkPendulum/dynamics_3_link.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248140158416, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.7398869444458489}} {"text": "function beampattern(N,d,w,steer_angle)\n% beampattern(N,d,w,steer_angle)\n% where:\n% N = NO. OF ELEMENTS\n% d = INTER-ELEMENT SPACINGS B/W ELEMENTS\n% w = WEIGHTINGS\n% steer_angle = STEERING ANGLE FOR BEAM PATTERN\n% By: Muhammad Fahad\n% 2005-MS-E-EE-38\nif nargin < 4, steer_angle = 0; end % for no steering direction\nif nargin < 3, w = 1/N*ones(1,N); end % for uniform linear arrays\nif nargin < 2, d = 1/2; end % for standard linear array\n\nn = (-(N-1)/2:(N-1)/2).'; \ntheta = pi*(-1:0.001:1);\nu = cos(theta);\nvv = exp(j*2*pi*d*n*u);\ntheta_T = steer_angle/180*pi;\nut=cos(theta_T);\nW = w.*exp(j*n*pi*cos(theta_T))';\nB = W*vv;\nB = 10*log10(abs(B).^2);\nfigure\npolardb(theta,B,-40)\nreturn", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/13864-digital-beamforming/m files/beampattern.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248225478306, "lm_q2_score": 0.7879311856832191, "lm_q1q2_score": 0.7398869418160865}} {"text": "% This function returns the oblique shock wave angle (beta) for a given\n% deflection angle (theta) in degrees and ratio of specific heats (gamma).\n% and Mach number M. Specify 0 for the weak oblique shock \n% or 1 for the strong shock.\n%\n% Syntax:\n% beta(M,theta,gamma,n) where n specifies weak or strong shock returned\n%\n% NOTE: Angles supplied and returned from this function are in DEGREES.\n%\n% Based on an analytical solution to the theta-beta-Mach relation given in\n% the following reference: Rudd, L., and Lewis, M. J., \"Comparison of\n% Shock Calculation Methods\", AIAA Journal of Aircraft, Vol. 35, No. 4,\n% July-August, 1998, pp. 647-649.\n%\n% By Chris Plumley, undergraduate, University of Maryland.\n\nfunction Beta=beta(M,theta,gamma,n)\n\ntheta=theta*pi/180; % convert to radians\nmu=asin(1/M); % Mach wave angle\nc=tan(mu)^2;\na=((gamma-1)/2+(gamma+1)*c/2)*tan(theta);\nb=((gamma+1)/2+(gamma+3)*c/2)*tan(theta);\nd=sqrt(4*(1-3*a*b)^3/((27*a^2*c+9*a*b-2)^2)-1);\nBeta=atan((b+9*a*c)/(2*(1-3*a*b))-(d*(27*a^2*c+9*a*b-2))/(6*a*(1-3*a*b))*tan(n*pi/3+1/3*atan(1/d)))*180/pi;\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/32777-theta-beta-mach-analytic-relation/beta.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9585377272885903, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.7398411072105237}} {"text": "function [y,deriv] = sums_of_squares(w,m)\n% This is a MV2DF. See MV2DF_API_DEFINITION.readme.\n% Does:\n% (i) Reshapes w to m-by-n. \n% (ii) Computes sum of squares of each of n columns. \n% (iii) Transposes to output n-vector.\n\n\nif nargin==0\n test_this();\n return;\nend\n\n\nif isempty(w)\n y = @(w)sums_of_squares(w,m);\n return;\nend\n\nif isa(w,'function_handle')\n outer = sums_of_squares([],m);\n y = compose_mv(outer,w,[]);\n return;\nend\n\n\n\nM = reshape(w,m,[]);\ny = sum(M.^2,1);\ny = y(:);\n\nderiv = @(g2) deriv_this(g2,M);\n\n\nfunction [g,hess,linear] = deriv_this(g2,M)\n\ng = 2*bsxfun(@times,M,g2.');\ng = g(:);\nlinear = false;\nhess = @(d) hess_this(d,g2,M);\n\n\nfunction [h,Jv] = hess_this(d,g2,M)\nh = deriv_this(g2,reshape(d,size(M)));\nif nargout>1\n Jv = 2*sum(reshape(d,size(M)).*M,1);\n Jv = Jv(:);\nend\n\n\nfunction test_this()\nf = sums_of_squares([],10);\ntest_MV2DF(f,randn(10*4,1));\n", "meta": {"author": "nesl", "repo": "asvspoof2019", "sha": "8b780369f7273345c22d979192119198bbf3db13", "save_path": "github-repos/MATLAB/nesl-asvspoof2019", "path": "github-repos/MATLAB/nesl-asvspoof2019/asvspoof2019-8b780369f7273345c22d979192119198bbf3db13/baseline/tDCF_v1/bosaris_toolkit.1.06/bosaris_toolkit/utility_funcs/Optimization_Toolkit/MV2DF/function_library/multivariate/sums_of_squares.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894632969137, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.7397330063379969}} {"text": "function y = wshift(type,x,p)\n%WSHIFT Shift Vector or Matrix.\n% Y = WSHIFT(TYPE,X,P) with TYPE = {1,'1','1d' or '1D'}\n% performs a P-circular shift of vector X.\n% The shift P must be an integer, positive for right to left\n% shift and negative for left to right shift.\n%\n% Y = WSHIFT(TYPE,X,P) with TYPE = {2,'2','2d' or '2D'}\n% performs a P-circular shift of matrix X.\n% The shifts P must be integers. P(1) is the shift for rows\n% and P(2) is the shift for columns.\n%\n% WSHIFT('1D',X) is equivalent to WSHIFT('1D',X,1)\n% WSHIFT('2D',X) is equivalent to WSHIFT('2D',X,[1 1])\n%\n% Example 1D:\n% x = [1 2 3 4 5]\n% wshift('1D',x,1) = [2 3 4 5 1]\n% wshift('1D',x,-1) = [5 1 2 3 4]\n%\n% Example 2D:\n% x = [1 2 3;5 6 7]\n% wshift('2D',x,[1 1]) = [6 7 5;2 3 1]\n% wshift('2D',x,[-1,0]) = [5 6 7;1 2 3]\n\n% M. Misiti, Y. Misiti, G. Oppenheim, J.M. Poggi 01-Dec-97.\n% Last Revision: 01-May-1998.\n% Copyright (c) 1995-98 by The MathWorks, Inc.\n% $Revision: 1.2 $ $Date: 1998/07/16 14:33:59 $\n\nif isempty(x) | all(p==0) , y = x; return; end\nswitch type\n case {1,'1','1d','1D'}\n if nargin<3 , p = 1; end\n L = length(x);\n p = rem(p,L);\n if p<0 , p = L+p; end\n y = x([p+1:L,1:p]);\n\n case {2,'2','2d','2D'}\n if nargin<3 , p = [1 1]; end\n S = size(x);\n p = rem(p,S);\n k = (p<0);\n p(k) = S(k)+p(k);\n y = x([p(1)+1:S(1),1:p(1)],[p(2)+1:S(2),1:p(2)]);\nend\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/25514-tp-tool/tptool/array/wshift.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677737461007, "lm_q2_score": 0.8723473630627234, "lm_q1q2_score": 0.739722451389579}} {"text": "function len = edgeLength(varargin)\n%EDGELENGTH Return length of an edge\n%\n% L = edgeLength(EDGE); \n% Returns the length of an edge, with parametric representation:\n% [x1 y1 x2 y2].\n%\n% The function also works for several edges, in this case input is a\n% N-by-4 array, containing parametric representation of each edge, and\n% output is a N-by-1 array containing length of each edge.\n%\n% See also:\n% edges2d, edgeAngle\n%\n% ---------\n%\n% author : David Legland \n% INRA - TPV URPOI - BIA IMASTE\n% created the 19/02/2004\n%\n\n% HISTORY\n% 15/04/2005 changes definition for edge, uses [x1 y1 x2 y2] instead of\n% [x0 y0 dx dy].\n\n% TODO : specify norm (euclidian, taxi, ...).\n\nif nargin == 1\n % input is an edge [X1 Y1 X2 Y2]\n edge = varargin{1};\n len = hypot(edge(:,3)-edge(:,1), edge(:,4)-edge(:,2));\n \nelseif nargin == 2\n % input are two points [X1 Y1] and [X2 Y2]\n p1 = varargin{1};\n p2 = varargin{2};\n len = hypot(p2(:,1)-p1(:,1), p2(:,2)-p1(:,2));\n \nend\n", "meta": {"author": "rpng", "repo": "lips", "sha": "a97157e586b509c9c2e3e01e64e4347f36d0b63e", "save_path": "github-repos/MATLAB/rpng-lips", "path": "github-repos/MATLAB/rpng-lips/lips-a97157e586b509c9c2e3e01e64e4347f36d0b63e/lips_matlab/matlab/functions/matGeom/geom2d/edgeLength.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9073122313857379, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7396704090121129}} {"text": "function g = std(f, varargin)\n%STD Standard deviation of a CHEBFUN3 along one variable.\n% G = STD(F) returns the standard deviation of F in the x-variable \n% (default). If F is defined on the cuboid [a, b] x [c, d] x [e, g] then\n%\n% b \n% /\n% G.^2 = 1/(b-a) | (F(x,y,z) - mean(F, 1))^2 dx\n% /\n% a\n%\n% The output G is a CHEBFUN2 object over the rectangle [c, d] x [e, g]. \n%\n% G = STD(F, FLAG, DIM) takes the standard deviation along the x, y, or\n% z directions if DIM = 1, 2, or 3, respectively. FLAG is ignored and\n% kept in this function so the syntax agrees with the Matlab STD command.\n%\n% See also CHEBFUN/STD, CHEBFUN2/STD, CHEBFUN2/STD2, CHEBFUN3/STD2 and \n% CHEBFUN3/STD3.\n\n% Copyright 2017 by The University of Oxford and The Chebfun Developers.\n% See http://www.chebfun.org/ for Chebfun information.\n\n% Empty check: \nif ( isempty(f) )\n g = chebfun2();\n return\nend\n\ndom = f.domain; \nif ( nargin < 3 )\n dim = 1; % default to std over the x-variable.\nelseif ( nargin == 3 )\n dim = varargin{ 2 }; \nelse \n error( 'CHEBFUN:CHEBFUN3:std:nargin', 'Too many input arguments.' ); \nend\n\n% std(X) = sqrt( mean( (X - mean(X) )^2 ) ).\nif ( dim == 1 ) % x-variable.\n mx = chebfun3(@(x,y,z) feval(mean(f, 1), y, z), dom);\n g = sqrt(1/(diff(dom(1:2))) * sum((f - mx).^2, 1)) ;\n \nelseif ( dim == 2 ) % y-variable.\n my = chebfun3(@(x,y,z) feval(mean(f, 2), x, z), dom);\n g = sqrt(1/(diff(dom(3:4))) * sum((f - my).^2, 2));\n \nelseif ( dim == 3 ) % z-variable.\n mz = chebfun3(@(x,y,z) feval(mean(f, 3), x, y), dom);\n g = sqrt(1/(diff(dom(5:6))) * sum((f - mz).^2, 3));\n \nelse\n error('CHEBFUN:CHEBFUN3:std:dim', ...\n 'Third argument should have value 1, 2 or 3.');\nend\n\nend\n", "meta": {"author": "chebfun", "repo": "chebfun", "sha": "8c49396a55e46ddd57a1d108c6a8f32e37536d54", "save_path": "github-repos/MATLAB/chebfun-chebfun", "path": "github-repos/MATLAB/chebfun-chebfun/chebfun-8c49396a55e46ddd57a1d108c6a8f32e37536d54/@chebfun3/std.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122138417881, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.7396704008192084}} {"text": "function M = multinomialdoublystochasticfactory(n)\n% Manifold of n-by-n doubly-stochastic matrices with positive entries.\n%\n% function M = multinomialdoublystochasticfactory(n)\n%\n% M is a Manopt manifold structure to optimize over the set of n-by-n\n% matrices with (strictly) positive entries and such that the entries of\n% each column and each row sum to one.\n%\n% Points on the manifold and tangent vectors are represented naturally as\n% matrices of size n. The Riemannian metric imposed on the manifold is the\n% Fisher metric, that is, if X is a point on the manifold and U, V are two\n% tangent vectors:\n%\n% M.inner(X, U, V) = _X = sum(sum(U.*V./X)).\n%\n% The retraction here provided is only first order. Consequently, the\n% slope test in the checkhessian tool is only valid at points X where the\n% gradient is zero. Furthermore, if some entries of X are very close to\n% zero, this may cause numerical difficulties that can also lead to a\n% failed slope test. More generally, it is important that the solution of\n% the optimization problem should have positive entries, sufficiently far\n% away from zero to avoid numerical issues.\n%\n% The file is based on developments in the research paper\n% A. Douik and B. Hassibi, \"Manifold Optimization Over the Set\n% of Doubly Stochastic Matrices: A Second-Order Geometry\"\n% ArXiv:1802.02628, 2018.\n%\n% Link to the paper: https://arxiv.org/abs/1802.02628.\n%\n% Please cite the Manopt paper as well as the research paper:\n% @Techreport{Douik2018Manifold,\n% Title = {Manifold Optimization Over the Set of Doubly Stochastic\n% Matrices: {A} Second-Order Geometry},\n% Author = {Douik, A. and Hassibi, B.},\n% Journal = {Arxiv preprint ArXiv:1802.02628},\n% Year = {2018}\n% }\n%\n% See also: multinomialsymmetricfactory multinomialfactory\n\n% This file is part of Manopt: www.manopt.org.\n% Original author: Ahmed Douik, March 6, 2018.\n% Contributors: Nicolas Boumal\n% Change log:\n%\n% Apr. 24, 2018 (AD):\n% Changed pinv() to a particular solution to the equation.\n%\n% July 24, 2018 (AD):\n% A bugfix related to the pinv() change, with effects in many places.\n%\n% Sep. 6, 2018 (NB):\n% Removed M.exp() as it was not implemented.\n%\n% Aug. 19, 2019 (AD, BM, NB):\n% Fixed typos in comments; replaced some linear solves with pcg\n% for efficiency when n is large. By default, pcg is used:\n% comments in the code indicate other possibilities and how they \n% differ. Added maxDSiters to doubly_stochastic argument.\n% The main change has been to factor out these linear solves.\n\n e = ones(n, 1);\n\n maxDSiters = 100 + 2*n;\n \n function [alpha, beta] = mylinearsolve(X, b)\n % zeta = sparse(A)\\b; % sparse might not be better perf.-wise.\n % where A = [eye(n) X ; X' eye(n)];\n %\n % For large n use the pcg solver instead of \\.\n % [zeta, ~, ~, iter] = pcg(sparse(A), b, 1e-6, 100);\n %\n % Even faster is to create a function handle\n % computing A*x (x is a given vector). \n % Make sure that A is not created, and X is only \n % passed with mylinearsolve and not A.\n [zeta, ~, ~, iter] = pcg(@mycompute, b, 1e-6, 100);\n \n function Ax = mycompute(x)\n xtop = x(1:n,1);\n xbottom = x(n+1:end,1);\n Axtop = xtop + X*xbottom;\n Axbottom = X'*xtop + xbottom;\n Ax = [Axtop; Axbottom];\n end\n \n alpha = zeta(1:n, 1);\n beta = zeta(n+1:end, 1);\n end\n\n M.name = @() sprintf('%dx%d doubly-stochastic matrices with positive entries', n, n);\n\n M.dim = @() (n-1)^2;\n\n % Fisher metric\n M.inner = @iproduct;\n function ip = iproduct(X, eta, zeta)\n ip = sum((eta(:).*zeta(:))./X(:));\n end\n\n M.norm = @(X, eta) sqrt(M.inner(X, eta, eta));\n\n M.dist = @(X, Y) error('multinomialdoublystochasticfactory.dist not implemented yet.');\n\n % The manifold is not compact as a result of the choice of the metric,\n % thus any choice here is arbitrary. This is notably used to pick\n % default values of initial and maximal trust-region radius in the\n % trustregions solver.\n M.typicaldist = @() n;\n\n % Pick a random point on the manifold\n M.rand = @random;\n function X = random()\n Z = abs(randn(n, n)); % Random point in the ambient space\n X = doubly_stochastic(Z, maxDSiters); % Projection on the Manifold\n end\n\n % Pick a random vector in the tangent space at X.\n M.randvec = @randomvec;\n function eta = randomvec(X) % A random vector in the tangent space\n % A random vector in the ambient space\n Z = randn(n, n);\n % Projection of the vector onto the tangent space\n b = [sum(Z, 2) ; sum(Z, 1)'];\n [alpha, beta] = mylinearsolve(X, b);\n eta = Z - (alpha*e' + e*beta').*X;\n % Normalizing the vector\n nrm = M.norm(X, eta);\n eta = eta / nrm;\n end\n\n % Projection of vector eta in the ambient space to the tangent space.\n M.proj = @projection; \n function etaproj = projection(X, eta) % Projection of the vector eta in the ambeint space onto the tangent space\n b = [sum(eta, 2) ; sum(eta, 1)'];\n [alpha, beta] = mylinearsolve(X, b);\n etaproj = eta - (alpha*e' + e*beta').*X;\n end\n\n M.tangent = M.proj;\n M.tangent2ambient = @(X, eta) eta;\n\n % Conversion of Euclidean to Riemannian gradient\n M.egrad2rgrad = @egrad2rgrad;\n function rgrad = egrad2rgrad(X, egrad) % projection of the euclidean gradient\n mu = (X.*egrad); \n b = [sum(mu, 2) ; sum(mu, 1)'];\n [alpha, beta] = mylinearsolve(X, b);\n rgrad = mu - (alpha*e' + e*beta').*X;\n end\n\n % First-order retraction\n M.retr = @retraction;\n function Y = retraction(X, eta, t)\n if nargin < 3\n t = 1.0;\n end\n Y = X.*exp(t*(eta./X));\n Y = doubly_stochastic(Y, maxDSiters);\n Y = max(Y, eps);\n end\n\n % Conversion of Euclidean to Riemannian Hessian\n M.ehess2rhess = @ehess2rhess;\n function rhess = ehess2rhess(X, egrad, ehess, eta)\n\n % computing the directional derivative of the Riemannian\n % gradient\n gamma = egrad.*X;\n gammadot = ehess.*X + egrad.*eta;\n \n b = [sum(gamma, 2) ; sum(gamma, 1)'];\n bdot = [sum(gammadot, 2) ; sum(gammadot, 1)'];\n [alpha, beta] = mylinearsolve(X, b);\n [alphadot, betadot] = mylinearsolve(X, bdot- [eta*beta; eta'*alpha]);\n \n S = (alpha*e' + e*beta');\n deltadot = gammadot - (alphadot*e' + e*betadot').*X- S.*eta;\n\n % projecting gamma\n delta = gamma - S.*X;\n\n % computing and projecting nabla\n nabla = deltadot - 0.5*(delta.*eta)./X;\n rhess = projection(X, nabla);\n end\n\n\n % Miscellaneous manifold functions\n M.hash = @(X) ['z' hashmd5(X(:))];\n M.lincomb = @matrixlincomb;\n M.zerovec = @(X) zeros(n, n);\n M.transp = @(X1, X2, d) projection(X2, d);\n M.vec = @(X, U) U(:);\n M.mat = @(X, u) reshape(u, n, n);\n M.vecmatareisometries = @() false;\n \nend\n", "meta": {"author": "NicolasBoumal", "repo": "manopt", "sha": "b8b54a6af8b965f7ae572972ba0d15787427744b", "save_path": "github-repos/MATLAB/NicolasBoumal-manopt", "path": "github-repos/MATLAB/NicolasBoumal-manopt/manopt-b8b54a6af8b965f7ae572972ba0d15787427744b/manopt/manifolds/multinomial/multinomialdoublystochasticfactory.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122188543453, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.7396703967596167}} {"text": "function [data clustPoints idx centers slopes lengths] = generateData( ...\n slope, ...\n slopeStd, ...\n numClusts, ...\n xClustAvgSep, ...\n yClustAvgSep, ...\n lengthAvg, ...\n lengthStd, ...\n lateralStd, ...\n totalPoints ...\n )\n% generateData Generates 2D data for clustering; data is created along \n% straight lines, which can be more or less parallel depending\n% on slopeStd argument.\n%\n% Inputs:\n% slope - Base direction of the lines on which clusters are based.\n% slopeStd - Standard deviation of the slope; used to obtain a random\n% slope variation from the normal distribution, which is\n% added to the base slope in order to obtain the final slope\n% of each cluster.\n% numClusts - Number of clusters (and therefore of lines) to generate.\n% xClustAvgSep - Average separation of line centers along the X axis.\n% yClustAvgSep - Average separation of line centers along the Y axis.\n% line centers along each dimension.\n% lengthAvg - The base length of lines on which clusters are based.\n% lengthStd - Standard deviation of line length; used to obtain a random\n% length variation from the normal distribution, which is\n% added to the base length in order to obtain the final\n% length of each line.\n% lateralStd - \"Cluster fatness\", i.e., the standard deviation of the \n% distance from each point to the respective line, in both x \n% and y directions; this distance is obtained from the \n% normal distribution.\n% totalPoints - Total points in generated data (will be \n% randomly divided among clusters).\n%\n% Output:\n% data - Matrix (totalPoints x 2) with the generated data\n% clustPoints - Vector (numClusts x 1) containing number of points in each \n% cluster\n% idx - Vector (totalPoints x 1) containing the cluster indices of \n% each point\n% centers - Matrix (numClusts x 2) containing centers from where\n% clusters were generated\n% slopes - Vector (numClusts x 1) containing the effective slopes \n% used to generate clusters\n% lengths - Vector (numClusts x 1) containing the effective lengths \n% used to generate clusters\n%\n% ----------------------------------------------------------\n% Usage example:\n%\n% [data cp idx] = generateData(1, 0.5, 5, 15, 15, 5, 1, 2, 200);\n%\n% This creates 5 clusters with a total of 200 points, with a base slope \n% of 1 (std=0.5), separated in average by 15 units in both x and y \n% directions, with average length of 5 units (std=1) and a \"fatness\" or\n% spread of 2 units.\n%\n% To take a quick look at the clusters just do:\n%\n% scatter(data(:,1), data(:,2), 8, idx);\n% ----------------------------------------------------------\n%\n% N. Fachada\n% Instituto Superior T\u00e9cnico\n% Aug 10, 2010\n% Updated: Aug 2, 2012\n\n% Make sure totalPoints >= numClusts\nif totalPoints < numClusts\n error('Number of points must be equal or larger than the number of clusters.');\nend;\n\n% Determine number of points in each cluster\nclustPoints = abs(randn(numClusts, 1));\nclustPoints = clustPoints / sum(clustPoints);\nclustPoints = round(clustPoints * totalPoints);\n\n% Make sure totalPoints is respected\nwhile sum(clustPoints) < totalPoints\n % If one point is missing add it to the smaller cluster\n [C,I] = min(clustPoints);\n clustPoints(I(1)) = C + 1;\nend;\nwhile sum(clustPoints) > totalPoints\n % If there is one extra point, remove it from larger cluster\n [C,I] = max(clustPoints);\n clustPoints(I(1)) = C - 1;\nend;\n\n% Make sure there are no empty clusters\nemptyClusts = find(clustPoints == 0);\nif ~isempty(emptyClusts)\n % If there are empty clusters...\n numEmptyClusts = size(emptyClusts, 1);\n for i=1:numEmptyClusts\n % ...get a point from the largest cluster and assign it to the\n % empty cluster\n [C,I] = max(clustPoints);\n clustPoints(I(1)) = C - 1;\n clustPoints(emptyClusts(i)) = 1;\n end;\nend;\n\n% Initialize data matrix\ndata = zeros(sum(clustPoints), 2);\n\n% Initialize idx (vector containing the cluster indices of each point)\nidx = zeros(totalPoints, 1);\n\n% Initialize lengths vector\nlengths = zeros(numClusts, 1);\n\n% Determine cluster centers\nxCenters = xClustAvgSep * numClusts * (rand(numClusts, 1) - 0.5);\nyCenters = yClustAvgSep * numClusts * (rand(numClusts, 1) - 0.5);\ncenters = [xCenters yCenters];\n\n% Determine cluster slopes\nslopes = slope + slopeStd * randn(numClusts, 1);\n\n% Create clusters\nfor i=1:numClusts\n % Determine length of line where this cluster will be based\n lengths(i) = abs(lengthAvg + lengthStd*randn);\n % Determine how many points have been assigned to previous clusters\n sumClustPoints = 0;\n if i > 1\n sumClustPoints = sum(clustPoints(1:(i - 1)));\n end;\n % Create points for this cluster\n for j=1:clustPoints(i)\n % Determine where in the line the next point will be projected\n position = lengths(i) * rand - lengths(i) / 2;\n % Determine x coordinate of point projection\n delta_x = cos(atan(slopes(i))) * position;\n % Determine y coordinate of point projection\n delta_y = delta_x * slopes(i);\n % Get point distance from line in x coordinate\n delta_x = delta_x + lateralStd * randn;\n % Get point distance from line in y coordinate\n delta_y = delta_y + lateralStd * randn;\n % Determine the actual point\n data(sumClustPoints + j, :) = [(xCenters(i) + delta_x) (yCenters(i) + delta_y)];\n end;\n % Update idx\n idx(sumClustPoints + 1 : sumClustPoints + clustPoints(i)) = i;\nend;", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/37435-generate-data-for-clustering/generateData.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122113355091, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.7396703947030129}} {"text": "function [y Bitrate MSE Stepsize QNoise]=pcm(A,fm,fs,n)\n%A=amplitute of cosine signal\n%fm=frequency of cosine signal\n%fs=sampling frequency\n%n= number of bits per sample\n%MSE=Mean Squar error, QNoise=Quantization Noise\n%Example [y Bitrate MSE Stepsize QNoise]=pcm(2,3,20,3)\n%If you have any problem or feedback please contact me @\n%%===============================================\n% NIKESH BAJAJ\n% Asst. Prof., Lovely Professional University, India\n% Almameter: Aligarh Muslim University, India\n% +919915522564, bajaj.nikkey@gmail.com\n%%===============================================\n\nt=0:1/(100*fm):1;\nx=A*cos(2*pi*fm*t);\n%---Sampling-----\nts=0:1/fs:1;\nxs=A*cos(2*pi*fm*ts);\n%xs Sampled signal\n\n%--Quantization---\nx1=xs+A;\nx1=x1/(2*A);\nL=(-1+2^n); % Levels\nx1=L*x1;\nxq=round(x1);\nr=xq/L;\nr=2*A*r;\nr=r-A;\n%r quantized signal\n\n%----Encoding---\ny=[];\nfor i=1:length(xq)\n d=dec2bin(xq(i),n);\n y=[y double(d)-48];\nend\n%Calculations\nMSE=sum((xs-r).^2)/length(x);\nBitrate=n*fs;\nStepsize=2*A/L;\nQNoise=((Stepsize)^2)/12;\n\nfigure(1)\nplot(t,x,'linewidth',2)\ntitle('Sampling')\nylabel('Amplitute')\nxlabel('Time t(in sec)')\nhold on\nstem(ts,xs,'r','linewidth',2)\nhold off\nlegend('Original Signal','Sampled Signal');\n\nfigure(2)\nstem(ts,x1,'linewidth',2)\ntitle('Quantization')\nylabel('Levels L')\nhold on\nstem(ts,xq,'r','linewidth',2)\nplot(ts,xq,'--r')\nplot(t,(x+A)*L/(2*A),'--b')\ngrid\nhold off\nlegend('Sampled Signal','Quantized Signal');\n\nfigure(3)\nstairs([y y(length(y))],'linewidth',2)\ntitle('Encoding')\nylabel('Binary Signal')\nxlabel('bits')\naxis([0 length(y) -1 2])\ngrid\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/30377-pulse-code-modulation/pcm.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122163480666, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.739670390643421}} {"text": "function v = rowNorm(A)\n%ROWNORM norm of each row\n% V = ROWNORM(A) returns the Euclidean norm of each row of A. When A is \n% an M*N matrix, the output, V, will be a M*1 vector.\n%\n% Babak taati May 4, 2005\n% revised May 19, 2009\n\nif nargin ~= 1\n error('Requires one input arguments.')\nend\n\nv = sqrt(sum(A.*A, 2));\n", "meta": {"author": "covartech", "repo": "PRT", "sha": "4305e612af048e7dbf3d9392efc7436db125b1fc", "save_path": "github-repos/MATLAB/covartech-PRT", "path": "github-repos/MATLAB/covartech-PRT/PRT-4305e612af048e7dbf3d9392efc7436db125b1fc/+prtExternal/+clickA3DPoint/rowNorm.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.880797071719777, "lm_q2_score": 0.8397339676722393, "lm_q1q2_score": 0.7396352197493382}} {"text": "function bti_test02 ( )\n\n%*****************************************************************************80\n%\n%% BTI_TEST02 tests BURGERS_TIME_INVISCID.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 24 April 2012\n%\n% Author:\n%\n% John Burkardt\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'BTI_TEST02\\n' );\n fprintf ( 1, ' Test BURGERS_TIME_INVISCID\\n' );\n\n method = 2;\n nx = 81;\n nt = 200;\n t_max = 2.0;\n bc = 4;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Method: 2, Upwind conservative.\\n' );\n fprintf ( 1, ' Initial condition: expansion\\n' );\n fprintf ( 1, ' Number of space nodes = %d\\n', nx );\n fprintf ( 1, ' Number of time steps = %d\\n', nt );\n fprintf ( 1, ' Final time T_MAX = %g\\n', t_max );\n fprintf ( 1, ' Boundary condition = %d\\n', bc );\n\n U = burgers_time_inviscid ( method, @ic_expansion, nx, nt, t_max, bc );\n\n x = linspace ( -1.0, +1.0, nx );\n\n figure ( 2 )\n\n plot ( x, U(1:50:(nt+1),:), 'Linewidth', 3 )\n grid on\n xlabel ( '<-- X -->' )\n ylabel ( '<-- U(X,T) -->' )\n title ( 'Burgers, inviscid, initial expansion, upwind conservative' )\n\n filename = 'bti_test02.png';\n print ( '-dpng', filename )\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Saved plot as \"%s\"\\n', filename );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/burgers_time_inviscid/bti_test02.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339516289534, "lm_q2_score": 0.8807970842359877, "lm_q1q2_score": 0.739635216128746}} {"text": "%% ODF Estimation from EBSD data\n%\n%%\n% In order to discuss ODF estimation from individual orientation data we\n% start by loading an EBSD data set\n\nmtexdata copper\n\nplot(ebsd,ebsd.orientations)\n\n%%\n% of copper. The orientation distribution function can now be computed by\n\nodf = calcDensity(ebsd('copper').orientations)\n\nplotSection(odf,'contourf')\nmtexColorMap LaboTeX\nmtexColorbar\n\n%%\n% The function implements the ODF\n% estimation from EBSD data in MTEX. The underlying statistical method is\n% called kernel density estimation, which can be seen as a generalized\n% histogram. To be more precise, let's $\\psi : SO(3) \\to R$ be a radially\n% symmetric, unimodal model ODF. Then the kernel density estimator for the\n% individual orientation data $o_1,o_2,\\ldots,o_M$ is defined as\n%\n% $$f(o) = \\frac{1}{M} \\sum_{i=1}^{M} \\psi(o o_i^{-1})$$\n%\n% The choice of the model ODF $\\psi$ and in particular its halfwidth has a\n% great impact in the resulting ODF. If no halfwidth is specified the\n% default halfwidth of 10 degrees is selected.\n%\n%% Automatic halfwidth selection\n%\n% MTEX includes an automatic halfwidth selection algorithm which is called\n% by the command . To work\n% properly, this algorithm needs spatially independent EBSD data as in the\n% case of this dataset of very rough EBSD measurements (only one\n% measurement per grain).\n\n% try to compute an optimal kernel\npsi = calcKernel(ebsd.orientations)\n\n%%\n% In the above example, the EBSD measurements are spatial dependent and the\n% resulting halfwidth is too small. To avoid this problem we have to perform\n% grain reconstruction first and then estimate the halfwidth from the\n% grains.\n\n% grains reconstruction\ngrains = calcGrains(ebsd);\n\n% correct for to small grains\ngrains = grains(grains.grainSize>5);\n\n% compute optimal halfwidth from the meanorientations of grains\npsi = calcKernel(grains('co').meanOrientation)\n\n% compute the ODF with the kernel psi\nodf = calcDensity(ebsd('co').orientations,'kernel',psi)\n\n\n%%\n% Once an ODF is estimated all the functionality MTEX offers for\n% and is available.\n\nh = [Miller(1,0,0,odf.CS),Miller(1,1,0,odf.CS),Miller(1,1,1,odf.CS)];\nplotPDF(odf,h,'antipodal','silent')\n\n\n%% Effect of halfwidth selection\n%\n% As mentioned above a proper halfwidth selection is crucial for ODF\n% estimation. The following simple numerical experiment illustrates the\n% dependency between the kernel halfwidth and the estimated error.\n%\n% Let's start with a model ODF and simulate some individual orientation data.\n\nmodelODF = fibreODF(Miller(1,1,1,crystalSymmetry('cubic')),xvector);\nori = discreteSample(modelODF,10000)\n\n%%\n% Next we define a list of kernel halfwidth ,\n\nhw = [1*degree, 2*degree, 4*degree, 8*degree, 16*degree, 32*degree];\n\n%%\n% estimate for each halfwidth an ODF and compare it to the original ODF.\n\ne = zeros(size(hw));\nfor i = 1:length(hw)\n \n odf = calcDensity(ori,'halfwidth',hw(i),'silent');\n e(i) = calcError(modelODF, odf);\n \nend\n\n%%\n% After visualizing the estimation error we observe that its value is large \n% either if we choose a very small or a very large halfwidth.\n% In this specific example, the optimal halfwidth seems to be about 4\n% degrees.\n\nclose all\nplot(hw/degree,e)\nxlabel('halfwidth in degree')\nylabel('esimation error')\n", "meta": {"author": "mtex-toolbox", "repo": "mtex", "sha": "f0ce46a720935e9ae8106ef919340534bca1adcb", "save_path": "github-repos/MATLAB/mtex-toolbox-mtex", "path": "github-repos/MATLAB/mtex-toolbox-mtex/mtex-f0ce46a720935e9ae8106ef919340534bca1adcb/doc/EBSDAnalysis/EBSD2ODF.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970654616711, "lm_q2_score": 0.8397339656668287, "lm_q1q2_score": 0.7396352127278344}} {"text": "% Figure 5.45 Feedback Control of Dynamic Systems, 6e \n% Franklin, Powell, Emami\n\n\nclf\nnumG=[1 0];\ndenG=[1 1 4];\nK1=0:.1:8; % K = 2 at breakin point\nK2=100;\nK=[K1 K2];\naxis('square')\nr=rlocus(numG,denG,K); % roots vs. K\nplot(r,'-'),nicegrid;\naxis([-6 2 -4 4])\nhold on\np=roots(denG); % find and plot OL poles\nz=roots(numG); % find and plot OL zeros\nplot(z(1),0,'o')\nplot(real(p(1)),imag(p(1)),'x',real(p(2)),imag(p(2)),'x')\ntitle('Fig. 5.45 Root Locus vs. K_T')\nxlabel('Re(s)')\nylabel('Im(s)')\nhold off\naxis('normal')\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/26412-feedback-control-of-dynamic-systems-6th-edition-prentice-hall-2010/fig5_45.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9099070011518829, "lm_q2_score": 0.8128673223709252, "lm_q1q2_score": 0.7396336676328894}} {"text": "function [s,lon,lat] = m_geodesic(lon1,lat1,lon2,lat2,Npoints,varargin)\n% M_GEODESIC - Compute points along geodesics of an ellipsoidal earth.\n%\n% [S,LON,LAT] = m_geodesic(lon1,lat1,lon2,lat2,Npoints,spheroid)\n%\n% lat1 = GEODETIC latitude of first point (degrees)\n% lon1 = longitude of first point (degrees)\n% lat2, lon2 = second point (degrees)\n% Npoints = number of points along geodesic\n% spheroid = (Optional) spheroid, defaults to 'wgs84'\n% S = distance in meters \n% LON,LAT = points on geodesics.\n%\n% Note that inputs can be the same size, or a mixture of scalars and matrices.\n% However, output curves will be on columns of a matrix (i.e. form of\n% inputs will not be preserved).\n%\n% See M_FDIST, M_IDIST, M_LLDIST\n\n% R. pawlowicz (rich@ocgy.ubc.ca) 10/Jan/2005\n%\n%\n% This software is provided \"as is\" without warranty of any kind. But\n% it's mine, so you can't sell it.\n\n\n\n% Do the equivalent of meshgrid-type calls to make all\n% matrix sizes match. To do this we can have no more than\n% two different numbers in any particular dimension, and one\n% of these has to be a '1'.\nallsize=[size(lon1);size(lat1);size(lon2);size(lat2)];\ni1=ones(1,size(allsize,2));\nfor k=1:size(allsize,2)\n rs=unique(allsize(:,k));\n if length(rs)==2 && rs(1)==1\n j1=i1;j1(k)=rs(2);\n if allsize(1,k)==1,lon1=repmat(lon1,j1); end\n if allsize(2,k)==1,lat1=repmat(lat1,j1); end\n if allsize(3,k)==1,lon2=repmat(lon2,j1); end\n if allsize(4,k)==1,lat2=repmat(lat2,j1); end\n elseif length(rs)>2\n error('incompatible array sizes!'); \n end\nend\n\n% Get the distances and bearings\n\n[S,A12,A21]=m_idist(lon1,lat1,lon2,lat2,varargin{:});\n\ns=[0:Npoints-1]'/(Npoints-1)*S(:)';\n\n[lon,lat]=m_fdist(lon1(:)',lat1(:)',A12(:)',s,varargin{:});\n\n\n\n", "meta": {"author": "goGPS-Project", "repo": "goGPS_MATLAB", "sha": "30644df61d2459e3347ac5f3e31b71d9f69f4b01", "save_path": "github-repos/MATLAB/goGPS-Project-goGPS_MATLAB", "path": "github-repos/MATLAB/goGPS-Project-goGPS_MATLAB/goGPS_MATLAB-30644df61d2459e3347ac5f3e31b71d9f69f4b01/source/utility/thirdParty/m_map/m_geodesic.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.909907001151883, "lm_q2_score": 0.8128673110375457, "lm_q1q2_score": 0.7396336573205682}} {"text": "% This code just simply run the SVM on the example data set \"heart_scale\",\n% which is scaled properly. The code divides the data into 2 parts\n% train: 1 to 200\n% test: 201:270\n% Then plot the results vs their true class. In order to visualize the high\n% dimensional data, we apply MDS to the 13D data and reduce the dimension\n% to 2D\n\nclear\nclc\nclose all\n\n% read the data set\n[heart_scale_label, heart_scale_inst] = libsvmread('heart_scale');\n[N,D] = size(heart_scale_inst);\n\n% Determine the train and test index\ntrainIndex = zeros(N,1); trainIndex(1:200) = 1;\ntestIndex = zeros(N,1); testIndex(201:N) = 1;\ntrainData = heart_scale_inst(trainIndex==1,:);\ntrainLabel = heart_scale_label(trainIndex==1,:);\ntestData = heart_scale_inst(testIndex==1,:);\ntestLabel = heart_scale_label(testIndex==1,:);\n\n% Train the SVM\nmodel = svmtrain(trainLabel, trainData, '-c 1 -g 0.07 -b 1');\n% Use the SVM model to classify the data\n[predict_label, accuracy, prob_values] = svmpredict(testLabel, testData, model, '-b 1'); % run the SVM model on the test data\n\n\n\n% ================================\n% ===== Showing the results ======\n% ================================\n\n% Assign color for each class\n% colorList = generateColorList(2); % This is my own way to assign the color...don't worry about it\ncolorList = prism(100);\n\n% true (ground truth) class\ntrueClassIndex = zeros(N,1);\ntrueClassIndex(heart_scale_label==1) = 1; \ntrueClassIndex(heart_scale_label==-1) = 2;\ncolorTrueClass = colorList(trueClassIndex,:);\n% result Class\nresultClassIndex = zeros(length(predict_label),1);\nresultClassIndex(predict_label==1) = 1; \nresultClassIndex(predict_label==-1) = 2;\ncolorResultClass = colorList(resultClassIndex,:);\n\n% Reduce the dimension from 13D to 2D\ndistanceMatrix = pdist(heart_scale_inst,'euclidean');\nnewCoor = mdscale(distanceMatrix,2);\n\n% Plot the whole data set\nx = newCoor(:,1);\ny = newCoor(:,2);\npatchSize = 30; %max(prob_values,[],2);\ncolorTrueClassPlot = colorTrueClass;\nfigure; scatter(x,y,patchSize,colorTrueClassPlot,'filled');\ntitle('whole data set');\n\n% Plot the test data\nx = newCoor(testIndex==1,1);\ny = newCoor(testIndex==1,2);\npatchSize = 80*max(prob_values,[],2);\ncolorTrueClassPlot = colorTrueClass(testIndex==1,:);\nfigure; hold on;\nscatter(x,y,2*patchSize,colorTrueClassPlot,'o','filled'); \nscatter(x,y,patchSize,colorResultClass,'o','filled');\n% Plot the training set\nx = newCoor(trainIndex==1,1);\ny = newCoor(trainIndex==1,2);\npatchSize = 30;\ncolorTrueClassPlot = colorTrueClass(trainIndex==1,:);\nscatter(x,y,patchSize,colorTrueClassPlot,'o');\ntitle('classification results');", "meta": {"author": "ravenxrz", "repo": "Mathematical-Modeling", "sha": "5ee2da1e45dbfd8e1ec1e827fb6d818125fcb007", "save_path": "github-repos/MATLAB/ravenxrz-Mathematical-Modeling", "path": "github-repos/MATLAB/ravenxrz-Mathematical-Modeling/Mathematical-Modeling-5ee2da1e45dbfd8e1ec1e827fb6d818125fcb007/\u6a21\u578b\u4e0e\u7b97\u6cd5\u96c6\u5408/forecast/SVM/LIBSVM_USE.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422645, "lm_q2_score": 0.8175744850834648, "lm_q1q2_score": 0.7396191996190477}} {"text": "function geometry_test0415 ( )\n\n%*****************************************************************************80\n%\n%% TEST0415 tests LINES_IMP_INT_2D.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 08 April 2009\n%\n% Author:\n%\n% John Burkardt\n%\n dim_num = 2;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TEST0415\\n' );\n fprintf ( 1, ' LINES_IMP_INT_2D finds the intersection of\\n' );\n fprintf ( 1, ' two lines written in implicit form.\\n' );\n fprintf ( 1, '\\n' );\n%\n% x + 2y - 4 = 0\n%\n a1 = 1.0;\n b1 = 2.0;\n c1 = -4.0;\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Line 1 coefficients: %8f %8f %8f\\n', a1, b1, c1 );\n%\n% x - y - 1 = 0\n%\n a2 = 1.0;\n b2 = -1.0;\n c2 = -1.0;\n fprintf ( 1, ' Line 2 coefficients: %8f %8f %8f\\n', a2, b2, c2 );\n\n [ ival, p ] = lines_imp_int_2d ( a1, b1, c1, a2, b2, c2 );\n\n if ( ival == 1 )\n fprintf ( 1, ' Intersection at %8f %8f\\n', p(1:dim_num) )\n elseif ( ival == 0 )\n fprintf ( 1, ' Lines are parallel, no intersection.\\n' );\n elseif ( ival == 2 )\n fprintf ( 1, ' Lines are coincident.\\n' );\n else\n fprintf ( 1, ' Unknown return value of ival = %d\\n', ival );\n end\n%\n% 2x + 4y - 1 = 0\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Line 1 coefficients: %8f %8f %8f\\n', a1, b1, c1 );\n\n a2 = 2.0;\n b2 = +4.0;\n c2 = -1.0;\n fprintf ( 1, ' Line 2 coefficients: %8f %8f %8f\\n', a2, b2, c2 );\n\n [ ival, p ] = lines_imp_int_2d (a1, b1, c1, a2, b2, c2 );\n\n if ( ival == 1 )\n fprintf ( 1, ' Intersection at %8f %8f\\n', p(1:dim_num) );\n elseif ( ival == 0 )\n fprintf ( 1, ' Lines are parallel, no intersection.\\n' );\n elseif ( ival == 2 )\n fprintf ( 1, ' Lines are coincident.\\n' );\n else\n fprintf ( 1, ' Unknown return value of ival = %d\\n', ival );\n end\n%\n% -3x - 6y +12 = 0\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Line 1 coefficients: %8f %8f %8f\\n', a1, b1, c1 );\n\n a2 = -3.0;\n b2 = -6.0;\n c2 = +12.0;\n fprintf ( 1, ' Line 2 coefficients: %8f %8f %8f\\n', a2, b2, c2 );\n \n [ ival, p ] = lines_imp_int_2d ( a1, b1, c1, a2, b2, c2 );\n\n if ( ival == 1 )\n fprintf ( 1, ' Intersection at %8f %8f\\n', p(1:dim_num) );\n elseif ( ival == 0 )\n fprintf ( 1, ' Lines are parallel, no intersection.\\n' );\n elseif ( ival == 2 )\n fprintf ( 1, ' Lines are coincident.\\n' );\n else\n fprintf ( 1, ' Unknown return value of ival = %d\\n', ival );\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/geometry/geometry_test0415.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505376715775, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.7396191914856836}} {"text": "% Plot steady state objects\ngSS = reshape(ggSS,I,2);\ng_a = (lla(2) / (lla(1) + lla(2))) * gSS(:,1) ...\n + (lla(1) / (lla(1) + lla(2))) * gSS(:,2);\n\nfigure\nhold on\nf = bar(a / (wSS * (1 - ttau) * zAvg),g_a,'histc');\nsh=findall(gcf,'marker','*'); delete(sh);\nset(f,'FaceColor',[.03,.24,.8],'EdgeColor',[.8,.24,.03]);\nxlim([min(a / (wSS * (1 - ttau) * zAvg)) .8*max(a / (wSS * (1 - ttau) * zAvg))])\nxlabel('Net worth to average income','interpreter','latex')\nylabel('Mass of households','interpreter','latex')\ntitle('Steady State Distribution of Assets','interpreter','latex','fontsize',14)\ngrid on\nalpha(0.9)\nset(gcf,'color','w')\nhold off\n\n% Plot steady state MPCs\ntau_MPC = 1;\nJ = 2;\nN_MPC = 21;\ndt_MPC = tau_MPC / (N_MPC - 1);\n\nC_stacked = zeros(I*J,N_MPC );\nctilde = zeros(I*J,1);\nC_stacked(:,N_MPC) = 0;\n\nB = (1/dt_MPC) * speye(I*J) - A;\nc_stacked = reshape(cSS,I*J,1);\n\nfor n=N_MPC-1:-1:1\n vec = c_stacked + C_stacked(:,n+1)/dt_MPC;\n C_stacked(:,n) = B\\vec;\nend\n\nC = reshape(C_stacked(:,1),I,J);\nMPC = (C(2:I,:) - C(1:I-1,:)) ./ (aa(2:I,:) - aa(1:I-1,:));\n\nfigure\nhold on\nplot(a(2:I) / (wSS * (1 - ttau) * zAvg),MPC(:,1),'linewidth',1.5,'linestyle','-','color',[.03,.24,.8])\nplot(a(2:I) / (wSS * (1 - ttau) * zAvg),MPC(:,2),'linewidth',1.5,'linestyle','-','color',[.8,.24,.03])\nplot(a(2:I) / (wSS * (1 - ttau) * zAvg),ones(I-1,1)*MPC(.8*I-1,2),'linewidth',1.5,'linestyle','--','color','k')\nxlim([min(a(2:I) / (wSS * (1 - ttau) * zAvg)) .8*max(a / (wSS * (1 - ttau) * zAvg))])\nxlabel('Net worth to average income','interpreter','latex')\nylabel('MPC','interpreter','latex')\ntext(3,.05,'$\\leftarrow z=0 $','Fontsize',20,'interpreter','latex','Color',[.8,.24,.03]);\ntext(1,0.25,'$\\leftarrow z=1 $','Fontsize',20,'interpreter','latex','Color',[.03,.24,.8]);\nset(gcf,'color','w')\ntitle('MPCs in steady state','interpreter','latex','fontsize',14)\nalpha(0.7)\ngrid on\nhold off\ndrawnow", "meta": {"author": "gregkaplan", "repo": "phact", "sha": "4cd7ff0c013b082db9c2ca070225feaff1056123", "save_path": "github-repos/MATLAB/gregkaplan-phact", "path": "github-repos/MATLAB/gregkaplan-phact/phact-4cd7ff0c013b082db9c2ca070225feaff1056123/examples/KrusellSmith/plot_steady_state.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422645, "lm_q2_score": 0.8175744695262775, "lm_q1q2_score": 0.7396191855452299}} {"text": "function [res] = lmc(x)\n\n%LMC calculates the left medcouple, a robust measure of\n%left tail weight\n%\n% The left medcouple is described in:\n% Brys, G., Hubert, M. and Struyf, A. (2006),\n% \"Robust Measures of Tail Weight\",\n% Computational Statistics and Data Analysis,\n% 50 (No 3), 733-759. \n%\n% For the up-to-date reference, please consult the website:\n% wis.kuleuven.be/stat/robust.html\n%\n% Required input arguments:\n% x : Data matrix (rows=observations, columns=variables)\n%\n% I/O:\n% result=lmc(x);\n% \n% Example:\n% result = lmc([chi2rnd(5,1000,1) trnd(3,1000,1)]);\n%\n% The output of LMC is a vector containing the left medcouple\n% for each column of the data matrix x\n%\n% This function is part of LIBRA: the Matlab Library for Robust Analysis,\n% available at: \n% http://wis.kuleuven.be/stat/robust.html\n%\n% Written by Guy Brys\n% Last Update: 17/03/2006\n\nif (nargin<1)\n error('No input arguments')\nend\nif (size(x,1)==1)\n x = x';\nend\nfor (i=1:size(x,2))\n res(i) = -mc(x(x(:,i)<=prctile(x(:,i),50),i));\nend\n", "meta": {"author": "marianux", "repo": "ecg-kit", "sha": "c8e3de47c54a9214138143676d2aa546b0540dd2", "save_path": "github-repos/MATLAB/marianux-ecg-kit", "path": "github-repos/MATLAB/marianux-ecg-kit/ecg-kit-c8e3de47c54a9214138143676d2aa546b0540dd2/common/LIBRA/lmc.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896824119663, "lm_q2_score": 0.8031738010682209, "lm_q1q2_score": 0.739554149207219}} {"text": "function pass = test_wronskian(pref)\n\n% Choose a tolerance:\ntol = 1e-11;\n\n% Check different input styles for a simple problem:\nop = @(x,u) diff(u, 2) + (u);\nL = chebop(op, [-pi, pi]);\nx = chebfun('x', [-pi, pi]);\nw = wronskian(L, cos(x), sin(x));\npass(1) = norm(w - 1, inf) < tol;\nw = wronskian(L, [cos(x), sin(x)]);\npass(2) = norm(w - 1, inf) < tol;\nw = wronskian(L, chebmatrix({cos(x), sin(x)}));\npass(3) = norm(w - 1, inf) < tol;\n\n\n% A slightly harder problem:\nop = @(u) diff(u,2) + 4*diff(u) - 5*u;\ndom = [0, 5];\nL = chebop(op, dom);\nx = chebfun(@(x) x, dom);\ng = exp(x);\nf = exp(-5*x);\nw = wronskian(L, f, g);\n% Compare with the exact wronskian:\npass(4) = norm(w - 6*exp(-4*x), inf) < tol;\n\nend\n", "meta": {"author": "chebfun", "repo": "chebfun", "sha": "8c49396a55e46ddd57a1d108c6a8f32e37536d54", "save_path": "github-repos/MATLAB/chebfun-chebfun", "path": "github-repos/MATLAB/chebfun-chebfun/chebfun-8c49396a55e46ddd57a1d108c6a8f32e37536d54/tests/chebop/test_wronskian.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896758909756, "lm_q2_score": 0.8031738034238807, "lm_q1q2_score": 0.7395541461387972}} {"text": "\n\nfunction call_price=european_call_div(S, K, r, sigma, time_to_maturity, dividend_times, dividend_amounts)\n\n\n%--------------------------------------------------------------------------\n%\n% DESCRIPTION:\n%\n% European option price with an underlying stock paying a discrete-time\n% dividend \n%\n%\n% Reference:\n%\n% John Hull, \"Options, Futures and other Derivative Securities\",\n% Prentice-Hall, second edition, 1993.\n% \n%--------------------------------------------------------------------------\n%\n% INPUTS:\n%\n% S: spot price\n% K: exercice price\n% r: interest rate\n% y: continous payout\n% sigma: volatility\n% time_to_maturity: time to maturity\n% dividend_times: periods of dividend payment\n% dividend_amounts: amounts of dividend payment \n%\n%--------------------------------------------------------------------------\n%\n% OUTPUT:\n%\n% call_price: price of a call option\n%\n%--------------------------------------------------------------------------\n%\n% Author: Paolo Z., February 2012\n%\n%--------------------------------------------------------------------------\n\n\n\nadjusted_S = S;\n\nfor ( i=1:max(size(dividend_times)) ) \n if (dividend_times(i)<=time_to_maturity)\n adjusted_S = adjusted_S-dividend_amounts(i)*exp(-r*dividend_times(i));\n end\nend\n\ncall_price = bs_european_call(adjusted_S,K,r,sigma,time_to_maturity);\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/35351-option-pricing-package/european_call_div.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896715436482, "lm_q2_score": 0.8031738057795402, "lm_q1q2_score": 0.7395541448162047}} {"text": "function U = phi2u(phi)\n\nm = length(phi);\nk = ceil(sqrt(2*m));\nU = eye(k);\nc = cos(phi);\ns = sin(phi);\ncount = 1;\nfor i=1:k\n for j=i+1:k\n R = eye(k);\n R(i,i) = c(count);\n R(i,j) = -s(count);\n R(j,i) = s(count);\n R(j,j) = c(count);\n U = U*R;\n count = count + 1;\n end\nend\n ", "meta": {"author": "bashtage", "repo": "mfe-toolbox", "sha": "9622b6c546bc6d649fd9bf0a36a7fcd53872e04a", "save_path": "github-repos/MATLAB/bashtage-mfe-toolbox", "path": "github-repos/MATLAB/bashtage-mfe-toolbox/mfe-toolbox-9622b6c546bc6d649fd9bf0a36a7fcd53872e04a/utility/phi2u.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9207896824119663, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.7395541427000175}} {"text": "function dcor = distcorr(x,y)\n\n% This function calculates the distance correlation between x and y.\n% Reference: http://en.wikipedia.org/wiki/Distance_correlation \n% Date: 18 Jan, 2013\n% Author: Shen Liu (shen.liu@hotmail.com.au)\n\n% Check if the sizes of the inputs match\nif size(x,1) ~= size(y,1);\n error('Inputs must have the same number of rows')\nend\n\n% Delete rows containing unobserved values\nN = any([isnan(x) isnan(y)],2);\nx(N,:) = [];\ny(N,:) = [];\n\n% Calculate doubly centered distance matrices for x and y\na = pdist2(x,x);\nmcol = mean(a);\nmrow = mean(a,2);\najbar = ones(size(mrow))*mcol;\nakbar = mrow*ones(size(mcol));\nabar = mean(mean(a))*ones(size(a));\nA = a - ajbar - akbar + abar;\n\nb = pdist2(y,y);\nmcol = mean(b);\nmrow = mean(b,2);\nbjbar = ones(size(mrow))*mcol;\nbkbar = mrow*ones(size(mcol));\nbbar = mean(mean(b))*ones(size(b));\nB = b - bjbar - bkbar + bbar;\n\n% Calculate squared sample distance covariance and variances\ndcov = sum(sum(A.*B))/(size(mrow,1)^2);\n\ndvarx = sum(sum(A.*A))/(size(mrow,1)^2);\ndvary = sum(sum(B.*B))/(size(mrow,1)^2);\n\n% Calculate the distance correlation\ndcor = sqrt(dcov/sqrt(dvarx*dvary));", "meta": {"author": "goodshawn12", "repo": "REST", "sha": "e34ce521fcb36e7813357a9720072dd111edf797", "save_path": "github-repos/MATLAB/goodshawn12-REST", "path": "github-repos/MATLAB/goodshawn12-REST/REST-e34ce521fcb36e7813357a9720072dd111edf797/dependencies/BCILAB/dependencies/SIFT-private/utils/distcorr.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896802383028, "lm_q2_score": 0.8031737892899222, "lm_q1q2_score": 0.7395541366160534}} {"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%\n% In this script, we perform phase transition analysis\n% of Orthogonal matching pursuit.\n%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nclose all;\nclear all;\nclc;\nrng('default');\n% Create the directory for storing results\n[status_code,message,message_id] = mkdir('bin');\ntarget_file_path = 'bin/ra_mmv_phase_transition_snr_20db_s_4.mat';\nN = 256;\nS = 4;\npta = spx.pursuit.PhaseTransitionAnalysis(N);\npta.SNR = 20;\n\n% options for CoSaMP MMV solver\nsolver_options.RankAwareResidual = true;\nP = 2;\n\n% pta.NumTrials = 100;\ndict_model = @(M, N) spx.dict.simple.gaussian_dict(M, N);\ndata_model = @(N, K) spx.data.synthetic.SparseSignalGenerator(N, K, S).gaussian;\nrecovery_solver = @(Phi, K, y) spx.pursuit.joint.CoSaMP(Phi, K, P, solver_options).solve(y).Z;\npta.run(dict_model, data_model, recovery_solver);\npta.save_results(target_file_path);\n\n", "meta": {"author": "indigits", "repo": "sparse-plex", "sha": "43cae2978f62938d001baaa03308a2a717ee6c9b", "save_path": "github-repos/MATLAB/indigits-sparse-plex", "path": "github-repos/MATLAB/indigits-sparse-plex/sparse-plex-43cae2978f62938d001baaa03308a2a717ee6c9b/experiments/cosamp_mmv/ex_ra_mmv_phase_transition_snr_20db_s_4.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9324533088603709, "lm_q2_score": 0.793105941403651, "lm_q1q2_score": 0.7395342593386538}} {"text": "% This program illustrates various examples presented in\n% 'Advanced Mathematics and Mechanics Applications Using MATLAB'\n% 3rd Ed., CRC Press, 2003, by Howard Wilson, Louis Turcotte and\n% David Halpern. The program is executed by typing rundynam.\n% Then select the individually numbered examples. The separate\n% program modules are listed below.\n% \n% rundynam main program which calls the other modules\n% beamwave vibrating beam with initial deflection\n% beszeros zeros of integer order Bessel functions\n% circwave circular membrane with an oscillating force\n% elipmodes elliptic membrane modes by Moler's method\n% forcmove moving force on a semi-infinite string\n% rectwave rectangular membrane with an oscillating force \n% runchain falling elastic chain with one end fixed\n% runpenl pendulum with large amplitude oscillations\n% runtop spinning and nutating top motion \n% smdplot spring-mass-damper with harmonic applied force\n% stringmo vibrating string shaken at one end\n% strngwave vibrating string with initial deflection\n% trusvibs natural frequencies of a pin-connected truss", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/6558-dynamics-of-some-classical-system-models/dynamics/contents.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404096760996, "lm_q2_score": 0.7956580976404297, "lm_q1q2_score": 0.7395167882330271}} {"text": "function r = revaltrig(zz, zj, fj, wj, form)\n%REVALTRIG Evaluate rational function in trigonometric barycentric form.\n% R = REVALTRIG(ZZ, ZJ, FJ, WJ, FORM) returns R (vector of floats), the\n% values of the trigonometric barycentric rational function of form FORM\n% with support points ZJ, function values FJ, and barycentric weights WJ\n% evaluated at the points ZZ.\n%\n% See also AAATRIG, PRZTRIG, REVAL.\n\n% Copyright 2018 by The University of Oxford and The Chebfun Developers.\n% See http://www.chebfun.org/ for Chebfun information.\nm = numel(zj);\nzv = zz(:); % vectorize zz if necessary\n\n% Define basis functions\nif strcmp(form,'even')\n cst = @(x) cot(x);\nelseif strcmp(form,'odd')\n cst = @(x) csc(x);\nend\n\nCC = cst(bsxfun(@minus, zv, zj.')/2); % Cauchy matrix\nr = (CC*(wj.*fj))./(CC*wj); % vector of values\n\nif strcmp(form,'odd') \nr(isinf(real(zv/1i)) & real(zv/1i)>0) = sum(wj.*fj.*exp(-1i*zj/2))./sum(wj.*exp(-1i*zj/2));\nr(isinf(real(zv/1i)) & real(zv/1i)<0) = sum(wj.*fj.*exp(+1i*zj/2))./sum(wj.*exp(+1i*zj/2));\nelseif strcmp(form,'even')\nr(isinf(real(zv/1i))) = sum(wj.*fj)./sum(wj);\nend\n\n% Deal with NaN:\nii = find(isnan(r));\nfor jj = 1:length(ii)\n if ( isnan(zv(ii(jj))) || ~any(zv(ii(jj)) == zj) )\n % r(NaN) = NaN is fine.\n % The second case may happen if r(zv(ii)) = 0/0 at some point.\n else\n % Clean up values NaN = inf/inf at support points.\n % Find the corresponding node and set entry to correct value:\n r(ii(jj)) = fj(zv(ii(jj)) == zj);\n end\nend\n\n% Reshape to input format:\nr = reshape(r, size(zz));\n\nend % End of REVALTRIG().\n", "meta": {"author": "chebfun", "repo": "chebfun", "sha": "8c49396a55e46ddd57a1d108c6a8f32e37536d54", "save_path": "github-repos/MATLAB/chebfun-chebfun", "path": "github-repos/MATLAB/chebfun-chebfun/chebfun-8c49396a55e46ddd57a1d108c6a8f32e37536d54/revaltrig.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.912436167620237, "lm_q2_score": 0.810478913248044, "lm_q1q2_score": 0.7395102735410598}} {"text": "function Y = sne(X, d, perplexity)\n%SNE Implementation of Stochastic Neighbor Embedding\n%\n% mappedX = sne(X, no_dims, perplexity)\n%\n% Runs the Stochastic Neighbor Embedding algorithm using a Gaussian kernel \n% with fixed perplexity. The high-dimensional datapoints are specified by X. \n% The target dimensionality is specified in no_dims, and the variance of \n% the Gaussian kernel may be specified through perplexity (default = 30).\n% The function returns the embedded points in Y.\n%\n%\n\n% This file is part of the Matlab Toolbox for Dimensionality Reduction.\n% The toolbox can be obtained from http://homepage.tudelft.nl/19j49\n% You are free to use, change, or redistribute this code in any way you\n% want for non-commercial purposes. However, it is appreciated if you \n% maintain the name of the original author.\n%\n% (C) Laurens van der Maaten, Delft University of Technology\n\n\n if ~exist('d', 'var') || isempty(d)\n d = 2;\n end\n if ~exist('perplexity', 'var') || isempty(perplexity)\n perplexity = 30;\n end\n\n % Initialize some variables\n n = size(X, 1); % number of instances\n eta = .05; % learning rate\n max_iter = 2000; % maximum number of iterations\n jitter = 0.3; % initial jitter\n jitter_decay = 0.99; % jitter decay\n momentum = 0.5; % initial momentum\n final_momentum = 0.8; % final momentum\n mom_switch_iter = 750; % iteration where momentum changes\n \n % Initialize embedding coordinates randomly (close to origin)\n Y = 0.0001 * rand(n, d);\n dC = zeros(n, d);\n y_incs = zeros(n, d);\n \n % Compute Gaussian kernel for high-dimensional data representation\n P = x2p(X, perplexity, 1e-5); % use fixed perplexity\n P = max(P, eps);\n \n % Iterating loop\n for iter=1:max_iter\n\n % Compute Gaussian kernel for low-dimensional data representation\n sum_Y = sum(Y .^ 2, 2); % precomputation for pairwise distances\n Q = exp(-bsxfun(@plus, sum_Y, bsxfun(@plus, sum_Y', -2 * Y * Y')) ./ 2); % Gaussian probabilities\n Q(1:n+1:end) = 0;\n Q = Q ./ repmat(sum(Q, 2), [1 n]);\n Q = max(Q, eps);\n \n % Compute cost function between P and Q\n if ~rem(iter, 20)\n costs = sum(P .* log((P + eps) ./ (Q + eps)), 2) ./ n; % division by n corrects for # of datapoints\n cost = sum(costs);\n disp(['Iteration ' num2str(iter) ': error is ' num2str(cost)]);\n end\n \n % Compute gradient\n PQ = P - Q + P' - Q';\n for i=1:n\n dC(i,:) = sum(bsxfun(@times, bsxfun(@minus, Y(i,:), Y), PQ(i,:)'), 1);\n end\n \n % Perform the gradient search\n y_incs = momentum * y_incs - eta * dC;\n Y = Y + y_incs;\n\t\tY = Y + jitter * randn(size(Y));\n Y = bsxfun(@minus, Y, mean(Y, 1));\n \n % Reduce jitter over time and change momentum\n jitter = jitter * jitter_decay;\n if iter == mom_switch_iter\n momentum = final_momentum;\n end\n end\n ", "meta": {"author": "tobyma2020", "repo": "cluster", "sha": "c9c3706523859f8c34f9741be94fb2dd89fa4cc0", "save_path": "github-repos/MATLAB/tobyma2020-cluster", "path": "github-repos/MATLAB/tobyma2020-cluster/cluster-c9c3706523859f8c34f9741be94fb2dd89fa4cc0/dr/drtoolbox/techniques/sne.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361604769413, "lm_q2_score": 0.8104789178257654, "lm_q1q2_score": 0.7395102719284479}} {"text": "%% An example run of VBRPCA\nclear\nclc\n\n%% Create a low-rank + sparse matrix\n% Dimensions\nm = 500;\nn = 500;\nr = 25; % rank of the low-rank component\n\nA = randn(m,r);\nB = randn(r,n);\nX_true = A*B; % low rank component\n\nSparseRatio = 0.05;\nE_true = zeros(size(X_true));\nEomega = randsample(m*n, round(m*n*SparseRatio));\nE_true(Eomega) = -10+20*rand(length(Eomega),1); % sparse component\n\n% Observation\nY = X_true + E_true;\n\n% Add noise?\nsigma = 0; % no noise\n% sigma = 1e-3; % some noise\n% sigma = sqrt(1e-3); % more noise\n\nY = Y + sigma*randn(size(Y));\n\nSNR = 10*log10( sum(sum((X_true+E_true).^2)) / sum(sum((Y-X_true-E_true).^2)));\n\n\n%% Run VRBPCA\n% all options are *optional*, everything will be set automatically\n% you can modify these options to get better performance\noptions.verbose = 1;\noptions.initial_rank = 'auto'; % This sets to the maximum possible rank\n% options.initial_rank = 300; % or we can use a value. \noptions.X_true = X_true;\noptions.E_true = E_true;\noptions.inf_flag = 2; % inference flag for the sparse component\n% 1 for standard VB, 2 for MacKay. MacKay generally converges faster.\n\noptions.MAXITER = 200;\n%Estimate noise variance? (beta is inverse noise variance)\noptions.UPDATE_BETA = 1; \n% If the noise inv. variance is not to be estimated, set\n% options.UPDATE_BETA = 0; % and set beta using\n% options.beta = 1e3; \n\n% Select the optimization mode: \n% 'VB': fully Bayesian inference (default)\n% 'VB_app': fully Bayesian with covariance approximation\n% 'MAP': maximum a posteriori (covariance is set to 0)\noptions.mode = 'VB';\n% For large scale problems, set to 'VB_app'. \n% options.mode = 'VB_app';\n\n\nfprintf('Running VBRPCA...\\n')\ntic\n[X_hat, A_hat, B_hat, E_hat] = VBRPCA(Y,options);\nt_total = toc;\n\n% Results\nXerr = norm( X_hat - X_true, 'fro' ) / norm( X_true, 'fro');\nEerr = norm( E_hat - E_true, 'fro' ) / norm( E_true, 'fro');\n\nr_hat = rank(X_hat);\n% the model does not allow for \"exact\" sparsity, but only \"soft\" sparsity.\n% That is, most coefficients are almost zero (very small values), but not \n% exactly zero. If the sparse coefficients are needed, one can use\n% thresholding such as\nnonzero_E = length(find(abs(E_hat)>1e-7));\n\n% Show results\nfprintf('\\n\\n-------------------------------------------------------------------\\n')\nfprintf('Dimensions (%d, %d), true rank = %d, nonzero E elements = %d, SNR = %g\\n',m, n, r, length(Eomega), SNR);\nfprintf('low rank comp. error = %g, sparse comp. error %g, est. rank = %d,\\nnonzero E elements = %d, running time = %g\\n', Xerr, Eerr, r_hat, nonzero_E, t_total);\nfprintf('-------------------------------------------------------------------\\n')\n\n", "meta": {"author": "andrewssobral", "repo": "lrslibrary", "sha": "06d457349cb5f1fc56a583cd61af9f1d5150e3a1", "save_path": "github-repos/MATLAB/andrewssobral-lrslibrary", "path": "github-repos/MATLAB/andrewssobral-lrslibrary/lrslibrary-06d457349cb5f1fc56a583cd61af9f1d5150e3a1/algorithms/rpca/VBRPCA/RunVBRPCA.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361580958427, "lm_q2_score": 0.8104789109591832, "lm_q1q2_score": 0.7395102637332996}} {"text": "function K = Abrarov2010CPC(x,y,tau,N)\n% This is an approximation of the Voigt function within the Humlicek\n% regions 3 and 4. The approximation is one given by S.M. Abrarov et. al.\n% \"High-accurace approximation of the complex probability function by\n% Fourier expansion of exponential multiplier\" (2010).\n% x = sqrt(ln(2))*(nu - nu0)/alphaD\n% y = sqrt(ln(2))*alphaL/alphaD\n% where 'ln' denotes the natural log, nu the wavenumber, nu0 the wavenumber\n% at center, alphaD and alphaL the Doppler and Lorentzian half-width at\n% half-maximum.\n% Suggested values for N & tau are 23 and 12 respectively.\n\nif nargin == 2\n tau = 12;\n N = 23;\nend\n\nK = zeros(size(x));\na = zeros(1,N);\nfor c = 1:length(x)\n summation = 0;\n for n = 0:N\n a(n+1) = 2*sqrt(pi)/tau*exp(-(n*pi/tau)^2);\n first = ((1i*n*pi*tau+tau^2*y)*(1-exp(-(1i*n*pi+tau*y))*cos(tau*x(c))) + exp(-(1i*n*pi+tau*y))*tau^2*x(c)*sin(tau*x(c)))/(tau^2*x(c)^2 - (n*pi - 1i*tau*y)^2);\n second = ((1i*n*pi*tau-tau^2*y)*(1-exp(1i*n*pi-tau*y)*cos(tau*x(c))) - exp(1i*n*pi-tau*y)*tau^2*x(c)*sin(tau*x(c)))/(tau^2*x(c)^2 - (n*pi + 1i*tau*y)^2);\n summation = summation + a(n+1)*(first - second);\n end\n third = (y-exp(-(tau*y))*(y*cos(tau*x(c))-x(c)*sin(tau*x(c))))/(2*sqrt(pi)*(x(c)^2+y^2));\n K(c) = summation/(2*sqrt(pi)) - a(1)*third;\nend", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/29617-voigt-funtcion-approximation-humlicek-region-1/Abrarov2010CPC.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9615338068793908, "lm_q2_score": 0.7690802476562641, "lm_q1q2_score": 0.7394966583246724}} {"text": "function [xk,niter,residuals,outputData,opts] =NESTA(A,At,b,muf,delta,opts)\n% [xk,niter,residuals,outputData] =NESTA(A,At,b,muf,delta,opts)\n%\n% Solves a L1 minimization problem under a quadratic constraint using the\n% Nesterov algorithm, with continuation:\n%\n% min_x || U x ||_1 s.t. ||y - Ax||_2 <= delta\n% \n% Continuation is performed by sequentially applying Nesterov's algorithm\n% with a decreasing sequence of values of mu0 >= mu >= muf\n%\n% The primal prox-function is also adapted by accounting for a first guess\n% xplug that also tends towards x_muf \n%\n% The observation matrix A is a projector\n%\n% Inputs: A and At - measurement matrix and adjoint (either a matrix, in which\n% case At is unused, or function handles). m x n dimensions.\n% b - Observed data, a m x 1 array\n% muf - The desired value of mu at the last continuation step.\n% A smaller mu leads to higher accuracy.\n% delta - l2 error bound. This enforces how close the variable\n% must fit the observations b, i.e. || y - Ax ||_2 <= delta\n% If delta = 0, enforces y = Ax\n% Common heuristic: delta = sqrt(m + 2*sqrt(2*m))*sigma;\n% where sigma=std(noise).\n% opts -\n% This is a structure that contains additional options,\n% some of which are optional.\n% The fieldnames are case insensitive. Below\n% are the possible fieldnames:\n% \n% opts.xplug - the first guess for the primal prox-function, and\n% also the initial point for xk. By default, xplug = At(b)\n% opts.U and opts.Ut - Analysis/Synthesis operators\n% (either matrices of function handles).\n% opts.normU - if opts.U is provided, this should be norm(U)\n% otherwise it will have to be calculated (potentially\n% expensive)\n% opts.MaxIntIter - number of continuation steps.\n% default is 5\n% opts.maxiter - max number of iterations in an inner loop.\n% default is 10,000\n% opts.TolVar - tolerance for the stopping criteria\n% opts.stopTest - which stopping criteria to apply\n% opts.stopTest == 1 : stop when the relative\n% change in the objective function is less than\n% TolVar\n% opts.stopTest == 2 : stop with the l_infinity norm\n% of difference in the xk variable is less\n% than TolVar\n% opts.TypeMin - if this is 'L1' (default), then\n% minimizes a smoothed version of the l_1 norm.\n% If this is 'tv', then minimizes a smoothed\n% version of the total-variation norm.\n% The string is case insensitive.\n% opts.Verbose - if this is 0 or false, then very\n% little output is displayed. If this is 1 or true,\n% then output every iteration is displayed.\n% If this is a number p greater than 1, then\n% output is displayed every pth iteration.\n% opts.fid - if this is 1 (default), the display is\n% the usual Matlab screen. If this is the file-id\n% of a file opened with fopen, then the display\n% will be redirected to this file.\n% opts.errFcn - if this is a function handle,\n% then the program will evaluate opts.errFcn(xk)\n% at every iteration and display the result.\n% ex. opts.errFcn = @(x) norm( x - x_true )\n% opts.outFcn - if this is a function handle, \n% then then program will evaluate opts.outFcn(xk)\n% at every iteration and save the results in outputData.\n% If the result is a vector (as opposed to a scalar),\n% it should be a row vector and not a column vector.\n% ex. opts.outFcn = @(x) [norm( x - xtrue, 'inf' ),...\n% norm( x - xtrue) / norm(xtrue)]\n% opts.AAtinv - this is an experimental new option. AAtinv\n% is the inverse of AA^*. This allows the use of a \n% matrix A which is not a projection, but only\n% for the noiseless (i.e. delta = 0) case.\n% opts.USV - another experimental option. This supercedes\n% the AAtinv option, so it is recommended that you\n% do not define AAtinv. This allows the use of a matrix\n% A which is not a projection, and works for the\n% noisy ( i.e. delta > 0 ) case.\n% opts.USV should contain three fields: \n% opts.USV.U is the U from [U,S,V] = svd(A)\n% likewise, opts.USV.S and opts.USV.V are S and V\n% from svd(A). S may be a matrix or a vector.\n%\n% Outputs:\n% xk - estimate of the solution x\n% niter - number of iterations\n% residuals - first column is the residual at every step,\n% second column is the value of f_mu at every step\n% outputData - a matrix, where each row r is the output\n% from opts.outFcn, if supplied.\n% opts - the structure containing the options that were used \n%\n% Written by: Jerome Bobin, Caltech\n% Email: bobin@acm.caltech.edu\n% Created: February 2009\n% Modified (version 1.0): May 2009, Jerome Bobin and Stephen Becker, Caltech\n% Modified (version 1.1): Nov 2009, Stephen Becker, Caltech\n%\n% NESTA Version 1.1\n% See also Core_Nesterov\n\n\nif nargin < 6, opts = []; end\nif isempty(opts) && isnumeric(opts), opts = struct; end\n\n%---- Set defaults\nfid = setOpts('fid',1);\nVerbose = setOpts('Verbose',true);\nfunction printf(varargin), fprintf(fid,varargin{:}); end\nMaxIntIter = setOpts('MaxIntIter',5,1);\nTypeMin = setOpts('TypeMin','L1');\nTolVar = setOpts('tolvar',1e-5);\n[U,U_userSet] = setOpts('U', @(x) x );\nif ~isa(U,'function_handle')\n Ut = setOpts('Ut',[]);\nelse\n Ut = setOpts('Ut', @(x) x );\nend\nxplug = setOpts('xplug',[]);\nnormU = setOpts('normU',[]); % so we can tell if it's been set\n\nresiduals = []; outputData = [];\nAAtinv = setOpts('AAtinv',[]);\nUSV = setOpts('USV',[]);\nif ~isempty(USV)\n if isstruct(USV)\n Q = USV.U; % we can't use \"U\" as the variable name\n % since \"U\" already refers to the analysis operator\n S = USV.S;\n if isvector(S), s = S; %S = diag(s);\n else s = diag(S); end\n %V = USV.V;\n else\n error('opts.USV must be a structure');\n end\nend\n\n% -- We can handle non-projections IF a (fast) routine for computing\n% the psuedo-inverse is available.\n% We can handle a nonzero delta, but we need the full SVD\nif isempty(AAtinv) && isempty(USV)\n % Check if A is a partial isometry, i.e. if AA' = I\n z = randn(size(b));\n if isa(A,'function_handle'), AAtz = A(At(z));\n else AAtz = A*(A'*z); end\n if norm( AAtz - z )/norm(z) > 1e-8\n error('Measurement matrix A must be a partial isometry: AA''=I');\n end\nend\n\n% -- Find a initial guess if not already provided.\n% Use least-squares solution: x_ref = A'*inv(A*A')*b\n% If A is a projection, the least squares solution is trivial\nif isempty(xplug) || norm(xplug) < 1e-12\n if ~isempty(USV) && isempty(AAtinv)\n AAtinv = Q*diag( s.^(-2) )*Q';\n end\n if ~isempty(AAtinv)\n if delta > 0 && isempty(USV)\n error('delta must be zero for non-projections');\n end\n if isa(AAtinv,'function_handle')\n x_ref = AAtinv(b);\n else\n x_ref = AAtinv * b;\n end\n else\n x_ref = b;\n end\n \n if isa(A,'function_handle')\n x_ref=At(x_ref);\n else\n x_ref = A'*x_ref;\n end\n\n if isempty(xplug)\n xplug = x_ref;\n end\n % x_ref itself is used to calculate mu_0\n % in the case that xplug has very small norm\nelse\n x_ref = xplug;\nend\n\n% use x_ref, not xplug, to find mu_0\nif isa(U,'function_handle')\n Ux_ref = U(x_ref);\nelse\n Ux_ref = U*x_ref;\nend\nswitch lower(TypeMin)\n case 'l1'\n mu0 = 0.9*max(abs(Ux_ref));\n case 'tv'\n mu0 = ValMUTv(Ux_ref);\nend\n\n% -- If U was set by the user and normU not supplied, then calcuate norm(U)\nif U_userSet && isempty(normU)\n % simple case: U*U' = I or U'*U = I, in which case norm(U) = 1\n z = randn(size(xplug));\n if isa(U,'function_handle'), UtUz = Ut(U(z)); else UtUz = U'*(U*z); end\n if norm( UtUz - z )/norm(z) < 1e-8\n normU = 1;\n else\n z = randn(size(Ux_ref));\n if isa(U,'function_handle')\n UUtz = U(Ut(z)); \n else\n UUtz = U*(U'*z);\n end\n if norm( UUtz - z )/norm(z) < 1e-8\n normU = 1;\n end\n end\n \n if isempty(normU)\n % have to actually calculate the norm\n if isa(U,'function_handle')\n [normU,cnt] = my_normest(U,Ut,length(xplug),1e-3,30);\n if cnt == 30, printf('Warning: norm(U) may be inaccurate\\n'); end\n else\n [mU,nU] = size(U);\n if mU < nU, UU = U*U'; else UU = U'*U; end \n % last resort is to call MATLAB's \"norm\", which is slow\n if norm( UU - diag(diag(UU)),'fro') < 100*eps\n % this means the matrix is diagonal, so norm is easy:\n normU = sqrt( max(abs(diag(UU))) );\n elseif issparse(UU)\n normU = sqrt( normest(UU) );\n else\n if min(size(U)) > 2000\n % norm(randn(2000)) takes about 5 seconds on my PC\n printf('Warning: calculation of norm(U) may be slow\\n');\n end\n normU = sqrt( norm(UU) );\n end\n end\n end\n opts.normU = normU;\nend\n \n\nniter = 0;\nGamma = (muf/mu0)^(1/MaxIntIter);\nmu = mu0;\nGammat= (TolVar/0.1)^(1/MaxIntIter);\nTolVar = 0.1;\n \nfor nl=1:MaxIntIter\n \n mu = mu*Gamma;\n TolVar=TolVar*Gammat; opts.TolVar = TolVar;\n opts.xplug = xplug;\n if Verbose, printf('\\tBeginning %s Minimization; mu = %g\\n',opts.TypeMin,mu); end\n [xk,niter_int,res,out,optsOut] = Core_Nesterov(...\n A,At,b,mu,delta,opts);\n \n xplug = xk;\n niter = niter_int + niter;\n \n residuals = [residuals; res];\n outputData = [outputData; out];\n\nend\nopts = optsOut;\n\n\n%---- internal routine for setting defaults\nfunction [var,userSet] = setOpts(field,default,mn,mx)\n var = default;\n % has the option already been set?\n if ~isfield(opts,field) \n % see if there is a capitalization problem:\n names = fieldnames(opts);\n for i = 1:length(names)\n if strcmpi(names{i},field)\n opts.(field) = opts.(names{i});\n opts = rmfield(opts,names{i});\n break;\n end\n end\n end\n if isfield(opts,field) && ~isempty(opts.(field))\n var = opts.(field); % override the default\n userSet = true;\n else\n userSet = false;\n end\n % perform error checking, if desired\n if nargin >= 3 && ~isempty(mn)\n if var < mn\n printf('Variable %s is %f, should be at least %f\\n',...\n field,var,mn); error('variable out-of-bounds');\n end\n end\n if nargin >= 4 && ~isempty(mx)\n if var > mx\n printf('Variable %s is %f, should be at least %f\\n',...\n field,var,mn); error('variable out-of-bounds');\n end\n end\n opts.(field) = var;\nend\n\n\n\n\n%---- internal routine for setting mu0 in the tv minimization case\nfunction th=ValMUTv(x)\n\n N = length(x);n = floor(sqrt(N));\n Dv = spdiags([reshape([-ones(n-1,n); zeros(1,n)],N,1) ...\n reshape([zeros(1,n); ones(n-1,n)],N,1)], [0 1], N, N);\n Dh = spdiags([reshape([-ones(n,n-1) zeros(n,1)],N,1) ...\n reshape([zeros(n,1) ones(n,n-1)],N,1)], [0 n], N, N);\n D = sparse([Dh;Dv]);\n\n\n Dhx = Dh*x;\n Dvx = Dv*x;\n \n sk = sqrt(abs(Dhx).^2 + abs(Dvx).^2);\n th = max(sk);\n\nend\n\nend %-- end of NESTA function\n\n%%%%%%%%%%%% POWER METHOD TO ESTIMATE NORM %%%%%%%%%%%%%%%\n% Copied from MATLAB's \"normest\" function, but allows function handles, not just sparse matrices\nfunction [e,cnt] = my_normest(S,St,n,tol, maxiter)\n%MY_NORMEST Estimate the matrix 2-norm via power method.\n if nargin < 4, tol = 1.e-6; end\n if nargin < 5, maxiter = 20; end\n if isempty(St)\n St = S; % we assume the matrix is symmetric;\n end\n x = ones(n,1);\n cnt = 0;\n e = norm(x);\n if e == 0, return, end\n x = x/e;\n e0 = 0;\n while abs(e-e0) > tol*e && cnt < maxiter\n e0 = e;\n Sx = S(x);\n if nnz(Sx) == 0\n Sx = rand(size(Sx));\n end\n e = norm(Sx);\n x = St(Sx);\n x = x/norm(x);\n cnt = cnt+1;\n end\nend\n", "meta": {"author": "goodshawn12", "repo": "REST", "sha": "e34ce521fcb36e7813357a9720072dd111edf797", "save_path": "github-repos/MATLAB/goodshawn12-REST", "path": "github-repos/MATLAB/goodshawn12-REST/REST-e34ce521fcb36e7813357a9720072dd111edf797/dependencies/BCILAB/dependencies/NESTA-1.1/NESTA.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206791658465, "lm_q2_score": 0.819893340314393, "lm_q1q2_score": 0.7394787583399118}} {"text": "function normals = faceNormal(nodes, faces)\n%FACENORMAL Compute normal vector of faces in a 3D mesh.\n%\n% NORMALS = faceNormal(VERTICES, FACES)\n% VERTICES is a set of 3D points (as a N-by-3 array), and FACES is either\n% a N-by-3 index array or a cell array of indices. The function computes\n% the normal vector of each face.\n% The orientation of the normal is defined by the sign of cross product\n% between vectors joining vertices 1 to 2 and 1 to 3.\n%\n%\n% Example\n% [v e f] = createIcosahedron;\n% normals1 = faceNormal(v, f);\n% centros1 = faceCentroids(v, f);\n% figure; drawMesh(v, f); \n% hold on; axis equal; view(3);\n% drawVector3d(centros1, normals1);\n%\n% pts = rand(50, 3);\n% hull = minConvexHull(pts);\n% normals2 = faceNormal(pts, hull);\n%\n% See also\n% meshes3d, drawMesh, convhull, convhulln, drawVector3d\n\n% ------\n% Author: David Legland\n% e-mail: david.legland@grignon.inra.fr\n% Created: 2006-07-05\n% Copyright 2006 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas)\n\n% deprecation warning\nwarning('geom3d:deprecated', ...\n [mfilename ' is deprecated, use ''meshFaceNormals'' instead']);\n\nif isnumeric(faces)\n % compute vector of first edges\n\tv1 = nodes(faces(:,2),1:3) - nodes(faces(:,1),1:3);\n v2 = nodes(faces(:,3),1:3) - nodes(faces(:,1),1:3);\n \n% % normalize vectors\n% v1 = normalizeVector3d(v1);\n% v2 = normalizeVector3d(v2);\n \n % compute normals using cross product (nodes have same size)\n\tnormals = normalizeVector3d(cross(v1, v2, 2));\n\nelse\n % initialize empty array\n normals = zeros(length(faces), 3);\n \n for i = 1:length(faces)\n face = faces{i};\n % compute vector of first edges\n v1 = nodes(face(2),1:3) - nodes(face(1),1:3);\n v2 = nodes(face(3),1:3) - nodes(face(1),1:3);\n \n% % normalize vectors\n% v1 = normalizeVector3d(v1);\n% v2 = normalizeVector3d(v2);\n \n % compute normals using cross product\n normals(i, :) = normalizeVector3d(cross(v1, v2, 2));\n end\nend\n\n", "meta": {"author": "mattools", "repo": "matGeom", "sha": "1fd2c937064be1ee1f4fd09fbfdf96145ebe5271", "save_path": "github-repos/MATLAB/mattools-matGeom", "path": "github-repos/MATLAB/mattools-matGeom/matGeom-1fd2c937064be1ee1f4fd09fbfdf96145ebe5271/matGeom/deprecated/meshes3d/faceNormal.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206712569267, "lm_q2_score": 0.8198933381139646, "lm_q1q2_score": 0.7394787498708293}} {"text": "function [R,lambda] = linreg( X , Y , lambda )\n\n%X = [ones(size(X,1),1) X];\n\n%% method 1: soving linear regression using close-form solution %%%%%%%%%%%\n\n%R = (X'*X+eye(size(X,2))*lambda)\\X'*Y;\n\n%% method 2: using SVR in liblinear %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nfeatdim = size(X,2);\nshapedim = size(Y,2);\n\nparam = sprintf('-s 12 -p 0 -c %f -q', lambda);\n%param = sprintf('-s 12 -p 0 -c 0.3 -q');\nR_tmp = zeros( featdim, shapedim );\ntic;\nfor o = 1 : shapedim\n disp(['Training landmarks ' num2str(o)]);\n model = train(Y(:,o),sparse(X),param);\n R_tmp(:,o) = model.w';\nend\ntoc;\n\nR = R_tmp;\n\nend\n", "meta": {"author": "tntrung", "repo": "sdm_face_alignment", "sha": "f546cbb1e77b8bad971e8c5914d2ca73e0bb9b67", "save_path": "github-repos/MATLAB/tntrung-sdm_face_alignment", "path": "github-repos/MATLAB/tntrung-sdm_face_alignment/sdm_face_alignment-f546cbb1e77b8bad971e8c5914d2ca73e0bb9b67/common/regression/linreg.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9353465116437761, "lm_q2_score": 0.7905303211371898, "lm_q1q2_score": 0.7394197782243046}} {"text": "% MINIMAL_REGRESSION\n% Demonstrates automatic differentiation of a least-squares objective.\n\nrun('../../setup_autonn.m') ; % add AutoNN to the path\nrng(0) ; % set random seed\n\n\n% load simple data (4 features, 3 classes)\ns = load('fisheriris.mat') ;\ndata_x = single(s.meas.') ; % features-by-samples matrix\n[~, ~, data_y] = unique(s.species) ; % convert strings to class labels\n\n\n\n% define inputs and parameters\nx = Input() ;\ny = Input() ;\nw = Param('value', 0.01 * randn(3, 4, 'single')) ;\nb = Param('value', 0.01 * randn(3, 1, 'single')) ;\n\n% combine them using math operators, which define the prediction\nprediction = w * x + b ;\n\n% compute least-squares loss\nloss = sum(sum((prediction - y).^2)) ;\n\n% use workspace variables' names as the layers' names, and compile net\nLayer.workspaceNames() ;\nnet = Net(loss) ;\n\n\n\n% simple SGD\nlearningRate = 1e-5 ;\noutputs = zeros(1, 100) ;\n\nfor iter = 1:100\n % draw minibatch\n idx = randperm(numel(data_y), 50) ;\n \n % evaluate network to compute gradients\n net.eval({x, data_x(:,idx), y, data_y(idx)'}) ;\n \n % update weights\n net.setValue(w, net.getValue(w) - learningRate * net.getDer(w)) ;\n net.setValue(b, net.getValue(b) - learningRate * net.getDer(b)) ;\n \n % plot loss\n outputs(iter) = net.getValue(loss) ;\nend\n\nfigure(3) ;\nplot(outputs) ;\nxlabel('Iteration') ; ylabel('Loss') ;\n\nloss\nnet\n", "meta": {"author": "ShuaiBai623", "repo": "MFT", "sha": "8762f8cdf494ce0b1a1c3d431660c5c8fd91744a", "save_path": "github-repos/MATLAB/ShuaiBai623-MFT", "path": "github-repos/MATLAB/ShuaiBai623-MFT/MFT-8762f8cdf494ce0b1a1c3d431660c5c8fd91744a/external_libs/autonn/examples/minimal/minimal_regression.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465062370313, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.7394197762580904}} {"text": "function pce_burgers ( )\n\n%*****************************************************************************80\n%\n%% PCE_BURGERS applies the polynomial chaos expansion to the Burgers equation.\n%\n% Discussion:\n%\n% The time-dependent viscous Burgers equation to be solved is:\n%\n% du/dt = - d ( u*(1/2-u)) /dx + nu d2u/dx2\n%\n% with boundary conditions\n%\n% u(-3.0) = 0.0, u(+3.0) = 1.0.\n%\n% The viscosity nu is assumed to be an uncertain quantity with\n% normal distribution of known mean and variance.\n%\n% A polynomial chaos expansion is to be used, with Hermite polynomial\n% basis functions h(i,x), 0 <= i <= n.\n%\n% Because the first two Hermite polynomials are simply 1 and x, \n% we have that \n%\n% nu = nu_mean * h(0,x) + nu_variance * h(1,x).\n%\n% We replace the time derivative by an explicit Euler approximation,\n% so that the equation now describes the value of U(x,t+dt) in terms\n% of known data at time t.\n%\n% Now assume that the solution U(x,t) can be approximated\n% by the truncated expansion:\n%\n% U(x,t) = sum ( 0 <= i <= n ) c(i,t) * h(i,x)\n%\n% In the equation, we replace U by its expansion, and then multiply\n% successively by each of the basis functions h(*,x) to get a set of\n% n+1 equations that can be used to determine the values of c(i,t+dt).\n%\n% This process is repeated until the desired final time is reached.\n%\n% At any time, the coefficients c(0,t) contain information definining\n% the expected value of u(x,t) at that time, while the higher order coefficients\n% can be used to deterimine higher moments.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 16 March 2012\n%\n% Author:\n%\n% Original FORTRAN90 version by Gianluca Iaccarino.\n% This MATLAB version is by John Burkardt.\n%\n% Local parameters:\n%\n% Local, real DT, the timestep.\n%\n% Local, real DX, the spacing between grid points.\n%\n% Local, integer N, the number of intervals in the spatial domain.\n%\n% Local, real NUMEAN, the mean of viscosity.\n%\n% Local, real NUVARIANCE, the variance of viscosity.\n%\n% Local, integer P, the order of the PC expansion.\n%\n% Local, real T, the current time.\n%\n% Local, real TF, the final integration time.\n%\n% Local, real U1(N+1,P+1), the PCE representation at the current time.\n%\n% Local, real U2(N+1,P+1), the PCE representation for the next time.\n%\n% Local, real X(N+1,1), the grid points.\n%\n p = 5;\n n = 32;\n nt = 2000;\n ti = 0.0;\n tf = 2.0;\n dt = ( tf - ti ) / nt;\n numean = 0.25;\n nuvariance = 0.08;\n\n timestamp ( );\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'PCE_BURGERS\\n' );\n fprintf ( 1, ' MATLAB version\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Polynomial Chaos Expansion\\n' );\n fprintf ( 1, ' 1D Burgers equation\\n' );\n fprintf ( 1, ' Original version by Gianluca Iaccarino\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' PCE order = %d\\n', p );\n fprintf ( 1, ' Number of cells = %d\\n', n );\n fprintf ( 1, ' Time step = %g\\n', dt );\n fprintf ( 1, ' Initial time = %g\\n', ti );\n fprintf ( 1, ' Final time = %g\\n', tf );\n fprintf ( 1, ' Viscosity Mean = %g\\n', numean );\n fprintf ( 1, ' Viscosity Var = %g\\n', nuvariance );\n fprintf ( 1, '\\n' );\n%\n% Define some numerical parameters.\n%\n dx = 6.0 / n;\n conv = dt / ( 2.0 * dx );\n\n visc = zeros ( p + 1, 1 );\n visc(1) = numean * dt / ( dx * dx );\n visc(2) = nuvariance * dt / ( dx * dx );\n%\n% Define a uniform grid.\n%\n x = ( linspace ( - 3.0, + 3.0, n + 1 ) )';\n%\n% Set the initial conditions.\n%\n u1 = zeros ( n + 1, p + 1 );\n u1(1:n+1,1) = 0.5 + x(1:n+1,1) / 6.0;\n\n u2 = zeros ( n + 1, p + 1 );\n%\n% Time integration.\n%\n t1 = ti;\n%\n% Write the current solution.\n%\n output_filename = 'burgers.history.txt';\n output_unit = fopen ( output_filename, 'wt' );\n fprintf ( output_unit, '----------\\n' );\n fprintf ( output_unit, 'T = %g\\n', t1 );\n for i = 1 : n + 1\n fprintf ( output_unit, ' %10g', x(i) );\n for k = 1 : p + 1\n fprintf ( output_unit, ' %10g', u1(i,k) );\n end\n fprintf ( output_unit, '\\n' );\n end\n%\n% Time integration.\n%\n for it = 1 : nt\n\n t2 = ( ( nt - it ) * ti ...\n + ( it ) * tf ) ...\n / ( nt );\n%\n% Boundary conditions.\n%\n u2(1,1:p+1) = 0.0;\n u2(n+1,1) = 1.0;\n u2(n+1,2:p+1) = 0.0;\n\n for k = 1 : p + 1\n\n dp = he_double_product_integral ( k - 1, k - 1 );\n\n for ix = 2 : n\n%\n% Viscous term.\n%\n term1 = visc(1) * ( u1(ix+1,k) - 2.0 * u1(ix,k) + u1(ix-1,k) );\n i = 2;\n for j = 1 : p + 1\n tp = he_triple_product_integral ( i - 1, j - 1, k - 1 );\n term1 = term1 + visc(i) * ( u1(ix+1,j) - 2.0 * u1(ix,j) + u1(ix-1,j) ) * tp / dp;\n end\n%\n% Convective term.\n%\n term2 = - conv * 0.5 * ( u1(ix+1,k) - u1(ix-1,k) );\n for j = 1 : p + 1\n for i = 1 : p + 1\n tp = he_triple_product_integral ( i - 1, j - 1, k - 1 );\n term2 = term2 + ( conv * u1(ix,i) * ( u1(ix+1,j) - u1(ix-1,j) ) * tp ) / dp;\n end\n end\n\n u2(ix,k) = u1(ix,k) + term1 + term2;\n\n end\n\n end\n\n t1 = t2;\n u1(1:n+1,1:p+1) = u2(1:n+1,1:p+1);\n%\n% Print solution every 100 time steps.\n%\n if ( mod ( it, 100 ) == 0 )\n fprintf ( output_unit, '----------\\n' );\n fprintf ( output_unit, 'T = %g\\n', t1 );\n for i = 1 : n + 1\n fprintf ( output_unit, ' %10g', x(i) );\n for k = 1 : p + 1\n fprintf ( output_unit, ' %10g', u1(i,k) );\n end\n fprintf ( output_unit, '\\n' );\n end\n end\n\n end\n\n fclose ( output_unit );\n fprintf ( 1, ' Time history in \"%s\".\\n', output_filename );\n%\n% Compute the mean and variance.\n%\n umean(1:n+1,1) = u1(1:n+1,1);\n\n uvariance = zeros ( n + 1, 1 );\n\n for i = 1 : n + 1\n for j = 2 : p + 1\n dp = he_double_product_integral ( j - 1, j - 1 );\n uvariance(i) = uvariance(i) + u1(i,j).^2 * dp;\n end\n end\n%\n% Save the solution at the final time.\n%\n output_filename = 'burgers.moments.txt';\n output_unit = fopen ( output_filename, 'wt' );\n fprintf ( output_unit, ' X E[U] Var[U]\\n' );\n for i = 1 : n + 1\n fprintf ( output_unit, ' %18.8g %18.8g %18.8g\\n', ...\n x(i), umean(i), uvariance(i) );\n end\n fclose ( output_unit );\n fprintf ( 1, ' Moments in \"%s\".\\n', output_filename );\n\n output_filename = 'burgers.modes.txt';\n output_unit = fopen ( output_filename, 'wt' );\n fprintf ( output_unit, ' X U_0 ... U_P \\n' );\n for i = 1 : n + 1\n fprintf ( output_unit, ' %10g', x(i) );\n for k = 1 : p + 1\n fprintf ( output_unit, ' %10g', u1(i,k) );\n end\n fprintf ( output_unit, '\\n' );\n end\n fclose ( output_unit );\n fprintf ( 1, ' Final modes in \"%s\".\\n', output_filename );\n%\n% Terminate.\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'PCE_BURGERS:\\n' );\n fprintf ( 1, ' Normal end of execution.\\n' );\n fprintf ( 1, '\\n' );\n timestamp ( );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/pce_burgers/pce_burgers.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037241905732, "lm_q2_score": 0.7981867801399695, "lm_q1q2_score": 0.7393633870433359}} {"text": "function [X,Y,Z]=cone0(z,t,p) \n% [X,Y,Z]=cone0 defines a non-orthogonal\n% coordinate system using a conical surface\n% with a planar base\nX=z.*tan(t).*cos(p); Y=z.*tan(t).*sin(p); Z=z;", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/15903-curvilinear-coordinates/cc/cone0.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9579122708828602, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.7393583628085344}} {"text": "% book : Signals and Systems Laboratory with MATLAB \n% authors : Alex Palamides & Anastasia Veloni\n%\n% \n% z-Transform properties\n\n\n%linearity \n\nsyms n z\n\nx1=n^2;\nx2=2^n;\na1=3;\na2=4;\n\nLe=a1*x1+a2*x2;\nLeft=ztrans(Le,z)\n\nX1=ztrans(x1);\nX2=ztrans(x2);\nRight=a1*X1+a2*X2\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/28762-signals-and-systems-laboratory-with-matlab-m-files/M-FILES/10/c105a.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.88720460564669, "lm_q2_score": 0.8333246015211008, "lm_q1q2_score": 0.7393294244682133}} {"text": "%% Introduction to Genetic Algorithms\n% Oren Rosen\n% The MathWorks\n% 11/7/2007\n%\n% This script is for a brief introduction to the MATLAB environment\n% and to introduce the concept of Genetic Algorithms using Rastrigin's\n% function.\n\n%% Intro to MATLAB 1\nx = 2;\ny = 3;\nz = ras([x,y])\n\n%% Intro to MATLAB 2\nx = -5:5\n\n%% Define x and y vectors that sample the interval [-5,5]\nx = -5:0.1:5;\ny = -5:0.1:5;\n\n%% Evaluate Rastrigin's function\n% allcomb creates all combinations of elements in x,y\nallcomb(x,y)\n\nz = ras(allcomb(x,y));\n\n%% Reshape resulting vector into a grid format\nz = reshape(z,length(x),length(y));\n\n%% Visualize the surface\nsurf(x,y,z);\ncontourf(x,y,z);\n\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/18126-mathworks-webinar-using-genetic-algorithms-in-financial-applications/UsingGeneticAlgorithmsInFinancialApplications/WhatAreGeneticAlgorithms/Script.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9149009549929797, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.7393014653779392}} {"text": "function [OBrientest] = OBrientest(X,alpha)\n%O'Brien's Test for Homogeneity of Variances.\n%[In the Obrien's test the data are transforming to \n%yij = ((nj-1.5)*nj*((xij-mean(xj))**2)-((0.5)*(var(xj))*(nj-1)))/((nj-1)*(nj-2))\n%and uses the F distribution performing an one-way ANOVA using y as the \n%dependent variable (O'Brien, 1979)].\n%\n% Syntax: function [OBrientest] = OBrientest(X,alpha) \n% \n% Inputs:\n% X - data matrix (Size of matrix must be n-by-2; data=column 1, sample=column 2). \n% alpha - significance level (default = 0.05).\n% Outputs:\n% - Sample variances vector.\n% - Whether or not the homoscedasticity was met.\n%\n% Example: From the example 10.1 of Zar (1999, p.180), to test the O'Brien's\n% homoscedasticity of data with a significance level = 0.05.\n%\n% Diet\n% ---------------------------------\n% 1 2 3 4\n% ---------------------------------\n% 60.8 68.7 102.6 87.9\n% 57.0 67.7 102.1 84.2\n% 65.0 74.0 100.2 83.1\n% 58.6 66.3 96.5 85.7\n% 61.7 69.8 90.3\n% ---------------------------------\n% \n% Data matrix must be:\n% X=[60.8 1;57.0 1;65.0 1;58.6 1;61.7 1;68.7 2;67.7 2;74.0 2;66.3 2;69.8 2;\n% 102.6 3;102.1 3;100.2 3;96.5 3;87.9 4;84.2 4;83.1 4;85.7 4;90.3 4];\n%\n% Calling on Matlab the function: \n% OBrientest(X)\n%\n% Answer is:\n%\n% The number of samples are: 4\n%\n% ----------------------------\n% Sample Size Variance\n% ----------------------------\n% 1 5 9.3920\n% 2 5 8.5650\n% 3 4 7.6567\n% 4 5 8.3880\n% ----------------------------\n% \n% O'Brien's Test for Equality of Variances F=0.0171, df1= 3, df2=15\n% Probability associated to the F statistic = 0.9968\n% The associated probability for the F test is larger than 0.05\n% So, the assumption of homoscedasticity was met. \n%\n\n% Created by A. Trujillo-Ortiz and R. Hernandez-Walls\n% Facultad de Ciencias Marinas\n% Universidad Autonoma de Baja California\n% Apdo. Postal 453\n% Ensenada, Baja California\n% Mexico.\n% atrujo@uabc.mx\n%\n% April 18, 2003.\n%\n% To cite this file, this would be an appropriate format:\n% Trujillo-Ortiz, A. and R. Hernandez-Walls. (2003). Obrientest: O'Brien's test for \n% homogeneity of variances. A MATLAB file. [WWW document]. URL http://www.mathworks.com/\n% matlabcentral/fileexchange/loadFile.do?objectId=3335&objectType=FILE\n%\n% References:\n% \n% O'Brien, R. G. (1979), A General ANOVA Method for Robust Tests of \n% Additive Models for Variances. Journal of the American\n% Statistical Association, 74:877-880.\n% Zar, J. H. (1999), Biostatistical Analysis (2nd ed.).\n% NJ: Prentice-Hall, Englewood Cliffs. p. 180. \n%\n\nif nargin < 2,\n alpha = 0.05;\nend\n\nY=X;\nk=max(Y(:,2));\nfprintf('The number of samples are:%2i\\n\\n', k);\n\n%O'Brien Procedure.\nn=[];s2=[];Z=[];\nindice=Y(:,2);\nfor i=1:k\n Ye=find(indice==i);\n eval(['Y' num2str(i) '=Y(Ye,1);']);\n eval(['mY' num2str(i) '=mean(Y(Ye,1));']);\n eval(['n' num2str(i) '=length(Y' num2str(i) ') ;'])\n eval(['s2' num2str(i) '=(std(Y' num2str(i) ').^2) ;'])\n eval(['xn= n' num2str(i) ';'])\n eval(['xs2= s2' num2str(i) ';'])\n eval(['Z' num2str(i) '= ((n' num2str(i) ' - 1.5)*(n' num2str(i) ')*((Y' num2str(i) ' - mY' num2str(i) ').^2)-((0.5)*(s2' num2str(i) ')*(n' num2str(i) ' - 1)))/((n' num2str(i) ' - 1)*(n' num2str(i) ' - 2));']);\n eval(['x= Z' num2str(i) ';']);\n n=[n;xn];s2=[s2;xs2];Z=[Z;x];\nend\n\nfor i=1:k\n if n(i)==2\n error('Requires sample sizes greater than two. Please, redefine the data matrix.');\n end\nend\n\nY=[Z Y(:,2)];\n\nfprintf('-----------------------------\\n');\ndisp(' Sample Size Variance')\nfprintf('-----------------------------\\n');\nfor i=1:k\n fprintf(' %d %2i %.4f\\n',i,n(i),s2(i))\nend\nfprintf('-----------------------------\\n');\ndisp(' ')\n\nC=(sum(Y(:,1)))^2/length(Y(:,1)); %correction term.\nSST=sum(Y(:,1).^2)-C; %total sum of squares.\ndfT=length(Y(:,1))-1; %total degrees of freedom.\n\nindice=Y(:,2);\nfor i=1:k\n Ye=find(indice==i);\n eval(['A' num2str(i) '=Y(Ye,1);']);\nend\n\nA=[];\nfor i=1:k\n eval(['x =((sum(A' num2str(i) ').^2)/length(A' num2str(i) '));']);\n A=[A,x];\nend\n\nSSA=sum(A)-C; %sample sum of squares.\ndfA=k-1; %sample degrees of freedom.\nSSE=SST-SSA; %error sum of squares.\ndfE=dfT-dfA; %error degrees of freedom.\nMSA=SSA/dfA; %sample mean squares.\nMSE=SSE/dfE; %error mean squares.\nF=MSA/MSE; %F-statistic.\nv1=dfA;df1=v1;\nv2=dfE;df2=v2;\n\nP = 1 - fcdf(F,v1,v2); %probability associated to the F-statistic. \n\nfprintf('O''Brien''s Test for Equality of Variances F=%3.4f, df1=%2i, df2=%2i\\n', F,df1,df2);\nfprintf('Probability associated to the F statistic = %3.4f\\n', P);\n\nif P >= alpha;\n fprintf('The associated probability for the F test is equal or larger than% 3.2f\\n', alpha);\n fprintf('So, the assumption of homoscedasticity was met.\\n');\nelse\n fprintf('The associated probability for the F test is smaller than% 3.2f\\n', alpha);\n fprintf('So, the assumption of homoscedasticity was not met.\\n');\nend\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/3510-homvar/OBrientest.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009549929797, "lm_q2_score": 0.8080672112416737, "lm_q1q2_score": 0.7393014632635212}} {"text": "function point = circle3dPoint(circle, pos)\n%CIRCLE3DPOINT Coordinates of a point on a 3D circle from its position.\n%\n% output = circle3dPoint(input)\n%\n% Example\n% % Draw some points on a 3D circle\n% figure('color','w'); hold on; view(130,-10);\n% circle = [10 20 30 50 90 45 0];\n% drawCircle3d(circle)\n% % origin point\n% pos1 = 0;\n% drawPoint3d(circle3dPoint(circle, pos1), 'ro')\n% % few points regularly spaced\n% drawPoint3d(circle3dPoint(circle, 10:10:40), '+')\n% % Draw point opposite to origin\n% drawPoint3d(circle3dPoint(circle, 180), 'k*')\n% \n%\n% See also\n% circles3d, circle3dPosition\n%\n% ------\n% Author: David Legland\n% e-mail: david.legland@grignon.inra.fr\n% Created: 2011-06-21, using Matlab 7.9.0.529 (R2009b)\n% Copyright 2011 INRA - Cepia Software Platform.\n\npos=pos(:);\n\n% extract circle coordinates\nxc = circle(1);\nyc = circle(2);\nzc = circle(3);\nr = circle(4);\n\ntheta = circle(5);\nphi = circle(6);\npsi = circle(7);\n\n% convert position to angle\nt = pos * pi / 180;\n\n% compute position on base circle\nx = r * cos(t);\ny = r * sin(t);\nz = zeros(length(pos),1);\npt0 = [x y z];\n\n% compute transformation from local basis to world basis\ntrans = localToGlobal3d(xc, yc, zc, theta, phi, psi);\n\n% compute points of transformed circle\npoint = transformPoint3d(pt0, trans);\n\n", "meta": {"author": "Arrowstar", "repo": "ksptot", "sha": "2b414440d3b167ba2294f56dafce0f465c07f982", "save_path": "github-repos/MATLAB/Arrowstar-ksptot", "path": "github-repos/MATLAB/Arrowstar-ksptot/ksptot-2b414440d3b167ba2294f56dafce0f465c07f982/helper_methods/z_geom3d/geom3d/circle3dPoint.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009596336302, "lm_q2_score": 0.8080672066194945, "lm_q1q2_score": 0.7393014627846424}} {"text": "function [val,idx] = of_PCMARE(obs,sim,idx)\n% of_MARE Calculates a version of the Mean Absolute Relative Error (MARE)\n% of simulated streamflow as a percentage of the MARE of the mean \n% observed flow. Ignores time steps with negative flow values. Adds a\n% constant e of 1/100 of mean(obs) to avoid issues with zero flows \n% (Pushpalatha et al., 2012).\n\n% Copyright (C) 2019, 2021 Wouter J.M. Knoben, Luca Trotter\n% This file is part of the Modular Assessment of Rainfall-Runoff Models\n% Toolbox (MARRMoT).\n% MARRMoT is a free software (GNU GPL v3) and distributed WITHOUT ANY\n% WARRANTY. See for details.\n\n% In:\n% obs - time series of observations [nx1]\n% sim - time series of simulations [nx1]\n% idx - optional vector of indices to use for calculation, can be\n% logical vector [nx1] or numeric vector [mx1], with m <= n\n%\n% Out:\n% val - objective function value [1x1]\n% idx - vector of indices used for calculation\n\n% Pushpalatha, R.; Perrin, C.; le Moine, N. and Andr\u00e9assian V. (2012). \"A\n% review of efficiency criteria suitable for evaluating low-flow\n% simulations\". Journal of Hydrology. 420-421, 171-182. \n% doi:10.1016/j.jhydrol.2011.11.055\n\n%% Check inputs and select timesteps\nif nargin < 2\n error('Not enugh input arguments') \nend\n\nif nargin < 3; idx = []; end\n[sim, obs, idx] = check_and_select(sim, obs, idx); \n\n%% Find the constant e\nm = mean(obs);\ne = m/100;\n\n%% Apply constant and transform flows\nobs = obs+e;\nsim = sim+e;\n\n%% Calculate metric\nMARE = mean(abs((sim-obs)/obs));\nMARE_mean = mean(abs((sim-m)/m));\n\nval = MARE/MARE_mean;\nend\n", "meta": {"author": "wknoben", "repo": "MARRMoT", "sha": "442622b3fd89bdd88420e96cfc6605770202dae9", "save_path": "github-repos/MATLAB/wknoben-MARRMoT", "path": "github-repos/MATLAB/wknoben-MARRMoT/MARRMoT-442622b3fd89bdd88420e96cfc6605770202dae9/MARRMoT/Functions/Objective functions/of_PCMARE.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9149009457116781, "lm_q2_score": 0.8080672158638527, "lm_q1q2_score": 0.7393014599924416}} {"text": "function test_two ( )\n\n%*****************************************************************************80\n%\n%% TEST_TWO performs quadrature with SPINTERP.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 18 March 2013\n%\n% Author:\n%\n% John Burkardt\n%\n timestamp ( );\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TEST_TWO:\\n' );\n fprintf ( 1, ' An example of the use of SPINTERP\\n' );\n fprintf ( 1, ' for quadrature in multiple dimensions.\\n' );\n\n addpath ( '../spinterp' );\n\n m = 2;\n fprintf ( 1, ' Using spatial dimension M = %d\\n', m );\n level_max = 8;\n fprintf ( 1, ' Using maximum level LEVEL_MAX = %d\\n', level_max );\n%\n% Turn off warnings from SPINTERP that a given integral estimate is poor.\n%\n warning ( 'off', 'MATLAB:spinterp:insufficientDepth' )\n%\n% Compute the integral estimate for an increasing sequence of levels.\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Level Points Estimate Error\\n' );\n fprintf ( 1, '\\n' );\n\n for level = 0 : level_max\n%\n% Indicate that we wish to use exactly the sparse grid of level LEVEL.\n%\n options = spset ( ...\n 'MinDepth', level, ...\n 'MaxDepth', level, ...\n 'GridType', 'Chebyshev', ...\n 'FunctionArgType', 'vector' );\n%\n% Compute the sparse grid structure.\n%\n z = spvals ( @f_two, m, [], options );\n%\n% Estimate the integral.\n%\n n = z.nPoints;\n\n q = spquad ( z );\n\n exact = 1.0;\n\n e = abs ( q - exact );\n\n fprintf ( 1, ' %4d %8d %14.6g %14.6g\\n', level, n, q, e );\n\n end\n\n rmpath ( '../spinterp' )\n%\n% Terminate.\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TEST_TWO:\\n' );\n fprintf ( 1, ' Normal end of execution.\\n' );\n fprintf ( 1, '\\n' );\n timestamp ( );\n return\nend\n\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/spinterp_examples/test_two.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888302, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.7392567881359646}} {"text": "function c = p_polynomial_coefficients ( n )\n\n%*****************************************************************************80\n%\n%% P_POLYNOMIAL_COEFFICIENTS: coefficients of Legendre polynomials P(n,x).\n%\n% First terms:\n%\n% 1\n% 0 1\n% -1/2 0 3/2\n% 0 -3/2 0 5/2\n% 3/8 0 -30/8 0 35/8\n% 0 15/8 0 -70/8 0 63/8\n% -5/16 0 105/16 0 -315/16 0 231/16\n% 0 -35/16 0 315/16 0 -693/16 0 429/16\n%\n% 1.00000\n% 0.00000 1.00000\n% -0.50000 0.00000 1.50000\n% 0.00000 -1.50000 0.00000 2.5000\n% 0.37500 0.00000 -3.75000 0.00000 4.37500\n% 0.00000 1.87500 0.00000 -8.75000 0.00000 7.87500\n% -0.31250 0.00000 6.56250 0.00000 -19.6875 0.00000 14.4375\n% 0.00000 -2.1875 0.00000 19.6875 0.00000 -43.3215 0.00000 26.8125\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 28 July 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Milton Abramowitz and Irene Stegun,\n% Handbook of Mathematical Functions,\n% US Department of Commerce, 1964.\n%\n% Daniel Zwillinger, editor,\n% CRC Standard Mathematical Tables and Formulae,\n% 30th Edition,\n% CRC Press, 1996.\n%\n% Parameters:\n%\n% Input, integer N, the highest order polynomial to evaluate.\n% Note that polynomials 0 through N will be evaluated.\n%\n% Output, real C(1:N+1,1:N+1), the coefficients of the Legendre polynomials \n% of degree 0 through N. Each polynomial is stored as a row.\n%\n if ( n < 0 )\n c = [];\n return\n end\n\n c(1:n+1,1:n+1) = 0.0;\n\n c(1,1) = 1.0;\n\n if ( n <= 0 )\n return\n end\n\n c(2,2) = 1.0;\n \n for i = 2 : n\n c(i+1,1:i-1) = ( - i + 1 ) * c(i-1,1:i-1) / ( i );\n c(i+1,2:i+1) = c(i+1,2:i+1) + ( i + i - 1 ) * c(i ,1:i ) / ( i );\n end\n \n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/legendre_polynomial/p_polynomial_coefficients.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110339361275, "lm_q2_score": 0.8289388019824946, "lm_q1q2_score": 0.7392567700657834}} {"text": "function p = predict(theta, X)\n%PREDICT Predict whether the label is 0 or 1 using learned logistic \n%regression parameters theta\n% p = PREDICT(theta, X) computes the predictions for X using a \n% threshold at 0.5 (i.e., if sigmoid(theta'*x) >= 0.5, predict 1)\n\nm = size(X, 1); % Number of training examples\n\n% You need to return the following variables correctly\np = zeros(m, 1);\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Complete the following code to make predictions using\n% your learned logistic regression parameters. \n% You should set p to a vector of 0's and 1's\n%\n\nprob = sigmoid(X * theta);\npos = find(prob >= 0.5);\np(pos,1) = 1;\n\n\n\n% =========================================================================\n\n\nend\n", "meta": {"author": "scruel", "repo": "Notes-ML-AndrewNg", "sha": "916852d35684dcc77047ed861650aca36b62b98d", "save_path": "github-repos/MATLAB/scruel-Notes-ML-AndrewNg", "path": "github-repos/MATLAB/scruel-Notes-ML-AndrewNg/Notes-ML-AndrewNg-916852d35684dcc77047ed861650aca36b62b98d/assignments/machine-learning-ex2/ex2/predict.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8991213880824791, "lm_q2_score": 0.8221891239865619, "lm_q1q2_score": 0.739247826425115}} {"text": "function [ x, w ] = rule_adjust ( a, b, c, d, n, x, w )\n\n%*****************************************************************************80\n%\n%% RULE_ADJUST maps a quadrature rule from [A,B] to [C,D].\n%\n% Discussion:\n%\n% Most quadrature rules are defined on a special interval, like\n% [-1,1] or [0,1]. To integrate over an interval, the abscissas\n% and weights must be adjusted. This can be done on the fly,\n% or by calling this routine.\n%\n% If the weight function W(X) is not 1, then the W vector will\n% require further adjustment by the user.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 12 October 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real A, B, the endpoints of the definition interval.\n%\n% Input, real C, D, the endpoints of the integration interval.\n%\n% Input, integer N, the number of abscissas and weights.\n%\n% Input, real X(N), the abscissas.\n%\n% Input, real W(N), the weights.\n%\n% Output, real X(N), the adjusted abscissas.\n%\n% Output, real W(N), the adjusted weights.\n%\n x(1:n) = ( ( b - x(1:n) ) * c ...\n + ( x(1:n) - a ) * d ) ...\n / ( b - a );\n\n w(1:n) = ( ( d - c ) / ( b - a ) ) * w(1:n);\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/quadrule/rule_adjust.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762114, "lm_q2_score": 0.8221891283434876, "lm_q1q2_score": 0.7392478258975456}} {"text": "% KM_DEMO_KPCA_U Kernel principal component analysis (KPCA) on a U-shaped\n% two-dimensional data set. \n%\n% This program implements the example shown in Figure 2.4 of \"Kernel\n% Methods for Nonlinear Identification, Equalization and Separation of\n% Signals\", Ph.D. dissertation by S. Van Vaerenbergh.\n%\n% Author: Steven Van Vaerenbergh (steven *at* gtas.dicom.unican.es), 2010.\n%\n% This file is part of the Kernel Methods Toolbox for MATLAB.\n% https://github.com/steven2358/kmbox\n\nclose all\nclear\n\n%% PARAMETERS\n\nN_split = [30, 30, 60];\t\t% number of data points in 2 straight parts and curve of \"U\"\ncorners = [3 4 2 4];\t% corners: x1 x2 y1 y2\nnvar = 0.05;\t% noise variance\n\nkernel.type = 'gauss';\nkernel.par = .5;\nnumeig = 4;\t% number of eigenvalues to plot\n\nNtest = [50,50];\t% number of test grid divisions, in each dimension\nborder = [0 6 0 6];\t% test grid border\n \n%% PROGRAM\ntic\n\n%% generate data\nN = sum(N_split);\nN1 = N_split(1); N2 = N_split(2); N3 = N_split(3);\n\nX1 = [linspace(corners(1),corners(2),N1)' repmat(corners(3),N1,1)];\t% lower straight part\nX2 = [linspace(corners(1),corners(2),N2)' repmat(corners(4),N2,1)];\t% upper straight part\n\nangles = linspace(pi/2,3*pi/2,N3)';\nrad = (corners(4)-corners(3))/2;\nm3 = [corners(1) corners(3)+rad];\nX3 = repmat(m3,N3,1) + rad*[cos(angles) sin(angles)];\n\nn = nvar*randn(N,2);\nX = [X1; X2; X3] + n;\n\n%% generate test grid data\nNt1 = Ntest(1); Nt2 = Ntest(2);\nXtest = zeros(Nt1*Nt2,2);\nabsc = linspace(border(1),border(2),Nt1);\nordi = linspace(border(3),border(4),Nt2);\nfor i=1:Nt1,\n\tfor j=1:Nt2,\n\t\tXtest((i-1)*Nt2+j,:) = [absc(i) ordi(j)];\n\tend\nend\n\n%% calculate kernel principal components and projections of Xtest\n[E,v] = km_kpca(X,numeig,kernel.type,kernel.par);\n\nKt = km_kernel(X,Xtest,kernel.type,kernel.par);\t% kernels of test data set\nXtestp = E'*Kt;\t % projections of test data set on the principal directions\n\nY = cell(numeig,1);\nfor i=1:numeig,\n \tY{i} = reshape(Xtestp(i,:),Nt2,Nt1);\t% shape into 2D grid\nend\n\ntoc\n%% OUTPUT\n\nfigure;\nplot(X(:,1),X(:,2),'.')\naxis(border)\n\n% fireworks!\nfor i=1:numeig,\n\tfigure; hold on\n\t[C,h] = contourf(-interp2(Y{i},2),25);\n\tplot(X(:,1)/border(2)*(Nt1*4-1)+1,X(:,2)/border(4)*(Nt2*4-1)+1,'o',...\n\t\t'MarkerFaceColor','White','MarkerEdgeColor','Black')\n\tset(gca, 'XTick', [])\n\tset(gca, 'YTick', [])\nend\n", "meta": {"author": "epfl-lasa", "repo": "ML_toolbox", "sha": "61cc1245a2abe0c86a737d7b48bd645b28ffebee", "save_path": "github-repos/MATLAB/epfl-lasa-ML_toolbox", "path": "github-repos/MATLAB/epfl-lasa-ML_toolbox/ML_toolbox-61cc1245a2abe0c86a737d7b48bd645b28ffebee/methods/toolboxes/kmbox/demo/km_demo_kpca_u.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636754, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.7392478248424058}} {"text": "function [ x, error_norm, iter, flag ] = sor ( A, x, b, w, max_it, tol )\n\n%*****************************************************************************80\n%\n%% SOR solves the linear system Ax=b using the Successive Over-Relaxation Method. \n%\n% Discussion:\n%\n% When the parameter W\n% is set to 1, this is equivalent to the Gauss-Seidel iteration.\n%\n% Reference:\n%\n% Richard Barrett, Michael Berry, Tony Chan, James Demmel,\n% June Donato, Jack Dongarra, Victor Eijkhout, Roidan Pozo,\n% Charles Romine, Henk van der Vorst\n% Templates for the Solution of Linear Systems: Building Blocks for \n% Iterative Methods, \n% SIAM Publications, 1993.\n%\n% Parameters:\n%\n% Input, real A(N,N), the symmetric positive definite matrix.\n%\n% Input, real X(N), the initial guess vector.\n%\n% Input, real B(N), the right hand side vector.\n%\n% Input, real W, the relaxation scalar, between 0 and 2.\n%\n% Input, integer MAX_IT, the maximum number of iterations.\n%\n% Input, real TOL, an error tolerance.\n%\n% Output, real X(N), the solution.\n%\n% Output, real ERROR_NORM, the norm of the error.\n%\n% Output, integer ITER, the number of iterations performed.\n%\n% Output, integer FLAG, the return flag.\n% 0 = the solution was found to within the specified tolerance.\n% 1 = a satisfactory solution was not found. The iteration limit\n% was exceeded.\n%\n\n%\n% Initialization.\n%\n flag = 1;\n iter = 0;\n\n bnrm2 = norm ( b );\n if ( bnrm2 == 0.0 )\n bnrm2 = 1.0\n end\n\n r = b - A * x;\n error_norm = norm ( r ) / bnrm2;\n errorhist = [ ];\n errorhist(1) = error_norm;\n\n if ( error_norm < tol )\n flag = 0;\n return\n end\n%\n% Split the matrix.\n%\n [ M, N, b ] = split ( A, b, w, 2 );\n\n for iter = 1 : max_it\n\n x_1 = x;\n%\n% Update the approximation.\n%\n x = M \\ ( N * x + b );\n%\n% Compute the error.\n%\n error_norm = norm ( x - x_1 ) / norm ( x );\n errorhist(iter+1) = error_norm;\n%\n% Check for convergence.\n%\n if ( error_norm <= tol )\n flag = 0;\n break \n end\n\n end\n%\n% Restore the right hand side.\n%\n b = b / w;\n\n error_norm = errorhist;\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/templates/sor.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.882427872638409, "lm_q2_score": 0.8376199653600372, "lm_q1q2_score": 0.7391392041121155}} {"text": "function [expr morder] = sim_ex_Schelter_2009_3_1(varargin)\n% Simulation: Schelter 2009 Eq 3.1\n%\n% Description: \n% \n% 5-variate VAR[3] system of coupled oscillators. \n% This system was first described in [1].\n% \n% The directed graph for this model is:\n% x1 -> x3\n% x1 -> x4\n% x2 -> x1\n% x2 -> x3\n% x4 -> x5\n% x5 -> x4\n%\n% The dependency structure of this model can \n% be viewed by executing the following command:\n%\n% >>hlp_viewGraphicsResource('sim/Schelter_2009_3_1.jpg');\n%\n% Author Credits:\n% \n% Tim Mullen, 2011\n%\n% References and Code:\n%\n% [1] (Ex 3.1, Eq. 11-15) Schelter B, Timmer J, Eichler M (2009) Assessing the strength of directed influences among neural signals using renormalized partial directed coherence. Journal of neuroscience methods 179:121-30\n%\n% ------------------------------------------------------------------------\n\n% specify the default system of equations\nexpr_def = { ...\n 'x1(t) = 0.9*x1(t-1) + 0.3*x2(t-2) + e1(t)' ...\n 'x2(t) = 1.3*x2(t-1) + -0.8*x2(t-2) + e2(t)' ...\n 'x3(t) = 0.3*x1(t-2) + 0.6*x2(t-1) + e3(t)' ...\n 'x4(t) = -0.7*x4(t-3) + -0.7*x1(t-3) + 0.3*x5(t-3) + e4(t)' ...\n 'x5(t) = 1*x5(t-1) + -0.4*x5(t-2) + 0.3*x4(t-2) + e5(t)' ...\n };\n\n% set up argument definitions\narg_define(varargin, ...\n arg({'expr','DynamicalEquations'},expr_def,[],'System of equations'), ...\n arg({'morder','ModelOrder'},3,[1 Inf],'Model order. This is mandatory'));\n\nif isempty(morder)\n error('SIFT:sim_examples:badParam','ModelOrder must be specified');\nend", "meta": {"author": "goodshawn12", "repo": "REST", "sha": "e34ce521fcb36e7813357a9720072dd111edf797", "save_path": "github-repos/MATLAB/goodshawn12-REST", "path": "github-repos/MATLAB/goodshawn12-REST/REST-e34ce521fcb36e7813357a9720072dd111edf797/dependencies/BCILAB/dependencies/SIFT-private/sim/examples/sim_ex_Schelter_2009_3_1.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278633625322, "lm_q2_score": 0.837619961306541, "lm_q1q2_score": 0.7391391927655379}} {"text": "%%%% discretization of direct space, to be used for plotting the field\n%%%% distribution; X,Y = vectors to be used for FFT; Xi,Yi = vectors to be\n%%%% used for interpolation\nfunction [X,Y,Xi,Yi]=prcellgrid(a1,a2,N1,N2)\nX=[]; Y=[]; %spatial coordinates after FFT \nfor l=1:N1\n for m=1:N2\n X(l,m)=(l-1-(N1-1)/2)*a1(1)/N1 + (m-1-(N2-1)/2)*a2(1)/N2;\n Y(l,m)=(l-1-(N1-1)/2)*a1(2)/N1 + (m-1-(N2-1)/2)*a2(2)/N2; \n end\nend\n\nM=501; \nXi=[]; Yi=[]; %finer discretization for field interpolation\nfor l=1:M\n for m=1:M\n Xi(l,m)=(l-1-(M-1)/2)*a1(1)/M + (m-1-(M-1)/2)*a2(1)/M;\n Yi(l,m)=(l-1-(M-1)/2)*a1(2)/M + (m-1-(M-1)/2)*a2(2)/M; \n end\nend\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/22808-eigenmodes-in-a-2d-photonic-crystal/prcellgrid.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391558355999, "lm_q2_score": 0.8006920092299292, "lm_q1q2_score": 0.7390700762839042}} {"text": "function [area,centroids] = calcVoronoiArea(v,varargin)\n% compute the spherical area of the Voronoi decomposition\n%\n% Input\n% v - @vector3d\n%\n% Output\n% area - area of the corresponding Voronoi cells\n% centroids - centroid of the voronoi cell\n%\n% Options\n% incomplete -\n\nv = reshape(v,[],1);\nN = length(v);\n\n% in case of antipodal symmetry - add antipodal points\nantipodal = v.antipodal || check_option(varargin, 'antipodal');\nif antipodal\n v.antipodal = false;\n [v,~,IC] = unique([v;-v],'noSymmetry');\nend\n\n[V,C] = calcVoronoi(v);\n\nnd = ~cellfun('isempty',C);\nv = v.subSet(nd);\n\nlast = cumsum(cellfun('prodofsize',C(nd)));\n\nleft = [C{nd}];\nshift = 2:last(end)+1; % that is the shift\nshift(last) = [0;last(1:end-1)]+1; % and the last gets the first\nright = left(shift);\n\ncenter = cumsum([1 diff(shift)>1]);\n\nva = v.subSet(center);\nvb = V.subSet(left);\nvc = V.subSet(right); % next vertex around\n\n% calculate the area for each triangle around generator (va)\nA = real(sphericalTriangleArea(va,vb,vc));\n\nif nargout>1\n [x,y,z]= double(A.*(va+vb+vc));\n x = full(sparse(center,1,x,length(S2G),1));\n y = full(sparse(center,1,y,length(S2G),1));\n z = full(sparse(center,1,z,length(S2G),1));\n centroids = vector3d(x,y,z);\nend\n\n% accumulate areas of spherical triangles around generator\nA = full(sparse(center,1,A,length(v),1));\n\narea = zeros(size(nd));\narea(nd) = A(1:nnz(nd));\n\nif antipodal\n idx = ( accumarray(IC,ones(size(IC))) == 2 ); % find all double occurences\n area(idx) = area(idx)/2; % halve their weight\n area = area(IC); % go back to original order\n area = area(1:N); % only the original nodes\nend\n\n\n\n\n", "meta": {"author": "mtex-toolbox", "repo": "mtex", "sha": "f0ce46a720935e9ae8106ef919340534bca1adcb", "save_path": "github-repos/MATLAB/mtex-toolbox-mtex", "path": "github-repos/MATLAB/mtex-toolbox-mtex/mtex-f0ce46a720935e9ae8106ef919340534bca1adcb/geometry/@vector3d/calcVoronoiArea.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391558355999, "lm_q2_score": 0.8006920044739461, "lm_q1q2_score": 0.7390700718939456}} {"text": "% Peak of Wigner-Ville Frequency Estimation\n%\n% Estimates the instantaneous frequency of the input signal by\n% extracting the peaks of the Wigner-Ville distribution.\n%\n%\n% Usage:\n%\n% ife = wvpe( signal, lag_window_length, time_res [, fft_length] )\n%\n% Parameters:\n%\n% signal\n%\n%\t Input one dimensional signal to be analysed. An analytic signal\n%\t is required for this function, however, if signal is real, a\n%\t default analytic transformer routine will be called from this\n%\t function before computing tfd.\n%\n% lag_window_length\n%\n%\t This is the data window length and controls the size of\n%\t the kernel used for analysis (lag_window_length must be\n%\t odd). The kernel used will be defined from -(lag_window_length+1)/2\n%\t to +(lag_window_length+1)/2 in both time and lag dimensions.\n%\n% time_res\n%\n%\t The number of time samples to skip between successive slices.\n%\t Default vaule is 1.\n%\n% fft_length\n%\n%\t Zero-padding at the FFT stage of the analysis may be specified by\n%\t giving an fft_length larger than lag_window_length. If fft_length\n%\t is not specified, or is smaller than the lag_window_length, then the\n%\t next highest power of two above lag_window_length is used. If\n%\t fft_length is not a power of two, the next highest power of two is\n%\t used.\n%\n% tfd\n%\n%\t The computed time-frequency distribution. size(tfd) will\n%\t return [a, b], where a is the next largest power of two above\n%\t fft_length, and b is floor(length(signal)/time_res) - 1.\n%\n%\n%\n% See Also: wvd\n% TFSAP 7.0\n% Copyright Prof. B. Boashash\n% Qatar University, Doha\n% email: tfsap.research@gmail.com\n", "meta": {"author": "HeLiangHIT", "repo": "time_frequency", "sha": "09c2abe92355ff5cd867bdb169229682e9d7af7c", "save_path": "github-repos/MATLAB/HeLiangHIT-time_frequency", "path": "github-repos/MATLAB/HeLiangHIT-time_frequency/time_frequency-09c2abe92355ff5cd867bdb169229682e9d7af7c/tf_tool_box/tfsa_7.0/win64_bin/wvpe.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026641072386, "lm_q2_score": 0.8056321983146849, "lm_q1q2_score": 0.7390085618046316}} {"text": "function pass = test_carrier_C2(pref)\n% Test Carrier equation.\n%\n% Toby Driscoll / Asgeir Birkisson, Jume 2014.\nif ( nargin == 0 )\n pref = cheboppref;\nend\n\ntol = 1e-10;\npref.bvpTol = tol;\ndom = [-1 1];\n\n%%\n\npref.discretization = @chebcolloc2;\nN = chebop(@(x,u) 0.01.*diff(u,2)+2.*(1-x.^2).*u+u.^2-1, dom);\nrhs = 0;\nN.bc = @(x,u) [u(-1); u(1)];\nx = chebfun(@(x) x, dom);\nN.init = 2.*(x.^2-1).*(1-2./(1+20.*x.^2));\n\nu = solvebvp(N, rhs, pref);\n\nxx = (-1:.25:1)';\nhiquality_ans = [\n 0\n -1.487429807540814\n -1.785617248281071\n 1.572366197526305\n -1.539652044363185\n 1.572366197526230\n -1.785617248281089\n -1.487429807540795\n 0\n ];\n\npass(1) = norm(u(xx) - hiquality_ans) < tol;\npass(2) = norm(u([-1 1])) < tol ;\n\n\nend\n\n\n", "meta": {"author": "chebfun", "repo": "chebfun", "sha": "8c49396a55e46ddd57a1d108c6a8f32e37536d54", "save_path": "github-repos/MATLAB/chebfun-chebfun", "path": "github-repos/MATLAB/chebfun-chebfun/chebfun-8c49396a55e46ddd57a1d108c6a8f32e37536d54/tests/chebop/test_carrier_C2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026663679976, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.739008559345182}} {"text": "function dz = doublePendulumDynamics(~,z,u,P) \n%DZ = DOUBLEPENDULUMDYNAMICS(T,Z,U,P)\n% \n%FUNCTION: This function computes the dynamics of a double\n% pendulum, and is designed to be called from ode45. The\n% model allows for arbitrary mass and inertia for each\n% link, but no friction or actuation\n% \n%INPUTS: \n% t = time. Dummy input for ode45. Not used.\n% z = [4xn] matrix of states.\n% u = [2xn] matrix of inputs\n% P = struct of parameters\n%OUTPUTS: \n% dz = [4xn] matrix of state derivatives\n% \n%NOTES:\n% This file was automatically generated by writeDoublePendulumDynamics\n\nm1 = P.m1; %link one mass\nm2 = P.m2; %link two mass\ng = P.g ; %gravity\nl1 = P.l1; %link one length\nl2 = P.l2; %link two length\nI1 = P.I1; %link one moment of inertia about its center of mass\nI2 = P.I2; %link two moment of inertia about its center of mass\nd1 = P.d1; %distance between link one center of mass and parent joint\nd2 = P.d2; %distance between link two center of mass and parent joint\n\nth1 = z(1,:); %link one absolute angle\ndth1 = z(2,:); %link one angular rate\nth2 = z(3,:); %link two absolute angle\ndth2 = z(4,:); %link two angular rate\n\nu1 = u(1,:); %torque acting on link 1 wrt ground\nu2 = u(2,:); %torque acting on link 2 wrt ground\n\nf1 = u1 - m2.*(d2.*dth2.^2.*cos(th2) + dth1.^2.*l1.*cos(th1)).*(d2.*sin(th2) + l1.*sin(th1)) + m2.*(d2.*dth2.^2.*sin(th2) + dth1.^2.*l1.*sin(th1)).*(d2.*cos(th2) + l1.*cos(th1)) - g.*m2.*(d2.*cos(th2) + l1.*cos(th1)) - d1.*g.*m1.*cos(th1);\nf2 = u2 - d2.*g.*m2.*cos(th2) + d2.*dth1.^2.*l1.*m2.*sin(th1 - th2);\n\nM11 = - I1 - d1.^2.*m1.*cos(th1).^2 - d1.^2.*m1.*sin(th1).^2 - l1.*m2.*cos(th1).*(d2.*cos(th2) + l1.*cos(th1)) - l1.*m2.*sin(th1).*(d2.*sin(th2) + l1.*sin(th1));\nM12 = - I2 - d2.*m2.*cos(th2).*(d2.*cos(th2) + l1.*cos(th1)) - d2.*m2.*sin(th2).*(d2.*sin(th2) + l1.*sin(th1));\nM21 = -d2.*l1.*m2.*cos(th1 - th2);\nM22 = - I2 - d2.^2.*m2;\n\nD = M11.*M22 - M12.*M21;\n\nddth1 = (f2.*M12 - f1.*M22)./D;\nddth2 = -(f2.*M11 - f1.*M21)./D;\n\ndz = [...\n dth1; %derivative of link one absolute angle\n ddth1; %derivative of link one angular rate\n dth2; %derivative of link two absolute angle\n ddth2; %derivative of link two angular rate\n];\nend \n", "meta": {"author": "MatthewPeterKelly", "repo": "dscTutorials", "sha": "e1e97a9be03ec146f88bd6ddd9e06db7ee52e242", "save_path": "github-repos/MATLAB/MatthewPeterKelly-dscTutorials", "path": "github-repos/MATLAB/MatthewPeterKelly-dscTutorials/dscTutorials-e1e97a9be03ec146f88bd6ddd9e06db7ee52e242/LagrangeMechanics/doublePendulumForced/doublePendulumDynamics.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026595857203, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.739008553881161}} {"text": "function [A, b, x0, lambda, lambda_max] = generate_lasso_data(n, d, k, noise_level)\n\n [A,~] = qr(randn(n,d),0); \n A = A'; \n p = randperm(n); \n p = p(1:k); % select location of k nonzeros\n x0 = zeros(n,1); \n x0(p) = randn(k,1); \n b = A*x0 + noise_level*randn(d, 1); % add random noise \n lambda_max = norm( A'*b, 'inf' );\n lambda = 0.1*lambda_max;\n\nend\n\n", "meta": {"author": "hiroyuki-kasai", "repo": "SGDLibrary", "sha": "d19a12559c79c3726683243885b15f982f4bec3d", "save_path": "github-repos/MATLAB/hiroyuki-kasai-SGDLibrary", "path": "github-repos/MATLAB/hiroyuki-kasai-SGDLibrary/SGDLibrary-d19a12559c79c3726683243885b15f982f4bec3d/tool/data_generator/generate_lasso_data.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9173026573249611, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.7390085477790307}} {"text": "function [dy,dh] = checkgrad(X_struct, f, e, varargin)\n\n% checkgrad checks the derivatives in a function, by comparing them to finite\n% differences approximations. The partial derivatives and the approximation\n% are printed and the norm of the diffrence divided by the norm of the sum is\n% returned as an indication of accuracy.\n%\n% usage: checkgrad('f', X, e, P1, P2, ...)\n%\n% where X is the argument and e is the small perturbation used for the finite\n% differences. and the P1, P2, ... are optional additional parameters which\n% get passed to f. The function f should be of the type \n%\n% [fX, dfX] = f(X, P1, P2, ...)\n%\n% where fX is the function value and dfX is a vector of partial derivatives.\n%\n% d - norm error\n% dy - analytic \n% dh - numerical\n% \n% Carl Edward Rasmussen, 2001-08-01.\n\n[X_vec, X_template] = struct2vector(X_struct);\n\n% [y, dy] = feval(f, vector2struct(X_vec + val*grad, X_template), varargin{:});\ntic\n[y, dy_struct] = feval(f, X_struct, varargin{:});\ny = sum(y);\ndy = struct2vector(dy_struct);\ntime1 = toc;\n\n% keyboard\n\nfig = figure;\ndh = nan(length(X_vec),1) ;\nt = cputime;\nn_char = 0;\ntime_step = 5;\nDIRECTION = 'forwards';\n% DIRECTION = 'backwards';\n% if length(X_vec) > 50000\n% \n% % SKIP = 10;\n% % START = 1;%14400;%1;\n% \n% SKIP = 2000;\n% START = 1;%14400;%1;\n% \n% % SKIP = 1000;\n% % START = 30000;%14400;%1;\n% else\n% SKIP = 1;%100;\n% START = 1;%4300;%1;\n% end\n\nSTART = 1;\nn = max(40, 30/time1) % Evalulate for ~15 seconds\nSKIP = ceil(length(X_vec)/n);\n\n% START = 20210;\n% SKIP = 1;\n\nif strcmp(DIRECTION, 'backwards');\n idx = length(X_vec):-SKIP:1;\nelseif strcmp(DIRECTION, 'forwards');\n idx = START:SKIP:length(X_vec);\nend\n\n% idx = length(X_vec):-1:(length(X_vec)-8);\n% DIRECTION = 'backwards';\n% SKIP = 1;\n\nfor j = idx\n \n dx = zeros(length(X_vec),1);\n dx(j) = dx(j) + e; % perturb a single dimension\n \n [y2] = feval(f, vector2struct(X_vec + dx, X_template), varargin{:});\n [y1] = feval(f, vector2struct(X_vec - dx, X_template), varargin{:});\n \n y1 = sum(y1(:));\n y2 = sum(y2(:));\n \n dh(j) = (y2 - y1)/(2*e);\n\n if ((cputime - t) > time_step) || (j == idx(end))\n t = cputime;\n figure(fig)\n clf\n subplot(2,1,1);\n if strcmp(DIRECTION, 'backwards');\n plot(j:SKIP:length(dy), dy(j:SKIP:end), 'bx-'); hold on;\n plot(j:SKIP:length(dy), dh(j:SKIP:end), 'r-');\n elseif strcmp(DIRECTION, 'forwards');\n plot(START:SKIP:j, dy(START:SKIP:j), 'bx-'); hold on;\n plot(START:SKIP:j, dh(START:SKIP:j), 'r-');\n end\n legend('analytical', 'numerical');\n ylabel('gradient');\n subplot(2,1,2);\n if strcmp(DIRECTION, 'backwards');\n plot(j:SKIP:length(dy), dy(j:SKIP:end) - dh(j:SKIP:end), 'gx-');\n elseif strcmp(DIRECTION, 'forwards');\n plot(START:SKIP:j, dy(START:SKIP:j) - dh(START:SKIP:j), 'gx-');\n end\n ylabel('error')\n drawnow\n\n s = [num2str(100*j/length(X_vec), '%0.1f'), '%, '];\n if n_char + length(s) >= 80\n fprintf('\\n')\n n_char = 0;\n end\n fprintf('%s', s);\n n_char = n_char + length(s);\n \n end\nend\nfprintf('\\n');\n\n% 'numerical:'\n% dh(idx)'\n% \n% 'analytical:'\n% dy(idx)'\n\n'delta:'\nerr = dy(idx)' - dh(idx)';\n\n'mult:'\nmult = dy(idx)' ./ dh(idx)';\n\nfor p = [1, 5, 20, 50, 90, 95, 99, 99.9, 99.99]\n fprintf('%g percentile err: \\t%e\\n', p, prctile(abs(err), p));\nend\n\n\n% % disp([dy dh]) % print the two vectors\n% d = norm(dh-dy)/norm(dh+dy); % return norm of diff divided by norm of sum\n", "meta": {"author": "akar43", "repo": "CategoryShapes", "sha": "55c9dab2293bcaceaaa3bf5fea782fdbf930fadb", "save_path": "github-repos/MATLAB/akar43-CategoryShapes", "path": "github-repos/MATLAB/akar43-CategoryShapes/CategoryShapes-55c9dab2293bcaceaaa3bf5fea782fdbf930fadb/external/SIRFS/minFunc_2012/checkgrad.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382129861583, "lm_q2_score": 0.857768108626046, "lm_q1q2_score": 0.7390000034622006}} {"text": "function phasediag\n% Phase diagram visualisation \n% using MATLAB expm \n%\n% $Ekkehard Holzbecher $Date: 2006/04/15 $\n%--------------------------------------------------------------------------\nT = 10; % maximum time\nC = [-1 1; 1 -3]; % matrix\nf = [1; 0]; % input vector\ncc = 1; % initial concentrations (absolute value of the vector)\nN = 60; % discretization of time\nM = 16; % no. of trajectories \n\n%----------------------execution & output----------------------------------\nequilibrium = -(inv(C)*f);\nt = linspace (0,T,N);\nfor angle = linspace (0,pi+pi,M)\n c0 = equilibrium + cc*[sin(angle); cos(angle)]; c = c0;\n for i = 2:N\n E = expm(C*t(i));\n c = [c E*c0-(eye(size(C,1))-E)*inv(C)*f];\n end \n plot (c(1,:)',c(2,:)'); hold on;\nend\n\nplot (equilibrium(1),equilibrium(2),'s');\nxlabel ('variable 1'); ylabel ('variable 2')\ntitle ('phase diagram')", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/15646-environmental-modeling/phasediag.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810466522863, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.7389504950691813}} {"text": "function nsub = subset_enum ( n )\n\n%*****************************************************************************80\n%\n%% SUBSET_ENUM enumerates the subsets of a set with N elements.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 25 January 2011\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the number of elements in the set.\n% N must be at least 0.\n%\n% Output, integer NSUB, the number of distinct elements.\n%\n nsub = 2^n;\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/combo/subset_enum.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8558511469672594, "lm_q2_score": 0.8633916152464017, "lm_q1q2_score": 0.7389347041905476}} {"text": "function perf=mse(e)\n%\n% calculate the mean squared error of the given errors\n% \n% 'perf = mse(E);'\n%\n% see also:\n% mae, linf, trimmedmse\n%\n\n% Copyright (c) 2011, KULeuven-ESAT-SCD, License & help @ http://www.esat.kuleuven.be/sista/lssvmlab\n\n\nperf = sum(sum(e.^2)) / numel(e);", "meta": {"author": "peterhcharlton", "repo": "RRest", "sha": "f5022e7029c5b6d6b8159b665dccc2c8f267976e", "save_path": "github-repos/MATLAB/peterhcharlton-RRest", "path": "github-repos/MATLAB/peterhcharlton-RRest/RRest-f5022e7029c5b6d6b8159b665dccc2c8f267976e/RRest_v3.0/Algorithms/extract_resp_sig/feat_based_extraction/LSSVMlabv1_8_R2009b_R2011a/mse.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8962513786759491, "lm_q2_score": 0.8244619220634457, "lm_q1q2_score": 0.738925134315186}} {"text": "function s = fastSampen(y,m,r)\n% INPUTS\n% y num_var x num_samples\n% m template length\n% r radius\n% OUTPUTS\n% s Sample Entropy\n%\n% Written by Shamim Nemati \n%\n% 01-31-2018 : modified by Giulia Da Poian , see\n% comments in the code \n% NOTE : Sample entropy quantifies the likelihood that a \n% sequence of m consecutive data points that matches another\n% sequence of the same length (match within a tolerance of r) \n% will still match the other sequence when their length is \n% increased of one sample (sequences of length m + 1); \n% References : \n% 1. Richman JS, Moorman JR. Physiological time-series \n% analysis using approximate entropy and sample entropy. \n% American Journal of Physiology-Heart and Circulatory \n% Physiology. 2000 Jun 1;278(6):H2039-49.\n% 2. Humeau-Heurtier A. The multiscale entropy \n% algorithm and its variants: A review. Entropy. 2015 May \n% 12;17(5):3110-23.\n% LICENSE: \n% This software is offered freely and without warranty under \n% the GNU (v3 or later) public license. See license file for\n% more information\n\n% Ensure y is a row vector\nif size(y, 1) > size(y,2)\n y = y';\nend\n\nxx = convert_to_lagged_form(y, m)'; % Giulia: replaced m-1 with m to match SampEn definition\nDxx = pdist(xx,'chebychev');\n\nyy = convert_to_lagged_form(y, m+1)'; % Giulia: replaced m with m+1 to match SampEn definition\nDyy = pdist(yy,'chebychev');\n\nA = mean( Dxx < r ) ;\nB = mean( Dyy < r );\n\ns = -log(B/A);\n\n\nfunction yy = convert_to_lagged_form(y, k)\n% Create an observation vector yy(:,t) containing the last k values of y, newest first\n% e.g., k=2, y = (a1 a2 a3) yy = a2 a3\n% (b1 b2 b3) b2 b2\n% a1 a2\n% b1 b2\n[s, T] = size(y);\nbs = s*ones(1,k);\nyy = zeros(k*s, T-k+1);\nfor i=1:k, yy(block(i,bs), :) = y(:, k-i+1:end-i+1); end\n\nfunction sub = block(blocks, block_sizes)\n% BLOCK Return a vector of subscripts corresponding to the specified blocks.\n% sub = block(blocks, block_sizes)\n%\n% e.g., block([2 5], [2 1 2 1 2]) = [3 7 8].\nblocks = blocks(:)';\nblock_sizes = block_sizes(:)';\nskip = [0 cumsum(block_sizes)];\nstart = skip(blocks)+1;\nfin = start + block_sizes(blocks) - 1;\nsub = [];\nfor j=1:length(blocks)\n sub = [sub start(j):fin(j)];\nend\n", "meta": {"author": "cliffordlab", "repo": "PhysioNet-Cardiovascular-Signal-Toolbox", "sha": "eec46e75e0b95c379ecb68cb0ebee0c4c9f54605", "save_path": "github-repos/MATLAB/cliffordlab-PhysioNet-Cardiovascular-Signal-Toolbox", "path": "github-repos/MATLAB/cliffordlab-PhysioNet-Cardiovascular-Signal-Toolbox/PhysioNet-Cardiovascular-Signal-Toolbox-eec46e75e0b95c379ecb68cb0ebee0c4c9f54605/Tools/Entropy_Tools/fastSampen.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8962513675912912, "lm_q2_score": 0.8244619220634456, "lm_q1q2_score": 0.7389251251763077}} {"text": "function P = perms_(x)\n%PERMS_ Functionality like MATLAB\\PERMS, but fast\n%\n% P = perms_(x)\n%\n% permuations of x in array of size n! x n for length(x)=n\n%\n%Sample timing comparing perms_(1:n) with built-in Matlab routine perms(1:n)\n%in seconds on 120 MHz Pentium Laptop:\n%\n%\n% n t(perms) t(perms_)\n% --------------------------------\n% 2.0000 0.0052 0.0044\n% 3.0000 0.0198 0.0091\n% 4.0000 0.0875 0.0154\n% 5.0000 0.4390 0.0253\n% 6.0000 2.6650 0.0495\n% 7.0000 18.8400 0.1870\n% 8.0000 167.4100 1.3400\n%\n%\n%Matlab description:\n% PERMS(1:N), or PERMS(V) where V is a vector of length N, creates a\n% matrix with N! rows and N columns containing all possible\n% permutations of the N elements.\n%\n% This function is only practical for situations where N is less\n% than about 15.\n%\n% See also NCHOOSEK, RANDPERM, PERMUTE.\n\n\n% written 03/19/98 S.M. Rump\n% modified 04/04/04 S.M. Rump set round to nearest for safety\n% modified 04/06/05 S.M. Rump rounding unchanged\n% modified 05/30/07 S.M. Rump typo\n% modified 09/28/08 S.M. Rump check for rounding to nearest improved\n%\n\n e = 1e-30;\n if 1+e==1-e % fast check for rounding to nearest\n rndold = 0;\n else\n rndold = getround;\n setround(0)\n end\n\n n=length(x);\n if n==0\n P = [];\n else\n P = zeros(prod(1:n),n);\n P(1,1)=1;\n fac = 1;\n for k=2:n\n Pold = P(1:fac,1:k-1);\n w = 1:k;\n v = ((k-1)*fac+1):(k*fac);\n for i=k:-1:1\n P(v,w) = [ i*ones(fac,1) Pold+(Pold>=i) ];\n v = v-fac;\n end\n fac = k*fac;\n end\n P = x(P);\n end\n \n if rndold\n setround(rndold)\n end\n", "meta": {"author": "douthwja01", "repo": "OpenMAS", "sha": "962f321f82167db78066b2c88c783423ecc3b73a", "save_path": "github-repos/MATLAB/douthwja01-OpenMAS", "path": "github-repos/MATLAB/douthwja01-OpenMAS/OpenMAS-962f321f82167db78066b2c88c783423ecc3b73a/toolboxes/Intlab_V7.1/utility/perms_.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240930029117, "lm_q2_score": 0.8539127548105611, "lm_q1q2_score": 0.7388258887845854}} {"text": "function value = i4_gcdb ( i, j, k )\n\n%*****************************************************************************80\n%\n%% I4_GCDB finds the greatest common divisor of the form K**N of two numbers.\n%\n% Discussion:\n%\n% Note that if J is negative, I4_GCDB will also be negative.\n% This is because it is likely that the caller is forming\n% the fraction I/J, and so any minus sign should be\n% factored out of J.\n%\n% If I and J are both zero, I4_GCDB is returned as 1.\n%\n% If I is zero and J is not, I4_GCDB is returned as J,\n% and vice versa.\n%\n% If I and J are nonzero, and have no common divisor of the\n% form K**N, I4_GCDB is returned as 1.\n%\n% Otherwise, I4_GCDB is returned as the largest common divisor\n% of the form K**N shared by I and J.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 19 April 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer I, J, two numbers whose greatest common divisor K**N\n% is desired.\n%\n% Input, integer K, the possible divisor of I and J.\n%\n% Output, integer VALUE, the greatest common divisor of\n% the form K^N shared by I and J.\n%\n value = 1;\n%\n% If both I and J are zero, I4_GCDB is 1.\n%\n if ( i == 0 && j == 0 )\n value = 1;\n return\n end\n%\n% If just one of I and J is zero, I4_GCDB is the other one.\n%\n if ( i == 0 )\n value = j;\n return\n elseif ( j == 0 )\n value = i;\n return\n end\n%\n% Divide out K as long as you can.\n%\n if ( 0 < j )\n value = 1;\n else\n value = -1;\n end\n\n while\n\n if ( mod ( i, k ) ~= 0 || mod ( j, k ) ~= 0 )\n break\n end\n\n value = value * k;\n i = i / k;\n j = j / k;\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/i4lib/i4_gcdb.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240791017536, "lm_q2_score": 0.8539127585282745, "lm_q1q2_score": 0.7388258801308644}} {"text": "function result = is_symmetric_matrix(A)\n%\n% Symmetric Matrices\n% \n% is_symmetric_matrix(A) determines if the matrix A is a symmetric\n% matrix. An error is returned if a matrix that is not square is attempted\n% to be determined for symmetry.\n\nmatrix_size = size(A);\n\nm = matrix_size(1,1);\nn = matrix_size(1,2);\n\nif m ~= n\n error('Only square matrices can be symmetric.');\nelse\n if A == A'\n result = 1;\n else\n result = 0;\n end\nend", "meta": {"author": "xiuyechen", "repo": "FishExplorer", "sha": "c61392cf0835480d64fc03c15f1992935fdc7106", "save_path": "github-repos/MATLAB/xiuyechen-FishExplorer", "path": "github-repos/MATLAB/xiuyechen-FishExplorer/FishExplorer-c61392cf0835480d64fc03c15f1992935fdc7106/ref functions/Gram-Schmidt Process/is_symmetric_matrix.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8652240825770432, "lm_q2_score": 0.8539127548105611, "lm_q1q2_score": 0.7388258798818034}} {"text": "function [ vX ] = ProjectOntoHalfSpace( vY, vA, valB )\n% ----------------------------------------------------------------------------------------------- %\n% [ vX ] = OrthogonalProjectionOntoConvexSets( cProjFun, vY, numIterations, stopThr )\n% Solves \\arg \\min_{x} 0.5 || x - y ||, s.t. x \\in \\bigcap {C}_{i} using\n% Dykstra's Projection Algorithm.\n% Input:\n% - mA - Model Matrix.\n% Input model matrix.\n% Structure: Matrix (m x n).\n% Type: 'Single' / 'Double'.\n% Range: (-inf, inf).\n% Output:\n% - vX - Solution Vector.\n% The solution to the optimization problem..\n% Structure: Vector (m x 1).\n% Type: 'Single' / 'Double'.\n% Range: (-inf, inf).\n% References\n% 1. Orthogonal Projection onto a Half Space - https://math.stackexchange.com/questions/318740.\n% Remarks:\n% 1. B\n% TODO:\n% 1. C\n% Release Notes:\n% - 1.0.000 19/03/2020 Royi Avital\n% * First release version.\n% ----------------------------------------------------------------------------------------------- %\n\nFALSE = 0;\nTRUE = 1;\n\nOFF = 0;\nON = 1;\n\nvalR = (vA.' * vY) - valB;\n\nif(valR > 0)\n vX = vY - ((valR / (vA.' * vA)) * vA);\nelse\n vX = vY;\nend\n\n\nend\n\n", "meta": {"author": "RoyiAvital", "repo": "StackExchangeCodes", "sha": "d2a934616995fa8a9f4df1ca29029402435b9e6f", "save_path": "github-repos/MATLAB/RoyiAvital-StackExchangeCodes", "path": "github-repos/MATLAB/RoyiAvital-StackExchangeCodes/StackExchangeCodes-d2a934616995fa8a9f4df1ca29029402435b9e6f/Mathematics/Q3599020/ProjectOntoHalfSpace.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625107731765, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.7387484537665019}} {"text": "% book : Signals and Systems Laboratory with MATLAB \n% authors : Alex Palamides & Anastasia Veloni\n\n%Fourier Transfrom properties\n\n%\tconvolution \n\n%x1(t)=u(t)-u(t-2) and x2(t)=u(t)-u(t-4) \n\n\n% F^-1{X1(w)X2(w)}\nsyms t w\nx1=heaviside(t)-heaviside(t-2);\nx2=heaviside(t)-heaviside(t-4);\nX1=fourier(x1,w);\nX2=fourier(x2,w);\nright =ifourier(X1*X2,t);\nezplot(right,[0 8]);\n\n% convolution of x1(t) with x2(t)\nfigure\nt1=0:.01:2;\nt2=2.01:.01:4;\nx1=[ones(size(t1)) zeros(size(t2))];\nx2=ones(size([t1 t2]));\ny=conv(x1,x2)*.01;\nplot(0:.01:8,y);\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/28762-signals-and-systems-laboratory-with-matlab-m-files/M-FILES/6/c65.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9284088045171237, "lm_q2_score": 0.7956581049086031, "lm_q1q2_score": 0.7386959899825564}} {"text": "%% viewFourthOrderTensor\n% Below is a demonstration of the features of the |viewFourthOrderTensor2D| function\n\n%%\nclear; close all; clc;\n\n%% Syntax\n% |viewFourthOrderTensor(C,numDigits,fontSizeIm,fontSize);|\n\n%% Description \n% This function creates the 9x9 and the 6x6 (aka Voigt) array mappings for\n% 3D 4th order input tensor C. The function can take up to 4 inputs: \n%%\n% * |C|, a fourth order tensor (3x3x3x3)\n% * |numDigits|, the number of decimal places to use for numerical values (default 5)\n% * |fontSizeIm|, the font size in the image (default 15)\n% * |fontSize|, the font size of the axis window (default 15)\n\n%% Examples \n\n%% Viewing fourth-order stiffness tensors\n\n%%\n% Creating the stiffness tensor for Hooke's law of linear elasticity\n\n%Constructing 4th order base tensor set\nI=eye(3,3); %The 2nd order identity tensor\nII1=dyadicProduct(I,I,1); %4th order base tensor 1 \nII3=dyadicProduct(I,I,3); %4th order base tensor 3\n\n%Parameters for Hooke's law\nmu=1; %The shear modulus\nlambda=5; %The lambda lame parameter\nC=lambda.*II1+2.*mu.*II3; %Construct 4th order stiffness tensor\n\n%%\n% Visualizing the tensor using |viewFourthOrderTensor|\n\nviewFourthOrderTensor(C); %Visualize tensor C\n\n%% Viewing fourth-order stiffness tensors with symbolic variables\n\ntry\n %%\n \n syms mu lambda; %Create symbolic Lame parameters\n \n %Parameters for Hooke's law \n C=lambda.*II1+2.*mu.*II3; %Construct 4th order stiffness tensor\n \n %%\n % Visualizing the tensor using |viewFourthOrderTensor|\n \n numDigits=0;\n fontSizeIm=15;\n fontSize=25;\n viewFourthOrderTensor(C,numDigits,fontSizeIm,fontSize); %Visualize tensor C\n\n %% \n syms mu k; %Create symbolic Lame parameters\n \n %Construct 4th order stiffness tensor\n k=lambda+2/3*mu; %Bulk modulus\n\n %Construct 4th order stiffness tensor\n C=(k-2/3*mu).*II1+2.*mu.*II3; %Construct 4th order stiffness tensor\n \n %%\n % Visualizing the tensor using |viewFourthOrderTensor|\n \n numDigits=0;\n fontSizeIm=15;\n fontSize=25;\n viewFourthOrderTensor(C,numDigits,fontSizeIm,fontSize); %Visualize tensor C\n\nend\n\n%%\n% \n% <>\n% \n% _*GIBBON*_ \n% \n% \n% _Kevin Mattheus Moerman_, \n \n%% \n% _*GIBBON footer text*_ \n% \n% License: \n% \n% GIBBON: The Geometry and Image-based Bioengineering add-On. A toolbox for\n% image segmentation, image-based modeling, meshing, and finite element\n% analysis.\n% \n% Copyright (C) 2006-2022 Kevin Mattheus Moerman and the GIBBON contributors\n% \n% This program is free software: you can redistribute it and/or modify\n% it under the terms of the GNU General Public License as published by\n% the Free Software Foundation, either version 3 of the License, or\n% (at your option) any later version.\n% \n% This program is distributed in the hope that it will be useful,\n% but WITHOUT ANY WARRANTY; without even the implied warranty of\n% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n% GNU General Public License for more details.\n% \n% You should have received a copy of the GNU General Public License\n% along with this program. If not, see .\n", "meta": {"author": "gibbonCode", "repo": "GIBBON", "sha": "8178520664a6148db939eaea87e75b3cba4f2b4f", "save_path": "github-repos/MATLAB/gibbonCode-GIBBON", "path": "github-repos/MATLAB/gibbonCode-GIBBON/GIBBON-8178520664a6148db939eaea87e75b3cba4f2b4f/docs/HELP_viewFourthOrderTensor.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588052782737, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.7386857078058652}} {"text": "function f = p01_f ( x )\n\n%*****************************************************************************80\n%\n%% P01_F evaluates the objective function for problem 1.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 25 February 2002\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real X, the argument of the objective function.\n%\n% Output, real F, the value of the objective function.\n%\n f = ( x - 2.0 ) * ( x - 2.0 ) + 1.0;\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_min/p01_f.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8311430478583168, "lm_q2_score": 0.8887587949656841, "lm_q1q2_score": 0.7386856936586635}} {"text": "%CIRCGRID Generate 2d quadrilateral grid for a circle.\n%\n% [ GRID ] = CIRCGRID( NS, NR, R, XP, TH_OFFSET ) Generates a quadrilateral\n% grid for a circular domain with NS+NR cells in the radial direction. NS\n% specifies the cell resolution of the inner square (default 4), and NR the\n% number of cells in the radial direction of the outer layer (default 3).\n% The optional arguments R and XP = [x0;y0] specify the radius and center\n% coordinates of the circle (default R = 1 and XP = [0;0]). Furthermore,\n% TH_OFFSET specifies a rotation of the whole grid in radians.\n%\n% Examples:\n%\n% 1) A 64 cell grid for a circle with radius 1 centered at [ 0, 0 ]:\n%\n% grid = circgrid();\n%\n% 2) A 1024 cell grid for a circle with radius 0.5 centered at [ 1, 1 ]:\n%\n% grid = circgrid( 16, 12, 0.5, [1;1], 0 );\n%\n% See also CYLGRID, BLOCKGRID, HOLEGRID, LINEGRID, RECTGRID, RINGGRID, SPHEREGRID\n\n% Copyright 2013-2022 Precise Simulation, Ltd.\n", "meta": {"author": "precise-simulation", "repo": "featool-multiphysics", "sha": "861c771adda317a9f091263d16dca060116bd516", "save_path": "github-repos/MATLAB/precise-simulation-featool-multiphysics", "path": "github-repos/MATLAB/precise-simulation-featool-multiphysics/featool-multiphysics-861c771adda317a9f091263d16dca060116bd516/grid/circgrid.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357563664174, "lm_q2_score": 0.8519527944504227, "lm_q1q2_score": 0.7386735355248052}} {"text": "function y = im2jpeg(x, quality) \n%IM2JPEG Compresses an image using a JPEG approximation.\n% Y = IM2JPEG(X, QUALITY) compresses image X based on 8 x 8 DCT\n% transforms, coefficient quantization, and Huffman symbol\n% coding. Input QUALITY determines the amount of information that\n% is lost and compression achieved. Y is an encoding structure\n% containing fields: \n%\n% Y.size Size of X\n% Y.numblocks Number of 8-by-8 encoded blocks\n% Y.quality Quality factor (as percent)\n% Y.huffman Huffman encoding structure, as returned by\n% MAT2HUFF\n%\n% See also JPEG2IM.\n\n% Copyright 2002-2004 R. C. Gonzalez, R. E. Woods, & S. L. Eddins\n% Digital Image Processing Using MATLAB, Prentice-Hall, 2004\n% $Revision: 1.4 $ $Date: 2003/10/26 18:37:41 $\n\nerror(nargchk(1, 2, nargin)); % Check input arguments\nif ndims(x) ~= 2 | ~isreal(x) | ~isnumeric(x) | ~isa(x, 'uint8')\n error('The input must be a UINT8 image.'); \nend\nif nargin < 2 \n quality = 1; % Default value for quality.\nend \n\nm = [16 11 10 16 24 40 51 61 % JPEG normalizing array\n 12 12 14 19 26 58 60 55 % and zig-zag redordering\n 14 13 16 24 40 57 69 56 % pattern.\n 14 17 22 29 51 87 80 62\n 18 22 37 56 68 109 103 77\n 24 35 55 64 81 104 113 92\n 49 64 78 87 103 121 120 101\n 72 92 95 98 112 100 103 99] * quality;\n\norder = [1 9 2 3 10 17 25 18 11 4 5 12 19 26 33 ...\n 41 34 27 20 13 6 7 14 21 28 35 42 49 57 50 ...\n 43 36 29 22 15 8 16 23 30 37 44 51 58 59 52 ...\n 45 38 31 24 32 39 46 53 60 61 54 47 40 48 55 ...\n 62 63 56 64];\n\n[xm, xn] = size(x); % Get input size.\nx = double(x) - 128; % Level shift input\nt = dctmtx(8); % Compute 8 x 8 DCT matrix\n\n% Compute DCTs of 8x8 blocks and quantize the coefficients.\ny = blkproc(x, [8 8], 'P1 * x * P2', t, t');\ny = blkproc(y, [8 8], 'round(x ./ P1)', m);\n\ny = im2col(y, [8 8], 'distinct'); % Break 8x8 blocks into columns\nxb = size(y, 2); % Get number of blocks\ny = y(order, :); % Reorder column elements\n\neob = max(x(:)) + 1; % Create end-of-block symbol\nr = zeros(numel(y) + size(y, 2), 1);\ncount = 0;\nfor j = 1:xb % Process 1 block (col) at a time\n i = max(find(y(:, j))); % Find last non-zero element\n if isempty(i) % No nonzero block values\n i = 0;\n end\n p = count + 1;\n q = p + i;\n r(p:q) = [y(1:i, j); eob]; % Truncate trailing 0's, add EOB,\n count = count + i + 1; % and add to output vector\nend\n\nr((count + 1):end) = []; % Delete unusued portion of r\n \ny.size = uint16([xm xn]);\ny.numblocks = uint16(xb);\ny.quality = uint16(quality * 100);\ny.huffman = mat2huff(r);\n", "meta": {"author": "61--", "repo": "weiyanmin", "sha": "e15a7789602ec65c7ce1972bd905826ff4851435", "save_path": "github-repos/MATLAB/61---weiyanmin", "path": "github-repos/MATLAB/61---weiyanmin/weiyanmin-e15a7789602ec65c7ce1972bd905826ff4851435/Matlab/im2jpeg.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951680216529, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.7386677145508298}} {"text": "% MultiQuadrics scattered data INTERPOLATION. \n% \n% SYNTAX: [fi, coefficients] = mq_interpolation( r, f, ri, c )\n%\n% where r and f are the scattered argument and function\n% values, fi is the data interpolated at ri, c is the \n% multiquadric parameter and coefficients is a vector \n% containing the coefficients of the MQ expansion. \n%\n% Examples: \n% N = 51; c = 0.2;\n% x = 2*pi*sort( rand([1 N]) ); f = sin(x);\n% xi = linspace(0,2*pi,N);\n% [fi,coefficients] = mq_interpolation(x(:),f(:),xi(:),c);\n% figure(1), plot(x,f,xi,fi,'o')\n% \n%\t N = 51; c = 0;\n%\t x = 2*rand([1 N]) - 1; y = 2*rand([1 N]) - 1; r = [x(:) y(:)];\n%\t for i = 1:N, f(i) = exp( -x(i)^2 -y(i)^2 ); end\n%\t xi = linspace(-1.1,1.1,N); yi = linspace(-1.1,1.1,N);\n%\t [Xi,Yi] = meshgrid(xi,yi);\n%\t for i = 1:N*N, ri(i,:) = [Xi(i) Yi(i)]; end\n%\t [fi,coefficients] = mq_interpolation(r,f(:),ri,c);\n%\t S = reshape(fi,N,N);\n%\t figure(2)\n%\t mesh(xi,yi,S), hold on, plot3(x,y,f,'o'), hold off\n\n\n% Written by Orlando Camargo Rodriguez\n\nfunction [fi,coefficients] = mq_interpolation(r,f,ri,c)\n\nfi = [];\ncoefficients = [];\n\nN = length( r(:,1) ); \n\nfor i = 1:N \n\n rj_minus_ri = ( r(i,:)'*ones([1 N]) )' - r;\n \n Phi(:,i) = sqrt( sum( rj_minus_ri.^2 , 2 ) + c*c );\n \nend\n\ncoefficients = Phi\\f(:); % Calculate the coefficients through Gaussian elimination\n\nNi = length( ri(:,1) );\n\nfor i = 1:Ni\n\n ri_minus_r = ( ri(i,:)'*ones([1 N]) )' - r;\n \n phi_at_ri = sqrt( sum( ri_minus_r.^2 , 2 ) + c*c );\n \n fi(i) = coefficients'*phi_at_ri(:);\n \nend\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/8662-mqinterpolation-m/mq_interpolation.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951625409307, "lm_q2_score": 0.79053032607222, "lm_q1q2_score": 0.7386677125237869}} {"text": "function CNR =Compute_VM(IM,sigma1,sigma2)\n\n% This new visibility metric is to calculate the Contrast-to-Noise Ratio \n% of noise image estimated by Gaussian kernel with sigma1 and sigma2 respectively.\n% Written by zhengguo dai in Beijing JX Digital Wave Co.ltd\n% Email: zhgdai@126.com\n% Note: This new metric should be tested by more pictures.\n\nepsilon=1e-1;\nhalf_size1 = ceil( -norminv( epsilon/2, 0, sigma1 ) );\nsize1 = 2 * half_size1 + 1 ;\nhalf_size2 = ceil( -norminv( epsilon/2, 0, sigma2 ) );\nsize2 = 2 * half_size2 + 1 ;\ngaussian1 = fspecial( 'gaussian', size1, sigma1 ) ;\ngaussian2 = fspecial( 'gaussian', size2, sigma2 ) ;\nIM = abs(IM - imfilter( IM, gaussian1, 'replicate' )) ;\nnoise = IM - imfilter( IM, gaussian1, 'replicate' ) ;\nlsd = sqrt(imfilter( noise.^2, gaussian2, 'replicate' ) ) ;\nlsd = lsd./max( lsd( : ) ) .*255 ; % normalize\n% figure; imshow(lsd,[])\nCNR = sum(lsd(:))/(size(lsd,1)*size(lsd,2));", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/33529-a-new-visibility-metric-for-haze-images/visibility metric/Compute_VM.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951552333004, "lm_q2_score": 0.7905303137346446, "lm_q1q2_score": 0.7386676952187129}} {"text": " function y = mod0(x,b)\n%function y = mod0(x,b)\n%\tthe usual mod function returns values in the range [0,b)\n%\twhereas this mod function returns values in the range [-b/2,b/2)\n%\twhich frequently arises in signal processing problems!\n%\tJeff Fessler\n\ny = mod(x + b/2, b) - b/2;\n", "meta": {"author": "JeffFessler", "repo": "mirt", "sha": "b7f36cc46916821e8bc8502301b1554ebc7efe1d", "save_path": "github-repos/MATLAB/JeffFessler-mirt", "path": "github-repos/MATLAB/JeffFessler-mirt/mirt-b7f36cc46916821e8bc8502301b1554ebc7efe1d/utilities/mod0.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9196425377849806, "lm_q2_score": 0.8031737987125613, "lm_q1q2_score": 0.7386327905304231}} {"text": "function det = r8pbu_det ( n, mu, a_lu )\n\n%*****************************************************************************80\n%\n%% R8PBU_DET computes the determinant of a matrix factored by R8PBU_FA.\n%\n% Discussion:\n%\n% The R8PBU storage format is for a symmetric positive definite band matrix.\n%\n% To save storage, only the diagonal and upper triangle of A is stored,\n% in a compact diagonal format that preserves columns.\n%\n% The diagonal is stored in row MU+1 of the array.\n% The first superdiagonal in row MU, columns 2 through N.\n% The second superdiagonal in row MU-1, columns 3 through N.\n% The MU-th superdiagonal in row 1, columns MU+1 through N.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 27 March 2004\n%\n% Author:\n%\n% MATLAB version by John Burkardt.\n%\n% Reference:\n%\n% Dongarra, Bunch, Moler, Stewart,\n% LINPACK User's Guide,\n% SIAM, Philadelphia, 1979.\n%\n% Parameters:\n%\n% Input, integer N, the order of the matrix.\n% N must be positive.\n%\n% Input, integer MU, the number of superdiagonals of the matrix.\n% MU must be at least 0 and no more than N-1.\n%\n% Input, real A_LU(MU+1,N), the LU factors from R8PBU_FA.\n%\n% Output, real DET, the determinant of the matrix.\n%\n det = prod ( a_lu(mu+1,1:n) );\n det = det * det;\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/linplus/r8pbu_det.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425311777929, "lm_q2_score": 0.803173801068221, "lm_q1q2_score": 0.7386327873900679}} {"text": "function par_est2a\n% parameter estimation with derivatives Holzbecher September 2005\n% using differential equations\n% Idea from FEMLAB - there R instead of Q \n% see COMSOL News, Nr. 1, 2005, page 15\nglobal xfit cfit Q\n\n% specify fitting data\nxfit = [0.05:0.1:0.95];\ncfit = [0.9256859756097451 0.7884908536585051 0.6665396341462926...\n 0.559832317073104 0.4683689024389414 0.39214939024380824...\n 0.33117378048770196 0.28544207317062964 0.25495426829258294 0.23971036585356142]; \nQ = -2;\nD = fzero(@myfun,1.8);\ndisplay (['Best fit for D = ' num2str(D)]);\nx = [0:0.01:1];\nplot (xfit,cfit,'o',x,-(Q/D/2)*x.*x + (Q/D)*x + 1,'-');\nlegend ('given','modelled');\nxlabel ('x'); ylabel ('c');\n\nfunction f = myfun(D); \nglobal xfit cfit Q\n\noptions = bvpset;\n% solve diffusion equation for c with c(0)=1 and dc/dx(1)=0 \nsolinit = bvpinit([0 xfit 1],@guess);\nc = bvp4c (@mat4ode,@mat4bc,solinit,options,Q/D,1);\n%plot (c.x,c.y(1,:),'r',xfit,-(Q/D/D)*xfit.*xfit+(Q/D)*xfit+ones(1,size(xfit,2)));\n\n% solve Poisson equation for dc/dD (cD) with boundary conditions\nsolinit = bvpinit([0 xfit 1],@guess1);\ncD = bvp4c (@mat4ode,@mat4bc,solinit,options,Q/D/D,0);\n\n% specify function f to vanish\nf = 2*(c.y(1,2:size(c.y,2)-1)-cfit)*cD.y(1,2:size(c.y,2)-1)';\n\nfunction dydx = mat4ode(x,y,Q,c0)\ndydx = [y(2); -Q];\n% ------------------------------------------------------------\nfunction res = mat4bc(y0,y1,Q,c0)\nres = [y0(1)-c0; y1(2)];\n% ------------------------------------------------------------\nfunction v = guess(x)\nv = [x*(x-2)+1; 2*(x-1)];\n% ------------------------------------------------------------\nfunction v = guess1(x)\nv = [x*(x-2); 2*(x-1)];\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/15646-environmental-modeling/par_est2a.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425245706047, "lm_q2_score": 0.8031737869342623, "lm_q1q2_score": 0.738632769085158}} {"text": " function [fwhm_best, costs, im_best] = ...\n\tfwhm_match(true_image, blurred_image, fwhms)\n%|function [fwhm_best, costs, im_best] = ...\n%|\tfwhm_match(true_image, blurred_image, fwhms)\n%|\n%| given a blurred_image of a true_image, find the FHWM of a Gaussian kernel\n%| that, when convolved to the true_image, yields the smoothed image\n%| that best matches blurred_image.\n%|\n%| the set of FWHM values given in the array fwhms is tried.\n%|\n%| Copyright 2001-8-30, Jeff Fessler, University of Michigan\n\nif nargin == 1 && streq(true_image, 'test'), fwhm_match_test, return, end\nif nargin < 2, ir_usage, end\n\nif nargin < 3\n\tfwhms = 0:0.5:4;\nend\n\ncosts = zeros(size(fwhms));\ncost_min = Inf;\nfor ii=1:length(fwhms)\n\tfwhm = fwhms(ii);\n\tkern = gaussian_kernel(fwhm);\n\tpsf = kern * kern';\n\ttmp = conv2(true_image, psf, 'same');\n\tcosts(ii) = norm(tmp(:) - blurred_image(:)) / norm(true_image(:));\n\tif costs(ii) < cost_min\n\t\tim_best = tmp;\n\tend\nend\n\n[dummy ibest] = min(costs);\nif ibest == 1 || ibest == length(fwhms)\n\twarning 'need wider range of fwhms'\nend\nfwhm_best = fwhms(ibest);\n\n\n% fwhm_match_test\nfunction fwhm_match_test\n\n% pyramidal PSF to stress the approach\npsf1 = [0:5 4:-1:0]; psf1 = psf1 / sum(psf1); psf = psf1' * psf1;\ntrue_image = zeros(128); true_image(64:96,64:96) = 1;\nblurred_image = conv2(true_image, psf, 'same');\nim plc 2 2\nim(1, true_image, 'True Image')\nim(2, blurred_image, 'Blurred Image')\n\nfwhms = [2:0.25:8];\n[fwhm_best, costs] = fwhm_match(true_image, blurred_image, fwhms);\nnp = length(psf);\tip = -(np-1)/2:(np-1)/2;\nkern = gaussian_kernel(fwhm_best);\nnk = length(kern);\tik = -(nk-1)/2:(nk-1)/2;\n\nif im\n\tim subplot 3\n\tplot(fwhms, costs, 'c-o', fwhm_best, min(costs), 'yx')\n\txlabel FWHM, ylabel Cost, title 'Cost vs FWHM' \n\tim subplot 4\n\tplot(ip, psf1, '-o', ik, kern(:), '-+')\n\txlabel pixel, title 'PSF profile: actual and Gaussian fit'\nend\n", "meta": {"author": "JeffFessler", "repo": "mirt", "sha": "b7f36cc46916821e8bc8502301b1554ebc7efe1d", "save_path": "github-repos/MATLAB/JeffFessler-mirt", "path": "github-repos/MATLAB/JeffFessler-mirt/mirt-b7f36cc46916821e8bc8502301b1554ebc7efe1d/utilities/fwhm_match.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392817460332, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.7386002696728945}} {"text": "function ex3bvp\n%EX3BVP Example 3 of the BVP tutorial.\n% This is the example for D02KAF from the NAG library. D02KAF is a code\n% for Sturm-Liouville problems that takes advantage of special features of\n% the problem. The task is to find the fourth eigenvalue of Mathieu's\n% equation \n% \n% y'' + (lambda -2*q*cos(2*x))*y = 0\n% \n% on the interval [0, pi] with boundary conditions y'(0) = 0, y'(pi) = 0.\n% The parameter q = 5.\n% \n% A code that exploits fully the special nature of the Sturm-Liouville\n% problem can compute a specific eigenvalue. Of course using BVP4C we can\n% only compute an eigenvalue near to a guessed value. We can make it much\n% more likely that we compute the desired eigenfunction by supplying a\n% guess that has the correct qualitative behavior. We use here the same\n% guess lambda = 15 as the example. The eigenfunction is determined only\n% to a constant multiple, so the normalizing condition y(0) = 1 is used to\n% specify a particular solution.\n%\n% Plotting the solution on the mesh found by BVP4C does not result in a\n% smooth graph. The solution S(x) is continuous and has a continuous\n% derivative. It can be evaluated inexpensively using DEVAL at as many\n% points as necessary to get a smooth graph. \n\n% Copyright 2002, The MathWorks, Inc.\n\n% BVPINT is used to form an initial guess for a mesh of 10 equally\n% spaced points. The guess cos(4x) for y(x) and its derivative as guess \n% for y'(x) are evaluated in EX3INIT. The desired eigenvalue is the one\n% nearest the guess lambda = 15. A guess for unknown parameters is the\n% (optional) last argument of BVPINIT.\nsolinit = bvpinit(linspace(0,pi,10),@ex3init,15);\n\noptions = bvpset('stats','on'); \n\nsol = bvp4c(@ex3ode,@ex3bc,solinit,options);\n\n% BVP4C returns the solution as the structure 'sol'. The computed eigenvalue \n% is returned in the field sol.parameters.\nfprintf('\\n');\nfprintf('D02KAF computed lambda = 17.097.\\n')\nfprintf('bvp4c computed lambda =%7.3f.\\n',sol.parameters)\n\nfigure\nplot(sol.x,sol.y(1,:),sol.x,sol.y(1,:),'*')\naxis([0 pi -1 1])\ntitle('Eigenfunction for Mathieu''s equation.') \nxlabel('Solution at mesh points only.')\n\n% Plotting the solution just at the mesh points does not result in a \n% smooth graph near the ends of the interval. The approximate solution \n% S(x) is continuous and has a continuous derivative. DEVAL is used to\n% evaluate it at enough points to get a smooth graph.\nfigure\nxint = linspace(0,pi);\nSxint = deval(sol,xint); \nplot(xint,Sxint(1,:))\naxis([0 pi -1 1])\ntitle('Eigenfunction for Mathieu''s equation.') \nxlabel('Solution evaluated on a finer mesh with DEVAL.')\n\n% --------------------------------------------------------------------------\n\nfunction dydx = ex3ode(x,y,lambda)\n%EX3ODE ODE function for Example 3 of the BVP tutorial.\nq = 5;\ndydx = [ y(2)\n -(lambda - 2*q*cos(2*x))*y(1) ];\n\n% --------------------------------------------------------------------------\n \nfunction res = ex3bc(ya,yb,lambda)\n%EX3BC Boundary conditions for Example 3 of the BVP tutorial.\nres = [ ya(2) \n yb(2) \n ya(1) - 1 ];\n \n% --------------------------------------------------------------------------\n \nfunction v = ex3init(x)\n%EX3INIT Guess for the solution of Example 3 of the BVP tutorial.\nv = [ cos(4*x)\n -4*sin(4*x) ];\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/3819-tutorial-on-solving-bvps-with-bvp4c/BVP_tutorial/BVP_examples_65/ex3bvp.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392878563336, "lm_q2_score": 0.8354835309589073, "lm_q1q2_score": 0.7386002657246074}} {"text": "%DEMGMM3 Demonstrate density modelling with a Gaussian mixture model.\n%\n%\tDescription\n%\t The problem consists of modelling data generated by a mixture of\n%\tthree Gaussians in 2 dimensions with a mixture model using diagonal\n%\tcovariance matrices. The priors are 0.3, 0.5 and 0.2; the centres\n%\tare (2, 3.5), (0, 0) and (0,2); the covariances are all axis aligned\n%\t(0.16, 0.64), (0.25, 1) and the identity matrix. The first figure\n%\tcontains a scatter plot of the data.\n%\n%\tA Gaussian mixture model with three components is trained using EM.\n%\tThe parameter vector is printed before training and after training.\n%\tThe user should press any key to continue at these points. The\n%\tparameter vector consists of priors (the column), and centres (given\n%\tas (x, y) pairs as the next two columns). The diagonal entries of\n%\tthe covariance matrices are printed separately.\n%\n%\tThe second figure is a 3 dimensional view of the density function,\n%\twhile the third shows the axes of the 1-standard deviation circles\n%\tfor the three components of the mixture model.\n%\n%\tSee also\n%\tGMM, GMMINIT, GMMEM, GMMPROB, GMMUNPAK\n%\n\n%\tCopyright (c) Ian T Nabney (1996-2001)\n\n% Generate the data\nndata = 500;\n\n% Fix the seeds for reproducible results\nrandn('state', 42);\nrand('state', 42);\ndata = randn(ndata, 2);\nprior = [0.3 0.5 0.2];\n% Mixture model swaps clusters 1 and 3\ndatap = [0.2 0.5 0.3];\ndatac = [0 2; 0 0; 2 3.5];\ndatacov = [1 1;1 0.25; 0.4*0.4 0.8*0.8];\ndata1 = data(1:prior(1)*ndata,:);\ndata2 = data(prior(1)*ndata+1:(prior(2)+prior(1))*ndata, :);\ndata3 = data((prior(1)+prior(2))*ndata +1:ndata, :);\n\n% First cluster has axis aligned variance and centre (2, 3.5)\ndata1(:, 1) = data1(:, 1)*0.4 + 2.0;\ndata1(:, 2) = data1(:, 2)*0.8 + 3.5;\n\n% Second cluster has axis aligned variance and centre (0, 0)\ndata2(:,2) = data2(:, 2)*0.5;\n\n% Third cluster is at (0,2) with identity matrix for covariance\ndata3 = data3 + repmat([0 2], prior(3)*ndata, 1);\n\n% Put the dataset together again\ndata = [data1; data2; data3];\n\nclc\ndisp('This demonstration illustrates the use of a Gaussian mixture model')\ndisp('with diagonal covariance matrices to approximate the unconditional')\ndisp('probability density of data in a two-dimensional space.')\ndisp('We begin by generating the data from a mixture of three Gaussians')\ndisp('with axis aligned covariance structure and plotting it.')\ndisp(' ')\ndisp('The first cluster has centre (0, 2).')\ndisp('The second cluster has centre (0, 0).')\ndisp('The third cluster has centre (2, 3.5).')\ndisp(' ')\ndisp('Press any key to continue')\npause\n\nfh1 = figure;\nplot(data(:, 1), data(:, 2), 'o')\nset(gca, 'Box', 'on')\n\n% Set up mixture model\nncentres = 3;\ninput_dim = 2;\nmix = gmm(input_dim, ncentres, 'diag');\n\noptions = foptions;\noptions(14) = 5;\t% Just use 5 iterations of k-means in initialisation\n% Initialise the model parameters from the data\nmix = gmminit(mix, data, options);\n\n% Print out model\ndisp('The mixture model has three components and diagonal covariance')\ndisp('matrices. The model parameters after initialisation using the')\ndisp('k-means algorithm are as follows')\ndisp(' Priors Centres')\ndisp([mix.priors' mix.centres])\ndisp('Covariance diagonals are')\ndisp(mix.covars)\ndisp('Press any key to continue.')\npause\n\n% Set up vector of options for EM trainer\noptions = zeros(1, 18);\noptions(1) = 1;\t\t% Prints out error values.\noptions(14) = 20;\t\t% Number of iterations.\n\ndisp('We now train the model using the EM algorithm for 20 iterations.')\ndisp(' ')\ndisp('Press any key to continue.')\npause\n\n[mix, options, errlog] = gmmem(mix, data, options);\n\n% Print out model\ndisp(' ')\ndisp('The trained model has priors and centres:')\ndisp(' Priors Centres')\ndisp([mix.priors' mix.centres])\ndisp('The data generator has priors and centres')\ndisp(' Priors Centres')\ndisp([datap' datac])\ndisp('Model covariance diagonals are')\ndisp(mix.covars)\ndisp('Data generator covariance diagonals are')\ndisp(datacov)\ndisp('Note the close correspondence between these parameters and those')\ndisp('of the distribution used to generate the data.')\ndisp(' ')\ndisp('Press any key to continue.')\npause\n\nclc\ndisp('We now plot the density given by the mixture model as a surface plot.')\ndisp(' ')\ndisp('Press any key to continue.')\npause\n\n% Plot the result\nx = -4.0:0.2:5.0;\ny = -4.0:0.2:5.0;\n[X, Y] = meshgrid(x,y);\nX = X(:);\nY = Y(:);\ngrid = [X Y];\nZ = gmmprob(mix, grid);\nZ = reshape(Z, length(x), length(y));\nc = mesh(x, y, Z);\nhold on\ntitle('Surface plot of probability density')\nhold off\ndrawnow\n\nclc\ndisp('The final plot shows the centres and widths, given by one standard')\ndisp('deviation, of the three components of the mixture model. The axes')\ndisp('of the ellipses of constant density are shown.')\ndisp(' ')\ndisp('Press any key to continue.')\npause\n\n% Try to calculate a sensible position for the second figure, below the first\nfig1_pos = get(fh1, 'Position');\nfig2_pos = fig1_pos;\nfig2_pos(2) = fig2_pos(2) - fig1_pos(4);\nfh2 = figure('Position', fig2_pos);\n\nh = plot(data(:, 1), data(:, 2), 'bo');\nhold on\naxis('equal');\ntitle('Plot of data and covariances')\nfor i = 1:ncentres\n v = [1 0];\n for j = 1:2\n start=mix.centres(i,:)-sqrt(mix.covars(i,:).*v);\n endpt=mix.centres(i,:)+sqrt(mix.covars(i,:).*v);\n linex = [start(1) endpt(1)];\n liney = [start(2) endpt(2)];\n line(linex, liney, 'Color', 'k', 'LineWidth', 3)\n v = [0 1];\n end\n % Plot ellipses of one standard deviation\n theta = 0:0.02:2*pi;\n x = sqrt(mix.covars(i,1))*cos(theta) + mix.centres(i,1);\n y = sqrt(mix.covars(i,2))*sin(theta) + mix.centres(i,2);\n plot(x, y, 'r-');\nend\nhold off\n\ndisp('Note how the data cluster positions and widths are captured by')\ndisp('the mixture model.')\ndisp(' ')\ndisp('Press any key to end.')\npause\n\nclose(fh1);\nclose(fh2);\nclear all;\n\n", "meta": {"author": "bayesnet", "repo": "bnt", "sha": "bebba5f437b4e1e29169f0f3669df59fb5392e62", "save_path": "github-repos/MATLAB/bayesnet-bnt", "path": "github-repos/MATLAB/bayesnet-bnt/bnt-bebba5f437b4e1e29169f0f3669df59fb5392e62/netlab3.3/demgmm3.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392756357327, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.738600264567839}} {"text": "% Distribution code Version 1.0 -- 02/31/2020 by Wei Liu Copyright 2020\n%\n% The code is created based on the method described in the following paper \n% [1] \"Real-time Image Smoothing via Iterative Least Squares\", Wei Liu, Pingping Zhang, \n% Xiaolin Huang, Jie Yang, Chunhua Shen and Ian Reid, ACM Transactions on Graphics, \n% presented at SIGGRAPH 2020. \n% \n% The code and the algorithm are for non-comercial use only.\n\n\n% ---------------------- Input------------------------\n% F: input image, can be gray image or RGB color image\n% lambda: \\lambda in Eq.(1), control smoothing strength\n% p: the power norm in the Charbonnier penalty in Eq. (2)\n% eps: the small constant number in the Charbonnier penalty in Eq. (2)\n% iter: iteration number of the ILS in Eq. (8)\n\n% ---------------------- Output------------------------\n% U: smoothed image\n\nfunction U =ILS_LNorm(F, lambda, p, eps, iter)\n\nF = single(F); % 'single' precision is very important to reduce the computational cost\n\ngamma = 0.5 * p - 1;\nc = p * eps^gamma;\n\n[N, M, D] = size(F);\nsizeI2D = [N, M];\n\notfFx = psf2otf_Dx(sizeI2D); % equal to otfFx = psf2otf(fx, sizeI2D) where fx = [1, -1];\notfFy = psf2otf_Dy(sizeI2D); % equal to otfFy = psf2otf(fy, sizeI2D) where fy = [1; -1];\n\nDenormin = abs(otfFx).^2 + abs(otfFy ).^2;\nDenormin = repmat(Denormin, [1, 1, D]);\nDenormin = 1 + 0.5 * c * lambda * Denormin;\n\nU = F; % smoothed image\n\nNormin1 = fft2(U);\n\nfor k = 1: iter\n \n % Intermediate variables \\mu update, in x-axis and y-axis direction\n u_h = [diff(U,1,2), U(:,1,:) - U(:,end,:)];\n u_v = [diff(U,1,1); U(1,:,:) - U(end,:,:)];\n \n mu_h = c .* u_h - p .* u_h .* (u_h .* u_h + eps) .^ gamma;\n mu_v = c .* u_v - p .* u_v .* (u_v .* u_v + eps) .^ gamma;\n \n % Update the smoothed image U\n Normin2_h = [mu_h(:,end,:) - mu_h(:, 1,:), - diff(mu_h,1,2)];\n Normin2_v = [mu_v(end,:,:) - mu_v(1, :,:); - diff(mu_v,1,1)];\n \n FU = (Normin1 + 0.5 * lambda * (fft2(Normin2_h + Normin2_v))) ./ Denormin;\n U = real(ifft2(FU));\n \n Normin1 = FU; % This helps to further enlarge the smoothing strength\n \nend\n", "meta": {"author": "wliusjtu", "repo": "Real-time-Image-Smoothing-via-Iterative-Least-Squares", "sha": "b6c01cb519050614433b3939c82819588e79f206", "save_path": "github-repos/MATLAB/wliusjtu-Real-time-Image-Smoothing-via-Iterative-Least-Squares", "path": "github-repos/MATLAB/wliusjtu-Real-time-Image-Smoothing-via-Iterative-Least-Squares/Real-time-Image-Smoothing-via-Iterative-Least-Squares-b6c01cb519050614433b3939c82819588e79f206/ILS_LNorm.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898254600903, "lm_q2_score": 0.8152324938410783, "lm_q1q2_score": 0.7385923448044727}} {"text": "data = 'lobby.mat'; \n% 'mall.mat'\n% 'yaleB02.mat'\n% 'lobby.mat'\n% 'hall.mat'\nfprintf('--------------------------------\\n')\nfprintf(strcat(data, ' experiment', ' has started! \\n'))\npath = strcat('..\\FW_SPCP\\data\\',data);\nload(path); \n[m n] = size(D); \nD = D/norm(D,'fro');\n\n%% parameter tuning\nrho = 0.5; % sampling ratio\nOmega = rand(m,n)<=rho; % support of observation\nobs = Omega.*D; % measurements\n\ndelta = 0.01;\n% this is parameter to control noise level\n% the smaller the noise, the smaller is delta\n\nlambda_1 = delta*rho*norm(obs,'fro'); \nlambda_2 = delta*sqrt(rho)*norm(obs,'fro')/sqrt(max(m,n));\n\n% compare or not\ncompare = 1;\n\npar.M = obs; \npar.lambda_1 = lambda_1; par.lambda_2 =lambda_2;\npar.iter = 1000; par.display = 1; par.rho = rho;\npar.epsilon = 10^-3; % stopping criterion\npar.method = 'exact';%'exact' or 'power'\npar.Omega = Omega;\npar.compare = compare; % make comparison or not\noutput = FW_T(par); % main function\n\n% obtain the objective value returned from FW-T\nL = output.L; S = output.S;\nobj = 0.5*norm(Omega.*(L+S-obs),'fro')^2 + lambda_1*sum(svd(L))+...\n lambda_2*norm(vec(S),1);\n\nif compare % make comparison with FISTA and ISTA\n par.obj = obj; \n fprintf('the objective value returned by FW-T is %d \\n', obj)\n tic\n fprintf('--------------------------------\\n')\n fprintf('fista is invoked! \\n')\n fista(par);\n toc\n tic\n fprintf('--------------------------------\\n')\n fprintf('ista is invoked! \\n')\n ista(par);\n toc\nend\n% plot objective values\nfigure();\nplot(output.hist(1:end)); \nxlabel('iter.'); ylabel('obj. value');\ntitle('obj. values produced by FW-T');\n\n% original video\ntoplay = Omega.*D;\ntemp = size(toplay);\nno_frames = temp(2); \nwidth = frameSize(1);\nlength = frameSize(2);\nvideo_ori = zeros(width,length,no_frames); % width*length*frames\nfor i=1:no_frames\n video_ori(:,:,i) = reshape(toplay(:,i),width,length); \nend\n% implay(video_ori/256,100);\n\n\n% background term video\ntoplay = output.L;\nno_frames = size(toplay,2);\nwidth = frameSize(1);\nlength = frameSize(2);\nvideo_L = zeros(width,length,no_frames); % width*length*frames\nfor i=1:no_frames\n video_L(:,:,i) = reshape(toplay(:,i),width,length); \nend\n\n% sparse term video\ntoplay = output.S;\nno_frames = size(toplay, 2);\nwidth = frameSize(1);\nlength = frameSize(2);\nvideo_S = zeros(width,length,no_frames); % width*length*frames\nfor i=1:no_frames\n video_S(:,:,i) = reshape(toplay(:,i),width,length); \nend\nfigure();\nvideo_combine = [video_ori, video_L, abs(video_S)];\nfor i=1:no_frames \n imagesc(video_combine(:,:,i));\n colormap('gray'); axis off; title('FW-T');\n pause(0.01);\nend\n\n\n\n", "meta": {"author": "andrewssobral", "repo": "lrslibrary", "sha": "06d457349cb5f1fc56a583cd61af9f1d5150e3a1", "save_path": "github-repos/MATLAB/andrewssobral-lrslibrary", "path": "github-repos/MATLAB/andrewssobral-lrslibrary/lrslibrary-06d457349cb5f1fc56a583cd61af9f1d5150e3a1/algorithms/rpca/FW-T/demo_FWT.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898203834277, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.738592342699342}} {"text": "% Test file for trigtech/vals2coeffs.m\n\nfunction pass = test_vals2coeffs(varargin)\n\n% Set a tolerance (pref.chebfuneps doesn't matter)\ntol = 100*eps;\n\n%%\n% Test that a single value is converted correctly\nvals = sqrt(2);\nc = trigtech.vals2coeffs(vals);\npass(1) = (vals == c);\n\n%%\n% Simple data (odd case)\n% Exact values\nf_exact = @(x) 1 + cos(2*pi*x);\nx_pts = trigtech.trigpts(5);\nvals = f_exact(x_pts);\n% Exact coefficients\ncTrue = [0.5 0 1 0 0.5].';\n\n%%\n% Test real branch\nc = trigtech.vals2coeffs(vals);\npass(2) = norm(c - cTrue, inf) < tol;\n\n%%\n% Test imaginary branch\nc = trigtech.vals2coeffs(1i*vals);\npass(3) = norm(c - 1i*cTrue, inf) < tol;\n\n%%\n% Test general branch\nc = trigtech.vals2coeffs((1+1i)*vals);\npass(4) = norm(c - (1+1i)*cTrue, inf) < tol;\n\n%%\n% Test for array input\nc = trigtech.vals2coeffs([vals, -vals]);\npass(5) = norm(c(:,1) - cTrue, inf) < tol && ...\n norm(c(:,2) + cTrue, inf) < tol;\n \n%%\n% Simple data (even case)\nx_pts = trigtech.trigpts(6);\n% Exact values\nf_exact = @(x) 1 + sin(2*pi*x) + cos(3*pi*x);\nvals = f_exact(x_pts);\n% Exact coefficients\ncTrue = [1 0.5i 0 1 0 -0.5i].';\n\n%%\n% Test real branch\nc = trigtech.vals2coeffs(vals);\npass(6) = norm(c - cTrue, inf) < tol;\n\n%%\n% Test imaginary branch\nc = trigtech.vals2coeffs(1i*vals);\npass(7) = norm(c - 1i*cTrue, inf) < tol;\n\n%%\n% Test general branch\nc = trigtech.vals2coeffs((1+1i)*vals);\npass(8) = norm(c - (1+1i)*cTrue, inf) < tol;\n\n%%\n% Test for array input\nc = trigtech.vals2coeffs([vals, -vals]);\npass(9) = norm(c(:,1) - cTrue, inf) < tol && ...\n norm(c(:,2) + cTrue, inf) < tol;\n \n%%\n% Test for symmetry\nx = trigpts(123);\nvals = [cos(pi*x),sin(pi*x),cos(pi*x)+sin(pi*x)];\nvals(1,2) = 0;\nc = trigtech.vals2coeffs(vals);\npass(10) = norm(c(:,1) - flipud(c(:,1)), inf) == 0 && ...\n norm(c(:,2) + flipud(c(:,2)), inf) == 0 && ...\n norm(c(:,3) - flipud(c(:,3)), inf) > 0 && ...\n norm(c(:,3) + flipud(c(:,3)), inf) > 0;\n\nend\n", "meta": {"author": "chebfun", "repo": "chebfun", "sha": "8c49396a55e46ddd57a1d108c6a8f32e37536d54", "save_path": "github-repos/MATLAB/chebfun-chebfun", "path": "github-repos/MATLAB/chebfun-chebfun/chebfun-8c49396a55e46ddd57a1d108c6a8f32e37536d54/tests/trigtech/test_vals2coeffs.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.905989822921759, "lm_q2_score": 0.8152324848629215, "lm_q1q2_score": 0.7385923346010239}} {"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%\n% Main problem is minimize \\| A x \\|_1 subject to A x = b\n% We introduce z = A x - b\n% x \\in R^n A \\in R^{m x n} b \\in R^m\n% m < n\n% ADMM terms\n% minimize f(x) + g(z) subject to A x + B z = c\n% f(x) : {x \\in R^n | Ax = b}\n% g(z) : \\| z \\|_1\n% minimize f(x) + \\| z \\|_1 subject to x - z = 0\n% A : 1\n% B : -1\n% c : 0\n% \n% x update x = proj (z - u) over the set {Ax = b}\n% z update: z = shrinkage(x + u)\n% u update : u = u + x - z\n%\n% Primal residual r = A x + B z - c : x - z\n% Dual residual s = rho A^T B (z_new - z_old) = rho (z_old - z_new)\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nfunction [x, history] = bp(A, b, options)\n if nargin < 2 || nargin > 3\n error('Invalid arguments');\n end\n if nargin < 3\n options = struct;\n end\n % weight for the quadratic penalty term\n rho = 1;\n if isfield(options, 'rho')\n rho = options.rho;\n end\n % weight for the relaxation\n alpha = 1;\n if isfield(options, 'alpha')\n alpha = options.alpha;\n end\n % size of the matrix\n [M, N] = size(A);\n % Main optimization variable\n if isfield(options, 'x')\n x = options.x;\n else\n x = zeros(N, 1);\n end\n % Auxiliary optimization variable z = Ax - b\n % Goal of ADMM iterations is to bring z closer to Ax - b\n if isfield(options, 'z')\n z = options.z;\n else\n z = zeros(N, 1);\n end\n % scaled Lagrangian variable\n if isfield(options, 'u')\n u = options.u;\n else\n u = zeros(N, 1);\n end\n % verbosity\n verbose = 0;\n if isfield(options, 'verbose')\n verbose = options.verbose;\n end\n % Maximum number of ADMM iterations\n max_iterations = 1000;\n if isfield(options, 'max_iterations')\n max_iterations = options.max_iterations;\n end\n % absolute tolerance\n eps_abs = 1e-4;\n if isfield(options, 'absolute_tolerance')\n eps_abs = options.absolute_tolerance;\n end\n % relative tolerance\n eps_rel = 1e-2;\n if isfield(options, 'relative_tolerance')\n eps_rel = options.relative_tolerance;\n end\n % Compute and cache factorizations\n AAt = A*A';\n P = eye(N) - A' * (AAt\\A);\n % pseudo-inverse based solution of equation Ax=b\n q = A' * (AAt \\b);\n % import relevant functions\n import spx.opt.shrinkage;\n if verbose\n fprintf('%3s\\t%10s\\t%10s\\t%10s\\t%10s\\t%10s\\n', 'iter', ...\n 'r norm', 'eps pri', 's norm', 'eps dual', 'objective');\n end\n % perform ADMM iterations\n for k=1:max_iterations\n % preserve old value of z\n z_old = z;\n % update x as a projection on to the set {Ax = b}\n % we add the projection of (z-u) to the null-space of A and add\n % it to the pseudo-inverse solution of Ax = b\n x = P*(z-u) + q;\n % relaxation\n if alpha ~= 1\n x_hat = alpha*x + (1-alpha)*z;\n else\n x_hat = x;\n end\n % update z\n z = shrinkage(x_hat + u, 1/rho);\n % update u\n u = u + (x_hat - z);\n % primal residual\n r = x - z;\n r_norm = norm(r);\n % dual residual\n s = rho * (z_old - z);\n s_norm = norm(s);\n % upper bound on primal residual\n eps_primal = sqrt(N) * eps_abs + eps_rel * max([norm(x), norm(z)]);\n eps_dual = sqrt(N) * eps_abs + eps_rel * norm(rho*u);\n if verbose\n % value of objective function\n objective_value = objective(x);\n fprintf('%3d\\t%10.4f\\t%10.4f\\t%10.4f\\t%10.4f\\t%10.2f\\n', k, ...\n r_norm, eps_primal, s_norm, eps_dual, objective_value);\n end\n if r_norm < eps_primal && s_norm < eps_dual\n % We have achieved convergence\n break;\n end\n end\nend\n\n% objective value\nfunction obj = objective(x)\n obj = norm(x,1);\nend\n", "meta": {"author": "indigits", "repo": "sparse-plex", "sha": "43cae2978f62938d001baaa03308a2a717ee6c9b", "save_path": "github-repos/MATLAB/indigits-sparse-plex", "path": "github-repos/MATLAB/indigits-sparse-plex/sparse-plex-43cae2978f62938d001baaa03308a2a717ee6c9b/library/+spx/+opt/+admm/bp.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.905989822921759, "lm_q2_score": 0.8152324848629215, "lm_q1q2_score": 0.7385923346010239}} {"text": "% EX_ARTICLEV3_EXAMPLE51: simple example to generate multipatch objects of a two-patch geometry.\n%\n% The geometry is given by the two squares, [0,1] x [0,1] and [1,2] x [0,1],\n% defined with biquadratic splines.\n%\n% The code generates the multipatch msh and space, as in Example 5.1 of the paper:\n%\n% R. Vazquez, A new design for the implementation of isogeometric analysis \n% in Octave and Matlab: GeoPDEs 3.0. Tech, Report, IMATI-CNR, 2016\n%\n% Copyright (C) 2016 Rafael Vazquez\n%\n% This program is free software: you can redistribute it and/or modify\n% it under the terms of the GNU General Public License as published by\n% the Free Software Foundation, either version 3 of the License, or\n% (at your option) any later version.\n\n% This program is distributed in the hope that it will be useful,\n% but WITHOUT ANY WARRANTY; without even the implied warranty of\n% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n% GNU General Public License for more details.\n%\n% You should have received a copy of the GNU General Public License\n% along with this program. If not, see .\n\nnrb(1) = nrbdegelev (nrb4surf ([0 0], [1 0], [0 1], [1 1]), [1 1]);\nnrb(2) = nrbtform (nrb(1), vectrans([1 0 0]));\n\n[geometry, boundaries, interfaces, ~, boundary_interfaces] = mp_geo_load (nrb);\nnpatch = numel (geometry);\nfor iptc = 1:npatch\n knots = geometry(iptc).nurbs.knots;\n [qn, qw] = msh_set_quad_nodes (knots, msh_gauss_nodes (geometry(iptc).nurbs.order));\n \n local_meshes{iptc} = msh_cartesian (knots, qn, qw, geometry(iptc), 'der2', false);\n local_spaces{iptc} = sp_nurbs (geometry(iptc).nurbs, local_meshes{iptc});\nend\n\nmsh = msh_multipatch (local_meshes, boundaries);\nspace = sp_multipatch (local_spaces, msh, interfaces, boundary_interfaces);\n\ndisp ('Local to global numbering in space.gnum')\ndisp(['PATCH 1: ', num2str(space.gnum{1}.')])\ndisp(['PATCH 2: ', num2str(space.gnum{2}.')])\nfprintf('\\n')\n\ndisp ('Boundary information in msh.boundary')\ndisp (['patch_numbers: ', num2str(msh.boundary.patch_numbers)])\ndisp (['side_numbers: ', num2str(msh.boundary.side_numbers)])\nfprintf('\\n')\n\ndisp (['Number of boundary patches, in space.boundary.npatch: ', num2str(space.boundary.npatch)]);\nfprintf('\\n')\ndisp ('Local to global numbering in space.boundary.gnum:')\nfor ii = 1:space.boundary.npatch\n disp(['PATCH ',num2str(ii),': ', num2str(space.boundary.gnum{ii}.')]) \nend\nfprintf('\\n')\n\ndisp ('Boundary to volumetric numbering, in space.boundary.dofs')\ndisp (num2str(space.boundary.dofs.'))\n\nfprintf('\\n')\ndisp ('For the solution of problems in multipatch geometries, see also mp_solve_laplace.m')\n\n%!test\n%! nrb(1) = nrbdegelev (nrb4surf ([0 0], [1 0], [0 1], [1 1]), [1 1]);\n%! nrb(2) = nrbtform (nrb(1), vectrans([1 0 0]));\n%! [geometry, boundaries, interfaces, ~, boundary_interfaces] = mp_geo_load (nrb);\n%! npatch = numel (geometry);\n%! for iptc = 1:npatch\n%! knots = geometry(iptc).nurbs.knots;\n%! [qn, qw] = msh_set_quad_nodes (knots, msh_gauss_nodes (geometry(iptc).nurbs.order));\n%! local_meshes{iptc} = msh_cartesian (knots, qn, qw, geometry(iptc), 'der2', false);\n%! local_spaces{iptc} = sp_nurbs (geometry(iptc).nurbs, local_meshes{iptc});\n%! end\n%! msh = msh_multipatch (local_meshes, boundaries);\n%! space = sp_multipatch (local_spaces, msh, interfaces, boundary_interfaces);\n%! assert (space.gnum{1}(:), [1 2 13 3 4 14 5 6 15].');\n%! assert (space.gnum{2}(:), [13 7 8 14 9 10 15 11 12].');\n%! assert (msh.boundary.patch_numbers, [1 1 1 2 2 2]);\n%! assert (msh.boundary.side_numbers, [1 3 4 2 3 4]);\n%! assert (space.boundary.npatch, 6)\n%! assert (space.boundary.gnum{1}(:), [7 1 8].');\n%! assert (space.boundary.gnum{2}(:), [7 2 9].');\n%! assert (space.boundary.gnum{3}(:), [8 3 10].');\n%! assert (space.boundary.gnum{4}(:), [11 4 12].');\n%! assert (space.boundary.gnum{5}(:), [9 5 11].');\n%! assert (space.boundary.gnum{6}(:), [10 6 12].');\n%! assert (space.boundary.dofs(:), [3 2 6 10 7 11 1 5 13 15 8 12].');\n", "meta": {"author": "rafavzqz", "repo": "geopdes", "sha": "3bfa57b1a38bd4da3148536c9f67cce81afce701", "save_path": "github-repos/MATLAB/rafavzqz-geopdes", "path": "github-repos/MATLAB/rafavzqz-geopdes/geopdes-3bfa57b1a38bd4da3148536c9f67cce81afce701/geopdes/inst/examples/base/ex_articlev3_example51.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.905989815306765, "lm_q2_score": 0.8152324915965391, "lm_q1q2_score": 0.7385923344936224}} {"text": "function quad_error = monomial_quadrature ( dim_num, expon, point_num, ...\n weight, x, rule )\n\n%*****************************************************************************80\n%\n%% MONOMIAL_QUADRATURE applies a quadrature rule to a monomial.\n%\n% Discussion:\n%\n% This routine assumes that the integral being approximated is that of\n% a multidimensional monomial, integrated over the [-1,+1] hypercube,\n% with a Legendre weight (that is, w(x) = 1).\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 30 March 2008\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer DIM_NUM, the spatial dimension.\n%\n% Input, integer EXPON(DIM_NUM), the exponents.\n%\n% Input, integer POINT_NUM, the number of points in the rule.\n%\n% Input, real WEIGHT(POINT_NUM), the quadrature weights.\n%\n% Input, real X(DIM_NUM,POINT_NUM), the quadrature points.\n%\n% Input, integer RULE, the index of the rule.\n% 1, \"CC\", Clenshaw Curtis Closed Fully Nested rule.\n% 2, \"F1\", Fejer 1 Open Fully Nested rule.\n% 3, \"F2\", Fejer 2 Open Fully Nested rule.\n% 4, \"GP\", Gauss Patterson Open Fully Nested rule.\n% 5, \"GL\", Gauss Legendre Open Weakly Nested rule.\n% 6, \"GH\", Gauss Hermite Open Weakly Nested rule.\n% 7, \"LG\", Gauss Laguerre Open Non Nested rule.\n%\n% Output, real QUAD_ERROR, the quadrature error.\n%\n\n%\n% Get the exact value of the integral of the monomial.\n%\n if ( 1 <= rule & rule <= 5 )\n exact = monomial_integral_legendre ( dim_num, expon );\n elseif ( rule == 6 )\n exact = monomial_integral_hermite ( dim_num, expon );\n elseif ( rule == 7 )\n exact = monomial_integral_laguerre ( dim_num, expon );\n end \n%\n% Evaluate the monomial at the quadrature points.\n%\n value = monomial_value ( dim_num, point_num, x, expon );\n%\n% Compute the quadrature sum.\n%\n quad = weight * value';\n%\n% Absolute error if EXACT = 0, relative error otherwise:\n%\n if ( exact == 0.0 )\n quad_error = abs ( quad - exact );\n else\n quad_error = abs ( quad - exact ) / abs ( exact );\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/sandia_sparse/monomial_quadrature.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.905989822921759, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.7385923325674941}} {"text": "% book : Signals and Systems Laboratory with MATLAB \n% authors : Alex Palamides & Anastasia Veloni\n\n\n% DFT of a circularly shifted sequence\n\n\n\n% circular shift in time \nx=[ 1 0 3 4 7];\nm=2;\nxc=circshift(x',m);\nLeft=dft(xc);\nLeft.'\n\nX=dft(x);\nN=length(x);\nk=0:N-1;\nRight=X.*exp(-j*2*pi*m*k/N);\nRight.'\n\n\n% circular shift in frequency \nx=[ 1 0 3 4 7];\nN=length(x);\nn=0:N-1;\nm=2;\nLeft=dft(x.*exp(j*2*pi*n*m/N));\nLeft.'\n\nX=dft(x);\nRight=circshift(X.',m)\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/28762-signals-and-systems-laboratory-with-matlab-m-files/M-FILES/7/c77_1.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9059898153067649, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.738592330426563}} {"text": "function Res = AccSumK(p,K)\n%ACCSUMK Res represents K-fold faithful rounding of sum(p)\n%\n% Res = AccSumK(p,K)\n%\n%On return, Res represents a K-fold faithful rounding of sum(p), also in the \n% presence of underflow. Input vector p may be single or double precision.\n%\n%Implements Algorithm 6.4 from\n% S.M. Rump, T. Ogita, S. Oishi: Accurate Floating-point Summation II: \n% Sign, K-fold Faithful and Rounding to Nearest, Siam J. Sci. Comput., \n% 31(2):1269-1302, 2008.\n%Requires (4m+5K+3)n flops for m executions of repeat-until loop in the\n% first and one execution of the repeat-until loops in subsequent calls\n% of TransformK.\n%\n%Reference implementation! Slow due to interpretation!\n%\n\n% written 03/03/07 S.M. Rump\n% modified 05/09/09 S.M. Rump rounding to nearest, complex input\n%\n\n if ~isreal(p)\n Res = complex(AccSumK(real(p),K),AccSumK(imag(p),K));\n return\n end\n \n e = 1e-30;\n if 1+e==1-e % fast check for rounding to nearest\n rndold = 0;\n else\n rndold = getround;\n setround(0)\n end\n\n if isa(p,'double')\n nmax = 2^26-2; % nmax = 67,108,864\n else\n nmax = 2^12-2; % nmax = 4,094\n end\n if length(p)>nmax\n error(['maximum length of input vector for AccSumK ' int2str(nmax) '.'])\n end\n\n R = 0;\n if isa(p,'double'), prec='double'; else prec='single'; end\n Res = zeros(1,K,prec);\n [Res(1),R,p,sigma,Ms] = TransformK(p,R);\n if abs(Res(1))<=realmin(prec)\n if rndold, setround(rndold); end\n return\n end\n for k=2:K\n [Res(k),R,p,sigma,Ms] = TransformK(p,R,sigma,Ms);\n if abs(Res(k))<=realmin(prec)\n if rndold, setround(rndold); end\n return\n end\n end\n \n if rndold\n setround(rndold)\n end\n", "meta": {"author": "douthwja01", "repo": "OpenMAS", "sha": "962f321f82167db78066b2c88c783423ecc3b73a", "save_path": "github-repos/MATLAB/douthwja01-OpenMAS", "path": "github-repos/MATLAB/douthwja01-OpenMAS/OpenMAS-962f321f82167db78066b2c88c783423ecc3b73a/toolboxes/Intlab_V7.1/accsumdot/AccSumK.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.908617906830944, "lm_q2_score": 0.8128673201042492, "lm_q1q2_score": 0.7385858029244019}} {"text": "%% Transient diffusion equation evaluated using FVTool\n%\n% adapted from A.A. Eftekhari by M.H.V. Werts (2020) \n%\n% GNU Octave 4.2.2 was used for development\n%\n% This script is intended to be run from the command line interface. \n% It is called in this manner from within the accompanying Jupyter \n% Python notebook. \n%\n% It should be inside the 'FVTool' directory tree as downloaded/cloned\n% from Github, under \n% './Examples/External/Diffusion1DSpherical_Analytic-vs-FVTool-vs-Fipy'\n%\n% Script calculates diffusion in a 1D spherical geometry for an 'infinite' \n% medium, with the initial condition that all mass at $t = 0$ is \n% homogeneously confined inside a sphere of radius $a$. This is sometimes\n% called a 'spherical initial condition'.\n%\n% see J. Crank (1975) \"The Mathematics of Diffusion\", 2nd Ed., \n% Clarendon Press (Oxford), pages 29-30 \n% Equation 3.8, Figure 3.1\n%\n% The transient diffusion equation reads\n%\n% $$\\alpha\\frac{\\partial c}{\\partial t}+\\nabla.\\left(-D\\nabla c\\right)=0,$$\n%\n% where $c$ is the independent variable (concentration, temperature, etc),\n% $D$ is the diffusion coefficient, and $\\alpha$ is a constant (1, here).\n%\n%\nclc; clear;\nmore off;\nrun('../../../FVToolStartUp.m')\n\n%% Define the domain and create a mesh structure\n% Here we work in a 1D spherical coordinate system (r coordinate)\nL = 10.0; % domain length\nNx = 2000; % number of cells\nm = createMeshSpherical1D(Nx, L);\n\n%% Create the boundary condition structure\nBC = createBC(m); % all Neumann boundary condition structure\n\n%% define the transfer coeffs\nD = createCellVariable(m, 1.0);\nalfa = createCellVariable(m, 1.0);\n\n%% define initial condition\nc_init = 0;\nc_old = createCellVariable(m, c_init, BC); % initial values\nr = c_old.domain.cellcenters.x;\nc_old.value(r<1.0) = 1.0;\n\n%% calculate volumes of FV cellslices\n% We use this for demonstrating mass conservation\ncellA = m.facecenters.x(1:end-1);\ncellB = m.facecenters.x(2:end);\ncellvol = 4/3 .* pi .* (cellB.^3 - cellA.^3);\ncellsum = sum(cellvol)\n\nc = c_old; % assign the old value of the cells to the current values\n\nt = 0.0; % master time\ndeltat = 0.0625/20; % time step\n\n% output total mass in the system\nm_tot = sum(c.value(2:end-1) .* cellvol);\nt,m_tot\n\n%% loop for \"time-stepping\" the solution\n% It outputs the spatial profile C(r) after\n% 20, 80 and 320 time-steps\n% This corresponds to t=0.0625, t=0.25 and t=1, respectively.\nti = 0\nfor s=[20,60,240]\n for n=1:s\n [M_trans, RHS_trans] = transientTerm(c, deltat, alfa);\n Dave = harmonicMean(D);\n Mdiff = diffusionTerm(Dave);\n [Mbc, RHSbc] = boundaryCondition(BC);\n M = M_trans-Mdiff+Mbc;\n RHS = RHS_trans+RHSbc;\n c = solvePDE(m,M, RHS);\n t += deltat;\n c_old = c;\n endfor\n m_tot = sum(c.value(2:end-1) .* cellvol);\n n,t,m_tot\n % The following writes the result to a file\n % adapted from visualizeCells with domain.dimension = 1.8\n x = [c.domain.facecenters.x(1); c.domain.cellcenters.x; c.domain.facecenters.x(end)];\n cval = [0.5*(c.value(1)+c.value(2)); c.value(2:end-1); 0.5*(c.value(end-1)+c.value(end))];\n ti += s;\n filename = [\"diffusion1Dspherical_FVTool_tstep\",num2str(ti),\".mat\"]\n save('-6',filename,'x','cval');\nendfor\n\n", "meta": {"author": "simulkade", "repo": "FVTool", "sha": "49f5cb9ee8a5ff0befebd9fa71a99feae7c724d6", "save_path": "github-repos/MATLAB/simulkade-FVTool", "path": "github-repos/MATLAB/simulkade-FVTool/FVTool-49f5cb9ee8a5ff0befebd9fa71a99feae7c724d6/Examples/External/Diffusion1DSpherical_Analytic-vs-FVTool-vs-Fipy/diffusion1Dspherical_FVTool.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179043564153, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.7385857947343116}} {"text": "% book : Signals and Systems Laboratory with MATLAB \n% authors : Alex Palamides & Anastasia Veloni\n%\n% \n% \tSystem response to sinusoidal inputs \n\n\nt=0:.1:30;\nx1=3*cos(t+pi/3);\nplot(t,x1);\nlegend('input signal x(t)')\nylim([-4 4]);\n\nfigure\nw0=1;\nHw0=(3*(j*w0)^2+4j*w0+2)/(-w0^2+j*w0+3)\nmagn=abs(Hw0)\nphas=angle(Hw0)\ny1=3*abs(Hw0)*cos(t+pi/3+angle(Hw0));\nplot(t,y1);\nlegend('system response')\nylim([-7 7]);\n\nfigure\nnum=[3 4 2];\nden=[1 1 3];\nyls=lsim(num,den,x1,t);\nplot(t,yls);\nlegend('system response by lsim')\n\n\nfigure\nplot(t,x1,t,y1,'o')\nlegend('x(t)','y(t)')\nylim([-7 9]);\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/28762-signals-and-systems-laboratory-with-matlab-m-files/M-FILES/8/c84a.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178919837705, "lm_q2_score": 0.8128673110375458, "lm_q1q2_score": 0.7385857826174508}} {"text": "% l1qc_logbarrier.m\n%\n% Solve quadratically constrained l1 minimization:\n% min ||x||_1 s.t. ||Ax - b||_2 <= \\epsilon\n%\n% Reformulate as the second-order cone program\n% min_{x,u} sum(u) s.t. x - u <= 0,\n% -x - u <= 0,\n% 1/2(||Ax-b||^2 - \\epsilon^2) <= 0\n% and use a log barrier algorithm.\n%\n% Usage: xp = l1qc_logbarrier(x0, A, At, b, epsilon, lbtol, mu, cgtol, cgmaxiter)\n%\n% x0 - Nx1 vector, initial point.\n%\n% A - Either a handle to a function that takes a N vector and returns a K \n% vector , or a KxN matrix. If A is a function handle, the algorithm\n% operates in \"largescale\" mode, solving the Newton systems via the\n% Conjugate Gradients algorithm.\n%\n% At - Handle to a function that takes a K vector and returns an N vector.\n% If A is a KxN matrix, At is ignored.\n%\n% b - Kx1 vector of observations.\n%\n% epsilon - scalar, constraint relaxation parameter\n%\n% lbtol - The log barrier algorithm terminates when the duality gap <= lbtol.\n% Also, the number of log barrier iterations is completely\n% determined by lbtol.\n% Default = 1e-3.\n%\n% mu - Factor by which to increase the barrier constant at each iteration.\n% Default = 10.\n%\n% cgtol - Tolerance for Conjugate Gradients; ignored if A is a matrix.\n% Default = 1e-8.\n%\n% cgmaxiter - Maximum number of iterations for Conjugate Gradients; ignored\n% if A is a matrix.\n% Default = 200.\n%\n% Written by: Justin Romberg, Caltech\n% Email: jrom@acm.caltech.edu\n% Created: October 2005\n%\n\nfunction xp = l1qc_logbarrier(x0, A, At, b, epsilon, lbtol, mu, cgtol, cgmaxiter) \n\nlargescale = isa(A,'function_handle');\n\nif (nargin < 6), lbtol = 1e-3; end\nif (nargin < 7), mu = 10; end\nif (nargin < 8), cgtol = 1e-8; end\nif (nargin < 9), cgmaxiter = 200; end\n\nnewtontol = lbtol;\nnewtonmaxiter = 50;\n\nN = length(x0);\n\n% starting point --- make sure that it is feasible\nif (largescale)\n if (norm(A(x0)-b) > epsilon)\n disp('Starting point infeasible; using x0 = At*inv(AAt)*y.');\n AAt = @(z) A(At(z));\n [w, cgres] = cgsolve(AAt, b, cgtol, cgmaxiter, 0);\n if (cgres > 1/2)\n disp('A*At is ill-conditioned: cannot find starting point');\n xp = x0;\n return;\n end\n x0 = At(w);\n end\nelse\n if (norm(A*x0-b) > epsilon)\n disp('Starting point infeasible; using x0 = At*inv(AAt)*y.');\n opts.POSDEF = true; opts.SYM = true;\n [w, hcond] = linsolve(A*A', b, opts);\n if (hcond < 1e-14)\n disp('A*At is ill-conditioned: cannot find starting point');\n xp = x0;\n return;\n end\n x0 = A'*w;\n end \nend\nx = x0;\nu = (0.95)*abs(x0) + (0.10)*max(abs(x0));\n\n% disp(sprintf('Original l1 norm = %.3f, original functional = %.3f', sum(abs(x0)), sum(u)));\n\n% choose initial value of tau so that the duality gap after the first\n% step will be about the origial norm\ntau = max((2*N+1)/sum(abs(x0)), 1);\n \nlbiter = ceil((log(2*N+1)-log(lbtol)-log(tau))/log(mu));\n% disp(sprintf('Number of log barrier iterations = %d\\n', lbiter));\n\ntotaliter = 0;\ndispProgress('Log barrier', 0, lbiter);\nfor ii = 1:lbiter\n\n [xp, up, ntiter] = l1qc_newton(x, u, A, At, b, epsilon, tau, newtontol, newtonmaxiter, cgtol, cgmaxiter);\n totaliter = totaliter + ntiter;\n \n% disp(sprintf('\\nLog barrier iter = %d, l1 = %.3f, functional = %8.3f, tau = %8.3e, total newton iter = %d\\n', ...\n% ii, sum(abs(xp)), sum(up), tau, totaliter));\n dispProgress('Log barrier',ii/lbiter);\n \n x = xp;\n u = up;\n \n tau = mu*tau;\n \nend\ndispProgress('Log barrier', 'Close');\n\nend\n \n", "meta": {"author": "thomaskuestner", "repo": "CS_MoCo_LAB", "sha": "a26e8e483624b2e4ee669e7a069ba9c74d2d2e4b", "save_path": "github-repos/MATLAB/thomaskuestner-CS_MoCo_LAB", "path": "github-repos/MATLAB/thomaskuestner-CS_MoCo_LAB/CS_MoCo_LAB-a26e8e483624b2e4ee669e7a069ba9c74d2d2e4b/reconstruction/matlab/CS_LAB_matlab/@L1_Magic/private/l1qc_logbarrier.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942014971871, "lm_q2_score": 0.8175744717487329, "lm_q1q2_score": 0.7385102796227562}} {"text": "function [f_alias, cond_N] = sphArrayAliasLim(R, Nmic, maxN, mic_dirs_rad, mic_weights)\n%SPHARRAYALIASLIM Get estimates of the aliasing limit of a spherical array\n% \n% First estimate takes into account only the radius and a nominal order\n% that the array is expected to support, it is the simplest one and it\n% expresses the kR = maxN rule.\n% The second estimate is based on the number of microphones, and it can\n% be more relaxed than the first, if the nominal supported order is less\n% than maxN\n% \n% GIBBON: The Geometry and Image-based Bioengineering add-On. A toolbox for\n% image segmentation, image-based modeling, meshing, and finite element\n% analysis.\n% \n% Copyright (C) 2006-2022 Kevin Mattheus Moerman and the GIBBON contributors\n% \n% This program is free software: you can redistribute it and/or modify\n% it under the terms of the GNU General Public License as published by\n% the Free Software Foundation, either version 3 of the License, or\n% (at your option) any later version.\n% \n% This program is distributed in the hope that it will be useful,\n% but WITHOUT ANY WARRANTY; without even the implied warranty of\n% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n% GNU General Public License for more details.\n% \n% You should have received a copy of the GNU General Public License\n% along with this program. If not, see .\n", "meta": {"author": "gibbonCode", "repo": "GIBBON", "sha": "8178520664a6148db939eaea87e75b3cba4f2b4f", "save_path": "github-repos/MATLAB/gibbonCode-GIBBON", "path": "github-repos/MATLAB/gibbonCode-GIBBON/GIBBON-8178520664a6148db939eaea87e75b3cba4f2b4f/lib/gauss_kernel.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094174159127, "lm_q2_score": 0.8267117919359419, "lm_q1q2_score": 0.7385094292251615}} {"text": "function [ v, more ] = tetrahedron_lattice_layer_point_next ( c, v, more )\n\n%*****************************************************************************80\n%\n%% TETRAHEDRON_LATTICE_LAYER_POINT_NEXT: next tetrahedron lattice layer point.\n%\n% Discussion:\n%\n% The tetrahedron lattice layer L is bounded by the lines\n%\n% 0 <= X,\n% 0 <= Y,\n% 0 <= Z,\n% L - 1 < X / C(1) + Y / C(2) + Z/C(3) <= L.\n%\n% In particular, layer L = 0 always contains the single point (0,0).\n%\n% This function returns, one at a time, the points that lie within \n% a given tetrahedron lattice layer.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 08 July 2009\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer C(4), coefficients defining the \n% lattice layer in entries 1 to 3, and the laver index in C(4). \n% The coefficients should be positive, and C(4) must be nonnegative.\n%\n% Input/output, integer V(3). On first call for a given layer,\n% the input value of V is not important. On a repeated call for the same\n% layer, the input value of V should be the output value from the previous \n% call. On output, V contains the next lattice layer point.\n%\n% Input/output, logical MORE. On input, set MORE to FALSE to indicate\n% that this is the first call for a given layer. Thereafter, the input\n% value should be the output value from the previous call. On output,\n% MORE is TRUE if the returned value V is a new point.\n% If the output value is FALSE, then no more points were found,\n% and V was reset to 0, and the lattice layer has been exhausted.\n%\n n = 3;\n%\n% Treat layer C(N+1) = 0 specially.\n%\n if ( c(n+1) == 0 )\n if ( ~more )\n v(1:n) = 0;\n more = 1;\n else\n more = 0;\n end\n return\n end\n%\n% Compute the first point.\n%\n if ( ~more )\n\n v(1) = ( c(n+1) - 1 ) * c(1) + 1;\n v(2:3) = 0;\n more = 1;\n\n else\n\n c1n = i4vec_lcm ( n, c );\n\n rhs1 = c1n * ( c(n+1) - 1 );\n rhs2 = c1n * c(n+1);\n%\n% Can we simply increase X?\n%\n v(1) = v(1) + 1;\n\n lhs = ( c1n / c(1) ) * v(1) ...\n + ( c1n / c(2) ) * v(2) ...\n + ( c1n / c(3) ) * v(3);\n\n if ( lhs <= rhs2 )\n%\n% No. Increase Y, and set X so we just exceed RHS1...if possible.\n%\n else\n\n v(2) = v(2) + 1;\n\n v(1) = floor ( ( c(1) * ( rhs1 - ( c1n / c(2) ) * v(2) ...\n - ( c1n / c(3) ) * v(3) ) ) / c1n );\n v(1) = max ( v(1), 0 );\n\n lhs = ( c1n / c(1) ) * v(1) ...\n + ( c1n / c(2) ) * v(2) ...\n + ( c1n / c(3) ) * v(3);\n\n if ( lhs <= rhs1 )\n v(1) = v(1) + 1;\n lhs = lhs + c1n / c(1);\n end\n%\n% We have increased Y by 1. Have we stayed below the upper bound?\n%\n if ( lhs <= rhs2 )\n\n else\n%\n% No. Increase Z, and set X so we just exceed RHS1...if possible.\n%\n v(3) = v(3) + 1;\n v(2) = 0;\n v(1) = floor ( ( c(1) * ( rhs1 - ( c1n / c(2) ) * v(2) ...\n - ( c1n / c(3) ) * v(3) ) ) / c1n );\n v(1) = max ( v(1), 0 );\n\n lhs = ( c1n / c(1) ) * v(1) ...\n + ( c1n / c(2) ) * v(2) ...\n + ( c1n / c(3) ) * v(3);\n\n if ( lhs <= rhs1 )\n v(1) = v(1) + 1;\n lhs = lhs + c1n / c(1);\n end\n\n if ( lhs <= rhs2 )\n\n else\n more = 0;\n v(1:n) = 0;\n end\n\n end\n end\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/geometry/tetrahedron_lattice_layer_point_next.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.8267118004748677, "lm_q1q2_score": 0.7385094227639556}} {"text": "function [ n_data, x, fx ] = cin_values ( n_data )\n\n%*****************************************************************************80\n%\n%% CIN_VALUES returns some values of the alternate cosine integral function.\n%\n% Discussion:\n%\n% The alternate cosine integral is defined by\n%\n% CIN(X) = gamma + log(X) + integral ( 0 <= T <= X ) ( cos ( T ) - 1 ) / T dT\n%\n% In Mathematica, the function can be evaluated by:\n%\n% EulerGamma + Log[x] - CosIntegral[x]\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 16 September 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Milton Abramowitz and Irene Stegun,\n% Handbook of Mathematical Functions,\n% US Department of Commerce, 1964.\n%\n% Stephen Wolfram,\n% The Mathematica Book,\n% Fourth Edition,\n% Wolfram Media / Cambridge University Press, 1999.\n%\n% Parameters:\n%\n% Input/output, integer N_DATA. The user sets N_DATA to 0 before the\n% first call. On each call, the routine increments N_DATA by 1, and\n% returns the corresponding data; when there is no more data, the\n% output value of N_DATA will be 0 again.\n%\n% Output, real X, the argument of the function.\n%\n% Output, real FX, the value of the function.\n%\n n_max = 16;\n\n fx_vec = [ ...\n 0.6185256314820045E-01, ...\n 0.8866074809482194E-01, ...\n 0.1200260139539026E+00, ...\n 0.1557934976348559E+00, ...\n 0.1957873187759337E+00, ...\n 0.2398117420005647E+00, ...\n 0.3390780388012470E+00, ...\n 0.4516813164280685E+00, ...\n 0.5754867772153906E+00, ...\n 0.7081912003853150E+00, ...\n 0.8473820166866132E+00, ...\n 0.1207635200410304E+01, ...\n 0.1556198167561642E+01, ...\n 0.1862107181909382E+01, ...\n 0.2104491723908354E+01, ...\n 0.2274784183779546E+01 ];\n\n x_vec = [ ...\n 0.5E+00, ...\n 0.6E+00, ...\n 0.7E+00, ...\n 0.8E+00, ...\n 0.9E+00, ...\n 1.0E+00, ...\n 1.2E+00, ...\n 1.4E+00, ...\n 1.6E+00, ...\n 1.8E+00, ...\n 2.0E+00, ...\n 2.5E+00, ...\n 3.0E+00, ...\n 3.5E+00, ...\n 4.0E+00, ... \n 4.5E+00 ];\n\n if ( n_data < 0 )\n n_data = 0;\n end\n\n n_data = n_data + 1;\n\n if ( n_max < n_data )\n n_data = 0;\n x = 0.0;\n fx = 0.0;\n else\n x = x_vec(n_data);\n fx = fx_vec(n_data);\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_values/cin_values.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093946927838, "lm_q2_score": 0.8267117919359419, "lm_q1q2_score": 0.7385094104396829}} {"text": "function [w, A, C, sbc, fpe, th]=ARFIT_arfit(v, pmin, pmax, selector, no_const)\n%ARFIT\tStepwise least squares estimation of multivariate AR model.\n%\n% [w,A,C,SBC,FPE,th]=ARFIT(v,pmin,pmax) produces estimates of the\n% parameters of an m-variate AR model of order p,\n%\n% v(k,:)' = w' + A1*v(k-1,:)' +...+ Ap*v(k-p,:)' + noise(C),\n%\n% where w is the (m x 1) intercept vector, A1, ..., Ap are (m x m)\n% coefficient matrices, and C is a (m x m) noise covariance\n% matrix. The estimated order p lies between pmin and pmax and is\n% chosen as the optimizer of Schwarz's Bayesian Criterion. \n% \n% The input matrix v must contain the time series data, with\n% columns v(:,l) representing m variables l=1,...,m and rows\n% v(k,:) representing n observations at different (equally\n% spaced) times k=1,..,n. Optionally, v can have a third\n% dimension, in which case the matrices v(:,:, itr) represent \n% the realizations (e.g., measurement trials) itr=1,...,ntr of the\n% time series. ARFIT returns least squares estimates of the\n% intercept vector w, of the coefficient matrices A1,...,Ap (as\n% A=[A1 ... Ap]), and of the noise covariance matrix C.\n%\n% As order selection criteria, ARFIT computes approximations to\n% Schwarz's Bayesian Criterion and to the logarithm of Akaike's Final\n% Prediction Error. The order selection criteria for models of order\n% pmin:pmax are returned as the vectors SBC and FPE.\n%\n% The matrix th contains information needed for the computation of\n% confidence intervals. ARMODE and ARCONF require th as input\n% arguments.\n% \n% If the optional argument SELECTOR is included in the function call,\n% as in ARFIT(v,pmin,pmax,SELECTOR), SELECTOR is used as the order\n% selection criterion in determining the optimum model order. The\n% three letter string SELECTOR must have one of the two values 'sbc'\n% or 'fpe'. (By default, Schwarz's criterion SBC is used.) If the\n% bounds pmin and pmax coincide, the order of the estimated model\n% is p=pmin=pmax. \n%\n% If the function call contains the optional argument 'zero' as the\n% fourth or fifth argument, a model of the form\n%\n% v(k,:)' = A1*v(k-1,:)' +...+ Ap*v(k-p,:)' + noise(C) \n%\n% is fitted to the time series data. That is, the intercept vector w\n% is taken to be zero, which amounts to assuming that the AR(p)\n% process has zero mean.\n%\n% Modified 14-Oct-00\n% 24-Oct-10 Tim Mullen (added support for multiple realizatons)\n%\n% Authors: Tapio Schneider\n% tapio@gps.caltech.edu\n%\n% Arnold Neumaier\n% neum@cma.univie.ac.at\n\n % n: number of time steps (per realization)\n % m: number of variables (dimension of state vectors) \n % ntr: number of realizations (trials)\n [n,m,ntr] = size(v); \n\n if (pmin ~= round(pmin) | pmax ~= round(pmax))\n error('Order must be integer.');\n end\n if (pmax < pmin)\n error('PMAX must be greater than or equal to PMIN.')\n end\n\n % set defaults and check for optional arguments\n if (nargin == 3) % no optional arguments => set default values\n mcor = 1; % fit intercept vector\n selector = 'sbc';\t % use SBC as order selection criterion\n elseif (nargin == 4) % one optional argument\n if strcmp(selector, 'zero')\n mcor = 0; % no intercept vector to be fitted\n selector = 'sbc';\t % default order selection \n else\n mcor = 1; \t\t % fit intercept vector\n end\n elseif (nargin == 5) % two optional arguments\n if strcmp(no_const, 'zero')\n mcor = 0; % no intercept vector to be fitted\n else\n error(['Bad argument. Usage: ', ...\n\t '[w,A,C,SBC,FPE,th]=AR(v,pmin,pmax,SELECTOR,''zero'')'])\n end\n end\n\n ne \t= ntr*(n-pmax); % number of block equations of size m\n npmax\t= m*pmax+mcor; % maximum number of parameter vectors of length m\n\n if (ne <= npmax)\n error('Time series (N = %u) too short.',size(v,1))\n end\n\n % compute QR factorization for model of order pmax\n [R, scale] = ARFIT_arqr(v, pmax, mcor);\n\n % compute approximate order selection criteria for models \n % of order pmin:pmax\n [sbc, fpe] = ARFIT_arord(R, m, mcor, ne, pmin, pmax);\n\n % get index iopt of order that minimizes the order selection \n % criterion specified by the variable selector\n [val, iopt] = min(eval(selector)); \n\n % select order of model\n popt = pmin + iopt-1; % estimated optimum order \n np = m*popt + mcor; % number of parameter vectors of length m\n\n % decompose R for the optimal model order popt according to \n %\n % | R11 R12 |\n % R=| |\n % | 0 R22 |\n %\n R11 = R(1:np, 1:np);\n R12 = R(1:np, npmax+1:npmax+m); \n R22 = R(np+1:npmax+m, npmax+1:npmax+m);\n\n % get augmented parameter matrix Aaug=[w A] if mcor=1 and Aaug=A if mcor=0\n if (np > 0) \n if (mcor == 1)\n % improve condition of R11 by re-scaling first column\n con \t= max(scale(2:npmax+m)) / scale(1); \n R11(:,1)\t= R11(:,1)*con; \n end;\n Aaug = (R11\\R12)';\n \n % return coefficient matrix A and intercept vector w separately\n if (mcor == 1)\n % intercept vector w is first column of Aaug, rest of Aaug is \n % coefficient matrix A\n w = Aaug(:,1)*con; % undo condition-improving scaling\n A = Aaug(:,2:np);\n else\n % return an intercept vector of zeros \n w = zeros(m,1);\n A = Aaug;\n end\n else\n % no parameters have been estimated \n % => return only covariance matrix estimate and order selection \n % criteria for ``zeroth order model'' \n w = zeros(m,1);\n A = [];\n end\n \n % return covariance matrix\n dof = ne-np; % number of block degrees of freedom\n C = R22'*R22./dof; % bias-corrected estimate of covariance matrix\n \n % for later computation of confidence intervals return in th: \n % (i) the inverse of U=R11'*R11, which appears in the asymptotic \n % covariance matrix of the least squares estimator\n % (ii) the number of degrees of freedom of the residual covariance matrix \n invR11 = inv(R11);\n if (mcor == 1)\n % undo condition improving scaling\n invR11(1, :) = invR11(1, :) * con;\n end\n Uinv = invR11*invR11';\n th = [dof zeros(1,size(Uinv,2)-1); Uinv];\n\n\n\n", "meta": {"author": "benfulcher", "repo": "hctsa", "sha": "919f2aed7cc8e1a3a03304c1ade573fa664c73f8", "save_path": "github-repos/MATLAB/benfulcher-hctsa", "path": "github-repos/MATLAB/benfulcher-hctsa/hctsa-919f2aed7cc8e1a3a03304c1ade573fa664c73f8/Toolboxes/ARFIT/ARFIT_arfit.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093975331752, "lm_q2_score": 0.8267117876664789, "lm_q1q2_score": 0.7385094089739165}} {"text": "function BPI = myFilteredBackprojectionCentralSlice(sinogram,thetas)\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% filtered back projection in the frequency domain applying central slice\n% theorem-> schlegel & bille 9.2.3\n% modified by: Mark Bangert\n% m.bangert@dkfz.de 2011\n%\n% note: a) matlab puts the 0 frequency component of a fourier spectrum _not_\n% in the middle. we need to fumble around with fftshift.\n\n% figure out how big our picture is going to be.\nnumOfParallelProjections = size(sinogram,1);\nnumOfAngularProjections = length(thetas); \n\n% convert thetas to radians\nthetas = (pi/180)*thetas;\n\n% set up the backprojected image\nBPI = zeros(numOfParallelProjections,numOfParallelProjections);\n\n% find the middle index of the projections\nmidindex = floor(numOfParallelProjections/2) + 1;\n\n% set up the coords of the image\n[xCoords,yCoords] = meshgrid(ceil(-numOfParallelProjections/2):ceil(numOfParallelProjections/2-1));\n\n% set up filter\nrampFilter = [floor(numOfParallelProjections/2):-1:0 1:ceil(numOfParallelProjections/2-1)]';\n\n% loop over each projection\nfor i = 1:numOfAngularProjections\n\n % figure out which projections to add to which spots\n rotCoords = round(midindex + xCoords*sin(thetas(i)) + yCoords*cos(thetas(i)));\n\n % check which coords are in bounds\n indices = find((rotCoords > 0) & (rotCoords <= numOfParallelProjections));\n newCoords = rotCoords(indices);\n \n % filter\n filteredProfile = real( ifft( ifftshift( rampFilter.*fftshift(fft(sinogram(:,i)) ) ) ) );\n\n % summation\n BPI(indices) = BPI(indices) + filteredProfile(newCoords)./numOfAngularProjections;\n \n % visualization on the fly\n imagesc(BPI)\n drawnow\n\nend\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/34608-ct-reconstruction-package/ctRecontruction/myFilteredBackprojectionCentralSlice.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92522995296862, "lm_q2_score": 0.798186784940666, "lm_q1q2_score": 0.7385063214908264}} {"text": "function [result] = nonLocalMeans(image, sigma, h, patchSize, windowSize, rgb)\n \n % the code is very similar to what we did in\n % \"nonLocalMeansWithoutIntegral\" and \"TemplateMatchingIntegralImage\"\n image = double(image);\n delta_window = floor(windowSize/2);\n delta = floor(patchSize/2);\n result = image;\n \n [rows, columns, dimensions] = size(image);\n \n tic\n integralImagesCell = cell(windowSize, windowSize);\n \n % All the attempts made to store and to compute the integral images are \n % explained in the \"templateMatchingIntegralImage\" file\n \n for row_searchWindow = -delta_window:delta_window\n for column_searchWindow = -delta_window:delta_window\n \n xOffset = row_searchWindow;\n yOffset = column_searchWindow;\n \n shifted_image = imtranslate(image,[yOffset, xOffset]);\n\n %integral_image = computeIntegralImage((shifted_image-image).^2, false);\n % NOTE MATLAB funciton is obviously faster\n integral_image = integralImage((shifted_image-image).^2);\n \n integralImagesCell{xOffset+delta_window+1, yOffset+delta_window+1} = integral_image;\n \n end\n end\n toc\n \n \n for row = 1+delta:rows-delta\n \n % clip the searchWindow\n start_rows = max(row-delta_window, 1+delta);\n end_rows = min(row+delta_window, rows-delta);\n \n for col = 1+delta:columns-delta\n \n start_columns = max(col-delta_window, 1+delta);\n end_columns = min(col+delta_window, columns-delta);\n \n % the same values in the other non local means version\n weighted_sum = 0;\n weight_sum = 0;\n \n % Loop through all the pixels in the SearchWindow \n for row_searchWindow = start_rows : end_rows\n for column_searchWindow = start_columns : end_columns\n \n xOffset = row_searchWindow - row;\n yOffset = column_searchWindow - col;\n \n % retrive the Integral Image for the corresponding\n % offset\n integral_image = integralImagesCell{xOffset+delta_window+1, yOffset+delta_window+1};\n \n % Compute the distance (how is explained inside the function)\n distance = evaluateIntegralImage(integral_image, row_searchWindow, column_searchWindow, delta);\n \n %compute the weights\n weight = computeWeighting(distance, h, sigma, patchSize);\n \n % compute the weighted sum\n weighted_sum = weighted_sum + (double(image(row_searchWindow,column_searchWindow, :)) * weight);\n \n % keep adding the weights in order to normalize.\n weight_sum = weight_sum + weight;\n end\n end\n \n % store the resulting denoised pixel at location (row, col)\n result(row, col, :) = (weighted_sum/weight_sum);\n \n end\n end\n \n % We need to normalize to actually see something otherwise is going to\n % bee too bright.\n result = 255*(result - min(result(:))) / (max(result(:)) - min(result(:)));\n result = uint8(result);\n\nend\n\n", "meta": {"author": "zhangqianqianQQ", "repo": "MachineVisionAlgorithm", "sha": "683338f6c3b1aab9fa2b80026915fe936aebf0ee", "save_path": "github-repos/MATLAB/zhangqianqianQQ-MachineVisionAlgorithm", "path": "github-repos/MATLAB/zhangqianqianQQ-MachineVisionAlgorithm/MachineVisionAlgorithm-683338f6c3b1aab9fa2b80026915fe936aebf0ee/\u53bb\u566a\u7b97\u6cd5/Non-Local-Means-master/nonLocalMeans.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92522995296862, "lm_q2_score": 0.7981867777396211, "lm_q1q2_score": 0.738506314828204}} {"text": "clear all; close all;\n\n% The data\nx=[1 2 3 4 5 6 7 8 9 10]\ny=[0.2 0.5 0.3 3.5 1.0 1.5 1.8 2.0 2.3 2.2]\n\np1=fminsearch('fit1',[1 1],[],x,y);\np2=fminsearch('fit2',[1 1],[],x,y);\np3=fminsearch('fit3',[1 1],[],x,y);\n\nxf=0:0.1:11\ny1=polyval(p1,xf); y2=polyval(p2,xf); y3=polyval(p3,xf);\n\nsubplot(2,1,2)\nplot(xf,y1,'k'), hold on\nplot(xf,y2,'k--','Linewidth',[2])\nplot(xf,y3,'k','Linewidth',[2])\nplot(x,y,'ro','Linewidth',[2]), hold on\n\nlegend('E_\\infty','E_1','E_2','location','NorthWest')\nset(gca,'Fontsize',[15],'Ylim',[0 4],'Ytick',[0 1 2 3 4],'Xlim',[0 11],'Xtick',[0 2 4 6 8 10])\n\nx=[1 2 3 4 5 6 7 8 9 10]\ny=[0.2 0.5 0.3 0.7 1.0 1.5 1.8 2.0 2.3 2.2]\n\np1=fminsearch('fit1',[1 1],[],x,y);\np2=fminsearch('fit2',[1 1],[],x,y);\np3=fminsearch('fit3',[1 1],[],x,y);\n\nxf=0:0.1:11\ny1=polyval(p1,xf);\ny2=polyval(p2,xf);\ny3=polyval(p3,xf);\n\nsubplot(2,1,1)\nplot(xf,y1,'k'), hold on\nplot(xf,y2,'k--','Linewidth',[2])\nplot(xf,y3,'k','Linewidth',[2])\n\nplot(x,y,'ro','Linewidth',[2]), hold on\n\nlegend('E_\\infty','E_1','E_2','location','NorthWest')\nset(gca,'Fontsize',[15],'Ylim',[0 4],'Ytick',[0 1 2 3 4],'Xlim',[0 11],'Xtick',[0 2 4 6 8 10])\n", "meta": {"author": "dynamicslab", "repo": "databook_matlab", "sha": "d390d39d18489a4804ee87a143ae8db8a1f3010b", "save_path": "github-repos/MATLAB/dynamicslab-databook_matlab", "path": "github-repos/MATLAB/dynamicslab-databook_matlab/databook_matlab-d390d39d18489a4804ee87a143ae8db8a1f3010b/CH04/CH04_SEC01_LinearRegression.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299488452012, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.7385063070951974}} {"text": "function dq = dqconj(dv,WHICHCONJ)\n\n% DQCONJ Dual quaternion conjugate\n%\n% DQ = DQCONJ(DV) returns the dual quaternion conjugate of the dual\n% quaternion DV. DV (resp. DQ) is a 8-vector representing a dual \n% quaternion or an array 8*N (column i represents dual quaternion i)\n% where N is the number of dual quaternions. The default type of \n% conjugate is 'point' (see below). DQ has the same size as DV.\n%\n% DQ = DQCONJ(DV,WHICHCONJ) returns the type of dual quaternion conjugate\n% corresponding to WHICHCONJ (DV = Q0+eps*Q1):\n% - 'point': mixed conjugate: dV* = Q0*-eps*Q1* (used for point\n% transformations).\n% - 'line': quaternion conjugate: dV* = Q0*+eps*Q1* (used for line\n% transformations).\n% - 'other': dual number conjugate: dV* = Q0-eps*Q1\n%\n% See also QCONJ, DQMULT\n\nif nargin < 2\n WHICHCONJ = 'point'; % default is 'mixed' conjugate' (point transformation)\nend\n\n\nsdv = size(dv);\nif sdv == [1 8]\n dv = dv.'; \n sdv = size(dv); \nend\n\n% wrong size\nif sdv(1) ~= 8 \n error('DualQuaternion:DQconj:wrongsize',...\n '%d rows in array dv. It should be 8.',sdv(1));\nend\n\nn = sdv(2);\ndq = sym(zeros(8,n));\nswitch WHICHCONJ\n case 'point' % % case of point transformation\n dq(1:4,:) = qconj(dv(1:4,:));\n dq(5:8,:) = -qconj(dv(5:8,:));\n case 'line' % case of line transformation\n dq(1:4,:) = qconj(dv(1:4,:));\n dq(5:8,:) = qconj(dv(5:8,:));\n case 'other' % dual number conjugate\n dq(1:4,:) = dv(1:4,:);\n dq(5:8,:) = -dv(5:8,:);\n otherwise\n error('DualQuaternion:DQconj:wrongsize',...\n 'WHICHCONJ must be ''point'', ''line'' or ''other'' ');\nend\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/43393-dual-quaternion-symbolic-toolbox/Dual quaternion symbolic toolbox/dqconj.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797148356995, "lm_q2_score": 0.810478913248044, "lm_q1q2_score": 0.7384919450537003}} {"text": "function y = fshift(x,s)\n% FSHIFT Fractional circular shift\n% Syntax:\n%\n% >> y = fshift(x,s)\n%\n% FSHIFT circularly shifts the elements of vector x by a (possibly\n% non-integer) number of elements s. FSHIFT works by applying a linear\n% phase in the spectrum domain and is equivalent to CIRCSHIFT for integer\n% values of argument s (to machine precision).\n\n% (c) 2005 Francois Bouffard\n% fbouffar@gel.ulaval.ca\n\nneedtr = 0; if size(x,1) == 1; x = x(:); needtr = 1; end;\nN = size(x,1); \nr = floor(N/2)+1; f = ((1:N)-r)/(N/2); \np = exp(-j*s*pi*f)'; \ny = ifft(fft(x).*ifftshift(p)); if isreal(x); y = real(y); end;\nif needtr; y = y.'; end;", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/7886-fshift/fshift.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797172476385, "lm_q2_score": 0.8104789086703224, "lm_q1q2_score": 0.7384919428373989}} {"text": "function polygon_solid_angle_3d_test ( )\n\n%*****************************************************************************80\n%\n%% POLYGON_SOLID_ANGLE_3D_TEST tests POLYGON_SOLID_ANGLE_3D.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 28 May 2015\n%\n% Author:\n%\n% John Burkardt\n%\n dim_num = 3;\n test_num = 4;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'POLYGON_SOLID_ANGLE_3D_TEST\\n' );\n fprintf ( 1, ' POLYGON_SOLID_ANGLE_3D computes the solid angle\\n' );\n fprintf ( 1, ' subtended by a planar polygon in 3D as viewed from\\n' );\n fprintf ( 1, ' a point P.\\n' );\n\n for test = 1 : test_num\n%\n% One eighth of sphere surface, on the unit sphere surface.\n%\n if ( test == 1 )\n\n n = 3;\n\n v = [ ...\n 1.0, 0.0, 0.0; ...\n 0.0, 1.0, 0.0; ...\n 0.0, 0.0, 1.0 ]';\n\n p(1:3,1) = [ 0.0; 0.0; 0.0 ];\n%\n% Reverse order of vertices.\n%\n elseif ( test == 2 )\n\n n = 3;\n\n v = [ ...\n 1.0, 0.0, 0.0; ...\n 0.0, 0.0, 1.0; ...\n 0.0, 1.0, 0.0 ]';\n\n p(1:3,1) = [ 0.0; 0.0; 0.0 ];\n%\n% One eighth of sphere surface, on the unit sphere surface, \n% translated by (1,2,3).\n%\n elseif ( test == 3 )\n\n n = 3;\n\n v = [ ...\n 2.0, 2.0, 3.0; ...\n 1.0, 3.0, 3.0; ...\n 1.0, 2.0, 4.0 ]';\n\n p(1:3,1) = [ 1.0; 2.0; 3.0 ];\n%\n% One eighth of sphere surface, but on sphere of radius 2.\n%\n elseif ( test == 4 )\n\n n = 3;\n\n v = [ ...\n 2.0, 0.0, 0.0; ...\n 0.0, 2.0, 0.0; ...\n 0.0, 0.0, 2.0 ]';\n\n p(1:3,1) = [ 0.0; 0.0; 0.0 ];\n\n end\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' TEST # %d\\n', test );\n fprintf ( 1, '\\n' );\n\n r8vec_print ( dim_num, p, ' The viewing point P:' );\n\n r8mat_transpose_print ( dim_num, n, v, ' The polygon vertices V:' );\n\n solid_angle = polygon_solid_angle_3d ( n, v, p );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Solid angle subtended: %f\\n', solid_angle );\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/geometry/polygon_solid_angle_3d_test.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267830311354, "lm_q2_score": 0.8499711813581708, "lm_q1q2_score": 0.7384777271685933}} {"text": "function coeffs=terms2MultiDimPolyMat(termMat)\n%%TERMS2MULTIDIMPOLYMAT Given a multidimensional polynomial represented as\n% a 2D matrix of terms (monomials), convert it into a\n% hypermatrix of coefficients suitable for use with\n% functions such as polyValMultiDim and where convn can\n% be used to multiply two such polynomials.\n%\n%INPUTS: termMat An (n+1)XnumTerms matrix such that\n% termMat(:,i)=[c,a1,a2,...,an] is a monomial term where c\n% is the value of of the monomial coefficient and the\n% monomial is\n% x1^(a1-1)*x2^(a2-1)*x3^(a3-1)...xn^(an-1). The ordering\n% of the terms in termMat does not matter.\n%\n%OUTPUTS: coeffs A hypermatrix of the coefficients for the multivariate\n% polynomial. These are arranged such that\n% coeffs(a1,a2,a3...an) corresponds to the coefficient of an\n% x1^(a1-1)*x2^(a2-1)*x3^(a3-1)...xn^(an-1) term. Thus, the\n% number of indices coeffs takes is equal to the\n% dimensionality of x (not counting singleton dimensions at\n% the end of coeffs). Note that this ordering is the reverse\n% that used in the 1D polyval function that is built into\n% Matlab. The number of elements for each index in coeffs is\n% the maximum order of that dimension +1.\n%\n%This function is the opposite of multiDimHyperMat2Terms. See\n%multiDimHyperMat2Terms for usage examples.\n%\n%January 2016 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nnumTerms=size(termMat,2);\nnumIdx=size(termMat,1)-1;\n\nnumDims=zeros(1,numIdx);\n\nif(isscalar(numDims))\n numDims=[numDims,1];\nend\n\nfor idx=1:numIdx\n numDims(idx)=max(termMat(idx+1,:))+1; \nend\n\ncoeffs=zeros(numDims);\nfor curTerm=1:numTerms \n idx=nDim2Index(numDims,termMat(2:end,curTerm)+1);\n coeffs(idx)=coeffs(idx)+termMat(1,curTerm);\nend\n\nend\n\n%LICENSE:\n%\n%The source code is in the public domain and not licensed or under\n%copyright. The information and software may be used freely by the public.\n%As required by 17 U.S.C. 403, third parties producing copyrighted works\n%consisting predominantly of the material produced by U.S. government\n%agencies must provide notice with such work(s) identifying the U.S.\n%Government material incorporated and stating that such material is not\n%subject to copyright protection.\n%\n%Derived works shall not identify themselves in a manner that implies an\n%endorsement by or an affiliation with the Naval Research Laboratory.\n%\n%RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF THE\n%SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY THE NAVAL\n%RESEARCH LABORATORY FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE ACTIONS\n%OF RECIPIENT IN THE USE OF THE SOFTWARE.\n", "meta": {"author": "USNavalResearchLaboratory", "repo": "TrackerComponentLibrary", "sha": "9f6e329de5be06a371757c4b853200beb6def2d0", "save_path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary", "path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary/TrackerComponentLibrary-9f6e329de5be06a371757c4b853200beb6def2d0/Mathematical_Functions/Polynomials/Generic_Multivariate_Polynomials/terms2MultiDimPolyMat.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711604559846, "lm_q2_score": 0.8688267881258485, "lm_q1q2_score": 0.7384777133385733}} {"text": "function prob_test0275 ( )\n\n%*****************************************************************************80\n%\n%% TEST0275 tests CARDIOID_CDF, CARDIOID_CDF_INV and CARDIOID_PDF.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 15 April 2009\n%\n% Author:\n%\n% John Burkardt\n%\n a = 0.0;\n b = 0.25;\n seed = 123456789;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TEST0275\\n' );\n fprintf ( 1, ' For the Cardioid PDF:\\n' );\n fprintf ( 1, ' CARDIOID_CDF evaluates the CDF;\\n' );\n fprintf ( 1, ' CARDIOID_CDF_INV inverts the CDF.\\n' );\n fprintf ( 1, ' CARDIOID_PDF evaluates the PDF;\\n' );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' PDF parameter A = %f\\n', a );\n fprintf ( 1, ' PDF parameter B = %f\\n', b );\n\n if ( ~cardioid_check ( a, b ) )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'Fatal error!\\n' );\n fprintf ( 1, ' The parameters are not legal.\\n' );\n return\n end\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' X PDF CDF CDF_INV\\n' );\n fprintf ( 1, '\\n' );\n\n for i = 1 : 10\n [ x, seed ] = cardioid_sample ( a, b, seed );\n pdf = cardioid_pdf ( x, a, b );\n cdf = cardioid_cdf ( x, a, b );\n x2 = cardioid_cdf_inv ( cdf, a, b );\n\n fprintf ( 1,' %12f %12f %12f %12f\\n', x, pdf, cdf, x2 );\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/prob/prob_test0275.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.868826769445233, "lm_q2_score": 0.8499711775577736, "lm_q1q2_score": 0.738477712319081}} {"text": "function FD = FermiDiract(z,nu)\n%% Fermi-Diract function\n% Implementation of the Fermi-Diract Statistical function\n% in latex words:\n%\n% $$F_\\nu(z)=\\frac{1}{\\Gamma(\\nu)} \\int_{0}^{\\infty}\\frac{x^{\\nu-1}}{z^{-1}e^x+1}\n% \\approx \\sum_{l=1}^{\\infty}(-1)^{l-1}\\frac{z^l}{l^\\nu}$$\n%\n% As we can notice this function is of the order $\\nu$ \n\nl = 1:50; % up to l = 50 to ensure a fair accuaracy\nfd = (-1).^(l-1) .* (z.^l) ./ (l.^nu);\nFD = sum(fd);\nreturn", "meta": {"author": "wme7", "repo": "Aero-matlab", "sha": "9430008f2e3b84f28633775a44dff534e780fbac", "save_path": "github-repos/MATLAB/wme7-Aero-matlab", "path": "github-repos/MATLAB/wme7-Aero-matlab/Aero-matlab-9430008f2e3b84f28633775a44dff534e780fbac/Coupled/FD.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9372107878954106, "lm_q2_score": 0.7879311956428946, "lm_q1q2_score": 0.7384576166758502}} {"text": "function [Az, El, D] = topocent(X,dx)\n%TOPOCENT Transformation of vector dx into topocentric coordinate\n% system with origin at X.\n% Both parameters are 3 by 1 vectors.\n% Output: D vector length in units like the input\n% Az azimuth from north positive clockwise, degrees\n% El elevation angle, degrees\n\n%Kai Borre 11-24-96\n%Copyright (c) by Kai Borre\n%$Revision: 1.0 $ $Date: 1997/09/26 $\n\ndtr = pi/180;\n[phi,lambda,~] = togeod(6378137,298.257223563,X(1),X(2),X(3));\ncl = cos(lambda*dtr); sl = sin(lambda*dtr);\ncb = cos(phi*dtr); sb = sin(phi*dtr);\nF = [-sl -sb*cl cb*cl;\n cl -sb*sl cb*sl;\n 0 cb sb];\nlocal_vector = F'*dx;\nE = local_vector(1);\nN = local_vector(2);\nU = local_vector(3);\nhor_dis = sqrt(E^2+N^2);\nif hor_dis < 1.e-20\n Az = 0;\n El = 90;\nelse\n Az = atan2(E,N)/dtr;\n El = atan2(U,hor_dis)/dtr;\nend\nif Az < 0\n Az = Az+360;\nend\nD = sqrt(dx(1)^2+dx(2)^2+dx(3)^2);\n%%%%%%%%% end topocent.m %%%%%%%%%\n", "meta": {"author": "yandld", "repo": "nav_matlab", "sha": "da70cb2083de407409ebe1ec1096a308611cf063", "save_path": "github-repos/MATLAB/yandld-nav_matlab", "path": "github-repos/MATLAB/yandld-nav_matlab/nav_matlab-da70cb2083de407409ebe1ec1096a308611cf063/example/gps_spp_test/easysuite/topocent.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750413739075, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.7383910075873585}} {"text": "clear all; close all;\nfigure(1)\n% underdetermined\nn=20; m=100\nA=rand(n,m); b=rand(n,1);\n\ncvx_begin;\nvariable x2(m)\nminimize( norm(x2,2) );\nsubject to\nA*x2 == b;\ncvx_end;\n\ncvx_begin;\nvariable x1(m)\nminimize( norm(x1,1) );\nsubject to\nA*x1 == b;\ncvx_end;\n\nsubplot(3,1,1), bar(x2,'FaceColor',[.6 .6 .6],'EdgeColor','k')\nsubplot(3,1,2), bar(x1,'FaceColor',[.6 .6 .6],'EdgeColor','k')\nsubplot(3,2,5), hist(x2,40)\nsubplot(3,2,6), hist(x1,40)\n\nsubplot(3,1,1), axis([0 100 -.2 .2]), subplot(3,1,2), axis([0 100 -.4 .4])\nsubplot(3,2,5), axis([-.15 .15 0 82]), set(gca,'Ytick',[0 40 80],'Xtick',[-0.1 0 0.1])\nh = findobj(gca,'Type','patch'); h.FaceColor = [0.6 0.6 0.6]; h.EdgeColor = 'k';\nsubplot(3,2,6), axis([-.15 .15 0 82]), set(gca,'Ytick',[0 40 80],'Xtick',[-0.1 0 0.1])\nh = findobj(gca,'Type','patch'); h.FaceColor = [0.6 0.6 0.6]; h.EdgeColor = 'k';\n\n%%\nclear A\nclear b\nclear x\nfigure(2)\n\n% overdetermined\nn=500; m=100;\nA=rand(n,m);\nb=rand(n,1);\nxdag=pinv(A)*b;\n\nlam=[0 0.1 0.5];\nfor j=1:3\n \n cvx_begin;\n variable x(m)\n minimize( norm(A*x-b,2) + lam(j)*norm(x,1) );\n cvx_end;\n \n subplot(4,1,j),bar(x,'FaceColor',[.6 .6 .6],'EdgeColor','k')\n subplot(4,3,9+j), hist(x,20)\nend\n\n\nfor j=1:3\n \n \n subplot(4,1,j), axis([0 100 -.15 .15])\n subplot(4,3,9+j), axis([-.15 .15 0 80]), set(gca,'Ytick',[0 40 80])\n h = findobj(gca,'Type','patch');\n h.FaceColor = [0.6 0.6 0.6];\n h.EdgeColor = 'k';\nend\n\n\n%%\n% matrix overdetermined system\n\nclear A\nclear b\nclear x\nfigure(3)\n\n% overdetermined\nn=300; m=60; p=20;\nA=rand(n,m); b=rand(n,p);\n\nlam=[0 0.1];\nfor j=1:2\n cvx_begin;\n variable x(m,p)\n minimize(norm(A*x-b,2) + lam(j)*norm(x,1));\n cvx_end;\n subplot(2,1,j), pcolor(x.'), colormap(hot), colorbar\nend\n\n%%\nsubplot(2,1,1), set(gca,'Fontsize',[15],'Xtick',[1 20 40 60],'Ytick',[1 10 20])\nsubplot(2,1,2), set(gca,'Fontsize',[15],'Xtick',[1 20 40 60],'Ytick',[1 10 20])\n\n\n\n\n\n\n\n", "meta": {"author": "dynamicslab", "repo": "databook_matlab", "sha": "d390d39d18489a4804ee87a143ae8db8a1f3010b", "save_path": "github-repos/MATLAB/dynamicslab-databook_matlab", "path": "github-repos/MATLAB/dynamicslab-databook_matlab/databook_matlab-d390d39d18489a4804ee87a143ae8db8a1f3010b/CH04/CH04_SEC03_1_OverUnderDetermined_production.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966762263737, "lm_q2_score": 0.7799928900257126, "lm_q1q2_score": 0.738338677178543}} {"text": "function [x, y, z] = geodetic_to_ecf(lat, lon, alt)\n%GEODETIC_TO_ECF Convert geodetic coordinates to ECF\n%\n% //////////////////////////////////////////\n% /// CLASSIFICATION: UNCLASSIFIED ///\n% //////////////////////////////////////////\n%\n%\n% Convert geodetic latitude, longitude, and altitude to ECF (Earth \n% Centered Fixed) coordinates.\n%\n% USAGE:\n% pos_ecf = geodetic_to_ecf(pos_lla)\n% [pos_ecf_x, pos_ecf_y, pos_ecf_z] = geodetic_to_ecf(lat, lon, alt)\n%\n% INPUTS:\n% pos_lla - required : geodetic latitude, longitude, and altitude [deg, deg, m]\n%\n% OUTPUTS:\n% pos_ecf - required : ecf x, y, z coordinates [m, m, m]\n%\n% NOTES:\n% Zhu, J. Conversion of Earth-centered, Earth-fixed coordinates to \n% geodetic coordinates. IEEE Transactions on Aerospace and Electronic\n% Systems, 30, 3 (July 1994), 957-962.\n%\n% VERSION:\n% 1.0\n% - Sean Hatch 20070911\n% - initial version\n% 1.1\n% - Wade Schwartzkopf 20130708\n% - vectorized and componentwise data handling\n%\n% TODO:\n\n% define constants\ne2 = 6.6943799901377997e-3; % eccentricity squared of Earth (WGS 84 value)\na = 6378137.0; % semimajor radius of the Earth (WGS 84 value)\n\n% Handle different forms in input arguments\nif nargin==3 % Componentwise inputs, separate arguments for lat,lon,alt\n % Nothing to do. Processing uses this form.\nelseif size(lat,1)==3 % Array of 3-element vectors\n alt = lat(3,:);\n lon = lat(2,:);\n lat = lat(1,:);\nelseif numel(lat)==3 % Horizontal 3-element vector\n alt = lat(3);\n lon = lat(2);\n lat = lat(1);\nelse\n error('WGS_84_NORM:INVALID_INPUTS', 'Invalid inputs.');\nend\n\n% calculate distance to surface of ellipsoid\nR = a ./ sqrt(1.0 - e2 .* sind(lat) .* sind(lat));\n\n% calculate coordinates\nx = (R + alt) .* cosd(lat) .* cosd(lon);\ny = (R + alt) .* cosd(lat) .* sind(lon);\nz = (R + alt - e2 .* R) .* sind(lat);\n\nif nargout < 2 % Matrix/vector form, rather than componentwise form, was requested\n x = [x; y; z];\nend\n\nend\n\n% //////////////////////////////////////////\n% /// CLASSIFICATION: UNCLASSIFIED ///\n% //////////////////////////////////////////", "meta": {"author": "ngageoint", "repo": "MATLAB_SAR", "sha": "6291feff8e200d387e271f49ec09b1acd5514c4e", "save_path": "github-repos/MATLAB/ngageoint-MATLAB_SAR", "path": "github-repos/MATLAB/ngageoint-MATLAB_SAR/MATLAB_SAR-6291feff8e200d387e271f49ec09b1acd5514c4e/Geometry/coordinates/geodetic_to_ecf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297914570319, "lm_q2_score": 0.819893340314393, "lm_q1q2_score": 0.7383383787703296}} {"text": "function [L, D, P, rho] = ldlt_skew(A)\n%LDLT_SKEW Block LDL^T factorization for a skew-symmetric matrix.\n% Given a real, skew-symmetric A,\n% [L, D, P, RHO] = LDLT_SKEW(A) computes a permutation P,\n% a unit lower triangular L, and a block diagonal D\n% with 1x1 and 2x2 diagonal blocks, such that P*A*P' = L*D*L'.\n% A partial pivoting strategy of Bunch is used.\n% RHO is the growth factor.\n\n% Reference:\n% J. R. Bunch, A note on the stable decomposition of skew-symmetric\n% matrices. Math. Comp., 38(158):475-479, 1982.\n% N. J. Higham, Accuracy and Stability of Numerical Algorithms,\n% Second edition, Society for Industrial and Applied Mathematics,\n% Philadelphia, PA, 2002; chap. 11.\n\n% This routine does not exploit skew-symmetry and is not designed to\n% be efficient.\n\nif ~isreal(A) | ~isequal(triu(A,1)',-tril(A,-1))\n error('Must supply real, skew-symmetric matrix.')\nend\n\nn = length(A);\nk = 1;\nD = zeros(n);\nL = eye(n);\npp = 1:n;\nif nargout >= 4\n maxA = norm(A(:), inf);\n rho = maxA;\nend\n\nwhile k < n\n\n if max( abs(A(k+1:n,k)) ) == 0\n\n s = 1;\n % Nothing to do.\n\n else\n\n s = 2;\n\n if k < n-1\n [colmaxima, rowindices] = max( abs(A(k+1:n, k:k+1)) );\n [biggest, colindex] = max(colmaxima);\n row = rowindices(colindex)+k; col = colindex+k-1;\n\n % Permute largest element into (k+1,k) position.\n % NB: k<->col permutation must be done before k+1<->row one.\n A( [k, col], : ) = A( [col, k], : );\n A( :, [k, col] ) = A( :, [col, k] );\n A( [k+1, row], : ) = A( [row, k+1], : );\n A( :, [k+1, row] ) = A( :, [row, k+1] );\n L( [k, col], : ) = L( [col, k], : );\n L( :, [k, col] ) = L( :, [col, k] );\n L( [k+1, row], : ) = L( [row, k+1], : );\n L( :, [k+1, row] ) = L( :, [row, k+1] );\n pp( [k, col] ) = pp( [col, k] );\n pp( [k+1, row] ) = pp( [row, k+1] );\n end\n\n E = A(k:k+1,k:k+1);\n D(k:k+1,k:k+1) = E;\n C = A(k+2:n,k:k+1);\n temp = C/E;\n L(k+2:n,k:k+1) = temp;\n A(k+2:n,k+2:n) = A(k+2:n,k+2:n) + temp*C'; % Note the plus sign.\n % Restore skew-symmetry.\n A(k+2:n,k+2:n) = 0.5 * (A(k+2:n,k+2:n) - A(k+2:n,k+2:n)');\n\n if nargout >= 4, rho = max(rho, max(max(abs(A(k+2:n,k+2:n)))) ); end\n\n end\n\n k = k + s;\n if k >= n-2, D(k:n,k:n) = A(k:n,k:n); break, end;\n\nend\n\nif nargout >= 3, P = eye(n); P = P(pp,:); end\nif nargout >= 4, rho = rho/maxA; end\n", "meta": {"author": "opencobra", "repo": "cobratoolbox", "sha": "e60274d127f65d518535fd0814d20c53dc530f73", "save_path": "github-repos/MATLAB/opencobra-cobratoolbox", "path": "github-repos/MATLAB/opencobra-cobratoolbox/cobratoolbox-e60274d127f65d518535fd0814d20c53dc530f73/external/base/utilities/matrixcomp/ldlt_skew.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297967961706, "lm_q2_score": 0.8198933315126791, "lm_q1q2_score": 0.7383383752216482}} {"text": "function mbasis = basis_matrix_overhauser_nonuni ( alpha, beta )\n\n%*****************************************************************************80\n%\n%% BASIS_MATRIX_OVERHAUSER_NONUNI sets up the nonuniform Overhauser spline basis matrix.\n%\n% Discussion:\n%\n% This basis matrix assumes that the data points P1, P2, P3 and\n% P4 are not uniformly spaced in T, and that P2 corresponds to T = 0,\n% and P3 to T = 1.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 23 February 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real ALPHA, BETA.\n% ALPHA = || P2 - P1 || / ( || P3 - P2 || + || P2 - P1 || )\n% BETA = || P3 - P2 || / ( || P4 - P3 || + || P3 - P2 || ).\n%\n% Output, real MBASIS(4,4), the basis matrix.\n%\n mbasis(1,1) = - ( 1.0 - alpha ) * ( 1.0 - alpha ) / alpha;\n mbasis(1,2) = beta + ( 1.0 - alpha ) / alpha;\n mbasis(1,3) = alpha - 1.0 / ( 1.0 - beta );\n mbasis(1,4) = beta * beta / ( 1.0 - beta );\n\n mbasis(2,1) = 2.0 * ( 1.0 - alpha ) * ( 1.0 - alpha ) / alpha;\n mbasis(2,2) = ( - 2.0 * ( 1.0 - alpha ) - alpha * beta ) / alpha;\n mbasis(2,3) = ( 2.0 * ( 1.0 - alpha ) ...\n - beta * ( 1.0 - 2.0 * alpha ) ) / ( 1.0 - beta );\n mbasis(2,4) = - beta * beta / ( 1.0 - beta );\n\n mbasis(3,1) = - ( 1.0 - alpha ) * ( 1.0 - alpha ) / alpha;\n mbasis(3,2) = ( 1.0 - 2.0 * alpha ) / alpha;\n mbasis(3,3) = alpha;\n mbasis(3,4) = 0.0;\n\n mbasis(4,1) = 0.0;\n mbasis(4,2) = 1.0;\n mbasis(4,3) = 0.0;\n mbasis(4,4) = 0.0;\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/spline/basis_matrix_overhauser_nonuni.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297861178929, "lm_q2_score": 0.819893340314393, "lm_q1q2_score": 0.7383383743928051}} {"text": "function mean = dirichlet_mix_mean ( comp_num, elem_num, a, comp_weight )\n\n%*****************************************************************************80\n%\n%% DIRICHLET_MIX_MEAN returns the means of a Dirichlet mixture PDF.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 30 October 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer COMP_NUM, the number of components in the Dirichlet\n% mixture density, that is, the number of distinct Dirichlet PDF's\n% that are mixed together.\n%\n% Input, integer ELEM_NUM, the number of elements of an observation.\n%\n% Input, real A(ELEM_NUM,COMP_NUM), the probabilities for\n% element ELEM_NUM in component COMP_NUM.\n% Each A(I,J) should be positive.\n%\n% Input, real COMP_WEIGHT(COMP_NUM), the mixture weights of the densities.\n% These do not need to be normalized. The weight of a given component is\n% the relative probability that that component will be used to generate\n% the sample.\n%\n% Output, real MEAN(ELEM_NUM), the means for each element.\n%\n comp_weight_sum = sum ( comp_weight );\n\n mean(1:elem_num) = 0.0;\n\n for comp_i = 1 : comp_num\n comp_mean(1:elem_num) = dirichlet_mean ( elem_num, a(1:elem_num,comp_i) );\n mean(1:elem_num) = mean(1:elem_num) ...\n + comp_weight(comp_i) * comp_mean(1:elem_num);\n end\n\n mean(1:elem_num) = mean(1:elem_num) / comp_weight_sum;\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/prob/dirichlet_mix_mean.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.900529786117893, "lm_q2_score": 0.8198933293122506, "lm_q1q2_score": 0.7383383644850482}} {"text": "% SUMMARY: Calculate probability of gauss mix model\n% AUTHOR: QIUQIANG KONG, Queen Mary University of London\n% Created: 19-09-2015\n% Modified: 15-11-2015 Modify output size\n% 20-11-2015 debug the order of [p,M]\n% -----------------------------------------------------------\n% input\n% X input data; size: N*p; dim 1: num of data, dim 2: feature dim\n% pi prior of mix; dim 1: mix num\n% mu size: p*M; dim 1: feature dim, dim 2: mix num\n% Sigma size: p*p*M; dim 1,2: feature dim, dim 3: mix num\n% output\n% probs probability of input data, size: N*1\n% ===========================================================\nfunction probs = Gmmpdf(X, prior, mu, Sigma)\nN = size(X,1); % num of data\n[p,M] = size(mu); % mix num & feature dim\nprobs = zeros(N,1); % init output array\nfor m = 1:M\n probs = probs + prior(m) * mvnpdf(X, mu(:,m)', Sigma(:,:,m));\nend\nend", "meta": {"author": "qiuqiangkong", "repo": "matlab-hmm", "sha": "4d8d24199956c3c713b56e70be1d40f6ae4c550d", "save_path": "github-repos/MATLAB/qiuqiangkong-matlab-hmm", "path": "github-repos/MATLAB/qiuqiangkong-matlab-hmm/matlab-hmm-4d8d24199956c3c713b56e70be1d40f6ae4c550d/matlab-gmm/Gmmpdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475810629193, "lm_q2_score": 0.782662489091802, "lm_q1q2_score": 0.7383227658734349}} {"text": "function linplus_test43 ( )\n\n%*****************************************************************************80\n%\n%% TEST43 tests R8LT_MXV, R8LT_SL, R8LT_VXM.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 14 February 2003\n%\n% Author:\n%\n% John Burkardt\n%\n n = 10;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TEST43\\n' );\n fprintf ( 1, ' For a matrix in lower triangular storage,\\n' );\n fprintf ( 1, ' R8LT_SL solves systems;\\n' );\n fprintf ( 1, ' R8LT_MXV computes matrix-vector products;\\n' );\n fprintf ( 1, ' R8LT_VXM computes vector-matrix products;\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Matrix order N = %d\\n', n );\n\n for i = 1 : n\n for j = 1 : n\n if ( j <= i )\n a(i,j) = j;\n else\n a(i,j) = 0.0;\n end\n end\n end\n\n r8lt_print ( n, n, a, ' The lower triangular matrix:' );\n\n for job = 0 : 1\n%\n% Set the desired solution.\n%\n x = r8vec_indicator ( n );\n%\n% Compute the corresponding right hand side.\n%\n if ( job == 0 )\n b = r8lt_mxv ( n, n, a, x );\n else\n b = r8lt_vxm ( n, n, a, x );\n end\n%\n% Solve the linear system.\n%\n x = r8lt_sl ( n, a, b, job );\n \n if ( job == 0 )\n r8vec_print ( n, x, ' Solution:' );\n else\n r8vec_print ( n, x, ' Solution to the transposed system:' );\n end\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/linplus/linplus_test43.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8397339756938818, "lm_q2_score": 0.8791467659263148, "lm_q1q2_score": 0.7382494089697228}} {"text": "function bti_test01 ( )\n\n%*****************************************************************************80\n%\n%% BTI_TEST01 tests BURGERS_TIME_INVISCID.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 24 April 2012\n%\n% Author:\n%\n% John Burkardt\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'BTI_TEST01\\n' );\n fprintf ( 1, ' Test BURGERS_TIME_INVISCID\\n' );\n\n method = 1;\n nx = 81;\n nt = 200;\n t_max = 2.0;\n bc = 4;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Method: 1, Upwind nonconservative.\\n' );\n fprintf ( 1, ' Initial condition: expansion\\n' );\n fprintf ( 1, ' Number of space nodes = %d\\n', nx );\n fprintf ( 1, ' Number of time steps = %d\\n', nt );\n fprintf ( 1, ' Final time T_MAX = %g\\n', t_max );\n fprintf ( 1, ' Boundary condition = %d\\n', bc );\n\n U = burgers_time_inviscid ( method, @ic_expansion, nx, nt, t_max, bc );\n\n x = linspace ( -1.0, +1.0, nx );\n\n figure ( 1 )\n\n plot ( x, U(1:50:(nt+1),:), 'Linewidth', 3 )\n grid on\n xlabel ( '<-- X -->' )\n ylabel ( '<-- U(X,T) -->' )\n title ( 'Burgers, inviscid, initial expansion, upwind nonconservative' )\n\n filename = 'bti_test01.png';\n print ( '-dpng', filename )\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Saved plot as \"%s\"\\n', filename );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/burgers_time_inviscid/bti_test01.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339676722393, "lm_q2_score": 0.8791467738423874, "lm_q1q2_score": 0.7382494085649168}} {"text": "function sftpack_test06 ( )\n\n%*****************************************************************************80\n%\n%% TEST06 tests R8VEC_SST.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 27 February 2010\n%\n% Author:\n%\n% John Burkardt\n%\n n = 256;\n alo = 0.0;\n ahi = 5.0;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TEST06\\n' );\n fprintf ( 1, ' For slow sine transforms,\\n' );\n fprintf ( 1, ' R8VEC_SST does a forward or backward transform.\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' The number of data items is N = %d\\n', n );\n%\n% Set the data values.\n%\n seed = 123456789;\n\n [ c, seed ] = r8vec_uniform ( n, alo, ahi, seed );\n\n r8vec_print_part ( n, c, 10, ' The original data:' );\n%\n% Compute the coefficients.\n%\n d = r8vec_sst ( n, c );\n\n r8vec_print_part ( n, d, 10, ' The sine coefficients:' );\n%\n% Now compute inverse transform of coefficients. Should get back the\n% original data.\n\n e = r8vec_sst ( n, d );\n\n e(1:n) = e(1:n) / 2 / ( n + 1 );\n\n r8vec_print_part ( n, e, 10, ' The retrieved data:' );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/sftpack/sftpack_test06.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677660619633, "lm_q2_score": 0.8705972717658209, "lm_q1q2_score": 0.7382384236789031}} {"text": "function M = spm_meanm(A)\n% Compute barycentre of matrix exponentials\n% FORMAT M = spm_meanm(A)\n% A - A 3D array, where each slice is a matrix\n% M - the resulting mean\n%\n% Note that matrices should not be too dissimilar to each other or the\n% procedure fails.\n% See http://hal.archives-ouvertes.fr/hal-00699361/\n%__________________________________________________________________________\n% Copyright (C) 2012-2019 Wellcome Trust Centre for Neuroimaging\n\n% John Ashburner\n% $Id: spm_meanm.m 7563 2019-04-01 10:39:24Z guillaume $\n\n\nN = size(A,3);\nM = eye(size(A,1),size(A,2));\n\nfor iter = 1:1024\n S = zeros(size(M));\n for i=1:N\n L = real(logm(M\\A(:,:,i)));\n S = S + L;\n end\n S = S/N;\n M = M*expm(S);\n %imagesc(M); drawnow\n %fprintf('%d\\t%g\\n', iter,sum(S(:).^2));\n if sum(S(:).^2)<1e-20\n break;\n end\nend\n", "meta": {"author": "spm", "repo": "spm12", "sha": "3085dac00ac804adb190a7e82c6ef11866c8af02", "save_path": "github-repos/MATLAB/spm-spm12", "path": "github-repos/MATLAB/spm-spm12/spm12-3085dac00ac804adb190a7e82c6ef11866c8af02/toolbox/Longitudinal/spm_meanm.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693674025232, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.7381778723431107}} {"text": "function LL = dirichlet_score_family(counts, prior)\n% DIRICHLET_SCORE Compute the log marginal likelihood of a single family\n% LL = dirichlet_score(counts, prior)\n%\n% counts(a, b, ..., z) is the number of times parent 1 = a, parent 2 = b, ..., child = z\n% prior is an optional multidimensional array of the same shape as counts.\n% It defaults to a uniform prior.\n% \n% We marginalize out the parameters:\n% LL = log \\int \\prod_m P(x(i,m) | x(Pa_i,m), theta_i) P(theta_i) d(theta_i)\n\n\n% LL = log[ prod_j gamma(alpha_ij)/gamma(alpha_ij + N_ij) *\n% prod_k gamma(alpha_ijk + N_ijk)/gamma(alpha_ijk) ]\n% Call the prod_k term U and the prod_j term V.\n% We reshape all quantities into (j,k) matrices\n% This formula was first derived by Cooper and Herskovits, 1992.\n% See also \"Learning Bayesian Networks\", Heckerman, Geiger and Chickering, MLJ 95.\n\nns = mysize(counts);\nns_ps = ns(1:end-1);\nns_self = ns(end);\n\nif nargin < 2, prior = normalise(myones(ns)); end\n\n\nif 1\n prior = reshape(prior(:), [prod(ns_ps) ns_self]);\n counts = reshape(counts, [prod(ns_ps) ns_self]);\n %U = prod(gamma(prior + counts) ./ gamma(prior), 2); % mult over k\n LU = sum(gammaln(prior + counts) - gammaln(prior), 2);\n alpha_ij = sum(prior, 2); % sum over k\n N_ij = sum(counts, 2);\n %V = gamma(alpha_ij) ./ gamma(alpha_ij + N_ij);\n LV = gammaln(alpha_ij) - gammaln(alpha_ij + N_ij);\n %L = prod(U .* V);\n LL = sum(LU + LV);\nelse\n CPT = mk_stochastic(prior + counts);\n LL = sum(log(CPT(:) .* counts(:)));\nend\n\n", "meta": {"author": "bayesnet", "repo": "bnt", "sha": "bebba5f437b4e1e29169f0f3669df59fb5392e62", "save_path": "github-repos/MATLAB/bayesnet-bnt", "path": "github-repos/MATLAB/bayesnet-bnt/bnt-bebba5f437b4e1e29169f0f3669df59fb5392e62/BNT/learning/dirichlet_score_family.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693716759488, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.7381778609670254}} {"text": "function [bias av_bias] = bias_f(x,y)\n\n% Bias calculator\n\n% Formula: 1 - mean(fused image)/mean(original image)\n% (Ideal value = 0)\n\n% 07/03/2010 Version 1.0\n% 25/06/2010 Version 1.2 - Excel Output option\n% 04/08/2011 Version 1.2F - Function Version\n\n% Author: Aristidis D. Vaiopoulos\n\n% Find the number of bands\nbands = size(x);\nif length(bands) == 3\n bands = bands(1,3);\nelse\n bands = 1;\nend\n% Preallocation\nmx = zeros(1,bands);\nmy = zeros(1,bands);\n% Mean value calculation\nfor i = 1:bands\n xt = double(x(:,:,i));\n yt = double(y(:,:,i));\n mx(i) = mean(xt(:));\n my(i) = mean(yt(:));\nend\n% Bias calculation\nbias = 1 - (my./mx);\nbias = bias';\n\nav_bias = mean(bias);\n\nend\n\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/32637-hyperspectral-image-index-analysis/hyperspectral image index analysis/bias_f.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.921921834855049, "lm_q2_score": 0.8006920092299292, "lm_q1q2_score": 0.7381754463030321}} {"text": "function [a, b] = VBA_guessHyperpriors (y, rangeEV)\n% // VBA toolbox //////////////////////////////////////////////////////////\n%\n% [a, b] = VBA_guessHyperpriors (y, rangeEV)\n% propose shape and scale parameters to use as hyperpriors for the\n% measurement noise precision, based on the part of the variance one can\n% expect the model to explain.\n%\n% IN:\n% - y: data to be fitted\n% - rangeEV: range of the fraction of variance to be explained. \n% default = [0.1, 0.9], .ie between 10% and 90% of the total variance\n% OUT:\n% - a, b: shape and scale parameters of the Gamma hyperprior\n%\n% /////////////////////////////////////////////////////////////////////////\n\n\n%% check parameters\n% =========================================================================\n% fill in defaults\nif nargin == 1\n rangeEV = [0.1, 0.9];\nend\n\n% check inputs\nassert (numel (y) > 3, '*** VBA_guessHyperpriors: no enough datapoints!');\nassert (numel (rangeEV) == 2, '*** VBA_guessHyperpriors: rangeEV must have 2 values.');\nassert (VBA_isInRange (rangeEV, [1e-8, 1 - 1e-8]), '*** VBA_guessHyperpriors: rangeEV must be between 0 and 1.');\n\n% cleanup\ny(isnan (y)) = [];\n\n%% Compute expected precision\n% =========================================================================\n% reformulate statistics of interest\nvarianceTotal = var (VBA_vec (y));\nvarianceUnexplained = varianceTotal * (1 - rangeEV);\nprecisionExpected = 1 ./ varianceUnexplained;\n\n% shortcuts\nsumPrecision = sum (precisionExpected);\ndiffPrecision = max (precisionExpected) - min (precisionExpected);\n\n% precision range as 98% confidence interval\na = 6 * (sumPrecision / diffPrecision) ^ 2;\nb = 12 * sumPrecision / (diffPrecision ^ 2);\n\n", "meta": {"author": "MBB-team", "repo": "VBA-toolbox", "sha": "01ff63f43ef7a6473bc5e3f28dd9ffa58fcfb414", "save_path": "github-repos/MATLAB/MBB-team-VBA-toolbox", "path": "github-repos/MATLAB/MBB-team-VBA-toolbox/VBA-toolbox-01ff63f43ef7a6473bc5e3f28dd9ffa58fcfb414/utils/VBA_guessHyperpriors.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.921921841290738, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.7381754404944247}} {"text": "function quality=meshquality(node,elem)\n%\n% quality=meshquality(node,elem)\n%\n% compute the Joe-Liu mesh quality measure of a tetrahedral mesh\n%\n% author: Qianqian Fang (fangq nmr.mgh.harvard.edu)\n% date: 2011/02/26\n%\n% input:\n% node: node coordinates of the mesh (nn x 3)\n% elem: element table of a tetrahedral mesh (ne x 4)\n%\n% output:\n% quality: a vector of the same length as size(elem,1), with \n% each element being the Joe-Liu mesh quality metric (0-1) of \n% the corresponding element. A value close to 1 represents\n% higher mesh quality (1 means equilateral tetrahedron); \n% a value close to 0 means nearly degenerated element.\n%\n% reference:\n% A. Liu, B. Joe, Relationship between tetrahedron shape measures, \n% BIT 34 (2) (1994) 268-287.\n%\n% -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)\n%\n\nif(size(elem,2)>4)\n elem=elem(:,1:4);\nend\nenum=size(elem,1);\nvol=elemvolume(node,elem);\nedges=meshedge(elem);\ned=node(edges(:,1),:)-node(edges(:,2),:);\ned=sum((ed.*ed)');\ned=sum(reshape(ed,[enum length(ed)/enum])')';\n\nquality=12*((3*vol).^(2/3))./ed;\n", "meta": {"author": "goodshawn12", "repo": "REST", "sha": "e34ce521fcb36e7813357a9720072dd111edf797", "save_path": "github-repos/MATLAB/goodshawn12-REST", "path": "github-repos/MATLAB/goodshawn12-REST/REST-e34ce521fcb36e7813357a9720072dd111edf797/dependencies/iso2mesh/meshquality.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218348550491, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.738175439726065}} {"text": "function [x, y] = findLinePoints(p1,p2);\n% \n% [x, y] = findLinePoints(p1,p2)\n%\n% Author: I think it was me. \n% Purpose:\n% Find the x,y values that fall along a line between p1 and p2.\n% \n% 2002.07.24 RFD & FWC- fixed bug in vertical and horizontal special cases.\n% (Was returning column vectors instead of row.)\n\nx1 = p1(1); y1 = p1(2);\nx2 = p2(1); y2 = p2(2);\n\nif y2 == y1\n if x1 == x2\n error;\n return;\n end\n x = [x1:x2]; y = y1*ones(1,length(x));\nelseif x1 == x2\n if y1 == y2\n error;\n return;\n end\n y = [y1:y2]; x = x1*ones(1,length(y));\nelse\n slope = (y2-y1)/(x2-x1);\n b = y1 - slope*x1; \n if abs(y2 - y1) > abs(x2 - x1)\n if y1 < y2, y = y1:y2;\n else, y = y2:y1;\n end\n x = round( (y - b) / slope);\n else\n if x1 < x2, x = x1:x2;\n else x = x2:x1;\n end\n y = round(slope*x + b);\n end\nend\n\nreturn;\n", "meta": {"author": "vistalab", "repo": "vistasoft", "sha": "7f0102c696c091c858233340cc7e1ab02f064d4c", "save_path": "github-repos/MATLAB/vistalab-vistasoft", "path": "github-repos/MATLAB/vistalab-vistasoft/vistasoft-7f0102c696c091c858233340cc7e1ab02f064d4c/mrBOLD/ROI/findLinePoints.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218391455084, "lm_q2_score": 0.8006919949619792, "lm_q1q2_score": 0.738175436584434}} {"text": "% A SYMBOLIC DERIVATION OF THE JACOBIAN MANIPULATOR OF A KUKA LBR IIWA 14\n%\n% Copyright (C) 2016, by Arturo Gil Aparicio\n%\n% This file is part of ARTE (A Robotics Toolbox for Education).\n% \n% ARTE is free software: you can redistribute it and/or modify\n% it under the terms of the GNU Lesser General Public License as published by\n% the Free Software Foundation, either version 3 of the License, or\n% (at your option) any later version.\n% \n% ARTE is distributed in the hope that it will be useful,\n% but WITHOUT ANY WARRANTY; without even the implied warranty of\n% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n% GNU Lesser General Public License for more details.\n% \n% You should have received a copy of the GNU Leser General Public License\n% along with ARTE. If not, see .\nfunction jacobian_symbolic_kuka_iiwa\n% link lengths\n\nsyms q1 q2 q3 q4 q5 q6 q7\nrobot = load_robot('KUKA', 'LBR_IIWA_R820_COP')\n\nd = eval(robot.DH.d);\na = eval(robot.DH.a);\nalpha = eval(robot.DH.alpha);\n\n% matrices DH\nA01 = dh_sym(q1, d(1), a(1), alpha(1));\nA12 = dh_sym(q2, d(2), a(2), alpha(2));\nA23 = dh_sym(q3, d(3), a(3), alpha(3));\nA34 = dh_sym(q4, d(4), a(4), alpha(4));\nA45 = dh_sym(q5, d(5), a(5), alpha(5));\nA56 = dh_sym(q6, d(6), a(6), alpha(6));\nA67 = dh_sym(q7, d(7), a(7), alpha(7));\n\nA02 = A01*A12;\nA03 = A02*A23;\nA04 = A03*A34;\nA05 = A04*A45;\nA06 = A05*A56;\nA07 = A06*A67;\nA07 = simplify(A07)\n \nz0 = [0 0 1]';\nz1 = A01(1:3,3);\nz2 = A02(1:3,3);\nz3 = A03(1:3,3);\nz4 = A04(1:3,3);\nz5 = A05(1:3,3);\nz6 = A06(1:3,3);\n\n% simplify expressions\nz2 = simplify(z2);\nz3 = simplify(z3);\nz4 = simplify(z4);\nz5 = simplify(z5);\nz6 = simplify(z6);\n\n\n\n \np07=A07(1:3,4);\np17=A07(1:3,4)-A01(1:3,4);\np27=A07(1:3,4)-A02(1:3,4);\np37=A07(1:3,4)-A03(1:3,4);\np47=A07(1:3,4)-A04(1:3,4);\np57=A07(1:3,4)-A05(1:3,4);\np67=A07(1:3,4)-A06(1:3,4);\n\n% Jacobian in linear speed\nJv = [cross(z0, p07) cross(z1, p17) cross(z2, p27) cross(z3, p37) cross(z4, p47) cross(z5, p57) cross(z6, p67)];\n% Jacobian in angular speed\nJw = [z0 z1 z2 z3 z4 z5 z6];\n\nJw = simplify(Jw)\nJv = simplify(Jv)\n% singularities = det(Jv)\nJs = [Jv; Jw]; \n\nq1 = 0.1\nq2 = 0.1\nq3 = 0.1\nq4 = 0.1\nq5 = 0.1\nq6 = 0.1\nq7 = 0.1\n\nJs = eval(Js)\n\nq = [q1 q2 q3 q4 q5 q6 q7]\nJ = manipulator_jacobian(robot, q)\n\nJ-Js\n\n\n\nTs = eval(A07)\nT = directkinematic(robot, q)\n\nT-Ts\n\n\n\n\n\n\n\nfunction A = dh_sym(theta, d, a, alpha)\nsyms q1 q2 q3 q4 q5 q6 q7\n% avoid almost zero elements in cos(alpha) and sin(alpha)\nca = cos(alpha);\nsa = sin(alpha);\nif abs(ca) < 1e-6\n ca = 0;\nend\nif abs(sa) < 1e-6\n sa = 0;\nend\n\n\nA=[cos(theta) -ca*sin(theta) sa*sin(theta) a*cos(theta);\n sin(theta) ca*cos(theta) -sa*cos(theta) a*sin(theta);\n 0 sa ca d;\n 0 0 0 1];\n \n\n \n", "meta": {"author": "4rtur1t0", "repo": "ARTE", "sha": "6e836f3156bb36af63b70bd93375c8ff4ee643c4", "save_path": "github-repos/MATLAB/4rtur1t0-ARTE", "path": "github-repos/MATLAB/4rtur1t0-ARTE/ARTE-6e836f3156bb36af63b70bd93375c8ff4ee643c4/exercises/book/jacobian_symbolic_kuka_iiwa.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218305645894, "lm_q2_score": 0.8006919949619793, "lm_q1q2_score": 0.7381754297137609}} {"text": "function [cost grad] = soft_cost(theta, instances, labels, lambda)\n\n[s1 s2] = size(instances);\n[~, s4] = size(labels);\n\nmat = reshape(theta(1:end-s4), s4, s2)';\nb = theta(end-s4+1:end);\nvec = mat'*instances';\nif s4 > 1\n sm = softmax(vec + b(:,ones(1,s1)));\nelse\n sm = sigmoid(vec + b(:,ones(1,s1)));\nend\nlbl = labels';\nlbl_sm = sm - lbl;\n\ncost = 1/2*sum(sum(((lbl_sm').*(lbl_sm'))))/s1 + 1/2*lambda*(theta(1:end-s4)'*theta(1:end-s4));\n\nif s4 > 1\n del = (sm.*lbl_sm) - bsxfun(@times,sum(sm.*lbl_sm), sm);\n gradW = del*instances;\n gradb = sum(del,2);\nelse\n del = (lbl_sm).*sigmoid_prime(sm);\n gradW = del*instances;\n gradb = sum(del);\n \nend\ngrad = [gradW(:); gradb]/s1 + [lambda*theta(1:end-s4); zeros(s4,1)];\n", "meta": {"author": "jacoxu", "repo": "STC2", "sha": "34a28c5a8cf2d6e1db300d32f271f6522db3bde5", "save_path": "github-repos/MATLAB/jacoxu-STC2", "path": "github-repos/MATLAB/jacoxu-STC2/STC2-34a28c5a8cf2d6e1db300d32f271f6522db3bde5/software/RecNN/soft_cost.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133464597457, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.7381220257112229}} {"text": "clear all; close all; clc;\n\nt=linspace(-pi,pi,10000);\ndelay=-pi/2;\namp1=0.8;\namp2=1;\nslowness=150;\n\n\nfor ii=1:1:length(t)\n \n \n A=amp1*sin(amp1*2*pi*1*(ii/slowness));\n B=amp2*sin(amp2*2*pi*1*(ii/slowness)+delay);\n \n sin_graph=amp1*sin(amp1*2*pi*1*(t+ii/slowness));\n cos_graph=amp2*sin(amp2*2*pi*1*(t+ii/slowness)+delay);\n subplot(311);\n plot(t,sin_graph);hold on;\n plot(0,A,'r*','Markersize',10);hold off;title('Signal A : X-Axis');\n xlim([-pi pi]);ylim([-1 1]);\n set(gcf,'Position',[250,100, 800, 800]);\n grid on;\n subplot(312);\n T=num2str(delay);\n Title_for_B=strcat('Signal B with Delay = ',T,' : Y-Axis');\n plot(t,cos_graph);hold on;title(Title_for_B);\n xlim([-pi pi]);ylim([-1 1]);\n plot(0,B,'r*','MarkerSize',10);hold off;\n grid on;\n subplot(338);\n T2=num2str(amp1/amp2);\n Title_for_C=strcat('Ratio A/B = ',T2);\n plot(sin_graph,cos_graph);title(Title_for_C);\n hold on;\n plot(A,B,'r*','MarkerSize',10);hold off;xlim([-1 1]); ylim([-1 1]);\n grid on;\n% drawnow;\n pause(0.00000001)\n \nend\n", "meta": {"author": "angeloyeo", "repo": "gongdols", "sha": "7be9fbd988dec6edab1dc881cb22d63e6f69398d", "save_path": "github-repos/MATLAB/angeloyeo-gongdols", "path": "github-repos/MATLAB/angeloyeo-gongdols/gongdols-7be9fbd988dec6edab1dc881cb22d63e6f69398d/\uc2e0\ud638\ucc98\ub9ac\uc77c\ubc18/\ub9ac\uc0ac\uc96c_\ub9e4\ud2b8\ub7a9\uc5f0\uc2b5/Lissajous_Construction.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133498259925, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.7381220189093091}} {"text": "% Calculate the MFCC from filter bank\n% Author: Xiao Xiong\n% Created: 4 Feb 2005\n% Last modified: 4 Feb 2005\n\nfunction [feature] = fbank2mfcc(fbank,logE,DO_BLIND_EQUALIZATION);\n\nglobal bias;\nbias = zeros(12,1);\n\n[N_vector, N_melBank]= size(fbank);\n\n% for i=1:N_vector\n% % calculate the DCT of the vector. The mfcc sequences is\n% % c1,c2,c3...c12,c0\n% feature(i,1:13) = mydct(fbank(i,:), 13, N_melBank);\n% % do blind equalization to reduce convolutional distortion\n% if DO_BLIND_EQUALIZATION == 1\n% feature(i,1:12) = blind_equal(feature(i,1:12), logE(i));\n% end \n% end\n\n% Faster implementation\nfeature(:,1:13) = mydct(fbank, 13, N_melBank);", "meta": {"author": "singaxiong", "repo": "SignalGraph", "sha": "e86d973556ae8796a05ee2adbd665f47c8525a21", "save_path": "github-repos/MATLAB/singaxiong-SignalGraph", "path": "github-repos/MATLAB/singaxiong-SignalGraph/SignalGraph-e86d973556ae8796a05ee2adbd665f47c8525a21/signal/feature/fbank2mfcc.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133498259925, "lm_q2_score": 0.7853085708384736, "lm_q1q2_score": 0.7381220094638524}} {"text": "%\n% function [Tx,fs] = synsq_cwt_squeeze(Wx, w, t, nv, opt)\n%\n% Calculates synchrosqueezed transform of f on a logarithmic\n% scale. Used internally by synsq_cwt_fw.\n%\n% Input:\n% Wx: wavelet transform of x\n% w: estimate of frequency at locations in Wx (see synsq_cwt_fw code)\n% t: time vector\n% nv: number of voices\n% opt: options struct, not currently used\n%\n% Output:\n% Tx: synchrosqueezed output\n% fs: associated frequencies\n%\n% Note the multiplicative correction term f in synsq_cwt_squeeze_mex (and in\n% the matlab equivalent code commented out), required due to the fact that\n% the squeezing integral of Eq. (2.7), in, [1], is taken w.r.t. dlog(a).\n% This correction term needs to be included as a factor of Eq. (2.3), which\n% we implement here.\n%\n% A more detailed explanation is available in Sec. III of [2].\n% Specifically, this is an implementation of Sec. IIIC, Alg. 1.\n% Note the constant multiplier log(2)/nv has been moved to the\n% inverse of the normalization constant, as calculated in synsq_adm.m\n%\n% 1. I. Daubechies, J. Lu, H.T. Wu, \"Synchrosqueezed Wavelet Transforms: a\n% tool for empirical mode decomposition\", 2010.\n%\n% 2. E. Brevdo, N.S. Fu\u010dkar, G. Thakur, and H-T. Wu, \"The\n% Synchrosqueezing algorithm: a robust analysis tool for signals\n% with time-varying spectrum,\" 2011.\n% \n%\n%---------------------------------------------------------------------------------\n% Synchrosqueezing Toolbox\n% Authors: Eugene Brevdo (http://www.math.princeton.edu/~ebrevdo/)\n%---------------------------------------------------------------------------------\nfunction [Tx,fs] = synsq_cwt_squeeze(Wx, w, t, nv, opt)\n dt = t(2)-t(1);\n dT = t(end)-t(1);\n \n % Maximum measurable frequency of data\n %fM = 1/(4*dt); % wavelet limit - tested\n fM = 1/(2*dt); % standard\n % Minimum measurable frequency, due to wavelet\n fm = 1/dT; % really\n %fm = 1/(2*dT); % standard\n\n [na, N] = size(Wx);\n as = 2^(1/nv) .^ [1:1:na]';\n das = [1; diff(as)];\n lfm = log2(fm); lfM = log2(fM);\n fs = 2.^linspace(lfm, lfM, na);\n %dfs = [fs(1) diff(fs)];\n\n % Harmonics of diff. frequencies but same\n % magnitude have same |Tx|\n dfs = ones(size(fs));\n\n % The rest of the computation is performed efficiently in MEX\n if norm(Wx,'fro') < eps,\n Tx = zeros(size(Wx));\n else\n Tx = 1/nv * synsq_cwt_squeeze_mex(Wx, w, as, fs, dfs, lfm, lfM);\n end\nend\n", "meta": {"author": "HeLiangHIT", "repo": "time_frequency", "sha": "09c2abe92355ff5cd867bdb169229682e9d7af7c", "save_path": "github-repos/MATLAB/HeLiangHIT-time_frequency", "path": "github-repos/MATLAB/HeLiangHIT-time_frequency/time_frequency-09c2abe92355ff5cd867bdb169229682e9d7af7c/tf_tool_box/synchrosqueezing/synchrosqueezing/synsq_cwt_squeeze.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953003183444, "lm_q2_score": 0.822189134878876, "lm_q1q2_score": 0.7380753223535724}} {"text": "function [ grid_weight, grid_point ] = sparse_grid ( dim_num, level_max, ...\n rule, point_num )\n\n%*****************************************************************************80\n%\n%% SPARSE_GRID computes a sparse grid.\n%\n% Discussion:\n%\n% A Smolyak construction is used to create a multidimensional sparse grid.\n%\n% The user specifies:\n% * the spatial dimension of the quadrature region,\n% * the level that defines the Smolyak grid.\n% * the 1D quadrature rule.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 30 March 2008\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Fabio Nobile, Raul Tempone, Clayton Webster,\n% A Sparse Grid Stochastic Collocation Method for Partial Differential\n% Equations with Random Input Data,\n% SIAM Journal on Numerical Analysis,\n% Volume 46, Number 5, 2008, pages 2309-2345.\n%\n% Parameters:\n%\n% Input, integer DIM_NUM, the spatial dimension.\n%\n% Input, integer LEVEL_MAX, controls the size of the final\n% sparse grid.\n%\n% Input, integer RULE, the index of the rule.\n% 1, \"CC\", Clenshaw Curtis Closed Fully Nested rule.\n% 2, \"F1\", Fejer 1 Open Fully Nested rule.\n% 3, \"F2\", Fejer 2 Open Fully Nested rule.\n% 4, \"GP\", Gauss Patterson Open Fully Nested rule.\n% 5, \"GL\", Gauss Legendre Open Weakly Nested rule.\n% 6, \"GH\", Gauss Hermite Open Weakly Nested rule.\n% 7, \"LG\", Gauss Laguerre Open Non Nested rule.\n%\n% Input, integer POINT_NUM, the number of points in the grid,\n% as determined by LEVELS_INDEX_SIZE.\n%\n% Output, real GRID_WEIGHT(POINT_NUM), the weights.\n%\n% Output, real GRID_POINT(DIM_NUM,POINT_NUM), the points.\n%\n if ( rule == 1 )\n [ grid_weight, grid_point ] = sparse_grid_cfn ( dim_num, level_max, ...\n rule, point_num );\n elseif ( 2 <= rule & rule <= 4 )\n [ grid_weight, grid_point ] = sparse_grid_ofn ( dim_num, level_max, ...\n rule, point_num );\n elseif ( 5 <= rule & rule <= 6 )\n [ grid_weight, grid_point ] = sparse_grid_own ( dim_num, level_max, ...\n rule, point_num );\n elseif ( 7 == rule ) \n [ grid_weight, grid_point ] = sparse_grid_onn ( dim_num, level_max, ...\n rule, point_num );\n else\n grid_weight = [];\n grid_point = [];\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'SPARSE_GRID - Fatal error!\\n' );\n fprintf ( 1, ' Illegal input rule index = %d\\n', rule );\n error ( 'SPARSE_GRID - Fatal error!' );\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/sandia_sparse/sparse_grid.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952866333484, "lm_q2_score": 0.8221891283434876, "lm_q1q2_score": 0.73807530523513}} {"text": "function [p,f] = oct3bank(x); \n% OCT3BANK Simple one-third-octave filter bank. \n% OCT3BANK(X) plots one-third-octave power spectra of signal vector X. \n% Implementation based on ANSI S1.11-1986 Order-3 filters. \n% Sampling frequency Fs = 44100 Hz. Restricted one-third-octave-band \n% range (from 100 Hz to 5000 Hz). RMS power is computed in each band \n% and expressed in dB with 1 as reference level. \n%\n% [P,F] = OCT3BANK(X) returns two length-18 row-vectors with \n% the RMS power (in dB) in P and the corresponding preferred labeling \n% frequencies (ANSI S1.6-1984) in F. \n% \t\t\t\t\t\n% See also OCT3DSGN, OCT3SPEC, OCTDSGN, OCTSPEC.\n\n% Author: Christophe Couvreur, Faculte Polytechnique de Mons (Belgium)\n% couvreur@thor.fpms.ac.be\n% Last modification: Aug. 23, 1997, 10:30pm.\n\n% References: \n% [1] ANSI S1.1-1986 (ASA 65-1986): Specifications for\n% Octave-Band and Fractional-Octave-Band Analog and\n% Digital Filters, 1993.\n% [2] S. J. Orfanidis, Introduction to Signal Processing, \n% Prentice Hall, Englewood Cliffs, 1996.\n\n\npi = 3.14159265358979; \nFs = 44100; \t\t\t\t% Sampling Frequency\nN = 3; \t\t\t\t\t% Order of analysis filters. \nF = [ 100 125 160, 200 250 315, 400 500 630, 800 1000 1250, ... \n\t1600 2000 2500, 3150 4000 5000 ]; % Preferred labeling freq. \nff = (1000).*((2^(1/3)).^[-10:7]); \t% Exact center freq. \t\nP = zeros(1,18);\nm = length(x); \n\n% Design filters and compute RMS powers in 1/3-oct. bands\n% 5000 Hz band to 1600 Hz band, direct implementation of filters. \nfor i = 18:-1:13\n [B,A] = oct3dsgn(ff(i),Fs,N);\n y = filter(B,A,x); \n P(i) = sum(y.^2)/m; \nend\n% 1250 Hz to 100 Hz, multirate filter implementation (see [2]). \n[Bu,Au] = oct3dsgn(ff(15),Fs,N); \t% Upper 1/3-oct. band in last octave. \n[Bc,Ac] = oct3dsgn(ff(14),Fs,N); \t% Center 1/3-oct. band in last octave. \n[Bl,Al] = oct3dsgn(ff(13),Fs,N); \t% Lower 1/3-oct. band in last octave. \nfor j = 3:-1:0\n x = decimate(x,2); \n m = length(x); \n y = filter(Bu,Au,x); \n P(j*3+3) = sum(y.^2)/m; \n y = filter(Bc,Ac,x); \n P(j*3+2) = sum(y.^2)/m; \n y = filter(Bl,Al,x); \n P(j*3+1) = sum(y.^2)/m; \nend\n\n% Convert to decibels. \nPref = 1; \t\t\t\t% Reference level for dB scale. \nidx = (P>0);\nP(idx) = 10*log10(P(idx)/Pref);\nP(~idx) = NaN*ones(sum(~idx),1);\n\n% Generate the plot\nif (nargout == 0) \t\t\t\n bar(P);\n ax = axis; \n axis([0 19 ax(3) ax(4)]) \n set(gca,'XTick',[2:3:18]); \t\t% Label frequency axis on octaves. \n set(gca,'XTickLabels',F(2:3:length(F))); % MATLAB 4.1c\n% set(gca,'XTickLabel',F(2:3:length(F))); % MATLAB 5.1\n xlabel('Frequency band [Hz]'); ylabel('Power [dB]');\n title('One-third-octave spectrum')\n% Set up output parameters\nelseif (nargout == 1) \t\t\t\n p = P; \nelseif (nargout == 2) \t\t\t\n p = P; \n f = F;\nend\n\n\n\n\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/69-octave/octave/oct3bank.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096181702032, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.7380474013084651}} {"text": "%[2016]-\"The whale optimization algorithm\"\n\n% (9/12/2020)\n\nfunction WOA = jWhaleOptimizationAlgorithm(feat,label,opts)\n% Parameters\nlb = 0;\nub = 1; \nthres = 0.5; \nb = 1; % constant\n\nif isfield(opts,'T'), max_Iter = opts.T; end\nif isfield(opts,'N'), N = opts.N; end\nif isfield(opts,'b'), b = opts.b; end \nif isfield(opts,'thres'), thres = opts.thres; end\n\n% Objective function\nfun = @jFitnessFunction;\n% Number of dimensions\ndim = size(feat,2); \n% Initial \nX = zeros(N,dim); \nfor i = 1:N\n\tfor d = 1:dim\n X(i,d) = lb + (ub - lb) * rand();\n\tend\nend\n% Fitness\nfit = zeros(1,N);\nfitG = inf;\nfor i = 1:N\n fit(i) = fun(feat,label,(X(i,:) > thres),opts);\n % Global best\n if fit(i) < fitG\n fitG = fit(i); \n Xgb = X(i,:);\n end\nend\n% Pre\ncurve = zeros(1,max_Iter);\ncurve(1) = fitG; \nt = 2; \nwhile t <= max_Iter\n\t% Define a, linearly decreases from 2 to 0 \n a = 2 - t * (2 / max_Iter);\n for i = 1:N\n % Parameter A (2.3)\n A = 2 * a * rand() - a;\n % Paramater C (2.4)\n C = 2 * rand();\n % Parameter p, random number in [0,1]\n p = rand();\n % Parameter l, random number in [-1,1]\n l = -1 + 2 * rand(); \n % Whale position update (2.6)\n if p < 0.5\n % {1} Encircling prey\n if abs(A) < 1\n for d = 1:dim\n % Compute D (2.1)\n Dx = abs(C * Xgb(d) - X(i,d));\n % Position update (2.2)\n X(i,d) = Xgb(d) - A * Dx;\n end\n % {2} Search for prey\n elseif abs(A) >= 1\n for d = 1:dim\n % Select a random whale\n k = randi([1,N]);\n % Compute D (2.7)\n Dx = abs(C * X(k,d) - X(i,d));\n % Position update (2.8)\n X(i,d) = X(k,d) - A * Dx;\n end\n end\n % {3} Bubble-net attacking \n elseif p >= 0.5\n for d = 1:dim\n % Distance of whale to prey\n dist = abs(Xgb(d) - X(i,d));\n % Position update (2.5)\n X(i,d) = dist * exp(b * l) * cos(2 * pi * l) + Xgb(d);\n end\n end\n % Boundary\n XB = X(i,:); XB(XB > ub) = ub; XB(XB < lb) = lb; \n X(i,:) = XB;\n end\n % Fitness\n for i = 1:N\n % Fitness \n fit(i) = fun(feat,label,(X(i,:) > thres),opts);\n % Global best\n if fit(i) < fitG\n fitG = fit(i);\n Xgb = X(i,:);\n end\n end\n curve(t) = fitG;\n fprintf('\\nIteration %d Best (WOA)= %f',t,curve(t))\n t = t + 1;\nend\n% Select features\nPos = 1:dim; \nSf = Pos((Xgb > thres) == 1);\nsFeat = feat(:,Sf);\n% Store results\nWOA.sf = Sf; \nWOA.ff = sFeat;\nWOA.nf = length(Sf);\nWOA.c = curve;\nWOA.f = feat;\nWOA.l = label;\nend\n\n\n\n\n\n", "meta": {"author": "JingweiToo", "repo": "Wrapper-Feature-Selection-Toolbox", "sha": "91b050142f331d2a58f7127aba91356b397379b3", "save_path": "github-repos/MATLAB/JingweiToo-Wrapper-Feature-Selection-Toolbox", "path": "github-repos/MATLAB/JingweiToo-Wrapper-Feature-Selection-Toolbox/Wrapper-Feature-Selection-Toolbox-91b050142f331d2a58f7127aba91356b397379b3/jWhaleOptimizationAlgorithm.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.91610961358942, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.7380473954804275}} {"text": "function [Pro,Res] = interpolationAMGa(A,isC) \n%% INTERPOLATIONAMGA construct prolongation and restriction matrices\n%\n% [Pro,Res] = INTERPOLATIONAMGA(A,isC) construct prolongation and\n% restriction matrices use matrix-dependent interpolation. Each fine nodes\n% use only one coarse node.\n%\n% In the input, A is a SPD matrix and isC is a logical array to indicate\n% nodes in coarse matrix. In the output Pro and Res are prolongation and\n% restriction matrices satisfying Res = Pro'.\n%\n% The submatrix A_{cf} is used to construct the interpolation of values on\n% fine nodes from that of coarse nodes. The weight is normalized to\n% preserve the constant.\n%\n% Example\n% load lakemesh\n% A = assemblematrix(node,elem);\n% [isC,As] = coarsenAMGc(A);\n% [Pro,Res] = interpolation(As,isC);\n%\n% See also: coarsenAMGc, amg\n%\n% Copyright (C) Long Chen. See COPYRIGHT.txt for details. \n\nN = size(A,1);\n%% Index map between coarse grid and fine grid\nallNode = (1:N)'; \nfineNode = allNode(~isC);\n% Nf = length(fineNode); \nNc = N-length(fineNode);\ncoarseNode = (1:Nc)'; % coarse node index\ncoarseNodeFineIdx = find(isC); % coarse node index in the fine grid\n\n%% Construct prolongation and restriction operator\nAfc = A(fineNode,coarseNodeFineIdx); % matrix-dependent interpolation\n[Dsum,j] = max(abs(Afc),[],2);\nidx = (Dsum ~= 0);\nip = [coarseNodeFineIdx; fineNode(idx)]; % fine node index\njp = [coarseNode; j(idx)]; % coarse node index\nsp = [ones(Nc,1); ones(length(j(idx)),1)]; % weight = 1;\nPro = sparse(ip,jp,sp,N,Nc);\nRes = Pro';", "meta": {"author": "lyc102", "repo": "ifem", "sha": "29f31c812001ca8d93dad08e67208ca60e8716d4", "save_path": "github-repos/MATLAB/lyc102-ifem", "path": "github-repos/MATLAB/lyc102-ifem/ifem-29f31c812001ca8d93dad08e67208ca60e8716d4/solver/interpolationAMGa.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9161096181702031, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.7380473948956315}} {"text": "function w = flattopwin (L, sym)\n% Author: Paul Kienzle (2004)\n% This program is granted to the public domain.\n%\n% flattopwin(L, [periodic|symmetric])\n%\n% Return the window f(w):\n%\n% f(w) = 1 - 1.93 cos(2 pi w) + 1.29 cos(4 pi w)\n% - 0.388 cos(6 pi w) + 0.0322cos(8 pi w)\n%\n% where w = i/(L-1) for i=0:L-1 for a symmetric window, or\n% w = i/L for i=0:L-1 for a periodic window. The default\n% is symmetric. The returned window is normalized to a peak\n% of 1 at w = 0.5.\n%\n% This window has low pass-band ripple, but high bandwidth.\n%\n% According to [1]:\n%\n% The main use for the Flat Top window is for calibration, due\n% to its negligible amplitude errors.\n%\n% [1] Gade, S; Herlufsen, H; (1987) 'Use of weighting functions in DFT/FFT\n% analysis (Part I)', Bruel & Kjaer Technical Review No.3.\n\n if nargin == 0 || nargin > 2\n help(mfilename);\n end % if\n\n divisor = L-1;\n if nargin > 1\n if strcmp(sym, 'periodic')\n divisor = L;\n elseif strcmp(sym, 'symmetric')\n divisor = L-1;\n else\n error('second argument must be ''periodic'' or ''symmetric''');\n end\n end % if\n \n x = 2*pi*(0:(L-1))'/divisor;\n if L==1\n w = 1;\n else\n % these coefficients come from wikipedia, and match better with what\n % matlab outputs (JM)\n a0 = 0.21557895;\n a1 = 0.41663158;\n a2 = 0.277263158;\n a3 = 0.083578947;\n a4 = 0.006947368;\n w = a0 - a1*cos(x) + a2*cos(2*x) - a3*cos(3*x) + ...\n a4*cos(4*x);\n %w = (1-1.93*cos(x)+1.29*cos(2*x)-0.388*cos(3*x)+0.0322*cos(4*x))/4.6402;\n end\nend\n", "meta": {"author": "fieldtrip", "repo": "fieldtrip", "sha": "c2039be598a02d86b39aae76bfa7aaa720f9801c", "save_path": "github-repos/MATLAB/fieldtrip-fieldtrip", "path": "github-repos/MATLAB/fieldtrip-fieldtrip/fieldtrip-c2039be598a02d86b39aae76bfa7aaa720f9801c/external/signal/flattopwin.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096090086367, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.7380473875147788}} {"text": "function value = r8_normal_01_sample ( )\n\n%*****************************************************************************80\n%\n%% R8_NORMAL_01_SAMPLE returns a unit pseudonormal R8.\n%\n% Discussion:\n%\n% The standard normal probability distribution function (PDF) has\n% mean 0 and standard deviation 1.\n%\n% The Box-Muller method is used, which is efficient, but\n% generates two values at a time. \n%\n% Typically, we would use one value and save the other for the next call.\n% However, the fact that this function has saved memory makes it difficult\n% to correctly handle cases where we want to re-initialize the code,\n% or to run in parallel. Therefore, we will instead use the first value\n% and DISCARD the second.\n%\n% EFFICIENCY must defer to SIMPLICITY.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 05 August 2013\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Output, real VALUE, a sample of the standard normal PDF.\n%\n r1 = r8_uniform_01_sample ( );\n r2 = r8_uniform_01_sample ( );\n\n x = sqrt ( - 2.0 * log ( r1 ) ) * cos ( 2.0 * pi * r2 );\n\n value = x;\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/pdflib/r8_normal_01_sample.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314858927012, "lm_q2_score": 0.8333245891029456, "lm_q1q2_score": 0.7380184940781664}} {"text": "function g=BaylissLinearTapering(sidelobedB,N,xPoints,a)\n%%BAYLISSLINEARTAPERING The Bayliss tapering is a set of complex amplitude\n% weights for a continuous linear (narrowband) aperture antenna\n% that will form a difference beam (odd symmetry about an axis)\n% and hold the four closest sidelobes to a desired level. Such a\n% tapering can be discretized and applied to the elements in a\n% circular phased array (An array of antenna elements can be\n% viewed as a discrete approximation to a continuous aperture).\n% This function will provide the tapering values at a set of\n% discrete points given by xPoints (the origin is taken to be the\n% center of the aperture). The radius of the aperture can either\n% be provided or is taken as value of the farthest point provided.\n%\n%INPUTS: sidelobedB The number of decibels of the ratio of the close-in\n% sidelobe voltages to the main lobe voltage. This must be a \n% negative number. A typical value is -30.\n% N The Bayliss tapering is computed using a certain number of\n% terms. Using too many terms can be undesirable as edge\n% illumination increases, as noted in [1]. If this parameter is\n% omitted or an empty matrix is passed, then the default of 17\n% is used. In [1], it is suggested that N be chosen to be\n% <2*a/lambda, where a is the radius of the aperture and\n% lambda the wavelength.\n% xyPoints An NX1 or 1XN set of N points at which the tapering values\n% should be evaluated. The center of the aperture is taken to\n% be the origin. \n% a The radius of the aperture. Tapering weights for points in\n% xPoints outside of the aperture are taken to be zero. If\n% this parameter is omitted or an empty matrix is passed, then\n% the radius is taken to be the distance of the farthest point\n% from the origin in xPoints.\n%\n%OUTPUTS: g The NX1 set of discretized Bayliss tapering values evaluated at\n% the points given in xPoints. All Bayliss tapering values are\n% imaginary. The coefficients are not normalized.\n%\n%This function implements the algorithm given in the appendix of in [1]\n%using the polynomial interpolation values in the table below Figure 4.\n%This approximation means that low sidelobe patterns (-45 dB and below)\n%will not have good fidelity sidelobes.\n%\n%EXAMPLE 1:\n%Here, we evaluate the tapering values for 30dB down on a fine grid of\n%points to plot what the amplitude and phase of the tapering weights looks\n%like.\n% numPoints=300;\n% xPoints=linspace(-1,1,numPoints);\n% %The Bayliss tapering weights, evaluated across the aperture.\n% a=1;%Aperture radius=1.\n% %gTest=BaylissLinear();\n% gBayliss=BaylissLinearTapering(-30,17,xPoints,a);\n% \n% figure(1)\n% clf\n% plot(xPoints,abs(gBayliss),'-b','linewidth',2)\n% h1=xlabel('x');\n% h2=ylabel('Imaginary Weight');\n% title('Bayliss Tapering Amplitude')\n% set(gca,'FontSize',14,'FontWeight','bold','FontName','Times')\n% set(h1,'FontSize',14,'FontWeight','bold','FontName','Times')\n% set(h2,'FontSize',14,'FontWeight','bold','FontName','Times')\n% \n% figure(2)\n% clf\n% plot(xPoints,angle(gBayliss),'-b','linewidth',2)\n% h1=xlabel('x');\n% h2=ylabel('Imaginary Weight');\n% title('Bayliss Tapering Phase')\n% set(gca,'FontSize',14,'FontWeight','bold','FontName','Times')\n% set(h1,'FontSize',14,'FontWeight','bold','FontName','Times')\n% set(h2,'FontSize',14,'FontWeight','bold','FontName','Times')\n%\n%EXAMPLE 2:\n%Here, we consider the array response when using tapering values for 30dB\n%sidelobes on a linear array with lambda/2 spacing between elements.\n% N=17;\n% sidelobedB=-30;\n% Nx=41;%There are 2*Nx+1 points total.\n% %Generate points symmetric about the origin.\n% xPoints=(-(Nx-1)/2):1/2:((Nx-1)/2);\n% g=BaylissLinearTapering(sidelobedB,N,xPoints);\n% \n% %Now, display the response with the tapering\n% T=diag(g);\n% [Rsp,U]=standardUVBeamPattern(T,xPoints,'NormRealVal');\n% \n% figure(2)\n% clf\n% plot(U,Rsp,'-b','LineWidth',2);\n% h1=xlabel('u');\n% h2=ylabel('Array Response');\n% title('Bayliss Weighted Array Response')\n% set(gca,'FontSize',14,'FontWeight','bold','FontName','Times')\n% set(h1,'FontSize',14,'FontWeight','bold','FontName','Times')\n% set(h2,'FontSize',14,'FontWeight','bold','FontName','Times')\n%\n%REFERENCES:\n%[1] E. T. Bayliss, \"Design of monopulse antenna difference patterns with\n% low sidelobes,\" The Bell System Technical Journal, vol. 47, no. 5, pp.\n% 623-650, May-Jun. 1968.\n%\n%August 2016 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nif(nargin<2||isempty(N))\n N=17; \nend\n\n%Defined below Equation 41 in [1].\nmu=((0:(N-1))+1/2)';\n\n%This holds the coefficients for the interpolating polynomials given below\n%Figure 4 in [1]. The polynomials all take the desired sidelobe level in\n%decibels as an input parameter. The first row is for the term A, which\n%is a translation of the SNR parameter to a parameter in the paper. The\n%next four rows are xi_1 to xi_4, which are the locations of the first four\n%zeroes in the modified pattern. The final row is for p_0, which is related\n%to the point at which the peak of the asymptotic difference pattern=1.\npolyCoeffTable=[0.30387530,-0.05042922,-0.00027989,-0.00000343,-0.00000002;\n 0.98583020,-0.03338850, 0.00014064, 0.00000190, 0.00000001;\n 2.00337487,-0.01141548, 0.00041590, 0.00000373, 0.00000001;\n 3.00636321,-0.00683394, 0.00029281, 0.00000161, 0;\n 4.00518423,-0.00501795, 0.00021735, 0.00000088, 0;\n 0.47972120,-0.01456692,-0.00018739,-0.00000218,-0.00000001];\n\nA =polyCoeffTable(1,1)+sidelobedB*(polyCoeffTable(1,2)+sidelobedB*(polyCoeffTable(1,3)+sidelobedB*(polyCoeffTable(1,4)+sidelobedB*polyCoeffTable(1,5))));\nxi1=polyCoeffTable(2,1)+sidelobedB*(polyCoeffTable(2,2)+sidelobedB*(polyCoeffTable(2,3)+sidelobedB*(polyCoeffTable(2,4)+sidelobedB*polyCoeffTable(2,5))));\nxi2=polyCoeffTable(3,1)+sidelobedB*(polyCoeffTable(3,2)+sidelobedB*(polyCoeffTable(3,3)+sidelobedB*(polyCoeffTable(3,4)+sidelobedB*polyCoeffTable(3,5))));\nxi3=polyCoeffTable(4,1)+sidelobedB*(polyCoeffTable(4,2)+sidelobedB*(polyCoeffTable(4,3)+sidelobedB*(polyCoeffTable(4,4)+sidelobedB*polyCoeffTable(4,5))));\nxi4=polyCoeffTable(5,1)+sidelobedB*(polyCoeffTable(5,2)+sidelobedB*(polyCoeffTable(5,3)+sidelobedB*(polyCoeffTable(5,4)+sidelobedB*polyCoeffTable(5,5))));\n%p0 =polyCoeffTable(6,1)+sldelobedB*(polyCoeffTable(6,2)+sldelobedB*(polyCoeffTable(6,3)+sldelobedB*(polyCoeffTable(6,4)+sldelobedB*polyCoeffTable(6,5))));\n\nZ=zeros(N+1,1);\n%Equation 15\nZ(1)=0;%The Z(0) term\n%Now, the moved zeros\nZ(2)=xi1;\nZ(3)=xi2;\nZ(4)=xi3;\nZ(5)=xi4;\nfor k=5:N\n %The location of the non-moved zeros as given by Equation 13.\n Z(k+1)=sqrt(A^2+k^2);\nend\n\nsigma=(N+1/2)/Z(N+1);\n\nB=zeros(N,1);\nfor m=0:(N-1)\n %This loop implements Equation 47.\n n=1:(N-1);\n num=prod(1-((m+1/2)./(sigma*Z(1+n))).^2);\n l=[0:(m-1),(m+1):(N-1)];\n denom=prod(1-((m+1/2)./(l+1/2)).^2);\n %We just use C=1.\n B(m+1)=1/(2*1j)*(-1)^m*(m-1/2)^2*num/denom;\nend\n\nnumPoints=length(xPoints);\n\nif(nargin<4||isempty(a))\n %The maximum distance from the origin to a point is taken to be the\n %radius of the aperture.\n a=sqrt(max(sum(xPoints.^2,1)));\nend\n\n%The loop below implements Equation 41 in [1].\ng=zeros(numPoints,1);\nfor curPoint=1:numPoints\n if(abs(xPoints(curPoint))<=a)\n %The normalized radius at this point.\n p=pi*xPoints(curPoint)/a;\n g(curPoint)=g(curPoint)+sum(B.*sin(mu*p));\n end\nend\nend\n\n%LICENSE:\n%\n%The source code is in the public domain and not licensed or under\n%copyright. The information and software may be used freely by the public.\n%As required by 17 U.S.C. 403, third parties producing copyrighted works\n%consisting predominantly of the material produced by U.S. government\n%agencies must provide notice with such work(s) identifying the U.S.\n%Government material incorporated and stating that such material is not\n%subject to copyright protection.\n%\n%Derived works shall not identify themselves in a manner that implies an\n%endorsement by or an affiliation with the Naval Research Laboratory.\n%\n%RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF THE\n%SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY THE NAVAL\n%RESEARCH LABORATORY FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE ACTIONS\n%OF RECIPIENT IN THE USE OF THE SOFTWARE.\n", "meta": {"author": "USNavalResearchLaboratory", "repo": "TrackerComponentLibrary", "sha": "9f6e329de5be06a371757c4b853200beb6def2d0", "save_path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary", "path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary/TrackerComponentLibrary-9f6e329de5be06a371757c4b853200beb6def2d0/Mathematical_Functions/Signal_Processing/Array_Processing/Tapering/BaylissLinearTapering.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314738181875, "lm_q2_score": 0.8333245953120233, "lm_q1q2_score": 0.7380184895151318}} {"text": "function circle_integrals_test01 ( )\n\n%*****************************************************************************80\n%\n%% CIRCLE_INTEGRALS_TEST01 tests CIRCLE01_SAMPLE.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 12 January 2014\n%\n% Author:\n%\n% John Burkardt\n%\n m = 2;\n n = 4192;\n test_num = 20;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TEST01\\n' );\n fprintf ( 1, ' Use CIRCLE01_SAMPLE to compare exact and\\n' );\n fprintf ( 1, ' estimated integrals along the circumference \\n' );\n fprintf ( 1, ' of the unit circle in 2D.\\n' );\n%\n% Get sample points.\n%\n seed = 123456789;\n [ x, seed ] = circle01_sample ( n, seed );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Number of sample points used is %d\\n', n );\n%\n% Randomly choose X, Y exponents.\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' If any exponent is odd, the integral is zero.\\n' );\n fprintf ( 1, ' We restrict this test to randomly chosen even exponents.\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Ex Ey MC-Estimate Exact Error\\n' );\n fprintf ( 1, '\\n' );\n\n for test = 1 : test_num\n\n [ e, seed ] = i4vec_uniform_ab ( m, 0, 5, seed );\n\n e(1:m) = e(1:m) * 2;\n\n value = monomial_value ( m, n, e, x );\n\n result = circle01_length ( ) * sum ( value(1:n) ) / n;\n exact = circle01_monomial_integral ( e );\n error = abs ( result - exact );\n\n fprintf ( 1, ' %2d %2d %14.6g %14.6g %10.2e\\n', ...\n e(1:m), result, exact, error );\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/circle_integrals/circle_integrals_test01.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314617436727, "lm_q2_score": 0.8333245870332531, "lm_q1q2_score": 0.7380184721212023}} {"text": "function a = kahan_inverse ( alpha, n )\n\n%*****************************************************************************80\n%\n%% KAHAN_INVERSE returns the inverse of the Kahan matrix.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 13 October 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real ALPHA, the scalar that defines A. A typical \n% value is 1.2. The \"interesting\" range of ALPHA is 0 < ALPHA < PI.\n%\n% Input, integer N, the order of A.\n%\n% Output, real A(N,N), the matrix.\n%\n ci = cos ( alpha );\n\n for i = 1 : n\n for j = 1 : n\n\n if ( i == j )\n a(i,j) = 1.0;\n elseif ( i == j - 1 )\n a(i,j) = ci;\n elseif ( i < j )\n a(i,j) = ci * ( 1.0 + ci )^(j-i-1);\n else\n a(i,j) = 0.0;\n end\n\n end\n end\n%\n% Scale the columns.\n%\n for j = 1 : n\n si = sin ( alpha )^j;\n a(1:n,j) = a(1:n,j) / si;\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/condition/kahan_inverse.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220292, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.7379994329758636}} {"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%\n% In this script, we perform phase transition analysis\n% of Orthogonal matching pursuit.\n%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nclose all;\nclear all;\nclc;\nrng('default');\n% Create the directory for storing results\n[status_code,message,message_id] = mkdir('bin');\ntarget_file_path = 'bin/ra_mmv_phase_transition_snr_30db_s_4.mat';\nN = 256;\nS = 4;\npta = spx.pursuit.PhaseTransitionAnalysis(N);\npta.SNR = 30;\n\n% options for CoSaMP MMV solver\nsolver_options.RankAwareResidual = true;\nP = 2;\n\n% pta.NumTrials = 100;\ndict_model = @(M, N) spx.dict.simple.gaussian_dict(M, N);\ndata_model = @(N, K) spx.data.synthetic.SparseSignalGenerator(N, K, S).gaussian;\nrecovery_solver = @(Phi, K, y) spx.pursuit.joint.CoSaMP(Phi, K, P, solver_options).solve(y).Z;\npta.run(dict_model, data_model, recovery_solver);\npta.save_results(target_file_path);\n\n", "meta": {"author": "indigits", "repo": "sparse-plex", "sha": "43cae2978f62938d001baaa03308a2a717ee6c9b", "save_path": "github-repos/MATLAB/indigits-sparse-plex", "path": "github-repos/MATLAB/indigits-sparse-plex/sparse-plex-43cae2978f62938d001baaa03308a2a717ee6c9b/experiments/cosamp_mmv/ex_ra_mmv_phase_transition_snr_30db_s_4.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9304582632076909, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.7379519904286076}} {"text": "function varargout = leon(X)\n% Leon funcion \n%\n% LEON([x1, x2]) returns the value of the value of the Leon\n% function at the specified points. [x1] and [x2] may be vectors.\n% The search domain is\n%\n% -1.2 < x_i < 1.2\n%\n% The global minimum is \n%\n% f(x1, x2) = f(1, 1) = 0.\n\n% Author: Rody P.S. Oldenhuis\n% Delft University of Technology\n% E-mail: oldenhuis@dds.nl\n% Last edited 20/Jul/2009\n\n % if no input is given, return dimensions, bounds and minimum\n if (nargin == 0)\n varargout{1} = 2; % # dims\n varargout{2} = [-1.2, -1.2]; % LB\n varargout{3} = [+1.2, +1.2]; % UB\n varargout{4} = [1,1]; % solution\n varargout{5} = 0; % function value at solution\n \n % otherwise, output function value\n else\n \n % keep values inside the search domain\n X(X < -1.2) = inf; X(X > 1.2) = inf;\n \n % split input vector X into x1, x2\n if size(X, 1) == 2\n x1 = X(1, :); x2 = X(2, :);\n else\n x1 = X(:, 1); x2 = X(:, 2);\n end\n \n % output function value\n varargout{1} = 100*(x2 - x1.^2).^2 + (1 - x1).^2;\n end\n \nend", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/23147-many-testfunctions-for-global-optimizers/single-objective/leon.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582574225517, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.7379519881154568}} {"text": "function G = get_payoff_G_matrix_from_ygrid_3d( y_1, y_2, y_3, S_0s, sigmas, R, contractParams)\n%UNTITLED5 Summary of this function goes here\n% Detailed explanation goes here\n\npayoff_type = contractParams.payoff_type;\n\nrho12 = R(1,2);\nrho23 = R(2,3);\nrho13 = R(1,3);\n\ngamma = (rho12*rho13 - rho23)/(1 - rho12^2);\n\nif payoff_type == 1 || payoff_type == 2 % G = S_1, or G=S_2, or G=S_3\n dim = contractParams.dim;\n if dim == 1\n payoff = @(y1,y2,y3)S_0s(1)*exp(sigmas(1)*y1);\n elseif dim == 2\n payoff = @(y1,y2,y3)S_0s(2)*exp(sigmas(2)*(y2 + rho12*y1));\n else\n payoff = @(y1,y2,y3)S_0s(3)*exp(sigmas(3)*(rho13*y1 -gamma*y2 + y3));\n end\n \n\nelseif payoff_type == 5 % Geometric Basket Call / Put: G = (sqrt(S_1) * sqrt(S_2) - K)^+ and\n K = contractParams.K;\n if contractParams.call == 1\n payoff = @(y1,y2,y3) max(0, (S_0s(1)*exp(sigmas(1)*y1) * S_0s(2)*exp(sigmas(2)*(y2 + rho12*y1))* S_0s(3)*exp(sigmas(3)*(rho13*y1 -gamma*y2 + y3)))^(1/3) - K);\n else\n payoff = @(y1,y2,y3) max(0, K - (S_0s(1)*exp(sigmas(1)*y1) * S_0s(2)*exp(sigmas(2)*(y2 + rho12*y1))* S_0s(3)*exp(sigmas(3)*(rho13*y1 -gamma*y2 + y3)))^(1/3)); \n end\n \nelseif payoff_type == 6 % Arithmetic Basket Call / Put: G = (sqrt(S_1) * sqrt(S_2) - K)^+\n K = contractParams.K;\n if contractParams.call == 1\n payoff = @(y1,y2,y3) max(0, (1/3)*(S_0s(1)*exp(sigmas(1)*y1) + S_0s(2)*exp(sigmas(2)*(y2 + rho12*y1)) + S_0s(3)*exp(sigmas(3)*(rho13*y1 -gamma*y2 + y3))) - K);\n else\n payoff = @(y1,y2,y3) max(0, K - (1/3)*(S_0s(1)*exp(sigmas(1)*y1) + S_0s(2)*exp(sigmas(2)*(y2 + rho12*y1)) + S_0s(3)*exp(sigmas(3)*(rho13*y1 -gamma*y2 + y3)))); \n end\n \n\n \nend\n \nm_0 = length(y_1);\nG = zeros(m_0, m_0, m_0);\n\nfor i=1:m_0\n for j=1:m_0\n for k=1:m_0\n G(i,j,k) = payoff(y_1(i), y_2(j), y_3(k));\n end\n end\nend\n\nend\n\n", "meta": {"author": "jkirkby3", "repo": "PROJ_Option_Pricing_Matlab", "sha": "3859a390f395e452ad61440f95a5714dd8fb4d90", "save_path": "github-repos/MATLAB/jkirkby3-PROJ_Option_Pricing_Matlab", "path": "github-repos/MATLAB/jkirkby3-PROJ_Option_Pricing_Matlab/PROJ_Option_Pricing_Matlab-3859a390f395e452ad61440f95a5714dd8fb4d90/CTMC/Diffusion_3D/get_payoff_G_matrix_from_ygrid_3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.930458253565792, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.7379519827815603}} {"text": "function v=dlyapsq(a,b)\n% Solves the discrete Lyapunov equation AV'VA' - V'V +BB' =0\n% V is upper triangular with real non-negative diagonal entries\n% this is equivalent to v=chol(dlyap(a,b*b')) but better conditioned numerically\n\n% Copyright (C) Mike Brookes 2002\n% Version: $Id: dlyapsq.m,v 1.4 2007/05/04 07:01:38 dmb Exp $\n%\n% VOICEBOX is a MATLAB toolbox for speech processing.\n% Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html\n%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% This program is free software; you can redistribute it and/or modify\n% it under the terms of the GNU General Public License as published by\n% the Free Software Foundation; either version 2 of the License, or\n% (at your option) any later version.\n%\n% This program is distributed in the hope that it will be useful,\n% but WITHOUT ANY WARRANTY; without even the implied warranty of\n% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n% GNU General Public License for more details.\n%\n% You can obtain a copy of the GNU General Public License from\n% http://www.gnu.org/copyleft/gpl.html or by writing to\n% Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n[q,s]=schur(a');\n[q,s]=rsf2csf(q,s);\n[qd,r]=qr(b'*q,0);\n% save r for testing\nr0=r;\n[m,n]=size(r);\nu=zeros(n,n);\nif m==1\n for i=1:n-1\n in=i+1:n;\n si=s(i,i);\n aa=sqrt(1-si*si');\n u(i,i)=r(1)/aa;\n u(i,in)=(u(i,i)*si'*s(i,in)+aa*r(2:end))/(eye(n-i)-si'*s(in,in));\n r=aa*(u(i,i)*s(i,in)+u(i,in)*s(in,in))-si*r(2:end);\n end\n u(n,n)=r/sqrt(1-s(n,n)*s(n,n)');\n \nelse\n w=zeros(m,1); w(m)=1;\n em=eye(m);\n for i=1:n-m\n in=i+1:n;\n si=s(i,i);\n aa=sqrt(1-si*si');\n u(i,i)=r(1,1)/aa;\n u(i,in)=(u(i,i)*si'*s(i,in)+aa*r(1,2:end))/(eye(n-i)-si'*s(in,in));\n vv=aa*(u(i,i)*s(i,in)+u(i,in)*s(in,in))-si*r(1,2:end);\n rr=zeros(m,n-i);\n rr(1:m-1,:)=r(2:end,2:end);\n [qq,r]=qrupdate(em,rr,w,vv');\n end\n for i=n-m+1:n-1\n in=i+1:n;\n si=s(i,i);\n aa=sqrt(1-si*si');\n u(i,i)=r(1,1)/aa;\n u(i,in)=(u(i,i)*si'*s(i,in)+aa*r(1,2:end))/(eye(n-i)-si'*s(in,in));\n vv=aa*(u(i,i)*s(i,in)+u(i,in)*s(in,in))-si*r(1,2:end);\n rr=zeros(n-i+1,n-i);\n rr(1:n-i,:)=r(2:end,2:end);\n [qq,rr]=qrupdate(eye(n-i+1),rr,w(m-n+i:end),vv');\n r=rr(1:n-i,:);\n end\n \n u(n,n)=r/sqrt(1-s(n,n)*s(n,n)');\n \nend\n\nv=triu(qr(u*q'));\ndv=diag(v);\nix=dv~=0;\nv(ix,:)=diag(abs(dv(ix))./dv(ix))*v(ix,:);\nif isreal(a) & isreal(b)\n v=real(v);\nend\n", "meta": {"author": "decouples", "repo": "Matlab_deep_learning", "sha": "1b823b82686080e32b03e1f1a4648896bd6e3c44", "save_path": "github-repos/MATLAB/decouples-Matlab_deep_learning", "path": "github-repos/MATLAB/decouples-Matlab_deep_learning/Matlab_deep_learning-1b823b82686080e32b03e1f1a4648896bd6e3c44/\u7b2c 19 \u7ae0 \u57fa\u4e8e\u8bed\u97f3\u8bc6\u522b\u7684\u4fe1\u53f7\u706f\u56fe\u50cf\u6a21\u62df\u63a7\u5236\u6280\u672f/voicebox/dlyapsq.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.930458253565792, "lm_q2_score": 0.7931059536292271, "lm_q1q2_score": 0.7379519805064827}} {"text": "function L = log_prob_node(CPD, self_ev, pev)\n% LOG_PROB_NODE Compute prod_m log P(x(i,m)| x(pi_i,m), theta_i) for node i (gaussian)\n% L = log_prob_node(CPD, self_ev, pev)\n%\n% self_ev(m) is the evidence on this node in case m.\n% pev(i,m) is the evidence on the i'th parent in case m (if there are any parents).\n% (These may also be cell arrays.)\n\nif iscell(self_ev), usecell = 1; else usecell = 0; end\n\nuse_log = 1;\nncases = length(self_ev);\nnparents = length(CPD.sizes)-1;\nassert(ncases == size(pev, 2));\n\nif ncases == 0\n L = 0;\n return;\nend\n\nL = 0;\nfor m=1:ncases\n if isempty(CPD.dps)\n i = 1;\n else\n if usecell\n dpvals = cat(1, pev{CPD.dps, m});\n else\n dpvals = pev(CPD.dps, m);\n end\n i = subv2ind(CPD.sizes(CPD.dps), dpvals(:)');\n end\n if usecell\n y = self_ev{m};\n else\n y = self_ev(m);\n end\n if length(CPD.cps) == 0 \n L = L + gaussian_prob(y, CPD.mean(:,i), CPD.cov(:,:,i), use_log);\n else\n if usecell\n x = cat(1, pev{CPD.cps, m});\n else\n x = pev(CPD.cps, m);\n end\n L = L + gaussian_prob(y, CPD.mean(:,i) + CPD.weights(:,:,i)*x, CPD.cov(:,:,i), use_log);\n end\nend\n\n", "meta": {"author": "bayesnet", "repo": "bnt", "sha": "bebba5f437b4e1e29169f0f3669df59fb5392e62", "save_path": "github-repos/MATLAB/bayesnet-bnt", "path": "github-repos/MATLAB/bayesnet-bnt/bnt-bebba5f437b4e1e29169f0f3669df59fb5392e62/BNT/CPDs/@gaussian_CPD/log_prob_node.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582554941719, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.7379519752106595}} {"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Q = T2quaternion2(T)\n% Returns the quaternion corresponding to an homogeneous transformation \n% matrix T. Only the 3x3 rotation matrix in T is used.\n%\n% See also QPROD, QUATERNION2T.\n% The method implemented here was extracted from:\n% Accurate Computation of Quaternions from Rotation Matrices. \n% Soheil Sarabandi and Federico Thomas\n% http://www.iri.upc.edu/files/scidoc/2068-Accurate-Computation-of-Quaternions-from-Rotation-Matrices.pdf\n% Author: Arturo Gil. Universidad Miguel Hern\ufffdndez de Elche. email:\n% arturo.gil@umh.es date: 21/04/2012\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n% Copyright (C) 2012, by Arturo Gil Aparicio\n%\n% This file is part of ARTE (A Robotics Toolbox for Education).\n% \n% ARTE is free software: you can redistribute it and/or modify\n% it under the terms of the GNU Lesser General Public License as published by\n% the Free Software Foundation, either version 3 of the License, or\n% (at your option) any later version.\n% \n% ARTE is distributed in the hope that it will be useful,\n% but WITHOUT ANY WARRANTY; without even the implied warranty of\n% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n% GNU Lesser General Public License for more details.\n% \n% You should have received a copy of the GNU Leser General Public License\n% along with ARTE. If not, see .\nfunction Q = T2quaternion2(T)\n% use only the orientation from T\nR = T(1:3, 1:3);\n\nif R(1,1) + R(2,2) + R(3,3) > 0\n Q(1) = 0.5*sqrt(1+R(1,1) + R(2,2) + R(3,3));\nelse\n num = (R(3,2)-R(2,3))^2 + (R(1,3)-R(3,1))^2 + (R(2,1)-R(1,2))^2;\n den = 3 - R(1,1) - R(2,2) - R(3,3);\n Q(1) = 0.5*sqrt(num/den);\nend\n\nif R(1,1) - R(2,2) - R(3,3) > 0\n Q(2) = 0.5*sqrt(1 + R(1,1) - R(2,2) - R(3,3));\nelse\n num = (R(3,2)-R(2,3))^2 + (R(1,3)+R(3,1))^2 + (R(2,1)+R(1,2))^2;\n den = 3 - R(1,1) + R(2,2) + R(3,3);\n Q(2) = 0.5*sqrt(num/den);\nend\n\nif -R(1,1) + R(2,2) - R(3,3) > 0\n Q(3) = 0.5*sqrt(1 - R(1,1) + R(2,2) - R(3,3));\nelse\n num = (R(3,2)+R(2,3))^2 + (R(1,3)-R(3,1))^2 + (R(2,1)+R(1,2))^2;\n den = 3 + R(1,1) - R(2,2) + R(3,3);\n Q(3) = 0.5*sqrt(num/den);\nend\n\nif -R(1,1) - R(2,2) + R(3,3) > 0\n Q(4) = 0.5*sqrt(1 - R(1,1) - R(2,2) + R(3,3));\nelse\n num = (R(3,2)+R(2,3))^2 + (R(1,3)+R(3,1))^2 + (R(2,1)-R(1,2))^2;\n den = 3 + R(1,1) + R(2,2) + R(3,3);\n Q(4) = 0.5*sqrt(num/den);\nend\n\n\n\n\n ", "meta": {"author": "4rtur1t0", "repo": "ARTE", "sha": "6e836f3156bb36af63b70bd93375c8ff4ee643c4", "save_path": "github-repos/MATLAB/4rtur1t0-ARTE", "path": "github-repos/MATLAB/4rtur1t0-ARTE/ARTE-6e836f3156bb36af63b70bd93375c8ff4ee643c4/lib/T2quaternion2_back.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582497090321, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.737951968347353}} {"text": "%computes the spectral spread from the magnitude spectrum\n%> called by ::ComputeFeature\n%>\n%> @param X: spectrogram (dimension FFTLength X Observations)\n%> @param f_s: sample rate of audio data \n%>\n%> @retval vss spectral spread (in Hz)\n% ======================================================================\nfunction [vss] = FeatureSpectralSpread (X, f_s)\n\n % get spectral centroid as index\n vsc = FeatureSpectralCentroid(X, f_s) * 2 / f_s * (size(X, 1)-1);\n\n % allocate memory\n vss = zeros(size(vsc));\n \n % compute spread\n for n = 1:size(X,2)\n vss(n) = (((0:size(X, 1)-1)-vsc(n)).^2 * X(:, n)) ./ sum(X(:, n));\n end\n vss = sqrt(vss);\n \n % convert from index to Hz\n vss = vss / (size(X, 1)-1) * f_s / 2;\n \n % avoid NaN for silence frames\n vss (sum(X, 1) == 0) = 0;\nend\n\n\n", "meta": {"author": "alexanderlerch", "repo": "ACA-Code", "sha": "85d7258d5fcee1ca52bac52f651d26b665717687", "save_path": "github-repos/MATLAB/alexanderlerch-ACA-Code", "path": "github-repos/MATLAB/alexanderlerch-ACA-Code/ACA-Code-85d7258d5fcee1ca52bac52f651d26b665717687/FeatureSpectralSpread.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308165850443, "lm_q2_score": 0.79053032607222, "lm_q1q2_score": 0.7379053678008336}} {"text": "function overlap = calcRectInt(A,B)\n%\n%each row is a rectangle.\n% A(i,:) = [x y w h]\n% B(j,:) = [x y w h]\n% overlap(i,j) = area of intersection\n% normoverlap(i,j) = overlap(i,j) / (area(i)+area(j)-overlap)\n%\n% Same as built-in rectint, but faster and uses less memory (since avoids repmat).\n\n\nlena = size(A, 1);\nlenb = size(B, 1);\nlena = min(lena, lenb);\nA = A(1:lena, :);\nB = B(1:lena, :);\nleftA = A(:,1);\nbottomA = A(:,2);\nrightA = leftA + A(:,3) - 1;\ntopA = bottomA + A(:,4) - 1;\n\nleftB = B(:,1);\nbottomB = B(:,2);\nrightB = leftB + B(:,3) - 1;\ntopB = bottomB + B(:,4) - 1;\n\ntmp = (max(0, min(rightA, rightB) - max(leftA, leftB)+1 )) .* (max(0, min(topA, topB) - max(bottomA, bottomB)+1 ));\n areaA = A(:,3) .* A(:,4);\n areaB = B(:,3) .* B(:,4);\n overlap = tmp./(areaA+areaB-tmp);\n% if tmp > 0\n%\n% overlap = tmp;\n%\n% areaA = A(3) .* A(4);\n% areaB = B(3) .* B(4);\n% overlap = tmp./(areaA+areaB-tmp);\n% else\n% overlap = 0;\n% end\n", "meta": {"author": "lifeng9472", "repo": "STRCF", "sha": "68c062d4aa7083b8721e37ce19d92497c8dc4de3", "save_path": "github-repos/MATLAB/lifeng9472-STRCF", "path": "github-repos/MATLAB/lifeng9472-STRCF/STRCF-68c062d4aa7083b8721e37ce19d92497c8dc4de3/utils/calcRectInt.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308147331956, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.7379053571238726}} {"text": "function [FaceArea, VertArea] = tess_area(Vertices, Faces)\n% TESS_AREA: Compute the surface area associated with each face and each vertex.\n\n% @=============================================================================\n% This function is part of the Brainstorm software:\n% https://neuroimage.usc.edu/brainstorm\n% \n% Copyright (c) University of Southern California & McGill University\n% This software is distributed under the terms of the GNU General Public License\n% as published by the Free Software Foundation. Further details on the GPLv3\n% license can be found at http://www.gnu.org/copyleft/gpl.html.\n% \n% FOR RESEARCH PURPOSES ONLY. THE SOFTWARE IS PROVIDED \"AS IS,\" AND THE\n% UNIVERSITY OF SOUTHERN CALIFORNIA AND ITS COLLABORATORS DO NOT MAKE ANY\n% WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF\n% MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, NOR DO THEY ASSUME ANY\n% LIABILITY OR RESPONSIBILITY FOR THE USE OF THIS SOFTWARE.\n%\n% For more information type \"brainstorm license\" at command prompt.\n% =============================================================================@\n%\n% Authors: Francois Tadel, 2012-2016\n\n% Compute the area of all the faces\nr12 = Vertices(Faces(:,1),:); % temporary holding\nr13 = Vertices(Faces(:,3),:) - r12; % negative of r31\nr12 = Vertices(Faces(:,2),:) - r12; % from 1 to 2\nFaceArea = sqrt(sum(bst_cross(r12,r13,2).^2, 2)) / 2;\n\n% Compute the triangle area only if needed\nif (nargout >= 2)\n % Build vertex-face connectivity matrix, with the area information\n nFaces = size(Faces,1);\n rowno = double([Faces(:,1); Faces(:,2); Faces(:,3)]);\n colno = [1:nFaces, 1:nFaces, 1:nFaces]';\n data = [FaceArea; FaceArea; FaceArea];\n VertFacesArea = sparse(rowno,colno,data);\n\n % Compute the vertex area: 1/3 of each triangle involving this vertex\n VertArea = 1/3 * full(sum(VertFacesArea,2));\nend\n \n ", "meta": {"author": "brainstorm-tools", "repo": "brainstorm3", "sha": "a892cfaabde1eaa2f9a3ac015c05b73f3739433a", "save_path": "github-repos/MATLAB/brainstorm-tools-brainstorm3", "path": "github-repos/MATLAB/brainstorm-tools-brainstorm3/brainstorm3-a892cfaabde1eaa2f9a3ac015c05b73f3739433a/toolbox/anatomy/tess_area.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.927363293639213, "lm_q2_score": 0.7956581097540519, "lm_q1q2_score": 0.7378641252722681}} {"text": "\n% This test example is taken from demo_gabmulappr\n\n% Setup parameters for the Gabor system and length of the signal\nL=576; % Length of the signal\na=32; % Time shift \nM=72; % Number of modulations\nN=L/a;\nfs=44100; % assumed sampling rate\nSNRtv=63; % signal to noise ratio of change rate of time-variant system\n\n% construction of slowly time variant system\n% take an initial vector and multiply by random vector close to one\nA = [];\nc1=(1:L/2); c2=(L/2:-1:1); c=[c1 c2].^(-1); % weight of decay x^(-1)\nA(1,:)=(tester_rand(1,L)-0.5).*c; % convolution kernel\nNlvl = exp(-SNRtv/10);\nSlvl = 1-Nlvl;\nfor ii=2:L;\n A(ii,:)=(Slvl*circshift(A(ii-1,:),[0 1]))+(Nlvl*(tester_rand(1,L)-0.5)); \nend;\nA = A/norm(A)*0.99; % normalize matrix\n\n% perform best approximation by gabor multiplier\ng=gabtight(a,M,L);\nsym1=gabmulappr(A,g,a,M);\n\n\n% Now do the same using the general frame algorithm.\n\nF=frame('dgt',g,a,M);\n\nsym2=framemulappr(F,F,A);\n\n\nnorm(sym1-reshape(sym2,M,N))\n\n% Test for exactness\n\ntestsym=tester_crand(M,N);\nFT=frsynmatrix(F,L);\n\nT=FT*diag(testsym(:))*FT';\n\n\nsym1b=gabmulappr(T,g,a,M);\nsym2b=framemulappr(F,F,T);\n\nnorm(testsym-sym1b)\nnorm(testsym-reshape(sym2b,M,N))\n", "meta": {"author": "ltfat", "repo": "ltfat", "sha": "4496a06ad8dddb85cd2e007216b765dc996ef327", "save_path": "github-repos/MATLAB/ltfat-ltfat", "path": "github-repos/MATLAB/ltfat-ltfat/ltfat-4496a06ad8dddb85cd2e007216b765dc996ef327/testing/test_framemulappr.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632896242074, "lm_q2_score": 0.7956580927949806, "lm_q1q2_score": 0.7378641063504761}} {"text": "% LOWPASSFILTER - Constructs a low-pass butterworth filter.\n%\n% usage: f = lowpassfilter(sze, cutoff, n)\n% \n% where: sze is a two element vector specifying the size of filter \n% to construct [rows cols].\n% cutoff is the cutoff frequency of the filter 0 - 0.5\n% n is the order of the filter, the higher n is the sharper\n% the transition is. (n must be an integer >= 1).\n% Note that n is doubled so that it is always an even integer.\n%\n% 1\n% f = --------------------\n% 2n\n% 1.0 + (w/cutoff)\n%\n% The frequency origin of the returned filter is at the corners.\n%\n% See also: HIGHPASSFILTER, HIGHBOOSTFILTER, BANDPASSFILTER\n%\n\n% Copyright (c) 1999 Peter Kovesi\n% School of Computer Science & Software Engineering\n% The University of Western Australia\n% http://www.csse.uwa.edu.au/\n% \n% Permission is hereby granted, free of charge, to any person obtaining a copy\n% of this software and associated documentation files (the \"Software\"), to deal\n% in the Software without restriction, subject to the following conditions:\n% \n% The above copyright notice and this permission notice shall be included in \n% all copies or substantial portions of the Software.\n%\n% The Software is provided \"as is\", without warranty of any kind.\n\n% October 1999\n% August 2005 - Fixed up frequency ranges for odd and even sized filters\n% (previous code was a bit approximate)\n\nfunction f = lowpassfilter(sze, cutoff, n)\n \n if cutoff < 0 | cutoff > 0.5\n\terror('cutoff frequency must be between 0 and 0.5');\n end\n \n if rem(n,1) ~= 0 | n < 1\n\terror('n must be an integer >= 1');\n end\n\n if length(sze) == 1\n\trows = sze; cols = sze;\n else\n\trows = sze(1); cols = sze(2);\n end\n\n % Set up X and Y matrices with ranges normalised to +/- 0.5\n % The following code adjusts things appropriately for odd and even values\n % of rows and columns.\n if mod(cols,2)\n\txrange = [-(cols-1)/2:(cols-1)/2]/(cols-1);\n else\n\txrange = [-cols/2:(cols/2-1)]/cols;\t\n end\n\n if mod(rows,2)\n\tyrange = [-(rows-1)/2:(rows-1)/2]/(rows-1);\n else\n\tyrange = [-rows/2:(rows/2-1)]/rows;\t\n end\n \n [x,y] = meshgrid(xrange, yrange);\n radius = sqrt(x.^2 + y.^2); % A matrix with every pixel = radius relative to centre.\n f = ifftshift( 1.0 ./ (1.0 + (radius ./ cutoff).^(2*n)) ); % The filter", "meta": {"author": "zhangqianqianQQ", "repo": "MachineVisionAlgorithm", "sha": "683338f6c3b1aab9fa2b80026915fe936aebf0ee", "save_path": "github-repos/MATLAB/zhangqianqianQQ-MachineVisionAlgorithm", "path": "github-repos/MATLAB/zhangqianqianQQ-MachineVisionAlgorithm/MachineVisionAlgorithm-683338f6c3b1aab9fa2b80026915fe936aebf0ee/\u53bb\u566a\u7b97\u6cd5/CGCSF-master/functions/lowpassfilter.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970748488297, "lm_q2_score": 0.837619959279793, "lm_q1q2_score": 0.7377732099686376}} {"text": "function term = sdlfmjMeanCompute(sdlfmKern, t , option)\n\n% SDLFMJMEANCOMPUTE Jolt mean for the switching dynamical LFM model.\n% Computes the terms $r_d$ and $q_d$ that appear in the mean function \n% associated with the switching dynamical LFM model. If the mean function \n% is mu(t), then\n%\n% mu(t) = r_d(t)y_d(t_0) + q_d(t)\\dot{y}_d(t_0),\n%\n% where $y_d(t_0)$ is the initial condition associated to the position and\n% $\\dot{y}_d(t_0)$ is the initial condition associated to the velocity.\n% \n% FORMAT\n% DESC\n% ARG sdlfmKern : switching dynamical LFM kernel structure with the\n% parameters.\n% ARG t : input times for which the mean is to be computed.\n% RETURN term : the value of $r_d$.\n%\n% FORMAT\n% DESC\n% Computes the terms that appear in the mean function associated with the\n% switching dynamical LFM model.\n% ARG sdlfmKern : switching dynamical LFM kernel structure with the\n% parameters.\n% ARG t : input times for which the mean is to be computed.\n% ARG option : indicates which term of the mean should be computed. Option\n% 'Pos' computes the term $r_d$ and option 'Vel' computes $q_d$ that \n% accompanies the initial condition of the velocity.\n% RETURN term : the value of $r_d$ or $q_d$ depending of option.\n%\n% COPYRIGHT : Mauricio A. Alvarez, 2010\n\n% KERN\n\nif nargin < 3\n option = 'Pos';\nend\n \nalpha = sdlfmKern.damper/(2*sdlfmKern.mass);\nomega = sqrt(sdlfmKern.spring/sdlfmKern.mass-alpha^2);\nfreq = omega*t;\n\nswitch option\n case 'Pos' \n term = (alpha^2/omega + omega)*exp(-alpha*t).*...\n ((omega^2 - alpha^2)*sin(freq) + 2*alpha*omega*cos(freq));\n case 'Vel'\n term = exp(-alpha*t).*((3*alpha*omega - alpha^3/omega)*sin(freq)...\n +(3*alpha^2- omega^2)*cos(freq)); \n otherwise\n error('No recognized option') \nend\n", "meta": {"author": "SheffieldML", "repo": "GPmat", "sha": "4b5914a38ecbad9fb7a13a3392970bfc28c9d911", "save_path": "github-repos/MATLAB/SheffieldML-GPmat", "path": "github-repos/MATLAB/SheffieldML-GPmat/GPmat-4b5914a38ecbad9fb7a13a3392970bfc28c9d911/kern/sdlfmjMeanCompute.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9362850039701653, "lm_q2_score": 0.78793120560257, "lm_q1q2_score": 0.7377281719658194}} {"text": "% LOGNORMAL_LOGPDF\n%\n% Y = LOGNORMAL_LOGPDF(X)\n% Y = LOGNORMAL_LOGPDF(X, MU, SIGMA)\n%\n% MU is the location parameter in (-INF, INF), default 0\n% SIGMA is the scale parameter in (0, INF)\n\n% Last modified 2010-11-12\n% Copyright (c) Jaakko Luttinen (jaakko.luttinen@tkk.fi)\n\nfunction y = lognormal_logpdf(x, varargin)\n\nif nargin <= 3\n if nargin == 1\n mu = 0;\n sigma = 1;\n else\n mu = varargin{1};\n sigma = varargin{2};\n end\n logx = log(x);\n y = -0.5*log(2*pi) ...\n -logx ...\n -log(sigma) ...\n -0.5*((logx-mu)./sigma).^2;\nend\n", "meta": {"author": "jluttine", "repo": "matlab", "sha": "63406c7782b0869948f06e1dbc594460c165d24e", "save_path": "github-repos/MATLAB/jluttine-matlab", "path": "github-repos/MATLAB/jluttine-matlab/matlab-63406c7782b0869948f06e1dbc594460c165d24e/distributions/lognormal_logpdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.936285002192296, "lm_q2_score": 0.787931190663057, "lm_q1q2_score": 0.7377281565773387}} {"text": "function [W] = amuse(X)\n% BSS using eigenvalue value decomposition\n% Program written by A. Cichocki and R. Szupiluk\n% \n% X [m x N] matrix of observed (measured) signals,\n% W separating matrix,\n% y estimated separated sources\n% p time delay used in computation of covariance matrices\n% optimal time-delay default p= 1\n%\n% First stage: Standard prewhitening\n\n[m,N]=size(X);\nif nargin==1,\n n=m; % \n end;\n\nRxx=(X*X')/N;\n\n[Ux,Dx,Vx]=svd(Rxx);\n Dx=diag(Dx);\n% n=xxx;\n if n1e-199)); %Detection the number of sources\n Q= diag(real(sqrt(1./Dx(1:n))))*Ux(:,1:n)';\nend;\n%\n% else %assumes no noise\n% Q=inv(sqrtm(Rxx));\n% end;\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Second stage: Fast separation using sorting EVD\n% notation the same as used in the Chapter 4\nXb=Q*X;\np=1; \n% paramter p can take here value different than 1\n% for example -1 or 2.\nN=max(size(Xb));\nXb=Xb-kron(mean(Xb')',ones(1,N));\n\nRxbxbp=(Xb(:,1:N-1)*Xb(:,2:N)')/(N-1);\nRxbxbp= Rxbxbp+Rxbxbp';\n[Vxb Dxb]=eig(Rxbxbp);\n[D1 perm]=sort(diag(Dxb));\nD1=flipud(D1);\nVxb=Vxb(:,flipud(perm));\nW = Vxb'*Q;\n%y = Vxb' * x1;\n\n\n", "meta": {"author": "aludnam", "repo": "MATLAB", "sha": "020b5cb02cc843e09a0ed689589382f18cce5e6d", "save_path": "github-repos/MATLAB/aludnam-MATLAB", "path": "github-repos/MATLAB/aludnam-MATLAB/MATLAB-020b5cb02cc843e09a0ed689589382f18cce5e6d/NMFLABSP_ver1.2/amuse.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850057480346, "lm_q2_score": 0.7879311856832191, "lm_q1q2_score": 0.7377281547164685}} {"text": "%NMC Nearest Mean Classifier\n% \n% W = NMC(A)\n% W = A*NMC\n%\n% INPUT\n% A Dataset\n%\n% OUTPUT\n% W Nearest Mean Classifier \n%\n% DESCRIPTION\n% Computation of the nearest mean classifier between the classes in the\n% dataset A. The use of soft labels is supported. Prior probabilities are\n% not used.\n%\n% The difference with NMSC is that NMSC is based on an assumption of normal\n% distributions and thereby automatically scales the features and is\n% sensitive to class priors. NMC is a plain nearest mean classifier for\n% which the assigned classes are are sensitive to feature scaling and \n% unsensitive to class priors.\n%\n% The estimated class confidences by B*NMC(A), however, are based on\n% assumed spherical gaussian distributions of the same size.\n%\n% SEE ALSO (PRTools Guide)\n% DATASETS, MAPPINGS, NMSC, LDC, FISHERC, QDC, UDC \n\n% Copyright: R.P.W. Duin, r.p.w.duin@37steps.com\n% Faculty EWI, Delft University of Technology\n% P.O. Box 5031, 2600 GA Delft, The Netherlands\n\n% $Id: nmc.m,v 1.14 2009/12/09 15:49:54 duin Exp $\n\nfunction W = nmc(varargin)\n \n\tmapname = 'NearestMean';\n argin = setdefaults(varargin,[],false);\n \n if mapping_task(argin,'definition')\n W = define_mapping(argin,'untrained',mapname);\n \n elseif mapping_task(argin,'training')\t\t\t% Train a mapping.\n \n [a,flag] = deal(argin{:});\n % flag = true forces execution by knn_map instead of normal_map\n % flag = false (defaults) finds posteriors by spherical normal\n % distributions\n\n if nargin < 2, flag = false; end\n % flag=true forces to skip computation of posteriors based on normal\n % densities\n\n\n if nargin < 1 | isempty(a)\n W = prmapping(mfilename);\n W = setname(W,'NearestMean');\n return\n end\n\n islabtype(a,'crisp','soft');\n isvaldfile(a,1,2); % at least 1 object per class, 2 classes\n\n [m,k,c] = getsize(a);\n if isdatafile(a), a = setfeatsize(a,k); end\n\n if ~flag & c == 2 % 2-class case: store linear classifier\n u = meancov(a);\n u1 = +u(1,:);\n u2 = +u(2,:);\n R = [u1-u2]';\n offset =(u2*u2' - u1*u1')/2;\n W = affine([R -R],[offset -offset],a,getlablist(a));\n W = cnormc(W,a);\n W = setname(W,'Nearest Mean');\n else \n if ~flag & all(classsizes(a) > 1)\n a = setprior(a,0); % NMC should be independent of priors: make them equal\n p = getprior(a);\n U = zeros(c,k);\n V = zeros(c,k);\n s = sprintf('NMC: Processing %i classes: ',c);\n prwaitbar(c,s);\n for j=1:c\n prwaitbar(c,j,[s int2str(j)]);\n b = seldat(a,j);\n [v,u] = var(b);\n U(j,:) = +u;\n V(j,:) = +v;\n end\n prwaitbar(0);\n %G = mean(V'*p') * eye(k);\n G = mean(V(:));\n w.mean = +U;\n w.cov = G;\n w.prior =p;\n W = normal_map(w,getlablist(a),k,c);\n W = setname(W,'Nearest Mean');\n W = setcost(W,a);\n else\n u = meancov(a);\n W = knnc(u,1);\n W = setname(W,mapname);\n end\n\n end\n\n W = setcost(W,a); \n \n end\n\t\n\treturn\n\n", "meta": {"author": "marianux", "repo": "ecg-kit", "sha": "c8e3de47c54a9214138143676d2aa546b0540dd2", "save_path": "github-repos/MATLAB/marianux-ecg-kit", "path": "github-repos/MATLAB/marianux-ecg-kit/ecg-kit-c8e3de47c54a9214138143676d2aa546b0540dd2/common/prtools/nmc.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894632969137, "lm_q2_score": 0.824461928533133, "lm_q1q2_score": 0.7377198465409005}} {"text": "function pass = test_integral(pref)\n% Test path integral for 3D functions.\n\nif ( nargin == 0)\n pref = chebfunpref; \nend\ntol = 1e3*pref.cheb3Prefs.chebfun3eps;\n\nf = chebfun3(@(x,y,z) 2*x.*y+3*z); \ncurve = chebfun(@(t) [2*t 5*t 4*t], [0, 1]); \nexact = 38*sqrt(5);\npass(1) = abs(integral(f, curve) - exact)/exact < tol;\n\nf = chebfun3(@(x,y,z) x.^2.*z); \ncurve = chebfun(@(t) [-t 6+2*t 2+5*t], [0 1]);\nexact = 23*sqrt(30)/12;\npass(2) = abs(integral(f, curve) - exact )/exact < tol;\n\n% http://tutorial.math.lamar.edu/Classes/CalcIII/LineIntegralsPtI.aspx\ndom = [-1 1 -1 1 0 12*pi];\nf = chebfun3(@(x,y,z) x.*y.*z, dom);\ncurve = chebfun(@(t) [cos(t) sin(t) 3*t], [0 4*pi]);\nexact = -3*sqrt(10)*pi;\npass(3) = abs(integral(f, curve) - exact )/exact < tol;\n\nend", "meta": {"author": "chebfun", "repo": "chebfun", "sha": "8c49396a55e46ddd57a1d108c6a8f32e37536d54", "save_path": "github-repos/MATLAB/chebfun-chebfun", "path": "github-repos/MATLAB/chebfun-chebfun/chebfun-8c49396a55e46ddd57a1d108c6a8f32e37536d54/tests/chebfun3/test_integral.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012701768145, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.7377182806262456}} {"text": "function point = cart2geod(src, curve)\n%CART2GEOD Convert cartesian coordinates to geodesic coord.\n%\n% PT2 = cart2geod(PT1, CURVE)\n% PT1 is the point to transform, in Cartesian coordinates (same system\n% used for the curve).\n% CURVE is a N-by-2 array which represents coordinates of curve vertices.\n%\n% The function first compute the projection of PT1 on the curve. Then,\n% the first geodesic coordinate is the length of the curve to the\n% projected point, and the second geodesic coordinate is the \n% distance between PT1 and it projection.\n%\n%\n% TODO : add processing of points not projected on the curve.\n% -> use the closest end \n%\n% See also\n% polylines2d, geod2cart, curveLength\n%\n\n% ---------\n% Author: David Legland\n% e-mail: david.legland@grignon.inra.fr\n% created the 08/04/2004.\n% Copyright 2010 INRA - Cepia Software Platform.\n\n% HISTORY\n% 15/02/2007 replace minDistance by minDistancePoints\n\n\n% parametrization approximation\nt = parametrize(curve);\n\n% compute distance between each src point and the curve\n[dist, ind] = minDistancePoints(src, curve);\n\n% convert to 'geodesic' coordinate\npoint = [t(ind) dist];\n\n% Old version:\n% for i=1:size(pt1, 1)\n% [dist, ind] = minDistance(src(i,:), curve);\n% point(i,:) = [t(ind) dist];\n% end\n", "meta": {"author": "rpng", "repo": "lips", "sha": "a97157e586b509c9c2e3e01e64e4347f36d0b63e", "save_path": "github-repos/MATLAB/rpng-lips", "path": "github-repos/MATLAB/rpng-lips/lips-a97157e586b509c9c2e3e01e64e4347f36d0b63e/lips_matlab/matlab/functions/matGeom/polygons2d/cart2geod.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9184802417938535, "lm_q2_score": 0.8031737963569014, "lm_q1q2_score": 0.7376992626803741}} {"text": "function [U,c] = MgnCalibration(X)\n% performs magnetometer calibration from a set of data\n% using Merayo technique with a non iterative algoritm\n% J.Merayo et al. \"Scalar calibration of vector magnemoters\"\n% Meas. Sci. Technol. 11 (2000) 120-132.\n%\n% X : a Nx3 (or 3xN) data matrix\n% each row (columns) contains x, y, z measurements\n% N must be such that the data set describes\n% as completely as possible the 3D space\n% In any case N > 10\n% \n% The calibration tries to find the best 3D ellipsoid that fits the data set\n% and returns the parameters of this ellipsoid\n%\n% U : shape ellipsoid parameter, (3x3) upper triangular matrix\n% c : ellipsoid center, (3x1) vector\n%\n% Ellipsoid equation : (v-c)'*(U'*U)(v-c) = 1 \n% with v a rough triaxes magnetometer measurement\n%\n% calibrated measurement w = U*(v-c)\n%\n% author : Alain Barraud, Suzanne Lesecq 2008\n%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n[N,m] = size(X);\nif m>3&&N==3,X = X';N = m;m = 3;end;%check that X is not transposed\nif N<=10,U = [];c = [];return;end;%not enough data no calibration !!\n% write the ellipsoid equation as D*p=0\n% the best parameter is the solution of min||D*p|| with ||p||=1;\n% form D matrix from X measurements\nx = X(:,1); y = X(:,2); z = X(:,3); \nD = [x.^2, y.^2, z.^2, x.*y, x.*z, y.*z, x, y, z, ones(N,1)];\nD=triu(qr(D));%avoids to compute the svd of a large matrix\n[U,S,V] = svd(D);%because usually N may be very large\np = V(:,end);if p(1)<0,p =-p;end;\n% the following matrix A(p) must be positive definite\n% The optimization done by svd does not include such a constraint\n% With \"good\" data the constraint is allways satisfied\n% With too poor data A may fail to be positive definite\n% In this case the calibration fails\n%\nA = [p(1) p(4)/2 p(5)/2;\n p(4)/2 p(2) p(6)/2; \n p(5)/2 p(6)/2 p(3)];\n[U,ok] = fchol(m,A);\nif ~ok,U = [];c = [];return;end%calibration fails too poor data!!\nb = [p(7);p(8);p(9)];\nv = Utsolve(U,b/2,m);\nd = p(10);\ns = 1/sqrt(v*v'-d);\nc =-Usolve(U,v,m)';%ellipsoid center\nU = s*U;%shape ellipsoid parameter\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nfunction [A,ok] = fchol(n,A)\n% performs Cholesky factoristation\nA(1,1:n) = A(1,1:n)/sqrt(A(1,1));\nA(2:n,1) = 0;\nfor j=2:n\n A(j,j:n) = A(j,j:n) - A(1:j-1,j)'*A(1:j-1,j:n);\n if A(j,j)<=0,ok=0;break;end%A is not positive definite\n A(j,j:n) = A(j,j:n)/sqrt(A(j,j));\n A(j+1:n,j) = 0;\nend\nok=1;\nfunction x=Utsolve(U,b,n)\n% solves U'*x=b\nx(1) = b(1)/U(1,1);\nfor k=2:n\n x(k) = (b(k)-x(1:k-1)*U(1:k-1,k))/U(k,k);\nend\nfunction x=Usolve(U,b,n)\n% solves U*x=b\nx(n) = b(n)/U(n,n);\nfor k=n-1:-1:1\n x(k) = (b(k)-U(k,k+1:n)*x(k+1:n)')/U(k,k);\nend\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/23398-magnetometers-calibration/MgnCalibration.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067195846918, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.737664640801982}} {"text": "function area = polyArea(v,varargin)\n% area of a flat polygon given by vertices v1, v2, ..., v_n\n%\n% Input\n% v - @vector3d\n%\n% Output\n% area - area the polygon v1, v2, ..., v_n\n%\n\nnv = length(v);\nif nv<3, area = 0; return; end\n\n% formula from http://geomalgorithms.com/a01-_area.html\nv1 = v.subSet(1);\nN = normalize(mean(cross(v.subSet(2)-v1,v.subSet(3:nv-1)-v1)));\n\narea = dot(N, sum(cross(v.subSet(1:nv-1),v.subSet(2:nv))))./2;\n", "meta": {"author": "mtex-toolbox", "repo": "mtex", "sha": "f0ce46a720935e9ae8106ef919340534bca1adcb", "save_path": "github-repos/MATLAB/mtex-toolbox-mtex", "path": "github-repos/MATLAB/mtex-toolbox-mtex/mtex-f0ce46a720935e9ae8106ef919340534bca1adcb/geometry/@vector3d/polyArea.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.92414182206801, "lm_q2_score": 0.7981867825403177, "lm_q1q2_score": 0.7376377875674117}} {"text": "function[f,name]=tidefreq(str)\n%TIDEFREQ Frequencies of the eight major tidal components.\n%\n% [F,NAME]=TIDEFREQ returns the frequencies of the eight major tidal \n% components together with a string matrix containing their names. In\n% order of increasing frequency, these are \n% \n% Mf O1 P1 K1 N2 M2 S2 K2.\n%\n% The units are given in *radians* per hour. See Gill (1982) page 335.\n% \n% F=TIDEFREQ(STR) returns the frequency for the component named STR, \n% if STR is a string. F=TIDEFREQ(N) where N is a number also works.\n% \n% Usage: [f,name]=tidefreq;\n% f=tidefreq(str);\n% __________________________________________________________________\n% This is part of JLAB --- type 'help jlab' for more information\n% (C) 2005--2015 J.M. Lilly --- type 'help jlab_license' for details \n\nname=('MFO1P1K1N2M2S2K2');\n \n%Gill only gives first two decimal points\n%I got the more exact numbers from\n%http://oceanworld.tamu.edu/resources/ocng_textbook/chapter17/chapter17_04.htm\n\np(1)=327.85;\np(2)=25.8194;\np(3)=24.0659;\np(4)=23.9344;\np(5)=12.6584;\np(6)=12.4206;\np(7)=12.0000;\np(8)=11.9673;\n\nf=1./p;\nif nargin==1\n if ~ischar(str)\n f=f(str);\n else\n str=upper(str);\n ii=strfind(name,str);\n f=f((ii-1)/2+1); \n end\n clear name\nelse\n name=reshape(name,2,8)';\nend\n\nf=f*2*pi;", "meta": {"author": "jonathanlilly", "repo": "jLab", "sha": "9f32f63e647209bc1cb81c8713deb954857f1919", "save_path": "github-repos/MATLAB/jonathanlilly-jLab", "path": "github-repos/MATLAB/jonathanlilly-jLab/jLab-9f32f63e647209bc1cb81c8713deb954857f1919/jsphere/tidefreq.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418199787564, "lm_q2_score": 0.7981867825403176, "lm_q1q2_score": 0.737637785899797}} {"text": "function [pTS,fmin]=grTravSale(C)\n% Function [pTS,fmin]=grTravSale(C) solve the nonsymmetrical\n% traveling salesman problem.\n% Input parameter: \n% C(n,n) - matrix of distances between cities, \n% maybe, nonsymmetrical;\n% n - number of cities.\n% Output parameters: \n% pTS(n) - the order of cities;\n% fmin - length of way.\n% Uses the reduction to integer LP-problem:\n% Look: Miller C.E., Tucker A. W., Zemlin R. A. \n% Integer Programming Formulation of Traveling Salesman Problems. \n% J.ACM, 1960, Vol.7, p. 326-329.\n% Needed other products: MIQP.M.\n% This software may be free downloaded from site:\n% http://control.ee.ethz.ch/~hybrid/miqp/\n% Author: Sergiy Iglin\n% e-mail: siglin@yandex.ru\n% personal page: http://iglin.exponenta.ru\n\n% ============= Input data validation ==================\nif nargin<1,\n error('There are no input data!')\nend\nif ~isnumeric(C),\n error('The array C must be numeric!') \nend\nif ~isreal(C),\n error('The array C must be real!') \nend\ns=size(C); % size of array C\nif length(s)~=2,\n error('The array C must be 2D!') \nend\nif s(1)~=s(2),\n error('Matrix C must be square!')\nend\nif s(1)<3,\n error('Must be not less than 3 cities!')\nend\n\n% ============ Size of problem ====================\nn=s(1); % number of vertexes\nm=n*(n-1); % number of arrows\n\n% ============ Parameters of integer LP problem ========\nAeq=[]; % for the matrix of the boundary equations\nfor k1=1:n,\n z1=zeros(n);\n z1(k1,:)=1;\n z2=[z1;eye(n)];\n Aeq=[Aeq z2([1:2*n-1],setdiff([1:n],k1))];\nend\nAeq=[Aeq zeros(2*n-1,n-1)];\nA=[]; % for the matrix of the boundary inequations\nfor k1=2:n,\n z1=[];\n for k2=1:n,\n z2=eye(n)*(n-1)*(k2==k1);\n z1=[z1 z2(setdiff([2:n],k1),setdiff([1:n],k2))];\n end\n z2=-eye(n);\n z2(:,k1)=z2(:,k1)+1;\n A=[A;[z1 z2(setdiff([2:n],k1),2:n)]];\nend\nbeq=ones(2*n-1,1); % the right parts of the boundary equations\nb=ones((n-1)*(n-2),1)*(n-2); % the right parts of the boundary inequations\nC1=C'+diag(ones(1,n)*NaN);\nC2=C1(:);\nc=[C2(~isnan(C2));zeros(n-1,1)]; % the factors for objective function\nvlb=[zeros(m,1);-inf*ones(n-1,1)]; % the lower bounds\nvub=[ones(m,1);inf*ones(n-1,1)]; % the upper bounds\nH=zeros(n^2-1); % Hessian\n\n% ============= We solve the MIQP problem ==========\n[xmin,fmin]=MIQP(H,c,A,b,Aeq,beq,[1:m],vlb,vub);\n\n% ============= We return the results ==============\neik=round(xmin(1:m)); % the arrows of the way\ne1=[zeros(1,n-1);reshape(eik,n,n-1)];\ne2=[e1(:);0]; % we add zero to a diagonal\ne3=(reshape(e2,n,n))'; % the matrix of the way\npTS=[1 find(e3(1,:))]; % we build the way\nwhile pTS(end)>1, % we add the city to the way\n pTS=[pTS find(e3(pTS(end),:))];\nend\nreturn", "meta": {"author": "HuangCongQing", "repo": "Algorithms_MathModels", "sha": "e15b0e9053b11f08b5ce1e3492c4acb444409c8b", "save_path": "github-repos/MATLAB/HuangCongQing-Algorithms_MathModels", "path": "github-repos/MATLAB/HuangCongQing-Algorithms_MathModels/Algorithms_MathModels-e15b0e9053b11f08b5ce1e3492c4acb444409c8b/GraphTheory(\u56fe\u8bba)/basic/grTravSale.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418178895029, "lm_q2_score": 0.7981867825403177, "lm_q1q2_score": 0.7376377842321825}} {"text": "% Test how accurately we can orthogonalize ill-conditioned bases of tangent\n% vectors. We test three metrics:\n% 1) Is Q actually orthonormal (the figure displays log(|Q'Q|); since Q'Q\n% should be identity, we hope to see 0 on diagonal and -inf everywhere\n% else.)\n% 2) Is A = QR? This is in the title of the plots.\n% 3) How much time does it take to compute?\n%\n% Nicolas Boumal, Oct. 5, 2017\n\nclear all;\nclc;\n\nM = spherefactory(100);\n\n% M = stiefelcomplexfactory(200, 56);\n% M = productmanifold(struct('S', spherefactory(5), 'R', rotationsfactory(3, 10)));\n\nx = M.rand();\n\n% Create a poorly conditioned basis\nA = cell(M.dim()-5, 1);\nA{1} = M.randvec(x);\nfor k = 2 : numel(A)\n A{k} = M.lincomb(x, 1, A{k-1}, 1e-6, M.randvec(x));\nend\n\nt1 = tic();\n[Q1, R1] = orthogonalize(M, x, A);\nt1 = toc(t1);\n\nt2 = tic();\n[Q2, R2] = orthogonalizetwice(M, x, A);\nt2 = toc(t2);\n\nt3 = tic();\n[Q3, R3] = orthogonalize_legacy(M, x, A);\nt3 = toc(t3);\n\n% To check if Q is really orthonormal\nG1 = grammatrix(M, x, Q1);\nG2 = grammatrix(M, x, Q2);\nG3 = grammatrix(M, x, Q3);\n\n% To check of QR = A\ndistsq = 0;\nfor k = 1 : numel(A)\n distsq = distsq + M.norm(x, M.lincomb(x, 1, lincomb(M, x, Q1(1:k), R1(1:k, k)), -1, A{k}))^2;\nend\ndist1 = sqrt(distsq);\n\ndistsq = 0;\nfor k = 1 : numel(A)\n distsq = distsq + M.norm(x, M.lincomb(x, 1, lincomb(M, x, Q2(1:k), R2(1:k, k)), -1, A{k}))^2;\nend\ndist2 = sqrt(distsq);\n\ndistsq = 0;\nfor k = 1 : numel(A)\n distsq = distsq + M.norm(x, M.lincomb(x, 1, lincomb(M, x, Q3(1:k), R3(1:k, k)), -1, A{k}))^2;\nend\ndist3 = sqrt(distsq);\n\n\nsubplot(1, 3, 1);\nimagesc(log10(abs(G1))); axis equal, axis tight; colorbar; set(gca, 'CLim', [-20, 0]);\ntitle(sprintf('MGS: CPU time: %g\\n||A - QR|| = %g', t1, dist1));\nsubplot(1, 3, 2);\nimagesc(log10(abs(G2))); axis equal, axis tight; colorbar; set(gca, 'CLim', [-20, 0]);\ntitle(sprintf('MGS-twice: CPU time: %g\\n||A - QR|| = %g', t2, dist2));\nsubplot(1, 3, 3);\nimagesc(log10(abs(G3))); axis equal, axis tight; colorbar; set(gca, 'CLim', [-20, 0]);\ntitle(sprintf('Legacy: CPU time: %g\\n||A - QR|| = %g', t3, dist3));\n", "meta": {"author": "NicolasBoumal", "repo": "manopt", "sha": "b8b54a6af8b965f7ae572972ba0d15787427744b", "save_path": "github-repos/MATLAB/NicolasBoumal-manopt", "path": "github-repos/MATLAB/NicolasBoumal-manopt/manopt-b8b54a6af8b965f7ae572972ba0d15787427744b/tests/test_orthogonalize.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92414182206801, "lm_q2_score": 0.7981867753392728, "lm_q1q2_score": 0.737637780912625}} {"text": "function [c, ceq] = unitdisk(x)\n% Unit disk. The vector x should be a row vector. This is to test the\n% non-linear constraint functionality of pso.\n% \n% Non-linear constraints such that\n% c(x) <= 0\n% ceq(x) = 0\n% Within a tolerance of options.TolCon\n\nc = x*x' - 1 ;\nceq = [] ;", "meta": {"author": "Arrowstar", "repo": "ksptot", "sha": "2b414440d3b167ba2294f56dafce0f465c07f982", "save_path": "github-repos/MATLAB/Arrowstar-ksptot", "path": "github-repos/MATLAB/Arrowstar-ksptot/ksptot-2b414440d3b167ba2294f56dafce0f465c07f982/helper_methods/psopt/private/unitdisk.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9241418199787564, "lm_q2_score": 0.7981867681382279, "lm_q1q2_score": 0.7376377725902236}} {"text": "function box_display_test06 ( )\n\n%*****************************************************************************80\n%\n%% BOX_DISPLAY_TEST06 compares several methods that reach degree 4 in X, 8 in Y.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 10 January 2014\n%\n% Author:\n%\n% John Burkardt\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'BOX_DISPLAY_TEST06:\\n' );\n fprintf ( 1, ' Plot index sets for various anisotropic methods\\n' );\n fprintf ( 1, ' that reach degree 4 in X, 8 in Y.\\n' );\n fprintf ( 1, '\\n' );\n\n m = 10;\n n = 10;\n title_string = '';\n%\n% Total degree <= 8.\n%\n box_display ( m, n, @(x,y)x+y<=-1, @(x,y)2*x+y<=8, title_string );\n filename = 'degree48_total.png';\n print ( '-dpng', filename );\n fprintf ( 1, ' Created \"%s\".\\n', filename );\n%\n% Maximum degree <= 8.\n%\n box_display ( m, n, @(x,y)x+y<=-1, @(x,y)max(2*x,y)<=8, title_string );\n filename = 'degree48_max.png';\n print ( '-dpng', filename );\n fprintf ( 1, ' Created \"%s\".\\n', filename );\n%\n% Hyperbolic cross.\n%\n box_display ( m, n, @(x,y)x+y<=-1, @(x,y)(2*x+1)*(y+1)<=9, title_string );\n filename = 'degree48_hyper.png';\n print ( '-dpng', filename );\n fprintf ( 1, ' Created \"%s\".\\n', filename );\n%\n% Clenshaw-Curtis sparse grid.\n%\n% box_display ( m, n, @(x,y)x+y<=-1, @cc_aniso, title_string );\n% filename = 'degree48_cc.png';\n% print ( '-dpng', filename );\n% fprintf ( 1, ' Created \"%s\".\\n', filename );\n%\n% Smolyak: Log2(2*x) + Log2(y) <= Log2(L)\n%\n box_display ( m, n, @(x,y)x+y<=-1, @(x,y)log2(max(2*x,1))+log2(max(y,1))<=log2(8.1), title_string );\n filename = 'degree48_smolyak.png';\n print ( '-dpng', filename );\n fprintf ( 1, ' Created \"%s\".\\n', filename );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/box_display/box_display_test06.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772384450968, "lm_q2_score": 0.8438951025545426, "lm_q1q2_score": 0.7376295007782163}} {"text": "function b = isPointOnLine3d(point, line, varargin)\n%ISPOINTONLINE3D Test if a 3D point belongs to a 3D line.\n%\n% B = isPointOnLine3d(POINT, LINE)\n% with POINT being [xp yp zp], and LINE being [x0 y0 z0 dx dy dz].\n% Returns 1 if point lies on the line, 0 otherwise.\n%\n% If POINT is an N-by-3 array of points, B is a N-by-1 array of booleans.\n%\n% If LINE is a N-by-6 array of lines, B is a N-by-1 array of booleans.\n%\n% B = isPointOnLine3d(POINT, LINE, TOL)\n% Specifies the tolerance used for testing location on 3D line.\n%\n% See also \n% lines3d, distancePointLine3d, linePosition3d, isPointOnLine\n%\n\n% ------\n% Author: David Legland \n% E-mail: david.legland@inra.fr\n% Created: 2003-10-31\n% Copyright 2003-2022 INRA - TPV URPOI - BIA IMASTE\n\n% extract computation tolerance\ntol = 1e-14;\nif ~isempty(varargin)\n tol = varargin{1};\nend\n\n% size of inputs\nnp = size(point,1);\nnl = size(line, 1);\n\nif np == 1 || nl == 1 || np == nl\n % test if lines are colinear, using norm of the cross product\n b = bsxfun(@rdivide, vectorNorm3d( ...\n crossProduct3d(bsxfun(@minus, line(:,1:3), point), line(:,4:6))), ...\n vectorNorm3d(line(:,4:6))) < tol;\nelse\n % same test, but after reshaping arrays to manage difference of\n % dimensionality\n point = reshape(point, [np 1 3]);\n line = reshape(line, [1 nl 6]);\n b = bsxfun(@rdivide, vectorNorm3d( ...\n cross(bsxfun(@minus, line(:,:,1:3), point), line(ones(1,np),:,4:6), 3)), ...\n vectorNorm3d(line(:,:,4:6))) < tol;\nend\n", "meta": {"author": "mattools", "repo": "matGeom", "sha": "1fd2c937064be1ee1f4fd09fbfdf96145ebe5271", "save_path": "github-repos/MATLAB/mattools-matGeom", "path": "github-repos/MATLAB/mattools-matGeom/matGeom-1fd2c937064be1ee1f4fd09fbfdf96145ebe5271/matGeom/geom3d/isPointOnLine3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8740772253241802, "lm_q2_score": 0.843895100591521, "lm_q1q2_score": 0.7376294879897066}} {"text": "function geometry_test011 ( )\n\n%*****************************************************************************80\n%\n%% TEST011 tests CIRCLE_DIA2IMP_2D.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 04 December 2010\n%\n% Author:\n%\n% John Burkardt\n%\n dim_num = 2;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TEST011\\n' );\n fprintf ( 1, ' CIRCLE_DIA2IMP_2D converts a diameter to an\\n' );\n fprintf ( 1, ' implicit circle in 2D.\\n' );\n\n theta = 2.0;\n\n p1(1,1) = 2.0 + 5.0 * cos ( theta );\n p1(2,1) = 3.0 + 5.0 * sin ( theta );\n\n p2(1,1) = 2.0 - 5.0 * cos ( theta );\n p2(2,1) = 3.0 - 5.0 * sin ( theta );\n\n r8vec_print ( dim_num, p1, ' P1:' )\n r8vec_print ( dim_num, p2, ' P2:' )\n\n [ r, center ] = circle_dia2imp_2d ( p1, p2 );\n\n circle_imp_print_2d ( r, center, ' The implicit circle:' );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/geometry/geometry_test011.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122213606238, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.7375244559318264}} {"text": "function [cc] = chaincode(b,unwrap)\n% Freeman Chain Code\n%\n% Description: Give Freeman chain code 8-connected representation of a\n% boundary\n% Author.....: Alessandro Mannini \n% Date.......: 2010, september\n%\n% usage:\n% --------------------------------------------------------\n% [cc] = chaincode(b,u)\n%\n% INPUT:\n% --------------------------------------------------------\n% b - boundary as np-by-2 array; \n% np is the number of pixels and each element is a pair (y,x) of\n% pixel coordinates\n% unwrap - (optional, default=false) unwrap code;\n% if enable phase inversions are eliminated\n% \n%\n% OUTPUT:\n% --------------------------------------------------------\n% cc is structure with the following fields:\n%\n% cc.code - 8-connected Freeman chain code as 1-by-np array (or\n% 1-by-(np-1) if the boundary isn't close)\n% cc.x0,cc.y0 - respectively the abscissa and ordinate of start point\n% cc.ucode - unwrapped 8-connected Freeman chain code (if required)\n%\n\n%\n%\n% used direction-to-code convention is: 3 2 1\n% \\ | /\n% 4 -- P -- 0\n% / | \\\n% 5 6 7\n% \n% and in terms of deltax,deltay if next pixel compared to the current:\n% --------------------------\n% | deltax | deltay | code |\n% |------------------------|\n% | 0 | +1 | 2 |\n% | 0 | -1 | 6 |\n% | -1 | +1 | 3 |\n% | -1 | -1 | 5 |\n% | +1 | +1 | 1 |\n% | +1 | -1 | 7 |\n% | -1 | 0 | 4 |\n% | +1 | 0 | 0 |\n% --------------------------\n%\n\n% check input arguments\nif nargin>2 \n error('Too many arguments');\nelseif nargin==0\n error('Too few arguments');\nelseif nargin==1\n unwrap=false;\nend \n% compute dx,dy by a circular shift on coords arrays by 1 element\nsb=circshift(b,[-1 0]);\ndelta=sb-b;\n% check if boundary is close, if not cut last element\nif abs(delta(end,1))>1 || abs(delta(end,2))>1\n delta=delta(1:(end-1),:);\nend\n% check if boundary is 8-connected\nn8c=find(abs(delta(:,1))>1 | abs(delta(:,2))>1);\nif size(n8c,1)>0 \n s='';\n for i=1:size(n8c,1)\n s=[s sprintf(' idx -> %d \\n',n8c(i))];\n end\n error('Curve isn''t 8-connected in elements: \\n%s',s);\nend\n\n\n% convert dy,dx pairs to scalar indexes thinking to them (+1) as base-3 numbers\n% according to: idx=3*(dy+1)+(dx+1)=3dy+dx+4 (adding 1 to have idx starting\n% from 1)\n% Then use a mapping array cm\n% --------------------------------------\n% | deltax | deltay | code | (base-3)+1 |\n% |-------------------------------------|\n% | 0 | +1 | 2 | 8 | \n% | 0 | -1 | 6 | 2 | \n% | -1 | +1 | 3 | 7 | \n% | -1 | -1 | 5 | 1 | \n% | +1 | +1 | 1 | 9 | \n% | +1 | -1 | 7 | 3 | \n% | -1 | 0 | 4 | 4 | \n% | +1 | 0 | 0 | 6 | \n% ---------------------------------------\n\nidx=3*delta(:,1)+delta(:,2)+5;\ncm([1 2 3 4 6 7 8 9])=[5 6 7 4 0 3 2 1];\n\n% finally the chain code array and the starting point\ncc.x0=b(1,2);\ncc.y0=b(1,1);\ncc.code=(cm(idx))';\n\n% If unwrapping is required, use the following algorithm\n%\n% if a(k), k=1..n is the original code and u(k) the unwrapped:\n%\n% - u(1)=a(1)\n% - u(k)=g(k), \n% g(k) in Z | (g(k)-a(k)) mod 8=0 and |g(k)-u(k-1)| is minimized \n%\nif (unwrap) \n a=cc.code;\n u(1)=a(1);\n la=size(a,1);\n for i=2:la\n n=round((u(i-1)-a(i))/8);\n u(i)=a(i)+n*8;\n end\n cc.ucode=u';\nend \n\nend", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/29518-freeman-chain-code/chaincode.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122288794594, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.7375244538173112}} {"text": "% this script represents the evolution of the covariance of an OU process in terms of the dispersion ellipsoid\n% see A. Meucci (2009) \n% \"Review of Statistical Arbitrage, Cointegration, and Multivariate Ornstein-Uhlenbeck\"\n% available at ssrn.com\n\n% Code by A. Meucci, April 2009\n% Most recent version available at www.symmys.com > Teaching > MATLAB\n\nclear; clc; close all\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% input parameters of multivariate OU process\nK=1;\nJ=1;\n\nx0=rand(K+2*J,1);\n\nMu=rand(K+2*J,1);\n\nA=rand(K+2*J,K+2*J)-.5;\nls=rand(K,1)-.5;\ngs=rand(J,1)-.5;\nos=rand(J,1)-.5;\n\nS=rand(K+2*J,K+2*J)-.5;\n\nts=.01*[0:10:100];\nNumSimul=10000;\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% process inputs\nGamma=diag(ls);\nfor j=1:J\n G=[gs(j) os(j)\n -os(j) gs(j)];\n Gamma=blkdiag(Gamma,G);\nend\nTheta=A*Gamma*inv(A);\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% one-step exact simulation\nSigma=S*S';\nX_0=repmat(x0',NumSimul,1);\n[X_t1, MuHat_t1, SigmaHat_t1]=OUstep(X_0,ts(end),Mu,Theta,Sigma);\n\n% multi-step simulation: exact and Euler approximation\nX_t=repmat(x0',NumSimul,1);\nX_tE=X_t;\nfor s=1:length(ts)\n Dt=ts(1);\n if s>1\n Dt=ts(s)-ts(s-1);\n end\n [X_t,MuHat_t,SigmaHat_t]=OUstep(X_t,Dt,Mu,Theta,Sigma);\n %[X_tE,MuHat_tE,SigmaHat_tE]=OUstepEuler(X_tE,Dt,Mu,Theta,Sigma);\n\nend\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% plots \nPick=[K+2*J-1 K+2*J];\n\n% horizon simulations\nhold on\nh5=plot(X_t1(:,Pick(1)),X_t1(:,Pick(2)),'.');\nset(h5,'color','r','markersize',4)\n\n% horizon location\nhold on\nh4=plot(MuHat_t1(Pick(1)),MuHat_t1(Pick(2)),'.');\nset(h4,'color','k','markersize',5)\n\n% horizon dispersion ellipsoid \nhold on\nh3=TwoDimEllipsoid(MuHat_t1(Pick),SigmaHat_t1(Pick,Pick),2,0,0);\nset(h3,'color','k','linewidth',2);\n\n% starting point\nhold on\nh2=plot(x0(Pick(1)),x0(Pick(2)),'.');\nset(h2,'color','b','markersize',5)\n\n% starting generating dispersion ellipsoid\nhold on\nh1=TwoDimEllipsoid(x0(Pick),Sigma(Pick,Pick),2,0,0);\nset(h1,'color','b','linewidth',2);\n\nlegend([h1 h3],'generator','horizon');", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/24120-review-of-statistical-arbitrage-cointegration-and-multivariate-ornstein-uhlenbeck/MultivariateOUnCointegration/Theory/S_CovarianceEvolution.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312226373181, "lm_q2_score": 0.8128673110375457, "lm_q1q2_score": 0.7375244497234567}} {"text": "function fx = p15_fun ( option, nvar, x )\n\n%*****************************************************************************80\n%\n%% P15_FUN evaluates the function for problem 15.\n%\n% Title:\n%\n% The Trigger Circuit.\n%\n% Description:\n%\n% The current flow of a trigger circuit with an operational amplifier\n% is modeled. The variables are voltages, with X(6) the output\n% voltage and X(7) the input voltage.\n%\n% The function has the form\n%\n% F(X) = A * X + PHI ( X )\n%\n% where A is a 6 by 7 matrix, and PHI is a nonlinear term, that is,\n%\n% F(I) = SUM ( 1 <= J <= 7 ) A(I,J) * X(J) + PHI ( X )\n%\n% Options:\n%\n% Melhem lists the following limit points in X(7):\n%\n% ( 0.04936 0.54735 0.04944 0.04944 0.12920 1.16602 0.60185 )\n% ( 0.23577 0.66296 0.23759 0.23760 0.62083 9.60913 0.32286 )\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 29 August 20008\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Rami Melhem, Werner Rheinboldt,\n% A Comparison of Methods for Determining Turning Points of Nonlinear Equations,\n% Computing,\n% Volume 29, Number 3, September 1982, pages 201-226.\n%\n% Gerd Poenisch, Hubert Schwetlick,\n% Computing Turning Points of Curves Implicitly Defined by Nonlinear\n% Equations Depending on a Parameter,\n% Computing,\n% Volume 26, Number 2, June 1981, pages 107-121.\n%\n% Parameters:\n%\n% Input, integer OPTION, the option index.\n%\n% Input, integer NVAR, the number of variables.\n%\n% Input, real X(NVAR), the argument of the function.\n%\n% Output, real FX(NVAR-1), the value of the function at X.\n%\n\n%\n% Get the linear coefficients.\n%\n array = p15_gx ( );\n%\n% Compute the linear portion of the function.\n%\n fx(1:nvar-1) = 0.0;\n\n for i = 1 : nvar - 1\n for j = 1 : nvar\n fx(i) = fx(i) + array(i,j) * x(j);\n end\n end\n%\n% Add the nonlinear terms.\n%\n fx(2) = fx(2) + 5.6D-08 * ( exp ( 25.0 * x(2) ) - 1.0 );\n fx(5) = fx(5) + 5.6D-08 * ( exp ( 25.0 * x(5) ) - 1.0 );\n fx(6) = fx(6) - 7.65 * atan ( 1962.0 * ( x(3) - x(1) ) ) / 0.201;\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_con/p15_fun.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.737500505563026}} {"text": "function out=prox_l1_squared(x,alpha)\n%PROX_L1_SQUARED computes the proximal operator of the function alpha*(norm(x(:),1)^2)\n%\n% Usage: \n% out = PROX_L1_SQUARED(x,alpha)\n% ===========================================\n% INPUT:\n% x - point to be projected (vector/matrix)\n% alpha - positive scalar\n% ===========================================\n% Output:\n% out - proximal operator at x\n\n% This file is part of the FOM package - a collection of first order methods for solving convex optimization problems\n% Copyright (C) 2017 Amir and Nili Beck\n% \n% This program is free software: you can redistribute it and/or modify\n% it under the terms of the GNU General Public License as published by\n% the Free Software Foundation, either version 3 of the License, or\n% (at your option) any later version.\n% \n% This program is distributed in the hope that it will be useful,\n% but WITHOUT ANY WARRANTY; without even the implied warranty of\n% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n% GNU General Public License for more details.\n% \n% You should have received a copy of the GNU General Public License\n% along with this program. If not, see .\n\nif (nargin < 2)\n error ('usage: prox_l1_squared(x,alpha)') ;\nend\n\nif (alpha < 0)\n error('usage: prox_l1_squared(x,alpha) - alpha should be positive')\nend\n\n%setting eps to defalut value : 1e-10\neps = 1e-10 ;\n\nif (norm(x) < eps)\n out = x;\n return ;\nend\n\n%defining f on mu - to be used by the bisetion\nf=@(mu) sum(sum( max(sqrt(alpha) *abs(x)/sqrt(mu) - 2*alpha,0))) - 1 ;\n\nmu_min = 0 ;\nmu_max = 1 ;\nwhile(f(mu_max)> 0)\n mu_max = mu_max * 2 ;\nend\n\nfinal_mu = bisection(f,mu_min,mu_max,eps) ;\nlam = max(sqrt(alpha) * abs(x)/sqrt(final_mu) - 2 *alpha,0) ;\n\nout = (lam .* x) ./ (lam + 2 * alpha) ;\n\nend\n\n", "meta": {"author": "hiroyuki-kasai", "repo": "SGDLibrary", "sha": "d19a12559c79c3726683243885b15f982f4bec3d", "save_path": "github-repos/MATLAB/hiroyuki-kasai-SGDLibrary", "path": "github-repos/MATLAB/hiroyuki-kasai-SGDLibrary/SGDLibrary-d19a12559c79c3726683243885b15f982f4bec3d/tool/FOM_prox functions/prox_l1_squared.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.7375005015019789}} {"text": "% MAIN - chain integrator\n%\n% Problem statement:\n%\n% Find the minimum-snap trajectory that moves a system between two boundary\n% points. Note that snap is the 4th derivative of position. Since the\n% dynamics are in first-order form, we need to include position, velocity,\n% acceleration, jerk in our state vector. We then set the control to be the\n% snap of the trajectory.\n%\n\nclc; clear;\naddpath ../../..\n\n%%%% Boundary-value problem:\n\nt0 = 0; %initial time\nx0 = [1;0]; %initial position\ndx0 = [0;0]; %initial velocity\nddx0 = [0;0]; %initial acceleration\ndddx0 = [0;0]; %initial jerk (derivative of acceleration)\nz0 = [x0;dx0;ddx0;dddx0]; %Full initial state\n\ntF = 1; %final time\nxF = [0;1]; %final position\ndxF = [0;0]; %final velocity\nddxF = [0;0]; %final acceleration\ndddxF = [0;0]; %final jerk (derivative of acceleration)\nzF = [xF;dxF;ddxF;dddxF]; %full final state\n\n\n%%%% Construct bounds struct, given problem specifications\n\nproblem.bounds.initialTime.low = t0;\nproblem.bounds.initialTime.upp = t0;\nproblem.bounds.finalTime.low = tF;\nproblem.bounds.finalTime.upp = tF;\n\nproblem.bounds.initialState.low = z0;\nproblem.bounds.initialState.upp = z0;\nproblem.bounds.finalState.low = zF;\nproblem.bounds.finalState.upp = zF;\n\n\n%%%% Construct a simple initial guess (linear between boundary)\nproblem.guess.time = [t0, tF];\nproblem.guess.state = [z0, zF];\nproblem.guess.control = [zeros(size(x0)), zeros(size(xF))];\n\n\n%%%% Define dynamics and objective functions:\n\n% Enforce the chain integrator dynamics:\nproblem.func.dynamics = @(t,z,u)( dynamics(z,u) );\n\n% Minimize the integral of the snap-squared along the trajectory.\n% Sum along each dimension of the state space. \nproblem.func.pathObj = @(t,z,u)( sum(u.^2,1) ); \n\n\n%%%% Select the method of choice:\n\n% problem.options.method = 'trapezoid';\n% problem.options.method = 'hermiteSimpson';\nproblem.options.method = 'chebyshev';\n% problem.options.method = 'rungeKutta';\n% problem.options.method = 'gpops'; % requires license for GPOPS-II\n\n\n%%%% Solve!\nsoln = optimTraj(problem);\n\n\n%%%% Unpack the solution\n\ntGrid = soln.grid.time;\nxGrid = soln.grid.state(1:2, :);\ndxGrid = soln.grid.state(3:4, :);\nddxGrid = soln.grid.state(5:6, :);\ndddxGrid = soln.grid.state(7:8, :);\nddddxGrid = soln.grid.control;\n\nt = linspace(tGrid(1), tGrid(end), 100);\nz = soln.interp.state(t);\nx = z(1:2,:);\ndx = z(3:4,:);\nddx = z(5:6,:);\ndddx = z(7:8,:);\nddddx = soln.interp.control(t);\n\n%%%% Plot the trajectory against time\nfigure(1); clf;\n\nsubplot(5,1,1); hold on;\nplot(t,x)\nplot(tGrid,xGrid,'ko','MarkerSize',8,'LineWidth',2);\n\nsubplot(5,1,2); hold on;\nplot(t,dx)\nplot(tGrid,dxGrid,'ko','MarkerSize',8,'LineWidth',2);\n\nsubplot(5,1,3); hold on;\nplot(t,ddx)\nplot(tGrid,ddxGrid,'ko','MarkerSize',8,'LineWidth',2);\n\nsubplot(5,1,4); hold on;\nplot(t,dddx)\nplot(tGrid,dddxGrid,'ko','MarkerSize',8,'LineWidth',2);\n\nsubplot(5,1,5); hold on;\nplot(t,ddddx)\nplot(tGrid,ddddxGrid,'ko','MarkerSize',8,'LineWidth',2);\n\n\n", "meta": {"author": "MatthewPeterKelly", "repo": "OptimTraj", "sha": "c97b57fda511dacc6a6187f683428f0f3a1965f2", "save_path": "github-repos/MATLAB/MatthewPeterKelly-OptimTraj", "path": "github-repos/MATLAB/MatthewPeterKelly-OptimTraj/OptimTraj-c97b57fda511dacc6a6187f683428f0f3a1965f2/demo/minimumSnap/chainIntegrator/MAIN.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070133672955, "lm_q2_score": 0.8104789178257654, "lm_q1q2_score": 0.7374604515159999}} {"text": "% Example of use for function 'power_flow_solver'.\n% Written by Dr. Yoash Levron, October 2012.\n%\n% All documentation may be obtained by typing:\n% 'HELP power_flow_solver' at the matlab command prompt.\n%\n% This script defines a simple power network\n% and uses the 'power_flow_solver' function to\n% compute the power flow in it.\n%\n% Associated file: 'power_flow_solver.m'\n\n\n%%%%%%% Define the network %%%%%%%\n% The network composes three buses.\n% bus 1 - (slack bus) a voltage source, E=1.0\n% bus 2 - a generator and a load.\n% bus 3 - a load.\n%\n% Define the line impedances:\nz12 = 0.05 + j*0.1; % impedance (inductive) connecting bus 1 to 2.\nz13 = 0.02 + j*0.05; % impedance (inductive) connecting bus 1 to 3.\nz23 = j*0.05; % impedance (inductive) connecting bus 2 to 3.\nz11 = -j*100; % shunt impedance (capacitive) at bus 1\nz22 = inf; % no shunt impedance at bus 2\nz33 = -j*40; % shunt impedance (capacitive) at bus 3\n\n% A matrix of the network impedances\nZmat = [z11 z12 z13;\n z12 z22 z23;\n z13 z23 z33];\n\n% compute the admittance matrix (admittamce = 1/impedance):\nYmat = 1./Zmat;\n\n% Define voltage at bus 1\nE1_phase = 0; % degree (reference phase angle).\nE1_mag = 1.0; % voltage magnitude\nE1 = E1_mag*exp(j*E1_phase*(pi/180));\n\n% Define generators and loads.\n% Pg&Qg - generators. Pl&Ql - loads.\nPg1=0; Qg1=0; Pl1=0; Ql1=0; % no power source on the slack bus.\nPg2=2; Qg2=0; Pl2=1; Ql2=1; % bus 2. generator and load.\nPg3=0; Qg3=0; Pl3=3; Ql3=0.5; % bus 3. a load.\n\n% sum generators and load to form united power sources.\n% (generators taken positive, loads taken negative).\nP1 = Pg1 - Pl1;\nP2 = Pg2 - Pl2;\nP3 = Pg3 - Pl3;\nQ1 = Qg1 - Ql1;\nQ2 = Qg2 - Ql2;\nQ3 = Qg3 - Ql3;\n\n% Define power vectors:\nPbus = [P1 P2 P3];\nQbus = [Q1 Q2 Q3];\n\n% run function to solve the power flow\n[Ebus, Ibus, Imat, iter] = ...\n power_flow_solver(Ymat, Pbus, Qbus, E1);\n\n% display results\nclc;\ndisp('--- SUMMARY OF RESULTS ---');\ndisp('number of iterations until convergence:');\ndisp(iter);\ndisp('voltage magnitudes');\ndisp(abs(Ebus.'));\ndisp('voltage phase angles (degree)');\ndisp(phase(Ebus.')*180/pi);\ndisp('current supplied by each source (amplitude)');\ndisp(abs(Ibus.'));\ndisp('Active power supplied by each source');\ndisp(real(Ebus.*conj(Ibus)));\ndisp('Reactive power supplied by each source');\ndisp(imag(Ebus.*conj(Ibus)));\ndisp('current in bus 1 --> bus 2');\ndisp(Imat(1,2));\ndisp('current in bus 1 --> bus 3');\ndisp(Imat(1,3));\ndisp('current in bus 2 --> bus 3');\ndisp(Imat(2,3));\ndisp('shunt currents in each bus (magnitude)');\ndisp(abs(diag(Imat).'));\n\n\n\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/38504-power-flow-solver-for-power-systems-analysis/test_flow_solver.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070158103778, "lm_q2_score": 0.8104789086703225, "lm_q1q2_score": 0.7374604451654648}} {"text": "clear all; close all; clc\n\nn=100; L=4;\nx=linspace(0,L,n);\nf=(x.^2).'; % parabola with 100 data points\n\nM=21; % polynomial degree\nfor j=1:M\n phi(:,j)=(x.').^(j-1); % build matrix A\nend\n\ntrials=[2 10 100];\nfor j=1:3 \n for jj=1:trials(j)\n f=(x.^2+0.2*randn(1,n)).';\n a1=pinv(phi)*f; f1=phi*a1; E1(jj)=norm(f-f1)/norm(f);\n a2=phi\\f; f2=phi*a2; E2(jj)=norm(f-f2)/norm(f);\n [a3,stats]=lasso(phi,f,'Lambda',0.1); f3=phi*a3; E3(jj)=norm(f-f3)/norm(f);\n A1(:,jj)=a1; A2(:,jj)=a2; A3(:,jj)=a3;\n end\n A1m=mean(A1.'); A2m=mean(A2.'); A3m=mean(A3.');\n Err=[E1; E2; E3];\n \n subplot(3,3,j), bar(A1m), axis([0 21 -1 1.2])\n subplot(3,3,3+j), bar(A2m), axis([0 21 -1 1.2])\n subplot(3,3,6+j), bar(A3m), axis([0 21 -1 1.2]) \nend\n\n\n%subplot(3,3,j), bar(A1m,'FaceColor',[.6 .6 .6],'EdgeColor','k'), axis([0 21 -1 1.2])\n%subplot(3,3,3+j), bar(A2m,'FaceColor',[.6 .6 .6],'EdgeColor','k'), axis([0 21 -1 1.2])\n%subplot(3,3,6+j), bar(A3m,'FaceColor',[.6 .6 .6],'EdgeColor','k'), axis([0 21 -1 1.2])\n\n\n\n\n\n\n\n\n\n%%\nfigure(2)\n\nAtot=[A1m; A2m; A3m]; % average loadings of three methods\nAtot2=(Atot>0.2).*Atot; % threshold\nAtot3=[Atot; Atot2]; % combine both thresholded and not\n\nfigure(3), bar3(Atot.'), axis([0 4 0 20 0 1]), view(-70,38), set(gca,'Xtick',[],'Fontsize',[18])\nfigure(4), bar3(Atot2.'), axis([0 4 0 20 0 1]), view(-70,38), set(gca,'Xtick',[],'Fontsize',[18])\n\nn=200; L=8;\nx=linspace(0,L,n);\nx1=x(1:100); % train (interpolation)\nx2=x(101:200); % test (extrapolation)\n\nftrain=(x1.^2).'; % interpolated parabola x=[0,4]\nftest=(x2.^2).'; % extrapolated parbola x=[4,5]\n\nfor j=1:M\n phi_i(:,j)=(x1.').^(j-1); % interpolation key\n phi_e(:,j)=(x2.').^(j-1); % extrapolation key\nend\n\nfor jj=1:6 % compute inter/extra-polation scores\n ani=Atot3(jj,:).';\n fnai=phi_i*ani;\n Eni(jj)=norm(ftrain-fnai)/norm(ftrain);\n fnae=phi_e*ani;\n Ene(jj)=norm(ftest-fnae)/norm(ftest);\nend\n\nfigure(5)\nsubplot(3,2,1), bar(Eni)\nsubplot(3,2,2), bar(Ene)\n\nsubplot(3,2,3), bar(Eni), axis([0 7 0 0.01])\nsubplot(3,2,4), bar(Ene), axis([0 7 0 0.1])\n\nfigure(3)\nlegend('','','','Location','NorthEast')\nlegend boxoff\n\n%% Dendrograms\n\n\n\n\n", "meta": {"author": "dynamicslab", "repo": "databook_matlab", "sha": "d390d39d18489a4804ee87a143ae8db8a1f3010b", "save_path": "github-repos/MATLAB/dynamicslab-databook_matlab", "path": "github-repos/MATLAB/dynamicslab-databook_matlab/databook_matlab-d390d39d18489a4804ee87a143ae8db8a1f3010b/CH04/CH04_SEC06_1_kFoldValidation_production.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.909907001151883, "lm_q2_score": 0.810478913248044, "lm_q1q2_score": 0.7374604374503649}} {"text": "% Peak of polynomial Wigner-Ville frequency estimation\n%\n% Estimates the instantaneous frequency of the input signal by\n% extracting the peaks of the sixth order kernel polynomial\n% Wigner-Ville distribution.\n%\n%\n% Usage:\n%\n% ife = pwvpe( signal, lag_window_length, time_res, interpol [, fft_length] ))\n%\n%\n% Parameters:\n%\n% signal\n%\n% Input one dimensional signal to be analysed. An analytic signal\n%\t is required for this function, howver, if signal is real, a\n%\t default analytic transformer routine will be called from this\n%\t function before computing tfd.\n%\n% lag_window_length\n%\n%\t The size of the kernel used for analysis. window_length must be\n%\t odd. The kernel used will be defined from -(lag_window_length+1)/2 to\n%\t +(lag_window_length+1)/2 in both time and lag dimensions.\n%\n% time_res\n%\n%\t The number of time samples to skip between successive slices of\n%\t the analysis.\n%\n% interpol\n%\n%\t The number of interpolating the input signal in time domain to get\n%\t the proper time fractional time lags required to compute the sixth\n% order kernel.\n%\n% fft_length\n%\n% Zero-padding at the fft stage of the analysis may be specified by\n% giving an fft_length larger than normal. If fft_length is not\n% specified, or is smaller than the lag_window_length, then the\n% next highest power of two above lag_window_length is used. If\n% fft_length is not a power of two, the next highest power of two is\n%\t used.\n%\n%\n%\n% See Also: pwvd4, pwvd6\n%\n% TFSAP 7.0\n% Copyright Prof. B. Boashash\n% Qatar University, Doha\n% email: tfsap.research@gmail.com\n", "meta": {"author": "HeLiangHIT", "repo": "time_frequency", "sha": "09c2abe92355ff5cd867bdb169229682e9d7af7c", "save_path": "github-repos/MATLAB/HeLiangHIT-time_frequency", "path": "github-repos/MATLAB/HeLiangHIT-time_frequency/time_frequency-09c2abe92355ff5cd867bdb169229682e9d7af7c/tf_tool_box/tfsa_7.0/win64_bin/pwvpe.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248208414329, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.7374242447551032}} {"text": "function pass = test_undampedNewton(pref)\n%TEST_UNDAMPEDNEWTON Test what happens when we turn off damping in Newton\n\n% This test tries to solve steady state Allen-Cahn using undamped Newton\n% iteration.\n\nif ( nargin == 0 ) \n pref = cheboppref();\nend\n\n% Turn off damping\npref.damping = 0;\n\n%% Setup and solve\ndom = [0, 10];\nx = chebfun(@(x) x, dom);\nf = sin(x);\nN = chebop(@(u) diff(u,2) + u - u.^3, dom, 1, -1);\nu = solvebvp(N, f, pref);\n\n% Happy?\nerr = norm(N(u) - f);\npass = ( err < 1e-8 );\n\n% end\n", "meta": {"author": "chebfun", "repo": "chebfun", "sha": "8c49396a55e46ddd57a1d108c6a8f32e37536d54", "save_path": "github-repos/MATLAB/chebfun-chebfun", "path": "github-repos/MATLAB/chebfun-chebfun/chebfun-8c49396a55e46ddd57a1d108c6a8f32e37536d54/tests/chebop/test_undampedNewton.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8872045877523147, "lm_q2_score": 0.831143045767024, "lm_q1q2_score": 0.7373939232829357}} {"text": "function t = dec2twos(x, nbits)\n\n% DEC2TWOS Convert decimal integer to binary string two's complement.\n% \n% Usage: T = DEC2TWOS(X, NBITS)\n% \n% Converts the signed decimal integer given by X (either a scalar, vector,\n% or matrix) to the two's complement representation as a string. If X is a\n% vector or matrix, T(i, :) is the representation for X(i) (the shape of X\n% is not preserved).\n% \n% Example:\n% >> dec2twos([23 3 -23 -3])\n% \n% ans =\n% \n% 010111\n% 000011\n% 101001\n% 111101\n% \n% Inputs:\n% -X: decimal integers to convert to two's complement.\n% -NBITS: number of bits in the representation (optional, default is the\n% fewest number of bits necessary).\n% \n% Outputs:\n% -T: two's complement representation of X as a string.\n% \n% See also: TWOS2DEC, DEC2FIX, FIX2DEC, DEC2BIN, DEC2HEX, DEC2BASE.\n\nerror(nargchk(1, 2, nargin));\nx = x(:);\nmaxx = max(abs(x));\nnbits_min = nextpow2(maxx + (any(x == maxx))) + 1;\n\n% Default number of bits.\nif nargin == 1 || isempty(nbits)\n nbits = nbits_min;\nelseif nbits < nbits_min\n warning('dec2twos:nbitsTooSmall', ['Minimum number of bits to ' ...\n 'represent maximum input x is %i, which is greater than ' ...\n 'input nbits = %i. Setting nbits = %i.'], ...\n nbits_min, nbits, nbits_min)\n nbits = nbits_min;\nend\n\nt = repmat('0', numel(x), nbits); % Initialize output: Case for x = 0\nif any(x > 0)\n t(x > 0, :) = dec2bin(x(x > 0), nbits); % Case for x > 0\nend\nif any(x < 0)\n t(x < 0, :) = dec2bin(2^nbits + x(x < 0), nbits); % Case for x < 0\nend", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/38889-twos-complement-binary-strings/dec2twos.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619885, "lm_q2_score": 0.8596637451167997, "lm_q1q2_score": 0.7373921478289085}} {"text": "function r8_walsh_1d_test ( )\n\n%*****************************************************************************80\n%\n%% R8_WALSH_1D_TEST tests R8_WALSH_1D;\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 19 April 2009\n%\n% Author:\n%\n% John Burkardt\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'R8_WALSH_1D_TEST\\n' );\n fprintf ( 1, ' R8_WALSH_1D evaluates 1D Walsh functions:\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' X W(+2) W(+1) W(0) W(-1) W(-2) W(-3)\\n' );\n fprintf ( 1, '\\n' );\n\n for i = 0 : 32\n\n x = i / 4.0;\n\n wp2 = r8_walsh_1d ( x, 2 );\n wp1 = r8_walsh_1d ( x, 1 );\n w0 = r8_walsh_1d ( x, 0 );\n wm1 = r8_walsh_1d ( x, -1 );\n wm2 = r8_walsh_1d ( x, -2 );\n wm3 = r8_walsh_1d ( x, -3 );\n\n fprintf ( 1, ' %10f %4f %4f %4f %4f %4f %4f\\n', ...\n x, wp2, wp1, w0, wm1, wm2, wm3 );\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/r8lib/r8_walsh_1d_test.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680977182186, "lm_q2_score": 0.8596637469145054, "lm_q1q2_score": 0.7373921368681714}} {"text": "function p = predictOneVsAll(all_theta, X)\n%PREDICT Predict the label for a trained one-vs-all classifier. The labels \n%are in the range 1..K, where K = size(all_theta, 1). \n% p = PREDICTONEVSALL(all_theta, X) will return a vector of predictions\n% for each example in the matrix X. Note that X contains the examples in\n% rows. all_theta is a matrix where the i-th row is a trained logistic\n% regression theta vector for the i-th class. You should set p to a vector\n% of values from 1..K (e.g., p = [1; 3; 1; 2] predicts classes 1, 3, 1, 2\n% for 4 examples) \n\nm = size(X, 1);\nnum_labels = size(all_theta, 1);\n\n% You need to return the following variables correctly \np = zeros(size(X, 1), 1);\n\n% Add ones to the X data matrix\nX = [ones(m, 1) X];\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Complete the following code to make predictions using\n% your learned logistic regression parameters (one-vs-all).\n% You should set p to a vector of predictions (from 1 to\n% num_labels).\n%\n% Hint: This code can be done all vectorized using the max function.\n% In particular, the max function can also return the index of the \n% max element, for more information see 'help max'. If your examples \n% are in rows, then, you can use max(A, [], 2) to obtain the max \n% for each row.\n% \n\n\n% x * all_theta' : 5000 * 10\uff0c\u6bcf\u4e00\u884c\u7684\u6bcf\u4e00\u4e2a\u5217\u503c\u4ee3\u8868\u56fe\u50cf\u662f1,2...10\u7684\u53ef\u80fd\u6027\n% use max(),M = max(A,[],dim) \u6cbf\u7740\u7ef4\u5ea6 dim \u8fd4\u56de\u6700\u5927\u5143\u7d20\u3002\u4f8b\u5982\uff0c\u5982\u679c A \u4e3a\u77e9\u9635\uff0c\u5219 max(A,[],2) \u662f\u5305\u542b\u6bcf\u4e00\u884c\u7684\u6700\u5927\u503c\u7684\u5217\u5411\u91cf\u3002\n% probaitilty\u4ee3\u8868\u6bcf\u4e00\u884c\u6700\u5927\u7684\u503c\uff0cp\u4ee3\u8868\u7d22\u5f15\n[probability, p] = max(sigmoid(X * all_theta'), [], 2);\n\n\n% =========================================================================\n\n\nend\n", "meta": {"author": "xjwhhh", "repo": "AndrewNgMachineLearning", "sha": "d9d8491b315755ea3726bc366d72ba069712c363", "save_path": "github-repos/MATLAB/xjwhhh-AndrewNgMachineLearning", "path": "github-repos/MATLAB/xjwhhh-AndrewNgMachineLearning/AndrewNgMachineLearning-d9d8491b315755ea3726bc366d72ba069712c363/code/machine-learning-ex3/ex3/predictOneVsAll.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.857768094082276, "lm_q2_score": 0.8596637505099168, "lm_q1q2_score": 0.7373921368265125}} {"text": "function [J,J_od,J_id,J_bl] = jdegree(CIJ)\n%JDEGREE Joint degree distribution\n%\n% [J,J_od,J_id,J_bl] = jdegree(CIJ);\n%\n% This function returns a matrix in which the value of each element (u,v)\n% corresponds to the number of nodes that have u outgoing connections \n% and v incoming connections.\n%\n% Input: CIJ, directed (weighted/binary) connection matrix\n%\n% Outputs: J, joint degree distribution matrix (shifted by one)\n% J_od, number of vertices with od>id.\n% J_id, number of vertices with id>od.\n% J_bl, number of vertices with id=od.\n%\n% Note: Weights are discarded.\n%\n%\n% Olaf Sporns, Indiana University, 2002/2006/2008\n\n\n% ensure CIJ is binary...\nCIJ = double(CIJ~=0);\n\nN = size(CIJ,1);\n\nid = sum(CIJ,1); % indegree = column sum of CIJ\nod = sum(CIJ,2)'; % outdegree = row sum of CIJ\n\n% Create the joint degree distribution matrix\n% Note: the matrix is shifted by one, to accomodate zero id and od in the first row/column.\n% Upper triangular part of the matrix has vertices with an excess of \n% outgoing edges (od>id)\n% Lower triangular part of the matrix has vertices with an excess of\n% outgoing edges (id>od)\n% Main diagonal has units with id=od\n\nszJ = max(max(id,od))+1;\nJ = zeros(szJ);\n\nfor i=1:N\n J(id(i)+1,od(i)+1) = J(id(i)+1,od(i)+1) + 1;\nend;\n\nJ_od = sum(sum(triu(J,1)));\nJ_id = sum(sum(tril(J,-1)));\nJ_bl = sum(diag(J));\n", "meta": {"author": "fieldtrip", "repo": "fieldtrip", "sha": "c2039be598a02d86b39aae76bfa7aaa720f9801c", "save_path": "github-repos/MATLAB/fieldtrip-fieldtrip", "path": "github-repos/MATLAB/fieldtrip-fieldtrip/fieldtrip-c2039be598a02d86b39aae76bfa7aaa720f9801c/external/bct/jdegree.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206659843131, "lm_q2_score": 0.8175744717487329, "lm_q1q2_score": 0.7373873120513901}} {"text": "function zList=genAllNestedZParenth(n,algorithm)\n%%GENALLNESTEDZPARENTH0 Generate all nested sets of n parenthesis pairs,\n% recording only the indices of the left parantheses.\n%\n%INPUTS: n The number of nested paranthesis pairs; n>=0. Passing zero will\n% result in an empty matrix being returned.\n% algorithm An optional parameter specifying the algorithm that should be\n% used to generate the parenthesis pairs. Possible values are:\n% 0 (The default if omitted or an empty matrix is passed) Use\n% the algorithm of Problem 2 of Section 7.2.1.6 of [1].\n% 1 Use algorithm N of Section 7.2.1.6 of [1].\n%\n%OUTPUTS: zList The nXnumPairs list of indices where the left parenthesis\n% goes.\n%\n%There is a total of CatalanNumber(n) possible arrangements of nested\n%parentheses.\n%\n%EXAMPLE:\n%To recreate the values in Table I of Section 7.2.1.6 of [1],\n%one can run\n% zList=genAllNestedZParenth(4)\n%\n%REFERENCES:\n%[1] D. E. Knuth, The Art of Computer Programming. Vol. 4A: Combinatorial\n% Algorithms, Part I, Boston: Addison-Wesley, 2011.\n%\n%October 2018 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nif(nargin<2||isempty(algorithm))\n algorithm=0;\nend\n\nif(n==0)\n zList=[];\n return;\nend\n\nswitch(algorithm)\n case 0\n zList=genAllNestedZParenth0(n);\n case 1\n zList=genAllNestedZParenth1(n);\n otherwise\n error('Unknown algorithm specified.')\nend\n\nend\n\nfunction zList=genAllNestedZParenth0(n)\n%%GENALLNESTEDZPARENTH0 Generate all nested sets of n parenthesis pairs,\n% recording only the indices of the left parantheses using the\n% algorithm in Problem 2 of Section 7.2.1.6 of [1].\n%\n%REFERENCES\n%[1] D. E. Knuth, The Art of Computer Programming. Vol. 4A: Combinatorial\n% Algorithms, Part I, Boston: Addison-Wesley, 2011.\n%\n%October 2018 David F. Crouse, Naval Research Laboratory, Washington D.C.\n\nif(n==1)\n zList=1;\n return;\nend\n\nnumBinTrees=CatalanNumber(n);\n%Allocate space.\nzList=zeros(n,numBinTrees);\n\n%Step T1 Initialize\nz=2*(0:n).'-1;\n\nfor curTree=1:numBinTrees\n %Step T2\n zList(:,curTree)=z(2:(n+1));\n \n %Step T3\n if(z(n-1+1)