GithubHelp home page GithubHelp logo

9beach / analyze-sgf Goto Github PK

View Code? Open in Web Editor NEW
19.0 6.0 2.0 13.88 MB

Analyze SGF files with KataGo Parallel Analysis Engine to produce Reviewed SGF files.

License: MIT License

JavaScript 91.03% Shell 8.97%
katago sgf baduk weiqi go sabaki rsgf cli

analyze-sgf's Introduction

analyze-sgf

npm version

한국어 | English

analyze-sgf카타고 분석 엔진으로 SGF 및 타이젬 파일(GIB)을 분석해서 승률 그래프, 좋은 수, 나쁜 수를 표시하고 변화도를 제안하여 새로운 기보 파일로 저장합니다.

사바키리지와 카타고를 연동해서 한 수 한 수 실시간으로 기보를 분석할 수도 있지만, analyze-sgf를 이용하면 여러 개의 기보를 한꺼번에 분석해서 결과를 자동으로 저장할 수 있습니다. 이렇게 분석된 기보를 사바키로 열면, 전체 승률 그래프와 변화도를 보면서 중요 부분만 카타고로 분석할 수 있어 편리합니다.

analyze-sgf는 아주 큰 탐색 숫자를 지정해서 카타고에게 몇 시간을 분석하게 한 뒤, 그 결과를 저장해서 재활용하는 방법도 제공합니다. 이것은 실시간으로 카타고를 이용하는 것과는 차원이 다른 깊이를 제공합니다.

설치

analyze-sgf 릴리스에서 실행 파일을 다운로드 하세요. 소스를 받아서 설치하려면 다음을 따르세요.

먼저 Node.js카타고를 설치한 뒤 analyze-sgf를 설치합니다. 맥이나 리눅스 환경에서는 터미널에서 다음을 실행합니다.

npm install -g analyze-sgf

마이크로소프트 윈도우 환경에서는 명령 프롬프트나 PowerShell에서 다음을 실행합니다.

C:\Users\hcho> npm install -g analyze-sgf

업데이트 명령어는 설치 명령어와 동일합니다.

사용법

analyze-sgf를 처음 실행하면 다음과 같이, 홈 디렉터리에 .analyze-sgf.yml 파일을 만들고 기본 사용법을 출력합니다. 윈도우 환경에서는 analyze-sgf가 아닌 analyze-sgf.cmd로 실행해야 하지만 편의상 모두 analyze-sgf로 표시하겠습니다. 이제 사용법을 하나씩 알아봅시다.

$ analyze-sgf
generated: /Users/hcho/.analyze-sgf.yml
Please specify SGF/GIB files.
Usage: analyze-sgf [-a=OPTS] [-g=OPTS] [-k=OPTS] [-s] [-f] FILE ...

Option:
  -a, --analysis=OPTS     Options for KataGo Parallel Analysis Engine query
  -g, --sgf=OPTS          Options for making reviewed SGF files
  -k, --katago=OPTS       Options for path and arguments of KataGo
  -r, --revisit=N         For variation cases, Analyze again with maxVisits N
  -s                      Save KataGo analysis as JSON files
  -f                      Analyze by KataGo JSON files
  -h, --help              Display this help and exit

Examples:
  analyze-sgf baduk-1.sgf baduk-2.gib
  analyze-sgf 'https://www.cyberoro.com/gibo_new/giboviewer/......'
  analyze-sgf -a 'maxVisits:16400,analyzeTurns:[197,198]' baduk.sgf
  analyze-sgf -f baduk.json
  analyze-sgf -g 'maxVariationsForEachMove:15' -r 20000 baduk.sgf

Edit ~/.analyze-sgf.yml for default options
Report analyze-sgf bugs to <https://github.com/9beach/analyze-sgf/issues>
analyze-sgf home page: <https://github.com/9beach/analyze-sgf/>

analyze-sgf를 사용하려면 홈 디렉터리에 있는 .analyze-sgf.yml 파일에 카타고 경로를 설정해야 합니다. .analyze-sgf.yml 파일의 내용은 아래와 같습니다. 이 중에서 "KataGo path here", "KataGo arguments here" 두 값을 설치된 카타고에 맞게 수정해야 합니다. 예시(e.g.)를 참고하세요.

# Please visit <https://github.com/9beach/analyze-sgf>.
#
# Options for path and arguments of KataGo.
katago:
  # e.g., "C:\\Users\\hcho\\KataGo\\katago.exe"
  path: 'KataGo path here'
  # e.g., "analysis -model C:\\Users\\hcho\\KataGo\\katago-best-network.bin.gz -config C:\\Users\\hcho\\KataGo\\analysis_example.cfg"
  arguments: 'KataGo arguments here'

# Options for KataGo Parallel Analysis Engine query.
#
# <https://github.com/lightvector/KataGo/blob/master/docs/Analysis_Engine.md>.
analysis:
  # e.g., "korean", "tromp-taylor", "chinese", ...
  rules: 'tromp-taylor'
  # If input SGF/GIB has no komi field (KM), then uses below.
  komi: 7.5
  boardXSize: 19
  boardYSize: 19
  # Maximum number of root visits.
  maxVisits: 1600

# Options for making reviewed SGF files.
sgf:
  # SGF can put good/bad/hotspot labels on moves for coloring game tree.
  # ......

이제 기보 파일, 가령 신진서-렌샤오.sgfanalyze-sgf를 실행하면 간단한 분석 결과가 출력되고 신진서-렌샤오-analyzed.sgf라는 파일이 생깁니다.

$ analyze-sgf 신진서-렌샤오.sgf
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 100% (208/208, 6.4k visits) | ETA: 0s (20m52s)
generated: 신진서-렌샤오-analyzed.sgf
# Analyze-SGF Report

제13회 춘란배 4강, Komi 7.5, 207수 흑불계승, 2021-01-20

신진서 (Black)
* KataGo top choices (54.81%, 57/104)
* Less than 2% win rate drops (75.00%, 78/104)
* Less than 5% win rate drops (88.46%, 92/104)
* More than 5% win rate drops (11.54%, 12/104): #39 ⇣6.32%, #69 ⇣7.03%, #105 ⇣18.34%, #109 ⇣18.41%, #121 ⇣6.67%, #133 ⇣5.92%, #141 ⇣20.10%, #161 ⇣15.17%, #165 ⇣5.78%, #173 ⇣17.48%, #179 ⇣15.75%, #183 ⇣13.84%
* More than 20% win rate drops (0.96%, 1/104): #141 ⇣20.10%
* Top 10 win rate drops: #141 ⇣20.10%, #109 ⇣18.41%, #105 ⇣18.34%, #173 ⇣17.48%, #179 ⇣15.75%, #161 ⇣15.17%, #183 ⇣13.84%, #69 ⇣7.03%, #121 ⇣6.67%, #39 ⇣6.32%
* Top 10 score drops: #141 ⇣35.84, #143 ⇣10.06, #173 ⇣4.93, #171 ⇣3.14, #145 ⇣1.49, #105 ⇣1.43, #179 ⇣1.25, #109 ⇣1.20, #165 ⇣1.14, #69 ⇣0.88

롄샤오 (White)
* KataGo top choices (52.43%, 54/103)
* Less than 2% win rate drops (74.76%, 77/103)
* Less than 5% win rate drops (81.55%, 84/103)
* More than 5% win rate drops (18.45%, 19/103): #64 ⇣11.43%, #96 ⇣5.20%, #102 ⇣7.88%, #104 ⇣8.71%, #106 ⇣9.51%, #108 ⇣6.93%, #114 ⇣9.05%, #116 ⇣11.45%, #120 ⇣8.97%, #138 ⇣7.90%, #146 ⇣15.73%, #150 ⇣9.34%, #166 ⇣5.62%, #172 ⇣14.41%, #174 ⇣54.39%, #176 ⇣20.59%, #180 ⇣14.40%, #184 ⇣19.62%, #190 ⇣6.76%
* More than 20% win rate drops (1.94%, 2/103): #174 ⇣54.39%, #176 ⇣20.59%
* Top 10 win rate drops: #174 ⇣54.39%, #176 ⇣20.59%, #184 ⇣19.62%, #146 ⇣15.73%, #172 ⇣14.41%, #180 ⇣14.40%, #116 ⇣11.45%, #64 ⇣11.43%, #106 ⇣9.51%, #150 ⇣9.34%
* Top 10 score drops: #146 ⇣52.72, #174 ⇣7.14, #172 ⇣4.61, #176 ⇣1.93, #116 ⇣1.38, #64 ⇣1.25, #140 ⇣1.21, #186 ⇣1.13, #166 ⇣1.13, #102 ⇣0.99

Analyzed by KataGo Parallel Analysis Engine (6415 max visits).

사이버오로의 기보 감상과 타이젬 바둑의 최신기보에서 원하는 기보를 골라 그 인터넷 주소를 analyze-sgf에 입력하면 자동으로 기보를 받아서 분석합니다.

$ analyze-sgf 'https://www.cyberoro.com/gibo_new/giboviewer/......'
downloaded: [제22회 농심배 12국, 2021-02-24] 이치리키 료 vs 신진서 (135수 흑불계승).sgf
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 100% (136/136, 2k visits) | ETA: 0s (6m23s)
generated: [제22회 농심배 12국, 2021-02-24] 이치리키 료 vs 신진서 (135수 흑불계승)-analyzed.sgf
$ analyze-sgf 'http://service.tygem.com/service/gibo2/?seq=......'
downloaded: [제22회 농심배 12국, 2021-02-24] 이치리키 료 vs 신진서 (135수 흑불계승).sgf
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 100% (136/136, 2k visits) | ETA: 0s (6m23s)
generated: [제22회 농심배 12국, 2021-02-24] 이치리키 료 vs 신진서 (135수 흑불계승)-analyzed.sgf

아래의 스크린숏은 신진서-렌샤오-analyzed.sgf 파일을 사바키로 연 모습입니다.

Sabaki Variations Screenshot 사바키로 변화도를 탐색하는 모습

승률이 5% 이상 하락하면 빨간색 점으로, 20% 이상 하락하면 빨간색 리본으로, 2% 이내로 하락하면 초록색 점으로 착수를 표시합니다. 이 기준은 .analyze-sgf.yml에서 minWinrateDropForBadMove, minWinrateDropForBadHotSpot, maxWinrateDropForGoodMove 값을 지정해서 변경할 수 있습니다.

매 수마다 승률 및 집 변동에 관한 정보, 카타고 추천수와 일치 여부, 승률 하락이 큰 수에 대한 링크 등을 포함하고 있어서 빠르게 승부처를 분석할 수 있습니다.

사바키에서 색깔이 검게 반전된 변화도 수순 위에 마우스를 올리면 위의 스크린숏처럼 자동으로 수순이 진행됩니다.

설정

.analyze-sgf.yml 파일은 analyze-sgf의 모든 기본 설정을 저장합니다. 기본 설정을 수정하기 위해 .analyze-sgf.yml 파일을 수정할 수도 있고 analyze-sgf를 실행할 때 지정할 수도 있습니다. 예를 들어, 카타고 분석 엔진의 탐색 숫자를 조절하기 위해서는 analysis 섹션의 maxVisits 값을 변경해야 하는데 다음과 같이, 실행할 때 지정할 수도 있습니다.

analyze-sgf -a 'maxVisits:5000' baduk.sgf

한 수를 분석할 때 카타고 분석 엔진이 얼마나 많은 탐색을 할지는 maxVisits 값으로 설정합니다. 크면 클수록 분석은 더 정확해지지만 시간도 더 많이 걸립니다. 만약 maxVisits을 10000으로 두고, 174, 176 수에 대해 최대 20개의 변화도를 분석하려면 다음을 실행합니다.

analyze-sgf -a 'maxVisits:10000,analyzeTurns:[173,175]' -g 'maxVariationsForEachMove:20,showBadVariations:true' baduk.sgf

-a, -g 옵션은 각각 analysis, sgf를 뜻합니다. 카타고는 0부터 순서를 세기 때문에 174번째 수를 분석하기 위해서는 173을 요청해야 합니다.

analyzeTurns을 지정하면 지정된 수의 변화도만 보여 줍니다. 그러나 analyzeTurns을 지정하지 않으면 승률 하락이 minWinrateDropForVariations보다 큰 모든 수의 변화도를 보여 줍니니다.

이와 같이 .analyze-sgf.yml 파일의 모든 설정은 직접 수정할 수도, 실행할 때 지정할 수도 있습니다.

참고로 덤은, -a 'komi:6.5' 옵션을 따로 주지 않아도 기보 파일의 정보를 이용해서 자동으로 설정합니다.

.analyze-sgf.yml 설정값에 따옴표가 있는 것은 실행 시에도 따옴표를 붙여야 합니다. 즉 아래와 같이 실행해야 합니다.

analyze-sgf -a 'rules:"korean"' baduk.sgf

고급 설정

분석 데이터 저장

카타고로 분석하는 데는 꽤 긴 시간이 걸립니다. 그런데 분석된 기보에는 승률 하락이 minWinrateDropForVariations보다 큰 수의 변화도만 수록되며 분석 이후에 이를 바꿀 수 없습니다. 이것을 바꾸려고 시간을 들여 새로 분석해야 한다면 많이 실망스러울 것입니다. 그래서 -s 옵션으로 카타고 분석 데이터를 저장해 두고 이를 재활용하는 기능이 있습니다.

$ analyze-sgf -s -a 'maxVisits:30000' baduk.sgf
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 100% (136/136, 30k visits) | ETA: 0s (1h15m43s)
generated: baduk.json
generated: baduk-analyzed.sgf

위와 같이 maxVisits에 큰수를 지정하면 긴 시간을 들여 많은 것을 분석합니다. 그리고 그 결과는 -s에 의해 baduk.json으로 저장되었습니다. 아래와 같이 실행하면 카타고가 아닌 baduk.json을 이용해서 실행과 동시에 분석을 끝마칩니다.

analyze-sgf -a 'analyzeTurns:[170,171]' -g 'maxVariationsForEachMove:20,showBadVariations:true' -f baduk.json

이제 171, 172 번째 수의 변화도를 나쁜 변화도까지 포함해서 최대 20개까지 볼 수 있습니다. 저장된 분석 정보를 이용하기 때문에 analyzeTurns를 제외한 maxVisits, komi 등의 -a 옵션 값은 무시됩니다.

몇 시간을 기다릴 수 있다면 -s -a 'maxVisits:100000'과 같이 아주 큰 탐색 숫자를 주고 분석 데이터를 저장하세요. 실시간으로 카타고를 이용하는 것과는 차원이 다른 깊이를 제공합니다.

카타고 분석 데이터에 존재하는 모든 변화도를 보고 싶다면 다음을 실행합니다.

analyze-sgf -g 'minWinrateDropForVariations:-100,showBadVariations:true,maxVariationsForEachMove:100 -f baduk.json'

가변 탐색

maxVisits에 큰 수를 지정하면 분석의 정확도를 높일 수 있지만, 중요하지 않은 착수에도 많은 시간을 들인다는 단점이 있습니다. 이때 가변 탐색을 이용하면 승률 변동이 minWinrateDropForVariations보다 작은 수순의 변화도는 낮게 설정된 maxVisits에 맞춰 분석하고, 큰 수순의 변화도는 별도로 지정한 높은 탐색수에 맞춰 분석할 수 있습니다. 즉, 다음을 실행하면, 승률 변동 5%를 기준으로 그 이상은 50000 방문수로, 그 이하는 1000 탐색수로 분석합니다.

$ analyze-sgf -a 'maxVisits:1000' -g 'minWinrateDropForVariations:5' --revisit 50000 baduk.sgf
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 100% (136/136, 1k visits) | ETA: 0s (3m43s)
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 100% (18/18, 50k visits) | ETA: 0s (19m23s)

주의할 것은 가변 탐색으로 변하는 것은 문제가 된 수의 탐색수가 아니라 그 이전 수의 탐색수라는 점입니다. 그래야 해당 수의 변화도들을 더 폭넓게 탐색할 수 있기 때문입니다.

analyze-sgf --revisit 50000 baduk.sgf로 실행하면 .analyze-sgf.yml에 설정된 maxVisits, minWinrateDropForVariations 값을 이용합니다.

analyze-sgf's People

Contributors

9beach avatar jtraister avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

analyze-sgf's Issues

Feature request: Swap "proposed variations"

I would like to swap the "proposed varations" text with "Bad moves left" in the analyzed SGF file.
Or a option to remove "proposed varations"?

Because on my mobile phone the room for text is limited and I think the "Bad moves left" information is more interesting for me.
Thank you in advance.

This file is unreadable error (Sabaki)

I downloaded a random game from GoKifu (test b.sgf) and KGS (test a and test c.sgf).

Test b-analyzed and test c-analyzed opens successfully in Sabaki and q5go!
but
Test a-analyzed cannot be opended in Sabaki (This file is unreadable error) and q5go (Erros found in SGF file).
I think because Test a is a unfinished game?

Attachments:
test.zip

And a extra question. How do i update analyze.sgf? And how do I check if there is an update?

Thank you in advance!

Error message

Thank you for your great work.
When trying to analyze my sgf like you suggested, (analyze-sgf lee.sgf or analyze-sgf.cmd lee.sgf),
cmd showed the following error message.
Could you help me out?

Oh I figured it out. Thanks!

What does maxVariationsForEachMove mean?

I see there's maxVariationsForEachMove option in .analyze-sgf.yml file. What does the variable mean? I've found "maxVariationsForEachMove" is not a parameter in KataGo. Does the option have effect on the accuracy of predictive win rate?

Does not handle SGF with handicap correctly

Please check moves C16 "Analyze-SGF_1337206 (3200v)".

For example:
-Move 149 (a variant of move 149: C15 C14 .. C9 B18)
-Move 155 (a variant of move 155: C15 C14 .. A8 G8)

Conclusion:
Analyze-sgf does not recognize the stone at C16 (which is the first move). So for example the variants of move 149 and move 155 places two stones on C16. With the analyze of q5go (q5go_Kata_1337206.sgf) this error does not seem to happen.

Attachement:
1x

SGF060321.zip

Does not handle SGF with pass moves

The first 17 moves contains "pass" moves which (maybe) causes the following error:
, while processing: e9.sgfboard location: U20","field":"moves","id":"9beach-1615326819529"}
Due to this error the analyze is halted.

Attached SGF:
e9.zip

Error when analysing multiple SGF

A) four SGF's:
"analyze-sgf 01.sgf 02.sgf 03.sgf 04.sgf"
works.

B) five SGF's:
"analyze-sgf 01.sgf 02.sgf 03.sgf 04.sgf 05.sgf"
crashes with the following error:

0% (0/136, 800 visits) | ETA: 0s (11s)
Process error. Please fix: C:\Users\m.analyze-sgf.yml
{"path":"C:\Users\m\Desktop\Engines\KG\katago.exe","arguments":"analysis -model C:\Users\m\Desktop\Engines\KG\kata1-latest.bin.gz -config C:\Users\m\Desktop\Engines\KG\analysis_example.cfg"}

Attachment:
Test180321.zip

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.