In [23]:
# TEST FIXING OF THE CENTER OF MASS FOR TWO LINKED TRIANGLES. 
# USE BOTH UNIFORM WEIGHTS AND WEIGHTS PROPORTIONAL TO THE NUMBER OF FACES MEETING AT THE VERTEX

In [24]:
%matplotlib inline

In [25]:
import datetime
dts = str(datetime.datetime.now())
date_time_str = dts[:10] + "-" + dts[11:13] + "-" + dts[14:16]
print date_time_str


2015-02-02-15-18

In [26]:
import numpy as np

import matplotlib.pyplot as plt

import bga_4_0 as bga
import manifold_reflected_brownian_motion as mrbm

bga = reload(bga)
mrbm = reload(mrbm)

In [27]:
def get_masses(x0, faces):
    V = len(x0)/3
    masses = np.zeros(V)
    for face in faces:
        for v in face:
            masses[v] += 1.0
    return masses

In [28]:
save_images = False

In [29]:
manifold_name = 'building_game'
poly_name = 'octahedron'
int_num = 2

In [30]:
stat_name = 'test_1'

In [31]:
err_tol = 10**-12
h = 0.05
N = 10**7

hist_min = 0.0
hist_max = 2.0*np.pi
hist_bins = 1000

In [32]:
x0, links, lengths, faces = bga.load_bg_int(poly_name, int_num)

In [33]:
manifold_kwargs_n = {'poly_name': poly_name, 'int_num': int_num, 'fixed_com': False}
manifold_kwargs_1 = {'poly_name': poly_name, 'int_num': int_num, 'fixed_com': True}
manifold_kwargs_m = {'poly_name': poly_name, 'int_num': int_num, 'fixed_com': True, 'masses': get_masses(x0,faces)}
manifold_kwargs_i = {'poly_name': poly_name, 'int_num': int_num, 'fixed_com': True, 'masses': 1.0/get_masses(x0,faces)}

In [34]:
kwargs_n = {'manifold_name': manifold_name,
            'stat_name': stat_name, 
            'record_hist': True, 
            'hist_min': hist_min, 
            'hist_max': hist_max, 
            'hist_bins': hist_bins,
            'err_tol': err_tol,
            'manifold_kwargs': manifold_kwargs_n}

kwargs_1 = {'manifold_name': manifold_name,
            'stat_name': stat_name, 
            'record_hist': True, 
            'hist_min': hist_min, 
            'hist_max': hist_max, 
            'hist_bins': hist_bins,
            'err_tol': err_tol,
            'manifold_kwargs': manifold_kwargs_1}

kwargs_m = {'manifold_name': manifold_name,
            'stat_name': stat_name, 
            'record_hist': True, 
            'hist_min': hist_min, 
            'hist_max': hist_max, 
            'hist_bins': hist_bins,
            'err_tol': err_tol,
            'manifold_kwargs': manifold_kwargs_m}

kwargs_i = {'manifold_name': manifold_name,
            'stat_name': stat_name,
            'record_hist': True, 
            'hist_min': hist_min, 
            'hist_max': hist_max, 
            'hist_bins': hist_bins,
            'err_tol': err_tol,
            'manifold_kwargs': manifold_kwargs_i}

In [35]:
z_n = mrbm.MRBM(x0, h, **kwargs_n)
z_1 = mrbm.MRBM(x0, h, **kwargs_1)
z_m = mrbm.MRBM(x0, h, **kwargs_m)
z_i = mrbm.MRBM(x0, h, **kwargs_i)

In [36]:
x_range = np.linspace(0.0, 2.0*np.pi)
a = 0.5/np.pi
b = -a*0.1
c = -a*0.1
ys = a + b*np.cos(x_range) + c*np.cos(2*x_range)

In [37]:
s_n = z_n.sample(N=N, record_trace=False, record_stats=False)
print 'done'


done

In [38]:
hist_n_0 = plt.hist(z_n.hist.midpoints, weights=z_n.hist.hist[0,:], bins=100, normed=True)
pp = plt.plot(x_range, ys, 'r')
if save_images == True:
    plt.savefig('test_5_n_'+date_time_str+'.png')



In [39]:
s_1 = z_1.sample(N=N, record_trace=False, record_stats=True)
print 'done'


done

In [40]:
hist_1_0 = plt.hist(z_1.hist.midpoints, weights=z_1.hist.hist[0,:], bins=100, normed=True)
pp = plt.plot(x_range, ys, 'r')
if save_images == True:
    plt.savefig('test_5_1_'+date_time_str+'.png')



In [41]:
s_m = z_m.sample(N=N, record_trace=False, record_stats=True)
print 'done'


done

In [42]:
hist_m_0 = plt.hist(z_m.hist.midpoints, weights=z_m.hist.hist[0,:], bins=100, normed=True)
pp = plt.plot(x_range, ys, 'r')
if save_images == True:
    plt.savefig('test_5_m_'+date_time_str+'.png')



In [43]:
s_i = z_i.sample(N=N, record_trace=False, record_stats=True)
print 'done'


done

In [44]:
hist_i_0 = plt.hist(z_i.hist.midpoints, weights=z_i.hist.hist[0,:], bins=100, normed=True)
pp = plt.plot(x_range, ys, 'r')
if save_images == True:
    plt.savefig('test_5_i_'+date_time_str+'.png')