text:
function v = ksvdver(history)
%KSVDVER K-SVD toolbox version information.
%  KSVDVER displays the current KSVD toolbox version information.
%
%  KSVDVER('history') also displays history information about the previous
%  versions of the KSVD toolbox and their change logs.
%
%  V = KSVDVER returns the version number of the current KSVD toolbox, and
%  does not display any information.

%  Ron Rubinstein
%  Computer Science Department
%  Technion, Haifa 32000 Israel
%  ronrubin@cs
%
%  October 2009

ver = 13;

if (nargout>0)
  if (nargin>0)
    error('Invalid number of parameters.');
  end
  v = ver;

else

  if (nargin==0 || (nargin==1 && strcmpi(history,'history')))

    disp(' ');
    disp('---------------------------------');
    printf('    KSVD Toolbox version %d       ',ver);
    disp('---------------------------------');
    disp(' ');

  else
    error('Unknown parameters.');
  end

  if (nargin>0)

    %% changes only displayed since first public release %%

%     disp(' ');
%     disp('KSVD Toolbox version 1, 24.10.07');
%     disp('---------------------------------');
%     disp(' ');
%     disp('Initial release.');
%     disp(' ');
%     disp(' ');
%     disp(' ');
%
%     disp('KSVD Toolbox version 2, 13.12.07');
%     disp('---------------------------------');
%     disp(' ');
%     disp('Features:');
%     disp(' ');
%     disp('  1. KSVD: support for sparsity and error based coding.');
%     disp('  2. New OMPDENOISE function for generic OMP-based denoising.');
%     disp('  3. ''memusage'' parameter introduced for controlling memory usage.');
%     disp(' ');
%     disp('Bug fixes:');
%     disp(' ');
%     disp('  1. KSVD: when initializing the dictionary with a set of signals, ');
%     disp('     only selects non-zero ones.');
%     disp('  2. KSVD: only negates atoms with first element negative, instead of');
%     disp('     multiplying each atom by its sign (which nullified atoms whose');
%     disp('     first element was zero).');
%     disp('  3. KSVD: tracks training signals used to replace unused atoms, so');
%     disp('     the same one is not used twice.');
%     disp(' ');
%     disp('Internal changes:');
%     disp('  1. Eliminated the use of function cleardict in KSVD, following bugfix (3).');
%     disp(' ');
%     disp(' ');
%     disp(' ');
%
%     disp('KSVD Toolbox version 3, 16.01.08');
%     disp('---------------------------------');
%     disp(' ');
%     disp('Features:');
%     disp(' ');
%     disp('  1. Option for specifying a list of initial signals for the dictionary using');
%     disp('     the parameter initdict.')
%     disp('  2. Changed error computation from Frobenius norm to MSE.');
%     disp('  3. Added the VERBOSE parameter for controlling printed output.');
%     disp('  4. Added the muthresh parameter to KSVD.');
%     disp('  5. Added parameter maxval to OMPDENOISE and KSVDDENOISE.');
%     disp(' ');
%     disp('Internal changes:');
%     disp(' ');
%     disp('  1. Added the sparsecode method for cleaner code.');
%     disp('  2. Re-introduced the use of function cleardict.');
%     disp(' ');
%     disp('Bug fixes:');
%     disp(' ');
%     disp('  1. Function cleardict now checks correlation between atoms in absolute value.');
%     disp(' ');
%     disp(' ');
%     disp(' ');
%
%     disp('KSVD Toolbox version 4, 27.01.08');
%     disp('---------------------------------');
%     disp(' ');
%     disp('Features:');
%     disp(' ');
%     disp('  1. Added functions OMPDENOISE2 and OMPDENOISE3 for faster denoising of');
%     disp('     2-D and 3-D signals.');
%     disp('  2. Added gain and lambda parameters to OMPDENOISE and KSVDDENOISE.');
%     disp(' ');
%     disp(' ');
%     disp(' ');
%
%     disp('KSVD Toolbox version 5, 03.02.08');
%     disp('---------------------------------');
%     disp(' ');
%     disp('Features:');
%     disp(' ');
%     disp('  1. KSVD: atom update is now in random order rather than sequential.');
%     disp('  2. KSVD: improved error computation: error is now computed after the');
%     disp('     dictionary update step, eliminating the need for an additional sparse');
%     disp('     coding step at the end of the algorithm for error computation.');
%     disp('     Computed error is now RMSE for sparsity-based minimization, and average');
%     disp('     atom count for error-based minimization.');
%     disp('  3. KSVD: cleardict now replaces every atom not used by at least 4 training');
%     disp('     signals. Atoms already replaced in the dictionary update step are');
%     disp('     excluded from this criterion.');
%     disp('  4. Added the ''exact'' parameter to KSVD/KSVDDENOISE, to allow using the exact');
%     disp('     SVD solution rather than the default quicker approximation method.');
%     disp('  5. Changed behavior of VERBOSE=3 mode in KSVD, and added VERBOSE=4 mode.');
%     disp('  6. VERBOSE in OMPDENOISE/2/3 now prints a message every VERBOSE seconds,');
%     disp('     not every VERBOSE blocks.');
%     disp('  7. OMPDENOISE: faster computation of the matrix cnt (a counter matrix');
%     disp('     containing the number of blocks covering each sample in the signal.');
%     disp('  8. KSVDDENOISE: new default values for gain and lambda.');
%     disp('  9. KSVDDENOISE: reverts to function OMPDENOISE when memusage is ''low''');
%     disp(' 10. Set a limit on the number of atoms used to code each block in OMPDENOISE');
%     disp('     and KSVDDENOISE. Added the maxatoms parameter to control this limit.');
%     disp(' 11. Improved documentation.');
%     disp(' 12. Added the KSVDVER function.');
%     disp(' ');
%     disp('Internal changes:');
%     disp(' ');
%     disp('  1. Support for the new call syntax of OMP Toolbox v6.');
%     disp('  2. OMPDENOISE3 now computes the matrix cnt using much less memory. Instead');
%     disp('     of allocating three matrices the size of the input signal, it only');
%     disp('     allocates one such matrix.');
%     disp(' ');
%     disp('Bug fixes:');
%     disp(' ');
%     disp('  1. OMPDENOISE2/3 now compute the matrix cnt correctly.');
%     disp(' ');
%     disp(' ');
%     disp(' ');
%
%     disp('KSVD Toolbox version 6, 14.02.08');
%     disp('---------------------------------');
%     disp(' ');
%     disp('Features:');
%     disp(' ');
%     disp('  1. New stepsize parameter in OMPDENOISE/2/3 and KSVDDENOISE.');
%     disp('  2. ''blocksize'' parameter in OMPDENOISE/2/3 and KSVDDENOISE can now be a scalar.');
%     disp('  3. Added the Contents.m file.');
%     disp('  4. Revised VERBOSE settings in KSVDDENOISE, and slightly improved display format');
%     disp('     in KSVD.');
%     disp(' ');
%     disp('Bug fixes:');
%     disp(' ');
%     disp('  1. OMPDENOISE/2/3: fixed a bug in the computation of the matrix cnt when');
%     disp('     the signal is not square.');
%     disp(' ');
%     disp(' ');
%     disp(' ');
%
%     disp('KSVD Toolbox version 7, 18.04.08');
%     disp('---------------------------------');
%     disp(' ');
%     disp('Features:');
%     disp(' ');
%     disp('  1. OMPDENOISE now prints the estimated remaining time.');
%     disp('  2. New ''msgdelta'' parameter in KSVD and KSVDDENOISE for printing');
%     disp('     periodic status updates.');
%     disp(' ');
%     disp('Internal changes:');
%     disp(' ');
%     disp('  1. Compatible with OMP Toolbox v7.');
%     disp(' ');
%     disp(' ');
%     disp(' ');

    disp(' ');
    disp(' ');
    disp('KSVD Toolbox version 7, 18.04.08');
    disp('---------------------------------');
    disp(' ');
    disp('First public release.');
    disp(' ');
    disp(' ');
    disp(' ');

    disp('KSVD Toolbox version 8, 29.05.08');
    disp('---------------------------------');
    disp(' ');
    disp('Features:');
    disp(' ');
    disp('  1. Added ''sigma'' and ''noisemode'' parameters to OMPDENOISE and KSVDDENOISE.');
    disp('  2. Added the overcomplete DCT dictionary as an optional initial dictionary');
    disp('     in KSVDDENOISE, by setting the initdict parameter to the string ''odct''.');
    disp('  3. Improved default gain and lambda parameters in OMPDENOISE.');
    disp(' ');
    disp('Bug fixes:');
    disp(' ');
    disp('  1. KSVDDENOISE: corrected a bug which caused incorrect gain and lambda');
    disp('     parameters to be sent to OMPDENOISE in some cases.');
    disp(' ');
    disp('Internal changes:');
    disp(' ');
    disp('  1. When replacing an unused atom, the search for an example with maximal');
    disp('     error is limited to a fixed number of signals.');
    disp('  2. Improved implementation of KSVDVER.');
    disp('  3. Uses the TIMER package for time estimation.');
    disp(' ');
    disp(' ');
    disp(' ');

    disp('KSVD Toolbox version 9, 30.11.08');
    disp('---------------------------------');
    disp(' ');
    disp('Features:');
    disp(' ');
    disp('  1. OMPDENOISE and KSVDDENOISE can now return the average number of');
    disp('     non-zeros in the denoised block representations.');
    disp(' ');
    disp('Bug fixes:');
    disp(' ');
    disp('  1. Corrected an error when parameter MSGDELTA was not specified.');
    disp(' ');
    disp('Internal changes:');
    disp(' ');
    disp('  1. The COUNTCOVER function counts the number of times a pixel in a');
    disp('     multi-dimensional signal is covered by overlapping blocks.');
    disp('  2. Function CLEARDICT now computes the error norm in blocks to reduce');
    disp('     memory consumption.');
    disp(' ');
    disp(' ');
    disp(' ');

    disp('KSVD Toolbox version 10, 21.05.09');
    disp('----------------------------------');
    disp(' ');
    disp('Features:');
    disp(' ');
    disp('  1. Source code for supporting C functions now available for compilation');
    disp('     on any Matlab platform.');
    disp('  2. Added KSVDDEMO and KSVDDENOISEDEMO.');
    disp('  3. Improved performance of OMPDENOISE2, OMPDENOISE3 and KSVD.');
    disp('  4. New SHOWDICT function for displaying a dictionary of image patches.');
    disp('  5. KSVD: improved VERBOSE/MSGDELTA parameter syntax.');
    disp('  6. KSVD: messages are now displayed by default.');
    disp('  7. KSVD: only one of the parameters dictsize/initdict needs to be specified.');
    disp('  8. KSVD: eliminated the data saving option.');
    disp('  9. OMPDENOISE: messages are now displayed by default.');
    disp(' 10. KSVDDENOISE: simplified MSGDELTA parameter.');
    disp(' 11. KSVDDENOISE: default initial dictionary is now overcomplete DCT.');
    disp(' 12. KSVDDENOISE: parameter initdict can be the string ''data'' to indicate');
    disp('     initialization from training examples.');
    disp(' ');
    disp(' ');
    disp(' ');

    disp('KSVD Toolbox version 11, 03.08.09');
    disp('----------------------------------');
    disp(' ');
    disp('Features:');
    disp(' ');
    disp('  1. Added OMPDENOISE1 for fast OMP denoising of 1-D signals.');
    disp('  2. Added support for 1-D signals in KSVDDENOISE.');
    disp(' ');
    disp('Bug fixes:');
    disp(' ');
    disp('  1. Corrected a bug in OMPDENOISE/2/3 when memusage is low.');
    disp(' ');
    disp('Internal changes:');
    disp(' ');
    disp('  1. KSVD: only compute sum(data.*data) when memusage is high.');
    disp(' ');
    disp(' ');
    disp(' ');

    disp('KSVD Toolbox version 12, 24.08.09');
    disp('----------------------------------');
    disp(' ');
    disp('Features:');
    disp(' ');
    disp('  1. KSVD: significantly faster atom update computation via optimized');
    disp('     sparse-matrix code.');
    disp('  2. KSVD: reduced memory consumption by computing one column of G');
    disp('     at a time when clearing the dictionary, and using block processing');
    disp('     to compute representation error.');
    disp(' ');
    disp('Internal changes:');
    disp(' ');
    disp('  1. KSVD: when replacing an atom in cleardict, the search for an example');
    disp('     with maximal error is limited to a fixed number of signals.');
    disp('  2. KSVDDENOISEDEMO: memusage is set to ''high'' for faster performance.');
    disp(' ');
    disp(' ');
    disp(' ');

    disp('KSVD Toolbox version 13, 18.10.09');
    disp('----------------------------------');
    disp(' ');
    disp('Features:');
    disp(' ');
    disp('  1. KSVDDENOISE: reduced memory consumption by employing block processing');
    disp('     to remove the DC channel from training examples.');
    disp('  2. OMPDENOISE1/2/3: significantly faster operation using new IM2COLSTEP and');
    disp('     COL2IMSTEP MEX functions.');
    disp('  3. OMPDENOISE/1/2/3: dictionary normalization is verified only once, eliminating');
    disp('     redundant computations.');
    disp('  4. KSVDDENOISE: ''low'' memory usage now uses the faster OMPDENOISE1/2/3');
    disp('     functions, and does not revert to OMPDENOISE.');
    disp(' ');
    disp('Internal changes:');
    disp(' ');
    disp('  1. KSVD: cleardict never replaces an atom if it was already replaced by');
    disp('     optimize_atom in the same iteration.');
    disp(' ');
    disp('Bug fixes:');
    disp(' ');
    disp('  1. OMPDENOISE1: progress messages now display the correct block number.');
    disp('  2. KSVD: cleardict considers all training examples to replace an unused atom,');
    disp('     rather than only a fixed number. This eliminates a rare bug introduced in v12');
    disp('     in which the fixed number of examples could be insufficient.');
    disp(' ');
    disp(' ');

   end
end

author: tiepvupsu

repo: DICTOL

save_path: github-repos/MATLAB/tiepvupsu-DICTOL


text:
function [newF,cData] = surface_outlines(plotdat,patchobj,colmap)

% helper function to compute the borders of ROIs on surface data
%
% input:
%
% plotdat   - cell array (1x2) with the data to plot for a single
%             hemisphere in each cell.
%             plotdat{1} = left hemisphere, plotdat{2} = right hemisphere
%
% patchobj  - cell array (1x2) containing the patch objects for left {1}
%             and right {2} hemispheres. Only need the Face and Vertex info
%             here, so could be structs in the cells.
%             e.g. patchobj{hem}.Faces = yourFaces;
%             patchobj{hem}.Vertices = yourVertices;
%
% colmap    - colormap to color the ROI outlines with. Can also be a single
%             color for all borders (e.g. [0.2 0.2 0.2]).
%
% output:
%
% newF      - the new Faces containing only the outline faces around each ROI
%
% cData     - the color information for the new outline faces. use with
%             patch as patch(...,'FaceVertexCdata',cData)
%
%
%  Examples:
%  % make surface figure
%  h = make_surface_figure('surfacefiles',surffiles);
%  [outlineF, outlineCData] = surface_outlines({ldat,rdat},{h.obj(1),h.obj(2)}, [0 0 0]);
%  % left lateral hem
%  patch(h.ax(1),'Faces',outlineF{1},'Vertices',h.obj(1).Vertices,'FaceVertexCData',outlineCData{1},...,
%         'FaceColor',fcolormode,'EdgeColor','none','SpecularStrength',.2,'FaceAlpha',facealpha,'SpecularExponent',200);
%  % right lateral hem
%  patch(h.ax(3),'Faces',outlineF{2},'Vertices',h.obj(3).Vertices,'FaceVertexCData',outlineCData{2},...,
%         'FaceColor',fcolormode,'EdgeColor','none','SpecularStrength',.2,'FaceAlpha',facealpha,'SpecularExponent',200);
%
%
%
% ..
%     Author and copyright information:
%     -------------------------------------------------------------------------
%     Copyright (C) 2018 Stephan Geuter
%
%     This program is free software: you can redistribute it and/or modify
%     it under the terms of the GNU General Public License as published by
%     the Free Software Foundation, either version 3 of the License, or
%     (at your option) any later version.
%
%     This program is distributed in the hope that it will be useful,
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%     GNU General Public License for more details.
%
%     You should have received a copy of the GNU General Public License
%     along with this program.  If not, see <http://www.gnu.org/licenses/>.
% ..
%

%
% ..
%    Programmers' notes:
%    List dates and changes here, and author of changes
%
%   3/30/2018 - created
%   Stephan Geuter, sgeuter@jhmi.edu
%

% regionIDs = [199 214 280 360  20 100 170];
% col = lines(numel(regionIDs));
%

% loop hemispheres
for hem=1:2

    % get data for this hemisphere
    atlasDat = plotdat{hem};
    atlasDat(isnan(atlasDat)) = 0;

    % get Faces, Vertices of the brain surface
    F = patchobj{hem}.Faces;
    V = patchobj{hem}.Vertices;

    % unique ROI/blob ID's
    hemRegions = unique(atlasDat(isfinite(atlasDat)));

    newF{hem}  = double.empty(0,3);
    cData{hem} = double.empty(0,3);

    % loop ROIs
    for r=1:numel(hemRegions)

        % find the vertices that belong to the current ROI
        idx = atlasDat .* single(ismember(atlasDat,hemRegions(r)));

        if numel(unique(idx))>1 && any(unique(idx)~=0)
            % compute the new Faces
            Fclasses = idx(F);
            roiFace  = F(any(diff(Fclasses,1,2),2) , :);

            % get color for current ROI outline
            if size(colmap,1) == 1
                roiCol   = repmat(colmap,size(roiFace,1),1);
            else
                roiCol   = repmat(colmap(hemRegions(r),:),size(roiFace,1),1);
            end

            % cat data across ROIs
            newF{hem} = vertcat(newF{hem},roiFace);
            cData{hem}= vertcat(cData{hem},roiCol);
        end
    end

%     for j=find(cellregexp(h.label,hemstr))
%         hp(j) = patch(h.ax(j),'Faces',newF{hem},'Vertices',V,'FaceColor','flat',...
%             'Edgecolor','none','FaceVertexCdata',cData{hem},...
%             'SpecularStrength',.2,'SpecularExponent',200);
%         material(hp(j),'dull');
%         lighting(h.ax(j),'gouraud');
%     end
end

author: canlab

repo: CanlabCore

save_path: github-repos/MATLAB/canlab-CanlabCore


text:
classdef(Abstract) AbstractBodyFixedSensorTarget < AbstractSensorTarget
    %AbstractBodyFixedSensorTarget Summary of this class goes here
    %   Detailed explanation goes here

    properties
        rVectECEF(3,:) double
    end

    methods
        function rVect = getTargetPositions(obj, time, vehElemSet, inFrame)
            arguments
                obj(1,1) AbstractBodyFixedSensorTarget
                time(1,1) double
                vehElemSet(1,1) CartesianElementSet
                inFrame(1,1) AbstractReferenceFrame
            end

            bodyFixedFrame = obj.bodyInfo.getBodyFixedFrame();

            numPts = size(obj.rVectECEF, 2);

            times = time*ones(1, numPts);
            rVects = obj.rVectECEF;
            vVects = zeros(3,numPts);
            cartElem = CartesianElementSet(times, rVects, vVects, bodyFixedFrame, true);

            cartElem = convertToFrame(cartElem, inFrame);
            rVect = cartElem.rVect;
        end

        function numPts = getNumberOfTargetPts(obj)
            numPts = width(obj.rVectECEF);
        end

        function strs = getTargetPtLabelStrs(obj)
            strs = string.empty(1,0);
            for(i=1:width(obj.rVectECEF))
                cartElem = CartesianElementSet(0, obj.rVectECEF(:,i), [0;0;0], obj.bodyInfo.getBodyFixedFrame(), false);
                geoElem = cartElem.convertToGeographicElementSet();

                strs(i) = string(sprintf('Target %u (Lat %0.3f deg, Long %0.3f deg, Alt %0.3f km)', i, rad2deg(geoElem.lat), rad2deg(geoElem.long), geoElem.alt)); %#ok<AGROW>
            end
        end
    end
end

author: Arrowstar

repo: ksptot

save_path: github-repos/MATLAB/Arrowstar-ksptot


text:
function qr=v_rotqc2qr(qc)
%V_ROTQC2QR converts a matrix of complex quaternion row vectors into real form
%
% Inputs:
%
%     QC(2m,...)   array of complex-valued quaternions
%
% Outputs:
%
%     QR(4m,...)   array of real-valued quaternions
%
% The complex-valued quaternion [r+j*b  a+j*c] becomes [r a b c]

%
%      Copyright (C) Mike Brookes 2000-2018
%      Version: $Id: v_rotqc2qr.m 10865 2018-09-21 17:22:45Z dmb $
%
%   VOICEBOX is a MATLAB toolbox for speech processing.
%   Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%   This program is free software; you can redistribute it and/or modify
%   it under the terms of the GNU General Public License as published by
%   the Free Software Foundation; either version 2 of the License, or
%   (at your option) any later version.
%
%   This program is distributed in the hope that it will be useful,
%   but WITHOUT ANY WARRANTY; without even the implied warranty of
%   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%   GNU General Public License for more details.
%
%   You can obtain a copy of the GNU General Public License from
%   http://www.gnu.org/copyleft/gpl.html or by writing to
%   Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
persistent a b
if isempty(a)
    a=[1 3 2 4];
end
s=size(qc);
s(1)=2*s(1); % each complex number needs two reals
qr=reshape([real(qc(:).'); imag(qc(:).')],4,[]);
qr=reshape(qr(a,:),s);
if ~nargout
    qr=qr(1:4); % just select the first one
    v_rotqr2ro(qr(:)); % plot a rotated cube
end

author: ImperialCollegeLondon

repo: sap-voicebox


text:
function fem2d_bvp_serene_test03 ( )

%*****************************************************************************80
%
%% FEM2D_BVP_SERENE_TEST03 carries out test case #3.
%
%  Discussion:
%
%    Use A3, C3, F3, EXACT3, EXACT_UX3, EXACT_UY3.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    30 June 2014
%
%  Author:
%
%    John Burkardt
%
  nx = 5;
  ny = 5;

  fprintf ( 1, '\n' );
  fprintf ( 1, 'FEM2D_BVP_SERENE_TEST03\n' );
  fprintf ( 1, '  Solve - del ( A del U ) + C U = F \n' );
  fprintf ( 1, '  on the unit square with zero boundary conditions.\n' );
  fprintf ( 1, '  A1(X,Y) = 0.0\n' );
  fprintf ( 1, '  C1(X,Y) = 1.0\n' );
  fprintf ( 1, '  F1(X,Y) = X * ( 1 - X ) * Y * ( 1 - Y ).\n' );
  fprintf ( 1, '  U1(X,Y) = X * ( 1 - X ) * Y * ( 1 - Y )\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  This example is contrived so that the system matrix\n' );
  fprintf ( 1, '  is the WATHEN matrix.\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  The grid uses %d by %d nodes.\n', nx, ny );
  node_num = fem2d_bvp_serene_node_num ( nx, ny );
  fprintf ( 1, '  The number of nodes is %d\n', node_num );
%
%  Geometry definitions.
%
  x = linspace ( 0.0, 1.0, nx );
  y = linspace ( 0.0, 1.0, ny );

  show11 = 1;

  u = fem2d_bvp_serene ( nx, ny, @a3, @c3, @f3, x, y, show11 );

  if ( nx * ny <= 25 )
    fprintf ( 1, '\n' );
    fprintf ( 1, '     I     J    X         Y         U         Uexact    Error\n' );
    fprintf ( 1, '\n' );

    k = 0;

    for j = 1 : ny

      if ( mod ( j, 2 ) == 1 )
        inc = 1;
      else
        inc = 2;
      end

      for i = 1 : inc : nx
        k = k + 1;
        uexact = exact3 ( x(i), y(j) );
        fprintf ( 1, '  %4d  %4d  %8f  %8f  %8f  %8f  %8e\n', ...
          i, j, x(i), y(j), u(k), uexact, abs ( u(k) - uexact ) );
      end
    end

  end

  e1 = fem2d_l1_error_serene ( nx, ny, x, y, u, @exact3 );
  e2 = fem2d_l2_error_serene ( nx, ny, x, y, u, @exact3 );
  h1s = fem2d_h1s_error_serene ( nx, ny, x, y, u, @exact_ux3, @exact_uy3 );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  l1 error   = %g\n', e1 );
  fprintf ( 1, '  L2 error   = %g\n', e2 );
  fprintf ( 1, '  H1S error  = %g\n', h1s );
%
%  Pull out the Wathen matrix from MATLAB.
%  It will have been multiplied by a random scale factor.
%  While my numbering scheme is
%    3  2  1
%    4     8
%    5  6  7
%  the numbering scheme used here is
%    1  2  3
%    4     5
%    6  7  8
%
%
  A = gallery ( 'wathen', 1, 1 );
  A = full ( A );
  s = 0.5 * A(1,3);
  A = A / s;
  fprintf ( 1, '\n' );
  fprintf ( 1, '  WATHEN Matrix from "gallery(''wathen'',1,1)"\n' );
  fprintf ( 1, '\n' );
  i = [3,2,1,4,6,7,8,5];
  A(i,i)

  return
end
function value = a3 ( x, y )

%*****************************************************************************80
%
%% A3 evaluates A function #3.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    30 June 2014
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, real X, Y, the evaluation point.
%
%    Output, real VALUE, the value of A(X).
%
  value = 0.0;

  return
end
function value = c3 ( x, y )

%*****************************************************************************80
%
%% C3 evaluates C function #3.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    30 June 2014
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, real X, Y, the evaluation point.
%
%    Output, real VALUE, the value of C(X).
%
  value = 1.0;

  return
end
function value = exact3 ( x, y )

%*****************************************************************************80
%
%% EXACT3 evaluates exact solution #3.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    30 June 2014
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, real X, Y, the evaluation point.
%
%    Output, real VALUE, the value of the solution.
%
  value = x .* ( 1.0 - x ) .* y .* ( 1.0 - y );

  return
end
function value = exact_ux3 ( x, y )

%*****************************************************************************80
%
%% EXACT_UX3 evaluates the derivative dUdX of exact solution #3.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    30 June 2014
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, real X, Y, the evaluation point.
%
%    Output, real VALUE, the value of dUdX.
%
  value = ( 1.0 - 2.0 * x ) .* ( y - y .* y );

  return
end
function value = exact_uy3 ( x, y )

%*****************************************************************************80
%
%% EXACT_UY3 evaluates the derivative dUdY of exact solution #3.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    30 June 2014
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, real X, Y, the evaluation point.
%
%    Output, real VALUE, the value of dUdX.
%
  value = ( x - x .* x ) .* ( 1.0 - 2.0 * y );

  return
end
function value = f3 ( x, y )

%*****************************************************************************80
%
%% F3 evaluates right hand side function #3.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    30 June 2014
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, real X, Y, the evaluation point.
%
%    Output, real VALUE, the value of the right hand side.
%
  value = x .* ( 1.0 - x ) .* y .* ( 1.0 - y );

  return
end

author: johannesgerer

repo: jburkardt-m


text:
function [ donepath ] = get_donepath( resfile )

[path, name] = fileparts(resfile);
donepath = fullfile(path, ['.', name, '.done']);

end

author: hpatches

repo: hpatches-benchmark


text:
function eeg_write_scan41(f,filename)

% eeg_write_scan41 - Write a Neuroscan 'scan4.1' average file
%
% Useage: eeg_write_scan41(f,filename)
%
% where:    filename is a complete 'path\fileprefix.ext' string;
%           the file will be a neuroscan 4.1 avg file.
%
%           f is a structure containing:
%
%               f.header
%               f.electloc
%               f.data
%               f.variance
%               f.tag
%
%           See companion function: eeg_load_scan4_avg.m
%

% $Revision: 1.1 $ $Date: 2009-04-28 22:13:54 $

% Licence:  GNU GPL, no implied or express warranties
% Created:  08/2000, Sean Fitzgibbon <psspf@id.psy.flinders.edu.au>
% Modified: 08/2001, Darren.Weber_at_radiology.ucsf.edu
%                    distribute under GPL, with Sean's permission
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

fid = fopen(filename,'w');

fwrite(fid,f.header.rev,'char');
fwrite(fid,f.header.nextfile,'long');
fwrite(fid,f.header.prevfile,'long');
fwrite(fid,f.header.type,'char');
fwrite(fid,f.header.id,'char');
fwrite(fid,f.header.oper,'char');
fwrite(fid,f.header.doctor,'char');
fwrite(fid,f.header.referral,'char');
fwrite(fid,f.header.hospital,'char');
fwrite(fid,f.header.patient,'char');
fwrite(fid,f.header.age,'short');
fwrite(fid,f.header.sex,'char');
fwrite(fid,f.header.hand,'char');
fwrite(fid,f.header.med,'char');
fwrite(fid,f.header.category,'char');
fwrite(fid,f.header.state,'char');
fwrite(fid,f.header.label,'char');
fwrite(fid,f.header.date,'char');
fwrite(fid,f.header.time,'char');
fwrite(fid,f.header.mean_age,'float');
fwrite(fid,f.header.stdev,'float');
fwrite(fid,f.header.n,'short');
fwrite(fid,f.header.compfile,'char');
fwrite(fid,f.header.spectwincomp,'float');
fwrite(fid,f.header.meanaccuracy,'float');
fwrite(fid,f.header.meanlatency,'float');
fwrite(fid,f.header.sortfile,'char');
fwrite(fid,f.header.numevents,'int');
fwrite(fid,f.header.compoper,'char');
fwrite(fid,f.header.avgmode,'char');
fwrite(fid,f.header.review,'char');
fwrite(fid,f.header.nsweeps,'ushort');
fwrite(fid,f.header.compsweeps,'ushort');
fwrite(fid,f.header.acceptcnt,'ushort');
fwrite(fid,f.header.rejectcnt,'ushort');
fwrite(fid,f.header.pnts,'ushort');
fwrite(fid,f.header.nchannels,'ushort');
fwrite(fid,f.header.avgupdate,'ushort');
fwrite(fid,f.header.domain,'char');
fwrite(fid,f.header.variance,'char');
fwrite(fid,f.header.rate,'ushort');
fwrite(fid,f.header.scale,'double');
fwrite(fid,f.header.veogcorrect,'char');
fwrite(fid,f.header.heogcorrect,'char');
fwrite(fid,f.header.aux1correct,'char');
fwrite(fid,f.header.aux2correct,'char');
fwrite(fid,f.header.veogtrig,'float');
fwrite(fid,f.header.heogtrig,'float');
fwrite(fid,f.header.aux1trig,'float');
fwrite(fid,f.header.aux2trig,'float');
fwrite(fid,f.header.heogchnl,'short');
fwrite(fid,f.header.veogchnl,'short');
fwrite(fid,f.header.aux1chnl,'short');
fwrite(fid,f.header.aux2chnl,'short');
fwrite(fid,f.header.veogdir,'char');
fwrite(fid,f.header.heogdir,'char');
fwrite(fid,f.header.aux1dir,'char');
fwrite(fid,f.header.aux2dir,'char');
fwrite(fid,f.header.veog_n,'short');
fwrite(fid,f.header.heog_n,'short');
fwrite(fid,f.header.aux1_n,'short');
fwrite(fid,f.header.aux2_n,'short');
fwrite(fid,f.header.veogmaxcnt,'short');
fwrite(fid,f.header.heogmaxcnt,'short');
fwrite(fid,f.header.aux1maxcnt,'short');
fwrite(fid,f.header.aux2maxcnt,'short');
fwrite(fid,f.header.veogmethod,'char');
fwrite(fid,f.header.heogmethod,'char');
fwrite(fid,f.header.aux1method,'char');
fwrite(fid,f.header.aux2method,'char');
fwrite(fid,f.header.ampsensitivity,'float');
fwrite(fid,f.header.lowpass,'char');
fwrite(fid,f.header.highpass,'char');
fwrite(fid,f.header.notch,'char');
fwrite(fid,f.header.autoclipadd,'char');
fwrite(fid,f.header.baseline,'char');
fwrite(fid,f.header.offstart,'float');
fwrite(fid,f.header.offstop,'float');
fwrite(fid,f.header.reject,'char');
fwrite(fid,f.header.rejstart,'float');
fwrite(fid,f.header.rejstop,'float');
fwrite(fid,f.header.rejmin,'float');
fwrite(fid,f.header.rejmax,'float');
fwrite(fid,f.header.trigtype,'char');
fwrite(fid,f.header.trigval,'float');
fwrite(fid,f.header.trigchnl,'char');
fwrite(fid,f.header.trigmask,'short');
fwrite(fid,f.header.trigisi,'float');
fwrite(fid,f.header.trigmin,'float');
fwrite(fid,f.header.trigmax,'float');
fwrite(fid,f.header.trigdir,'char');
fwrite(fid,f.header.autoscale,'char');
fwrite(fid,f.header.n2,'short');
fwrite(fid,f.header.dir,'char');
fwrite(fid,f.header.dispmin,'float');
fwrite(fid,f.header.dispmax,'float');
fwrite(fid,f.header.xmin,'float');
fwrite(fid,f.header.xmax,'float');
fwrite(fid,f.header.automin,'float');
fwrite(fid,f.header.automax,'float');
fwrite(fid,f.header.zmin,'float');
fwrite(fid,f.header.zmax,'float');
fwrite(fid,f.header.lowcut,'float');
fwrite(fid,f.header.highcut,'float');
fwrite(fid,f.header.common,'char');
fwrite(fid,f.header.savemode,'char');
fwrite(fid,f.header.manmode,'char');
fwrite(fid,f.header.ref,'char');
fwrite(fid,f.header.rectify,'char');
fwrite(fid,f.header.displayxmin,'float');
fwrite(fid,f.header.displayxmax,'float');
fwrite(fid,f.header.phase,'char');
fwrite(fid,f.header.screen,'char');
fwrite(fid,f.header.calmode,'short');
fwrite(fid,f.header.calmethod,'short');
fwrite(fid,f.header.calupdate,'short');
fwrite(fid,f.header.calbaseline,'short');
fwrite(fid,f.header.calsweeps,'short');
fwrite(fid,f.header.calattenuator,'float');
fwrite(fid,f.header.calpulsevolt,'float');
fwrite(fid,f.header.calpulsestart,'float');
fwrite(fid,f.header.calpulsestop,'float');
fwrite(fid,f.header.calfreq,'float');
fwrite(fid,f.header.taskfile,'char');
fwrite(fid,f.header.seqfile,'char');
fwrite(fid,f.header.spectmethod,'char');
fwrite(fid,f.header.spectscaling,'char');
fwrite(fid,f.header.spectwindow,'char');
fwrite(fid,f.header.spectwinlength,'float');
fwrite(fid,f.header.spectorder,'char');
fwrite(fid,f.header.notchfilter,'char');
fwrite(fid,f.header.headgain,'short');
fwrite(fid,f.header.additionalfiles,'int');
fwrite(fid,f.header.unused,'char');
fwrite(fid,f.header.fspstopmethod,'short');
fwrite(fid,f.header.fspstopmode,'short');
fwrite(fid,f.header.fspfvalue,'float');
fwrite(fid,f.header.fsppoint,'short');
fwrite(fid,f.header.fspblocksize,'short');
fwrite(fid,f.header.fspp1,'ushort');
fwrite(fid,f.header.fspp2,'ushort');
fwrite(fid,f.header.fspalpha,'float');
fwrite(fid,f.header.fspnoise,'float');
fwrite(fid,f.header.fspv1,'short');
fwrite(fid,f.header.montage,'char');
fwrite(fid,f.header.eventfile,'char');
fwrite(fid,f.header.fratio,'float');
fwrite(fid,f.header.minor_rev,'char');
fwrite(fid,f.header.eegupdate,'short');
fwrite(fid,f.header.compressed,'char');
fwrite(fid,f.header.xscale,'float');
fwrite(fid,f.header.yscale,'float');
fwrite(fid,f.header.xsize,'float');
fwrite(fid,f.header.ysize,'float');
fwrite(fid,f.header.acmode,'char');
fwrite(fid,f.header.commonchnl,'uchar');
fwrite(fid,f.header.xtics,'char');
fwrite(fid,f.header.xrange,'char');
fwrite(fid,f.header.ytics,'char');
fwrite(fid,f.header.yrange,'char');
fwrite(fid,f.header.xscalevalue,'float');
fwrite(fid,f.header.xscaleinterval,'float');
fwrite(fid,f.header.yscalevalue,'float');
fwrite(fid,f.header.yscaleinterval,'float');
fwrite(fid,f.header.scaletoolx1,'float');
fwrite(fid,f.header.scaletooly1,'float');
fwrite(fid,f.header.scaletoolx2,'float');
fwrite(fid,f.header.scaletooly2,'float');
fwrite(fid,f.header.port,'short');
fwrite(fid,f.header.numsamples,'long');
fwrite(fid,f.header.filterflag,'char');
fwrite(fid,f.header.lowcutoff,'float');
fwrite(fid,f.header.lowpoles,'short');
fwrite(fid,f.header.highcutoff,'float');
fwrite(fid,f.header.highpoles,'short');
fwrite(fid,f.header.filtertype,'char');
fwrite(fid,f.header.filterdomain,'char');
fwrite(fid,f.header.snrflag,'char');
fwrite(fid,f.header.coherenceflag,'char');
fwrite(fid,f.header.continuoustype,'char');
fwrite(fid,f.header.eventtablepos,'long');
fwrite(fid,f.header.continuousseconds,'float');
fwrite(fid,f.header.channeloffset,'long');
fwrite(fid,f.header.autocorrectflag,'char');
fwrite(fid,f.header.dcthreshold,'uchar');

for n = 1:f.header.nchannels
fwrite(fid,f.electloc(n).lab,'char');
fwrite(fid,f.electloc(n).reference,'char');
fwrite(fid,f.electloc(n).skip,'char');
fwrite(fid,f.electloc(n).reject,'char');
fwrite(fid,f.electloc(n).display,'char');
fwrite(fid,f.electloc(n).bad,'char');
fwrite(fid,f.electloc(n).n,'ushort');
fwrite(fid,f.electloc(n).avg_reference,'char');
fwrite(fid,f.electloc(n).clipadd,'char');
fwrite(fid,f.electloc(n).x_coord,'float');
fwrite(fid,f.electloc(n).y_coord,'float');
fwrite(fid,f.electloc(n).veog_wt,'float');
fwrite(fid,f.electloc(n).veog_std,'float');
fwrite(fid,f.electloc(n).snr,'float');
fwrite(fid,f.electloc(n).heog_wt,'float');
fwrite(fid,f.electloc(n).heog_std,'float');
fwrite(fid,f.electloc(n).baseline,'short');
fwrite(fid,f.electloc(n).filtered,'char');
fwrite(fid,f.electloc(n).fsp,'char');
fwrite(fid,f.electloc(n).aux1_wt,'float');
fwrite(fid,f.electloc(n).aux1_std,'float');
fwrite(fid,f.electloc(n).senstivity,'float');
fwrite(fid,f.electloc(n).gain,'char');
fwrite(fid,f.electloc(n).hipass,'char');
fwrite(fid,f.electloc(n).lopass,'char');
fwrite(fid,f.electloc(n).page,'uchar');
fwrite(fid,f.electloc(n).size,'uchar');
fwrite(fid,f.electloc(n).impedance,'uchar');
fwrite(fid,f.electloc(n).physicalchnl,'uchar');
fwrite(fid,f.electloc(n).rectify,'char');
fwrite(fid,f.electloc(n).calib,'float');
end

for i = 1:f.header.nchannels
   fwrite(fid,f.data(i).header,'char');
   fwrite(fid,f.data(i).samples,'float');
end

for j = 1:f.header.nchannels
   fwrite(fid,f.variance(j).samples,'float');
end

fwrite(fid,f.tag,'char');

frewind(fid);

fclose(fid);

author: PatternRecognition

repo: OpenBMI


text:
function ASAversionbkup(funct_name)
%ASAVERSIONBKUP Version-tagged function backup
%   ASAVERSIONBKUP(FUNCTION) copies a m-file FUNCTION, that is provided
%   with an ARMASA version identifier, into a directory 'Backup' and
%   renames the file by appending the version identifier (that has been
%   numerically converted) to its name. For more details about the
%   numeric conversion, see ASAVERSION2NUMSTR. FUNCTION must be a
%   character string, containing the name of the m-file to backup. The
%   directory 'Backup' must be located in the directory where the m-file
%   resides, or otherwise it is created.
%
%   See also: ASAVERSION2NUMSTR

[funct_root,funct_name,funct_ext]=fileparts(which(funct_name));
ASAcontrol.run=0;
ASAcontrol.version_chk=0;
ASAcontrol=feval(funct_name,ASAcontrol);
funct_version=ASAversion2numstr(ASAcontrol.is_version);
bkup_name=[funct_name '_' strrep(funct_version,'.','_')];
if ~exist([funct_root filesep 'Backup'],'dir')
   mkdir(funct_root,'Backup');
end
copyfile([funct_root filesep funct_name funct_ext], ...
   [funct_root filesep 'Backup' filesep bkup_name funct_ext]);

%Program history
%======================================================================
%
% Version                Programmer(s)          E-mail address
% -------                -------------          --------------
% [2000 12 30 20 0 0]    W. Wunderink           wwunderink01@freeler.nl

author: Sable

repo: mcbench-benchmarks


text:
%EXPANDBDR Expand physics mode boundary coefficients.

% Copyright 2013-2022 Precise Simulation, Ltd.

author: precise-simulation

repo: featool-multiphysics


text:
%% Experience generation
sim_100 = [];
testData = readtable('data\testData.csv');
simOpts = rlSimulationOptions('MaxSteps',4000);
for i = 1:100
    experience = sim(envT,agent,simOpts);
    prices = testData(end,:);
    nbStock = experience.Observation.StockTradingStates.Data(:,1:3,end);
    cash = experience.Observation.StockTradingStates.Data(:,7,end);
    cur_val = sum(nbStock.*prices{1,:}) + cash;
    sim_100(end+1) = cur_val;
end
sim_norm = sim_100 - 20000;

%% Analisis of the simulations
figure;
h1 = histogram(sim_norm,'Normalization','pdf');
pd = fitdist(sim_norm','Weibull');

x_pdf = linspace(min(sim_norm),max(sim_norm),100);
y = pdf(pd,x_pdf); %pdf calculation
line(x_pdf,y,'color','r')

val_5per = pd.icdf(0.05);
val_95per = pd.icdf(0.95);

prob_upto_mean = pd.cdf(pd.mean);

xlabel(['tph - prob of up to mean: ',num2str(round(100*prob_upto_mean)),'%'])
ylabel('count pdf')
title(['distribution fit of trading profit'])
xtickformat('usd');
% hold on
line([val_5per,val_5per],[0,max(h1.Values)],'color','m')
line([pd.mean,pd.mean],[0,max(h1.Values)])
line([val_95per,val_95per],[0,max(h1.Values)],'color','m')

legend('Distribution',pd.DistributionName,['Lower 5%: ',num2str(val_5per )],...
    ['Dist Mean: ',num2str(pd.mean) ] ,...
    ['Upper 5%: ',num2str(val_95per)]);

author: matlab-deep-learning


text:
function edgeBoxesSweeps()
% Parameter sweeps for Edges Boxes object proposals.
%
% Running the parameter sweeps requires altering internal flags.
% The sweeps are not well documented, use at your own discretion.
%
% Structured Edge Detection Toolbox      Version 3.01
% Code written by Piotr Dollar and Larry Zitnick, 2014.
% Licensed under the MSR-LA Full Rights License [see license.txt]

% define parameter sweeps
rt = [fileparts(mfilename('fullpath')) filesep];
expNms = {'alpha','beta','eta','minScore','edgeMinMag','edgeMergeThr',...
  'clusterMinMag','maxAspectRatio','minBoxArea','gamma','kappa'};
expNms=expNms(1:end); opts=createExp(rt,expNms); maxn=inf;

% run training and testing jobs
jobs = createJobs(rt,opts,maxn);
tic, for i=1:length(jobs), edgeBoxes(jobs{i}{:}); end; toc

% plot all results
for e=1:length(expNms)
  eval={'data',boxesData('split','val'),'names',{opts{e}.name},...
    'resDir',[rt 'boxes/sweeps/'],'maxn',maxn,'fName',expNms{e}};
  boxesEval(eval{:},'thrs',.7);
  ar=boxesEval(eval{:},'thrs',.5:.05:1,'cnts',1000);
  ar=squeeze(mean(ar,2)); [~,i]=max(ar); disp(opts{e}(i))
end

end

function jobs = createJobs( rt, opts, maxn )
% create jobs
M='models/forest/modelBsds'; M=load(M); M=M.model; M.opts.nThreads=1;
data=boxesData('split','val'); fs=data.imgs(1:min(end,maxn));
opts=[opts{:}]; N=length(opts); jobs=cell(1,N); D=zeros(1,N);
for e=1:N, opts(e).name=[rt 'boxes/sweeps/' opts(e).name '-val.mat']; end
for e=1:N, D(e)=exist(opts(e).name,'file')==2; jobs{e}={fs,M,opts(e)}; end
[~,K]=unique({opts.name},'stable'); D=D(K); jobs=jobs(K); jobs=jobs(~D);
fprintf('nJobs = %i\n',length(jobs));
end

function opts = createExp( rt, expNm )

% if expNm is a cell, call recursively and return
if( iscell(expNm) )
  N=length(expNm); opts=cell(1,N);
  for e=1:N, opts{e}=createExp(rt,expNm{e}); end; return;
end

% setup opts
opts=edgeBoxes(); opts.minScore=0;
N=100; optsDefault=opts; opts=opts(ones(1,N));
switch expNm
  case 'alpha'
    vs=45:5:75; N=length(vs);
    for e=1:N, opts(e).alpha=vs(e)/100; end
  case 'beta'
    vs=60:5:90; N=length(vs);
    for e=1:N, opts(e).beta=vs(e)/100; end
  case 'eta'
    vs=0:5; N=length(vs);
    for e=1:N, opts(e).eta=1-vs(e)/10000; end
  case 'minScore'
    vs=[0 5 10 25 50 100]; N=length(vs);
    for e=1:N, opts(e).minScore=vs(e)/1000; end
  case 'edgeMinMag'
    vs=[0 50 100 200 400]; N=length(vs);
    for e=1:N, opts(e).edgeMinMag=vs(e)/1000; end
  case 'edgeMergeThr'
    vs=[25 50 100 200 400]; N=length(vs);
    for e=1:N, opts(e).edgeMergeThr=vs(e)/100; end
  case 'clusterMinMag'
    vs=[0 50 100 200 400]; N=length(vs);
    for e=1:N, opts(e).clusterMinMag=vs(e)/100; end
  case 'maxAspectRatio'
    vs=1:5; N=length(vs);
    for e=1:N, opts(e).maxAspectRatio=vs(e); end
  case 'minBoxArea'
    vs=[100 250 500 1000 2500 5000]; N=length(vs);
    for e=1:N, opts(e).minBoxArea=vs(e); end
  case 'gamma'
    vs=[25 50 100 200 400 10000]; N=length(vs);
    for e=1:N, opts(e).gamma=vs(e)/100; end
  case 'kappa'
    vs=50:25:200; N=length(vs);
    for e=1:N, opts(e).kappa=vs(e)/100; end
  otherwise, error('invalid exp: %s',expNm);
end

% produce final set of opts and find default opts
O=1:N; opts=opts(O); d=0;
for e=1:N, if(isequal(optsDefault,opts(e))), d=e; break; end; end
if(d==0), disp(expNm); assert(false); end; opts(d).name='Default';
for e=1:N, if(e~=d), opts(e).name=[expNm int2str2(vs(e),5)]; end; end

end

author: pdollar

repo: edges

save_path: github-repos/MATLAB/pdollar-edges


text:
function [varargout]=hex8_hex20(varargin)

% function [E_hex20,V_hex20,V_hex20_cell,Fb_hex20,S]=hex8_hex20(E_hex8,V_hex8,V_hex8_cell,Fb_hex8)
% ------------------------------------------------------------------------
% This function converts 8 node (e.g. linear) hexahedral elements into 20
% node (e.g. quadratic) hexahedral elements compatible with FEBio.
%
%
% varargout{1}=E_hex20;
% varargout{2}=V_hex20;
% varargout{3}=V_hex20_cell;
% varargout{4}=Fb_hex20;
% varargout{5}=S;
%
%
% Kevin Mattheus Moerman
% gibbon.toolbox@gmail.com
%
% 2018/10/19 Created based on tet4_tet10
%------------------------------------------------------------------------
%%

%% Parse input
switch nargin
    case 2
        E_hex8=varargin{1};
        V_hex8=varargin{2};
        V_hex8_cell={};
        Fb_hex8={};
    case 3
        E_hex8=varargin{1};
        V_hex8=varargin{2};
        V_hex8_cell=varargin{3};
        Fb_hex8={};
    case 4
        E_hex8=varargin{1};
        V_hex8=varargin{2};
        V_hex8_cell=varargin{3};
        Fb_hex8=varargin{4};
    otherwise
        error('wrong number of input arguments');
end

%% Create element set

%Creating "egdge indices" matrices
matVirtSize=size(V_hex8,1)*ones(1,2);

%Edges matrix
indMatrix_1=[E_hex8(:,1) E_hex8(:,2) E_hex8(:,3) E_hex8(:,4)  E_hex8(:,5) E_hex8(:,6) E_hex8(:,7) E_hex8(:,8)  E_hex8(:,5) E_hex8(:,6) E_hex8(:,7) E_hex8(:,8)];
indMatrix_2=[E_hex8(:,2) E_hex8(:,3) E_hex8(:,4) E_hex8(:,1)  E_hex8(:,6) E_hex8(:,7) E_hex8(:,8) E_hex8(:,5)  E_hex8(:,1) E_hex8(:,2) E_hex8(:,3) E_hex8(:,4)];

%3D edges matrix, first layer, first points, second layer, second points
edgeMatrix=indMatrix_1;
edgeMatrix(:,:,2)=indMatrix_2;
edgeMatrix=sort(edgeMatrix,3);

%Convert to virtual indices
edgeIndexMatrix=sub2ind(matVirtSize,edgeMatrix(:,:,1),edgeMatrix(:,:,2));

%Compose unique set
[edgeIndexUni,ind1,ind2]=unique(edgeIndexMatrix(:));

indhex20_new=reshape(ind2,size(edgeIndexMatrix));

%Create unique point index matrices
[indMatrix_1_uni,indMatrix_2_uni]=ind2sub(matVirtSize,edgeIndexUni);

E_hex20=[E_hex8 indhex20_new+size(V_hex8,1)];

%% Create and add new coordinates
% Calculate coordinates for unique new points
V_new=0.5*(V_hex8(indMatrix_1_uni,:)+V_hex8(indMatrix_2_uni,:));%
V_hex20=[V_hex8;V_new];

%% Process cell data

if ~isempty(V_hex8_cell)
    V_hex20_cell=V_hex8_cell;
    for qc=1:1:numel(V_hex20_cell)
        XX_hex8=V_hex8_cell{qc};
        XX_new=0.5*(XX_hex8(indMatrix_1_uni,:)+XX_hex8(indMatrix_2_uni,:));
        XX_hex20=[XX_hex8;XX_new];
        V_hex20_cell{qc}=XX_hex20;
    end
else
    V_hex20_cell={};
end

%% Compose output
varargout{1}=E_hex20;
varargout{2}=V_hex20;
varargout{3}=V_hex20_cell;

if nargout>3

    % Process boundary faces
    if ~isempty(Fb_hex8)

        S = sparse(indMatrix_1_uni,indMatrix_2_uni,ind2(ind1),matVirtSize(1),matVirtSize(2),numel(ind1));

        %Edges matrix
        indMatrix_1=[Fb_hex8(:,1) Fb_hex8(:,2) Fb_hex8(:,3) Fb_hex8(:,4)];
        indMatrix_2=[Fb_hex8(:,2) Fb_hex8(:,3) Fb_hex8(:,4) Fb_hex8(:,1)];

        %3D edges matrix, first layer, first points, second layer, second points
        edgeMatrix=indMatrix_1;
        edgeMatrix(:,:,2)=indMatrix_2;
        edgeMatrix=sort(edgeMatrix,3);

        edgeIndexMatrix=sub2ind(matVirtSize,edgeMatrix(:,:,1),edgeMatrix(:,:,2));

        indhex20_new=full(S(edgeIndexMatrix));

        Fb_hex20_quad8=[Fb_hex8 indhex20_new+size(V_hex8,1)];
        Fb_hex20=Fb_hex20_quad8(:,[1 5 2 6 3 7 4 8]);
    else
        Fb_hex20_quad8=[];
        Fb_hex20=[];
    end
    varargout{4}=Fb_hex20;
    varargout{5}=Fb_hex20_quad8;
end

%%
% _*GIBBON footer text*_
%
% License: <https://github.com/gibbonCode/GIBBON/blob/master/LICENSE>
%
% GIBBON: The Geometry and Image-based Bioengineering add-On. A toolbox for
% image segmentation, image-based modeling, meshing, and finite element
% analysis.
%
% Copyright (C) 2006-2022 Kevin Mattheus Moerman and the GIBBON contributors
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program.  If not, see <http://www.gnu.org/licenses/>.

author: gibbonCode

repo: GIBBON

save_path: github-repos/MATLAB/gibbonCode-GIBBON


text:
function nfmi = fmi(ima, imb, imf, feature, w)

% FMI calculates the Feature Mutual Information (FMI), the non-reference
% performance metric for fusion algorithms, proposed in:
%
% M.B.A. Haghighat, A. Aghagolzadeh, H. Seyedarabi, "A Non-Reference Image
% Fusion Metric Based on Mutual Information of Image Features," Computers
% and Electrical Engineering, vol. 37, no. 5, pp. 744-756, Sept. 2011.
% http://dx.doi.org/10.1016/j.compeleceng.2011.07.012
%
%
% This code is the implementation of FAST-FMI, presented in:
%
% M. Haghighat, M.A. Razian, "Fast-FMI: non-reference image fusion metric,"
% 8th International Conference on Application of Information and
% Communication Technologies (AICT), pp. 1-3, 2014.
%
%
% Inputs:
% 		ima 	: 	First source image
% 		imb 	: 	Second source image
% 		imf 	: 	Fused image
% 		feature : 	Feature extraction method: gradient, edge, dct, wavelet, none (raw pixels) (default: image with no feature extraction)
% 		w       : 	Sliding window size w by w (default: 3)
%
% Output:
% 		nfmi 	: 	Normalized Feature Mutual Information
%
%
% Sample use:
% nfmi = fmi(ima,imb,imf,'none',3);
% % Or simply:
% nfmi = fmi(ima,imb,imf);
%
%
% (C)	Mohammad Haghighat, University of Miami
%       haghighat@ieee.org
%       IF YOU USE THIS CODE IN YOUR WORK, PLEASE CITE THE ABOVE PAPERS.

if nargin < 3               % Check correct number of arguments
    error('There should be three input images (2 source images and 1 fused image)!');
end

if size(ima) ~= size(imb)	% Check if the source images are of the same size
    error('Size of the source images must be the same!');
end

if size(ima) ~= size(imf)	% Check if the source images are of the same size
    error('Size of the source and fused images must be the same!');
end

if ~exist('feature', 'var')
    feature = 'edge';       % Default feature extraction
end

if ~exist('w', 'var')
    w = 3;                  % Default window size
end

ima = double(ima);
imb = double(imb);
imf = double(imf);

% Feature Extraction

switch feature

	case 'none'         % Raw pixels (no feature extraction)
        aFeature = ima;
        bFeature = imb;
        fFeature = imf;

    case 'gradient'     % Gradient
        aFeature = gradient(ima);
        bFeature = gradient(imb);
        fFeature = gradient(imf);

    case 'edge'         % Edge
        aFeature = edge(ima);
        bFeature = edge(imb);
        fFeature = edge(imf);

    case 'dct'          % DCT
        aFeature = dct2(ima);
        bFeature = dct2(imb);
        fFeature = dct2(imf);

    case 'wavelet'      % Discrete Meyer wavelet
        [cA,cH,cV,cD] = dwt2(ima,'dmey');
        aFeature = rerange([cA,cH;cV,cD]);
        [cA,cH,cV,cD] = dwt2(imb,'dmey');
        bFeature = rerange([cA,cH;cV,cD]);
        [cA,cH,cV,cD] = dwt2(imf,'dmey');
        fFeature = rerange([cA,cH;cV,cD]);

    otherwise
        error('Please specify a feature extraction method among ''gradient'', ''edge'', ''dct'', ''wavelet'', or ''none'' (raw pixels)!');

end

% Sliding window

[m,n] = size(aFeature);
w = floor(w/2);
fmi_map = ones(m-2*w, n-2*w);

for p = w+1:m-w
    for q = w+1:n-w

        aSub = aFeature(p-w:p+w, q-w:q+w);
        bSub = bFeature(p-w:p+w, q-w:q+w);
        fSub = fFeature(p-w:p+w, q-w:q+w);

        l = round((2*w+1).^2);

        if aSub == fSub
            fmi_af = 1;
        else
            aMax = max(aSub(:));
            aMin = min(aSub(:));
            if aMax == aMin
                aSub = ones(2*w+1);
            else
                aSub = (aSub - aMin)/(aMax - aMin);
            end

            fMax = max(fSub(:));
            fMin = min(fSub(:));
            if fMax == fMin
                fSub = ones(2*w+1);
            else
                fSub = (fSub - fMin)/(fMax - fMin);
            end

            % Normalize the feature images to get the marginal PDFs
            aPdf = aSub(:)./(sum(sum(aSub)));
            fPdf = fSub(:)./(sum(sum(fSub)));

            % PDF to CDF tranformation
            aCdf = zeros(size(aPdf));
            fCdf = zeros(size(fPdf));
            aCdf(1) = aPdf(1);
            fCdf(1) = fPdf(1);
            for i = 2:l
                aCdf(i) = aPdf(i)+aCdf(i-1);
                fCdf(i) = fPdf(i)+fCdf(i-1);
            end

            % Pearson correlation between marginal PDFs
            aTemp = aPdf - mean(aPdf);
            fTemp = fPdf - mean(fPdf);
            if sum(aTemp.*fTemp) == 0
                c = 0;
            else
                c = sum(aTemp.*fTemp)/sqrt(sum(aTemp.*aTemp)*sum(fTemp.*fTemp));
            end

            % Population standard deviations
            e_aPdf = 0; e2_aPdf = 0; e_fPdf = 0; e2_fPdf = 0;
            for i = 1:l
                e_aPdf  = e_aPdf  + i.*aPdf(i);         % Expected value of aPdf
                e2_aPdf = e2_aPdf + (i.^2).*aPdf(i);    % 2nd-order moment of aPdf
                e_fPdf  = e_fPdf  + i.*fPdf(i);         % Expected value of fPdf
                e2_fPdf = e2_fPdf + (i.^2).*fPdf(i);	% 2nd-order moment of fPdf
            end
            aSd = sqrt(e2_aPdf - e_aPdf.^2);	% Population standard deviation of aPdf
            fSd = sqrt(e2_fPdf - e_fPdf.^2);	% Population standard deviation of fPdf

            jointEntropy = 0;
            % Joint PDF calculation using simplified Nelsen method with joint entropy calculation
            if c >= 0

                if c == 0 || aSd == 0 || fSd == 0
                    phi = 0;
                else
                    covUp = 0;
                    for i = 1:l
                        for j = 1:l
                            % Frechet's upper bound bivariate distributions between f & a
                            covUp = covUp + 0.5*(fCdf(i)+aCdf(j)-abs(fCdf(i)-aCdf(j))) - fCdf(i).*aCdf(j);
                        end
                    end
                    corrUp = covUp/(fSd*aSd); % Upper correlation between f & a
                    phi = c/corrUp;
                end

                jpdfUp = 0.5*(fCdf(1)+aCdf(1)-abs(fCdf(1)-aCdf(1)));
                jpdf = phi.*jpdfUp + (1-phi).*fPdf(1).*aPdf(1);
                if jpdf~=0
                    jointEntropy = real(-jpdf.*log2(jpdf)); % Joint entropy
                end

                % 1-D boundaries
                for i=2:l
                    jpdfUp = 0.5*(fCdf(i)+aCdf(1)-abs(fCdf(i)-aCdf(1))) - ...
                        0.5*(fCdf(i-1)+aCdf(1)-abs(fCdf(i-1)-aCdf(1)));
                    jpdf = phi.*jpdfUp + (1-phi).*fPdf(i).*aPdf(1);
                    if jpdf~=0
                        jointEntropy = jointEntropy + real(-jpdf.*log2(jpdf)); % Joint entropy
                    end
                end
                for j=2:l
                    jpdfUp = 0.5*(fCdf(1)+aCdf(j)-abs(fCdf(1)-aCdf(j))) - ...
                        0.5*(fCdf(1)+aCdf(j-1)-abs(fCdf(1)-aCdf(j-1)));
                    jpdf = phi.*jpdfUp + (1-phi).*fPdf(1).*aPdf(j);
                    if jpdf~=0
                        jointEntropy = jointEntropy + real(-jpdf.*log2(jpdf)); % Joint entropy
                    end
                end
                % 2-D walls
                for i=2:l
                    for j=2:l
                        jpdfUp = 0.5*(fCdf(i)+aCdf(j)-abs(fCdf(i)-aCdf(j))) - ...
                            0.5*(fCdf(i-1)+aCdf(j)-abs(fCdf(i-1)-aCdf(j))) - ...
                            0.5*(fCdf(i)+aCdf(j-1)-abs(fCdf(i)-aCdf(j-1))) + ...
                            0.5*(fCdf(i-1)+aCdf(j-1)-abs(fCdf(i-1)-aCdf(j-1)));
                        jpdf = phi.*jpdfUp + (1-phi).*fPdf(i).*aPdf(j);
                        if jpdf~=0
                            jointEntropy = jointEntropy + real(-jpdf.*log2(jpdf)); % Joint entropy
                        end
                    end
                end

            end

            if c < 0

                if aSd == 0 || fSd == 0
                    theta = 0;
                else
                    covLo = 0;
                    for i = 1:l
                        for j = 1:l
                            % Frechet's lower bound bivariate distributions between f & a
                            covLo = covLo + 0.5*(fCdf(i)+aCdf(j)-1+abs(fCdf(i)+aCdf(j)-1)) - fCdf(i).*aCdf(j);
                        end
                    end
                    corrLo = covLo/(fSd*aSd); % Lower correlation between f & a
                    theta = c/corrLo;
                end

                jpdfLo = 0.5*(fCdf(1)+aCdf(1)-1+abs(fCdf(1)+aCdf(1)-1));
                jpdf = theta.*jpdfLo + (1-theta).*fPdf(1).*aPdf(1);
                if jpdf~=0
                    jointEntropy = real(-jpdf.*log2(jpdf)); % Joint entropy
                end

                % 1-D boundaries
                for i=2:l
                    jpdfLo = 0.5*(fCdf(i)+aCdf(1)-1+abs(fCdf(i)+aCdf(1)-1)) - ...
                        0.5*(fCdf(i-1)+aCdf(1)-1+abs(fCdf(i-1)+aCdf(1)-1));
                    jpdf = theta.*jpdfLo + (1-theta).*fPdf(i).*aPdf(1);
                    if jpdf~=0
                        jointEntropy = jointEntropy + real(-jpdf.*log2(jpdf)); % Joint entropy
                    end
                end
                for j=2:l
                    jpdfLo = 0.5*(fCdf(1)+aCdf(j)-1+abs(fCdf(1)+aCdf(j)-1)) - ...
                        0.5*(fCdf(1)+aCdf(j-1)-1+abs(fCdf(1)+aCdf(j-1)-1));
                    jpdf = theta.*jpdfLo + (1-theta).*fPdf(1).*aPdf(j);
                    if jpdf~=0
                        jointEntropy = jointEntropy + real(-jpdf.*log2(jpdf)); % Joint entropy
                    end
                end
                % 2-D walls
                for i=2:l
                    for j=2:l
                        jpdfLo = 0.5*(fCdf(i)+aCdf(j)-1+abs(fCdf(i)+aCdf(j)-1)) - ...
                            0.5*(fCdf(i-1)+aCdf(j)-1+abs(fCdf(i-1)+aCdf(j)-1)) - ...
                            0.5*(fCdf(i)+aCdf(j-1)-1+abs(fCdf(i)+aCdf(j-1)-1)) + ...
                            0.5*(fCdf(i-1)+aCdf(j-1)-1+abs(fCdf(i-1)+aCdf(j-1)-1));
                        jpdf = theta.*jpdfLo + (1-theta).*fPdf(i).*aPdf(j);
                        if jpdf~=0
                            jointEntropy = jointEntropy + real(-jpdf.*log2(jpdf)); % Joint entropy
                        end
                    end
                end

            end

            % Marginal entropies
            index = find(aPdf~=0);
            aEntropy = sum(-aPdf(index).*log2(aPdf(index)));
            index = find(fPdf~=0);
            fEntropy = sum(-fPdf(index).*log2(fPdf(index)));

            % Mutual information between a & f
            mi = aEntropy + fEntropy - jointEntropy;

            % Overall normalized mutual information
            if mi == 0
                fmi_af = 0;
            else
                fmi_af = 2.*mi./(aEntropy+fEntropy);
            end

        end

        if bSub == fSub
            fmi_bf = 1;
        else
            bMax = max(bSub(:));
            bMin = min(bSub(:));
            if bMax == bMin
                bSub = ones(2*w+1);
            else
                bSub = (bSub - bMin)/(bMax - bMin);
            end

            fMax = max(fSub(:));
            fMin = min(fSub(:));
            if fMax == fMin
                fSub = ones(2*w+1);
            else
                fSub = (fSub - fMin)/(fMax - fMin);
            end

            % PDF of the gradients of the images
            bPdf = bSub(:)./(sum(sum(bSub)));
            fPdf = fSub(:)./(sum(sum(fSub)));

            l = length(bPdf);

            % PDF to CDF tranformation
            bCdf = zeros(size(bPdf));
            fCdf = zeros(size(fPdf));
            bCdf(1) = bPdf(1);
            fCdf(1) = fPdf(1);
            for i=2:l
                bCdf(i) = bPdf(i)+bCdf(i-1);
                fCdf(i) = fPdf(i)+fCdf(i-1);
            end

            % Pearson correlation between marginal PDFs
            bTemp = bPdf - mean(bPdf);
            fTemp = fPdf - mean(fPdf);
            if sum(bTemp.*fTemp) == 0
                c = 0;
            else
                c = sum(bTemp.*fTemp)/sqrt(sum(bTemp.*bTemp)*sum(fTemp.*fTemp));
            end

            % Population standard deviations
            e_bPdf = 0; e2_bPdf = 0; e_fPdf = 0; e2_fPdf = 0;
            for i = 1:l
                e_bPdf  = e_bPdf  + i.*bPdf(i);         % Expected value of the aPdf
                e2_bPdf = e2_bPdf + (i.^2).*bPdf(i);	% 2nd-order moment of the aPdf
                e_fPdf  = e_fPdf  + i.*fPdf(i);         % Expected value of the bPdf
                e2_fPdf = e2_fPdf + (i.^2).*fPdf(i);	% 2nd-order moment of the bPdf
            end
            bSd = sqrt(e2_bPdf - e_bPdf.^2);	% Population standard deviation of the intensity
            fSd = sqrt(e2_fPdf - e_fPdf.^2);	% Population standard deviation of the intensity

            jointEntropy = 0;
            % JPDF calculation using simplified Nelsen method with joint entropy calculation
            if c >= 0

                if c == 0 || bSd == 0 || fSd == 0
                    phi = 0;
                else
                    covUp = 0;
                    for i = 1:l
                        for j = 1:l
                            % Frechet's upper bound bivariate distributions between f & b
                            covUp = covUp + 0.5*(fCdf(i)+bCdf(j)-abs(fCdf(i)-bCdf(j))) - fCdf(i).*bCdf(j);
                        end
                    end
                    corrUp = covUp/(fSd*bSd); % Upper correlation between f & b
                    phi = c/corrUp;
                end

                jpdfUp = 0.5*(fCdf(1)+bCdf(1)-abs(fCdf(1)-bCdf(1)));
                jpdf = phi.*jpdfUp + (1-phi).*fPdf(1).*bPdf(1);
                if jpdf~=0
                    jointEntropy = real(-jpdf.*log2(jpdf)); % Joint entropy
                end

                % 1-D boundaries
                for i=2:l
                    jpdfUp = 0.5*(fCdf(i)+bCdf(1)-abs(fCdf(i)-bCdf(1))) - ...
                        0.5*(fCdf(i-1)+bCdf(1)-abs(fCdf(i-1)-bCdf(1)));
                    jpdf = phi.*jpdfUp + (1-phi).*fPdf(i).*bPdf(1);
                    if jpdf~=0
                        jointEntropy = jointEntropy + real(-jpdf.*log2(jpdf)); % Joint entropy
                    end
                end
                for j=2:l
                    jpdfUp = 0.5*(fCdf(1)+bCdf(j)-abs(fCdf(1)-bCdf(j))) - ...
                        0.5*(fCdf(1)+bCdf(j-1)-abs(fCdf(1)-bCdf(j-1)));
                    jpdf = phi.*jpdfUp + (1-phi).*fPdf(1).*bPdf(j);
                    if jpdf~=0
                        jointEntropy = jointEntropy + real(-jpdf.*log2(jpdf)); % Joint entropy
                    end
                end
                % 2-D walls
                for i=2:l
                    for j=2:l
                        jpdfUp = 0.5*(fCdf(i)+bCdf(j)-abs(fCdf(i)-bCdf(j))) - ...
                            0.5*(fCdf(i-1)+bCdf(j)-abs(fCdf(i-1)-bCdf(j))) - ...
                            0.5*(fCdf(i)+bCdf(j-1)-abs(fCdf(i)-bCdf(j-1))) + ...
                            0.5*(fCdf(i-1)+bCdf(j-1)-abs(fCdf(i-1)-bCdf(j-1)));
                        jpdf = phi.*jpdfUp + (1-phi).*fPdf(i).*bPdf(j);
                        if jpdf~=0
                            jointEntropy = jointEntropy + real(-jpdf.*log2(jpdf)); % Joint entropy
                        end
                    end
                end

            end

            if c < 0

                if bSd == 0 || fSd == 0
                    theta = 0;
                else
                    covLo = 0;
                    for i = 1:l
                        for j = 1:l
                            % Frechet's lower bound bivariate distributions between f & b
                            covLo = covLo + 0.5*(fCdf(i)+bCdf(j)-1+abs(fCdf(i)+bCdf(j)-1)) - fCdf(i).*bCdf(j);
                        end
                    end
                    corrLo = covLo/(fSd*bSd); % Lower correlation between f & b
                    theta = c/corrLo;
                end

                jpdfLo = 0.5*(fCdf(1)+bCdf(1)-1+abs(fCdf(1)+bCdf(1)-1));
                jpdf = theta.*jpdfLo + (1-theta).*fPdf(1).*bPdf(1);
                if jpdf~=0
                    jointEntropy = real(-jpdf.*log2(jpdf)); % Joint entropy
                end

                % 1-D boundaries
                for i=2:l
                    jpdfLo = 0.5*(fCdf(i)+bCdf(1)-1+abs(fCdf(i)+bCdf(1)-1)) - ...
                        0.5*(fCdf(i-1)+bCdf(1)-1+abs(fCdf(i-1)+bCdf(1)-1));
                    jpdf = theta.*jpdfLo + (1-theta).*fPdf(i).*bPdf(1);
                    if jpdf~=0
                        jointEntropy = jointEntropy + real(-jpdf.*log2(jpdf)); % Joint entropy
                    end
                end
                for j=2:l
                    jpdfLo = 0.5*(fCdf(1)+bCdf(j)-1+abs(fCdf(1)+bCdf(j)-1)) - ...
                        0.5*(fCdf(1)+bCdf(j-1)-1+abs(fCdf(1)+bCdf(j-1)-1));
                    jpdf = theta.*jpdfLo + (1-theta).*fPdf(1).*bPdf(j);
                    if jpdf~=0
                        jointEntropy = jointEntropy + real(-jpdf.*log2(jpdf)); % Joint entropy
                    end
                end
                % 2-D walls
                for i=2:l
                    for j=2:l
                        jpdfLo = 0.5*(fCdf(i)+bCdf(j)-1+abs(fCdf(i)+bCdf(j)-1)) - ...
                            0.5*(fCdf(i-1)+bCdf(j)-1+abs(fCdf(i-1)+bCdf(j)-1)) - ...
                            0.5*(fCdf(i)+bCdf(j-1)-1+abs(fCdf(i)+bCdf(j-1)-1)) + ...
                            0.5*(fCdf(i-1)+bCdf(j-1)-1+abs(fCdf(i-1)+bCdf(j-1)-1));
                        jpdf = theta.*jpdfLo + (1-theta).*fPdf(i).*bPdf(j);
                        if jpdf~=0
                            jointEntropy = jointEntropy + real(-jpdf.*log2(jpdf)); % Joint entropy
                        end
                    end
                end

            end

            % Marginal entropies
            index = find(bPdf~=0);
            bEntropy = sum(-bPdf(index).*log2(bPdf(index)));
            index = find(fPdf~=0);
            fEntropy = sum(-fPdf(index).*log2(fPdf(index)));

            % Mutual information between b & f
            mi = bEntropy + fEntropy - jointEntropy;

            % Overall normalized mutual information
            if mi == 0
                fmi_bf = 0;
            else
                fmi_bf = 2.*mi./(bEntropy+fEntropy);
            end

        end

        fmi_map(p-w,q-w) = (fmi_af + fmi_bf)./2;

    end
end

nfmi = mean2(fmi_map);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function imNorm = rerange(im)

% RERANGE changes the range of images into interval [0,1]

im = double(im);

[m,n] = size(im);

imMax = max(im(:));
imMin = min(im(:));

if imMax == imMin
    imNorm = ones(m,n);
else
    imNorm = (im - imMin)/(imMax - imMin);
end

author: thfylsty


text:
function test_bug1667

% WALLTIME 00:20:00
% MEM 4gb
% DEPENDENCY ft_read_data ft_fetch_data

% Improvements:
% 1-make buffering from multiple sources possible
% 2-if part of the trial is already buffered, only fetch what is needed

datainfo = ref_datasets;

datanr = 13;
datafile1 = fullfile(datainfo(datanr).origdir,'original',datainfo(datanr).type,datainfo(datanr).datatype,'/',datainfo(datanr).filename);
datanr = datanr+1;
datafile2 = fullfile(datainfo(datanr).origdir,'original',datainfo(datanr).type,datainfo(datanr).datatype,'/',datainfo(datanr).filename);
hdr1 = ft_read_header(datafile1);
hdr2 = ft_read_header(datafile2);
% fetch something
tic;
dat1 = ft_read_data(datafile1, 'cache', true, 'begsample', 1, 'endsample', 1000, 'checkboundary', false, 'header', hdr1);
t11 = toc;
tic;
dat2 = ft_read_data(datafile2, 'cache', true, 'begsample', 1, 'endsample', 1000, 'checkboundary', false, 'header', hdr1);
t12 = toc;
% fetch something that is partly overlapping
tic;
dat1 = ft_read_data(datafile1, 'cache', true, 'begsample', 500, 'endsample', 1500, 'checkboundary', false, 'header', hdr1);
t21 = toc;
tic;
dat2 = ft_read_data(datafile2, 'cache', true, 'begsample', 500, 'endsample', 1500, 'checkboundary', false, 'header', hdr1);
t22 = toc;
% fetch something completely else
tic;
dat1 = ft_read_data(datafile1, 'cache', true, 'begsample', 2000, 'endsample', 3000, 'checkboundary', false, 'header', hdr1);
t31 = toc;
tic;
dat2 = ft_read_data(datafile2, 'cache', true, 'begsample', 2000, 'endsample', 3000, 'checkboundary', false, 'header', hdr1);
t32 = toc;

% compare timing, the latter should be way slower, if not ERROR!!!11

author: fieldtrip

repo: fieldtrip

save_path: github-repos/MATLAB/fieldtrip-fieldtrip


text:
classdef MockPluginDependencyTracker < handle
    % MockPluginDependencyTracker. Part of the PTK test framework
    %
    % This class is used in tests in place of a MimPluginDependencyTracker. It
    % allows expected calls to be verified, while maintaining some of the
    % expected behaviour of a MimPluginDependencyTracker object.
    %
    %
    %     Licence
    %     -------
    %     Part of the TD Pulmonary Toolkit. https://github.com/tomdoel/pulmonarytoolkit
    %     Author: Tom Doel, 2012.  www.tomdoel.com
    %     Distributed under the GNU GPL v3 licence. Please see website for details.
    %

    properties
        MockResults
        SavedMockResults
    end

    methods

        function obj = MockPluginDependencyTracker()
            obj.MockResults = containers.Map;
            obj.SavedMockResults = containers.Map;
        end

        function AddMockResult(obj, name, context, dataset_uid, result_to_add, cache_info, has_been_run)
            result = [];
            result.Result = result_to_add;
            result.CacheInfo = cache_info;
            result.HasBeenRun = has_been_run;
            obj.MockResults([name '.' char(context) '.' dataset_uid]) = result;
        end

        function cache_info = GetCacheInfo(obj, plugin_name)
        end

        function [result, plugin_has_been_run, cache_info] = GetResult(obj, plugin_name, context, linked_dataset_chooser, plugin_info, plugin_class, dataset_uid, dataset_stack, memory_cache_policy, disk_cache_policy, reporting)

            key_name = [plugin_name '.' char(context) '.' dataset_uid];

            result_from_cache = obj.MockResults(key_name);
            result = result_from_cache.Result;
            cache_info = result_from_cache.CacheInfo;
            plugin_has_been_run = result_from_cache.HasBeenRun;

        end

        function SaveEditedResult(obj, plugin_name, context, result, dataset_uid, reporting)
            obj.SavedMockResults([plugin_name '.' char(context) '.' dataset_uid]) = result;
        end

        function valid = CheckDependencyValid(obj, next_dependency, reporting)
        end
    end

end

author: tomdoel

repo: pulmonarytoolkit


text:
function P = pu2_encode( L )
% Perceptually uniform luminance encoding using the CSF from HDR-VDP-2
%
% P = pu2_encode( L )
%
% Transforms absolute luminance values L into approximately perceptually
% uniform values P.
%
% This is meant to be used with display-referred quality metrics - the
% image values much correspond to the luminance emitted from the target
% HDR display.
%
% This is an improved encoding described in detail in the paper:
%
% Aydin, T. O., Mantiuk, R., & Seidel, H.-P. (2008). Extending quality
% metrics to full luminance range images. Proceedings of SPIE (p. 68060B–10).
% SPIE. doi:10.1117/12.765095
%
% Note that the P-values can be negative or greater than 255. Most metrics
% can deal with such values.
%
% Copyright (c) 2014, Rafal Mantiuk <mantiuk@gmail.com>

persistent P_lut;
persistent l_lut;

l_min = -5;
l_max = 10;

if( isempty( P_lut ) ) % caching for better performance

    metric_par.csf_sa = [30.162 4.0627 1.6596 0.2712];
    l_lut = linspace( l_min, l_max, 2^12 );
    S = hdrvdp_joint_rod_cone_sens( 10.^l_lut, metric_par );

    [~, P_lut] = build_jndspace_from_S(l_lut,S);
end

l = log10(max(min(L,10^l_max),10^l_min));

pu_l = 31.9270;
pu_h = 149.9244;

P = 255 * (interp1( l_lut, P_lut, l ) - pu_l) / (pu_h-pu_l);

end

function S = hdrvdp_joint_rod_cone_sens( la, metric_par )
% Copyright (c) 2011, Rafal Mantiuk <mantiuk@gmail.com>

% Permission to use, copy, modify, and/or distribute this software for any
% purpose with or without fee is hereby granted, provided that the above
% copyright notice and this permission notice appear in all copies.
%
% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

cvi_sens_drop = metric_par.csf_sa(2); % in the paper - p6
cvi_trans_slope = metric_par.csf_sa(3); % in the paper - p7
cvi_low_slope = metric_par.csf_sa(4); % in the paper - p8

S = metric_par.csf_sa(1) * ( (cvi_sens_drop./la).^cvi_trans_slope+1).^-cvi_low_slope;

end

function [Y jnd] = build_jndspace_from_S(l,S)

L = 10.^l;
dL = zeros(size(L));

for k=1:length(L)
    thr = L(k)/S(k);

    % Different than in the paper because integration is done in the log
    % domain - requires substitution with a Jacobian determinant
    dL(k) = 1/thr * L(k) * log(10);
end

Y = l;
jnd = cumtrapz( l, dL );

end

author: banterle


text:
function [ ntig ] = gsp_norm_tig( G,g, exact,M,param )
%GSP_NORM_TIG Compute the norm of the tig of a frame
%   Usage:  gsp_norm_tig( G,g );
%           gsp_norm_tig( G,g, exact );
%
%   Input parameters:
%       G       : Graph
%       g       : filterbank
%       exact   : Exact method (default 1)
%       M       : Order for the approximation (default 50)
%   Output parameters:
%       ntig    : norm of tig
%
%   This function compute the norm of all atoms of the filterbank g.
%
%   If *exact* is set to one, you can compute the norm chunk by chunk by
%   setting *M* to the size of the desired chunk. If *M* is -1, then
%   parpool is used.
%

% Author: Nathanael Perraudin
% Date  : 22 December 2014
% Tesing: gsp_test_tig

if nargin<3
    exact = 1;
end

if nargin<4
    if exact
        M = G.N;
    else
        M = 50;
    end
end

if nargin<5
    param = struct;
end

if iscell(G)
    NG = length(G);
    ntig = cell(NG,1);
    for ii =1:NG
        ntig{ii} = gsp_norm_tig( G{ii},g{ii}, exact,M ,param);
    end
    return
end

Nf = length(g);
N = G.N;

if exact
    if M == -1
        if isempty(gcp('nocreate'))
            parpool
        end
%         parfor n = 1:N;
%             xin = zeros(N,1);
%             xin(n)= 1;
%             tig = gsp_vec2mat(gsp_filter_analysis(G,g,xin,param),Nf);
%             ntigt = sum(abs(tig).^2);
%             ntig(:,n) = reshape(ntigt,Nf,1);
%         end
        M = abs(M);
        N = ceil(G.N / M); % Chunks of M to save runtime memory.
        ntig = zeros(Nf,G.N);
        ntig2 = zeros(Nf*M,(N-1));
        parfor n = 1:(N-1);
            xin = zeros(G.N,M);
            for ii = 1:M
                xin(ii+(n-1)*M,ii)= 1;
            end
            tig = gsp_vec2mat(gsp_filter_analysis(G,g,xin),Nf);
            ntigt = sum(abs(tig).^2);
            ntig2(:,n) = reshape(ntigt,Nf*M,1);
        end
        for n = 1:(N-1)
            ntig(:,(1:M)+(n-1)*M) = reshape(ntig2(:,n),Nf,M);
        end
        M = G.N - M * (N-1);
        xin = zeros(G.N,M);
        for ii = 1:M
            xin(ii+G.N-M,ii) = 1;
        end
        tig = gsp_vec2mat(gsp_filter_analysis(G,g,xin),Nf);
        ntigt = sum(abs(tig).^2);
        ntig(:,(end-M+1) : end) = reshape(ntigt,Nf,M);
    else
        N = ceil(G.N / M); % Chunks of 1000 to save runtime memory.
        ntig = zeros(Nf,G.N);
        for n = 1:(N-1);
            xin = zeros(G.N,M);
            for ii = 1:M
                xin(ii+(n-1)*M,ii)= 1;
            end
            tig = gsp_vec2mat(gsp_filter_analysis(G,g,xin,param),Nf);
            ntigt = sum(abs(tig).^2);
            ntig(:,(1:M)+(n-1)*M) = reshape(ntigt,Nf,M);
        end
        M = G.N - M * (N-1);
        xin = zeros(G.N,M);
        for ii = 1:M
            xin(ii+G.N-M,ii) = 1;
        end
        tig = gsp_vec2mat(gsp_filter_analysis(G,g,xin,param),Nf);
        ntigt = sum(abs(tig).^2);
        ntig(:,(end-M+1) : end) = reshape(ntigt,Nf,M);
    end

    ntig = ntig';
else
    WN = sign(randn(N,M));
    filter_WN = gsp_vec2mat(gsp_filter_analysis(G,g,WN,param),Nf);
    ntig = sum(abs(filter_WN).^2,3)/M;
end

ntig = sqrt(ntig);
end

repo: gspbox


text:
function loadmovz()

    report_this_filefun();

    [file1,path1] = uigetfile(['*.mat'],'Moviefile');

    if length(path1) > 1
        load([path1 file1])
        showmovi
    end   % if exist

end

author: CelsoReyes


text:
function [VW, sptHist] = LMdenseVisualWords(D, HOMEIMAGES, VWparam)
%
% Compute dense visual words and spatial pyramid histogram.
%
% The SIFT grid + visual words will be defined by the parameters VWparam:
%   VWparam.imagesize = 256; % normalized image size (images will be scaled so that the maximal axis has this dimension before computing the sift features)
%   VWparam.grid_spacing = 1; % distance between grid centers
%   VWparam.patch_size = 16; % size of patch from which to compute SIFT descriptor (it has to be a factor of 4)
%   VWparam.NumVisualWords = 200; % number of visual words
%   VWparam.Mw = 2; % number of spatial scales for spatial pyramid histogram
%
% Run demoVisualWords.m to see an example of how it works.
%
% The SIFT descriptor at each location has 128 dimensions and is vector quantized.
%
% This function can be called as:
%
% [VW, sptHist] = LMdenseVisualWords(img, HOMEIMAGES, param);
% [VW, sptHist] = LMdenseVisualWords(D(n), HOMEIMAGES, param);
% [VW, sptHist] = LMdenseVisualWords(filename, HOMEIMAGES, param);
%
%
% Antonio Torralba, 2008

if ~isfield(VWparam, 'descriptor')
    VWparam.descriptor = 'sift';
end

if isfield(VWparam, 'imageSize')
    VWparam.imagesize = VWparam.imageSize;
end

if isfield(VWparam, 'storewords')
    storewords = VWparam.storewords;
else
    storewords = 1;
end

if isfield(VWparam, 'imagesize')
    if length(VWparam.imagesize)==1
        VWparam.imagesize = [1 1]*VWparam.imagesize;
    end
end

if nargin==4
    precomputed = 1;
    % get list of folders and create non-existing ones
    %listoffolders = {D(:).annotation.folder};
else
    precomputed = 0;
    HOMESIFT = '';
end

if nargin<3
    % Default parameters
    VWparam.grid_spacing = 1; % distance between grid centers
    VWparam.patch_size = 16; % size of patch from which to compute SIFT descriptor (it has to be a factor of 4)
end

switch VWparam.descriptor
    case 'sift'
        Nfeatures = 128;
        w = VWparam.patch_size-2; % boundary for SIFT
    case 'hog'
        Nfeatures = 124;
        w = floor(VWparam.patch_size/2*2.5)*2; % boundary for HOG
end

if isstruct(D)
    % [gist, param] = LMdenseVisualWords(D, HOMEIMAGES, param);
    Nscenes = length(D);
    typeD = 1;
end
if iscell(D)
    % [gist, param] = LMdenseVisualWords(filename, HOMEIMAGES, param);
    Nscenes = length(D);
    typeD = 2;
end
if isnumeric(D)
    % [gist, param] = LMdenseVisualWords(img, HOMEIMAGES, param);
    Nscenes = size(D,4);
    typeD = 3;
end

if Nscenes >1
    fig = figure;
end

% Loop: Compute visual words for all scenes
if storewords==1
    if isfield(VWparam, 'imagesize')
        n = VWparam.imagesize(1)-w;
        m = VWparam.imagesize(2)-w;
    else
        % read one image to check size. This will only work if all the images
        % have the same size
        switch typeD
            case 1
                img = LMimread(D, 1, HOMEIMAGES);
            case 2
                img = imread(fullfile(HOMEIMAGES, D{1}));
            case 3
                img = D(:,:,:,1);
        end
        n = size(img,1)-w;
        m = size(img,2)-w;
    end

    if VWparam.NumVisualWords<256
        VW = zeros([n m Nscenes], 'uint8');
    else
        VW = zeros([n m Nscenes], 'uint16');
    end
else
    VW= [];
end

sptHist = zeros([VWparam.NumVisualWords*((4^VWparam.Mw-1)/3) Nscenes], 'single');
for n = 1:Nscenes
    g = [];
    todo = 1;
    % otherwise compute gist
    if todo==1
        if Nscenes>1
            disp([n Nscenes])
        end

        % load image
        try
            switch typeD
                case 1
                    img = LMimread(D, n, HOMEIMAGES);
                case 2
                    img = imread(fullfile(HOMEIMAGES, D{n}));
                case 3
                    img = D(:,:,:,n);
            end
        catch
            disp(D(n).annotation.folder)
            disp(D(n).annotation.filename)
            rethrow(lasterror)
        end

        % Reshape image to standard format
        if isfield(VWparam, 'imagesize')
            img = imresizecrop(img, VWparam.imagesize, 'bilinear');
        end

        %M = max(size(img,1), size(img,2));
        %if M~=VWparam.imagesize
        %    img = imresize(img, VWparam.imagesize/M, 'bilinear');
        %end

        % get  descriptors
        switch VWparam.descriptor
            case 'sift'
                v = LMdenseSift(img, HOMEIMAGES, VWparam);
            case 'hog'
                v = dense_hog2x2(img, VWparam);

        end

        %sift = single(LMdenseSift(img, HOMEIMAGES, VWparam));
        [nrows ncols nf] = size(v);
        v = reshape(v, [size(v,1)*size(v,2) Nfeatures]);

        % vector quantization
        [fitd, w] = min(distMat(single(VWparam.visualwordcenters), v));
        w = reshape(w, [nrows ncols]);

        if storewords==1
            if VWparam.NumVisualWords<256
                VW(:,:,n) = uint8(w);
            else
                VW(:,:,n) = uint16(w);
            end
        end

        % Compute spatial histogram
        sptHist(:,n) = single(spatialHistogram(w, VWparam.Mw, VWparam.NumVisualWords));

        if Nscenes >1
            figure(fig);
            subplot(121)
            imshow(uint8(img))
            subplot(122)
            imagesc(w)
            axis('equal')
            axis('off')
        end
    end

    drawnow
end

function D=distMat(P1, P2)
%
% Euclidian distances between vectors

if nargin == 2
    X1=repmat(single(sum(P1.^2,2)),[1 size(P2,1)]);
    X2=repmat(single(sum(P2.^2,2)),[1 size(P1,1)]);
    R=P1*P2';
    D=X1+X2'-2*R;
else
    % each vector is one column
    X1=repmat(sum(P1.^2,1),[size(P1,2) 1]);
    R=P1'*P1;
    D=X1+X1'-2*R;
    D = sqrt(D);
end

function h = spatialHistogram(W, Mw, Nwords)
% Mw = number of spatial windows for computing histograms
coef = 1./[2^(Mw-1) 2.^(Mw-(1:(Mw-1)))];

h = [];
for M = 1:Mw
    lx = round(linspace(1, size(W,2)-1, 2^(M-1)+1));
    ly = round(linspace(1, size(W,1)-1, 2^(M-1)+1));
    for x = 1:2^(M-1)
        for y = 1:2^(M-1)
            ww = W(ly(y)+1:ly(y+1), lx(x)+1:lx(x+1));
            hh = hist(ww(:), 1:Nwords);
            h = [h coef(M)*hh];
        end
    end
end

% store words
h = h /sum(h);

author: CSAILVision

repo: LabelMeToolbox


text:
function [ W, confidences, d ] = mergeBestIOU( W, confidences, mergeThreshold, d )

    % Get most similar windows
    if(isempty(d))
        d = squareform(pdist(W, @IOU));
    end
    [v, p] = max(d);
    [v2, p2] = max(v);

    % Only keep merge if their IoU >= mergeThreshold
    if(size(W,1) > 1 && v2 >= mergeThreshold)
        w1 = W(p(p2),:);
        w2 = W(p2,:);

        % Create merged window
        w_new = mean([w1; w2]);
        conf_new = mean([confidences(p(p2)) confidences(p2)]);

        % Remove old windows
        W([p(p2), p2],:) = [];
        confidences([p(p2) p2]) = [];

        % Remove old windows' distances
        d([p(p2) p2],:) = [];
        d(:,[p(p2) p2]) = [];

        % Calculate distances to new window and insert
        d_new = pdist2(w_new, W, @IOU);
        d(:,end+1) = d_new';
        d(end+1,:) = [d_new 0];
        W(end+1,:) = w_new;
        confidences(end+1) = conf_new;
    end

end

author: zhangqianqianQQ

repo: MachineVisionAlgorithm


text:
function mpc = ex_case3b
%EX_CASE3B  Three bus example system for stochastic unit commitment.
%   Same as EX_CASE3A with the following changes:
%       - Non-zero PMIN values for generators
%       - Linear (vs quadratic) generator costs
%       - Includes some STARTUP and SHUTDOWN costs
%   Please see CASEFORMAT for details on the case file format.

%   MOST
%   Copyright (c) 2015-2016, Power Systems Engineering Research Center (PSERC)
%   by Ray Zimmerman, PSERC Cornell
%
%   This file is part of MOST.
%   Covered by the 3-clause BSD License (see LICENSE file for details).
%   See https://github.com/MATPOWER/most for more info.

%% MATPOWER Case Format : Version 2
mpc.version = '2';

%%-----  Power Flow Data  -----%%
%% system MVA base
mpc.baseMVA = 100;

%% bus data
%	bus_i	type	Pd	Qd	Gs	Bs	area	Vm	Va	baseKV	zone	Vmax	Vmin
mpc.bus = [
	1	3	0	0	0	0	1	1	0	135	1	1.05	0.95;
	2	2	0	0	0	0	1	1	0	135	1	1.05	0.95;
	3	2	0	0	0	0	1	1	0	135	1	1.05	0.95;
];

%% generator data
%	bus	Pg	Qg	Qmax	Qmin	Vg	mBase	status	Pmax	Pmin	Pc1	Pc2	Qc1min	Qc1max	Qc2min	Qc2max	ramp_agc	ramp_10	ramp_30	ramp_q	apf
mpc.gen = [
	1	125	0	25	-25	1	100	1	200	60	0	0	0	0	0	0	0	250	250	0	0;
	1	125	0	25	-25	1	100	1	200	65	0	0	0	0	0	0	0	250	250	0	0;
	2	200	0	50	-50	1	100	1	500	60	0	0	0	0	0	0	0	600	600	0	0;
	3	-450	0	0	0	1	100	1	0	-450	0	0	0	0	0	0	0	500	500	0	0;
];

%% branch data
%	fbus	tbus	r	x	b	rateA	rateB	rateC	ratio	angle	status	angmin	angmax
mpc.branch = [
	1	2	0.005	0.01	0	300	300	300	0	0	1	-360	360;
	1	3	0.005	0.01	0	240	240	240	0	0	1	-360	360;
	2	3	0.005	0.01	0	300	300	300	0	0	1	-360	360;
];

%%-----  OPF Data  -----%%
%% generator cost data
%	1	startup	shutdown	n	x1	y1	...	xn	yn
%	2	startup	shutdown	n	c(n-1)	...	c0
mpc.gencost = [
	2	0	0	2	25	0;
	2	200	200	2	30	0;
	2	3000	600	2	40	0;
	2	0	0	2	1000	0;
];

%%-----  Reserve Data  -----%%
%% reserve zones, element i, j is 1 if gen j is in zone i, 0 otherwise
mpc.reserves.zones = [
	1	1	1	0;
];

%% reserve requirements for each zone in MW
mpc.reserves.req   = 150;

%% reserve costs in $/MW for each gen that belongs to at least 1 zone
%% (same order as gens, but skipping any gen that does not belong to any zone)
% mpc.reserves.cost  = [	5;	5;	21;	];
% mpc.reserves.cost  = [	5;	5;	16.25;	];
% mpc.reserves.cost  = [	0;	0;	11.25;	];
mpc.reserves.cost  = [	1;	3;	5;	];

%% OPTIONAL max reserve quantities for each gen that belongs to at least 1 zone
%% (same order as gens, but skipping any gen that does not belong to any zone)
mpc.reserves.qty   = [	100;	100;	200;	];

author: MATPOWER

repo: matpower

save_path: github-repos/MATLAB/MATPOWER-matpower


text:
clear all
        % Desemnarea variabilei x ca si simbolica
x=sym('x');
		% Incarcarea functiei de integrat
F=1/x
        % Calcularea integralei nedefinite
I1=int(F)
        % Calcularea integralei definite intre limitele 1 si 2
I2=int(F,1,2)


text:
function [g_phi1,g_Phi,g_phi2] = grad_phi(odf,ori)
% discrete derivatives with respect to Euler angles

[phi1,Phi,phi2] = Euler(ori,'nfft');

delta = 0.05 * degree;
ori = orientation.byEuler(phi1 + [-1 1] * delta,Phi,phi2,ori.CS,'nfft');

g_phi1 = diff(odf.eval(ori))/delta/2;

ori = orientation.byEuler(phi1,Phi + [-1 1] * delta,phi2,ori.CS,'nfft');

g_Phi = diff(odf.eval(ori))/delta/2;

ori = orientation.byEuler(phi1,Phi,phi2 + [-1 1] * delta,ori.CS,'nfft');

g_phi2 = diff(odf.eval(ori))/delta/2;

author: mtex-toolbox

repo: mtex

save_path: github-repos/MATLAB/mtex-toolbox-mtex


text:
function p = propagate_upforce(p)

% Find inconsistency of y <= x1 + x2 + ...
if p.feasible
    for i = 1:length(p.upForce)
        forcing = p.upForce{i}.forcing;
        if p.lb(forcing)==1
            forced = p.upForce{i}.forced;
            if all(p.ub(forced)==0)
                p.feasible = 0;
                return
            end
        end
    end
end

author: yalmip

repo: YALMIP

save_path: github-repos/MATLAB/yalmip-YALMIP


text:
%
%  fft wrt the center of the array, instead of the first sample
%

%  written by John Pauly, 1992
%  (c) Board of Trustees, Leland Stanford Junior University

function y=fftc(x)

y = fftshift(fft(fftshift(x)));

author: leoliuf

repo: MRiLab

save_path: github-repos/MATLAB/leoliuf-MRiLab


text:
%BrickIO Abstract class definition for brick input output
%
% Methods::
%  open         Open the connection to the brick
%  close        Close the connection to the brick
%  read         Read data from the brick
%  write        Write data to the brick
%
% Notes::
% - handle is the connection object
% - The read function should return a uint8 datatype
% - The write function should be given a uint8 datatype as a parameter

classdef BrickIO
    properties (Abstract)
        % connection handle
        handle
    end

    methods (Abstract)
        % open the brick connection
        open(BrickIO)
        % close the brick connection
        close(BrickIO)
        % read data from the brick
        read(BrickIO)
        % write data to the brick
        write(BrickIO)
    end
end

author: petercorke

repo: robotics-toolbox-matlab


text:
function [points1, points2] = get_uniform_points_boundary(ellipse1, ellipse2, nr_points)
% GET_UNIFORM_POINTS_BOUNDARY gives the sets of points that are
% equidistantly chosen on the boudary of two ellipses, so that future OSPA
% could be calculated
%
% Input:
%        ellipse1, 1x5, parameterization of one ellispe [m1 m2 alpha l1 l2]
%        ellipse2, 1x5, parameterization of the other ellispe [m1 m2 alpha l1 l2]
%        nr_points, nr of points that are uniformly chosen on the boundary
%                   to calculate OPSA distance
% Output:
%       points1, 2xnr_points, points that are chosen on the ellipse1
%       poitns2, 2xnr_points, points that are chosen on the ellispe2
% Written by Shishan Yang

theta = (0:2*pi/nr_points:2*pi-2*pi/nr_points);

alpha1 = ellipse1(3);
center1 = ellipse1(1:2)';
l1 = ellipse1(4:5);
gt_rotation_mat = [cos(alpha1) -sin(alpha1); sin(alpha1) cos(alpha1)];
points1(1,:) = l1(1)*cos(theta);
points1(2,:) = l1(2)*sin(theta);

alpha2 = ellipse2(3);
center2 = ellipse2(1:2)';
l2 = ellipse2(4:5);
est_rotation_mat = [cos(alpha2) -sin(alpha2); sin(alpha2) cos(alpha2)];
points2(1,:) = l2(1)*cos(theta);
points2(2,:) = l2(2)*sin(theta);

points1 = gt_rotation_mat*points1 + repmat(center1,1,size(points1,2));
points2 = est_rotation_mat*points2 + repmat(center2,1,size(points2,2));
end

author: Fusion-Goettingen

repo: ExtendedObjectTracking


text:
peval.path_res = [cd '/'];
peval.path_data = '~/project/data/qdots/S44/';

peval.ncomp = 2; %number of components without the background component....

savethis = 1;
winit_pix = [];
hinit = [];
[res, peval] = separcomp(dpixc, peval, winit_pix, hinit);
if savethis == 1
    saveresults(res, peval, p, peval.namefile_res)
    peval.dir_res = [peval.path_res peval.namedir_data];
    writedata([],[],peval,[peval.dir_res '/' peval.namefile_res '_param_eval'])
    writedata([],[],p,[peval.dir_res '/' peval.namefile_res '_param_simul'])
end

author: aludnam

repo: MATLAB

save_path: github-repos/MATLAB/aludnam-MATLAB


text:
function startup()
% startup()
% --------------------------------------------------------
% Faster R-CNN
% Copyright (c) 2015, Shaoqing Ren
% Licensed under The MIT License [see LICENSE for details]
% --------------------------------------------------------

    curdir = fileparts(mfilename('fullpath'));
    addpath(genpath(fullfile(curdir, 'utils')));
    addpath(genpath(fullfile(curdir, 'functions')));
    addpath(genpath(fullfile(curdir, 'bin')));
    addpath(genpath(fullfile(curdir, 'experiments')));
    addpath(genpath(fullfile(curdir, 'imdb')));

    mkdir_if_missing(fullfile(curdir, 'datasets'));

    mkdir_if_missing(fullfile(curdir, 'external'));

    caffe_path = fullfile(curdir, 'external', 'caffe', 'matlab');
    if exist(caffe_path, 'dir') == 0
        error('matcaffe is missing from external/caffe/matlab; See README.md');
    end
    addpath(genpath(caffe_path));

    mkdir_if_missing(fullfile(curdir, 'imdb', 'cache'));

    mkdir_if_missing(fullfile(curdir, 'output'));

    mkdir_if_missing(fullfile(curdir, 'models'));

    fprintf('fast_rcnn startup done\n');
end

author: ShaoqingRen