Skip to content
{{ message }}

Instantly share code, notes, and snippets.

🏠
Working from home

# Keisuke OTAKIcocomoff

🏠
Working from home
Created Jul 2, 2020
View main.py
 # 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],
Created May 7, 2020
softmin, softmax, softcramp in Julia
View example.jl
 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) # . がいるかも
Created May 1, 2020
python bidirectional search
View example_bi_search.py
 # 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
Created Apr 22, 2020
とてもシンプルなボルツマンマシン的なやつの計算
View super_simple_bm.rs
 #[derive(Debug)] struct Boltzmann { n: usize, // number of nodes {1,2,...,n} edges: Vec<(usize, usize)>, // list of edges bias: Vec, // node parameter (on node) weights: Vec, // weight parameter (on edge) } impl Boltzmann { fn phi(&self, x: &Vec) -> f64 {
Created Apr 22, 2020
Rust アンテナ選択 貪欲
View rust_antenna_greedy.rs
 use rand::{Rng, thread_rng}; use rand::distributions::{Uniform}; use std::collections::{HashMap, HashSet}; #[allow(dead_code)] struct Env { rg: f32, // ランダム位置範囲 (-rg, rg) n: usize, // アンテナ数 r: f32, // アンテナの半径 a: Vec<[f32; 2]>, // アンテナの位置
Last active Apr 8, 2020
Rust何も分からない練習帳
View main.rs
 use rand::distributions::{Bernoulli, Distribution}; use rand::prelude::*; // Armは以下の機能を持つ // - 報酬を観察できる trait Arm { fn draw(&self) -> f64; } // ベルヌーイ分布に従うarm
Created Feb 18, 2020
JuliaのDataStructures.jlを利用したDijkstra法の実装例(C++ -> Julia)
View julia_dijkstra_example.jl
 # -*- coding: utf-8 -*- module Dijkstra using DataStructures mutable struct Edge to::Int cost::Int end
Created Dec 11, 2019
segments and intersect
View line_segment_intersect.py
 def line_segment_intersection(p1, p2, p3, p4): d = (p2[0] - p1[0]) * (p4[1] - p3[1]) - (p2[1] - p1[1]) * (p4[0] - p3[0]) if d == 0.0: return None intersect = [0.0, 0.0] u = ((p3[0] - p1[0]) * (p4[1] - p3[1]) - (p3[1] - p1[1]) * (p4[0] - p3[0])) / d v = ((p3[0] - p1[0]) * (p2[1] - p1[1]) - (p3[1] - p1[1]) * (p2[0] - p1[0])) / d if u < 0.0 or u > 1.0 or v < 0.0 or v > 1.0: return None
Created Dec 4, 2019
example of module
View dFrechet.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Created Dec 3, 2019
Plots in Julia for graph visualizer (tentative)
View edge.txt
 1 2 1 3 2 4 3 4 3 5 4 5
You can’t perform that action at this time.