Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
summing tied (duplicate) numbers in a series

Subject: summing tied (duplicate) numbers in a series

From: Vincent Odongo

Date: 22 May, 2012 11:23:06

Message: 1 of 6

Greetings to all, I have a time series data e.g. [4 4 6 7 9 9 9 10 10 13 17 17 17] which is long. I need to identify tied values such that t1=3(three untied values (6, 7, 13)), t2=2 (two ties of extent two (4, 10)), t3=2 (two ties of extent three (9, 17)).

After performing this, I need to sum all the ties in the series using the following equation... ti[(ti-1)(2ti+5)] where ti denotes the magnitude of the tie.(i.e. t1=3,t2=2, t3=2)

Such that the expected final solution and answer to the above should be;
{3[(3-1)(2*3+5)]+2[(2-1)(2*5+5)]+2[(2-1)(2*5+5)]}=126

Anyone with suggestion on how to go about this is welcome to help.

Thanks in advance.

Vincent

Subject: summing tied (duplicate) numbers in a series

From: Roger Stafford

Date: 22 May, 2012 13:13:06

Message: 2 of 6

"Vincent Odongo" wrote in message <jpfsup$pc8$1@newscl01ah.mathworks.com>...
> Greetings to all, I have a time series data e.g. [4 4 6 7 9 9 9 10 10 13 17 17 17] which is long. I need to identify tied values such that t1=3(three untied values (6, 7, 13)), t2=2 (two ties of extent two (4, 10)), t3=2 (two ties of extent three (9, 17)).
>
> After performing this, I need to sum all the ties in the series using the following equation... ti[(ti-1)(2ti+5)] where ti denotes the magnitude of the tie.(i.e. t1=3,t2=2, t3=2)
>
> Such that the expected final solution and answer to the above should be;
> {3[(3-1)(2*3+5)]+2[(2-1)(2*5+5)]+2[(2-1)(2*5+5)]}=126
- - - - - - - - - -
  With your use of the word "tied", I assume you are only counting repetitions of successive numbers in your time series.

  Let x be a row vector of the time series.

 f = find([1,diff(x),1]~=0);
 r = f(2:end)-f(1:end-1);
 u = unique(r);
 t = histc(r,u);
 s = sum(t.*(t-1).*(2*t+5));

(Note: I get 102 for your example, not 126.)

Roger Stafford

Subject: summing tied (duplicate) numbers in a series

From: Vincent Odongo

Date: 22 May, 2012 14:39:05

Message: 3 of 6

"Roger Stafford" wrote in message <jpg3d2$o2g$1@newscl01ah.mathworks.com>...
> "Vincent Odongo" wrote in message <jpfsup$pc8$1@newscl01ah.mathworks.com>...
> > Greetings to all, I have a time series data e.g. [4 4 6 7 9 9 9 10 10 13 17 17 17] which is long. I need to identify tied values such that t1=3(three untied values (6, 7, 13)), t2=2 (two ties of extent two (4, 10)), t3=2 (two ties of extent three (9, 17)).
> >
> > After performing this, I need to sum all the ties in the series using the following equation... ti[(ti-1)(2ti+5)] where ti denotes the magnitude of the tie.(i.e. t1=3,t2=2, t3=2)
> >
> > Such that the expected final solution and answer to the above should be;
> > {3[(3-1)(2*3+5)]+2[(2-1)(2*5+5)]+2[(2-1)(2*5+5)]}=126
> - - - - - - - - - -
> With your use of the word "tied", I assume you are only counting repetitions of successive numbers in your time series.
>
> Let x be a row vector of the time series.
>
> f = find([1,diff(x),1]~=0);
> r = f(2:end)-f(1:end-1);
> u = unique(r);
> t = histc(r,u);
> s = sum(t.*(t-1).*(2*t+5));
>
> (Note: I get 102 for your example, not 126.)
>
> Roger Stafford

Thanks Roger, your solution solved my problem.
While at it I also found out that this alternative works the same...
t = [4 4 6 7 9 9 9 10 10 13 17 17 17];
[a,~,n] = unique(t);
m = histc(n,1:max(n));
ti = accumarray(m',1);
x = length(ti);
sum_tie1=sum(ti.*((ti-1).*((2*ti)+5)))

Vincent

Subject: summing tied (duplicate) numbers in a series

From: Roger Stafford

Date: 22 May, 2012 18:30:07

Message: 4 of 6

"Vincent Odongo" wrote in message <jpg8e9$icq$1@newscl01ah.mathworks.com>...
> While at it I also found out that this alternative works the same...
> t = [4 4 6 7 9 9 9 10 10 13 17 17 17];
> [a,~,n] = unique(t);
> m = histc(n,1:max(n));
> ti = accumarray(m',1);
> x = length(ti);
> sum_tie1=sum(ti.*((ti-1).*((2*ti)+5)))
- - - - - - - - - -
  That's a solution to a different problem, Vincent. It may give the same answers as mine for your example, but in general the answers will be different. If you recall I said, "I assume you are only counting repetitions of successive numbers." Your code counts repetitions that are not necessarily occurring in successive numbers. Consider the time sequence:

 [7 5 5 7]

Mine would have t (or ti) equal to [2 1], whereas yours would get [0 2] and these would produce different sums. It is your decision as to which problem you want solved.

Roger Stafford

Subject: summing tied (duplicate) numbers in a series

From: Vincent Odongo

Date: 22 May, 2012 19:11:06

Message: 5 of 6

"Roger Stafford" wrote in message <jpglvf$msl$1@newscl01ah.mathworks.com>...
> "Vincent Odongo" wrote in message <jpg8e9$icq$1@newscl01ah.mathworks.com>...
> > While at it I also found out that this alternative works the same...
> > t = [4 4 6 7 9 9 9 10 10 13 17 17 17];
> > [a,~,n] = unique(t);
> > m = histc(n,1:max(n));
> > ti = accumarray(m',1);
> > x = length(ti);
> > sum_tie1=sum(ti.*((ti-1).*((2*ti)+5)))
> - - - - - - - - - -
> That's a solution to a different problem, Vincent. It may give the same answers as mine for your example, but in general the answers will be different. If you recall I said, "I assume you are only counting repetitions of successive numbers." Your code counts repetitions that are not necessarily occurring in successive numbers. Consider the time sequence:
>
> [7 5 5 7]
>
> Mine would have t (or ti) equal to [2 1], whereas yours would get [0 2] and these would produce different sums. It is your decision as to which problem you want solved.
>
> Roger Stafford

Thanks Roger. I hadn't checked that out. However, the correct output for t (ti) in this instance would be [0 2] because there are zero repetitions (ties) of extent 1; 2 repetitions of extent 2. Apologies I should have made that clearer.
Now I have an added twist to the problem. Assuming that the data series does not have repetitions in values, then the summation in the formula...
 sum_tie1=sum(ti.*((ti-1).*((2*ti)+5)))
should be avoided and instead the following formula should apply...
var=[n(n-1)(2n+5)]
where n is the length of data series.
So I needed the script to be robust enough to deal with these two situations in whichever series of data is to be analysed.
I can't seem to make headway with this. Any assistance given is welcome.

Vincent

Subject: summing tied (duplicate) numbers in a series

From: Vincent Odongo

Date: 22 May, 2012 19:34:06

Message: 6 of 6

"Vincent Odongo" wrote in message <jpgoca$569$1@newscl01ah.mathworks.com>...
> "Roger Stafford" wrote in message <jpglvf$msl$1@newscl01ah.mathworks.com>...
> > "Vincent Odongo" wrote in message <jpg8e9$icq$1@newscl01ah.mathworks.com>...
> > > While at it I also found out that this alternative works the same...
> > > t = [4 4 6 7 9 9 9 10 10 13 17 17 17];
> > > [a,~,n] = unique(t);
> > > m = histc(n,1:max(n));
> > > ti = accumarray(m',1);
> > > x = length(ti);
> > > sum_tie1=sum(ti.*((ti-1).*((2*ti)+5)))
> > - - - - - - - - - -
> > That's a solution to a different problem, Vincent. It may give the same answers as mine for your example, but in general the answers will be different. If you recall I said, "I assume you are only counting repetitions of successive numbers." Your code counts repetitions that are not necessarily occurring in successive numbers. Consider the time sequence:
> >
> > [7 5 5 7]
> >
> > Mine would have t (or ti) equal to [2 1], whereas yours would get [0 2] and these would produce different sums. It is your decision as to which problem you want solved.
> >
> > Roger Stafford
>
Some correction...
Thanks Roger. I hadn't checked that out. However, the correct output for t (ti) in this instance would be [0 2] because there are zero repetitions (ties) of extent 1; 2 repetitions of extent 2. Apologies I should have made that clearer.
Now I have an added twist to the problem. Assuming that the data series does not have repetitions in values, then the summation in the formula...
 sum_tie1=sum(ti.*((ti-1).*((2*ti)+5)))
should be avoided and instead the following formula should apply...
 var=[n(n-1)(2n+5)]
where n is the length of data series. Meaning sum_tie1=0
such that answer=[n(n-1)(2n+5)]-sum_tie1

So I needed the script to be robust enough to deal with these two situations in whichever series of data is to be analysed. That is, when there are no repetitions the answer follows this formula =[n(n-1)(2n+5)]-0. When there are repetitions the answer follows =[n(n-1)(2n+5)]-sum_tie1 where sum_tie1=sum(ti.*((ti-1).*((2*ti)+5))).
I can't seem to make headway with this. Any assistance given is welcome.

> Vincent

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us