https://leetcode.com/problems/01-matrix/

재귀함수 중급 문제인데 너무 오래걸렸다.

막상 짜고 보면 별거 없었는데....

class Solution(object):
    def findzero(self, r, c):
        if self.mat[r][c] == 0:
            self.distanceMap[r][c] = 0
            return self.distanceMap[r][c] + 1

        if self.distanceMap[r][c] != 10000:
            return self.distanceMap[r][c] + 1

        self.distanceMap[r][c] = 10001

        if(c > 0):
            target_r = r
            target_c = c-1
            if self.distanceMap[target_r][target_c] != 10001:
                findDistance = self.findzero(target_r, target_c)
                if self.distanceMap[r][c] > findDistance:
                    self.distanceMap[r][c] = findDistance
                    
        if(c < self.len_c - 1):
            target_r = r
            target_c = c+1            
            if self.distanceMap[target_r][target_c] != 10001:
                findDistance = self.findzero(target_r, target_c)
                if self.distanceMap[r][c] > findDistance:
                    self.distanceMap[r][c] = findDistance

        if(r > 0):
            target_r = r-1
            target_c = c
            if self.distanceMap[target_r][target_c] != 10001:
                findDistance = self.findzero(target_r, target_c)
                if self.distanceMap[r][c] > findDistance:
                    self.distanceMap[r][c] = findDistance

        if(r < self.len_r - 1):
            target_r = r+1
            target_c = c            
            if self.distanceMap[target_r][target_c] != 10001:
                findDistance = self.findzero(target_r, target_c)
                if self.distanceMap[r][c] > findDistance:
                    self.distanceMap[r][c] = findDistance


        return self.distanceMap[r][c] + 1
            
        
    def updateMatrix(self, matrix):
        self.len_r = len(matrix)
        self.len_c = len(matrix[0])
        
        self.distanceMap = [[10000 for k in range(self.len_c)] for l in range(self.len_r)]
        self.mat = matrix

        for i in range(self.len_r):
            for j in range(self.len_c):
                self.distanceMap[i][j] = 10000
                self.findzero(i, j)
                
        return self.distanceMap
        """
        :type matrix: List[List[int]]
        :rtype: List[List[int]]
        """

Posted by 공놀이나하여보세
,

문제 : https://leetcode.com/problems/implement-queue-using-stacks/

불러오는 중입니다...

스택은 나중에 들어간 것이 먼저 나오고,

큐는 먼저 들어간 것이 먼저 나온다.

큐와 스택을 헷깔려서, 마지막에 넣은걸 먼저 꺼냈다가 시간이 좀 걸렸다.

 

파이썬의 리스트를 활용해서 아래와 같이 구현해 보았다.

class MyQueue(object):

    def __init__(self):
        self.data = []
        self.size = 0
        
        """
        Initialize your data structure here.
        """
        

    def push(self, x):
        self.data.append(x)
        self.size += 1
        #print self.data
        
        """
        Push element x to the back of queue.
        :type x: int
        :rtype: None
        """
        
    def pop(self):
        if(self.size > 0):
            self.size -= 1
            pop_data = self.data[0]
            self.data.remove(pop_data)
            return pop_data
            
        return 0
        
        """
        Removes the element from in front of queue and returns that element.
        :rtype: int
        """
        

    def peek(self):
        if(self.size > 0):
            #print self.data[0]
            return self.data[0]
        else:
            return 0
        
        """
        Get the front element.
        :rtype: int
        """
        

    def empty(self):
        if self.size == 0:
            return 1
        else:
            return 0
        
        """
        Returns whether the queue is empty.
        :rtype: bool
        """
        


# Your MyQueue object will be instantiated and called as such:
# obj = MyQueue()
obj.push(x)
# param_2 = obj.pop()
# param_3 = obj.peek()
# param_4 = obj.empty()

Posted by 공놀이나하여보세
,

https://leetcode.com/problems/number-of-islands/

733 Flood Fill 과 비슷한 재귀 함수 문제..

약간만 더 생각하면 되는 문제였다. ㅎㅎ

 

오랜만에 파이썬을 했더니 프린트 하는 문법이 좀 헷깔렸다.

디버깅을 하기 위해 파이썬 2.x에서 프린트를 하려면 아래와 같이 해주면 되었다

괄호도 필요없고, 출력할 값은 %뒤에 괄호로 묶어서 적어주면 되었다.

print "print "grid[%d][%d] = %s" % (i, j, grid[i][j])

 

내가 쓴 답은 허접하지만 공유해 보겠다. ㅎㅎ

 

class Solution(object):
    
    def checkIslands(self, grid, r, c):        
        if self.g[r][c] == '0':
            return 0
        self.g[r][c] = '0'
        
        if r > 0:         self.checkIslands(grid, r-1, c)
        if r < self.r_len - 1: self.checkIslands(grid, r+1, c)   
        if c > 0:         self.checkIslands(grid, r, c - 1)
        if c < self.c_len - 1: self.checkIslands(grid, r, c+1)   
         
        return 1
    
    def numIslands(self, grid):
        self.r_len = len(grid)
        if(self.r_len > 0):
            self.c_len = len(grid[0])
        else:
            return 0
        cnt = 0
        self.g = grid

        for i in range(self.r_len):
            for j in range(self.c_len):
                if self.checkIslands(grid, i, j) == 1:
                    cnt+=1
                
        return cnt
        """
        :type grid: List[List[str]]
        :rtype: int
        """
       

사내 역량평가 준비를 위해 기초 문법 먼저 공부하기로 했다.

1. 232 : implement Queue using Stacks

2. 283 : Move Zeroes

3. 290 : word pattern

4. 485 : Max Consecutive Ones

5. 492 : Construct the Rectangle

 

BST

6. 501. Find Mode in Binary Search Tree
Minimum Absolute Difference in BST
543. Diameter of Binary Tree
563. Binary Tree Tilt

linked list
203. Remove Linked List Elements
206. Reverse Linked List

conversion
504. Base 7

string
557. Reverse Words in a String III
189. Rotate Array
599. Minimum Index Sum of Two Lists

matrix
566. Reshape the Matrix

783. Minimum Distance Between BST Nodes

 

Hash 

705. Design HashSet

 

그 다음에 graph로 넘어가기

Posted by 공놀이나하여보세
,

State, Action, Reward


자율주행 인공지능 

1. State

(1) 도로

(2) 차의 위치와 속도


2. Action

(1) Steering

(2) Accel

(3) Break


3. Reward

(1) 잘 갔는지


Agent => action->Environment-> Reward, state -> Agent


입력에 따라 State가 변함

State 가 안변할 수도 있음


써튼 교수님 책 - Slot machine - state가 안변하는 대표적인 사례


최종 목표

Rewards를 최대화 하는 Action 을 구하라



(1)  Return - Action At 이후에 받은 모든 Reward의 총합

- but 끝이 없는 task라면?? - 연날리기? 

(2) Continuous task 

- Discounted Return 을 최대화 하는 행동을 찾음

(3) Gt = Rt + rGt+1

(4) Value Function

- 어떤 state에 놓여 있을 때 expected discounted return (기대 값)을 최대로 


(5) Bellman Equation - 굉장히 많이 씀

(6) Markov Decision Process?

(7) Monte Carlo Method

- 뭐라도 해본다.

- 단점 : Episode가 끝나야만 알 수 있다.

(8) Q Function

State에서 어떤 Action을 취했을 때의 return

(9) Policy Based 

- State에서 최적의 Action을 알려줌


(10) Deep Deterministic Policy Gradient




Posted by 공놀이나하여보세
,

https://gist.github.com/haje01/0fb6d63bf065c9831256



Posted by 공놀이나하여보세
,
Posted by 공놀이나하여보세
,
가장 빨리 만나는 딥러닝 WITH CAFFE

CUDA Install

http://pythonkim.tistory.com/71

Caffe 설치 시 생기는 문제들은 아래 블로그를 통해 대부분 해결됨
http://iamyoonkim.tistory.com/6

쉘 내부
1. 솔버의 파라미터 : lenet_solver.prototxt
(1) net : 네트워크의 파라미터 파일로 파일 버스를 지정 
lenet_train_test.prototxt 
(2) test_interval: 학습 중 테스트를 실행하는 간격
(3) base_Ir : 학습 시 학습률의 초기값 지정
(4) display : 학습 시 경과를 나타내는 간격
(5) max_iter : 학습을 실행하는 최대 회수 지정
(6) solver_mode : 학습 시 cpu 또는 gpu 선택


2. 네트워크의 파라미터 : lenet_train_test.prototxt

[공통]

(1) name : 계층의 이름을 지정

(2) type : 입력층, 은닉층 타입 지정


[입력층]

(1) top : 입력 데이터와 지도 학습 데이터를 각각 지정

(2) include 

      - phase : 학습 시 또는 테스트 시 어느 경우 그 계층을 이용할 것인지 지정 - TRAIN, TEST

(3) data_param

      - source: 읽기 데이터의 파일 버스를 지정


[은닉층]

(1) Type: "Convolution"은 컨볼루션층을 나타내는 타입

      - bottom: 입력이 되는 계층 지정

      - top : 출력이 되는 계층 지정

      - convolution_param: 컨볼루션층의 파라미터를 지정

              num_output: 컨볼루션층에서의 출력 횟수

              kernel_size: 컨볼루션 창의 크기를 지정

              stride: 컨볼루션 창의 움직이는 크기 지정

(2) Type: "Pooling"은 풀링층을 나타내는 타입

(3) Type: "InnerProduct"는 전결합층을 나타내는 타입


[활성화 함수]

Tanh, Sigmoid, ReLU


[출력층]

Accuracy : 정밀도 산출 

SoftmaxWithLoss : 정밀도 산출




'Machine Learning > Caffe' 카테고리의 다른 글

Docker를 이용해 Caffe 설치  (0) 2018.02.03
Posted by 공놀이나하여보세
,

Object Detect - Tensorflow 이용

https://github.com/MarvinTeichmann/KittiBox


Digits Object Detect - Caffe Digits 이용

https://github.com/NVIDIA/DIGITS/tree/master/examples/object-detection



http://goodtogreate.tistory.com/588



ImportError: No module named nets


export PYTHONPATH="$PYTHONPATH:/home/jaehyeuck/tensorflow/models/slim" 




fastmaskR CNN

https://github.com/CharlesShang/FastMaskRCNN


Posted by 공놀이나하여보세
,

http://pythonkim.tistory.com/71


우분투 무한 로그인


apt로 nvidia-current 를 설치할 경우 무한 로그인에 빠져들 수 있습니다. 

이럴 경우 로그인 화면에서 tty 화면으로 이동합니다.


ctrl + alt + f1


여기에서 로그인 후 기존에 설치된 드라이버를 모두 삭제하고 375 버전을 설치합니다.


sudo apt-get purge nvidia-*

sudo add-apt-repository ppa:graphics-drivers/ppa

sudo apt-get update

sudo apt-get install nvidia-375


그 이후 reboot 명령으로 재시작을 하면 문제 해결~



출처: http://mikelim.mintocean.com/entry/Ubuntu-1604-Nvidia-드라이버-설치-후-무한-로그인-될-경우 [Simple is best]



Posted by 공놀이나하여보세
,

http://dsnight.tistory.com/44


http://www.ftdichip.com/Support/SoftwareExamples/Android_Projects.htm

android.zip 다운

Posted by 공놀이나하여보세
,