-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrun_hiertenmdl.py
executable file
·79 lines (67 loc) · 2.9 KB
/
run_hiertenmdl.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
#!/usr/bin/python
# -*- coding=utf-8 -*-
#################################################################################
# # CatchCore: Catching Hierarchical Dense Sub-Tensor
# Author: wenchieh
#
# Project: catchcore
# run_hiertenmdl.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_hiertenmdl.py ./example.tensor ./output/hierways.out 3 -1 binomials ','
#
#################################################################################
__author__ = 'wenchieh'
# sys
import argparse
# project
from src.toolz import initialize_tailortens
from src.mdlmodel import MDLModel, ProbModel
from src.utils.ioutils import load_hierten_indicators
models = {
'binomials': ProbModel.BINOMIALS,
'poisson': ProbModel.POISSION,
'gaussian': ProbModel.GAUSSIAN
}
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="[HierTenMDL]: Minimum Description Length for hierarchical dense subtensors.",
usage="python run_hiertenmdl.py infn_ten infn_hts dim valcol modeltype --sep")
parser.add_argument("infn_ten", help="input tensor path", type=str)
parser.add_argument("infn_hts", help="input hierarchical subtensor file path", type=str)
parser.add_argument("dim", help="feature dimensions", type=int)
parser.add_argument("valcol", help="the column of 'measurement' in the input tensor", type=int)
parser.add_argument("modeltype", help="the model type for entity distribution [default: poisson]",
type=str, default="poisson", choices=['binomials', 'poisson', 'gaussian'])
parser.add_argument("--sep", help="separator of input tensor", type=str, default=' ')
args = parser.parse_args()
infn_ten, infn_hts = args.infn_ten, args.infn_hts
ndim, valcol = args.dim, args.valcol
modeltype = str(args.modeltype)
sep = args.sep
print("Information:")
tten, _ = initialize_tailortens(infn_ten, valcol, -1, sep=sep)
print("\t tensor info: ndim:{} shape:{}".format(tten.ndim, tten.shape))
nhs, ndim, hidvs_col = load_hierten_indicators(infn_hts)
print("\t Hierarchies info: Nhs: {}, ndim: {}".format(nhs, ndim))
model = models[modeltype]
print("\t Probability model: {}".format(repr(model)))
gmdl0 = MDLModel(tten.data)
gmdl0.setting(model)
costC0 = gmdl0.measure()
print("[Original Tensor summary]\n MDL cost: {}".format(costC0))
gmdl = MDLModel(tten.data, hidvs_col)
gmdl.setting(model)
costC = gmdl.measure()
print("[With Hierarchical Dense Subtenor summary]\n MDL cost: {}, **save: {}**".format(costC, costC0 - costC))
print("done!")