Skip to content

Instantly share code, notes, and snippets.

View nagataka's full-sized avatar

Takashi Nagata nagataka

View GitHub Profile
@nagataka
nagataka / rsr_pytorch_port.py
Last active July 7, 2026 07:52
TemporalRelationalRanking for Stock Prediction PyTorch port by Claude Opus 4.8
# Clone the repo and replace these three files #
### training/rank_lstm.py ###
"""Rank_LSTM baseline, PyTorch port (Python 3.14 / PyTorch).
Ported from the original TensorFlow 1.x implementation of
"Temporal Relational Ranking for Stock Prediction" (Feng et al., 2019).
In addition to training the sequential LSTM ranking model, this script can
save the per-day sequential embeddings to ``<data>/pretrain/<name>.npy`` so that
@nagataka
nagataka / construct_inverted_index.py
Created January 16, 2026 18:48
A naive script to construct an inverted index
def construct_index(docs):
term_dict = {}
postings = {}
for id, doc in docs.items():
terms = list(set(doc.lower().split()))
for term in terms:
term_count = term_dict.get(term, 0)
term_posting = postings.get(term, None)
@nagataka
nagataka / tech_notes.md
Last active February 23, 2026 18:14
Tech notes

Object detection で得られた結果を利用する際に、「少し(例えば5%)実際のbboxよりも大きな領域をcropしてcontext情報を含めてやると良い」いうことを慣例としてやっていたのだけど、それってどこかで示されているのだっけ?それとも経験的にやっているだけなのだっけ?とふと疑問に思ったので調べてみた。これとかが参考になるか? An Empirical Study of Context in Object Detection

AWS

aws login コマンドを初めて使ってみたが、これであればアクセスキーを作らなくていいので良さそうだなと思った。 https://dev.classmethod.jp/articles/aws-cli-aws-login/

SAM (Segment Anything Model)

@nagataka
nagataka / math_in_english.md
Created February 28, 2021 15:06
数学表現 in English
@nagataka
nagataka / study_lstm.md
Last active February 6, 2021 01:24
Studying LSTM
@nagataka
nagataka / blocking_maze_env01.py
Last active January 15, 2021 05:33
Blocking Maze for OpenAI Gym
# OpenAI gym custom environment mimicking Blocking Maze
# See Sutton and Barto "Reinforcement Learning an Introduction"
# Example 8.2: Blocking Maze
from enum import Enum
import sys
import copy
import gym
from gym import error, spaces, utils
from gym.utils import seeding
@nagataka
nagataka / settings.json
Created September 4, 2020 22:55
VS Code settings.json
{
"python.formatting.provider": "black",
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"python.linting.flake8Args": [
"--ignore=E501,W503"
],
"python.sortImports.args": [
"-m 3"
],
@nagataka
nagataka / kelly_criterion.py
Created May 11, 2020 05:34
Experiment on coin flipping game
import random
import numpy as np
np.random.seed(0)
def kerri(p, b):
"""https://en.wikipedia.org/wiki/Kelly_criterion
"""
return (p*(b+1)-1 )/b
N = 300
@nagataka
nagataka / minimal_rllib.py
Created April 21, 2020 22:15
Initial example of using RLlib
import gym
import ray
from ray.rllib.agents.ppo import PPOTrainer, DEFAULT_CONFIG
import pprint as pp
#tune.run(PPOTrainer, config={"env": "Breakout-v0", "use_pytorch": True})
ray.init(num_gpus=1, ignore_reinit_error=True, log_to_driver=False)
# https://github.com/ray-project/ray/blob/master/rllib/agents/ppo/ppo.py#L15
@nagataka
nagataka / notify_slack.sh
Created March 4, 2020 19:28
Send a slack notification
#!/bin/bash
set -eu
### Incoming WebHooks URL
WEBHOOKURL="https://hooks.slack.com/services/FILL_YOUR_WEBHOOKURL"
### channel
CHANNEL=${CHANNEL:-"#notifications"}