Skip to content

Commit b1e1daa

Browse files
Zhao develop (#7) 更新
* 文档更新 * 更新其中的1.17版本官方文档 * 开始新版本1.18的开发 开始开发任务 * update * 新增矩阵 AGG 函数的逻辑实现 * update * 新增边框对象 * update * update * 完善模板匹配函数的实现,增加步长,提升效率。 * update * update * 矩阵开始被归一化计算组件支持 * Update Case.md * update * 针对图像矩阵进行了合并功能的更新 * 针对IO数据流进行了优化。 * update * 为AS库添加第三方数据源支持,并允许通过摄像头获取到图像数据 * update * update * update * 更新HDFS数据IO组件 * update * 1.18版本发布 * 1.18版本发布,新版本已发布至maven * update log * 更新日志中英文文档链接 * update * 格式化文档 * Update Case.md * Update Case.md * Create sourceMaterial.md * update * 更新1.18版本的文档 * 更新主页文档 * 1.18-1.19版本开发开始 * update * 新增 单例数据DF对象,其在存在大量重复数据的场景下,内存将节省很多倍。 * update * update * update * update * 支持目标外绝矩形,图像监督分类两种模型的计算。 * Update sourceMaterial.md * Update sourceMaterial.md * Update sourceMaterial.md * update * update * 更新数学模型类 * 新增线性神经网络训练模型 * 数据输入设备对象升级 * Input HDFS 支持针对矩阵的输入操作 * 线性神经网络支持进行训练时的附加Task。 * update * update * 1.19版本上传至maven * 更新1.19版本代码,准备合并分支
1 parent 0d72593 commit b1e1daa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+8062
-1366
lines changed

AsLib/libBeardedManZhao.dll

0 Bytes
Binary file not shown.

README-Chinese.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ AS库目录有多个版本,如果希望查询不同版本的更新日志以及
2323
<dependency>
2424
<groupId>io.github.BeardedManZhao</groupId>
2525
<artifactId>algorithmStar</artifactId>
26-
<version>1.18</version>
26+
<version>1.19</version>
2727
</dependency>
2828
</dependencies>
2929
```
@@ -81,18 +81,18 @@ AS库在针对数据库,Spark等各种平台对接的时候,需要使用到
8181
<dependency>
8282
<groupId>org.apache.spark</groupId>
8383
<artifactId>spark-core_2.12</artifactId>
84-
<version>3.1.3</version>
84+
<version>3.4.0</version>
8585
</dependency>
8686
<dependency>
8787
<groupId>org.apache.spark</groupId>
8888
<artifactId>spark-sql_2.12</artifactId>
89-
<version>3.1.3</version>
89+
<version>3.4.0</version>
9090
</dependency>
9191

9292
<dependency>
9393
<groupId>org.apache.spark</groupId>
9494
<artifactId>spark-mllib_2.12</artifactId>
95-
<version>3.1.3</version>
95+
<version>3.4.0</version>
9696
</dependency>
9797

9898
<!-- 摄像头依赖库,如果您有需要通过摄像头获取数据对象的需求,可以引入本库 -->

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ can add it to your maven project, or you can download it from Releases and manua
2929
<dependency>
3030
<groupId>io.github.BeardedManZhao</groupId>
3131
<artifactId>algorithmStar</artifactId>
32-
<version>1.18</version>
32+
<version>1.19</version>
3333
</dependency>
3434
</dependencies>
3535
```
@@ -95,19 +95,19 @@ need to, you can refer to the following configuration.
9595
<dependency>
9696
<groupId>org.apache.spark</groupId>
9797
<artifactId>spark-core_2.12</artifactId>
98-
<version>3.1.3</version>
98+
<version>3.4.0</version>
9999
</dependency>
100100

101101
<dependency>
102102
<groupId>org.apache.spark</groupId>
103103
<artifactId>spark-sql_2.12</artifactId>
104-
<version>3.1.3</version>
104+
<version>3.4.0</version>
105105
</dependency>
106106

107107
<dependency>
108108
<groupId>org.apache.spark</groupId>
109109
<artifactId>spark-mllib_2.12</artifactId>
110-
<version>3.1.3</version>
110+
<version>3.4.0</version>
111111
</dependency>
112112

113113
<!-- Camera device dependency library. If you have a need to obtain data objects through the camera, you can import this dependency. -->

sourceMaterial.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212

1313
![catHead_YB1](https://user-images.githubusercontent.com/113756063/232627018-1ab647ff-38f7-408c-a3df-365028463152.jpg)
1414
![cat_YB1](https://user-images.githubusercontent.com/113756063/232627526-efb34160-8948-48c9-9b4f-094069b00e38.jpg)
15-
![cat1](https://user-images.githubusercontent.com/113756063/232627057-a49d6958-d608-4d44-b309-f63454998aaa.jpg)
15+
![cat1-1](https://user-images.githubusercontent.com/113756063/232627057-a49d6958-d608-4d44-b309-f63454998aaa.jpg)
16+
![cat1-2](https://user-images.githubusercontent.com/113756063/232637017-93f207c7-fa38-4cb6-9fad-09f3c710995b.jpg)
17+
![cat_YB2](https://user-images.githubusercontent.com/113756063/232640579-731b2639-d244-419f-911e-6379363c2554.jpg)
18+
![cat2-1](https://user-images.githubusercontent.com/113756063/232640566-c113e212-c21c-4101-aa25-123200dc9684.jpg)
1619
![catHead1](https://user-images.githubusercontent.com/113756063/232627111-d319abbb-7cd3-44f8-92d6-b22c05c2f80b.jpg)
1720
![hamster1](https://user-images.githubusercontent.com/113756063/231063245-7177e066-1a9f-44bd-a996-d9fb4a94ed23.jpg)
1821
![hamster2](https://user-images.githubusercontent.com/113756063/231063257-bdd15967-f664-471e-b9da-2c2bd86a610e.jpg)

src_code/Case.md

Lines changed: 122 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import java.awt.*;
1414
public class MAIN1 {
1515
public static void main(String[] args) {
1616
// 获取一张图像的像素矩阵
17-
ColorMatrix parse1 = ColorMatrix.parseGrayscale("C:\\Users\\Liming\\Desktop\\fsdownload\\test1.bmp");
17+
ColorMatrix parse1 = ColorMatrix.parseGrayscale("C:\\Users\\Liming\\Desktop\\fsDownload\\test1.bmp");
1818
// 将 parse1 进行二值化
1919
parse1.localBinary(ColorMatrix._G_, 30, 0, 0xffffff, 1);
2020
// 将 parse1 矩阵腐蚀,然后将腐蚀的结果获取到
@@ -42,7 +42,7 @@ import java.awt.*;
4242
public class MAIN1 {
4343
public static void main(String[] args) {
4444
// 获取一张图像的像素矩阵
45-
ColorMatrix colors = ColorMatrix.parse("C:\\Users\\Liming\\Desktop\\fsdownload\\test1.bmp");
45+
ColorMatrix colors = ColorMatrix.parse("C:\\Users\\Liming\\Desktop\\fsDownload\\test1.bmp");
4646
// 将图像拷贝一份出来
4747
ColorMatrix parse1 = ColorMatrix.parse(colors.copyToNewArrays());
4848
// 将 parse1 进行二值化 // 请注意阈值
@@ -80,7 +80,7 @@ public class MAIN1 {
8080
ColorMatrix resImage1, parse1;
8181
{
8282
// 获取一张图像的像素矩阵
83-
ColorMatrix colors = ColorMatrix.parse("C:\\Users\\Liming\\Desktop\\fsdownload\\test3.bmp");
83+
ColorMatrix colors = ColorMatrix.parse("C:\\Users\\Liming\\Desktop\\fsDownload\\test3.bmp");
8484
// 将图像拷贝一份出来
8585
parse1 = ColorMatrix.parse(colors.copyToNewArrays());
8686
// 将结果二值化
@@ -133,8 +133,8 @@ public class MAIN1 {
133133
public static void main(String[] args) {
134134
ColorMatrix colorMatrix1, colorMatrix2;
135135
{ // 将图像与样本读取进来
136-
colorMatrix1 = ColorMatrix.parse("C:\\Users\\zhao\\Desktop\\fsdownload\\YB.bmp");
137-
colorMatrix2 = ColorMatrix.parse("C:\\Users\\zhao\\Desktop\\fsdownload\\test22.jpg");
136+
colorMatrix1 = ColorMatrix.parse("C:\\Users\\zhao\\Desktop\\fsDownload\\YB.bmp");
137+
colorMatrix2 = ColorMatrix.parse("C:\\Users\\zhao\\Desktop\\fsDownload\\test22.jpg");
138138
ColorMatrix temp = ColorMatrix.parse(colorMatrix2.copyToNewArrays());
139139
// 开始二值化
140140
colorMatrix1.localBinary(ColorMatrix._G_, 10, 0xffffff, 0, 1);
@@ -177,10 +177,10 @@ import java.util.Map;
177177
public class MAIN1 {
178178
public static void main(String[] args) {
179179
ColorMatrix colorMatrix1, colorMatrix2;
180-
{
180+
{
181181
// 将图像与样本读取进来
182-
colorMatrix1 = ColorMatrix.parse("C:\\Users\\zhao\\Desktop\\fsdownload\\YB.bmp");
183-
colorMatrix2 = ColorMatrix.parse("C:\\Users\\zhao\\Desktop\\fsdownload\\test22.jpg");
182+
colorMatrix1 = ColorMatrix.parse("C:\\Users\\zhao\\Desktop\\fsDownload\\YB.bmp");
183+
colorMatrix2 = ColorMatrix.parse("C:\\Users\\zhao\\Desktop\\fsDownload\\test22.jpg");
184184
ColorMatrix temp = ColorMatrix.parse(colorMatrix2.copyToNewArrays());
185185
// 开始二值化
186186
colorMatrix1.localBinary(ColorMatrix._G_, 10, 0xffffff, 0, 1);
@@ -388,7 +388,7 @@ import java.util.HashMap;
388388
public class MAIN1 {
389389
public static void main(String[] args) {
390390
// 被处理图像路径
391-
String dataPath = "C:\\Users\\Liming\\Desktop\\fsdownload\\微信图片_33.jpg";
391+
String dataPath = "C:\\Users\\Liming\\Desktop\\fsDownload\\微信图片_33.jpg";
392392
ColorMatrix colorMatrix1 = ColorMatrix.parse(dataPath);
393393
colorMatrix1.show("src");
394394
// 将矩阵变换 首先需要创建出不同模式中需要的配置信息 这里是反转和拉伸矩阵的配置
@@ -438,3 +438,116 @@ public class MAIN1 {
438438
```
439439

440440
## 机器学习类案例
441+
442+
### 线性神经网络模型训练案例
443+
444+
线性神经网络训练结果是一个数学模型,其能够在庞大是数据集中查找相关规律,返回的数学模型能够被保存下来。
445+
446+
```java
447+
package zhao.algorithmMagic;
448+
449+
import zhao.algorithmMagic.core.model.*;
450+
import zhao.algorithmMagic.operands.table.SingletonCell;
451+
import zhao.algorithmMagic.operands.vector.DoubleVector;
452+
453+
public class MAIN1 {
454+
455+
// 在 main 函数中进行模型的保存和读取以及使用
456+
public static void main(String[] args) {
457+
458+
// 构建 X 数据
459+
DoubleVector[] X = {
460+
DoubleVector.parse(100, 50, 50),
461+
DoubleVector.parse(50, 50, 50),
462+
DoubleVector.parse(50, 100, 50),
463+
// 最后一行是初始权重数据
464+
DoubleVector.parse(20, 18, 18)
465+
};
466+
// 构建 Y 数据
467+
double[] Y = {300, 200, 250, 350};
468+
469+
// 将 线性神经网络模型获取到
470+
LNeuralNetwork lNeuralNetwork = ASModel.L_NEURAL_NETWORK;
471+
// 设置学习率
472+
lNeuralNetwork.setArg(LNeuralNetwork.LEARNING_RATE, SingletonCell.$(0.02));
473+
// 设置每一个数据样本的训练次数 为 1024
474+
lNeuralNetwork.setArg(LNeuralNetwork.LEARN_COUNT, SingletonCell.$(1024));
475+
// 设置当前神经网络中神经元的激活函数
476+
lNeuralNetwork.setArg(LNeuralNetwork.PERCEPTRON, SingletonCell.$(Perceptron.parse(ActivationFunction.RELU)));
477+
// 设置当前神经网络中的目标数值
478+
lNeuralNetwork.setArg(LNeuralNetwork.TARGET, SingletonCell.$(Y));
479+
480+
// 开始训练 在这里传递进需要被学习的数据 并获取到模型
481+
NumberModel numberModel = lNeuralNetwork.function(X);
482+
System.out.println(numberModel);
483+
// 这里直接调用模型 预测 x1 = 200 x2 = 100 x3 = 50 时候的结果 期望数值是 550
484+
Double function = numberModel.function(new Double[]{200.0, 100.0, 50.0});
485+
System.out.println(function);
486+
}
487+
}
488+
```
489+
490+
### 线性随机神经网络模型训练案例
491+
492+
线性随机神经网络相较于 线性神经网络训练模型 来说具有强大的兼容性和较好的性能,但是其牺牲了些精确度,线性随机神经网络模型的使用以及训练出来的模型从保存如下所示。
493+
494+
```java
495+
package zhao.algorithmMagic;
496+
497+
import zhao.algorithmMagic.core.model.*;
498+
import zhao.algorithmMagic.operands.table.SingletonCell;
499+
import zhao.algorithmMagic.operands.vector.DoubleVector;
500+
501+
import java.io.File;
502+
import java.util.Arrays;
503+
504+
public class MAIN1 {
505+
506+
// 在 main 函数中进行模型的保存和读取以及使用
507+
public static void main(String[] args) {
508+
// 获取到线性神经网络模型
509+
LNeuralNetwork lNeuralNetwork = ASModel.LS_NEURAL_NETWORK;
510+
// 设置学习率 为 0.01
511+
lNeuralNetwork.setArg(LNeuralNetwork.LEARNING_RATE, SingletonCell.$(0.03));
512+
// 设置激活函数为 LEAKY_RE_LU
513+
lNeuralNetwork.setArg(LNeuralNetwork.PERCEPTRON, SingletonCell.$(Perceptron.parse(ActivationFunction.LEAKY_RE_LU)));
514+
// 设置学习次数 为 600
515+
lNeuralNetwork.setArg(LNeuralNetwork.LEARN_COUNT, SingletonCell.$(1000));
516+
// 设置目标数值
517+
lNeuralNetwork.setArg(
518+
LNeuralNetwork.TARGET,
519+
// 假设这里是5组数据对应的结果
520+
SingletonCell.$(new double[]{300, 210, 340, 400, 500})
521+
);
522+
// 构建被学习的数据 由此数据推导结果 找到每一组数据中 3 个参数之间的数学模型
523+
DoubleVector X1 = DoubleVector.parse(100, 50, 50);
524+
DoubleVector X2 = DoubleVector.parse(80, 50, 50);
525+
DoubleVector X3 = DoubleVector.parse(120, 50, 50);
526+
DoubleVector x4 = DoubleVector.parse(100, 100, 100);
527+
DoubleVector x5 = DoubleVector.parse(150, 100, 100);
528+
// 构建初始权重向量
529+
DoubleVector W = DoubleVector.parse(20, 18, 18);
530+
// 实例化出附加 Task 任务对象
531+
LNeuralNetwork.TaskConsumer taskConsumer = (loss, g, weight) -> {
532+
// 在这里打印出每一次训练的信息
533+
System.out.println("损失函数 = " + loss);
534+
System.out.println("计算梯度 = " + g);
535+
System.out.println("权重参数 = " + Arrays.toString(weight) + '\n');
536+
};
537+
// 训练出模型 TODO 在这里指定出每一次训练时的附加任务
538+
NumberModel model = lNeuralNetwork.function(taskConsumer, X1, X2, X3, x4, x5, W);
539+
// TODO 接下来开始使用模型进行一些测试
540+
// 向模型中传递一些数值
541+
Double function1 = model.function(new Double[]{100.0, 50.0, 50.0});
542+
// 打印计算出来的结果
543+
System.out.println(function1);
544+
// 再一次传递一些数值
545+
Double function2 = model.function(new Double[]{150.0, 100.0, 100.0});
546+
// 打印计算出来的结果
547+
System.out.println(function2);
548+
549+
// TODO 确定模型可用,将模型保存
550+
ASModel.Utils.write(new File("C:\\Users\\zhao\\Desktop\\fsDownload\\MytModel.as"), model);
551+
}
552+
}
553+
```

0 commit comments

Comments
 (0)