<jupyter_start><jupyter_text>Test the Algorithm<jupyter_code>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}}
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
              
             }
    }
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);
new = btmorph3.Neuron(file_format = 'only list of nodes',input_file = deepcopy(per.neuron.nodes_list))
gen = per.neuron
Inter1 = btmorph3.Neuron(file_format = 'swc', input_file=loc2)
#Inter2 = btmorph3.Neuron(file_format = 'only list of nodes', input_file=deepcopy(Inter1.nodes_list))
btmorph3.visualize.plot_2D(Inter1,show_radius=False);
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);
new = Inter1
gen = inter
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
new.root.xyz
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])
np.random.normal(size = 3)
gen.branch_order
for i in range(12):
    print gen.features.keys()[i]
    a = gen.features.values()[i] - new.features.values()[i]
    print a
new.branch_order
print new.angle_global
print gen.angle_global
len(per1.neuron.nodes_list)
np.where(np.where(~np.isnan(new.overall_connectivity_matrix)) == np.where(~np.isnan(gen.overall_connectivity_matrix)))
np.where(~np.isnan(gen.overall_connectivity_matrix))[1] - np.where(~np.isnan(new.overall_connectivity_matrix))[1]
np.where(~np.isnan(new.overall_connectivity_matrix))[1]
print new.features
print gen.features
gen.ext_red_list - new.ext_red_list
print new.local_angle
print gen.local_angle
new.nodes_list[19].children
gen.local_angle[25]
new.n_soma
new.overall_connectivity_matrix[:,3]
gen.overall_connectivity_matrix[:,43]
gen_old.overall_connectivity_matrix[:,4]
print np.where(~np.isnan(gen.overall_connectivity_matrix))[0]
print np.where(~np.isnan(new.overall_connectivity_matrix))[0]
print np.where(~np.isnan(gen_old.overall_connectivity_matrix))[0]
plt.imshow(gen.overall_connectivity_matrix)
plt.imshow(new.overall_connectivity_matrix)
plt.imshow(gen_old.overall_connectivity_matrix)
new.get_index_for_no_soma_node(new.nodes_list[12].parent)
new.get_index_for_no_soma_node(new.nodes_list[3].children[0])
gen.overall_connectivity_matrix[8,3]<jupyter_output><empty_output><jupyter_text>Test ext/red perturbation<jupyter_code>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);
plt.plot(np.transpose(per.trend_normal[:,2000:]));
plt.legend(M['mean'].keys(),bbox_to_anchor=(1.7, 1))
#plt.ylim([-1,1])
plt.plot(sum(per.trend,0));
per.neuron.features
plt.plot(np.transpose(per.trend_normal[:,500:]));
plt.legend(M['mean'].keys(),bbox_to_anchor=(1.7, 1))
#plt.ylim([-1,1])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17326092578226016, 'fraction_numerical': 0.04512542022239462, 'mean_word_length': 5.456594323873122, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '562871', 'license': 'MIT', 'n_tokens_mistral': 3418, 'n_tokens_neox': 3179, 'n_words': 477, 'path': 'Test/Test the perturbations.ipynb', 'repo_name': 'RoozbehFarhoodi/McNeuron', 'size': '7734'}