初始化page

This commit is contained in:
veypi 2021-01-09 11:18:13 +08:00
parent 07274909e2
commit cb8dd97c4a
20 changed files with 2337 additions and 19 deletions

View File

@ -1,3 +1,4 @@
# courses
课程作业
课程作业

5
eda/edaf/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
node_modules
.DS_Store
dist
dist-ssr
*.local

13
eda/edaf/index.html Normal file
View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vite App</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>

15
eda/edaf/package.json Normal file
View File

@ -0,0 +1,15 @@
{
"name": "edaf",
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "vite build"
},
"dependencies": {
"vue": "^3.0.4"
},
"devDependencies": {
"vite": "^1.0.0-rc.13",
"@vue/compiler-sfc": "^3.0.4"
}
}

BIN
eda/edaf/public/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

15
eda/edaf/src/App.vue Normal file
View File

@ -0,0 +1,15 @@
<template>
<img alt="Vue logo" src="./assets/logo.png" />
<HelloWorld msg="Hello Vue 3.0 + Vite" />
</template>
<script>
import HelloWorld from './components/HelloWorld.vue'
export default {
name: 'App',
components: {
HelloWorld
}
}
</script>

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

View File

@ -0,0 +1,19 @@
<template>
<h1>{{ msg }}</h1>
<button @click="count++">count is: {{ count }}</button>
<p>Edit <code>components/HelloWorld.vue</code> to test hot module replacement.</p>
</template>
<script>
export default {
name: 'HelloWorld',
props: {
msg: String
},
data() {
return {
count: 0
}
}
}
</script>

8
eda/edaf/src/index.css Normal file
View File

@ -0,0 +1,8 @@
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}

5
eda/edaf/src/main.js Normal file
View File

@ -0,0 +1,5 @@
import { createApp } from 'vue'
import App from './App.vue'
import './index.css'
createApp(App).mount('#app')

2134
eda/edaf/yarn.lock Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,60 @@
# 工程数值方法与机器学习
> 2020/2021 学年
>
> 北京航空航天大学微电子学院
>
> 授课教师:王鹏教授,邢炜博士
### 作业1
简介:
> 在本次作业中你需要编写Matlab或python程序来求解一些线性方程组你需要能在电脑上运行Matlab2012a以上版本或python
请按照本文档中的说明执行任务并生成并以所需格式保存结果。 提交你的求解器代码和报告(其中包含总结和图表)。
完成A部分与B部分的所有内容。
A部分编写你自己的求解器
1. 编写一个用来求解方程 Ux = d的向后替代求解器, 其中 U 是上三角矩阵。
2. 编写一个方阵 A的LU分解求解器。 建议添加选主元步骤,它通过交换矩阵的行来避免小数字的除法,可以有效提高稳定性。
3. 结合12编写一个线性方程组的求解器。
4. 编写一个Jacobi求解器。
B部分测试你的求解器
- i 对不同的bi 求解线性方程组Axi = bi 其中A 是随机矩阵。
- 1. 创建 NxN 的随机矩阵 A. 确保 A 的行列式不接近0. 你可以通过给A加上一个对角阵来确保行列式不为零。
- 2. 创建i=1…1000 的随机向量bi
- 3. 对每个 i, 求解Axi = bi , 通过求解上面的问题并计算平方根均方误差 (RMSE, a.k.a., L2误差计算方法为假如解法器求得为x*,误差计算为 (Ax*-b)^2 的平均值 ). 记录每次求解的总计算时间。
- 4. 对 N =2,4,8,16,32,64,128,…,2048 ), 比较下面几个不同的求解器的精度和消耗时间。
- a. 你的基于LU分解的求解器,
b. 你的Jacobi求解器
c. 对矩阵 A 求一次逆 (Matlab 命令: inv(A) or A^(-1) ) 并直接计算结果inv(A)*b
d. Matlab的默认求解器 linsolve(A,B) (或者python的默认求解器).
结果应当类似下图:
(ii) 对不同的bi 求解线性方程组Axi = bi 其中矩阵A的条件数较大。
这个目标和B部分 (i) 类似除了A被设计为病态矩阵顾名思义有较大的条件数
Tips: 如果你不知道怎么生成一个病态随机矩阵可以按下面的Matlab函数来生成。你可以直接将下面的代码复制到你的Matlab程序中使用。
function A = illA(N)
A = rand(N);
A = (A + A') / 2;
[U,S,V] = svd(A);
S(1,1) = S(1,1) * 10^log(N^2);
S(end,end) = S(end,end) ./ 10^log(N^2);
A = U * S * V';
end
(iii) 对不同的bi 求解线性方程组Axi = bi 其中矩阵A是随机稀疏矩阵。
这个目标和B部分 (i) 类似除了A被设计为稀疏矩阵它的大部分元素都是0。
生成(i)(i)(iii)的图表并进行对比总结你的实验结论例如什么情况下使用什么解法器是比较合适的为什么Matlab自带的解法器效果总是最好等等。
作业提交有效时间是今天到10月23日两周后之前的任意时间。提交作业请将代码和报告打包以“课后作业1-名字-学号”命名提交。

View File

View File

View File

View File

View File

View File

View File

@ -32,7 +32,8 @@
使用神经网络进行回归预测
1. 使用共11个理化指标作为模型输入经过大量调试不同的网络结构不同的深度宽度激活函数初始化策略优化函数确定出最好的网络结构和策略。说明为什么你选择了该模型结构和策略。你对比了哪些其他的结构你觉得为什么该模型的效果比较好如何防止你的选择基准只是一个巧合用图表总结你的搜索结果列出每个模型或者经过挑选的有代表性的模型的RMSER2和模型训练时间。
1.
使用共11个理化指标作为模型输入经过大量调试不同的网络结构不同的深度宽度激活函数初始化策略优化函数确定出最好的网络结构和策略。说明为什么你选择了该模型结构和策略。你对比了哪些其他的结构你觉得为什么该模型的效果比较好如何防止你的选择基准只是一个巧合用图表总结你的搜索结果列出每个模型或者经过挑选的有代表性的模型的RMSER2和模型训练时间。
2. 进一步精调模型提升模型效果并减少过拟合例如dropoutearly stoppingbagging交叉验证L2/L1正则化等等。用图表总结你使用的精调方法的带来的效果提升。
@ -44,5 +45,29 @@
1. 选择目标1目标2 里面选得的最优秀的模型,对比他们在不同训练数据下的表现并总结,作图。
作业提交有效时间是今天到12月29日三周后之前的任意时间。
提交作业请将代码和报告打包,以“学号-姓名-UQ”命名提交至链接 [http://www.xzc.cn/YvcM5sqqVm]
作业提交有效时间是今天到12月29日三周后之前的任意时间。 提交作业请将代码和报告打包,以“学号-姓名-UQ”命名提交至链接 [http://www.xzc.cn/YvcM5sqqVm]
```shell
# 运行
cd numerical_analysis/8
python main.py
```
```
随机森林
R2: 0.475379
accuracy: 0.687500
线性回归
R2: 0.297383
accuracy: 0.587500
支持向量机
R2: 0.250542
accuracy: 0.681250
随机梯度下降
R2: -0.124188
accuracy: 0.475000
多层感知器
R2: 0.288015
accuracy: 0.637500
```

View File

@ -22,33 +22,42 @@ class WinePredict:
self.X_train = sc.fit_transform(self.X_train)
self.X_test = sc.fit_transform(self.X_test)
# 线性回归
def lr(self):
"""
线性回归
"""
lr = LinearRegression()
lr.fit(self.X_train, self.y_train)
return lr.predict(self.X_test)
# 随机森林
def rfc(self):
rfc = RandomForestClassifier(n_estimators=200)
"""
随机森林
"""
rfc = RandomForestClassifier(n_estimators=200, random_state=20)
rfc.fit(self.X_train, self.y_train)
return rfc.predict(self.X_test)
# 随机梯度下降
# 0.2 极其不稳定
def sgd(self):
"""
随机梯度下降
"""
sgd = SGDClassifier(penalty=None)
sgd.fit(self.X_train, self.y_train)
return sgd.predict(self.X_test)
# 支持向量机
# 0.23 -> 0.25
def svc(self):
"""
支持向量机
"""
svc = SVC(C=1.4, gamma=0.8, kernel='rbf')
svc.fit(self.X_train, self.y_train)
return svc.predict(self.X_test)
def mlp(self):
"""
多层感知器
"""
mlp = MLPClassifier([10, 6], learning_rate_init=0.001, activation='relu', solver='adam', alpha=0.0001,
max_iter=30000)
# 神经网络
@ -57,9 +66,10 @@ class WinePredict:
# 参数调优
def grid_search(self, model, param):
grid_svc = GridSearchCV(model, param_grid=param, scoring='accuracy', cv=10)
grid_svc.fit(self.X_train, self.y_train)
return grid_svc.best_params_
print('search %s', param)
grid = GridSearchCV(model, param_grid=param, scoring='accuracy', cv=10)
grid.fit(self.X_train, self.y_train)
print("%s: %f" % (grid.best_params_, grid.best_score_))
def gs_svc(self):
param = {
@ -67,17 +77,23 @@ class WinePredict:
'kernel': ['linear', 'rbf'],
'gamma': [0.1, 0.8, 0.9, 1, 1.1, 1.2, 1.3, 1.4]
}
print(self.grid_search(SVC, param))
self.grid_search(SVC(), param)
# {'C': 1.4, 'gamma': 0.8, 'kernel': 'rbf'}
def gs_rfc(self):
self.grid_search(RandomForestClassifier(), {
'n_estimators': [200],
'random_state': [_ for _ in range(0, 200, 10)]
})
def report(self, fc):
r = fc()
if r.dtype == 'float64' or r.dtype == 'float32':
r = r.round()
# print(classification_report(self.y_test, r))
print(fc.__name__)
print(" R2: %f" % r2_score(self.y_test, r))
print(" accuracy: %f" % accuracy_score(self.y_test, r))
print(fc.__doc__.strip())
print(" R2: %f" % r2_score(self.y_test, r))
print(" accuracy: %f" % accuracy_score(self.y_test, r))
def showXY(self):
# fig = plt.figure(figsize=(10, 6))
@ -91,5 +107,7 @@ class WinePredict:
if __name__ == '__main__':
wp = WinePredict()
wp.report(wp.lr)
wp.gs_rfc()
for i in [wp.rfc, wp.lr, wp.svc, wp.sgd, wp.mlp][:1]:
wp.report(i)
# wp.showXY()