matlab求cusum,Detect small changes in mean using cumulative sum

Every hole in golf has an associated "par" that indicates the expected number of strokes needed to sink the ball. Skilled players usually complete each hole with a number of strokes very close to par. It is necessary to play several holes and let scores accumulate before a clear winner emerges in a match.

Ben, Jen, and Ken play a full round, which consists of 18 holes. The course has an assortment of par-3, par-4, and par-5 holes. At the end of the game, the players tabulate their scores.

hole = 1:18;

par = [4 3 5 3 4 5 3 4 4 4 5 3 5 4 4 4 3 4];

nms = {'Ben';'Jen';'Ken'};

Ben = [4 3 4 2 3 5 2 3 3 4 3 2 3 3 3 3 2 3];

Jen = [4 3 4 3 4 4 3 4 4 4 5 3 4 4 5 5 3 3];

Ken = [4 3 4 3 5 5 4 4 4 4 5 3 5 4 5 4 3 5];

T = table(hole',par',Ben',Jen',Ken', ...

'VariableNames',['hole';'par';nms])

T=18×5 table

hole par Ben Jen Ken

____ ___ ___ ___ ___

1 4 4 4 4

2 3 3 3 3

3 5 4 4 4

4 3 2 3 3

5 4 3 4 5

6 5 5 4 5

7 3 2 3 4

8 4 3 4 4

9 4 3 4 4

10 4 4 4 4

11 5 3 5 5

12 3 2 3 3

13 5 3 4 5

14 4 3 4 4

15 4 3 5 5

16 4 3 5 4

The winner of the round is the player whose lower cumulative sum drifts the most below par at the end. Compute the sums for the three players to determine the winner. Make every shift in mean detectable by setting a small threshold.

[~,b,~,Bensum] = cusum(Ben-par,1,1e-4,0);

[~,j,~,Jensum] = cusum(Jen-par,1,1e-4,0);

[~,k,~,Kensum] = cusum(Ken-par,1,1e-4,0);

plot([Bensum;Jensum;Kensum]')

legend(nms,'Location','best')

f0eb10906a1520f13bc9ee5f405319c3.png

Ben wins the round. Simulate their next game by adding or subtracting a stroke per hole at random.

Ben = Ben+randi(3,1,18)-2;

Jen = Jen+randi(3,1,18)-2;

Ken = Ken+randi(3,1,18)-2;

[~,b,~,Bensum] = cusum(Ben-par,1,1e-4,0);

[~,j,~,Jensum] = cusum(Jen-par,1,1e-4,0);

[~,k,~,Kensum] = cusum(Ken-par,1,1e-4,0);

plot([Bensum;Jensum;Kensum]')

legend(nms,'Location','best')

099b59afb4fbcf15e1ec4b21501504de.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值