Skip to content

Commit a08f9f5

Browse files
committed
probabilistic properties were refined
1 parent b5d4cb3 commit a08f9f5

File tree

3 files changed

+83
-10
lines changed

3 files changed

+83
-10
lines changed

sbf.cpp

+70-10
Original file line numberDiff line numberDiff line change
@@ -296,13 +296,13 @@ void SBF::PrintFilter(int mode)
296296
printf("Area-related parameters:\n");
297297
for(int j = 1; j < this->AREA_number+1; j++){
298298
potential_elements = (this->AREA_members[j]*this->HASH_number)-this->AREA_self_collisions[j];
299-
printf("Area %d: %d members, %d cells out of %d potential (%d self-collisions)",j,this->AREA_members[j],this->AREA_cells[j],potential_elements,this->AREA_self_collisions[j]);
299+
printf("Area %d: %d members, %.5f expected cells, %d cells out of %d potential (%d self-collisions)",j,this->AREA_members[j],this->AREA_expected_cells[j],this->AREA_cells[j],potential_elements,this->AREA_self_collisions[j]);
300300
printf("\n");
301301
}
302302

303303
printf("\nEmersion, Fpp, Isep:\n");
304304
for(int j = 1; j < this->AREA_number+1; j++){
305-
printf("Area %d: emersion %.5f, a-priori fpp %.5f, fpp %.5f, a-priori isep %.5f",j,this->GetAreaEmersion(j),this->AREA_a_priori_fpp[j],this->AREA_fpp[j],this->AREA_a_priori_isep[j]);
305+
printf("Area %d: expected emersion %.5f, emersion %.5f, a-priori fpp %.5f, fpp %.5f, a-priori isep %.5f, expected ise %.5f, isep %.5f",j,this->GetExpectedAreaEmersion(j),this->GetAreaEmersion(j),this->AREA_a_priori_fpp[j],this->AREA_fpp[j],this->AREA_a_priori_isep[j], this->AREA_a_priori_isep[j]*this->AREA_members[j], this->AREA_isep[j]);
306306
printf("\n");
307307
}
308308
printf("\n");
@@ -336,10 +336,10 @@ void SBF::SaveToDisk(std::string path, int mode)
336336
myfile << "a-priori fpp" << ";" << this->GetFilterAPrioriFpp() << std::endl;
337337
myfile << "fpp" << ";" << this->GetFilterFpp() << std::endl;
338338
// area-related parameters:
339-
// area,members,self-collisions,cells,emersion,a-priori fpp,fpp,a-priori isep
340-
myfile << "area" << ";" << "members" << ";" << "self-collisions" << ";" << "cells" << ";" << "emersion" << ";" << "a-priori fpp" << ";" << "fpp" << ";" << "a-priori isep" << std::endl;
339+
// area,members,expected cells,self-collisions,cells,expected emersion,emersion,a-priori fpp,fpp,a-priori isep,expected ise,isep
340+
myfile << "area" << ";" << "members" << ";" << "expected cells" << ";" << "self-collisions" << ";" << "cells" << ";" << "expected emersion" << ";" << "emersion" << ";" << "a-priori fpp" << ";" << "fpp" << ";" << "a-priori isep" << ";" << "expected ise" << ";" << "isep" << std::endl;
341341
for(int j = 1; j < this->AREA_number+1; j++){
342-
myfile << j << ";" << this->AREA_members[j] << ";" << this->AREA_self_collisions[j] << ";" << this->AREA_cells[j] << ";" << this->GetAreaEmersion(j) << ";" << this->AREA_a_priori_fpp[j] << ";" << this->AREA_fpp[j] << ";" << this->AREA_a_priori_isep[j] << std::endl;
342+
myfile << j << ";" << this->AREA_members[j] << ";" << this->AREA_expected_cells[j] << ";" << this->AREA_self_collisions[j] << ";" << this->AREA_cells[j] << ";" << this->GetExpectedAreaEmersion(j) << ";" << this->GetAreaEmersion(j) << ";" << this->AREA_a_priori_fpp[j] << ";" << this->AREA_fpp[j] << ";" << this->AREA_a_priori_isep[j] << ";" << (float)this->AREA_members[j] * this->AREA_a_priori_isep[j] << ";" << (float)this->AREA_isep[j] << std::endl;
343343
}
344344

345345
}
@@ -491,7 +491,7 @@ int SBF::Check(char *string, int size)
491491
// Computes a-priori area-specific inter-set error probability (a_priori_isep)
492492
void SBF::SetAPrioriAreaIsep()
493493
{
494-
double p1;
494+
double p;
495495
int nfill;
496496

497497

@@ -502,16 +502,58 @@ void SBF::SetAPrioriAreaIsep()
502502
nfill += this->AREA_members[j];
503503
}
504504

505-
p1 = (double)(1 - 1 / (double)this->cells);
506-
p1 = (double)(1 - (double)pow(p1, this->HASH_number*nfill));
507-
p1 = (double)pow(p1, this->HASH_number);
505+
p = (double)(1 - 1 / (double)this->cells);
506+
p = (double)(1 - (double)pow(p, this->HASH_number*nfill));
507+
p = (double)pow(p, this->HASH_number);
508508

509-
this->AREA_a_priori_isep[i] = (float)p1;
509+
this->AREA_a_priori_isep[i] = (float)p;
510510

511511
}
512512
}
513513

514514

515+
// Computes a-posteriori area-specific inter-set error probability (isep)
516+
void SBF::SetAreaIsep()
517+
{
518+
double p;
519+
520+
for (int i = this->AREA_number; i>0; i--) {
521+
522+
p = (double)(1 - (double)this->GetAreaEmersion(i));
523+
p = (double)pow(p, this->HASH_number);
524+
525+
this->AREA_isep[i] = (float)p;
526+
527+
}
528+
}
529+
530+
531+
// Computes the expected number of cells for each area (expected_cells)
532+
void SBF::SetExpectedAreaCells()
533+
{
534+
double p1, p2;
535+
int nfill;
536+
537+
538+
for (int i = this->AREA_number; i>0; i--) {
539+
nfill = 0;
540+
541+
for (int j = i + 1; j <= this->AREA_number; j++) {
542+
nfill += this->AREA_members[j];
543+
}
544+
545+
p1 = (double)(1 - 1 / (double)this->cells);
546+
p2 = (double)pow(p1, this->HASH_number*nfill);
547+
p1 = (double)(1 - (double)pow(p1, this->HASH_number*this->AREA_members[i]));
548+
549+
p1 = (double)this->cells*p1*p2;
550+
551+
this->AREA_expected_cells[i] = (float)p1;
552+
553+
}
554+
}
555+
556+
515557
// Computes a-priori area-specific false positives probability (a_priori_fpp)
516558
void SBF::SetAPrioriAreaFpp()
517559
{
@@ -617,6 +659,24 @@ float SBF::GetFilterFpp()
617659
return (float)p;
618660
}
619661

662+
663+
// Returns the expected emersion value for the input area
664+
float SBF::GetExpectedAreaEmersion(int area)
665+
{
666+
double p;
667+
int nfill = 0;
668+
669+
for (int j = area + 1; j <= this->AREA_number; j++) {
670+
nfill += this->AREA_members[j];
671+
}
672+
673+
p = (double)(1 - 1 / (double)this->cells);
674+
p = (double)pow(p, this->HASH_number*nfill);
675+
676+
return (float)p;
677+
}
678+
679+
620680
// Returns the emersion value for the input area
621681
float SBF::GetAreaEmersion(int area)
622682
{

sbf.h

+11
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,13 @@ namespace sbf {
6868
int collisions;
6969
int AREA_number;
7070
int *AREA_members;
71+
float *AREA_expected_cells;
7172
int *AREA_cells;
7273
int *AREA_self_collisions;
7374
float *AREA_a_priori_fpp;
7475
float *AREA_fpp;
7576
float *AREA_a_priori_isep;
77+
float *AREA_isep;
7678
int BIG_end;
7779

7880
// Private methods (commented in the sbf.cpp)
@@ -176,8 +178,10 @@ namespace sbf {
176178
// Memory allocations for area related parameters
177179
this->AREA_members = new int[this->AREA_number + 1];
178180
this->AREA_cells = new int[this->AREA_number + 1];
181+
this->AREA_expected_cells = new float[this->AREA_number + 1];
179182
this->AREA_self_collisions = new int[this->AREA_number + 1];
180183
this->AREA_fpp = new float[this->AREA_number + 1];
184+
this->AREA_isep = new float[this->AREA_number + 1];
181185
this->AREA_a_priori_fpp = new float[this->AREA_number + 1];
182186
this->AREA_a_priori_isep = new float[this->AREA_number + 1];
183187

@@ -187,8 +191,10 @@ namespace sbf {
187191
for (int a = 0; a < this->AREA_number + 1; a++) {
188192
this->AREA_members[a] = 0;
189193
this->AREA_cells[a] = 0;
194+
this->AREA_expected_cells[a] = -1;
190195
this->AREA_self_collisions[a] = 0;
191196
this->AREA_fpp[a] = -1;
197+
this->AREA_isep[a] = -1;
192198
this->AREA_a_priori_fpp[a] = -1;
193199
this->AREA_a_priori_isep[a] = -1;
194200
}
@@ -201,8 +207,10 @@ namespace sbf {
201207
delete[] filter;
202208
delete[] AREA_members;
203209
delete[] AREA_cells;
210+
delete[] AREA_expected_cells;
204211
delete[] AREA_self_collisions;
205212
delete[] AREA_fpp;
213+
delete[] AREA_isep;
206214
delete[] AREA_a_priori_fpp;
207215
delete[] AREA_a_priori_isep;
208216
for (int j = 0; j<this->HASH_number; j++) {
@@ -223,7 +231,10 @@ namespace sbf {
223231
float GetFilterAPrioriFpp();
224232
void SetAreaFpp();
225233
void SetAPrioriAreaFpp();
234+
void SetAreaIsep();
226235
void SetAPrioriAreaIsep();
236+
void SetExpectedAreaCells();
237+
float GetExpectedAreaEmersion(int area);
227238
float GetAreaEmersion(int area);
228239
};
229240

test-app/test-app.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ int main() {
227227
myFilter->SetAPrioriAreaFpp();
228228
myFilter->SetAreaFpp();
229229
myFilter->SetAPrioriAreaIsep();
230+
myFilter->SetAreaIsep();
231+
myFilter->SetExpectedAreaCells();
230232

231233
//prints filter to the standard output or saves it to disk
232234
if (print_mode == 1) myFilter->PrintFilter(0);

0 commit comments

Comments
 (0)