File: sls_alp_sim.hpp

package info (click to toggle)
mmseqs2 12-113e3%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 25,760 kB
  • sloc: cpp: 67,306; ansic: 6,279; sh: 2,425; makefile: 94; perl: 32
file content (579 lines) | stat: -rwxr-xr-x 12,707 bytes parent folder | download | duplicates (16)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
#ifndef INCLUDED_SLS_ALP_SIMULATION
#define INCLUDED_SLS_ALP_SIMULATION

/* $Id: $
* ===========================================================================
*
*                            PUBLIC DOMAIN NOTICE
*               National Center for Biotechnology Information
*
*  This software/database is a "United States Government Work" under the
*  terms of the United States Copyright Act.  It was written as part of
*  the author's offical duties as a United States Government employee and
*  thus cannot be copyrighted.  This software/database is freely available
*  to the public for use. The National Library of Medicine and the U.S.
*  Government have not placed any restriction on its use or reproduction.
*
*  Although all reasonable efforts have been taken to ensure the accuracy
*  and reliability of the software and data, the NLM and the U.S.
*  Government do not and cannot warrant the performance or results that
*  may be obtained by using this software or data. The NLM and the U.S.
*  Government disclaim all warranties, express or implied, including
*  warranties of performance, merchantability or fitness for any particular
*  purpose.
*
*  Please cite the author in any work or product based on this material.
*
* ===========================================================================*/

/*****************************************************************************

File name: sls_alp_sim.hpp

Author: Sergey Sheetlin

Contents: Simulation of Gumbel parameters

******************************************************************************/


#include <complex>
#include <iostream>
#include <map>
#include <vector>
#include <fstream>
#include <float.h>
#include <algorithm>

#include "sls_alp_data.hpp"
#include "sls_alp.hpp"
#include "sls_alp_regression.hpp"

namespace Sls {

	struct struct_for_lambda_calculation
	{
		void **d_alp_distr;
		void **d_alp_distr_errors;
		long int d_nalp;
		double d_f_error;

		double d_last_sum;
		double d_last_sum_error;

		bool d_calculate_alp_number;
		long int d_alp_number;
	};




	class alp_sim{

	

	public:


		alp_sim(//constructor
			alp_data *alp_data_
			);


		~alp_sim();//destructor

		void alp_sim_from_random_seed(//simulation from random seed
		alp_data *alp_data_);

		void quick_test(//runs quick tests to determine whether the scoring scheme is linear
		long int trials_number_,
		double max_time_);

		void get_minimal_simulation(
		long int ind1_,
		long int ind2_,
		long int &M_min_,
		long int &nalp_,
		long int &nalp_lambda_,
		bool C_calculation_,
		bool check_time_flag_);//simulation using [ind1_,ind2_] range of realizations with an estimation of parameters for accuracy, memory usage and calculation time


		void memory_release_for_get_minimal_simulation(
		long int nalp_,
		void **&alp_distr,
		void **&alp_distr_errors);

		bool the_criterion(//criteria of stopping of the simulating ALP
		//if the function returns true then calculates optimal M_min and ALP number
		//sets the flags M_min_flag_ and nalp_flag_ checking the corresponding condition
		long int upto_nalp_,
		long int &nalp_for_lambda_simulation_,
		long int ind1_,
		long int ind2_,
		void **&alp_distr,
		void **&alp_distr_errors,
		long int &M_min_,
		bool &M_min_flag_,
		bool &nalp_flag_,
		bool &inside_simulation_flag_,
		bool C_calculation_,
		double *lambda_=NULL,
		double *lambda_error_=NULL);

		void calculate_lambda(
		bool check_the_criteria_,
		long int nalp_,
		long int &nalp_thr_,
		bool &inside_simulation_flag_,
		void **alp_distr,
		void **alp_distr_errors,
		double &lambda_,
		double &lambda_error_,
		double &test_difference_,
		double &test_difference_error_);

		void calculate_C(
		long int starting_point,
		long int nalp_,
		void **alp_distr,
		void **alp_distr_errors,
		double lambda_,
		double lambda_error_,
		double &C_,
		double &C_error_,
		double &Sc_,
		double &Sc_error_);

		void memory_release_for_calculate_FSC(
		double *&exp_array,

		double *&delta_E,
		double *&delta_E_error,

		double *&delta_E_E,
		double *&delta_E_E_error,


		double *&delta_I,
		double *&delta_I_error,

		double *&delta_J,
		double *&delta_J_error,

		double *&delta_I_I,
		double *&delta_I_I_error,

		double *&delta_I_J,
		double *&delta_I_J_error,

		double *&delta_J_J,
		double *&delta_J_J_error,

		double *&cov_J_J,
		double *&cov_J_J_error,

		double *&cov_I_J,
		double *&cov_I_J_error,

		double *&cov_I_I,
		double *&cov_I_I_error,

		double *&cov_E_E,
		double *&cov_E_E_error);


		void calculate_FSC(
		long int nalp_,
		long int ind1_,
		long int ind2_,
		void **alp_distr,
		double lambda_,
		double Sc_,
		//double Sc_error_,

		double &a_I_,
		double &a_I_error_,
		double &a_J_,
		double &a_J_error_,
		double &sigma_,
		double &sigma_error_,
		double &alpha_I_,
		double &alpha_I_error_,
		double &alpha_J_,
		double &alpha_J_error_);

		void sigma_calculation(
		double delta_I_aver_,
		double delta_I_aver_error_,
		double delta_J_aver_,
		double delta_J_aver_error_,
		double delta_E_aver_,
		double delta_E_aver_error_,
		double cov_E_E_aver_,
		double cov_E_E_aver_error_,
		double cov_I_J_aver_,
		double cov_I_J_aver_error_,
		double &sigma_,
		double &sigma_error_);

		void get_and_allocate_alp_distribution(
		long int ind1_,
		long int ind2_,
		void **&alp_distr,
		void **&alp_distr_errors,
		long int nalp);

		bool check_K_criterion(
		long int nalp_,
		long int ind1_,
		long int ind2_,
		double lambda_,
		double eps_K_,
		long int &M_min_);

		void kill(
		bool check_time_,
		long int ind1_,
		long int ind2_,
		long int M_min_,
		double lambda_,
		double eps_K_,
		double &K_C_,
		double &K_C_error_,
		long int &level_,
		long int &diff_opt_);


		
		bool check_K_criterion_during_killing2(
		long int ind1_,
		long int ind2_,
		double lambda_,
		double eps_K_,
		long int current_level_,
		long int &recommended_level_,
		long int &diff_opt_,
		double &K_C_,
		double &K_C_error_);
		

		bool check_K_criterion_during_killing(
		long int ind1_,
		long int ind2_,
		double lambda_,
		double eps_K_,
		long int current_level_,
		long int &recommended_level_,
		long int &diff_opt_,
		double &K_C_,
		double &K_C_error_);




		inline static double lambda_exp(
		long int &i_,
		double *&exp_array_);

		void get_single_realization(
		bool check_time_,
		long int M_min_,
		long int nalp_,
		bool killing_flag_,
		long int level_,
		long int diff_opt_,
		alp *&obj_,
		bool &sucess_flag_,
		double &d_eps_);

		void calculate_main_parameters(
		long int final_realizations_number_lambda_,
		long int final_realizations_number_killing_,
		long int nalp,
		long int nalp_for_lambda_simulation,
		long int level,
		bool &inside_simulation_flag,
		double &lambda,
		double &lambda_error,
		double &test_difference,
		double &test_difference_error,
		double &C,
		double &C_error,
		double &C2,
		double &C2_error,
		double &C4,
		double &C4_error,
		double &K_C,
		double &K_C_error,
		double &a_I,
		double &a_I_error,
		double &a_J,
		double &a_J_error,
		double &sigma,
		double &sigma_error,
		double &alpha_I,
		double &alpha_I_error,
		double &alpha_J,
		double &alpha_J_error,
		double &K,
		double &K_error);

		void calculate_main_parameters2(
		long int final_realizations_number_lambda_,
		long int final_realizations_number_killing_,
		long int nalp,
		long int nalp_for_lambda_simulation,
		long int level,
		bool &inside_simulation_flag,
		double &lambda,
		double &lambda_error,
		double &test_difference,
		double &test_difference_error,
		double &C,
		double &C_error,
		double &C2,
		double &C2_error,
		double &C4,
		double &C4_error,
		double &K_C,
		double &K_C_error,
		double &a_I,
		double &a_I_error,
		double &a_J,
		double &a_J_error,
		double &sigma,
		double &sigma_error,
		double &alpha_I,
		double &alpha_I_error,
		double &alpha_J,
		double &alpha_J_error,
		double &K,
		double &K_error);

		void memory_release_for_calculate_main_parameters2m(
		long int nalp_for_lambda_simulation,
		long int *&d_mult_realizations,
		long int *&d_mult_K_realizations,

		double *&lambda_mult,
		double *&lambda_mult_error,

		double *&C_mult,
		double *&C_mult_error,

		double *&a_I_mult,
		double *&a_I_mult_error,

		double *&a_J_mult,
		double *&a_J_mult_error,

		double *&sigma_mult,
		double *&sigma_mult_error,

		double *&alpha_I_mult,
		double *&alpha_I_mult_error,

		double *&alpha_J_mult,
		double *&alpha_J_mult_error,

		double *&K_C_mult,
		double *&K_C_mult_error,

		double *&K_mult,
		double *&K_mult_error,

		double *&Sc_mult,
		double *&Sc_mult_error,


		void **&alp_distr,
		void **&alp_distr_errors,

		void ***&alp_mult_distr,
		void ***&alp_mult_distr_errors);

		void calculate_main_parameters2m(
		long int final_realizations_number_lambda_,
		long int final_realizations_number_killing_,
		long int nalp_for_lambda_simulation,
		long int level,
		bool &inside_simulation_flag,
		double &lambda,
		double &lambda_error,
		double &test_difference,
		double &test_difference_error,
		double &C,
		double &C_error,
		double &K_C,
		double &K_C_error,
		double &a_I,
		double &a_I_error,
		double &a_J,
		double &a_J_error,
		double &sigma,
		double &sigma_error,
		double &alpha_I,
		double &alpha_I_error,
		double &alpha_J,
		double &alpha_J_error,
		double &K,
		double &K_error,
		bool &flag_);

		void randomize_realizations(
		long int final_realizations_number_lambda_,
		long int final_realizations_number_killing_);

		void randomize_realizations_ind(
		long int ind1_,
		long int ind2_);

		void generate_random_permulation(
		long int *perm_,
		long int dim_);




		static void error_in_calculate_main_parameters2m(
		double C,
		double &C_error,
		double C_mult2,
		double C_mult2_error);




		void output_main_parameters(
		double time_,
		long int nalp,
		long int nalp_for_lambda_simulation,
		long int level,
		long int M_min_,
		bool &inside_simulation_flag,
		long int final_realizations_number_lambda_,
		long int final_realizations_number_killing_);

		void output_main_parameters2(
		double time_,
		long int nalp,
		long int nalp_for_lambda_simulation,
		long int level,
		long int M_min_,
		bool &inside_simulation_flag,
		long int final_realizations_number_lambda_,
		long int final_realizations_number_killing_);

		void output_main_parameters2m_new(
		long int nalp_for_lambda_simulation,
		long int level,
		bool &inside_simulation_flag,
		long int final_realizations_number_lambda_,
		long int final_realizations_number_killing_);

		void symmetric_parameters_for_symmetric_scheme();




		static double relative_error_in_percents(
		double val_,
		double val_error_);

		static double round_double(
		double val_,
		long int digits_);

		static long int get_number_of_subsimulations(
		long int number_of_realizations_);



		static double function_for_lambda_calculation(
		double lambda_,
		void * data_);

		static double get_root(
		const std::vector<double> &res_tmp_,
		double point_);
		



	public:


				
		alp_data *d_alp_data;//initial data
		array_positive<alp*> *d_alp_obj;//vector with the alp objects
		long int d_n_alp_obj;//number of alp objects
					
		array_positive<double> *d_lambda_tmp;
		array_positive<double> *d_lambda_tmp_errors;

		array_positive<double> *d_C_tmp;
		array_positive<double> *d_C_tmp_errors;

		//Subsimulations' parameters

		//number of subsimulations
		long int d_mult_number;


		//parameters estimations

		double m_Lambda;
		double m_LambdaError;
		double m_K;
		double m_KError;
		double m_C;
		double m_CError;

		double m_Sigma;
		double m_SigmaError;

		double m_GaplessAlpha;
		double m_GaplessAlphaError;

		double m_GaplessA;
		double m_GaplessAError;


		double m_AlphaI;
		double m_AlphaIError;
		double m_AlphaJ;
		double m_AlphaJError;

		double m_AI;
		double m_AIError;
		double m_AJ;
		double m_AJError;



		double m_CalcTime;

		long int m_G;
		long int m_G1;
		long int m_G2;

		std::vector<double> m_LambdaSbs;
		std::vector<double> m_KSbs;
		std::vector<double> m_CSbs;

		std::vector<double> m_SigmaSbs;

		std::vector<double> m_AlphaISbs;
		std::vector<double> m_AlphaJSbs;

		std::vector<double> m_AISbs;
		std::vector<double> m_AJSbs;



	};
}

#endif