This is the core sampling method. Samples a state from a
        demonstration, in accordance with the configuration.
343833
def sample(self):
        

        # chooses a sampling scheme randomly based on the mixing ratios
        seed = random.uniform(0, 1)
        ratio = np.cumsum(self.scheme_ratios)
        ratio = ratio > seed
        for i, v in enumerate(ratio):
            if v:
                break

        sample_method = getattr(self, self.sample_method_dict[self.sampling_schemes[i]])
        return sample_method()
1175785
@Override
    public DataSet sample(int numSamples, boolean withReplacement) {
        return sample(numSamples, Nd4j.getRandom(), withReplacement);
    }
590864
protected void initFromExtractedTraceState(APMSpanBuilder builder, TraceRecorder recorder, Reference ref, ContextSampler sampler) {
        APMSpanBuilder parentBuilder = (APMSpanBuilder) ref.getReferredTo();

        initTopLevelState(this, recorder, sampler);

        // Check for passed state
        if (parentBuilder.state().containsKey(Constants.HAWKULAR_APM_ID)) {
            setInteractionId(parentBuilder.state().get(Constants.HAWKULAR_APM_ID).toString());

            traceContext.initTraceState(parentBuilder.state());
        }

        // Assume top level consumer, even if no state was provided, as span context
        // as passed using a 'child of' relationship
        getNodeBuilder().setNodeType(NodeType.Consumer);

        processRemainingReferences(builder, ref);
    }
1118278
@Override
	public TimelineSample<StopwatchTimeRange> sample() {
		StopwatchTimeRange[] timeRangesCopy;
		synchronized (this) {
			timeRangesCopy = timeRanges.toArray(new StopwatchTimeRange[timeRanges.size()]);
		}
		// TODO sample each time-range by making a copy of it
		return new TimelineSample<>(timeRanges.getCapacity(), timeRangeWidth * SimonClock.NANOS_IN_MILLIS, timeRangesCopy);
	}
345451
function(n, loc, scale) {
                    n = this._v(n, "n");
                    loc = this._v(loc, "r", 0);
                    scale = this._v(scale, "nn", 1);

                    var toReturn = [];

                    for(var i=0; i<n; i++) {
                        var core = this.sample([-1,1])[0] * ln(this.prng());

                        var x = loc - scale * core;

                        toReturn[i] = x;
                    }

                    return toReturn
                }
965262
function Sample(cpu, thread, title, start, leafStackFrame,
                  opt_weight, opt_args) {
    tr.model.TimedEvent.call(this, start);

    this.title = title;
    this.cpu = cpu;
    this.thread = thread;
    this.leafStackFrame = leafStackFrame;
    this.weight = opt_weight;
    this.args = opt_args || {};
  }
741153
public void record(double sample) {
        rotate();
        long sampleLong = Double.doubleToLongBits(sample);
        for (AtomicLong max : ringBuffer) {
            updateMax(max, sampleLong);
        }
    }
283432
function() {
			var context = this.loopContext;
			var choiceContext = this.choiceContext;
			var forkContext = this.forkContext;

			// Update state.
			if (context.updateSegments) {
				context.endOfUpdateSegments = forkContext.head;

				// `update` -> `test`
				if (context.testSegments) {
					makeLooped(
						this,
						context.endOfUpdateSegments,
						context.testSegments);
				}
			} else if (context.testSegments) {
				finalizeTestSegmentsOfFor(
					context,
					choiceContext,
					forkContext.head);
			} else {
				context.endOfInitSegments = forkContext.head;
			}

			var bodySegments = context.endOfTestSegments;

			if (!bodySegments) {

				/*
				 * If there is not the `test` part, the `body` path comes from the
				 * `init` part and the `update` part.
				 */
				var prevForkContext = ForkContext.newEmpty(forkContext);

				prevForkContext.add(context.endOfInitSegments);
				if (context.endOfUpdateSegments) {
					prevForkContext.add(context.endOfUpdateSegments);
				}

				bodySegments = prevForkContext.makeNext(0, -1);
			}
			context.continueDestSegments = context.continueDestSegments || bodySegments;
			forkContext.replaceHead(bodySegments);
		}
1074591
private BitMatrix sampleGrid(BitMatrix image,
                               ResultPoint topLeft,
                               ResultPoint topRight,
                               ResultPoint bottomRight,
                               ResultPoint bottomLeft) throws NotFoundException {

    GridSampler sampler = GridSampler.getInstance();
    int dimension = getDimension();

    float low = dimension / 2.0f - nbCenterLayers;
    float high = dimension / 2.0f + nbCenterLayers;

    return sampler.sampleGrid(image,
                              dimension,
                              dimension,
                              low, low,   // topleft
                              high, low,  // topright
                              high, high, // bottomright
                              low, high,  // bottomleft
                              topLeft.getX(), topLeft.getY(),
                              topRight.getX(), topRight.getY(),
                              bottomRight.getX(), bottomRight.getY(),
                              bottomLeft.getX(), bottomLeft.getY());
  }
1035077
def _sample(self, position, stepsize):
        

        # Re-sampling momentum
        momentum = np.random.normal(0, 1, len(position))

        # Initializations
        depth = 0
        position_backward, position_forward = position, position
        momentum_backward, momentum_forward = momentum, momentum
        candidate_set_size = accept_set_bool = 1
        _, log_pdf = self.grad_log_pdf(position, self.model).get_gradient_log_pdf()

        # Resample slice variable `u`
        slice_var = np.random.uniform(0, np.exp(log_pdf - 0.5 * np.dot(momentum, momentum)))

        while accept_set_bool == 1:
            direction = np.random.choice([-1, 1], p=[0.5, 0.5])
            if direction == -1:
                # Build a tree in backward direction
                (position_backward, momentum_backward, _, _, position_bar,
                 candidate_set_size2, accept_set_bool2) = self._build_tree(position_backward, momentum_backward,
                                                                           slice_var, direction, depth, stepsize)
            else:
                # Build tree in forward direction
                (_, _, position_forward, momentum_forward, position_bar,
                 candidate_set_size2, accept_set_bool2) = self._build_tree(position_forward, momentum_forward,
                                                                           slice_var, direction, depth, stepsize)
            if accept_set_bool2 == 1:
                if np.random.rand() < candidate_set_size2 / candidate_set_size:
                    position = position_bar.copy()

            accept_set_bool, candidate_set_size = self._update_acceptance_criteria(position_forward, position_backward,
                                                                                   momentum_forward, momentum_backward,
                                                                                   accept_set_bool2, candidate_set_size,
                                                                                   candidate_set_size2)
            depth += 1

        return position
831730
@Override
	public Iterator<T> sample(Iterator<T> input) {
		return sampleInCoordinator(sampleInPartition(input));
	}
216888
function samples () {
  form.samples.url.link.on("click", function (event) {
    event.preventDefault();
    form.url.val(samples.url);
  });

  form.samples.text.link.on("click", function (event) {
    event.preventDefault();
    form.textBox.setValue(samples.text, -1);
    form.samples.text.container.hide();
    form.textBox.focus();
  });

  form.textBox.on("input", function () {
    if (form.textBox.session.getValue().length === 0) {
      form.samples.text.container.show();
    }
    else {
      form.samples.text.container.hide();
    }
  });
}
367382
def sample_bitstrings(self, n_samples):
        
        if self.rs is None:
            raise ValueError("You have tried to perform a stochastic operation without setting the "
                             "random state of the simulator. Might I suggest using a PyQVM object?")
        probabilities = np.real_if_close(np.diagonal(self.density))
        possible_bitstrings = all_bitstrings(self.n_qubits)
        inds = self.rs.choice(2 ** self.n_qubits, n_samples, p=probabilities)
        bitstrings = possible_bitstrings[inds, :]
        bitstrings = np.flip(bitstrings, axis=1)  # qubit ordering: 0 on the left.
        return bitstrings
810165
@Inject
    public void setSamplerConfiguration(@Nullable Configuration.SamplerConfiguration samplerConfiguration) {
        if (samplerConfiguration != null) {
            configuration.withSampler(samplerConfiguration);
        }
    }
500187
def icontinue(self):
        
        if self.status != 'paused':
            print_(
                "No sampling to continue. Please initiate sampling with isample.")
            return

        def sample_and_finalize():
            self._loop()
            self._finalize()

        self._sampling_thread = Thread(target=sample_and_finalize)
        self.status = 'running'
        self._sampling_thread.start()
        self.iprompt()
341406
public final void sample()
  {
    long sum = _sum.getAndSet(0);
    int count = _count.getAndSet(0);

    if (count != 0)
      _value =sum / (double) count;
    else
      _value = 0;
  }
1295508
public void setSamples(java.util.Collection<Sample> samples) {
        if (samples == null) {
            this.samples = null;
            return;
        }

        this.samples = new java.util.ArrayList<Sample>(samples);
    }