diff --git a/S10_penalty_postprocess.asv b/S10_penalty_postprocess.asv index 03b89cf9f88222707b40313f4350c0c1abe1632d..c80879ca2129bbde808836a3ffcbeb9477a8285c 100644 --- a/S10_penalty_postprocess.asv +++ b/S10_penalty_postprocess.asv @@ -147,7 +147,7 @@ for i = 1:10%length(fields_) seldata.(fields_{i}).avg_z_sm,'Color',[178/255 34/255 34/255],... 'LineWidth',1) plot(seldata.(fields_{i}).numtime-min(seldata.(fields_{i}).numtime),... - seldata.(fields_{i}).islying*2.3,'Color',[0/255 0/255 128/255],... + seldata.(fields_{i}).islying*(-2.3)+2.3,'Color',[0/255 0/255 128/255],... 'LineWidth',2) subplot(2,1,2); hold on;box on; title('Center distance',... 'Interpreter','none'); @@ -156,7 +156,7 @@ for i = 1:10%length(fields_) seldata.(fields_{i}).centerdist,'Color',[178/255 34/255 34/255],... 'LineWidth',1) plot(seldata.(fields_{i}).numtime-min(seldata.(fields_{i}).numtime),... - seldata.(fields_{i}).islying*13,'Color',[0/255 0/255 128/255],... + seldata.(fields_{i}).islying*(-13)+13,'Color',[0/255 0/255 128/255],... 'LineWidth',2) end @@ -329,4 +329,38 @@ end figure('Units','centimeters','OuterPosition',[4 1 28 20]); subplot(2,3,1); plot(cpsums.nochanges,cpsums.ZmeanDif,'o','Color',[102/255 0 51/255],... 'MarkerSize',6,'LineWidth',1.5) - \ No newline at end of file +subplot(2,3,2); plot(cpsums.nochanges,cpsums.ZstdDif,'o','Color',[102/255 0 51/255],... + 'MarkerSize',6,'LineWidth',1.5) +subplot(2,3,3); plot(cpsums.nochanges,cpsums.ZrmsDif,'o','Color',[102/255 0 51/255],... + 'MarkerSize',6,'LineWidth',1.5) +subplot(2,3,4); plot(cpsums.nochanges,cpsums.CDmeanDif,'o','Color',[102/255 0 51/255],... + 'MarkerSize',6,'LineWidth',1.5) +subplot(2,3,5); plot(cpsums.nochanges,cpsums.CDstdDif,'o','Color',[102/255 0 51/255],... + 'MarkerSize',6,'LineWidth',1.5) +subplot(2,3,6); plot(cpsums.nochanges,cpsums.CDrmsDif,'o','Color',[102/255 0 51/255],... + 'MarkerSize',6,'LineWidth',1.5) + + +% try a different approach based on a moving STD window of 30 minutes +tic +ind = find(~isnan(seldata.cow_99.avg_z_sm)); +n = length(ind); +x = seldata.cow_99.avg_z_sm(ind); +test = movsum(30*60*log(movvar(x,30*60)),30*60); +toc +figure; +plot(test) +sum(n*log(var(x,1,2))); + +[~,b] = findchangepts(x,'Statistic','std','MinThreshold',100000000000) + + +figure, +findchangepts(x,'Statistic','std','MinThreshold',abs(b)*0.05, 'MinDistance',600) +figure, +findchangepts(x,'Statistic','std','MaxNumChanges',20, 'MinDistance',600) + + +% for "mean" ==> residue = n*sum(var(x,1,2)); +% for "std" ==> residue = sum(n*log(var(x,1,2))); +% for "rms" ==> residue = sum(n*log(sum(x.^2,2)/n)); \ No newline at end of file diff --git a/S10_penalty_postprocess.m b/S10_penalty_postprocess.m index 1640fb5fb01cddb59cfc72da664869f7ddbf3e1e..445e5bdc5ef493cc2a57e2a17115d6ff12713a3e 100644 --- a/S10_penalty_postprocess.m +++ b/S10_penalty_postprocess.m @@ -147,7 +147,7 @@ for i = 1:10%length(fields_) seldata.(fields_{i}).avg_z_sm,'Color',[178/255 34/255 34/255],... 'LineWidth',1) plot(seldata.(fields_{i}).numtime-min(seldata.(fields_{i}).numtime),... - seldata.(fields_{i}).islying*2.3,'Color',[0/255 0/255 128/255],... + seldata.(fields_{i}).islying*(-2.3)+2.3,'Color',[0/255 0/255 128/255],... 'LineWidth',2) subplot(2,1,2); hold on;box on; title('Center distance',... 'Interpreter','none'); @@ -156,7 +156,7 @@ for i = 1:10%length(fields_) seldata.(fields_{i}).centerdist,'Color',[178/255 34/255 34/255],... 'LineWidth',1) plot(seldata.(fields_{i}).numtime-min(seldata.(fields_{i}).numtime),... - seldata.(fields_{i}).islying*13,'Color',[0/255 0/255 128/255],... + seldata.(fields_{i}).islying*(-13)+13,'Color',[0/255 0/255 128/255],... 'LineWidth',2) end @@ -338,4 +338,29 @@ subplot(2,3,4); plot(cpsums.nochanges,cpsums.CDmeanDif,'o','Color',[102/255 0 51 subplot(2,3,5); plot(cpsums.nochanges,cpsums.CDstdDif,'o','Color',[102/255 0 51/255],... 'MarkerSize',6,'LineWidth',1.5) subplot(2,3,6); plot(cpsums.nochanges,cpsums.CDrmsDif,'o','Color',[102/255 0 51/255],... - 'MarkerSize',6,'LineWidth',1.5) \ No newline at end of file + 'MarkerSize',6,'LineWidth',1.5) + + +% try a different approach based on a moving STD window of 30 minutes +tic +ind = find(~isnan(seldata.cow_152.avg_z_sm)); +n = length(ind); +x = seldata.cow_152.avg_z_sm(ind); +test = movsum(30*60*log(movvar(x,30*60)),30*60); +toc +figure; +plot(test) +sum(n*log(var(x,1,2))); + +[~,b] = findchangepts(x,'Statistic','std','MinThreshold',100000000000) + + +figure, +findchangepts(x,'Statistic','std','MinThreshold',abs(b)*0.05, 'MinDistance',600) +figure, +findchangepts(x,'Statistic','std','MaxNumChanges',20, 'MinDistance',600) + + +% for "mean" ==> residue = n*sum(var(x,1,2)); +% for "std" ==> residue = sum(n*log(var(x,1,2))); +% for "rms" ==> residue = sum(n*log(sum(x.^2,2)/n)); \ No newline at end of file