-
Notifications
You must be signed in to change notification settings - Fork 2
/
arg_defs.py
616 lines (603 loc) · 17.3 KB
/
arg_defs.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
def add_general_arguments(parser):
parser.add_argument(
'--experiment-prefix',
'-ep',
type=str,
default='',
required=False,
metavar='str',
help='Output csv file name prefix (default: None)')
parser.add_argument(
'--order',
type=int,
default=3,
metavar='int',
help='Tensor order (default: 3)')
parser.add_argument(
'--s',
type=int,
default=64,
metavar='int',
help='Input tensor size in each dimension (default: 64)')
parser.add_argument(
'--R',
type=int,
default=10,
metavar='int',
help='Input CP decomposition rank (default: 10)')
parser.add_argument(
'--r',
type=int,
default=10,
metavar='int',
help='Update rank size (default: 10)')
parser.add_argument(
'--R-app',
type=int,
default=10,
metavar='int',
help='Approximate rank (default: 10)')
parser.add_argument(
'--num-iter',
type=int,
default=10,
metavar='int',
help='Number of iterations (default: 10)')
parser.add_argument(
'--regularization',
type=float,
default=0.0000001,
metavar='float',
help='regularization (default: 0.0000001)')
parser.add_argument(
'--tensor',
default="random",
metavar='string',
choices=[
'random',
'random_col',
'mom_cons',
'mom_cons_sv',
'amino',
'coil100',
'timelapse',
'scf',
'embedding',
'bert-param',
'mm',
'negrandom',
'randn'
],
help='choose tensor to test, available: random, negrandom,randn, random_col, mm, mom_cons, mom_cons_sv, amino, coil100, timelapse, scf (default: random)')
parser.add_argument(
'--tlib',
default="ctf",
metavar='string',
choices=[
'ctf',
'numpy',
],
help='choose tensor library teo test, choose between numpy and ctf (default: ctf)')
parser.add_argument(
'--method',
default="DT",
metavar='string',
choices=[
'DT',
'DTLR',
'PP',
'partialPP',
'NLS',
'NLSALS',
'SNLS'
],
help='choose the optimization method: DT, PP, partialPP, DTLR (default: DT)')
parser.add_argument(
'--decomposition',
default="CP",
metavar='string',
choices=[
'CP',
'Tucker',
],
help='choose the decomposition method: CP, Tucker (default: CP)')
parser.add_argument(
'--hosvd',
type=int,
default=0,
metavar='int',
help='initialize factor matrices with hosvd or not (default: 0)')
parser.add_argument(
'--hosvd-core-dim',
type=int,
nargs='+',
help='hosvd core dimensitionality.')
parser.add_argument(
'--seed',
type=int,
default=1,
metavar='int',
help='random seed')
parser.add_argument(
'--tol',
default=1e-5,
type=float,
metavar='float',
help='Tolerance for stopping the iteration.')
parser.add_argument(
'--fit',
default=0.99,
type=float,
metavar='float',
help='Tolerance for stopping the iteration. default = 0.99')
parser.add_argument(
'--thresh',
type=int,
default=10,
metavar='int',
help='Threshhold for inverting singular vals (default : 10)')
parser.add_argument(
'--reduce-thresh',
type=int,
default=0,
metavar='int',
help='Reduce threhshold for hybrid algorithm (default : 0)')
parser.add_argument(
'--reduce-thresh-freq',
type=int,
default=5,
metavar='int',
help='Reduce threhshold iteration frequency for hybrid algorithm (default : 5)')
parser.add_argument(
'--calc-cond',
type=int,
default=1,
metavar='int',
help='Calculate CPD condition number (default : 1)')
parser.add_argument(
'--res-calc-freq',
default=1,
type=int,
metavar='int',
help='residual calculation frequency (default: 1).')
parser.add_argument(
'--save-tensor',
action='store_true',
help="Whether to save the tensor to file.")
parser.add_argument(
'--load-tensor',
type=str,
default='',
metavar='str',
help=
'Where to load the tensor if the file exists. Empty means it starts from scratch. E.g. --load-tensor results/YOUR-FOLDER/ (do not forget the /)'
)
def add_pp_arguments(parser):
parser.add_argument(
'--tol-restart-dt',
default=0.01,
type=float,
metavar='float',
help='used in pairwise perturbation optimizer, tolerance for dimention tree restart')
def add_col_arguments(parser):
parser.add_argument(
'--col',
type=float,
nargs='+',
default=[0.75, 0.75],
help='collinearity range')
def add_lrdt_arguments(parser):
parser.add_argument(
'--run-lowrank-dt',
type=int,
default=0,
metavar='int',
help='Run Dimension tree algorithm with low rank update on two of the factor matrices (default: 0)')
parser.add_argument(
'--do-lr-tol',
default=1,
type=int,
metavar='int',
help='Whether to perform low rank update by tolerance truncation.')
parser.add_argument(
'--lr-tol',
default=0.1,
type=float,
metavar='float',
help='Tolerance for low rank update truncation. This is the ratio of the singular values to be dropped. Can only be from 0 to 1.')
parser.add_argument(
'--sp-update-factor',
type=int,
default=0,
metavar='int',
help='use a sparse right factor in the low rank update scheme (default: 0)')
parser.add_argument(
'--num-lowr-init-iter',
type=int,
default=2,
metavar='int',
help='Number of initializing iterations (default: 2)')
parser.add_argument(
'--num-inter-iter',
type=int,
default=10,
metavar='int',
help='Number of intermediate iterations when running low rand dimension tree with two fixed children of the root (default: 10)')
def add_general_arguments_3d(parser):
parser.add_argument(
'--run-naive',
type=int,
default=1,
metavar='int',
help='Run naive Dimension tree algorithm (default: 1)')
parser.add_argument(
'--run-lowrank',
type=int,
default=0,
metavar='int',
help='Run Dimension tree algorithm with low rank update (default: 0)')
parser.add_argument(
'--mm-test',
type=int,
default=0,
metavar='int',
help='decompose matrix multiplication tensor as opposed to random (default: 0)')
parser.add_argument(
'--pois-test',
type=int,
default=0,
metavar='int',
help='decompose Poisson tensor as opposed to random (default: 0)')
parser.add_argument(
'--num-slices',
type=int,
default=1,
metavar='int',
help='if greater than one do sliced standard ALS with this many slices (default: 1)')
def add_sparse_arguments(parser):
parser.add_argument(
'--sp-fraction',
type=float,
default=1.,
metavar='float',
help='sparsity (default: 1)')
parser.add_argument(
'--sp-updatelowrank',
type=int,
default=0,
metavar='int',
help='mem-preserving ordering of low-rank sparse contractions (default: 0)')
parser.add_argument(
'--sp',
type=int,
default=0,
metavar='int',
help='sparse decomposition (default: 0)')
def add_nls_arguments(parser):
parser.add_argument(
'--nls-tol',
type=float,
default= 1e-05,
metavar='float',
help='tolerance for nls to stop the iteration (default: 1e-05)')
parser.add_argument(
'--cg-tol',
type=float,
default=1e-03,
metavar='float',
help='tolerance for conjugate gradient method in nls (default: 1e-03)')
parser.add_argument(
'--grad-tol',
type=float,
default= 0.1,
metavar='float',
help='gradient tolerance for nls to stop the iteration (default: 0.1)')
parser.add_argument(
'--num',
type=float,
default=0,
metavar='float',
help='For controlling the last step tolerance for nls (default:0)')
parser.add_argument(
'--switch-tol',
type=float,
default= 0.1,
metavar='float',
help='tolerance for switching to nls (default: 0.1)')
parser.add_argument(
'--own-cg',
type=bool,
default= False,
metavar='bool',
help='cg implementation for nls (default: False)')
parser.add_argument(
'--nls-iter',
type=int,
default= 2,
metavar='int',
help='Number of NLS iterations (default: 2)')
parser.add_argument(
'--als-iter',
type=int,
default= 30,
metavar='int',
help='Number of ALS iterations (default: 30)')
parser.add_argument(
'--maxiter',
type= int,
default= 0,
metavar ='int',
help ='Number of cg iterations for NLS (default: Nsr)')
parser.add_argument(
'--varying',
type=int,
default=1,
metavar='int',
help='varying regularization for nls (default: 1)')
parser.add_argument(
'--varying-fact',
type= float,
default= 2,
metavar ='float',
help ='Factor by which you would want to vary the regularization for NLS (default: 2)')
parser.add_argument(
'--lower',
type= float,
default=1e-06,
metavar='float',
help ='Lower Threshhold till we vary the regularization for NLS (default: 1e-06)')
parser.add_argument(
'--upper',
type= float,
default=1,
metavar='float',
help ='Upper Threshhold till we vary the regularization for NLS (default: 1)')
parser.add_argument(
'--diag',
type=int,
default=0,
metavar='int',
help='diagonal regularization for nls (default: 0 = False)')
parser.add_argument(
'--arm',
type=int,
default=0,
metavar='int',
help='Run with Armijo"s condition for line search (default: 0 = False)')
parser.add_argument(
'--c',
type= float,
default=1e-04,
metavar='float',
help ='Parameter for armijo"s line search (default: 1e-04)')
parser.add_argument(
'--tau',
type= float,
default=0.5,
metavar='float',
help ='Parameter for armijo"s line search (default: 0.5)')
parser.add_argument(
'--arm-iters',
type=int,
default=8,
metavar='int',
help='Max number of Armijo"s line search iterations (default: 8 )')
parser.add_argument(
'--experiment-prefix',
'-ep',
type=str,
default='',
required=False,
metavar='str',
help='Output csv file name prefix (default: None)')
parser.add_argument(
'--order',
type=int,
default=3,
metavar='int',
help='Tensor order (default: 3)')
parser.add_argument(
'--s',
type=int,
default=64,
metavar='int',
help='Input tensor size in each dimension (default: 64)')
parser.add_argument(
'--R',
type=int,
default=10,
metavar='int',
help='Input CP decomposition rank (default: 10)')
parser.add_argument(
'--r',
type=int,
default=10,
metavar='int',
help='Update rank size (default: 10)')
parser.add_argument(
'--num-iter',
type=int,
default=10,
metavar='int',
help='Number of iterations (default: 10)')
parser.add_argument(
'--regularization',
type=float,
default=0.0000001,
metavar='float',
help='regularization (default: 0.0000001)')
parser.add_argument(
'--tensor',
default="random",
metavar='string',
choices=[
'random',
'random_col',
'mom_cons',
'mom_cons_sv',
'amino',
'coil100',
'timelapse',
'scf',
'embedding',
'bert-param',
'mm',
'negrandom',
'randn'
],
help='choose tensor to test, available: random, negrandom,randn, random_col, mm, mom_cons, mom_cons_sv, amino, coil100, timelapse, scf (default: random)')
parser.add_argument(
'--tlib',
default="ctf",
metavar='string',
choices=[
'ctf',
'numpy',
],
help='choose tensor library teo test, choose between numpy and ctf (default: ctf)')
parser.add_argument(
'--method',
default="NLS",
metavar='string',
choices=[
'NLS',
'NLSALS',
'SNLS',
'DT'
],
help='choose the optimization method: DT, PP, partialPP, DTLR (default: DT)')
parser.add_argument(
'--decomposition',
default="CP",
metavar='string',
choices=[
'CP',
'Tucker',
],
help='choose the decomposition method: CP, Tucker (default: CP)')
parser.add_argument(
'--hosvd',
type=int,
default=0,
metavar='int',
help='initialize factor matrices with hosvd or not (default: 0)')
parser.add_argument(
'--hosvd-core-dim',
type=int,
nargs='+',
help='hosvd core dimensitionality.')
parser.add_argument(
'--seed',
type=int,
default=1,
metavar='int',
help='random seed')
parser.add_argument(
'--tol',
default=1e-5,
type=float,
metavar='float',
help='Tolerance for stopping the iteration.')
parser.add_argument(
'--res-calc-freq',
default=1,
type=int,
metavar='int',
help='residual calculation frequency (default: 1).')
parser.add_argument(
'--save-tensor',
action='store_true',
help="Whether to save the tensor to file.")
parser.add_argument(
'--load-tensor',
type=str,
default='',
metavar='str',
help=
'Where to load the tensor if the file exists. Empty means it starts from scratch. E.g. --load-tensor results/YOUR-FOLDER/ (do not forget the /)'
)
def add_probability_arguments(parser):
parser.add_argument(
'--num-gen',
type=int,
default=10,
metavar='int',
help='number of problems generated (default:10)')
parser.add_argument(
'--num-init',
type=int,
default=5,
metavar='int',
help='number of initializations (default:5)')
parser.add_argument(
'--conv-tol',
type=float,
default= 5e-05,
metavar='float',
help='tolerance for residual for convergence (default:5e-05)')
parser.add_argument(
'--f-R',
type=int,
default=3,
metavar='int',
help='First number for defining the range of Rank R (default:3)')
parser.add_argument(
'--l-R',
type=int,
default=6,
metavar='int',
help='Last number (including) for defining the range of R (default:6)')
parser.add_argument(
'--probmethod',
default="DT",
metavar='string',
choices=[
'DT',
'DTLR',
'PP',
'partialPP',
'NLS',
'NLSALS',
'SNLS'
],
help='choose the optimization method: DT, PP, partialPP, DTLR (default: DT)')
def get_prob_file_prefix(args):
return "-".join(filter(None, [
args.experiment_prefix,
args.decomposition,
args.probmethod,
args.tensor,
's' + str(args.s),
'fR' + str(args.f_R),
'lR'+ str(args.l_R),
#'spfrac' + str(args.sp_fraction),
#'splowrank' + str(args.sp_updatelowrank),
#'runlowrank' + str(args.run_lowrank),
#'runlowrankdt' + str(args.run_lowrank_dt),
#'numinteriter' + str(args.num_inter_iter),
#'pois' + str(args.pois_test),
#'numslices' + str(args.num_slices),
#'numinit-iter' + str(args.num_lowr_init_iter),
'regu' + str(args.regularization),
'tlib' + str(args.tlib)
]))
def get_file_prefix(args):
return "-".join(filter(None, [
args.experiment_prefix,
args.decomposition,
args.method,
args.tensor,
's' + str(args.s),
'R' + str(args.R),
'r' + str(args.r),
#'spfrac' + str(args.sp_fraction),
#'splowrank' + str(args.sp_updatelowrank),
#'runlowrank' + str(args.run_lowrank),
#'runlowrankdt' + str(args.run_lowrank_dt),
#'numinteriter' + str(args.num_inter_iter),
#'pois' + str(args.pois_test),
#'numslices' + str(args.num_slices),
#'numinit-iter' + str(args.num_lowr_init_iter),
'regu' + str(args.regularization),
'tlib' + str(args.tlib)
]))