diff --git a/AsLib/LibSrc/.idea/workspace.xml b/AsLib/LibSrc/.idea/workspace.xml index 2eb27a2..7583df5 100644 --- a/AsLib/LibSrc/.idea/workspace.xml +++ b/AsLib/LibSrc/.idea/workspace.xml @@ -110,6 +110,7 @@ + diff --git a/AsLib/LibSrc/cmake-build-debug/Testing/Temporary/LastTest.log b/AsLib/LibSrc/cmake-build-debug/Testing/Temporary/LastTest.log index 0022b89..b4e6485 100644 --- a/AsLib/LibSrc/cmake-build-debug/Testing/Temporary/LastTest.log +++ b/AsLib/LibSrc/cmake-build-debug/Testing/Temporary/LastTest.log @@ -1,3 +1,3 @@ -Start testing: Mar 26 11:37 ?D1迆㊣那℅?那㊣?? +Start testing: Apr 09 14:04 ?D1迆㊣那℅?那㊣?? ---------------------------------------------------------- -End testing: Mar 26 11:37 ?D1迆㊣那℅?那㊣?? +End testing: Apr 09 14:04 ?D1迆㊣那℅?那㊣?? diff --git a/AsLib/libBeardedManZhao.dll b/AsLib/libBeardedManZhao.dll index 1bf4d30..7d66fce 100644 Binary files a/AsLib/libBeardedManZhao.dll and b/AsLib/libBeardedManZhao.dll differ diff --git a/KnowledgeDocument/Operands-Chinese.md b/KnowledgeDocument/Operands-Chinese.md index 220db86..663dce1 100644 --- a/KnowledgeDocument/Operands-Chinese.md +++ b/KnowledgeDocument/Operands-Chinese.md @@ -413,14 +413,16 @@ Table 涉S摨銝剔其餈銵唳桀唳桀笆鞊∴嗉”啣耦撘撅鈭 ### DataFrameBuilder 銝 DataFrame -DataFrameBuilder 銝 DataFrame 怎其唳桃頧賭唳桃雿嚗冽唳桃頧質蝔銝剖臭誑餈 DataFameBuilder 唳桀笆鞊∪翰瑕嗅捆閫賣唳箔銝枋ataFrame嚗撟嗡蝙求ataFrame餈銵唳桃憭 +DataFrameBuilder 銝 DataFrame 怎其唳桃頧賭唳桃雿嚗冽唳桃頧質蝔銝剖臭誑餈 DataFameBuilder +唳桀笆鞊∪翰瑕嗅捆閫賣唳箔銝枋ataFrame嚗撟嗡蝙求ataFrame餈銵唳桃憭 DataFrame 蝞蝘 "DF" 冽唳桃憭嗆挾嚗霂詨賣圈沒QL憌潸挽霈∴賢雿摮虫穿雿踹蝎曉銝瘜其湧閬鈭銝嚗乩亙蝷箔 DataFrameBuilder 箸砌蝙具 #### 雿輻 FDataFrame 頧賣唳 -- 霂餃唳桀 - 杗S摨銝剜典臭誑撠唳桀頧賣銝 FDataFrame 唳桀笆鞊∴霂亙笆鞊∟賢摰啣箸祉唳株粉銝唳桀踝賢摰唳唳桃恣改典臭誑撠唳桀銝剔唳桀頧賣銝箔銝 FDataFrame 嚗乩亙停舀單唳桀唳桀頧賜隞蝷箔 - - 閬瘜冽荔刻粉唳桀嗅霂瑕券★桐葉撖澆 JDBC 撽勗函掩 + +- 霂餃唳桀 杗S摨銝剜典臭誑撠唳桀頧賣銝 FDataFrame 唳桀笆鞊∴霂亙笆鞊∟賢摰啣箸祉唳株粉銝唳桀踝賢摰唳唳桃恣改典臭誑撠唳桀銝剔唳桀頧賣銝箔銝 FDataFrame + 嚗乩亙停舀單唳桀唳桀頧賜隞蝷箔 + - 閬瘜冽荔刻粉唳桀嗅霂瑕券★桐葉撖澆 JDBC 撽勗函掩 ```java package zhao.algorithmMagic; @@ -447,8 +449,8 @@ public class MAIN1 { } } ``` -- 霂餃隞嗥頂蝏 - 撖寞隞嗥頂蝏霂餃嚗FDataFrame 臬臭誑頧餅曉唳砍唳隞嗥頂蝏霂餃嚗銝閬靘韏隞颱蝚砌孵撠勗臭誑摰唳隞嗥頂蝏霂餃嚗乩亙停摰唬銝瑚甇仿炊嚗 + +- 霂餃隞嗥頂蝏 撖寞隞嗥頂蝏霂餃嚗FDataFrame 臬臭誑頧餅曉唳砍唳隞嗥頂蝏霂餃嚗銝閬靘韏隞颱蝚砌孵撠勗臭誑摰唳隞嗥頂蝏霂餃嚗乩亙停摰唬銝瑚甇仿炊嚗 ```java package zhao.algorithmMagic; @@ -481,6 +483,7 @@ public class MAIN1 { } } ``` + #### 蝏澆獢靘 ```java diff --git a/KnowledgeDocument/Operands.md b/KnowledgeDocument/Operands.md index 4b8bc76..365f422 100644 --- a/KnowledgeDocument/Operands.md +++ b/KnowledgeDocument/Operands.md @@ -427,19 +427,27 @@ public class MAIN1 { } } ``` + ## Table -Table is the data object used for data analysis in the AS database. Its representation is a table with row and column indexes, which can realize convenient data processing tasks. Data can be loaded and processed in the AS database through the DataFrame object. +Table is the data object used for data analysis in the AS database. Its representation is a table with row and column +indexes, which can realize convenient data processing tasks. Data can be loaded and processed in the AS database through +the DataFrame object. ### DataFrameBuilder & DataFrame -DataFrameBuilder and DataFrame are used for data loading and data analysis respectively. In the process of data loading, a DataFrame can be constructed through DataFameBuilder data object fast and easy to understand functions, and the DataFrame can be used for data processing. -DataFrame is called "DF" for short. In the data processing stage, many functions are designed in SQL style, which can effectively reduce learning costs and focus on more important things. Next, we will show the basic use of DataFrameBuilder. +DataFrameBuilder and DataFrame are used for data loading and data analysis respectively. In the process of data loading, +a DataFrame can be constructed through DataFameBuilder data object fast and easy to understand functions, and the +DataFrame can be used for data processing. DataFrame is called "DF" for short. In the data processing stage, many +functions are designed in SQL style, which can effectively reduce learning costs and focus on more important things. +Next, we will show the basic use of DataFrameBuilder. #### Load data using FDataFrame --Read Database - In the AS database, you can load data into an FDataFrame data object, which can realize basic data reading and data processing functions, and effective data control. You can load data in the database into an FDataFrame. Next is the code example about database data loading. - -It should be noted that when reading the database, please import the JDBC driver class in the project. + +-Read Database In the AS database, you can load data into an FDataFrame data object, which can realize basic data +reading and data processing functions, and effective data control. You can load data in the database into an FDataFrame. +Next is the code example about database data loading. -It should be noted that when reading the database, please import +the JDBC driver class in the project. ```java package zhao.algorithmMagic; @@ -466,8 +474,9 @@ public class MAIN1 { } } ``` --Read file system - For the reading of the file system, FDataFrame can easily read the local file system without relying on any third-party library. Next, we will implement the specific steps! + +-Read file system For the reading of the file system, FDataFrame can easily read the local file system without relying +on any third-party library. Next, we will implement the specific steps! ```java package zhao.algorithmMagic; @@ -500,6 +509,7 @@ public class MAIN1 { } } ``` + #### Comprehensive case ```java diff --git a/README-Chinese.md b/README-Chinese.md index 1665a67..c8ab5ec 100644 --- a/README-Chinese.md +++ b/README-Chinese.md @@ -18,16 +18,19 @@ io.github.BeardedManZhao algorithmStar - 1.17 + 1.18 ``` + ### AS摨靘韏 1.17砌嚗AS摨靘韏鋡怠亦氖嚗游末踹靘韏蝏桅嚗撠憿寧桀脩航賣改嗡臭誑批瘙雿輻冽游靘韏蝵桅★嚗典臭誑刻亦蚊S摨靘韏蝚砌孵靘韏 #### 敹靘韏憿 + AS摨刻銵霂詨霈∠賣啁嗅隡鈭抒銝鈭亙唳殷甇乙S摨雿輻券閬撖澆交亙靘韏憿對餈銝芯韏憿寞臬銝臬嚗霂瑟批銝孵撖澆乩韏 + ```xml @@ -54,9 +57,11 @@ AS摨刻銵霂詨霈∠賣啁嗅隡鈭抒銝鈭亙唳殷甇乙S ``` + #### 舫靘韏憿 AS摨券撖寞唳桀嚗Spark蝑蝘撟喳啣笆亦嗅嚗閬雿輻典啁洵銝嫣韏蝔摨嚗餈鈭臬舫嚗憒其閬雿輻刻鈭踝典臭誑銝餃紡乩韏嚗憒券閬嚗臭誑銝Y蝵柴 + ```xml @@ -82,6 +87,21 @@ AS摨券撖寞唳桀嚗Spark蝑蝘撟喳啣笆亦嗅嚗閬雿輻典 spark-mllib_2.12 3.1.3 + + + + com.github.sarxos + webcam-capture + 0.3.12 + + + + + org.apache.hadoop + hadoop-client + 3.3.1 + + ``` diff --git a/README.md b/README.md index 3faeaf3..40c283c 100644 --- a/README.md +++ b/README.md @@ -21,18 +21,25 @@ can add it to your maven project, or you can download it from Releases and manua io.github.BeardedManZhao algorithmStar - 1.17 + 1.18 ``` ### Required dependencies of the AS library -After version 1.17, all dependencies of the AS library have been stripped to better avoid binding dependencies and reduce the possibility of project conflicts. At the same time, more suitable dependency configuration items can be used according to the needs of developers. You can view third-party library dependencies on which the AS library depends here. +After version 1.17, all dependencies of the AS library have been stripped to better avoid binding dependencies and +reduce the possibility of project conflicts. At the same time, more suitable dependency configuration items can be used +according to the needs of developers. You can view third-party library dependencies on which the AS library depends +here. #### Required Dependencies -The AS library generates some log data when performing many calculation functions. Therefore, the use of the AS library requires importing log dependencies, which are essential. Please import the dependencies as follows. + +The AS library generates some log data when performing many calculation functions. Therefore, the use of the AS library +requires importing log dependencies, which are essential. Please import the dependencies as follows. + ```xml + @@ -58,18 +65,23 @@ The AS library generates some log data when performing many calculation function ``` + #### Optional Dependencies -When interfacing with various platforms such as databases and Sparks, the AS library needs to use third-party dependency packages, which are optional. If you do not need to use these functions, you may not need to import dependencies. If you need to, you can refer to the following configuration. +When interfacing with various platforms such as databases and Sparks, the AS library needs to use third-party dependency +packages, which are optional. If you do not need to use these functions, you may not need to import dependencies. If you +need to, you can refer to the following configuration. + ```xml + - + mysql mysql-connector-java 8.0.30 - + org.apache.spark spark-core_2.12 @@ -80,12 +92,27 @@ When interfacing with various platforms such as databases and Sparks, the AS lib spark-sql_2.12 3.1.3 - + org.apache.spark spark-mllib_2.12 3.1.3 + + + + com.github.sarxos + webcam-capture + 0.3.12 + + + + + org.apache.hadoop + hadoop-client + 3.3.1 + + ``` diff --git a/src_code/Case.md b/src_code/Case.md new file mode 100644 index 0000000..03fd6ad --- /dev/null +++ b/src_code/Case.md @@ -0,0 +1,426 @@ +# AS 箏典郎銋摨獢靘 + +## 箏刻閫蝐餅靘 + +### 瑕曉颲寧蝥 + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.matrix.ColorMatrix; + +import java.awt.*; + +public class MAIN1 { + public static void main(String[] args) { + // 瑕銝撘曉蝝拚 + ColorMatrix parse1 = ColorMatrix.parseGrayscale("C:\\Users\\Liming\\Desktop\\fsdownload\\test1.bmp"); + // 撠 parse1 餈銵鈭澆 + parse1.localBinary(ColorMatrix._G_, 30, 0, 0xffffff, 1); + // 撠 parse1 拚菔嚗嗅撠蝏瑕 + ColorMatrix parse2 = parse1.erode(3, 3, true, Color.BLACK); + // 撠 parse1 拚萎葉質脖銝箄航莎刻嚗 + parse1.erode(3, 3, false, Color.WHITE); + // 亦銝湔嗥 + parse1.show("image1"); + parse2.show("image2"); + // 撠銝支葵拚菔銵撌株蝞嚗撟嗆亦撌桐曉 + (parse1.diff(parse2)).show("蝏曉"); + } +} +``` + +### 蝏箏曉颲寧 + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.matrix.ColorMatrix; + +import java.awt.*; + +public class MAIN1 { + public static void main(String[] args) { + // 瑕銝撘曉蝝拚 + ColorMatrix colors = ColorMatrix.parse("C:\\Users\\Liming\\Desktop\\fsdownload\\test1.bmp"); + // 撠曉瑁銝隞賢箸 + ColorMatrix parse1 = ColorMatrix.parse(colors.copyToNewArrays()); + // 撠 parse1 餈銵鈭澆 // 霂瑟釣 + parse1.globalBinary(ColorMatrix._G_, 60, 0, 0xffffff); + // 撠 parse1 拚菔嚗嗅撠蝏瑕 + ColorMatrix parse2 = parse1.erode(2, 2, true, Color.BLACK); + // 撠 parse1 拚萎葉質脖銝箄航莎刻嚗 + parse1.erode(2, 2, false, Color.WHITE); + // 亦銝湔嗥 + parse1.show("image1"); + parse2.show("image2"); + // 撠銝支葵拚菔銵撌株蝞嚗撟嗆亦撌桐曉 + ColorMatrix resImage1 = parse1.diff(parse2); + resImage1.show("頧桀曉"); + // 撠頧桀蝏嗅啣曉銝 撟嗆亦蝏嗡曉 + ColorMatrix resImage2 = colors.agg(resImage1, ColorMatrix.COLOR_SUM_REGULATE); + // 亦蝏唳 + resImage2.show("蝏嗡蝏曉"); + } +} +``` + +### 曉拚菔蔭撱璉瘚 + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.matrix.ColorMatrix; +import zhao.algorithmMagic.operands.matrix.RectangleMatrix; + +import java.awt.*; + +public class MAIN1 { + public static void main(String[] args) { + ColorMatrix resImage1, parse1; + { + // 瑕銝撘曉蝝拚 + ColorMatrix colors = ColorMatrix.parse("C:\\Users\\Liming\\Desktop\\fsdownload\\test3.bmp"); + // 撠曉瑁銝隞賢箸 + parse1 = ColorMatrix.parse(colors.copyToNewArrays()); + // 撠蝏鈭澆 + parse1.globalBinary(ColorMatrix._G_, 150, 0xffffff, 0); + // 撠 parse1 拚菔嚗嗅撠蝏瑕 + ColorMatrix parse2 = parse1.erode(3, 3, true, Color.BLACK); + // 撠 parse1 拚萎葉質脖銝箄航莎刻嚗 + parse1.erode(2, 2, false, Color.WHITE); + // 亦銝湔嗥 + parse1.show("image1"); + parse2.show("image2"); + // 撠銝支葵拚菔銵撌株蝞嚗撟嗆亦撌桐曉 + resImage1 = parse1.diff(parse2); + resImage1.show("頧桀曉"); + } + // 撘憪質脰蔭撱蝥踹Y妖 + System.out.print("頧桀Y妖 = "); + System.out.println(resImage1.contourArea(ColorMatrix.WHITE)); + // 撠頧桀蝥輯蓮拙耦頧桀 + ColorMatrix parse = RectangleMatrix.parse(resImage1, Color.GREEN); + parse.show("拙耦頧桀"); + System.out.print(parse); + // 撠拙耦頧桀瘛餃啣拚 餈閫荔憒憸脫啣潔蛹 0xff000000 撠曹撟 + ColorMatrix res = parse1.agg(parse, (inputType1, inputType2) -> inputType2.getRGB() == 0xff000000 ? inputType1 : inputType2); + res.show("蝏"); + } +} +``` + +### 曉璅⊥踹寥 + +- 鈭箄貉 餈鈭箄豢芋踹寥澆憿輻訾撮蝟餅 + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.algorithm.distanceAlgorithm.ManhattanDistance; +import zhao.algorithmMagic.operands.coordinate.IntegerCoordinateTwo; +import zhao.algorithmMagic.operands.matrix.ColorMatrix; + +import java.awt.*; +import java.util.Map; + + +public class MAIN1 { + public static void main(String[] args) { + ColorMatrix colorMatrix1, colorMatrix2; + { // 撠曉銝瑟祈粉餈 + colorMatrix1 = ColorMatrix.parse("C:\\Users\\zhao\\Desktop\\fsdownload\\YB.bmp"); + colorMatrix2 = ColorMatrix.parse("C:\\Users\\zhao\\Desktop\\fsdownload\\test22.jpg"); + ColorMatrix temp = ColorMatrix.parse(colorMatrix2.copyToNewArrays()); + // 撘憪鈭澆 + colorMatrix1.localBinary(ColorMatrix._G_, 10, 0xffffff, 0, 1); + temp.localBinary(ColorMatrix._G_, 5, 0xffffff, 0, 0); + // 撘憪餈銵璅⊥踹寥 撟嗉寥蝏啣潘刻餈撠望舀寥蝏唳殷key銝箏寥蝟餅 value銝箏寥蝏 + Map.Entry matching = temp.templateMatching( + ManhattanDistance.getInstance("MAN"), + colorMatrix1, + ColorMatrix._G_, + 10, + false + ); + // 撘憪餈銵蝏 刻擐瑕啣唳 + IntegerCoordinateTwo coordinateTwo = matching.getValue(); + System.out.print("寥蝟餅 = "); + System.out.println(matching.getKey()); + colorMatrix2.drawRectangle( + coordinateTwo, + new IntegerCoordinateTwo(coordinateTwo.getX() + colorMatrix1.getColCount(), coordinateTwo.getY() + colorMatrix1.getRowCount()), + Color.MAGENTA + ); + } + colorMatrix1.show("鈭箄豢瑟"); + colorMatrix2.show("霂怎"); + } +} +``` + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.algorithm.distanceAlgorithm.ManhattanDistance; +import zhao.algorithmMagic.operands.coordinate.IntegerCoordinateTwo; +import zhao.algorithmMagic.operands.matrix.ColorMatrix; + +import java.awt.*; +import java.util.ArrayList; +import java.util.Map; + +public class MAIN1 { + public static void main(String[] args) { + ColorMatrix colorMatrix1, colorMatrix2; + { // 撠曉銝瑟祈粉餈 + colorMatrix1 = ColorMatrix.parse("C:\\Users\\zhao\\Desktop\\fsdownload\\YB.bmp"); + colorMatrix2 = ColorMatrix.parse("C:\\Users\\zhao\\Desktop\\fsdownload\\test22.jpg"); + ColorMatrix temp = ColorMatrix.parse(colorMatrix2.copyToNewArrays()); + // 撘憪鈭澆 + colorMatrix1.localBinary(ColorMatrix._G_, 10, 0xffffff, 0, 1); + temp.localBinary(ColorMatrix._G_, 5, 0xffffff, 0, 15); + temp.erode(2, 2, false); + temp.show("temp"); + // 撘憪餈銵璅⊥踹寥 撟嗉寥蝏啣潘刻餈撠望舀寥蝏唳 + // 嗡葉瘥銝銝芸蝝賣臭銝芸寥啁蝚血∩辣蝏靽⊥臬笆鞊 key銝箏寥蝟餅 value銝箏寥蝏 + ArrayList> entries = temp.templateMatching( + // 霈∠訾撮摨阡閬雿輻函霈∠蝏隞 + ManhattanDistance.getInstance("MAN"), + // 閬鋡怨恣蝞拚萄笆鞊 + colorMatrix1, + // 霈∠園閬雿輻函憸脤 + ColorMatrix._G_, + // 霈∠園閬雿輻函瑞妖甇仿 + 16, + // 訾撮摨阡潸挽摰∩辣 + v -> v < 1200000 + ); + // 撠颲寞蝏嗅啣曆葉 + for (Map.Entry matching : entries) { + // 撘憪餈銵蝏 刻擐瑕啣唳 + IntegerCoordinateTwo coordinateTwo = matching.getValue(); + System.out.print("寥蝟餅 = "); + System.out.println(matching.getKey()); + colorMatrix2.drawRectangle( + coordinateTwo, + new IntegerCoordinateTwo(coordinateTwo.getX() + colorMatrix1.getColCount(), coordinateTwo.getY() + colorMatrix1.getRowCount()), + Color.MAGENTA + ); + } + } + colorMatrix1.show("鈭箄豢瑟"); + colorMatrix2.show("霂怎"); + } +} +``` + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.algorithm.distanceAlgorithm.ManhattanDistance; +import zhao.algorithmMagic.io.InputCamera; +import zhao.algorithmMagic.io.InputCameraBuilder; +import zhao.algorithmMagic.io.InputComponent; +import zhao.algorithmMagic.operands.coordinate.IntegerCoordinateTwo; +import zhao.algorithmMagic.operands.matrix.ColorMatrix; +import zhao.algorithmMagic.operands.table.FinalCell; + +import java.awt.*; +import java.util.Map; + +public class MAIN1 { + public static void main(String[] args) { + ColorMatrix colorMatrix1, colorMatrix2; + { + // 瑕唳憭渲亥挽憭 + InputComponent inputComponent = InputCamera.builder() + // 閬雿輻函憭渡摮 蝝W def暺霈歹隞祈雿輻函 def 隞銵其蝙券霈斗憭 + .addInputArg(InputCameraBuilder.Camera_Index, new FinalCell<>("def")) + // 閬雿輻函曉澆 + .addInputArg(InputCameraBuilder.Image_Format, new FinalCell<>("JPG")) + // 曉撠箏站 餈啣潭 WebcamResolution 銝曄掩撅批畾 VGA + .addInputArg(InputCameraBuilder.CUSTOM_VIEW_SIZES, new FinalCell<>("VGA")) + .create(); + // 撠曉銝瑟祈粉餈 + colorMatrix1 = ColorMatrix.parse("C:\\Users\\liming\\Desktop\\fsdownload\\YB.bmp"); + colorMatrix2 = ColorMatrix.parse(inputComponent); + ColorMatrix temp = ColorMatrix.parse(colorMatrix2.copyToNewArrays()); + // 撘憪鈭澆 + colorMatrix1.localBinary(ColorMatrix._G_, 10, 0xffffff, 0, 1); + temp.localBinary(ColorMatrix._G_, 5, 0xffffff, 0, 20); + temp.erode(2, 2, false); + temp.show("temp"); + // 撘憪餈銵璅⊥踹寥 撟嗉寥蝏啣潘刻餈撠望舀寥蝏唳殷key銝箏寥蝟餅 value銝箏寥蝏 + Map.Entry matching = temp.templateMatching( + ManhattanDistance.getInstance("MAN"), + colorMatrix1, + ColorMatrix._G_, + 10, + false + ); + // 撘憪餈銵蝏 刻擐瑕啣唳 + IntegerCoordinateTwo coordinateTwo = matching.getValue(); + System.out.print("寥蝟餅 = "); + System.out.println(matching.getKey()); + colorMatrix2.drawRectangle( + coordinateTwo, + new IntegerCoordinateTwo(coordinateTwo.getX() + colorMatrix1.getColCount(), coordinateTwo.getY() + colorMatrix1.getRowCount()), + Color.MAGENTA + ); + } + colorMatrix1.show("鈭箄豢瑟"); + colorMatrix2.show("霂怎"); + } +} +``` + +### 摰摮霂 + +餈撅蝷箇舫餈璅⊥踹寥雿嚗箏曉銝剔摰啣摮蝚佗曉唳桅銝曉憭隞憒銝蝷箝 + +- 曉唳桅 餈啣曉唳桐誑鋡怠曉 + +![1](https://user-images.githubusercontent.com/113756063/229441539-03d9adb6-4883-4c2c-a86d-e008b2a620d6.jpg) +![2](https://user-images.githubusercontent.com/113756063/229441568-a273d88e-a411-4d70-907b-67084ec404a8.jpg) +![3](https://user-images.githubusercontent.com/113756063/229441606-fa1f7195-0bbb-4c86-91dc-c0b7d3267850.jpg) +![4](https://user-images.githubusercontent.com/113756063/229441641-f0e01024-df8a-432f-a028-462327beb3c0.jpg) +![5](https://user-images.githubusercontent.com/113756063/229441669-ae0b3a20-fbf0-447f-bf76-20ea84016751.jpg) +![6](https://user-images.githubusercontent.com/113756063/229441694-c80357da-865e-40ec-815b-7dcebe743897.jpg) +![7](https://user-images.githubusercontent.com/113756063/229441706-5ae85394-ae91-4d77-85d8-5c088693277b.jpg) +![8](https://user-images.githubusercontent.com/113756063/229441723-c51b2a73-c007-436e-9a5c-e841a5312424.jpg) +![9](https://user-images.githubusercontent.com/113756063/229441430-7b9b8ded-b207-4415-b5a0-0b3e594d7846.jpg) +![test4](https://user-images.githubusercontent.com/113756063/229441864-ec1770d5-1154-4e9c-837e-a4acfc5fb259.jpg) + +- 曉霂思誨嚗餈銝Y隞摰唬曉銝剜啣 4 箸雿 + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.algorithm.distanceAlgorithm.ManhattanDistance; +import zhao.algorithmMagic.operands.coordinate.IntegerCoordinateTwo; +import zhao.algorithmMagic.operands.matrix.ColorMatrix; + +import java.awt.*; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +public class MAIN1 { + public static void main(String[] args) throws MalformedURLException { + HashMap hashMap = new HashMap<>(0b1100); + // 撠瑟祇餈蝵蝏霂餃餈 + { + hashMap.put(1, ColorMatrix.parse(new URL("https://user-images.githubusercontent.com/113756063/229441539-03d9adb6-4883-4c2c-a86d-e008b2a620d6.jpg"))); + hashMap.put(2, ColorMatrix.parse(new URL("https://user-images.githubusercontent.com/113756063/229441568-a273d88e-a411-4d70-907b-67084ec404a8.jpg"))); + hashMap.put(3, ColorMatrix.parse(new URL("https://user-images.githubusercontent.com/113756063/229441606-fa1f7195-0bbb-4c86-91dc-c0b7d3267850.jpg"))); + hashMap.put(4, ColorMatrix.parse(new URL("https://user-images.githubusercontent.com/113756063/229441641-f0e01024-df8a-432f-a028-462327beb3c0.jpg"))); + hashMap.put(5, ColorMatrix.parse(new URL("https://user-images.githubusercontent.com/113756063/229441669-ae0b3a20-fbf0-447f-bf76-20ea84016751.jpg"))); + hashMap.put(6, ColorMatrix.parse(new URL("https://user-images.githubusercontent.com/113756063/229441694-c80357da-865e-40ec-815b-7dcebe743897.jpg"))); + hashMap.put(7, ColorMatrix.parse(new URL("https://user-images.githubusercontent.com/113756063/229441706-5ae85394-ae91-4d77-85d8-5c088693277b.jpg"))); + hashMap.put(8, ColorMatrix.parse(new URL("https://user-images.githubusercontent.com/113756063/229441723-c51b2a73-c007-436e-9a5c-e841a5312424.jpg"))); + hashMap.put(9, ColorMatrix.parse(new URL("https://user-images.githubusercontent.com/113756063/229441430-7b9b8ded-b207-4415-b5a0-0b3e594d7846.jpg"))); + } + // 撠閬鋡怨銵啣曉餈蝵蝏瑕 + ColorMatrix parse = ColorMatrix.parse(new URL("https://user-images.githubusercontent.com/113756063/229441864-ec1770d5-1154-4e9c-837e-a4acfc5fb259.jpg")); + // 撠拚萄嗡隞踝蝔其蝏撅蝷 + ColorMatrix parse1 = ColorMatrix.parse(parse.copyToNewArrays()); + // 撠閬鋡怠曉餈銵鈭澆嚗雿踹園脖隡撟脫啣寥 + parse.localBinary(ColorMatrix._G_, 4, 0xffffff, 0, -15); + parse.show("鈭澆蝏"); + // 刻瑕 4 啣澆笆摨瑟 + ColorMatrix temp = hashMap.get(4); + temp.show("璅⊥踵唳"); + // 撘憪餈銵璅⊥踹寥雿嚗霂交雿撠隡餈摨阡蝟餅啣鈭 3500 摮曉撌虫閫 + ArrayList> matching = parse.templateMatching( + ManhattanDistance.getInstance("MAN"), + temp, + ColorMatrix._G_, + 1, + v -> { + System.out.println(v); + return v < 5000; + } + ); + // 撠頧桀蝏嗅啁其撅蝷箇拚萄笆鞊∩ + for (Map.Entry doubleIntegerCoordinateTwoEntry : matching) { + IntegerCoordinateTwo value = doubleIntegerCoordinateTwoEntry.getValue(); + parse1.drawRectangle( + value, + new IntegerCoordinateTwo(value.getX() + temp.getColCount() - 1, value.getY() + temp.getRowCount() - 1), + Color.MAGENTA + ); + } + // 亦蝏 + parse1.show("res"); + } +} +``` + +### 曉曉之獢靘 + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.matrix.ColorMatrix; +import zhao.algorithmMagic.operands.table.Cell; +import zhao.algorithmMagic.operands.table.FinalCell; + +import java.util.HashMap; + + +public class MAIN1 { + public static void main(String[] args) { + // 鋡怠曉頝臬 + String dataPath = "C:\\Users\\Liming\\Desktop\\fsdownload\\敺桐縑曄_33.jpg"; + ColorMatrix colorMatrix1 = ColorMatrix.parse(dataPath); + colorMatrix1.show("src"); + // 撠拚萄 擐閬撱箏箔璅∪銝剝閬蝵桐縑 餈臬頧砍隡貊拚萇蝵 + HashMap> pro = new HashMap<>(); + // 隡貊拚菜嗆摰隡詨 + pro.put("times", new FinalCell<>(2)); + // 撘憪撌血單隡 + ColorMatrix converter = colorMatrix1.converter(ColorMatrix.SLIT_LR, pro); + // 撠撌血單隡詨蝏餈銵銝銝隡賂嗅亦曉 + converter.converter(ColorMatrix.SLIT_BT, pro).show("res"); + } +} +``` + +## 唳株恣蝞蝐餅靘 + +### Series 頧 Stream + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.table.*; + +import java.util.stream.Stream; + + +public class MAIN1 { + public static void main(String[] args) { + // 典撱箔銝枋F撖寡情 + DataFrame dataFrame = FDataFrame.select( + FieldCell.parse("name", "sex", "age"), 0 + ); + // 乩銵唳 + dataFrame.insert( + FinalSeries.parse("zhao1", "", "19"), + FinalSeries.parse("zhao2", "憟", "18"), + FinalSeries.parse("zhao3", "憟", "20") + ); + System.out.println(dataFrame); + // 撠嗡葉蝚砌銵唳株蓮XJavaStream撖寡情 + Series cells = dataFrame.toList().get(1); + Stream> cellStream = cells.toStream(); + // 亦撖寡情 + cellStream.forEach(System.out::println); + } +} +``` + +## 箏典郎銋蝐餅靘 diff --git a/src_code/README-Chinese.md b/src_code/README-Chinese.md index ce0123a..633f2e5 100644 --- a/src_code/README-Chinese.md +++ b/src_code/README-Chinese.md @@ -1,6 +1,6 @@ # ![image](https://user-images.githubusercontent.com/113756063/194830221-abe24fcc-484b-4769-b3b7-ec6d8138f436.png) 蝞瘜銋-箏典之 -- Switch to [English Document](https://github.com/BeardedManZhao/algorithmStar/blob/main/src_code/README.md) +- Switch to [English Document](https://github.com/BeardedManZhao/algorithmStar/blob/Zhao-develop/src_code/README.md) - knowledge base @@ -8,126 +8,81 @@ ### 湔唳亙 -* 獢嗥穿1.16 - 1.17 -* 撠函蝘唬耨嫣蛹Integrator -* 靘瑞妖賣啁霈∠舀嚗賢餈瑞妖賣啣孵曉之嗥憬撠曉拚萇蝝圈 +* 獢嗥穿1.17 - 1.18 +* 銝箏曉拚菜溶diff賣啁摰唳舀嚗嗡蛹霂亦拚萄笆鞊⊥溶撘箏之瘙撌株霈∠賬 ```java package zhao.algorithmMagic; -import zhao.algorithmMagic.integrator.ImageRenderingIntegrator; -import zhao.algorithmMagic.integrator.launcher.ImageRenderingMarLauncher; -import zhao.algorithmMagic.operands.matrix.IntegerMatrix; -import zhao.algorithmMagic.operands.matrix.block.IntegerMatrixSpace; +import zhao.algorithmMagic.core.AlgorithmStar; +import zhao.algorithmMagic.operands.matrix.ColorMatrix; + +import java.awt.*; public class MAIN1 { public static void main(String[] args) { - String s1 = "C:\\Users\\Liming\\Desktop\\fsDownload\\敺桐縑曄_1.jpg"; - IntegerMatrix integerMatrix; - { - // 霈曄蔭 - IntegerMatrix weight = IntegerMatrix.parse( - new int[]{0, -1}, - new int[]{-1, 2}, - new int[]{0, 0} - ); - // 霂餃曉撟嗉瑕唬拚萇征 - IntegerMatrixSpace parse = IntegerMatrixSpace.parse(s1); - // 撖孵曉餈銵瑞妖嚗瑕銝銝芾脣蔗拚萇征渡 - integerMatrix = parse.foldingAndSum(2, 3, IntegerMatrixSpace.parse(weight, weight, weight)); - } - // 颲箏曄1瑞妖曉隞 - ImageRenderingIntegrator image = new ImageRenderingIntegrator( - "image", - new ImageRenderingMarLauncher<>(integerMatrix, "C:\\Users\\Liming\\Desktop\\fsDownload\\res12.jpg", 1) - ); - if (image.run()) { - System.out.println("ok!!!"); - } + // 瑕銝撘曉蝝拚 + ColorMatrix parse1 = AlgorithmStar.parseGrayscaleImage("C:\\Users\\Liming\\Desktop\\fsdownload\\test1.bmp"); + // 撠 parse1 餈銵鈭澆 + parse1.localBinary(ColorMatrix._G_, 30, 0, 0xffffff, 1); + // 撠 parse1 拚菔嚗嗅撠蝏瑕 + ColorMatrix parse2 = parse1.erode(3, 3, true, Color.BLACK); + // 撠銝支葵拚菔銵撌株蝞嚗撟嗆亦撌桐曉 霂亙賣啁鈭雿撌 + (parse1.diff(parse2)).show("蝏曉1"); + // 撠銝支葵拚菔銵 agg 賣啁撌株蝞嚗餈雿輻函 閫游撌 + (parse1.agg(parse2, ColorMatrix.COLOR_DIFF_REGULATE)).show("蝏曉2"); } } ``` -* 曉拚菜舀湔仿餈 show 賣啣典撟銝剜曄內箏曉 +* 銝箏曉拚菜溶鈭銝蝘摰圈餉嚗撌桀潛撖孵潘典撌桐餈蝏撖孵潦 ```java package zhao.algorithmMagic; import zhao.algorithmMagic.operands.matrix.ColorMatrix; -public class MAIN1 { - public static void main(String[] args) throws InterruptedException { - String s1 = "C:\\Users\\Liming\\Desktop\\fsDownload\\敺桐縑曄_1.jpg"; - ColorMatrix parse = ColorMatrix.parse(s1); - parse.show("image"); - Thread.sleep(1024); - parse.colorReversal(false); - parse.show("image"); - } -} -``` - -* 隡箸銋勗賣 shuffle 銝剔憭折箸銋望活啁瘜嚗雿踹嗡隡箇啗撘撣詻 -* 隡餈箄挪桃拚萎葉唳桃賣圈餉嚗玖ash餈銵啣撠 - -```java -package zhao.algorithmMagic; - -import zhao.algorithmMagic.operands.matrix.ColumnDoubleMatrix; - -import java.util.Arrays; -import java.util.Random; - public class MAIN1 { public static void main(String[] args) { - // 撱箔隞賜拚菜唳 - double[][] data = new double[][]{ - new double[]{10, 11, 14, 10, 100}, - new double[]{11, 11, 14, 10, 100}, - new double[]{25, 20, 28, 20, 100}, - new double[]{26, 20, 28, 20, 100} - }; - // 撠拚菜唳桐蝙冽摰銝銵蝘啁孵撱箏箸 - ColumnDoubleMatrix columnDoubleMatrix = ColumnDoubleMatrix.parse( - new String[]{"col1", "col2", "col3", "col4", "col5"}, - new String[]{"row1", "row2", "row3", "row4"}, - data - ); - // 雿輻其撱箸啁拚萇孵銋勗嗡葉唳桅◇摨 銝憭銋 10 甈 - columnDoubleMatrix.shuffle(new Random(), false, 10); - // 啣箇拚菜唳 - System.out.println(columnDoubleMatrix); - // 啣箇拚萎葉 col2 冽啁銝剛砲賣圈撣摰 摨行敺 - System.out.println(Arrays.toString(columnDoubleMatrix.getArrayByColName("col2"))); - // 啣箇拚萎葉 row2 銵 冽啁銝剛砲賣圈撣摰 摨行敺 - System.out.println(Arrays.toString(columnDoubleMatrix.getArrayByRowName("row2"))); + // 撱箔銝芸曉拚 + ColorMatrix parse = AlgorithmStar.parseGrayscaleImage("C:\\Users\\Liming\\Desktop\\fsdownload\\test3.bmp"); + // 銝箏曉拚菔銵刻雿 + // 暺脖銝箄航脰 + ColorMatrix erode1 = parse.erode(3, 3, true); + // 質脖銝箄航脰刻 + ColorMatrix erode2 = parse.erode(3, 3, true, ColorMatrix.WHITE); + // 撠刻拚萄笆鞊 雿輻災gg賣 拚萄笆鞊 + (erode2.agg(erode1, ColorMatrix.COLOR_DIFF_ABS)).show("image"); } } ``` -* 舀曉敹急瑚摮賣啁靚冽雿嚗雿踹曉隞嗥靽摮敺渡 +* 靽格迤鈭蝏湔啁瑁塚芸冽啁撅瘛望瑁桅嚗鈭蝏游漲啁銝剔銝蝏湔啁瘝⊥餈銵瘛望瑁嚗啣典歇蝏啗挽霈∴雿踹瘛望瑁雿撘憪啁 ```java package zhao.algorithmMagic; import zhao.algorithmMagic.operands.matrix.ColorMatrix; +import java.awt.*; + public class MAIN1 { public static void main(String[] args) { - String s1 = "C:\\Users\\zhao\\Desktop\\fsDownload\\敺桐縑曄_2.jpg"; - // 瑕啣曉拚萄笆鞊 - ColorMatrix parse = ColorMatrix.parse(s1); - // 撠曉典曉箇銝餈銵憸脣頧祆雿 - parse.colorReversal(false); - // 亦憸脣頧砌曉 - parse.show("image1"); - // 颲箏頧砌曉 - parse.save("C:\\Users\\zhao\\Desktop\\fsDownload\\res123.jpg"); + // 瑕銝撘曉蝝拚 + ColorMatrix parse1 = AlgorithmStar.parseGrayscaleImage("C:\\Users\\Liming\\Desktop\\fsdownload\\test1.bmp"); + Color[][] colors = parse1.copyToNewArrays(); } } ``` -* 憓鈭 "SaveMatrix" 亙嚗摰唬霂交亙銝拚菟賢臭誑雿輻函蝏靽摮 +* 啣拚萄餈蝞賣堆霂亙賣啗賢摰啁拚萎葉蝝霈∠雿嚗銝X舀舀霈∠雿嚗撟嗉銝銝芾恣蝞銋拚萄笆鞊∼ + +| 霈∠撣賊 | | 雿 | +|---------------------------|-------------------------|----------------| +| CALCULATE_GRADIENT_RL | mid = right - left | 霈∠曉典椰喟璇臬漲 | +| CALCULATE_GRADIENT_LH | mid = low - high | 霈∠曉其銝璇臬漲 | +| CALCULATE_GRADIENT_RL_ABS | mid = abs(right - left) | 霈∠曉典椰喟璇臬漲蝏撖孵潦 | +| CALCULATE_GRADIENT_LH_ABS | mid = abs(low - high) | 霈∠曉其銝璇臬漲蝏撖孵潦 | ```java package zhao.algorithmMagic; @@ -136,679 +91,685 @@ import zhao.algorithmMagic.operands.matrix.ColorMatrix; public class MAIN1 { public static void main(String[] args) { - String s1 = "C:\\Users\\Liming\\Desktop\\fsDownload\\敺桐縑曄_2.jpg"; - // 瑕啣曉拚萄笆鞊 - ColorMatrix parse = ColorMatrix.parse(s1); - // 颲箏曉RGB祆唳 - parse.save("C:\\Users\\Liming\\Desktop\\fsDownload\\res1234.csv", ','); + ColorMatrix calculate1; + ColorMatrix calculate2; + { + // 撱箔銝芸曉拚 + ColorMatrix parse = AlgorithmStar.parseGrayscaleImage("C:\\Users\\Liming\\Desktop\\fsdownload\\test3.bmp"); + // 餈銵撌血喟璇臬漲霈∠ + parse.calculate(ColorMatrix.CALCULATE_GRADIENT_RL, true).show("image1"); + // 餈銵銝銝璇臬漲霈∠ + parse.calculate(ColorMatrix.CALCULATE_GRADIENT_LH, true).show("image2"); + // 餈銵撌血喟蝏撖孵潭0摨西恣蝞 + calculate1 = parse.calculate(ColorMatrix.CALCULATE_GRADIENT_RL_ABS, true); + calculate1.show("image3"); + // 餈銵銝銝蝏撖孵潭0摨西恣蝞 + calculate2 = parse.calculate(ColorMatrix.CALCULATE_GRADIENT_LH_ABS, true); + calculate2.show("image4"); + } + // 餈銵銝文曉瘜撟 撟嗆唳啁拚 + (calculate1.add(calculate2)).show("image"); } } ``` -* AS摨銝剖鈭唳桀摨嚗雿輻沒QL憌澆唳殷餈霂亙臭誑嫣噶撠唳桀銝剔唳株瑕啣摮銝剛銵憭 +* DF 撖寡情 select * 鋡急舀嚗雿輻 * 亥砭雿蝚血銝隡餈銵隞颱餈蝞嚗舐湔亥唳柴 ```java package zhao.algorithmMagic; -import zhao.algorithmMagic.operands.table.DataFrame; -import zhao.algorithmMagic.operands.table.FDataFrame; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; +import zhao.algorithmMagic.operands.table.*; public class MAIN1 { - public static void main(String[] args) throws SQLException { - // 憭唳桀餈亙笆鞊 - Connection connection = DriverManager.getConnection("jdbc:mysql://192.168.0.101:38243/tq_SCHOOL", "liming", "liming7887"); - // 撠唳桀唳桀笆鞊∪頧賣 FDF - DataFrame execute = FDataFrame.builder(connection) // 摰唳桀餈 - .create("*") // 摰亥砭摮畾 - .from("STU_FIVE") // 摰亥砭銵 - .primaryKey(0) // 摰摮AS銵函銝駁殷AS隡芸典遣蝡銵蝝W嚗唳桀亥砭閬雿輻函揣撘摰佗 - .execute();// 撘憪亥砭 - // 啣 FDF 銝剔唳 - System.out.println(execute); - - // 撘憪亥砭 FDF - // 甇摨啣 FDF 銝 name踹漲銝3鈭箏銝剔瑕戊鈭箸 啣箏 3 銵唳 - DataFrame select = execute - .select("name", "sex") // 亥砭嗡葉 name sex - .where(v -> v.getCell(0).getStringValue().length() == 3) // 瑕啣嗡葉摮踹漲銝 3 唳株 - .groupBy("sex") // sex 蝏 - .count() // 撠瘥銝蝏餈銵蝏霈 - .sort("count()") // 抒霈∠餈銵甇摨摨 - .limit(3); // 瑕憭3銵唳 - System.out.println(select.into_outfile("C:\\Users\\zhao\\Desktop\\fsDownload\\res1.csv")); - // 啣 FDF 銝剔唳株 - System.out.println("唳株 = " + execute.count()); - // 啣箏嗡葉靽⊥ - System.out.println(execute.desc()); - // 瑕 韏萄摰 靽⊥ 曹 name 臭蜓殷甇文臭誑湔仿餈餈瑕唳唳 - System.out.println(execute.selectRow("韏萄摰")); + public static void main(String[] args) { + // 撱箔銝芰征 DataFrame 撖寡情 + FDataFrame dataFrame = FDataFrame.select( + FieldCell.parse("id", "name", "sex", "age"), 1 + ); + // 冽交唳 + dataFrame.insert( + FinalSeries.parse("1", "zhao", "M", "19"), + FinalSeries.parse("2", "tang", "W", "18"), + FinalSeries.parse("3", "yang", "W", "20"), + FinalSeries.parse("4", "shen", "W", "19") + ); + // 啣 select * 唳 + System.out.println( + dataFrame.select("*") + ); } } ``` -* 雿輻 FDataFrame 頧賣唳桀銝隞嗡葉唳柴 +* 曉拚 agg 賣堆啣拚萄詨笆摨憸脫啣潛訾霈∠餉摰啜 ```java package zhao.algorithmMagic; -import zhao.algorithmMagic.operands.table.*; +import zhao.algorithmMagic.operands.matrix.ColorMatrix; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; - -public class MAIN1 { - public static void main(String[] args) throws SQLException { - // 憭唳桀餈亙笆鞊 - Connection connection = DriverManager.getConnection("jdbc:mysql://192.168.0.101:38243/tq_SCHOOL", "liming", "liming7887"); - // 撠唳桀唳桀笆鞊∪頧賣 FDF - DataFrame execute = FDataFrame.builder(connection) // 摰唳桀餈 - .create("*") // 摰亥砭摮畾 - .from("STU_FIVE") // 摰亥砭銵 - .where(" name = '韏萄摰' ") // 摰亥砭∩辣 - .primaryKey(0) // 摰摮AS銵函銝駁殷AS隡芸典遣蝡銵蝝W嚗唳桀亥砭閬雿輻函揣撘摰佗 - .execute();// 撘憪亥砭 - // 啣 FDF 銝剔唳 - System.out.println(execute); - } -} -``` - -```java -package zhao.algorithmMagic; - -import zhao.algorithmMagic.operands.table.DataFrame; -import zhao.algorithmMagic.operands.table.FDataFrame; - -import java.io.File; -import java.sql.SQLException; -import java.util.Objects; +import java.awt.*; public class MAIN1 { public static void main(String[] args) { - // 憭隞嗅笆鞊 - File file = new File("C:\\Users\\zhao\\Desktop\\out\\res1.csv"); - // 雿輻 FDF 頧賣隞 - DataFrame execute1 = FDataFrame.builder(file) - // 隞嗅笆鞊∠霂餃閬摰砍蝚 - .setSep(',') - // 隞嗅笆鞊⊿閬摰憟賢蝘堆銝賭蝙 * 餈隞銵函銝舀亥砭嚗臬撱箔銝枋F摮畾 - .create("id", "name", "sex") - // 隞嗅笆鞊⊿閬雿輻甸ambda銵刻噢撘餈銵唳桃餈皛 - .where(v -> Objects.equals(v.getCell(1).getStringValue(), "韏萄摰")) - // 隞嗅笆鞊∠銝駁格摰霈訾蝙典蝘 - .primaryKey("name") - // 扯亥砭 - .execute(); - // 啣箇唳 - System.out.println(execute1); + Color[] colors = {Color.CYAN, Color.GREEN, Color.PINK, Color.red}; + // 典撱箏曉拚 + ColorMatrix parse = ColorMatrix.parse( + colors, colors, colors, colors + ); + // 亦曉拚 + parse.show("image", 100, 100); + // 撠曉銝剔蝝銝芾澈拚菔銵閫港瘜霈∠ + ColorMatrix agg1 = parse.agg(parse, ColorMatrix.COLOR_MULTIPLY_REGULATE); + // 撠曉銝剔蝝銝芾澈拚菔銵雿銋瘜霈∠ + ColorMatrix agg2 = parse.agg(parse, ColorMatrix.COLOR_MULTIPLY_REMAINDER); + // 亦銝支葵曉唳 + agg1.show("image1", 100, 100); + agg2.show("image2", 100, 100); } } - ``` +``` -* 撖達DF扯蝘啗銵limit雿 +* 舀曉頧桀Y妖霈∠嚗刻恣蝞嗅隞亙蝝雿銝箄恣蝞雿嚗頧桀憸脫舀芸銋 ```java package zhao.algorithmMagic; -import zhao.algorithmMagic.operands.table.DataFrame; -import zhao.algorithmMagic.operands.table.FDataFrame; +import zhao.algorithmMagic.operands.matrix.ColorMatrix; -import java.io.File; -import java.sql.SQLException; +import java.awt.*; public class MAIN1 { public static void main(String[] args) { - // 憭隞嗅笆鞊 - File file = new File("C:\\Users\\zhao\\Desktop\\out\\res1.csv"); - // 雿輻 FDF 頧賣隞 - DataFrame execute1 = FDataFrame.builder(file) - // 隞嗅笆鞊∠霂餃閬摰砍蝚 - .setSep(',') - // 隞嗅笆鞊⊿閬摰憟賢蝘堆銝賭蝙 * 餈隞銵函銝舀亥砭嚗臬撱箔銝枋F摮畾 - .create("id", "name", "sex") - // 隞嗅笆鞊∠銝駁格摰霈訾蝙典蝘 - .primaryKey("name") - // 扯亥砭 - .execute(); - // 啣箇唳 餈啣箔 韏 韐 銋渡唳株 - System.out.println(execute1.limit("韏", "韐")); + ColorMatrix resImage1; + { + // 瑕銝撘曉蝝拚 + ColorMatrix colors = ColorMatrix.parse("C:\\Users\\Liming\\Desktop\\fsdownload\\test1.bmp"); + // 撠曉瑁銝隞賢箸 + ColorMatrix parse1 = ColorMatrix.parse(colors.copyToNewArrays()); + // 撠 parse1 餈銵鈭澆 // 霂瑟釣 + parse1.globalBinary(ColorMatrix._G_, 60, 0, 0xffffff); + // 撠 parse1 拚菔嚗嗅撠蝏瑕 + ColorMatrix parse2 = parse1.erode(2, 2, true, Color.BLACK); + // 撠 parse1 拚萎葉質脖銝箄航莎刻嚗 + parse1.erode(2, 2, false, Color.WHITE); + // 亦銝湔嗥 + parse1.show("image1"); + parse2.show("image2"); + // 撠銝支葵拚菔銵撌株蝞嚗撟嗆亦撌桐曉 + resImage1 = parse1.diff(parse2); + resImage1.show("頧桀曉"); + } + // 亦蝏唳 + resImage1.show("蝏嗡蝏曉"); + // 撘憪質脰蔭撱蝥踹Y妖 + System.out.print("頧桀Y妖 = "); + System.out.println(resImage1.contourArea(ColorMatrix.WHITE)); } } ``` -* 舀銝箏怠隞亙啣唳株雿 +* 舀頧桀憭亦拙耦雿嚗刻砲賣啁撣桀拐嚗曉銝剔頧桀撠鋡怎銝銝哨銝箔銝芸之拚萸 ```java package zhao.algorithmMagic; -import zhao.algorithmMagic.operands.table.DataFrame; -import zhao.algorithmMagic.operands.table.FDataFrame; -import zhao.algorithmMagic.operands.table.FieldCell; -import zhao.algorithmMagic.operands.table.FinalSeries; +import zhao.algorithmMagic.operands.matrix.ColorMatrix; +import zhao.algorithmMagic.operands.matrix.RectangleMatrix; -import java.io.File; -import java.io.IOException; -import java.sql.SQLException; +import java.awt.*; public class MAIN1 { public static void main(String[] args) { - // 憭隞嗅笆鞊 - File file = new File("C:\\Users\\zhao\\Desktop\\out\\res1.csv"); - // 雿輻 FDF 頧賣隞 - DataFrame execute1 = FDataFrame.builder(file) - // 隞嗅笆鞊∠霂餃閬摰砍蝚 - .setSep(',') - // 隞嗅笆鞊⊿閬摰憟賢蝘堆銝賭蝙 * 餈隞銵函銝舀亥砭嚗臬撱箔銝枋F摮畾 - .create("id", "name", "sex") - // 隞嗅笆鞊∠銝駁格摰霈訾蝙典蝘 - .primaryKey("name") - // 扯亥砭 - .execute(); - // 扳批怠蝏嚗霈∠箇瑕戊鈭箸 - long start = System.currentTimeMillis(); - System.out.println( - execute1 - // 摰亥砭嚗撟嗉絲怠 - .select(FieldCell.$("sex").as("批")) - // sex 蝏 - .groupBy("批") - // 餈銵 蝏霈⊥ - .count() - // 摰亥砭 撟嗉絲怠 - .select( - FieldCell.$("批"), - FieldCell.$("count()").as("鈭箸") - ) - // 啣銝銵唳 - .insert(FinalSeries.parse("", "10")) + ColorMatrix parse1; + { + // 瑕銝撘曉蝝拚 + ColorMatrix colors = ColorMatrix.parse("C:\\Users\\zhao\\Desktop\\fsdownload\\test3.bmp"); + // 撠曉瑁銝隞賢箸 + parse1 = ColorMatrix.parse(colors.copyToNewArrays()); + // 撠蝏鈭澆 + parse1.globalBinary(ColorMatrix._G_, 150, 0xffffff, 0); + } + // 撠頧桀蝥輯蓮拙耦頧桀 + ColorMatrix parse = RectangleMatrix.parse(parse1, Color.GREEN); + parse.show("鈭澆曉"); + System.out.print(parse); + // 撠拙耦頧桀瘛餃啣拚 餈閫荔憒憸脫啣潔蛹 0xff000000 撠曹撟 + ColorMatrix res = parse1.agg( + // 閬鋡怨銵瘛餃拚萄笆鞊 + parse, + // 瘛餃餉 餈雿輻函臬暺脩憸脣蝝湔亥 銝粹支暺脖誑憭蝝賣航蔭撱 + (inputType1, inputType2) -> inputType2.getRGB() == 0xff000000 ? inputType1 : inputType2 ); - System.out.print("憭塚MS嚗嚗"); - System.out.println(System.currentTimeMillis() - start); + res.show("蝏"); } } - ``` -* 賢撖道F唳桅撖寡情銝剔啣潸銵銵唳桃賣啣湔堆嗆舀DF唳桀笆鞊∪啁拚萎渡頧祆U +* 舀拚萇訾撮賣啁霈∠嚗刻典臭誑批銝蝷箔餈銵拙耦訾撮摨衣霈∠ ```java package zhao.algorithmMagic; +import zhao.algorithmMagic.algorithm.distanceAlgorithm.ManhattanDistance; +import zhao.algorithmMagic.algorithm.distanceAlgorithm.StandardizedEuclideanDistance; +import zhao.algorithmMagic.core.AlgorithmStar; +import zhao.algorithmMagic.operands.matrix.DoubleMatrix; import zhao.algorithmMagic.operands.matrix.IntegerMatrix; -import zhao.algorithmMagic.operands.table.DataFrame; -import zhao.algorithmMagic.operands.table.FDataFrame; -import zhao.algorithmMagic.operands.table.FieldCell; -import zhao.algorithmMagic.operands.table.FinalCell; -import zhao.algorithmMagic.operands.vector.IntegerVector; - -import java.io.File; public class MAIN1 { public static void main(String[] args) { - // 憭隞嗅笆鞊 - File file = new File("C:\\Users\\zhao\\Desktop\\out\\res1.csv"); - // 雿輻 FDF 頧賣隞 - DataFrame execute1 = FDataFrame.builder(file) - // 隞嗅笆鞊∠霂餃閬摰砍蝚 - .setSep(',') - // 隞嗅笆鞊⊿閬摰憟賢蝘堆銝賭蝙 * 餈隞銵函銝舀亥砭嚗臬撱箔銝枋F摮畾 - .create("id", "name", "sex") - // 隞嗅笆鞊∠銝駁格摰霈訾蝙典蝘 - .primaryKey("name") - // 扯亥砭 - .execute() - // 銝箏韏瑕怠 - .select( - FieldCell.$("id"), - FieldCell.$("name").as("蝘"), - FieldCell.$("sex").as("批") - ) - // 撠批怠餈銵頧祆g瑞銝1 憟喟銝0 - .updateCol(FieldCell.$("批"), cell -> new FinalCell<>(cell.getStringValue().equals("") ? 1 : 0)) - // 撠銵銝駁格啣潔蛹ZLY唳株銝剔潭踵X銝箸唳 405 - .updateRow("ZLY", cell -> new FinalCell<>(405)); - - // 啣箄”銝剔銵銝駁桀蝘唬蛹 405 唳株 - System.out.println(execute1.selectRow("405")); - long start = System.currentTimeMillis(); - // 撠銵刻蓮X銝箔銝芣游耦拚萄笆鞊∴霂交雿隡撠DF撖寡情銝剔啣潸曇蓮X銝 col.count()*3 拚萄笆鞊 - IntegerMatrix parse = IntegerMatrix.parse(execute1, execute1.count().getIntValue(), 3); - System.out.println(IntegerVector.parse(parse.getArrayByColIndex(2))); - System.out.print("憭塚MS嚗嚗"); - System.out.println(System.currentTimeMillis() - start); - } -} -``` - -* 舀餈銝銝芰蝏 URL 撖寡情瑕唳喳曉唳殷撟嗅嗉蓮X銝箔銝芸曉拚萸 - -```java -package zhao.algorithmMagic; - -import zhao.algorithmMagic.operands.matrix.ColorMatrix; + // 瑕唬銝芸曉拚萇憸涮GB啣 + IntegerMatrix parse1, parse2, parse3; + { + parse1 = IntegerMatrix.parse("C:\\Users\\zhao\\Desktop\\fsdownload\\test3.bmp"); + parse2 = IntegerMatrix.parse("C:\\Users\\zhao\\Desktop\\fsdownload\\test32.bmp"); + parse3 = IntegerMatrix.parse("C:\\Users\\zhao\\Desktop\\fsdownload\\test33.bmp"); + } + // 霈∠箔銝芸曉訾撮摨衣頂 + AlgorithmStar algorithmStar = AlgorithmStar.getInstance(); + System.out.println(algorithmStar.getTrueDistance(ManhattanDistance.getInstance("MAN"), parse1, parse2)); + System.out.println(algorithmStar.getTrueDistance(ManhattanDistance.getInstance("MAN"), parse1, parse3)); -import java.net.MalformedURLException; -import java.net.URL; + // 撠銝銝芸曉拚萇啣潸蓮X銝榛ouble蝐餃嚗瑕蚤ouble拚 + DoubleMatrix parse11, parse22, parse33; + { + parse11 = DoubleMatrix.parse(parse1); + parse22 = DoubleMatrix.parse(parse2); + parse33 = DoubleMatrix.parse(parse3); + } + // 霈∠箔銝芸曉訾撮摨衣頂 + System.out.println(algorithmStar.getTrueDistance(ManhattanDistance.getInstance("MAN"), parse11, parse22)); + System.out.println(algorithmStar.getTrueDistance(ManhattanDistance.getInstance("MAN"), parse11, parse33)); -public class MAIN1 { - public static void main(String[] args) throws MalformedURLException { - // 憭曉URL撖寡情 - URL url = new URL("https://user-images.githubusercontent.com/113756063/194830221-abe24fcc-484b-4769-b3b7-ec6d8138f436.png"); - // 閫URL瑕啣曉拚 - ColorMatrix parse1 = ColorMatrix.parse(url); - // 閫URL瑕啣曉啣漲拚 - ColorMatrix parse2 = ColorMatrix.parseGrayscale(url); - // 亦曉 - parse1.show("image"); - parse2.show("image"); + // TODO 澆瘜冽 甈批敺銝舀餈蝐餅雿霈∠ 餈銝隡仿 + double se = algorithmStar.getTrueDistance(StandardizedEuclideanDistance.getInstance2("SE"), parse11, parse22); + System.out.println(se); } } ``` -* 舀餈銵脣蔗鈭澆閫渲嚗賢餈摰脣蔗啣潘曄內箸游曉孵嚗駁斗游雿孵 +* 舀曉拚萎葉閫曉耦嚗拙耦嚗蝏塚蝏嗉蝔撠銝隡鈭抒雿霈∠霈∠唳柴 ```java package zhao.algorithmMagic; +import zhao.algorithmMagic.operands.coordinate.IntegerCoordinateTwo; import zhao.algorithmMagic.operands.matrix.ColorMatrix; -import java.net.MalformedURLException; -import java.net.URL; +import java.awt.*; public class MAIN1 { - public static void main(String[] args) throws MalformedURLException { - // 憭曉URL撖寡情 - URL url = new URL("https://user-images.githubusercontent.com/113756063/194830221-abe24fcc-484b-4769-b3b7-ec6d8138f436.png"); - // 閫URL瑕啣曉拚 - ColorMatrix parse1 = ColorMatrix.parse(url); - // 撠 URL 曉拚萎葉 G 憸脫啣澆之鈭 40 憸脣港蛹暺莎銋港蛹質 - // 刻曹拐 G 甇 蝏輯脰瘛 頞航賢銝箇質 - parse1.globalBinary(ColorMatrix._G_, 40, 0, 0xffffff); - // 銋臭誑雿輻典嗅憸脤餈銵脣蔗靚 - parse1.globalBinary(ColorMatrix._R_, 40, 0, 0xffffff); - parse1.globalBinary(ColorMatrix._B_, 40, 0, 0xffffff); - // 亦蝏曉 - parse1.show("image"); + public static void main(String[] args) { + ColorMatrix colorMatrix1; + // 撠曉銝瑟祈粉餈 + colorMatrix1 = ColorMatrix.parse("C:\\Users\\zhao\\Desktop\\fsdownload\\test3.bmp"); + // 撠曉拚萇嗅啣拚萎葉嚗撟嗆亦蝏 + colorMatrix1.drawRectangle( + // 拙耦撌虫閫 + new IntegerCoordinateTwo(40, 30), + // 拙耦喃閫 + new IntegerCoordinateTwo(140, 130), + // 拙耦颲寞憸脣笆鞊 + Color.MAGENTA + ); + colorMatrix1.show("res"); } } ``` -* 舀餈銵曉 ASCII 曄嚗典臭誑敹恍撠銝銝芸曄 ASCII 箸伐銝餈霂瑟函&靽曉撠箏站頞喳撠 +* 舀曉拚萇璅⊥踹寥雿嚗嗡葉瑞妖詨之撠銝箸芋踹之撠嚗敶璅⊥蹂曉拙耦摰賢漲銝渡嗅隡雿輻其蝞瘜 ```java package zhao.algorithmMagic; +import zhao.algorithmMagic.algorithm.distanceAlgorithm.ManhattanDistance; +import zhao.algorithmMagic.operands.coordinate.IntegerCoordinateTwo; import zhao.algorithmMagic.operands.matrix.ColorMatrix; -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; +import java.util.Map; public class MAIN1 { - public static void main(String[] args) throws MalformedURLException { - // 憭曉URL撖寡情 - URL url = new URL("https://user-images.githubusercontent.com/113756063/194830221-abe24fcc-484b-4769-b3b7-ec6d8138f436.png"); - // 閫URL瑕啣曉拚 - ColorMatrix parse1 = ColorMatrix.parse(url); - // 亦蝏曉 - parse1.show("image"); - // 颲箏曉 ASCII 啣潘颲箄銝 G 憸脫啣 憭找 40 颲箇泵 'A' 嗅颲箇泵 ' ' - parse1.save( - new File("C:\\Users\\zhao\\Desktop\\fsDownload\\res.txt"), - ColorMatrix._G_, 40, 'A', ' ' + public static void main(String[] args) { + ColorMatrix colorMatrix1, colorMatrix2; + // 撠曉銝瑟祈粉餈 + colorMatrix1 = ColorMatrix.parse("C:\\Users\\zhao\\Desktop\\fsdownload\\test3.bmp"); + colorMatrix2 = ColorMatrix.parse("C:\\Users\\zhao\\Desktop\\fsdownload\\test3YB.bmp"); + // 雿輻冽芋踹寥 瑕 colorMat1 銝 銝 colorMat2 貉摮拚萎縑 + // 嗡葉 key 銝箸訾撮摮拚萄寥蝟餅 value 銝箸訾撮摮拚萄椰銝閫 + Map.Entry matching = colorMatrix1.templateMatching( + // 訾撮摨西恣蝞蝏隞 + ManhattanDistance.getInstance("MAN"), + // 璅⊥踹曉 + colorMatrix2, + // 閬鋡怨恣蝞憸脤 + ColorMatrix._G_, + // 瑞妖嗥甇仿踵啣 + 10, + // 訾撮摨西撠 寥摨西憭 + false ); + System.out.println(matching); } } ``` -* 賢典撱箔銝芰征 DataFrame 撖寡情嚗撟嗉芯蜓雿嗡葉唳柴 +* 舀拚萇敶銝雿嚗雿踹敶銝霈∠賢其游撟踵撖寡情 ```java package zhao.algorithmMagic; -import zhao.algorithmMagic.operands.table.DataFrame; -import zhao.algorithmMagic.operands.table.FDataFrame; -import zhao.algorithmMagic.operands.table.FieldCell; -import zhao.algorithmMagic.operands.table.FinalSeries; +import zhao.algorithmMagic.algorithm.normalization.LinearNormalization; +import zhao.algorithmMagic.core.AlgorithmStar; +import zhao.algorithmMagic.operands.matrix.DoubleMatrix; +import zhao.algorithmMagic.operands.matrix.IntegerMatrix; public class MAIN1 { public static void main(String[] args) { - // 撱箔銝芰征 DF 撖寡情 隞 name 雿銝箄銝駁桃揣撘 - FDataFrame create = FDataFrame.select(FieldCell.parse("name", "sex", "phoneNum"), 1); - // 乩鈭唳 - DataFrame insert = create.insert( - FinalSeries.parse("zhao", "M", "110xxxxxxxx"), - FinalSeries.parse("tang", "W", "110xxxxxxxx"), - FinalSeries.parse("yang", "M", "110xxxxxxxx") + IntegerMatrix integerMatrix = IntegerMatrix.parse( + new int[]{1, 2, 3, 4, 5}, + new int[]{5, 4, 3, 4, 5}, + new int[]{5, 4, 3, 2, 1} ); - // 亦唳桅 - System.out.println(insert); - // 撠嗡葉 name sex 亥砭 - System.out.println( - insert.select( - FieldCell.$("name").as("AllName"), - FieldCell.$("sex").as("AllSex") - ) + // 敶銝霈∠蝏隞 + LinearNormalization line = LinearNormalization.getInstance("line").setMax(3).setMin(-3); + AlgorithmStar algorithmStar = AlgorithmStar.getInstance(); + // 撘憪餈銵敶銝雿 + IntegerMatrix pretreatment1 = algorithmStar.pretreatment( + line, + // 閬鋡怠銝拚萄笆鞊 + integerMatrix ); + System.out.print(pretreatment1); + + DoubleMatrix doubleMatrix = DoubleMatrix.parse(integerMatrix); + DoubleMatrix pretreatment2 = algorithmStar.pretreatment(line, doubleMatrix); + System.out.print(pretreatment2); } } ``` -* 舀 group 嗅摰 where摮伐雿踹霈∠憭批之憓撘 +* 舀拚萇餈賢撟嗉恣蝞嚗嗅臭誑撠銝支葵曉拚萄撟嗅啣銝銝芣啁曉拚萎葉 ```java package zhao.algorithmMagic; -import zhao.algorithmMagic.operands.table.DataFrame; -import zhao.algorithmMagic.operands.table.FDataFrame; -import zhao.algorithmMagic.operands.table.FieldCell; -import zhao.algorithmMagic.operands.table.FinalSeries; +import zhao.algorithmMagic.operands.matrix.ColorMatrix; import java.net.MalformedURLException; +import java.net.URL; public class MAIN1 { - public static void main(String[] args) { - // 撱箔銝芰征 DF 撖寡情 隞 name 雿銝箄銝駁桃揣撘 - FDataFrame create = FDataFrame.select(FieldCell.parse("name", "sex", "phoneNum"), 1); - // 乩鈭唳 - DataFrame insert = create.insert( - FinalSeries.parse("zhao1", "M", "110xxxxxxxx"), - FinalSeries.parse("tang2", "W", "120xxxxxxxx"), - FinalSeries.parse("yang3", "W", "110xxxxxxxx"), - FinalSeries.parse("zhao4", "M", "120xxxxxxxx"), - FinalSeries.parse("tang5", "W", "110xxxxxxxx"), - FinalSeries.parse("yang6", "W", "110xxxxxxxx"), - FinalSeries.parse("zhao7", "M", "120xxxxxxxx"), - FinalSeries.parse("tang8", "W", "110xxxxxxxx"), - FinalSeries.parse("yang9", "W", "110xxxxxxxx") - ); - // 亦唳桅 - System.out.println(insert); - // 撠嗡葉箏瑕銝雿銝銝 120 唳株批嗡葉 sex 蝏 刻湔乩蝙典蝏嗉皛文喳 - System.out.println( - insert.groupBy("sex", v -> { - // 瑕唳箏瑞摮蝚虫葡 - String s = v.getCell(2).toString(); - // 斗剖 3 銝芸蝚行臬虫蛹 120 嚗臬虫誑 120 撘憭湛 憒臬停銝瘛餃 - return !s.startsWith("120"); - }).count() + public static void main(String[] args) throws MalformedURLException { + // 瑕唬銝芸曉拙耦撖寡情 + ColorMatrix parse1 = ColorMatrix.parse( + new URL("https://user-images.githubusercontent.com/113756063/229441864-ec1770d5-1154-4e9c-837e-a4acfc5fb259.jpg") ); + // 撠曉拚萄笆鞊⊥瑁箔隞賢僎餈銵憸脣頧 + ColorMatrix parse2 = ColorMatrix.parse(parse1.copyToNewArrays()).colorReversal(false); + // 撠銝支葵曉拚菔銵撟嗆雿嚗撟嗅蝷箏箔銝撌血喳撟嗥蝏曉 + // 餈臬椰喳撟 + ColorMatrix colorMatrixLR = parse1.append(parse2, true); + // 餈臭銝撟 + ColorMatrix colorMatrixTB = parse1.append(parse2, false); + // 亦蝏曉 + colorMatrixLR.show("LR"); + colorMatrixTB.show("TB"); } } ``` -* 舀撅其澆雿嚗賢摰啣曉鈭澆憭嚗貉鈭典鈭澆嚗賣唳游菜暑 +* 舀曉拚萇典W賣唳雿嚗刻銝芸賣唬葉嚗典臭誑函摰拙耦X芋撘嚗銋臭誑典啣曉a餉 ```java package zhao.algorithmMagic; import zhao.algorithmMagic.operands.matrix.ColorMatrix; +import zhao.algorithmMagic.operands.table.Cell; +import zhao.algorithmMagic.operands.table.FinalCell; + +import java.util.HashMap; -import java.net.MalformedURLException; -import java.net.URL; public class MAIN1 { - public static void main(String[] args) throws MalformedURLException { - // 瑕啣曉拚 - ColorMatrix parse = ColorMatrix.parse(new URL("https://img-blog.csdnimg.cn/img_convert/5765bdab08ef6e117d434e7e225b9013.png")); - parse.show("image"); - System.out.println("ok!!!"); - System.out.println(" = " + parse.getRowCount()); - System.out.println("摰 = " + parse.getColCount()); - // 撠曉餈銵撅其澆 - parse.localBinary( - // 摰祆活鈭澆拍憸脤 - ColorMatrix._G_, - // 摰祆活鈭澆箇撅典曉拚菜圈 - 100, - // 摰祆活鈭澆銝剖函拚萎葉憭找撅券潛憸脩 - 0xffffff, - // 摰祆活鈭澆銝剖函拚萎葉撠鈭撅券潛憸脩 - 0, - // 摰祆活鈭澆銝剖券潛閬餈銵敺株啣潘餈舫雿20銝芷潭啣 - -30 - ); - // 亦蝏唳 - parse.show("image"); + public static void main(String[] args) { + // 鋡怠曉頝臬 + String dataPath = "C:\\Users\\Liming\\Desktop\\fsdownload\\test7.jpg"; + ColorMatrix colorMatrix1 = ColorMatrix.parse(dataPath); + // 撠拚萄 擐閬撱箏箔璅∪銝剝閬蝵桐縑 餈臬頧砍隡貊拚萇蝵 + HashMap> pro = new HashMap<>(); + // 頧祉拚菜嗆摰瑁雿 + pro.put("isCopy", new FinalCell<>(true)); + // 隡貊拚菜嗆摰隡詨 + pro.put("times", new FinalCell<>(2)); + // 銝銝 頧 + ColorMatrix converter1 = colorMatrix1.converter(ColorMatrix.REVERSE_BT, pro); + converter1.show("REVERSE_BT"); + // 撌血 頧 + converter1 = colorMatrix1.converter(ColorMatrix.REVERSE_LR, pro); + converter1.show("REVERSE_LR"); + // 銝銝 隡 + converter1 = colorMatrix1.converter(ColorMatrix.SLIT_BT, pro); + converter1.show("SLIT_BT"); + // 撌血 隡 + converter1 = colorMatrix1.converter(ColorMatrix.SLIT_LR, pro); + converter1.show("SLIT_LR"); } } ``` -* DF撖寡情唳格舀靽摮銝 HTML 隞塚賢摰唳芸典憿菟Y嗆雿 +* 舀餈憭渲瑕啣曉拚萸 ```java package zhao.algorithmMagic; -import zhao.algorithmMagic.operands.table.DataFrame; -import zhao.algorithmMagic.operands.table.FDataFrame; -import zhao.algorithmMagic.operands.table.FieldCell; -import zhao.algorithmMagic.operands.table.FinalSeries; +import zhao.algorithmMagic.io.InputCamera; +import zhao.algorithmMagic.io.InputCameraBuilder; +import zhao.algorithmMagic.io.InputComponent; +import zhao.algorithmMagic.operands.matrix.ColorMatrix; +import zhao.algorithmMagic.operands.matrix.DoubleMatrix; +import zhao.algorithmMagic.operands.table.FinalCell; public class MAIN1 { public static void main(String[] args) { - // 撱箔銝芰征 DF 撖寡情 隞 name 雿銝箄銝駁桃揣撘 - FDataFrame create = FDataFrame.select(FieldCell.parse("name", "sex", "phoneNum", "salary"), 1); - // 乩鈭唳 - DataFrame insert = create.insert( - FinalSeries.parse("zhao1", "M", "110xxxxxxxx", "30000"), - FinalSeries.parse("tang2", "W", "120xxxxxxxx", "30000"), - FinalSeries.parse("yang3", "W", "110xxxxxxxx", "30000"), - FinalSeries.parse("zhao4", "M", "120xxxxxxxx", "30000"), - FinalSeries.parse("tang5", "W", "110xxxxxxxx", "30000"), - FinalSeries.parse("yang6", "W", "110xxxxxxxx", "30000"), - FinalSeries.parse("zhao7", "M", "120xxxxxxxx", "30000"), - FinalSeries.parse("tang8", "W", "110xxxxxxxx", "30000"), - FinalSeries.parse("yang9", "W", "110xxxxxxxx", "30000") - ); - // 颲箄”HTML 嗅亦銵其葉唳 - System.out.println( - insert.into_outHtml("C:\\Users\\Liming\\Desktop\\fsDownload\\res11234.html", "myTable") - ); + // 瑕唳憭渲亥挽憭 + InputComponent inputComponent = InputCamera.builder() + // 閬雿輻函憭渡摮 蝝W def暺霈歹隞祈雿輻函 def 隞銵其蝙券霈斗憭 + .addInputArg(InputCameraBuilder.Camera_Index, new FinalCell<>("def")) + // 閬雿輻函曉澆 + .addInputArg(InputCameraBuilder.Image_Format, new FinalCell<>("JPG")) + // 曉撠箏站 餈啣潭 WebcamResolution 銝曄掩撅批畾 VGA + .addInputArg(InputCameraBuilder.CUSTOM_VIEW_SIZES, new FinalCell<>("VGA")) + .create(); + ColorMatrix parse1 = ColorMatrix.parse(inputComponent); + parse1.show("image1"); + double[][] double2Array = inputComponent.getDouble2Array(); + DoubleMatrix parse = DoubleMatrix.parse(double2Array); } } ``` -* 曉撘憪舀 add 賣堆災dd賣啁雿銝嚗臭誑摰啣曉賣啁撟塚 +* 舀餈 HDFS 瑕 ColorMatrix 雿啣笆鞊∩誑 ColorMatrix 唳桀笆鞊∠靽摮雿 ```java package zhao.algorithmMagic; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import zhao.algorithmMagic.io.*; import zhao.algorithmMagic.operands.matrix.ColorMatrix; +import zhao.algorithmMagic.operands.table.FinalCell; + +import java.io.IOException; -import java.sql.SQLException; public class MAIN1 { - public static void main(String[] args) { - // 撠銝鈭曉隞嗉蓮X銝箔銝芸曉拚萄笆鞊 - ColorMatrix colorMatrix1 = ColorMatrix.parse("C:\\Users\\Liming\\Desktop\\fsDownload\\test.bmp"); - ColorMatrix colorMatrix2 = ColorMatrix.parse("C:\\Users\\Liming\\Desktop\\fsDownload\\test1.bmp"); - // 撠 colorMatrix2 + colorMatrix1 蝏曉撅蝷箏箸 - (colorMatrix1.add(colorMatrix2)).show("image"); + public static void main(String[] args) throws IOException { + // 瑕 HDFS 唳株亥箄挽憭撖寡情 擐撠銝方閬啣撱箏箸 + FileSystem fileSystem; + String inPath; + { + Path path = new Path("hdfs://192.168.0.141:8020"); + // 撱慵DFS隞嗥頂蝏撖寡情 + fileSystem = path.getFileSystem(new Configuration()); + // 霈曄蔭閬鋡怨粉隞嗅笆鞊 + inPath = "hdfs://192.168.0.141:8020/data/test.png"; + } + + /* ***************************************************** + * TODO 隞HDFS銝剖頧賣唳 + * *****************************************************/ + // 撘憪撠圈蝵桀啗挽憭撖寡情銝哨撱箏箸唳株亥挽憭 + InputComponent inputComponent = InputHDFS.builder() + .addInputArg(InputHDFSBuilder.FILE_SYSTEM, new FinalCell<>(fileSystem)) + .addInputArg(InputHDFSBuilder.IN_PATH, new FinalCell<>(inPath)) + // 曹曉銝閬摮畾萄蝘堆雿臬冽脫迫蝛箏潭⊿嚗甇方隡銝銝芸蝚虫葡蝏喳 + .addInputArg(InputHDFSBuilder.FIELD, new FinalCell<>(new String[]{"null"})) + .create(); + + /* ***************************************************** + * TODO 憭頧賢箸亦 Color 撖寡情嚗餈臬憸脰銵頧 + * *****************************************************/ + // 撘憪撠 HDFS 銝剔唳桀頧賣銝箔銝 曉拚 撖寡情 撟嗅嗉銵憸脣頧祆雿 + ColorMatrix colorMatrix = ColorMatrix.parse(inputComponent); + colorMatrix.colorReversal(false); + + /* ***************************************************** + * TODO 撠憭憟賜唳株箏 HDFS /data/res.jpg 銝 + * *****************************************************/ + // 摰靘箸亦格頝臬 + Path path = new Path("hdfs://192.168.0.141:8020/data/res.jpg"); + // 撘憪撱箸唳株箇隞 + OutputComponent outputComponent = OutputHDFS.builder() + .addOutputArg(OutputHDFSBuidler.FILE_SYSTEM, new FinalCell<>(fileSystem)) + .addOutputArg(OutputHDFSBuidler.OUT_PATH, new FinalCell<>(path)) + .addOutputArg(OutputHDFSBuidler.FORMAT, new FinalCell<>("JPG")) + .create(); + // 撘憪餈蝏隞嗅唳株 嗆啣箇 + colorMatrix.show("res"); + colorMatrix.save(outputComponent); } } ``` -* 舀芸銋隞亙蝵格唳格寞雿 +* 舀餈 HDFS 瑕 DataFrame 雿啣笆鞊∴嗉舀霂亙笆鞊∠唳株箝 ```java package zhao.algorithmMagic; -import zhao.algorithmMagic.operands.matrix.ColorMatrix; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import zhao.algorithmMagic.io.*; +import zhao.algorithmMagic.operands.table.DataFrame; +import zhao.algorithmMagic.operands.table.FDataFrame; +import zhao.algorithmMagic.operands.table.FinalCell; + +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.OutputStreamWriter; -import java.sql.SQLException; public class MAIN1 { - public static void main(String[] args) { - // 撠銝鈭曉隞嗉蓮X銝箔銝芸曉拚萄笆鞊 - ColorMatrix colorMatrix1 = ColorMatrix.parse("C:\\Users\\Liming\\Desktop\\fsDownload\\test.bmp"); - ColorMatrix colorMatrix2 = ColorMatrix.parse("C:\\Users\\Liming\\Desktop\\fsDownload\\test1.bmp"); - // 雿輻 agg 賣唬誑蝵桃霈∠寞餈銵銝支葵拚萇撟 - // 銝W賣唬葉蝚砌銝芸耦隞銵函撠望舐拚萎葉蝝餉嚗餈雿輻函舀嚗撟嗅笆頞憸脫啣潸銵閫渡餉摰 - colorMatrix1.agg(colorMatrix2, ColorMatrix.COLOR_SUM_REGULATE).show("image"); + public static void main(String[] args) throws IOException { + // 瑕 HDFS 唳株亥箄挽憭撖寡情 擐撠銝方閬啣撱箏箸 + FileSystem fileSystem; + String inPath; + { + Path path = new Path("hdfs://192.168.0.141:8020"); + // 撱慵DFS隞嗥頂蝏撖寡情 + fileSystem = path.getFileSystem(new Configuration()); + // 霈曄蔭閬鋡怨粉隞嗅笆鞊 + inPath = "hdfs://192.168.0.141:8020/data/test.txt"; + } + + /* ***************************************************** + * TODO 隞HDFS銝剖頧賣唳 + * *****************************************************/ + // 撘憪撠圈蝵桀啗挽憭撖寡情銝哨撱箏箸唳株亥挽憭 + InputComponent inputComponent = InputHDFS.builder() + .addInputArg(InputHDFSBuilder.FILE_SYSTEM, new FinalCell<>(fileSystem)) + .addInputArg(InputHDFSBuilder.IN_PATH, new FinalCell<>(inPath)) + // 霈曄蔭隞嗡葉摰寧摮畾萄蝘 + .addInputArg(InputHDFSBuilder.FIELD, new FinalCell<>(new String[]{"name", "sex", "age"})) + // 霈曄蔭隞嗡葉瘥蝚 + .addInputArg(InputHDFSBuilder.SEP, new FinalCell<>('\t')) + // 霈曄蔭隞嗡葉霂餃摮蝚阡 + .addInputArg(InputHDFSBuilder.CHAR_SET, new FinalCell<>("utf-8")) + .create(); + + /* ***************************************************** + * TODO 憭頧賢箸亦 DataFrame 撖寡情嚗餈舀 age 甇摨摨 + * *****************************************************/ + // 撘憪撠 HDFS 銝剔唳桀頧賣銝箔銝 DataFrame 撖寡情 撟嗅嗉銵age甇摨摨雿 + DataFrame builder = FDataFrame + .builder(inputComponent) + .sort("age"); + + /* ***************************************************** + * TODO 撠憭憟賜唳株箏 HDFS /data/res.csv 銝 + * *****************************************************/ + // 摰靘箸亦格頝臬 + Path path = new Path("hdfs://192.168.0.141:8020/data/res.csv"); + // 撘憪撱箸唳株箇隞 + OutputComponent outputComponent = OutputHDFS.builder() + // 霈曄蔭颲箸嗥HDFS隞嗥頂蝏隞亙嗉楝敺 + .addOutputArg(OutputHDFSBuidler.FILE_SYSTEM, new FinalCell<>(fileSystem)) + .addOutputArg(OutputHDFSBuidler.OUT_PATH, new FinalCell<>(path)) + // 霈曄蔭颲箸澆嚗餈航箔銝杭SV隞 + .addOutputArg(OutputHDFSBuidler.FORMAT, new FinalCell<>("csv")) + // 颲箸嗥蝚 + .addOutputArg(OutputHDFSBuidler.SEP, new FinalCell<>(',')) + .create(); + // 撘憪餈蝏隞嗅唳株 嗡蝙 show 賣啣冽批嗅唳啣箇 澆瘜冽荔show 賣唬隡喲剜唳格撖寡情 + BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(System.out)); + builder.show(bufferedWriter); + System.out.println("ok!!!!"); + builder.into_outComponent(outputComponent); } } ``` -* 曉拚菜舀餈蝞賣堆刻砲賣唬葉臭誑駁斗雿孵唳柴 +* 舀餈唳格瑕唳唳桀笆鞊∴刻隞砌蝟餌颲交銝剛瑕 DataFrame 撖寡情嚗瞍蝷箝 ```java package zhao.algorithmMagic; -import zhao.algorithmMagic.operands.matrix.ColorMatrix; +import zhao.algorithmMagic.io.InputByStream; +import zhao.algorithmMagic.io.InputByStreamBuilder; +import zhao.algorithmMagic.io.InputComponent; +import zhao.algorithmMagic.operands.table.DataFrame; +import zhao.algorithmMagic.operands.table.FDataFrame; +import zhao.algorithmMagic.operands.table.FinalCell; -import java.sql.SQLException; +import java.io.IOException; public class MAIN1 { public static void main(String[] args) { - // 撠銝鈭曉隞嗉蓮X銝箔銝芸曉拚萄笆鞊 - ColorMatrix colorMatrix1 = ColorMatrix.parseGrayscale("C:\\Users\\Liming\\Desktop\\fsDownload\\test2.bmp"); - // 撖孵曉餈銵鈭澆 - colorMatrix1.globalBinary(ColorMatrix._G_, 100, 0xffffff, 0); - colorMatrix1.show("銋 image"); - // 撘憪撖孵曉拚菔銵雿 - colorMatrix1.erode(2, 2, false).show("銋 image"); + /* ***************************************************** + * TODO 隞唳格銝剛粉唳唳 撟嗆撱 DF 撖寡情 + * *****************************************************/ + // 撘憪撠圈蝵桀啗挽憭撖寡情銝哨撱箏箸唳株亥挽憭 + InputComponent inputComponent = InputByStream.builder() + // 憭唳株交嚗刻憭舐蝡舀唳株交 + .addInputArg(InputByStreamBuilder.INPUT_STREAM, new FinalCell<>(System.in)) + // 霈曄蔭唳株亦摮蝚阡 + .addInputArg(InputByStreamBuilder.CHARSET, new FinalCell<>("utf-8")) + // 曹 DF 唳桀頧賣舐璅∪頧踝甇日閬霈曄蔭唳株亦蝚 + .addInputArg(InputByStreamBuilder.SEP, new FinalCell<>(',')) + // 曹 DF 唳桀笆鞊⊥銝駁桀踝甇日閬摰銝駁桃揣撘蝻 餈臭0撘憪蝝W + .addInputArg(InputByStreamBuilder.PK, new FinalCell<>(1)) + // 霈曄蔭祆活唳株颲亦銵圈 隞銵冽隞祈颲 3 銵唳 + .addInputArg(InputByStreamBuilder.ROW_LEN, new FinalCell<>(3)) + .create(); + // 撘憪餈銵唳桃頧 閬瘜冽荔曹隞砌蝙函舐蝡舀唳格嚗甇支閬獢嗆亙喲剜唳格嚗閬摰isOC銝榻alse + DataFrame builder = FDataFrame.builder(inputComponent, true); + builder.show(); } } ``` -* 舀瘛餃嚗雿舫閬瘜冽臬瘛餃隡餈銝銝芣啁 DataFrame DF銝剔唳桀隡鋡急瑁箸乓 +* 舀餈 AlgorithmStar 霂餃唳啣潛拚萎蝏 DF 唳桀笆鞊∴餈蝘孵撱箔餈 摰啁掩parse賣啣撱箇銝瑯 ```java package zhao.algorithmMagic; -import zhao.algorithmMagic.operands.table.*; +import zhao.algorithmMagic.core.AlgorithmStar; +import zhao.algorithmMagic.io.InputByStream; +import zhao.algorithmMagic.io.InputByStreamBuilder; +import zhao.algorithmMagic.io.InputComponent; +import zhao.algorithmMagic.operands.matrix.DoubleMatrix; +import zhao.algorithmMagic.operands.matrix.IntegerMatrix; +import zhao.algorithmMagic.operands.table.DataFrame; +import zhao.algorithmMagic.operands.table.FinalCell; +import java.io.File; +import java.io.IOException; +import java.sql.Connection; +import java.sql.DriverManager; import java.sql.SQLException; + public class MAIN1 { - public static void main(String[] args) { - // 撱箔銝芰征 DataFrame 撖寡情 - FDataFrame select = FDataFrame.select( - FieldCell.parse("id", "name", "sex", "age"), 1 - ); - // 冽交唳 - select.insert( - FinalSeries.parse("1", "zhao", "M", "19"), - FinalSeries.parse("2", "tang", "W", "18"), - FinalSeries.parse("3", "yang", "W", "20"), - FinalSeries.parse("4", "shen", "W", "19") - ); - // 啣 DF 撖寡情喟靽⊥ - System.out.println( - select.desc() + public static void main(String[] args) throws SQLException { + /* ***************************************************** + * TODO 隞唳格銝剛粉唳唳 + * *****************************************************/ + // 撘憪撠圈蝵桀啗挽憭撖寡情銝哨撱箏箸唳株亥挽憭 + InputComponent inputComponent = InputByStream.builder() + .addInputArg(InputByStreamBuilder.INPUT_STREAM, new FinalCell<>(System.in)) + .addInputArg(InputByStreamBuilder.CHARSET, new FinalCell<>("utf-8")) + .addInputArg(InputByStreamBuilder.SEP, new FinalCell<>(',')) + .addInputArg(InputByStreamBuilder.PK, new FinalCell<>(1)) + .addInputArg(InputByStreamBuilder.ROW_LEN, new FinalCell<>(3)) + .create(); + + // TODO 撘憪餈 algorithmStar 撱箏箸啣潛拚 餈舀湔唬瘚桃寞唬舅蝘蝐餃 + IntegerMatrix integerMatrix = AlgorithmStar.parseIntMat( + new int[]{1, 2, 3}, new int[]{5, 6, 7}, new int[]{8, 9, 0} ); - // 瘛餃銝唳殷其銵函內撟湧臬虫蛹嗆 - DataFrame ageIsE = select.insertColGetNew( - // 啣蝘 - FieldCell.$("AgeIsE"), - // 啣啣潛餉 憒蝚 4 嚗index == 3嚗啣 % 2 == 0 撠望眩rue - cells -> cells.getCell(3).getIntValue() % 2 == 0 ? new FinalCell<>(true) : new FinalCell<>(false) + DoubleMatrix doubleMatrix = AlgorithmStar.parseDoubleMat( + new double[]{1, 2, 3}, new double[]{5, 6, 7}, new double[]{8, 9, 0} ); - System.out.println(ageIsE); - } -} -``` + System.out.println(integerMatrix); + System.out.println(doubleMatrix); -* 舀銵冽唳桐渡餈蝞雿嚗賢撠銵其葉啣潛掩餈銵瘙銝撌株恣蝞嚗霈∠銋撠餈蚤F撖寡情 - -```java -package zhao.algorithmMagic; + // TODO 撘憪餈 algorithmStar 撱箏慣ataFrame撖寡情 餈舫餈隞 唳桀 唳株亦隞 亥銵撱 + File file = new File("C:\\Users\\zhao\\Downloads\\test.csv"); + DataFrame dataFrame1 = AlgorithmStar.parseDF(file).setSep(',') + .create("year", "month", "day", "week", "temp_2", "temp_1", "average", "actual", "friend") + .execute(); + dataFrame1.show(); -import zhao.algorithmMagic.operands.table.*; + DataFrame dataFrame2 = AlgorithmStar.parseDF(inputComponent, false); + dataFrame2.show(); -public class MAIN1 { - public static void main(String[] args) { - // 撱箔銝芰征 DataFrame 撖寡情 - FDataFrame select1 = FDataFrame.select( - FieldCell.parse("id", "name", "sex", "age"), 1 - ); - // 冽交唳 - select1.insert( - FinalSeries.parse("1", "zhao", "M", "19"), - FinalSeries.parse("2", "tang", "W", "18"), - FinalSeries.parse("3", "yang", "W", "20"), - FinalSeries.parse("4", "shen", "W", "19") - ); - // 撱箔銝芰征 DataFrame 撖寡情 - FDataFrame select2 = FDataFrame.select( - FieldCell.parse("id", "name", "sex", "age"), 1 - ); - // 冽交唳 - select2.insert( - FinalSeries.parse("1", "zhao", "M", "19"), - FinalSeries.parse("2", "tang", "W", "18"), - FinalSeries.parse("3", "yang", "W", "20") - ); - // 餈銵瘙銝撌桃餈蝞雿 - System.out.println(select1.add(select2)); - System.out.println(select1.diff(select2)); + Connection connection = DriverManager.getConnection(""); + DataFrame dataFrame3 = AlgorithmStar.parseDF(connection) + .from("xxx") + .execute(); + dataFrame3.show(); } } ``` -* DataFrame唳桀笆鞊⊥摰撟 +* 舀餈 AlgorithmStar 霂餃啣曉拚蛛賢隞隞塚URL嚗隞亙唳株亦隞嗡葉瑕啣曉撖寡情嚗餈蝘孵撱箔餈 摰啁掩parse賣啣撱箇銝瑯 ```java package zhao.algorithmMagic; -import zhao.algorithmMagic.operands.table.*; +import zhao.algorithmMagic.core.AlgorithmStar; +import zhao.algorithmMagic.io.InputCamera; +import zhao.algorithmMagic.io.InputCameraBuilder; +import zhao.algorithmMagic.io.InputComponent; +import zhao.algorithmMagic.operands.matrix.ColorMatrix; +import zhao.algorithmMagic.operands.table.FinalCell; +import java.io.IOException; +import java.net.URL; import java.sql.SQLException; + public class MAIN1 { - public static void main(String[] args) { - // 撱箔銝芰征 DataFrame 撖寡情 - FDataFrame select = FDataFrame.select( - FieldCell.parse("id", "name", "sex", "age"), 1 - ); - // 冽交唳 嗅餈銵蝏 - GroupDataFrameData groupDataFrameData = select.insert( - FinalSeries.parse("1", "zhao", "M", "19"), - FinalSeries.parse("2", "tang", "W", "18"), - FinalSeries.parse("3", "yang", "W", "20") - ).groupBy("sex"); - // 啣 M 蝏唳 - System.out.println(groupDataFrameData.getDFByGroup("M")); - // 啣 W 蝏唳 - System.out.println(groupDataFrameData.getDFByGroup("W")); + public static void main(String[] args) throws IOException { + InputComponent inputComponent = InputCamera.builder() + .addInputArg(InputCameraBuilder.Camera_Index, new FinalCell<>(0)) + .addInputArg(InputCameraBuilder.Image_Format, new FinalCell<>("JPG")) + .create(); + // 餈唳株亥挽憭撖寡情瑕啣曉拚 + ColorMatrix colorMatrix = AlgorithmStar.parseImage(inputComponent, true); + colorMatrix.show("image"); + // 餈 URL 瑕啣曉拚 嚗銝箔蝞瘣銋血刻瘝⊥餈銵韏澆其嚗 + URL url = new URL("https://user-images.githubusercontent.com/113756063/194830221-abe24fcc-484b-4769-b3b7-ec6d8138f436.png"); + AlgorithmStar.parseImage(url).show("image"); + AlgorithmStar.parseGrayscaleImage(url).show("image"); + // 餈 隞 瑕啣曉拚 + AlgorithmStar.parseImage("C:\\Users\\zhao\\Desktop\\fsdownload\\test.bmp").show("image"); + AlgorithmStar.parseGrayscaleImage("C:\\Users\\zhao\\Desktop\\fsdownload\\test.bmp").show("image"); } } ``` -* 啁祆釣鈭憿對甇斤砌葉靘韏鋡急霈唬蛹 provided 餈瑕臭誑憭批雿雿蝔摨佗賢寞株芸楛摰憿寧格亥銵詨喟蝵殷甇文刻銵AS摨瘜典亦嗅霂瑕隞乩敹憿駁★銝桀紡乓 - -```xml - - - - - org.apache.logging.log4j - log4j-slf4j-impl - 2.20.0 - - - - - - org.apache.logging.log4j - log4j-api - 2.20.0 - - - - - org.apache.logging.log4j - log4j-core - 2.20.0 - - - -``` - -### Version update date : xx xx-xx-xx \ No newline at end of file +### Version update date : 2023-04-09 \ No newline at end of file diff --git a/src_code/README.md b/src_code/README.md index c5eacca..72843b7 100644 --- a/src_code/README.md +++ b/src_code/README.md @@ -1,6 +1,6 @@ # ![image](https://user-images.githubusercontent.com/113756063/194830221-abe24fcc-484b-4769-b3b7-ec6d8138f436.png) Algorithm Star-MachineBrain -- W [銝剜獢β(https://github.com/BeardedManZhao/algorithmStar/blob/main/src_code/README-Chinese.md) +- W [銝剜獢β(https://github.com/BeardedManZhao/algorithmStar/blob/Zhao-develop/src_code/README-Chinese.md) - knowledge base @@ -8,107 +8,35 @@ ### Update log: -* Framework version: 1.16 - 1.17 -* Change the name of the integrator to Integrator. -* It provides the calculation support of convolution function, which can enlarge the features and reduce the number of - elements in the image matrix. - -```java -package zhao.algorithmMagic; - -import zhao.algorithmMagic.integrator.ImageRenderingIntegrator; -import zhao.algorithmMagic.integrator.launcher.ImageRenderingMarLauncher; -import zhao.algorithmMagic.operands.matrix.IntegerMatrix; -import zhao.algorithmMagic.operands.matrix.block.IntegerMatrixSpace; - -public class MAIN1 { - public static void main(String[] args) { - String s1 = "C:\\Users\\Liming\\Desktop\\fsDownload\\敺桐縑曄_1.jpg"; - IntegerMatrix integerMatrix; - { - // 霈曄蔭 - IntegerMatrix weight = IntegerMatrix.parse( - new int[]{0, -1}, - new int[]{-1, 2}, - new int[]{0, 0} - ); - // 霂餃曉撟嗉瑕唬拚萇征 - IntegerMatrixSpace parse = IntegerMatrixSpace.parse(s1); - // 撖孵曉餈銵瑞妖嚗瑕銝銝芾脣蔗拚萇征渡 - integerMatrix = parse.foldingAndSum(2, 3, IntegerMatrixSpace.parse(weight, weight, weight)); - } - // 颲箏曄1瑞妖曉隞 - ImageRenderingIntegrator image = new ImageRenderingIntegrator( - "image", - new ImageRenderingMarLauncher<>(integerMatrix, "C:\\Users\\Liming\\Desktop\\fsDownload\\res12.jpg", 1) - ); - if (image.run()) { - System.out.println("ok!!!"); - } - } -} -``` - -* The image matrix supports displaying images on the screen directly through the show function. +* Framework version: 1.17 - 1.18 +* Add implementation support for the diff function to the image matrix, and add powerful subtractive aggregation + calculation functions to the matrix object. ```java package zhao.algorithmMagic; import zhao.algorithmMagic.operands.matrix.ColorMatrix; -public class MAIN1 { - public static void main(String[] args) throws InterruptedException { - String s1 = "C:\\Users\\Liming\\Desktop\\fsDownload\\敺桐縑曄_1.jpg"; - ColorMatrix parse = ColorMatrix.parse(s1); - parse.show("image"); - Thread.sleep(1024); - parse.colorReversal(false); - parse.show("image"); - } -} -``` - -* Optimize the algorithm of maximum random scrambling times in the random scrambling function shuffle, so that it will - not have out-of-bounds exceptions. -* Optimize the function logic of random access to data in the matrix through column names, and use hash to map - addresses. - -```java -package zhao.algorithmMagic; - -import zhao.algorithmMagic.operands.matrix.ColumnDoubleMatrix; - -import java.util.Arrays; -import java.util.Random; +import java.awt.*; public class MAIN1 { public static void main(String[] args) { - // 撱箔隞賜拚菜唳 - double[][] data = new double[][]{ - new double[]{10, 11, 14, 10, 100}, - new double[]{11, 11, 14, 10, 100}, - new double[]{25, 20, 28, 20, 100}, - new double[]{26, 20, 28, 20, 100} - }; - // 撠拚菜唳桐蝙冽摰銝銵蝘啁孵撱箏箸 - ColumnDoubleMatrix columnDoubleMatrix = ColumnDoubleMatrix.parse( - new String[]{"col1", "col2", "col3", "col4", "col5"}, - new String[]{"row1", "row2", "row3", "row4"}, - data - ); - // 雿輻其撱箸啁拚萇孵銋勗嗡葉唳桅◇摨 銝憭銋 10 甈 - columnDoubleMatrix.shuffle(new Random(), false, 10); - // 啣箇拚菜唳 - System.out.println(columnDoubleMatrix); - // 啣箇拚萎葉 col2 冽啁銝剛砲賣圈撣摰 摨行敺 - System.out.println(Arrays.toString(columnDoubleMatrix.getArrayByColName("col2"))); - // 啣箇拚萎葉 row2 銵 冽啁銝剛砲賣圈撣摰 摨行敺 - System.out.println(Arrays.toString(columnDoubleMatrix.getArrayByRowName("row2"))); + // 瑕銝撘曉蝝拚 + ColorMatrix parse1 = ColorMatrix.parseGrayscale("C:\\Users\\Liming\\Desktop\\fsdownload\\test1.bmp"); + // 撠 parse1 餈銵鈭澆 + parse1.localBinary(ColorMatrix._G_, 30, 0, 0xffffff, 1); + // 撠 parse1 拚菔嚗嗅撠蝏瑕 + ColorMatrix parse2 = parse1.erode(3, 3, true, Color.BLACK); + // 撠銝支葵拚菔銵撌株蝞嚗撟嗆亦撌桐曉 霂亙賣啁鈭雿撌 + (parse1.diff(parse2)).show("蝏曉1"); + // 撠銝支葵拚菔銵 agg 賣啁撌株蝞嚗餈雿輻函 閫游撌 + (parse1.agg(parse2, ColorMatrix.COLOR_DIFF_REGULATE)).show("蝏曉2"); } } ``` -* It supports the call operation of the quick save function of the image, making the saving of the image file easier. +* An aggregation implementation logic has been added to the image matrix, where the absolute value of the difference is + returned after the difference is made. ```java package zhao.algorithmMagic; @@ -117,675 +45,777 @@ import zhao.algorithmMagic.operands.matrix.ColorMatrix; public class MAIN1 { public static void main(String[] args) { - String s1 = "C:\\Users\\zhao\\Desktop\\fsDownload\\敺桐縑曄_2.jpg"; - // 瑕啣曉拚萄笆鞊 - ColorMatrix parse = ColorMatrix.parse(s1); - // 撠曉典曉箇銝餈銵憸脣頧祆雿 - parse.colorReversal(false); - // 亦憸脣頧砌曉 - parse.show("image1"); - // 颲箏頧砌曉 - parse.save("C:\\Users\\zhao\\Desktop\\fsDownload\\res123.jpg"); + // 撱箔銝芸曉拚 + ColorMatrix parse = ColorMatrix.parseGrayscale("C:\\Users\\Liming\\Desktop\\fsdownload\\test3.bmp"); + // 銝箏曉拚菔銵刻雿 + // 暺脖銝箄航脰 + ColorMatrix erode1 = parse.erode(3, 3, true); + // 質脖銝箄航脰刻 + ColorMatrix erode2 = parse.erode(3, 3, true, ColorMatrix.WHITE); + // 撠刻拚萄笆鞊 雿輻災gg賣 拚萄笆鞊 + (erode2.agg(erode1, ColorMatrix.COLOR_DIFF_ABS)).show("image"); } } ``` -* The "SaveMatrix" interface is added. All matrices that implement this interface can be saved in structured or - unstructured way. +* When fixing the problem of copying two-dimensional arrays, only deep copies were made at the array level ( + one-dimensional arrays in two-dimensional arrays did not undergo deep copies). This has now been redesigned to make + the deep copy operation effective again. ```java package zhao.algorithmMagic; import zhao.algorithmMagic.operands.matrix.ColorMatrix; +import java.awt.*; + public class MAIN1 { public static void main(String[] args) { - String s1 = "C:\\Users\\Liming\\Desktop\\fsDownload\\敺桐縑曄_2.jpg"; - // 瑕啣曉拚萄笆鞊 - ColorMatrix parse = ColorMatrix.parse(s1); - // 颲箏曉RGB祆唳 - parse.save("C:\\Users\\Liming\\Desktop\\fsDownload\\res1234.csv", ','); + // 瑕銝撘曉蝝拚 + ColorMatrix parse1 = ColorMatrix.parseGrayscale("C:\\Users\\Liming\\Desktop\\fsdownload\\test1.bmp"); + Color[][] colors = parse1.copyToNewArrays(); } } ``` -* A data analysis library is added to the AS library, which uses SQL styles to process data. Through this library, data - in the database can be easily obtained into memory for processing. +* 啣拚萄餈蝞賣堆霂亙賣啗賢摰啁拚萎葉蝝霈∠雿嚗銝X舀舀霈∠雿嚗撟嗉銝銝芾恣蝞銋拚萄笆鞊∼ + +| Calculating Constants | effect | use | +|---------------------------|-------------------------|---------------------------------------------------------------------------------| +| CALCULATE_GRADIENT_RL | mid = right - left | Calculate the gradient of the image on the left and right. | +| CALCULATE_GRADIENT_LH | mid = low - high | Calculate the gradient of the image up and down. | +| CALCULATE_GRADIENT_RL_ABS | mid = abs(right - left) | Calculate the absolute gradient value of the image at the left and right sides. | +| CALCULATE_GRADIENT_LH_ABS | mid = abs(low - high) | Calculate the absolute gradient value of the image at the top and bottom. | ```java package zhao.algorithmMagic; -import zhao.algorithmMagic.operands.table.DataFrame; -import zhao.algorithmMagic.operands.table.FDataFrame; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; +import zhao.algorithmMagic.operands.matrix.ColorMatrix; public class MAIN1 { - public static void main(String[] args) throws SQLException { - // 憭唳桀餈亙笆鞊 - Connection connection = DriverManager.getConnection("jdbc:mysql://192.168.0.101:38243/tq_SCHOOL", "liming", "liming7887"); - // 撠唳桀唳桀笆鞊∪頧賣 FDF - DataFrame execute = FDataFrame.builder(connection) // 摰唳桀餈 - .create("*") // 摰亥砭摮畾 - .from("STU_FIVE") // 摰亥砭銵 - .primaryKey(0) // 摰摮AS銵函銝駁殷AS隡芸典遣蝡銵蝝W嚗唳桀亥砭閬雿輻函揣撘摰佗 - .execute();// 撘憪亥砭 - // 啣 FDF 銝剔唳 - System.out.println(execute); - - // 撘憪亥砭 FDF - // 甇摨啣 FDF 銝 name踹漲銝3鈭箏銝剔瑕戊鈭箸 啣箏 3 銵唳 - DataFrame select = execute - .select("name", "sex") // 亥砭嗡葉 name sex - .where(v -> v.getCell(0).getStringValue().length() == 3) // 瑕啣嗡葉摮踹漲銝 3 唳株 - .groupBy("sex") // sex 蝏 - .count() // 撠瘥銝蝏餈銵蝏霈 - .sort("count()") // 抒霈∠餈銵甇摨摨 - .limit(3); // 瑕憭3銵唳 - System.out.println(select.into_outfile("C:\\Users\\zhao\\Desktop\\fsDownload\\res1.csv")); - // 啣 FDF 銝剔唳株 - System.out.println("唳株 = " + execute.count()); - // 啣箏嗡葉靽⊥ - System.out.println(execute.desc()); - // 瑕 韏萄摰 靽⊥ 曹 name 臭蜓殷甇文臭誑湔仿餈餈瑕唳唳 - System.out.println(execute.selectRow("韏萄摰")); + public static void main(String[] args) { + ColorMatrix calculate1; + ColorMatrix calculate2; + { + // 撱箔銝芸曉拚 + ColorMatrix parse = ColorMatrix.parseGrayscale("C:\\Users\\Liming\\Desktop\\fsdownload\\test3.bmp"); + // 餈銵撌血喟璇臬漲霈∠ + parse.calculate(ColorMatrix.CALCULATE_GRADIENT_RL, true).show("image1"); + // 餈銵銝銝璇臬漲霈∠ + parse.calculate(ColorMatrix.CALCULATE_GRADIENT_LH, true).show("image2"); + // 餈銵撌血喟蝏撖孵潭0摨西恣蝞 + calculate1 = parse.calculate(ColorMatrix.CALCULATE_GRADIENT_RL_ABS, true); + calculate1.show("image3"); + // 餈銵銝銝蝏撖孵潭0摨西恣蝞 + calculate2 = parse.calculate(ColorMatrix.CALCULATE_GRADIENT_LH_ABS, true); + calculate2.show("image4"); + } + // 餈銵銝文曉瘜撟 撟嗆唳啁拚 + (calculate1.add(calculate2)).show("image"); } } ``` -* Use FDataFrame to load the data in the database and file. +* The DF object's select * is supported. Using * as a query placeholder will not perform any operations, but will + directly return data. ```java package zhao.algorithmMagic; import zhao.algorithmMagic.operands.table.*; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; - public class MAIN1 { - public static void main(String[] args) throws SQLException { - // 憭唳桀餈亙笆鞊 - Connection connection = DriverManager.getConnection("jdbc:mysql://192.168.0.101:38243/tq_SCHOOL", "liming", "liming7887"); - // 撠唳桀唳桀笆鞊∪頧賣 FDF - DataFrame execute = FDataFrame.builder(connection) // 摰唳桀餈 - .create("*") // 摰亥砭摮畾 - .from("STU_FIVE") // 摰亥砭銵 - .where(" name = '韏萄摰' ") // 摰亥砭∩辣 - .primaryKey(0) // 摰摮AS銵函銝駁殷AS隡芸典遣蝡銵蝝W嚗唳桀亥砭閬雿輻函揣撘摰佗 - .execute();// 撘憪亥砭 - // 啣 FDF 銝剔唳 - System.out.println(execute); + public static void main(String[] args) { + // 撱箔銝芰征 DataFrame 撖寡情 + FDataFrame dataFrame = FDataFrame.select( + FieldCell.parse("id", "name", "sex", "age"), 1 + ); + // 冽交唳 + dataFrame.insert( + FinalSeries.parse("1", "zhao", "M", "19"), + FinalSeries.parse("2", "tang", "W", "18"), + FinalSeries.parse("3", "yang", "W", "20"), + FinalSeries.parse("4", "shen", "W", "19") + ); + // 啣 select * 唳 + System.out.println( + dataFrame.select("*") + ); } } ``` +* In a color value quadrature calculation scheme, the processing logic is to take the current value of% 256 as the + current color value if the value exceeds the range. + ```java package zhao.algorithmMagic; -import zhao.algorithmMagic.operands.table.DataFrame; -import zhao.algorithmMagic.operands.table.FDataFrame; +import zhao.algorithmMagic.operands.matrix.ColorMatrix; -import java.io.File; -import java.sql.SQLException; -import java.util.Objects; +import java.awt.*; public class MAIN1 { public static void main(String[] args) { - // 憭隞嗅笆鞊 - File file = new File("C:\\Users\\zhao\\Desktop\\out\\res1.csv"); - // 雿輻 FDF 頧賣隞 - DataFrame execute1 = FDataFrame.builder(file) - // 隞嗅笆鞊∠霂餃閬摰砍蝚 - .setSep(',') - // 隞嗅笆鞊⊿閬摰憟賢蝘堆銝賭蝙 * 餈隞銵函銝舀亥砭嚗臬撱箔銝枋F摮畾 - .create("id", "name", "sex") - // 隞嗅笆鞊⊿閬雿輻甸ambda銵刻噢撘餈銵唳桃餈皛 - .where(v -> Objects.equals(v.getCell(1).getStringValue(), "韏萄摰")) - // 隞嗅笆鞊∠銝駁格摰霈訾蝙典蝘 - .primaryKey("name") - // 扯亥砭 - .execute(); - // 啣箇唳 - System.out.println(execute1); + Color[] colors = {Color.CYAN, Color.GREEN, Color.PINK, Color.red}; + // 典撱箏曉拚 + ColorMatrix parse = ColorMatrix.parse( + colors, colors, colors, colors + ); + // 亦曉拚 + parse.show("image", 100, 100); + // 撠曉銝剔蝝銝芾澈拚菔銵閫港瘜霈∠ + ColorMatrix agg1 = parse.agg(parse, ColorMatrix.COLOR_MULTIPLY_REGULATE); + // 撠曉銝剔蝝銝芾澈拚菔銵雿銋瘜霈∠ + ColorMatrix agg2 = parse.agg(parse, ColorMatrix.COLOR_MULTIPLY_REMAINDER); + // 亦銝支葵曉唳 + agg1.show("image1", 100, 100); + agg2.show("image2", 100, 100); } } - ``` +``` -* Limit FDF by line name +* Support area calculation of image contours, using pixels as the calculation unit during calculation, and support + customization of contour colors. ```java package zhao.algorithmMagic; -import zhao.algorithmMagic.operands.table.DataFrame; -import zhao.algorithmMagic.operands.table.FDataFrame; +import zhao.algorithmMagic.operands.matrix.ColorMatrix; -import java.io.File; -import java.sql.SQLException; +import java.awt.*; public class MAIN1 { public static void main(String[] args) { - // 憭隞嗅笆鞊 - File file = new File("C:\\Users\\zhao\\Desktop\\out\\res1.csv"); - // 雿輻 FDF 頧賣隞 - DataFrame execute1 = FDataFrame.builder(file) - // 隞嗅笆鞊∠霂餃閬摰砍蝚 - .setSep(',') - // 隞嗅笆鞊⊿閬摰憟賢蝘堆銝賭蝙 * 餈隞銵函銝舀亥砭嚗臬撱箔銝枋F摮畾 - .create("id", "name", "sex") - // 隞嗅笆鞊∠銝駁格摰霈訾蝙典蝘 - .primaryKey("name") - // 扯亥砭 - .execute(); - // 啣箇唳 餈啣箔 韏 韐 銋渡唳株 - System.out.println(execute1.limit("韏", "韐")); + ColorMatrix resImage1; + { + // 瑕銝撘曉蝝拚 + ColorMatrix colors = ColorMatrix.parse("C:\\Users\\Liming\\Desktop\\fsdownload\\test1.bmp"); + // 撠曉瑁銝隞賢箸 + ColorMatrix parse1 = ColorMatrix.parse(colors.copyToNewArrays()); + // 撠 parse1 餈銵鈭澆 // 霂瑟釣 + parse1.globalBinary(ColorMatrix._G_, 60, 0, 0xffffff); + // 撠 parse1 拚菔嚗嗅撠蝏瑕 + ColorMatrix parse2 = parse1.erode(2, 2, true, Color.BLACK); + // 撠 parse1 拚萎葉質脖銝箄航莎刻嚗 + parse1.erode(2, 2, false, Color.WHITE); + // 亦銝湔嗥 + parse1.show("image1"); + parse2.show("image2"); + // 撠銝支葵拚菔銵撌株蝞嚗撟嗆亦撌桐曉 + resImage1 = parse1.diff(parse2); + resImage1.show("頧桀曉"); + } + // 亦蝏唳 + resImage1.show("蝏嗡蝏曉"); + // 撘憪質脰蔭撱蝥踹Y妖 + System.out.print("頧桀Y妖 = "); + System.out.println(resImage1.contourArea(ColorMatrix.WHITE)); } } ``` -* Support the operations of aliasing columns and adding data rows. +* Supports the operation of enclosing rectangles with contours. With the help of this function, all contours in the + image will be unified into a circle, forming a large matrix. ```java package zhao.algorithmMagic; -import zhao.algorithmMagic.operands.table.DataFrame; -import zhao.algorithmMagic.operands.table.FDataFrame; -import zhao.algorithmMagic.operands.table.FieldCell; +import zhao.algorithmMagic.operands.matrix.ColorMatrix; +import zhao.algorithmMagic.operands.matrix.RectangleMatrix; -import java.io.File; -import java.sql.SQLException; +import java.awt.*; public class MAIN1 { public static void main(String[] args) { - // 憭隞嗅笆鞊 - File file = new File("C:\\Users\\zhao\\Desktop\\out\\res1.csv"); - // 雿輻 FDF 頧賣隞 - DataFrame execute1 = FDataFrame.builder(file) - // 隞嗅笆鞊∠霂餃閬摰砍蝚 - .setSep(',') - // 隞嗅笆鞊⊿閬摰憟賢蝘堆銝賭蝙 * 餈隞銵函銝舀亥砭嚗臬撱箔銝枋F摮畾 - .create("id", "name", "sex") - // 隞嗅笆鞊∠銝駁格摰霈訾蝙典蝘 - .primaryKey("name") - // 扯亥砭 - .execute(); - // 扳批怠蝏嚗霈∠箇瑕戊鈭箸 - System.out.println( - execute1 - // 摰亥砭嚗撟嗉絲怠 - .select(FieldCell.$("sex").as("批")) - // sex 蝏 - .groupBy("批") - // 餈銵 蝏霈⊥ - .count() - // 摰亥砭 撟嗉絲怠 - .select( - FieldCell.$("批"), - FieldCell.$("count()").as("鈭箸") - ) + ColorMatrix parse1; + { + // 瑕銝撘曉蝝拚 + ColorMatrix colors = ColorMatrix.parse("C:\\Users\\zhao\\Desktop\\fsdownload\\test3.bmp"); + // 撠曉瑁銝隞賢箸 + parse1 = ColorMatrix.parse(colors.copyToNewArrays()); + // 撠蝏鈭澆 + parse1.globalBinary(ColorMatrix._G_, 150, 0xffffff, 0); + } + // 撠頧桀蝥輯蓮拙耦頧桀 + ColorMatrix parse = RectangleMatrix.parse(parse1, Color.GREEN); + parse.show("鈭澆曉"); + System.out.print(parse); + // 撠拙耦頧桀瘛餃啣拚 餈閫荔憒憸脫啣潔蛹 0xff000000 撠曹撟 + ColorMatrix res = parse1.agg( + // 閬鋡怨銵瘛餃拚萄笆鞊 + parse, + // 瘛餃餉 餈雿輻函臬暺脩憸脣蝝湔亥 銝粹支暺脖誑憭蝝賣航蔭撱 + (inputType1, inputType2) -> inputType2.getRGB() == 0xff000000 ? inputType1 : inputType2 ); + res.show("蝏"); } } ``` -* Capable of functional update of row or column data for all values in DF data set objects, and supports conversion from - DF data objects to matrices. +* Support the calculation of matrix similarity functions. Here, you can calculate the rectangular similarity using the + following example. ```java package zhao.algorithmMagic; +import zhao.algorithmMagic.algorithm.distanceAlgorithm.ManhattanDistance; +import zhao.algorithmMagic.algorithm.distanceAlgorithm.StandardizedEuclideanDistance; +import zhao.algorithmMagic.core.AlgorithmStar; +import zhao.algorithmMagic.operands.matrix.DoubleMatrix; import zhao.algorithmMagic.operands.matrix.IntegerMatrix; -import zhao.algorithmMagic.operands.table.DataFrame; -import zhao.algorithmMagic.operands.table.FDataFrame; -import zhao.algorithmMagic.operands.table.FieldCell; -import zhao.algorithmMagic.operands.table.FinalCell; -import zhao.algorithmMagic.operands.vector.IntegerVector; - -import java.io.File; public class MAIN1 { public static void main(String[] args) { - // 憭隞嗅笆鞊 - File file = new File("C:\\Users\\zhao\\Desktop\\out\\res1.csv"); - // 雿輻 FDF 頧賣隞 - DataFrame execute1 = FDataFrame.builder(file) - // 隞嗅笆鞊∠霂餃閬摰砍蝚 - .setSep(',') - // 隞嗅笆鞊⊿閬摰憟賢蝘堆銝賭蝙 * 餈隞銵函銝舀亥砭嚗臬撱箔銝枋F摮畾 - .create("id", "name", "sex") - // 隞嗅笆鞊∠銝駁格摰霈訾蝙典蝘 - .primaryKey("name") - // 扯亥砭 - .execute() - // 銝箏韏瑕怠 - .select( - FieldCell.$("id"), - FieldCell.$("name").as("蝘"), - FieldCell.$("sex").as("批") - ) - // 撠批怠餈銵頧祆g瑞銝1 憟喟銝0 - .updateCol(FieldCell.$("批"), cell -> new FinalCell<>(cell.getStringValue().equals("") ? 1 : 0)) - // 撠銵銝駁格啣潔蛹ZLY唳株銝剔潭踵X銝箸唳 405 - .updateRow("ZLY", cell -> new FinalCell<>(405)); - - // 啣箄”銝剔銵銝駁桀蝘唬蛹 405 唳株 - System.out.println(execute1.selectRow("405")); - long start = System.currentTimeMillis(); - // 撠銵刻蓮X銝箔銝芣游耦拚萄笆鞊∴霂交雿隡撠DF撖寡情銝剔啣潸曇蓮X銝 col.count()*3 拚萄笆鞊 - IntegerMatrix parse = IntegerMatrix.parse(execute1, execute1.count().getIntValue(), 3); - System.out.println(IntegerVector.parse(parse.getArrayByColIndex(2))); - System.out.print("憭塚MS嚗嚗"); - System.out.println(System.currentTimeMillis() - start); - } -} -``` - -* Support for obtaining image related data through a web URL object and converting it into an image matrix. - -```java -package zhao.algorithmMagic; - -import zhao.algorithmMagic.operands.matrix.ColorMatrix; + // 瑕唬銝芸曉拚萇憸涮GB啣 + IntegerMatrix parse1, parse2, parse3; + { + parse1 = IntegerMatrix.parse("C:\\Users\\zhao\\Desktop\\fsdownload\\test3.bmp"); + parse2 = IntegerMatrix.parse("C:\\Users\\zhao\\Desktop\\fsdownload\\test32.bmp"); + parse3 = IntegerMatrix.parse("C:\\Users\\zhao\\Desktop\\fsdownload\\test33.bmp"); + } + // 霈∠箔銝芸曉訾撮摨衣頂 + AlgorithmStar algorithmStar = AlgorithmStar.getInstance(); + System.out.println(algorithmStar.getTrueDistance(ManhattanDistance.getInstance("MAN"), parse1, parse2)); + System.out.println(algorithmStar.getTrueDistance(ManhattanDistance.getInstance("MAN"), parse1, parse3)); -import java.net.MalformedURLException; -import java.net.URL; + // 撠銝銝芸曉拚萇啣潸蓮X銝榛ouble蝐餃嚗瑕蚤ouble拚 + DoubleMatrix parse11, parse22, parse33; + { + parse11 = DoubleMatrix.parse(parse1); + parse22 = DoubleMatrix.parse(parse2); + parse33 = DoubleMatrix.parse(parse3); + } + // 霈∠箔銝芸曉訾撮摨衣頂 + System.out.println(algorithmStar.getTrueDistance(ManhattanDistance.getInstance("MAN"), parse11, parse22)); + System.out.println(algorithmStar.getTrueDistance(ManhattanDistance.getInstance("MAN"), parse11, parse33)); -public class MAIN1 { - public static void main(String[] args) throws MalformedURLException { - // 憭曉URL撖寡情 - URL url = new URL("https://user-images.githubusercontent.com/113756063/194830221-abe24fcc-484b-4769-b3b7-ec6d8138f436.png"); - // 閫URL瑕啣曉拚 - ColorMatrix parse1 = ColorMatrix.parse(url); - // 閫URL瑕啣曉啣漲拚 - ColorMatrix parse2 = ColorMatrix.parseGrayscale(url); - // 亦曉 - parse1.show("image"); - parse2.show("image"); + // TODO 澆瘜冽 甈批敺銝舀餈蝐餅雿霈∠ 餈銝隡仿 + double se = algorithmStar.getTrueDistance(StandardizedEuclideanDistance.getInstance2("SE"), parse11, parse22); + System.out.println(se); } } ``` -* It supports color binarization and regularization coverage, and can display more image features or remove more - redundant features by specifying the color values of the channel. +* Support the rendering of regular graphics (rectangles) in the image matrix, and the rendering process will not + generate redundant computational data. ```java package zhao.algorithmMagic; +import zhao.algorithmMagic.operands.coordinate.IntegerCoordinateTwo; import zhao.algorithmMagic.operands.matrix.ColorMatrix; -import java.net.MalformedURLException; -import java.net.URL; +import java.awt.*; public class MAIN1 { - public static void main(String[] args) throws MalformedURLException { - // 憭曉URL撖寡情 - URL url = new URL("https://user-images.githubusercontent.com/113756063/194830221-abe24fcc-484b-4769-b3b7-ec6d8138f436.png"); - // 閫URL瑕啣曉拚 - ColorMatrix parse1 = ColorMatrix.parse(url); - // 撠 URL 曉拚萎葉 G 憸脫啣澆之鈭 40 憸脣港蛹暺莎銋港蛹質 - // 刻曹拐 G 甇 蝏輯脰瘛 頞航賢銝箇質 - parse1.globalBinary(ColorMatrix._G_, 40, 0, 0xffffff); - // 銋臭誑雿輻典嗅憸脤餈銵脣蔗靚 - parse1.globalBinary(ColorMatrix._R_, 40, 0, 0xffffff); - parse1.globalBinary(ColorMatrix._B_, 40, 0, 0xffffff); - // 亦蝏曉 - parse1.show("image"); + public static void main(String[] args) { + ColorMatrix colorMatrix1; + // 撠曉銝瑟祈粉餈 + colorMatrix1 = ColorMatrix.parse("C:\\Users\\zhao\\Desktop\\fsdownload\\test3.bmp"); + // 撠曉拚萇嗅啣拚萎葉嚗撟嗆亦蝏 + colorMatrix1.drawRectangle( + // 拙耦撌虫閫 + new IntegerCoordinateTwo(40, 30), + // 拙耦喃閫 + new IntegerCoordinateTwo(140, 130), + // 拙耦颲寞憸脣笆鞊 + Color.MAGENTA + ); + colorMatrix1.show("res"); } } ``` -* Supports the construction of image ASCII images. You can quickly construct an image in ASCII, but please ensure that - the image size is small enough. +* Support template matching operations for image matrices, where the convolution core size is the template size. When + the width of the template and the image rectangle coincide, an optimization algorithm is used. ```java package zhao.algorithmMagic; +import zhao.algorithmMagic.algorithm.distanceAlgorithm.ManhattanDistance; +import zhao.algorithmMagic.operands.coordinate.IntegerCoordinateTwo; import zhao.algorithmMagic.operands.matrix.ColorMatrix; -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; +import java.util.Map; public class MAIN1 { - public static void main(String[] args) throws MalformedURLException { - // 憭曉URL撖寡情 - URL url = new URL("https://user-images.githubusercontent.com/113756063/194830221-abe24fcc-484b-4769-b3b7-ec6d8138f436.png"); - // 閫URL瑕啣曉拚 - ColorMatrix parse1 = ColorMatrix.parse(url); - // 亦蝏曉 - parse1.show("image"); - // 颲箏曉 ASCII 啣潘颲箄銝 G 憸脫啣 憭找 40 颲箇泵 'A' 嗅颲箇泵 ' ' - parse1.save( - new File("C:\\Users\\zhao\\Desktop\\fsDownload\\res.txt"), - ColorMatrix._G_, 40, 'A', ' ' + public static void main(String[] args) { + ColorMatrix colorMatrix1, colorMatrix2; + // 撠曉銝瑟祈粉餈 + colorMatrix1 = ColorMatrix.parse("C:\\Users\\zhao\\Desktop\\fsdownload\\test3.bmp"); + colorMatrix2 = ColorMatrix.parse("C:\\Users\\zhao\\Desktop\\fsdownload\\test3YB.bmp"); + // 雿輻冽芋踹寥 瑕 colorMat1 銝 銝 colorMat2 貉摮拚萎縑 + // 嗡葉 key 銝箸訾撮摮拚萄寥蝟餅 value 銝箸訾撮摮拚萄椰銝閫 + Map.Entry matching = colorMatrix1.templateMatching( + // 訾撮摨西恣蝞蝏隞 + ManhattanDistance.getInstance("MAN"), + // 璅⊥踹曉 + colorMatrix2, + // 閬鋡怨恣蝞憸脤 + ColorMatrix._G_, + // 瑞妖嗥甇仿踵啣 + 10, + // 訾撮摨西撠 寥摨西憭 + false ); + System.out.println(matching); } } ``` -* Ability to manually create an empty DataFrame object and independently manipulate the data therein. +* Support the normalization operation of matrices, making the normalization calculation applicable to a wider range of + objects. ```java package zhao.algorithmMagic; -import zhao.algorithmMagic.operands.table.DataFrame; -import zhao.algorithmMagic.operands.table.FDataFrame; -import zhao.algorithmMagic.operands.table.FieldCell; -import zhao.algorithmMagic.operands.table.FinalSeries; +import zhao.algorithmMagic.algorithm.normalization.LinearNormalization; +import zhao.algorithmMagic.core.AlgorithmStar; +import zhao.algorithmMagic.operands.matrix.DoubleMatrix; +import zhao.algorithmMagic.operands.matrix.IntegerMatrix; public class MAIN1 { public static void main(String[] args) { - // 撱箔銝芰征 DF 撖寡情 隞 name 雿銝箄銝駁桃揣撘 - FDataFrame create = FDataFrame.select(FieldCell.parse("name", "sex", "phoneNum"), 1); - // 乩鈭唳 - DataFrame insert = create.insert( - FinalSeries.parse("zhao", "M", "110xxxxxxxx"), - FinalSeries.parse("tang", "W", "110xxxxxxxx"), - FinalSeries.parse("yang", "M", "110xxxxxxxx") + IntegerMatrix integerMatrix = IntegerMatrix.parse( + new int[]{1, 2, 3, 4, 5}, + new int[]{5, 4, 3, 4, 5}, + new int[]{5, 4, 3, 2, 1} ); - // 亦唳桅 - System.out.println(insert); - // 撠嗡葉 name sex 亥砭 - System.out.println( - insert.select( - FieldCell.$("name").as("AllName"), - FieldCell.$("sex").as("AllSex") - ) + // 敶銝霈∠蝏隞 + LinearNormalization line = LinearNormalization.getInstance("line").setMax(3).setMin(-3); + AlgorithmStar algorithmStar = AlgorithmStar.getInstance(); + // 撘憪餈銵敶銝雿 + IntegerMatrix pretreatment1 = algorithmStar.pretreatment( + line, + // 閬鋡怠銝拚萄笆鞊 + integerMatrix ); + System.out.print(pretreatment1); + + DoubleMatrix doubleMatrix = DoubleMatrix.parse(integerMatrix); + DoubleMatrix pretreatment2 = algorithmStar.pretreatment(line, doubleMatrix); + System.out.print(pretreatment2); } } ``` -* 舀 group 嗅摰 where摮伐雿踹霈∠憭批之憓撘 +* Support the addition and merging calculation of matrices, which can merge two image matrices into the same new image + matrix. ```java package zhao.algorithmMagic; -import zhao.algorithmMagic.operands.table.DataFrame; -import zhao.algorithmMagic.operands.table.FDataFrame; -import zhao.algorithmMagic.operands.table.FieldCell; -import zhao.algorithmMagic.operands.table.FinalSeries; +import zhao.algorithmMagic.operands.matrix.ColorMatrix; import java.net.MalformedURLException; +import java.net.URL; public class MAIN1 { - public static void main(String[] args) { - // 撱箔銝芰征 DF 撖寡情 隞 name 雿銝箄銝駁桃揣撘 - FDataFrame create = FDataFrame.select(FieldCell.parse("name", "sex", "phoneNum"), 1); - // 乩鈭唳 - DataFrame insert = create.insert( - FinalSeries.parse("zhao1", "M", "110xxxxxxxx"), - FinalSeries.parse("tang2", "W", "120xxxxxxxx"), - FinalSeries.parse("yang3", "W", "110xxxxxxxx"), - FinalSeries.parse("zhao4", "M", "120xxxxxxxx"), - FinalSeries.parse("tang5", "W", "110xxxxxxxx"), - FinalSeries.parse("yang6", "W", "110xxxxxxxx"), - FinalSeries.parse("zhao7", "M", "120xxxxxxxx"), - FinalSeries.parse("tang8", "W", "110xxxxxxxx"), - FinalSeries.parse("yang9", "W", "110xxxxxxxx") - ); - // 亦唳桅 - System.out.println(insert); - // 撠嗡葉箏瑕銝雿銝銝 120 唳株批嗡葉 sex 蝏 刻湔乩蝙典蝏嗉皛文喳 - System.out.println( - insert.groupBy("sex", v -> { - // 瑕唳箏瑞摮蝚虫葡 - String s = v.getCell(2).toString(); - // 斗剖 3 銝芸蝚行臬虫蛹 120 嚗臬虫誑 120 撘憭湛 憒臬停銝瘛餃 - return !s.startsWith("120"); - }).count() + public static void main(String[] args) throws MalformedURLException { + // 瑕唬銝芸曉拙耦撖寡情 + ColorMatrix parse1 = ColorMatrix.parse( + new URL("https://user-images.githubusercontent.com/113756063/229441864-ec1770d5-1154-4e9c-837e-a4acfc5fb259.jpg") ); + // 撠曉拚萄笆鞊⊥瑁箔隞賢僎餈銵憸脣頧 + ColorMatrix parse2 = ColorMatrix.parse(parse1.copyToNewArrays()).colorReversal(false); + // 撠銝支葵曉拚菔銵撟嗆雿嚗撟嗅蝷箏箔銝撌血喳撟嗥蝏曉 + // 餈臬椰喳撟 + ColorMatrix colorMatrixLR = parse1.append(parse2, true); + // 餈臭銝撟 + ColorMatrix colorMatrixTB = parse1.append(parse2, false); + // 亦蝏曉 + colorMatrixLR.show("LR"); + colorMatrixTB.show("TB"); } } ``` -* Support for local binarization operations, which can effectively achieve image binarization processing. Compared to - global binarization, functions are more flexible. +* Support obtaining image matrix through camera. ```java package zhao.algorithmMagic; +import zhao.algorithmMagic.io.InputCamera; +import zhao.algorithmMagic.io.InputCameraBuilder; +import zhao.algorithmMagic.io.InputComponent; import zhao.algorithmMagic.operands.matrix.ColorMatrix; - -import java.net.MalformedURLException; -import java.net.URL; +import zhao.algorithmMagic.operands.matrix.DoubleMatrix; +import zhao.algorithmMagic.operands.table.FinalCell; public class MAIN1 { - public static void main(String[] args) throws MalformedURLException { - // 瑕啣曉拚 - ColorMatrix parse = ColorMatrix.parse(new URL("https://img-blog.csdnimg.cn/img_convert/5765bdab08ef6e117d434e7e225b9013.png")); - parse.show("image"); - System.out.println("ok!!!"); - System.out.println(" = " + parse.getRowCount()); - System.out.println("摰 = " + parse.getColCount()); - // 撠曉餈銵撅其澆 - parse.localBinary( - // 摰祆活鈭澆拍憸脤 - ColorMatrix._G_, - // 摰祆活鈭澆箇撅典曉拚菜圈 - 100, - // 摰祆活鈭澆銝剖函拚萎葉憭找撅券潛憸脩 - 0xffffff, - // 摰祆活鈭澆銝剖函拚萎葉撠鈭撅券潛憸脩 - 0, - // 摰祆活鈭澆銝剖券潛閬餈銵敺株啣潘餈舫雿20銝芷潭啣 - -30 - ); - // 亦蝏唳 - parse.show("image"); + public static void main(String[] args) { + // 瑕唳憭渲亥挽憭 + InputComponent inputComponent = InputCamera.builder() + // 閬雿輻函憭渡摮 蝝W def暺霈歹隞祈雿輻函 def 隞銵其蝙券霈斗憭 + .addInputArg(InputCameraBuilder.Camera_Index, new FinalCell<>("def")) + // 閬雿輻函曉澆 + .addInputArg(InputCameraBuilder.Image_Format, new FinalCell<>("JPG")) + // 曉撠箏站 餈啣潭 WebcamResolution 銝曄掩撅批畾 VGA + .addInputArg(InputCameraBuilder.CUSTOM_VIEW_SIZES, new FinalCell<>("VGA")) + .create(); + ColorMatrix parse1 = ColorMatrix.parse(inputComponent); + parse1.show("image1"); + double[][] double2Array = inputComponent.getDouble2Array(); + DoubleMatrix parse = DoubleMatrix.parse(double2Array); } } ``` -* DF object data supports saving as HTML files, enabling effective automated page rendering operations. +* Supports obtaining DataFrame operand objects and saving DataFrame data objects through HDFS. ```java package zhao.algorithmMagic; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import zhao.algorithmMagic.io.*; import zhao.algorithmMagic.operands.table.DataFrame; import zhao.algorithmMagic.operands.table.FDataFrame; -import zhao.algorithmMagic.operands.table.FieldCell; -import zhao.algorithmMagic.operands.table.FinalSeries; +import zhao.algorithmMagic.operands.table.FinalCell; + +import java.io.IOException; + public class MAIN1 { - public static void main(String[] args) { - // 撱箔銝芰征 DF 撖寡情 隞 name 雿銝箄銝駁桃揣撘 - FDataFrame create = FDataFrame.select(FieldCell.parse("name", "sex", "phoneNum", "salary"), 1); - // 乩鈭唳 - DataFrame insert = create.insert( - FinalSeries.parse("zhao1", "M", "110xxxxxxxx", "30000"), - FinalSeries.parse("tang2", "W", "120xxxxxxxx", "30000"), - FinalSeries.parse("yang3", "W", "110xxxxxxxx", "30000"), - FinalSeries.parse("zhao4", "M", "120xxxxxxxx", "30000"), - FinalSeries.parse("tang5", "W", "110xxxxxxxx", "30000"), - FinalSeries.parse("yang6", "W", "110xxxxxxxx", "30000"), - FinalSeries.parse("zhao7", "M", "120xxxxxxxx", "30000"), - FinalSeries.parse("tang8", "W", "110xxxxxxxx", "30000"), - FinalSeries.parse("yang9", "W", "110xxxxxxxx", "30000") - ); - // 颲箄”HTML 嗅亦銵其葉唳 + public static void main(String[] args) throws IOException { + // 瑕 HDFS 唳株亥箄挽憭撖寡情 擐撠銝方閬啣撱箏箸 + FileSystem fileSystem; + String inPath; + String[] field; + { + Path path = new Path("hdfs://192.168.0.141:8020"); + // 撱慵DFS隞嗥頂蝏撖寡情 + fileSystem = path.getFileSystem(new Configuration()); + // 霈曄蔭閬鋡怨粉隞嗅笆鞊 + inPath = "hdfs://192.168.0.141:8020/data/test.txt"; + // 霈曄蔭摮畾萄仍 + field = new String[]{"name", "sex", "age"}; + } + + /* ***************************************************** + * TODO 隞HDFS銝剖頧賣唳 + * *****************************************************/ + // 撘憪撠圈蝵桀啗挽憭撖寡情銝哨撱箏箸唳株亥挽憭 + InputComponent inputComponent = InputHDFS.builder() + .addInputArg(InputHDFSBuilder.FILE_SYSTEM, new FinalCell<>(fileSystem)) + .addInputArg(InputHDFSBuilder.IN_PATH, new FinalCell<>(inPath)) + .addInputArg(InputHDFSBuilder.FIELD, new FinalCell<>(field)) + // 霈曄蔭蝚 + .addInputArg(InputHDFSBuilder.SEP, new FinalCell<>('\t')) + .create(); + + /* ***************************************************** + * TODO 憭頧賢箸亦 DataFrame 撖寡情嚗餈舀 age 甇摨摨 + * *****************************************************/ + // 撘憪撠 HDFS 銝剔唳桀頧賣銝箔銝 DataFrame撖寡情 + DataFrame dataFrame = FDataFrame + .builder(inputComponent) + .sort("age"); + + /* ***************************************************** + * TODO 撠憭憟賜唳株箏 HDFS /data/res.csv 銝 + * *****************************************************/ + // 摰靘箸亦格頝臬 + Path path = new Path("hdfs://192.168.0.141:8020/data/res.csv"); + // 撘憪撱箸唳株箇隞 + OutputComponent outputComponent = OutputHDFS.builder() + .addOutputArg(OutputHDFSBuidler.FILE_SYSTEM, new FinalCell<>(fileSystem)) + .addOutputArg(OutputHDFSBuidler.SEP, new FinalCell<>(',')) + .addOutputArg(OutputHDFSBuidler.OUT_PATH, new FinalCell<>(path)) + .addOutputArg(OutputHDFSBuidler.FORMAT, new FinalCell<>("csv")) + .create(); + // 撘憪餈蝏隞嗅唳株 嗆啣箇 System.out.println( - insert.into_outHtml("C:\\Users\\Liming\\Desktop\\fsDownload\\res11234.html", "myTable") + dataFrame.into_outComponent(outputComponent) ); } } ``` -* Images begin to support the add function, which enables overlapping and merging of image functions under the operation - of the add function! +* Support the saving operation of obtaining ColorMatrix operand objects and ColorMatrix data objects through HDFS. ```java package zhao.algorithmMagic; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import zhao.algorithmMagic.io.*; import zhao.algorithmMagic.operands.matrix.ColorMatrix; +import zhao.algorithmMagic.operands.table.FinalCell; + +import java.io.IOException; -import java.sql.SQLException; public class MAIN1 { - public static void main(String[] args) { - // 撠銝鈭曉隞嗉蓮X銝箔銝芸曉拚萄笆鞊 - ColorMatrix colorMatrix1 = ColorMatrix.parse("C:\\Users\\Liming\\Desktop\\fsDownload\\test.bmp"); - ColorMatrix colorMatrix2 = ColorMatrix.parse("C:\\Users\\Liming\\Desktop\\fsDownload\\test1.bmp"); - // 撠 colorMatrix2 + colorMatrix1 蝏曉撅蝷箏箸 - (colorMatrix1.add(colorMatrix2)).show("image"); + public static void main(String[] args) throws IOException { + // 瑕 HDFS 唳株亥箄挽憭撖寡情 擐撠銝方閬啣撱箏箸 + FileSystem fileSystem; + String inPath; + { + Path path = new Path("hdfs://192.168.0.141:8020"); + // 撱慵DFS隞嗥頂蝏撖寡情 + fileSystem = path.getFileSystem(new Configuration()); + // 霈曄蔭閬鋡怨粉隞嗅笆鞊 + inPath = "hdfs://192.168.0.141:8020/data/test.jpg"; + } + + /* ***************************************************** + * TODO 隞HDFS銝剖頧賣唳 + * *****************************************************/ + // 撘憪撠圈蝵桀啗挽憭撖寡情銝哨撱箏箸唳株亥挽憭 + InputComponent inputComponent = InputHDFS.builder() + .addInputArg(InputHDFSBuilder.FILE_SYSTEM, new FinalCell<>(fileSystem)) + .addInputArg(InputHDFSBuilder.IN_PATH, new FinalCell<>(inPath)) + .create(); + + /* ***************************************************** + * TODO 憭頧賢箸亦 DataFrame 撖寡情嚗餈舀 age 甇摨摨 + * *****************************************************/ + // 撘憪撠 HDFS 銝剔唳桀頧賣銝箔銝 曉拚 撖寡情 撟嗅嗉銵憸脣頧祆雿 + ColorMatrix colorMatrix = ColorMatrix.parse(inputComponent); + colorMatrix.colorReversal(false); + + /* ***************************************************** + * TODO 撠憭憟賜唳株箏 HDFS /data/res.jpg 銝 + * *****************************************************/ + // 摰靘箸亦格頝臬 + Path path = new Path("hdfs://192.168.0.141:8020/data/res.jpg"); + // 撘憪撱箸唳株箇隞 + OutputComponent outputComponent = OutputHDFS.builder() + .addOutputArg(OutputHDFSBuidler.FILE_SYSTEM, new FinalCell<>(fileSystem)) + .addOutputArg(OutputHDFSBuidler.OUT_PATH, new FinalCell<>(path)) + .addOutputArg(OutputHDFSBuidler.FORMAT, new FinalCell<>("JPG")) + .create(); + // 撘憪餈蝏隞嗅唳株 嗆啣箇 + colorMatrix.show("res"); + colorMatrix.save(outputComponent); } } ``` -* Support aggregation operations for custom aggregation and built-in data schemes. +* Supports obtaining DataFrame operand objects through HDFS, while also supporting data output for this object. ```java package zhao.algorithmMagic; -import zhao.algorithmMagic.operands.matrix.ColorMatrix; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import zhao.algorithmMagic.io.*; +import zhao.algorithmMagic.operands.table.DataFrame; +import zhao.algorithmMagic.operands.table.FDataFrame; +import zhao.algorithmMagic.operands.table.FinalCell; + +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.OutputStreamWriter; -import java.sql.SQLException; public class MAIN1 { - public static void main(String[] args) { - // 撠銝鈭曉隞嗉蓮X銝箔銝芸曉拚萄笆鞊 - ColorMatrix colorMatrix1 = ColorMatrix.parse("C:\\Users\\Liming\\Desktop\\fsDownload\\test.bmp"); - ColorMatrix colorMatrix2 = ColorMatrix.parse("C:\\Users\\Liming\\Desktop\\fsDownload\\test1.bmp"); - // 雿輻 agg 賣唬誑蝵桃霈∠寞餈銵銝支葵拚萇撟 - // 銝W賣唬葉蝚砌銝芸耦隞銵函撠望舐拚萎葉蝝餉嚗餈雿輻函舀嚗撟嗅笆頞憸脫啣潸銵閫渡餉摰 - colorMatrix1.agg(colorMatrix2, ColorMatrix.COLOR_SUM_REGULATE).show("image"); + public static void main(String[] args) throws IOException { + // 瑕 HDFS 唳株亥箄挽憭撖寡情 擐撠銝方閬啣撱箏箸 + FileSystem fileSystem; + String inPath; + { + Path path = new Path("hdfs://192.168.0.141:8020"); + // 撱慵DFS隞嗥頂蝏撖寡情 + fileSystem = path.getFileSystem(new Configuration()); + // 霈曄蔭閬鋡怨粉隞嗅笆鞊 + inPath = "hdfs://192.168.0.141:8020/data/test.txt"; + } + + /* ***************************************************** + * TODO 隞HDFS銝剖頧賣唳 + * *****************************************************/ + // 撘憪撠圈蝵桀啗挽憭撖寡情銝哨撱箏箸唳株亥挽憭 + InputComponent inputComponent = InputHDFS.builder() + .addInputArg(InputHDFSBuilder.FILE_SYSTEM, new FinalCell<>(fileSystem)) + .addInputArg(InputHDFSBuilder.IN_PATH, new FinalCell<>(inPath)) + // 霈曄蔭隞嗡葉摰寧摮畾萄蝘 + .addInputArg(InputHDFSBuilder.FIELD, new FinalCell<>(new String[]{"name", "sex", "age"})) + // 霈曄蔭隞嗡葉瘥蝚 + .addInputArg(InputHDFSBuilder.SEP, new FinalCell<>('\t')) + // 霈曄蔭隞嗡葉霂餃摮蝚阡 + .addInputArg(InputHDFSBuilder.CHAR_SET, new FinalCell<>("utf-8")) + .create(); + + /* ***************************************************** + * TODO 憭頧賢箸亦 DataFrame 撖寡情嚗餈舀 age 甇摨摨 + * *****************************************************/ + // 撘憪撠 HDFS 銝剔唳桀頧賣銝箔銝 DataFrame 撖寡情 撟嗅嗉銵age甇摨摨雿 + DataFrame builder = FDataFrame + .builder(inputComponent) + .sort("age"); + + /* ***************************************************** + * TODO 撠憭憟賜唳株箏 HDFS /data/res.csv 銝 + * *****************************************************/ + // 摰靘箸亦格頝臬 + Path path = new Path("hdfs://192.168.0.141:8020/data/res.csv"); + // 撘憪撱箸唳株箇隞 + OutputComponent outputComponent = OutputHDFS.builder() + // 霈曄蔭颲箸嗥HDFS隞嗥頂蝏隞亙嗉楝敺 + .addOutputArg(OutputHDFSBuidler.FILE_SYSTEM, new FinalCell<>(fileSystem)) + .addOutputArg(OutputHDFSBuidler.OUT_PATH, new FinalCell<>(path)) + // 霈曄蔭颲箸澆嚗餈航箔銝杭SV隞 + .addOutputArg(OutputHDFSBuidler.FORMAT, new FinalCell<>("csv")) + // 颲箸嗥蝚 + .addOutputArg(OutputHDFSBuidler.SEP, new FinalCell<>(',')) + .create(); + // 撘憪餈蝏隞嗅唳株 嗡蝙 show 賣啣冽批嗅唳啣箇 澆瘜冽荔show 賣唬隡喲剜唳格撖寡情 + BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(System.out)); + builder.show(bufferedWriter); + System.out.println("ok!!!!"); + builder.into_outComponent(outputComponent); } } ``` -* The image matrix supports a corrosion operation function in which redundant feature data can be removed. +* Support obtaining data objects through data streams. Here, we obtain DataFrame objects from the system input stream + for demonstration. ```java package zhao.algorithmMagic; -import zhao.algorithmMagic.operands.matrix.ColorMatrix; +import zhao.algorithmMagic.io.InputByStream; +import zhao.algorithmMagic.io.InputByStreamBuilder; +import zhao.algorithmMagic.io.InputComponent; +import zhao.algorithmMagic.operands.table.DataFrame; +import zhao.algorithmMagic.operands.table.FDataFrame; +import zhao.algorithmMagic.operands.table.FinalCell; -import java.sql.SQLException; +import java.io.IOException; public class MAIN1 { public static void main(String[] args) { - // 撠銝鈭曉隞嗉蓮X銝箔銝芸曉拚萄笆鞊 - ColorMatrix colorMatrix1 = ColorMatrix.parseGrayscale("C:\\Users\\Liming\\Desktop\\fsDownload\\test2.bmp"); - // 撖孵曉餈銵鈭澆 - colorMatrix1.globalBinary(ColorMatrix._G_, 100, 0xffffff, 0); - colorMatrix1.show("銋 image"); - // 撘憪撖孵曉拚菔銵雿 - colorMatrix1.erode(2, 2, false).show("銋 image"); + /* ***************************************************** + * TODO 隞唳格銝剛粉唳唳 撟嗆撱 DF 撖寡情 + * *****************************************************/ + // 撘憪撠圈蝵桀啗挽憭撖寡情銝哨撱箏箸唳株亥挽憭 + InputComponent inputComponent = InputByStream.builder() + // 憭唳株交嚗刻憭舐蝡舀唳株交 + .addInputArg(InputByStreamBuilder.INPUT_STREAM, new FinalCell<>(System.in)) + // 霈曄蔭唳株亦摮蝚阡 + .addInputArg(InputByStreamBuilder.CHARSET, new FinalCell<>("utf-8")) + // 曹 DF 唳桀頧賣舐璅∪頧踝甇日閬霈曄蔭唳株亦蝚 + .addInputArg(InputByStreamBuilder.SEP, new FinalCell<>(',')) + // 曹 DF 唳桀笆鞊⊥銝駁桀踝甇日閬摰銝駁桃揣撘蝻 餈臭0撘憪蝝W + .addInputArg(InputByStreamBuilder.PK, new FinalCell<>(1)) + // 霈曄蔭祆活唳株颲亦銵圈 隞銵冽隞祈颲 3 銵唳 + .addInputArg(InputByStreamBuilder.ROW_LEN, new FinalCell<>(3)) + .create(); + // 撘憪餈銵唳桃頧 閬瘜冽荔曹隞砌蝙函舐蝡舀唳格嚗甇支閬獢嗆亙喲剜唳格嚗閬摰isOC銝榻alse + DataFrame builder = FDataFrame.builder(inputComponent, true); + builder.show(); } } ``` -* The addition of columns is supported, but it should be noted that the addition of columns will return a new DataFrame - DF in which the data will be lightly copied. +* Supports reading numerical matrices and structured DF data objects through AlgorithmStar, creating the same effect as + creating class static parse functions. ```java package zhao.algorithmMagic; -import zhao.algorithmMagic.operands.table.*; +import zhao.algorithmMagic.core.AlgorithmStar; +import zhao.algorithmMagic.io.InputByStream; +import zhao.algorithmMagic.io.InputByStreamBuilder; +import zhao.algorithmMagic.io.InputComponent; +import zhao.algorithmMagic.operands.matrix.DoubleMatrix; +import zhao.algorithmMagic.operands.matrix.IntegerMatrix; +import zhao.algorithmMagic.operands.table.DataFrame; +import zhao.algorithmMagic.operands.table.FinalCell; +import java.io.File; +import java.io.IOException; +import java.sql.Connection; +import java.sql.DriverManager; import java.sql.SQLException; + public class MAIN1 { - public static void main(String[] args) { - // 撱箔銝芰征 DataFrame 撖寡情 - FDataFrame select = FDataFrame.select( - FieldCell.parse("id", "name", "sex", "age"), 1 - ); - // 冽交唳 - select.insert( - FinalSeries.parse("1", "zhao", "M", "19"), - FinalSeries.parse("2", "tang", "W", "18"), - FinalSeries.parse("3", "yang", "W", "20"), - FinalSeries.parse("4", "shen", "W", "19") - ); - // 啣 DF 撖寡情喟靽⊥ - System.out.println( - select.desc() + public static void main(String[] args) throws SQLException { + /* ***************************************************** + * TODO 隞唳格銝剛粉唳唳 + * *****************************************************/ + // 撘憪撠圈蝵桀啗挽憭撖寡情銝哨撱箏箸唳株亥挽憭 + InputComponent inputComponent = InputByStream.builder() + .addInputArg(InputByStreamBuilder.INPUT_STREAM, new FinalCell<>(System.in)) + .addInputArg(InputByStreamBuilder.CHARSET, new FinalCell<>("utf-8")) + .addInputArg(InputByStreamBuilder.SEP, new FinalCell<>(',')) + .addInputArg(InputByStreamBuilder.PK, new FinalCell<>(1)) + .addInputArg(InputByStreamBuilder.ROW_LEN, new FinalCell<>(3)) + .create(); + + // TODO 撘憪餈 algorithmStar 撱箏箸啣潛拚 餈舀湔唬瘚桃寞唬舅蝘蝐餃 + IntegerMatrix integerMatrix = AlgorithmStar.parseIntMat( + new int[]{1, 2, 3}, new int[]{5, 6, 7}, new int[]{8, 9, 0} ); - // 瘛餃銝唳殷其銵函內撟湧臬虫蛹嗆 - DataFrame ageIsE = select.insertColGetNew( - // 啣蝘 - FieldCell.$("AgeIsE"), - // 啣啣潛餉 憒蝚 4 嚗index == 3嚗啣 % 2 == 0 撠望眩rue - cells -> cells.getCell(3).getIntValue() % 2 == 0 ? new FinalCell<>(true) : new FinalCell<>(false) + DoubleMatrix doubleMatrix = AlgorithmStar.parseDoubleMat( + new double[]{1, 2, 3}, new double[]{5, 6, 7}, new double[]{8, 9, 0} ); - System.out.println(ageIsE); + System.out.println(integerMatrix); + System.out.println(doubleMatrix); + + // TODO 撘憪餈 algorithmStar 撱箏慣ataFrame撖寡情 餈舫餈隞 唳桀 唳株亦隞 亥銵撱 + File file = new File("C:\\Users\\zhao\\Downloads\\test.csv"); + DataFrame dataFrame1 = AlgorithmStar.parseDF(file).setSep(',') + .create("year", "month", "day", "week", "temp_2", "temp_1", "average", "actual", "friend") + .execute(); + dataFrame1.show(); + + DataFrame dataFrame2 = AlgorithmStar.parseDF(inputComponent, false); + dataFrame2.show(); + + Connection connection = DriverManager.getConnection(""); + DataFrame dataFrame3 = AlgorithmStar.parseDF(connection) + .from("xxx") + .execute(); + dataFrame3.show(); } } ``` -* Supports operations between table data, and can perform summation and subtraction calculations on all numeric types in - the table. After calculation, a new DF object will be returned. +* Support static reading of image matrices through AlgorithmStar, and the ability to obtain image objects from files, + URLs, and data input components. This method of creation has the same effect as creating class static parse functions. ```java package zhao.algorithmMagic; -import zhao.algorithmMagic.operands.table.*; +import zhao.algorithmMagic.core.AlgorithmStar; +import zhao.algorithmMagic.io.InputCamera; +import zhao.algorithmMagic.io.InputCameraBuilder; +import zhao.algorithmMagic.io.InputComponent; +import zhao.algorithmMagic.operands.matrix.ColorMatrix; +import zhao.algorithmMagic.operands.table.FinalCell; + +import java.io.IOException; +import java.net.URL; +import java.sql.SQLException; + public class MAIN1 { - public static void main(String[] args) { - // 撱箔銝芰征 DataFrame 撖寡情 - FDataFrame select1 = FDataFrame.select( - FieldCell.parse("id", "name", "sex", "age"), 1 - ); - // 冽交唳 - select1.insert( - FinalSeries.parse("1", "zhao", "M", "19"), - FinalSeries.parse("2", "tang", "W", "18"), - FinalSeries.parse("3", "yang", "W", "20"), - FinalSeries.parse("4", "shen", "W", "19") - ); - // 撱箔銝芰征 DataFrame 撖寡情 - FDataFrame select2 = FDataFrame.select( - FieldCell.parse("id", "name", "sex", "age"), 1 - ); - // 冽交唳 - select2.insert( - FinalSeries.parse("1", "zhao", "M", "19"), - FinalSeries.parse("2", "tang", "W", "18"), - FinalSeries.parse("3", "yang", "W", "20") - ); - // 餈銵瘙銝撌桃餈蝞雿 - System.out.println(select1.add(select2)); - System.out.println(select1.diff(select2)); + public static void main(String[] args) throws IOException { + InputComponent inputComponent = InputCamera.builder() + .addInputArg(InputCameraBuilder.Camera_Index, new FinalCell<>(0)) + .addInputArg(InputCameraBuilder.Image_Format, new FinalCell<>("JPG")) + .create(); + // 餈唳株亥挽憭撖寡情瑕啣曉拚 + ColorMatrix colorMatrix = AlgorithmStar.parseImage(inputComponent, true); + colorMatrix.show("image"); + // 餈 URL 瑕啣曉拚 嚗銝箔蝞瘣銋血刻瘝⊥餈銵韏澆其嚗 + URL url = new URL("https://user-images.githubusercontent.com/113756063/194830221-abe24fcc-484b-4769-b3b7-ec6d8138f436.png"); + AlgorithmStar.parseImage(url).show("image"); + AlgorithmStar.parseGrayscaleImage(url).show("image"); + // 餈 隞 瑕啣曉拚 + AlgorithmStar.parseImage("C:\\Users\\zhao\\Desktop\\fsdownload\\test.bmp").show("image"); + AlgorithmStar.parseGrayscaleImage("C:\\Users\\zhao\\Desktop\\fsdownload\\test.bmp").show("image"); } } ``` -* Note for the new version: All dependencies in this version are marked as provided, which can minimize redundancy and - enable related configuration based on your actual project. Therefore, when performing AS library injection, please - import the following required items in one click. - -```xml - - - - - org.apache.logging.log4j - log4j-slf4j-impl - 2.20.0 - - - - - - org.apache.logging.log4j - log4j-api - 2.20.0 - - - - - org.apache.logging.log4j - log4j-core - 2.20.0 - - - -``` - -### Version update date : xx xx-xx-xx \ No newline at end of file +### Version update date : 2023-04-09 \ No newline at end of file diff --git a/src_code/pom.xml b/src_code/pom.xml index d52bc17..93b0da2 100644 --- a/src_code/pom.xml +++ b/src_code/pom.xml @@ -5,7 +5,7 @@ io.github.BeardedManZhao algorithmStar - 1.17 + 1.18 jar algorithmStar algorithmStar-java @@ -81,6 +81,29 @@ 3.1.3 provided + + + + com.github.sarxos + webcam-capture + 0.3.12 + provided + + + + + org.apache.hadoop + hadoop-client + 3.3.2 + provided + + + + org.apache.hadoop + hadoop-hdfs + 3.3.2 + provided + diff --git a/src_code/src/main/java/zhao/algorithmMagic/MAIN1.java b/src_code/src/main/java/zhao/algorithmMagic/MAIN1.java index 8483572..761e70b 100644 --- a/src_code/src/main/java/zhao/algorithmMagic/MAIN1.java +++ b/src_code/src/main/java/zhao/algorithmMagic/MAIN1.java @@ -1,9 +1,18 @@ package zhao.algorithmMagic; import zhao.algorithmMagic.algorithm.OperationAlgorithmManager; +import zhao.algorithmMagic.core.ASDynamicLibrary; + +import java.io.File; public class MAIN1 { public static void main(String[] args) { System.out.println(OperationAlgorithmManager.VERSION); + if (args.length > 0) { + ASDynamicLibrary.addDllDir(new File(args[0])); + System.out.println(OperationAlgorithmManager.getAlgorithmStarUrl()); + } else { + System.out.println("靚X函雿輻具"); + } } } diff --git a/src_code/src/main/java/zhao/algorithmMagic/algorithm/OperationAlgorithmManager.java b/src_code/src/main/java/zhao/algorithmMagic/algorithm/OperationAlgorithmManager.java index 767f1a4..a9f879a 100644 --- a/src_code/src/main/java/zhao/algorithmMagic/algorithm/OperationAlgorithmManager.java +++ b/src_code/src/main/java/zhao/algorithmMagic/algorithm/OperationAlgorithmManager.java @@ -18,7 +18,7 @@ * @author LingYuZhao */ public final class OperationAlgorithmManager implements OperationAlgorithm { - public final static float VERSION = 1.17f; + public final static float VERSION = 1.18f; /** * 霈∠蝏隞嗥亙啣喉敶甇文潔蛹false嗅嚗霈∠蝏隞嗡葉亙撠銝隡鋡急堆logger銋銝隡鋡怨剁銝祆亥秩嚗餈銝箔撠雿摮蝚虫葡摰靘雿嚗隡霈曄蔭銝榻alse嚗敶閬靚霂嗅閬撘甇文啣潦 *

diff --git a/src_code/src/main/java/zhao/algorithmMagic/algorithm/distanceAlgorithm/CanberraDistance.java b/src_code/src/main/java/zhao/algorithmMagic/algorithm/distanceAlgorithm/CanberraDistance.java index 9514fda..1fd94a3 100644 --- a/src_code/src/main/java/zhao/algorithmMagic/algorithm/distanceAlgorithm/CanberraDistance.java +++ b/src_code/src/main/java/zhao/algorithmMagic/algorithm/distanceAlgorithm/CanberraDistance.java @@ -7,6 +7,8 @@ import zhao.algorithmMagic.exception.OperatorOperationException; import zhao.algorithmMagic.exception.TargetNotRealizedException; import zhao.algorithmMagic.operands.coordinate.*; +import zhao.algorithmMagic.operands.matrix.DoubleMatrix; +import zhao.algorithmMagic.operands.matrix.IntegerMatrix; import zhao.algorithmMagic.operands.route.DoubleConsanguinityRoute; import zhao.algorithmMagic.operands.route.DoubleConsanguinityRoute2D; import zhao.algorithmMagic.operands.route.IntegerConsanguinityRoute; @@ -14,6 +16,8 @@ import zhao.algorithmMagic.utils.ASClass; import zhao.algorithmMagic.utils.ASMath; +import java.util.Iterator; + /** * Java蝐颱 2022/10/14 12:47:02 撱 *

@@ -298,4 +302,58 @@ public double getTrueDistance(IntegerConsanguinityRoute2D integerConsanguinityRo IntegerCoordinateTwo endPointCoordinate = integerConsanguinityRoute2D.getEndPointCoordinate(); return getTrueDistance(startingCoordinate.toArray(), endPointCoordinate.toArray()); } + + /** + * 霈∠銝支葵拚萄笆鞊∩渡頝蝳餃漲賣堆餈霂亙賣啣臭誑摰唬舅銝芰拚萄笆鞊∪漲蝟餅啁霈∠ + *

+ * Calculates the distance metric function between two matrix objects, through which the metric coefficients of two matrix objects can be calculated. + * + * @param integerMatrix1 閬鋡怨銵霈∠拚萄笆鞊∼ + *

+ * The matrix object that needs to be calculated. + * @param matrix2 閬鋡怨銵霈∠拚萄笆鞊∼ + *

+ * The matrix object that needs to be calculated. + * @return 霈∠箸亦摨阡蝏蝟餅啜 + *

+ * The calculated measurement result coefficient. + */ + @Override + public double getTrueDistance(IntegerMatrix integerMatrix1, IntegerMatrix matrix2) { + DistanceAlgorithm.checkMat(integerMatrix1, matrix2); + Iterator iterator1 = integerMatrix1.iterator(); + Iterator iterator2 = matrix2.iterator(); + double res = 0; + while (iterator1.hasNext() && iterator2.hasNext()) { + res += getTrueDistance(iterator1.next(), iterator2.next()); + } + return res; + } + + /** + * 霈∠銝支葵拚萄笆鞊∩渡頝蝳餃漲賣堆餈霂亙賣啣臭誑摰唬舅銝芰拚萄笆鞊∪漲蝟餅啁霈∠ + *

+ * Calculates the distance metric function between two matrix objects, through which the metric coefficients of two matrix objects can be calculated. + * + * @param matrix1 閬鋡怨銵霈∠拚萄笆鞊∼ + *

+ * The matrix object that needs to be calculated. + * @param matrix2 閬鋡怨銵霈∠拚萄笆鞊∼ + *

+ * The matrix object that needs to be calculated. + * @return 霈∠箸亦摨阡蝏蝟餅啜 + *

+ * The calculated measurement result coefficient. + */ + @Override + public double getTrueDistance(DoubleMatrix matrix1, DoubleMatrix matrix2) { + DistanceAlgorithm.checkMat(matrix1, matrix2); + Iterator iterator1 = matrix1.iterator(); + Iterator iterator2 = matrix2.iterator(); + double res = 0; + while (iterator1.hasNext() && iterator2.hasNext()) { + res += getTrueDistance(iterator1.next(), iterator2.next()); + } + return res; + } } diff --git a/src_code/src/main/java/zhao/algorithmMagic/algorithm/distanceAlgorithm/ChebyshevDistance.java b/src_code/src/main/java/zhao/algorithmMagic/algorithm/distanceAlgorithm/ChebyshevDistance.java index 7b1433f..08f551d 100644 --- a/src_code/src/main/java/zhao/algorithmMagic/algorithm/distanceAlgorithm/ChebyshevDistance.java +++ b/src_code/src/main/java/zhao/algorithmMagic/algorithm/distanceAlgorithm/ChebyshevDistance.java @@ -9,6 +9,8 @@ import zhao.algorithmMagic.operands.coordinate.Coordinate; import zhao.algorithmMagic.operands.coordinate.FloatingPointCoordinates; import zhao.algorithmMagic.operands.coordinate.IntegerCoordinates; +import zhao.algorithmMagic.operands.matrix.DoubleMatrix; +import zhao.algorithmMagic.operands.matrix.IntegerMatrix; import zhao.algorithmMagic.operands.route.DoubleConsanguinityRoute; import zhao.algorithmMagic.operands.route.DoubleConsanguinityRoute2D; import zhao.algorithmMagic.operands.route.IntegerConsanguinityRoute; @@ -322,4 +324,56 @@ public double getTrueDistance(IntegerConsanguinityRoute integerConsanguinityRout public double getTrueDistance(IntegerConsanguinityRoute2D integerConsanguinityRoute2D) { return getTrueDistance(integerConsanguinityRoute2D.getStartingCoordinate().toArray(), integerConsanguinityRoute2D.getEndPointCoordinate().toArray()); } + + /** + * 霈∠銝支葵拚萄笆鞊∩渡頝蝳餃漲賣堆餈霂亙賣啣臭誑摰唬舅銝芰拚萄笆鞊∪漲蝟餅啁霈∠ + *

+ * Calculates the distance metric function between two matrix objects, through which the metric coefficients of two matrix objects can be calculated. + * + * @param integerMatrix1 閬鋡怨銵霈∠拚萄笆鞊∼ + *

+ * The matrix object that needs to be calculated. + * @param matrix2 閬鋡怨銵霈∠拚萄笆鞊∼ + *

+ * The matrix object that needs to be calculated. + * @return 霈∠箸亦摨阡蝏蝟餅啜 + *

+ * The calculated measurement result coefficient. + */ + @Override + public double getTrueDistance(IntegerMatrix integerMatrix1, IntegerMatrix matrix2) { + int res = 0; + for (int[] ints : integerMatrix1.diff(matrix2)) { + for (int anInt : ints) { + if (anInt > res) res = anInt; + } + } + return res; + } + + /** + * 霈∠銝支葵拚萄笆鞊∩渡頝蝳餃漲賣堆餈霂亙賣啣臭誑摰唬舅銝芰拚萄笆鞊∪漲蝟餅啁霈∠ + *

+ * Calculates the distance metric function between two matrix objects, through which the metric coefficients of two matrix objects can be calculated. + * + * @param matrix1 閬鋡怨銵霈∠拚萄笆鞊∼ + *

+ * The matrix object that needs to be calculated. + * @param matrix2 閬鋡怨銵霈∠拚萄笆鞊∼ + *

+ * The matrix object that needs to be calculated. + * @return 霈∠箸亦摨阡蝏蝟餅啜 + *

+ * The calculated measurement result coefficient. + */ + @Override + public double getTrueDistance(DoubleMatrix matrix1, DoubleMatrix matrix2) { + double res = 0; + for (double[] ints : matrix1.diff(matrix2)) { + for (double anInt : ints) { + if (anInt > res) res = anInt; + } + } + return res; + } } diff --git a/src_code/src/main/java/zhao/algorithmMagic/algorithm/distanceAlgorithm/CosineDistance.java b/src_code/src/main/java/zhao/algorithmMagic/algorithm/distanceAlgorithm/CosineDistance.java index 563ebd4..a9243bf 100644 --- a/src_code/src/main/java/zhao/algorithmMagic/algorithm/distanceAlgorithm/CosineDistance.java +++ b/src_code/src/main/java/zhao/algorithmMagic/algorithm/distanceAlgorithm/CosineDistance.java @@ -5,6 +5,8 @@ import zhao.algorithmMagic.algorithm.OperationAlgorithm; import zhao.algorithmMagic.algorithm.OperationAlgorithmManager; import zhao.algorithmMagic.exception.TargetNotRealizedException; +import zhao.algorithmMagic.operands.matrix.DoubleMatrix; +import zhao.algorithmMagic.operands.matrix.IntegerMatrix; import zhao.algorithmMagic.operands.route.DoubleConsanguinityRoute; import zhao.algorithmMagic.operands.route.DoubleConsanguinityRoute2D; import zhao.algorithmMagic.operands.route.IntegerConsanguinityRoute; @@ -273,4 +275,44 @@ public double getTrueDistance(IntegerConsanguinityRoute integerConsanguinityRout public double getTrueDistance(IntegerConsanguinityRoute2D integerConsanguinityRoute2D) { return getTrueDistance(integerConsanguinityRoute2D.getStartingCoordinate().toArray(), integerConsanguinityRoute2D.getEndPointCoordinate().toArray()); } + + /** + * 霈∠銝支葵拚萄笆鞊∩渡頝蝳餃漲賣堆餈霂亙賣啣臭誑摰唬舅銝芰拚萄笆鞊∪漲蝟餅啁霈∠ + *

+ * Calculates the distance metric function between two matrix objects, through which the metric coefficients of two matrix objects can be calculated. + * + * @param integerMatrix1 閬鋡怨銵霈∠拚萄笆鞊∼ + *

+ * The matrix object that needs to be calculated. + * @param matrix2 閬鋡怨銵霈∠拚萄笆鞊∼ + *

+ * The matrix object that needs to be calculated. + * @return 霈∠箸亦摨阡蝏蝟餅啜 + *

+ * The calculated measurement result coefficient. + */ + @Override + public double getTrueDistance(IntegerMatrix integerMatrix1, IntegerMatrix matrix2) { + return integerMatrix1.innerProduct(matrix2) / (double) (integerMatrix1.moduleLength() * matrix2.moduleLength()); + } + + /** + * 霈∠銝支葵拚萄笆鞊∩渡頝蝳餃漲賣堆餈霂亙賣啣臭誑摰唬舅銝芰拚萄笆鞊∪漲蝟餅啁霈∠ + *

+ * Calculates the distance metric function between two matrix objects, through which the metric coefficients of two matrix objects can be calculated. + * + * @param matrix1 閬鋡怨銵霈∠拚萄笆鞊∼ + *

+ * The matrix object that needs to be calculated. + * @param matrix2 閬鋡怨銵霈∠拚萄笆鞊∼ + *

+ * The matrix object that needs to be calculated. + * @return 霈∠箸亦摨阡蝏蝟餅啜 + *

+ * The calculated measurement result coefficient. + */ + @Override + public double getTrueDistance(DoubleMatrix matrix1, DoubleMatrix matrix2) { + return matrix1.innerProduct(matrix2) / (matrix1.moduleLength() * matrix2.moduleLength()); + } } diff --git a/src_code/src/main/java/zhao/algorithmMagic/algorithm/distanceAlgorithm/DistanceAlgorithm.java b/src_code/src/main/java/zhao/algorithmMagic/algorithm/distanceAlgorithm/DistanceAlgorithm.java index cd2b46a..e9ed0fe 100644 --- a/src_code/src/main/java/zhao/algorithmMagic/algorithm/distanceAlgorithm/DistanceAlgorithm.java +++ b/src_code/src/main/java/zhao/algorithmMagic/algorithm/distanceAlgorithm/DistanceAlgorithm.java @@ -1,6 +1,10 @@ package zhao.algorithmMagic.algorithm.distanceAlgorithm; import zhao.algorithmMagic.algorithm.OperationAlgorithm; +import zhao.algorithmMagic.exception.OperatorOperationException; +import zhao.algorithmMagic.operands.matrix.DoubleMatrix; +import zhao.algorithmMagic.operands.matrix.IntegerMatrix; +import zhao.algorithmMagic.operands.matrix.Matrix; import zhao.algorithmMagic.operands.route.DoubleConsanguinityRoute; import zhao.algorithmMagic.operands.route.DoubleConsanguinityRoute2D; import zhao.algorithmMagic.operands.route.IntegerConsanguinityRoute; @@ -13,6 +17,31 @@ */ public interface DistanceAlgorithm extends OperationAlgorithm { + /** + * 典漲霈∠蝞瘜蝏隞嗡葉嚗賢舀拚萄笆鞊∠餈蝞嚗雿臬刻蝞銋閬撖寧拚萎葉唳株銵銝銝芣伐蝖桐嗡隡霂胯 + *

+ * In the metric calculation algorithm component, operations on matrix objects can be supported, but before operations, it is necessary to check the data in the matrix to ensure that no errors occur. + * + * @param Matrix1 閬鋡怨恣蝞拚萄笆鞊∴敺璉亦拚萄笆鞊∼ + *

+ * The matrix object to be calculated and the matrix object to be checked. + * @param Matrix2 閬鋡怨恣蝞拚萄笆鞊∴敺璉亦拚萄笆鞊∼ + *

+ * The matrix object to be calculated and the matrix object to be checked. + */ + static void checkMat(Matrix Matrix1, Matrix Matrix2) { + check(Matrix1.getRowCount(), Matrix1.getColCount(), Matrix2.getRowCount(), Matrix2.getColCount()); + } + + static void check(int rowCount, int colCount, int rowCount3, int colCount3) { + if (rowCount != rowCount3) + throw new OperatorOperationException("拚萄笆鞊∩葉銵圈銝銝湛銝航恣蝞\nThe number of rows in the matrix object is inconsistent and cannot be calculated.ERROR => row1 = " + + rowCount + "\trow2 = " + rowCount3); + if (colCount != colCount3) + throw new OperatorOperationException("拚萄笆鞊∩葉圈銝銝湛銝航恣蝞\nThe number of cols in the matrix object is inconsistent and cannot be calculated.ERROR => col1 = " + + colCount + "\tcol2 = " + colCount3); + } + /** * 霈∠銝銝芾楝蝥輻韏瑕嫣蝏甇Y寧摰頝蝳颯瑚頝蝳餃堆閬冽仿蝞瘜摰啁獢 *

@@ -82,4 +111,38 @@ public interface DistanceAlgorithm extends OperationAlgorithm { * @return ... */ double getTrueDistance(IntegerConsanguinityRoute2D integerConsanguinityRoute2D); + + /** + * 霈∠銝支葵拚萄笆鞊∩渡頝蝳餃漲賣堆餈霂亙賣啣臭誑摰唬舅銝芰拚萄笆鞊∪漲蝟餅啁霈∠ + *

+ * Calculates the distance metric function between two matrix objects, through which the metric coefficients of two matrix objects can be calculated. + * + * @param matrix1 閬鋡怨銵霈∠拚萄笆鞊∼ + *

+ * The matrix object that needs to be calculated. + * @param matrix2 閬鋡怨銵霈∠拚萄笆鞊∼ + *

+ * The matrix object that needs to be calculated. + * @return 霈∠箸亦摨阡蝏蝟餅啜 + *

+ * The calculated measurement result coefficient. + */ + double getTrueDistance(IntegerMatrix matrix1, IntegerMatrix matrix2); + + /** + * 霈∠銝支葵拚萄笆鞊∩渡頝蝳餃漲賣堆餈霂亙賣啣臭誑摰唬舅銝芰拚萄笆鞊∪漲蝟餅啁霈∠ + *

+ * Calculates the distance metric function between two matrix objects, through which the metric coefficients of two matrix objects can be calculated. + * + * @param matrix1 閬鋡怨銵霈∠拚萄笆鞊∼ + *

+ * The matrix object that needs to be calculated. + * @param matrix2 閬鋡怨銵霈∠拚萄笆鞊∼ + *

+ * The matrix object that needs to be calculated. + * @return 霈∠箸亦摨阡蝏蝟餅啜 + *

+ * The calculated measurement result coefficient. + */ + double getTrueDistance(DoubleMatrix matrix1, DoubleMatrix matrix2); } diff --git a/src_code/src/main/java/zhao/algorithmMagic/algorithm/distanceAlgorithm/EuclideanMetric.java b/src_code/src/main/java/zhao/algorithmMagic/algorithm/distanceAlgorithm/EuclideanMetric.java index 94f5388..c7bbe1a 100644 --- a/src_code/src/main/java/zhao/algorithmMagic/algorithm/distanceAlgorithm/EuclideanMetric.java +++ b/src_code/src/main/java/zhao/algorithmMagic/algorithm/distanceAlgorithm/EuclideanMetric.java @@ -9,6 +9,8 @@ import zhao.algorithmMagic.operands.coordinate.Coordinate; import zhao.algorithmMagic.operands.coordinate.FloatingPointCoordinates; import zhao.algorithmMagic.operands.coordinate.IntegerCoordinates; +import zhao.algorithmMagic.operands.matrix.DoubleMatrix; +import zhao.algorithmMagic.operands.matrix.IntegerMatrix; import zhao.algorithmMagic.operands.route.DoubleConsanguinityRoute; import zhao.algorithmMagic.operands.route.DoubleConsanguinityRoute2D; import zhao.algorithmMagic.operands.route.IntegerConsanguinityRoute; @@ -332,6 +334,58 @@ public double getTrueDistance(IntegerConsanguinityRoute2D integerConsanguinityRo return getTrueDistance(integerConsanguinityRoute2D.getStartingCoordinate().toArray(), integerConsanguinityRoute2D.getEndPointCoordinate().toArray()); } + /** + * 霈∠銝支葵拚萄笆鞊∩渡頝蝳餃漲賣堆餈霂亙賣啣臭誑摰唬舅銝芰拚萄笆鞊∪漲蝟餅啁霈∠ + *

+ * Calculates the distance metric function between two matrix objects, through which the metric coefficients of two matrix objects can be calculated. + * + * @param integerMatrix1 閬鋡怨銵霈∠拚萄笆鞊∼ + *

+ * The matrix object that needs to be calculated. + * @param matrix2 閬鋡怨銵霈∠拚萄笆鞊∼ + *

+ * The matrix object that needs to be calculated. + * @return 霈∠箸亦摨阡蝏蝟餅啜 + *

+ * The calculated measurement result coefficient. + */ + @Override + public double getTrueDistance(IntegerMatrix integerMatrix1, IntegerMatrix matrix2) { + int res = 0; + for (int[] ints : integerMatrix1.diff(matrix2)) { + for (int anInt : ints) { + res += ASMath.Power2(anInt); + } + } + return Math.sqrt(res); + } + + /** + * 霈∠銝支葵拚萄笆鞊∩渡頝蝳餃漲賣堆餈霂亙賣啣臭誑摰唬舅銝芰拚萄笆鞊∪漲蝟餅啁霈∠ + *

+ * Calculates the distance metric function between two matrix objects, through which the metric coefficients of two matrix objects can be calculated. + * + * @param matrix1 閬鋡怨銵霈∠拚萄笆鞊∼ + *

+ * The matrix object that needs to be calculated. + * @param matrix2 閬鋡怨銵霈∠拚萄笆鞊∼ + *

+ * The matrix object that needs to be calculated. + * @return 霈∠箸亦摨阡蝏蝟餅啜 + *

+ * The calculated measurement result coefficient. + */ + @Override + public double getTrueDistance(DoubleMatrix matrix1, DoubleMatrix matrix2) { + double res = 0; + for (double[] ints : matrix1.diff(matrix2)) { + for (double anInt : ints) { + res += ASMath.Power2(anInt); + } + } + return Math.sqrt(res); + } + /** * 霈∠頝蝳餃寧頝蝳颯 * diff --git a/src_code/src/main/java/zhao/algorithmMagic/algorithm/distanceAlgorithm/HausdorffDistance.java b/src_code/src/main/java/zhao/algorithmMagic/algorithm/distanceAlgorithm/HausdorffDistance.java index e55ebec..2952d59 100644 --- a/src_code/src/main/java/zhao/algorithmMagic/algorithm/distanceAlgorithm/HausdorffDistance.java +++ b/src_code/src/main/java/zhao/algorithmMagic/algorithm/distanceAlgorithm/HausdorffDistance.java @@ -9,11 +9,14 @@ import zhao.algorithmMagic.operands.coordinate.Coordinate; import zhao.algorithmMagic.operands.coordinate.FloatingPointCoordinates; import zhao.algorithmMagic.operands.coordinate.IntegerCoordinates; +import zhao.algorithmMagic.operands.matrix.DoubleMatrix; +import zhao.algorithmMagic.operands.matrix.IntegerMatrix; import zhao.algorithmMagic.operands.route.DoubleConsanguinityRoute; import zhao.algorithmMagic.operands.route.DoubleConsanguinityRoute2D; import zhao.algorithmMagic.operands.route.IntegerConsanguinityRoute; import zhao.algorithmMagic.operands.route.IntegerConsanguinityRoute2D; import zhao.algorithmMagic.utils.ASClass; +import zhao.algorithmMagic.utils.ASMath; import java.util.HashMap; @@ -230,4 +233,74 @@ public double getTrueDistance(IntegerConsanguinityRoute integerConsanguinityRout public double getTrueDistance(IntegerConsanguinityRoute2D integerConsanguinityRoute2D) { return getTrueDistance(integerConsanguinityRoute2D.getStartingCoordinate().toArray(), integerConsanguinityRoute2D.getEndPointCoordinate().toArray()); } + + /** + * 霈∠銝支葵拚萄笆鞊∩渡頝蝳餃漲賣堆餈霂亙賣啣臭誑摰唬舅銝芰拚萄笆鞊∪漲蝟餅啁霈∠ + *

+ * Calculates the distance metric function between two matrix objects, through which the metric coefficients of two matrix objects can be calculated. + * + * @param integerMatrix1 閬鋡怨銵霈∠拚萄笆鞊∼ + *

+ * The matrix object that needs to be calculated. + * @param matrix2 閬鋡怨銵霈∠拚萄笆鞊∼ + *

+ * The matrix object that needs to be calculated. + * @return 霈∠箸亦摨阡蝏蝟餅啜 + *

+ * The calculated measurement result coefficient. + */ + @Override + public double getTrueDistance(IntegerMatrix integerMatrix1, IntegerMatrix matrix2) { + DistanceAlgorithm.checkMat(integerMatrix1, matrix2); + int[][] mat2 = matrix2.toArrays(); + int[] res = new int[integerMatrix1.getNumberOfDimensions()]; + for (int[] ints : integerMatrix1) { + for (int anInt : ints) { + // 撠 1 拚萎葉嫣 2 拚萎葉寧頝蝳餌憭批潸恣蝞箸 + int max = 0; + for (int[] ints1 : mat2) { + for (int i : ints1) { + max = Math.max(anInt - i, max); + } + } + } + } + // 瑕 res 銝剔憭扳啣澆僎餈 + return res[ASMath.findMaxIndex(res)]; + } + + /** + * 霈∠銝支葵拚萄笆鞊∩渡頝蝳餃漲賣堆餈霂亙賣啣臭誑摰唬舅銝芰拚萄笆鞊∪漲蝟餅啁霈∠ + *

+ * Calculates the distance metric function between two matrix objects, through which the metric coefficients of two matrix objects can be calculated. + * + * @param matrix1 閬鋡怨銵霈∠拚萄笆鞊∼ + *

+ * The matrix object that needs to be calculated. + * @param matrix2 閬鋡怨銵霈∠拚萄笆鞊∼ + *

+ * The matrix object that needs to be calculated. + * @return 霈∠箸亦摨阡蝏蝟餅啜 + *

+ * The calculated measurement result coefficient. + */ + @Override + public double getTrueDistance(DoubleMatrix matrix1, DoubleMatrix matrix2) { + DistanceAlgorithm.checkMat(matrix1, matrix2); + double[][] mat2 = matrix2.toArrays(); + double[] res = new double[matrix1.getNumberOfDimensions()]; + for (double[] ints : matrix1) { + for (double anInt : ints) { + // 撠 1 拚萎葉嫣 2 拚萎葉寧頝蝳餌憭批潸恣蝞箸 + double max = 0; + for (double[] ints1 : mat2) { + for (double i : ints1) { + max = Math.max(anInt - i, max); + } + } + } + } + // 瑕 res 銝剔憭扳啣澆僎餈 + return res[ASMath.findMaxIndex(res)]; + } } diff --git a/src_code/src/main/java/zhao/algorithmMagic/algorithm/distanceAlgorithm/ManhattanDistance.java b/src_code/src/main/java/zhao/algorithmMagic/algorithm/distanceAlgorithm/ManhattanDistance.java index 71b8270..6f86cfb 100644 --- a/src_code/src/main/java/zhao/algorithmMagic/algorithm/distanceAlgorithm/ManhattanDistance.java +++ b/src_code/src/main/java/zhao/algorithmMagic/algorithm/distanceAlgorithm/ManhattanDistance.java @@ -6,6 +6,8 @@ import zhao.algorithmMagic.algorithm.OperationAlgorithmManager; import zhao.algorithmMagic.exception.TargetNotRealizedException; import zhao.algorithmMagic.operands.coordinate.*; +import zhao.algorithmMagic.operands.matrix.DoubleMatrix; +import zhao.algorithmMagic.operands.matrix.IntegerMatrix; import zhao.algorithmMagic.operands.route.DoubleConsanguinityRoute; import zhao.algorithmMagic.operands.route.DoubleConsanguinityRoute2D; import zhao.algorithmMagic.operands.route.IntegerConsanguinityRoute; @@ -329,6 +331,58 @@ public double getTrueDistance(IntegerConsanguinityRoute2D integerConsanguinityRo return getTrueDistance(integerConsanguinityRoute2D.getStartingCoordinate().toArray(), integerConsanguinityRoute2D.getEndPointCoordinate().toArray()); } + /** + * 霈∠銝支葵拚萄笆鞊∩渡頝蝳餃漲賣堆餈霂亙賣啣臭誑摰唬舅銝芰拚萄笆鞊∪漲蝟餅啁霈∠ + *

+ * Calculates the distance metric function between two matrix objects, through which the metric coefficients of two matrix objects can be calculated. + * + * @param integerMatrix1 閬鋡怨銵霈∠拚萄笆鞊∼ + *

+ * The matrix object that needs to be calculated. + * @param matrix2 閬鋡怨銵霈∠拚萄笆鞊∼ + *

+ * The matrix object that needs to be calculated. + * @return 霈∠箸亦摨阡蝏蝟餅啜 + *

+ * The calculated measurement result coefficient. + */ + @Override + public double getTrueDistance(IntegerMatrix integerMatrix1, IntegerMatrix matrix2) { + int res = 0; + for (int[] ints : integerMatrix1.diff(matrix2)) { + for (int anInt : ints) { + res += ASMath.absoluteValue(anInt); + } + } + return res; + } + + /** + * 霈∠銝支葵拚萄笆鞊∩渡頝蝳餃漲賣堆餈霂亙賣啣臭誑摰唬舅銝芰拚萄笆鞊∪漲蝟餅啁霈∠ + *

+ * Calculates the distance metric function between two matrix objects, through which the metric coefficients of two matrix objects can be calculated. + * + * @param matrix1 閬鋡怨銵霈∠拚萄笆鞊∼ + *

+ * The matrix object that needs to be calculated. + * @param matrix2 閬鋡怨銵霈∠拚萄笆鞊∼ + *

+ * The matrix object that needs to be calculated. + * @return 霈∠箸亦摨阡蝏蝟餅啜 + *

+ * The calculated measurement result coefficient. + */ + @Override + public double getTrueDistance(DoubleMatrix matrix1, DoubleMatrix matrix2) { + double res = 0; + for (double[] ints : matrix1.diff(matrix2)) { + for (double anInt : ints) { + res += ASMath.absoluteValue(anInt); + } + } + return res; + } + /** * 霈∠頝蝳餃寧頝蝳颯 * diff --git a/src_code/src/main/java/zhao/algorithmMagic/algorithm/distanceAlgorithm/MinkowskiDistance.java b/src_code/src/main/java/zhao/algorithmMagic/algorithm/distanceAlgorithm/MinkowskiDistance.java index 2491248..7034066 100644 --- a/src_code/src/main/java/zhao/algorithmMagic/algorithm/distanceAlgorithm/MinkowskiDistance.java +++ b/src_code/src/main/java/zhao/algorithmMagic/algorithm/distanceAlgorithm/MinkowskiDistance.java @@ -6,6 +6,8 @@ import zhao.algorithmMagic.algorithm.OperationAlgorithmManager; import zhao.algorithmMagic.exception.TargetNotRealizedException; import zhao.algorithmMagic.operands.coordinate.*; +import zhao.algorithmMagic.operands.matrix.DoubleMatrix; +import zhao.algorithmMagic.operands.matrix.IntegerMatrix; import zhao.algorithmMagic.operands.route.DoubleConsanguinityRoute; import zhao.algorithmMagic.operands.route.DoubleConsanguinityRoute2D; import zhao.algorithmMagic.operands.route.IntegerConsanguinityRoute; @@ -339,6 +341,60 @@ public double getTrueDistance(IntegerConsanguinityRoute2D integerConsanguinityRo return getTrueDistance(integerConsanguinityRoute2D.getStartingCoordinate().toArray(), integerConsanguinityRoute2D.getEndPointCoordinate().toArray()); } + /** + * 霈∠銝支葵拚萄笆鞊∩渡頝蝳餃漲賣堆餈霂亙賣啣臭誑摰唬舅銝芰拚萄笆鞊∪漲蝟餅啁霈∠ + *

+ * Calculates the distance metric function between two matrix objects, through which the metric coefficients of two matrix objects can be calculated. + * + * @param matrix1 閬鋡怨銵霈∠拚萄笆鞊∼ + *

+ * The matrix object that needs to be calculated. + * @param matrix2 閬鋡怨銵霈∠拚萄笆鞊∼ + *

+ * The matrix object that needs to be calculated. + * @return 霈∠箸亦摨阡蝏蝟餅啜 + *

+ * The calculated measurement result coefficient. + */ + @Override + public double getTrueDistance(IntegerMatrix matrix1, IntegerMatrix matrix2) { + int res = 0; + int $P = get$P(); + for (int[] ints : matrix1.diff(matrix2)) { + for (int anInt : ints) { + res += Math.pow(anInt, $P); + } + } + return res; + } + + /** + * 霈∠銝支葵拚萄笆鞊∩渡頝蝳餃漲賣堆餈霂亙賣啣臭誑摰唬舅銝芰拚萄笆鞊∪漲蝟餅啁霈∠ + *

+ * Calculates the distance metric function between two matrix objects, through which the metric coefficients of two matrix objects can be calculated. + * + * @param matrix1 閬鋡怨銵霈∠拚萄笆鞊∼ + *

+ * The matrix object that needs to be calculated. + * @param matrix2 閬鋡怨銵霈∠拚萄笆鞊∼ + *

+ * The matrix object that needs to be calculated. + * @return 霈∠箸亦摨阡蝏蝟餅啜 + *

+ * The calculated measurement result coefficient. + */ + @Override + public double getTrueDistance(DoubleMatrix matrix1, DoubleMatrix matrix2) { + int res = 0; + int $P = get$P(); + for (double[] ints : matrix1.diff(matrix2)) { + for (double anInt : ints) { + res += Math.pow(anInt, $P); + } + } + return res; + } + /** * 霈∠頝蝳餃寧頝蝳颯 * diff --git a/src_code/src/main/java/zhao/algorithmMagic/algorithm/distanceAlgorithm/StandardizedEuclideanDistance.java b/src_code/src/main/java/zhao/algorithmMagic/algorithm/distanceAlgorithm/StandardizedEuclideanDistance.java index acbe5cf..05f83f0 100644 --- a/src_code/src/main/java/zhao/algorithmMagic/algorithm/distanceAlgorithm/StandardizedEuclideanDistance.java +++ b/src_code/src/main/java/zhao/algorithmMagic/algorithm/distanceAlgorithm/StandardizedEuclideanDistance.java @@ -4,30 +4,22 @@ import zhao.algorithmMagic.algorithm.OperationAlgorithmManager; import zhao.algorithmMagic.algorithm.normalization.Z_ScoreNormalization; import zhao.algorithmMagic.exception.TargetNotRealizedException; -import zhao.algorithmMagic.operands.coordinate.*; +import zhao.algorithmMagic.operands.coordinate.DoubleCoordinateMany; +import zhao.algorithmMagic.operands.coordinate.FloatingPointCoordinates; +import zhao.algorithmMagic.operands.coordinate.IntegerCoordinateMany; +import zhao.algorithmMagic.operands.coordinate.IntegerCoordinates; +import zhao.algorithmMagic.operands.matrix.DoubleMatrix; +import zhao.algorithmMagic.operands.matrix.IntegerMatrix; import zhao.algorithmMagic.utils.ASClass; -import zhao.algorithmMagic.utils.DependentAlgorithmNameLibrary; /** * Java蝐颱 2022/10/13 10:30:50 撱 *

* 甈批敺摨阡嚗撠瘥銝銝芰輕摨衣餈銵嚗嗅餈銵甈批敺霈∠ * - * @param 祉掩銝剖銝餈蝞湔啣蝐餃嚗券閬冽迨蝐餌摰霂亦掩臭誑餈蝞游耦 - *

- * The type of integer coordinates involved in the operation in this class, you need to specify the integer coordinates that this class can operate on in this class. - * @param 祉掩銝剖銝餈蝞瘚桃孵蝐餃嚗券閬冽迨蝐餌摰霂亦掩臭誑餈蝞瘚桃孵 - *

- * The type of floating-point coordinates involved in the operation in this class. You need to specify the floating-point coordinates that this class can operate on. * @author LingYuZhao */ -public class StandardizedEuclideanDistance & Coordinate, D extends FloatingPointCoordinates> extends EuclideanMetric { - - private final EuclideanMetric euclideanMetric = EuclideanMetric.getInstance(DependentAlgorithmNameLibrary.EUCLIDEAN_METRIC_NAME); - - protected StandardizedEuclideanDistance() { - super(); - } +public class StandardizedEuclideanDistance extends EuclideanMetric { protected StandardizedEuclideanDistance(String algorithmName) { super(algorithmName); @@ -37,40 +29,25 @@ protected StandardizedEuclideanDistance(String algorithmName) { * 瑕啗砲蝞瘜蝐餃笆鞊∴ * * @param Name 霂亦瘜蝘 - * @param 霂亦瘜冽亙游耦臭銋唳桃掩 - *

- * What data type is the integer coordinate used by this algorithm? - * @param

霂亦瘜冽亙瘚桃孵臭銋唳桃掩 * @return 蝞瘜蝐餃笆鞊 * @throws TargetNotRealizedException 敶其亦蝞瘜蝘啣笆摨蝏隞嗡質◤嗅隡箏撣 */ - public static & Coordinate, DD extends FloatingPointCoordinates> StandardizedEuclideanDistance getInstance2(String Name) { + public static StandardizedEuclideanDistance getInstance2(String Name) { if (OperationAlgorithmManager.containsAlgorithmName(Name)) { OperationAlgorithm operationAlgorithm = OperationAlgorithmManager.getInstance().get(Name); - if (operationAlgorithm instanceof StandardizedEuclideanDistance) { + if (operationAlgorithm instanceof StandardizedEuclideanDistance) { return ASClass.transform(operationAlgorithm); } else { throw new TargetNotRealizedException("冽[" + Name + "]蝞瘜鋡急曉唬嚗雿臬銝撅鈭StandardizedEuclideanDistance蝐餃嚗霂瑟其蛹餈銝芰瘜啣銋銝銝芸蝘啜\n" + "The [" + Name + "] algorithm you extracted has been found, but it does not belong to the StandardizedEuclideanDistance type. Please redefine a name for this algorithm."); } } else { - StandardizedEuclideanDistance standardizedEuclideanDistance = new StandardizedEuclideanDistance<>(Name); + StandardizedEuclideanDistance standardizedEuclideanDistance = new StandardizedEuclideanDistance(Name); OperationAlgorithmManager.getInstance().register(standardizedEuclideanDistance); return standardizedEuclideanDistance; } } - public EuclideanMetric toEuclideanMetric() { - if (this.euclideanMetric != null) { - return this.euclideanMetric; - } else { - String euclideanMetricName = DependentAlgorithmNameLibrary.EUCLIDEAN_METRIC_NAME; - logger.warn("蝘唬蛹嚗[" + euclideanMetricName + "]蝞瘜鋡怠支嚗銝箔踹撘撣賂甈批敺瑞瘜璅∪甈批敺瑞瘜靘韏嚗撌脩湔亦摰記perationAlgorithmManager嚗憒冽唾踹霂亥郎嚗霂瑟典其久EuclideanMetric]蝞瘜銝舐摨嚗\n" + - "The algorithm named: [" + euclideanMetricName + "] has been removed. To avoid exceptions, the Euclidean algorithm dependencies required by the standardized Euclidean algorithm module have been directly bound to the Operation Algorithm Manager, if you want to avoid the warning , please restart the program without deleting the [" + euclideanMetricName + "] algorithm!"); - return EuclideanMetric.getInstance(euclideanMetricName); - } - } - /** * 憭蝏渡征港銝哨芾澈孵啣寧頝蝳鳴餈臬蝏渡征湛隞交舀銝銝芰輕摨衣寥賭鋡怨銵2甈⊥ *

@@ -82,13 +59,13 @@ public EuclideanMetric toEuclideanM * @return Euclidean distance from its own coordinates to the origin */ @Override - public double getTrueDistance(FloatingPointCoordinates iFloatingPointCoordinates) { + public double getTrueDistance(FloatingPointCoordinates iFloatingPointCoordinates) { double[] doubles1 = iFloatingPointCoordinates.toArray(); double[] doublesZ = Z_ScoreNormalization.StandardizedSequence(doubles1); if (OperationAlgorithmManager.PrintCalculationComponentLog) { logger.info(" 踱( (iFloatingPointCoordinates(n) / StandardSequence(n))簡 )"); } - return this.euclideanMetric.getTrueDistance(new DoubleCoordinateMany(DivideByNormalization(doubles1, doublesZ))); + return super.getTrueDistance(new DoubleCoordinateMany(DivideByNormalization(doubles1, doublesZ))); } /** @@ -132,13 +109,13 @@ private int[] DivideByNormalization(int[] NonstandardSequence, int[] StandardSeq * @return Euclidean distance from its own coordinates to the origin */ @Override - public double getTrueDistance(IntegerCoordinates integerCoordinates) { + public double getTrueDistance(IntegerCoordinates integerCoordinates) { int[] doubles1 = integerCoordinates.toArray(); int[] doublesZ = Z_ScoreNormalization.StandardizedSequence(doubles1); if (OperationAlgorithmManager.PrintCalculationComponentLog) { logger.info(" 踱( (integerCoordinates(n) / StandardSequence(n))簡 )"); } - return this.euclideanMetric.getTrueDistance(new IntegerCoordinateMany(DivideByNormalization(doubles1, doublesZ))); + return super.getTrueDistance(new IntegerCoordinateMany(DivideByNormalization(doubles1, doublesZ))); } /** @@ -152,13 +129,13 @@ public double getTrueDistance(IntegerCoordinates integerCoordinates) { * @return True Euclidean distance between two points */ @Override - public double getTrueDistance(IntegerCoordinates integerCoordinateMany1, IntegerCoordinates integerCoordinateMany2) { + public double getTrueDistance(IntegerCoordinates integerCoordinateMany1, IntegerCoordinates integerCoordinateMany2) { if (OperationAlgorithmManager.PrintCalculationComponentLog) { logger.info(" 踱( " + integerCoordinateMany1 + " - " + integerCoordinateMany2 + ").map(i -> (i / StandardSequence)簡)"); } int[] doubles1 = integerCoordinateMany1.extend().diff(integerCoordinateMany2.extend()).toArray(); int[] doublesZ = Z_ScoreNormalization.StandardizedSequence(doubles1); - return this.euclideanMetric.getTrueDistance(new IntegerCoordinateMany(DivideByNormalization(doubles1, doublesZ))); + return super.getTrueDistance(new IntegerCoordinateMany(DivideByNormalization(doubles1, doublesZ))); } /** @@ -171,13 +148,13 @@ public double getTrueDistance(IntegerCoordinates integerCoordinateMany1, Inte * @return True Euclidean distance between two points */ @Override - public double getTrueDistance(FloatingPointCoordinates doubleCoordinateMany1, FloatingPointCoordinates doubleCoordinateMany2) { + public double getTrueDistance(FloatingPointCoordinates doubleCoordinateMany1, FloatingPointCoordinates doubleCoordinateMany2) { if (OperationAlgorithmManager.PrintCalculationComponentLog) { logger.info(" 踱( " + doubleCoordinateMany1 + " - " + doubleCoordinateMany2 + ").map(d -> (d / StandardSequence)簡)"); } double[] doubles1 = doubleCoordinateMany1.diff(doubleCoordinateMany2.extend()).toArray(); double[] doublesZ = Z_ScoreNormalization.StandardizedSequence(doubles1); - return this.euclideanMetric.getTrueDistance(new DoubleCoordinateMany(DivideByNormalization(doubles1, doublesZ))); + return super.getTrueDistance(new DoubleCoordinateMany(DivideByNormalization(doubles1, doublesZ))); } @@ -223,7 +200,7 @@ public boolean init() { public double getTrueDistance(double[] doubles1, double[] doubles2) { double[] doubles11 = new DoubleCoordinateMany(doubles1).diff(new DoubleCoordinateMany(doubles2)).toArray(); double[] doubles22 = Z_ScoreNormalization.StandardizedSequence(doubles11); - return this.euclideanMetric.getTrueDistance(new DoubleCoordinateMany(DivideByNormalization(doubles11, doubles22))); + return super.getTrueDistance(new DoubleCoordinateMany(DivideByNormalization(doubles11, doubles22))); } /** @@ -241,6 +218,46 @@ public double getTrueDistance(double[] doubles1, double[] doubles2) { public double getTrueDistance(int[] ints1, int[] ints2) { double[] doubles11 = new DoubleCoordinateMany(ints1).diff(new DoubleCoordinateMany(ints2)).toArray(); double[] doubles22 = Z_ScoreNormalization.StandardizedSequence(doubles11); - return this.euclideanMetric.getTrueDistance(new DoubleCoordinateMany(DivideByNormalization(doubles11, doubles22))); + return super.getTrueDistance(new DoubleCoordinateMany(DivideByNormalization(doubles11, doubles22))); + } + + /** + * 霈∠銝支葵拚萄笆鞊∩渡頝蝳餃漲賣堆餈霂亙賣啣臭誑摰唬舅銝芰拚萄笆鞊∪漲蝟餅啁霈∠ + *

+ * Calculates the distance metric function between two matrix objects, through which the metric coefficients of two matrix objects can be calculated. + * + * @param integerMatrix1 閬鋡怨銵霈∠拚萄笆鞊∼ + *

+ * The matrix object that needs to be calculated. + * @param matrix2 閬鋡怨銵霈∠拚萄笆鞊∼ + *

+ * The matrix object that needs to be calculated. + * @return 霈∠箸亦摨阡蝏蝟餅啜 + *

+ * The calculated measurement result coefficient. + */ + @Override + public double getTrueDistance(IntegerMatrix integerMatrix1, IntegerMatrix matrix2) { + throw new UnsupportedOperationException("The matrix does not currently support serialization operations"); + } + + /** + * 霈∠銝支葵拚萄笆鞊∩渡頝蝳餃漲賣堆餈霂亙賣啣臭誑摰唬舅銝芰拚萄笆鞊∪漲蝟餅啁霈∠ + *

+ * Calculates the distance metric function between two matrix objects, through which the metric coefficients of two matrix objects can be calculated. + * + * @param matrix1 閬鋡怨銵霈∠拚萄笆鞊∼ + *

+ * The matrix object that needs to be calculated. + * @param matrix2 閬鋡怨銵霈∠拚萄笆鞊∼ + *

+ * The matrix object that needs to be calculated. + * @return 霈∠箸亦摨阡蝏蝟餅啜 + *

+ * The calculated measurement result coefficient. + */ + @Override + public double getTrueDistance(DoubleMatrix matrix1, DoubleMatrix matrix2) { + throw new UnsupportedOperationException("The matrix does not currently support serialization operations"); } } diff --git a/src_code/src/main/java/zhao/algorithmMagic/algorithm/modelAlgorithm/LinearRegression.java b/src_code/src/main/java/zhao/algorithmMagic/algorithm/modelAlgorithm/LinearRegression.java index 93ce0d8..6d20701 100644 --- a/src_code/src/main/java/zhao/algorithmMagic/algorithm/modelAlgorithm/LinearRegression.java +++ b/src_code/src/main/java/zhao/algorithmMagic/algorithm/modelAlgorithm/LinearRegression.java @@ -47,10 +47,20 @@ public static LinearRegression getInstance(String Name) { } } + /** + * 霈曄蔭芸蝻 + * + * @param featureIndex 芸蝻 + */ public void setFeatureIndex(int featureIndex) { this.featureIndex = featureIndex; } + /** + * 霈曄蔭蝻 + * + * @param targetIndex 蝻 + */ public void setTargetIndex(int targetIndex) { this.targetIndex = targetIndex; } diff --git a/src_code/src/main/java/zhao/algorithmMagic/algorithm/normalization/DataStandardization.java b/src_code/src/main/java/zhao/algorithmMagic/algorithm/normalization/DataStandardization.java index 382a107..611ca70 100644 --- a/src_code/src/main/java/zhao/algorithmMagic/algorithm/normalization/DataStandardization.java +++ b/src_code/src/main/java/zhao/algorithmMagic/algorithm/normalization/DataStandardization.java @@ -8,6 +8,8 @@ import zhao.algorithmMagic.operands.coordinate.FloatingPointCoordinates; import zhao.algorithmMagic.operands.coordinate.IntegerCoordinateMany; import zhao.algorithmMagic.operands.coordinate.IntegerCoordinates; +import zhao.algorithmMagic.operands.matrix.DoubleMatrix; +import zhao.algorithmMagic.operands.matrix.IntegerMatrix; import zhao.algorithmMagic.operands.vector.DoubleVector; import zhao.algorithmMagic.operands.vector.IntegerVector; @@ -93,6 +95,30 @@ public String getAlgorithmName() { */ public abstract IntegerVector pretreatment(IntegerVector integerVector); + /** + * 撠銝銝芸餈銵嚗瑚銝摰 + * + * @param doubleMatrix 閬鋡急啣潘臭誑臬嚗游靽⊥舫閬仿摰 + *

+ * The value to be normalized, which can be a coordinate or a vector. For more information, see the implementation + * @return v瑕 + *

+ * Normalized style of v + */ + public abstract DoubleMatrix pretreatment(DoubleMatrix doubleMatrix); + + /** + * 撠銝銝芸餈銵嚗瑚銝摰 + * + * @param integerMatrix 閬鋡急啣潘臭誑臬嚗游靽⊥舫閬仿摰 + *

+ * The value to be normalized, which can be a coordinate or a vector. For more information, see the implementation + * @return v瑕 + *

+ * Normalized style of v + */ + public abstract IntegerMatrix pretreatment(IntegerMatrix integerMatrix); + /** * 蝞瘜璅∪憪寞嚗刻典臭誑餈銵蝏隞嗥憪寞嚗敶憪銋嚗霂亦瘜撠勗臭誑憭鈭撠梁貌嗆嚗銝祈撠望臬芸楛瘛餃啁瘜蝞∠蝐颱葉 *

diff --git a/src_code/src/main/java/zhao/algorithmMagic/algorithm/normalization/LinearNormalization.java b/src_code/src/main/java/zhao/algorithmMagic/algorithm/normalization/LinearNormalization.java index 2b30f7a..53dbf72 100644 --- a/src_code/src/main/java/zhao/algorithmMagic/algorithm/normalization/LinearNormalization.java +++ b/src_code/src/main/java/zhao/algorithmMagic/algorithm/normalization/LinearNormalization.java @@ -7,6 +7,8 @@ import zhao.algorithmMagic.operands.coordinate.FloatingPointCoordinates; import zhao.algorithmMagic.operands.coordinate.IntegerCoordinateMany; import zhao.algorithmMagic.operands.coordinate.IntegerCoordinates; +import zhao.algorithmMagic.operands.matrix.DoubleMatrix; +import zhao.algorithmMagic.operands.matrix.IntegerMatrix; import zhao.algorithmMagic.operands.vector.DoubleVector; import zhao.algorithmMagic.operands.vector.FastRangeDoubleVector; import zhao.algorithmMagic.operands.vector.FastRangeIntegerVector; @@ -69,13 +71,13 @@ public static LinearNormalization getInstance(String Name) { * @param doubles 閬鋡急銝銝芸 * @return 蝏 */ - public static double[] normalization(double[] doubles, double min1, double max1) { + public static double[] pretreatment(double[] doubles, double min1, double max1) { // 霈∠憭批潭撠 double[] doubles1 = ASMath.MaxAndMin(doubles); double max = doubles1[0b0]; double min = doubles1[0b1]; // 撘憪撠摨 - return normalization(doubles, min, max, min1, max1); + return pretreatment(doubles, min, max, min1, max1); } /** @@ -88,7 +90,7 @@ public static double[] normalization(double[] doubles, double min1, double max1) * @param min1 敶銝銋瘥銝銝芸蝝霈貊憭批 * @return 敶銝銋啣啁撖寡情 */ - public static double[] normalization(double[] doubles, double min, double max, double min1, double max1) { + public static double[] pretreatment(double[] doubles, double min, double max, double min1, double max1) { double[] res = new double[doubles.length]; // 斗剜臬阡閬敶銝嚗銝閬撠勗瑁 if (max <= max1 && min >= min1) { @@ -114,12 +116,12 @@ public static double[] normalization(double[] doubles, double min, double max, d * @param ints 閬鋡急銝銝芸 * @return 蝏 */ - public static int[] normalization(int[] ints, int min1, int max1) { + public static int[] pretreatment(int[] ints, int min1, int max1) { int[] doubles1 = ASMath.MaxAndMin(ints); int max = doubles1[0b0]; int min = doubles1[0b1]; // 撘憪撠摨 - return normalization(ints, min, max, min1, max1); + return pretreatment(ints, min, max, min1, max1); } /** @@ -132,7 +134,7 @@ public static int[] normalization(int[] ints, int min1, int max1) { * @param min1 敶銝銋瘥銝銝芸蝝霈貊憭批 * @return 敶銝銋啣撖寡情啁 */ - public static int[] normalization(int[] ints, int min, int max, int min1, int max1) { + public static int[] pretreatment(int[] ints, int min, int max, int min1, int max1) { int[] res = new int[ints.length]; // 斗剜臬阡閬敶銝嚗銝閬撠勗瑁 if (max <= max1 && min >= min1) { @@ -148,6 +150,100 @@ public static int[] normalization(int[] ints, int min, int max, int min1, int ma return res; } + /** + * 撠銝銝芸蝏游嚗畾萄停臬v銝剔瘥銝銝芣啣潸銵餈蝞嚗Xn = 嚗Xn - min(x)嚗/ max(x) - min(x) + *

+ * To normalize a multidimensional sequence, the normalization method is to operate on each value in the sequence v: x = (x - min(x)) max(x) - min(x) + * + * @param max1 敶銝銋瘥銝銝芸蝝霈貊撠 + * @param min1 敶銝銋瘥銝銝芸蝝霈貊憭批 + * @param ints 閬鋡急銝銝芸 + * @return 蝏 + */ + public static int[][] pretreatment(int[][] ints, int min1, int max1) { + int[] doubles1 = ASMath.MaxAndMin(ints); + int max = doubles1[0b0]; + int min = doubles1[0b1]; + // 撘憪撠摨 + return pretreatment(ints, min, max, min1, max1); + } + + /** + * 撠銝銝芸蝏游敶銝嚗刻砲賣唬葉臭誑摰敶銝銋蝏粹湔啣 + * + * @param ints 閬鋡怠銝摨 + * @param min 摨銝剔憭批 + * @param max 摨銝剔撠 + * @param max1 敶銝銋瘥銝銝芸蝝霈貊撠 + * @param min1 敶銝銋瘥銝銝芸蝝霈貊憭批 + * @return 敶銝銋啣撖寡情啁 + */ + public static int[][] pretreatment(int[][] ints, int min, int max, int min1, int max1) { + int[][] res1 = new int[ints.length][ints[0].length]; + // 斗剜臬阡閬敶銝嚗銝閬撠勗瑁 + if (max <= max1 && min >= min1) { + return ASClass.array2DCopy(ints, res1); + } + // 憒閬撠勗憪敶銝 + int MAX_MIN = max - min; + int MAX_MIN1 = max1 - min1; + int y = -1; + for (int[] res : ints) { + int[] ints1 = res1[++y]; + for (int i = 0; i < res.length; i++) { + ints1[i] = (int) (((res[i] - min) / (double) MAX_MIN) * MAX_MIN1 + min1); + } + } + return res1; + } + + + /** + * 撠銝銝芸蝏游嚗畾萄停臬v銝剔瘥銝銝芣啣潸銵餈蝞嚗Xn = 嚗Xn - min(x)嚗/ max(x) - min(x) + *

+ * To normalize a multidimensional sequence, the normalization method is to operate on each value in the sequence v: x = (x - min(x)) max(x) - min(x) + * + * @param max1 敶銝銋瘥銝銝芸蝝霈貊撠 + * @param min1 敶銝銋瘥銝銝芸蝝霈貊憭批 + * @param doubles 閬鋡急銝銝芸 + * @return 蝏 + */ + public static double[][] pretreatment(double[][] doubles, double min1, double max1) { + // 霈∠憭批潭撠 + double[] doubles1 = ASMath.MaxAndMin(doubles); + // 撘憪撠摨 + return pretreatment(doubles, doubles1[0b1], doubles1[0b0], min1, max1); + } + + /** + * 撠銝銝芸蝏游敶銝嚗刻砲賣唬葉臭誑摰敶銝銋蝏粹湔啣 + * + * @param ints 閬鋡怠銝摨 + * @param min 摨銝剔憭批 + * @param max 摨銝剔撠 + * @param max1 敶銝銋瘥銝銝芸蝝霈貊撠 + * @param min1 敶銝銋瘥銝銝芸蝝霈貊憭批 + * @return 敶銝銋啣撖寡情啁 + */ + public static double[][] pretreatment(double[][] ints, double min, double max, double min1, double max1) { + double[][] res1 = new double[ints.length][ints[0].length]; + // 斗剜臬阡閬敶銝嚗銝閬撠勗瑁 + if (max <= max1 && min >= min1) { + return ASClass.array2DCopy(ints, res1); + } + // 憒閬撠勗憪敶銝 + double MAX_MIN = max - min; + double MAX_MIN1 = max1 - min1; + int y = -1; + for (double[] res : ints) { + double[] doubles = res1[++y]; + for (int i = 0; i < res.length; i++) { + doubles[i] = ((res[i] - min) / MAX_MIN) * MAX_MIN1 + min1; + } + } + return res1; + } + /** * 霈曄蔭敶銝銋摨憭批 * @@ -182,7 +278,7 @@ public LinearNormalization setMin(double min) { */ @Override public FloatingPointCoordinates pretreatment(DoubleCoordinateMany v) { - return new DoubleCoordinateMany(normalization(v.toArray(), min, max)); + return new DoubleCoordinateMany(pretreatment(v.toArray(), min, max)); } /** @@ -197,7 +293,7 @@ public FloatingPointCoordinates pretreatment(DoubleCoordin */ @Override public IntegerCoordinates pretreatment(IntegerCoordinateMany v) { - return new IntegerCoordinateMany(normalization(v.toArray(), (int) min, (int) max)); + return new IntegerCoordinateMany(pretreatment(v.toArray(), (int) min, (int) max)); } /** @@ -210,7 +306,7 @@ public IntegerCoordinates pretreatment(IntegerCoordinateM */ @Override public DoubleVector pretreatment(DoubleVector doubleVector) { - return new DoubleVector(normalization(doubleVector.toArray(), min, max)); + return new DoubleVector(pretreatment(doubleVector.toArray(), min, max)); } /** @@ -223,7 +319,37 @@ public DoubleVector pretreatment(DoubleVector doubleVector) { */ @Override public IntegerVector pretreatment(IntegerVector integerVector) { - return new IntegerVector(normalization(integerVector.toArray(), (int) min, (int) max)); + return new IntegerVector(pretreatment(integerVector.toArray(), (int) min, (int) max)); + } + + /** + * 撠銝銝芸餈銵嚗瑚銝摰 + * + * @param doubleMatrix 閬鋡急啣潘臭誑臬嚗游靽⊥舫閬仿摰 + *

+ * The value to be normalized, which can be a coordinate or a vector. For more information, see the implementation + * @return v瑕 + *

+ * Normalized style of v + */ + @Override + public DoubleMatrix pretreatment(DoubleMatrix doubleMatrix) { + return DoubleMatrix.parse(pretreatment(doubleMatrix.toArrays(), min, max)); + } + + /** + * 撠銝銝芸餈銵嚗瑚銝摰 + * + * @param integerMatrix 閬鋡急啣潘臭誑臬嚗游靽⊥舫閬仿摰 + *

+ * The value to be normalized, which can be a coordinate or a vector. For more information, see the implementation + * @return v瑕 + *

+ * Normalized style of v + */ + @Override + public IntegerMatrix pretreatment(IntegerMatrix integerMatrix) { + return IntegerMatrix.parse(pretreatment(integerMatrix.toArrays(), (int) min, (int) max)); } /** diff --git a/src_code/src/main/java/zhao/algorithmMagic/algorithm/normalization/Z_ScoreNormalization.java b/src_code/src/main/java/zhao/algorithmMagic/algorithm/normalization/Z_ScoreNormalization.java index 9675972..1a8f4d3 100644 --- a/src_code/src/main/java/zhao/algorithmMagic/algorithm/normalization/Z_ScoreNormalization.java +++ b/src_code/src/main/java/zhao/algorithmMagic/algorithm/normalization/Z_ScoreNormalization.java @@ -8,6 +8,8 @@ import zhao.algorithmMagic.operands.coordinate.FloatingPointCoordinates; import zhao.algorithmMagic.operands.coordinate.IntegerCoordinateMany; import zhao.algorithmMagic.operands.coordinate.IntegerCoordinates; +import zhao.algorithmMagic.operands.matrix.DoubleMatrix; +import zhao.algorithmMagic.operands.matrix.IntegerMatrix; import zhao.algorithmMagic.operands.vector.DoubleVector; import zhao.algorithmMagic.operands.vector.FastRangeDoubleVector; import zhao.algorithmMagic.operands.vector.FastRangeIntegerVector; @@ -171,6 +173,36 @@ public IntegerVector pretreatment(IntegerVector integerVector) { return new IntegerVector(StandardizedSequence(integerVector.toArray())); } + /** + * 撠銝銝芸餈銵嚗瑚銝摰 + * + * @param doubleMatrix 閬鋡急啣潘臭誑臬嚗游靽⊥舫閬仿摰 + *

+ * The value to be normalized, which can be a coordinate or a vector. For more information, see the implementation + * @return v瑕 + *

+ * Normalized style of v + */ + @Override + public DoubleMatrix pretreatment(DoubleMatrix doubleMatrix) { + throw new UnsupportedOperationException("The matrix currently does not support standardization operations."); + } + + /** + * 撠銝銝芸餈銵嚗瑚銝摰 + * + * @param integerMatrix 閬鋡急啣潘臭誑臬嚗游靽⊥舫閬仿摰 + *

+ * The value to be normalized, which can be a coordinate or a vector. For more information, see the implementation + * @return v瑕 + *

+ * Normalized style of v + */ + @Override + public IntegerMatrix pretreatment(IntegerMatrix integerMatrix) { + throw new UnsupportedOperationException("The matrix currently does not support standardization operations."); + } + /** * 撠銝銝芸餈銵嚗瑚銝摰 * diff --git a/src_code/src/main/java/zhao/algorithmMagic/core/AlgorithmStar.java b/src_code/src/main/java/zhao/algorithmMagic/core/AlgorithmStar.java index c047db6..583cd19 100644 --- a/src_code/src/main/java/zhao/algorithmMagic/core/AlgorithmStar.java +++ b/src_code/src/main/java/zhao/algorithmMagic/core/AlgorithmStar.java @@ -13,22 +13,26 @@ import zhao.algorithmMagic.algorithm.normalization.RangeDataStandardization; import zhao.algorithmMagic.algorithm.probabilisticAlgorithm.ProbabilisticAlgorithm; import zhao.algorithmMagic.algorithm.schemeAlgorithm.SchemeAlgorithm; +import zhao.algorithmMagic.io.InputComponent; import zhao.algorithmMagic.operands.coordinate.DoubleCoordinateMany; import zhao.algorithmMagic.operands.coordinate.FloatingPointCoordinates; import zhao.algorithmMagic.operands.coordinate.IntegerCoordinateMany; import zhao.algorithmMagic.operands.coordinate.IntegerCoordinates; -import zhao.algorithmMagic.operands.matrix.ColumnDoubleMatrix; -import zhao.algorithmMagic.operands.matrix.ColumnIntegerMatrix; -import zhao.algorithmMagic.operands.matrix.DoubleMatrix; -import zhao.algorithmMagic.operands.matrix.IntegerMatrix; +import zhao.algorithmMagic.operands.matrix.*; import zhao.algorithmMagic.operands.route.DoubleConsanguinityRoute; import zhao.algorithmMagic.operands.route.DoubleConsanguinityRoute2D; import zhao.algorithmMagic.operands.route.IntegerConsanguinityRoute; import zhao.algorithmMagic.operands.route.IntegerConsanguinityRoute2D; +import zhao.algorithmMagic.operands.table.DataFrame; +import zhao.algorithmMagic.operands.table.DataFrameBuilder; +import zhao.algorithmMagic.operands.table.FDataFrame; import zhao.algorithmMagic.operands.vector.*; import zhao.algorithmMagic.utils.filter.ArrayDoubleFiltering; import zhao.algorithmMagic.utils.filter.ArrayIntegerFiltering; +import java.io.File; +import java.net.URL; +import java.sql.Connection; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; @@ -90,6 +94,132 @@ public static void clear() { ******************************************************************** */ + /** + * 銝銝芰拚蛛拚萇圈隞亦拚萇蝚砌銵銝箏嚗 + *

+ * Construct a matrix, the number of columns of the matrix is based on the first row of the matrix! + * + * @param v 其拚萇鈭蝏湔啁 + *

+ * 2D array for constructing the matrix + * @return matrix object + */ + public static IntegerMatrix parseIntMat(int[]... v) { + return IntegerMatrix.parse(v); + } + + /** + * 銝銝芰拚蛛拚萇圈隞亦拚萇蝚砌銵銝箏嚗 + *

+ * Construct a matrix, the number of columns of the matrix is based on the first row of the matrix! + * + * @param v 其拚萇鈭蝏湔啁 + *

+ * 2D array for constructing the matrix + * @return matrix object + */ + public static DoubleMatrix parseDoubleMat(double[]... v) { + return DoubleMatrix.parse(v); + } + + /** + * 隞砍唳隞嗥頂蝏銝剛粉銝銝芣唳桀笆鞊∴撟嗉撖孵唳桀笆鞊∠撱粹蝐颯 + * + * @param file 閬鋡怨粉隞嗅笆鞊∼ + * @return 霂餃銋隡餈霂交唳桅撖孵銝銝芸遣撖寡情嚗刻砲撖寡情銝剖臭誑撖寡粉雿餈銵游霂衣霈曄蔭嚗 + */ + public static DataFrameBuilder parseDF(File file) { + return FDataFrame.builder(file); + } + + /** + * 隞餈蝔唳桀銝剛粉銝銝芣唳桀笆鞊∴撟嗉唳桀笆鞊∪笆摨撱粹蝐颯 + * + * @param DBC 刻交唳桀園閬雿輻函唳桀餈亙笆鞊∼ + * @return 唳桀餈亥挽蝵桀瘥撠隡餈銝銝芸遣撖寡情嚗刻砲撖寡情銝剖臭誑撖寡粉唳桀雿餈銵游霂衣霈曄蔭 + */ + public static DataFrameBuilder parseDF(Connection DBC) { + return FDataFrame.builder(DBC); + } + + /** + * 雿輻函洵銝寞唳格颲亦隞嗉銵唳桃頧踝撟嗉瑕啣笆摨DataFrame撖寡情 + * + * @param inputComponent 閬雿輻函蝚砌寞唳株亦隞嗅笆鞊 + * @param isOC 憒霈曄蔭銝 true 隞銵冽唳株亥挽憭撖寡情撘銝喲凋漱望嗥恣嚗典撠銝閬撖寧隞嗉銵撘喲剜雿嚗銋隞銵冽嗅芯蝙函隞塚雿銝隡撘銝喲剔隞嗅笆鞊∼ + *

+ * If set to true, it means that the opening and closing of data input device objects are managed by the framework, and there will be no need to open or close components externally. Conversely, it means that the framework only uses components, but will not open or close component objects. + * @return 瑕啁DataFrame撖寡情 + */ + public static DataFrame parseDF(InputComponent inputComponent, boolean isOC) { + return FDataFrame.builder(inputComponent, isOC); + } + + /** + * 雿輻函隞嗅銝銝芸曉唳格嚗撟嗉瑕撖孵曉拚萸 + * + * @param inputComponent 賢鋡急箏曉拚萇唳桃隞嗚 + * @param isOC 憒霈曄蔭銝 true 隞銵冽唳株亥挽憭撖寡情撘銝喲凋漱望嗥恣嚗典撠銝閬撖寧隞嗉銵撘喲剜雿嚗銋隞銵冽嗅芯蝙函隞塚雿銝隡撘銝喲剔隞嗅笆鞊∼ + *

+ * If set to true, it means that the opening and closing of data input device objects are managed by the framework, and there will be no need to open or close components externally. Conversely, it means that the framework only uses components, but will not open or close component objects. + * @return 隞蝏隞嗡葉箸亦曉拚萄笆鞊∼ + */ + public static ColorMatrix parseImage(InputComponent inputComponent, boolean isOC) { + return ColorMatrix.parse(inputComponent, isOC); + } + + /** + * 撠曉URL閫嚗撟嗉瑕撖孵曉拚 + * + * @param url 閬鋡怨圾URL撖寡情 + * @return URL撖寡情撖孵曉拚萸 + */ + public static ColorMatrix parseImage(URL url) { + return ColorMatrix.parse(url); + } + + /** + * 撠曉URL閫嚗撟嗉瑕撖孵曉拚 + * + * @param url 閬鋡怨圾URL撖寡情 + * @return URL撖寡情撖孵曉拚萸 + */ + public static ColorMatrix parseGrayscaleImage(URL url) { + return ColorMatrix.parseGrayscale(url); + } + + /** + * 寞桀曉隞嗉瑕唳游耦拚萄笆鞊∴冽游耦拚萄笆鞊∩葉隡怨砲曉瘥銝銝芸蝝孵笆摨啣漲游耦啣潦 + *

+ * The reshaping matrix object is obtained from the image file, and the reshaping value corresponding to each pixel of the image will be included in the reshaping matrix object. + * + * @param imagePath 閬霂餃格曉隞嗉楝敺 + *

+ * The target image file path to read. + * @return 寞桀曉瑕啁拚萄笆鞊∼ + *

+ * The matrix object obtained from the image. + */ + public static ColorMatrix parseImage(String imagePath) { + return ColorMatrix.parse(imagePath); + } + + /** + * 寞桀曉隞嗉瑕唳游耦拚萄笆鞊∴冽游耦拚萄笆鞊∩葉隡怨砲曉瘥銝銝芸蝝孵笆摨啣漲游耦啣潦 + *

+ * The reshaping matrix object is obtained from the image file, and the reshaping value corresponding to each pixel of the image will be included in the reshaping matrix object. + * + * @param imagePath 閬霂餃格曉隞嗉楝敺 + *

+ * The target image file path to read. + * @return 寞桀曉瑕啁拚萄笆鞊∼ + *

+ * The matrix object obtained from the image. + */ + public static ColorMatrix parseGrayscaleImage(String imagePath) { + return ColorMatrix.parseGrayscale(imagePath); + } + /** * 霈∠銝銝芾楝蝥輻韏瑕嫣蝏甇Y寧摰頝蝳颯瑚頝蝳餃堆閬冽仿蝞瘜摰啁獢 *

@@ -139,6 +269,13 @@ public double getTrueDistance(DistanceAlgorithm distanceAlgorithm, int[] ints1, return distanceAlgorithm.getTrueDistance(ints1, ints2); } + /* + ******************************************************************** + * 蝞瘜蝏隞嗉恣蝞賣啣憪蝥 + * Aggregation algorithm component calculation function start boundary + ******************************************************************** + */ + /** * 霈∠銝銝芾楝蝥輻韏瑕嫣蝏甇Y寧摰頝蝳颯瑚頝蝳餃堆閬冽仿蝞瘜摰啁獢 *

@@ -190,6 +327,58 @@ public double getTrueDistance(DistanceAlgorithm distanceAlgorithm, IntegerConsan return distanceAlgorithm.getTrueDistance(integerConsanguinityRoute2D); } + /** + * 霈∠銝支葵拚萄笆鞊∩渡頝蝳餃漲賣堆餈霂亙賣啣臭誑摰唬舅銝芰拚萄笆鞊∪漲蝟餅啁霈∠ + *

+ * Calculates the distance metric function between two matrix objects, through which the metric coefficients of two matrix objects can be calculated. + * + * @param distanceAlgorithm 頝蝳餉恣蝞蝏隞塚舀典刻冽祆活賣唬嚗賣啁冽亥恣蝞頝蝳餉恣蝞蝏隞嗅笆鞊∼ + *

+ * The distance calculation component is the distance calculation component object that the function uses to calculate after you call this function. + * @param matrix1 閬鋡怨銵霈∠拚萄笆鞊∼ + *

+ * The matrix object that needs to be calculated. + * @param matrix2 閬鋡怨銵霈∠拚萄笆鞊∼ + *

+ * The matrix object that needs to be calculated. + * @return 霈∠箸亦摨阡蝏蝟餅啜 + *

+ * The calculated measurement result coefficient. + */ + public double getTrueDistance(DistanceAlgorithm distanceAlgorithm, IntegerMatrix matrix1, IntegerMatrix matrix2) { + return distanceAlgorithm.getTrueDistance(matrix1, matrix2); + } + + /** + * 霈∠銝支葵拚萄笆鞊∩渡頝蝳餃漲賣堆餈霂亙賣啣臭誑摰唬舅銝芰拚萄笆鞊∪漲蝟餅啁霈∠ + *

+ * Calculates the distance metric function between two matrix objects, through which the metric coefficients of two matrix objects can be calculated. + * + * @param distanceAlgorithm 頝蝳餉恣蝞蝏隞塚舀典刻冽祆活賣唬嚗賣啁冽亥恣蝞頝蝳餉恣蝞蝏隞嗅笆鞊∼ + *

+ * The distance calculation component is the distance calculation component object that the function uses to calculate after you call this function. + * @param matrix1 閬鋡怨銵霈∠拚萄笆鞊∼ + *

+ * The matrix object that needs to be calculated. + * @param matrix2 閬鋡怨銵霈∠拚萄笆鞊∼ + *

+ * The matrix object that needs to be calculated. + * @return 霈∠箸亦摨阡蝏蝟餅啜 + *

+ * The calculated measurement result coefficient. + */ + public double getTrueDistance(DistanceAlgorithm distanceAlgorithm, DoubleMatrix matrix1, DoubleMatrix matrix2) { + return distanceAlgorithm.getTrueDistance(matrix1, matrix2); + } + + + /* + ******************************************************************** + * 蝐餌瘜蝏隞嗉恣蝞賣啣憪蝥 + * Classification algorithm component calculation function start boundary + ******************************************************************** + */ + /** * 霈∠頝蝳餃寧頝蝳颯 * @@ -203,13 +392,6 @@ public double getTrueDistance(RangeDistance rangeDistance, RangeVector @@ -227,7 +409,6 @@ public double calculation(AggregationAlgorithm aggregationAlgorithm, double... d return aggregationAlgorithm.calculation(doubles); } - /** * 霈∠賣堆撠銝芣啁銝剔蝝扳銝芾餈銵 *

@@ -306,14 +487,6 @@ public double calculation(RangeAggregation rangeAggregation, RangeVector @@ -400,6 +573,13 @@ public HashMap> classification(NoSampleClassific return noSampleClassification.classification(keys, doubles); } + /* + ******************************************************************** + * 撌桀蝞瘜蝏隞嗉恣蝞賣啣憪蝥 * + * diff algorithm component calculation function start boundary * + ******************************************************************** + */ + /** * 瑟祉頝蝳餉恣蝞嚗典冽迨餈銵蝐鳴銝閬隡敺憭唳格瑟穿芷閬勗啁掩扯芸楛蝞瘜餈銵蝐餃急冽剖喳胯 *

@@ -422,6 +602,13 @@ public HashMap> classification(NoSampleCl return noSampleClassification.classification(keys, columnIntegerMatrix); } + /* + ******************************************************************** + * 孵蝞瘜蝏隞嗉恣蝞賣啣憪蝥 * + * FeatureExtraction algorithm component calculation function start boundary * + ******************************************************************** + */ + /** * 瑟祉頝蝳餉恣蝞嚗典冽迨餈銵蝐鳴銝閬隡敺憭唳格瑟穿芷閬勗啁掩扯芸楛蝞瘜餈銵蝐餃急冽剖喳胯 *

@@ -444,6 +631,12 @@ public HashMap> classification(NoSampleCla return noSampleClassification.classification(keys, columnDoubleMatrix); } + /* + ******************************************************************** + * 唳桅憭蝞瘜蝏隞嗉恣蝞賣啣憪蝥 * + * Data preprocessing algorithm component calculation function start boundary * + ******************************************************************** + */ /** * 霈∠銝銝芰拚萎葉銵唳桃掩恬撟嗅霈∠銋唳桃掩急瑟祈箏颯 @@ -549,14 +742,6 @@ public HashMap> classification(SampleClassifica return sampleClassification.classification(data, categorySample); } - /* - ******************************************************************** - * 撌桀蝞瘜蝏隞嗉恣蝞賣啣憪蝥 * - * diff algorithm component calculation function start boundary * - ******************************************************************** - */ - - /** * 霈∠銝支葵鈭拐港撌桀蝟餅啁曉瘥 *

@@ -571,13 +756,6 @@ public double getDifferenceRatio(DifferenceAlgorithm differenceAlgori return differenceAlgorithm.getDifferenceRatio(value1, value2); } - /* - ******************************************************************** - * 孵蝞瘜蝏隞嗉恣蝞賣啣憪蝥 * - * FeatureExtraction algorithm component calculation function start boundary * - ******************************************************************** - */ - /** * 撠敺憭摮蝚虫葡蝏韏瑟亥銵孵嚗嗡葉瘥銝銝芾賣臭銝芰孵潦 *

@@ -591,13 +769,6 @@ public featureReturn extract(StringArrayFeature stringArrayFeatur return stringArrayFeature.extract(data); } - /* - ******************************************************************** - * 唳桅憭蝞瘜蝏隞嗉恣蝞賣啣憪蝥 * - * Data preprocessing algorithm component calculation function start boundary * - ******************************************************************** - */ - /** * 撠銝銝芸餈銵嚗瑚銝摰 * @@ -628,6 +799,43 @@ public IntegerCoordinates pretreatment(DataStandardizatio return dataStandardization.pretreatment(v); } + /* + ******************************************************************** + * 璁蝞瘜蝏隞嗉恣蝞賣啣憪蝥 + * Probability algorithm component calculation function start boundary + ******************************************************************** + */ + + /** + * 撠銝銝芸餈銵嚗瑚銝摰 + * + * @param dataStandardization 閬雿輻函唳桅憭蝞瘜蝏隞嗅笆鞊∼ + * @param integerMatrix 閬鋡急啣潘臭誑臬嚗游靽⊥舫閬仿摰 + *

+ * The value to be normalized, which can be a coordinate or a vector. For more information, see the implementation + * @return v瑕 + *

+ * Normalized style of v + */ + public IntegerMatrix pretreatment(DataStandardization dataStandardization, IntegerMatrix integerMatrix) { + return dataStandardization.pretreatment(integerMatrix); + } + + /** + * 撠銝銝芸餈銵嚗瑚銝摰 + * + * @param dataStandardization 閬雿輻函唳桅憭蝞瘜蝏隞嗅笆鞊∼ + * @param doubleMatrix 閬鋡急啣潘臭誑臬嚗游靽⊥舫閬仿摰 + *

+ * The value to be normalized, which can be a coordinate or a vector. For more information, see the implementation + * @return v瑕 + *

+ * Normalized style of v + */ + public DoubleMatrix pretreatment(DataStandardization dataStandardization, DoubleMatrix doubleMatrix) { + return dataStandardization.pretreatment(doubleMatrix); + } + /** * 撠銝銝芸餈銵嚗瑚銝摰 * @@ -692,13 +900,6 @@ public DoubleVector pretreatment(RangeDataStandardization rangeDataStandardizati return rangeDataStandardization.pretreatment(fastRangeDoubleVector); } - /* - ******************************************************************** - * 璁蝞瘜蝏隞嗉恣蝞賣啣憪蝥 - * Probability algorithm component calculation function start boundary - ******************************************************************** - */ - /** * 霈∠銝銝芰拚萎葉鈭∩辣嗡璁蝏 P(A|B) 嗡葉摮銝瘥潘 * @@ -833,7 +1034,6 @@ public ArrayList decision(SchemeAlgorithm schemeAlgorithm, return decision(schemeAlgorithm, doubleMatrix.toArrays(), 2, arrayDoubleFiltering); } - /** * 餈喟嚗撖嫣餈餈亦喟摨唳嚗雿踹嗆銝箸隡閫 *

@@ -878,7 +1078,6 @@ public ArrayList decision(SchemeAlgorithm schemeAlgorithm, return decision(schemeAlgorithm, ints, 2, arrayDoubleFiltering); } - /** * 餈喟嚗撖嫣餈餈亦喟摨唳嚗雿踹嗆銝箸隡閫 *

diff --git a/src_code/src/main/java/zhao/algorithmMagic/integrator/ImageRenderingIntegrator.java b/src_code/src/main/java/zhao/algorithmMagic/integrator/ImageRenderingIntegrator.java index 8559a2f..9f406f8 100644 --- a/src_code/src/main/java/zhao/algorithmMagic/integrator/ImageRenderingIntegrator.java +++ b/src_code/src/main/java/zhao/algorithmMagic/integrator/ImageRenderingIntegrator.java @@ -93,6 +93,20 @@ public static boolean draw(String outFilePath, int[][] ints, int imageWidth, int * @return 憒餈true 隞銵函嗆嚗 */ public static boolean draw(String outFilePath, Color[][] colors, int imageWidth, int imageHeight, int pixelMagnification, boolean writeNumber) { + BufferedImage image = drawBufferedImage(colors, imageWidth, imageHeight, pixelMagnification, writeNumber); + // 颲箏曄 + return ASIO.outImage(image, outFilePath); + } + + /** + * @param colors 閬鋡怎冽乩銝箏曉颲箇蝝拚萄笆鞊 + * @param imageWidth 閬蝏嗅曉摰賢漲 + * @param imageHeight 閬蝏嗅曉擃摨 + * @param pixelMagnification 拚萎葉銝銝芸蝝隞銵函蝝嚗銋臭銝芸蝝憭批 + * @param writeNumber 憒霈曄蔭銝演rue嚗隞銵刻箏曄嗅撠憸脩瑟銝 + * @return 憒餈true 隞銵函嗆嚗 + */ + public static BufferedImage drawBufferedImage(Color[][] colors, int imageWidth, int imageHeight, int pixelMagnification, boolean writeNumber) { // 撱箔銝芸曄 int width = imageWidth * pixelMagnification; int height = imageHeight * pixelMagnification; @@ -125,8 +139,7 @@ public static boolean draw(String outFilePath, Color[][] colors, int imageWidth, x1 = 0; } } - // 颲箏曄 - return ASIO.outImage(image, outFilePath); + return image; } @Override diff --git a/src_code/src/main/java/zhao/algorithmMagic/io/InputBuilder.java b/src_code/src/main/java/zhao/algorithmMagic/io/InputBuilder.java new file mode 100644 index 0000000..9ce8784 --- /dev/null +++ b/src_code/src/main/java/zhao/algorithmMagic/io/InputBuilder.java @@ -0,0 +1,39 @@ +package zhao.algorithmMagic.io; + +import zhao.algorithmMagic.operands.table.FinalCell; + +/** + * 唳株亦隞嗥剁嗆祈澈雿銝箸唳株亥挽憭撖寡情撱粹撖寡情 + *

+ * The data input component generator itself serves as the creator object for all data input device objects. + * + * @author 韏萄摰 + * 2023/4/5 13:54 + */ +public interface InputBuilder { + + /** + * 瘛餃唳株交餈堆銝蝏隞嗆銝蝵桀改瑚臭誑摰啁掩 + *

+ * Add data input descriptions, and different components have different configuration properties. Please refer to the implementation class for details. + * + * @param key 撅批蝘 + *

+ * Attribute Name. + * @param value 撅扳啣 + *

+ * Attribute Value. + * @return 曉靚剁蝏抒賒撱 + *

+ * Chain call, continue building. + */ + InputBuilder addInputArg(String key, FinalCell value); + + /** + * 撠撖寡情撱箏箸亙僎瑕啣笆摨颲亥挽憭撖寡情 + * + * @return 颲亥挽憭撖寡情 + */ + InputComponent create(); + +} diff --git a/src_code/src/main/java/zhao/algorithmMagic/io/InputByStream.java b/src_code/src/main/java/zhao/algorithmMagic/io/InputByStream.java new file mode 100644 index 0000000..d36c9ec --- /dev/null +++ b/src_code/src/main/java/zhao/algorithmMagic/io/InputByStream.java @@ -0,0 +1,220 @@ +package zhao.algorithmMagic.io; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import zhao.algorithmMagic.exception.OperatorOperationException; +import zhao.algorithmMagic.operands.table.*; +import zhao.algorithmMagic.utils.ASIO; +import zhao.algorithmMagic.utils.ASStr; + +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.Charset; +import java.util.Scanner; + +/** + * 隞銝銝芣唳株交銝剛瑕唳桃摰啁掩嚗霂亦掩銝剖鋆鈭銝蝟餃餈唳株交瑕唳唳桃雿 + *

+ * An implementation class that obtains data from a data input stream, encapsulating a series of operations to obtain data through the data input stream. + * + * @author zhao + */ +public class InputByStream implements InputComponent { + + private final static Logger LOGGER = LoggerFactory.getLogger("InputByStream"); + private final InputStream inputStream; + private final Scanner scanner; + private final Charset charSet; + private final int rowLength; + private final int pk; + private final char sep; + + /** + * @param inputStream 閬鋡怨粉唳株交撖寡情 + * @param charSet 唳株亙蝚佗蝏唳桅閬雿輻冽迨 + * @param rowLength 唳株亥堆蝏唳桅閬雿輻冽迨 + * @param pk 唳桐蜓殷DF唳株仿閬雿輻冽迨 + * @param sep 唳株亙蝚佗蝏唳株仿閬甇文 + */ + public InputByStream(Cell inputStream, Cell charSet, int rowLength, int pk, char sep) { + if (inputStream == null || charSet == null) { + throw new OperatorOperationException("The parameter in [Cell inputStream, Cell charSet] cannot be null!!!!"); + } + this.inputStream = inputStream.getValue(); + scanner = new Scanner(this.inputStream); + this.charSet = Charset.forName(charSet.toString()); + this.rowLength = rowLength; + this.pk = pk; + this.sep = sep; + } + + public static InputBuilder builder() { + return new InputByStreamBuilder(); + } + + /** + * 臬冽唳株亦隞 + * + * @return 憒臬冽餈true + */ + @Override + public boolean open() { + LOGGER.info("open()"); + LOGGER.info("The data input stream component is ready!!!!"); + return isOpen(); + } + + /** + * @return 憒蝏隞嗅歇蝏臬其嚗刻餈true + *

+ * If the component has already started, return true here. + */ + @Override + public boolean isOpen() { + LOGGER.info("isOpen()"); + return true; + } + + /** + * 隞唳株亦隞嗡葉 byte 啁唳殷銝祆萎嚗餈餈賣臭鈭鈭餈嗥唳柴 + *

+ * Extract the data of the byte array from the data input component. Generally, the returned data here is some binary data. + * + * @return byte[] 唳桀笆鞊 + */ + @Override + public byte[] getByteArray() { + LOGGER.info("getByteArray()"); + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + try { + while (scanner.hasNext()) { + byteArrayOutputStream.write(scanner.nextLine().getBytes(charSet)); + } + return byteArrayOutputStream.toByteArray(); + } catch (IOException e) { + throw new OperatorOperationException(e); + } finally { + ASIO.close(byteArrayOutputStream); + } + } + + /** + * 隞唳株亦隞嗡葉 int 拚菜唳殷銝祆萎嚗餈餈臭鈭拚萄蝝唳柴 + *

+ * From the data input component, int matrix data is increasingly generated. Generally, some matrix element data is returned here. + * + * @return int[][] + */ + @Override + public int[][] getInt2Array() { + LOGGER.info("getInt2Array()"); + int[][] res = new int[this.rowLength][]; + int index = -1; + while (++index < this.rowLength) { + String[] strings = ASStr.splitByChar(scanner.nextLine(), sep); + int[] row = new int[strings.length]; + int index_2 = -1; + for (String string : strings) { + row[++index_2] = Integer.parseInt(string); + } + res[index] = row; + } + return res; + } + + /** + * 隞唳株亦隞嗡葉 int 拚菜唳殷銝祆萎嚗餈餈臭鈭拚萄蝝唳柴 + *

+ * From the data input component, double matrix data is increasingly generated. Generally, some matrix element data is returned here. + * + * @return double[][] + */ + @Override + public double[][] getDouble2Array() { + LOGGER.info("getDouble2Array()"); + double[][] res = new double[this.rowLength][]; + int index = -1; + while (++index < this.rowLength) { + String[] strings = ASStr.splitByChar(scanner.nextLine(), sep); + double[] row = new double[strings.length]; + int index_2 = -1; + for (String string : strings) { + row[++index_2] = Double.parseDouble(string); + } + res[index] = row; + } + return res; + } + + /** + * 隞唳株亦隞嗉瑕 DataFrame 撖寡情嚗霂亙賣唳鈭唳株亦隞嗅航賭舀 + *

+ * Retrieve the DataFrame object from the data input component, which may not be supported by some data input components. + * + * @return 隞唳株亦隞嗡葉瑕啁DataFrame唳桀鋆撖寡情 + *

+ * The DataFrame data encapsulation object obtained from the data input component. + */ + @Override + public DataFrame getDataFrame() { + LOGGER.info("getDataFrame()"); + DataFrame select = FDataFrame.select( + FieldCell.parse(ASStr.splitByChar(scanner.nextLine(), sep)), pk + ); + int index = -1; + while (++index < this.rowLength) { + select.insert(FinalSeries.parse(ASStr.splitByChar(scanner.nextLine(), sep))); + } + return select; + } + + /** + * 隞唳株亦隞嗡葉 唳格 撖寡情 + *

+ * Extract the data flow object from the data input component. + * + * @return 唳株交撖寡情 + */ + @Override + public InputStream getInputStream() { + LOGGER.info("getInputStream()"); + return inputStream; + } + + /** + * 隞唳株亦隞嗡葉 曉蝻摮 撖寡情嚗閬瘜冽荔霂交雿冽鈭萎航賭鋡急舀 + *

+ * Extracting image cache objects from the data input component, it should be noted that this operation may not be supported in some cases. + * + * @return 曉蝻摮撖寡情 + */ + @Override + public BufferedImage getBufferedImage() { + LOGGER.info("getBufferedImage()"); + try { + return ImageIO.read(inputStream); + } catch (IOException e) { + throw new OperatorOperationException(e); + } + } + + /** + * Closes this stream and releases any system resources associated + * with it. If the stream is already closed then invoking this + * method has no effect. + * + *

As noted in {@link AutoCloseable#close()}, cases where the + * close may fail require careful attention. It is strongly advised + * to relinquish the underlying resources and to internally + * mark the {@code Closeable} as closed, prior to throwing + * the {@code IOException}. + */ + @Override + public void close() { + LOGGER.info("close()"); + ASIO.close(this.scanner); + } +} diff --git a/src_code/src/main/java/zhao/algorithmMagic/io/InputByStreamBuilder.java b/src_code/src/main/java/zhao/algorithmMagic/io/InputByStreamBuilder.java new file mode 100644 index 0000000..d719be2 --- /dev/null +++ b/src_code/src/main/java/zhao/algorithmMagic/io/InputByStreamBuilder.java @@ -0,0 +1,77 @@ +package zhao.algorithmMagic.io; + +import zhao.algorithmMagic.operands.table.Cell; +import zhao.algorithmMagic.operands.table.FinalCell; +import zhao.algorithmMagic.utils.ASClass; + +import java.util.HashMap; + +/** + * 唳格颲亥挽憭撖寡情撱粹蝐鳴刻砲蝐颱葉典臭誑撖寞唳格唳株交雿餈銵銝鈭蝵殷隞亥瑕唳唳格銝剔唳桀笆鞊∼ + *

+ * The data flow input device object creator class allows you to configure the data input operations of the data flow to obtain the data objects in the data flow. + */ +public class InputByStreamBuilder extends HashMap> implements InputBuilder { + + /** + * 唳株交 + */ + public final static String INPUT_STREAM = "ism"; + + /** + * 蝏唳桐閬鋡怨粉銵 + */ + public final static String ROW_LEN = "rc"; + + /** + * DF撖寡情霂餃銝剝閬霂餃銵 + */ + public final static String PK = "pk"; + + /** + * 唳株亦 + */ + public final static String CHARSET = "cs"; + + /** + * 蝏唳桐閬雿輻函蝚 + */ + public final static String SEP = "sep"; + + /** + * 瘛餃唳株交餈堆銝蝏隞嗆銝蝵桀改瑚臭誑摰啁掩 + *

+ * Add data input descriptions, and different components have different configuration properties. Please refer to the implementation class for details. + * + * @param key 撅批蝘 + *

+ * Attribute Name. + * @param value 撅扳啣 + *

+ * Attribute Value. + * @return 曉靚剁蝏抒賒撱 + *

+ * Chain call, continue building. + */ + @Override + public InputBuilder addInputArg(String key, FinalCell value) { + this.put(key, value); + return this; + } + + /** + * 撠撖寡情撱箏箸亙僎瑕啣笆摨颲亥挽憭撖寡情 + * + * @return 颲亥挽憭撖寡情 + */ + @Override + public InputComponent create() { + return new InputByStream( + ASClass.transform(this.get(INPUT_STREAM)), + ASClass.transform(this.get(CHARSET)), + this.getOrDefault(ROW_LEN, new FinalCell<>(10)).getIntValue(), + this.getOrDefault(PK, new FinalCell<>(0)).getIntValue(), + ASClass., Cell>transform(this.getOrDefault(SEP, new FinalCell<>(','))).getValue() + ); + } +} diff --git a/src_code/src/main/java/zhao/algorithmMagic/io/InputCamera.java b/src_code/src/main/java/zhao/algorithmMagic/io/InputCamera.java new file mode 100644 index 0000000..d98f7c2 --- /dev/null +++ b/src_code/src/main/java/zhao/algorithmMagic/io/InputCamera.java @@ -0,0 +1,159 @@ +package zhao.algorithmMagic.io; + +import com.github.sarxos.webcam.Webcam; +import com.github.sarxos.webcam.WebcamUtils; +import zhao.algorithmMagic.exception.OperatorOperationException; +import zhao.algorithmMagic.operands.table.DataFrame; +import zhao.algorithmMagic.utils.ASClass; +import zhao.algorithmMagic.utils.ASIO; + +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; + +/** + * 憭游笆鞊∴其隞憭湔銝撘曉 + * + * @author 韏萄摰 + * 2023/4/5 13:51 + */ +public class InputCamera implements InputComponent { + + private final Webcam webcam; + private final String format; + + /** + * @param webcam 批笆鞊 + * @param format 找曉澆 + */ + protected InputCamera(Webcam webcam, String format) { + this.webcam = webcam; + this.format = format; + } + + /** + * @return 撘憪撱箸祆唳桃隞嗅笆鞊∼ + *

+ * Start building this data component object. + */ + public static InputBuilder builder() { + return new InputCameraBuilder(); + } + + /** + * 臬冽唳株亦隞 + * + * @return 憒臬冽餈true + */ + @Override + public boolean open() { + return webcam.open(); + } + + /** + * @return 憒蝏隞嗅歇蝏臬其嚗刻餈true + */ + @Override + public boolean isOpen() { + return webcam.isOpen(); + } + + /** + * 喲剜唳株亦隞 + */ + @Override + public void close() { + webcam.close(); + } + + /** + * 隞唳株亦隞嗡葉 byte 啁唳殷銝祆萎嚗餈餈賣臭鈭鈭餈嗥唳柴 + *

+ * Extract the data of the byte array from the data input component. Generally, the returned data here is some binary data. + * + * @return byte[] 唳桀笆鞊 + */ + @Override + public byte[] getByteArray() { + return WebcamUtils.getImageBytes(webcam, format); + } + + /** + * 隞唳株亦隞嗡葉 int 拚菜唳殷銝祆萎嚗餈餈臭鈭拚萄蝝唳柴 + *

+ * From the data input component, int matrix data is increasingly generated. Generally, some matrix element data is returned here. + * + * @return int[][] + */ + @Override + public int[][] getInt2Array() { + return ASIO.parseImageGetArray(this.getBufferedImage()); + } + + /** + * 隞唳株亦隞嗡葉 int 拚菜唳殷銝祆萎嚗餈餈臭鈭拚萄蝝唳柴 + *

+ * From the data input component, double matrix data is increasingly generated. Generally, some matrix element data is returned here. + * + * @return double[][] + */ + @Override + public double[][] getDouble2Array() { + int[][] int2Array = this.getInt2Array(); + double[][] res = new double[int2Array.length][]; + int index = -1; + for (int[] ints : int2Array) { + res[++index] = ASClass.IntArray_To_DoubleArray(ints); + } + return res; + } + + /** + * 隞唳株亦隞嗉瑕 DataFrame 撖寡情嚗霂亙賣唳鈭唳株亦隞嗅航賭舀 + *

+ * Retrieve the DataFrame object from the data input component, which may not be supported by some data input components. + * + * @return 隞唳株亦隞嗡葉瑕啁DataFrame唳桀鋆撖寡情 + *

+ * The DataFrame data encapsulation object obtained from the data input component. + */ + @Override + public DataFrame getDataFrame() { + throw new UnsupportedOperationException("豢箄挽憭銝舀瑕蚤ataFrame撖寡情\nThe camera device does not support obtaining DataFrame objects."); + } + + /** + * 隞唳株亦隞嗡葉 唳格 撖寡情 + *

+ * Extract the data flow object from the data input component. + * + * @return 唳株交撖寡情 + */ + @Override + public InputStream getInputStream() { + return new ByteArrayInputStream(this.getByteArray()); + } + + /** + * 隞唳株亦隞嗡葉 曉蝻摮 撖寡情嚗閬瘜冽荔霂交雿冽鈭萎航賭鋡急舀 + *

+ * Extracting image cache objects from the data input component, it should be noted that this operation may not be supported in some cases. + * + * @return 曉蝻摮撖寡情 + */ + @Override + public BufferedImage getBufferedImage() { + InputStream inputStream = null; + try { + inputStream = this.getInputStream(); + return ImageIO.read(inputStream); + } catch (IOException e) { + throw new OperatorOperationException("抒豢箸扯粉憭梯揖.Camera photo reading failed.", e); + } finally { + ASIO.close(inputStream); + } + } + +} diff --git a/src_code/src/main/java/zhao/algorithmMagic/io/InputCameraBuilder.java b/src_code/src/main/java/zhao/algorithmMagic/io/InputCameraBuilder.java new file mode 100644 index 0000000..3eebc7a --- /dev/null +++ b/src_code/src/main/java/zhao/algorithmMagic/io/InputCameraBuilder.java @@ -0,0 +1,94 @@ +package zhao.algorithmMagic.io; + +import com.github.sarxos.webcam.Webcam; +import com.github.sarxos.webcam.WebcamResolution; +import zhao.algorithmMagic.exception.OperatorOperationException; +import zhao.algorithmMagic.operands.table.Cell; +import zhao.algorithmMagic.operands.table.FinalCell; + +import java.util.HashMap; + +/** + * 憭渲挽憭颲亙遣撖寡情 + * + * @author 韏萄摰 + * 2023/4/5 14:28 + */ +public class InputCameraBuilder extends HashMap> implements InputBuilder { + + /** + * 扳園閬雿輻函憭渡揣撘嚗蝝W撖孵value摨臭銝芣啣潭摮蝚虫葡嚗憒嗆啣澆敶雿蝝W憭嚗憒嗅蝚虫葡撠敶雿憭游蝘啣 + */ + public final static String Camera_Index = "Camera"; + + /** + * 扳園閬雿輻函曉扳澆嚗澆撖孵澆臭銝芸蝚虫葡 + */ + public final static String Image_Format = "ImageFormat"; + + /** + * 曉批之撠撠箏站撖寡情嚗澆撖孵澆臭誑湔交 WebcamResolution 蝐餌撅扼 + */ + public final static String CUSTOM_VIEW_SIZES = "CustomViewSizes"; + + public WebcamResolution webcamResolution = WebcamResolution.VGA; + + /** + * 瘛餃唳株交餈堆銝蝏隞嗆銝蝵桀改瑚臭誑摰啁掩 + *

+ * Add data input descriptions, and different components have different configuration properties. Please refer to the implementation class for details. + * + * @param key 撅批蝘 + *

+ * Attribute Name. + * @param value 撅扳啣 + *

+ * Attribute Value. + * @return 曉靚剁蝏抒賒撱 + *

+ * Chain call, continue building. + */ + @Override + public InputBuilder addInputArg(String key, FinalCell value) { + if (CUSTOM_VIEW_SIZES.equals(key)) { + return this.setViewSize(WebcamResolution.valueOf(value.toString())); + } + this.put(key, value); + return this; + } + + /** + * @param WebcamResolution 曉批之撠撠箏站撖寡情 + * @return 曉靚剁蝏抒賒撱 + *

+ * Chain call, continue building. + */ + public InputBuilder setViewSize(WebcamResolution WebcamResolution) { + this.webcamResolution = WebcamResolution; + return this; + } + + /** + * 撠撖寡情撱箏箸亙僎瑕啣笆摨颲亥挽憭撖寡情 + * + * @return 颲亥挽憭撖寡情 + */ + @Override + public InputComponent create() { + Cell cell = this.get(Camera_Index); + Webcam webcam; + if (cell != null) { + if (cell.isNumber()) { + webcam = Webcam.getWebcams().get(cell.getIntValue()); + } else { + String s = cell.toString(); + if ("def".equals(s)) webcam = Webcam.getDefault(); + else webcam = Webcam.getWebcamByName(s); + } + webcam.setViewSize(this.webcamResolution.getSize()); + return new InputCamera(webcam, this.getOrDefault(Image_Format, new FinalCell<>("JPG")).toString()); + } else { + throw new OperatorOperationException("霂瑟券蝵格憭渡蝘唳憭渡揣撘\nPlease configure the name or camera index of the camera."); + } + } +} diff --git a/src_code/src/main/java/zhao/algorithmMagic/io/InputComponent.java b/src_code/src/main/java/zhao/algorithmMagic/io/InputComponent.java new file mode 100644 index 0000000..90c7069 --- /dev/null +++ b/src_code/src/main/java/zhao/algorithmMagic/io/InputComponent.java @@ -0,0 +1,88 @@ +package zhao.algorithmMagic.io; + +import zhao.algorithmMagic.operands.table.DataFrame; + +import java.awt.image.BufferedImage; +import java.io.Closeable; +import java.io.InputStream; + +/** + * IO蝏隞嗅笆鞊∴霂亙笆鞊⊥舀唳株亥挽憭嗥掩亙撖寡情嚗餈霂亙笆鞊∪臭誑摰啗瑕啁洵銝寞唳桃雿 + *

+ * IO component object, which is the parent interface object of all data input devices, through which the operation of obtaining third-party data can be achieved + * + * @author 韏萄摰 + * 2023/4/5 13:52 + */ +public interface InputComponent extends Closeable { + + /** + * 臬冽唳株亦隞 + * + * @return 憒臬冽餈true + */ + boolean open(); + + /** + * @return 憒蝏隞嗅歇蝏臬其嚗刻餈true + *

+ * If the component has already started, return true here. + */ + boolean isOpen(); + + /** + * 隞唳株亦隞嗡葉 byte 啁唳殷銝祆萎嚗餈餈賣臭鈭鈭餈嗥唳柴 + *

+ * Extract the data of the byte array from the data input component. Generally, the returned data here is some binary data. + * + * @return byte[] 唳桀笆鞊 + */ + byte[] getByteArray(); + + /** + * 隞唳株亦隞嗡葉 int 拚菜唳殷銝祆萎嚗餈餈臭鈭拚萄蝝唳柴 + *

+ * From the data input component, int matrix data is increasingly generated. Generally, some matrix element data is returned here. + * + * @return int[][] + */ + int[][] getInt2Array(); + + /** + * 隞唳株亦隞嗡葉 int 拚菜唳殷銝祆萎嚗餈餈臭鈭拚萄蝝唳柴 + *

+ * From the data input component, double matrix data is increasingly generated. Generally, some matrix element data is returned here. + * + * @return double[][] + */ + double[][] getDouble2Array(); + + /** + * 隞唳株亦隞嗉瑕 DataFrame 撖寡情嚗霂亙賣唳鈭唳株亦隞嗅航賭舀 + *

+ * Retrieve the DataFrame object from the data input component, which may not be supported by some data input components. + * + * @return 隞唳株亦隞嗡葉瑕啁DataFrame唳桀鋆撖寡情 + *

+ * The DataFrame data encapsulation object obtained from the data input component. + */ + DataFrame getDataFrame(); + + /** + * 隞唳株亦隞嗡葉 唳格 撖寡情 + *

+ * Extract the data flow object from the data input component. + * + * @return 唳株交撖寡情 + */ + InputStream getInputStream(); + + /** + * 隞唳株亦隞嗡葉 曉蝻摮 撖寡情嚗閬瘜冽荔霂交雿冽鈭萎航賭鋡急舀 + *

+ * Extracting image cache objects from the data input component, it should be noted that this operation may not be supported in some cases. + * + * @return 曉蝻摮撖寡情 + */ + BufferedImage getBufferedImage(); +} diff --git a/src_code/src/main/java/zhao/algorithmMagic/io/InputHDFS.java b/src_code/src/main/java/zhao/algorithmMagic/io/InputHDFS.java new file mode 100644 index 0000000..7f793d8 --- /dev/null +++ b/src_code/src/main/java/zhao/algorithmMagic/io/InputHDFS.java @@ -0,0 +1,216 @@ +package zhao.algorithmMagic.io; + +import org.apache.hadoop.fs.FSDataInputStream; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import zhao.algorithmMagic.exception.OperatorOperationException; +import zhao.algorithmMagic.operands.table.*; +import zhao.algorithmMagic.utils.ASIO; +import zhao.algorithmMagic.utils.ASStr; + +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.*; + +/** + * HDFS唳株亦隞嗅笆鞊∴賢隞HDFS撟喳唬葉瑕唳隞嗆唳柴 + *

+ * HDFS data input component object, which can obtain file data from the HDFS platform. + * + * @author 韏萄摰 + * 2023/4/6 8:40 + */ +public class InputHDFS implements InputComponent { + + private final static Logger LOGGER = LoggerFactory.getLogger("InputHDFS"); + private final FileSystem fileSystem; + private final Path inputPath; + private final char sep; + private final String charset; + private final Series field; + private final int pk; + private FSDataInputStream fsDataInputStream; + private BufferedReader bufferedReader; + private boolean isOpen; + + /** + * @param fileSystem HDFS 隞嗥頂蝏撖寡情 + * @param inputPath 閬鋡怨粉隞嗉楝敺 + * @param sep 霂餃園閬雿輻函蝚 + * @param charset 霂餃園閬雿輻典蝚阡 + * @param field 霂餃嗥銵典畾萄蝘啗 + * @param pk 霂餃嗥銵其蜓桀笆鞊 + */ + protected InputHDFS(FileSystem fileSystem, Path inputPath, char sep, String charset, Cell field, int pk) { + if (fileSystem == null || inputPath == null || field == null) { + throw new OperatorOperationException("The parameter in [FileSystem fileSystem, Path inputPath, String[] field] cannot be null!!!!"); + } + this.fileSystem = fileSystem; + this.inputPath = inputPath; + this.sep = sep; + this.charset = charset; + this.field = FieldCell.parse(field.getValue()); + this.pk = pk; + this.isOpen = false; + } + + /** + * @return 撘憪撱箸祆唳桃隞嗅笆鞊∼ + *

+ * Start building this data component object. + */ + public static InputBuilder builder() { + return new InputHDFSBuilder(); + } + + /** + * 臬冽唳株亦隞 + * + * @return 憒臬冽餈true + */ + @Override + public boolean open() { + try { + LOGGER.info("InputHDFS.open()"); + this.fsDataInputStream = fileSystem.open(this.inputPath); + this.bufferedReader = new BufferedReader(new InputStreamReader(fsDataInputStream)); + return true; + } catch (IOException e) { + LOGGER.error("InputHDFS.open() error!!!", e); + return false; + } + } + + /** + * @return 憒蝏隞嗅歇蝏臬其嚗刻餈true + */ + @Override + public boolean isOpen() { + LOGGER.info("InputHDFS.isOpen()"); + return this.isOpen; + } + + /** + * 隞唳株亦隞嗡葉 byte 啁唳殷銝祆萎嚗餈餈賣臭鈭鈭餈嗥唳柴 + *

+ * Extract the data of the byte array from the data input component. Generally, the returned data here is some binary data. + * + * @return byte[] 唳桀笆鞊 + */ + @Override + public byte[] getByteArray() { + LOGGER.info("getByteArray()"); + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + try { + while (bufferedReader.ready()) { + byteArrayOutputStream.write(bufferedReader.readLine().getBytes(charset)); + } + return byteArrayOutputStream.toByteArray(); + } catch (IOException e) { + throw new OperatorOperationException(e); + } finally { + ASIO.close(byteArrayOutputStream); + } + } + + /** + * 隞唳株亦隞嗡葉 int 拚菜唳殷銝祆萎嚗餈餈臭鈭拚萄蝝唳柴 + *

+ * From the data input component, int matrix data is increasingly generated. Generally, some matrix element data is returned here. + * + * @return int[][] + */ + @Override + public int[][] getInt2Array() { + LOGGER.info("getInt2Array()"); + LOGGER.warn("Not currently supported getInt2Array()!!!"); + return new int[0][]; + } + + /** + * 隞唳株亦隞嗡葉 int 拚菜唳殷銝祆萎嚗餈餈臭鈭拚萄蝝唳柴 + *

+ * From the data input component, double matrix data is increasingly generated. Generally, some matrix element data is returned here. + * + * @return double[][] + */ + @Override + public double[][] getDouble2Array() { + LOGGER.info("getDouble2Array()"); + LOGGER.warn("Not currently supported getDouble2Array()!!!"); + return new double[0][]; + } + + /** + * 隞唳株亦隞嗉瑕 DataFrame 撖寡情嚗霂亙賣唳鈭唳株亦隞嗅航賭舀 + *

+ * Retrieve the DataFrame object from the data input component, which may not be supported by some data input components. + * + * @return 隞唳株亦隞嗡葉瑕啁DataFrame唳桀鋆撖寡情 + *

+ * The DataFrame data encapsulation object obtained from the data input component. + */ + @Override + public DataFrame getDataFrame() { + LOGGER.info("getDataFrame()"); + DataFrame select = FDataFrame.select(this.field, pk); + try { + while (bufferedReader.ready()) { + select.insert(FinalSeries.parse(ASStr.splitByChar(bufferedReader.readLine(), sep))); + } + return select; + } catch (IOException e) { + throw new OperatorOperationException(e); + } + } + + /** + * 隞唳株亦隞嗡葉 唳格 撖寡情 + *

+ * Extract the data flow object from the data input component. + * + * @return 唳株交撖寡情 + */ + @Override + public InputStream getInputStream() { + LOGGER.info("getInputStream()"); + return this.fsDataInputStream; + } + + /** + * 隞唳株亦隞嗡葉 曉蝻摮 撖寡情嚗閬瘜冽荔霂交雿冽鈭萎航賭鋡急舀 + *

+ * Extracting image cache objects from the data input component, it should be noted that this operation may not be supported in some cases. + * + * @return 曉蝻摮撖寡情 + */ + @Override + public BufferedImage getBufferedImage() { + LOGGER.info("getBufferedImage()"); + try { + return ImageIO.read(this.fsDataInputStream); + } catch (IOException e) { + throw new OperatorOperationException(e); + } + } + + /** + * Closes this stream and releases any system resources associated + * with it. If the stream is already closed then invoking this + * method has no effect. + * + *

As noted in {@link AutoCloseable#close()}, cases where the + * close may fail require careful attention. It is strongly advised + * to relinquish the underlying resources and to internally + * mark the {@code Closeable} as closed, prior to throwing + * the {@code IOException}. + */ + @Override + public void close() { + LOGGER.info("close()"); + ASIO.close(this.bufferedReader); + isOpen = false; + } +} diff --git a/src_code/src/main/java/zhao/algorithmMagic/io/InputHDFSBuilder.java b/src_code/src/main/java/zhao/algorithmMagic/io/InputHDFSBuilder.java new file mode 100644 index 0000000..9c9a325 --- /dev/null +++ b/src_code/src/main/java/zhao/algorithmMagic/io/InputHDFSBuilder.java @@ -0,0 +1,88 @@ +package zhao.algorithmMagic.io; + +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import zhao.algorithmMagic.operands.table.Cell; +import zhao.algorithmMagic.operands.table.FinalCell; +import zhao.algorithmMagic.utils.ASClass; + +import java.util.HashMap; + +/** + * HDFS唳株亦隞嗅遣撖寡情嚗刻砲撖寡情銝剛賢銝慵DFS唳株亦隞嗉銵撱箝 + *

+ * HDFS data input component object, which can obtain file data from the HDFS platform. + * + * @author 韏萄摰 + * 2023/4/6 9:18 + */ +public class InputHDFSBuilder extends HashMap> implements InputBuilder { + + /** + * HDFS隞嗥頂蝏撖寡情 + */ + public final static String FILE_SYSTEM = "FS"; + + /** + * 唳桀頧賢蝚 + */ + public final static String SEP = "sep"; + + /** + * 唳株亥楝敺 + */ + public final static String IN_PATH = "inPath"; + + /** + * 唳株亙蝚阡 + */ + public final static String CHAR_SET = "cs"; + + /** + * 唳株乩蜓 + */ + public final static String PK = "pk"; + + /** + * 唳桀蝚血蝘 + */ + public final static String FIELD = "field"; + + /** + * 瘛餃唳株交餈堆銝蝏隞嗆銝蝵桀改瑚臭誑摰啁掩 + *

+ * Add data input descriptions, and different components have different configuration properties. Please refer to the implementation class for details. + * + * @param key 撅批蝘 + *

+ * Attribute Name. + * @param value 撅扳啣 + *

+ * Attribute Value. + * @return 曉靚剁蝏抒賒撱 + *

+ * Chain call, continue building. + */ + @Override + public InputBuilder addInputArg(String key, FinalCell value) { + this.put(key, value); + return this; + } + + /** + * 撠撖寡情撱箏箸亙僎瑕啣笆摨颲亥挽憭撖寡情 + * + * @return 颲亥挽憭撖寡情 + */ + @Override + public InputComponent create() { + return new InputHDFS( + (FileSystem) this.get(FILE_SYSTEM).getValue(), + new Path(this.get(IN_PATH).toString()), + ASClass., Cell>transform(this.getOrDefault(SEP, new FinalCell<>(','))).getValue(), + this.getOrDefault(CHAR_SET, new FinalCell<>("utf-8")).toString(), + ASClass., Cell>transform(this.get(FIELD)), + this.getOrDefault(PK, new FinalCell<>(0)).getIntValue() + ); + } +} diff --git a/src_code/src/main/java/zhao/algorithmMagic/io/OutputBuilder.java b/src_code/src/main/java/zhao/algorithmMagic/io/OutputBuilder.java new file mode 100644 index 0000000..519cfc1 --- /dev/null +++ b/src_code/src/main/java/zhao/algorithmMagic/io/OutputBuilder.java @@ -0,0 +1,37 @@ +package zhao.algorithmMagic.io; + +import zhao.algorithmMagic.operands.table.FinalCell; + +/** + * 唳株箇隞嗅遣蝐鳴梯砲蝐餃遣箸唳株箇隞嗅笆鞊∼ + *

+ * The data output component builder class, which constructs effective data output component objects. + * + * @author 韏萄摰 + * 2023/4/6 19:32 + */ +public interface OutputBuilder { + /** + * 瘛餃唳株交餈堆銝蝏隞嗆銝蝵桀改瑚臭誑摰啁掩 + *

+ * Add data input descriptions, and different components have different configuration properties. Please refer to the implementation class for details. + * + * @param key 撅批蝘 + *

+ * Attribute Name. + * @param value 撅扳啣 + *

+ * Attribute Value. + * @return 曉靚剁蝏抒賒撱 + *

+ * Chain call, continue building. + */ + OutputBuilder addOutputArg(String key, FinalCell value); + + /** + * 撠撖寡情撱箏箸亙僎瑕啣笆摨颲亥挽憭撖寡情 + * + * @return 颲亥挽憭撖寡情 + */ + OutputComponent create(); +} diff --git a/src_code/src/main/java/zhao/algorithmMagic/io/OutputComponent.java b/src_code/src/main/java/zhao/algorithmMagic/io/OutputComponent.java new file mode 100644 index 0000000..e12dcec --- /dev/null +++ b/src_code/src/main/java/zhao/algorithmMagic/io/OutputComponent.java @@ -0,0 +1,80 @@ +package zhao.algorithmMagic.io; + +import zhao.algorithmMagic.operands.matrix.ColorMatrix; +import zhao.algorithmMagic.operands.matrix.ColumnDoubleMatrix; +import zhao.algorithmMagic.operands.matrix.ColumnIntegerMatrix; +import zhao.algorithmMagic.operands.table.DataFrame; + +import java.io.Closeable; + +/** + * 唳株箄挽憭蝐鳴甇斤掩銝剖急唳株粹餉摰堆臭誑餈甇斗亙湔亙唳株箏啁洵銝孵像啜 + *

+ * Data output device class, which includes data output logic implementation, can directly output data to third-party platforms through this interface. + * + * @author 韏萄摰 + * 2023/4/6 19:35 + */ +public interface OutputComponent extends Closeable { + + /** + * 臬冽唳株箇隞. + *

+ * Start data output component. + * + * @return 憒臬冽餈true + */ + boolean open(); + + /** + * @return 憒蝏隞嗅歇蝏臬其嚗刻餈true. + *

+ * If the component has already started, return true here + */ + boolean isOpen(); + + /** + * 撠銝隞賭餈嗆唳株箝 + *

+ * Output a binary data. + * + * @param data 閬鋡怨箇鈭餈嗆唳桀 + *

+ * The binary data package that needs to be output. + */ + void writeByteArray(byte[] data); + + /** + * 颲箔銝 游耦 拚萄笆鞊 + * + * @param matrix 閬鋡怨箇拚 + */ + void writeMat(ColumnIntegerMatrix matrix); + + /** + * 颲箔銝 double蝐餃 拚萄笆鞊 + * + * @param matrix 閬鋡怨箇拚 + */ + void writeMat(ColumnDoubleMatrix matrix); + + /** + * 撠曉拚菜怎曉湔亥箏啁格 + *

+ * Directly output the images contained in the image matrix to the target. + * + * @param colorMatrix 閬鋡怨箇曉拚萄笆鞊∼ + *

+ * The image matrix object that needs to be output. + */ + void writeImage(ColorMatrix colorMatrix); + + /** + * 撠銝銝 DataFrame 銝剔唳格扳唳株箇隞嗉銵颲. + *

+ * Output the data in a DataFrame according to the data output component. + * + * @param dataFrame 閬鋡怨箇唳桀笆鞊 + */ + void writeDataFrame(DataFrame dataFrame); +} diff --git a/src_code/src/main/java/zhao/algorithmMagic/io/OutputHDFS.java b/src_code/src/main/java/zhao/algorithmMagic/io/OutputHDFS.java new file mode 100644 index 0000000..eb06c87 --- /dev/null +++ b/src_code/src/main/java/zhao/algorithmMagic/io/OutputHDFS.java @@ -0,0 +1,252 @@ +package zhao.algorithmMagic.io; + +import org.apache.hadoop.fs.FSDataOutputStream; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import zhao.algorithmMagic.exception.OperatorOperationException; +import zhao.algorithmMagic.integrator.ImageRenderingIntegrator; +import zhao.algorithmMagic.operands.matrix.ColorMatrix; +import zhao.algorithmMagic.operands.matrix.ColumnDoubleMatrix; +import zhao.algorithmMagic.operands.matrix.ColumnIntegerMatrix; +import zhao.algorithmMagic.operands.table.Cell; +import zhao.algorithmMagic.operands.table.DataFrame; +import zhao.algorithmMagic.operands.table.Series; +import zhao.algorithmMagic.utils.ASIO; + +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.OutputStreamWriter; + +/** + * HDFS 撟喳唳唳株箄挽憭蝐鳴刻砲蝐餌內靘箸亦撖寡情銝剛賢湔亙唳株箏蚜DFS隞嗥頂蝏銝准 + *

+ * HDFS platform data output device class, which can directly output data to the HDFS file system in the instantiated objects of this class. + * + * @author 韏萄摰 + * 2023/4/6 20:01 + */ +public class OutputHDFS implements OutputComponent { + + private final static Logger LOGGER = LoggerFactory.getLogger("OutputHDFS"); + + + private final FileSystem fileSystem; + private final Path outputPath; + private final String format; + private final char sep; + private boolean isOpen = false; + private FSDataOutputStream fsDataOutputStream; + private BufferedWriter bufferedWriter; + + /** + * @param fileSystem HDFS 隞嗥頂蝏撖寡情 + *

+ * HDFS File System Objects. + * @param outputPath HDFS 隞嗆唳株箇桀 + *

+ * HDFS file data output directory. + * @param format HDFS 隞嗆唳株箸澆 + *

+ * HDFS file data output format. + * @param sep 隞嗆唳株箸園閬雿輻函蝚艾 + *

+ * Delimiters required for file data output. + */ + public OutputHDFS(FileSystem fileSystem, Path outputPath, String format, char sep) { + if (fileSystem == null || outputPath == null || format == null) { + throw new OperatorOperationException("The parameter in [FileSystem fileSystem, Path outputPath, String format] cannot be null!!!!"); + } + this.fileSystem = fileSystem; + this.outputPath = outputPath; + this.format = format; + this.sep = sep; + } + + public static OutputBuilder builder() { + return new OutputHDFSBuidler(); + } + + /** + * 臬冽唳株箇隞. + *

+ * Start data output component. + * + * @return 憒臬冽餈true + */ + @Override + public boolean open() { + try { + LOGGER.info("OutputHDFS.open()"); + fsDataOutputStream = fileSystem.create(outputPath); + bufferedWriter = new BufferedWriter(new OutputStreamWriter(fsDataOutputStream)); + this.isOpen = true; + return true; + } catch (IOException e) { + LOGGER.error("OutputHDFS.open() error!!!", e); + return false; + } + } + + /** + * @return 憒蝏隞嗅歇蝏臬其嚗刻餈true. + *

+ * If the component has already started, return true here + */ + @Override + public boolean isOpen() { + LOGGER.info("OutputHDFS.isOpen()"); + return this.isOpen; + } + + /** + * 撠銝隞賭餈嗆唳株箝 + *

+ * Output a binary data. + * + * @param data 閬鋡怨箇鈭餈嗆唳桀 + *

+ * The binary data package that needs to be output. + */ + @Override + public void writeByteArray(byte[] data) { + LOGGER.info("writeByteArray(byte[] data)"); + try { + fsDataOutputStream.write(data); + } catch (IOException e) { + throw new OperatorOperationException(e); + } + } + + /** + * 颲箔銝 游耦 拚萄笆鞊 + * + * @param matrix 閬鋡怨箇拚 + */ + @Override + public void writeMat(ColumnIntegerMatrix matrix) { + int rowCount = -1; + try { + // 颲箏 + bufferedWriter.write("colName"); + String[] rowFieldNames = matrix.getRowFieldNames(); + for (String colName : matrix.getColFieldNames()) { + bufferedWriter.write(sep); + bufferedWriter.write(colName); + } + bufferedWriter.newLine(); + for (int[] ints : matrix.toArrays()) { + bufferedWriter.write(rowFieldNames[++rowCount]); + for (int aInt : ints) { + bufferedWriter.write(sep); + bufferedWriter.write(String.valueOf(aInt)); + } + } + } catch (IOException e) { + throw new OperatorOperationException("Write data exception!", e); + } + } + + /** + * 颲箔銝 double蝐餃 拚萄笆鞊 + * + * @param matrix 閬鋡怨箇拚 + */ + @Override + public void writeMat(ColumnDoubleMatrix matrix) { + int rowCount = -1; + try { + // 颲箏 + bufferedWriter.write("colName"); + String[] rowFieldNames = matrix.getRowFieldNames(); + for (String colName : matrix.getColFieldNames()) { + bufferedWriter.write(sep); + bufferedWriter.write(colName); + } + bufferedWriter.newLine(); + for (double[] ints : matrix.toArrays()) { + bufferedWriter.write(rowFieldNames[++rowCount]); + for (double aInt : ints) { + bufferedWriter.write(sep); + bufferedWriter.write(String.valueOf(aInt)); + } + } + } catch (IOException e) { + throw new OperatorOperationException("Write data exception!", e); + } + } + + /** + * 撠曉拚菜怎曉湔亥箏啁格 + *

+ * Directly output the images contained in the image matrix to the target. + * + * @param colorMatrix 閬鋡怨箇曉拚萄笆鞊∼ + *

+ * The image matrix object that needs to be output. + */ + @Override + public void writeImage(ColorMatrix colorMatrix) { + LOGGER.info("writeImage(ColorMatrix colorMatrix)"); + BufferedImage bufferedImage = ImageRenderingIntegrator.drawBufferedImage( + colorMatrix.toArrays(), colorMatrix.getColCount(), colorMatrix.getRowCount(), 1, false + ); + try { + ImageIO.write(bufferedImage, format, fsDataOutputStream); + } catch (IOException e) { + throw new OperatorOperationException(e); + } + } + + /** + * 撠銝銝 DataFrame 銝剔唳格扳唳株箇隞嗉銵颲. + *

+ * Output the data in a DataFrame according to the data output component. + * + * @param dataFrame 閬鋡怨箇唳桀笆鞊 + */ + @Override + public void writeDataFrame(DataFrame dataFrame) { + LOGGER.info("writeDataFrame(DataFrame dataFrame)"); + try { + bufferedWriter.write("rowNumber"); + for (Cell cell : dataFrame.getFields()) { + bufferedWriter.write(sep); + bufferedWriter.write(cell.getStringValue()); + } + bufferedWriter.newLine(); + int count = 0; + for (Series cells : dataFrame) { + bufferedWriter.write(String.valueOf(++count)); + for (Cell cell : cells) { + bufferedWriter.write(sep); + bufferedWriter.write(cell.toString()); + } + bufferedWriter.newLine(); + } + } catch (IOException e) { + throw new OperatorOperationException(e); + } + } + + /** + * Closes this stream and releases any system resources associated + * with it. If the stream is already closed then invoking this + * method has no effect. + * + *

As noted in {@link AutoCloseable#close()}, cases where the + * close may fail require careful attention. It is strongly advised + * to relinquish the underlying resources and to internally + * mark the {@code Closeable} as closed, prior to throwing + * the {@code IOException}. + */ + @Override + public void close() { + LOGGER.info("close()"); + ASIO.close(this.bufferedWriter); + ASIO.close(this.fsDataOutputStream); + } +} diff --git a/src_code/src/main/java/zhao/algorithmMagic/io/OutputHDFSBuidler.java b/src_code/src/main/java/zhao/algorithmMagic/io/OutputHDFSBuidler.java new file mode 100644 index 0000000..faf93fc --- /dev/null +++ b/src_code/src/main/java/zhao/algorithmMagic/io/OutputHDFSBuidler.java @@ -0,0 +1,78 @@ +package zhao.algorithmMagic.io; + +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import zhao.algorithmMagic.operands.table.Cell; +import zhao.algorithmMagic.operands.table.FinalCell; +import zhao.algorithmMagic.utils.ASClass; + +import java.util.HashMap; + +/** + * HDFS唳株箄挽憭撱粹蝐鳴餈霂亦掩撱粹箸以DFS唳株箇內靘 + *

+ * The builder class of HDFS data output devices, through which HDFS data output examples are constructed. + * + * @author 韏萄摰 + * 2023/4/6 20:01 + */ +public class OutputHDFSBuidler extends HashMap> implements OutputBuilder { + + /** + * HDFS隞嗥頂蝏撖寡情 + */ + public final static String FILE_SYSTEM = "FS"; + + /** + * 唳桀頧賢蝚 + */ + public final static String SEP = "sep"; + + /** + * 唳株箄楝敺 + */ + public final static String OUT_PATH = "outPath"; + + /** + * 唳株箸嗥澆嚗桀舀銵典銝蝷 + * 祆唳殷csv + * 曉唳殷Java舀曉澆 + */ + public final static String FORMAT = "format"; + + /** + * 瘛餃唳株交餈堆銝蝏隞嗆銝蝵桀改瑚臭誑摰啁掩 + *

+ * Add data input descriptions, and different components have different configuration properties. Please refer to the implementation class for details. + * + * @param key 撅批蝘 + *

+ * Attribute Name. + * @param value 撅扳啣 + *

+ * Attribute Value. + * @return 曉靚剁蝏抒賒撱 + *

+ * Chain call, continue building. + */ + @Override + public OutputBuilder addOutputArg(String key, FinalCell value) { + this.put(key, value); + return this; + } + + /** + * 撠撖寡情撱箏箸亙僎瑕啣笆摨颲亥挽憭撖寡情 + * + * @return 颲亥挽憭撖寡情 + */ + @Override + public OutputComponent create() { + return new OutputHDFS( + (FileSystem) this.get(FILE_SYSTEM).getValue(), + (Path) this.get(OUT_PATH).getValue(), + this.get(FORMAT).toString(), + ASClass., Cell>transform(this.getOrDefault(SEP, new FinalCell<>(','))).getValue() + ); + } +} diff --git a/src_code/src/main/java/zhao/algorithmMagic/operands/matrix/ColorMatrix.java b/src_code/src/main/java/zhao/algorithmMagic/operands/matrix/ColorMatrix.java index 3c59103..8532b36 100644 --- a/src_code/src/main/java/zhao/algorithmMagic/operands/matrix/ColorMatrix.java +++ b/src_code/src/main/java/zhao/algorithmMagic/operands/matrix/ColorMatrix.java @@ -1,19 +1,28 @@ package zhao.algorithmMagic.operands.matrix; +import zhao.algorithmMagic.algorithm.distanceAlgorithm.DistanceAlgorithm; import zhao.algorithmMagic.exception.OperatorOperationException; import zhao.algorithmMagic.integrator.ImageRenderingIntegrator; +import zhao.algorithmMagic.io.InputComponent; +import zhao.algorithmMagic.io.OutputComponent; +import zhao.algorithmMagic.operands.coordinate.IntegerCoordinateTwo; import zhao.algorithmMagic.operands.matrix.block.IntegerMatrixSpace; +import zhao.algorithmMagic.operands.table.Cell; +import zhao.algorithmMagic.utils.ASClass; import zhao.algorithmMagic.utils.ASIO; import zhao.algorithmMagic.utils.ASMath; +import zhao.algorithmMagic.utils.filter.DoubleFiltering; import zhao.algorithmMagic.utils.transformation.ManyTrans; +import zhao.algorithmMagic.utils.transformation.ProTransForm; import javax.swing.*; import java.awt.*; +import java.io.BufferedWriter; import java.io.File; import java.io.IOException; import java.net.URL; -import java.util.Arrays; -import java.util.Iterator; +import java.util.*; +import java.util.function.Consumer; /** * 憸脩拚萄笆鞊∴嗡葉摮函瘥銝銝芸蝝賣臭銝 Color 撖寡情嚗冽亥銵曉蝏嗥撌乩 @@ -74,6 +83,217 @@ public class ColorMatrix extends Matrix + * The processing logic in the color value difference calculation scheme is to take 0 or 255 if the value exceeds the range, and take the value itself if the value does not exceed the range, achieving an efficient calculation scheme for limiting color values. + */ + public final static ManyTrans COLOR_DIFF_REGULATE = (inputType1, inputType2) -> new Color( + ASMath.regularTricolor(inputType1.getRed() - inputType2.getRed()), + ASMath.regularTricolor(inputType1.getGreen() - inputType2.getGreen()), + ASMath.regularTricolor(inputType1.getBlue() - inputType2.getGreen()) + ); + + /** + * 憸脫啣潭撌株恣蝞寞嚗刻砲寞銝剔憭餉銝綽憒x銝箸頞啣潘 x % 256 蝏雿銝粹脫啣潦 + *

+ * The processing logic in the color value difference calculation scheme is: if x is the out-of-boundary value after the sum, the result of x% 256 is taken as the color value. + */ + public final static ManyTrans COLOR_DIFF_REMAINDER = (inputType1, inputType2) -> { + int red = inputType1.getRed() - inputType2.getRed(); + int green = inputType1.getGreen() - inputType2.getGreen(); + int blue = inputType1.getBlue() - inputType2.getGreen(); + return new Color( + red - (red >> _G_ << _G_), + green - (green >> _G_ << _G_), + blue - (blue >> _G_ << _G_) + ); + }; + + /** + * 憸脫啣潭撌株恣蝞寞嚗刻砲寞銝剔憭餉銝箏啣潸箄湛0255嚗憒啣潭瓷頞餈游啣潭祈澈嚗摰圈脫啣潛擃嗥霈∠寞 + *

+ * The processing logic in the color value difference calculation scheme is to take 0 or 255 if the value exceeds the range, and take the value itself if the value does not exceed the range, achieving an efficient calculation scheme for limiting color values. + */ + public final static ManyTrans COLOR_DIFF_ABS = (inputType1, inputType2) -> new Color( + ASMath.absoluteValue(inputType1.getRed() - inputType2.getRed()), + ASMath.absoluteValue(inputType1.getGreen() - inputType2.getGreen()), + ASMath.absoluteValue(inputType1.getBlue() - inputType2.getGreen()) + ); + + /** + * 憸脫啣潭蝘航恣蝞寞嚗刻砲寞銝剔憭餉銝箏啣潸箄湛0255嚗憒啣潭瓷頞餈游啣潭祈澈嚗摰圈脫啣潛擃嗥霈∠寞 + *

+ * The processing logic in the color value quadrature calculation scheme is to take 0 or 255 if the value exceeds the range, and take the value itself if the value does not exceed the range, achieving an efficient calculation scheme for limiting color values. + */ + public final static ManyTrans COLOR_MULTIPLY_REGULATE = (inputType1, inputType2) -> new Color( + ASMath.regularTricolor(inputType1.getRed() * inputType2.getRed()), + ASMath.regularTricolor(inputType1.getGreen() * inputType2.getGreen()), + ASMath.regularTricolor(inputType1.getBlue() * inputType2.getGreen()) + ); + + /** + * 憸脫啣潭蝘航恣蝞寞嚗刻砲寞銝剔憭餉銝箏啣潸箄湛敶啣 % 256 蝏啣潔銝箏憸脫啣潦 + *

+ * The processing logic in the color value quadrature calculation scheme is to take 0 or 255 if the value exceeds the range, and take the value itself if the value does not exceed the range, achieving an efficient calculation scheme for limiting color values. + */ + public final static ManyTrans COLOR_MULTIPLY_REMAINDER = (inputType1, inputType2) -> { + int red = inputType1.getRed() + inputType2.getRed(); + int green = inputType1.getGreen() + inputType2.getGreen(); + int blue = inputType1.getBlue() + inputType2.getGreen(); + return new Color( + red - (red >> _G_ << _G_), + green - (green >> _G_ << _G_), + blue - (blue >> _G_ << _G_) + ); + }; + + /** + * 撠拚萎葉寡恣蝞銝綽 敶 = 喳 - 撌血 + */ + public final static Consumer CALCULATE_GRADIENT_RL = colors -> { + if (colors[0].length <= 2) return; + for (Color[] color : colors) { + Color left = color[0], right = color[2]; + color[0] = color[1]; + for (int i = 1, maxI = color.length - 2; i < maxI; ) { + Color now = right; + color[i] = COLOR_DIFF_REGULATE.function(right, left); + left = now; + right = color[++i]; + } + } + }; + + /** + * 撠拚萎葉寡恣蝞銝綽 敶 = 銝 - 銝 + */ + public final static Consumer CALCULATE_GRADIENT_LH = colors -> { + if (colors.length <= 2) return; + Color[] back = colors[0], next = colors[2]; + for (int i = 1, maxI = colors.length - 2; i < maxI; ) { + Color[] now1 = colors[i].clone(); + Color[] now2 = next; + for (int index = 0; index < now2.length; index++) { + now2[index] = COLOR_DIFF_REGULATE.function(next[index], back[index]); + } + back = now1; + next = colors[++i]; + } + }; + + /** + * 撠拚萎葉寡恣蝞銝綽 敶 = 喳 - 撌血 + */ + public final static Consumer CALCULATE_GRADIENT_RL_ABS = colors -> { + if (colors[0].length <= 2) return; + for (Color[] color : colors) { + Color left = color[0], right = color[2]; + color[0] = color[1]; + for (int i = 1, maxI = color.length - 2; i < maxI; ) { + Color now = right; + color[i] = COLOR_DIFF_ABS.function(right, left); + left = now; + right = color[++i]; + } + } + }; + + /** + * 撠拚萎葉寡恣蝞銝綽 敶 = 銝 - 銝 + */ + public final static Consumer CALCULATE_GRADIENT_LH_ABS = colors -> { + if (colors.length <= 2) return; + Color[] back = colors[0], next = colors[2]; + for (int i = 1, maxI = colors.length - 2; i < maxI; ) { + Color[] now1 = colors[i].clone(); + Color[] now2 = next; + for (int index = 0; index < now2.length; index++) { + now2[index] = COLOR_DIFF_ABS.function(next[index], back[index]); + } + back = now1; + next = colors[++i]; + } + }; + + /** + * 拚萄椰喳頧祆雿嚗嗅唳臬舫嚗憒冽唾隡堆霂瑟批銝孵隡 + * key = "isCopy" value = boolean 啣 隞銵典頧祆雿臬阡閬瑁箸啁拚蛛憒銝閬典拚萎葉餈銵頧研 + */ + public final static ProTransForm REVERSE_LR = (colorMatrix, value) -> { + if (value != null) { + Cell isCopy = value.get("isCopy"); + if (isCopy != null) { + return colorMatrix.reverseLR(Boolean.parseBoolean(isCopy.toString())); + } + } + return colorMatrix.reverseLR(true); + }; + + /** + * 拚萄椰喳頧祆雿嚗嗅唳臬舫嚗憒冽唾隡堆霂瑟批銝孵隡 + * key = "isCopy" value = boolean 啣 + */ + public final static ProTransForm REVERSE_BT = (colorMatrix, value) -> { + if (value != null) { + Cell isCopy = value.get("isCopy"); + if (isCopy != null) { + return colorMatrix.reverseBT(Boolean.parseBoolean(isCopy.toString())); + } + } + return colorMatrix.reverseBT(true); + }; + + /** + * 拚菜批椰喟孵餈銵隡豢雿嚗雿踹曉摰踝閬隡 times + */ + public final static ProTransForm SLIT_LR = (colorMatrix, value) -> { + if (value == null || !value.containsKey("times")) { + throw new OperatorOperationException("拚菜隡豢雿閬其蝵桅★ times 嗡誨銵冽銝銝芸蝝典拚萎葉璅芸隡詨啜"); + } + // 瑕唳赤隡詨 + int times = value.get("times").getIntValue(); + // 撘憪隡 + Color[][] res = new Color[colorMatrix.getRowCount()][colorMatrix.getColCount() * times]; + int index = -1; + for (Color[] colors : colorMatrix.toArrays()) { + Color[] re = res[++index]; + int x1 = 0, x2 = times; + for (Color color : colors) { + // 刻隡訾銝芸蝝銝箏亦 times 摰 + for (int x = x1; x < x2; x++) { + re[x] = color; + } + x1 += times; + x2 += times; + } + } + return ColorMatrix.parse(res); + }; + + /** + * 拚菜找銝孵餈銵隡豢雿嚗雿踹曉摰踝閬隡 times + */ + public final static ProTransForm SLIT_BT = (colorMatrix, value) -> { + if (value == null || !value.containsKey("times")) { + throw new OperatorOperationException("拚菜隡豢雿閬其蝵桅★ times 嗡誨銵冽銝銝芸蝝典拚萎葉璅芸隡詨啜"); + } + // 瑕唳赤隡詨 + int times = value.get("times").getIntValue(); + // 撘憪隡 + Color[][] res = new Color[colorMatrix.getRowCount() * times][colorMatrix.getColCount()]; + int x1 = 0, x2 = times; + for (Color[] colors : colorMatrix.toArrays()) { + // 刻撠銵隡 times + for (int i = x1; i < x2; i++) { + res[i] = colors.clone(); + } + x1 += times; + x2 += times; + } + return ColorMatrix.parse(res); + }; + private boolean isGrayscale; /** @@ -169,17 +389,7 @@ public static ColorMatrix parse(String inputString) { */ public static ColorMatrix parseGrayscale(String inputString) { Color[][] colors = ASIO.parseImageGetColorArray(inputString); - return GrayscaleColors(colors); - } - - /** - * 撠曉URL閫嚗撟嗉瑕撖孵曉拚 - * - * @param url 閬鋡怨圾URL撖寡情 - * @return URL撖寡情撖孵曉拚萸 - */ - public static ColorMatrix parseGrayscale(URL url) { - return GrayscaleColors(ASIO.parseURLGetColorArray(url)); + return ColorMatrix.GrayscaleColors(colors); } /** @@ -266,6 +476,51 @@ public static ColorMatrix parse(URL url) { return ColorMatrix.parse(ASIO.parseURLGetColorArray(url)); } + + /** + * 撠曉URL閫嚗撟嗉瑕撖孵曉拚 + * + * @param url 閬鋡怨圾URL撖寡情 + * @return URL撖寡情撖孵曉拚萸 + */ + public static ColorMatrix parseGrayscale(URL url) { + return ColorMatrix.GrayscaleColors(ASIO.parseURLGetColorArray(url)); + } + + /** + * 雿輻函隞嗅銝銝芸曉唳格嚗撟嗉瑕撖孵曉拚萸 + * + * @param inputComponent 賢鋡急箏曉拚萇唳桃隞嗚 + * @return 隞蝏隞嗡葉箸亦曉拚萄笆鞊∼ + */ + public static ColorMatrix parse(InputComponent inputComponent) { + return parse(inputComponent, true); + } + + /** + * 雿輻函隞嗅銝銝芸曉唳格嚗撟嗉瑕撖孵曉拚萸 + * + * @param inputComponent 賢鋡急箏曉拚萇唳桃隞嗚 + * @param isOC 憒霈曄蔭銝 true 隞銵冽唳株亥挽憭撖寡情撘銝喲凋漱望嗥恣嚗典撠銝閬撖寧隞嗉銵撘喲剜雿嚗銋隞銵冽嗅芯蝙函隞塚雿銝隡撘銝喲剔隞嗅笆鞊∼ + *

+ * If set to true, it means that the opening and closing of data input device objects are managed by the framework, and there will be no need to open or close components externally. Conversely, it means that the framework only uses components, but will not open or close component objects. + * @return 隞蝏隞嗡葉箸亦曉拚萄笆鞊∼ + */ + public static ColorMatrix parse(InputComponent inputComponent, boolean isOC) { + boolean isOk; + if (!inputComponent.isOpen() && isOC) { + isOk = inputComponent.open(); + } else { + isOk = true; + } + if (isOk) { + // 撘憪餈銵唳格 + ColorMatrix parse = ColorMatrix.parse(ASIO.parseImageGetColorArray(inputComponent.getBufferedImage())); + if (isOC) ASIO.close(inputComponent); + return parse; + } else throw new OperatorOperationException("Unable to open your inputComponent."); + } + /** * 撠銝銝芸曉拚萎葉蝝頧祆X銝箔脣潘瑕啁啣漲拚萸 * @@ -283,6 +538,58 @@ private static ColorMatrix GrayscaleColors(Color[][] colors) { return new ColorMatrix(colors.length, colors[0].length, colors, true); } + /** + * 瑕唳祆唳株粹餉摰啣笆鞊 + * + * @param colorMatrix 閬鋡怨箇曉拙耦 + * @param sep 颲箸園閬雿輻函蝚 + * @return 銝銝芯其撠曉銝剔憸脫啣潭低SV澆颲箏唳摰隞嗡葉摰圈餉 + */ + public static Consumer getSAVE_TEXT(ColorMatrix colorMatrix, char sep) { + return (stream) -> { + try { + int rowCount = 0; + for (Color[] colors : colorMatrix.toArrays()) { + stream.write(String.valueOf(++rowCount)); + for (Color color : colors) { + stream.write(sep); + stream.write(String.valueOf(color.getRGB())); + } + stream.newLine(); + } + } catch (IOException e) { + throw new OperatorOperationException("Write data exception!", e); + } + }; + } + + /** + * 撠曉隞丕SCII敶W颲箏唳摰隞嗡葉 + * + * @param colorMatrix 閬鋡怨箇曉撖寡情 + * @param Mode 閬鋡怨箇憸脤 + * @param colorBoundary 颲箸嗥憸脰器啣 + * @param imageAscii1 颲箸嗥ASCII + * @param imageAscii2 颲箸嗥ASCII + * @return 銝銝服SCII蝚血瑞砍曉 + */ + public static Consumer getSAVE_ASCII(ColorMatrix colorMatrix, byte Mode, int colorBoundary, char imageAscii1, char imageAscii2) { + return bufferedWriter -> { + try { + for (Color[] colors : colorMatrix.toArrays()) { + for (Color color : colors) { + if (((color.getRGB() >> Mode) & 0xFF) > colorBoundary) { + bufferedWriter.write(imageAscii1); + } else bufferedWriter.write(imageAscii2); + } + bufferedWriter.newLine(); + } + } catch (IOException e) { + throw new OperatorOperationException("Write data exception!", e); + } + }; + } + /** * 撠銝支葵雿啗銵瘙寞嚗瑚冽霂瑕API霂湔 *

@@ -309,7 +616,7 @@ public ColorMatrix add(ColorMatrix value) { */ @Override public ColorMatrix diff(ColorMatrix value) { - throw new UnsupportedOperationException("The color matrix object does not support the operation of \"addition\", \"subtraction\" and \"multiplication\", because the calculation of such operations on the color object is not necessary!"); + return agg(value, COLOR_DIFF_REMAINDER); } /** @@ -348,6 +655,43 @@ public ColorMatrix agg(ColorMatrix value, ManyTrans manyTrans) { } } + /** + * 函拚萄典霈∠嚗雿踹拚萄臭誑皛∟雲隞祉瘙銝霈∠雿 + *

+ * Computing occurs within the matrix, enabling the matrix to meet our needs and computational operations. + * + * @param action 霈∠摰圈餉嚗舀芸銋銋舀湔乩蝙典蝵桀啜 + *

+ * Computational implementation logic supports customization and direct use of built-in implementations. + * @param isCopy 霈∠雿臬西冽瑁銋啁銝剜扯嚗憒霈曄蔭銝 true 隞銵刻恣蝞雿撠鈭唳唳桐葉嚗銝隡敶勗拚萄笆鞊∼ + *

+ * Whether the calculation operation should be performed in the copied array. If set to true, it means that the calculation operation will occur in the new data and will not affect the original matrix object. + * @return 霈∠銋拚萄笆鞊∼ + *

+ * The calculated matrix object. + */ + public ColorMatrix calculate(Consumer action, boolean isCopy) { + if (isCopy) { + Color[][] colors = this.copyToNewArrays(); + action.accept(colors); + return ColorMatrix.parse(colors); + } else { + action.accept(this.toArrays()); + return this; + } + } + + /** + * 拚萄X雿賣堆冽迨賣唬葉典臭誑隡憭銝芰拚萄X芋撘嚗摰啣蝘銝拚菔蓮X嚗嗉臭誑芸銋拚萄X園閬雿輻函餉 + * + * @param transformation 拚萄a餉 + * @param value 拚萎葉X雿霈∠園閬嗅啣笆鞊∼ + * @return 拚萄V餈啁拚萄笆鞊∼ + */ + public ColorMatrix converter(ProTransForm transformation, HashMap> value) { + return transformation.function(this, value); + } + /** * 瑕啁拚萎葉摰寧啣 * @@ -516,7 +860,7 @@ public ColorMatrix shuffle(long seed) { public Color[][] copyToNewArrays() { Color[][] colors = this.toArrays(); Color[][] res = new Color[colors.length][colors[0].length]; - System.arraycopy(colors, 0, res, 0, colors.length); + ASClass.array2DCopy(colors, res); return res; } @@ -988,7 +1332,7 @@ public final void contrast(int contrastThreshold) { public ColorMatrix extractImage(int x1, int y1, int x2, int y2) { if (x1 >= x2 || y1 >= y2) { throw new OperatorOperationException("曉霂荔刻挽蝵桃寞霂!!!\nAn error occurred in image extraction. The extraction coordinate point you set is incorrect!!!\n" + - "ERROR => (" + x1 + ',' + y1 + ") >= (" + y1 + ',' + y2 + ')'); + "ERROR => (" + x1 + ',' + y1 + ") >= (" + x2 + ',' + y2 + ')'); } if (x2 >= this.getColCount() || y2 >= this.getRowCount()) { throw new OperatorOperationException("曉霂荔其賣銝摮其曉銝剔鈾nAn error occurred in image extraction. You cannot extract coordinate points that do not exist in the image\n" + @@ -1162,6 +1506,40 @@ public double avg(byte colorMode) { return sum / (double) (this.getNumberOfDimensions()); } + /** + * 霈∠箄蔭撱Y妖憭批嚗隞亙蝝銝箏雿 + *

+ * Calculate the size of the area within the contour, in pixels. + * + * @param contourColor 頧桀蝥輻憸脣笆鞊∴憒蝝憸脫啣潔甇文潔湛霈支蛹嗅鈭颲寞 + *

+ * The color object of the outline. If the color value of a pixel matches this value, it is considered to belong to the border. + * @return 頧桀蝝圈 + *

+ * The number of all pixels within the contour. + */ + public int contourArea(Color contourColor) { + int rgb = contourColor.getRGB(); + int res = 0; + for (Color[] colors : this.toArrays()) { + boolean isOk = false; + for (Color color : colors) { + if (isOk) { + ++res; + if (color.getRGB() == rgb) { + isOk = false; + } + continue; + } + if (color.getRGB() == rgb) { + isOk = true; + ++res; + } + } + } + return res; + } + /** * 曉賣堆刻砲賣啁憭銋銝嚗臭誑撖孵曉鈭銝頞喳憸脫啣潸銵雿嚗 * @@ -1203,7 +1581,7 @@ public ColorMatrix erode(int width, int height, boolean isCopy, Color backColor) for (Color[] colors : nowSub.toArrays()) { for (Color color : colors) { if (color.getRGB() == colorNum) { - // 唬暺 湔亙霂亙拚萎葉憸脫湔V蛹暺 + // 唬 湔亙霂亙拚萎葉憸脫湔V蛹 isR = true; } } @@ -1226,6 +1604,223 @@ public ColorMatrix erode(int width, int height, boolean isCopy, Color backColor) return res; } + /** + * 瘚瑁孵瑕唬舅銝芰拚萎銝撌血喳撟嗡鈭抒啁拚萄笆鞊∴閬瘜冽荔霂交雿銝隡暹亦拚蛛港隡湔寡冽寧唳柴 + *

+ * The shallow copy method obtains a new matrix object generated by merging two matrices up and down or left and right. Note that this operation does not link the matrix, nor does it change the caller's data. + * + * @param colorMatrix 閬鋡怨蕭憸脩拚萄笆鞊∼ + *

+ * The color matrix object that needs to be appended. + * @param isLR 憒霈曄蔭銝 true 隞銵其蝙典椰唾蕭孵餈銵餈賢嚗 憒霈曄蔭銝 false 隞銵其蝙其銝餈賢孵餈銵餈賢 + *

+ * If set to true, it means appending using the left and right appending method. If set to false, it means appending using the up and down appending method. + * @return 餈賢銋拚萄笆鞊∴霂亦拚萄笆鞊∩葉銵銝拚菜舀唾 + *

+ * The appended matrix object has no rows associated with the original matrix. + */ + public ColorMatrix append(ColorMatrix colorMatrix, boolean isLR) { + if (isLR) { + Color[][] colors1 = this.toArrays(); + Color[][] colors2 = colorMatrix.toArrays(); + if (colors1.length != colors2.length) { + throw new OperatorOperationException("撌血唾蕭拚萄笆鞊⊿閬靽銵啁詨嚗"); + } + Color[][] res = new Color[colors1.length][this.getColCount() + colorMatrix.getColCount()]; + int index = -1; + for (Color[] re : res) { + ASClass.mergeArray(re, colors1[++index], colors2[index]); + } + return ColorMatrix.parse(res); + } + Color[][] colors1 = this.copyToNewArrays(); + Color[][] colors2 = colorMatrix.copyToNewArrays(); + if (colors1.length != colors2.length) { + throw new OperatorOperationException("銝銝餈賢拚萄笆鞊⊿閬靽啁詨嚗"); + } + Color[][] res = new Color[colors1.length + colors2.length][]; + ASClass.mergeArray(res, colors1, colors2); + return ColorMatrix.parse(res); + } + + /** + * 撠曉拚萎葉摰憸脫湔唳啣潛拚菔瑕啜 + * + * @param colorMode 閬鋡怨瑕圈脤蝻 + * @return 撖孵憸脤憸脫啣潛憸脩拚萄笆鞊∼ + */ + public final IntegerMatrix getChannel(int colorMode) { + int[][] res = new int[this.getRowCount()][this.getColCount()]; + int y = -1; + for (Color[] colors : this.toArrays()) { + int[] re = res[++y]; + int x = -1; + for (Color color : colors) { + re[++x] = (color.getRGB() >> colorMode) & 0xFF; + } + } + return IntegerMatrix.parse(res); + } + + /** + * 拚萎葉蝏嗡銝芰拚萸 + * + * @param start 拚萇撌虫閫撖寡情 + * @param end 拚萇喃閫撖寡情 + * @param color 蝏嗥頧桀憸脣笆鞊∼ + */ + public void drawRectangle(IntegerCoordinateTwo start, IntegerCoordinateTwo end, Color color) { + Color[][] colors = this.toArrays(); + int x1 = start.getX(); + int x2 = end.getX(); + int y1 = start.getY(); + int y2 = end.getY(); + // 擐撠韏瑕蝏甇Y寧 x 頧游港蛹 color 憸莎雿輻肘頧渲瑕嚗 + Color[] color1 = colors[start.getY()]; + Color[] color2 = colors[end.getY()]; + for (int i = x1; i <= x2; i++) { + color1[i] = color; + color2[i] = color; + } + // 嗅撠拐寧 y 頧游銝 color 憸莎雿輻肝頧渲瑕嚗 + for (int i = y1; i <= y2; i++) { + Color[] colorRow = colors[i]; + colorRow[x1] = color; + colorRow[x2] = color; + } + } + + /** + * 撠曉餈銵璅⊥踹寥霈∠ + * + * @param distanceAlgorithm 閬雿輻函摨阡霈∠蝏隞嗚 + *

+ * The metric calculation component that needs to be used. + * @param template 刻銵璅⊥踹寥嗥鋡怠寥璅⊥踴 + *

+ * The template to be matched during template matching. + * @param channel 刻銵霈∠塚閬鋡怨恣蝞憸脤 + *

+ * When calculating, the color channel to be calculated is required. + * @param sep 曉瑞妖甇仿踵啣潦霂交啣澆嚗隡憓撘箄恣蝞摨虫扯踝霂交啣潛撠嚗隡憓撘箄恣蝞蝎曄&摨艾 + *

+ * Image convolution step size value. An increase in this value will enhance the speed and performance of the calculation, while a decrease in this value will enhance the accuracy of the calculation. + * @param isMAX 憒霈曄蔭銝 true 隞銵典訾撮摨衣頂唳憭抒摮曉雿銝箝 + *

+ * If set to true, the coordinate of the sub image with the largest similarity coefficient is taken as the coordinate. + * @return 蝏餈霈∠銋嚗銝敶拚萄笆鞊⊥訾撮摮曉撌虫閫啣澆笆鞊∼ + */ + public final Map.Entry templateMatching(DistanceAlgorithm distanceAlgorithm, ColorMatrix template, int channel, int sep, boolean isMAX) { + // 撘憪寥 + IntegerMatrix channel1 = template.getChannel(channel); + IntegerMatrix channel2 = this.getChannel(channel); + // 擐箇拚1銝剔詨憭批摮拚萄曉 + int rowCount1 = this.getRowCount(); + int colCount1 = this.getColCount(); + int rowCount2 = template.getRowCount(); + int colCount2 = template.getColCount(); + if (rowCount1 < rowCount2 || colCount1 < colCount2) { + throw new OperatorOperationException("函璅⊥輻拚萄偕撖貉憭!!"); + } + int[] xy = new int[2]; + double value = isMAX ? Integer.MIN_VALUE : Integer.MAX_VALUE; + + if (rowCount1 == rowCount2) { + // 餈蝘萎誨銵典臭誑雿輻其寞 + int ye = rowCount2 - 1; + for (int y = 0; y < rowCount1; y += sep, ye += sep) { + double trueDistance = distanceAlgorithm.getTrueDistance(channel2.extractSrcMat(y, ye), channel1); + if (isMAX) { + if (value < trueDistance) { + value = trueDistance; + xy[1] = y; + } + } else { + if (value > trueDistance) { + value = trueDistance; + xy[1] = y; + } + } + } + return new AbstractMap.SimpleEntry<>(value, new IntegerCoordinateTwo(xy[0], xy[1])); + } + int ye = rowCount2 - 1; + for (int y = 0; ye < rowCount1; y += sep, ye += sep) { + int xe = colCount2 - 1; + for (int x = 0; xe < colCount1; x += sep, xe += sep) { + // 霈∠箇訾撮摨 + double trueDistance = distanceAlgorithm.getTrueDistance(channel2.extractMat(x, y, xe, ye), channel1); + if (isMAX) { + if (value < trueDistance) { + value = trueDistance; + xy[0] = x; + xy[1] = y; + } + } else { + if (value > trueDistance) { + value = trueDistance; + xy[0] = x; + xy[1] = y; + } + } + } + } + return new AbstractMap.SimpleEntry<>(value, new IntegerCoordinateTwo(xy[0], xy[1])); + } + + /** + * @param distanceAlgorithm 閬雿輻函摨阡霈∠蝏隞嗚 + *

+ * The metric calculation component that needs to be used. + * @param template 刻銵璅⊥踹寥嗥鋡怠寥璅⊥踴 + *

+ * The template to be matched during template matching. + * @param channel 刻銵霈∠塚閬鋡怨恣蝞憸脤 + *

+ * When calculating, the color channel to be calculated is required. + * @param sep 曉瑞妖甇仿踵啣潦霂交啣澆嚗隡憓撘箄恣蝞摨虫扯踝霂交啣潛撠嚗隡憓撘箄恣蝞蝎曄&摨艾 + *

+ * Image convolution step size value. An increase in this value will enhance the speed and performance of the calculation, while a decrease in this value will enhance the accuracy of the calculation. + * @param cFilter 訾撮蝟餅啗皛日餉摰堆刻典臭誑芸銋銋血訾撮摨衣頂啁餈皛斗雿嚗蝚血蝟餅啣笆摨靽⊥臬隡鋡急溶啁唳桐葉 + * @return 曉銝剜蝚血餈皛斗∩辣摮拚萎縑舀唳桀笆鞊∼ + *

+ * All sub matrix information data objects in the image that meet the filtering conditions. + */ + public final ArrayList> templateMatching(DistanceAlgorithm distanceAlgorithm, ColorMatrix template, int channel, int sep, DoubleFiltering cFilter) { + // 撘憪寥 + IntegerMatrix channel1 = template.getChannel(channel); + IntegerMatrix channel2 = this.getChannel(channel); + // 擐箇拚1銝剔詨憭批摮拚萄曉 + int rowCount1 = this.getRowCount(), colCount1 = this.getColCount(); + int rowCount2 = template.getRowCount(), colCount2 = template.getColCount(); + if (rowCount1 < rowCount2 || colCount1 < colCount2) { + throw new OperatorOperationException("函璅⊥輻拚萄偕撖貉憭!!"); + } + ArrayList> res = new ArrayList<>(); + if (rowCount1 == rowCount2) { + // 餈蝘萎誨銵典臭誑雿輻其寞 + int ye = rowCount2 - 1; + for (int y = 0; y < rowCount1; y += sep, ye += sep) { + double trueDistance = distanceAlgorithm.getTrueDistance(channel2.extractSrcMat(y, ye), channel1); + if (cFilter.isComplianceEvents(trueDistance)) + res.add(new AbstractMap.SimpleEntry<>(trueDistance, new IntegerCoordinateTwo(0, y))); + } + return res; + } + // 餈撠曹誨銵其賢雿輻其寞 + int ye = rowCount2 - 1; + for (int y = 0; ye < rowCount1; y += sep, ye += sep) { + int xe = colCount2 - 1; + for (int x = 0; xe < colCount1; x += sep, xe += sep) { + // 霈∠箇訾撮摨 + double trueDistance = distanceAlgorithm.getTrueDistance(channel2.extractMat(x, y, xe, ye), channel1); + if (cFilter.isComplianceEvents(trueDistance)) + res.add(new AbstractMap.SimpleEntry<>(trueDistance, new IntegerCoordinateTwo(x, y))); + } + } + return res; + } + /** * 撠曉拚萄蝷箏箸伐雿踹函拚萇曉唳株賢鋡怠蝷箏箸乓 *

@@ -1282,21 +1877,26 @@ public void save(String path, char sep) { */ @Override public void save(File path, char sep) { - ASIO.writer(path, (stream) -> { - try { - int rowCount = 0; - for (Color[] colors : this.toArrays()) { - stream.write(String.valueOf(++rowCount)); - for (Color color : colors) { - stream.write(sep); - stream.write(String.valueOf(color.getRGB())); - } - stream.newLine(); - } - } catch (IOException e) { - throw new OperatorOperationException("Write data exception!", e); - } - }); + ASIO.writer(path, getSAVE_TEXT(this, sep)); + } + + /** + * 撠撖寡情鈭斤梁洵銝寞唳株箇隞嗉銵唳桃颲箝 + *

+ * Submit the object to a third-party data output component for data output. + * + * @param outputComponent 蝚砌寞唳株箄挽憭撖寡情摰啜 + *

+ * Implementation of third-party data output device objects. + */ + @Override + public void save(OutputComponent outputComponent) { + if (!outputComponent.isOpen()) { + if (!outputComponent.open()) + throw new OperatorOperationException("函唳株箇隞嗆撘憭梯揖\nYour data output component failed to open."); + } + outputComponent.writeImage(this); + ASIO.close(outputComponent); } /** @@ -1319,20 +1919,7 @@ public void save(File path, char sep) { * ASCII Symbol In the output ASCII image file, the ASCII value corresponding to the constituent characters of the image for coordinates that are less than the threshold value. */ public void save(File path, byte Mode, int colorBoundary, char imageAscii1, char imageAscii2) { - ASIO.writer(path, bufferedWriter -> { - try { - for (Color[] colors : this.toArrays()) { - for (Color color : colors) { - if (((color.getRGB() >> Mode) & 0xFF) > colorBoundary) { - bufferedWriter.write(imageAscii1); - } else bufferedWriter.write(imageAscii2); - } - bufferedWriter.newLine(); - } - } catch (IOException e) { - throw new OperatorOperationException("Write data exception!", e); - } - }); + ASIO.writer(path, getSAVE_ASCII(this, Mode, colorBoundary, imageAscii1, imageAscii2)); } /** diff --git a/src_code/src/main/java/zhao/algorithmMagic/operands/matrix/ColumnDoubleMatrix.java b/src_code/src/main/java/zhao/algorithmMagic/operands/matrix/ColumnDoubleMatrix.java index 285c828..6e11a16 100644 --- a/src_code/src/main/java/zhao/algorithmMagic/operands/matrix/ColumnDoubleMatrix.java +++ b/src_code/src/main/java/zhao/algorithmMagic/operands/matrix/ColumnDoubleMatrix.java @@ -2,6 +2,7 @@ import zhao.algorithmMagic.core.ASDynamicLibrary; import zhao.algorithmMagic.exception.OperatorOperationException; +import zhao.algorithmMagic.io.OutputComponent; import zhao.algorithmMagic.operands.RCNOperands; import zhao.algorithmMagic.operands.vector.DoubleVector; import zhao.algorithmMagic.utils.ASClass; @@ -677,4 +678,23 @@ public void save(File path, char sep) { } }); } + + /** + * 撠撖寡情鈭斤梁洵銝寞唳株箇隞嗉銵唳桃颲箝 + *

+ * Submit the object to a third-party data output component for data output. + * + * @param outputComponent 蝚砌寞唳株箄挽憭撖寡情摰啜 + *

+ * Implementation of third-party data output device objects. + */ + @Override + public void save(OutputComponent outputComponent) { + if (!outputComponent.isOpen()) { + if (!outputComponent.open()) + throw new OperatorOperationException("函唳株箇隞嗆撘憭梯揖\nYour data output component failed to open."); + } + outputComponent.writeMat(this); + ASIO.close(outputComponent); + } } diff --git a/src_code/src/main/java/zhao/algorithmMagic/operands/matrix/ColumnIntegerMatrix.java b/src_code/src/main/java/zhao/algorithmMagic/operands/matrix/ColumnIntegerMatrix.java index 7549490..b863083 100644 --- a/src_code/src/main/java/zhao/algorithmMagic/operands/matrix/ColumnIntegerMatrix.java +++ b/src_code/src/main/java/zhao/algorithmMagic/operands/matrix/ColumnIntegerMatrix.java @@ -2,6 +2,7 @@ import zhao.algorithmMagic.core.ASDynamicLibrary; import zhao.algorithmMagic.exception.OperatorOperationException; +import zhao.algorithmMagic.io.OutputComponent; import zhao.algorithmMagic.operands.RCNOperands; import zhao.algorithmMagic.operands.vector.IntegerVector; import zhao.algorithmMagic.utils.ASClass; @@ -672,4 +673,23 @@ public void save(File path, char sep) { } }); } + + /** + * 撠撖寡情鈭斤梁洵銝寞唳株箇隞嗉銵唳桃颲箝 + *

+ * Submit the object to a third-party data output component for data output. + * + * @param outputComponent 蝚砌寞唳株箄挽憭撖寡情摰啜 + *

+ * Implementation of third-party data output device objects. + */ + @Override + public void save(OutputComponent outputComponent) { + if (!outputComponent.isOpen()) { + if (!outputComponent.open()) + throw new OperatorOperationException("函唳株箇隞嗆撘憭梯揖\nYour data output component failed to open."); + } + outputComponent.writeMat(this); + ASIO.close(outputComponent); + } } diff --git a/src_code/src/main/java/zhao/algorithmMagic/operands/matrix/DoubleMatrix.java b/src_code/src/main/java/zhao/algorithmMagic/operands/matrix/DoubleMatrix.java index ab7e6df..b997219 100644 --- a/src_code/src/main/java/zhao/algorithmMagic/operands/matrix/DoubleMatrix.java +++ b/src_code/src/main/java/zhao/algorithmMagic/operands/matrix/DoubleMatrix.java @@ -185,6 +185,15 @@ public static DoubleMatrix parse(DataFrame dataFrame, int height, int width) { return parse(doubles); } + public static DoubleMatrix parse(IntegerMatrix parse1) { + double[][] doubles = new double[parse1.getRowCount()][]; + int index = -1; + for (int[] ints : parse1.toArrays()) { + doubles[++index] = ASClass.IntArray_To_DoubleArray(ints); + } + return new DoubleMatrix(doubles.length, parse1.getColCount(), doubles); + } + /** * 瑕啁拚萎葉摰寧啣 * @@ -315,15 +324,11 @@ public DoubleMatrix diff(DoubleMatrix value) { @Override public Double moduleLength() { double res = 0; - int rowPointer = this.RowPointer; - PointerReset(); - while (this.MovePointerDown()) { - double[] doubles1 = this.toArray(); - for (double v : doubles1) { - res += ASMath.Power2(v); + for (double[] ints : this.toArrays()) { + for (double anInt : ints) { + res += anInt * anInt; } } - this.RowPointer = rowPointer; return res; } @@ -632,6 +637,32 @@ public DoubleMatrix extractMat(int x1, int y1, int x2, int y2) { return DoubleMatrix.parse(colors); } + /** + * 箏拚萄笆鞊 + * + * @param y1 鋡急拚萄典拚萎葉韏瑕嫘 + *

+ * The starting coordinate point of the extracted matrix in the original matrix. + * @param y2 鋡急拚萄典拚萎葉蝏甇W嫘 + *

+ * The end coordinate point of the extracted matrix in the original matrix. + * @return 游耦拚萄笆鞊∩葉摮拚萄笆鞊∼ + */ + @Override + public DoubleMatrix extractSrcMat(int y1, int y2) { + if (y1 >= y2) { + throw new OperatorOperationException("游耦拚菜霂荔刻挽蝵桃寞霂!!!\nAn error occurred in mat extraction. The extraction coordinate point you set is incorrect!!!\n" + + "ERROR => (" + y1 + ") >= (" + y2 + ')'); + } + double[][] res_colors = new double[y2 - y1][]; + double[][] colors1 = this.toArrays(); + int index = -1; + for (int i = y1; i < y2; i++) { + res_colors[++index] = colors1[i]; + } + return DoubleMatrix.parse(res_colors); + } + @Override protected void reFresh() { this.PointerReset(); diff --git a/src_code/src/main/java/zhao/algorithmMagic/operands/matrix/IntegerMatrix.java b/src_code/src/main/java/zhao/algorithmMagic/operands/matrix/IntegerMatrix.java index f3eb817..633108a 100644 --- a/src_code/src/main/java/zhao/algorithmMagic/operands/matrix/IntegerMatrix.java +++ b/src_code/src/main/java/zhao/algorithmMagic/operands/matrix/IntegerMatrix.java @@ -338,15 +338,11 @@ protected void reFresh() { @Override public Integer moduleLength() { int res = 0; - int rowPointer = this.RowPointer; - PointerReset(); - while (this.MovePointerDown()) { - int[] ints = toArray(); - for (int v : ints) { - res += ASMath.Power2(v); + for (int[] ints : this.toArrays()) { + for (int anInt : ints) { + res += anInt * anInt; } } - this.RowPointer = rowPointer; return res; } @@ -629,7 +625,7 @@ public IntegerMatrix deleteRelatedDimensions(int index, double thresholdLeft, do public IntegerMatrix extractMat(int x1, int y1, int x2, int y2) { if (x1 >= x2 || y1 >= y2) { throw new OperatorOperationException("游耦拚菜霂荔刻挽蝵桃寞霂!!!\nAn error occurred in mat extraction. The extraction coordinate point you set is incorrect!!!\n" + - "ERROR => (" + x1 + ',' + x2 + ") >= (" + x2 + ',' + y2 + ')'); + "ERROR => (" + x1 + ',' + y1 + ") >= (" + x2 + ',' + y2 + ')'); } if (x2 >= this.getColCount() || y2 >= this.getRowCount()) { throw new OperatorOperationException("游耦拚菜霂荔其賣銝摮其拚萎葉鈾nAn error occurred in mat extraction. You cannot extract coordinate points that do not exist in the image\n" + @@ -644,6 +640,32 @@ public IntegerMatrix extractMat(int x1, int y1, int x2, int y2) { return IntegerMatrix.parse(colors); } + /** + * 箏拚萄笆鞊 + * + * @param y1 鋡急拚萄典拚萎葉韏瑕嫘 + *

+ * The starting coordinate point of the extracted matrix in the original matrix. + * @param y2 鋡急拚萄典拚萎葉蝏甇W嫘 + *

+ * The end coordinate point of the extracted matrix in the original matrix. + * @return 游耦拚萄笆鞊∩葉摮拚萄笆鞊∼ + */ + @Override + public IntegerMatrix extractSrcMat(int y1, int y2) { + if (y1 >= y2) { + throw new OperatorOperationException("游耦拚菜霂荔刻挽蝵桃寞霂!!!\nAn error occurred in mat extraction. The extraction coordinate point you set is incorrect!!!\n" + + "ERROR => (" + y1 + ") >= (" + y2 + ')'); + } + int[][] res_colors = new int[y2 - y1][]; + int[][] colors1 = this.toArrays(); + int index = -1; + for (int i = y1; i < y2; i++) { + res_colors[++index] = colors1[i]; + } + return IntegerMatrix.parse(res_colors); + } + /** * 撠唳格蝏湔斤啁撌衣宏n銝芯蝵殷撟嗉瑕啁啣 *

diff --git a/src_code/src/main/java/zhao/algorithmMagic/operands/matrix/NumberMatrix.java b/src_code/src/main/java/zhao/algorithmMagic/operands/matrix/NumberMatrix.java index 1c079ef..5ebd82e 100644 --- a/src_code/src/main/java/zhao/algorithmMagic/operands/matrix/NumberMatrix.java +++ b/src_code/src/main/java/zhao/algorithmMagic/operands/matrix/NumberMatrix.java @@ -78,4 +78,17 @@ protected NumberMatrix(int rowCount, int colCount, ArraysType arraysType) { * @return 游耦拚萄笆鞊∩葉摮拚萄笆鞊∼ */ public abstract ImplementationType extractMat(int x1, int y1, int x2, int y2); + + /** + * 箏拚萄笆鞊 + * + * @param y1 鋡急拚萄典拚萎葉韏瑕嫘 + *

+ * The starting coordinate point of the extracted matrix in the original matrix. + * @param y2 鋡急拚萄典拚萎葉蝏甇W嫘 + *

+ * The end coordinate point of the extracted matrix in the original matrix. + * @return 游耦拚萄笆鞊∩葉摮拚萄笆鞊∼ + */ + public abstract ImplementationType extractSrcMat(int y1, int y2); } diff --git a/src_code/src/main/java/zhao/algorithmMagic/operands/matrix/RectangleMatrix.java b/src_code/src/main/java/zhao/algorithmMagic/operands/matrix/RectangleMatrix.java new file mode 100644 index 0000000..b7a4b54 --- /dev/null +++ b/src_code/src/main/java/zhao/algorithmMagic/operands/matrix/RectangleMatrix.java @@ -0,0 +1,148 @@ +package zhao.algorithmMagic.operands.matrix; + +import java.awt.*; +import java.util.Arrays; + +/** + * 曉颲寧拚萄笆鞊∴霂亙笆鞊∩其撖孵曉颲寧撖寡情餈銵銝鈭寞雿嚗刻典臭誑湔交扯嗡葉颲寧霈∠賣堆游末典曉颲寧霈∠銝剜靘臬末 + *

+ * Image edge matrix object, which is specially used to carry out some special operations on image edge objects. Here you can directly execute the edge computing function to better provide good results in image edge computing. + * + * @author 韏萄摰 + * 2023/3/30 16:53 + */ +public class RectangleMatrix extends ColorMatrix { + + private final int outlineWidthL; + private final int outlineHeightR; + private final int outlineWidthR; + private final int outlineHeightL; + + /** + * 銝銝芣摰銵唳桃拚萄笆鞊∴嗡葉銵憭批澆隡暺霈支蝙刻圈 + *

+ * Construct a matrix object with specified row and column data. The maximum value of row pointer will use the number of rows by default. + * + * @param rowCount 拚萎葉銵圈 + *

+ * the number of rows in the matrix + * @param colCount 拚萎葉圈 + *

+ * the number of cols in the matrix + * @param colors 霂亦拚萄笆鞊∩葉鈭蝏湔啁撖寡情 + * @param isGrayscale 憒霈曄蔭銝演rue 隞銵冽迨曉舐啣漲曉 + * @param outlineWidthL 拙耦韏瑕摰賢漲蝝W + * @param outlineWidthR 拙耦蝏甇W捐摨衣揣撘 + * @param outlineHeightL 拙耦韏瑕擃摨衣揣撘 + * @param outlineHeightR 拙耦蝏甇a摨衣揣撘 + */ + protected RectangleMatrix(int rowCount, int colCount, Color[][] colors, boolean isGrayscale, int outlineWidthL, int outlineHeightR, int outlineWidthR, int outlineHeightL) { + super(rowCount, colCount, colors, isGrayscale); + this.outlineWidthL = outlineWidthL; + this.outlineHeightR = outlineHeightR; + this.outlineWidthR = outlineWidthR; + this.outlineHeightL = outlineHeightL; + } + + /** + * 撠銝銝芸曉拚萎葉頧桀撖寡情瑕 + * + * @param colorMatrix 閬鋡急曉拚萄笆鞊 + * @param rectColor 拚萄笆鞊∠頧桀憸脣笆鞊 + * @return 憭曉頧桀撖寡情 + */ + public static RectangleMatrix parse(ColorMatrix colorMatrix, Color rectColor) { + // 撠頧桀擃摨虫摰賢漲霈∠箸 + int outlineWidthL = colorMatrix.getColCount() - 1; + int outlineHeightL = colorMatrix.getRowCount() - 1; + int outlineHeightR = 0; + int outlineWidthR = 0; + // 瑕啗絲憪銝蝏甇Y揣撘 + boolean isH = false; + boolean isW = false; + int rc = -1; + for (Color[] colors : colorMatrix.toArrays()) { + ++rc; + boolean isRw = false; + int cc = -1; + boolean isOk = false; + for (Color color : colors) { + ++cc; + // 斗剖捐 + if (color.getRGB() != 0xff000000) { + isOk = true; + if (!isRw && cc < outlineWidthL) { + outlineWidthL = cc; + outlineWidthR = cc; + isW = true; + isRw = true; + } + if (isW) { + if (cc > outlineWidthR) outlineWidthR = cc; + } + } + } + // 斗剝 + if (isOk) { + if (isH) { + if (rc > outlineHeightR) outlineHeightR = rc; + } else if (rc < outlineHeightL) { + outlineHeightL = rc; + outlineHeightR = rc; + isH = true; + } + } + } + // 批捐擃銝銝芰拚 + Color[][] colors = new Color[colorMatrix.getRowCount()][colorMatrix.getColCount()]; + for (Color[] color : colors) { + Arrays.fill(color, Color.BLACK); + } + Color[] row = new Color[colorMatrix.getColCount()]; + Arrays.fill(row, Color.BLACK); + for (int i = outlineWidthL; i <= outlineWidthR; i++) { + row[i] = rectColor; + } + colors[outlineHeightL] = row; + colors[outlineHeightR] = row; + for (int i = outlineHeightL, colorsLength = outlineHeightR; i <= colorsLength; i++) { + Color[] color = colors[i]; + color[outlineWidthL] = rectColor; + color[outlineWidthR] = rectColor; + } + return new RectangleMatrix( + colorMatrix.getRowCount(), + colorMatrix.getColCount(), + colors, + false, + outlineWidthL, outlineHeightL, + outlineWidthR, outlineHeightR + ); + } + + public int getOutlineWidthL() { + return outlineWidthL; + } + + public int getOutlineHeightR() { + return outlineHeightR; + } + + public int getOutlineWidthR() { + return outlineWidthR; + } + + public int getOutlineHeightL() { + return outlineHeightL; + } + + @Override + public String toString() { + return "RectangleMatrix{" + + "outlineWidthL=" + getOutlineWidthL() + + ", outlineWidthR=" + getOutlineWidthR() + + ", outlineHeightL=" + getOutlineHeightL() + + ", outlineHeightR=" + getOutlineHeightR() + + '}'; + } +} diff --git a/src_code/src/main/java/zhao/algorithmMagic/operands/matrix/SaveMatrix.java b/src_code/src/main/java/zhao/algorithmMagic/operands/matrix/SaveMatrix.java index 8de93d2..cf9c386 100644 --- a/src_code/src/main/java/zhao/algorithmMagic/operands/matrix/SaveMatrix.java +++ b/src_code/src/main/java/zhao/algorithmMagic/operands/matrix/SaveMatrix.java @@ -1,5 +1,7 @@ package zhao.algorithmMagic.operands.matrix; +import zhao.algorithmMagic.io.OutputComponent; + import java.io.File; /** @@ -50,4 +52,15 @@ public interface SaveMatrix { * Separator used when saving. */ void save(File path, char sep); + + /** + * 撠撖寡情鈭斤梁洵銝寞唳株箇隞嗉銵唳桃颲箝 + *

+ * Submit the object to a third-party data output component for data output. + * + * @param outputComponent 蝚砌寞唳株箄挽憭撖寡情摰啜 + *

+ * Implementation of third-party data output device objects. + */ + void save(OutputComponent outputComponent); } diff --git a/src_code/src/main/java/zhao/algorithmMagic/operands/table/Cell.java b/src_code/src/main/java/zhao/algorithmMagic/operands/table/Cell.java index bb6c596..d996085 100644 --- a/src_code/src/main/java/zhao/algorithmMagic/operands/table/Cell.java +++ b/src_code/src/main/java/zhao/algorithmMagic/operands/table/Cell.java @@ -3,6 +3,7 @@ import zhao.algorithmMagic.operands.Operands; import java.io.Serializable; +import java.util.Date; /** * 潭唳桃掩嚗霂交唳桃掩鋡 Multi-type 拚菜雿輻剁撟嗉銵詨笆摨憭銝雿 @@ -33,6 +34,13 @@ public interface Cell extends Serializable, Operands> { */ int getIntValue(); + /** + * @return 敶潔葉摮函湔唳啣潛掩嚗霂交雿餈撠銝臬撖寡情 + *

+ * The integer numeric type stored in the current cell. This operation will not return the original object. + */ + long getLongValue(); + /** * @return 敶潔葉摮函Double啣潛掩嚗霂交雿餈撠銝臬撖寡情 *

@@ -40,6 +48,13 @@ public interface Cell extends Serializable, Operands> { */ double getDoubleValue(); + /** + * @return 敶潔葉摮函 Date 啣潛掩嚗霂交雿餈撠銝臬撖寡情 + *

+ * The Date numeric type stored in the current cell. This operation will not return the original object. + */ + Date getDate(); + /** * @return 敶潔葉摮函摮蝚虫葡啣潛掩嚗霂交雿餈撠銝臬撖寡情 *

diff --git a/src_code/src/main/java/zhao/algorithmMagic/operands/table/DataFrame.java b/src_code/src/main/java/zhao/algorithmMagic/operands/table/DataFrame.java index 8ee0f37..98d8ce4 100644 --- a/src_code/src/main/java/zhao/algorithmMagic/operands/table/DataFrame.java +++ b/src_code/src/main/java/zhao/algorithmMagic/operands/table/DataFrame.java @@ -1,8 +1,11 @@ package zhao.algorithmMagic.operands.table; +import zhao.algorithmMagic.io.OutputComponent; import zhao.algorithmMagic.operands.Operands; import zhao.algorithmMagic.utils.transformation.Transformation; +import java.io.BufferedWriter; +import java.io.PrintStream; import java.io.Serializable; import java.util.List; @@ -255,6 +258,34 @@ public interface DataFrame extends AggDataFrameData, Iterable, Serializa */ DataFrame into_outHtml(String outPath, String tableName); + /** + * 撠霈∠蝏靘蝏摰唳株箇隞嗉銵唳桃颲箸雿嚗 + * + * @param outputComponent 颲箸唳桅閬雿輻函唳株箇隞 + * @return 颲箔隡餈唳桅祈澈嚗銝隡蝏甇Z具 + *

+ * After output, the data set itself will be returned and the call will not be terminated. + */ + DataFrame into_outComponent(OutputComponent outputComponent); + + /** + * 暺霈斗孵亦 DF 唳桀笆鞊∩葉唳柴 + *

+ * The default method is to view data in DF data objects. + */ + void show(); + + /** + * 摰唳格孵亦 DF 唳桀笆鞊∩葉唳殷霂交雿撠隡雿踹 DF 唳株◤颲箏唳唳格銝准 + *

+ * Specify the method of viewing data in the DF data object through a data stream, which will cause the DF data to be output into the data stream. + * + * @param bufferedWriter 閬隡唳桃唳格撖寡情 + */ + void show(BufferedWriter bufferedWriter); + + void show(PrintStream printStream); + /** * 撠DF撖寡情銝剔唳株蓮X銝箔銝泓ist摰孵具 *

diff --git a/src_code/src/main/java/zhao/algorithmMagic/operands/table/DataFrameBuilder.java b/src_code/src/main/java/zhao/algorithmMagic/operands/table/DataFrameBuilder.java index c3d4371..043f3a9 100644 --- a/src_code/src/main/java/zhao/algorithmMagic/operands/table/DataFrameBuilder.java +++ b/src_code/src/main/java/zhao/algorithmMagic/operands/table/DataFrameBuilder.java @@ -15,6 +15,14 @@ public interface DataFrameBuilder { */ Mode getInMode(); + /** + * 霈曄蔭霂餃唳格園閬雿輻函蝚艾刻粉銝銝芣隞嗅笆鞊∠嗅隡 + * + * @param sep 摰唳桀蝚佗霂亙蝚血隡刻粉嗅鋡怨其瑕嚗蝏霈∠箇泵∩辣唳株撖寡情 + * @return 曉靚 + */ + FDataFrameBuilder setSep(char sep); + /** * 撠摰唳格亥砭箸 * diff --git a/src_code/src/main/java/zhao/algorithmMagic/operands/table/FDataFrame.java b/src_code/src/main/java/zhao/algorithmMagic/operands/table/FDataFrame.java index cbf958c..154d45e 100644 --- a/src_code/src/main/java/zhao/algorithmMagic/operands/table/FDataFrame.java +++ b/src_code/src/main/java/zhao/algorithmMagic/operands/table/FDataFrame.java @@ -1,12 +1,16 @@ package zhao.algorithmMagic.operands.table; import zhao.algorithmMagic.exception.OperatorOperationException; +import zhao.algorithmMagic.io.InputComponent; +import zhao.algorithmMagic.io.OutputComponent; import zhao.algorithmMagic.utils.ASIO; import zhao.algorithmMagic.utils.ASMath; import zhao.algorithmMagic.utils.transformation.Transformation; +import java.io.BufferedWriter; import java.io.File; import java.io.IOException; +import java.io.PrintStream; import java.sql.Connection; import java.util.*; @@ -91,6 +95,41 @@ public static FDataFrame select(Series colNameRow, int pk) { ).refreshField(false, true); } + /** + * 雿輻函洵銝寞唳格颲亦隞嗉銵唳桃頧踝撟嗉瑕啣笆摨DataFrame撖寡情 + * + * @param inputComponent 閬雿輻函蝚砌寞唳株亦隞嗅笆鞊 + * @return 瑕啁DataFrame撖寡情 + */ + public static DataFrame builder(InputComponent inputComponent) { + if (inputComponent.open()) { + DataFrame dataFrame = inputComponent.getDataFrame(); + ASIO.close(inputComponent); + return dataFrame; + } + throw new OperatorOperationException("inputComponent open error!!!"); + } + + /** + * 雿輻函洵銝寞唳格颲亦隞嗉銵唳桃頧踝撟嗉瑕啣笆摨DataFrame撖寡情 + * + * @param inputComponent 閬雿輻函蝚砌寞唳株亦隞嗅笆鞊 + * @param isOC 憒霈曄蔭銝 true 隞銵冽唳株亥挽憭撖寡情撘銝喲凋漱望嗥恣嚗典撠銝閬撖寧隞嗉銵撘喲剜雿嚗銋隞銵冽嗅芯蝙函隞塚雿銝隡撘銝喲剔隞嗅笆鞊∼ + *

+ * If set to true, it means that the opening and closing of data input device objects are managed by the framework, and there will be no need to open or close components externally. Conversely, it means that the framework only uses components, but will not open or close component objects. + * @return 瑕啁DataFrame撖寡情 + */ + public static DataFrame builder(InputComponent inputComponent, boolean isOC) { + if (isOC) { + if (inputComponent.open()) { + DataFrame dataFrame = inputComponent.getDataFrame(); + ASIO.close(inputComponent); + return dataFrame; + } + throw new OperatorOperationException("inputComponent open error!!!"); + } else return inputComponent.getDataFrame(); + } + /** * 瑟啣畾菜唳殷冽唳桅銝剖恍撖寡摮畾萄蝘唳撱箇蝝WHash銵剁玖ash銵其葉摮畾菜嗅臭誑餈銵瑟啁嚗蝏餈瑟唬嚗摮畾萄銝隡瘨憭梧臭啣畾萄勗銝銝芣唳株嚗銝祆亥秩嚗銝湔寡摮畾萇萎撠銝隡靚刻砲賣啜 *

@@ -197,6 +236,9 @@ public DataFrame desc() { */ @Override public DataFrame select(String... colNames) { + if (colNames.length == 1 && "*".equals(colNames[0])) { + return this; + } ArrayList arrayList = new ArrayList<>(list.size() + 4); int[] index = new int[colNames.length]; { @@ -643,6 +685,109 @@ public DataFrame into_outHtml(String outPath, String tableName) { return this; } + /** + * 撠霈∠蝏靘蝏摰唳株箇隞嗉銵唳桃颲箸雿嚗 + * + * @param outputComponent 颲箸唳桅閬雿輻函唳株箇隞 + * @return 颲箔隡餈唳桅祈澈嚗銝隡蝏甇Z具 + *

+ * After output, the data set itself will be returned and the call will not be terminated. + */ + @Override + public DataFrame into_outComponent(OutputComponent outputComponent) { + if (outputComponent.open()) { + outputComponent.writeDataFrame(this); + ASIO.close(outputComponent); + } else throw new OperatorOperationException("into_outComponent(OutputComponent outputComponent) error!!!"); + return this; + } + + /** + * 暺霈斗孵亦 DF 唳桀笆鞊∩葉唳柴 + *

+ * The default method is to view data in DF data objects. + */ + @Override + public void show() { + this.show(System.out); + } + + /** + * 湔亙刻箸銝剖曇”銝剔唳桀蝷箏箸伐貉鈭 toString 霂亙賣唳扯賣游隡蝘 + * + * @param bufferedWriter 閬雿輻函唳株箸 + */ + @Override + public void show(BufferedWriter bufferedWriter) { + StringBuilder split = new StringBuilder(); + StringBuilder field = new StringBuilder(); + String s; + try { + s = getFieldRowStr(split, field); + bufferedWriter.append('\n') + .append(s) + .append(field) + .append('\n') + .write(s); + for (Series cells : this.list) { + bufferedWriter.write("\t\t"); + for (Cell cell : cells) { + bufferedWriter + .append(cell.getValue().toString()) + .write("\t\t"); + } + bufferedWriter.write('\n'); + } + bufferedWriter.append(s); + } catch (IOException e) { + throw new OperatorOperationException(e); + } + } + + public final String getFieldRowStr(StringBuilder split, StringBuilder field) { + String s; + split.append(''); + field.append("\t\t"); + for (Cell cell : this.getFields()) { + field.append(cell.toString()); + field.append("\t\t"); + split.append(""); + } + split.append('').append('\n'); + s = split.toString(); + return s; + } + + /** + * 湔亙刻箸銝剖曇”銝剔唳桀蝷箏箸伐貉鈭 toString 霂亙賣唳扯賣游隡蝘 + * + * @param printStream 閬雿輻函唳株箸 + */ + @Override + public void show(PrintStream printStream) { + StringBuilder split = new StringBuilder(); + StringBuilder field = new StringBuilder(); + String s; + { + s = getFieldRowStr(split, field); + printStream.append('\n') + .append(s) + .append(field) + .append('\n') + .append(s); + } + for (Series cells : this.list) { + printStream.append("\t\t"); + for (Cell cell : cells) { + printStream + .append(cell.getValue().toString()) + .append("\t\t"); + } + printStream.append('\n'); + } + printStream.append(s); + } + /** * 撠DF撖寡情銝剔唳株蓮X銝箔銝泓ist摰孵具 *

diff --git a/src_code/src/main/java/zhao/algorithmMagic/operands/table/FDataFrameBuilder.java b/src_code/src/main/java/zhao/algorithmMagic/operands/table/FDataFrameBuilder.java index 5627f15..72576ad 100644 --- a/src_code/src/main/java/zhao/algorithmMagic/operands/table/FDataFrameBuilder.java +++ b/src_code/src/main/java/zhao/algorithmMagic/operands/table/FDataFrameBuilder.java @@ -74,6 +74,7 @@ public FDataFrameBuilder setColNames(String[] colNames) { * @param sep 摰唳桀蝚佗霂亙蝚血隡刻粉嗅鋡怨其瑕嚗蝏霈∠箇泵∩辣唳株撖寡情 * @return 曉靚 */ + @Override public FDataFrameBuilder setSep(char sep) { this.sep = sep; return this; diff --git a/src_code/src/main/java/zhao/algorithmMagic/operands/table/FinalCell.java b/src_code/src/main/java/zhao/algorithmMagic/operands/table/FinalCell.java index 1d98e28..1d6b074 100644 --- a/src_code/src/main/java/zhao/algorithmMagic/operands/table/FinalCell.java +++ b/src_code/src/main/java/zhao/algorithmMagic/operands/table/FinalCell.java @@ -3,6 +3,8 @@ import zhao.algorithmMagic.exception.OperatorOperationException; import zhao.algorithmMagic.utils.ASStr; +import java.util.Date; + /** * 銝臬啣潛澆笆鞊∴霂交唳桃掩撠臬其銝芸潘撟嗅霈詨嗥掩臬瑞 *

@@ -76,6 +78,20 @@ public final int getIntValue() { } } + /** + * @return 敶潔葉摮函湔唳啣潛掩嚗霂交雿餈撠銝臬撖寡情 + *

+ * The integer numeric type stored in the current cell. This operation will not return the original object. + */ + @Override + public final long getLongValue() { + if (isNumber()) { + return ((Number) this.valueType).longValue(); + } else { + throw new OperatorOperationException("典典霂撠銝銝芷啣潛潭扳湔啁孵嚗餈臭霈貊\nYou are trying to extract a non-numeric cell as an integer, which is not allowed."); + } + } + /** * @return 敶潔葉摮函Double啣潛掩嚗霂交雿餈撠銝臬撖寡情 *

@@ -90,6 +106,22 @@ public final double getDoubleValue() { } } + /** + * @return 敶潔葉摮函 Date 啣潛掩嚗霂交雿餈撠銝臬撖寡情 + *

+ * The Date numeric type stored in the current cell. This operation will not return the original object. + */ + @Override + public Date getDate() { + if (isNumber()) { + return new Date(this.getLongValue()); + } else { + if (this.valueType instanceof Date) return (Date) this.valueType; + else + throw new OperatorOperationException("冽瘜隞潔葉唳殷銝箏嗡撅鈭瘥怎啣潔銝撅鈭交撖寡情\nYou cannot extract data from a cell because it does not belong to a millisecond value or a date object."); + } + } + /** * @return 敶潔葉摮函摮蝚虫葡啣潛掩嚗霂交雿餈撠銝臬撖寡情 *

diff --git a/src_code/src/main/java/zhao/algorithmMagic/operands/vector/SparkVector.scala b/src_code/src/main/java/zhao/algorithmMagic/operands/vector/SparkVector.scala index 366e195..416767a 100644 --- a/src_code/src/main/java/zhao/algorithmMagic/operands/vector/SparkVector.scala +++ b/src_code/src/main/java/zhao/algorithmMagic/operands/vector/SparkVector.scala @@ -77,14 +77,6 @@ final class SparkVector(sparkContext: SparkContext, vector: org.apache.spark.mll else throw new OperatorOperationException("'DoubleVector1 innerProduct DoubleVector2' 塚銝支葵'DoubleVector'怎圈銝嚗DoubleVector1=[" + doubles1.length + "]嚗DoubleVector2=[" + doubles2.length + "]\n" + "When 'DoubleVector1 innerProduct DoubleVector2', the two vectors of 'DoubleVector' contain different quantities, DoubleVector1=[" + doubles1.length + "], DoubleVector2=[" + doubles2.length + "]") } - /** - * - * @return 撠砍笆鞊∩葉摮函摨啁瑁唬銝芣唳啁撟嗅唳啁餈嚗餈餈臭銝芣唳啁嚗舀靽格寧雿 - * - * Copy the vector sequence array stored in this object to a new array and return the new array. Here, a new array is returned, which supports modification and other operations. - */ - override def copyToNewArray(): Array[Double] = vector.toArray - /** * @return 霂亦掩摰啁掩撖寡情嚗其撅霂交亙摮蝐 */ @@ -115,13 +107,6 @@ final class SparkVector(sparkContext: SparkContext, vector: org.apache.spark.mll else throw new OperatorOperationException("'DoubleVector1 add DoubleVector2' 塚銝支葵'DoubleVector'怎圈銝嚗DoubleVector1=[" + numberOfDimensions1 + "]嚗DoubleVector2=[" + numberOfDimensions2 + "]\n" + "When 'DoubleVector1 add DoubleVector2', the two vectors of 'DoubleVector' contain different quantities, DoubleVector1=[" + numberOfDimensions1 + "], DoubleVector2=[" + numberOfDimensions2 + "]") } - /** - * @return 銝剖怎蝏游漲圈 - *

- * the number of dimensions contained in the vector - */ - override def getNumberOfDimensions: Int = size - /** * 其舅銝芣雿唬游撌桃寞嚗瑚冽霂瑕API霂湔 *

@@ -146,6 +131,21 @@ final class SparkVector(sparkContext: SparkContext, vector: org.apache.spark.mll else throw new OperatorOperationException("'DoubleVector1 diff DoubleVector2' 塚銝支葵'DoubleVector'怎圈銝嚗DoubleVector1=[" + numberOfDimensions1 + "]嚗DoubleVector2=[" + numberOfDimensions2 + "]\n" + "When 'DoubleVector1 diff DoubleVector2', the two vectors of 'DoubleVector' contain different quantities, DoubleVector1=[" + numberOfDimensions1 + "], DoubleVector2=[" + numberOfDimensions2 + "]") } + /** + * + * @return 撠砍笆鞊∩葉摮函摨啁瑁唬銝芣唳啁撟嗅唳啁餈嚗餈餈臭銝芣唳啁嚗舀靽格寧雿 + * + * Copy the vector sequence array stored in this object to a new array and return the new array. Here, a new array is returned, which supports modification and other operations. + */ + override def copyToNewArray(): Array[Double] = vector.toArray + + /** + * @return 銝剖怎蝏游漲圈 + *

+ * the number of dimensions contained in the vector + */ + override def getNumberOfDimensions: Int = size + /** * * @return 蝚砌孵銝剜蝏湔斤摨嚗餈甇文賣唳典臭誑湔亥瑕啁洵銝孵銝剔撖寡情 diff --git a/src_code/src/main/java/zhao/algorithmMagic/utils/ASClass.java b/src_code/src/main/java/zhao/algorithmMagic/utils/ASClass.java index 76a9317..abbc855 100644 --- a/src_code/src/main/java/zhao/algorithmMagic/utils/ASClass.java +++ b/src_code/src/main/java/zhao/algorithmMagic/utils/ASClass.java @@ -262,20 +262,14 @@ public static int[] DoubleArray_To_IntArray(double[] doubles) { * @return 瑁摰啁撖寡情嚗嗆祈澈 dest */ public static int[][] array2DCopy(int[][] src, int[][] dest) { - array2DCopy(src, dest, Math.min(src.length, dest.length)); + int index = -1; + for (int[] objects : src) { + int[] res = dest[++index]; + System.arraycopy(objects, 0, res, 0, Math.min(objects.length, res.length)); + } return dest; } - /** - * 撠銝銝芯蝏湔啁銝剔唳桀瑟瑁唳啁鈭蝏湔啁銝 - * - * @param src 閬鋡急瑁啁 - * @param dest 閬鋡急瑁格啁 - */ - private static void array2DCopy(int[][] src, int[][] dest, int length) { - System.arraycopy(src, 0, dest, 0, length); - } - /** * 撠銝銝芯蝏湔啁銝剔唳桀瑟瑁唳啁鈭蝏湔啁銝 * @@ -284,20 +278,14 @@ private static void array2DCopy(int[][] src, int[][] dest, int length) { * @return 瑁摰啁撖寡情嚗嗆祈澈 dest */ public static double[][] array2DCopy(double[][] src, double[][] dest) { - array2DCopy(src, dest, Math.min(src.length, dest.length)); + int index = -1; + for (double[] objects : src) { + double[] res = dest[++index]; + System.arraycopy(objects, 0, res, 0, Math.min(objects.length, res.length)); + } return dest; } - /** - * 撠銝銝芯蝏湔啁銝剔唳桀瑟瑁唳啁鈭蝏湔啁銝 - * - * @param src 閬鋡急瑁啁 - * @param dest 閬鋡急瑁格啁 - */ - private static void array2DCopy(double[][] src, double[][] dest, int length) { - System.arraycopy(src, 0, dest, 0, length); - } - /** * 撠銝銝芯蝏湔啁銝剔唳桀瑟瑁唳啁鈭蝏湔啁銝 * @@ -305,7 +293,11 @@ private static void array2DCopy(double[][] src, double[][] dest, int length) { * @param dest 閬鋡急瑁格啁 */ public static void array2DCopy(Object[][] src, Object[][] dest) { - System.arraycopy(src, 0, dest, 0, Math.min(src.length, dest.length)); + int index = -1; + for (Object[] objects : src) { + Object[] res = dest[++index]; + System.arraycopy(objects, 0, res, 0, Math.min(objects.length, res.length)); + } } /** @@ -362,5 +354,4 @@ public static void mergeArray(arr[] res, arr[] arr1, arr[] arr2) { } } } - } \ No newline at end of file diff --git a/src_code/src/main/java/zhao/algorithmMagic/utils/ASIO.java b/src_code/src/main/java/zhao/algorithmMagic/utils/ASIO.java index e41f3e1..6c993e4 100644 --- a/src_code/src/main/java/zhao/algorithmMagic/utils/ASIO.java +++ b/src_code/src/main/java/zhao/algorithmMagic/utils/ASIO.java @@ -65,6 +65,18 @@ public static void writer(File path, Consumer voidTrans) { } } + /** + * 唳桃撌亙瑕賣堆霂亙賣啣蝞∠唳格 + * + * @param outputStream 祆唳株箸 + * @param voidTrans 祆唳株箔蝙刻箸 + */ + public static void writer(OutputStream outputStream, Consumer voidTrans) { + BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream)); + voidTrans.accept(bufferedWriter); + ASIO.close(bufferedWriter); + } + /** * 撠銝銝沱yte啁颲箏唳摰頝臬 * @@ -148,7 +160,10 @@ public static Color[][] parseImageGetColorArray(String inputString) { */ public static Color[][] parseURLGetColorArray(URL imageUrl) { try { - return parseImageGetColorArray(ImageIO.read(imageUrl.openStream())); + InputStream inputStream = imageUrl.openStream(); + Color[][] colors = parseImageGetColorArray(ImageIO.read(inputStream)); + inputStream.close(); + return colors; } catch (IOException e) { throw new OperatorOperationException(e); } @@ -181,7 +196,7 @@ public static Color[][] parseImageGetColorArray(File inputFile) throws IOExcepti * @param image 閬鋡怨粉曉蝻脣笆鞊 * @return 霂餃銋餈游耦拚 */ - private static Color[][] parseImageGetColorArray(BufferedImage image) { + public static Color[][] parseImageGetColorArray(BufferedImage image) { final byte[] pixels = ((DataBufferByte) image.getRaster() .getDataBuffer()) .getData(); @@ -235,6 +250,10 @@ private static Color[][] parseImageGetColorArray(BufferedImage image) { */ public static int[][] parseImageGetArray(File inputFile) throws IOException { BufferedImage image = ImageIO.read(inputFile); + return parseImageGetArray(image); + } + + public static int[][] parseImageGetArray(BufferedImage image) { final byte[] pixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData(); final int width = image.getWidth(), height = image.getHeight(); final boolean hasAlphaChannel = image.getAlphaRaster() != null; @@ -316,4 +335,17 @@ public static IntegerMatrix[] parseImageGetArrays(File inputFile) throws IOExcep IntegerMatrix.parse(RMat), IntegerMatrix.parse(GMat), IntegerMatrix.parse(BMat) }; } + + /** + * @param closeable 閬鋡怠喲剔撖寡情 + */ + public static void close(Closeable closeable) { + if (closeable != null) { + try { + closeable.close(); + } catch (IOException ignored) { + + } + } + } } diff --git a/src_code/src/main/java/zhao/algorithmMagic/utils/ASMath.java b/src_code/src/main/java/zhao/algorithmMagic/utils/ASMath.java index 13e2ca1..c084087 100644 --- a/src_code/src/main/java/zhao/algorithmMagic/utils/ASMath.java +++ b/src_code/src/main/java/zhao/algorithmMagic/utils/ASMath.java @@ -63,6 +63,43 @@ public static int[] MaxAndMin(int[] doubles) { return new int[]{max, min}; } + /** + * 霈∠銝銝芸憭批潔撠 + * + * @param doubles 鋡怨恣蝞摨 + * @return 霈∠蝏嚗蝚砌銝芸唳舀憭批潘蝚砌銝芸唳舀撠 + */ + public static double[] MaxAndMin(double[][] doubles) { + // 霈∠憭批潭撠 + double max = doubles[0][0]; + double min = doubles[0][0]; + for (double[] aDouble : doubles) { + for (double v : aDouble) { + if (v > max) max = v; + if (v < min) min = v; + } + } + return new double[]{max, min}; + } + + /** + * 霈∠銝銝芸憭批潔撠 + * + * @param doubles 鋡怨恣蝞摨 + * @return 霈∠蝏嚗蝚砌銝芸唳舀憭批潘蝚砌銝芸唳舀撠 + */ + public static int[] MaxAndMin(int[][] doubles) { + // 霈∠憭批潭撠 + int max = doubles[0][0]; + int min = doubles[0][0]; + for (int[] aDouble : doubles) { + for (int v : aDouble) { + if (v > max) max = v; + if (v < min) min = v; + } + } + return new int[]{max, min}; + } /** * 霈∠銝銝芸銝剔憭批潭撠 diff --git a/src_code/src/main/java/zhao/algorithmMagic/utils/transformation/ProTransForm.java b/src_code/src/main/java/zhao/algorithmMagic/utils/transformation/ProTransForm.java new file mode 100644 index 0000000..9293ee8 --- /dev/null +++ b/src_code/src/main/java/zhao/algorithmMagic/utils/transformation/ProTransForm.java @@ -0,0 +1,28 @@ +package zhao.algorithmMagic.utils.transformation; + +import zhao.algorithmMagic.operands.table.Cell; + +import java.util.HashMap; + +/** + * 撣血啁唳株蓮X亙蝐鳴嗡葉冽亙銝銝芷閬鋡怨蓮Y撖寡情銋餈閬隡銝銝芷蝵桀圈★ + *

+ * A data conversion interface class with parameters, in which a configuration parameter item needs to be passed after receiving an object that needs to be converted. + * + * @author 韏萄摰 + * 2023/4/5 9:05 + */ +public interface ProTransForm { + + /** + * @param inputType 亥芸函敺頧祆X唳柴 + * Data to be converted from inside. + * @param value 頧祆X園閬雿輻函啣銵剁嗡葉key臬啣蝘堆value臬唳啣潛澆笆鞊∴臭誑撠鋆隞餅蝐餃唳殷銝祆萎嚗憒銝閬隡啣臭誑湔乩null + *

+ * The list of parameters that need to be used during conversion, where key is the parameter name and value is the cell object of the parameter value, which can encapsulate any type of data. Generally, if no parameters need to be passed, null can be passed directly. + * @return 頧祆V唳柴 + *

+ * Data after conversion. + */ + OutputType function(InputType inputType, HashMap> value); +} diff --git a/src_code/update/1.16_1.17-Chinese.md b/src_code/update/1.16_1.17-Chinese.md new file mode 100644 index 0000000..58ce62c --- /dev/null +++ b/src_code/update/1.16_1.17-Chinese.md @@ -0,0 +1,814 @@ +# ![image](https://user-images.githubusercontent.com/113756063/194830221-abe24fcc-484b-4769-b3b7-ec6d8138f436.png) 蝞瘜銋-箏典之 + +- Switch to [English Document](https://github.com/BeardedManZhao/algorithmStar/blob/main/src_code/update/1.16_1.17.md) +- knowledge base + + + + +### 湔唳亙 + +* 獢嗥穿1.16 - 1.17 +* 撠函蝘唬耨嫣蛹Integrator +* 靘瑞妖賣啁霈∠舀嚗賢餈瑞妖賣啣孵曉之嗥憬撠曉拚萇蝝圈 + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.integrator.ImageRenderingIntegrator; +import zhao.algorithmMagic.integrator.launcher.ImageRenderingMarLauncher; +import zhao.algorithmMagic.operands.matrix.IntegerMatrix; +import zhao.algorithmMagic.operands.matrix.block.IntegerMatrixSpace; + +public class MAIN1 { + public static void main(String[] args) { + String s1 = "C:\\Users\\Liming\\Desktop\\fsDownload\\敺桐縑曄_1.jpg"; + IntegerMatrix integerMatrix; + { + // 霈曄蔭 + IntegerMatrix weight = IntegerMatrix.parse( + new int[]{0, -1}, + new int[]{-1, 2}, + new int[]{0, 0} + ); + // 霂餃曉撟嗉瑕唬拚萇征 + IntegerMatrixSpace parse = IntegerMatrixSpace.parse(s1); + // 撖孵曉餈銵瑞妖嚗瑕銝銝芾脣蔗拚萇征渡 + integerMatrix = parse.foldingAndSum(2, 3, IntegerMatrixSpace.parse(weight, weight, weight)); + } + // 颲箏曄1瑞妖曉隞 + ImageRenderingIntegrator image = new ImageRenderingIntegrator( + "image", + new ImageRenderingMarLauncher<>(integerMatrix, "C:\\Users\\Liming\\Desktop\\fsDownload\\res12.jpg", 1) + ); + if (image.run()) { + System.out.println("ok!!!"); + } + } +} +``` + +* 曉拚菜舀湔仿餈 show 賣啣典撟銝剜曄內箏曉 + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.matrix.ColorMatrix; + +public class MAIN1 { + public static void main(String[] args) throws InterruptedException { + String s1 = "C:\\Users\\Liming\\Desktop\\fsDownload\\敺桐縑曄_1.jpg"; + ColorMatrix parse = ColorMatrix.parse(s1); + parse.show("image"); + Thread.sleep(1024); + parse.colorReversal(false); + parse.show("image"); + } +} +``` + +* 隡箸銋勗賣 shuffle 銝剔憭折箸銋望活啁瘜嚗雿踹嗡隡箇啗撘撣詻 +* 隡餈箄挪桃拚萎葉唳桃賣圈餉嚗玖ash餈銵啣撠 + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.matrix.ColumnDoubleMatrix; + +import java.util.Arrays; +import java.util.Random; + +public class MAIN1 { + public static void main(String[] args) { + // 撱箔隞賜拚菜唳 + double[][] data = new double[][]{ + new double[]{10, 11, 14, 10, 100}, + new double[]{11, 11, 14, 10, 100}, + new double[]{25, 20, 28, 20, 100}, + new double[]{26, 20, 28, 20, 100} + }; + // 撠拚菜唳桐蝙冽摰銝銵蝘啁孵撱箏箸 + ColumnDoubleMatrix columnDoubleMatrix = ColumnDoubleMatrix.parse( + new String[]{"col1", "col2", "col3", "col4", "col5"}, + new String[]{"row1", "row2", "row3", "row4"}, + data + ); + // 雿輻其撱箸啁拚萇孵銋勗嗡葉唳桅◇摨 銝憭銋 10 甈 + columnDoubleMatrix.shuffle(new Random(), false, 10); + // 啣箇拚菜唳 + System.out.println(columnDoubleMatrix); + // 啣箇拚萎葉 col2 冽啁銝剛砲賣圈撣摰 摨行敺 + System.out.println(Arrays.toString(columnDoubleMatrix.getArrayByColName("col2"))); + // 啣箇拚萎葉 row2 銵 冽啁銝剛砲賣圈撣摰 摨行敺 + System.out.println(Arrays.toString(columnDoubleMatrix.getArrayByRowName("row2"))); + } +} +``` + +* 舀曉敹急瑚摮賣啁靚冽雿嚗雿踹曉隞嗥靽摮敺渡 + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.matrix.ColorMatrix; + +public class MAIN1 { + public static void main(String[] args) { + String s1 = "C:\\Users\\zhao\\Desktop\\fsDownload\\敺桐縑曄_2.jpg"; + // 瑕啣曉拚萄笆鞊 + ColorMatrix parse = ColorMatrix.parse(s1); + // 撠曉典曉箇銝餈銵憸脣頧祆雿 + parse.colorReversal(false); + // 亦憸脣頧砌曉 + parse.show("image1"); + // 颲箏頧砌曉 + parse.save("C:\\Users\\zhao\\Desktop\\fsDownload\\res123.jpg"); + } +} +``` + +* 憓鈭 "SaveMatrix" 亙嚗摰唬霂交亙銝拚菟賢臭誑雿輻函蝏靽摮 + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.matrix.ColorMatrix; + +public class MAIN1 { + public static void main(String[] args) { + String s1 = "C:\\Users\\Liming\\Desktop\\fsDownload\\敺桐縑曄_2.jpg"; + // 瑕啣曉拚萄笆鞊 + ColorMatrix parse = ColorMatrix.parse(s1); + // 颲箏曉RGB祆唳 + parse.save("C:\\Users\\Liming\\Desktop\\fsDownload\\res1234.csv", ','); + } +} +``` + +* AS摨銝剖鈭唳桀摨嚗雿輻沒QL憌澆唳殷餈霂亙臭誑嫣噶撠唳桀銝剔唳株瑕啣摮銝剛銵憭 + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.table.DataFrame; +import zhao.algorithmMagic.operands.table.FDataFrame; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + +public class MAIN1 { + public static void main(String[] args) throws SQLException { + // 憭唳桀餈亙笆鞊 + Connection connection = DriverManager.getConnection("jdbc:mysql://192.168.0.101:38243/tq_SCHOOL", "liming", "liming7887"); + // 撠唳桀唳桀笆鞊∪頧賣 FDF + DataFrame execute = FDataFrame.builder(connection) // 摰唳桀餈 + .create("*") // 摰亥砭摮畾 + .from("STU_FIVE") // 摰亥砭銵 + .primaryKey(0) // 摰摮AS銵函銝駁殷AS隡芸典遣蝡銵蝝W嚗唳桀亥砭閬雿輻函揣撘摰佗 + .execute();// 撘憪亥砭 + // 啣 FDF 銝剔唳 + System.out.println(execute); + + // 撘憪亥砭 FDF + // 甇摨啣 FDF 銝 name踹漲銝3鈭箏銝剔瑕戊鈭箸 啣箏 3 銵唳 + DataFrame select = execute + .select("name", "sex") // 亥砭嗡葉 name sex + .where(v -> v.getCell(0).getStringValue().length() == 3) // 瑕啣嗡葉摮踹漲銝 3 唳株 + .groupBy("sex") // sex 蝏 + .count() // 撠瘥銝蝏餈銵蝏霈 + .sort("count()") // 抒霈∠餈銵甇摨摨 + .limit(3); // 瑕憭3銵唳 + System.out.println(select.into_outfile("C:\\Users\\zhao\\Desktop\\fsDownload\\res1.csv")); + // 啣 FDF 銝剔唳株 + System.out.println("唳株 = " + execute.count()); + // 啣箏嗡葉靽⊥ + System.out.println(execute.desc()); + // 瑕 韏萄摰 靽⊥ 曹 name 臭蜓殷甇文臭誑湔仿餈餈瑕唳唳 + System.out.println(execute.selectRow("韏萄摰")); + } +} +``` + +* 雿輻 FDataFrame 頧賣唳桀銝隞嗡葉唳柴 + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.table.*; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + +public class MAIN1 { + public static void main(String[] args) throws SQLException { + // 憭唳桀餈亙笆鞊 + Connection connection = DriverManager.getConnection("jdbc:mysql://192.168.0.101:38243/tq_SCHOOL", "liming", "liming7887"); + // 撠唳桀唳桀笆鞊∪頧賣 FDF + DataFrame execute = FDataFrame.builder(connection) // 摰唳桀餈 + .create("*") // 摰亥砭摮畾 + .from("STU_FIVE") // 摰亥砭銵 + .where(" name = '韏萄摰' ") // 摰亥砭∩辣 + .primaryKey(0) // 摰摮AS銵函銝駁殷AS隡芸典遣蝡銵蝝W嚗唳桀亥砭閬雿輻函揣撘摰佗 + .execute();// 撘憪亥砭 + // 啣 FDF 銝剔唳 + System.out.println(execute); + } +} +``` + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.table.DataFrame; +import zhao.algorithmMagic.operands.table.FDataFrame; + +import java.io.File; +import java.sql.SQLException; +import java.util.Objects; + +public class MAIN1 { + public static void main(String[] args) { + // 憭隞嗅笆鞊 + File file = new File("C:\\Users\\zhao\\Desktop\\out\\res1.csv"); + // 雿輻 FDF 頧賣隞 + DataFrame execute1 = FDataFrame.builder(file) + // 隞嗅笆鞊∠霂餃閬摰砍蝚 + .setSep(',') + // 隞嗅笆鞊⊿閬摰憟賢蝘堆銝賭蝙 * 餈隞銵函銝舀亥砭嚗臬撱箔銝枋F摮畾 + .create("id", "name", "sex") + // 隞嗅笆鞊⊿閬雿輻甸ambda銵刻噢撘餈銵唳桃餈皛 + .where(v -> Objects.equals(v.getCell(1).getStringValue(), "韏萄摰")) + // 隞嗅笆鞊∠銝駁格摰霈訾蝙典蝘 + .primaryKey("name") + // 扯亥砭 + .execute(); + // 啣箇唳 + System.out.println(execute1); + } +} + ``` + +* 撖達DF扯蝘啗銵limit雿 + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.table.DataFrame; +import zhao.algorithmMagic.operands.table.FDataFrame; + +import java.io.File; +import java.sql.SQLException; + +public class MAIN1 { + public static void main(String[] args) { + // 憭隞嗅笆鞊 + File file = new File("C:\\Users\\zhao\\Desktop\\out\\res1.csv"); + // 雿輻 FDF 頧賣隞 + DataFrame execute1 = FDataFrame.builder(file) + // 隞嗅笆鞊∠霂餃閬摰砍蝚 + .setSep(',') + // 隞嗅笆鞊⊿閬摰憟賢蝘堆銝賭蝙 * 餈隞銵函銝舀亥砭嚗臬撱箔銝枋F摮畾 + .create("id", "name", "sex") + // 隞嗅笆鞊∠銝駁格摰霈訾蝙典蝘 + .primaryKey("name") + // 扯亥砭 + .execute(); + // 啣箇唳 餈啣箔 韏 韐 銋渡唳株 + System.out.println(execute1.limit("韏", "韐")); + } +} +``` + +* 舀銝箏怠隞亙啣唳株雿 + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.table.DataFrame; +import zhao.algorithmMagic.operands.table.FDataFrame; +import zhao.algorithmMagic.operands.table.FieldCell; +import zhao.algorithmMagic.operands.table.FinalSeries; + +import java.io.File; +import java.io.IOException; +import java.sql.SQLException; + +public class MAIN1 { + public static void main(String[] args) { + // 憭隞嗅笆鞊 + File file = new File("C:\\Users\\zhao\\Desktop\\out\\res1.csv"); + // 雿輻 FDF 頧賣隞 + DataFrame execute1 = FDataFrame.builder(file) + // 隞嗅笆鞊∠霂餃閬摰砍蝚 + .setSep(',') + // 隞嗅笆鞊⊿閬摰憟賢蝘堆銝賭蝙 * 餈隞銵函銝舀亥砭嚗臬撱箔銝枋F摮畾 + .create("id", "name", "sex") + // 隞嗅笆鞊∠銝駁格摰霈訾蝙典蝘 + .primaryKey("name") + // 扯亥砭 + .execute(); + // 扳批怠蝏嚗霈∠箇瑕戊鈭箸 + long start = System.currentTimeMillis(); + System.out.println( + execute1 + // 摰亥砭嚗撟嗉絲怠 + .select(FieldCell.$("sex").as("批")) + // sex 蝏 + .groupBy("批") + // 餈銵 蝏霈⊥ + .count() + // 摰亥砭 撟嗉絲怠 + .select( + FieldCell.$("批"), + FieldCell.$("count()").as("鈭箸") + ) + // 啣銝銵唳 + .insert(FinalSeries.parse("", "10")) + ); + System.out.print("憭塚MS嚗嚗"); + System.out.println(System.currentTimeMillis() - start); + } +} + +``` + +* 賢撖道F唳桅撖寡情銝剔啣潸銵銵唳桃賣啣湔堆嗆舀DF唳桀笆鞊∪啁拚萎渡頧祆U + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.matrix.IntegerMatrix; +import zhao.algorithmMagic.operands.table.DataFrame; +import zhao.algorithmMagic.operands.table.FDataFrame; +import zhao.algorithmMagic.operands.table.FieldCell; +import zhao.algorithmMagic.operands.table.FinalCell; +import zhao.algorithmMagic.operands.vector.IntegerVector; + +import java.io.File; + +public class MAIN1 { + public static void main(String[] args) { + // 憭隞嗅笆鞊 + File file = new File("C:\\Users\\zhao\\Desktop\\out\\res1.csv"); + // 雿輻 FDF 頧賣隞 + DataFrame execute1 = FDataFrame.builder(file) + // 隞嗅笆鞊∠霂餃閬摰砍蝚 + .setSep(',') + // 隞嗅笆鞊⊿閬摰憟賢蝘堆銝賭蝙 * 餈隞銵函銝舀亥砭嚗臬撱箔銝枋F摮畾 + .create("id", "name", "sex") + // 隞嗅笆鞊∠銝駁格摰霈訾蝙典蝘 + .primaryKey("name") + // 扯亥砭 + .execute() + // 銝箏韏瑕怠 + .select( + FieldCell.$("id"), + FieldCell.$("name").as("蝘"), + FieldCell.$("sex").as("批") + ) + // 撠批怠餈銵頧祆g瑞銝1 憟喟銝0 + .updateCol(FieldCell.$("批"), cell -> new FinalCell<>(cell.getStringValue().equals("") ? 1 : 0)) + // 撠銵銝駁格啣潔蛹ZLY唳株銝剔潭踵X銝箸唳 405 + .updateRow("ZLY", cell -> new FinalCell<>(405)); + + // 啣箄”銝剔銵銝駁桀蝘唬蛹 405 唳株 + System.out.println(execute1.selectRow("405")); + long start = System.currentTimeMillis(); + // 撠銵刻蓮X銝箔銝芣游耦拚萄笆鞊∴霂交雿隡撠DF撖寡情銝剔啣潸曇蓮X銝 col.count()*3 拚萄笆鞊 + IntegerMatrix parse = IntegerMatrix.parse(execute1, execute1.count().getIntValue(), 3); + System.out.println(IntegerVector.parse(parse.getArrayByColIndex(2))); + System.out.print("憭塚MS嚗嚗"); + System.out.println(System.currentTimeMillis() - start); + } +} +``` + +* 舀餈銝銝芰蝏 URL 撖寡情瑕唳喳曉唳殷撟嗅嗉蓮X銝箔銝芸曉拚萸 + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.matrix.ColorMatrix; + +import java.net.MalformedURLException; +import java.net.URL; + +public class MAIN1 { + public static void main(String[] args) throws MalformedURLException { + // 憭曉URL撖寡情 + URL url = new URL("https://user-images.githubusercontent.com/113756063/194830221-abe24fcc-484b-4769-b3b7-ec6d8138f436.png"); + // 閫URL瑕啣曉拚 + ColorMatrix parse1 = ColorMatrix.parse(url); + // 閫URL瑕啣曉啣漲拚 + ColorMatrix parse2 = ColorMatrix.parseGrayscale(url); + // 亦曉 + parse1.show("image"); + parse2.show("image"); + } +} +``` + +* 舀餈銵脣蔗鈭澆閫渲嚗賢餈摰脣蔗啣潘曄內箸游曉孵嚗駁斗游雿孵 + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.matrix.ColorMatrix; + +import java.net.MalformedURLException; +import java.net.URL; + +public class MAIN1 { + public static void main(String[] args) throws MalformedURLException { + // 憭曉URL撖寡情 + URL url = new URL("https://user-images.githubusercontent.com/113756063/194830221-abe24fcc-484b-4769-b3b7-ec6d8138f436.png"); + // 閫URL瑕啣曉拚 + ColorMatrix parse1 = ColorMatrix.parse(url); + // 撠 URL 曉拚萎葉 G 憸脫啣澆之鈭 40 憸脣港蛹暺莎銋港蛹質 + // 刻曹拐 G 甇 蝏輯脰瘛 頞航賢銝箇質 + parse1.globalBinary(ColorMatrix._G_, 40, 0, 0xffffff); + // 銋臭誑雿輻典嗅憸脤餈銵脣蔗靚 + parse1.globalBinary(ColorMatrix._R_, 40, 0, 0xffffff); + parse1.globalBinary(ColorMatrix._B_, 40, 0, 0xffffff); + // 亦蝏曉 + parse1.show("image"); + } +} +``` + +* 舀餈銵曉 ASCII 曄嚗典臭誑敹恍撠銝銝芸曄 ASCII 箸伐銝餈霂瑟函&靽曉撠箏站頞喳撠 + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.matrix.ColorMatrix; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; + +public class MAIN1 { + public static void main(String[] args) throws MalformedURLException { + // 憭曉URL撖寡情 + URL url = new URL("https://user-images.githubusercontent.com/113756063/194830221-abe24fcc-484b-4769-b3b7-ec6d8138f436.png"); + // 閫URL瑕啣曉拚 + ColorMatrix parse1 = ColorMatrix.parse(url); + // 亦蝏曉 + parse1.show("image"); + // 颲箏曉 ASCII 啣潘颲箄銝 G 憸脫啣 憭找 40 颲箇泵 'A' 嗅颲箇泵 ' ' + parse1.save( + new File("C:\\Users\\zhao\\Desktop\\fsDownload\\res.txt"), + ColorMatrix._G_, 40, 'A', ' ' + ); + } +} +``` + +* 賢典撱箔銝芰征 DataFrame 撖寡情嚗撟嗉芯蜓雿嗡葉唳柴 + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.table.DataFrame; +import zhao.algorithmMagic.operands.table.FDataFrame; +import zhao.algorithmMagic.operands.table.FieldCell; +import zhao.algorithmMagic.operands.table.FinalSeries; + +public class MAIN1 { + public static void main(String[] args) { + // 撱箔銝芰征 DF 撖寡情 隞 name 雿銝箄銝駁桃揣撘 + FDataFrame create = FDataFrame.select(FieldCell.parse("name", "sex", "phoneNum"), 1); + // 乩鈭唳 + DataFrame insert = create.insert( + FinalSeries.parse("zhao", "M", "110xxxxxxxx"), + FinalSeries.parse("tang", "W", "110xxxxxxxx"), + FinalSeries.parse("yang", "M", "110xxxxxxxx") + ); + // 亦唳桅 + System.out.println(insert); + // 撠嗡葉 name sex 亥砭 + System.out.println( + insert.select( + FieldCell.$("name").as("AllName"), + FieldCell.$("sex").as("AllSex") + ) + ); + } +} +``` + +* 舀 group 嗅摰 where摮伐雿踹霈∠憭批之憓撘 + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.table.DataFrame; +import zhao.algorithmMagic.operands.table.FDataFrame; +import zhao.algorithmMagic.operands.table.FieldCell; +import zhao.algorithmMagic.operands.table.FinalSeries; + +import java.net.MalformedURLException; + +public class MAIN1 { + public static void main(String[] args) { + // 撱箔銝芰征 DF 撖寡情 隞 name 雿銝箄銝駁桃揣撘 + FDataFrame create = FDataFrame.select(FieldCell.parse("name", "sex", "phoneNum"), 1); + // 乩鈭唳 + DataFrame insert = create.insert( + FinalSeries.parse("zhao1", "M", "110xxxxxxxx"), + FinalSeries.parse("tang2", "W", "120xxxxxxxx"), + FinalSeries.parse("yang3", "W", "110xxxxxxxx"), + FinalSeries.parse("zhao4", "M", "120xxxxxxxx"), + FinalSeries.parse("tang5", "W", "110xxxxxxxx"), + FinalSeries.parse("yang6", "W", "110xxxxxxxx"), + FinalSeries.parse("zhao7", "M", "120xxxxxxxx"), + FinalSeries.parse("tang8", "W", "110xxxxxxxx"), + FinalSeries.parse("yang9", "W", "110xxxxxxxx") + ); + // 亦唳桅 + System.out.println(insert); + // 撠嗡葉箏瑕銝雿銝銝 120 唳株批嗡葉 sex 蝏 刻湔乩蝙典蝏嗉皛文喳 + System.out.println( + insert.groupBy("sex", v -> { + // 瑕唳箏瑞摮蝚虫葡 + String s = v.getCell(2).toString(); + // 斗剖 3 銝芸蝚行臬虫蛹 120 嚗臬虫誑 120 撘憭湛 憒臬停銝瘛餃 + return !s.startsWith("120"); + }).count() + ); + } +} +``` + +* 舀撅其澆雿嚗賢啣啣曉鈭澆憭嚗貉鈭典鈭澆嚗賣唳游菜暑 + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.matrix.ColorMatrix; + +import java.net.MalformedURLException; +import java.net.URL; + +public class MAIN1 { + public static void main(String[] args) throws MalformedURLException { + // 瑕啣曉拚 + ColorMatrix parse = ColorMatrix.parse(new URL("https://img-blog.csdnimg.cn/img_convert/5765bdab08ef6e117d434e7e225b9013.png")); + parse.show("image"); + System.out.println("ok!!!"); + System.out.println(" = " + parse.getRowCount()); + System.out.println("摰 = " + parse.getColCount()); + // 撠曉餈銵撅其澆 + parse.localBinary( + // 摰祆活鈭澆拍憸脤 + ColorMatrix._G_, + // 摰祆活鈭澆箇撅典曉拚菜圈 + 100, + // 摰祆活鈭澆銝剖函拚萎葉憭找撅券潛憸脩 + 0xffffff, + // 摰祆活鈭澆銝剖函拚萎葉撠鈭撅券潛憸脩 + 0, + // 摰祆活鈭澆銝剖券潛閬餈銵敺株啣潘餈舫雿20銝芷潭啣 + -30 + ); + // 亦蝏唳 + parse.show("image"); + } +} +``` + +* DF撖寡情唳格舀靽摮銝 HTML 隞塚賢摰唳芸典憿菟Y嗆雿 + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.table.DataFrame; +import zhao.algorithmMagic.operands.table.FDataFrame; +import zhao.algorithmMagic.operands.table.FieldCell; +import zhao.algorithmMagic.operands.table.FinalSeries; + +public class MAIN1 { + public static void main(String[] args) { + // 撱箔銝芰征 DF 撖寡情 隞 name 雿銝箄銝駁桃揣撘 + FDataFrame create = FDataFrame.select(FieldCell.parse("name", "sex", "phoneNum", "salary"), 1); + // 乩鈭唳 + DataFrame insert = create.insert( + FinalSeries.parse("zhao1", "M", "110xxxxxxxx", "30000"), + FinalSeries.parse("tang2", "W", "120xxxxxxxx", "30000"), + FinalSeries.parse("yang3", "W", "110xxxxxxxx", "30000"), + FinalSeries.parse("zhao4", "M", "120xxxxxxxx", "30000"), + FinalSeries.parse("tang5", "W", "110xxxxxxxx", "30000"), + FinalSeries.parse("yang6", "W", "110xxxxxxxx", "30000"), + FinalSeries.parse("zhao7", "M", "120xxxxxxxx", "30000"), + FinalSeries.parse("tang8", "W", "110xxxxxxxx", "30000"), + FinalSeries.parse("yang9", "W", "110xxxxxxxx", "30000") + ); + // 颲箄”HTML 嗅亦銵其葉唳 + System.out.println( + insert.into_outHtml("C:\\Users\\Liming\\Desktop\\fsDownload\\res11234.html", "myTable") + ); + } +} +``` + +* 曉撘憪舀 add 賣堆災dd賣啁雿銝嚗臭誑摰啣曉賣啁撟塚 + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.matrix.ColorMatrix; + +import java.sql.SQLException; + +public class MAIN1 { + public static void main(String[] args) { + // 撠銝鈭曉隞嗉蓮X銝箔銝芸曉拚萄笆鞊 + ColorMatrix colorMatrix1 = ColorMatrix.parse("C:\\Users\\Liming\\Desktop\\fsDownload\\test.bmp"); + ColorMatrix colorMatrix2 = ColorMatrix.parse("C:\\Users\\Liming\\Desktop\\fsDownload\\test1.bmp"); + // 撠 colorMatrix2 + colorMatrix1 蝏曉撅蝷箏箸 + (colorMatrix1.add(colorMatrix2)).show("image"); + } +} +``` + +* 舀芸銋隞亙蝵格唳格寞雿 + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.matrix.ColorMatrix; + +import java.sql.SQLException; + +public class MAIN1 { + public static void main(String[] args) { + // 撠銝鈭曉隞嗉蓮X銝箔銝芸曉拚萄笆鞊 + ColorMatrix colorMatrix1 = ColorMatrix.parse("C:\\Users\\Liming\\Desktop\\fsDownload\\test.bmp"); + ColorMatrix colorMatrix2 = ColorMatrix.parse("C:\\Users\\Liming\\Desktop\\fsDownload\\test1.bmp"); + // 雿輻 agg 賣唬誑蝵桃霈∠寞餈銵銝支葵拚萇撟 + // 銝W賣唬葉蝚砌銝芸耦隞銵函撠望舐拚萎葉蝝餉嚗餈雿輻函舀嚗撟嗅笆頞憸脫啣潸銵閫渡餉摰 + colorMatrix1.agg(colorMatrix2, ColorMatrix.COLOR_SUM_REGULATE).show("image"); + } +} +``` + +* 曉拚菜舀餈蝞賣堆刻砲賣唬葉臭誑駁斗雿孵唳柴 + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.matrix.ColorMatrix; + +import java.sql.SQLException; + + +public class MAIN1 { + public static void main(String[] args) { + // 撠銝鈭曉隞嗉蓮X銝箔銝芸曉拚萄笆鞊 + ColorMatrix colorMatrix1 = ColorMatrix.parseGrayscale("C:\\Users\\Liming\\Desktop\\fsDownload\\test2.bmp"); + // 撖孵曉餈銵鈭澆 + colorMatrix1.globalBinary(ColorMatrix._G_, 100, 0xffffff, 0); + colorMatrix1.show("銋 image"); + // 撘憪撖孵曉拚菔銵雿 + colorMatrix1.erode(2, 2, false).show("銋 image"); + } +} +``` + +* 舀瘛餃嚗雿舫閬瘜冽臬瘛餃隡餈銝銝芣啁 DataFrame DF銝剔唳桀隡鋡急瑁箸乓 + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.table.*; + +import java.sql.SQLException; + +public class MAIN1 { + public static void main(String[] args) { + // 撱箔銝芰征 DataFrame 撖寡情 + FDataFrame select = FDataFrame.select( + FieldCell.parse("id", "name", "sex", "age"), 1 + ); + // 冽交唳 + select.insert( + FinalSeries.parse("1", "zhao", "M", "19"), + FinalSeries.parse("2", "tang", "W", "18"), + FinalSeries.parse("3", "yang", "W", "20"), + FinalSeries.parse("4", "shen", "W", "19") + ); + // 啣 DF 撖寡情喟靽⊥ + System.out.println( + select.desc() + ); + // 瘛餃銝唳殷其銵函內撟湧臬虫蛹嗆 + DataFrame ageIsE = select.insertColGetNew( + // 啣蝘 + FieldCell.$("AgeIsE"), + // 啣啣潛餉 憒蝚 4 嚗index == 3嚗啣 % 2 == 0 撠望眩rue + cells -> cells.getCell(3).getIntValue() % 2 == 0 ? new FinalCell<>(true) : new FinalCell<>(false) + ); + System.out.println(ageIsE); + } +} +``` + +* 舀銵冽唳桐渡餈蝞雿嚗賢撠銵其葉啣潛掩餈銵瘙銝撌株恣蝞嚗霈∠銋撠餈蚤F撖寡情 + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.table.*; + +public class MAIN1 { + public static void main(String[] args) { + // 撱箔銝芰征 DataFrame 撖寡情 + FDataFrame select1 = FDataFrame.select( + FieldCell.parse("id", "name", "sex", "age"), 1 + ); + // 冽交唳 + select1.insert( + FinalSeries.parse("1", "zhao", "M", "19"), + FinalSeries.parse("2", "tang", "W", "18"), + FinalSeries.parse("3", "yang", "W", "20"), + FinalSeries.parse("4", "shen", "W", "19") + ); + // 撱箔銝芰征 DataFrame 撖寡情 + FDataFrame select2 = FDataFrame.select( + FieldCell.parse("id", "name", "sex", "age"), 1 + ); + // 冽交唳 + select2.insert( + FinalSeries.parse("1", "zhao", "M", "19"), + FinalSeries.parse("2", "tang", "W", "18"), + FinalSeries.parse("3", "yang", "W", "20") + ); + // 餈銵瘙銝撌桃餈蝞雿 + System.out.println(select1.add(select2)); + System.out.println(select1.diff(select2)); + } +} +``` + +* DataFrame唳桀笆鞊⊥摰撟 + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.table.*; + +import java.sql.SQLException; + +public class MAIN1 { + public static void main(String[] args) { + // 撱箔銝芰征 DataFrame 撖寡情 + FDataFrame select = FDataFrame.select( + FieldCell.parse("id", "name", "sex", "age"), 1 + ); + // 冽交唳 嗅餈銵蝏 + GroupDataFrameData groupDataFrameData = select.insert( + FinalSeries.parse("1", "zhao", "M", "19"), + FinalSeries.parse("2", "tang", "W", "18"), + FinalSeries.parse("3", "yang", "W", "20") + ).groupBy("sex"); + // 啣 M 蝏唳 + System.out.println(groupDataFrameData.getDFByGroup("M")); + // 啣 W 蝏唳 + System.out.println(groupDataFrameData.getDFByGroup("W")); + } +} +``` + +* 啁祆釣鈭憿對甇斤砌葉靘韏鋡急霈唬蛹 provided 餈瑕臭誑憭批雿雿蝔摨佗賢寞株芸楛摰憿寧格亥銵詨喟蝵殷甇文刻銵AS摨瘜典亦嗅霂瑕隞乩敹憿駁★銝桀紡乓 + +```xml + + + + + org.apache.logging.log4j + log4j-slf4j-impl + 2.20.0 + + + + + + org.apache.logging.log4j + log4j-api + 2.20.0 + + + + + org.apache.logging.log4j + log4j-core + 2.20.0 + + + +``` + +### Version update date : 2023-03-26 \ No newline at end of file diff --git a/src_code/update/1.16_1.17.md b/src_code/update/1.16_1.17.md new file mode 100644 index 0000000..e9e3e81 --- /dev/null +++ b/src_code/update/1.16_1.17.md @@ -0,0 +1,791 @@ +# ![image](https://user-images.githubusercontent.com/113756063/194830221-abe24fcc-484b-4769-b3b7-ec6d8138f436.png) Algorithm Star-MachineBrain + +- W [銝剜獢β(https://github.com/BeardedManZhao/algorithmStar/blob/main/src_code/update/1.16_1.17-Chinese.md) +- knowledge base + + + + +### Update log: + +* Framework version: 1.16 - 1.17 +* Change the name of the integrator to Integrator. +* It provides the calculation support of convolution function, which can enlarge the features and reduce the number of + elements in the image matrix. + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.integrator.ImageRenderingIntegrator; +import zhao.algorithmMagic.integrator.launcher.ImageRenderingMarLauncher; +import zhao.algorithmMagic.operands.matrix.IntegerMatrix; +import zhao.algorithmMagic.operands.matrix.block.IntegerMatrixSpace; + +public class MAIN1 { + public static void main(String[] args) { + String s1 = "C:\\Users\\Liming\\Desktop\\fsDownload\\敺桐縑曄_1.jpg"; + IntegerMatrix integerMatrix; + { + // 霈曄蔭 + IntegerMatrix weight = IntegerMatrix.parse( + new int[]{0, -1}, + new int[]{-1, 2}, + new int[]{0, 0} + ); + // 霂餃曉撟嗉瑕唬拚萇征 + IntegerMatrixSpace parse = IntegerMatrixSpace.parse(s1); + // 撖孵曉餈銵瑞妖嚗瑕銝銝芾脣蔗拚萇征渡 + integerMatrix = parse.foldingAndSum(2, 3, IntegerMatrixSpace.parse(weight, weight, weight)); + } + // 颲箏曄1瑞妖曉隞 + ImageRenderingIntegrator image = new ImageRenderingIntegrator( + "image", + new ImageRenderingMarLauncher<>(integerMatrix, "C:\\Users\\Liming\\Desktop\\fsDownload\\res12.jpg", 1) + ); + if (image.run()) { + System.out.println("ok!!!"); + } + } +} +``` + +* The image matrix supports displaying images on the screen directly through the show function. + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.matrix.ColorMatrix; + +public class MAIN1 { + public static void main(String[] args) throws InterruptedException { + String s1 = "C:\\Users\\Liming\\Desktop\\fsDownload\\敺桐縑曄_1.jpg"; + ColorMatrix parse = ColorMatrix.parse(s1); + parse.show("image"); + Thread.sleep(1024); + parse.colorReversal(false); + parse.show("image"); + } +} +``` + +* Optimize the algorithm of maximum random scrambling times in the random scrambling function shuffle, so that it will + not have out-of-bounds exceptions. +* Optimize the function logic of random access to data in the matrix through column names, and use hash to map + addresses. + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.matrix.ColumnDoubleMatrix; + +import java.util.Arrays; +import java.util.Random; + +public class MAIN1 { + public static void main(String[] args) { + // 撱箔隞賜拚菜唳 + double[][] data = new double[][]{ + new double[]{10, 11, 14, 10, 100}, + new double[]{11, 11, 14, 10, 100}, + new double[]{25, 20, 28, 20, 100}, + new double[]{26, 20, 28, 20, 100} + }; + // 撠拚菜唳桐蝙冽摰銝銵蝘啁孵撱箏箸 + ColumnDoubleMatrix columnDoubleMatrix = ColumnDoubleMatrix.parse( + new String[]{"col1", "col2", "col3", "col4", "col5"}, + new String[]{"row1", "row2", "row3", "row4"}, + data + ); + // 雿輻其撱箸啁拚萇孵銋勗嗡葉唳桅◇摨 銝憭銋 10 甈 + columnDoubleMatrix.shuffle(new Random(), false, 10); + // 啣箇拚菜唳 + System.out.println(columnDoubleMatrix); + // 啣箇拚萎葉 col2 冽啁銝剛砲賣圈撣摰 摨行敺 + System.out.println(Arrays.toString(columnDoubleMatrix.getArrayByColName("col2"))); + // 啣箇拚萎葉 row2 銵 冽啁銝剛砲賣圈撣摰 摨行敺 + System.out.println(Arrays.toString(columnDoubleMatrix.getArrayByRowName("row2"))); + } +} +``` + +* It supports the call operation of the quick save function of the image, making the saving of the image file easier. + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.matrix.ColorMatrix; + +public class MAIN1 { + public static void main(String[] args) { + String s1 = "C:\\Users\\zhao\\Desktop\\fsDownload\\敺桐縑曄_2.jpg"; + // 瑕啣曉拚萄笆鞊 + ColorMatrix parse = ColorMatrix.parse(s1); + // 撠曉典曉箇銝餈銵憸脣頧祆雿 + parse.colorReversal(false); + // 亦憸脣頧砌曉 + parse.show("image1"); + // 颲箏頧砌曉 + parse.save("C:\\Users\\zhao\\Desktop\\fsDownload\\res123.jpg"); + } +} +``` + +* The "SaveMatrix" interface is added. All matrices that implement this interface can be saved in structured or + unstructured way. + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.matrix.ColorMatrix; + +public class MAIN1 { + public static void main(String[] args) { + String s1 = "C:\\Users\\Liming\\Desktop\\fsDownload\\敺桐縑曄_2.jpg"; + // 瑕啣曉拚萄笆鞊 + ColorMatrix parse = ColorMatrix.parse(s1); + // 颲箏曉RGB祆唳 + parse.save("C:\\Users\\Liming\\Desktop\\fsDownload\\res1234.csv", ','); + } +} +``` + +* A data analysis library is added to the AS library, which uses SQL styles to process data. Through this library, data + in the database can be easily obtained into memory for processing. + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.table.DataFrame; +import zhao.algorithmMagic.operands.table.FDataFrame; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + +public class MAIN1 { + public static void main(String[] args) throws SQLException { + // 憭唳桀餈亙笆鞊 + Connection connection = DriverManager.getConnection("jdbc:mysql://192.168.0.101:38243/tq_SCHOOL", "liming", "liming7887"); + // 撠唳桀唳桀笆鞊∪頧賣 FDF + DataFrame execute = FDataFrame.builder(connection) // 摰唳桀餈 + .create("*") // 摰亥砭摮畾 + .from("STU_FIVE") // 摰亥砭銵 + .primaryKey(0) // 摰摮AS銵函銝駁殷AS隡芸典遣蝡銵蝝W嚗唳桀亥砭閬雿輻函揣撘摰佗 + .execute();// 撘憪亥砭 + // 啣 FDF 銝剔唳 + System.out.println(execute); + + // 撘憪亥砭 FDF + // 甇摨啣 FDF 銝 name踹漲銝3鈭箏銝剔瑕戊鈭箸 啣箏 3 銵唳 + DataFrame select = execute + .select("name", "sex") // 亥砭嗡葉 name sex + .where(v -> v.getCell(0).getStringValue().length() == 3) // 瑕啣嗡葉摮踹漲銝 3 唳株 + .groupBy("sex") // sex 蝏 + .count() // 撠瘥銝蝏餈銵蝏霈 + .sort("count()") // 抒霈∠餈銵甇摨摨 + .limit(3); // 瑕憭3銵唳 + System.out.println(select.into_outfile("C:\\Users\\zhao\\Desktop\\fsDownload\\res1.csv")); + // 啣 FDF 銝剔唳株 + System.out.println("唳株 = " + execute.count()); + // 啣箏嗡葉靽⊥ + System.out.println(execute.desc()); + // 瑕 韏萄摰 靽⊥ 曹 name 臭蜓殷甇文臭誑湔仿餈餈瑕唳唳 + System.out.println(execute.selectRow("韏萄摰")); + } +} +``` + +* Use FDataFrame to load the data in the database and file. + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.table.*; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + +public class MAIN1 { + public static void main(String[] args) throws SQLException { + // 憭唳桀餈亙笆鞊 + Connection connection = DriverManager.getConnection("jdbc:mysql://192.168.0.101:38243/tq_SCHOOL", "liming", "liming7887"); + // 撠唳桀唳桀笆鞊∪頧賣 FDF + DataFrame execute = FDataFrame.builder(connection) // 摰唳桀餈 + .create("*") // 摰亥砭摮畾 + .from("STU_FIVE") // 摰亥砭銵 + .where(" name = '韏萄摰' ") // 摰亥砭∩辣 + .primaryKey(0) // 摰摮AS銵函銝駁殷AS隡芸典遣蝡銵蝝W嚗唳桀亥砭閬雿輻函揣撘摰佗 + .execute();// 撘憪亥砭 + // 啣 FDF 銝剔唳 + System.out.println(execute); + } +} +``` + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.table.DataFrame; +import zhao.algorithmMagic.operands.table.FDataFrame; + +import java.io.File; +import java.sql.SQLException; +import java.util.Objects; + +public class MAIN1 { + public static void main(String[] args) { + // 憭隞嗅笆鞊 + File file = new File("C:\\Users\\zhao\\Desktop\\out\\res1.csv"); + // 雿輻 FDF 頧賣隞 + DataFrame execute1 = FDataFrame.builder(file) + // 隞嗅笆鞊∠霂餃閬摰砍蝚 + .setSep(',') + // 隞嗅笆鞊⊿閬摰憟賢蝘堆銝賭蝙 * 餈隞銵函銝舀亥砭嚗臬撱箔銝枋F摮畾 + .create("id", "name", "sex") + // 隞嗅笆鞊⊿閬雿輻甸ambda銵刻噢撘餈銵唳桃餈皛 + .where(v -> Objects.equals(v.getCell(1).getStringValue(), "韏萄摰")) + // 隞嗅笆鞊∠銝駁格摰霈訾蝙典蝘 + .primaryKey("name") + // 扯亥砭 + .execute(); + // 啣箇唳 + System.out.println(execute1); + } +} + ``` + +* Limit FDF by line name + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.table.DataFrame; +import zhao.algorithmMagic.operands.table.FDataFrame; + +import java.io.File; +import java.sql.SQLException; + +public class MAIN1 { + public static void main(String[] args) { + // 憭隞嗅笆鞊 + File file = new File("C:\\Users\\zhao\\Desktop\\out\\res1.csv"); + // 雿輻 FDF 頧賣隞 + DataFrame execute1 = FDataFrame.builder(file) + // 隞嗅笆鞊∠霂餃閬摰砍蝚 + .setSep(',') + // 隞嗅笆鞊⊿閬摰憟賢蝘堆銝賭蝙 * 餈隞銵函銝舀亥砭嚗臬撱箔銝枋F摮畾 + .create("id", "name", "sex") + // 隞嗅笆鞊∠銝駁格摰霈訾蝙典蝘 + .primaryKey("name") + // 扯亥砭 + .execute(); + // 啣箇唳 餈啣箔 韏 韐 銋渡唳株 + System.out.println(execute1.limit("韏", "韐")); + } +} +``` + +* Support the operations of aliasing columns and adding data rows. + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.table.DataFrame; +import zhao.algorithmMagic.operands.table.FDataFrame; +import zhao.algorithmMagic.operands.table.FieldCell; + +import java.io.File; +import java.sql.SQLException; + +public class MAIN1 { + public static void main(String[] args) { + // 憭隞嗅笆鞊 + File file = new File("C:\\Users\\zhao\\Desktop\\out\\res1.csv"); + // 雿輻 FDF 頧賣隞 + DataFrame execute1 = FDataFrame.builder(file) + // 隞嗅笆鞊∠霂餃閬摰砍蝚 + .setSep(',') + // 隞嗅笆鞊⊿閬摰憟賢蝘堆銝賭蝙 * 餈隞銵函銝舀亥砭嚗臬撱箔銝枋F摮畾 + .create("id", "name", "sex") + // 隞嗅笆鞊∠銝駁格摰霈訾蝙典蝘 + .primaryKey("name") + // 扯亥砭 + .execute(); + // 扳批怠蝏嚗霈∠箇瑕戊鈭箸 + System.out.println( + execute1 + // 摰亥砭嚗撟嗉絲怠 + .select(FieldCell.$("sex").as("批")) + // sex 蝏 + .groupBy("批") + // 餈銵 蝏霈⊥ + .count() + // 摰亥砭 撟嗉絲怠 + .select( + FieldCell.$("批"), + FieldCell.$("count()").as("鈭箸") + ) + ); + } +} +``` + +* Capable of functional update of row or column data for all values in DF data set objects, and supports conversion from + DF data objects to matrices. + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.matrix.IntegerMatrix; +import zhao.algorithmMagic.operands.table.DataFrame; +import zhao.algorithmMagic.operands.table.FDataFrame; +import zhao.algorithmMagic.operands.table.FieldCell; +import zhao.algorithmMagic.operands.table.FinalCell; +import zhao.algorithmMagic.operands.vector.IntegerVector; + +import java.io.File; + +public class MAIN1 { + public static void main(String[] args) { + // 憭隞嗅笆鞊 + File file = new File("C:\\Users\\zhao\\Desktop\\out\\res1.csv"); + // 雿輻 FDF 頧賣隞 + DataFrame execute1 = FDataFrame.builder(file) + // 隞嗅笆鞊∠霂餃閬摰砍蝚 + .setSep(',') + // 隞嗅笆鞊⊿閬摰憟賢蝘堆銝賭蝙 * 餈隞銵函銝舀亥砭嚗臬撱箔銝枋F摮畾 + .create("id", "name", "sex") + // 隞嗅笆鞊∠銝駁格摰霈訾蝙典蝘 + .primaryKey("name") + // 扯亥砭 + .execute() + // 銝箏韏瑕怠 + .select( + FieldCell.$("id"), + FieldCell.$("name").as("蝘"), + FieldCell.$("sex").as("批") + ) + // 撠批怠餈銵頧祆g瑞銝1 憟喟銝0 + .updateCol(FieldCell.$("批"), cell -> new FinalCell<>(cell.getStringValue().equals("") ? 1 : 0)) + // 撠銵銝駁格啣潔蛹ZLY唳株銝剔潭踵X銝箸唳 405 + .updateRow("ZLY", cell -> new FinalCell<>(405)); + + // 啣箄”銝剔銵銝駁桀蝘唬蛹 405 唳株 + System.out.println(execute1.selectRow("405")); + long start = System.currentTimeMillis(); + // 撠銵刻蓮X銝箔銝芣游耦拚萄笆鞊∴霂交雿隡撠DF撖寡情銝剔啣潸曇蓮X銝 col.count()*3 拚萄笆鞊 + IntegerMatrix parse = IntegerMatrix.parse(execute1, execute1.count().getIntValue(), 3); + System.out.println(IntegerVector.parse(parse.getArrayByColIndex(2))); + System.out.print("憭塚MS嚗嚗"); + System.out.println(System.currentTimeMillis() - start); + } +} +``` + +* Support for obtaining image related data through a web URL object and converting it into an image matrix. + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.matrix.ColorMatrix; + +import java.net.MalformedURLException; +import java.net.URL; + +public class MAIN1 { + public static void main(String[] args) throws MalformedURLException { + // 憭曉URL撖寡情 + URL url = new URL("https://user-images.githubusercontent.com/113756063/194830221-abe24fcc-484b-4769-b3b7-ec6d8138f436.png"); + // 閫URL瑕啣曉拚 + ColorMatrix parse1 = ColorMatrix.parse(url); + // 閫URL瑕啣曉啣漲拚 + ColorMatrix parse2 = ColorMatrix.parseGrayscale(url); + // 亦曉 + parse1.show("image"); + parse2.show("image"); + } +} +``` + +* It supports color binarization and regularization coverage, and can display more image features or remove more + redundant features by specifying the color values of the channel. + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.matrix.ColorMatrix; + +import java.net.MalformedURLException; +import java.net.URL; + +public class MAIN1 { + public static void main(String[] args) throws MalformedURLException { + // 憭曉URL撖寡情 + URL url = new URL("https://user-images.githubusercontent.com/113756063/194830221-abe24fcc-484b-4769-b3b7-ec6d8138f436.png"); + // 閫URL瑕啣曉拚 + ColorMatrix parse1 = ColorMatrix.parse(url); + // 撠 URL 曉拚萎葉 G 憸脫啣澆之鈭 40 憸脣港蛹暺莎銋港蛹質 + // 刻曹拐 G 甇 蝏輯脰瘛 頞航賢銝箇質 + parse1.globalBinary(ColorMatrix._G_, 40, 0, 0xffffff); + // 銋臭誑雿輻典嗅憸脤餈銵脣蔗靚 + parse1.globalBinary(ColorMatrix._R_, 40, 0, 0xffffff); + parse1.globalBinary(ColorMatrix._B_, 40, 0, 0xffffff); + // 亦蝏曉 + parse1.show("image"); + } +} +``` + +* Supports the construction of image ASCII images. You can quickly construct an image in ASCII, but please ensure that + the image size is small enough. + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.matrix.ColorMatrix; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; + +public class MAIN1 { + public static void main(String[] args) throws MalformedURLException { + // 憭曉URL撖寡情 + URL url = new URL("https://user-images.githubusercontent.com/113756063/194830221-abe24fcc-484b-4769-b3b7-ec6d8138f436.png"); + // 閫URL瑕啣曉拚 + ColorMatrix parse1 = ColorMatrix.parse(url); + // 亦蝏曉 + parse1.show("image"); + // 颲箏曉 ASCII 啣潘颲箄銝 G 憸脫啣 憭找 40 颲箇泵 'A' 嗅颲箇泵 ' ' + parse1.save( + new File("C:\\Users\\zhao\\Desktop\\fsDownload\\res.txt"), + ColorMatrix._G_, 40, 'A', ' ' + ); + } +} +``` + +* Ability to manually create an empty DataFrame object and independently manipulate the data therein. + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.table.DataFrame; +import zhao.algorithmMagic.operands.table.FDataFrame; +import zhao.algorithmMagic.operands.table.FieldCell; +import zhao.algorithmMagic.operands.table.FinalSeries; + +public class MAIN1 { + public static void main(String[] args) { + // 撱箔銝芰征 DF 撖寡情 隞 name 雿銝箄銝駁桃揣撘 + FDataFrame create = FDataFrame.select(FieldCell.parse("name", "sex", "phoneNum"), 1); + // 乩鈭唳 + DataFrame insert = create.insert( + FinalSeries.parse("zhao", "M", "110xxxxxxxx"), + FinalSeries.parse("tang", "W", "110xxxxxxxx"), + FinalSeries.parse("yang", "M", "110xxxxxxxx") + ); + // 亦唳桅 + System.out.println(insert); + // 撠嗡葉 name sex 亥砭 + System.out.println( + insert.select( + FieldCell.$("name").as("AllName"), + FieldCell.$("sex").as("AllSex") + ) + ); + } +} +``` + +* 舀 group 嗅摰 where摮伐雿踹霈∠憭批之憓撘 + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.table.DataFrame; +import zhao.algorithmMagic.operands.table.FDataFrame; +import zhao.algorithmMagic.operands.table.FieldCell; +import zhao.algorithmMagic.operands.table.FinalSeries; + +import java.net.MalformedURLException; + +public class MAIN1 { + public static void main(String[] args) { + // 撱箔銝芰征 DF 撖寡情 隞 name 雿銝箄銝駁桃揣撘 + FDataFrame create = FDataFrame.select(FieldCell.parse("name", "sex", "phoneNum"), 1); + // 乩鈭唳 + DataFrame insert = create.insert( + FinalSeries.parse("zhao1", "M", "110xxxxxxxx"), + FinalSeries.parse("tang2", "W", "120xxxxxxxx"), + FinalSeries.parse("yang3", "W", "110xxxxxxxx"), + FinalSeries.parse("zhao4", "M", "120xxxxxxxx"), + FinalSeries.parse("tang5", "W", "110xxxxxxxx"), + FinalSeries.parse("yang6", "W", "110xxxxxxxx"), + FinalSeries.parse("zhao7", "M", "120xxxxxxxx"), + FinalSeries.parse("tang8", "W", "110xxxxxxxx"), + FinalSeries.parse("yang9", "W", "110xxxxxxxx") + ); + // 亦唳桅 + System.out.println(insert); + // 撠嗡葉箏瑕銝雿銝銝 120 唳株批嗡葉 sex 蝏 刻湔乩蝙典蝏嗉皛文喳 + System.out.println( + insert.groupBy("sex", v -> { + // 瑕唳箏瑞摮蝚虫葡 + String s = v.getCell(2).toString(); + // 斗剖 3 銝芸蝚行臬虫蛹 120 嚗臬虫誑 120 撘憭湛 憒臬停銝瘛餃 + return !s.startsWith("120"); + }).count() + ); + } +} +``` + +* Support for local binarization operations, which can effectively achieve image binarization processing. Compared to + global binarization, functions are more flexible. + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.matrix.ColorMatrix; + +import java.net.MalformedURLException; +import java.net.URL; + +public class MAIN1 { + public static void main(String[] args) throws MalformedURLException { + // 瑕啣曉拚 + ColorMatrix parse = ColorMatrix.parse(new URL("https://img-blog.csdnimg.cn/img_convert/5765bdab08ef6e117d434e7e225b9013.png")); + parse.show("image"); + System.out.println("ok!!!"); + System.out.println(" = " + parse.getRowCount()); + System.out.println("摰 = " + parse.getColCount()); + // 撠曉餈銵撅其澆 + parse.localBinary( + // 摰祆活鈭澆拍憸脤 + ColorMatrix._G_, + // 摰祆活鈭澆箇撅典曉拚菜圈 + 100, + // 摰祆活鈭澆銝剖函拚萎葉憭找撅券潛憸脩 + 0xffffff, + // 摰祆活鈭澆銝剖函拚萎葉撠鈭撅券潛憸脩 + 0, + // 摰祆活鈭澆銝剖券潛閬餈銵敺株啣潘餈舫雿20銝芷潭啣 + -30 + ); + // 亦蝏唳 + parse.show("image"); + } +} +``` + +* DF object data supports saving as HTML files, enabling effective automated page rendering operations. + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.table.DataFrame; +import zhao.algorithmMagic.operands.table.FDataFrame; +import zhao.algorithmMagic.operands.table.FieldCell; +import zhao.algorithmMagic.operands.table.FinalSeries; + +public class MAIN1 { + public static void main(String[] args) { + // 撱箔銝芰征 DF 撖寡情 隞 name 雿銝箄銝駁桃揣撘 + FDataFrame create = FDataFrame.select(FieldCell.parse("name", "sex", "phoneNum", "salary"), 1); + // 乩鈭唳 + DataFrame insert = create.insert( + FinalSeries.parse("zhao1", "M", "110xxxxxxxx", "30000"), + FinalSeries.parse("tang2", "W", "120xxxxxxxx", "30000"), + FinalSeries.parse("yang3", "W", "110xxxxxxxx", "30000"), + FinalSeries.parse("zhao4", "M", "120xxxxxxxx", "30000"), + FinalSeries.parse("tang5", "W", "110xxxxxxxx", "30000"), + FinalSeries.parse("yang6", "W", "110xxxxxxxx", "30000"), + FinalSeries.parse("zhao7", "M", "120xxxxxxxx", "30000"), + FinalSeries.parse("tang8", "W", "110xxxxxxxx", "30000"), + FinalSeries.parse("yang9", "W", "110xxxxxxxx", "30000") + ); + // 颲箄”HTML 嗅亦銵其葉唳 + System.out.println( + insert.into_outHtml("C:\\Users\\Liming\\Desktop\\fsDownload\\res11234.html", "myTable") + ); + } +} +``` + +* Images begin to support the add function, which enables overlapping and merging of image functions under the operation + of the add function! + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.matrix.ColorMatrix; + +import java.sql.SQLException; + +public class MAIN1 { + public static void main(String[] args) { + // 撠銝鈭曉隞嗉蓮X銝箔銝芸曉拚萄笆鞊 + ColorMatrix colorMatrix1 = ColorMatrix.parse("C:\\Users\\Liming\\Desktop\\fsDownload\\test.bmp"); + ColorMatrix colorMatrix2 = ColorMatrix.parse("C:\\Users\\Liming\\Desktop\\fsDownload\\test1.bmp"); + // 撠 colorMatrix2 + colorMatrix1 蝏曉撅蝷箏箸 + (colorMatrix1.add(colorMatrix2)).show("image"); + } +} +``` + +* Support aggregation operations for custom aggregation and built-in data schemes. + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.matrix.ColorMatrix; + +import java.sql.SQLException; + +public class MAIN1 { + public static void main(String[] args) { + // 撠銝鈭曉隞嗉蓮X銝箔銝芸曉拚萄笆鞊 + ColorMatrix colorMatrix1 = ColorMatrix.parse("C:\\Users\\Liming\\Desktop\\fsDownload\\test.bmp"); + ColorMatrix colorMatrix2 = ColorMatrix.parse("C:\\Users\\Liming\\Desktop\\fsDownload\\test1.bmp"); + // 雿輻 agg 賣唬誑蝵桃霈∠寞餈銵銝支葵拚萇撟 + // 銝W賣唬葉蝚砌銝芸耦隞銵函撠望舐拚萎葉蝝餉嚗餈雿輻函舀嚗撟嗅笆頞憸脫啣潸銵閫渡餉摰 + colorMatrix1.agg(colorMatrix2, ColorMatrix.COLOR_SUM_REGULATE).show("image"); + } +} +``` + +* The image matrix supports a corrosion operation function in which redundant feature data can be removed. + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.matrix.ColorMatrix; + +import java.sql.SQLException; + + +public class MAIN1 { + public static void main(String[] args) { + // 撠銝鈭曉隞嗉蓮X銝箔銝芸曉拚萄笆鞊 + ColorMatrix colorMatrix1 = ColorMatrix.parseGrayscale("C:\\Users\\Liming\\Desktop\\fsDownload\\test2.bmp"); + // 撖孵曉餈銵鈭澆 + colorMatrix1.globalBinary(ColorMatrix._G_, 100, 0xffffff, 0); + colorMatrix1.show("銋 image"); + // 撘憪撖孵曉拚菔銵雿 + colorMatrix1.erode(2, 2, false).show("銋 image"); + } +} +``` + +* The addition of columns is supported, but it should be noted that the addition of columns will return a new DataFrame + DF in which the data will be lightly copied. + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.table.*; + +import java.sql.SQLException; + +public class MAIN1 { + public static void main(String[] args) { + // 撱箔銝芰征 DataFrame 撖寡情 + FDataFrame select = FDataFrame.select( + FieldCell.parse("id", "name", "sex", "age"), 1 + ); + // 冽交唳 + select.insert( + FinalSeries.parse("1", "zhao", "M", "19"), + FinalSeries.parse("2", "tang", "W", "18"), + FinalSeries.parse("3", "yang", "W", "20"), + FinalSeries.parse("4", "shen", "W", "19") + ); + // 啣 DF 撖寡情喟靽⊥ + System.out.println( + select.desc() + ); + // 瘛餃銝唳殷其銵函內撟湧臬虫蛹嗆 + DataFrame ageIsE = select.insertColGetNew( + // 啣蝘 + FieldCell.$("AgeIsE"), + // 啣啣潛餉 憒蝚 4 嚗index == 3嚗啣 % 2 == 0 撠望眩rue + cells -> cells.getCell(3).getIntValue() % 2 == 0 ? new FinalCell<>(true) : new FinalCell<>(false) + ); + System.out.println(ageIsE); + } +} +``` + +* Supports operations between table data, and can perform summation and subtraction calculations on all numeric types in + the table. After calculation, a new DF object will be returned. + +```java +package zhao.algorithmMagic; + +import zhao.algorithmMagic.operands.table.*; + +public class MAIN1 { + public static void main(String[] args) { + // 撱箔銝芰征 DataFrame 撖寡情 + FDataFrame select1 = FDataFrame.select( + FieldCell.parse("id", "name", "sex", "age"), 1 + ); + // 冽交唳 + select1.insert( + FinalSeries.parse("1", "zhao", "M", "19"), + FinalSeries.parse("2", "tang", "W", "18"), + FinalSeries.parse("3", "yang", "W", "20"), + FinalSeries.parse("4", "shen", "W", "19") + ); + // 撱箔銝芰征 DataFrame 撖寡情 + FDataFrame select2 = FDataFrame.select( + FieldCell.parse("id", "name", "sex", "age"), 1 + ); + // 冽交唳 + select2.insert( + FinalSeries.parse("1", "zhao", "M", "19"), + FinalSeries.parse("2", "tang", "W", "18"), + FinalSeries.parse("3", "yang", "W", "20") + ); + // 餈銵瘙銝撌桃餈蝞雿 + System.out.println(select1.add(select2)); + System.out.println(select1.diff(select2)); + } +} +``` + +* Note for the new version: All dependencies in this version are marked as provided, which can minimize redundancy and + enable related configuration based on your actual project. Therefore, when performing AS library injection, please + import the following required items in one click. + +```xml + + + + + org.apache.logging.log4j + log4j-slf4j-impl + 2.20.0 + + + + + + org.apache.logging.log4j + log4j-api + 2.20.0 + + + + + org.apache.logging.log4j + log4j-core + 2.20.0 + + + +``` + +### Version update date : 2023-03-26 \ No newline at end of file