This file contains hidden or 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
""" | |
A*アルゴリズムの実装です. | |
手順はWikipedia(https://ja.wikipedia.org/wiki/A*)の解説と同じです | |
""" | |
def generate_path(parents, start_node, goal_node): | |
"""経路上のノードの親子関係を記録した辞書(parents)から経路を復元する""" | |
c = goal_node | |
path = [goal_node] | |
while c != start_node: |
This file contains hidden or 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
function plot_bisection_method(f, a, b; | |
n_max_iter=20, n_samples=100, interval=1000) | |
xrange, yrange, xs, ys = init_xs_ys(f, a, b, n_samples) | |
fig, ax = init_figure_plot() | |
function draw(i) | |
cla() | |
ax[:set_xlabel]("x") | |
ax[:set_ylabel]("f(x)") |
This file contains hidden or 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
from itertools import permutations, combinations | |
import numpy as np | |
from numpy.linalg import det | |
from matplotlib.patches import FancyArrowPatch | |
from matplotlib import pyplot as plt | |
from mpl_toolkits.mplot3d import proj3d | |
from mpl_toolkits.mplot3d import Axes3D |
This file contains hidden or 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 PyPlot | |
using PyCall | |
function generate_Lᵢ(xs, ys, i) | |
function Lᵢ(x) | |
n, d = 1, 1 | |
for (j, xⱼ) in enumerate(xs) | |
if i == j | |
continue |
This file contains hidden or 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 Base.Test | |
function integrate(f, a, b, n_samples=100) | |
assert(b > a) | |
h = (b - a) / n_samples | |
xs = linspace(a, b, n_samples) | |
ys = [f(x) for x in xs] | |
h * ((ys[1] + ys[end]) / 2 + sum(ys[2:end-1])) | |
end |
This file contains hidden or 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 Base.Test | |
using Iterators: filter | |
using Distributions | |
function h_xs_ys(f, a, b, n_parts) | |
h = (b - a) / n_parts | |
xs = linspace(a, b, n_parts + 1) | |
ys = [f(x) for x in xs] | |
h, xs, ys |
This file contains hidden or 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
from xml.etree import ElementTree as ET | |
from bs4 import BeautifulSoup | |
from gensim.models.doc2vec import Doc2Vec, TaggedDocument, DocvecsArray | |
# root = tree.getroot() | |
# for neighbor in root.iter("neighbor"): | |
# print(neighbor) | |
MIN_LINE_LENGTH = 80 | |
def generate_documents(): |
This file contains hidden or 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 PyPlot | |
using PyCall | |
PyDict(pyimport("matplotlib")["rcParams"])["font.size"] = 18 | |
include("ode_solvers.jl") | |
f(x, y) = -3sin(10*x) / exp(x+y^2) |
This file contains hidden or 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 numpy as np | |
from matplotlib.animation import FuncAnimation | |
from matplotlib import pyplot as plt | |
from mcl import Environment, MCL, Agent | |
def particle_weight(particle_observation, agent_observation): | |
return 1 if particle_observation == agent_observation else 0 |
This file contains hidden or 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 numpy as np | |
from matplotlib.animation import FuncAnimation | |
from matplotlib import pyplot as plt | |
from mcl import Environment, MCL, Agent | |
def particle_weight(particle_observation, agent_observation): | |
return 1 if particle_observation == agent_observation else 0 |