### Several new additions. rho_t.m calculates the circular correlation coefficient...

`Several new additions. rho_t.m calculates the circular correlation coefficient from Fisher and Lee (1983). genopt.m is a general optimisation routine using a genetic algorythm. seabirdCTD.m is designed to be a low fuss reader for seabird .cnv files.`
parent cc34cf0a
math/genopt.m 0 → 100644
 function MOM = genopt(Q,X,dom,NP,NI,pc,pm) % Synthax: MOM = genopt(@Q,@X,dom,NP,NI,pc,pm) % % Optimisation routine following a genetic algorithm. Returns the best parameter % set which solves the problem expressed by the anonymous function 'Q', when % either the criteria expressed by the anonymous function 'X' has been met or % NI iterations have been completed. 'X' should be formulated in terms of the % values returned by 'Q'. The 'dom' variable is a matrix of size [p 2], where % p is the number of parameters passed to the function 'Q'. It's rows are the % domains from which the initial population will be generated for each parameter. % Variable 'NP' is the size of the population and must be an even number. Variables % 'pc' and 'pm' are respectively the probability of mixing genetic material and % probability of mutation. Recommended values are 0.8 and 0.2 . %INIT POPULATION NA = numel(dom(:,1)) ; PP = nan(NP,NA) ; SC = nan(NP,1) ; RK = nan(NP,1) ; for ii = 1:NP for jj = 1:NA PP(ii,jj) = dom(jj,1) + (dom(jj,2)-dom(jj,1))*rand(1) ; end end for kk = 1:NI %EVALUATION for ii = 1:NP ; SC(ii) = Q(PP(ii,:)) ; end %RANKING [HS,RK] = sort(SC) ; PP = PP(RK,:) ; %TEST if X(HS(1)) ; break; end %SELECTION DICE = randi([2 4]) ; MOM = PP(1, :) ; DAD = PP(DICE,:) ; %REPRODUCTION PP(1,:) = MOM ; PP(2,:) = DAD ; for ii = 3:2:NP for jj = 1:NA % CROISEMENT if rand(1) < pc DICE = rand(1) ; PP(ii,jj) = MOM(jj)*DICE + DAD(jj)*(1-DICE) ; PP(ii+1,jj) = DAD(jj)*DICE + MOM(jj)*(1-DICE) ; else PP(ii,jj) = MOM(jj) ; PP(ii+1,jj) = DAD(jj) ; end % MUTATION if rand(1) < pm PP(ii,jj) = dom(jj,1) + (dom(jj,2)-dom(jj,1))*rand(1) ; end end end end end
 ... ... @@ -27,6 +27,7 @@ elseif sz(1) == 1 & sz(2) > 1 | sz(2) == 1 & sz(1) > 1 start = pars ; end % Minimize parameters A = fminsearch(@(a)sum( (y - rhs(a,x,varargin{:})).^2 ),start) ; yfit = rhs(A,x,varargin{:}) ; ... ...
math/rho_t.m 0 → 100644
 function [rho] = rho_t(x,y,degrad) % [rho] = rho_t(x,y,degrad) % % Explicitly calculates the correlation coefficient rho_t detailed in % Fisher and Lee (1983), between the two circular variables 'x' and 'y'. % Variable 'degrad' is a string and should be "deg" if 'x' and 'y' are % in degrees or 'rad' if they are in radians. % % Reference: Fisher, N.I., LEE, A.J.,(1983), A correlation coefficient % for circular data, Biometrika, 70, 2, pp. 327-32 numerator = 0 ; denA = 0 ; denB = 0 ; switch degrad case 'deg' x = x*pi/180 ; y = -y*pi/180 ; case 'rad' % do nothing end for ii = 1:numel(x)-1 numerator = numerator + sum( sin(x(ii)-x(ii+1:end)).*sin(y(ii)-y(ii+1:end)) ) ; denA = denA + sum( sin(x(ii)-x(ii+1:end)).^2 ); denB = denB + sum( sin(y(ii)-y(ii+1:end)).^2 ) ; end rho = numerator./( sqrt(denA).*sqrt(denB) ) ; end
 ... ... @@ -179,7 +179,7 @@ z = movmean(A{:,Iz},10/sr) ; if startsWith(showz,'y'); figure; plot(dnum,z,'b'); hold on; end dz = gradient(z,dnum*24*3600) ; % compute downward velocity z( [1:nvalues]' < warmup/sr | dz<=0.001 ) = nan ; % get rid of start and end values z( [1:nvalues]' < warmup/sr | dz<=0.005 ) = nan ; % get rid of start and end values [~,Im] = min(z) ; % find min depth [~,IM] = max(z) ; % find max depth I = find(dz > dzthres & [1:nvalues]' > Im & [1:nvalues]' < IM) ; % select down-going between min z and max z ... ...
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!