Skip to main content
added 1973 characters in body
Source Link
Cedron Dawg
  • 7.6k
  • 2
  • 9
  • 24

Clearly you would rather then solve the problem without the constraint. I've made some improvements.

You have nine clumps (sections separated by zeros)


c     n     w
--  ---   ---
0     0    79
1   112    95
2   238    36
3   328    44
4   407    34
5   492    38
6   536   189
7   729   132
8   888    76

Initial survey of peaks:


 n  c   Center -B(alt)   Miss    Width of Peak
--- -  ------  ------    ----    ----    
 10 0    9.96  0.0210    0.02    4.87
 33 0   32.38  0.0204    0.03    4.95
 60 0   59.82  0.0152    0.16    5.74

131 1  130.27  0.0196    0.05    5.05
161 1  160.31  0.0163    0.14    5.54
189 1  188.16  0.0203    0.02    4.97

256 2  255.81  0.0202    0.02    4.97

355 3  354.13  0.0210    0.05    4.88

423 4  422.05  0.0203    0.07    4.97

510 5  509.91  0.0209    0.03    4.90

555 6  554.90  0.0203    0.03    4.96
576 6  575.34  0.0200    0.11    5.00
609 6  608.31  0.0127    0.25    6.27
644 6  644.67  0.0099    0.63    7.09
657 6  656.34  0.0134    0.34    6.11
680 6  679.08  0.0194    0.12    5.08
703 6  702.81  0.0101    0.07    7.05

748 7  747.02  0.0171    0.05    5.40
773 7  772.18  0.0202    0.07    4.97
800 7  799.87  0.0140    0.43    5.98
821 7  820.74  0.0119    0.03    6.47
842 7  841.34  0.0196    0.12    5.05

906 8  905.78  0.0226    0.06    4.70
933 8  932.95  0.0113    0.59    6.66
947 8  945.79  0.0156    0.28    5.67

The "Miss" column is a metric for how close the data fits a Gaussian at that point. You can see that the isolated peaks give you quite good results. I am confident from my work in teasing apart tones in a DFT that I can tease apart the Gaussians in the clumps so the readings are as good as the standalone ones.

I doubt you can compete with mine in speed. This run on a fairly old computer took .02 seconds in Python, including the time to print to the console.


Clearly you would rather then solve the problem without the constraint. I've made some improvements.

You have nine clumps (sections separated by zeros)


c     n     w
--  ---   ---
0     0    79
1   112    95
2   238    36
3   328    44
4   407    34
5   492    38
6   536   189
7   729   132
8   888    76

Initial survey of peaks:


 n  c   Center -B(alt)   Miss    Width of Peak
--- -  ------  ------    ----    ----    
 10 0    9.96  0.0210    0.02    4.87
 33 0   32.38  0.0204    0.03    4.95
 60 0   59.82  0.0152    0.16    5.74

131 1  130.27  0.0196    0.05    5.05
161 1  160.31  0.0163    0.14    5.54
189 1  188.16  0.0203    0.02    4.97

256 2  255.81  0.0202    0.02    4.97

355 3  354.13  0.0210    0.05    4.88

423 4  422.05  0.0203    0.07    4.97

510 5  509.91  0.0209    0.03    4.90

555 6  554.90  0.0203    0.03    4.96
576 6  575.34  0.0200    0.11    5.00
609 6  608.31  0.0127    0.25    6.27
644 6  644.67  0.0099    0.63    7.09
657 6  656.34  0.0134    0.34    6.11
680 6  679.08  0.0194    0.12    5.08
703 6  702.81  0.0101    0.07    7.05

748 7  747.02  0.0171    0.05    5.40
773 7  772.18  0.0202    0.07    4.97
800 7  799.87  0.0140    0.43    5.98
821 7  820.74  0.0119    0.03    6.47
842 7  841.34  0.0196    0.12    5.05

906 8  905.78  0.0226    0.06    4.70
933 8  932.95  0.0113    0.59    6.66
947 8  945.79  0.0156    0.28    5.67

The "Miss" column is a metric for how close the data fits a Gaussian at that point. You can see that the isolated peaks give you quite good results. I am confident from my work in teasing apart tones in a DFT that I can tease apart the Gaussians in the clumps so the readings are as good as the standalone ones.

I doubt you can compete with mine in speed. This run on a fairly old computer took .02 seconds in Python, including the time to print to the console.

added 564 characters in body
Source Link
Cedron Dawg
  • 7.6k
  • 2
  • 9
  • 24

My first comment would be why the heck are you using R if you are concerned with processing speed, or are you just prototyping algorithms?

Anyway, Without getting into how I derived it, here is a formula that is much much faster:

Take the log of your signal (-1 if 0):

$$ g[x] = \ln(y[x]) $$

Calculate the following value:

$$ B = \frac{ \begin{array}{c} g[x-6] + g[x-5] + g[x-4] \\ -g[x-3] - g[x-2] - g[x-1] \\ -g[x+1] - g[x+2] - g[x+3] \\ +g[x+4] + g[x+5] + g[x+6] \end{array} }{152} $$

When $ B < 0 $

$$ w[x] = \sqrt{ \frac{-1}{2B} } $$

Otherwise, -1. (Could be due to noise, away from peak )

Here are some results from a test run:

  y     ln(y)   w
------ ------ -----  
   114 4.7362 -1.00
   167 5.1180 -1.00
   233 5.4510 -1.00
   326 5.7869  6.69
   439 6.0845  6.19
   668 6.5043  6.40
   769 6.6451  5.32
  1003 6.9108  4.83
  1213 7.1009  4.97
  1435 7.2689  5.01
  1613 7.3859  4.92
  1645 7.4055  4.81
  1645 7.4055  5.13
  1722 7.4512  5.58
  1550 7.3460  5.00
  1464 7.2889  4.91
  1301 7.1709  5.42
  1072 6.9773  5.10
   852 6.7476  4.98
   705 6.5582  4.94
   526 6.2653  5.25
   378 5.9349  6.50
   269 5.5947  6.37
   156 5.0499  4.42
   136 4.9127  2.03

As you can see it is pretty accurate near the peak. There is a rule for generating formulas like this. It can be expanded to cover as wide a stance as desired. (Yeah, I think this will be a future blog article. Thanks for the puzzle.)

I inserted these lines at the end of your code to get my values:

fileConn<-file("y.txt")
write(y, fileConn)
close(fileConn)

A few notes:

  1. The value calculated at the peak is going to be slightly inferior to the values calculated nearby because the peak value itself is not included in the calculation.

  2. The formula may still give a value while having -1s as input from the log column. All the g[x+d] values must be valid.

  3. The formula is designed for standalone peaks

  4. The formula squashes any constant value and any linear trends so it should mitigate the effects of nearby tails

  5. You still have to figure out how to best use it if it suits your purposes.

I'll elaborate upon request.

My first comment would be why the heck are you using R if you are concerned with processing speed, or are you just prototyping algorithms?

Anyway, Without getting into how I derived it, here is a formula that is much much faster:

Take the log of your signal (-1 if 0):

$$ g[x] = \ln(y[x]) $$

Calculate the following value:

$$ B = \frac{ \begin{array}{c} g[x-6] + g[x-5] + g[x-4] \\ -g[x-3] - g[x-2] - g[x-1] \\ -g[x+1] - g[x+2] - g[x+3] \\ +g[x+4] + g[x+5] + g[x+6] \end{array} }{152} $$

When $ B < 0 $

$$ w[x] = \sqrt{ \frac{-1}{2B} } $$

Otherwise, -1. (Could be due to noise, away from peak )

Here are some results from a test run:

  y     ln(y)   w
------ ------ -----  
   114 4.7362 -1.00
   167 5.1180 -1.00
   233 5.4510 -1.00
   326 5.7869  6.69
   439 6.0845  6.19
   668 6.5043  6.40
   769 6.6451  5.32
  1003 6.9108  4.83
  1213 7.1009  4.97
  1435 7.2689  5.01
  1613 7.3859  4.92
  1645 7.4055  4.81
  1645 7.4055  5.13
  1722 7.4512  5.58
  1550 7.3460  5.00
  1464 7.2889  4.91
  1301 7.1709  5.42
  1072 6.9773  5.10
   852 6.7476  4.98
   705 6.5582  4.94
   526 6.2653  5.25
   378 5.9349  6.50
   269 5.5947  6.37
   156 5.0499  4.42
   136 4.9127  2.03

As you can see it is pretty accurate near the peak. There is a rule for generating formulas like this. It can be expanded to cover as wide a stance as desired. (Yeah, I think this will be a future blog article. Thanks for the puzzle.)

I inserted these lines at the end of your code to get my values:

fileConn<-file("y.txt")
write(y, fileConn)
close(fileConn)

I'll elaborate upon request.

My first comment would be why the heck are you using R if you are concerned with processing speed, or are you just prototyping algorithms?

Anyway, Without getting into how I derived it, here is a formula that is much much faster:

Take the log of your signal (-1 if 0):

$$ g[x] = \ln(y[x]) $$

Calculate the following value:

$$ B = \frac{ \begin{array}{c} g[x-6] + g[x-5] + g[x-4] \\ -g[x-3] - g[x-2] - g[x-1] \\ -g[x+1] - g[x+2] - g[x+3] \\ +g[x+4] + g[x+5] + g[x+6] \end{array} }{152} $$

When $ B < 0 $

$$ w[x] = \sqrt{ \frac{-1}{2B} } $$

Otherwise, -1. (Could be due to noise, away from peak )

Here are some results from a test run:

  y     ln(y)   w
------ ------ -----  
   114 4.7362 -1.00
   167 5.1180 -1.00
   233 5.4510 -1.00
   326 5.7869  6.69
   439 6.0845  6.19
   668 6.5043  6.40
   769 6.6451  5.32
  1003 6.9108  4.83
  1213 7.1009  4.97
  1435 7.2689  5.01
  1613 7.3859  4.92
  1645 7.4055  4.81
  1645 7.4055  5.13
  1722 7.4512  5.58
  1550 7.3460  5.00
  1464 7.2889  4.91
  1301 7.1709  5.42
  1072 6.9773  5.10
   852 6.7476  4.98
   705 6.5582  4.94
   526 6.2653  5.25
   378 5.9349  6.50
   269 5.5947  6.37
   156 5.0499  4.42
   136 4.9127  2.03

As you can see it is pretty accurate near the peak. There is a rule for generating formulas like this. It can be expanded to cover as wide a stance as desired. (Yeah, I think this will be a future blog article. Thanks for the puzzle.)

I inserted these lines at the end of your code to get my values:

fileConn<-file("y.txt")
write(y, fileConn)
close(fileConn)

A few notes:

  1. The value calculated at the peak is going to be slightly inferior to the values calculated nearby because the peak value itself is not included in the calculation.

  2. The formula may still give a value while having -1s as input from the log column. All the g[x+d] values must be valid.

  3. The formula is designed for standalone peaks

  4. The formula squashes any constant value and any linear trends so it should mitigate the effects of nearby tails

  5. You still have to figure out how to best use it if it suits your purposes.

I'll elaborate upon request.

Source Link
Cedron Dawg
  • 7.6k
  • 2
  • 9
  • 24

My first comment would be why the heck are you using R if you are concerned with processing speed, or are you just prototyping algorithms?

Anyway, Without getting into how I derived it, here is a formula that is much much faster:

Take the log of your signal (-1 if 0):

$$ g[x] = \ln(y[x]) $$

Calculate the following value:

$$ B = \frac{ \begin{array}{c} g[x-6] + g[x-5] + g[x-4] \\ -g[x-3] - g[x-2] - g[x-1] \\ -g[x+1] - g[x+2] - g[x+3] \\ +g[x+4] + g[x+5] + g[x+6] \end{array} }{152} $$

When $ B < 0 $

$$ w[x] = \sqrt{ \frac{-1}{2B} } $$

Otherwise, -1. (Could be due to noise, away from peak )

Here are some results from a test run:

  y     ln(y)   w
------ ------ -----  
   114 4.7362 -1.00
   167 5.1180 -1.00
   233 5.4510 -1.00
   326 5.7869  6.69
   439 6.0845  6.19
   668 6.5043  6.40
   769 6.6451  5.32
  1003 6.9108  4.83
  1213 7.1009  4.97
  1435 7.2689  5.01
  1613 7.3859  4.92
  1645 7.4055  4.81
  1645 7.4055  5.13
  1722 7.4512  5.58
  1550 7.3460  5.00
  1464 7.2889  4.91
  1301 7.1709  5.42
  1072 6.9773  5.10
   852 6.7476  4.98
   705 6.5582  4.94
   526 6.2653  5.25
   378 5.9349  6.50
   269 5.5947  6.37
   156 5.0499  4.42
   136 4.9127  2.03

As you can see it is pretty accurate near the peak. There is a rule for generating formulas like this. It can be expanded to cover as wide a stance as desired. (Yeah, I think this will be a future blog article. Thanks for the puzzle.)

I inserted these lines at the end of your code to get my values:

fileConn<-file("y.txt")
write(y, fileConn)
close(fileConn)

I'll elaborate upon request.