Bifurcation section lengths in a collection of neurites
11524
def section_bif_lengths(neurites, neurite_type=NeuriteType.all):
    ''''''
    return map_sections(_section_length, neurites, neurite_type=neurite_type,
                        iterator_type=Tree.ibifurcation_point)
1124788
def neurite_volume_density(neurites, neurite_type=NeuriteType.all):
    '''
    '''
    def vol_density(neurite):
        '''volume density of a single neurite'''
        return neurite.volume / convex_hull(neurite).volume

    return list(vol_density(n)
                for n in iter_neurites(neurites, filt=is_type(neurite_type)))
753840
def radius_of_gyration(neurite):
    ''''''
    centre_mass = neurite_centre_of_mass(neurite)
    sum_sqr_distance = 0
    N = 0
    dist_sqr = [distance_sqr(centre_mass, s) for s in nm.iter_segments(neurite)]
    sum_sqr_distance = np.sum(dist_sqr)
    N = len(dist_sqr)
    return np.sqrt(sum_sqr_distance / N)
702721
def partition_asymmetries(neurites, neurite_type=NeuriteType.all):
    ''''''
    return map(_bifurcationfunc.partition_asymmetry,
               iter_sections(neurites,
                             iterator_type=Tree.ibifurcation_point,
                             neurite_filter=is_type(neurite_type)))
415229
def neurite_root_section_ids(self):
        ''''''
        sec = self.sections
        return [i for i, ss in enumerate(sec)
                if ss.pid > -1 and (sec[ss.pid].ntype == POINT_TYPE.SOMA and
                                    ss.ntype != POINT_TYPE.SOMA)]
979971
def plot_neuron_on_density(population, # pylint: disable=too-many-arguments
                           bins=100, new_fig=True, subplot=111, levels=None, plane='xy',
                           colorlabel='Nodes per unit area', labelfontsize=16,
                           color_map='Reds', no_colorbar=False, threshold=0.01,
                           neurite_type=NeuriteType.basal_dendrite, **kwargs):
    '''
    '''
    _, ax = common.get_figure(new_fig=new_fig)

    view.plot_tree(ax, population.neurites[0])

    return plot_density(population, plane=plane, bins=bins, new_fig=False, subplot=subplot,
                        colorlabel=colorlabel, labelfontsize=labelfontsize, levels=levels,
                        color_map=color_map, no_colorbar=no_colorbar, threshold=threshold,
                        neurite_type=neurite_type, **kwargs)
590775
def _preSynapticFFCells(self, i, j):
    
    xmin = max(i - 1, 0)
    xmax = min(i + 2, self.inputWidth)
    ymin = max(j - 1, 0)
    ymax = min(j + 2, self.inputHeight)
    inputCells = [
      (x, y) for x in range(xmin, xmax) for y in range(ymin, ymax)
    ]

    return inputCells
916806
def principal_direction_extents(neurites, neurite_type=NeuriteType.all, direction=0):
    ''''''
    def _pde(neurite):
        '''Get the PDE of a single neurite'''
        # Get the X, Y,Z coordinates of the points in each section
        points = neurite.points[:, :3]
        return morphmath.principal_direction_extent(points)[direction]

    return map(_pde, iter_neurites(neurites, filt=is_type(neurite_type)))
855027
def updateSynapses(self, segment, synapses, delta):
    

    reached0 = False

    if delta > 0:
      for synapse in synapses:
        segment[synapse][2] = newValue = segment[synapse][2] + delta

        # Cap synapse permanence at permanenceMax
        if newValue > self.permanenceMax:
          segment[synapse][2] = self.permanenceMax

    else:
      for synapse in synapses:
        segment[synapse][2] = newValue = segment[synapse][2] + delta

        # Cap min synapse permanence to 0 in case there is no global decay
        if newValue < 0:
          segment[synapse][2] = 0
          reached0 = True

    return reached0
15120
def get_T_yX(fname, y, y_in_Y, x_in_X, F_y):
    '''
     
    
    '''
    def _get_k_yX_mul_F_y(y, y_index, X_index):
        # Load data from json dictionary
        f = open(fname, 'r')
        data = json.load(f)
        f.close()
    
        #init variables
        k_yX = 0.
        
        for l in [str(key) for key in data['data'][y]['syn_dict'].keys()]:
            for x in x_in_X[X_index]:
                p_yxL = data['data'][y]['syn_dict'][l][x] / 100.
                k_yL = data['data'][y]['syn_dict'][l]['number of synapses per neuron']
                k_yX +=  p_yxL * k_yL
        
        return k_yX * F_y[y_index]


    #container
    T_yX = np.zeros((len(y), len(x_in_X)))
    
    #iterate over postsynaptic cell types
    for i, y_value in enumerate(y):
        #iterate over presynapse population inds
        for j in range(len(x_in_X)):
            k_yX_mul_F_y = 0
            for k, yy in enumerate(sum(y_in_Y, [])):                
                if y_value in yy:
                    for yy_value in yy:
                        ii = np.where(np.array(y) == yy_value)[0][0]
                        k_yX_mul_F_y += _get_k_yX_mul_F_y(yy_value, ii, j)
            
            
            if k_yX_mul_F_y != 0:
                T_yX[i, j] = _get_k_yX_mul_F_y(y_value, i, j) / k_yX_mul_F_y
            
    return T_yX
739579
def map_neurons(fun, neurites, neurite_type):
    ''''''
    nrns = _neuronfunc.neuron_population(neurites)
    return [fun(n, neurite_type=neurite_type) for n in nrns]
403524
def number_of_sections_per_neurite(neurites, neurite_type=NeuriteType.all):
    ''''''
    return list(sum(1 for _ in n.iter_sections())
                for n in iter_neurites(neurites, filt=is_type(neurite_type)))
721333
def segment_meander_angles(neurites, neurite_type=NeuriteType.all):
    ''''''
    return list(chain.from_iterable(map_sections(
        sectionfunc.section_meander_angles, neurites, neurite_type)))
467196
def local_bifurcation_angles(neurites, neurite_type=NeuriteType.all):
    ''''''
    return map_sections(_bifurcationfunc.local_bifurcation_angle,
                        neurites,
                        neurite_type=neurite_type,
                        iterator_type=Tree.ibifurcation_point)
953655
def _sensoryComputeLearningMode(self, anchorInput):
    
    overlaps = self.connections.computeActivity(anchorInput,
                                                self.connectedPermanence)
    activeSegments = np.where(overlaps >= self.activationThreshold)[0]

    potentialOverlaps = self.connections.computeActivity(anchorInput)
    matchingSegments = np.where(potentialOverlaps >=
                                self.learningThreshold)[0]

    # Cells with a active segment: reinforce the segment
    cellsForActiveSegments = self.connections.mapSegmentsToCells(
      activeSegments)
    learningActiveSegments = activeSegments[
      np.in1d(cellsForActiveSegments, self.activeCells)]
    remainingCells = np.setdiff1d(self.activeCells, cellsForActiveSegments)

    # Remaining cells with a matching segment: reinforce the best
    # matching segment.
    candidateSegments = self.connections.filterSegmentsByCell(
      matchingSegments, remainingCells)
    cellsForCandidateSegments = (
      self.connections.mapSegmentsToCells(candidateSegments))
    candidateSegments = candidateSegments[
      np.in1d(cellsForCandidateSegments, remainingCells)]
    onePerCellFilter = np2.argmaxMulti(potentialOverlaps[candidateSegments],
                                       cellsForCandidateSegments)
    learningMatchingSegments = candidateSegments[onePerCellFilter]

    newSegmentCells = np.setdiff1d(remainingCells, cellsForCandidateSegments)

    for learningSegments in (learningActiveSegments,
                             learningMatchingSegments):
      self._learn(self.connections, self.rng, learningSegments,
                  anchorInput, potentialOverlaps,
                  self.initialPermanence, self.sampleSize,
                  self.permanenceIncrement, self.permanenceDecrement,
                  self.maxSynapsesPerSegment)

    # Remaining cells without a matching segment: grow one.
    numNewSynapses = len(anchorInput)

    if self.sampleSize != -1:
      numNewSynapses = min(numNewSynapses, self.sampleSize)

    if self.maxSynapsesPerSegment != -1:
      numNewSynapses = min(numNewSynapses, self.maxSynapsesPerSegment)

    newSegments = self.connections.createSegments(newSegmentCells)

    self.connections.growSynapsesToSample(
      newSegments, anchorInput, numNewSynapses,
      self.initialPermanence, self.rng)
    self.activeSegments = activeSegments
    self.sensoryAssociatedCells = self.activeCells
1272651
static public void bpropMiniBatch(Neurons[] neurons, int n) {
    neurons[neurons.length - 1].bpropOutputLayer(n);
    for (int i = neurons.length - 2; i > 0; --i)
      neurons[i].bprop(n);

    for (int mb=0;mb<n;++mb) {
      // all errors are reset to 0
      for (int i = 0; i<neurons.length ;++i) {
        Storage.DenseVector e = neurons[i]._e == null ? null : neurons[i]._e[mb];
        if (e==null) continue;
        Arrays.fill(e.raw(), 0);
      }
    }
  }
178633
def total_length(nrn_pop, neurite_type=NeuriteType.all):
    ''''''
    nrns = _neuronfunc.neuron_population(nrn_pop)
    return list(sum(section_lengths(n, neurite_type=neurite_type)) for n in nrns)