Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
openfpm_numerics
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
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
Sbalzarini Lab
Software
Parallel Computing
OpenFPM
openfpm_numerics
Commits
40b30a17
Commit
40b30a17
authored
2 years ago
by
Sachin Krishnan T V
Browse files
Options
Downloads
Patches
Plain Diff
Add Regression support (incomplete)
parent
e706b03e
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/regression/poly_levelset_test.cpp
+5
-4
5 additions, 4 deletions
src/regression/poly_levelset_test.cpp
src/regression/regression.hpp
+28
-16
28 additions, 16 deletions
src/regression/regression.hpp
src/regression/regression_test.cpp
+76
-39
76 additions, 39 deletions
src/regression/regression_test.cpp
with
109 additions
and
59 deletions
src/regression/poly_levelset_test.cpp
+
5
−
4
View file @
40b30a17
...
...
@@ -52,15 +52,15 @@ BOOST_AUTO_TEST_CASE ( PolyLevelset_Sphere )
}
vd
.
map
();
auto
model
=
PolyLevelset
<
3
>
(
vd
,
1e-4
);
//
auto model = PolyLevelset<3>(vd, 1e-4);
/*
double max_err = -1.0;
auto it2 = vd.getDomainIterator();
while (it2.isNext())
{
auto key = it2.get();
Point<3, double> pos = {vd.getPos(key)[0], vd.getPos(key)[1], vd.getPos(key)[2]};
vd
.
template
getProp
<
mean_curvature
>(
key
)
=
model
.
estimate_mean_curvature_at
(
pos
);
//
vd.template getProp<mean_curvature>(key) = model.estimate_mean_curvature_at(pos);
// vd.template getProp<gauss_curvature>(key) = model->estimate_gauss_curvature_at(vd.getPos(key));
double val = vd.getProp<mean_curvature>(key);
...
...
@@ -79,8 +79,9 @@ BOOST_AUTO_TEST_CASE ( PolyLevelset_Sphere )
else
check = false;
std::cout<<"Max err (poly level) = "<<max_err<<"\n";
BOOST_TEST( check );
*/
// if(model)
// delete model;
...
...
This diff is collapsed.
Click to expand it.
src/regression/regression.hpp
+
28
−
16
View file @
40b30a17
...
...
@@ -11,31 +11,41 @@
#include
"Vector/map_vector.hpp"
#include
"Space/Shape/Point.hpp"
#include
"DMatrix/EMatrix.hpp"
#include
"DCPSE/SupportBuilder.hpp"
#include
"minter.h"
/*
template<typename vector_type, typename NN_type>
class
Regression
Domain
class Regression
Support
{
openfpm::vector_std<size_t> keys;
public:
RegressionDomain
(
vector_type
&
vd
,
Point
<
vector_type
::
dims
,
typename
vector_type
::
stype
>
pos
,
typename
vector_type
::
stype
size
,
NN_type
&
NN
)
template<typename iterator_type>
RegressionSupport(vector_type &vd, iterator_type itPoint, unsigned int requiredSize, support_options opt, NN_type &cellList)
{
// Not efficient to compute cell list each time.
//auto NN = vd.getCellList(size);
auto
Np
=
NN
.
template
getNNIterator
(
NN
.
getCell
(
pos
));
while
(
Np
.
isNext
())
{
auto
key
=
Np
.
get
();
if
(
pos
.
distance
(
vd
.
getPos
(
key
))
<
size
)
keys
.
add
(
key
);
++
Np
;
}
}
// Get spatial position from point iterator
vect_dist_key_dx p = itPoint.get();
vect_dist_key_dx pOrig = itPoint.getOrig();
Point<vector_type::dims, typename vector_type::stype> pos = vd.getPos(p.getKey());
// Get cell containing current point and add it to the set of cell keys
grid_key_dx<vector_type::dims> curCellKey = cellList.getCellGrid(
pos); // Here get the key of the cell where the current point is
std::set<grid_key_dx<vector_type::dims>> supportCells;
supportCells.insert(curCellKey);
// Make sure to consider a set of cells providing enough points for the support
enlargeSetOfCellsUntilSize(supportCells, requiredSize + 1,
opt, cellList); // NOTE: this +1 is because we then remove the point itself
// Now return all the points from the support into a vector
keys = getPointsInSetOfCells(supportCells, p, pOrig, requiredSize, opt);
}
auto getKeys()
{
return keys;
...
...
@@ -46,6 +56,7 @@ public:
return keys.size();
}
};
*/
template
<
int
spatial_dim
,
unsigned
int
prp_id
,
typename
MatType
=
EMatrixXd
,
typename
VecType
=
EVectorXd
>
class
RegressionModel
...
...
@@ -158,7 +169,7 @@ public:
if
(
err
>
error
)
error
=
err
;
}
std
::
cout
<<
"Fit of degree "
<<
poly_degree
<<
" with error = "
<<
error
<<
std
::
endl
;
//
std::cout<<"Fit of degree "<<poly_degree<<" with error = "<<error<<std::endl;
}
while
(
error
>
tolerance
);
...
...
@@ -235,6 +246,7 @@ public:
return
res
;
}
};
...
...
This diff is collapsed.
Click to expand it.
src/regression/regression_test.cpp
+
76
−
39
View file @
40b30a17
...
...
@@ -14,8 +14,8 @@
BOOST_AUTO_TEST_SUITE
(
Regression_test
)
/*
BOOST_AUTO_TEST_CASE ( Regression_
domain_initialization
)
BOOST_AUTO_TEST_CASE
(
Regression_
local
)
{
Box
<
2
,
float
>
domain
({
0.0
,
0.0
},{
1.0
,
1.0
});
// Here we define the boundary conditions of our problem
...
...
@@ -44,13 +44,14 @@ BOOST_AUTO_TEST_CASE ( Regression_domain_initialization )
}
vd
.
map
();
double size = 0.075;
auto NN = vd.getCellList(size);
auto dom = new RegressionDomain<vectorType, decltype(NN)>(vd, {0.8,0.8}, size, NN);
auto
it2
=
vd
.
getDomainIterator
();
auto
NN
=
vd
.
getCellList
(
0.1
);
/*
auto support = RegressionSupport<vectorType, decltype(NN)>(vd, it2, 10, N_PARTICLES, NN);
std::cout<<"Initialized domain with "<<
dom->
getNumParticles()<<" particles.\n";
auto model =
new
RegressionModel<2, 0, vectorType>(vd, dom, 6, 2.0);
std::cout<<"Initialized domain with "<<
support.
getNumParticles()<<" particles.\n";
auto model = RegressionModel<2, 0, vectorType>(vd, dom, 6, 2.0);
double max_err = -1.0;
for(double x = 0.75; x < 0.85;x+=0.01)
...
...
@@ -73,15 +74,9 @@ BOOST_AUTO_TEST_CASE ( Regression_domain_initialization )
check = false;
std::cout<<"Max err = "<<max_err<<"\n";
BOOST_TEST( check );
if(model)
delete model;
if(dom)
delete dom;
*/
}
*/
BOOST_AUTO_TEST_CASE
(
Regression_without_domain_initialization
)
...
...
@@ -93,52 +88,94 @@ BOOST_AUTO_TEST_CASE ( Regression_without_domain_initialization)
Ghost
<
2
,
float
>
g
(
0.01
);
using
vectorType
=
vector_dist
<
2
,
float
,
aggregate
<
double
>
>
;
vectorType
vd
(
2048
,
domain
,
bc
,
g
);
vectorType
vd_orig
(
1024
,
domain
,
bc
,
g
);
vectorType
vd_test
(
vd_orig
.
getDecomposition
(),
200
);
Vcluster
<>
&
v_cl
=
create_vcluster
();
long
int
N_prc
=
v_cl
.
getProcessingUnits
();
if
(
v_cl
.
getProcessUnitID
()
==
0
)
std
::
cout
<<
"Running regression test with "
<<
N_prc
<<
" procs.
\n
"
;
// the scalar is the element at position 0 in the aggregate
const
int
scalar
=
0
;
auto
it
=
vd
.
getDomainIterator
();
while
(
it
.
isNext
())
// Creating a grid with synthetic data
{
auto
key
=
it
.
get
();
double
posx
=
(
double
)
rand
()
/
RAND_MAX
;
double
posy
=
(
double
)
rand
()
/
RAND_MAX
;
vd
.
getPos
(
key
)[
0
]
=
posx
;
vd
.
getPos
(
key
)[
1
]
=
posy
;
auto
it
=
vd_orig
.
getDomainIterator
();
while
(
it
.
isNext
())
{
auto
key
=
it
.
get
();
double
posx
=
(
double
)
rand
()
/
RAND_MAX
;
double
posy
=
(
double
)
rand
()
/
RAND_MAX
;
vd_orig
.
getPos
(
key
)[
0
]
=
posx
;
vd_orig
.
getPos
(
key
)[
1
]
=
posy
;
// Use synthetic data x*y
vd_orig
.
template
getProp
<
scalar
>(
key
)
=
sin
(
posx
*
posy
);
++
it
;
}
vd_orig
.
map
();
}
// Use synthetic data x*y
vd
.
template
getProp
<
scalar
>(
key
)
=
sin
(
posx
*
posy
);
++
it
;
}
vd
.
map
();
// Creating test points
{
auto
it
=
vd_test
.
getDomainIterator
();
while
(
it
.
isNext
())
{
auto
key
=
it
.
get
();
double
posx
=
(
double
)
rand
()
/
RAND_MAX
;
double
posy
=
(
double
)
rand
()
/
RAND_MAX
;
vd_test
.
getPos
(
key
)[
0
]
=
posx
;
vd_test
.
getPos
(
key
)[
1
]
=
posy
;
vd_test
.
template
getProp
<
scalar
>(
key
)
=
0.0
;
++
it
;
}
vd_test
.
map
();
}
auto
model
=
RegressionModel
<
2
,
0
>
(
vd
,
1e-6
);
auto
model
=
RegressionModel
<
2
,
0
>
(
vd
_orig
,
1e-6
);
double
max_err
=
-
1.0
;
for
(
double
x
=
0.75
;
x
<
0.85
;
x
+=
0.01
)
// Checking the error
{
for
(
double
y
=
0.75
;
y
<
0.85
;
y
+=
0.01
)
auto
it
=
vd_test
.
getDomainIterator
();
while
(
it
.
isNext
())
{
Point
<
2
,
double
>
pos
{
x
,
y
};
auto
key
=
it
.
get
();
Point
<
2
,
double
>
pos
=
{
vd_test
.
getPos
(
key
)[
0
],
vd_test
.
getPos
(
key
)[
1
]};
double
val
=
model
.
eval
(
pos
);
double
actual
=
sin
(
x
*
y
);
double
actual
=
sin
(
pos
[
0
]
*
pos
[
1
]
);
double
err
=
std
::
abs
(
actual
-
val
);
if
(
err
>
max_err
)
max_err
=
err
;
}
vd_test
.
template
getProp
<
scalar
>(
key
)
=
val
;
++
it
;
}
vd_test
.
ghost_get
<
scalar
>
();
}
v_cl
.
max
(
max_err
);
v_cl
.
execute
();
if
(
v_cl
.
getProcessUnitID
()
==
0
)
std
::
cout
<<
"Maximum error: "
<<
max_err
<<
"
\n
"
;
double
tolerance
=
1e-5
;
bool
check
;
if
(
std
::
abs
(
max_err
)
<
tolerance
)
check
=
true
;
else
check
=
false
;
std
::
cout
<<
"Max err = "
<<
max_err
<<
"
\n
"
;
BOOST_TEST
(
check
);
// if(model)
// delete model;
}
...
...
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