离散型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. 后台返回路由的数组,然后根事先写好的路由比对如果相等就放到一个数组中https://www.cnblogs.com/zhengrunlin/p/8981017.html

    https://www.cnblogs.com/zhengrunlin/p/8981017.html 首先,await fetchPermission()获取后台给的权限数组,格式大概如下 { &qu ...

  2. [LeetCode] 35. Search Insert Position_Easy tag: Binary Search

    Given a sorted array and a target value, return the index if the target is found. If not, return the ...

  3. js动态规划---背包问题

    //每种物品仅有一件,可以选择放或不放 //即f[i][w]表示前i件物品恰放入一个容量为w的背包可以获得的最大价值. //则其状态转移方程便是:f[i][w]=max{f[i-1][w],f[i-1 ...

  4. js 图片区域可点击,适配移动端,图片大小随意改变

    实现图片区域可点击,实际上使用map是可以的,但是适配效果并不好,图片只能是固定大小的值,而且点都被写死了. 在这里,我使用的js基于canvas写的一个小工具.可以圈出你需要点击的部分,然后生成一串 ...

  5. 将多行按分隔符"|"合成一行

    原数据文件s.txt api_test account info 参数错误 合并后数据格式 api_test|account||参数错误||||| 方法介绍: 1.sed + xargs sed 's ...

  6. iOS 开发常用链接总结

    知识归纳 1.招聘一个靠谱的程序员 面试题答案 https://github.com/ChenYilong/iOSInterviewQuestions 2.中文 iOS/Mac 开发博客列表 http ...

  7. Oracle如何重启mmon/mmnl进程(AWR自动采集)

    环境:Oracle 11.2.0.4 RAC 现象:sysaux空间满导致无法正常生成快照,清理空间后,手工生成快照可以成功,但是观察自动生成快照依然是不成功. 之前了解到awr对应的相关后台进程是m ...

  8. SSM框架-SpringMVC 实例文件上传下载

    一.新建一个Web工程,导入相关的包 springmvc的包+commons-fileupload.jar+connom-io.jar+commons-logging,jar+jstl.jar+sta ...

  9. DataGridView控件用法一:数据绑定

    使用DataGridView控件,可以显示和编辑来自多种不同类型的数据源的表格数据. 将数据绑定到DataGridView控件非常简单和直观,在大多数情况下,只需设置DataSource属性即可.在绑 ...

  10. spark sql01

    package sql; import org.apache.spark.SparkConf; import org.apache.spark.api.java.JavaSparkContext; i ...