Case = int(input())
num_list = list(map(int, input().split(' ')))

res_counting = 0

for i in num_list:
    cnt = 0
    if(i == 1):
        continue
    for j in range(2, i + 1):
        if(i % j == 0):
            cnt += 1
    if(cnt == 1):
        res_counting += 1
print(res_counting)

'# 코딩 문제 관련 > 파이썬' 카테고리의 다른 글

백준 2581번(python)  (0) 2019.05.31
백준 1929번(python)  (0) 2019.05.31
백준 1181번(python)  (0) 2019.05.30
백준 2108번(python)  (0) 2019.05.30
백준 1427번(python)  (0) 2019.05.29

Abstract

How can we perform efficient inference and learning in directed probabilistic models, in the presence of continuous latent variables with intractable posterior distributions, and large datasets? We introduce a stochastic variational inference and learning algorithm that scales to large datasets and, under some mild differentiability conditions, even works in the intractable case. Our contributions is two-fold. First, we show that a reparameterization of the variational lower bound yields a lower bound estimator that can be straightforwardly optimized using standard stochastic gradient methods. Second, we show that for i.i.d. datasets with continuous latent variables per datapoint, posterior inference can be made especially efficient by fitting an approximate inference model (also called a recognition model) to the intractable posterior using the proposed lower bound estimator. Theoretical advantages are reflected in experimental results.


대규모 데이터셋과 난해한 사후분포에 연속적인 잠재변수가 존재할 때, 확률적 모델을 어떻게 효율적으로 학습시키고 추론할 것인가?

우리는 대규모 데이터셋으로 확장되는 확률적 가변 추론 및 학습 알고리즘을 소개하고, 미분이 힘든 상황에서도 다뤄본다.

contribution은 2가지이다.

첫번째는 variational lower bound의 reparameterization이 확률 경사법을 통해 최적화되어 질 수 있다.

두번째는 데이터 당 연속 잠재변수를 가지는 i.i.d. 데이터셋같은 경우에 제안된 lower bound estimator를 이용하여 대략적인 추론 모델(인식 모델이라고도 불림)을 다루기 힘든 posterior에 fit함으로써 특히 효율적인 추론을 생성해낼 수 있다.

이론적 이점은 experimental results에 나와있다.


요약

  • generative model의 가장 classic한 방법이라고 할 수 있다.
  • variance inference는 우리가 가진 데이터의 복잡한 확률분포를 직접 추정하기는 어려우니 이와 비슷한 분포로 근사하겠다는 의미이다.
  • KL-divergence는 P와 Q의 분포의 거리에 대한 식이다.
  • p(x)를 풀어보면 L(lower bound) + KL-divergence로 풀어놓을 수 있는데, 이때 L을 최대화시키면 p(x)를 maximum하는 것과 같게 된다.
  • reparametriczation이란, backprop시에 sampling하는 부분은 미분을 할 수 없기때문에 바깥으로 빼주어서 결과를 도출한다. 밖으로 빼낸다고해서 결과가 달라지진 않는다.

 

Reference

Kingma, D. P., & Welling, M. (2013). Auto-encoding variational bayes. arXiv preprint arXiv:1312.6114.

1. tensorflow api 다운로드

https://github.com/tensorflow/models

 

tensorflow/models

Models and examples built with TensorFlow. Contribute to tensorflow/models development by creating an account on GitHub.

github.com


2. 본인이 사용하기 편한 경로로 이동시키기


3. protoc이 안깔렸으면 설치가 되어 있어야 합니다. --> protoc을 통한 .py 파일 생성하기

models/research에서 다음을 입력합니다.

protoc object_detection/protos/*.proto --python_out=.

proto파일에 _pb2.py로 끝나는 여러 파일이 생성되었다면 성공입니다.


4.

models/research

에서 다음의 명령어를 실행합니다. 

python setup.py build

python setup.py install

5. 환경변수 설정

다음의 명령어를 실행합니다.

export PYTHONPATH=$PYTHONPATH:[path]:[path]/slim

(여기서 [path]는 models/research 경로를 넣어주면 됩니다.)

예를 들면, /Users/.../models/research

후에 source ~/.bash_profile 을 실행합니다.


6. 설치 확인하기

models/research에서 다음의 명령어를 실행하여 설치를 확인합니다.

python object_detection/builders/mode_builder_test.py

다음 이미지의 결과를 보았다면 성공.


7. .ipynb로 튜토리얼 실행해보기

object_detection경로에 들어가보면 있습니다.


num = int(input())
word_list = []
for word in range(num):
    word_list.append(input())
word_list = set(word_list)
word_dict = dict()
for word in word_list:
    word_dict[word] = len(word)
word_dict = sorted(word_dict, key = lambda x :  [len(x), x.lower()])
for word in word_dict:
    print(word)

'# 코딩 문제 관련 > 파이썬' 카테고리의 다른 글

백준 1929번(python)  (0) 2019.05.31
백준 1978번(python)  (0) 2019.05.31
백준 2108번(python)  (0) 2019.05.30
백준 1427번(python)  (0) 2019.05.29
백준 2751번(python)  (0) 2019.05.29


import sys
from collections import Counter
  
t = int(sys.stdin.readline())
num_list = []
for _ in range(t):
    num_list.append(int(sys.stdin.readline())) 

def mode(x):
    mode_dict = Counter(x)
    modes = mode_dict.most_common()
    if len(x) > 1 : 
        if modes[0][1] == modes[1][1]:
            mod = modes[1][0]
        else : 
            mod = modes[0][0]
    else : 
        mod = modes[0][0]
    
    return mod

print(round(sum(num_list) / len(num_list)))
num_list.sort()
print(num_list[len(num_list) // 2])
print(mode(num_list))
print(num_list[-1] - num_list[0])

- Counter()는 각 num에 대해 빈도수를 dict로 만들어줌

- most_common()은 배열안에 튜플 형식으로 최빈값부터 2번째로 자주 나오는 수.... 를 반환함

- 최빈값이 여러 개인 경우, key값이 작은 것부터 정렬해서 나타내줌.

- 따라서 문제에서는 두번째로 작은 값이므로 1번째 것을 가져오면 됨

'# 코딩 문제 관련 > 파이썬' 카테고리의 다른 글

백준 1978번(python)  (0) 2019.05.31
백준 1181번(python)  (0) 2019.05.30
백준 1427번(python)  (0) 2019.05.29
백준 2751번(python)  (0) 2019.05.29
백준 2750번(python)  (0) 2019.05.29