Skip to content

Instantly share code, notes, and snippets.

View cocomoff's full-sized avatar
🏠
Working from home

Keisuke OTAKI cocomoff

🏠
Working from home
View GitHub Profile
@cocomoff
cocomoff / main.py
Created October 25, 2023 14:10
Smallest running example of GCN-like processing using PyTorch Geometric
import networkx as nx
import torch
import torch_geometric
from torch.nn import Linear, Parameter
from torch_geometric.data import Data
from torch_geometric.nn import MessagePassing
from torch_geometric.utils import add_self_loops, degree, from_networkx
def get_graph() -> nx.Graph:
@cocomoff
cocomoff / tsp_ls_naive.jl
Last active March 31, 2023 16:49
Naive local search
mutable struct TSP
name::String
num::Int
coord::Array{Float64, 2}
end
function read(fn::String = "./data/rat783.tsp")
tspname = ""
tspn = 0
coords = nothing
# C++ source at geeksforgeeks: https://www.geeksforgeeks.org/implementation-of-0-1-knapsack-using-branch-and-bound/
using DataStructures
struct Item
weight::Float64
value::Int
end
mutable struct Node
@cocomoff
cocomoff / graph.jl
Created October 15, 2021 15:26
graph example
using Plots
gr()
f1(x) = sin(x)
f2(x) = cos(x)
x = 0.0:0.2:2π
y1 = f1.(x);
y2 = f2.(x);
l = @layout [a{0.8w} b]
@cocomoff
cocomoff / network.xml
Created June 24, 2021 01:25
network.xmlのparse
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE network SYSTEM "http://www.matsim.org/files/dtd/network_v1.dtd">
<network name="equil test network">
<nodes>
<node id="1" x="-20000" y="0"/>
<node id="2" x="-15000" y="0"/>
<node id="3" x="-865" y="5925"/>
<node id="4" x="-2498" y="4331"/>
<node id="5" x="-3829" y="3215"/>
@cocomoff
cocomoff / kuso_walk.jl
Created March 16, 2021 13:20
kuso random-walk program
using LightGraphs
using GraphPlot
using Colors
using Cairo
using Compose
using Plots
using StatsBase
gr()
# plot example
# see https://qiita.com/takechanman1228/items/6d1f65f94f7aaa016377
from sklearn.decomposition import NMF
import numpy as np
R = np.array([
[5, 3, 0, 1],
[4, 0, 0, 1],
[1, 1, 0, 5],
[1, 0, 0, 4],
@cocomoff
cocomoff / example.jl
Created May 7, 2020 01:48
softmin, softmax, softcramp in Julia
using Plots
gr()
function softmax(x, y)
maxxy = max.(x, y)
minxy = min.(x, y)
maxxy .+ log.(1.0 .+ exp.(minxy .- maxxy))
end
softmin(x, y) = -log.(exp.(-x) .+ exp.(-y))
softcramp(x, min, max) = softmax(softmin(x, max), min) # . がいるかも
@cocomoff
cocomoff / example_bi_search.py
Created May 1, 2020 05:50
python bidirectional search
# Implementation https://stackoverflow.com/questions/54437905/bidirectional-search using deque
class Node:
def __init__(self, val, neighbors=[]):
self.val = val
self.neighbors = neighbors
self.visited_right = False # whether the node was reached by the BFS that started from source
self.visited_left = False # whether the node was reached by the BFS that started from destination
self.parent_right = None # used for retrieving the final path from source to the meeting point
self.parent_left = None # used for retrieving the final path from the meeting point to destination
@cocomoff
cocomoff / super_simple_bm.rs
Created April 22, 2020 05:01
とてもシンプルなボルツマンマシン的なやつの計算
#[derive(Debug)]
struct Boltzmann {
n: usize, // number of nodes {1,2,...,n}
edges: Vec<(usize, usize)>, // list of edges
bias: Vec<f64>, // node parameter (on node)
weights: Vec<f64>, // weight parameter (on edge)
}
impl Boltzmann {
fn phi(&self, x: &Vec<usize>) -> f64 {