Skip to content

Instantly share code, notes, and snippets.

View kuredev's full-sized avatar
😏

Akira kure kuredev

😏
View GitHub Profile
@kuredev
kuredev / call-sample.php
Created November 18, 2017 11:40
_call(マジックメソッド)の小さなメモ
<?php
class Test{
public function __call($name, $arguments)
{
var_dump($name);
var_dump($arguments);
}
}
@kuredev
kuredev / ref.php
Created November 18, 2017 15:08
リファレンス渡しの小さなメモ
<?php
function test1($n){
$n++;
}
function test2(&$n){
$n++;
}
@kuredev
kuredev / pchart-spline.php
Created November 26, 2017 06:36
pChartでグラフを作成する小さなメモ
<?php
require_once "vendor/autoload.php";
$myData = new CpChart\Data();
$myData->addPoints(array(VOID,3,4,3,5));
$myPicture = new CpChart\Image(700,230,$myData);
$myPicture->setGraphArea(60,40,670,190);
$myPicture->drawScale();
@kuredev
kuredev / test-mnist.php
Created December 8, 2017 07:33
MNISTの画像ファイルの1つ目を表示する
<?php
$image = file_get_contents("train-images.idx3-ubyte");
for($k = 0; $k < 28; $k++){
$cut_image = substr($image, (16+$k*28), 28);
for($i = 0; $i < strlen($cut_image); $i++) {
$value = (int)(ord($cut_image[$i]));
echo $value === 0 ? "0" : "1";
}
@kuredev
kuredev / matrix.php
Created December 11, 2017 01:58
【ゼロから作るDeep Learning】3.3.3の行列の実装メモ
<?php
class Matrix{
private $lineArray = array();
/**
* Matrix constructor.
* @param array $lineArray [[1,2],[3,4]]
* (1,2)
* (3,4)
@kuredev
kuredev / meanSquaredError.php
Last active January 20, 2018 11:01
【ゼロから作るDeep Learning】4.2.1 2乗和誤差のメモ
<?php
$y = [0.1,0.05,0.6,0.0,0.05,0.1,0.0,0.1,0.0,0.0];
$t = [0,0,1,0,0,0,0,0,0,0];
var_dump(meanSquaredError($y, $t));
/**
* @param array $y
* @param array $t
@kuredev
kuredev / numerical_diff.php
Created January 20, 2018 11:01
【ゼロから作るDeep Learning】4.3.2 数値微分
<?php
/**
* @param $f function
* @param $x
*/
function numerical_diff($f, $x){
$h = 1e-4;
return (($f($x + $h) - $f($x - $h))/(2*$h));
}
@kuredev
kuredev / numerical_gradient.php
Created January 29, 2018 08:22
【ゼロから作るDeep Learning】4.4 勾配
<?php
require_once "numerical_diff.php";
/**
* 2変数を前提
*/
function numerical_gradient($f, $x, $y){
$grad = array();
$h = 1e-4;
@kuredev
kuredev / gradient_descent.php
Created February 3, 2018 12:03
【ゼロから作るDeep Learning】4.4.1 勾配法
<?php
$f = function($x, $y){
return pow($x, 2) + pow($y, 2);
};
function numerical_gradient($f, $x, $y){
$h = 1e-4;
//x
$x_ = ($f($x + $h, $y) - $f($x - $h, $y))/(2*$h);
@kuredev
kuredev / matrix.rb
Created February 4, 2018 07:50
行列積の小さなサンプル
require 'matrix'
m = Matrix[[1, 2], [3, 4]]
n = Matrix[[5, 6], [7, 8]]
puts m * n