-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMapper.cpp
58 lines (50 loc) · 1.76 KB
/
Mapper.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//
// Created by jakob on 26.06.24.
//
#include "Mapper.h"
#include <cassert>
#include <utility>
#include "DataCover.h"
#include "CechComplex.h"
#include "Clusterer.h"
#include "Projection.h"
namespace MapperLib {
Mapper::Mapper(
std::shared_ptr<DataCoverFactory> data_cover_factory,
std::shared_ptr<ComplexFactory> complex_factory,
std::shared_ptr<Clusterer> clusterer,
std::shared_ptr<Projection> projection):
_data_cover_factory(std::move(data_cover_factory)),
_complex_factory(std::move(complex_factory)),
_clusterer(std::move(clusterer)),
_projection(std::move(projection))
{
assert(_data_cover_factory);
assert(_complex_factory);
assert(_clusterer);
assert(_projection);
}
std::vector<Simplex> Mapper::map(const Matrix &data)
{
auto const projected_data = _projection->project(data);
assert(_data_cover_factory);
assert(_complex_factory);
assert(_clusterer);
assert(_projection);
_data_cover = _data_cover_factory->create_data_cover(projected_data);
assert(_data_cover);
_complex = _complex_factory->create_complex(*_data_cover);
assert(_complex);
std::vector<MapperCluster> clusters;
std::cout << " === Mapper ===" << std::endl;
std::cout << "-> Starting cluster computation" << std::endl;
for(IntegerCubeId integer_cube_id = 0; integer_cube_id < _data_cover->get_total_num_cubes(); integer_cube_id++){
auto const data_in_cube = _data_cover->get_points_in_cube(integer_cube_id);
auto const cluster_assignment = _clusterer->predict(data, data_in_cube);
for(auto const& cluster: cluster_assignment){
clusters.push_back({cluster, clusters.size(), integer_cube_id});
}
}
return _complex->generate(clusters);
}
} // Mapper