初始化page
This commit is contained in:
parent
07274909e2
commit
cb8dd97c4a
5
eda/edaf/.gitignore
vendored
Normal file
5
eda/edaf/.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
node_modules
|
||||||
|
.DS_Store
|
||||||
|
dist
|
||||||
|
dist-ssr
|
||||||
|
*.local
|
||||||
13
eda/edaf/index.html
Normal file
13
eda/edaf/index.html
Normal 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
15
eda/edaf/package.json
Normal 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
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
15
eda/edaf/src/App.vue
Normal 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>
|
||||||
BIN
eda/edaf/src/assets/logo.png
Normal file
BIN
eda/edaf/src/assets/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.7 KiB |
19
eda/edaf/src/components/HelloWorld.vue
Normal file
19
eda/edaf/src/components/HelloWorld.vue
Normal 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
8
eda/edaf/src/index.css
Normal 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
5
eda/edaf/src/main.js
Normal 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
2134
eda/edaf/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
60
numerical_analysis/1/README.md
Normal file
60
numerical_analysis/1/README.md
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
# 工程数值方法与机器学习
|
||||||
|
|
||||||
|
> 2020/2021 学年
|
||||||
|
>
|
||||||
|
> 北京航空航天大学微电子学院
|
||||||
|
>
|
||||||
|
> 授课教师:王鹏教授,邢炜博士
|
||||||
|
|
||||||
|
### 作业1
|
||||||
|
简介:
|
||||||
|
> 在本次作业中,你需要编写Matlab(或python)程序来求解一些线性方程组,你需要能在电脑上运行Matlab2012a以上版本(或python)。
|
||||||
|
请按照本文档中的说明执行任务并生成并以所需格式保存结果。 提交你的求解器代码和报告(其中包含总结和图表)。
|
||||||
|
完成A部分与B部分的所有内容。
|
||||||
|
|
||||||
|
A部分:编写你自己的求解器
|
||||||
|
1. 编写一个用来求解方程 Ux = d的向后替代求解器, 其中 U 是上三角矩阵。
|
||||||
|
2. 编写一个方阵 A的LU分解求解器。 建议添加选主元步骤,它通过交换矩阵的行来避免小数字的除法,可以有效提高稳定性。
|
||||||
|
3. 结合(1,2)编写一个线性方程组的求解器。
|
||||||
|
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-名字-学号”命名提交。
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
0
numerical_analysis/2/README.md
Normal file
0
numerical_analysis/2/README.md
Normal file
0
numerical_analysis/3/README.md
Normal file
0
numerical_analysis/3/README.md
Normal file
0
numerical_analysis/4/README.md
Normal file
0
numerical_analysis/4/README.md
Normal file
0
numerical_analysis/5/README.md
Normal file
0
numerical_analysis/5/README.md
Normal file
0
numerical_analysis/6/README.md
Normal file
0
numerical_analysis/6/README.md
Normal file
0
numerical_analysis/7/README.md
Normal file
0
numerical_analysis/7/README.md
Normal file
@ -32,7 +32,8 @@
|
|||||||
|
|
||||||
使用神经网络进行回归预测
|
使用神经网络进行回归预测
|
||||||
|
|
||||||
1. 使用共11个理化指标作为模型输入,经过大量调试(不同的网络结构,不同的深度,宽度,激活函数,初始化策略,优化函数)确定出最好的网络结构和策略。说明为什么你选择了该模型结构和策略。(你对比了哪些其他的结构?你觉得为什么该模型的效果比较好?如何防止你的选择基准只是一个巧合?)用图表总结你的搜索结果,列出每个模型(或者经过挑选的有代表性的模型)的RMSE,R2和模型训练时间。
|
1.
|
||||||
|
使用共11个理化指标作为模型输入,经过大量调试(不同的网络结构,不同的深度,宽度,激活函数,初始化策略,优化函数)确定出最好的网络结构和策略。说明为什么你选择了该模型结构和策略。(你对比了哪些其他的结构?你觉得为什么该模型的效果比较好?如何防止你的选择基准只是一个巧合?)用图表总结你的搜索结果,列出每个模型(或者经过挑选的有代表性的模型)的RMSE,R2和模型训练时间。
|
||||||
|
|
||||||
2. 进一步精调模型,提升模型效果并减少过拟合(例如:dropout,early stopping,bagging,交叉验证,L2/L1正则化等等)。用图表总结你使用的精调方法的带来的效果提升。
|
2. 进一步精调模型,提升模型效果并减少过拟合(例如:dropout,early stopping,bagging,交叉验证,L2/L1正则化等等)。用图表总结你使用的精调方法的带来的效果提升。
|
||||||
|
|
||||||
@ -44,5 +45,29 @@
|
|||||||
|
|
||||||
1. 选择目标1,目标2 里面选得的最优秀的模型,对比他们在不同训练数据下的表现并总结,作图。
|
1. 选择目标1,目标2 里面选得的最优秀的模型,对比他们在不同训练数据下的表现并总结,作图。
|
||||||
|
|
||||||
作业提交有效时间是今天到12月29日(三周后)之前的任意时间。
|
作业提交有效时间是今天到12月29日(三周后)之前的任意时间。 提交作业请将代码和报告打包,以“学号-姓名-UQ”命名提交至链接 [http://www.xzc.cn/YvcM5sqqVm]
|
||||||
提交作业请将代码和报告打包,以“学号-姓名-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
|
||||||
|
```
|
||||||
@ -22,33 +22,42 @@ class WinePredict:
|
|||||||
self.X_train = sc.fit_transform(self.X_train)
|
self.X_train = sc.fit_transform(self.X_train)
|
||||||
self.X_test = sc.fit_transform(self.X_test)
|
self.X_test = sc.fit_transform(self.X_test)
|
||||||
|
|
||||||
# 线性回归
|
|
||||||
def lr(self):
|
def lr(self):
|
||||||
|
"""
|
||||||
|
线性回归
|
||||||
|
"""
|
||||||
lr = LinearRegression()
|
lr = LinearRegression()
|
||||||
lr.fit(self.X_train, self.y_train)
|
lr.fit(self.X_train, self.y_train)
|
||||||
return lr.predict(self.X_test)
|
return lr.predict(self.X_test)
|
||||||
|
|
||||||
# 随机森林
|
|
||||||
def rfc(self):
|
def rfc(self):
|
||||||
rfc = RandomForestClassifier(n_estimators=200)
|
"""
|
||||||
|
随机森林
|
||||||
|
"""
|
||||||
|
rfc = RandomForestClassifier(n_estimators=200, random_state=20)
|
||||||
rfc.fit(self.X_train, self.y_train)
|
rfc.fit(self.X_train, self.y_train)
|
||||||
return rfc.predict(self.X_test)
|
return rfc.predict(self.X_test)
|
||||||
|
|
||||||
# 随机梯度下降
|
|
||||||
# 0.2 极其不稳定
|
|
||||||
def sgd(self):
|
def sgd(self):
|
||||||
|
"""
|
||||||
|
随机梯度下降
|
||||||
|
"""
|
||||||
sgd = SGDClassifier(penalty=None)
|
sgd = SGDClassifier(penalty=None)
|
||||||
sgd.fit(self.X_train, self.y_train)
|
sgd.fit(self.X_train, self.y_train)
|
||||||
return sgd.predict(self.X_test)
|
return sgd.predict(self.X_test)
|
||||||
|
|
||||||
# 支持向量机
|
|
||||||
# 0.23 -> 0.25
|
|
||||||
def svc(self):
|
def svc(self):
|
||||||
|
"""
|
||||||
|
支持向量机
|
||||||
|
"""
|
||||||
svc = SVC(C=1.4, gamma=0.8, kernel='rbf')
|
svc = SVC(C=1.4, gamma=0.8, kernel='rbf')
|
||||||
svc.fit(self.X_train, self.y_train)
|
svc.fit(self.X_train, self.y_train)
|
||||||
return svc.predict(self.X_test)
|
return svc.predict(self.X_test)
|
||||||
|
|
||||||
def mlp(self):
|
def mlp(self):
|
||||||
|
"""
|
||||||
|
多层感知器
|
||||||
|
"""
|
||||||
mlp = MLPClassifier([10, 6], learning_rate_init=0.001, activation='relu', solver='adam', alpha=0.0001,
|
mlp = MLPClassifier([10, 6], learning_rate_init=0.001, activation='relu', solver='adam', alpha=0.0001,
|
||||||
max_iter=30000)
|
max_iter=30000)
|
||||||
# 神经网络
|
# 神经网络
|
||||||
@ -57,9 +66,10 @@ class WinePredict:
|
|||||||
|
|
||||||
# 参数调优
|
# 参数调优
|
||||||
def grid_search(self, model, param):
|
def grid_search(self, model, param):
|
||||||
grid_svc = GridSearchCV(model, param_grid=param, scoring='accuracy', cv=10)
|
print('search %s', param)
|
||||||
grid_svc.fit(self.X_train, self.y_train)
|
grid = GridSearchCV(model, param_grid=param, scoring='accuracy', cv=10)
|
||||||
return grid_svc.best_params_
|
grid.fit(self.X_train, self.y_train)
|
||||||
|
print("%s: %f" % (grid.best_params_, grid.best_score_))
|
||||||
|
|
||||||
def gs_svc(self):
|
def gs_svc(self):
|
||||||
param = {
|
param = {
|
||||||
@ -67,15 +77,21 @@ class WinePredict:
|
|||||||
'kernel': ['linear', 'rbf'],
|
'kernel': ['linear', 'rbf'],
|
||||||
'gamma': [0.1, 0.8, 0.9, 1, 1.1, 1.2, 1.3, 1.4]
|
'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'}
|
# {'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):
|
def report(self, fc):
|
||||||
r = fc()
|
r = fc()
|
||||||
if r.dtype == 'float64' or r.dtype == 'float32':
|
if r.dtype == 'float64' or r.dtype == 'float32':
|
||||||
r = r.round()
|
r = r.round()
|
||||||
# print(classification_report(self.y_test, r))
|
# print(classification_report(self.y_test, r))
|
||||||
print(fc.__name__)
|
print(fc.__doc__.strip())
|
||||||
print(" R2: %f" % r2_score(self.y_test, r))
|
print(" R2: %f" % r2_score(self.y_test, r))
|
||||||
print(" accuracy: %f" % accuracy_score(self.y_test, r))
|
print(" accuracy: %f" % accuracy_score(self.y_test, r))
|
||||||
|
|
||||||
@ -91,5 +107,7 @@ class WinePredict:
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
wp = WinePredict()
|
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()
|
# wp.showXY()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user