This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mutable struct TSP | |
name::String | |
num::Int | |
coord::Array{Float64, 2} | |
end | |
function read(fn::String = "./data/rat783.tsp") | |
tspname = "" | |
tspn = 0 | |
coords = nothing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using LightGraphs | |
using GraphPlot | |
using Colors | |
using Cairo | |
using Compose | |
using Plots | |
using StatsBase | |
gr() | |
# plot example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) # . がいるかも |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[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 { |
NewerOlder