Sunday, January 9, 2022

AnaPoker Development Notes

\(  s1 (m,n,p,q,r)  = \dfrac{52*51*50*49*48}{120} - \dfrac{m(m-1)(m-2)(m-3)(m-4)}{120}   \)

\(  s2 (m,n,p,q,r)  = \dfrac{(m-1)(m-2)(m-3)(m-4)}{24}  - \dfrac{n(n-1)(n-2)(n-3)}{24}\)

\(  s3 (m,n,p,q,r)  = \dfrac{(n-1)(n-2)(n-3)}{6}  - \dfrac{p(p-1)(p-2)}{6}\)

\(  s4 (m,n,p,q,r)  = \dfrac{(p-1)(p-2)}{2}  - \dfrac{q(q-1)}{2}\)

\(  s5 (m,n,p,q,r)  = (q-1)  - r \)

\(  t0 (m,n,p,q,r)  = \dfrac{52*51*50*49*48}{120} \)

\(  t1 (m,n,p,q,r)  = \dfrac{(m-1)(m-2)(m-3)(m-4)(m-5)}{120}   \)

\(  t2 (m,n,p,q,r)  = \dfrac{(n-1)(n-2)(n-3)(n-4)}{24}   \)

\(  t3 (m,n,p,q,r)  = \dfrac{(p-1)(p-2)(p-3)}{6}   \)

\(  t4 (m,n,p,q,r)  = \dfrac{(q-1)(q-2)}{2}   \)

\(  t5 (m,n,p,q,r)  = r  \)


1. Calculate the combinations of all the poker 5-card hands.

2. Derive the indexing method for all the combinations (m,n,p,q,r)

3. Write functions to generate all the combinations from the highest rank.

4. Create the <key.value> pair for the combinations.

5. Create the 21 combinations of the 5-card index for the 7-card hands.

6. Find the highest rank in the 21 combinations.

7. Calculate the estimated win rate after the flop and the turn


Notes:

1. Card number from 52 to 1 by the order AKQJT98765432

2. The total rank of 5-card hands is 7462.

3. Ranks

  • 1: Royal Flush
  • 2~10: Straight Flush
  • 11~166: Four of a Kind 
  • 167~322: Full House
  • 323~1599: Flush
  • 1600~1609: Straight
  • 1610~2467: Three of a Kind
  • 2468~3325: Two Pair
  • 3326~6185: One Pair




Friday, January 15, 2021

Arduino 101 Setup

If the driver installation of Arduino101/Genuino101 fails, try restarting Windows with "Advanced startup options" (and Disable Driver Signature Enforcement/F7)

Arduino IDE:

Sketchbook location: the folder to hold libraries (downloaded/user defined) and other projects.  It's defined in [Preferences].


Thursday, October 1, 2020

lifecycle investing

(1) Present Value of Future Lifetime Savings = (Net) Current Savings + Future Lifetime Savings

(2) Samuelson Share

(3) Maximum Leverage Ratio 2:1

Ideal Investment Target = Present Value of future lifetime savings * Samuelson Share


Case A:

Current Savings: 60,000

Future Lifetime Savings: 400,000

Samuelson Share 40% (conservative)


( 60,000 + 400,000 ) * 40% = 184,000  

Saturday, May 2, 2020

Functional Programming Notes

Actions:
   Anything that depends on when it is run, or how many times it is run, or both, is an action.
Calculations
   Calculations are computations from input to output. They always give the same output when you give them the same input.
Data
   Data is recorded facts about events.
   * Serializable, Compare for equality, Open for interpretation

Notes:
   pp.11 Once computers talk over networks, things get chaotic. Messages arrive out of order, are duplicated, or never arrive at all. Making sense of what happened when, basically modeling change over time, is very important, but also difficult. The more we can do to eliminate a dependency on when or how many times, the easier it will be to avoid serious bugs.
   Data and calculations do not depend on how many times they are run or accessed. By moving more of our code into data and calculations, we sweep that code clean of the problems inherent in distributed systems.

   pp.13  three important ideas are 1) distinguishing actions, calculations, and data, 2) using first-class abstractions, and 3) building composable models.

   pp.62 Ch.4 Extracting calculations from actions

Q: Are reusability and testability the only concerns that functional programming helps with?
A: Absolutely not! FP does help with those, but there’s a lot more out there. We’ll get to concurrency, architecture, and data modeling by the end of the book. Also, FP is a big field and this book cannot cover all of it.

Copy-on-Write
   Make a copy, Modify the copy, Return the copy
   Making copies allows us to keep the original and the copy without worry that it will change. This is great for implementing undo/ redo.

JavaScript Object Copy
var item_copy = Object.assign({}, item);


Monday, March 16, 2020

感染 COVID-19 的機率


感染 COVID-19 病毒的機率 跟 與帶原者接觸的 時間 空間環境 和 個人的防護設備 有關
基本上 接觸帶原者的機會愈大  感染機率就愈高
口罩到底有沒有效  與口罩的種類也有關

根據 一些研究 和 疫情的報導  基本上口罩還是有一定的防護效果

個案案19 與家人朋友聚餐  感染的機率接近三成
與個案案34 中的醫院患者接觸過的 清潔工和護理師 也有多人感染  可見在一般病房中被感染的機率相當高 即使有戴口罩
與帶原者同住的家人被感染的機率也相當高

以下 文中單位接觸史被感染的機率 為假設值 僅供模擬說明用.口罩為一般醫療用口罩

假設餐廳聚餐  其中有一帶原者  聚餐一小時 被感染的機率為 \(50\%\)  那聚餐二小時 被感染的機率就變為 \( 1-(1-0.5)^2 = 75\% \) (也就是 \(100\%\) 減去 兩小時都不被感染的機率)

假設密閉空間中
   帶原者與另一人相處  都未戴口罩  一小時內被感染的機率為 50%  那相處兩小時被感染的機率也接近 \(75\%\)

   如果只有帶原者有戴口罩 假設一小時內被感染的機率可以降為 \(2.5\%\)
   如果只有非帶原者有戴口罩 假設一小時內被感染的機率可以降為 \(5\%\)
   如果兩人都有戴口罩 假設一小時內被感染的機率可以降為 \(0.5\%\)

   如果 有 10 單位(帶原者-小時)接觸史  那相對的被感染的機率為
      只有帶原者有戴口罩  \( 1-(1-0.025)^{10}= 22.367\% \)
      只有非帶原者有戴口罩 \( 1-(1-0.050)^{10}= 40.126\% \)
      兩人都有戴口罩 \( 1-(1-0.005)^{10}= 4.889\% \)

所以可以得知 如果只有單方面戴口罩 那接觸一多  在密閉空間 被感染的機率也會相當大

另外 如果假設在開放空間 民眾保持適當的距離(1.8m以上) 接觸過一單位帶原者小時 如果兩方都有戴口罩 被感染的機率為 \(0.05\%\)    那即使有十單位的接觸史 被感染的機率也只有 \(0.499\%\)



假設 一千萬人口中 有二萬個帶原者(未被隔離)  如果平均每天接觸過 一千人單位小時
平均每月的單位接觸史為  \(  \dfrac{2*10^4}{10^7}*1000*30= 60  \)

都在密閉空間 被感染的機率為
    都戴口罩 \(25.974\%\)
    僅帶原者戴口罩 \(78.108\%\)

都在開放空間 都戴口罩 被感染的機率為 \(2.956\%\)

由此可知 當族群中 已有多數人感染  要盡量避免長時間與多數人群聚在密閉的空間

另一方面 坐電梯時 如果只有自己一個人  但因為內部空氣不流通  如果之前搭乘的人有帶原者  那也是 等同於有接觸到帶原者  同理 大眾交通工具 也是一樣

Thursday, March 5, 2020

Riemann Zeta Function

\( \zeta (s)  = \dfrac{1}{1-2^{-s}} . \dfrac{1}{1-3^{-s}} . \dfrac{1}{1-5^{-s}} ... \dfrac{1}{1-p^{-s}} ...\)

\( \eta (s)  = (1-2^{1-s}) \zeta (s) , 0 < s < 1\)

\( \eta (s)  = \dfrac{1-2^{1-s}}{1-2^{-s}} . \dfrac{1}{1-3^{-s}} . \dfrac{1}{1-5^{-s}} ... \dfrac{1}{1-p^{-s}} ...\)

\( \rho (s,p)  = (1-p^{1-s}) \zeta (s)\)

\( \rho (s,q)  = (1-q^{1-s}) \zeta (s)\)

\( \rho (s,p) - \rho (s,q)  = (q^{1-s}-p^{1-s}) \zeta (s)\)

\( p=7, q=11 \)
\( \rho(s,7) - \rho(s,11) =- \dfrac{7}{7^s} + \dfrac{11}{11^s} -\dfrac{7}{14^s} - \dfrac{7}{21^s} + \dfrac{11}{22^s} - \dfrac{7}{28^s} + \dfrac{11}{33^s}... + \dfrac{4}{77^s}...\)

calculate to \( m \) terms, \( m=p*q*k \)

\( \rho (s,p) - \rho (s,q)  = q\sum\limits_{n=1}^{pk}{\dfrac{1}{(nq)^s}} - p\sum\limits_{n=1}^{qk}{\dfrac{1}{(np)^s}}\)

Wednesday, December 18, 2019

PyTorch - Installation through Conda

1. Install Anaconda Python 3.7
   64-Bit Graphical Installer (Download, Run)

2. Install PyTorch (
Windows 64 CUDA 10.1 Python 3.7)
   Launch Anaconda Prompt

   conda install pytorch torchvision cudatoolkit=10.1 -c pytorch

3. Test Installation
   from __future__ import print_function
   import torch
   x = torch.rand(5, 3)
   print(x)

   import torch
   torch.cuda.is_available()

   *if ModuleNotFoundError: with "import torch"

   example: Windows 64 CUDA 10.1 Python 3.7
   pip install https://download.pytorch.org/whl/cu101/torch-1.3.1-cp37-cp37m-win_amd64.whl

   *if torch.cuda.is_available() is FALSE
    then try update the GPU driver

4. Launch jupyter notebook in Anacoda Prompt

5. test jupyter
   at the right corner of Files click New|Python 3