# FAQ for Homeworks <font color="#00EEEE"> ## 下次出作業的改進事項(麻煩助教填寫) ### 共同事項 - 如何明確界定抄襲?使用 LLM 的規範? - 抄襲相關 -- (信宏)本次抓抄襲是使用Gradescope的"程式碼相似性"功能,可以上傳sample code後,再讓程式判斷同學間的程式碼相似度高低,且會自動排除與sample code相似的內容。 -- 這個系統可以抓出"單純改變數名稱"與"調換函式順序"的抄襲。即在該系統眼中,只改變數名稱,或僅調換數個函式的順序,仍會被抓到有抄襲疑慮。 -- 以HW3(DP)為例,只要兩人的程式碼相似度被系統判斷為高於50%,我就會人工確認是否有抄襲的情況。**我認為我這次採用偏寬鬆的判定方式:只有當三個子題中,至少一題達到95%以上完全相同(改變數名稱也視為相同),才會被認定為抄襲**。我認為仍有一些同學可能是用LLM,請它將另一位同學的程式碼"改寫"後,就沒有被我抓到抄襲 -- 往後建議作法:可以和同學公告「我們會比對各位繳交的程式碼,確認程式碼之間的相似程度。且僅修改變數名稱也會被視為抄襲!」 - LLM 相關 -- (信宏)關於LLM,我個人認為"如果同學能夠自己下prompt,自己得到由LLM生成的程式碼,並且沒有去拿其他同學由LLM生成的程式碼來使用,就不判為抄襲"。類似"可以跟其他人討論 prompt 要怎麼下,但是不可以將生成後的結果複製給他人,生成結果相當於自己寫的code" -- 今年有發生以下幾個情形,往後可以告知同學「以下例子是否會被判定為抄襲」: (1) 數位同學共用一個ChatGPT帳號,並"一起下prompt,生成同一結果",導致繳交code幾乎相同 (2) 數位同學共用一個ChatGPT帳號,並"生成一個不錯的策略(內含可以tune的參數)"後,各自tune參數再繳交(後來因為他們每人要tune的參數名稱都一樣故被我抓抄襲,但每個人tune出來的參數值不同) (3) 一位同學使用ChatGPT帳號生成結果後,再傳給其他同學(爾後聲稱"這個是GPT生成的結果",並非"同學想的內容"故不算抄襲) (4) 找到公開repo的code後,再丟給LLM請它生成符合作業要求的code(這樣做理應不會被抓到抄襲,但他與另一名同學的程式碼高度相似,猜測是他將結果傳給另一位同學。只是另一位同學完全未回覆,故無法得知詳細情況) ### HW 1 - 題目的答案盡量只有一個,而且介於 0 ~ 0.2 之間,比較符合現實情況 - (信宏)可以將部分測資改為 hidden,在作業截止後再公布答對情形 (今年是一繳交就會知道所有測資的對錯) - (信宏)由於HW1的程式碼較短(可不超過10行便完成),較難抓抄襲情形 ### HW 2 - 需要加入另一階段來放出驗證資料,以讓同學進行自我測試,並瞭解資料的特性。 ### HW 3 - 題目過於簡單,都能由 DP 來解。需要出一小題是無法使用 DP 來解。 - (信宏)整體而言,我反而認為這次題目不會簡單,反而是**有點偏難**。即使是有最佳解的 DP 演算法,但在這次繳交作業的 233 人中,只有分別(105,44,53)人在(myAction01, myAction02, myAction03)獲得最高return rate,其中包含25位滿分的同學。由此可知,同學對於較複雜的DP(myAction02)掌握度仍然不佳 - myAction03 可用其他非DP且有效率的方式得到最佳解,故反而更多人在 myAction03 做得最好 -- 非DP方式:用sliding window,假設連續K天是從第0~第K天 / 第1~第K+1天...等,再將前後兩段DP後,取全域最佳 - 建議可以將HW3再調整得簡單一點:myAction01改為單一股票;myAction02、myAction03分別為今年的myAction01(M個股票)、myAction02(M個股票+至少K天全持有現金) - (信宏)這次的公開與隱藏測資長度不同,導致有些同學在隱藏測資超時。建議公開&隱藏測資的長度相同、且資料型態相同(小數點位數相同) - (信宏)關於time & memory limit:Gradescope上有一些選項可以直接使用。Time Limit有10/20/30/40分鐘四個選項;Memory Limit有0.75GB/1.5GB/3GB/6GB (但這可能不只有待測function會占用,main function可能也會占用這個memory limit的一部分)。若是直接使用Gradescope的預設設定,可以較省事 -- 作業一開始公開測試時,是額外寫一個thread來監控time & memory limit。只是後來這麼做會導致**部分同學的程式嚴重超時**(尤其是使用遞迴解的同學)。因此在測隱藏測資時,將該thread拿掉,僅用Gradescope的預設設定(20分鐘/1.5GB)來運作(因為公開測試時同學都有達到限制,故隱藏測試也就不會超時) ### HW 4 ### 期末考 - (信宏) 期末考時,可以提醒同學帶有log功能的計算機 (有些較簡易的計算機無法按log) - (信宏) 若是需要鎖IP並用NTU COOL的線上測驗來考試,除了開放COOL與myntu的網域以外,還須開放**COOL內渲染latex所使用的網域**,否則latex公式會直接無法渲染並顯示原樣(比如:"$1 \le x \lt 3$"會顯示為 "1 \le x \lt 3") - (信宏) 若考完試後,有某幾題要開放其他答案也判對,NTU COOL的線上測驗只能重改選擇題,**無法重改填空題**。填空題需要手動修正分數,非常麻煩。建議對於有要求小數點位數的答案,有無補零都給分,並將全部可能的答案都先加進去,可以減少日後爭議 -- 比如:答案是5,但題目要求要到小數點以下第二位,原先需要回答5.00才會判對,再開放"5"與"5.0"都判對,並**需要在同學作答前就把這些答案都加進去該題的可接受答案中** -- 但對於陣列類型的答案(如:[2 3 4 4 2 5 1 3]),還是會有很多同學格式錯誤(如:[2,3,4,4,2,5,1,3], [2, 3, 4, 4, 2, 5, 1, 3],(2 3 4 4 2 5 1 3)......逐繁不及備載)。建議可以減少這類型的格式,改為詢問"陣列內所有元素的和"等單一數字之答案會比較不容易有爭議 </font> ## HW 1 1. Q: 有看到 hackmd 上面有提到,root 可能有很多個,想請問這套批改系統已經會自動考量多個 root 的情況嗎? A: 多個解的部分,所有範圍內的解都會算對。 ## HW 2 (呂紹嵊) ### 中文版 1. Q: 如果使用DNN之類的神經網路,繳交作業的時候是不是要再多附上權重等等,而不只是myStrategy.py而已 A: 我們的autograder會將程式移到你的directory中,所以如果要讀取其他檔案(例如DNN的權重檔案),請確保這些檔案也一併繳交。 2. Q: 想請問繳交的function ```myStrategy(pastPriceVec, currentPrice, windowSize, alpha, beta)```之中,裡面的參數都可以自己做調整嗎? 還是要按照範例程式碼裡面寫的alpha跟beta? A: 函式裡面的參數都是可以自己調整的,也可以根據自己的喜好使用想要的技術指標或其他的模型來進行預測。 3. Q: 最後在跑結果的python版本,gpu(若有使用)的機器與其空間? A: python版本是3.10,自動批改器上的資源是4.0 CPU、6.0GB RAM,**沒有GPU可供使用**。 4. Q: 使用的套件版本? A: 目前批改器下支援的套件及版本只有```pandas==2.2.2 numpy==2.1.1 scipy==1.14.1 statsmodels==0.14.2 ta==0.11.0 scikit-learn==1.5.1 lightgbm==4.5.0```,原則上無法使用其他套件,如有必要新增其他套件請來信詢問。 5. Q: HW2是根據gradescope上的排行榜來給分嗎,還是會使用隱藏測資或是其他方法計分,否則使用亂數碰運氣或甚至用暴力去搜測資等方式都會取得非常好的回報率? A: 到時候的評分標準不會以 public score 作為依據而是**以未公開的 private test data 去評斷同學們的策略並依照排名作為成績的衡量標準**。 6. Q: 想請問最終評測時使用的evaluation implementation程式碼? A: 到時候的evaluation code是跟同學現在看到的```rrEstimate.py```是同一份,只是改input讓他變成另外一份不包含先前public dataset的csv檔。 7. Q: private data 的部份是 open data 所代表的股票往後的歷史價格嗎?如果是的話,我可以把 open data hardcode 成一個 dictionary 放在我的 Python code 裡面嗎? A: **Private data 是延續 public dataset 後的歷史價格**,可以依照自己的需求進行預估。 8. Q: 在本地端用```rrEstimate.py```測試時有測出結果,但上傳時卻一直得到 0。想請問是否是我的程式有用到global variable的關係? A: 我們 **autograder 會跑多次```rrEstimate()```來確保同學沒有使用一些作弊的手段或是亂數產生action**,如果兩次跑出來的結果不一樣就會顯示0分,所以我想應該是你的 global variable 沒有考慮到會有跑兩次```rrEstimate()```需要重新 init 的情況,把這個更正之後確保跑多次的結果會是一樣的應該就會顯示出正常的結果。 9. Q: 為什麼我在本地端測試可以跑出正確結果,上傳的時候卻顯示0分? A: 通常都是檔名出錯,**我們只會從你名為 ```myStrategy.py``` 的程式中 import 名為 ```myStrategy()``` 的 function ,所以請確保你上傳的檔案有符合這些需求**。 10. Q: 請問最後會根據哪一個繳交的檔案做為評分依據? A: 會是同學在作業截止前**最後一份上傳到 Gradescope 的 code**。 ### English Version 1. Q: If I use a neural network such as DNN, do I need to submit additional files like the weights, or is submitting just `myStrategy.py` sufficient? A: Our autograder will move the code to your directory, so if you need to load additional files (e.g., DNN weight files), please make sure to submit those files as well. 2. Q: For the function `myStrategy(pastPriceVec, currentPrice, windowSize, alpha, beta)`, can I modify the parameters, or do I have to use the example parameters for `alpha` and `beta` as shown in the template? A: The parameters in the function can be adjusted to your preference. You can also use any technical indicators or models you want to make predictions. 3. Q: What Python version and machine specifications (e.g., GPU and memory) will be used for the final evaluation? A: The Python version is 3.10, and the autograder machine has 4.0 CPUs, 6.0 GB of RAM, and **no GPU** is available. 4. Q: What package versions are supported? A: The supported packages and versions on the grader are: `pandas==2.2.2 numpy==2.1.1 scipy==1.14.1 statsmodels==0.14.2 ta==0.11.0 scikit-learn==1.5.1 lightgbm==4.5.0`. No other packages are allowed unless you request and receive approval by email. 5. Q: Will HW2 be graded based on the leaderboard on Gradescope, or will there be hidden test data or other scoring methods? Otherwise, brute force or random guessing might achieve a high return. A: The grading will not be based on the public score. Instead, we will use private test data that is not disclosed to the students. Your **strategy will be evaluated based on this private test data, and rankings will determine the final scores**. 6. Q: What will be the final evaluation implementation code? A: The evaluation code used for the final test is the same as the one you are currently using, `rrEstimate.py`, except the input will be changed to a new CSV file that doesn't include the public dataset. 7. Q: Is the private data just a continuation of the open dataset with future historical prices? If so, can I hardcode the open data into a dictionary in my Python code? A: **Yes, the private data is a continuation of the public dataset**, and you can use that information to estimate future prices. 8. Q: I got results locally using `rrEstimate.py`, but when I upload the code, it always returns 0. Could this be because I'm using global variables? A: **Our autograder runs `rrEstimate()` multiple times to ensure that students are not using random actions or cheating.** If your results differ across runs, the score will be 0. It seems like your global variables are not being reinitialized properly when `rrEstimate()` runs multiple times. Fix this issue to ensure consistent results across runs, and you should get a proper score. 9. Q: Why does my code produce the correct result when tested locally, but shows 0 points after uploading? A: It's usually due to an incorrect file name. **We will only import the function named ```myStrategy()``` from a file named ```myStrategy.py```, so please ensure that the file you upload meets these requirements**. 10. Q: Which submitted file will be used for grading? A: It will be the **last code file uploaded to Gradescope before the assignment deadline**. ## HW 3 (沈信宏) (Last Updated: 2024/11/11) ### 中文版 #### 關於程式邏輯 1. 初始資金為何? A: 初始資金為 1,000 元。 2. 需不需要考慮四捨五入/整數購股相關問題? (例如: 一開始有 100 元,且一股 11 元,在不考慮手續費的情況下,可買到 9 股還是 9.090...股?) A: 不需要。以上述例子而言,可以買到 9.090...股。同理,若一開始有 10 股,且一股為 15.05 元,則可獲得 150.5 元而非 151 元 (在不考慮手續費的情況下)。簡言之,所有金額、股票數皆以 "**floating-point number**" 處理。 3. 若要買某一檔股票,但餘額不足以購買這麼多,則程式會如何處理? A: 程式會直接以你的所有餘額去購買。但**若是餘額為 0 又想買股票,程式會產生 Error 並視為繳交失敗**。 4. 若要賣某一檔股票,但將所有股票變現後,又無法獲得在[d,a,b,z]中設定的這麼多錢(z),則程式會如何處理? A: 程式會直接將你該檔的所有股票賣掉。但**若是並無該檔股票卻又想賣,程式會產生 Error 並視為繳交失敗**。 5. 計算 return rate 的方式為何? A: 系統會直接將最後一天的所有持有股票賣掉後 (亦會扣除 transaction fee),再計算 return rate。 6. actionMat 的天數 d 是否有限制? A: 請注意**輸出的 actionMat 中,天數 $d$ 需為單調遞增**。例如:若已經進行第 $10$ 天的交易,則第 $0$~$9$ 天的交易將不再被接受。**若發生此類情形,程式會產生 Error 並視為繳交失敗**。 7. 非遞減單調遞增意味著每天可以進行多筆交易嗎?如果是的話我同一天可以先賣一些股票然後把盈餘拿去買其他股票嗎? A: 可以。同一天的交易次數並無任何限制。(但是否有必要進行多次交易?) 8. m,n範圍是多少? A: 根據作業的說明: "The TA will use a hidden dataset of 4 stocks with a similar time span to evaluate your trading strategies."在隱藏測資中,stocks數仍為4,而days會是約1300天。**若你的程式是使用遞迴的方式來進行,請特別留意python預設的遞迴層數上限為1000。對於隱藏測資來說可能會不夠。若須增加遞迴層數上限,可參考下方範例程式:** ```python import sys sys.setrecursionlimit(5000) # 增加遞迴層數上限至5000 ``` 9. DP有唯一解,private 拿滿,但public return 卻沒拿滿,程式應該不能算正確? #### 關於繳交 1. 需要繳交的檔案為? A: 僅需繳交一個檔案 "[myAction.py](http://mirlab.org/jang/courses/fintech/homework/2024/optimumTradingStrategy/exampleCode/myAction.py)"。裡面需要有 myAction01、myAction02、myAction03 三個函式。 若有使用到其他檔案,亦可一併上傳,批改系統會將所有繳交的檔案放在同一個資料夾內。 2. 繳交的方式為? A: 繳交至 Gradescope 的 "HW03" 上。**其餘繳交方式皆不予接受,並以 $0$ 分計算。** 3. 在 myAction02 與 myAction03 中,60 秒的時間限制是單次呼叫時間還是合計時間? A: 單次呼叫時間。對於 K = 200, 300, 400 的三個 case 而言,皆各有 60 秒的時間執行。 4. 若 Gradescope 上顯示成績為 $100.0$,是否即代表繳交成功? A: 是的。成績顯示 $100.0$ 代表繳交的程式通過所有測試,包含 time limit 與 memory limit。 **相對地,成績顯示 $0.0$ 代表繳交的程式未通過測試,且我們不會以這些程式進行最終評分。** 5. 最終成績是否就是 Gradescope 上顯示的成績? A: **不是**。Gradescope 上顯示成績為 $100.0$,僅表示繳交成功 (若顯示 $0$ 分則代表繳交失敗)。此外,HW3 的最終成績會以其他隱藏測資來決定,故**亦不會直接以 Gradescope 上顯示的排行榜計算成績**。 6. 最終成績會以哪一個繳交檔案進行計算? A: 會以最後繳交的檔案進行排名並計分。若想要使用前幾次繳交的檔案來計分,需在 deadline 前重新繳交一次該檔案。 #### 關於程式錯誤/繳交錯誤 1. 若我的程式在某一個 case 出現 "Time Limit Exceeded" 或 "Memory Limit Exceeded" 等 Error,則會是僅有該 case 不計分,還是整個程式皆不計分? A: 只要某一個 case 出現 Error,就是**整個程式皆不計分**。 2. 程式出現 Assertion Error? A: 請確認你的程式在執行時,是否出現以下情形: (1) 已無現金,卻又想買股票 (2) 已無某一檔股票,卻又想賣出該檔股票 (3) 已進行完第 $d$ $(d\ge1)$天的交易,卻又想進行第 $d-i$ $(1\le i\le d)$天的交易 (4) 欲進行交易的天數 $(d)$ 為負數 (5) 欲進行交易的金額 $(z)$ 為負數或 $0$ 3. 繳交結果失敗,並出現 "No value returned from your code."? A: 請先確認是否有以下情形: (1) 繳交檔名為 "[myAction.py](http://mirlab.org/jang/courses/fintech/homework/2024/optimumTradingStrategy/exampleCode/myAction.py)",且這一個檔案內有三個函式:myAction01、myAction02、myAction03。 (2) myAction01 有且僅有兩個傳入參數 (priceMat & transFeeRate),myAction02 與 myAction03 有且僅有三個傳入參數 (priceMat & transFeeRate & K) (3) 程式未超過時間限制與記憶體限制 **建議作法**: 繳交前,先使用**未修改過的** [rrEstimateOpen02.py](http://mirlab.org/jang/courses/fintech/homework/2024/optimumTradingStrategy/exampleCode/rrEstimateOpen02.py) 檔案測試一次 #### 關於抄襲規定 1. 你們是怎麼判定是否抄襲的? A: 只要兩人以上的"程式碼"相似(包含但不限於: 程式邏輯相似但僅更改變數名稱/僅對調函數位置等),即視為抄襲。 2. 我所寫的程式碼與 sample code 類似,這樣會不會被算是抄襲? A: 不會。與 sample code 類似的內容不會被當作抄襲。 3. 如何避免抄襲? A: 與同學討論時,**不要將你所寫的程式碼給任何人看**。此外,也**不要在繳交期限截止前(包含遲交時段)將你的程式碼放在如GitHub等有公開權限的開放空間**。 ### English version #### About Program Logic 1. What is the initial capital? A: The initial capital is 1,000 units. 2. Do we need to consider rounding or whole-number stock purchases? (For example: starting with 100 units and each share costs 11 units, can 9 shares be purchased or 9.090... shares, assuming no transaction fees?) A: No, we do not need to consider rounding. In the given example, 9.090... shares can be purchased. Similarly, if starting with 10 shares valued at 15.05 units each, the total would be 150.5 units instead of 151 units (assuming no transaction fees). In short, all amounts and stock quantities are handled using **floating-point numbers**. 3. What happens if I attempt to buy a stock, but the remaining balance is insufficient for the purchase? A: The program will use your entire available balance to purchase as many shares as possible. However, **if your balance is 0 and you attempt to buy stocks, the program will raise an error and the submission will be marked as failed**. 4. What happens if I attempt to sell a stock, but after liquidating all shares, the amount earned doesn’t match the required amount? (the value z in [d, a, b, z]) A: The program will sell all shares of the specified stock. However, **if you attempt to sell a stock you do not own, the program will raise an error, and the submission will be marked as failed**. 5. How is the return rate calculated? A: The system will calculate the return rate by selling all held stocks on the final day (transaction fees are deducted). 6. Is there a limit on the number of days (d) in actionMat? A: Please note that **the number of days (d) in the output actionMat must be monotonically increasing**. For example, if trading on day 10, trades on days 0–9 will no longer be accepted. **If this occurs, the program will raise an error, and the submission will be marked as failed**. 7. Does "monotonically increasing" imply that multiple transactions can be made within a single day? If so, can I sell some stocks during the day and use the proceeds to buy other stocks? A: Yes, there is no limit on the number of transactions within the same day. (However, is it necessary to make multiple transactions?) 8. What is the range of $m$ and $n$ ? A: According to the description of HW3: "The TA will use a hidden dataset of 4 stocks with a similar time span to evaluate your trading strategies."In the hidden test cases, the number of stocks remains 4, while the number of days will be approximately 1300. **If your program uses recursion, please note that Python's default recursion depth limit is 1000, which might be insufficient for the hidden test cases.** If you need to increase the recursion depth limit, you can refer to the example code below: ```python import sys sys.setrecursionlimit(5000) # Increase the recursion depth limit to 5000 ``` #### #### About Submission 1. What files need to be submitted? A: Only "[myAction.py](http://mirlab.org/jang/courses/fintech/homework/2024/optimumTradingStrategy/exampleCode/myAction.py)" needs to be submitted. It should include three functions: myAction01, myAction02, and myAction03. If any additional files are used, they may also be submitted; the grading system will place all submitted files in the same folder. 2. How should the file(s) be submitted? A: Submit on Gradescope under "HW03". **Submissions via any other method will not be accepted and will result in a score of zero.** 3. In myAction02 and myAction03, is the 60-second time limit for each individual call or the total execution time? A: It is the time limit for each individual call. For the cases where K = 200, 300, and 400, each case has a 60-second execution time limit. 4. If the score shown on Gradescope is 100.0, does that confirm a successful submission? A: Yes. A score of 100.0 means that the submitted code has passed all tests, including time and memory limits. **On the other hand, a score of 0.0 indicates that the code did not pass the tests, and we will not use it for final grading.** 5. Is the final score the same as the score displayed on Gradescope? A: **No**. A score of 100.0 on Gradescope only indicates successful submission (a score of 0 indicates a failed submission). Additionally, HW3's final score will be determined by a separate hidden test set, so **the leaderboard on Gradescope does not directly determine the final grade**. 6. Which submitted file will be used for the final score? A: The last submitted file will be used for ranking and scoring. If you wish to use an earlier submission, you must resubmit that file before the deadline. #### About Program Errors/Submission Errors 1. If my program encounters an error like "Time Limit Exceeded" or "Memory Limit Exceeded" on a specific case, will only that case be unscored, or will the entire program be unscored? A: If any single case produces an error, **the entire program will receive no score**. 2. What should I do if the program encounters an Assertion Error? A: Please verify if any of the following issues occur during program execution: (1) Attempting to buy stocks with no available cash (2) Attempting to sell a stock that you do not own (3) Attempting a trade for day $d$ $(d \ge 1)$ but then attempting a trade for day $d-i$ $(1 \le i \le d)$ (4) Attempting a trade on a negative day (d) (5) Attempting a trade with a negative or zero amount (z) 3. Submission failed with the message "No value returned from your code"? A: Please check the following issues: (1) The submitted file is named "[myAction.py](http://mirlab.org/jang/courses/fintech/homework/2024/optimumTradingStrategy/exampleCode/myAction.py)" and contains three functions: myAction01, myAction02, and myAction03. (2) myAction01 has exactly two input parameters (priceMat & transFeeRate), and myAction02 and myAction03 each have exactly three input parameters (priceMat & transFeeRate & K). (3) The program does not exceed the time and memory limits. **Suggested Practice**: Before submitting, test your code once with the **unmodified** [rrEstimateOpen02.py](http://mirlab.org/jang/courses/fintech/homework/2024/optimumTradingStrategy/exampleCode/rrEstimateOpen02.py) file. #### About Plagiarism Policy 1. How do you determine if plagiarism has occurred? A: If the "code" of two or more individuals is similar (including, but not limited to: similar program logic with only variable names changed, functions reordered, etc.), it will be considered plagiarism. 2. My code is similar to the sample code; will this be counted as plagiarism? A: No. Content similar to the sample code will not be considered plagiarism. 3. How can I avoid plagiarism? A: When discussing with classmates, **do not show your code to anyone**. Besides, **do not post your code in publicly accessible spaces like GitHub before the submission deadline (including late submission period)**. ## HW 4 (蕭睆文 Wen Hsiao) (Last Updated: 2024/12/03) ### 中文版 Q1: 請問是否可以import package? A1: 不行。本次作業的設計不需要同學載入額外的套件即可完成。 Q2: Problem 4 是否需要將初始設定算一次add? A2: 原本的設定是從INFINITY開始加。但與老師的投影片初始值為P不一致。已於11/27更新autograder,讓它與老師的投影片一致。 Q3: 我該怎麼在本地端測試我的程式? A3: `echo [problem#] [test_input] [expected_output] | python main.py private_key`,細節請參考`main.py`。例如: ```bash % echo "0" | python main.py 31 ``` Q4: Problem 5 最佳化問題綜合討論。 A4: 實務上 Double (shift) 的速度會比 point addition 快一點點。因此最佳化後 (double + addition) 的次數一定會小於或等於未最佳化前的結果。 如果相等,使用較少的 point addition 的演算法較佳。 Q5: $d$ 的範圍為何? A5: $d$ 是 $F_p$ 的值,範圍介於 $[0, p)$之間。詳見投影片第18頁。 Q6: $0*G$ 為什麼不是 $(0,0)$? A6: 因為$(0,0)$點不在這個橢圓曲線上。$0*G$會落回$F_p$的原點$O$,我們稱之為 zero point,又叫 point at infinity (`ellipticcurve.INFINITY`)。詳見投影片第15頁。 Q7: 批改程式使用的ecdsa是那個版本? A7: 批改系統上安裝的是 ecdsa v0.19.0. 然而我們只使用到`ellipticcurve.PointJacobi` 和 `ellipticcurve.INFINITY`. 因此,不同版本的package理論上不影響本次作業。 Q8: Problem 6 中的 `sign_transaction()` 輸入和輸出資料型別是什麼? A8: `(int, int) = sign_transaction(int, str, callback function, callback function, callback method)` 值得留意的是,hashID是一個hash過的transaction ID。詳細資訊可參考`main.py`中的註解,你可以了解`main.py`如何呼叫你的程式。 Q9: Gradescope上"PASS"是什麼意思? A9: 代表你的程式通過了這組測資的驗證。 Q10: 有任何時間限制嗎? A10: 批改系統設定了10分鐘的上限。然而本次作業所有題目應該都能在1秒內跑完,應該不太需要擔心時間的限制。 Q11: `callback_randint` 一定會是 `random.randint` 嗎? A11: 同學可以直接假設是`random.randint`。事實上,我們可能會將它override成其它函式,方便取得同學使用的random nonce。但無論如何,函式的prototype都不會改變。 Q12: Problem 5中,如果我們想將兩個點相加,有規定其中一個點一定要是$P$或$-P$嗎? A12: 沒有限制。Problem 5請同學開發一個最佳化的演算法來計算$n*P$。目前批改系統上的演算法被視為最佳解。如果你認為你的演算法比批改系統還要好,但批改系統判斷你是錯的,請在deadline結束後送出重新批改申請。我們會進行人工批改,一旦證明你的演算法是對的,並且比批改系統的演算法還要更好,我們會跟老師報告,並提供額外的Bonus。這個設計是希望同學不必著重在猜測系統使用的演算法是什麼,擔心使用了對同的算法而被判錯,可專心在最佳化演算法上。別管批改系統怎麼做,想辦法找到更好的演算法打敗批改系統吧。 :) Q13: Problem 5 可以提供參考測資嗎? A13: 31P在傳統演算法上需要4次doubles和4次additions。但在最佳化演算法上,只需要5次doubles和1次加法。關於"最佳解"的定義,請參考Q&A Q4 and Q12 in "[FAQ for Homeworks](https://hackmd.io/@rogerjang/rJbDrP000#English-version18)." (待回覆)Q14: Promble 5 可以先使用多個算法,再從中挑出最好的回傳嗎? ### English version Q1: Should I import other packages? A1: No. This assignment was designed without the need of non-build-in packages. Q2. Should the initial configuration in Problem 4 be calculated as one addition? A2. The original problem was designed to start from INFINITY, which is inconsistent with the lecture slide.  The Autotrader was updated on November 27.  Now, the consistency holds. Q3: How can I test my program on my desktop? A3: `echo [problem#] [test_input] [expected_output] | python main.py private_key` For more information, please refer to `main.py`. For example, ```bash % echo "0" | python main.py 31 ``` Q4: Discussions on Problem 5. A4: Practically, the double (shift) operation is slightly faster than point addition, so the optimized number of ((double + addition) should be smaller or equal to the non-optimized one. If the equality hold, the algorithm using less pint addition is better. Q5: What is the value range of $d$? A5: $d$ is a value under field $F_p$, so it should be ranged at $[0, p)$. For more information, please refer to lecture slide page 18. Q6: What 0*G is not (0,0)? A6: $(0,0)$ is not a point on Koblitz curve (secp256k1). $0*G$ point to the origin of $F_p$, denoted $O$. We call it zero point or point at infinity (`ellipticcurve.INFINITY`). For more information, please refer to lecture slide page 15. Q7: Which version of ecdsa package are used for grading? A7: Our grading machine uses ecdsa v0.19.0. However, only `ellipticcurve.PointJacobi` and `ellipticcurve.INFINITY` in this library is used. The version might not be an issue to this problem. Q8: What are the input and return types of `sign_transaction()` in Problem 6? A8: `(int, int) = sign_transaction(int, str, callback function, callback function, callback method)` Be noted that hashID is a hashed transaction ID. For more detailed information, please refer to the comments in `main.py`, including how your implemented function will be invoked. Q9: What is the meaning of PASS on Gradescope? A9: PASS means your result for this test data is correct. Q10: Is there any time constraint on this homework? A10: A 10-minute bond was set on the grading server. However, all problems in this assignment are supposed to be completed in 1 second. Time constraints should not be a concern in this assignment. Q11: Will the `callback_randint` be fixed to `random.randint`? A11: You can view it as fixed to `random.randint`. Actually, we might change it with another overridden function to know which random nonce you are using but keeping the same prototype of the callback function. Therefore, you can directly assume that it is just the `random.randint`. Q12: In Problem 5, when adding two points, is one of the points mandatory to be $P$ or $-P$? A12: No, we don't have this limitation. Problem 5 requests you to implement an optimal algorithm to calculate $n*P$. Our optimized solution was considered the optimal. If you believe your solution is optimal(better) than the one grader uses but failed by the judge system, feel free to submit your code for regrading after the deadline. We will manually review your code and give you a bonus if the algorithm is proven correct. We hope this mechanism makes you feel at ease without worrying about the algorithm grader used. Just focus on the optimal solution as best as you can. :) Q13: Can you give me a sample and its corresponding optimization result? A13: $31P$ takes 4 doubles and 4 additions in the traditional double_and_add algorithm. However, the optimized algorithm takes only 5 doubles and 1 addition. As to the definition of "optimal," please refer to Q&A Q4 and Q12 in "[FAQ for Homeworks](https://hackmd.io/@rogerjang/rJbDrP000#English-version18)."