Python笔记 #21# DHNN
离散型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的更多相关文章
- python笔记21(面向对象课程三)
今日内容 嵌套 特殊方法:__init__ type/isinstance/issubclass/super 异常处理 内容回顾 def login(): pass login() class Acc ...
- 13.python笔记之pyyaml模块
Date:2016-03-25 Title:13.Python笔记之Pyymal模块使用 Tags:Python Category:Python 博客地址:www.liuyao.me 作者:刘耀 YA ...
- 8.python笔记之面向对象基础
title: 8.Python笔记之面向对象基础 date: 2016-02-21 15:10:35 tags: Python categories: Python --- 面向对象思维导图 (来自1 ...
- python笔记 - day5
python笔记 - day5 参考: http://www.cnblogs.com/wupeiqi/articles/5484747.html http://www.cnblogs.com/alex ...
- s21day06 python笔记
s21day06 python笔记 一.昨日内容回顾及补充 回顾 补充 列表独有功能 reverse:反转 v = [1,2,3,4,5] v.reverse() #[5,4,3,2,1] sort: ...
- python笔记-1(import导入、time/datetime/random/os/sys模块)
python笔记-6(import导入.time/datetime/random/os/sys模块) 一.了解模块导入的基本知识 此部分此处不展开细说import导入,仅写几个点目前的认知即可.其 ...
- python笔记(2)--字符串
一.字符串 字符串是不可变序列,具有序列的公共操作方法,具体操作见python笔记(1)--序列(列表 元组 range) 1.创建字符串 单引号:'Hello , I am Logan ! ' 双引 ...
- python笔记06
python笔记06 数据类型 上个笔记内容补充 补充 列表 reverse,反转. v1 = [1,2,3111,32,13] print(v1) v1.reverse() print(v1) v1 ...
- Python笔记之不可不练
如果您已经有了一定的Python编程基础,那么本文就是为您的编程能力锦上添花,如果您刚刚开始对Python有一点点兴趣,不怕,Python的重点基础知识已经总结在博文<Python笔记之不可不知 ...
随机推荐
- [vue]webpack使用样式
webpack: 使用自己写样式 main.js导入全局生效 import Vue from 'vue' import App from './App.vue' import './index.css ...
- [js]promise学习2
let fs = require("fs"), path = require('path'); 普通读取文件方法 /* fs.readFile(path.resolve('./da ...
- solr创建业务域以及指定中文分析器IK
第一步:把中文分析器添加到工程中. 1.把IKAnalyzer2012FF_u1.jar添加到solr工程的lib目录下 2.把扩展词典.配置文件放到solr工程的WEB-INF/classes目录下 ...
- python 类组合
场景:有一辆车违章需要通知到车主 定义两个类车辆类和通知类,车辆类和通知类并没有共同点,但是要通知车主这两个类就有了关联,这时候可以把这两个类组合在一起 #!/usr/bin/python3 # -* ...
- ansible 快速入门
安装 $ sudo apt-get install software-properties-common $ sudo apt-add-repository ppa:ansible/ansible $ ...
- spring的面向切面实现的两种方式
面向切面:主要应用在日志记录方面.实现业务与日志记录分离开发. spring面向切面有两种实现方式:1.注解 2.xml配置. 1.注解实现如下: (1)配置如下: <?xml version= ...
- Pandas 常见的基本方法
说明:文章所有内容均截选自实验楼教程[Pandas 使用教程],想要查看教程完整内容,点击教程即可~ 前言: Pandas 是非常著名的开源数据处理工具,我们可以通过它对数据集进行快速读取.转换.过滤 ...
- nodejs+mysql入门实例(增)
var userAddSql = 'INSERT INTO userinfo(id,username,pwd) VALUES(0,?,?)'; var userAddSql_Params = ['Wi ...
- 时间序列模式(ARIMA)---Python实现
时间序列分析的主要目的是根据已有的历史数据对未来进行预测.如餐饮销售预测可以看做是基于时间序列的短期数据预测, 预测的对象时具体菜品的销售量. 1.时间序列算法: 常见的时间序列模型; 2.时序模 ...
- HDU 4686 Arc of Dream(矩阵)
Arc of Dream [题目链接]Arc of Dream [题目类型]矩阵 &题解: 这题你做的复杂与否很大取决于你建的矩阵是什么样的,膜一发kuangbin大神的矩阵: 还有几个坑点: ...