Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
soap-plus-plus
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
nomad-lab
soap-plus-plus
Commits
5ec40e2e
Commit
5ec40e2e
authored
8 years ago
by
Carl Poelking
Browse files
Options
Downloads
Patches
Plain Diff
Added atomic rematch kernel.
parent
bad7b67f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/soap/linalg/kernel.hpp
+86
-0
86 additions, 0 deletions
src/soap/linalg/kernel.hpp
with
86 additions
and
0 deletions
src/soap/linalg/kernel.hpp
0 → 100644
+
86
−
0
View file @
5ec40e2e
#ifndef _SOAP_LINALG_KERNEL_H
#define _SOAP_LINALG_KERNEL_H
#include
<iostream>
#include
<cmath>
#include
<stdexcept>
#include
<string>
#include
<boost/numeric/ublas/lu.hpp>
#include
<boost/python.hpp>
#include
<boost/python/numeric.hpp>
#include
"soap/linalg/numpy.hpp"
namespace
soap
{
namespace
linalg
{
namespace
ub
=
boost
::
numeric
::
ublas
;
boost
::
python
::
object
kernel_rematch_atomic
(
boost
::
python
::
object
&
kmat_npy
,
double
gamma
,
double
eps
)
{
// CONVERT NUMPY KERNEL MATRIX TO UBLAS
soap
::
linalg
::
numpy_converter
npc
(
"float64"
);
ub
::
matrix
<
double
>
kmat
;
npc
.
numpy_to_ublas
<
double
>
(
kmat_npy
,
kmat
);
// INITIALIZE OPTIMIZATION
int
nx
=
kmat
.
size1
();
int
ny
=
kmat
.
size2
();
std
::
vector
<
double
>
u
(
nx
),
ou
(
nx
),
v
(
ny
);
double
ax
=
1.0
/
nx
,
ay
=
1.0
/
ny
;
ub
::
matrix
<
double
>
Kg
(
nx
,
ny
);
for
(
int
i
=
0
;
i
<
nx
;
++
i
)
u
[
i
]
=
1.0
;
for
(
int
i
=
0
;
i
<
ny
;
++
i
)
v
[
i
]
=
1.0
;
double
lambda
=
1.0
/
gamma
,
terr
=
eps
*
eps
,
derr
;
for
(
int
i
=
0
;
i
<
nx
;
++
i
)
for
(
int
j
=
0
;
j
<
ny
;
++
j
)
Kg
(
i
,
j
)
=
std
::
exp
(
-
(
1
-
kmat
(
i
,
j
))
*
lambda
);
// OPTIMIZE
do
{
// u<-1.0/Kg.v
for
(
int
i
=
0
;
i
<
nx
;
++
i
)
{
ou
[
i
]
=
u
[
i
];
u
[
i
]
=
0.0
;
}
for
(
int
i
=
0
;
i
<
nx
;
++
i
)
for
(
int
j
=
0
;
j
<
ny
;
++
j
)
u
[
i
]
+=
Kg
(
i
,
j
)
*
v
[
j
];
// at this point we can compute how far off unity we are
derr
=
0.0
;
for
(
int
i
=
0
;
i
<
nx
;
++
i
)
derr
+=
(
ax
-
ou
[
i
]
*
u
[
i
])
*
(
ax
-
ou
[
i
]
*
u
[
i
]);
for
(
int
i
=
0
;
i
<
nx
;
++
i
)
u
[
i
]
=
ax
/
u
[
i
];
// v<-1.0/Kg.u
for
(
int
i
=
0
;
i
<
ny
;
++
i
)
v
[
i
]
=
0.0
;
for
(
int
i
=
0
;
i
<
ny
;
++
i
)
for
(
int
j
=
0
;
j
<
nx
;
++
j
)
v
[
i
]
+=
Kg
(
j
,
i
)
*
u
[
j
];
for
(
int
i
=
0
;
i
<
ny
;
++
i
)
v
[
i
]
=
ay
/
v
[
i
];
//std::cerr<<derr<<"\n";
}
while
(
derr
>
terr
);
/*
// COMPUTE KERNEL VALUE
double rval=0, rrow;
for (int i=0; i<nx; ++i)
{
std::cout << "Row " << i << std::endl;
rrow=0;
for (int j=0; j<ny; ++j) {
rrow+=Kg(i,j)*kmat(i,j)*v[j];
std::cout << Kg(i,j) << " " << kmat(i,j) << " " << v[j] << " u*K*v " << u[i]*Kg(i,j)*v[j] << std::endl;
}
rval+=u[i]*rrow;
}
*/
// RETURN REGULARIZED PERMUTATION MATRIX
ub
::
matrix
<
double
>
Pij
(
nx
,
ny
);
for
(
int
i
=
0
;
i
<
nx
;
++
i
)
{
for
(
int
j
=
0
;
j
<
ny
;
++
j
)
{
Pij
(
i
,
j
)
=
u
[
i
]
*
Kg
(
i
,
j
)
*
v
[
j
];
}
}
return
npc
.
ublas_to_numpy
<
double
>
(
Pij
);
};
class
KernelModule
{
public:
KernelModule
();
static
void
registerPython
()
{
using
namespace
boost
::
python
;
def
(
"kernel_rematch_atomic"
,
kernel_rematch_atomic
);
}
private
:
};
}}
#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