Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tnl-dev
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor 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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
TNL
tnl-dev
Commits
cfc7a125
There was an error fetching the commit references. Please try again later.
Commit
cfc7a125
authored
2 years ago
by
Tomáš Oberhuber
Browse files
Options
Downloads
Patches
Plain Diff
Renaming aux to gradient in the gradient descent method.
parent
ea91987f
No related branches found
No related tags found
1 merge request
!134
To/optimization
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/TNL/Solvers/Optimization/GradientDescent.h
+5
-9
5 additions, 9 deletions
src/TNL/Solvers/Optimization/GradientDescent.h
src/TNL/Solvers/Optimization/GradientDescent.hpp
+13
-17
13 additions, 17 deletions
src/TNL/Solvers/Optimization/GradientDescent.hpp
with
18 additions
and
26 deletions
src/TNL/Solvers/Optimization/GradientDescent.h
+
5
−
9
View file @
cfc7a125
/***************************************************************************
Timer.h - description
-------------------
begin : Mar 14, 2016
copyright : (C) 2016 by Tomas Oberhuber
email : tomas.oberhuber@fjfi.cvut.cz
***************************************************************************/
/* See Copyright Notice in tnl/Copyright */
// Copyright (c) 2004-2022 Tomáš Oberhuber et al.
//
// This file is part of TNL - Template Numerical Library (https://tnl-project.org/)
//
// SPDX-License-Identifier: MIT
#pragma once
...
...
This diff is collapsed.
Click to expand it.
src/TNL/Solvers/Optimization/GradientDescent.hpp
+
13
−
17
View file @
cfc7a125
/***************************************************************************
Timer.h - description
-------------------
begin : Mar 14, 2016
copyright : (C) 2016 by Tomas Oberhuber
email : tomas.oberhuber@fjfi.cvut.cz
***************************************************************************/
/* See Copyright Notice in tnl/Copyright */
// Copyright (c) 2004-2022 Tomáš Oberhuber et al.
//
// This file is part of TNL - Template Numerical Library (https://tnl-project.org/)
//
// SPDX-License-Identifier: MIT
#pragma once
...
...
@@ -23,7 +19,7 @@ GradientDescent< Vector, SolverMonitor >::
configSetup
(
Config
::
ConfigDescription
&
config
,
const
String
&
prefix
)
{
IterativeSolver
<
RealType
,
IndexType
,
SolverMonitor
>::
configSetup
(
config
,
prefix
);
config
.
addEntry
<
double
>
(
prefix
+
"
gd-
relaxation"
,
"Relaxation parameter for the gradient descent."
,
1.0
);
config
.
addEntry
<
double
>
(
prefix
+
"relaxation"
,
"Relaxation parameter for the gradient descent."
,
1.0
);
}
template
<
typename
Vector
,
typename
SolverMonitor
>
...
...
@@ -31,7 +27,7 @@ bool
GradientDescent
<
Vector
,
SolverMonitor
>::
setup
(
const
Config
::
ParameterContainer
&
parameters
,
const
String
&
prefix
)
{
this
->
setRelaxation
(
parameters
.
getParameter
<
double
>
(
prefix
+
"
gd-
relaxation"
)
);
this
->
setRelaxation
(
parameters
.
getParameter
<
double
>
(
prefix
+
"relaxation"
)
);
return
IterativeSolver
<
RealType
,
IndexType
,
SolverMonitor
>::
setup
(
parameters
,
prefix
);
}
...
...
@@ -57,10 +53,10 @@ bool
GradientDescent
<
Vector
,
SolverMonitor
>::
solve
(
VectorView
&
w
,
GradientGetter
&&
getGradient
)
{
this
->
aux
.
setLike
(
w
);
auto
aux_view
=
aux
.
getView
();
this
->
gradient
.
setLike
(
w
);
auto
gradient_view
=
gradient
.
getView
();
auto
w_view
=
w
.
getView
();
aux
=
0.0
;
this
->
gradient
=
0.0
;
/////
// Set necessary parameters
...
...
@@ -73,16 +69,16 @@ solve( VectorView& w, GradientGetter&& getGradient )
{
/////
// Compute the gradient
getGradient
(
w_view
,
aux
_view
);
getGradient
(
w_view
,
gradient
_view
);
RealType
lastResidue
=
this
->
getResidue
();
this
->
setResidue
(
addAndReduceAbs
(
w_view
,
this
->
relaxation
*
aux
_view
,
TNL
::
Plus
(),
(
RealType
)
0.0
)
/
(
this
->
relaxation
*
(
RealType
)
w
.
getSize
()
)
);
this
->
setResidue
(
addAndReduceAbs
(
w_view
,
-
this
->
relaxation
*
gradient
_view
,
TNL
::
Plus
(),
(
RealType
)
0.0
)
/
(
this
->
relaxation
*
(
RealType
)
w
.
getSize
()
)
);
if
(
!
this
->
nextIteration
()
)
return
this
->
checkConvergence
();
/////
// Check the stop condition
if
(
this
->
getConvergenceResidue
()
!=
0.0
&&
this
->
getResidue
()
<
this
->
getConvergenceResidue
()
)
if
(
this
->
getConvergenceResidue
()
!=
0.0
&&
this
->
getResidue
()
<
this
->
getConvergenceResidue
()
)
return
true
;
}
return
false
;
// just to avoid warnings
...
...
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