/* (non-Javadoc)
@see net.finmath.stochastic.RandomVariableInterface#getHistogram(int,double)
8107
@Override
	public double[][] getHistogram(int numberOfPoints, double standardDeviations) {
		double[] intervalPoints = new double[numberOfPoints];
		double[] anchorPoints	= new double[numberOfPoints+1];
		double center	= getAverage();
		double radius	= standardDeviations * getStandardDeviation();
		double stepSize	= (numberOfPoints-1) / 2.0;
		for(int i=0; i<numberOfPoints;i++) {
			double alpha = (-(double)(numberOfPoints-1) / 2.0 + i) / stepSize;
			intervalPoints[i]	= center + alpha * radius;
			anchorPoints[i]		= center + alpha * radius - radius / (2 * stepSize);
		}
		anchorPoints[numberOfPoints] = center + 1 * radius + radius / (2 * stepSize);

		double[][] result = new double[2][];
		result[0] = anchorPoints;
		result[1] = getHistogram(intervalPoints);

		return result;
	}
198521
public static final Double getDouble(InputStream is) throws IOException
   {
      double result = Double.longBitsToDouble(getLong(is));
      if (Double.isNaN(result))
      {
         result = 0;
      }
      return Double.valueOf(result);
   }
664776
@Override
	public RandomVariable floor(double floor) {
		return apply(new DoubleUnaryOperator() {
			@Override
			public double applyAsDouble(double x) {
				return Math.max(x, floor);
			}
		});
	}
989351
public static double ChiSquare(double[] histogram1, double[] histogram2) {
        double r = 0;
        for (int i = 0; i < histogram1.length; i++) {
            double t = histogram1[i] + histogram2[i];
            if (t != 0)
                r += Math.pow(histogram1[i] - histogram2[i], 2) / t;
        }

        return 0.5 * r;
    }
930634
public void removeHistogram(String histogramID) throws ShanksException {
        Scenario2DPortrayal scenarioPortrayal = (Scenario2DPortrayal) this
                .getSimulation().getScenarioPortrayal();
        scenarioPortrayal.removeHistogram(histogramID);
    }
1078207
@Override
	public double getQuantile(double quantile, RandomVariable probabilities) {
		return ((RandomVariableDifferentiableAADPathwise) getValues()).getValues().getQuantile(quantile, probabilities);
	}
724656
protected void computeHistogramBorder(T image, RectangleRotate_F32 region) {
		for( int i = 0; i < samplePts.size(); i++ ) {
			Point2D_F32 p = samplePts.get(i);

			squareToImageSample(p.x, p.y, region);

			// make sure its inside the image
			if( !BoofMiscOps.checkInside(image, imageX, imageY)) {
				sampleHistIndex[ i ] = -1;
			} else {
				// use the slower interpolation which can handle the border
				interpolate.get(imageX, imageY, value);

				int indexHistogram = computeHistogramBin(value);

				sampleHistIndex[ i ] = indexHistogram;
				histogram[indexHistogram] += weights[i];
			}
		}
	}
1338314
public static double getRandomDouble(double min, double max) {
		Random r = new Random();
		return min + (max - min) * r.nextDouble();
	}
676371
public static Map<String, Double> histogramsPlus(List<Map<String, Double>> histograms) {
        return histogramsPlus(histograms.toArray(new HashMap[histograms.size()]));
    }
203830
MetricFamilySamples fromHistogram(String dropwizardName, Histogram histogram) {
        return fromSnapshotAndCount(dropwizardName, histogram.getSnapshot(), histogram.getCount(), 1.0,
                getHelpMessage(dropwizardName, histogram));
    }
98566
@Override
	public double getQuantile(double quantile, RandomVariable probabilities) {
		return ((RandomVariableDifferentiableAADStochasticNonOptimized) getValues()).getValues().getQuantile(quantile, probabilities);
	}
505344
public Histogram toHistogram(int size)
  {
    Preconditions.checkArgument(size > 1, "histogram size must be greater than 1");

    float[] breaks = new float[size + 1];
    float delta = (max - min) / (size - 1);
    breaks[0] = min - delta;
    for (int i = 1; i < breaks.length - 1; ++i) {
      breaks[i] = breaks[i - 1] + delta;
    }
    breaks[breaks.length - 1] = max;
    return toHistogram(breaks);
  }
1259620
function getHistogram(domain, mappedValue) {
  const histogram = histogramConstruct(domain, mappedValue, histogramBins);
  const enlargedHistogram = histogramConstruct(
    domain,
    mappedValue,
    enlargedHistogramBins
  );

  return {histogram, enlargedHistogram};
}
490589
public Histogram histogram(String id, int[] data, double[] breaks, Color color) {
        if (base.dimension != 2) {
            throw new IllegalArgumentException("Histogram can be only painted in a 2D canvas.");
        }

        Histogram histogram = new Histogram(data, breaks);
        histogram.setID(id);
        histogram.setColor(color);

        double[] lowerBound = {Math.min(data) - 0.5, 0};
        double[] upperBound = {Math.max(data) + 0.5, 0};
        double[][] freq = histogram.getHistogram();
        for (int i = 0; i < freq.length; i++) {
            if (freq[i][1] > upperBound[1]) {
                upperBound[1] = freq[i][1];
            }
        }

        extendBound(lowerBound, upperBound);
        add(histogram);

        return histogram;
    }
1019581
public void add(final DoubleHistogram fromHistogram) throws ArrayIndexOutOfBoundsException {
        int arrayLength = fromHistogram.integerValuesHistogram.countsArrayLength;
        AbstractHistogram fromIntegerHistogram = fromHistogram.integerValuesHistogram;
        for (int i = 0; i < arrayLength; i++) {
            long count = fromIntegerHistogram.getCountAtIndex(i);
            if (count > 0) {
                recordValueWithCount(
                        fromIntegerHistogram.valueFromIndex(i) *
                                fromHistogram.integerToDoubleValueConversionRatio,
                        count);
            }
        }
    }
386014
private Histogram getHistogram(String entity, String watermarkColumn, SourceState state,
      Partition partition) {
    SalesforceConnector connector = getConnector(state);

    try {
      if (!connector.connect()) {
        throw new RuntimeException("Failed to connect.");
      }
    } catch (RestApiConnectionException e) {
      throw new RuntimeException("Failed to connect.", e);
    }

    Histogram histogram = getHistogramByDayBucketing(connector, entity, watermarkColumn, partition);

    // exchange the first histogram group key with the global low watermark to ensure that the low watermark is captured
    // in the range of generated partitions
    HistogramGroup firstGroup = histogram.get(0);
    Date lwmDate = Utils.toDate(partition.getLowWatermark(), Partitioner.WATERMARKTIMEFORMAT);
    histogram.getGroups().set(0, new HistogramGroup(Utils.epochToDate(lwmDate.getTime(), SECONDS_FORMAT),
        firstGroup.getCount()));

    // refine the histogram
    if (state.getPropAsBoolean(ENABLE_DYNAMIC_PROBING)) {
      histogram = getRefinedHistogram(connector, entity, watermarkColumn, state, partition, histogram);
    }

    return histogram;
  }
432385
@Override
	public double getStandardDeviation(RandomVariable probabilities) {
		if(isDeterministic()) {
			return 0.0;
		}
		if(size() == 0) {
			return Double.NaN;
		}

		return Math.sqrt(getVariance(probabilities));
	}