|
| 1 | +## PostgreSQL 与 人工智能(AI) |
| 2 | + |
| 3 | +### 作者 |
| 4 | +digoal |
| 5 | + |
| 6 | +### 日期 |
| 7 | +2017-01-05 |
| 8 | + |
| 9 | +### 标签 |
| 10 | +PostgreSQL , AI , 人工智能 , 神经网络 , 机器学习 , MADlib , Greenplum |
| 11 | + |
| 12 | +---- |
| 13 | + |
| 14 | +## 背景 |
| 15 | +想必很多朋友这几天被铺天盖地的AI战胜60位围棋高手的新闻,我们不得不承认,人工智能真的越来越强了。 |
| 16 | + |
| 17 | +http://wallstreetcn.com/node/283152 |
| 18 | + |
| 19 | +1月4日晚,随着古力认输,Master对人类顶尖高手的战绩停留在60胜0负1和,而令人尴尬的是这唯一一场和棋还是因为棋手掉线系统自动判和,并不是棋盘上的局势真的势均力敌了。包括聂卫平、柯洁、朴廷桓、井山裕太在内的数十位中日韩围棋高手,在30秒一手的快棋对决中落败。Master(最新版AlphaGo)网测以60战全胜的战绩收场! |
| 20 | + |
| 21 | +在横扫中日韩顶尖棋手,豪取47连胜之后,昨晚神秘的“Master”再战世界冠军棋手朴廷桓,元晟溱,和中国第一人柯洁。随着柯洁黯然投子,Master的连胜纪录已扩大至50盘,难逢敌手。 |
| 22 | + |
| 23 | +今天早些时候,Master挑战人类顶尖高手第54局,中国棋圣、64岁的聂卫平出战。《新闻晨报》报道,本局“Master”特意把比赛用时调整为每方1分钟一手,以示对聂卫平的尊敬,最终执白的聂卫平以7目半的劣势落败。神秘AI围棋Master战胜棋圣聂卫平,54连胜。 |
| 24 | + |
| 25 | +## 人工智能知识背景 |
| 26 | + |
| 27 | +http://mp.weixin.qq.com/s/Chln4htaCq1rQWTpPgFYZg |
| 28 | + |
| 29 | +## 与PostgreSQL下一场国际象棋 |
| 30 | +PostgreSQL的用户有点疯狂,看看他们怎么让PostgreSQL和你玩国际象棋吧。 |
| 31 | + |
| 32 | +http://pgxn.org/dist/pg2podg/ |
| 33 | + |
| 34 | +http://pgxn.org/dist/pgchess/ |
| 35 | + |
| 36 | +### 部署 |
| 37 | + |
| 38 | +``` |
| 39 | +wget http://api.pgxn.org/dist/pg2podg/0.1.3/pg2podg-0.1.3.zip |
| 40 | +wget http://api.pgxn.org/dist/pgchess/0.1.7/pgchess-0.1.7.zip |
| 41 | + |
| 42 | +unzip pg2podg-0.1.3.zip |
| 43 | +unzip pgchess-0.1.7.zip |
| 44 | + |
| 45 | +cd pg2podg-0.1.3 |
| 46 | +make clean; make; make install |
| 47 | + |
| 48 | +cd ../pgchess-0.1.7 |
| 49 | +make clean; make; make install |
| 50 | +``` |
| 51 | + |
| 52 | +部署结束 |
| 53 | + |
| 54 | +``` |
| 55 | +-rw-r--r-- 1 digoal users 94 Jan 6 10:05 pg2podg.control |
| 56 | +-rw-r--r-- 1 digoal users 21K Jan 6 10:05 pg2podg--0.1.3.sql |
| 57 | +-rw-r--r-- 1 digoal users 131 Jan 6 10:05 pgchess.control |
| 58 | +-rw-r--r-- 1 digoal users 14K Jan 6 10:05 pgchess--0.1.7.sql |
| 59 | + |
| 60 | +-rwxr-xr-x 1 digoal users 22K Jan 6 10:05 chess.so |
| 61 | +``` |
| 62 | + |
| 63 | +将游戏加载到PostgreSQL数据库中 |
| 64 | + |
| 65 | +``` |
| 66 | +psql -h 127.0.0.1 |
| 67 | +psql (9.4.5) |
| 68 | +Type "help" for help. |
| 69 | + |
| 70 | +postgres=# create extension pgchess; |
| 71 | +CREATE EXTENSION |
| 72 | +postgres=# create extension pg2podg; |
| 73 | +CREATE EXTENSION |
| 74 | +``` |
| 75 | + |
| 76 | +新增了3个数据类型 |
| 77 | + |
| 78 | +``` |
| 79 | +postgres=# \dT |
| 80 | + List of data types |
| 81 | + Schema | Name | Description |
| 82 | +--------+----------+----------------------------------------------------------------------- |
| 83 | + public | game | "moves" is encoded via the %% operators, which throughout this file + |
| 84 | + | | represent a compact textual encoding of a game or a move. + |
| 85 | + | | + |
| 86 | + | | "board" could be computed from "moves", but only for standard games + |
| 87 | + | | (e.g. not for chess problems). Also, remembering "board" is efficient+ |
| 88 | + | | and simpler. + |
| 89 | + | | + |
| 90 | + | | The first 64 characters of "board" represent the chessgame locations;+ |
| 91 | + | | the next four characters encode castling information, and the last + |
| 92 | + | | character is the piece captured in the last move (if any). |
| 93 | + public | location | |
| 94 | + public | move | |
| 95 | +(3 rows) |
| 96 | +``` |
| 97 | + |
| 98 | +玩法参考 |
| 99 | + |
| 100 | +http://api.pgxn.org/src/pgchess/pgchess-0.1.7/doc/pgchess-QUICKSTART.md |
| 101 | + |
| 102 | + |
| 103 | +游戏在以下目录 |
| 104 | + |
| 105 | +``` |
| 106 | +pgchess-0.1.7/test/sql/play |
| 107 | + |
| 108 | +-rw-r--r-- 1 digoal users 160 Oct 19 2012 Human_v_PG.sql |
| 109 | +-rw-r--r-- 1 digoal users 148 Oct 19 2012 new-game.sql |
| 110 | +-rw-r--r-- 1 digoal users 160 Oct 19 2012 PG_v_Human.sql |
| 111 | +-rw-r--r-- 1 digoal users 160 Oct 19 2012 PG_v_PG.sql |
| 112 | +-rw-r--r-- 1 digoal users 242 Oct 19 2012 reset-stats.sql |
| 113 | +-rw-r--r-- 1 digoal users 933 Oct 19 2012 _.sql |
| 114 | +-rw-r--r-- 1 digoal users 854 Oct 19 2012 view-stats.sql |
| 115 | +``` |
| 116 | + |
| 117 | +玩法如下 |
| 118 | + |
| 119 | +Step 1 |
| 120 | + |
| 121 | +``` |
| 122 | +------ |
| 123 | + |
| 124 | +Load a default game in the chessboard: |
| 125 | + |
| 126 | + \i /home/dege.zzz/pgchess-0.1.7/test/sql/play/new-game.sql |
| 127 | +``` |
| 128 | + |
| 129 | +Step 2 |
| 130 | + |
| 131 | +``` |
| 132 | +------ |
| 133 | + |
| 134 | +View the game in FEN notation |
| 135 | + |
| 136 | + gianni=# select %% game from status; |
| 137 | + ?column? |
| 138 | + ---------------------------------------------------------- |
| 139 | + rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1 |
| 140 | + (1 row) |
| 141 | +``` |
| 142 | + |
| 143 | +Step 2a (optional) |
| 144 | + |
| 145 | +``` |
| 146 | +------------------ |
| 147 | + |
| 148 | +If you are using a VT100-compatible terminal, you can use an enhanced |
| 149 | +graphical display. |
| 150 | + |
| 151 | +First make sure that the background is lighter than the foreground (e.g. |
| 152 | +black on white); then issue |
| 153 | + |
| 154 | + gianni=# \pset format unaligned |
| 155 | + Output format is unaligned. |
| 156 | + |
| 157 | +and check that it is working by displaying the current game: |
| 158 | + |
| 159 | +gianni=# select # game from status; |
| 160 | +``` |
| 161 | + |
| 162 | + |
| 163 | + |
| 164 | + |
| 165 | +Step 3 |
| 166 | + |
| 167 | +``` |
| 168 | +------ |
| 169 | + |
| 170 | +Now you can start a CPU v CPU game: |
| 171 | + |
| 172 | + \i play/PG_v_PG.sql |
| 173 | + |
| 174 | +you can interrupt the game with CTRL-C. |
| 175 | + |
| 176 | +Since each half-move is executed in a separate transaction, the game will be left in the state corresponding to the last completed move. |
| 177 | +``` |
| 178 | + |
| 179 | +由于我的终端问题,无法正确的显示图标 |
| 180 | + |
| 181 | + |
| 182 | + |
| 183 | + |
| 184 | +请使用9.4来把玩,9.5以后这个接口有变,需要修改以上两个游戏模块的代码。 |
| 185 | + |
| 186 | +``` |
| 187 | +extern ArrayIterator array_create_iterator(ArrayType *arr, int slice_ndim); |
| 188 | +``` |
| 189 | + |
| 190 | +一个小小的下棋插件,主要体现的是PostgreSQL的开放性,不要把它当成单纯的数据库,它是一个真正的面向对象数据库。 |
| 191 | + |
| 192 | +真的可以实现很多有趣的特性,能帮助业务解决很多的问题,本文末尾有很有很实用的例子,已经帮到了很多用户。 |
| 193 | + |
| 194 | +## Greenplum与PostgreSQL 的机器学习库MADlib |
| 195 | + |
| 196 | +### 在数据库中像生物神经网络一样训练 |
| 197 | + |
| 198 | +http://www.infoq.com/cn/articles/in-database-analytics-sdg-arithmetic |
| 199 | + |
| 200 | +### 一张图读懂madlib |
| 201 | +http://blog.163.com/digoal@126/blog/static/163877040201510119148173 |
| 202 | + |
| 203 | + |
| 204 | +http://mp.weixin.qq.com/s/Chln4htaCq1rQWTpPgFYZg |
| 205 | + |
| 206 | +http://madlib.incubator.apache.org/docs/latest/group__grp__tsa.html |
| 207 | + |
| 208 | +### 大数据与人工智能的结合 |
| 209 | +Greenplum, PostgreSQL, MADLib, R, pivotalR |
| 210 | + |
| 211 | + |
| 212 | +## 参考文档 |
| 213 | + |
| 214 | +PostgreSQL也是一个 "很有爱" 的数据库,用心学习它,用心回报社会吧。 |
| 215 | + |
| 216 | + |
| 217 | + |
| 218 | +[《元旦技术大礼包 - ApsaraDB的左右互搏术 - 解决企业痛处 TP+AP混合需求 - 无须再唱《爱你痛到不知痛》》](./20170101_02.md) |
| 219 | + |
| 220 | +[《Leap second , 闰秒 , 数据库 , PostgreSQL , Solar time , UNIX time , UTC , UT1》](./20170102_01.md) |
| 221 | + |
| 222 | +[《元旦技术大礼包 - 2017金秋将要发布的PostgreSQL 10.0已装备了哪些核武器?》](./20170101_01.md) |
| 223 | + |
| 224 | +[《从天津滨海新区大爆炸、危化品监管聊聊 IT人背负的社会责任感》](../201612/20161228_01.md) |
| 225 | + |
| 226 | +[《PostgreSQL 重复 数据清洗 优化教程》](../201612/20161230_01.md) |
| 227 | + |
| 228 | +[《从难缠的模糊查询聊开 - PostgreSQL独门绝招之一 GIN , GiST , SP-GiST , RUM 索引原理与技术背景》](../201612/20161231_01.md) |
| 229 | + |
| 230 | +[《从真假美猴王谈起 - 让套牌车、克隆x 无处遁形的技术手段思考》](../201612/20161227_01.md) |
| 231 | + |
| 232 | +[《恭迎万亿级营销(圈人)潇洒的迈入毫秒时代 - 万亿user_tags级实时推荐系统数据库设计》](../201612/20161225_01.md) |
| 233 | + |
| 234 | +[《DBA专供 冈本003系列 - 数据库安全第一,过个好年》](../201612/20161224_01.md) |
| 235 | + |
| 236 | +[《聊一下PostgreSQL优化器 - in里面有重复值时PostgreSQL如何处理?》](../201612/20161223_01.md) |
| 237 | + |
| 238 | +[《从相似度算法谈起 - Effective similarity search in PostgreSQL》](../201612/20161222_02.md) |
| 239 | + |
| 240 | +[《一场IT民工 与 人贩子 之间的战争 - 只要人人都献出一点爱》](../201612/20161222_01.md) |
| 241 | + |
| 242 | +[《"物联网"流式处理应用 - 用PostgreSQL实时处理(万亿每天)》](../201512/20151215_01.md) |
| 243 | + |
| 244 | +[《为了部落 - 如何通过PostgreSQL基因配对,产生优良下一代》](../201606/20160621_1.md) |
| 245 | + |
| 246 | +[《流计算风云再起 - PostgreSQL携PipelineDB力挺IoT》](../201612/20161220_01.md) |
| 247 | + |
| 248 | +[《分析加速引擎黑科技 - LLVM、列存、多核并行、算子复用 大联姻 - 一起来开启PostgreSQL的百宝箱》](../201612/20161216_01.md) |
| 249 | + |
| 250 | +[《金融风控、公安刑侦、社会关系、人脉分析等需求分析与数据库实现 - PostgreSQL图数据库场景应用》](../201612/20161213_01.md) |
| 251 | + |
| 252 | +[《实时数据交换平台 - BottledWater-pg with confluent》](../201612/20161205_02.md) |
| 253 | + |
| 254 | +[《PostgreSQL 在视频、图片去重,图像搜索业务中的应用》](../201611/20161126_01.md) |
| 255 | + |
| 256 | +[《基于 阿里云 RDS PostgreSQL 打造实时用户画像推荐系统》](../201610/20161021_01.md) |
| 257 | + |
| 258 | +[《PostgreSQL 与 12306 抢火车票的思考》](../201611/20161124_02.md) |
| 259 | + |
| 260 | +[《门禁广告销售系统需求剖析 与 PostgreSQL数据库实现》](../201611/20161124_01.md) |
| 261 | + |
| 262 | +[《聊一聊双十一背后的技术 - 物流、动态路径规划》](../201611/20161114_01.md) |
| 263 | + |
| 264 | +[《聊一聊双十一背后的技术 - 分词和搜索》](../201611/20161115_01.md) |
| 265 | + |
| 266 | +[《聊一聊双十一背后的技术 - 不一样的秒杀技术, 裸秒》](../201611/20161117_01.md) |
| 267 | + |
| 268 | +[《聊一聊双十一背后的技术 - 毫秒分词算啥, 试试正则和相似度》](../201611/20161118_01.md) |
| 269 | + |
| 270 | +[《PostgreSQL 9.6 引领开源数据库攻克多核并行计算难题》](../201610/20161001_01.md) |
| 271 | + |
| 272 | +[《PostgreSQL 前世今生》](../201609/20160929_02.md) |
| 273 | + |
| 274 | +[《如何建立GIS测试环境 - 将openstreetmap的样本数据导入PostgreSQL PostGIS库》](../201609/20160906_01.md) |
| 275 | + |
| 276 | +[《PostgreSQL 9.6 单元化,sharding (based on postgres_fdw) - 内核层支持前传》](../201610/20161004_01.md) |
| 277 | + |
| 278 | +[《PostgreSQL 9.6 sharding + 单元化 (based on postgres_fdw) 最佳实践 - 通用水平分库场景设计与实践》](../201610/20161005_01.md) |
| 279 | + |
| 280 | +[《PostgreSQL 9.6 sharding based on FDW & pg_pathman》](../201610/20161027_01.md) |
| 281 | + |
| 282 | +[《PostgreSQL 9.5+ 高效分区表实现 - pg_pathman》](../201610/20161024_01.md) |
| 283 | + |
| 284 | +[《PostgreSQL 数据库安全指南》](../201506/20150601_01.md) |
| 285 | + |
| 286 | +[《PostgreSQL 9.6 黑科技 bloom 算法索引,一个索引支撑任意列组合查询》](../201605/20160523_01.md) |
| 287 | + |
| 288 | +[《PostgreSQL 使用递归SQL 找出数据库对象之间的依赖关系》](../201607/20160725_01.md) |
| 289 | + |
| 290 | +[《用PostgreSQL描绘人生的高潮、尿点、低谷 - 窗口/帧 or 斜率/导数/曲率/微积分?》](../201612/20161203_01.md) |
| 291 | + |
| 292 | +[《用PostgreSQL找回618秒逝去的青春 - 递归收敛优化》](../201612/20161201_01.md) |
| 293 | + |
| 294 | +[《PostGIS 在 O2O应用中的优势》](https://yq.aliyun.com/articles/50922) |
| 295 | + |
| 296 | +[《PostgreSQL 百亿地理位置数据 近邻查询性能》](https://yq.aliyun.com/articles/2999) |
| 297 | + |
| 298 | +[《HybridDB最佳实践, 实现OLAP和OLTP一体化》](https://yq.aliyun.com/articles/66902) |
| 299 | + |
| 300 | + |
| 301 | +[Count](http://info.flagcounter.com/h9V1) |
| 302 | + |
| 303 | + |
0 commit comments