-
-
Save dmadisetti/ea7b46aa0457d757a4b52057b5b9f5ea to your computer and use it in GitHub Desktop.
Revisions
-
dmadisetti revised this gist
Oct 28, 2021 . 1 changed file with 7 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,9 @@ @tf.function def histogram(x, y, value_range, nbins=100, weights=None, bin_dtype=tf.dtypes.int32): """ Bins x, y coordinates of points onto simple square 2d histogram @@ -18,7 +17,7 @@ def histogram(x, y, Args: x: Numeric `Tensor`. y: Numeric `Tensor`. value_range[0] lims for x value_range[1] lims for y @@ -39,12 +38,12 @@ def histogram(x, y, y_range = value_range[1] if weights is None: hist_bins = tf.histogram_fixed_width_bins(y, y_range, nbins=nbins, dtype=bin_dtype) return tf.map_fn(lambda i: tf.histogram_fixed_width(x[hist_bins == i], x_range, nbins=nbins), tf.range(nbins)) x_bins = tf.histogram_fixed_width_bins(x, x_range, nbins=nbins, dtype=bin_dtype) y_bins = tf.histogram_fixed_width_bins(y, y_range, nbins=nbins, dtype=bin_dtype) hist = tf.zeros((nbins, nbins), dtype=weights.dtype) indices = tf.transpose(tf.stack([y_bins, x_bins])) return tf.tensor_scatter_nd_add(hist, indices, weights) -
dmadisetti revised this gist
Sep 11, 2021 . 1 changed file with 15 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,10 @@ import tensorflow as tf @tf.function def histogram(x, y, value_range, nbins=100, weights=None, dtype=tf.dtypes.int32): """ Bins x, y coordinates of points onto simple square 2d histogram @@ -23,6 +24,7 @@ def get2dHistogram(x, y, value_range[1] lims for y nbins: Scalar `int32 Tensor`. Number of histogram bins. weights: The value to scale dtype: dtype for returned histogram. Example: @@ -36,8 +38,13 @@ def get2dHistogram(x, y, x_range = value_range[0] y_range = value_range[1] if weights is None: hist_bins = tf.histogram_fixed_width_bins(y, y_range, nbins=nbins, dtype=dtype) return tf.map_fn(lambda i: tf.histogram_fixed_width(x[hist_bins == i], x_range, nbins=nbins), tf.range(nbins)) x_bins = tf.histogram_fixed_width_bins(x, x_range, nbins=nbins, dtype=tf.dtypes.int32) y_bins = tf.histogram_fixed_width_bins(y, y_range, nbins=nbins, dtype=tf.dtypes.int32) hist = tf.zeros((nbins, nbins), dtype=dtype) indices = tf.transpose(tf.stack([x_bins, y_bins])) return tf.tensor_scatter_nd_add(hist, indices, weights) -
isentropic revised this gist
May 5, 2020 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -25,6 +25,11 @@ def get2dHistogram(x, y, nbins: Scalar `int32 Tensor`. Number of histogram bins. dtype: dtype for returned histogram. Example: N = 1000 xs = tf.random.normal([N]) ys = tf.random.normal([N]) get2dHistogram(xs, ys, ([-5.0, 5.0], [-5.0, 5.0]), 50) """ -
isentropic revised this gist
Nov 14, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ def get2dHistogram(x, y, value_range, nbins=100, dtype=tf.dtypes.int32): """ Bins x, y coordinates of points onto simple square 2d histogram -
isentropic created this gist
Nov 14, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ import tensorflow as tf @tf.function def get2dHistogram(x, y, value_range, nbins=100, dtype=dtypes.int32): """ Bins x, y coordinates of points onto simple square 2d histogram Given the tensor x and y: x: x coordinates of points y: y coordinates of points this operation returns a rank 2 `Tensor` representing the indices of a histogram into which each element of `values` would be binned. The bins are equal width and determined by the arguments `value_range` and `nbins`. Args: x: Numeric `Tensor`. y: Numeric `Tensor`. value_range[0] lims for x value_range[1] lims for y nbins: Scalar `int32 Tensor`. Number of histogram bins. dtype: dtype for returned histogram. """ x_range = value_range[0] y_range = value_range[1] histy_bins = tf.histogram_fixed_width_bins(y, y_range, nbins=nbins, dtype=dtype) H = tf.map_fn(lambda i: tf.histogram_fixed_width(x[histy_bins == i], x_range, nbins=nbins), tf.range(nbins)) return H # Matrix!