Test the Algorithm


In [ ]:
M = {'mean': {'Nbranch': 10,
  'Nendpoint': 10,
  'Nnodes': 300,
  'branch_angle': 2.4,
  #'diameter': 1,
  #'distance_from_root2': 0, #30,
'distance_from_root': 50,
  'global_angle': .3,
  'length_to_parent': 1,
  'local_angle':  3,
  'initial_segments': 4,
  #'slope': .1,
'discrepancy_space': 60,
  'ratio_euclidian_neuronal': 1},
 'variance': {'Nbranch': 1,
  'Nendpoint': 10,
  'Nnodes': 5,
  'branch_angleangle_branch': .2,
  #'diameter': 1,
  #'distance_from_root2': .5,
    'distance_from_root': 10,
  'global_angle': .100,
  'length_to_parent': 1,
  'local_angle': .1, 
  'initial_segments': 1,
  #'slope': .1,
'discrepancy_space': 5,
  'ratio_euclidian_neuronal': .01}}

In [ ]:
import numpy as np
M = {'mean': {'Nbranch': 10,
 'branch_angle': .3,
# 'Nendpoint': 10,
 # 'Nnodes': 2000,
  #'diameter': 1,
#  'distance_from_root2': 0,
'distance_from_root': 20,
 'global_angle': .1,
  'distance_from_parent': 1.2,
  'local_angle':  3,
  'initial_segments': 4,
 # 'slope': .1,
'discrepancy_space': 60,
              'curvature' : .5,
 'ratio_euclidian_neuronal': 1
              
             },
'variance': {
'Nbranch': 1,
  'branch_angle': .1,
 # 'Nnodes': 30,
  #'diameter': 1,
 # 'distance_from_root2': .2,
   'distance_from_root': 3,
  'global_angle': .1,
  'distance_from_parent': .1,
 'local_angle': .1, 
  'initial_segments': 1,
        'curvature' : .1,
  #'slope': .1,
'discrepancy_space': 5,
  'ratio_euclidian_neuronal': .01
             },
    'hist_range': {'Nbranch': np.array([1]),
 'branch_angle': np.arange(0,np.pi,np.pi/10),
# 'Nendpoint': 10,
 # 'Nnodes': 2000,
  #'diameter': 1,
#  'distance_from_root2': 0,
'distance_from_root': np.append(np.arange(1,200,3),500),
 'global_angle': np.arange(0,np.pi,np.pi/20),
  'distance_from_parent': np.append(np.arange(.5,1.5,.1),10),
  'local_angle': np.arange(0,np.pi,np.pi/20),
  'initial_segments': np.array([1]),
 # 'slope': .1,
'discrepancy_space': np.array([1]),
              'curvature' : np.arange(0,np.pi,np.pi/20),
 'ratio_euclidian_neuronal': np.append(np.arange(1,1.5,.03),6)
              
             },
    'hist_variance': {'Nbranch': 2,
 'branch_angle': 1,
# 'Nendpoint': 10,
 # 'Nnodes': 2000,
  #'diameter': 1,
#  'distance_from_root2': 0,
'distance_from_root': 1,
 'global_angle': 1,
  'distance_from_parent': 1,
  'local_angle': 1,
  'initial_segments': 1,
 # 'slope': .1,
'discrepancy_space': .4,
              'curvature' : 1,
 'ratio_euclidian_neuronal': 5
              
             }
    }

In [ ]:
import os
import sys
sys.path.append("/Users/RoozbehFarhoudi/Documents/Repos/Generative-Models-of-Neuron-Morphology/")
import numpy as np
import btmorph3
import matplotlib.pyplot as plt
from copy import deepcopy
%matplotlib inline
#np.random.seed(0)
loc2 = "/Users/RoozbehFarhoudi/Documents/Repos/Generative-Models-of-Neuron-Morphology/Data/Interneuron/allen cell types/CNG version/Pvalb-IRES-Cre-Ai14-475124495.CNG.swc"
inter = btmorph3.Neuron(file_format = 'swc', input_file=loc2)
per = btmorph3.Perturbation(iterations = 10,verbose=0); per.set_n_node(300)
#per.set_measure(M)
per.set_real_neuron(inter,M)
per.set_probability(np.array([.5,.5,0,0,0,0,0,0,0,0,0,0,0]))
per.fit()
gen = per.neuron
btmorph3.visualize.plot_2D(gen,show_radius=False);
gen_old = deepcopy(per.neuron)
per1 = btmorph3.Perturbation(neuron=gen_old, iterations = 1,verbose=1)
#per1.set_measure(M)
per1.set_real_neuron(inter,M)
per1.set_probability(np.array([0,0,0,0,0,0,0,0,0,0,1,0,0]))
per1.fit()
btmorph3.visualize.plot_2D(per1.neuron,show_radius=False);

In [ ]:
new = btmorph3.Neuron(file_format = 'only list of nodes',input_file = deepcopy(per.neuron.nodes_list))
gen = per.neuron

In [ ]:
Inter1 = btmorph3.Neuron(file_format = 'swc', input_file=loc2)
#Inter2 = btmorph3.Neuron(file_format = 'only list of nodes', input_file=deepcopy(Inter1.nodes_list))

In [ ]:
btmorph3.visualize.plot_2D(Inter1,show_radius=False);

In [ ]:
inter = deepcopy(Inter1)
inter.change_location_toward_end_nodes(10,[30,30,10])
inter.set_nodes_values()
btmorph3.visualize.plot_2D(inter,show_radius=False);

In [ ]:
new = Inter1
gen = inter

In [ ]:
print('parent index')
print new.parent_index - gen.parent_index
print('child_index')
print new.child_index - gen.child_index
print('branch_order')
print new.branch_order - gen.branch_order
print('angle_branch')
print new.branch_angle - gen.branch_angle
print('distance_from_root')
print new.distance_from_root - gen.distance_from_root
print('length_to_parent')
print new.distance_from_parent - gen.distance_from_parent
print('local_angle')
print new.local_angle - gen.local_angle
print('angle_global')
print new.global_angle - gen.global_angle
print new.location - gen.location

In [ ]:
new.root.xyz

In [ ]:
M = gen.connection
m = new.connection
M1, M2 = np.where(~np.isnan(M))
m1, m2 = np.where(~np.isnan(m))
plt.plot(M[M1,M2] - m[m1,m2])

In [ ]:
np.random.normal(size = 3)

In [ ]:
gen.branch_order

In [ ]:
for i in range(12):
    print gen.features.keys()[i]
    a = gen.features.values()[i] - new.features.values()[i]
    print a

In [ ]:
new.branch_order

In [ ]:
print new.angle_global
print gen.angle_global

In [ ]:
len(per1.neuron.nodes_list)

In [ ]:
np.where(np.where(~np.isnan(new.overall_connectivity_matrix)) == np.where(~np.isnan(gen.overall_connectivity_matrix)))

In [ ]:
np.where(~np.isnan(gen.overall_connectivity_matrix))[1] - np.where(~np.isnan(new.overall_connectivity_matrix))[1]

In [ ]:
np.where(~np.isnan(new.overall_connectivity_matrix))[1]

In [ ]:
print new.features
print gen.features

In [ ]:
gen.ext_red_list - new.ext_red_list

In [ ]:
print new.local_angle
print gen.local_angle

In [ ]:
new.nodes_list[19].children

In [ ]:
gen.local_angle[25]

In [ ]:
new.n_soma

In [ ]:
new.overall_connectivity_matrix[:,3]

In [ ]:
gen.overall_connectivity_matrix[:,43]

In [ ]:
gen_old.overall_connectivity_matrix[:,4]

In [ ]:
print np.where(~np.isnan(gen.overall_connectivity_matrix))[0]

In [ ]:
print np.where(~np.isnan(new.overall_connectivity_matrix))[0]

In [ ]:
print np.where(~np.isnan(gen_old.overall_connectivity_matrix))[0]

In [ ]:
plt.imshow(gen.overall_connectivity_matrix)

In [ ]:
plt.imshow(new.overall_connectivity_matrix)

In [ ]:
plt.imshow(gen_old.overall_connectivity_matrix)

In [ ]:
new.get_index_for_no_soma_node(new.nodes_list[12].parent)

In [ ]:
new.get_index_for_no_soma_node(new.nodes_list[3].children[0])

In [ ]:
gen.overall_connectivity_matrix[8,3]

Test ext/red perturbation


In [ ]:
import os
import sys
sys.path.append("/Users/RoozbehFarhoudi/Documents/Repos/Generative-Models-of-Neuron-Morphology/")
import btmorph3
import numpy as np
import matplotlib.pyplot as plt
from copy import deepcopy
%matplotlib inline
#np.random.seed(0)
per = btmorph3.Perturbation(iterations = 20000,verbose=0)
M = {'mean': {
# 'Nbranch': 20,
  'Nendpoint': 20,
  'Nnodes': 400,
  #'angle_branch': 2.4,
  #'diameter': 1,
  #'distance_from_root2': 0, #30,
#'distance_from_root': 50,
  #'global_angle': .3,
  #'length_to_parent': 1,
 # 'local_angle':  3,
  'initial_segments': 4,
  #'slope': .1,
#'discrepancy_space': 60,
  'ratio_euclidian_neuronal': 1
    },
 'variance': {
 #  'Nbranch': 1,
  'Nendpoint': 1,
  'Nnodes': 5,
 # 'angle_branch': .2,
  #'diameter': 1,
  #'distance_from_root2': .5,
  #  'distance_from_root': 10,
 # 'global_angle': .100,
  #'length_to_parent': 1,
 # 'local_angle': .1, 
  'initial_segments': .3,
  #'slope': .1,
#'discrepancy_space': 5,
  'ratio_euclidian_neuronal': .01
             }}
per.set_ratio_red_to_ext(.1)
per.set_measure(M)
per.set_probability(np.array([.5,.5,0,0,0,0,0,0,0,0]))
per.fit()
gen = per.neuron
btmorph3.visualize.plot_2D(gen,show_radius=False);

In [ ]:
plt.plot(np.transpose(per.trend_normal[:,2000:]));
plt.legend(M['mean'].keys(),bbox_to_anchor=(1.7, 1))
#plt.ylim([-1,1])

In [ ]:
plt.plot(sum(per.trend,0));

In [ ]:
per.neuron.features

In [ ]:
plt.plot(np.transpose(per.trend_normal[:,500:]));
plt.legend(M['mean'].keys(),bbox_to_anchor=(1.7, 1))
#plt.ylim([-1,1])