Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MODELS
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
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
Tadah
MODELS
Commits
bb249ee9
Commit
bb249ee9
authored
1 year ago
by
mkirsz
Browse files
Options
Downloads
Patches
Plain Diff
Refactoring
parent
52095af5
No related branches found
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
m_blr_core.h
+10
-39
10 additions, 39 deletions
m_blr_core.h
m_blr_train.h
+42
-0
42 additions, 0 deletions
m_blr_train.h
m_core.h
+1
-1
1 addition, 1 deletion
m_core.h
m_krr_core.h
+8
-50
8 additions, 50 deletions
m_krr_core.h
m_krr_train.h
+55
-0
55 additions, 0 deletions
m_krr_train.h
with
116 additions
and
90 deletions
m_blr_core.h
+
10
−
39
View file @
bb249ee9
#ifndef M_BLR_Core_H
#define M_BLR_Core_H
#include
"linear_regressor.h"
#include
"../CORE/config/config.h"
#include
"m_core.h"
#include
"functions/function_base.h"
#include
"functions/basis_functions/bf_base.h"
#include
"
m_core
.h"
#include
"
../CORE/config/config
.h"
#include
<iostream>
...
...
@@ -42,7 +41,14 @@ class M_BLR_Core:
}
double
predict
(
const
rvec
&
v
)
const
{
return
bf
.
epredict
(
get_weights
(),
v
);
};
}
t_type
get_weights_uncertainty
()
const
{
double
lambda
=
config
.
template
get
<
double
>(
"LAMBDA"
);
if
(
lambda
>=
0
)
throw
std
::
runtime_error
(
"Sigma matrix is only computed for LAMBDA < 0"
);
return
Sigma
.
diagonal
();
}
private
:
...
...
@@ -56,39 +62,4 @@ class M_BLR_Core:
verbose
=
(
config
.
get
<
int
>
(
"VERBOSE"
));
}
};
template
<
class
BF
=
Function_Base
&
>
class
M_BLR_Train
:
public
M_BLR_Core
<
BF
>
,
// MUST NOT BE VIRUAL!!
public
M_Train
{
public:
using
M_BLR_Core
<
BF
>::
trained
;
using
M_BLR_Core
<
BF
>::
config
;
using
M_BLR_Core
<
BF
>::
weights
;
using
M_BLR_Core
<
BF
>::
Sigma
;
M_BLR_Train
(
Config
&
c
)
:
M_BLR_Core
<
BF
>
(
c
)
{}
M_BLR_Train
(
BF
&
bf
,
Config
&
c
)
:
M_BLR_Core
<
BF
>
(
bf
,
c
)
{}
void
train
(
phi_type
&
Phi
,
const
t_type
&
T
)
{
if
(
trained
)
{
throw
std
::
runtime_error
(
"This object is already trained!"
);
}
LinearRegressor
::
train
(
config
,
Phi
,
T
,
weights
,
Sigma
);
trained
=
true
;
}
t_type
get_weights_uncertainty
()
const
{
double
lambda
=
config
.
template
get
<
double
>(
"LAMBDA"
);
if
(
lambda
>=
0
)
throw
std
::
runtime_error
(
"Sigma matrix is only computed for LAMBDA < 0"
);
return
Sigma
.
diagonal
();
}
};
#endif
This diff is collapsed.
Click to expand it.
m_blr_train.h
0 → 100644
+
42
−
0
View file @
bb249ee9
#ifndef M_BLR_TRAIN_H
#define M_BLR_TRAIN_H
#include
"m_core.h"
#include
"m_blr_core.h"
#include
"linear_regressor.h"
#include
"functions/function_base.h"
#include
"functions/basis_functions/bf_base.h"
#include
"../CORE/config/config.h"
#include
<iostream>
template
<
class
BF
=
Function_Base
&
>
class
M_BLR_Train
:
public
M_BLR_Core
<
BF
>
,
// MUST NOT BE VIRUAL!!
public
M_Train
{
public:
using
M_BLR_Core
<
BF
>::
trained
;
using
M_BLR_Core
<
BF
>::
config
;
using
M_BLR_Core
<
BF
>::
weights
;
using
M_BLR_Core
<
BF
>::
Sigma
;
M_BLR_Train
(
Config
&
c
)
:
M_BLR_Core
<
BF
>
(
c
)
{}
M_BLR_Train
(
BF
&
bf
,
Config
&
c
)
:
M_BLR_Core
<
BF
>
(
bf
,
c
)
{}
void
train
(
phi_type
&
Phi
,
const
t_type
&
T
)
{
if
(
trained
)
{
throw
std
::
runtime_error
(
"This object is already trained!"
);
}
LinearRegressor
::
train
(
config
,
Phi
,
T
,
weights
,
Sigma
);
trained
=
true
;
}
};
#endif
This diff is collapsed.
Click to expand it.
m_core.h
+
1
−
1
View file @
bb249ee9
...
...
@@ -22,6 +22,7 @@ class M_Core {
weights
=
w
;
}
virtual
double
predict
(
const
rvec
&
v
)
const
=
0
;
virtual
t_type
get_weights_uncertainty
()
const
=
0
;
};
class
M_Predict
{
public:
...
...
@@ -50,6 +51,5 @@ class M_Train {
public:
virtual
~
M_Train
()
{}
virtual
void
train
(
phi_type
&
Phi
,
const
t_type
&
T
)
=
0
;
virtual
t_type
get_weights_uncertainty
()
const
=
0
;
};
#endif
This diff is collapsed.
Click to expand it.
m_krr_core.h
+
8
−
50
View file @
bb249ee9
#ifndef M_KRR_Core_H
#define M_KRR_Core_H
#include
"linear_regressor.h"
#include
"../CORE/config/config.h"
#include
"functions/function_base.h"
#include
"functions/kernels/kern_base.h"
#include
"m_core.h"
#include
"ekm.h"
#include
<iostream>
...
...
@@ -43,7 +41,14 @@ class M_KRR_Core:
}
double
predict
(
const
rvec
&
v
)
const
{
return
kernel
.
epredict
(
weights
,
v
);
};
}
t_type
get_weights_uncertainty
()
const
{
double
lambda
=
config
.
template
get
<
double
>(
"LAMBDA"
);
if
(
lambda
>=
0
)
throw
std
::
runtime_error
(
"Sigma matrix is only computed for LAMBDA < 0"
);
return
Sigma
.
diagonal
();
}
private
:
...
...
@@ -57,53 +62,6 @@ class M_KRR_Core:
verbose
=
(
config
.
get
<
int
>
(
"VERBOSE"
));
}
};
template
<
class
K
=
Function_Base
&
>
class
M_KRR_Train
:
public
M_KRR_Core
<
K
>
,
// MUST NOT BE VIRUAL!!
public
M_Train
{
public:
EKM
<
K
>
ekm
;
using
M_KRR_Core
<
K
>::
trained
;
using
M_KRR_Core
<
K
>::
config
;
using
M_KRR_Core
<
K
>::
kernel
;
using
M_KRR_Core
<
K
>::
weights
;
using
M_KRR_Core
<
K
>::
Sigma
;
M_KRR_Train
(
Config
&
c
)
:
M_KRR_Core
<
K
>
(
c
),
ekm
(
c
)
{}
M_KRR_Train
(
K
&
kernel
,
Config
&
c
)
:
M_KRR_Core
<
K
>
(
kernel
,
c
),
ekm
(
kernel
)
{}
void
train
(
phi_type
&
Phi
,
const
t_type
&
T
)
{
if
(
trained
)
{
throw
std
::
runtime_error
(
"This object is already trained!"
);
}
if
(
kernel
.
get_label
()
!=
"Kern_Linear"
)
{
ekm
.
project
(
Phi
);
}
LinearRegressor
::
train
(
config
,
Phi
,
T
,
weights
,
Sigma
);
if
(
kernel
.
get_label
()
!=
"Kern_Linear"
)
{
//kernalize weights
weights
=
ekm
.
KK
.
transpose
()
*
weights
;
}
trained
=
true
;
}
t_type
get_weights_uncertainty
()
const
{
double
lambda
=
config
.
template
get
<
double
>(
"LAMBDA"
);
if
(
lambda
>=
0
)
throw
std
::
runtime_error
(
"Sigma matrix is only computed for LAMBDA < 0"
);
return
Sigma
.
diagonal
();
}
};
//template
//<class K=Function_Base&>
...
...
This diff is collapsed.
Click to expand it.
m_krr_train.h
0 → 100644
+
55
−
0
View file @
bb249ee9
#ifndef M_KRR_TRAIN_H
#define M_KRR_TRAIN_H
#include
"linear_regressor.h"
#include
"../CORE/config/config.h"
#include
"functions/function_base.h"
#include
"functions/kernels/kern_base.h"
#include
"m_core.h"
#include
"m_krr_core.h"
#include
"ekm.h"
#include
<iostream>
template
<
class
K
=
Function_Base
&
>
class
M_KRR_Train
:
public
M_KRR_Core
<
K
>
,
// MUST NOT BE VIRUAL!!
public
M_Train
{
public:
EKM
<
K
>
ekm
;
using
M_KRR_Core
<
K
>::
trained
;
using
M_KRR_Core
<
K
>::
config
;
using
M_KRR_Core
<
K
>::
kernel
;
using
M_KRR_Core
<
K
>::
weights
;
using
M_KRR_Core
<
K
>::
Sigma
;
M_KRR_Train
(
Config
&
c
)
:
M_KRR_Core
<
K
>
(
c
),
ekm
(
c
)
{}
M_KRR_Train
(
K
&
kernel
,
Config
&
c
)
:
M_KRR_Core
<
K
>
(
kernel
,
c
),
ekm
(
kernel
)
{}
void
train
(
phi_type
&
Phi
,
const
t_type
&
T
)
{
if
(
trained
)
{
throw
std
::
runtime_error
(
"This object is already trained!"
);
}
if
(
kernel
.
get_label
()
!=
"Kern_Linear"
)
{
ekm
.
project
(
Phi
);
}
LinearRegressor
::
train
(
config
,
Phi
,
T
,
weights
,
Sigma
);
if
(
kernel
.
get_label
()
!=
"Kern_Linear"
)
{
//kernalize weights
weights
=
ekm
.
KK
.
transpose
()
*
weights
;
}
trained
=
true
;
}
};
#endif
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