BlosSOM
Interactive dimensionality reduction on large datasets (EmbedSOM and FLOWER combined)
frame_stats.h
Go to the documentation of this file.
1/* This file is part of BlosSOM.
2 *
3 * Copyright (C) 2021 Sona Molnarova
4 *
5 * BlosSOM is free software: you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free
7 * Software Foundation, either version 3 of the License, or (at your option)
8 * any later version.
9 *
10 * BlosSOM is distributed in the hope that it will be useful, but WITHOUT ANY
11 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * BlosSOM. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19#ifndef FRAME_STATS_H
20#define FRAME_STATS_H
21
22#include <cstddef>
23#include <vector>
24
25#include "timer.h"
26
28{
29 // Actual computation time of the methods.
30 float trans_t = 0.00001f;
31 float embedsom_t = 0.00001f;
32 float scaled_t = 0.00001f;
33 float color_t = 0.00001f;
34
36
37 // Maximal duration of the measured method
38 // (in milliseconds) for estimation of the
39 // batch size.
40 float trans_duration = 5.0f;
41 float embedsom_duration = 5.0f;
42 float scaled_duration = 5.0f;
43 float color_duration = 5.0f;
44
45 // Duration of the constant functions, per one frame,
46 // that does not need to estimate batch size
47 // (in milliseconds).
48 float constant_time = 0.0f;
49 // Time left for computation of method with estimated batch
50 // size for the next frame.
51 float est_time = 0.1f;
52
53 float embed_priority = 0.05f;
54 float color_priority = 0.05f;
55 float trans_priority = 0.45f;
56 float scaled_priority = 0.45f;
57
59 {
60 constant_time = 0.0f;
61 timer.tick();
62 }
63
64 void end_frame()
65 {
67
68 // Because we want the frame to last ~50ms (~20 FPS).
69 float diff = 50.0f - constant_time;
70 est_time = diff < 0.0001f ? 1.0f : diff;
71 }
72
74 {
75 timer.tick();
76 constant_time += timer.frametime * 1000; // to get milliseconds
77 }
78
79 void store_time(float &to)
80 {
81 timer.tick();
82 to = timer.frametime * 1000; // to get milliseconds
83 }
84
85 void reset(float &t) { t = 0.00001f; }
86
87 /**
88 * @brief Compute durations of the estimation batch sizes computations.
89 *
90 */
92 {
93 float high = 0.45f;
94 float low = 0.05f;
95 // First compute statistics
96 // if all 4 are computing
97 if (trans_t > 0.00001f && scaled_t > 0.00001f &&
98 embedsom_t > 0.00001f && color_t > 0.00001f) {
99 trans_priority = high;
100 scaled_priority = high;
101 color_priority = low;
102 embed_priority = low;
103 } else
104 // if trans finished and all other are computing
105 if (trans_t <= 0.00001f && scaled_t > 0.00001f &&
106 embedsom_t > 0.00001f && color_t > 0.00001f) {
107 trans_priority = 0.0f;
108 scaled_priority = high + high;
109 color_priority = low;
110 embed_priority = low;
111 } else
112 // if scaled finished and all others are computing
113 if (trans_t > 0.00001f && scaled_t <= 0.00001f &&
114 embedsom_t > 0.00001f && color_t > 0.00001f) {
115 trans_priority = high + high;
116 scaled_priority = 0.0f;
117 color_priority = low;
118 embed_priority = low;
119 } else
120 // if trans and scaled finished computing
121 if (trans_t <= 0.00001f && scaled_t <= 0.00001f &&
122 embedsom_t > 0.00001f && color_t > 0.00001f) {
123 trans_priority = 0.0f;
124 scaled_priority = 0.0f;
125 color_priority = 0.75f;
126 embed_priority = 0.25f;
127 } else
128 // if trans, scaled and color finished computing
129 if (trans_t <= 0.00001f && scaled_t <= 0.00001f &&
130 embedsom_t > 0.00001f && color_t <= 0.00001f) {
131 trans_priority = 0.0f;
132 scaled_priority = 0.0f;
133 color_priority = 0.0f;
134 embed_priority = 1.0f;
135 } else
136 // if trans, scaled and embedsom finished computing
137 if (trans_t <= 0.00001f && scaled_t <= 0.00001f &&
138 embedsom_t <= 0.00001f && color_t > 0.00001f) {
139 trans_priority = 0.0f;
140 scaled_priority = 0.0f;
141 color_priority = 1.0f;
142 embed_priority = 0.0f;
143 } else
144 // if trans, scaled, color and embedsom finished
145 // computing
146 if (trans_t <= 0.00001f &&
147 scaled_t <= 0.00001f &&
148 embedsom_t <= 0.00001f &&
149 color_t <= 0.00001f) {
150 trans_priority = 0.0f;
151 scaled_priority = 0.0f;
152 color_priority = 0.0f;
153 embed_priority = 0.0f;
154 }
155
156 if (trans_priority == 0.0f)
157 trans_duration = 0.0f;
158 else
160 if (embed_priority == 0.0f)
161 embedsom_duration = 0.0f;
162 else
164 if (scaled_priority == 0.0f)
165 scaled_duration = 0.0f;
166 else
168 if (color_priority == 0.0f)
169 color_duration = 0.0f;
170 else
172 }
173};
174
175#endif // FRAME_STATS_H
float scaled_duration
Definition: frame_stats.h:42
void add_const_time()
Definition: frame_stats.h:73
float color_t
Definition: frame_stats.h:33
void store_time(float &to)
Definition: frame_stats.h:79
void reset(float &t)
Definition: frame_stats.h:85
float trans_duration
Definition: frame_stats.h:40
float scaled_t
Definition: frame_stats.h:32
void update_times()
Compute durations of the estimation batch sizes computations.
Definition: frame_stats.h:91
float trans_priority
Definition: frame_stats.h:55
float color_duration
Definition: frame_stats.h:43
float embedsom_duration
Definition: frame_stats.h:41
Timer timer
Definition: frame_stats.h:35
float trans_t
Definition: frame_stats.h:30
float embed_priority
Definition: frame_stats.h:53
void end_frame()
Definition: frame_stats.h:64
void start_frame()
Definition: frame_stats.h:58
float est_time
Definition: frame_stats.h:51
float constant_time
Definition: frame_stats.h:48
float embedsom_t
Definition: frame_stats.h:31
float color_priority
Definition: frame_stats.h:54
float scaled_priority
Definition: frame_stats.h:56
Handler for frametime computation.
Definition: timer.h:29
void tick()
Counts frametime and sets last_tick variable to current time.
Definition: timer.h:52
float frametime
Duration of the last frame (in seconds).
Definition: timer.h:33