'Hopfield'에 해당되는 글 3

  1. 2009/04/09 Hopfield network algorithm (1)
  2. 2009/03/24 Hopfield network 데모 (4)
  3. 2009/02/14 Hopfield network의 루비 구현 (3)
 

Hopfield network algorithm

신경망 | 2009/04/09 23:48 | Posted by DMW
크리에이티브 커먼즈 라이선스
Creative Commons License

냉무 >_<
저작자 표시 비영리 동일 조건 변경 허락

댓글을 달아 주세요

  1. Favicon of http://shieldhorizon.com BlogIcon PEPE 2009/04/20 00:58  댓글주소  수정/삭제  댓글쓰기

    아오 여기글보다가 교수님이 하라고 던져준 neural network using c-sharp 어쩌구 책이 갑자기 생각이났넥,,

Hopfield network 데모

신경망 | 2009/03/24 08:35 | Posted by DMW
크리에이티브 커먼즈 라이선스
Creative Commons License
간단한 데모 프로그램입니다.

HELLO 라는 문자 페턴을 학습시키구...노이즈가 섞인 입력이 들어갔을때
그걸 원래의 패턴으로 수렴시키는 과정을 볼 수 있다능


http://www.filepang.co.kr/entry/Hopfield-network의-루비-구현

소스 코드는 위의 링크랑 별 다를게 업ㅂ구...'HELLO' 패턴을 타이핑하는게 무지 귀찬았다능 -_-;;
저작자 표시 비영리 동일 조건 변경 허락

댓글을 달아 주세요

  1. sloth 2009/03/24 11:31  댓글주소  수정/삭제  댓글쓰기

    우와아 신기하다능!!!!

  2. sloth 2009/03/25 11:04  댓글주소  수정/삭제  댓글쓰기

    하악하악

  3. Favicon of http://www.filepang.co.kr BlogIcon DMW 2009/03/25 18:29  댓글주소  수정/삭제  댓글쓰기

    읭읭 읭읭 읭읭

Hopfield network의 루비 구현

신경망 | 2009/02/14 18:39 | Posted by DMW
크리에이티브 커먼즈 라이선스
Creative Commons License
역시 별 내용은 업ㅂ구 소스 코드만 나온다능

require "matrix"
require "pp"

class Hopfield
    attr_reader :output_pattern
    
    def initialize(pattern_size)
        @pattern_size = pattern_size
        @w = Matrix[ *[].fill([].fill(0, 0, @pattern_size), 0, @pattern_size) ]
    end
    
    def learn(pattern)
        delta_w = Matrix[pattern].t * Matrix[pattern]        
        @w += delta_w - Matrix.I(@pattern_size)
    end
    
    def recall(input_pattern, iteration_sequence)
        old_output = [].fill(rand, 0, @pattern_size)
        new_output = input_pattern
        
        while true
            iteration_sequence.each do |iter|
                net = input_pattern[iter] + Vector[*input_pattern].inner_product(@w.column(iter))
                new_output[iter] = af(net, new_output[iter])
                print "#{iter+1} : "
                pp new_output
            end
            puts
            if old_output == new_output
                @output_pattern = new_output
                break
            else
                old_output = new_output
            end
        end
    end
    
    private
    def af(x, net)
        if x > 0
            +1
        elsif x == 0
            net
        else
            -1
        end
    end
end

x = [ [+1, +1, -1, -1], [-1, -1, +1, +1] ]

net = Hopfield.new(4)

x.each do |i|
    net.learn i
end

puts "sequence [2, 1, 4, 3]"
net.recall [+1, -1, -1, -1], [1, 0, 3, 2]
puts "sequence [4, 1, 3, 2]"
net.recall [+1, -1, -1, -1], [3, 0, 2, 1]


Output:
sequence [2, 1, 4, 3]
2 : [1, 1, -1, -1]
1 : [1, 1, -1, -1]
4 : [1, 1, -1, -1]
3 : [1, 1, -1, -1]

2 : [1, 1, -1, -1]
1 : [1, 1, -1, -1]
4 : [1, 1, -1, -1]
3 : [1, 1, -1, -1]

sequence [4, 1, 3, 2]
4 : [1, -1, -1, -1]
1 : [1, -1, -1, -1]
3 : [1, -1, -1, -1]
2 : [1, 1, -1, -1]

4 : [1, 1, -1, -1]
1 : [1, 1, -1, -1]
3 : [1, 1, -1, -1]
2 : [1, 1, -1, -1]


저작자 표시 비영리 동일 조건 변경 허락

댓글을 달아 주세요

  1. Favicon of http://www.filepang.co.kr BlogIcon DMW 2009/02/19 13:33  댓글주소  수정/삭제  댓글쓰기

    지금보니까 좀 이상하네....하지만 귀차느니까 고치진 않는다능. recall 메소드에서
    new_output = input_pattern 를 new_output = input_pattern.clone 로
    net = input_pattern[iter] + Vector[*input_pattern].inner_product(@w.column(iter)) 를
    net = new_output[iter] + Vector[*new_output].inner_product(@w.column(iter)) 로 바꿔야 될꺼임

  2. Favicon of http://marocchino.tistory.com BlogIcon progr_ 2009/02/22 19:10  댓글주소  수정/삭제  댓글쓰기

    이론을 보르니 입력 * 결과가 무슨 의미인지 모르겠다능 ..;ㅅ; 어흐흐흐 늅늅.