CCC8011 Term 2 2024-2025 3Python

Java Python CCC8011 Term 2 2024-2025

Assignment 3

Question 1: Argument Maps [6 points]

Consider the following complex argument.

“18-month-old toddlers can have knowledge since they can know, for example, that the television set is on. However, if someone doesn’t understand the word ‘know’, then they cannot know what they know. Therefore, it is possible for someone to have knowledge without knowing what they know.’

a)   Assign a number to each of the statements in the argument.

b)   Use your numbering from (a) to write down, for each premise in the argument, whether it is a co-premise or an independent premise, and to write down, for each conclusion in  the argument, whether it is the main conclusion or an intermediate conclusion.

c)   Draw an argument map for the argument, reflecting your judgments in part (b).

Question 2: Hidden Premises [4 points]

Suppose that someone offers you the following argument.

An 18-month-old toddler doesn’t understand the word ‘responsibility’ .

No 18-month-old toddler can be held responsible for their actions.

a)   Propose a hidden premise that would make the argument valid if it were added to the above argument’s premises.

b)   Explain why your proposed hidden premise is in line with the Holding Hands rule and the Rabbit rule.

Question 3: Inductive Arguments [4 points]

Consider the following inductive argument.

At 3pm, Joe rolled a standard six-sided die in a fair way.

Joe’s roll of the die at 3pm resulted in it landing with an even-numbered side facing up.

(Remember, the sides of a standard six-sided die are each marked with one number from 1 to 6, and each number from 1 to 6 appears on some side.)

a)   The above argument is not inductively strong. Is it inductively weak, inductively irrelevant, or inductively bad? Explain your answer.

b)   Propose an extra premise that would make the above argument induc CCC8011 Term 2 2024-2025 Assignment 3Python tively weaker if that premise were added to the argument.

c)   Propose an extra premise that would make the above argument inductively strong (but not valid!) if that premise were added to the argument.

(When adding premises, it is helpful to think of it like this: imagine that we have learnt some new information about what happened when Joe rolled the die and you’ve added a further premise that describes this new information.)

Question 4: Common Fallacies [6 points]

For each of the following bad arguments, identify the common fallacy that best describes the mistake in that argument. You don’t need to provide justification for your answer. In each case, you must select a fallacy from the list discussed in lecture: equivocation, denying the antecedent, affirming the consequent, hasty generalization, begging the question, false dilemma, irrelevant appeal to popularity, argument ad hominem, attacking a strawman, wishful thinking, accepting a contradiction.

a)   Introducing the death penalty would result in a dramatic reduction in violent crime,

since adding capital punishment to the law would ensure that there is far less violence of a criminal nature.

b)   If Jane is the best doctor in town, then we can trust her advice. But Jane isn’t the best doctor in town. So, we can’t trust her advice.

c)   If Jane is the best doctor in town, then we can trust her advice. We can definitely trust Jane’s advice. So, she is the best doctor in town.

d)   Most forms of gambling are currently illegal in Hong Kong. But gambling is an

unavoidable part of life because we gamble every time that we cross a busy road, get married, or start a new career. So, Hong Kong’s laws on gambling should change.

e)   My sociology lecturer says that there is no evidence that atheists are more likely to

become criminals than people that belong to established religions. However, we should reject what she says, since she is herself one of the misguided people that embrace atheism.

f)    Either a person has taken a critical thinking course, or they are incapable of reasoning well. So, we can ignore all of Mary’s arguments, since she has never taken a critical thinking course         

以下是将你提供的 C 代码翻译为 Python 并实现曲线拟合功能的完整实现。我们将使用 NumPy 来进行数值计算,并使用 Matplotlib 进行可视化。 --- ### ✅ Python 实现:使用梯度下降进行多项式曲线拟合 ```python import numpy as np import matplotlib.pyplot as plt import csv # 超参数 ORDER_NUM = 3 # 多项式阶数(比如:3 表示 y = a0 + a1*x + a2*x^2 + a3*x^3) ALPHA = 0.003 # 学习率 TRAINING_LEN = int(5e4) # 训练轮数 LOSS_THRESHOLD = 1e-5 # 停止训练的损失阈值 CSV_FILE = "databank.csv" # 数据文件 # 从 CSV 文件加载数据 def load_data(filename): x, y = [], [] with open(filename, &#39;r&#39;) as f: reader = csv.reader(f) next(reader) # 跳过表头 for row in reader: x.append(float(row[0])) y.append(float(row[1])) return np.array(x), np.array(y) # 数据归一化(标准化) def data_normalizer(x, y): x = (x - np.mean(x)) / np.std(x) y = (y - np.mean(y)) / np.std(y) return x, y # 多项式函数:y = a0 + a1*x + a2*x^2 + ... + an*x^n def polynomial(a, x): return sum(a[i] * x**i for i in range(len(a))) # 损失函数(均方误差) def loss_func(y_pred, y_true): return 0.5 * (y_pred - y_true) ** 2 # 损失函数的导数 def d_loss_func(y_pred, y_true, x_term): return (y_pred - y_true) * x_term # 梯度下降更新 def gradient_descent_step(a, x, y, alpha): grad = np.zeros_like(a) loss_total = 0 for xi, yi in zip(x, y): y_pred = polynomial(a, xi) loss_total += loss_func(y_pred, yi) for i in range(len(a)): grad[i] += d_loss_func(y_pred, yi, xi**i) a -= alpha * grad return a, loss_total / len(x) # 打印并检查损失 def check_loss(a, x, y, epoch): if epoch % (TRAINING_LEN // 200) == 0: total_loss = 0 for xi, yi in zip(x, y): total_loss += loss_func(polynomial(a, xi), yi) avg_loss = total_loss / len(x) print(f"Iteration {epoch}: Loss = {avg_loss:.6f}") if avg_loss < LOSS_THRESHOLD: return True return False # 主函数 def main(): # 加载并预处理数据 x_raw, y_raw = load_data(CSV_FILE) x, y = data_normalizer(x_raw, y_raw) # 初始化参数 a = np.random.randn(ORDER_NUM) # 训练模型 for i in range(TRAINING_LEN): a, _ = gradient_descent_step(a, x, y, ALPHA) if check_loss(a, x, y, i): print("Loss threshold reached, stopping training.") break # 可视化拟合结果 x_plot = np.linspace(min(x), max(x), 100) y_plot = [polynomial(a, xi) for xi in x_plot] plt.scatter(x, y, label="Data") plt.plot(x_plot, y_plot, color=&#39;red&#39;, label=f"Fitted Curve (Order {ORDER_NUM})") plt.legend() plt.xlabel("x") plt.ylabel("y") plt.title("Polynomial Curve Fitting using Gradient Descent") plt.grid(True) plt.show() # 打印最终系数 print("Fitted coefficients:") for i, ai in enumerate(a): print(f"a{i} = {ai:.6f}") if __name__ == "__main__": main() ``` --- ### 🔍 代码解释: 1. **加载数据**: - 使用 `csv.reader` 读取 CSV 文件,假设数据格式为两列(x 和 y)。 2. **数据预处理**: - 对 `x` 和 `y` 进行标准化处理(减去均值,除以标准差),提高梯度下降的稳定性。 3. **多项式函数**: - `polynomial(a, x)` 表示拟合函数 $ y = a_0 + a_1 x + a_2 x^2 + \dots $ 4. **损失函数**: - 使用均方误差(MSE):$ \text{loss} = 0.5 (y_{pred} - y_{true})^2 $ 5. **梯度下降**: - 每次迭代计算所有样本的梯度,更新参数 `a`。 6. **可视化**: - 使用 `matplotlib` 显示原始数据点和拟合曲线。 7. **终止条件**: - 每隔一定次数检查损失,若低于阈值则提前停止。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值