M♪o 之學習筆記本《卯》基件︰【䷊】無平不陂

派生碼訊

卯 兔

泰:小往大來,吉亨。

彖曰:泰,小往大來,吉亨。則是天地交,而萬物通也﹔上下交,而其志同也。內陽而外陰,內健而外順,內君子而外小人,君子道長,小人道消也。

象曰:天地交泰,后以裁成天地之道,輔相天地之宜,以左右民。

傳說 泰 泰的古意是,用淨水潑身,以祈吉祥。 否否為唾棄,吐口水。昨兒才剛 教學 學觀摩,今兒學長們就為著課綱的『理念性』與『實務性』熟重?講說內容應該多深多淺??吵得不可開交。後來學堂先生來了,斷之以『並重』和『兩可』。《 易 》易有︰『臨,至于八月有凶』。正所謂『臨將入泰,觀才出否』,因而推知『八月有凶』,只不過不知道這『凶』會落在哪兒罷了!!

 

派︰同學們,《 數 》數說︰

150px-Pierre_Francois_Verhulst

Logistic-curve.svg

P(t) = \frac{1}{1 + \mathrm e^{-t}}

350px-Logit.svg

\operatorname{logit}(p)=\log\left( \frac{p}{1-p} \right)

220px-Linear_regression.svg

Y \approx F(X, \Box)

Maple_logistic_plot_small

x_{n+1} = r x_n(1 - x_n)

Logistic_map_animation

Logistic_map_phase_plot_of_x-n+1--x-n-_vs_x-n-

相圖

512px-LogisticMap_BifurcationDiagram

Logistic_map

Logistic_map_scatterplots_large

LogisticCobwebChaos
定點震盪混沌

200px-Ganzhi001

300px-NewtonIteration_Ani

一八三八年,比利時數學家 Pierre François Verhulst 發表了一個『人口成長』方程式,

\frac{dN}{dt} = r N \left(1 - \frac {N}{K} \right)

,此處 N(t) 是某時的人口數,r 是自然成長率, K 是環境承載力。求解後得到

N(t) = \frac{K}{1+ C K e^{-rt}}

,此處 C = \frac{1}{N(0)} - \frac{1}{K} 是初始條件。 Verhulst 將這個函數稱作『logistic function』,於是那個微分方程式也就叫做『 logistic equation』。假使用 P = \frac{N}{K} 改寫成 \frac{dP}{dt} = r P \left(1 - P \right),將它『標準化』,取 CK = 1r = 1,從左圖的解答來看, 0 < P <1,也就是講人口數成長不可能超過環境承載力的啊!

如果求 P(t) 的反函數,得到 t = \ln{\frac {1 -P}{P}},這個反函數被稱之為『Logit』函數,定義為

\operatorname{logit}(p)=\log\left( \frac{p}{1-p} \right) , \ 0 < p < 1

,一般常用於『二元選擇』,比方說『To Be or Not To Be』的『機率分佈』,也用於『迴歸分析』 Regression Analysis 來看看兩個『變量』在統計上是『相干』還是『無干』的ㄡ!假使試著用『無窮小』 數來看 \log\left( \frac{\delta p}{1-\delta p} \right) = \log(\delta p) \approx - \infty\log\left( \frac{1-\delta p} {\delta p}\right) = \log(\frac{1}{\delta p}) = \log(H) \approx \infty,或許更能體會『兩極性』的吧!!

一九七六年,澳洲科學家 Robert McCredie May 發表了一篇《Simple mathematical models with very complicated dynamics》文章,提出了一個『單峰映象』 logistic map 遞迴關係式 x_{n+1} = r x_n(1 - x_n), \ 0\leq x_n <1。這個遞迴關係式很像是『差分版』的『 logistic equation』,竟然是產生『混沌現象』的經典範例。假使說一個『遞迴關係式』有『極限值x_{\infty} = x_H 的話,此時 x_H = r x_H(1-x_H),可以得到 r{x_H}^2 = (r - 1) x_H,於是 x_H \approx 0 或者 x_H \approx \frac{r - 1}{r}。在 r < 1 之時,『單峰映象』或快或慢的收斂到『』; 當 1 < r < 2 之時,它很快的逼近 \frac{r - 1}{r};於 2 < r < 3 之時,線性的上下震盪趨近 \frac{r - 1}{r};雖然 r=3 也收斂到 \frac{r - 1}{r},然而已經是很緩慢而且不是線性的了;當 r > 1 + \sqrt{6} \approx 3.45 時,對幾乎各個『初始條件』而言,系統開始發生兩值『震盪現象』,而後變成四值、八值、十六值…等等的『持續震盪』;最終於大約 r = 3.5699 時,這個震盪現象消失了,系統就步入了所謂的『混沌狀態』的了!!

連續的』微分方程式沒有『混沌性』,『離散的』差分方程式反倒發生了『混沌現象』,那麼這個『量子』的『宇宙』到底是不是『混沌』的呢??回想之前『λ 運算』裡的『遞迴函式』,與數學中的『定點』定義,『單峰映象』可以看成函數 f(x) = r \cdot x(1 - x) 的『迭代求值』︰x_1 = f(x_0), x_2 = f(x_1), \cdots x_{k+1} = f(x_k) \cdots。當 f^{(p)} (x_f) = f \cdots p -2 times f \cdots f(x_f) = x_f,這個 x_f 就是『定點』,左圖中顯示出不同的 r 值的求解現象,從有『定點』向『震盪』到『混沌』。如果我們將『 logistic equation』 改寫成 \Delta P(t) = P(t + \Delta t) - P(t) = \left( r P(t) \left[ 1 - P(t) \right]  \right) \cdot \Delta t,假使取 t = n \Delta t, \Delta t = 1,可以得到 P(n + 1) - P(n) =  r P(n) \left[ 1 - P(n) \right],它的『極限值P(H) \approx 0, 1,根本與 r 沒有關係,這也就說明了兩者的『根源』是不同的啊!然而這卻建議著一種『時間序列』的觀點,如將 x_n 看成 x(n \Delta t), \ \Delta t = 1,這樣 \frac{x[(n+1) \Delta t]  - x[n \Delta t]}{\Delta t} = x_{n+1} - x_n 就說是『速度』的了,於是 (x_n, x_{n+1} - x_n) 便構成了假想的『相空間』,這可就把一個『遞迴關係式』轉譯成了一種『符號動力學』的了!!

在某些特定的 r 值,這個『遞迴關係式』有『正確解』 exact solution,比方說 r=2 時,x_n = \frac{1}{2} - \frac{1}{2}(1-2x_0)^{2^{n}},因為 x_0 \in [0,1),所以 (1-2x_0)\in (-1,1),於是 n \approx \infty \Longrightarrow (1-2x_0)^{2^{n}} \approx 0,因此 x_H \approx \frac{1}{2}。再者由於『指數項2^n 是『偶數』,所以此『符號動力系統』不等速 ── 非線性 ── 而且不震盪的逼近『極限值』的啊。

對於 r=4 來講,它的解是

x_{n}=\sin^{2}(2^{n} \theta \pi)

,此處 \theta 是『初始條件』參數,可由 \theta = \tfrac{1}{\pi}\sin^{-1}(x_0^{1/2}) 來決定。假使 \theta 是『有理數』,那麼 \sin^{2}(2^{n} \theta \pi) 這個『周期函數』,多次『迭代』後就可能產生『極限循環』;要是 \theta 是『無理數』,它有一個『不循環』的無窮小數成份,這個『符號動力系統』就彷彿是『隨機亂動』一般,因此才說它是『混沌』的啊!假使思考 \theta = \tfrac{1}{\pi}\sin^{-1}(x_0^{1/2}) 是一個『有理數』的機會,怕是很渺茫的吧!!

之後,有人『擴張』了 r=4 方法的『解決範圍』,考慮了如下的方程式

y_{n+1} = a_2 {y_n}^2 + a_1 y_n + a_0, \ a_0 = \frac{(a_1 - 4)(a_1 + 2)}{4 a_2},它的解是

y_n(\omega) = \frac{1}{a_2} \left( 2 \cos{\omega 2^{n}} - \frac{a_1}{2} \right)

並且探討了對於『整數p,當滿足 f^{(p)} (x) = x定點』時的『情況』,在此我們就不多說的了。一般來說『非線性』方程式﹐很少能夠有『正確解』,通常多半需要依賴『數值分析』工具去『了解』它的內蘊,在此再次提醒讀者『樹莓派』上的『Mathematica』的『實用性』,並且給出兩個相關的鍊結給有興趣的讀者

logistic equation
……

, 真真是,夏日午後雷雨多,把我們當『鴨子』,叫我們『聽雷』的哩!雖是這麼想,那裡頭還彷彿真有『名堂』的ㄟ,即使聽無,就當是異地觀光!!

 

☆ 編者言說明

自『卯』的首篇 ䷁ 起, M♪o 學習筆記之篇章序次,改成了『十二爻辰』,或許是因應課綱變了,不宜再用『五行序』。十二爻辰又稱作『十二消息卦』,是一年四季流轉,天地給予『消息』。所謂『八月有凶』,蓋指『臨』䷒ 經過『泰』䷊ ,而後『否』䷋ ,再到『觀』 ䷓ ,中有八個月。由『臨』月始一,八月入『否』。此篇可苦了編者,九天九地,收尋《庫文》《網文》以應其《 數 》數。

 

生 ︰同學們,要深入理解『入出針』,必須確實明白『取樣原理』, 《 技 》技講︰

Sampling (signal processing)

Signal_Sampling

 

In signal processing, sampling is the reduction of a continuous signal to a discrete signal. A common example is the conversion of a sound wave (a continuous signal) to a sequence of samples (a discrete-time signal).

A sample is a value or set of values at a point in time and/or space.

A sampler is a subsystem or operation that extracts samples from a continuous signal.

A theoretical ideal sampler produces samples equivalent to the instantaneous value of the continuous signal at the desired points.

Theory

Sampling can be done for functions varying in space, time, or any other dimension, and similar results are obtained in two or more dimensions.

For functions that vary with time, let s(t) be a continuous function (or “signal”) to be sampled, and let sampling be performed by measuring the value of the continuous function every T seconds, which is called the sampling interval.[1]  Then the sampled function is given by the sequence:

s(nT),   for integer values of n.

The sampling frequency or sampling rate, fs, is the average number of samples obtained in one second (samples per second), thus fs = 1/T.

Reconstructing a continuous function from samples is done by interpolation algorithms. The Whittaker–Shannon interpolation formula is mathematically equivalent to an ideal lowpass filter whose input is a sequence of Dirac delta functions that are modulated (multiplied) by the sample values. When the time interval between adjacent samples is a constant (T), the sequence of delta functions is called a Dirac comb. Mathematically, the modulated Dirac comb is equivalent to the product of the comb function with s(t). That purely mathematical abstraction is sometimes referred to as impulse sampling.[2]

Most sampled signals are not simply stored and reconstructed. But the fidelity of a theoretical reconstruction is a customary measure of the effectiveness of sampling. That fidelity is reduced when s(t) contains frequency components whose periodicity is smaller than 2 samples; or equivalently the ratio of cycles to samples exceeds ½ (see Aliasing). The quantity ½ cycles/sample × fs samples/sec = fs/2 cycles/sec (hertz) is known as the Nyquist frequency of the sampler. Therefore s(t) is usually the output of a lowpass filter, functionally known as an anti-aliasing filter. Without an anti-aliasing filter, frequencies higher than the Nyquist frequency will influence the samples in a way that is misinterpreted by the interpolation process.[3]
……

ㄚ˙ㄏㄚˋ,AHHA 過去本不是『白老鼠』,焉知 ── 莊子 ──,焉不知 ── 惠施 ──『魚出游』的『感覺』?!

果然然,『拔茅茹,以其夤,』但求『征吉。』??

 

碼 ︰研 習 。今天時候晚了,不實作,就研習一點什麼是『取樣』之概念。何謂『平』與『陂』的呢?如果從螞蟻和大象的『觀點』來看,能夠一樣嗎??光以『相對大小』來講,大象以為『平』的,對螞蟻來說,可以『陂』陡的不得了。再說螞蟻的一步『小』,大象的足距『大』,要是用幾何上的『曲線』比喻,螞蟻『沿』著曲線走,大象一『踏』就一段。如此螞蟻的『足跡』即使是『離散』也較『符合』那條『曲線』,大象『疏闊』之『步履』恐不存那條『曲線』之形的了。此《 圖

debouce-graph

的精義,就是表達開關『兩態取值』之『取樣』觀。不同的取樣『速度』 ── 頻率 ──,所讀到的『情況』可以不同。『高』頻的似『螞蟻』,『低』頻的如『大象』。若是忽略了『彈跳』的暫態現象,恐會引發『開』或『關』狀態之『誤判』,不可不慎。

同學們可以參考下面程式

pi@raspberrypi ~ $ sudo -s
root@raspberrypi:/home/pi# python3
Python 3.2.3 (default, Mar  1 2013, 11:53:50) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import RPi.GPIO as GPIO
>>> from time import sleep
>>> GPIO.setmode(GPIO.BCM)
>>> 
>>> 按鍵一 = 23
>>> 頻率 = 100
>>> 數據列 = []
>>> 
>>> def 等入高針按鍵取值(針碼, 取值列, 頻率=100, 資料=100):
...     GPIO.setup(針碼, GPIO.IN, pull_up_down = GPIO.PUD_UP)
...     while True:
...         if GPIO.input(針碼) == 0:
...             for i in range(資料):
...                 取值列.append(GPIO.input(針碼))
...                 sleep(1.0/頻率)
...             break
... 
>>> 等入高針按鍵取值(按鍵一, 數據列)
>>> 數據列
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
>>> len(數據列)
100
>>> 測試列=[]
>>> 等入高針按鍵取值(按鍵一, 測試列, 頻率=500, 資料=500)
>>> len(測試列)
500
>>> 數據列
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
>>>

,試著探討『彈跳現象』。

 

行 ︰豈可『妄自菲薄』,定要『發憤圖強』。☿

 

訊 ︰☿ 今方知所謂『無平不陂』矣。