-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrun_catchcore.py
executable file
·85 lines (73 loc) · 3.37 KB
/
run_catchcore.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
#!/usr/bin/python
# -*- coding=utf-8 -*-
#################################################################################
# # CatchCore: Catching Hierarchical Dense Sub-Tensor
# Author: wenchieh
#
# Project: catchcore
# run_catchcore.py
# Version: 1.0
# Date: Oct. 30 2018
#
# Copyright:
# This software is free of charge under research purposes.
# For commercial purposes, please contact the author.
#
# Created by @wenchieh on <10/30/2018>
#
# -------------------------------------------------------------------------------
# CatchCore Algorithm interface
#
# example:
# python run_catchcore.py ./example.tensor ./output/ 3 -1 2 3e-4 20 10 1e-6 ','
#
#################################################################################
__author__ = 'wenchieh'
# sys
import time
import argparse
# project
from src.hierten import HierTen
from src.toolz import initialize_tailortens
from src.utils.ioutils import save_hierten_indicators
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="[CatchCore]: Catching Hierarchical Dense Sub-Tensor.",
usage="python run_catchcore.py ins outs dim valcol hs p cons etas eps sep")
parser.add_argument("ins", help="input tensor path", type=str)
parser.add_argument("outs", help="result output path", type=str)
parser.add_argument("dim", help="the number of feature dimensions", type=int)
parser.add_argument("valcol", help="the column of 'measurement' in the input tensor", type=int, default=-1)
parser.add_argument("hs", help="the expected number of hierarchies", type=int, default=2)
parser.add_argument("p", help="the penalty for missing entities", type=float, default=1e-3)
parser.add_argument("cons", help="the Lagrange parameter for constraints of optimization func.", type=float, default=5)
parser.add_argument("etas", help="the density ratio for two adjacent hierarchies", type=float, default=5)
parser.add_argument("eps", help="the convergence parameter", type=float, default=1e-6)
parser.add_argument("sep", help="separator of input tensor", type=str, default=',')
args = parser.parse_args()
ins, sep, outs = args.ins, args.sep, args.outs
hs, p, cons, etas, eps = args.hs, args.p, args.cons, args.etas, args.eps
dims, valcol = args.dim, args.valcol
outfn = 'hierways.out'
print("\nhs:{}\npenalty: {}\netas: {}\nconstraint:{}\neps:{}\n".format(hs, p, etas, cons, eps))
starts = time.time()
tten, label = initialize_tailortens(
ins, valcol, -1, sep=sep, usecols=range(max([valcol, dims])))
print("load data @{}s".format(time.time() - starts))
tten.info()
hrten = HierTen(tten.tosptensor())
hrten.setting(hs, p, cons)
algtm = time.time()
print("total construct @{}s\n".format(algtm - starts))
xhs = hrten.hieroptimal(max_iters=100, eps=eps, convtol=1e-6)
runtm = time.time() - algtm
print("\n Algorithm run @{}s \n".format(runtm))
vhs, hidx, hnnzs, hshapes, hdens = hrten.hierarchy_indicator(xhs)
print("detect index run @{}s".format(time.time() - algtm))
hrten.dump()
print("Hierarchies density: ", hdens)
if len(hidx) > 0:
hr_idx = list()
for h in range(len(hidx)):
hr_idx.append(tten.selectormap(hidx[h], range(dims)))
save_hierten_indicators(outs + outfn, hr_idx)
print("done! " + ' @%.2f' % (runtm))