Find all local maxima in a one-dimensional array

I implemented the following class (it works) and I just want to hear your opinions about best practices and what can be improved. The idea was to do it using mostly arrays.

The class just finds the peak elements in an array with respect to their neighbors. The first element and the last element are ignored.

Example: {3, 15, 5, 20, 10} Answer: {15, 20}

package findpeak;  import java.util.ArrayList; import java.util.List;   public class ArrayPeak {     private final int[] ARRAY;     private final int LEN;     private static final int IGNORE_FIRST_POSITION = 0;     private final int IGNORE_LAST_POSITION;      public ArrayPeak(int[] array)     {         this.ARRAY = array;         this.LEN = this.ARRAY.length;         this.IGNORE_LAST_POSITION = this.LEN - 1;     }      public List<Integer> findPeaks()     {         List<Integer> peaks = new ArrayList<>();         for (int position = 0; position < LEN; position++)         {             int output = 0;             if (position != IGNORE_FIRST_POSITION && position != IGNORE_LAST_POSITION)             {                 int[] trippleArray =                 {                     ARRAY[position - 1], ARRAY[position], ARRAY[position + 1]                 };                 output = checkPeak(trippleArray);             }             peaks.add(output);         }          return filterZeros(peaks);     }      private static int checkPeak(int[] inputArray)     {         int peak = 0;         if (inputArray[1] > inputArray[0] && inputArray[1] > inputArray[2])         {             peak = inputArray[1];         }         return peak;     }      private static List<Integer> filterZeros(List<Integer> list)     {         List<Integer> filteredList = new ArrayList<>();         for (int i = 0; i < list.size(); i++)         {             if (list.get(i) != 0)             {                 filteredList.add(list.get(i));             }         }         return filteredList;     } }  

Maxima of Brownian motion

It is well-known that Brownian motion attains infinitely many maxima in each time interval $ [0,T]$ a.s..

From a physics perspective it seems reasonable that when the disorder of the path of a particle decreases and the motion becomes more deterministic, then the number of maxima should decrease.

But I could not find anything on that. Now, there were two natural things to look at:

Is there a way to quantify that a Brownian motion with large variance (large disorder) has more maxima than one with little disorder?

Or is there a way to say that a diffusion process

$ dX_t = \mu (X_t) \ dt + \alpha dB_t $

has “less” maxima when $ \alpha $ is small compared to $ \alpha$ large?

I guess it is hard to make this question more precise, since this is not a question of cardinality of maxima but more about finding a suitably chosen measure that could capture such an effect.

About maxima of injective holomorphic maps on $\mathbb{C}^n$

I am hoping the following is true. Mention of related ideas/topics are appreciated.

Suppose $ F:\mathbb{C}^n \to \mathbb{C}^n$ is a injective holomorphic mapping such that $ F(0)=0$ and $ dF(0) = I_n$ where $ I_n$ is the $ n \times n$ identity matrix. Let $ \partial B$ denote the boundary of the unit ball centered at the origin in $ \mathbb{C}^n$ . Let $ M = \sup_{x \in \partial B} ||F(x)||$ where $ || \cdot ||$ is the usual Euclidean norm. Then $ \partial B \cap \{x: M = ||F(x)|| \}$ is equal to one of three things: i) $ \{p\}$ for some point $ p$ , ii) $ \{\alpha p : |\alpha|=1 \}$ for some point $ p$ , iii) $ \partial B$

Rademacher, maxima, convex hulls

Let $ F\subset \mathbb{R}^n$ be a finite set and $ \sigma$ be uniformly distributed over $ \{-1,1\}^n$ . The usual Rademacher average of $ F$ (modulo normalizing factors) is $ $ R_n(F)=\mathbb{E}_\sigma \max_{f\in F}\sum_{i=1}^n \sigma_if_i. $ $ Now let us define two operations on $ F$ : $ \mathrm{conv}(F)$ and $ [F]_\vee$ . The former is just the convex hull of the vector-set $ F$ in $ \mathbb{R}^n$ . The latter is defined by $ $ [F]_\vee=\{ f\vee g :f,g \in F\}, $ $ where $ (f\vee g)_i=\max\{f_i,g_i\}$ is the coordinate-wise maximum.

Question: is it true that $ $ R_n( [\mathrm{conv}(F)]_\vee) \le R_n( [F]_\vee) $ $ ?

On sums of minima and maxima

Let $ h_1,\ldots,h_n$ be positive integers, and define $ $ m(h_1,\ldots,h_n)=\sum_{r_1=0}^{h_1-1}\ldots\sum_{r_n=0}^{h_n-1}\min\left\{\frac{r_1}{h_1},\ldots,\frac{r_n}{h_n}\right\}$ $ and $ $ M(h_1,\ldots,h_n)=\sum_{r_1=0}^{h_1-1}\ldots\sum_{r_n=0}^{h_n-1}\max\left\{\frac{r_1}{h_1},\ldots,\frac{r_n}{h_n}\right\}.$ $ Motivated by Dedekind sums, I introduced $ m(h_1,\ldots,h_n)$ and $ M(h_1,\ldots,h_n)$ in my paper in Discrete Math. 257(2002), 143-159, and determined their exact values for $ n\le 3$ in that paper. For example, I showed that if $ h,k,l$ are positive integers then \begin{align} m(h,k,l)=&\frac{hkl}4-\frac{hk+hl+kl}6+\frac{h+k+l-1}8 \&+\frac{h+k-2hk}{24l}+\frac{h+l-2hl}{24k}+\frac{k+l-2kl}{24h} \&+\frac{(h-1)(k,l)^2}{24kl}+\frac{(k-1)(h,l)^2}{24hl}+\frac{(l-1)(h,k)^2}{24hk}, \end{align} where $ (a,b)$ denotes the greatest common divisor of integers $ a$ and $ b$ .

QUESTION. Are $ m(h_1,\ldots,h_n)$ and $ M(h_1,\ldots,h_n)$ rational functions in $ h_1,\ldots,h_n$ whenever $ h_1,\ldots,h_n$ are pairwise coprime?

I conjectured that this question has a positive answer in the mentioned 2002 paper of mine.

Any ideas towards the solution? Your comments are welcome!

Local maxima 3D array python

Hi I’m trying to find local maxima in a 3D numpy array, but I can’t seem to find a easy way to do that using numpy, scipy, or anything else.

For now I implemented it using scipy.signal.argrelexrema. But it’s very long to process large arrays, and only works on separated axis.

import numpy as np from scipy.signal import argrelextrema   def local_maxima_3D(data, order=1):     """Detects local maxima in a 3D array      Parameters     ---------     data : 3d ndarray     order : int         How many points on each side to use for the comparison      Returns     -------     coordinates : ndarray         coordinates of the local maxima     values : ndarray         values of the local maxima     """     # Coordinates of local maxima along each axis     peaks0 = np.array(argrelextrema(data, np.greater, axis=0, order=order))     peaks1 = np.array(argrelextrema(data, np.greater, axis=1, order=order))     peaks2 = np.array(argrelextrema(data, np.greater, axis=2, order=order))      # Stack all coordinates     stacked = np.vstack((peaks0.transpose(), peaks1.transpose(),                          peaks2.transpose()))      # We keep coordinates that appear three times (once for each axis)     elements, counts = np.unique(stacked, axis=0, return_counts=True)     coords = elements[np.where(counts == 3)[0]]      # Compute values at filtered coordinates     values = data[coords[:, 0], coords[:, 1], coords[:, 2]]      return coords, values 

I know this solution is far from optimal and only works with order=1. Is there any better way to find local maxima in a 3D array in python ?

Finding maxima of a function $f(x) = \sqrt{x} – 2x^2$ without calculus

My question is how to prove that $ f(x) = \sqrt x – 2x^2$ has its maximum at point $ x_0 = \frac{1}{4}$

It is easy to do that by finding its derivative and setting it to be zero (this is how I got $ x_0 = \frac{1}{4}$ ). But the task is to do that without using any calculus tools and I`m stuck at it.

My idea was to introduce $ t = \sqrt x$ to get $ f(t) = t – 2t^4$ and then find its maximum because I know how to do that with parabola which can be transformed to $ a(x-x_0)^2 + y_0$ . So I was trying to turn $ f(t) = t – 2t^4$ into $ f(t) = a(x-x_0)^4 + y_0$ but it seems impossible.

My second thought was to use the definition of rising function on an interval so I supposed we have $ a, b \in \left(0; \frac{1}{4}\right) \text{and } a < b$ . Then I prove that $ $ \sqrt a – 2a^2 < \sqrt b – 2b^2$ $ $ $ 2(b – a)(a + b) < \sqrt b – \sqrt a$ $ $ $ 2(\sqrt a + \sqrt b)(a + b) < 1$ $ which is true since $ 0 < a < b < \frac{1}{4}$

Exactly the same way I prove that for every $ a, b \in \left(\frac{1}{4}; +\infty\right) \text{and } a < b$ $ $ \sqrt a – 2a^2 > \sqrt b – 2b^2$ $

So we have that $ f(x)$ is rising on $ \left(0; \frac{1}{4}\right)$ and declining on $ \left(\frac{1}{4}; +\infty\right)$ , consequently at $ \frac{1}{4}$ we have a maximum of $ f$

But I guess it is not fair to use derivatives to find the maximum and then simply prove that this value is correct. Is there an even better solution? What are your thoughts about my proof?