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
/* | |
* Your task is to implement the sum() function so that it computes the sum of | |
* all elements in the given array a. | |
*/ | |
fun sum(a: IntArray): Int { | |
when { | |
a.size > 0 -> return a.reduce{s1, s2 -> s1 + s2} | |
else -> println("Array must be longer than 2") | |
} |
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 matplotlib.pyplot as plt | |
import numpy | |
import random | |
def create_datas(): | |
datas = [] | |
for i in range(20): | |
a = 10 * (random.random() - 0.5) | |
datas.append((a, a + 3 * (random.random() - 0.5))) | |
return datas |
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 matplotlib.pyplot as plt | |
import numpy | |
def pca(datas, dim): | |
cov_matrix = cov(transposition(datas)) | |
evs = eigen_vectors(cov_matrix) | |
return [tuple(sum([a*b for a, b in zip(v,d)]) for v in evs[:dim]) for d in datas] | |
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 numpy | |
import random | |
def create_datas(dimension): | |
datas = [] | |
for i in range(50): | |
explanatory = [random.random() for i in range(dimension - 1)] | |
criterion = sum([d * (i + 1) for i, d in enumerate(explanatory)]) + 4 | |
datas.append( (explanatory, criterion + random.random() * 0.3) ) | |
return datas |
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 random | |
def create_datas(): | |
datas = [] | |
for i in range(50): | |
a = random.random() | |
datas.append((a, 3 * a + 2 + (random.random() - 0.5))) | |
return datas | |
def regression_analysis(datas): |
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
def regression_analysis(datas): | |
# x, yの平均値を求める | |
x_ave = sum([d[0] for d in datas]) / len(datas) | |
y_ave = sum([d[1] for d in datas]) / len(datas) | |
# x, yの分散、xyの共分散を求める | |
c_xy = sum([(d[0] - x_ave) * (d[1] - y_ave) for d in datas]) / len(datas) | |
d_x = sum([(d[0] - x_ave) ** 2 for d in datas]) / len(datas) | |
d_y = sum([(d[1] - y_ave) ** 2 for d in datas]) / len(datas) | |
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 random | |
def create_datas(): | |
datas = [] | |
for i in range(50): | |
a = random.random() | |
datas.append((a, 3 * a + 2 + (random.random() - 0.5))) | |
return datas |
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 random | |
import itertools | |
import neuron | |
from IPython import embed | |
from IPython.terminal.embed import InteractiveShellEmbed | |
class NeuralNetwork(): | |
def __init__(self, layers, learn_rate): |
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
test = [1, 2, 3, [4, 5], 6, 7, [8, [9, 10]], [[11, 12, [13, 14]]]] | |
def greedy_flatten(seq): | |
if not isinstance(seq, list): | |
return seq | |
seq = seq.copy() | |
while any([isinstance(x, list) for x in seq]): | |
for idx, x in enumerate(seq): | |
if isinstance(seq[idx], list): |
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
# -*- coding: utf-8 -*- | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import pygame | |
from pygame.locals import * | |
import serial | |
import sys | |
import re | |
import time |