Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
compressed_sensing
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Erik Strand
compressed_sensing
Commits
16f716ce
Commit
16f716ce
authored
6 years ago
by
Erik Strand
Browse files
Options
Downloads
Patches
Plain Diff
Compute loss and gradient
parent
e3f60784
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
main.cpp
+28
-5
28 additions, 5 deletions
main.cpp
with
28 additions
and
5 deletions
main.cpp
+
28
−
5
View file @
16f716ce
...
@@ -45,11 +45,18 @@ Matrix compute_dct_matrix(uint32_t n_samples) {
...
@@ -45,11 +45,18 @@ Matrix compute_dct_matrix(uint32_t n_samples) {
}
}
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
int
main
()
{
// Selects certain columns of a matrix.
//Vector x = Vector::Random(5);
Matrix
matrix_subset
(
Matrix
const
&
matrix
,
std
::
vector
<
uint32_t
>
const
&
subset_indices
)
{
//std::cout << x << '\n';
Matrix
subset
(
matrix
.
rows
(),
subset_indices
.
size
());
for
(
uint32_t
i
=
0
;
i
<
subset_indices
.
size
();
++
i
)
{
auto
const
index
=
subset_indices
[
i
];
subset
.
col
(
i
)
=
matrix
.
col
(
index
);
}
return
subset
;
}
//--------------------------------------------------------------------------------------------------
int
main
()
{
constexpr
Scalar
f1
=
697
;
constexpr
Scalar
f1
=
697
;
constexpr
Scalar
f2
=
1209
;
constexpr
Scalar
f2
=
1209
;
...
@@ -67,7 +74,7 @@ int main() {
...
@@ -67,7 +74,7 @@ int main() {
python_print
(
"dct"
,
dct
);
python_print
(
"dct"
,
dct
);
// Part (c)
// Part (c)
Vector
const
recovered_sample_values
=
dct_matrix
.
transpose
()
*
dct
;
Vector
recovered_sample_values
=
dct_matrix
.
transpose
()
*
dct
;
python_print
(
"recovered_sample_values"
,
recovered_sample_values
);
python_print
(
"recovered_sample_values"
,
recovered_sample_values
);
// Part (d)
// Part (d)
...
@@ -93,5 +100,21 @@ int main() {
...
@@ -93,5 +100,21 @@ int main() {
python_print
(
"subset_sample_times"
,
subset_sample_times
);
python_print
(
"subset_sample_times"
,
subset_sample_times
);
python_print
(
"subset_sample_values"
,
subset_sample_values
);
python_print
(
"subset_sample_values"
,
subset_sample_values
);
// Part (e)
Matrix
const
subset_dct_matrix
=
matrix_subset
(
dct_matrix
,
subset_indices
);
Vector
recovered_dct
=
Vector
::
Random
(
n_samples
);
recovered_sample_values
=
dct_matrix
.
transpose
()
*
recovered_dct
;
Vector
subset_recovered_sample_values
(
n_subsamples
);
for
(
uint32_t
i
=
0
;
i
<
n_subsamples
;
++
i
)
{
auto
const
index
=
subset_indices
[
i
];
subset_recovered_sample_values
[
i
]
=
recovered_sample_values
[
index
];
}
Vector
subset_differences
=
subset_sample_values
-
subset_recovered_sample_values
;
Scalar
loss
=
subset_differences
.
squaredNorm
();
Vector
gradient
=
-
2
*
subset_dct_matrix
*
subset_differences
;
std
::
cout
<<
loss
<<
'\n'
;
std
::
cout
<<
gradient
<<
'\n'
;
return
0
;
return
0
;
}
}
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