Types in SQLite

storage class, data types
NULL, INTEGER, REAL, TEXT, BLOB

No booleans, use INTEGER instead
Ex:
false = 0
true = 1

attribute
Name TEXT
Price INTEGER
Style INTEGER
In Stock INTEGER
Description TEXT

CREATE TABLE headphones (_id INTEGER, name TEXT,
	price INTEGER,
	style INTEGER,
	in_stock INTEGER,
	description TEXT);

CREATE TABLE pets (_id INTEGER, 
	name TEXT,
	bread TEXT,
	gender INTEGER,
	weight INTEGER);

Computer Memory

Temporary Storage:Short term
-can be used for calculations or displaying data on screen
-quick to access
-short-lived
e.g.
-computer RAM

Permanent Storage:Long term
-can be used for storing user data
-slower to save and access data
-stick around forever(until deleted)
e.g.
-Hard disk, Flash drives

Different Data Storage Options
Files: good for saving large media files
SharedPreferences: Good for in-app user preferences, key and value, Unique String and primitive types and strings
SQLight Databases: Good for organizing a lot of related and structured data for easy access: Row, Column
commonly used for text data, easily grows in size and easily searchable

PS C:\Users\xxx> sqlite3 -version
3.15.0 2016-10-14 10:20:30 707875582fcba352b4906a595ad89198d84711d8

PS C:\Users\xxx> sqlite3
SQLite version 3.15.0 2016-10-14 10:20:30
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> .open pets.db
sqlite>

プッシュ通知

スマホのプッシュ通知
iOS:Apple Push Notification Service(APNs)
Android:Google Cloud Messaging(GCM)

①Apple / google よりデバイストークンを取得
②アプリ用サーバにデバイストークンを登録
(ユーザーIDや端末IDと紐づけて送信)
③デバイストークンとメッセージを送信

$ curl \
--header "Authorization:key=【APIキー】"\
--header "Content-Type:\"application/json\""\
https://android.googleapis.com/gcm/send\
-d"{\"registration_ids\":[\"【RegistrationID】\"],\"data\":
{\"message\":/"Hello monotty!\"}}"

iOSのプッシュ通知
Command, Frame data(Item, Item)
device_id, os, device_token

AndroidはテキストベースのシンプルなHTTP通信で送信できる
iOSは、ApnsPHPを使う

function connectAPSN($sslclient,$pem_path,$passphrase){
	$ctx = stream_content_create();
	stream_context_set_option($ctx, 'ssl', 'local_cert', $pem_path);
	stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
	$fp = stream_socket_client($sslclient, $err,
		$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
	if (!$fp){
		echo "接続エラーになったので1秒後再接続を試みます。メメタア!". PHP_EOL;
	sleep(1);
	$fp = connectAPSN($sslclient,$pem_path,$passphrase);
	return $fp;
	} else {
		echo "APNS接続OK" . PHP_EOL;
		return $fp;
	}

	// 送信処理
	$passphrase = 'password';
	$pem_path = '/xxx/xxx.pem';
	$sslclient = 'ssl://gateway.sandbox.push.apple.com:2195';
	$fp = connectAPSN($sslclient,$pem_path,$passphrase);

Calculating a confidence interval

P^ = x/N
P^ = 100/1000 = 0.1

m = z*se
m = z * √p^(1-p^)/n
m = 0.019
z distribution μ=0, σ=1 -1.96, 1.96

N = 2000, x = 300
p^ = 300 / 2000
center of confident 0.15

Hypothesis Testing
P(results due to chance)
Pcont, Pexp
Pcont = Pexp
Pexp-Pcont = 0

Size vs. Power Trade-Off
How many page views
α = P(reject null | null true)

A/B testing

AB test is using data like user behavior to make a decision.
Which part of the future is better.
AB testing rather than useful for new experiment.

Overview
Example
Choose a metric
Review statistics
Design
Analyze

Examples of when to use A/B testing
・Movie recommendation site: new ranking algorithm
・Change backend-page load time, results users see etc.
・Test layout of initial page

probability
Repeated measurement of click-through-probability
visitors = 1000
unique clicks = 10
click-through-probability ≒10%

Binominal Distribution
@ p = 3/4
mean = P
std dev = √p(1-p)/N
P^ = 16/20 = 4/5

types of outcomes
independent events
identical distribution

Antilock Braking System

Two types of friction
static: moves when F > μs・N
kinetic: F = μk * N

wheel slip
rolling, rocked

speed = 120 km/h
μ=1.0: 3.4s
μ=0.7: 4.9s

F = m*a
u*gravitational force(mg)
a = μ*g

t/ 120km/h = 1 / μg
t = 120km/h / μ*g

Computing the coefficient of Friction
s = 1 – w/v
F(s) = μ(s)*mqcG
V= -F(s)/mqc
F = ma
w = F(s)/mew – B

import math
from **** import *

h = 0.01
mass_quarter_car = 250.
mass_effective_wheel = 20.
g = 9.81

end_time = 5.
num_steps = int(end_time / h)

w = numpy.zeros(num_steps + 1)
v = numpy.zeros(num_steps + 1)
x = numpy.zeros(num_steps + 1)
times = h * numpy.array(range(num_steps + 1))

@show_plot(7, 7)
def plot_me():
	axes_x = matplotlib.pyplot.subplot(411)
	axes_v = matplotlib.pyplot.subplot(412)
	axes_w = matplotlib.pyplot.subplot(413)
	awes_s = matplotlib.pyplot.subplot(414)

	def friction_coeff(slip):
		return 1.1 * (1. - math.exp(-20. * slip)) - 0.4 * slip

	def wheel_slip():
		b_values = numpy.arange(70., 190.1, 30.)
		for b in b_values:
			x[0] = 0.

			for step in range(num_steps):
				if v[step] < 0.01:
					break
				s = max(0., 1. - w[step] / v[step])

				w[step + 1] = max(0., w[step + 1])

			axes_x.plot(times[:step], x[:step])
			axes_v.plot(times[:step], v[:step])
			axes_w.plot(times[:step], w[:step])
			axes_s.plot(times[:step], 1. - w[:step] / v[:step])
			p = int((0.35 + 0.4 * (b - b_values[0])/ (b_values[-1] - b_values[0])) * num_steps)
			axes_x.annotate(b, (times[p], x[p]),
					xytext = (-30, -30), textcoords = 'offset point',
					arrowprops = dict(arrowstyle = '-', connectionstyle = 'arc3, '))

			p = int((0.35 + 0.4 * (v - b_values[0]) / (b_values[-1] - b_values[0])) * num_steps)
			axes_x.annotate(b, (times[p], x[p]),
				xytext = (-30, -30), textcoords - 'offset points',
				arrowprops = dict(arrowstyle = '-', connectionstyle = 'arc3, rad = 0.2', shrinkB = 0.))

		return x, v, w

    axes_x.set_ylabel('Position\nin m', multialignment = 'center')
    axes_v.set_ylabel('Car velocity\nin m/s', multialignment = 'center')
    axes_w.set_ylabel('Wheel velocity\nin m/s', multialignment = 'center')
    axes_s.set_ylabel('Wheel\nslip', multialignment = 'center')
    axes_s.set_xlabel('Time in s')
    axes_s.set_ylim(0., 1.)

    return wheel_slip()

x, v, w = plot_me()

Tangent

y=2^x, y=3^x
the slope of the tangent line at x < 1, x > 1

the exponential function

y = e^x -> slope of the tange line is exactly 1.

e = lim n->∞(1 + 1/N)^N = 2.7
e^π = (1+ 3.1416/10,000)^10,000

(1 + x/4)^4 = 1 + x + 3/8x^2 + 1/16x^3 + 1/256x^4

e^x = 1 + x + x^2/2 + x^3/6 + x^4/24 + …
e^x+h = e^x * e^h

dy(x)/dx = -3y(x)
y(0) = 5

Infinity Time

x(t) = (x(t)^2 + 1)/2
with * (0) = 3

from *** import *

end_time = 42.
h = 0.0001
num_steps = int(end_time / h)
times = h * numpy.array(range(num_steps) + 1)

x = numpy.zeros(num_steps + 1)
x[0] = 3.

def forward_euler():
	for step in range(num_steps):

	return x

x = forward_euler()

@show_plot
def plot_me():
	matplotlib.pyplot.plot(times, x)
	matplotlib.pyplot.show()

plot_me()

Sources of Errors
-model, parameters, initial data, numerics