Analytic expression to find the range of non-negative numbers in array

nazmul.islam
Messages
2
Reaction score
0
Hello,

I have an array of length M. Some of the indices are non-negative. I need to derive a function/analytic expression (preferably linear or convex) that finds the span of indices for which the indices are non-negative.

Example: Let p denote the desired vector.

Let, p = [0 0 0.3 2.6 0 0 1.1 0 1.8 0]

There are 10 elements in the array. Non-negative numbers start from index 3 (0.3) and end at index 9 (1.8). Range/span of non-negative numbers = 9-3+1 = 7.

I need a linear/convex function/analytic expression that can find this number.

Previous work:

I have already derived a similar function if the array only contains binary numbers.

Example: let, x = [0 0 1 1 0 0 1 0 1 0].

Now, let M denote the set of indices of x, i.e., M = {1,2,3,...,10}. Assume that x_m denotes the
m-th entry of the array x. For example, x_2 = 0, x_3 = 1. Here, |M| = 10.

My derived function (written in Latex format),
f(x) = max_{m \in M} (m * x_m) - min_{m \in M} (m * x_m + |M| (1 - x_m)) + 1

= max (1 * x_1, 2 * x_2, ..) - min (1 * x_1 + 10 * (1 - x_1), 2 * x_2 + 10 * (1 - x_2), ...) + 1

= 9 - 3 + 1

= 7.

This function is convex and it provides the correct answer. However, it only works for arrays that consist of binary numbers.

I need to find a linear/convex function/analytic expressions which work for arrays that consist of any non-negative number. This function will go into a constraint of my optimization problem. Hence, linearity/convexity is required. However, even a non-linear/non-convex function may help me, too.

Any ideas? Thanks a lot for reading this message. Let me know if I should post it in a different sub-forum of the math forum.

Thanks,

Nazmul
 
Physics news on Phys.org
nazmul.islam said:
Hello,

I have an array of length M. Some of the indices are non-negative.
No. Based on what you have said below, all indexes are positive (1, 2, 3, etc.). Also, no elements of your array are negative, but some of them are zero. It might be a language translation problem. Nonnegative means "not negative" and includes numbers that are either zero or positive.
nazmul.islam said:
I need to derive a function/analytic expression (preferably linear or convex) that finds the span of indices for which the indices are non-negative.
Based on your example, what you're looking for is a function that finds the number of elements that are positive.
nazmul.islam said:
Example: Let p denote the desired vector.

Let, p = [0 0 0.3 2.6 0 0 1.1 0 1.8 0]

There are 10 elements in the array. Non-negative numbers start from index 3 (0.3) and end at index 9 (1.8). Range/span of non-negative numbers = 9-3+1 = 7.
All elements in your array are nonnegative. Some elements are zero and the rest are positive.

Pretty much any programming language can be used to write a simple function that returns the number of positive elements in an array.

In C, the code would look like this:

Code:
int positiveElements(float arr[], int count)
{
  int i;
  int numPos = 0;

  if (count != 0) 
  {
    for (int i = 0; i < count; i++)
    {
      if (arr[i] > 0) numPos++;
    }
  }
  return numPos;
}
nazmul.islam said:
I need a linear/convex function/analytic expression that can find this number.

Previous work:

I have already derived a similar function if the array only contains binary numbers.

Example: let, x = [0 0 1 1 0 0 1 0 1 0].

Now, let M denote the set of indices of x, i.e., M = {1,2,3,...,10}. Assume that x_m denotes the
m-th entry of the array x. For example, x_2 = 0, x_3 = 1. Here, |M| = 10.

My derived function (written in Latex format),
f(x) = max_{m \in M} (m * x_m) - min_{m \in M} (m * x_m + |M| (1 - x_m)) + 1

= max (1 * x_1, 2 * x_2, ..) - min (1 * x_1 + 10 * (1 - x_1), 2 * x_2 + 10 * (1 - x_2), ...) + 1

= 9 - 3 + 1

= 7.

This function is convex and it provides the correct answer. However, it only works for arrays that consist of binary numbers.

I need to find a linear/convex function/analytic expressions which work for arrays that consist of any non-negative number. This function will go into a constraint of my optimization problem. Hence, linearity/convexity is required. However, even a non-linear/non-convex function may help me, too.

Any ideas? Thanks a lot for reading this message. Let me know if I should post it in a different sub-forum of the math forum.

Thanks,

Nazmul
 
Hello Mark44,

Thanks for your reply. I appreciate your effort.

Actually, I probably confused readers by mentioning "non-negative indices". Ideally, I want to find the SPAN of indices that correspond to the "positive elements" in an array. Note that, it is not equal to the number of "positive elements" in an array.

For example, let p = [0 0 0.3 2.6 0 0 1.1 0 1.8 0].

Here, there are 4 positive elements in the array (0.3, 2.6, 1.1, 1.8). However, I want to find the span of indices for which the elements are positive, i.e., the difference between the rightmost and leftmost index for which the element is positive.

In this case, the leftmost index is 3 (corresponding value of the element is 0.3). The rightmost index is 9 (corresponding value of the element is 1.8). Hence, the span is, 9-3+1 = 7.

I know how to find this "span" using a C code. I just need to find an analytic expression that can find this expression when the vector is given.

I have already derived an analytic expression when the elements are binary (shown in my original post). I need to derive an expression where the elements of the vectors are real numbers.
 
The world of 2\times 2 complex matrices is very colorful. They form a Banach-algebra, they act on spinors, they contain the quaternions, SU(2), su(2), SL(2,\mathbb C), sl(2,\mathbb C). Furthermore, with the determinant as Euclidean or pseudo-Euclidean norm, isu(2) is a 3-dimensional Euclidean space, \mathbb RI\oplus isu(2) is a Minkowski space with signature (1,3), i\mathbb RI\oplus su(2) is a Minkowski space with signature (3,1), SU(2) is the double cover of SO(3), sl(2,\mathbb C) is the...

Similar threads

Back
Top