original_docstring: 
          Computes Ripley's K cross-function. Only works with 'radius' neighborhood matrix type.
          Stores results in the dataframe perimage_results_table.
  
          :feature_column: str
                            features' name from feature_table.
  
          :radius: int or float
                   maximum distance at which objects are considered save_neighbors
  
          :permutations: int
                         number of random permutations to compute the quantiles and p-value
          :quantiles: list of 2 float
                      quantiles, 2 numbers between 0 and 100
          
docstring: Computes Ripley's K cross-function. Only works with 'radius' neighborhood matrix type.
  Stores results in the dataframe perimage_results_table.
docstring_tokens: Computes Ripley ' s K cross - function . Only works with ' radius ' neighborhood matrix type . Stores results in the dataframe perimage_results_table .
code: def _compute_ripley(self,
                          feature_column,
                          radius,
                          permutations=999,
                          quantiles=[2.5, 97.5],
                          **kwargs):
  
          '''
          Computes Ripley's K cross-function. Only works with 'radius' neighborhood matrix type.
          Stores results in the dataframe perimage_results_table.
  
          :feature_column: str
                            features' name from feature_table.
  
          :radius: int or float
                   maximum distance at which objects are considered save_neighbors
  
          :permutations: int
                         number of random permutations to compute the quantiles and p-value
          :quantiles: list of 2 float
                      quantiles, 2 numbers between 0 and 100
          '''
  
          area = self.image_label.size
  
          _, radius, _ = self._check_neighborhood_matrix_parameters('radius', 0, radius, 'None')
  
          try:
              w = self.get_neighborhood_matrix('radius', 0, radius)
          except ValueError:
              self.compute_neighborhood_matrix('radius', 0, radius, save_neighbors=False)
              w = self.get_neighborhood_matrix('radius', 0, radius)
  
          suffix = self.get_suffix('radius', 0, radius)
          cond = self.feature_table['NumberNeighbors_{}'.format(suffix)]>0
          class_object, classes = pd.factorize(self.feature_table.loc[cond, feature_column], sort=True)
          count_classes = pd.value_counts(self.feature_table.loc[cond, feature_column])[classes].values
  
          if self._debug:
              print("in _compute_ripley", classes, count_classes)
  
          lambda_i = count_classes/area
          sum_lambda = lambda_i + lambda_i[:,np.newaxis]
  
          if (count_classes<=1).all():
              raise TypeError("{} is not categorical".format(feature_column))
  
          edge_corr = self._get_edge_correction_area(radius)
          product = w[0]*edge_corr
  
          ### monte carlo simulations: "fix the combined set of locations and the number of each type of event, then randomly assigns labels to locations." Dixon 2002
          shuffled_labels = self._compute_randomizations(cond,
                                    feature_column,
                                    permutations,
                                    **kwargs)
          print(shuffled_labels[0].shape, product.shape)
  
          ripley_cross = np.zeros((len(classes), len(classes)))
          ripley_cross_permutations = np.zeros((len(classes), len(classes), permutations))
  
          for i, count_i in enumerate(count_classes):
              for j, count_j in enumerate(count_classes):
  
                  big_sum = np.nansum(product[class_object == i,:]
                                             [:,class_object == j])
                  factor = area/count_i/count_j
                  ripley_cross[i,j] = factor*big_sum
  
                  ripley_cross_perm = np.array([factor*
                                  np.nansum(product[class_shuffled == classes[i],:]
                                                   [:,class_shuffled == classes[j]]) 
                                  for class_shuffled in shuffled_labels])
                  ripley_cross_permutations[i,j,:] = ripley_cross_perm
  
  
          if self._debug:
              print("in _compute_ripley", ripley_cross, classes, lambda_i)
              
          ripley_cross_star = (ripley_cross*lambda_i + (ripley_cross*lambda_i).T)/sum_lambda
          K = area*np.nansum(product)/self.n/self.n
  
          ripley_results = RipleyObject(classes, count_classes, K, ripley_cross, ripley_cross_star, ripley_cross_permutations, lambda_i)
  
          multiIndex_f = (feature_column, \
                          'radius', 0, radius, 'None',\
                          permutations, quantiles[0], quantiles[1])
  
          self.perimage_results_table.loc[multiIndex_f, "ripley_results"] = ripley_results
          self.perimage_results_table.sortlevel(inplace=True)
code_tokens: def _compute_ripley ( self , feature_column , radius , permutations = 999 , quantiles = [ 2.5 , 97.5 ] , ** kwargs ) : area = self . image_label . size _ , radius , _ = self . _check_neighborhood_matrix_parameters ( 'radius' , 0 , radius , 'None' ) try : w = self . get_neighborhood_matrix ( 'radius' , 0 , radius ) except ValueError : self . compute_neighborhood_matrix ( 'radius' , 0 , radius , save_neighbors = False ) w = self . get_neighborhood_matrix ( 'radius' , 0 , radius ) suffix = self . get_suffix ( 'radius' , 0 , radius ) cond = self . feature_table [ 'NumberNeighbors_{}' . format ( suffix ) ] > 0 class_object , classes = pd . factorize ( self . feature_table . loc [ cond , feature_column ] , sort = True ) count_classes = pd . value_counts ( self . feature_table . loc [ cond , feature_column ] ) [ classes ] . values if self . _debug : print ( "in _compute_ripley" , classes , count_classes ) lambda_i = count_classes / area sum_lambda = lambda_i + lambda_i [ : , np . newaxis ] if ( count_classes <= 1 ) . all ( ) : raise TypeError ( "{} is not categorical" . format ( feature_column ) ) edge_corr = self . _get_edge_correction_area ( radius ) product = w [ 0 ] * edge_corr shuffled_labels = self . _compute_randomizations ( cond , feature_column , permutations , ** kwargs ) print ( shuffled_labels [ 0 ] . shape , product . shape ) ripley_cross = np . zeros ( ( len ( classes ) , len ( classes ) ) ) ripley_cross_permutations = np . zeros ( ( len ( classes ) , len ( classes ) , permutations ) ) for i , count_i in enumerate ( count_classes ) : for j , count_j in enumerate ( count_classes ) : big_sum = np . nansum ( product [ class_object == i , : ] [ : , class_object == j ] ) factor = area / count_i / count_j ripley_cross [ i , j ] = factor * big_sum ripley_cross_perm = np . array ( [ factor * np . nansum ( product [ class_shuffled == classes [ i ] , : ] [ : , class_shuffled == classes [ j ] ] ) for class_shuffled in shuffled_labels ] ) ripley_cross_permutations [ i , j , : ] = ripley_cross_perm if self . _debug : print ( "in _compute_ripley" , ripley_cross , classes , lambda_i ) ripley_cross_star = ( ripley_cross * lambda_i + ( ripley_cross * lambda_i ) . T ) / sum_lambda K = area * np . nansum ( product ) / self . n / self . n ripley_results = RipleyObject ( classes , count_classes , K , ripley_cross , ripley_cross_star , ripley_cross_permutations , lambda_i ) multiIndex_f = ( feature_column , 'radius' , 0 , radius , 'None' , permutations , quantiles [ 0 ] , quantiles [ 1 ] ) self . perimage_results_table . loc [ multiIndex_f , "ripley_results" ] = ripley_results self . perimage_results_table . sortlevel ( inplace = True )
short_docstring: Computes Ripley's K cross-function.
short_docstring_tokens: Computes Ripley ' s K cross - function .
comment: '''
          Computes Ripley's K cross-function. Only works with 'radius' neighborhood matrix type.
          Stores results in the dataframe perimage_results_table.
  
          :feature_column: str
                            features' name from feature_table.
  
          :radius: int or float
                   maximum distance at which objects are considered save_neighbors
  
          :permutations: int
                         number of random permutations to compute the quantiles and p-value
          :quantiles: list of 2 float
                      quantiles, 2 numbers between 0 and 100
          '''$SEP$### monte carlo simulations: "fix the combined set of locations and the number of each type of event, then randomly assigns labels to locations." Dixon 2002