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

In [31]:
%matplotlib inline

In [32]:
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-16

In [33]:
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 [34]:
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 [35]:
save_images = False

In [36]:
manifold_name = 'building_game'
poly_name = 'octahedron'
int_num = 3

stat_name = 'test_2'

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

In [38]:
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 [39]:
err_tol = 10**-12
h = 0.05
N = 10**7
run_kwargs = {'N': N}

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

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

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

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

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

In [41]:
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 [42]:
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 [43]:
s_n = z_n.sample(N=N, record_trace=False, record_stats=True)
print 'done'


done

In [44]:
hist_n = plt.hist2d(z_n.stat_log[:,0], z_n.stat_log[:,1], bins=100, normed=True)
plt.colorbar()
if save_images == True:
    plt.savefig('test_4_n_h2_'+date_time_str+'.png')



In [45]:
hh1nx = plt.hist(z_n.hist.midpoints, weights=z_n.hist.hist[0,:], normed=True, bins=40)
xyn = plt.plot(x_range, ys, 'r') 
if save_images == True:
    plt.savefig('test_4_n_h1x_'+date_time_str+'.png')



In [46]:
hh1ny = plt.hist(z_n.hist.midpoints, weights=z_n.hist.hist[1,:], normed=True, bins=40)
xyn = plt.plot(x_range, ys, 'r') 
if save_images == True:
    plt.savefig('test_4_n_h1y_'+date_time_str+'.png')



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


done

In [48]:
hist_1 = plt.hist2d(z_1.stat_log[:,0], z_1.stat_log[:,1], bins=100, normed=True)
plt.colorbar()
if save_images == True:
    plt.savefig('test_4_1_h2_'+date_time_str+'.png')



In [49]:
hh11x = plt.hist(z_1.hist.midpoints, weights=z_1.hist.hist[0,:], normed=True, bins=40)
xy1 = plt.plot(x_range, ys, 'r') 
if save_images == True:
    plt.savefig('test_4_1_h1x_'+date_time_str+'.png')



In [50]:
hh11y = plt.hist(z_1.hist.midpoints, weights=z_1.hist.hist[1,:], normed=True, bins=40)
xy1 = plt.plot(x_range, ys, 'r') 
if save_images == True:
    plt.savefig('test_4_1_h1y_'+date_time_str+'.png')



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


done

In [52]:
hist_m = plt.hist2d(z_m.stat_log[:,0], z_m.stat_log[:,1], bins=100, normed=True)
plt.colorbar()
if save_images == True:
    plt.savefig('test_4_m_h2_'+date_time_str+'.png')



In [53]:
hh1mx = plt.hist(z_m.hist.midpoints, weights=z_m.hist.hist[0,:], normed=True, bins=40)
xym = plt.plot(x_range, ys, 'r') 
if save_images == True:
    plt.savefig('test_4_m_h1x_'+date_time_str+'.png')



In [54]:
hh1my = plt.hist(z_m.hist.midpoints, weights=z_m.hist.hist[1,:], normed=True, bins=40)
xym = plt.plot(x_range, ys, 'r') 
if save_images == True:
    plt.savefig('test_4_m_h1y_'+date_time_str+'.png')



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


done

In [56]:
hist_m = plt.hist2d(z_i.stat_log[:,0], z_i.stat_log[:,1], bins=100, normed=True)
plt.colorbar()
if save_images == True:
    plt.savefig('test_4_i_h2_'+date_time_str+'.png')



In [57]:
hh1ix = plt.hist(z_i.hist.midpoints, weights=z_i.hist.hist[0,:], normed=True, bins=40)
xym = plt.plot(x_range, ys, 'r') 
if save_images == True:
    plt.savefig('test_4_i_h1x_'+date_time_str+'.png')



In [58]:
hh1iy = plt.hist(z_i.hist.midpoints, weights=z_i.hist.hist[1,:], normed=True, bins=40)
xyi = plt.plot(x_range, ys, 'r') 
if save_images == True:
    plt.savefig('test_4_i_h1y_'+date_time_str+'.png')