Estimates std of underlying data, assuming each datapoint was exactly in the center of its bin.
486919
def std(self, bessel_correction=True):
        """"""
        if bessel_correction:
            n = self.n
            bc = n / (n - 1)
        else:
            bc = 1
        return np.sqrt(np.average((self.bin_centers - self.mean) ** 2, weights=self.histogram)) * bc
108708
def background_estimator(bdata):
    """"""

    crowded = False

    std = numpy.std(bdata)
    std0 = std
    mean = bdata.mean()
    while True:
        prep = len(bdata)
        numpy.clip(bdata, mean - 3 * std, mean + 3 * std, out=bdata)
        if prep == len(bdata):
            if std < 0.8 * std0:
                crowded = True
            break
        std = numpy.std(bdata)
        mean = bdata.mean()

    if crowded:
        median = numpy.median(bdata)
        mean = bdata.mean()
        std = bdata.std()
        return 2.5 * median - 1.5 * mean, std

    return bdata.mean(), bdata.std()
528739
def estimate(self, points):
        """"""
        points = list(points)
        densities = callMLlibFunc(
            "estimateKernelDensity", self._sample, self._bandwidth, points)
        return np.asarray(densities)
1088794
function (D) {
			var N = D.length;
			assert(N > 0, " X is empty? You must have some data!");
			// convert D to a (fast) typed array version
			var dists = zeros(N * N); // allocate contiguous array
			for (var i = 0; i < N; i++) {
				for (var j = i + 1; j < N; j++) {
					var d = D[i][j];
					dists[i * N + j] = d;
					dists[j * N + i] = d;
				}
			}
			this.P = d2p(dists, this.perplexity, 1e-4);
			this.N = N;
			this.initSolution(); // refresh this
		}
181926
def glBufferData(target, data, usage):
    
    if isinstance(data, int):
        size = data
        data = ctypes.c_voidp(0)
    else:
        if not data.flags['C_CONTIGUOUS'] or not data.flags['ALIGNED']:
            data = data.copy('C')
        data_ = data
        size = data_.nbytes
        data = data_.ctypes.data
    res = _lib.glBufferData(target, size, data, usage)
416736
protected static double calculateLof(LofPoint basePoint, LofDataSet dataSet)
    {
        int countedData = 0;
        double totalAmount = 0.0d;
        for (String targetDataId : basePoint.getkDistanceNeighbor())
        {
            LofPoint targetPoint = dataSet.getDataMap().get(targetDataId);

            totalAmount = totalAmount + (targetPoint.getLrd() / basePoint.getLrd());
            countedData++;
        }

        if (countedData == 0)
        {
            return totalAmount;
        }

        return totalAmount / (countedData);
    }
65607
def val_to_bin(edges, x):
    """"""
    ibin = np.digitize(np.array(x, ndmin=1), edges) - 1
    return ibin
557461
def percentile(data, n):
    

    size = len(data)
    idx = (n / 100.0) * size - 0.5

    if idx < 0 or idx > size:
        raise StatisticsError("Too few data points ({}) for {}th percentile".format(size, n))

    return data[int(idx)]
283850
def normalize_std_array(vector):
  """"""

  # Initializes variables
  length = 1
  n_samples = len(vector)
  mean = numpy.ndarray((length,), 'float64')
  std = numpy.ndarray((length,), 'float64')
  mean.fill(0)
  std.fill(0)

  # Computes mean and variance
  for array in vector:
    x = array.astype('float64')
    mean += x
    std += (x ** 2)

  mean /= n_samples
  std /= n_samples
  std -= (mean ** 2)
  std = std ** 0.5
  arrayset = numpy.ndarray(shape=(n_samples,mean.shape[0]), dtype=numpy.float64)

  for i in range (0, n_samples):
    arrayset[i,:] = (vector[i]-mean) / std
  return arrayset
317026
def kde(data, npoints=_npoints):
    
    # Clipping of severe outliers to concentrate more KDE samples in the parameter range of interest
    mad = np.median(np.fabs(np.median(data) - data))
    cut = (data > np.median(data) - 5. * mad) & (data < np.median(data) + 5. * mad)
    x = data[cut]
    kde = scipy.stats.gaussian_kde(x)
    # No penalty for using a finer sampling for KDE evaluation except computation time
    values = np.linspace(np.min(x), np.max(x), npoints)
    kde_values = kde.evaluate(values)
    peak = values[np.argmax(kde_values)]
    return values[np.argmax(kde_values)], kde.evaluate(peak)
1256349
def sum_of_reoccurring_data_points(x):
    
    unique, counts = np.unique(x, return_counts=True)
    counts[counts < 2] = 0
    return np.sum(counts * unique)
1228031
def _compute_std_dev(self, X):
        """"""

        self._sigma = []
        if X.shape[0] <= 1:
            self._sigma = [0.0]
        else:
            for x_mean in range(X.shape[0]):
                std_dev = np.sqrt(sum([np.linalg.norm(x - x_mean) ** 2 for x in X]) / float(X.shape[0]-1))
                self._sigma.append(std_dev)

        return self._sigma
1316446
function getNearestDataPoint(mouseX) {
            let adjustedMouseX = mouseX - margin.left,
                epsilon = xScale2.bandwidth(),
                nearest = [];

            layers.forEach(function (data) {
                let found = data.values.find((d2) => Math.abs(adjustedMouseX >= xScale(d2[nameLabel]) + xScale2(d2[groupLabel])) && Math.abs(adjustedMouseX - xScale2(d2[groupLabel]) - xScale(d2[nameLabel]) <= epsilon));

                if (found) {
                    found.values = data.values;
                    found.key = found.name;
                    nearest.push(found);
                }

            });

            return nearest.length ? nearest[0] : undefined;
        }
1292746
public DoubleDataStore computeAverageDistInSet() {
    WritableDoubleDataStore davg = DataStoreUtil.makeDoubleStorage(points.getDBIDs(), DataStoreFactory.HINT_HOT);
    WritableIntegerDataStore nDists = DataStoreUtil.makeIntegerStorage(points.getDBIDs(), DataStoreFactory.HINT_HOT | DataStoreFactory.HINT_TEMP);
    FiniteProgress splitp = LOG.isVerbose() ? new FiniteProgress("Processing splits for density estimation", splitsets.size(), LOG) : null;
    DBIDVar v = DBIDUtil.newVar();
    for(Iterator<ArrayDBIDs> it1 = splitsets.iterator(); it1.hasNext();) {
      ArrayDBIDs pinSet = it1.next();
      final int len = pinSet.size();
      final int indoff = len >> 1;
      pinSet.assignVar(indoff, v);
      V midpoint = points.get(v);
      for(DBIDArrayIter it = pinSet.iter(); it.getOffset() < len; it.advance()) {
        if(DBIDUtil.equal(it, v)) {
          continue;
        }
        double dist = EuclideanDistanceFunction.STATIC.distance(points.get(it), midpoint);
        ++distanceComputations;
        davg.increment(v, dist);
        nDists.increment(v, 1);
        davg.increment(it, dist);
        nDists.increment(it, 1);
      }
      LOG.incrementProcessed(splitp);
    }
    LOG.ensureCompleted(splitp);
    for(DBIDIter it = points.getDBIDs().iter(); it.valid(); it.advance()) {
      // it might be that a point does not occur for a certain size of a
      // projection (likely if do few projections, in this case there is no avg
      // distance)
      int count = nDists.intValue(it);
      double val = (count == 0) ? FastOPTICS.UNDEFINED_DISTANCE : (davg.doubleValue(it) / count);
      davg.put(it, val);
    }
    nDists.destroy(); // No longer needed after normalization
    return davg;
  }
982964
def estimate_parameters(self, max_dist_kb, size_bin_kb, display_graph):
        
        logger.info("estimation of the parameters of the model")
        self.bins = np.arange(
            size_bin_kb, max_dist_kb + size_bin_kb, size_bin_kb
        )

        self.mean_contacts = np.zeros_like(self.bins, dtype=np.float32)
        self.dict_collect = dict()
        self.gpu_vect_frags.copy_from_gpu()
        epsi = self.mean_value_trans
        for k in self.bins:
            self.dict_collect[k] = []
        for i in range(0, 2000):
            # print "frag i = ", i
            start = self.sparse_matrix.indptr[i]
            end = self.sparse_matrix.indptr[i + 1]
            id_j = self.sparse_matrix.indices[start:end]
            data = self.sparse_matrix.data[start:end]

            info_i = self.np_sub_frags_2_frags[i]
            init_id_fi = info_i[0]
            # pos_i = self.S_o_A_frags["pos"][init_id_fi]
            id_c_i = self.S_o_A_frags["id_c"][init_id_fi]
            s_i = (
                self.S_o_A_frags["start_bp"][init_id_fi] / 1000.0
                + self.np_sub_frags_2_frags[i][1]
            )
            len_kb_c_i = self.S_o_A_frags["l_cont_bp"][init_id_fi] / 1000
            local_bins = np.arange(
                size_bin_kb,
                min(len_kb_c_i, max_dist_kb) + size_bin_kb,
                size_bin_kb,
            )
            local_storage = np.zeros_like(local_bins, dtype=np.int32)

            for fj, dj in zip(id_j, data):
                info_j = self.np_sub_frags_2_frags[fj]
                init_id_fj = info_j[0]
                id_c_j = self.S_o_A_frags["id_c"][init_id_fj]
                if id_c_i == id_c_j:
                    # pos_j = self.S_o_A_frags["pos"][init_id_fj]
                    s_j = (
                        self.S_o_A_frags["start_bp"][init_id_fj] / 1000.0
                        + self.np_sub_frags_2_frags[fj][1]
                    )
                    d = np.abs(s_i - s_j)
                    if d < max_dist_kb:
                        id_bin = d / size_bin_kb
                        local_storage[id_bin] += dj
                        # self.dict_collect[self.bins[id_bin]].append(dj)
            # we have to add also the zeros
            for my_bin, val in zip(local_bins, local_storage):
                # print "bin = ", bin
                self.dict_collect[my_bin].append(val)

        for id_bin in range(0, len(self.bins)):
            k = self.bins[id_bin]
            self.mean_contacts[id_bin] = np.mean(self.dict_collect[k])

        for id_bin in range(0, len(self.bins)):
            k = self.bins[id_bin]
            tmp = np.mean(self.dict_collect[k])
            if np.isnan(tmp) or tmp == 0:
                # if np.isnan(tmp):
                # if np.isnan(tmp):
                #     print "removing nan"
                self.mean_contacts[id_bin] = np.nan
            else:
                self.mean_contacts[id_bin] = tmp + epsi

        self.mean_contacts_upd = []
        self.bins_upd = []

        for count, ele in zip(self.mean_contacts, self.bins):
            if not np.isnan(count):
                self.bins_upd.append(ele)
                self.mean_contacts_upd.append(count)

        self.bins_upd = np.array(self.bins_upd)
        self.mean_contacts_upd = np.array(self.mean_contacts_upd)

        # self.mean_contacts_upd =
        # ndi.filters.gaussian_filter1d(self.mean_contacts_upd,
        # sigma=len(self.bins_upd) / 5.)

        p, self.y_estim = nuis.estimate_param_hic(
            self.mean_contacts_upd, self.bins_upd
        )
        ##########################################
        fit_param = p.x
        ##########################################
        logger.info("mean value trans = {}".format(self.mean_value_trans))
        ##########################################
        estim_max_dist = nuis.estimate_max_dist_intra(
            fit_param, self.mean_value_trans
        )
        logger.info("max distance cis/trans = {}".format(estim_max_dist))
        ##########################################
        self.param_simu = self.setup_model_parameters(
            fit_param, estim_max_dist
        )
        self.gpu_param_simu = cuda.mem_alloc(self.param_simu.nbytes)
        self.gpu_param_simu_test = cuda.mem_alloc(self.param_simu.nbytes)

        cuda.memcpy_htod(self.gpu_param_simu, self.param_simu)

        if display_graph:
            plt.loglog(self.bins_upd, self.mean_contacts_upd, "-*b")
            plt.loglog(self.bins_upd, self.y_estim, "-*r")
            plt.xlabel("genomic distance (kb)")
            plt.ylabel("frequency of contact")
            plt.legend(["obs", "fit"])
            plt.show()
378926
def WorkersDensity(dataTasks):
    """"""

    start_time, end_time = getTimes(dataTasks)
    graphdata = []

    for name in getWorkersName(dataTasks):
        vals = dataTasks[name]
        if hasattr(vals, 'values'):
            # Data from worker
            workerdata = []
            print("Plotting density map for {}".format(name))
            # We only have 800 pixels
            try:
                for graphtime in timeRange(start_time, end_time, DENSITY_MAP_TIME_AXIS_LENGTH):
                    for a in vals.values():
                        if not all((a['start_time'], a['end_time'])):
                            print("Invalid data:", a['start_time'], a['end_time'])
                        #print(a['start_time'], a['end_time'])
                    workerdata.append(sum([a['start_time'][0] <= float(graphtime) /
                        1000. <= a['end_time'][0] for a in vals.values()
                            if a['start_time'] and a['end_time']])
                    )
            except OverflowError:
                print("Error processing {0} or {1}".format(start_time, end_time))
            graphdata.append(workerdata)

            if args.binarydensity:
                # Normalize [...]
                maxval = max(graphdata[-1])
                if maxval > 1:
                    maxval = maxval - 1
                    graphdata[-1] = [x - maxval for x in graphdata[-1]]
    return graphdata
930387
def _centroids(self, verts):
        
        '''
        value = sp.zeros([len(verts), 3])
        for i, i_verts in enumerate(verts):
            value[i] = np.mean(i_verts, axis=0)
        return value