LoginSignup
0
1

More than 5 years have passed since last update.

statistics > mean size and variance > 緯度経度ごとの値から緯度のmeanとvarianceを求める

Last updated at Posted at 2017-03-15

以下は間違っている可能性があります

問題

  • ある値の分布が緯度、経度ごとに与えられている
  • そこから、以下の4つの値を求める
    • 平均緯度
    • 平均経度
    • 緯度の分散
    • 経度の分散

資料

思い出したのはCharlie Zender氏によるFACTという資料。
サイズ分布関連の式であるが、緯度経度の分布にも応用できるような気がする。

式(14)にMean size, 式(15)にVarianceがある。

Mean > 式(14)

\bar{x} = \int_{0}^{\inf} p(x) x dx 

Variance > 式(15)

\sigma_x^2 = \int_{0}^{\inf}p(x)(x - \bar{x})^2 dx

p(x)相当の計算

緯度経度ごとの値(val(x))より、p(x)が計算できると思う。

ここで、
p(x) : インデックスxごとの確率分布。

p(x) = val(x)/T 

ここで

T = \int{val(x)}

平均緯度

式(14)とp(x)を関連付けて

\bar{lat} = \int{p(x)*lat(x)dx}

numpyで実装した計算では実際の分布図と合致した。

緯度の分散

式(15)と関連付けて

\sigma^2_{lat} = \int{p(x)(lat(x) - \bar{lat})^2 }dx

numpyで実装した計算結果の検証はまだ。

code

calc_latlon_avg_std_170315.py
#!/usr/bin/env python

import numpy as np

'''
codingrule:PEP8
'''


def calc_variance(vals, loc, avg, ttl):
    acc = 0.0
    for elem in zip(vals, loc):
        tmp = (elem[1] - avg) ** 2
        acc += elem[0] * tmp
    return acc / ttl

with open('out_val_170315') as vfp:
    val = vfp.read()
with open('out_lat_170315') as afp:
    lat = afp.read()
with open('out_lon_170315') as ofp:
    lon = ofp.read()

vals = map(float, val.split())
lats = map(float, lat.split())
lons = map(float, lon.split())

# 1. total
total_val = np.sum(vals)
print('total=%.2f' % total_val)

# 2. average for latitude
acc_lat = np.dot(vals, lats)
avg_lat = acc_lat / total_val
print('avg_lat=%.3f' % avg_lat)

# 3. average for longitude
acc_lon = np.dot(vals, lons)
avg_lon = acc_lon / total_val
print('avg_lon=%.3f' % avg_lon)

# 4. stdev for latitude
vrc_lat = calc_variance(vals, lats, avg_lat, total_val)
std_lat = np.sqrt(vrc_lat)
print('std_lat=%.3f' % std_lat)

# 5. stdev for longitude
vrc_lon = calc_variance(vals, lons, avg_lon, total_val)
std_lon = np.sqrt(vrc_lon)
print('std_lon=%.3f' % std_lon)
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1