离散型hopfield神经网络。参考自http://web.cs.ucla.edu/~rosen/161/notes/hopfield.html实现的草稿版本:

# http://web.cs.ucla.edu/~rosen/161/notes/hopfield.html

attractors = np.array([[0, 1, 1, 0, 1], [1, 0, 1, 0, 1]])
print('attractors:\n', attractors) weight_matrix = np.zeros((5, 5))
print('weight_matrix:\n', weight_matrix)
# 第一个向量表示第一个节点到各个节点的权值 # 初始化网络,权值是对称的,例如w12 = w21,而w11 w22都是0
# for i in range(len(weight_matrix)):
def reflect_about_the_diagonal(matrix):
# 将矩阵上三角翻转拷贝到下三角
matrix += matrix.T - np.diag(matrix.diagonal()) for attractor in attractors:
temp_matrix = np.zeros((5, 5))
for i in range(0, 4):
for j in range(i + 1, 5):
temp_matrix[i, j] = (2 * attractor[i] - 1) * (2 * attractor[j] - 1)
weight_matrix += temp_matrix reflect_about_the_diagonal(weight_matrix)
print('weight_matrix:\n', weight_matrix) # print(weight_matrix[2].dot(attractors[0])) # 类似于bp里的预测,som里的map
def xxxx(input_vector):
vector = input_vector.copy() stable_state = False random_order = np.arange(len(attractors[0])) while not stable_state:
# 生成一个随机序列,以随机的顺序更新节点
np.random.shuffle(random_order)
stable_state = True
for i in random_order:
original_value = vector[i]
vector[i] = weight_matrix[i].dot(vector)
if (vector[i] >= 0):
vector[i] = 1
else:
vector[i] = 0
if (vector[i] != original_value):
print(i, "change ", original_value, '->', vector[i])
stable_state = False return vector x = [1, 1, 1, 1, 1]
print('test:', x, '->', xxxx(np.array(x)))

Python笔记 #21# DHNN的更多相关文章

  1. python笔记21(面向对象课程三)

    今日内容 嵌套 特殊方法:__init__ type/isinstance/issubclass/super 异常处理 内容回顾 def login(): pass login() class Acc ...

  2. 13.python笔记之pyyaml模块

    Date:2016-03-25 Title:13.Python笔记之Pyymal模块使用 Tags:Python Category:Python 博客地址:www.liuyao.me 作者:刘耀 YA ...

  3. 8.python笔记之面向对象基础

    title: 8.Python笔记之面向对象基础 date: 2016-02-21 15:10:35 tags: Python categories: Python --- 面向对象思维导图 (来自1 ...

  4. python笔记 - day5

    python笔记 - day5 参考: http://www.cnblogs.com/wupeiqi/articles/5484747.html http://www.cnblogs.com/alex ...

  5. s21day06 python笔记

    s21day06 python笔记 一.昨日内容回顾及补充 回顾 补充 列表独有功能 reverse:反转 v = [1,2,3,4,5] v.reverse() #[5,4,3,2,1] sort: ...

  6. python笔记-1(import导入、time/datetime/random/os/sys模块)

    python笔记-6(import导入.time/datetime/random/os/sys模块)   一.了解模块导入的基本知识 此部分此处不展开细说import导入,仅写几个点目前的认知即可.其 ...

  7. python笔记(2)--字符串

    一.字符串 字符串是不可变序列,具有序列的公共操作方法,具体操作见python笔记(1)--序列(列表 元组 range) 1.创建字符串 单引号:'Hello , I am Logan ! ' 双引 ...

  8. python笔记06

    python笔记06 数据类型 上个笔记内容补充 补充 列表 reverse,反转. v1 = [1,2,3111,32,13] print(v1) v1.reverse() print(v1) v1 ...

  9. Python笔记之不可不练

    如果您已经有了一定的Python编程基础,那么本文就是为您的编程能力锦上添花,如果您刚刚开始对Python有一点点兴趣,不怕,Python的重点基础知识已经总结在博文<Python笔记之不可不知 ...

随机推荐

  1. Spring boot 整合hive-jdbc导致无法启动的问题

    使用Spring boot整合Hive,在启动Spring boot项目时,报出异常: 经过排查,是maven的包冲突引起的,具体做法,排除:jetty-all.hive-shims依赖包.对应的po ...

  2. ssh tunnel 三种模式

    环境介绍: 主机 位置 公网 内网IP 角色 host-a 局域网1 否 192.168.0.1 ssh client host-b 局域网2.公网 是 192.168.1.1 ssh server ...

  3. [LeetCode] 106. Construct Binary Tree from Postorder and Inorder Traversal_Medium tag: Tree Traversal

    Given inorder and postorder traversal of a tree, construct the binary tree. Note:You may assume that ...

  4. Repeater 中TextBox 触发TextChanged事件

    两种方法 1.TextBox 绑定TextChanged 并设置AutoPostBack ="true" ,如果不设置AutoPostBack ="true"则 ...

  5. Mac使用数据线连接ios,安装deb

    原创http://www.cnblogs.com/fply/p/8478702.html mac连接ios mac连接ios需要用到usbmuxd,这个可自行下载 到python-client目录下, ...

  6. cocos2d JS-(JavaScript) 动态生成方法的例子

    function User(properties) { for (var i in properties) { (function (which) { var p = i; which["g ...

  7. 延期版本webstorm(解决许可证过期,注册,激活,破解,码,支持正版,最新可用)

    很多人都发现 http://idea.lanyus.com/ 不能激活了 很多帖子说的 http://15.idea.lanyus.com/ 之类都用不了了 选择 License server (20 ...

  8. 分享一种系统事故&问题处理反馈方式(COE)

    标签: COE, 复盘 如下为2014/11月份的邮件. 丁总,如下为摇钱树标的交易订单号重复事故的发生及处理过程.COE(Correction Of Error)是我们在JD研发部时使用的一种事故& ...

  9. 使用mysqlbinlog从二进制日志文件中查询mysql执行过的sql语句 (原)

    前提MySQL开启了binlog日志操作1. 查看MySQL是否开启binlog(进mysql操作) mysql> show variables like 'log_bin%';       2 ...

  10. java微信小程序调用支付接口

    简介:微信小程序支付这里的坑还是有的,所以提醒各位在编写的一定要注意!!! 1.首先呢,你需要准备openid,appid,还有申请微信支付后要设置一个32位的密钥,需要先生成一个sign,得到pre ...