Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
HDL
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RTSD
HDL
Commits
5c73e20c
Commit
5c73e20c
authored
2 years ago
by
Eric Kooistra
Browse files
Options
Downloads
Patches
Plain Diff
Added conclusion for sufficient -r.
parent
a77c7b14
No related branches found
No related tags found
1 merge request
!305
Resolve L2SDP-846
Pipeline
#42188
passed
2 years ago
Stage: simulation
Stage: synthesis
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
libraries/base/common/python/try_round_weight.py
+47
-16
47 additions, 16 deletions
libraries/base/common/python/try_round_weight.py
with
47 additions
and
16 deletions
libraries/base/common/python/try_round_weight.py
+
47
−
16
View file @
5c73e20c
...
...
@@ -28,16 +28,27 @@
# . quantized subbands --> sigma_qq
# . unquantized subbands --> sigma_sq
# Preliminary conclusion:
# .
f
or small input noise with sigma < 2 the output sigma gets disturbed
# .
F
or small input noise with sigma < 2 the output sigma gets disturbed
# due to the weighting if the weighting is applied after the subband
# quantisation
# .
i
ncreasing -N improves the results, for LOFAR subbands N = 195312
# .
I
ncreasing -N improves the results, for LOFAR subbands N = 195312
# . it may be preferred to apply the subband weights to the unquantized
# WPFB output.
# . Choosing sufficient intermediate resolution (-r) before applying
# weights:
# - Rounding noise changes the sigma of the noise anyway, as shown by
# sigmas_ratio_sq_input_T. Therefore choose resolution such that
# jumps in sigma due to rounding weighted noise, as shown by
# sigmas_ratio_qq_sq_T, is much smaller than sigmas_ratio_sq_input_T
# ==> -r 2.
# - For input sigma >= 1
# . Choose sigmas_ratio_qq_sq_T < 10% ==> -r 3
# . Choose sigmas_ratio_qq_sq_T < 1% ==> -r 6
# . Choose sigmas_ratio_qq_sq_T < 0.1% ==> -r 9
# Note:
# . For values exactly halfway between rounded decimal values, NumPy
rounds t
o
# the nearest even value. Thus 1.5 and 2.5 round to 2.0,
-0.5 and 0.5 round
#
to 0.0, etc
.
# . For values exactly halfway between rounded decimal values, NumPy o
f
#
Python3 rounds to
the nearest even value. Thus 1.5 and 2.5 round to 2.0,
#
-0.5 and 0.5 round to 0.0, etc. (Python2 rounds half away from zero)
.
# Usage:
# > python3 try_round_weight.py -N 195312
...
...
@@ -74,6 +85,7 @@ _parser = argparse.ArgumentParser(
# Use -r = 6 to see effect of having more resolution before rounding
> python try_round_weight.py --w_lo 0.7 --w_hi 0.8 --w_step 0.0001 --s_lo 1 --s_hi 10 --s_step 1 -N 195312 -S 0 -r 6
> python try_round_weight.py --w_lo 0.3 --w_hi 1.1 --w_step 0.001 --s_lo 1 --s_hi 10 --s_step 1 -N 195312 -S 0 -r 6
\n
"""
)),
formatter_class
=
argparse
.
RawTextHelpFormatter
)
_parser
.
add_argument
(
'
-S
'
,
default
=
0
,
type
=
int
,
help
=
'
Random number seed
'
)
...
...
@@ -118,7 +130,8 @@ resolution = args.r
resolution_factor
=
2
**
resolution
# Determine weighted rounded noise sigma / weighted noise sigma for range of weights and input noise sigmas
sigmas_ratio
=
np
.
nan
*
np
.
zeros
((
N_weights
,
N_sigmas
))
# w rows, s cols
sigmas_ratio_qq_sq
=
np
.
nan
*
np
.
zeros
((
N_weights
,
N_sigmas
))
# w rows, s cols
sigmas_ratio_sq_input
=
np
.
nan
*
np
.
zeros
((
N_weights
,
N_sigmas
))
# w rows, s cols
sigmas_qq
=
np
.
zeros
((
N_weights
,
N_sigmas
))
sigmas_sq
=
np
.
zeros
((
N_weights
,
N_sigmas
))
for
s
,
sigma
in
enumerate
(
sigmas
):
...
...
@@ -143,21 +156,25 @@ for s, sigma in enumerate(sigmas):
sigmas_qq
[
w
][
s
]
=
s_qq
sigmas_sq
[
w
][
s
]
=
s_sq
if
s_sq
!=
0
:
sigmas_ratio
[
w
][
s
]
=
s_qq
/
s_sq
# weighted rounded noise sigma / weighted noise sigma
sigmas_ratio_qq_sq
[
w
][
s
]
=
s_qq
/
s_sq
# weighted rounded noise sigma / weighted noise sigma
sigmas_ratio_sq_input
[
w
][
s
]
=
s_sq
/
sigma
# weighted noise sigma / input noise sigma
# Transpose [w][s] to have index ranges [s][w]
sigmas_ratio_T
=
sigmas_ratio
.
transpose
()
sigmas_ratio_qq_sq_T
=
sigmas_ratio_qq_sq
.
transpose
()
sigmas_ratio_sq_input_T
=
sigmas_ratio_sq_input
.
transpose
()
sigmas_qq_T
=
sigmas_qq
.
transpose
()
sigmas_sq_T
=
sigmas_sq
.
transpose
()
# Plot results
figNr
=
0
s_colors
=
plt
.
cm
.
jet
(
np
.
linspace
(
0
,
1
,
N_sigmas
))
w_colors
=
plt
.
cm
.
jet
(
np
.
linspace
(
0
,
1
,
N_weights
))
figNr
+=
1
plt
.
figure
(
figNr
)
for
s
,
sigma
in
enumerate
(
sigmas
):
# Plot sigma_qq of twice quantized noise as function of weight for
# different input sigmas
plt
.
plot
(
weights
,
sigmas_qq_T
[
s
],
label
=
'
s = %4.2f
'
%
sigma
)
plt
.
plot
(
weights
,
sigmas_qq_T
[
s
],
color
=
s_colors
[
s
],
label
=
'
s = %4.2f
'
%
sigma
)
plt
.
title
(
"
Sigma of weighted quantized noise
"
)
plt
.
xlabel
(
"
Weight
"
)
plt
.
ylabel
(
"
Sigma_qq
"
)
...
...
@@ -171,14 +188,28 @@ for s, sigma in enumerate(sigmas):
# different input sigmas.
# Normalize the sigma_qq by the weight, so that it can be compared with
# the input sigma that is shown by the horizontal sigma reference lines.
plt
.
plot
(
weights
,
sigmas_qq_T
[
s
]
/
weights
,
label
=
'
s = %4.2f
'
%
sigma
)
plt
.
plot
(
weights
,
sigmas
[
s
]
*
np
.
ones
(
N_weights
))
# add sigma reference lines
plt
.
plot
(
weights
,
sigmas_qq_T
[
s
]
/
weights
,
color
=
s_colors
[
s
],
label
=
'
s = %4.2f
'
%
sigma
)
plt
.
plot
(
weights
,
sigmas
[
s
]
*
np
.
ones
(
N_weights
)
,
'
--
'
,
color
=
s_colors
[
s
]
)
# add sigma reference lines
plt
.
title
(
"
Sigma of weighted quantized noise, normalized for weight
"
)
plt
.
xlabel
(
"
Weight
"
)
plt
.
ylabel
(
"
Sigma_qq
"
)
plt
.
legend
(
loc
=
'
upper right
'
)
plt
.
grid
()
figNr
+=
1
plt
.
figure
(
figNr
)
for
s
,
sigma
in
enumerate
(
sigmas
):
# Plot ratio of sigma_sq / sigma as function of weight for different
# input sigma. The ratio deviation from 1 tells how much quantized
# weighted noise deviates from the input noise. This shows that rounding
# noise cause a change in sigma even when weight is 1.
plt
.
plot
(
weights
,
sigmas_ratio_sq_input_T
[
s
]
/
weights
,
color
=
s_colors
[
s
],
label
=
'
s = %4.2f
'
%
sigma
)
plt
.
title
(
"
Relative sigma difference of weighted quantized data / input data
"
)
plt
.
xlabel
(
"
Weight
"
)
plt
.
ylabel
(
"
Relative sigma difference
"
)
plt
.
legend
(
loc
=
'
upper right
'
)
plt
.
grid
()
figNr
+=
1
plt
.
figure
(
figNr
)
for
s
,
sigma
in
enumerate
(
sigmas
):
...
...
@@ -186,8 +217,8 @@ for s, sigma in enumerate(sigmas):
# input sigma. The ratio deviation from 1 tells how much the twice
# quantized noise deviates from the noise that is only quantized after
# the weighting.
plt
.
plot
(
weights
,
sigmas_ratio_
T
[
s
],
label
=
'
s = %4.2f
'
%
sigma
)
plt
.
title
(
"
Relative sigma difference of weighting
after / before
quantisation
"
)
plt
.
plot
(
weights
,
sigmas_ratio_
qq_sq_T
[
s
],
color
=
s_colors
[
s
],
label
=
'
s = %4.2f
'
%
sigma
)
plt
.
title
(
"
Relative sigma difference of weighting
before / after
quantisation
"
)
plt
.
xlabel
(
"
Weight
"
)
plt
.
ylabel
(
"
Relative sigma difference
"
)
plt
.
legend
(
loc
=
'
upper right
'
)
...
...
@@ -198,8 +229,8 @@ plt.figure(figNr)
for
w
,
weight
in
enumerate
(
weights
):
# Plot ratio of sigma_qq / sigma_sq as function of input sigma for
# different weights
plt
.
plot
(
sigmas
,
sigmas_ratio
[
w
],
label
=
'
w = %4.2f
'
%
weight
)
plt
.
title
(
"
Relative sigma difference of weighting
after / before
quantisation
"
)
plt
.
plot
(
sigmas
,
sigmas_ratio
_qq_sq
[
w
],
color
=
w_colors
[
w
],
label
=
'
w = %4.2f
'
%
weight
)
plt
.
title
(
"
Relative sigma difference of weighting
before / after
quantisation
"
)
plt
.
xlabel
(
"
Sigma
"
)
plt
.
ylabel
(
"
Relative sigma difference (s_qq / s_sq)
"
)
plt
.
legend
(
loc
=
'
upper right
'
)
...
...
@@ -207,7 +238,7 @@ plt.grid()
figNr
+=
1
plt
.
figure
(
figNr
)
plt
.
imshow
(
sigmas_ratio
,
origin
=
'
lower
'
,
interpolation
=
'
none
'
,
aspect
=
'
auto
'
,
extent
=
[
sigma_lo
,
sigma_hi
,
weight_lo
,
weight_hi
])
plt
.
imshow
(
sigmas_ratio
_qq_sq
,
origin
=
'
lower
'
,
interpolation
=
'
none
'
,
aspect
=
'
auto
'
,
extent
=
[
sigma_lo
,
sigma_hi
,
weight_lo
,
weight_hi
])
plt
.
colorbar
()
plt
.
title
(
"
Relative sigma difference of weighting after / before quantisation
"
)
plt
.
xlabel
(
"
Sigma
"
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment