Skip to content

Commit

Permalink
Merge branch 'Danielyan86-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
hanbingtao committed Dec 19, 2018
2 parents 66a69fa + 505060c commit c2ec5f1
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
10 changes: 9 additions & 1 deletion python3/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
Refactor the code with python3
## refactor with python3
## Classify iris
- problem description:https://en.wikipedia.org/wiki/Iris_flower_data_set
- data source: http://archive.ics.uci.edu/ml/datasets/Iris

## 使用python3重构
## 鸢尾花分类问题
- 问题描述:https://en.wikipedia.org/wiki/Iris_flower_data_set
- 数据集来源 http://archive.ics.uci.edu/ml/datasets/Iris
41 changes: 41 additions & 0 deletions rbm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

from __future__ import print_function

import numpy as np


def sigmoid(x):
return 1.0 / (1.0 + np.exp(-x))


class RBMLayer(object):
def __init__(self, visible_size, hidden_size):
self.visible_size = visible_size
self.hidden_size = hidden_size
self.W = self.initialize_weights()
self.b = self.initialize_visible_bias()
self.c = self.initialize_hidden_bias()

def initialize_weights(self):
return np.random.normal(scale=0.01,
size=(self.visible_size, self.hidden_size))

def initialize_visible_bias(self):
return np.zeros(self.visible_size)

def initialize_hidden_bias(self):
return np.zeros(self.hidden_size)

# 输入观测变量v, 输出隐变量的值h
def forward(self, v):
return sigmoid(np.dot(v, self.W) + self.c)

# 输入隐变量的值h, 输出观测变量值y
def backward(self, h):
return sigmoid(np.dot(h, self.W.T) + self.b)

# k-step contrastive divergence 训练算法
def contrastive_divergence(self, k, data_set):
pass

0 comments on commit c2ec5f1

Please sign in to comment.