text:
function [sigma,mu,A]=mygaussfit(x,y,h)

%
% [sigma,mu,A]=mygaussfit(x,y)
% [sigma,mu,A]=mygaussfit(x,y,h)
%
% this function is doing fit to the function
% y=A * exp( -(x-mu)^2 / (2*sigma^2) )
%
% the fitting is been done by a polyfit
% the lan of the data.
%
% h is the threshold which is the fraction
% from the maximum y height that the data
% is been taken from.
% h should be a number between 0-1.
% if h have not been taken it is set to be 0.2
% as default.
%

%% threshold
if nargin==2, h=0.2; end

%% cutting
ymax=max(y);
xnew=[];
ynew=[];
for n=1:length(x)
    if y(n)>ymax*h;
        xnew=[xnew,x(n)];
        ynew=[ynew,y(n)];
    end
end

%% fitting
ylog=log(ynew);
xlog=xnew;
p=polyfit(xlog,ylog,2);
A2=p(1);
A1=p(2);
A0=p(3);
sigma=sqrt(-1/(2*A2));
mu=A1*sigma^2;
A=exp(A0+mu^2/(2*sigma^2));

author: Sable

repo: mcbench-benchmarks


text:
function res = innerprod( x, y, dir, upto )
    %INNERPROD Inner product between two TT/MPS tensors.
    %   innerprod(X,Y) computes the inner product between the TT/MPS tensors X and Y.
    %   Assumes that the first rank of both tensors, X.rank(1) and Y.rank(1), is 1.
    %   The last rank may be different from 1, resulting in a matrix of size
    %   [X.rank(end), Y.rank(end)].
    %
    %   See also NORM

    %   TTeMPS Toolbox.
    %   Michael Steinlechner, 2013-2016
    %   Questions and contact: michael.steinlechner@epfl.ch
    %   BSD 2-clause license, see LICENSE.txt

    if ~exist( 'dir', 'var' )
        dir = 'LR';
    end
    if ~exist( 'upto', 'var' )
        if strcmpi( dir, 'LR')
            upto = x.order;
        else
            upto = 1;
        end
    end

    % Left-to-Right procedure
    if strcmpi( dir, 'LR')

        res = unfold( x.U{1}, 'left')' * unfold( y.U{1}, 'left');

        for i = 2:upto
            tmp = tensorprod_ttemps( x.U{i}, res', 1);
            res = unfold( tmp, 'left')' * unfold( y.U{i}, 'left');
        end

    % Right-to-Left procedure
    elseif strcmpi( dir, 'RL')
        d = x.order;
        res = conj(unfold( x.U{d}, 'right')) * unfold( y.U{d}, 'right').';

        for i = d-1:-1:upto
            tmp = tensorprod_ttemps( x.U{i}, res', 3);
            res = conj(unfold( tmp, 'right')) * unfold( y.U{i}, 'right').';
        end

    else
        error('Unknown direction specified. Choose either LR (default) or RL')
    end

end

author: NicolasBoumal

repo: manopt


text:
function a = i4_to_a ( i )

%*****************************************************************************80
%
%% I4_TO_A returns the I-th alphabetic character.
%
%  Example:
%
%    I   A
%
%   -8  ' '
%    0  ' '
%    1  'A'
%    2  'B'
%   ..
%   26  'Z'
%   27  'a'
%   52  'z'
%   53  ' '
%   99  ' '
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    22 February 2010
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, integer I, the index of the letter to be returned.
%    0 is a space;
%    1 through 26 requests 'A' through 'Z', (ASCII 65:90);
%    27 through 52 requests 'a' through 'z', (ASCII 97:122);
%
%    Output, character A, the requested alphabetic letter.
%
  if ( i <= 0 )
    a = ' ';
  elseif ( 1 <= i && i <= 26 )
    a = char ( 'A' + i - 1 );
  elseif ( 27 <= i && i <= 52 )
    a = char ( 'a' + i - 27 );
  else
    a = ' ';
  end

  return
end

author: johannesgerer

repo: jburkardt-m


text:
function flag = validateTheta_homography(X, Theta, s)

% flag = validateMSS_homography(X, Theta, s)
%
% DESC:
% Validates the parameter vector
%
% INPUT:
% X                 = samples on the manifold
% Theta             = parameter vector
% s                 = indices of the MSS
%
% OUTPUT:
% flag              = true if the MSS is valid

% condition number threshold
T_K = 1e12;

% perform here the check on the parameter vector Theta
H = reshape(Theta, 3, 3);
K = cond(H);

if (K > T_K)
    flag = false;
else
    flag = true;
end;

return

author: RANSAC

repo: RANSAC-Toolbox


text:
function plot_branch_segmentation(P,cover,segment,Color,fig,ms,segind,BO)

% ---------------------------------------------------------------------
% PLOT_BRANCH_SEGMENTATION.M   Plots branch-segmented point cloud, coloring
%                               based on branching order or branches
%
% Version 1.0.0
% Latest update     13 July 2020
%
% Copyright (C) 2013-2020 Pasi Raumonen
% ---------------------------------------------------------------------
%
% If the coloring is based on branches (Color = 'branch'), then each segment
% is colored with unique color. If the coloring is based on branching order
% (Color = 'order'), then Blue = trunk, Green = 1st-order branches,
% Red = 2nd-order branches, etc.
%
% If segind = 1 and BO = 0, then plots the stem. If segind = 1 and BO = 1,
% then plots the stem and the 1st-order branches. If segind = 1 and
% BO >= maximum branching order or BO input is not given, then plots the
% whole tree. If segind = 2 and BO is not given or it is high enough, then
% plots the branch whose index is 2 and all its sub-branches.
%
% Inputs
% P         Point cloud
% cover     Cover sets structure
% segment   Segments structure
% Color     Color option, 'order' or 'branch'
% fig       Figure number
% ms        Marker size
% segind    Index of the segment where the plotting of tree structure starts.
% BO        How many branching orders are plotted. 0 = stem, 1 = 1st order, etc

n = nargin;
if n < 8
    BO = 1000;
    if n < 7
        segind = 1;
        if n < 6
            ms = 1;
            if n < 5
                fig = 1;
                if n == 3
                    Color = 'order';
                end
            end
        end
    end
end

Bal = cover.ball;
Segs = segment.segments;
SChi = segment.ChildSegment;
SPar = segment.ParentSegment;
ns = max(size(Segs));

if iscell(Segs{1})
    Seg = cell(ns,1);
    for i = 1:ns
        m = size(Segs{i},1);
        S = zeros(0);
        for j = 1:m
            s = Segs{i}(j);
            s = s{:};
            S = [S; s];
        end
        Seg{i} = S;
    end
else
    Seg = Segs;
end

if strcmp(Color,'branch')
    Color = 1;
    % Color the segments with unique colors
    col = rand(ns,3);
    for i = 2:ns
        C = col(SPar(i),:);
        c = col(i,:);
        while sum(abs(C-c)) < 0.2
            c = rand(1,3);
        end
        col(i,:) = c;
    end
elseif strcmp(Color,'order')
    Color = 0;
    % Color the cylinders in branches based on the branch order
    col = [
        0.00  0.00  1.00
        0.00  0.50  0.00
        1.00  0.00  0.00
        0.00  0.75  0.75
        0.75  0.00  0.75
        0.75  0.75  0.00
        0.25  0.25  0.25
        0.75  0.25  0.25
        0.95  0.95  0.00
        0.25  0.25  0.75
        0.75  0.75  0.75
        0.00  1.00  0.00
        0.76  0.57  0.17
        0.54  0.63  0.22
        0.34  0.57  0.92
        1.00  0.10  0.60
        0.88  0.75  0.73
        0.10  0.49  0.47
        0.66  0.34  0.65
        0.99  0.41  0.23];
    col = repmat(col,[10,1]);
end

segments = segind;
C = SChi{segind};
b = 1;
order = 1;
while ~isempty(C) && b <= BO
    b = b+1;
    segments = [segments; C];
    order = [order; b*ones(length(C),1)];
    C = vertcat(SChi{C});
end

ns = length(segments);
figure(fig)
for i = 1:ns
    if i == 2
        hold on
    end
    S = vertcat(Bal{Seg{segments(i)}});
    if Color
    % Coloring based on branch
    plot3(P(S,1),P(S,2),P(S,3),'.','Color',col(segments(i),:),'Markersize',ms)
    else
    % Coloring based on branch order
    plot3(P(S,1),P(S,2),P(S,3),'.','Color',col(order(i),:),'Markersize',ms)
    end
end
hold off
axis equal

author: InverseTampere

repo: TreeQSM


text:
function v = cvx_value( x )
v = value( x );

% Copyright 2010 Michael C. Grant and Stephen P. Boyd.
% See the file COPYING.txt for full copyright information.
% The command 'cvx_where' will show where this file is located.

repo: REST