æ¯è¨ã¨æè¡
æ®æ®µä½¿ãã³ãã³ãã、å°ã£ããã¨ãã¾ã¨ããåå¿é²çæè¡ããã° ãã¾ã«è¶£å³ã®ãã¿w
ãã¼ã¸
2023å¹´1æ15æ¥æ¥ææ¥
ãµã¤ãã®ç§»å
è¨äºã移åãã¾ãã。
https://www.keydrop.net
Laravel9ãªã©è¨äºã¯æ°è¦ãµã¤ãã«ã¦è¨è¼
2017å¹´8æ20æ¥æ¥ææ¥
Mac Sierraã§apache +PHP5.6ãPHP7.1ãå©ç¨ããæé
PHP5.6=>PHP7.1ãMac Sierraã§å©ç¨ããããã®æé
åºæ¬ã¯ããã§è¡ããã¯ãã§ãã、èªåã®ç°å¢ã§ã¯è¡ãã以ä¸ã対å¿
php.iniãå¤ãã®ãåé¡ã®å¯è½æ§ãé«ã
php5.6ããphp7.1åãã®php.iniãå ¬å¼ãµã¤ãããphp-7.1.8.tar.bz2ãDLã
Downloadãã©ã«ãã«è§£åå¾ä»¥ä¸ãå®æ½
ããã§è¡ãã¾ãã。
å称 | æ¦è¦ |
---|---|
å®è¡æ¥ | 2017/08/20 |
OS | MacOS Sierra |
Apache | 2.4.27 |
Brew | Homebrew 1.3.1 |
$ brew tap homebrew/dupes
$ brew tap homebrew/versions
$ brew tap homebrew/php
$ brew tap homebrew/apache
$ brew update
-- ä¸è¦ãªãå¤ã
$ brew unlink php56
$ brew install php71 --with-httpd24
-- æ®æ®µCakePHPãããå©ç¨ããã®ã§ã¤ãã§ã«æé å
$ brew install php71-intl php71-pdo-pgsql
$ sudo vi /etc/apache2/httpd.conf
-- 以ä¸ã®å¤æ´--
# LoadModule php5_module libexec/apache2/libphp5.so
LoadModule php7_module /usr/local/opt/php71/libexec/apache2/libphp7.so
-------------
$ sudo vi /etc/apache2/other/php7.conf
--- 以ä¸ã追å ---
SetHandler application/x-httpd-php
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
DirectoryIndex index.html index.php
---------------
sudo mv /etc/apache2/other/php5.conf /etc/apache2/other/php5.conf.bk
-- versionãã§ãã¯
$ php -v
$ sudo apachectl restart
åºæ¬ã¯ããã§è¡ããã¯ãã§ãã、èªåã®ç°å¢ã§ã¯è¡ãã以ä¸ã対å¿
less /var/log/apache2/error_log
---- ã¨ã©ã¼ãã°ããã§ã㯠-----
[Sun Aug 20 20:53:25.102393 2017] [mpm_prefork:notice] [pid 86] AH00163: Apache/2.4.25 (Unix) PHP/7.1.8 configured -- resuming normal operations
[Sun Aug 20 20:53:25.102609 2017] [core:notice] [pid 86] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
---------------------------
php.iniãå¤ãã®ãåé¡ã®å¯è½æ§ãé«ã
php5.6ããphp7.1åãã®php.iniãå ¬å¼ãµã¤ãããphp-7.1.8.tar.bz2ãDLã
Downloadãã©ã«ãã«è§£åå¾ä»¥ä¸ãå®æ½
sudo mv /etc/php.ini /etc/php.ini.20170820
sudo cp Downloads/php-7.1.8/php.ini-production /etc/php.ini
ããã§è¡ãã¾ãã。
localhostã§Webããã·ã¥ã®å®ç¾(OneSignalç·¨)
Webããã·ã¥æè¡ãæµè¡ã£ã¦ããã®ã§è©¦ãã«å®è£
åã³ã¾ã¨ãã¦ã¿ã¾ãã。
ç°å¢ã¯ä»¥ä¸ã«è¨è¼ã§ãã、localhostã§è©¦é¨çã«ãã£ã¦ã¿ãã人åãã«æ¸ãã¦ãã¾ã。
OneSignalã¨ãããµã¼ãã¹ãå©ç¨ãã¦å¯¾å¿ãã¦ã¿ã¾ããã以ä¸ã®çç±ã§å¯¾å¿ãã¾ãã。ä»ã«è¯ããã®ããããããããªãã§ããèªåã®ä¸ã§ã¯ãããä¸çªãã£ãããã¾ãã。
åºæ¬çã«Macã触ã£ã¦ããã°åæç¶æ
?ã§å©ç¨ã§ãããã®ãåæã«ãã¦ã¿ã¾ãã。
ã«ç»é²、ç»é²ã«ã¯ã¡ã¢ã&ãã¹ã¯ã¼ãã§OK
GitHubã¨ããã®ä»ã§ãå¯
ããã¯èªåã§é©å½ã«æ±ºããä»åã¯`Test’ã§ä½æ
ä½ãèãã
ã¾ã㯠Safariã®è¨å®ãããã®ã§
å¿ é å ¥åã、ï¼ã¤ã§
æ®ãï¼ã¤ã¯è£½åããªãªã¼ã¹ããã®ãªã触ã£ãæ¹ãè¯ããã¨ãå¾ãä»ã¯æ¾ç½®
ä½ãèãã
ãã®ç»é¢ã«æ¥ãã¨ï¼ã¤ã®ãã¨ãããå¿ è¦ããã
1. æ¿èªç¨HTMLã®ä½æ
2. ãã©ã¦ã¶ããæ¿èª
ã¾ãã¯、
以ä¸ã®ã½ã¼ã¹ãè¨è¼
http://localhost/
ã«ã¢ã¯ã»ã¹ãã¦ã¢ã¯ã»ã¹ã許å¯ããã¦ãµã¤ãã«æ»ã確èªä½æ¥
ã¨ããã¾ã§ãSafariã®è¨å®æ¬¡ã«ãã®ä»ãã©ã¦ã¶å¯¾å¿
å人çã«ã§ããå®ã¯Safariã®æ¹ãç°¡åã§ãã。
ãã®æ¹æ³ã§FireFoxã対å¿å¯è½ã§ã。
å ¥åæ å ±ããã®å ´åã¯、
è²ã 試ããã®ã§ããããããªãã¨æ£ããç»é²ã§ããªã。
ã©ãããChromeãFireFoxã ã¨ãã¼ã«ã«å ã®OneSignalSDKWorker.jsãå¿ è¦ã¿ããã§ãããåã£ã¦æ¥ãå¿ è¦ãããã¾ã。
ãã®å 容ã®æ³¨æãããã¨ãããããã¾ã。
ä¾ãã°ãµã¤ãã®ã¢ã¯ã»ã¹ã
å°ãã¿ã¦ã¿ãã¨Crhomeç¨ã®ãããã°ã³ã³ã½ã¼ã«ã«åºã¦æ¥ãã®ã§å¤±æããå ´åã¯、ã¨ã©ã¼ãã°ããã§ãã¯ãã¦ã¿ãã¨è¯ãã§ã。
ç°å¢ã¯ä»¥ä¸ã«è¨è¼ã§ãã、localhostã§è©¦é¨çã«ãã£ã¦ã¿ãã人åãã«æ¸ãã¦ãã¾ã。
OneSignalã¨ãããµã¼ãã¹ãå©ç¨ãã¦å¯¾å¿ãã¦ã¿ã¾ããã以ä¸ã®çç±ã§å¯¾å¿ãã¾ãã。ä»ã«è¯ããã®ããããããããªãã§ããèªåã®ä¸ã§ã¯ãããä¸çªãã£ãããã¾ãã。
ç¡æã§å©ç¨ã§ããæ©éæ¤è¨¼ç°å¢ãç¾ å
éSSLã§å©ç¨å¯è½
Mac & Windowsç³»ã®ä¸»è¦ãã©ã¦ã¶å¯¾å¿(iOSã¯é対å¿)
ç°å¢ | æ¦è¦ |
---|---|
2017/08/19æ¥æ¤è¨¼ | |
ããã·ã¥ãµã¼ãã¹ | OneSignal |
Webãµã¼ã | macOS Sierraä¸ã«apache(Apache/2.4.25) |
ãã¹ã | http://localhost/~{ã¦ã¼ã¶å}/ |
http://localhost/index.htmlã«å®ç¾ããã¤ã¡ã¼ã¸ã§ã。
1.ãµã¤ãã«ç»é²
https://onesignal.com/ã«ç»é²、ç»é²ã«ã¯ã¡ã¢ã&ãã¹ã¯ã¼ãã§OK
GitHubã¨ããã®ä»ã§ãå¯
ç»é²ä½æ¥ã¯æ¬è³ªã§ã¯ãªãã®ã§çç¥
2.æ°ããããã¸ã§ã¯ãã®è¨å®(Safariç·¨)
2-1.ããã¸ã§ã¯ãåã®å ¥å
Add a new app
ãæ¼ãæ°è¦ä½æ ããã¯èªåã§é©å½ã«æ±ºããä»åã¯`Test’ã§ä½æ
2-2.WebSite Pushãæå®
WebSiet Push
ãé¸æ2-3.Apple Safariãæå®
Apple Safari
ãæå®2-4.ãã¹ããµã¤ãæ å ±ãæå®
å¿ é å ¥åã、ï¼ã¤ã§
Site Name
ããã¯é©å½ã§è¯ãä»åã¯Test1
ãæå® Site URL
ããã«http://localhost
ãæå® æ®ãï¼ã¤ã¯è£½åããªãªã¼ã¹ããã®ãªã触ã£ãæ¹ãè¯ããã¨ãå¾ãä»ã¯æ¾ç½®
2-5.SDKã®æå®
ä½ãèãã
Websiet Push
ãé¸æ2-6.Testå®è¡
ãã®ç»é¢ã«æ¥ãã¨ï¼ã¤ã®ãã¨ãããå¿ è¦ããã
1. æ¿èªç¨HTMLã®ä½æ
2. ãã©ã¦ã¶ããæ¿èª
ã¾ãã¯、
æ¿èªç¨HTMLã®ä½æ
ãã # sudo vi /Library/WebServer/Documents/index.html.en
以ä¸ã®ã½ã¼ã¹ãè¨è¼
<html>
<script src="https://cdn.onesignal.com/sdks/OneSignalSDK.js" async='async'></script>
<script>
var OneSignal = window.OneSignal || [];
OneSignal.push(["init", {
appId: "{Your App IDãç½®ãæã}",
httpPermissionRequest: {enable: true},
allowLocalhostAsSecureOrigin: true,
autoRegister: true,
notifyButton: {enable: false}
}]);
</script>
<body>
<h1>It works!</h1>
</body>
</html>
èªåã§、Your App IDãç½®ãæã
é¨åãæ¸ãæãã¦ãã ãã。ãã©ã¦ã¶ããæ¿èª
ã®å®è¡ http://localhost/
ã«ã¢ã¯ã»ã¹ãã¦ã¢ã¯ã»ã¹ã許å¯ããã¦ãµã¤ãã«æ»ã確èªä½æ¥
ã¨ããã¾ã§ãSafariã®è¨å®æ¬¡ã«ãã®ä»ãã©ã¦ã¶å¯¾å¿
å人çã«ã§ããå®ã¯Safariã®æ¹ãç°¡åã§ãã。
3.ãã®ä»ãã©ã¦ã¶å¯¾å¿
次ã¯ãã®ä»ãã©ã¦ã¶ä»åã®ãã¹ãã¯Chromeã§å®æ½ãã®æ¹æ³ã§FireFoxã対å¿å¯è½ã§ã。
3-1.è¨å®æ å ±ã®ç»é²
App Setting
=> Google Chrome and Mozilla Firefox
=> CONFIGURE
ã®é çªã§ç§»åå ¥åæ å ±ããã®å ´åã¯、
https://localhost
ã«ãã¦My site is not fully HTTPS
è¨å®ããã§ãã¯ãã¤ããªãããã«ãã¦ç»é²ãã¾ã。 è²ã 試ããã®ã§ããããããªãã¨æ£ããç»é²ã§ããªã。
3-2.追å ãã¡ã¤ã«ã®è¨ç½®
ããã§èªè¨¼ã®åã«ä¸ã¤å¯¾å¿ãå ¥ãã¾ã。index.html
ã®å¤æ´ã¯ä¸è¦ãªã®ã§ãã追å ã§JSãã¡ã¤ã«ãï¼ã¤å¿
è¦ã§ã。# cd /Library/WebServer/Documents/
# sudo wget https://cdn.onesignal.com/sdks/OneSignalSDKWorker.js
ã©ãããChromeãFireFoxã ã¨ãã¼ã«ã«å ã®OneSignalSDKWorker.jsãå¿ è¦ã¿ããã§ãããåã£ã¦æ¥ãå¿ è¦ãããã¾ã。
ãã®å 容ã®æ³¨æãããã¨ãããããã¾ã。
ä¾ãã°ãµã¤ãã®ã¢ã¯ã»ã¹ã
http://localhost/~{ã¦ã¼ã¶å}/index.html
ãã®å ´åã§ãOneSignalSDKWorker.js
ã®ã¢ã¯ã»ã¹å
ã¯http://localhost/OneSignalSDKWorker.js
ã«ããå¿
è¦ãããã¨ããã§ã。å°ãã¿ã¦ã¿ãã¨Crhomeç¨ã®ãããã°ã³ã³ã½ã¼ã«ã«åºã¦æ¥ãã®ã§å¤±æããå ´åã¯、ã¨ã©ã¼ãã°ããã§ãã¯ãã¦ã¿ãã¨è¯ãã§ã。
2017å¹´6æ24æ¥åææ¥
CakePHP ã¯ã¨ãªã¼ãã«ãã¼æ´»ç¨
CakePHP 3ç³»ãå©ç¨ããQueryBuilderã®æ´»ç¨æ³
è¤éãªSQL(Group BYã主ä½)ãè¨è¼ããæ¹æ³ãè¨è¼
åºæ¬çã«、ç¹å¥ãªã±ã¼ã¹ã§ãªãå ´ååæåã®å¦çã¯
çãControllerä¸ã§åä½ãããåæã§è¨è¼ãã¾ã
Software | Version |
---|---|
Postgres | 9.6.1 |
CakePHP | 3.3.16 |
ã¾ãã¯ãã¼ãã«ã¨ãã¼ã¿ãä½æ.
SQL
CREATE TABLE users (
user_id SERIAL,
user_name VARCHAR(256),
role VARCHAR(32) DEFAULT 'author',
created_date TIMESTAMP DEFAULT NOW(),
update_date TIMESTAMP DEFAULT NOW(),
PRIMARY KEY(user_id)
);
CREATE TABLE products (
product_id SERIAL,
product_name VARCHAR(256),
price INTEGER,
PRIMARY KEY(product_id)
);
CREATE TABLE product_orders (
product_order_id SERIAL,
product_id INTEGER,
date TIMESAMP,
user_id INTEGER,
PRIMARY KEY(product_order_id)
);
ãã¼ã¿ç¨SQL
INSERT INTO users(user_name) VALUES
('User A'),
('User B');
INSERT INTO products(product_name, price) VALUES
('product A', 1000),
('product B', 100),
('product C', 200);
INSERT INTO product_orders(product_id, date, user_id) VALUES
(1, '2017/06/24 15:00:00', 1),
(1, '2017/06/24 16:00:00', 2),
(2, '2017/06/24 17:00:00', 3),
(1, '2017/06/25 15:00:00', 2),
(2, '2017/06/25 16:00:00', 3),
(2, '2017/06/26 15:00:00', 1);
åºæ¬çãªå ±éå¦ç
use Cake\ORM\TableRegistry;
public function initialize(array $config) {
$this->Users = TableRegistry::get('Users');
$this->Products = TableRegistry::get('Products');
$this->ProductOrders = TableRegistry::get('ProductOrders');
}
1. ç°¡åãªGroup BY
ååIDã¨åè¨ä»¶æ°ãæ½åº
SQL
SELECT product_id, COUNT(product_order_id) AS total FROM product_orders GROUP BY product_id;
PHP
$productOrders = $this->ProductOrders->find();
$datas = $productOrders->select([
'product_id',
'total' => $productOrders->func()->count('product_order_id')
])->toArray();
- å°ãè¤éãªGroup By
SELECT
product_id, product_name, T1.total
FROM
products
INNER JOIN (
SELECT
product_id, COUNT(product_order_id) AS total
FROM
product_orders
WHERE
date >= '2016/06/25'
GROUP BY product_order_id
) AS T1 USING(product_id)
PHP
$products = $this->Products->find();
$productOrders = $this->ProductOrders->find();
$datas = $productOrders->select([
'product_id',
'total' => $productOrders->func()->count('product_order_id')->where(['date' => new Time('2017-06-25')])
]);
$productsRecored = $products->join([
'T1' => [
'table' => $datas,
'type' => 'INNER',
'conditions' => 'T1.product_id = Products.product_id',
]
])->select([
"product_id",
"product_name",
"total" => "T1.total"
])->toArray();
èªåãå°ã£ãSQLãè¨è¼
2016å¹´7æ24æ¥æ¥ææ¥
Cakephp3ãå©ç¨ãShellã§Componentãå©ç¨ãã.
cakephp3ãå©ç¨ãã¦Shellã§Componentãå¼ã³åºãã®ã
å°ãé¢åã ã£ãã®ã§ã¾ã¨ã
ã©ããããªã¼ããã¼ãã§ããªãã¿ãããªã®ã§èªåã§ã³ã³ãã¼ãã³ããåæåããå¿ è¦ãããã¿ããã§ã。
Abstractåããããã¦ãªãã¬ã¯ã·ã§ã³çãªæãã§ç°¡æåã§ããããªæ°ãããã®ã§ã§ããã追è¨äºå®。
å°ãé¢åã ã£ãã®ã§ã¾ã¨ã
src/Controller/Component/TestsComponent.php
<?php namespace App\Controller\Component; use Cake\Controller\Component; class TestsComponent extends Component { public function test() { echo "OK\n"; } }
src/Shell/SampleShell.php
<?php namespace App\Shell; use Cake\Console\ConsoleOptionParser; use Cake\Console\Shell; use Cake\Log\Log; use Psy\Shell as PsyShell; use Cake\Controller\Component; use Cake\Controller\ComponentRegistry; use App\Controller\Component\TestsComponent; class SampleShell extends Shell { public function initialize() { $this->Tests = new TestsComponent(new ComponentRegistry()); } public function main() { $this->Tests->test(); } }
ã©ããããªã¼ããã¼ãã§ããªãã¿ãããªã®ã§èªåã§ã³ã³ãã¼ãã³ããåæåããå¿ è¦ãããã¿ããã§ã。
Abstractåããããã¦ãªãã¬ã¯ã·ã§ã³çãªæãã§ç°¡æåã§ããããªæ°ãããã®ã§ã§ããã追è¨äºå®。
2016å¹´7æ2æ¥åææ¥
CentOS 7ã«TensorFlowãã¤ã³ã¹ãã¼ã«ãã
èªåã¡ã¢
以ä¸ã®Windowsã«Virutal Boxãã¤ã³ã¹ãã¼ã«ãå®æ½
æ®éã«ã¤ã³ã¹ãã¼ã«ãã¦ãããã¯ã¼ã¯ãèµ·åããªãå ´åã¯ä»¥ä¸ãå®æ½ãã¦å¯¾å¦
ãããã¼ã¯ã¼ã¯ã®èµ·å
ã¤ã³ã¹ãã¼ã«æã«onbootãonã«ãã¦ããªãå ´åã¯ãã®è¨å®ãå¿ è¦ã§ã。
$ nmcli c
=====
NAME UUID TYPE DEVICE
enp0s3 xxxxxxx-xxxxx-xxxx-xxxxx-xxxxxxxxxxx 802-3-ethernet enp0s3
=========
enp0s3ãããã¤ã¹ã®ID
onbootãæå¹ã«ãã。
$ nmcli c m enp0s3 connection.autoconnect yes
ãããã¯ã¼ã¯ã®åèµ·å
$ systemctl restart NetworkManager
$ systemctl restart network
IPã¢ãã¬ã¹ã®ç¢ºèª
$ ip addr
pipã®ã¤ã³ã¹ãã¼ã«
$ yum install -y epel-release
$ yum install -y python-pip
$ pip install pip --upgrade
ãã®ä»ã©ã¤ãã©ãªã®ã¤ã³ã¹ãã¼ã«
$ yum install -y python-devel python-virtualenv
TensorFlowã®ã¤ã³ã¹ãã¼ã«
$ pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.9.0-cp27-none-linux_x86_64.whl
TensorFlowã®ç°å¢è¨å®ãã¡ã¤ã«ãè¨ç½®
$ virtualenv --system-site-packages ~/tensorflow
TensorFlowã®è¨å®ãå¼ã³åºã
$ source ~/tensorflow/bin/activate
$ vi test.py
========以ä¸ãè²¼ãä»ã============
import tensorflow as tf
import numpy as np
==================================
$ python test.py
ã¨ã©ã¼ãåºãªããã°æå
ã¾ã¨ã
CentOS6ç³»ã¨ãã¨æ¯ã¹ã¦ã»ã¨ãã©å¤ãããªãã§ã。
以ä¸ã®Windowsã«Virutal Boxãã¤ã³ã¹ãã¼ã«ãå®æ½
- Virtual Box 5.0.22 r108108
- å®æ½æ¥:2016/06/28
- OS CentOS-7-x86_64-Minimal-1511
æ®éã«ã¤ã³ã¹ãã¼ã«ãã¦ãããã¯ã¼ã¯ãèµ·åããªãå ´åã¯ä»¥ä¸ãå®æ½ãã¦å¯¾å¦
ãããã¼ã¯ã¼ã¯ã®èµ·å
ã¤ã³ã¹ãã¼ã«æã«onbootãonã«ãã¦ããªãå ´åã¯ãã®è¨å®ãå¿ è¦ã§ã。
$ nmcli c
=====
NAME UUID TYPE DEVICE
enp0s3 xxxxxxx-xxxxx-xxxx-xxxxx-xxxxxxxxxxx 802-3-ethernet enp0s3
=========
enp0s3ãããã¤ã¹ã®ID
onbootãæå¹ã«ãã。
$ nmcli c m enp0s3 connection.autoconnect yes
ãããã¯ã¼ã¯ã®åèµ·å
$ systemctl restart NetworkManager
$ systemctl restart network
IPã¢ãã¬ã¹ã®ç¢ºèª
$ ip addr
pipã®ã¤ã³ã¹ãã¼ã«
$ yum install -y epel-release
$ yum install -y python-pip
$ pip install pip --upgrade
ãã®ä»ã©ã¤ãã©ãªã®ã¤ã³ã¹ãã¼ã«
$ yum install -y python-devel python-virtualenv
TensorFlowã®ã¤ã³ã¹ãã¼ã«
$ pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.9.0-cp27-none-linux_x86_64.whl
TensorFlowã®ç°å¢è¨å®ãã¡ã¤ã«ãè¨ç½®
$ virtualenv --system-site-packages ~/tensorflow
TensorFlowã®è¨å®ãå¼ã³åºã
$ source ~/tensorflow/bin/activate
$ vi test.py
========以ä¸ãè²¼ãä»ã============
import tensorflow as tf
import numpy as np
==================================
$ python test.py
ã¨ã©ã¼ãåºãªããã°æå
ã¾ã¨ã
CentOS6ç³»ã¨ãã¨æ¯ã¹ã¦ã»ã¨ãã©å¤ãããªãã§ã。
2015å¹´12æ14æ¥æææ¥
Tensorflowã§å¦ã¶ææ¥éä¸æ³
Tensorflowã§å¦ã¶ææ¥éä¸æ³
ãããããã§ãã、Tensorflowã®åæãµã³ãã«ã«æ²è¼ããã¦ãã
ææ¥éä¸æ³(train.GradientDescentOptimizer)ã®è§£èª¬ã§ã。
ææ¥éä¸æ³ã¨ã¯、ããå¼ãä½ããã®å¼ã«åºã¥ã
å¾®åãè¡ããã£ã¨ãå¾ãããæå°ã®å¤ãç®åºããææ³ã§ã。
TensorFlowã®get startedã«ããIntroductionã
ãã®ææ¥éä¸æ³ã®ãµã³ãã«ã¨ãªãã¾ã。
大ã¾ããªããã¼ã¨ãã¦ã¯
Step1.åæãã¼ã¿ä½æ
Step2.äºæ¸¬ã¢ãã«ããæ¹ç¨å¼ãä½æ
Step3.ãã¹é¢æ°ã¨ç®æ¨è¨å®ãä½æ
Step4.æé©åã®å®è¡
ããããã£ããã§ãããã®ï¼ã¹ãããã§ææ¥éä¸æ³ãå®ç¾ãã¦ãã¾ã。
ãã®æµãã«ãªãã¾ã。
ä½ã®èç¥ããªãã®ã§ããèªå·±ç解ã®ããã®ç°¡æ解説ã¨ãªãã¾ã。
ãããããã§ãã、Tensorflowã®åæãµã³ãã«ã«æ²è¼ããã¦ãã
ææ¥éä¸æ³(train.GradientDescentOptimizer)ã®è§£èª¬ã§ã。
ææ¥éä¸æ³ã¨ã¯、ããå¼ãä½ããã®å¼ã«åºã¥ã
å¾®åãè¡ããã£ã¨ãå¾ãããæå°ã®å¤ãç®åºããææ³ã§ã。
TensorFlowã®get startedã«ããIntroductionã
ãã®ææ¥éä¸æ³ã®ãµã³ãã«ã¨ãªãã¾ã。
大ã¾ããªããã¼ã¨ãã¦ã¯
Step1.åæãã¼ã¿ä½æ
Step2.äºæ¸¬ã¢ãã«ããæ¹ç¨å¼ãä½æ
Step3.ãã¹é¢æ°ã¨ç®æ¨è¨å®ãä½æ
Step4.æé©åã®å®è¡
ããããã£ããã§ãããã®ï¼ã¹ãããã§ææ¥éä¸æ³ãå®ç¾ãã¦ãã¾ã。
# ãã¾ããªã
import tensorflow as tf
import numpy as np
### Step1.åæãã¼ã¿ä½æ ###
# ã©ã³ãã ãªxã®å¤ãä½æ
x_data = np.random.rand(100).astype("float32")
# y = 0.1x + 0.3ã®å¼ã«åºã¥ããå¤ãç®åº
y_data = x_data * 0.1 + 0.3
### Step2.äºæ¸¬ã¢ãã«ããæ¹ç¨å¼ãä½æ ###
# W ä¸ã§ãã aã«å¤ããä¿æ°ãåæå¤ã¨ãã¦-1.0~1.0ã®ç¯å²ã§ã©ã³ãã çæ
W = tf.Variable(tf.random_uniform([1], -1.0, 1.0))
# bã®å¤ãåæå¤0ã§ä½æ
b = tf.Variable(tf.zeros([1]))
# y = W * x + bãåç¾
y = W * x_data + b
### Step3.ãã¹é¢æ°ã¨ç®æ¨è¨å®ãä½æ ###
# äºæ³ããçµæy - å®éã®yã®ãã¼ã¿äºä¹ããçµæã®å¹³åãlossã¨ä½ç½®ä»ãã
loss = tf.reduce_mean(tf.square(y - y_data))
# Learning Rateã®æå®
optimizer = tf.train.GradientDescentOptimizer(0.5)
# lossãæå°åããå¤ãç®çã«ç½®ã
train = optimizer.minimize(loss)
### Step4.æé©åã®å®è¡ ###
# TensorFlowã®å®è¡æºå
init = tf.initialize_all_variables()
# graphã®æºå
sess = tf.Session()
sess.run(init)
# 201åã®æé©åãå®è¡
for step in xrange(201):
sess.run(train)
# 20åæ¯ã«éä¸ã®å¤ãåºå
if step % 20 == 0:
print step, sess.run(W), sess.run(b)
ãã®æµãã«ãªãã¾ã。
ä½ã®èç¥ããªãã®ã§ããèªå·±ç解ã®ããã®ç°¡æ解説ã¨ãªãã¾ã。
ç»é²:
æ稿 (Atom)