2022年1月21日 星期五

機率

 

Random variable 

  1. A discrete random variable X is a quantity that can assume any value x from a discrete list of values with a certain probability.
  2. The probability that the random variable X assumes the particular value x is denoted by Pr(X = x). This collection of probabilities, along with all possible values x, is the probability distribution of the random variable X.

Ex. Sum of two dices

X=4 ==> (1,3), (2,2) (3,1)


Discrete Probability Rules
  1. Probabilities are numbers between 0 and 1: 0 ≤ Pr(X = xk) ≤ 1 for all k
  2. The sum of all probabilities for a given experiment (random variable) is equal to one: 
  3. The probability of an event is 1 minus the probability that any other event occurs: 

Ex. Sum of two dices

Pr(X=3) = 2/36     ,   Pr(X=4) = 3/36     





Cumulative Distribution Function of a Discrete Random Variable
The cumulative distribution function (CDF) of a random variable X is denoted by F(x), and is defined as F(x) = Pr(X ≤ x).

Using our identity for the probability of disjoint events, if X is a discrete random variable, we can write

where xn is the largest possible value of X that is less than or equal to x







Binomial PDF
If X is a binomial random variable associated to n independent trials, each with a success probability p, then the probability density function of X is:

where k is any integer from 0 to n. Recall that the factorial notation n! denotes the product of the first n positive integers: n! = 1·2·3···(n-1)·n, and that we observe the convention 0! = 1.


Definition: Expected Value of a Discrete Random Variable
The expected value, , of a random variable X is weighted average of the possible values of X, weight by their corresponding probabilities:

where N is the number of possible values of X.

References: 

2021年12月13日 星期一

[Linux 核心] Linux 核心功能的配置選單

 

 開啓Linux 核心功能的配置選單, 

Step1: 得先安裝ncurses 套件, 才能產生選單畫面


>> sudo apt-get install libncurses5-dev libncursesw5-dev 
若以上無法成功安裝, 則先下這個指令後再安裝套件, 應該就能順利安裝 >> sudo apt-get update --allow-releaseinfo-change  
Step2: 進入到核心原始碼的資料匣, 執行 make menuconfig 

    >> cd linux-raspberrypi-kernel_1.20190401-1/
    >>  make menuconfig






2021年12月10日 星期五

為什麼Z-Score標準化後, 會得到平均數為0, 標準差為1

 1.) How can I choose between normalization and standardization in different situations?


     資料並無特別遵從常態分佈, 則使用 Normalization , 如圖片的像素常用  Normalization 將像素值壓在0~1 之間。若資料遵從常態分佈 (很多時候會假設資料是常態分佈), 則使用Standardization (z-score)


2.) 證明: 為什麼Z-Score標準化後, 會得到平均數為0, 標準差為1 



2021年11月10日 星期三

How to save and load fine-tuned model?



 如何儲存Fine-tune BERT model 的網路權重及架構?

Custom mask layers require a config and must override get_config  ...........


1. ) 若pre-trained bert model 只是用來作為sentence embedding 的話,. 那就只儲存後面自己接的網路架構..不用整個儲存(即不必含BERT model), 因此可忽略載入pre-trained bert model . 那就回到原本傳統的model.save() , load_models('xxxx.h5')


2.) pre-trained bert model 串接自己網路架構, 一起訓練, 如果是這種的, 就用方法2

只存weight (model.save_weights), 用原本model 架構去產生一個空的new_model, 然後new_model.load_weights

model.save_weights('my_model_weights.h5')
...
new_model = <build your model with your model building code>

new_model.load_weights('my_model_weights.h5')








2021年10月21日 星期四

[JavaScript] ES7的async/await 非同步



前端瀏覽器執行JavaScript ,都是採"同步" (即函式執行完,才會往下執行它的下一行程式碼)。



若要採用非同步(Asynchronous)方式執行,可以在函數前面加入async 關鍵詞,如 async init () ,可以使函式init() 具有非同步的處理能力,即init()函內可以包含有需要等待的工作敍述,對需要等待的工作可以在該敍述前,加上await 關鍵字。





<case 左方程式區塊 >
程式呼叫了init()函式, 而在init()函式內因為遇到了await a() 這一行,故init() 會直接返回,去執行console.log('3'), 而原本await a() 的下一行, 會一直等到  a() 函式執行結束後才會開始執行。

因為await, 所以await a() 的下一行 是在未來某個時間點才又繼續執行,這就是非同步函數呼叫的概念。


<case 右方程式區塊 >

雖然 async init()  是一個可以允許非同步執行的函數,但這種寫法then()=> { },會使得console.log(3), 會在init()函式執行完才會執行。 



<!DOCTYPE html>
<html>
<body>

<h2>JavaScript async / await</h2>

<h1 id="demo"></h1>

<script>

async function myDisplay() {

      console.log('1')
    console.log('2')

  console.log('3')
}

myDisplay();
console.log('4')
console.log('5')
</script>

</body>
</html>

輸出為 ==> 1 2 3 4 5


<script>

async function myDisplay() {

      console.log('1')
       await console.log('2')

        console.log('3')
}


</script>

輸出為 ==> 1 2 4 5 3


<script>

async function myDisplay() {

await console.log('1')
await console.log('2')

  console.log('3')
}

myDisplay();
console.log('4')
console.log('5')
</script>

</body>
</html>

輸出為 ==> 1 4 5 2 3