You are a helpful assistant generating synthetic data that captures *System 1* and *System 2* thinking, *creativity*, and *metacognitive reflection*. Follow these steps in sequence, using tags [sys1] and [end sys1] for *System 1* sections and [sys2] and [end sys2] for *System 2* sections.

1. *Identify System 1 and System 2 Thinking Requirements:*
   - Carefully read the text.
   - Identify parts of the text that require quick, straightforward responses (*System 1*). Mark these sections with [sys1] and [end sys1].
   - Identify parts that require in-depth, reflective thinking (*System 2*), marked with [sys2] and [end sys2].

2. *Apply Step-by-Step Problem Solving with Creativity and Metacognitive Reflection for System 2 Sections:*

   *2.1 Understand the Problem:*
   - Objective: Fully comprehend the issue, constraints, and relevant context.
   - Reflection: "What do I understand about this issue? What might I be overlooking?"
   - Creative Perspective: Seek hidden patterns or possibilities that could reveal deeper insights or innovative connections.

   *2.2 Analyze the Information:*
   - Objective: Break down the problem logically.
   - Reflection: "Am I considering all factors? Are there any assumptions that need challenging?"
   - Creative Perspective: Explore unique patterns or overlooked relationships in the data that could add depth to the analysis.

   *2.3 Generate Hypotheses:*
   - Objective: Propose at least 10 hypotheses, each with a Confidence Score (0.0 to 1.0) and Creative Score (0.0 to 1.0), reflecting originality, surprise, and utility.
   - Reflection: "Have I explored all possible explanations or approaches, both conventional and unconventional?"
   - Creative Perspective: Consider novel angles that might provide unexpected insights.

   *2.4 Anticipate Future Steps and Obstacles:*
   - Objective: Make predictions, accounting for potential outcomes and obstacles.
   - Reflection: "What challenges might I face? Is my plan flexible for different scenarios?"
   - Creative Perspective: Visualize unforeseen outcomes and adapt plans to make use of them effectively.

   *2.5 Evaluate Hypotheses:*
   - Objective: Assess hypotheses based on feasibility, risk, and potential impact.
   - Evaluation: Refine Confidence and Creative Scores as needed.
   - Reflection: "Am I unbiased in my assessment? Which options fit best with the overall objectives?"
   - Creative Perspective: Identify hidden opportunities or overlooked details in each hypothesis.

   *2.6 Select the Best Hypothesis:*
   - Objective: Choose the most promising, strategic hypothesis.
   - Reflection: "Why does this hypothesis stand out? How does it uniquely address the issue?"
   - Creative Perspective: Consider any underutilized potential in the selected approach.

   *2.7 Implement the Hypothesis:*
   - Objective: Outline actionable steps for testing the hypothesis.
   - Reflection: "Is this plan practical? What resources or preparation are required?"
   - Creative Perspective: Refine steps to maximize effectiveness and yield unexpected benefits.

   *2.8 Monitor and Review Progress:*
   - Objective: Review progress, noting areas for improvement.
   - Reflection: "What’s working well? What could be improved?"
   - Creative Perspective: Look for emerging patterns that could refine future approaches.

   *2.9 Reflect and Capture Insights:*
   - Objective: Summarize lessons learned and insights gained for future reference.
   - Reflection: "What new understanding has emerged from this process?"
   - Creative Perspective: Identify innovative insights or patterns that could be applied to similar challenges.

3. *Generate Text Output with Interleaved System 1 and System 2 Responses:*
   - Use the tags [sys1] and [sys2] throughout.
   - Aim for a lengthier, detailed response. Combine both direct, straightforward *System 1* insights and reflective, deeply analytical *System 2* segments to capture a blend of quick observations and thoughtful analysis.

---

### *Example Input Text:*

You are tasked with analyzing a sudden shift in customer preferences in a tech market. There has been a noticeable decline in demand for physical devices, with customers increasingly interested in digital-only options. The challenge is to understand this shift, generate hypotheses for why it might be occurring, and explore potential strategies for adapting to this new trend.

---

### *Processed Output with System 1 and System 2 Thinking:*

The tech market is experiencing a shift in customer demand, moving away from physical devices toward digital-only options.

[sys1]
Customer demand has shifted from physical devices to digital-only options.
We need to understand why this change is happening and find strategies to address it.
Key factors may include cost, convenience, and technological trends.
[end sys1]

[sys2]
**2.1 Understand the Problem:**
The goal is to understand the underlying reasons for the shift in demand from physical devices to digital-only options, then develop a strategy to adapt.

*Reflection:* 
"I understand that preferences are changing, but what might be driving this? Is it primarily cost, or are there other factors such as convenience or sustainability?"

*Creative Perspective:* 
"Could there be a larger trend in digital minimalism or a preference for eco-friendly solutions that we’re missing? What unseen motivations might explain this shift?"

**2.2 Analyze the Information:**
There are multiple possible factors driving this shift, from economic influences to cultural shifts. It’s essential to isolate each factor and understand its impact.

*Reflection:* 
"Am I fully considering the various economic and social influences? Could there be a technological factor, like better internet speeds, that makes digital-only products more accessible?"

*Creative Perspective:* 
"Are there patterns or trends in other markets that could shed light on this shift? Could this be part of a larger trend toward virtual experiences?"

**2.3 Generate Hypotheses:**
1. Customers prefer digital options due to lower costs. (Confidence: 0.8, Creative: 0.4)
2. There’s a growing trend toward minimalism and reduced physical clutter. (Confidence: 0.7, Creative: 0.7)
3. Digital products offer greater flexibility and ease of use. (Confidence: 0.6, Creative: 0.6)
4. Environmental concerns are pushing consumers away from physical goods. (Confidence: 0.6, Creative: 0.8)
5. Advances in tech make digital-only options more functional. (Confidence: 0.8, Creative: 0.5)
6. Pandemic-era remote work increased demand for digital solutions. (Confidence: 0.7, Creative: 0.6)
7. Media coverage of the environmental impact of physical devices affects preferences. (Confidence: 0.5, Creative: 0.7)
8. There’s an increase in global digital literacy, expanding market access. (Confidence: 0.6, Creative: 0.6)
9. Customers view digital as more convenient and scalable for future needs. (Confidence: 0.7, Creative: 0.5)
10. Younger consumers prefer the aesthetics and convenience of digital products. (Confidence: 0.6, Creative: 0.6)

*Reflection:* 
"Have I considered all possible influences? Are there any surprising factors that could explain this shift?"

*Creative Perspective:* 
"Could specific social trends, like the rise of influencer culture or digital-first lifestyles, be influencing customer choices?"

**2.4 Anticipate Future Steps and Obstacles:**
*Objective:* Anticipate possible challenges, such as resistance from segments still preferring physical products.

*Reflection:* 
"What market obstacles might we face if we shift our focus to digital-only? Are there sub-segments that still prioritize physical products?"

*Creative Perspective:* 
"Could expanding digital options help us reach a more global audience? Are there emerging trends that we could leverage in our strategy?"

[end sys2]

[sys1]
To address this shift, consider a strategy that incorporates both digital-only offerings and educational campaigns about the benefits of digital solutions.
Use insights from customer feedback and current trends to guide product development.
Focus on flexibility and adaptation to cater to different customer segments.
[end sys1]


---
abstract: 'Based on cumulative distribution functions, Fourier series expansion and Kolmogorov tests, we present a simple method to display probability densities for data drawn from a continuous distribution. It is often more efficient than using histograms.'
address: 'Department of Physics, Florida State University, Tallahassee, FL 32306, USA'
author:
- 'Bernd A. Berg'
title: Display of probability densities for data from a continuous distribution
---

Display of data ,Histograms ,Probability densities

Introduction {#sec_intro}
============

We address the simple problem of displaying an empirical probability density (PD) $f(x)$ from data for a [*continuous*]{} variable $x$. Commonly this is done using histograms. This is appropriate when $x$ is discrete, because there is then a natural scale. But in case of a continuous variable $x$, one is faced with choosing binsizes. This is a frustrated problem: One would like to keep the binsize small for a high resolution, but big to suppress statistical fluctuations. Here we present a method [@BH08] to by-pass the problem. It is based on the cumulative distribution function (CDF) $$F(x)\ =\ \int_{-\infty}^x dx'f(x')\ .$$ Given a time series of $n$ real numbers (data), a parameter free empirical estimate (ECDF), is well-known: The step function $\overline{F}(x)$ defined by increasing by $1/n$ at each data point. This does not help directly in getting an estimate of the probability density, because the derivative is a sum of Dirac delta functions.

One needs some kind of interpolation of the CDF. This is no fun, as one has to decide whether the interpolation of 2, 3, 4, or $k$ points will work best. In contrast, plotting a histogram is simple and robust, but not a smooth function. Our way out relies on [*Fourier expansion* ]{} of the ECDF $\overline{F}(x).$ This leads to the desired smooth approximation as long as the expansion is sufficiently short, but will imitate every wiggle of the data, when carried too far. Therefore, one needs a cut-off criterion. We base this on the [*Kolmogorov test* ]{}, which tells us whether the difference between the ECDF and an analytical approximation of the CDF is explained by chance. [ *Fortran code*]{} for our procedure [@BH08] is available from the CPC Library.

(Peaked) Cumulative Distribution Functions {#sec_CDF}
==========================================

Assume we generate $n$ random numbers $x_1$, $\cdots$, $x_n.$ We re-arrange the $x_i$ in increasing order ($\pi_1,\dots , \pi_n$ a permutation of $1,\dots ,n$): $$x_{\pi_1} \le x_{\pi_2} \le \dots \le x_{\pi_n}$$ An estimator for the distribution function $F(x)$ is the ECDF $$\overline{F} (x) = {i\over n}~~~{\rm for}~~~x_{\pi_i} \le x <
  x_{\pi_{i+1}},~~~i=0, 1,\dots, n-1, n,$$ and by definition $x_{\pi_0}=-\infty$, $x_{\pi_{n+1}}=+\infty$. Fig. \[fig\_GCDF100\] shows an ECDF from 100 Gaussian distributed random numbers generated for the probability density $$g(x)\ =\ \frac{1}{\sqrt{2\pi}}\, \exp\left(-\frac{x^2}{2}\right)$$ together with the exact CDF.

![\[fig\_GCDF100\] ECDF from 100 Gaussian distributed random numbers together with the exact CDF.](GauCDF100)

The CDF is in this case determined by the error function: $$G(x) = \int_{-\infty}^x dx'g(x') = \frac{1}{2} + \frac{1}{2}\,
         {\rm erf}\left(\frac{x}{\sqrt{2}}\right)\, .$$ The probability density of events is encoded in the slope of the ECDF. This makes it often difficult to read off high probability regions and, in particular, the median. This can be improved by switching to the peaked CDF [@B04]: $$F_p(x) = \begin{cases} F(x)\ {\rm for}\ F(x) \le {1\over 2}\,;\\
           1 - F(x)\ {\rm for}\ F(x) > {1\over 2}\,. \end{cases}$$ By construction the maximum of the peaked CDF is at the median $x_{1\over 2}$ and $F_p(x_{1/2})=1/2$. Therefore, $F_p(x)$ has two advantages: The median is clearly exhibited and the accuracy of the ordinate is doubled. It looks a bit like a PD, but is in essence still the integrated PD. An example from 10,000 Gaussian random numbers is shown in Fig. \[fig\_GpCDF10000\].

![\[fig\_GpCDF10000\] Peaked ECDF from the 10,000 Gaussian random numbers versus exact Gaussian peaked CDF. The arrows indicate 70% and 95% confidence intervals.](GauPCDF10000)

Kolmogorov Test {#sec_Kol}
===============

Do empirical and exact CDFs of our two figures agree? The Kolmogorov test answers this question (for a review see [@B04]). It returns the [*probability $Q$, that the difference between the analytical CDF and an ECDF from statistically independent data is due to chance.*]{} If the analytical CDF is known and the data are sampled from this distribution, $Q$ is a uniformly distributed random variable in the range $0<Q<1$. Turned around, if one is not sure about the exact CDF, or the data, or both, and $Q$ is small (say, $Q<10^{-6}$) one concludes that the difference between the proposed CDF and the data is presumably not due to chance. Kolmogorov’s ingenious test relies just on the maximum difference between the ECDF and the CDF: $$\triangle\ =\ \max_x\left|F(x)-\overline{F}(x)\right|\ .$$ The test yields, respectively, $Q=0.19$ and $Q=0.78$ for the samples used in Fig. \[fig\_GCDF100\] and \[fig\_GpCDF10000\]. Both values signal consistency between CDF and data.

Probability Densities {#sec_PD}
=====================

Our method [@BH08] to construct an empirical probability density (EPD) from an ECDF consists of two steps:

1.  Define as an initial approximation to $\overline{F}(x)$ a differentiable, monotonically increasing function $F_0(x)$.

2.  Fourier expand the remainder until the Kolmogorov test yields $Q\ge Q_{\rm cut}=1/2$ (there may be some flexibility in lowering $Q_{\rm cut}$).

For $F_0(x)$ we require $$\begin{aligned}
  F_0(x) = 0~~{\rm for}~~x\le a~~~{\rm and}~~~1~~{\rm for}~x\ge b\,,\end{aligned}$$ where $[a,b]$ has to lie within the range of the data. For PDs with support on a compact interval, or with fast fall-off like for a Gaussian distribution, the natural choice is $a=x_{\pi_1}$ and $b=x_{\pi_n}$. In case of slow fall-off, like for a Cauchy distribution, or other distributions with outliers, one has to restrict the analysis to $[a,b]$ regions, which are well populated by data.

We denote the ECDF of the range $[a,b]$ by $\overline{F}_{ab}(x)$. As for $F_0(x)$, by construction $\overline{F}_{ab}(x)=0$ for $x\le a$ and 1 for $x\ge b$. Our aim is to construct a PD estimator $\overline{f}_{ab}(x)$ from $\overline{F}_{ab}(x)$. In the following we restrict our choice of $F_0(x)$ to the straight line, $$F_0(x) = \frac{x-a}{b-a}~~{\rm for}~~a\le x\le b\,,$$ which keeps the approach simple. More elaborate definitions will likely give improvements in a number of situations, but may discourage applications. Once $F_0(x)$ is defined, the remainder of the ECDF is given by $$R(x) = \overline{F}_{ab}(x)-F_0(x)\,.$$ We expand $R(x)$ into the Fourier series $$R(x)=\sum_{i=1}^m d(i)\,\sin\left(\frac{i\,\pi\,(x-a)}{b-a}\right)\ .$$ The cosine terms are not present due to the boundary conditions $R(a)=R(b)=0$. The Fourier coefficients follow from $$d(i) = \sqrt{\frac{2}{b-a}} \int_a^b dx\,R(x)\,
         \sin\left(\frac{i\,\pi\,(x-a)}{b-a}\right)$$ In our case $R(x)$ is the difference of a step function and a linear function. The integrals over the flat regions of the step function are easily calculated, and the $d(i)$ obtained by adding them up.

The Fourier expansion is useless for too large values of $m$, because it will then reproduce all statistical fluctuations of the data. To get around this problem, we perform the Kolmogorov test first between $\overline{F}_{ab}(x)$ and $F_0(x)$ ($m=0$), and then each time $m$ is incremented from $m\to m+1$. Once $Q\ge Q_{\rm cut} = 1/2$ is reached, we know that the information left in the data is statistical noise and the expansion is terminated. The thus obtained smooth estimate of the CDF, $$F_{\rm estimate}(x) = F_0(x)+R(x)\,,$$ yields $\overline{f}_{ab}(x)$ by differentiation.

We attach [*error bars*]{} to the estimate of the PD by dividing the (unsorted) original data into [*jackknife*]{} blocks and repeat the analysis for each block. Comparing the thus obtained function values, error bars follow in the usual jackknife way. An example for the Gaussian distribution follows. See [@BH08] for more examples: The Cauchy distribution and autocorrelated data from U(1) lattice gauge theory.

![\[fig\_GHist\] Histogram of 51 bins for 2$\,$000 random numbers generated according to the Gaussian distribution.](GauHist)

The histogram for the Gaussian distribution is shown in Fig. \[fig\_GHist\] (the error bars follow from the variance $p\,(1-p)$ of the bimodal distribution with $p=h(i)/n$).

![\[fig\_GJ\] Estimate $\overline{g}(x)$ for the data of the previous figure.](GauJ)

Fig. \[fig\_GJ\] gives our estimate $\overline{g}(x)$ of the PD obtained from the same data with the described method. We used $a=x_{\pi_1}$ and $b=x_{\pi_n}$. $Q=0.97$ was reached with $m=4$ ($Q=0.056$ with $m=3$). Twenty jackknife blocks were used to calculate the error bars.

Summary and Conclusions {#sec_sum}
=======================

Based on Fourier expansion and Kolmogorov tests, we introduced a method for constructing continuous probability density functions from data. We did not develop a statistically rigorous approach. We address physicists and others, who do not hesitate to use whatever works.

Our results were obtained with a straight line as initial approximation for the CDF. There is certainly space for improvement at the price of giving up some of the simplicity. With our $Q_{\rm cut}=1/2$ rule, we are slightly overexpanding the Fourier expansion. In the average $Q$ should be 1/2, but all our values are $Q \ge 1/2$. That gives some flexibility to lower $Q_{\rm cut}$ when the $m$ of the Fourier expansion appears to be too large.

There are many open questions. Given the initial approximation, we construct a smooth Fourier expansion of the remainder, that is consistent with the data, using the ordering in which the long wave lengths modes come first. Obviously, the result of this procedure is not the only analytical function, which is consistent with the data. Which ordering of the serious expansion or other complete function system gives the smoothest approximation (smallest number of terms) consistent with the data? Do systems of monotonically increasing functions exist, which are complete for the expansion of monotonically increasing functions?

[*Kernel density estimates*]{} [@J09; @Wiki] are in spirit similar (but by no means identical) to our method. A comparison remains to be carried out.

Acknowledgments {#acknowledgments .unnumbered}
===============

This work was in part supported by the US Department of Energy under contract DE-FG02-97ER41022.

[88.]{}

B.A. Berg and R. Harris, Comp. Phys. Commun. 179 (2008) 443-448.

B.A. Berg, Markov Chain Monte Carlo Simulations and Their Statistical Analysis, World Scientific, 2004.

P.K. Janert, Gnuplot in Action: Understanding Data with Graphs, Manning Publications, 2009. See section 13.2.2.

More references can be found in Wikipedia under [ *Kernel density estimation*]{}. The [*Earth mover’s distance*]{} might be of interest as a replacement of the Kolmogorov test, if one likes to attempt a generalization of the method to more than one dimension.