111 年 國立成功大學製造資訊與系統研究所丙組《計算機概論》
第 1 題
Briefly describe the following terms.
(a) Embedded System. (10%)
(b) Genetic Algorithm. (10%)
登入後即可作答並保存紀錄。
本題主要在測試考生對於計算機概論中兩個重要概念的理解程度,分別是嵌入式系統與基因演算法。
(a) 嵌入式系統 (Embedded System)
核心觀念: 嵌入式系統是一種專門設計用於執行特定功能,且通常內嵌於較大系統中的計算機系統。
詳解:
嵌入式系統是一種專用目的的計算機系統,它被設計來執行單一或有限數量的任務,並且通常是某個更大系統的一部分。與通用計算機(如個人電腦)不同,嵌入式系統通常具有高度的整合性、低功耗、實時性要求以及固定的軟硬體配置。它們廣泛應用於各種設備中,例如:
- 消費電子: 智慧型手機、數位電視、DVD播放器、微波爐、洗衣機。
- 汽車: 引擎控制單元 (ECU)、防鎖煞車系統 (ABS)、導航系統。
- 工業控制: 生產線自動化設備、機器人、監控系統。
- 醫療設備: 心臟起搏器、血糖儀、醫療影像設備。
- 通訊設備: 路由器、交換機、基地台。
嵌入式系統的關鍵特徵包括:
- 專用性: 為特定應用而設計。
- 資源受限: 通常具有有限的處理能力、記憶體和儲存空間。
- 實時性: 許多嵌入式系統需要嚴格的時間限制來響應事件。
- 高可靠性: 經常在嚴苛的環境下運行,需要高度穩定性。
- 硬體/軟體整合: 軟體通常緊密耦合於特定的硬體。
【答案】 嵌入式系統是一種為執行特定功能而設計的計算機系統,通常內嵌於更大的設備中,具有資源受限、實時性、高可靠性等特點,廣泛應用於各種電子設備和自動化系統。
(b) 基因演算法 (Genetic Algorithm, GA)
核心觀念: 基因演算法是一種受自然選擇和遺傳學啟發的啟發式搜尋演算法,用於尋找優化問題的最佳或近似最佳解。
第 2 題
You are asked to develop a manufacturing application on a four-core Rasperry Pi (RPi) device for
collecting data from an equipment with data generation rate A. The collected data will be sent to a
REST API in a remote server through Internet. Assume a core of the RPi can collect A data records
per second. For keeping the RPi system stable, your manufacturing application does not place the
collected data in the RPi's storage (i.e.. sending back the collected data in the real-time manner).
Please write Python-like pseudo codes to collect/send data with parallel processing capacity. Also
describe limitations of your algorithm if necessary. (20%)
登入後即可作答並保存紀錄。
本題主要測試考生對於並行處理、網路通訊以及資源受限系統的設計能力,特別是在嵌入式系統(Raspberry Pi)上實現即時數據收集與傳輸。
核心觀念: 使用多執行緒或多進程來實現並行處理,以提高數據收集和傳輸的效率,並考慮到嵌入式系統的穩定性和資源限制。
詳解:
題目要求設計一個應用程式,在一個四核心的 Raspberry Pi (RPi) 上,從設備收集數據,並將數據即時傳輸到遠端伺服器的 REST API。RPi 的每個核心每秒能收集 A 筆數據記錄。為了保持系統穩定,數據不儲存在 RPi 的本地儲存中,而是即時傳輸。我們需要編寫類似 Python 的偽代碼,並描述其限制。
設計思路:
由於 RPi 有四個核心,並且需要同時進行數據收集和數據傳輸,我們可以利用多執行緒 (multithreading) 或多進程 (multiprocessing) 來實現並行處理。由於是 Python-like 偽代碼,我們可以使用類似 threading 或 multiprocessing 的概念。
- 數據收集 (Data Collection): 每個核心負責從設備收集數據。由於每個核心可以處理 A 筆數據/秒,總共可以處理 4A 筆數據/秒。
- 數據傳輸 (Data Transmission): 數據收集後需要即時傳輸到遠端 REST API。網路傳輸是一個 I/O 密集型操作,可能會阻塞 CPU。因此,數據傳輸應該與數據收集分開進行,以便不影響收集的效率。
- 緩衝區 (Buffer): 為了解耦數據收集和數據傳輸,以及處理兩者之間的速率差異,我們可以使用一個共享的緩衝區(例如一個佇列)。收集執行緒將數據放入緩衝區,傳輸執行緒從緩衝區取出數據並傳輸。
Python-like 偽代碼:
我們將使用類似 Python 的 threading 和 queue 模組來實現。
第 3 題
(a) Draw an ER diagram according to the following requirements. (10%)
A friend asks you to help her design a database to model doctors' offices across Tainan. She described
requirements as follows. You need to finish the ER diagram and define a number of constraints to
ensure that you model the semantics of an office as closely as possible.
Make sure that you do not impose additional constraints not defined by the model.
• A doctor has a name, mobile phone number (possibly multiple phone), and a unique badgeld
for been identified. A doctor may manage more than one office.
• An office is identified by its officeID and has address and phone numbers (possibly more than
one phone #). An office contains one or more exam rooms and may be managed by at most
one doctor.
• An exam room can be identified by its room number, and the office that it is in.
• A patient has SSN, name, and phone number. Each patient is uniquely identified by their SSN.
• When a patient visits an office, he or she has a consultation with a doctor in an examination
room. The start time and the end time need to be recorded for a consultation.
(b) Transform the ER diagram of the above doctors' office system into the relational schenia. (10%)
登入後即可作答並保存紀錄。
核心觀念
本題評量資料庫系統(Database Systems)的核心設計流程,包含兩個主要部分:
- 實體關聯模型(Entity-Relationship Model, ER Model)之建構:
- 實體型態(Entity Sets):辨認系統中的強實體(Strong Entity)與弱實體(Weak Entity)。
- 屬性特性(Attributes):辨識單值屬性、多值屬性(Multivalued Attributes,如多支電話)、主鍵(Primary Key)及局部鍵(Partial Key / Discriminator)。
- 關聯型態(Relationship Sets):
- 基數比限制(Cardinality Constraints):一對一()、一對多()、多對多()。
- 參與限制(Participation Constraints):部分參與(Partial Participation)與完全參與(Total Participation)。
- 關聯度數(Degree of Relationship):二元關聯(Binary Relationship)與三元關聯(Ternary Relationship)。
- ER 圖轉關聯綱要(Relational Schema Mapping):
- 強實體與弱實體的表格轉換規則。
- 多值屬性必須獨立成表的正規化原則(以符合 1NF)。
- 一對多關聯(以「外來鍵 Foreign Key」置於 端)與多對多/多元關聯(獨立成表並以參與實體之主鍵組成複合主鍵)的轉換規範。
解題方法
(a) ER 圖設計與語意分析
-
實體集與屬性分析:
- Doctor(強實體):
- 主鍵:。
- 屬性:。
- 多值屬性:(雙橢圓表示)。
- Office(強實體):
- 主鍵:。
- 屬性:。
- 多值屬性:(雙橢圓表示)。
- ExamRoom(弱實體):
- 題目敘述「An exam room can be identified by its room number, and the office that it is in」,說明診間無法單獨以診間號碼識別,必須依附於診所,因此為弱實體(雙矩形表示)。
- 局部鍵(Partial Key):(虛底線)。
- 識別關聯(Identifying Relationship):(雙菱形表示,從 ExamRoom 到 Contains 為雙線代表完全參與)。
- Patient(強實體):
- 主鍵:。
- 屬性:, 。
- Doctor(強實體):
-
關聯集分析與限制:
- 管理關聯(Manages):
- 參與實體: 與 。
- 基數比:一位醫生可管理多間診所(),一間診所最多由一位醫生管理(,即 或 )。因此為 。
- 參與度:診所「may be managed by at most one」,非所有診所都有管理者,為部分參與(單線);非所有醫生都有管理診所,為部分參與(單線)。
- 診所包含診間關聯(Contains):
- 參與實體: 與 。
- 一間診所包含一個或多個診間;弱實體 存在必定依附於 (Total Participation,雙線)。
- 看診諮詢關聯(Consultation):
- 題目描述「When a patient visits an office, he or she has a consultation with a doctor in an examination room. The start time and the end time need to be recorded...」。
- 涉及 、、 三者在特定診所與診間進行的活動,故建構為三元關聯(Ternary Relationship):。
- 關聯屬性:, 。
- 限制:病人、醫生、診間皆可參與多次不同時段的諮詢,基數為 。
- 管理關聯(Manages):
-
ER 圖繪製(陳氏標記法 Chen's Notation):
(name) (badgeId) ((mobilePhone))
\ | /
\ | /
+--------------------+
| Doctor |
+--------------------+
| 1 | M
| |
(Manages) |
| N |
+--------------------+ |
| Office | |
+--------------------+ |
| 1 | \ |
| | \ |
| (address) ((phone))|
| |
(Contains) | (startTime) (endTime)
|| | \ /
|| N | \ /
+====================+ | [Consultation]
| ExamRoom |----|----------------/ \
+====================+ M | \
| | \ P
(roomNo) \--------------------------+
|
+--------------------+
| Patient |
+--------------------+
/ | \
(SSN) (name) (phone)
(註:圖中 [] 為實體,[[]] 為弱實體,() 為單值屬性,(()) 為多值屬性,__ 為主鍵,-- 為局部鍵,|| 代表完全參與 Total Participation)
(b) 關聯綱要轉換(Relational Schema Mapping)
遵循 ER 轉換至關聯綱要之標準演算法:
- 強實體轉換:
第 4 題
You work on a financial-technology (FinTech) project and are assigned to write a linear regression
model to predict stock trends. Assume the linear regression model is in the form: y=C-t²+D-t+E.
Given stock price samples (y) in five time units (t) as follows:
| t | 0 | 1 | 2 | 3 | 4 |
|---|---|---|---|---|---|
| y | 600 | 580 | 570 | 610 | 620 |
(a) Write Python-like pseudo codes to find the best-fitting coefficients for the linear regression model.
(10%)
(b) Analyze the computation complexity of your answer in (a). (10%)
(c) At t = 5, the stock price is 666. Write Python-like psuedo codes to calculate the residue that
your model makes. (10%)
登入後即可作答並保存紀錄。
核心觀念
本題考查二次多項式迴歸(quadratic polynomial regression)與最小平方法(least squares)。
題目中的模型可解讀為:
雖然模型對 是二次式,但對未知係數 仍是線性的,因此屬於「線性迴歸模型」。
對每一筆資料 ,預測誤差為:
最小平方法的目標,是使所有平方誤差總和最小:
令 分別對 偏微分並設為零,即可得到正規方程式(normal equations)。
解題方法
(a) 求最佳擬合係數
資料如下:
| 0 | 1 | 2 | 3 | 4 | |
|---|---|---|---|---|---|
| 600 | 580 | 570 | 610 | 620 |
建立設計矩陣:
係數向量為:
最小平方法的矩陣解為:
先計算所需總和:
因此正規方程式為:
由第三式:
代入第二式:
代入第一式:
由 ,得:
所以最佳擬合模型為:
Python-like pseudo code 如下:
第 4 題
(b) Analyze the computation complexity of your answer in (a). (10%)
登入後即可作答並保存紀錄。
本題要求分析 Part (a) 中求解係數的計算複雜度。
核心觀念: 計算複雜度通常用大 O 符號 (Big O notation) 來表示,關注演算法隨著輸入規模增長而增長的趨勢。在線性回歸中,輸入規模通常是指數據點的數量 。
詳解:
在 Part (a) 中,我們採用了最小平方法來求解係數 和 。
偽代碼中的主要計算步驟包括:
-
數據預處理: 計算 。這需要遍歷所有 個數據點,對每個點進行一次平方和一次加法。
- 計算 對於每個點: 次乘法。
- 計算 對於每個點: 次加法。
- 總體:。
-
計算總和: 遍歷所有 個數據點,計算 , , , 。
- 在循環中,我們執行:
- 一次加法 (
sum_t += t_val) - 一次乘法和一次加法 (
sum_t_squared += t_val**2) - 一次加法 (
sum_y_prime += y_prime_val) - 一次乘法和一次加法 (
sum_t_y_prime += t_val * y_prime_val)
- 一次加法 (
- 這些都是常數時間的操作。對於 個點,總共需要 次這樣的循環。
- 總體:。
- 在循環中,我們執行:
-
計算係數: 使用正規方程組的解法計算 和 。
- 計算分母
denominator = n * sum_t_squared - sum_t**2:涉及幾次乘法、減法。常數時間 。 - 計算分子和係數 和 :涉及幾次乘法、減法、除法。
- 計算分母
第 4 題
(c) At t = 5, the stock price is 666. Write Python-like psuedo codes to calculate the residue that
your model makes. (10%)
登入後即可作答並保存紀錄。
核心觀念
本題的核心觀念為機器學習與迴歸分析中的**殘差(Residual,題目作 Residue)**定義與模型預測評估:
-
殘差的數學定義:
在統計學與迴歸模型(Regression Model)中,殘差定義為「實際觀察值(Actual/Observed Value)」與「模型預測值(Predicted Value)」之間的差值。在時間點 的殘差 計算公式為:
其中:- 為時間點 的真實值(Ground Truth)。本題在 時,。
- 為已訓練模型(Model)在輸入時間點 時所輸出的預測股價。
-
殘差方向性約定:
依據標準統計學定義,殘差方向一律為 (真實值減去預測值)。若實際值高於預測值,殘差為正(Underestimation);反之為負(Overestimation)。
解題方法
-
變數與參數設定:
- 設定時間變數:。
- 設定真實股價:。
-
模型推論(Inference):
- 呼叫題組前小題所建立之預測模型物件(例如
model),將特徵 傳入預測函式,取得模型預測值 。
- 呼叫題組前小題所建立之預測模型物件(例如
-
計算殘差:
- 將真實股價與預測股價相減:。
-
偽代碼實作(Python-like Pseudo-code):
第 5 題
Consider the database relation with schema: Book(Bnumber, Title, Publisher, Price, Pub-
lished Year). Write a SQL statement to retrieve the first five publishers with most amount of books
and the number of books published by them, where books published after 2016 are considered and
publishers whose the average book price is less than 550 dollars are discarded. (10%)
登入後即可作答並保存紀錄。
核心觀念
本題考查 SQL 的分組聚合與查詢結果排序,涉及:
WHERE:先篩選符合條件的資料列。GROUP BY:依出版社分組。COUNT(*):計算每家出版社出版的書籍數量。AVG(Price):計算每家出版社的平均書價。HAVING:篩選分組後的聚合結果。ORDER BY ... DESC:依書籍數量由多至少排序。FETCH FIRST 5 ROWS ONLY:取排序後的前五筆資料。
本題的條件順序是:
- 只考慮出版年份晚於 2016 年的書。
- 依
Publisher分組。 - 計算各出版社的書籍數量與平均價格。
- 捨棄平均價格低於 550 的出版社。
- 依書籍數量遞減排序。
- 取前五家出版社。
解題方法
WHERE 必須放在 GROUP BY 前,用來先限制資料範圍;AVG(Price) 是分組後才能計算的聚合值,因此平均價格條件必須放在 HAVING,不能放在 WHERE。
SELECT
Publisher,
COUNT(*) AS BookCount
FROM Book
WHERE "Published Year" > 2016
GROUP BY Publisher
HAVING AVG(Price) >= 550
ORDER BY BookCount DESC
FETCH FIRST 5 ROWS ONLY;
若使用支援 LIMIT 的資料庫,也可寫成:
SELECT
Publisher,
COUNT(*) AS BookCount
FROM Book
WHERE "Published Year" > 2016
GROUP BY Publisher
HAVING AVG(Price) >= 550
ORDER BY BookCount DESC
LIMIT 5;
其中:
"Published Year" > 2016:只保留 2017 年以後出版的書。GROUP BY Publisher:將書籍按照出版社分組。COUNT(*) AS BookCount:計算每個出版社符合年份條件的書籍數。HAVING AVG(Price) >= 550:保留平均書價至少為 550 的出版社。ORDER BY BookCount DESC:書籍數量最多的出版社排在前面。FETCH FIRST 5 ROWS ONLY或LIMIT 5:取前五家出版社。