In [153]:
import numpy as np
In [154]:
X = np.random.random((3, 4, 4))
In [155]:
X_reshape = X.reshape((X.shape[0], -1))
In [156]:
X_sort = np.sort(X_reshape, axis=1)
In [168]:
import math
v_frac = [0.3, 0.2,0.3,0.2]
X_segs = np.zeros((X_reshape.shape))
if sum(v_frac)!=1.0:
raise RuntimeError("Volume fractions do not add up to 1")
v_frac1 = 0.3
for i in range(1,len(v_frac)):
v = sum(v_frac[0:i])
print v
length = X_sort.shape[1]
ind = int(math.floor(v*length))
seg = X_sort[:, ind-1]
print seg
X_seg = X_reshape >= seg[:, None]
X_segs = X_segs+X_seg
#X_seg = X_seg1.astype(int)+X_seg2.astype(int)
In [162]:
X_segs
Out[162]:
In [152]:
X_seg
Out[152]:
In [116]:
import math
v_frac = 0.5
length = X_sort.shape[1]
ind = int(math.floor(v_frac*length))
ind
Out[116]:
In [117]:
seg = X_sort[:, ind-1]
In [121]:
#X_seg = np.zeros(shape = X_reshape.shape)
#for i in range(X.shape[0]):
# X_seg[i,:] = X_reshape[i,:] >= seg[i]
#print X_seg
X_seg = X_reshape >= seg[:, None]
In [122]:
X_seg.astype(int)
Out[122]:
In [123]:
np.sum(X_seg, axis=1)/float(X_reshape.shape[1])
Out[123]:
In [76]:
%matplotlib inline
%load_ext autoreload
%autoreload 2
import numpy as np
import matplotlib.pyplot as plt
from pymks.datasets import make_microstructure
n_samples, n_phases = 3, 3
size, grain_size = (100, 100), (10, 1)
v_frac = [0.2,0.8]
sigma1 = 100
sigma2 = 20
X = make_microstructure(n_samples=n_samples, size=size,n_phases=n_phases, grain_size=grain_size,seed=1, v_frac = v_frac,
sigma=sigma1)
Y = make_microstructure(n_samples=n_samples, size=size,n_phases=n_phases, grain_size=grain_size,seed=1, v_frac = v_frac,
sigma=sigma2)
X_reshape = X.reshape(n_samples, -1)
In [72]:
X_reshape
Out[72]:
In [215]:
np.sum(X_reshape, axis=1)/float(X.shape[1]*X.shape[2])
Out[215]:
In [216]:
np.count_nonzero(X_reshape)/3
Out[216]:
In [77]:
from pymks.tools import draw_microstructures
draw_microstructures(X)
In [78]:
draw_microstructures(Y)
In [12]:
ind = np.array(range(1, 6))
ind
Out[12]:
In [75]:
np.allclose(X, Y)
Out[75]:
In [ ]:
In [36]:
import numpy as np
np.rint(2 * np.random.randn(len(ind)))
Out[36]:
In [68]:
np.rint(10*np.random.randn())
Out[68]:
In [ ]:
In [ ]: