-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_impact_pytest.py
1466 lines (1190 loc) · 45 KB
/
test_impact_pytest.py
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
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import Impact_Funcs
# common data for conducting tests
test_citations = [9, 14, 3, 9, 11, 2, 1, 2, 0, 1, 0, 42, 36, 2, 1, 0]
test_years = [1997, 1997, 1997, 1997, 1998, 1999, 2000, 2000, 2001, 2001, 2001, 1997, 2000, 2001, 2000, 2000]
test_author_cnt = [1, 3, 4, 4, 2, 4, 4, 1, 1, 2, 2, 3, 3, 1, 1, 4]
test_author_order = [1, 3, 3, 3, 2, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 3]
def test_rank():
indices = [8, 10, 15, 6, 9, 14, 5, 7, 13, 2, 0, 3, 4, 1, 12, 11]
ranks = [10, 13, 9, 11, 12, 6, 3, 7, 0, 4, 1, 15, 14, 8, 5, 2]
assert Impact_Funcs.rank(16, indices) == ranks
def test_sort_and_rank():
# this is the index of the citations in ith order, i.e.i, the 0th entry lists the index of the smallest value,
# the 1st entry lists the index of the second smallest value, etc.
indices = [8, 10, 15, 6, 9, 14, 5, 7, 13, 2, 0, 3, 4, 1, 12, 11]
# rank_order is the rank of the ith entry (starting at 1, not 0), from high to low
rank_order = [6, 3, 7, 5, 4, 10, 13, 9, 16, 12, 15, 1, 2, 8, 11, 14]
assert Impact_Funcs.sort_and_rank(test_citations, len(test_citations)) == (indices, rank_order)
def test_calculate_ranks():
rank_order = [6, 3, 7, 5, 4, 10, 13, 9, 16, 12, 15, 1, 2, 8, 11, 14]
# the cumulative citation count, when pubs are ranked from most to fewest cites
cumulative_cnt = [42, 78, 92, 103, 112, 121, 124, 126, 128, 130, 131, 132, 133, 133, 133, 133]
assert Impact_Funcs.calculate_ranks(test_citations) == (rank_order, cumulative_cnt)
def test_calculate_median_odd():
# test when there are an odd number of values
assert Impact_Funcs.calculate_median([1, 12, 3, 10, 4]) == 4
def test_calculate_median_even():
# test when there are an even number of values
assert Impact_Funcs.calculate_median([1, 10, 3, 4]) == 3.5
def test_publication_ages():
year = 2018
answer = [22, 22, 22, 22, 21, 20, 19, 19, 18, 18, 18, 22, 19, 18, 19, 19]
assert Impact_Funcs.publication_ages(year, test_years) == answer
def test_citations_per_year():
answer = [9/22, 14/22, 3/22, 9/22, 11/21, 2/20, 1/19, 2/19, 0/18, 1/18, 0/18, 42/22, 36/19, 2/18, 1/19, 0/19]
ages = Impact_Funcs.publication_ages(2018, test_years)
assert Impact_Funcs.citations_per_year(test_citations, ages) == answer
def test_calculate_total_pubs():
assert Impact_Funcs.calculate_total_pubs(test_citations) == 16
def test_calculate_total_cites():
assert Impact_Funcs.calculate_total_cites(test_citations) == 133
def test_max_cites():
assert Impact_Funcs.calculate_max_cites(test_citations) == 42
def test_calculate_mean_cites():
p = Impact_Funcs.calculate_total_pubs(test_citations)
c = Impact_Funcs.calculate_total_cites(test_citations)
assert Impact_Funcs.calculate_mean_cites(c, p) == 133/16
def test_calculate_h_index():
rank_order, _ = Impact_Funcs.calculate_ranks(test_citations)
is_core = [True, True, False, True, True, False, False, False, False, False, False, True, True, False, False, False]
assert Impact_Funcs.calculate_h_index(test_citations, rank_order) == (6, is_core)
"""
def author_effort(measure: str, n_authors: int, author_pos: int=1) -> float:
'''
returns the estimated effort of an author for a publication
'''
if measure == "fractional":
return 1 / n_authors
elif measure == "proportional":
return 2*(n_authors + 1 - author_pos) / (n_authors*(n_authors + 1))
elif measure == "geometric":
return 2**(n_authors - author_pos) / (2**n_authors - 1)
elif measure == "harmonic":
if n_authors % 2 == 0:
d = 0
else:
d = 1 / (2*n_authors)
return (1 + abs(n_authors + 1 - 2*author_pos)) / ((n_authors**2)/2 + n_authors*(1 - d))
else:
return 1
def citations_per_pub_per_year(pub_list: list) -> list:
def convert_none(x) -> int:
if x is None:
return 0
else:
return x
# take total citations for each pub at each year and convert to yearly only totals
pub_cites = []
for p in pub_list:
cites = [convert_none(p[0])]
for i in range(1, len(p)):
cites.append(convert_none(p[i]) - convert_none(p[i-1]))
pub_cites.append(cites)
return pub_cites
# --- Metric Calculations ---
# Hirsch core citations (Hirsch )
def calculate_h_core(citations: list, is_core: list) -> int:
core_cites = 0
for i in range(len(citations)):
if is_core[i]:
core_cites += citations[i]
return core_cites
# Hirsch minimum constant
def calculate_hirsch_min_const(total_cites: int, h: int) -> float:
return total_cites / h**2
# g-index (Egghe 2006)
def calculate_g_index(cumulative_citations: list, rank_order: list) -> int:
g = 0
for i in range(len(rank_order)):
if rank_order[i]**2 <= cumulative_citations[rank_order[i]-1]:
g += 1
return g
# h2-index (Kosmulski 2006)
def calculate_h2_index(citations: list, rank_order: list) -> int:
h2_index = 0
for i in range(len(rank_order)):
if rank_order[i] <= math.sqrt(citations[i]):
h2_index += 1
return h2_index
# hg-index (Alonso et al 2010)
def calculate_hg_index(h: int, g: int) -> float:
return math.sqrt(h*g)
# total self citations
def calculate_total_self_cites(self_citations: list) -> int:
return sum(self_citations)
# total self-citation rate
def calculate_total_self_cite_rate(total_self_cites: int, total_cites: int) -> float:
return total_self_cites/total_cites
# mean self-citation rate
def calculate_mean_self_cite_rate(self_citations: list, all_citations: list) -> float:
mean_rate = 0
for i in range(len(self_citations)):
if all_citations[i] != 0:
mean_rate += self_citations[i] / all_citations[i]
return mean_rate / len(self_citations)
# sharpened h-index (Schreiber 2007)
def calculate_sharpened_h_index(self_citations: list, all_citations: list) -> int:
sharp_citations = [all_citations[i] - self_citations[i] for i in range(len(self_citations))]
# for i in range(len(self_citations)):
# sharp_citations.append(all_citations[i] - self_citations[i])
_, tmprank = sort_and_rank(sharp_citations, len(sharp_citations))
sharp_h_index = 0
for i in range(len(sharp_citations)):
if tmprank[i] <= sharp_citations[i]:
sharp_h_index += 1
return sharp_h_index
# b-index (Brown 2009)
def calculate_b_index(h: int, avg_rate: float) -> float:
return h * avg_rate**0.75
# real h-index (hr-index) (Guns and Rousseau 2009)
def calculate_real_h_index(citations: list, rank_order: list, h: int) -> Number:
j = -1
k = -1
for i in range(len(citations)):
if rank_order[i] == h:
j = i
elif rank_order[i] == h + 1:
k = i
if (k != -1) and (j != -1):
return ((h + 1) * citations[j] - h * citations[k]) / (1 - citations[k] + citations[j])
else:
return h
# a-index (Jin 2006; Rousseau 2006)
def calculate_a_index(core_cites: int, total_pubs: int) -> float:
return core_cites / total_pubs
# r-index (Jin et al 2007)
def calculate_r_index(core_cites: int) -> float:
return math.sqrt(core_cites)
# rm-index (Panaretos and Malesios 2009)
def calculate_rm_index(citations: list, is_core: list) -> float:
rm_index = 0
for i in range(len(citations)):
if is_core[i]:
rm_index += math.sqrt(citations[i])
rm_index = math.sqrt(rm_index)
return rm_index
# ar-index (Jin 2007; Jin et al 2007)
def calculate_ar_index(citations: list, pub_years: list, is_core: list, year: int) -> float:
pub_ages = publication_ages(year, pub_years)
cites_per_year = citations_per_year(citations, pub_ages)
ar_index = 0
for i in range(len(citations)):
if is_core[i]:
ar_index += cites_per_year[i]
return math.sqrt(ar_index)
# m-index (median index) (Bornmann et al 2008)
def calculate_m_index(citations: list, is_core: list, h: int) -> float:
core_cites = []
for i in range(len(citations)):
if is_core[i]:
core_cites.append(citations[i])
core_cites.sort()
if h % 2 == 1:
# odd number in core
m_index = core_cites[(h // 2)]
else:
# even number in core
m_index = (core_cites[(h // 2) - 1] + core_cites[h // 2]) / 2
return m_index
# q2-index (Cabrerizo et al 2010)
def calculate_q2_index(h: int, m: float) -> float:
return math.sqrt(h * m)
# k-index (Ye and Rousseau 2010)
def calculate_k_index(total_cites: int, core_cites: int, total_pubs: int) -> float:
return (total_cites * core_cites) / (total_pubs * (total_cites - core_cites))
# Franceschini f-index (Franceschini and Maisano 2010)
def calculate_franceschini_f_index(citations: list, pub_years: list) -> int:
miny = max(pub_years)
maxy = min(pub_years)
for i in range(len(citations)):
if citations[i] > 0:
miny = min(miny, pub_years[i])
maxy = max(maxy, pub_years[i])
return maxy - miny + 1
# weighted h-index (Egghe and Rousseau 2008)
def calculate_weighted_h_index(citations: list, cumulative_citations: list, rank_order: list, h: int) -> float:
weighted_h_index = 0
for i in range(len(citations)):
if citations[i] >= cumulative_citations[rank_order[i]-1] / h:
weighted_h_index += citations[i]
return math.sqrt(weighted_h_index)
# normalized h-index (Sidiropoulos et al 2007)
def calculate_normalized_h_index(h: int, total_pubs: int) -> float:
return h / total_pubs
# v-index (Riikonen and Vihinen 2008)
def calculate_v_index(h: int, total_pubs: int) -> float:
return 100 * h / total_pubs
# e-index (Zhang 2009)
def calculate_e_index(core_cites: int, h: int) -> float:
return math.sqrt(core_cites - h ** 2)
# rational h-index (Ruane and Tol 2008)
def calculate_rational_h(citations: list, rank_order: list, is_core: list, h: int) -> float:
j = 0
for i in range(len(citations)):
if is_core[i]:
if citations[i] == h:
j += 1
else:
if rank_order[i] == h + 1:
j += (h + 1 - citations[i])
return h + 1 - j/(2*h + 1)
# h2-upper index (Bornmann et al 2010)
def calculate_h2_upper_index(total_cites: int, core_cites: int, h: int) -> float:
return 100 * (core_cites - h**2) / total_cites
# h2-center index (Bornmann et al 2010)
def calculate_h2_center_index(total_cites: int, h: int) -> float:
return 100 * h**2 / total_cites
# h2-tail index (Bornmann et al 2010)
def calculate_h2_tail_index(total_cites: int, core_cites: int) -> float:
return 100 * (total_cites - core_cites) / total_cites
# tapered h-index (Anderson et al 2008)
def calculate_tapered_h_index(citations: list, rank_order: list) -> float:
n = len(citations)
ht = []
for i in range(n):
ht.append(0)
if citations[i] <= rank_order[i]:
ht[i] = citations[i] / (2*rank_order[i] - 1)
else:
ht[i] = rank_order[i] / (2*rank_order[i] - 1)
for j in range(rank_order[i]+1, n+1):
ht[i] += 1 / (2*j - 1)
tapered_h_index = 0
for i in range(n):
tapered_h_index += ht[i]
return tapered_h_index
# pi-index (Vinkler 2009)
def calculate_pi_index(total_pubs: int, citations: list, rank_order: list) -> float:
p_pi = math.floor(math.sqrt(total_pubs))
pi_index = 0
for i in range(len(citations)):
if rank_order[i] <= p_pi:
pi_index += citations[i]
return pi_index / 100
# pi-rate
def calculate_pi_rate(total_pubs: int, pi_index: float) -> float:
p_pi = math.floor(math.sqrt(total_pubs))
c_pi = pi_index * 100
return c_pi / p_pi
# p-index (originally called mock hm-index) (Prathap 2010b, 2011)
def calculate_prathap_p_index(total_cites: int, total_pubs: int) -> float:
return (total_cites**2 / total_pubs)**(1/3)
# ph-ratio (Prathap 2010b, 2011)
def calculate_ph_ratio(p: float, h: int) -> float:
return p / h
# fractional p-index (pf) (Prathap 2010b, 2011)
def calculate_fractional_p_index(citations: list, n_authors: list) -> float:
pf = 0
nf = 0
for i in range(len(citations)):
pf += 1 / n_authors[i]
nf += citations[i] / n_authors[i]
return (nf**2 / pf)**(1/3)
# harmonic p-index (Prathap 2011)
def calculate_harmonic_p_index(citations: list, n_authors: list, author_pos: list) -> float:
ph = 0
nh = 0
for i in range(len(citations)):
num = 1 / author_pos[i]
denom = 0
for j in range(n_authors[i]):
denom += 1 / (j + 1)
r = num / denom
ph += r
nh += citations[i] * r
return (nh**2 / ph)**(1/3)
# hi-index (Batista et al 2006)
def calculate_hi_index(is_core: list, n_authors: list, h: int) -> float:
suma = 0
for i in range(len(n_authors)):
if is_core[i]:
suma += n_authors[i]
return h**2 / suma
# fractional pure h-index (Wan et al 2007)
def calculate_pure_h_index_frac(is_core: list, n_authors: list, h: int) -> float:
suma = 0
for i in range(len(n_authors)):
if is_core[i]:
suma += n_authors[i]
return h / math.sqrt(suma / h)
# proportional pure h-index (Wan et al 2007)
def calculate_pure_h_index_prop(is_core: list, n_authors: list, author_pos: list, h: int) -> float:
sump = 0
for i in range(len(is_core)):
if is_core[i]:
# sump += n_authors[i]*(n_authors[i] + 1) / (2*(n_authors[i] + 1 - author_pos[i]))
sump += 1 / author_effort("proportional", n_authors[i], author_pos[i])
return h / math.sqrt(sump / h)
# geometric pure h-index (Wan et al 2007)
def calculate_pure_h_index_geom(is_core: list, n_authors: list, author_pos: list, h: int) -> float:
sumg = 0
for i in range(len(is_core)):
if is_core[i]:
sumg += 1 / author_effort("geometric", n_authors[i], author_pos[i])
# sumg += (2**n_authors[i] - 1) / (2**(n_authors[i] - author_pos[i]))
return h / math.sqrt(sumg / h)
# Tol's f-index (Tol 2007)
def calculate_tol_f_index(citations: list) -> int:
n = len(citations)
harmonic_means = [0 for _ in range(n)]
tmp_index, rank_order = sort_and_rank(citations, n)
for i in range(n):
if citations[tmp_index[n - i - 1]] > 0:
harmonic_means[i] = harmonic_means[i - 1] + 1 / citations[tmp_index[n - i - 1]]
else:
harmonic_means[i] = harmonic_means[i - 1]
f = 0
for i in range(n):
if rank_order[i] / harmonic_means[rank_order[i]-1] >= rank_order[i]:
if rank_order[i] > f:
f = rank_order[i]
return f
# Tol's t-index (Tol 2007)
def calculate_tol_t_index(citations: list) -> int:
n = len(citations)
geometric_means = [0 for _ in range(n)]
tmp_index, rank_order = sort_and_rank(citations, n)
for i in range(n):
if citations[tmp_index[n - i - 1]] > 0:
geometric_means[i] = geometric_means[i - 1] + math.log(citations[tmp_index[n - i - 1]])
else:
geometric_means[i] = geometric_means[i - 1]
t = 0
for i in range(n):
if math.exp(geometric_means[rank_order[i]-1]/rank_order[i]) >= rank_order[i]:
if rank_order[i] > t:
t = rank_order[i]
return t
# mu-index (Glanzel and Schubert 2010)
def calculate_mu_index(citations: list) -> int:
n = len(citations)
tmp_cites = [c for c in citations]
tmp_cites.sort(reverse=True)
# calculate medians
median_list = [calculate_median(tmp_cites[:i+1]) for i in range(0, n)]
mu_index = 0
for i in range(n):
if median_list[i] >= i+1:
mu_index = i+1
return mu_index
# Wu w-index (Wu 2010)
def calculate_wu_w_index(citations: list, rank_order: list) -> int:
w = 0
for i in range(len(citations)):
if citations[i] >= 10 * rank_order[i]:
w += 1
return w
# Wu w-index (Wu 2010)
def calculate_wu_wq(citations: list, rank_order: list, w: int) -> int:
j = 0
for i in range(len(citations)):
if citations[i] >= 10 * rank_order[i]:
if citations[i] < 10 * (w + 1):
j += (10 * (w + 1) - citations[i])
else:
if rank_order[i] == w + 1:
j += 10 * (w + 1) - citations[i]
return j
# Wohlin w-index (Wohlin 2009)
def calculate_wohlin_w(citations: list, max_cites: int) -> float:
j = 5
nc = 1
while max_cites > j-1:
j *= 2
nc += 1
wval = []
wclass = []
for i in range(nc):
if i + 1 == 1:
wval.append(5)
else:
wval.append(2 * wval[i-1])
wclass.append(0)
for j in range(len(citations)):
if citations[j] >= wval[i]:
wclass[i] += 1
wohlin_w_index = 0
for i in range(nc):
wohlin_w_index += math.log(wval[i]) * wclass[i]
return wohlin_w_index
# contemporary h-index (Sidiropoulos et al 2007)
def calculate_contemporary_h_index(citations: list, pub_years: list, year: int) -> int:
n = len(citations)
pub_ages = publication_ages(year, pub_years)
# sc = [4*citations[i]/(1 + pub_ages[i]) for i in range(n)]
sc = [4*citations[i]/pub_ages[i] for i in range(n)]
_, tmporder = sort_and_rank(sc, n)
contemp_h_index = 0
for i in range(n):
if tmporder[i] <= sc[i]:
contemp_h_index += 1
return contemp_h_index
# hpd-index (Kosmulski 2009)
def calculate_hpd_index(citations: list, pub_years: list, year: int) -> int:
n = len(citations)
pub_ages = publication_ages(year, pub_years)
cites_per_year = citations_per_year(citations, pub_ages)
sc = [10*c for c in cites_per_year]
_, tmporder = sort_and_rank(sc, n)
hpd_index = 0
for i in range(n):
if tmporder[i] <= sc[i]:
hpd_index += 1
return hpd_index
# specific impact s-index (De Visscher 2010)
def calculate_specific_impact_s_index(pub_years: list, year: int, total_cites: int) -> float:
pub_ages = publication_ages(year, pub_years)
specific_impact_s_index = 0
for i in range(len(pub_years)):
specific_impact_s_index += 1 - math.exp(-0.1 * pub_ages[i])
if specific_impact_s_index != 0:
specific_impact_s_index = total_cites / (10 * specific_impact_s_index)
return specific_impact_s_index
# hm-index/hF-index (Schreiber 2008)
def calculate_hm_index(citations: list, n_authors: list) -> float:
hm_index = 0
cumulative_rank = 0
data = []
for i in range(len(citations)):
data.append([citations[i], n_authors[i]])
data.sort(reverse=True)
for d in data:
c = d[0]
a = d[1]
e = 1/a
cumulative_rank += e
if cumulative_rank <= c:
hm_index = cumulative_rank
return hm_index
# gF-index (fractional paper) (Egghe 2008)
def calculate_gf_paper_index(cumulative_citations: list, rank_order: list, n_authors: list, ) -> float:
gf_paper = 0
cumulative_rank = 0
for i in range(len(cumulative_citations)):
cumulative_rank += 1/n_authors[rank_order[i]-1]
if cumulative_rank**2 <= cumulative_citations[i]:
gf_paper = cumulative_rank
return gf_paper
# multidimensional h-index (Garcia-Perez 2009)
def calculate_multidimensional_h_index(citations: list, rank_order: list, is_core: list, h: int) -> list:
multi_dim_h_index = [h]
multi_used = []
for i in range(len(citations)):
if is_core[i]:
multi_used.append(True)
else:
multi_used.append(False)
j = 0
tmph = -1
while tmph != 0:
nc = len(multi_dim_h_index)
j += multi_dim_h_index[nc-1]
tmph = 0
for i in range(len(citations)):
if not multi_used[i]:
if rank_order[i] - j <= citations[i]:
multi_used[i] = True
tmph += 1
if tmph > 0:
multi_dim_h_index.append(tmph)
return multi_dim_h_index
# two-sided h-index (Garcia-Perez 2012)
def calculate_two_sided_h(citations: list, rank_order: list, h: int, multidim_h: list) -> list:
# only need to calculate the upper part of the index
# the center and tail are identical to multidimensional h
# auto-calculate for as many steps in core as equal to length of
# steps in tail
two_sided_h = [i for i in multidim_h]
j = 0
tmph = h
k = 1
while k < len(multidim_h):
j += tmph
tmph = 0
for i in range(len(citations)):
if rank_order[i] <= citations[i] - j:
tmph += 1
two_sided_h.insert(0, tmph)
k += 1
return two_sided_h
# normalized hi-index/hf-index (Wohlin 2009)
def calculate_normal_hi_index(citations: list, n_authors: list) -> int:
n = len(citations)
sc = [citations[i] / n_authors[i] for i in range(n)]
_, tmporder = sort_and_rank(sc, n)
hi_index = 0
for i in range(n):
if tmporder[i] <= sc[i]:
hi_index += 1
return hi_index
# gf-index (Egghe 2008)
def calculate_gf_cite_index(citations: list, n_authors: list) -> int:
n = len(citations)
sc = [citations[i] / n_authors[i] for i in range(n)]
tmpindex, tmporder = sort_and_rank(sc, n)
acum = [sc[tmpindex[n-1]]]
for i in range(1, n):
acum.append(acum[i-1] + sc[tmpindex[n-i-1]])
gf_cite = 0
for i in range(n):
if tmporder[i]**2 <= acum[tmporder[i]-1]:
gf_cite += 1
return gf_cite
# position-weighted h-index (Abbas 2011)
def calculate_position_weighted_h_index(citations: list, n_authors: list, author_pos: list) -> int:
n = len(citations)
sc = []
totalsum = 0
for i in range(n):
w = (2 * (n_authors[i] + 1 - author_pos[i])) / (n_authors[i] * (n_authors[i] + 1))
sc.append(citations[i] * w)
totalsum += citations[i] * w
_, tmporder = sort_and_rank(sc, n)
wh = 0
for i in range(n):
if tmporder[i] <= sc[i]:
wh += 1
return wh
# proportional weighted citation aggregate (Abbas 2011)
def calculate_prop_weight_cite_agg(citations: list, n_authors: list, author_pos: list) -> float:
weighted_aggregate = 0
for i in range(len(citations)):
w = author_effort("proportional", n_authors[i], author_pos[i])
# w = (2 * (n_authors[i] + 1 - author_pos[i])) / (n_authors[i] * (n_authors[i] + 1))
weighted_aggregate += citations[i] * w
return weighted_aggregate
# proportional weighted citation h-cut (Abbas 2011)
def calculate_prop_weight_cite_h_cut(citations: list, n_authors: list, author_pos: list) -> float:
n = len(citations)
sc = []
for i in range(n):
# w = (2 * (n_authors[i] + 1 - author_pos[i])) / (n_authors[i] * (n_authors[i] + 1))
w = author_effort("proportional", n_authors[i], author_pos[i])
sc.append(citations[i] * w)
_, tmporder = sort_and_rank(sc, n)
hcut = 0
for i in range(n):
if tmporder[i] <= sc[i]:
hcut += sc[i]
return hcut
# fractional weighted citation aggregate (Abbas 2011)
def calculate_frac_weight_cite_agg(citations: list, n_authors: list) -> float:
weighted_aggregate = 0
for i in range(len(citations)):
weighted_aggregate += citations[i] / n_authors[i]
return weighted_aggregate
# fractional weighted citation h-cut (Abbas 2011)
def calculate_frac_weight_cite_h_cut(citations: list, n_authors: list) -> float:
n = len(citations)
sc = []
for i in range(n):
sc.append(citations[i] / n_authors[i])
_, tmporder = sort_and_rank(sc, n)
hcut = 0
for i in range(n):
if tmporder[i] <= sc[i]:
hcut += sc[i]
return hcut
# Woeginger w-index (Woeginger 2008)
def calculate_woeginger_w(citations: list, rank_order: list) -> int:
w = 0
for j in range(len(citations)):
tmp_good = True
for i in range(len(rank_order)):
if rank_order[i] <= j:
if citations[i] < j - rank_order[i] + 1:
tmp_good = False
if tmp_good:
w = j
return w
# maxprod (Kosmulski 2007)
def calculate_maxprod_index(citations: list, rank_order: list) -> int:
maxprod_index = 0
for i in range(len(citations)):
if citations[i] * rank_order[i] > maxprod_index:
maxprod_index = citations[i] * rank_order[i]
return maxprod_index
# j-index (Todeschini 2011)
def calculate_todeschini_j_index(citations: list, h: int) -> float:
# constants for j-index
ndhk = 12
dhk = (500, 250, 100, 50, 25, 10, 5, 4, 3, 2, 1.5, 1.25)
sumw = 0
sumwdhk = 0
for j in range(ndhk):
sumw += 1 / (j + 1)
c = 0
for i in range(len(citations)):
if citations[i] >= h * dhk[j]:
c += 1
sumwdhk += c / (j + 1)
return h + sumwdhk/sumw
# (general) adapted pure h-index (Chai et al 2008)
def calculate_adapt_pure_h_index(sc: list) -> float:
'''
this is used to calculate the adapted pure h-index once the weighted citations (sc) are determined
'''
n = len(sc)
_, tmporder = sort_and_rank(sc, n)
j = 0
for i in range(n):
if tmporder[i] <= sc[i]:
j += 1
cite_e = 0
cite_e1 = 0
for i in range(n):
if tmporder[i] == j:
cite_e = sc[i]
elif tmporder[i] == j + 1:
cite_e1 = sc[i]
return (((j + 1)*cite_e) - (j*cite_e1)) / (cite_e - cite_e1 + 1)
# fractional adapted pure h-index (Chai et al 2008)
def calculate_adapt_pure_h_index_frac(citations: list, n_authors: list) -> float:
sc = [citations[i] / math.sqrt(n_authors[i]) for i in range(len(citations))]
return calculate_adapt_pure_h_index(sc)
# adapted pure h-index w/proportional author credit (Chai et al 2008)
def calculate_adapt_pure_h_index_prop(citations: list, n_authors: list, author_pos: list) -> float:
sc = []
for i in range(len(citations)):
# ea = n_authors[i]*(n_authors[i] + 1) / (2*(n_authors[i] + 1 - author_pos[i]))
ea = author_effort("proportional", n_authors[i], author_pos[i])
sc.append(citations[i] / math.sqrt(1/ea))
return calculate_adapt_pure_h_index(sc)
# adapted pure h-index w/geometric author credit (Chai et al 2008)
def calculate_adapt_pure_h_index_geom(citations: list, n_authors: list, author_pos: list) -> float:
sc = []
for i in range(len(citations)):
ea = author_effort("geometric", n_authors[i], author_pos[i])
sc.append(citations[i] / math.sqrt(1/ea))
return calculate_adapt_pure_h_index(sc)
# profit p-index (Aziz and Rozing 2013)
def calculate_profit_p_index(citations: list, n_authors: list, author_pos: list) -> float:
mon_equiv = []
for i in range(len(citations)):
# if n_authors[i] % 2 == 0:
# me_d = 0
# else:
# me_d = 1 / (2 * n_authors[i])
# mon_equiv.append((1 + abs(n_authors[i] + 1 - 2*author_pos[i])) /
# ((n_authors[i]**2)/2 + n_authors[i]*(1 - me_d)))
mon_equiv.append(author_effort("harmonic", n_authors[i], author_pos[i]))
monograph_equiv = sum(mon_equiv)
return 1 - monograph_equiv / len(citations)
# profit adjusted h-index (Aziz and Rozing 2013)
def calculate_profit_adj_h_index(citations: list, n_authors: list, author_pos: list) -> int:
n = len(citations)
mon_equiv = []
for i in range(n):
# if n_authors[i] % 2 == 0:
# me_d = 0
# else:
# me_d = 1 / (2 * n_authors[i])
# mon_equiv.append((1 + abs(n_authors[i] + 1 - 2*author_pos[i])) /
# ((n_authors[i]**2)/2 + n_authors[i]*(1 - me_d)))
mon_equiv.append(author_effort("harmonic", n_authors[i], author_pos[i]))
sc = [citations[i] * mon_equiv[i] for i in range(n)]
_, tmporder = sort_and_rank(sc, n)
profit_adj_h_index = 0
for i in range(n):
if tmporder[i] <= sc[i]:
profit_adj_h_index += 1
return profit_adj_h_index
# profit h-index (Aziz and Rozing 2013)
def calculate_profit_h_index(profit_adj_h: int, h: int) -> float:
return 1 - profit_adj_h / h
# hj-indices (Dorta-Gonzalez and Dorta-Gonzalez 2010)
def calculate_hj_indices(total_pubs: int, h: int, sorted_citations: list) -> list:
if total_pubs < 2 * h - 1:
j = total_pubs - h
else:
j = h - 1
hj_index = [h**2]
for i in range(1, j+1):
hj_index.append(hj_index[i-1] + (h-i)*(sorted_citations[h-i-1] - sorted_citations[h-i])
+ sorted_citations[h+i-1])
return hj_index
# iteratively weighted h-index (Todeschini and Baccini 2016)
def calculate_iteratively_weighted_h_index(multidim_h_index: list) -> float:
iteratively_weighted_h_index = 0
for p, h in enumerate(multidim_h_index):
iteratively_weighted_h_index += h / (p + 1)
return iteratively_weighted_h_index
# EM-index (Bihari and Tripathi 2017)
def calculate_em_index(citations: list, rank_order: list) -> float:
def count_cited_articles(tmpc: list) -> int:
cnt = 0
for c in tmpc:
if c > 0:
cnt += 1
return cnt
# EM-index
em_component = []
tmp_cites = [c for c in citations] # make a temporary copy of the citation counts
n_cited = count_cited_articles(tmp_cites)
while n_cited > 1:
if max(tmp_cites) == 1:
em_component.append(1)
n_cited = 0
else:
h_index = 0
for i in range(len(citations)):
if rank_order[i] <= tmp_cites[i]:
h_index += 1
em_component.append(h_index)
tmp_cites = [max(0, c-h_index) for c in tmp_cites] # subtract previous h-index from citations
n_cited = count_cited_articles(tmp_cites)
return math.sqrt(sum(em_component))
# EM'-index (Bihari and Tripathi 2017)
def calculate_emp_index(citations: list, rank_order: list) -> float:
def count_cited_articles(tmpc: list) -> int:
cnt = 0
for c in tmpc:
if c > 0:
cnt += 1
return cnt
# EM'-index
em_component = []
tmp_cites = [c for c in citations] # make a temporary copy of the citation counts
tmp_ranks = [r for r in rank_order] # make a temporary copy of the ranks
n_cited = count_cited_articles(tmp_cites)
while n_cited > 1:
if max(tmp_cites) == 1:
em_component.append(1)
n_cited = 0
else:
h_index = 0
for i in range(len(citations)):
if tmp_ranks[i] <= tmp_cites[i]:
h_index += 1
em_component.append(h_index)
# subtract h_index only from top h pubs
for i in range(len(citations)):
if tmp_ranks[i] <= tmp_cites[i]:
tmp_cites[i] = max(0, tmp_cites[i]-h_index)
n_cited = count_cited_articles(tmp_cites)
# rerank counts
_, tmp_ranks = sort_and_rank(tmp_cites, len(citations))
return math.sqrt(sum(em_component))
# alpha-index
def calculate_alpha_index(h: int, age: int) -> float:
ndecades = math.ceil(age/10)
return h / ndecades
# h-rate / m-quotient
def calculate_h_rate(h: int, age: int) -> float:
return h / age
# time-scaled h-index (Todeschini and Baccini 2016)
def calculate_time_scaled_h_index(h: int, age: int) -> float:
return h / math.sqrt(age)
# pubs per year (time-scaled)(Todeschini and Baccini 2016)
def calculate_pubs_per_year(total_pubs: int, age: int) -> float:
return total_pubs / age
# citations per year (time-scaled)(Todeschini and Baccini 2016)
def calculate_cites_per_year(total_cites: int, age: int) -> float:
return total_cites / age
# annual h-index (hIa) (Harzing et al 2014)
def calculate_annual_h_index(norm_h: int, age: int) -> float:
return norm_h / age
# CDS-index (Vinkler 2011, 2013)
def calculate_cds_index(citations: list) -> int:
maxg = 14 # largest category = more than 8192 citations
cds = 0
for c in citations:
if c < 2:
cds += 1
else:
g = 2
while c > 2**g:
g += 1
if g > maxg:
g = maxg
cds += g
return cds
# CDR-index (Vinkler 2011, 2013)
def calculate_cdr_index(total_pubs: int, cds: int) -> float:
maxg = 14 # largest category = more than 8192 citations