Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #464 from Koed00/django_3_1
Updates to Django 3.1
- Loading branch information
Showing
8 changed files
with
116 additions
and
87 deletions.
There are no files selected for viewing
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import numpy | ||
|
||
from django_q.tasks import async_iter, result | ||
|
||
|
||
# the estimation function | ||
def parzen_estimation(x_samples, point_x, h): | ||
k_n = 0 | ||
for row in x_samples: | ||
x_i = (point_x - row[:, numpy.newaxis]) / h | ||
for row in x_i: | ||
if numpy.abs(row) > (1 / 2): | ||
break | ||
else: | ||
k_n += 1 | ||
return h, (k_n / len(x_samples)) / (h ** point_x.shape[1]) | ||
|
||
|
||
def parzen_async(): | ||
mu_vec = numpy.array([0, 0]) | ||
cov_mat = numpy.array([[1, 0], [0, 1]]) | ||
sample = numpy.random.multivariate_normal(mu_vec, cov_mat, 10000) | ||
widths = numpy.linspace(1.0, 1.2, 100) | ||
x = numpy.array([[0], [0]]) | ||
# async_task them with async_task iterable | ||
args = [(sample, x, w) for w in widths] | ||
result_id = async_iter(parzen_estimation, args, cached=True) | ||
# return the cached result or timeout after 10 seconds | ||
return result(result_id, wait=10000, cached=True) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 characters