Repository navigation
Expand file tree
/
Copy pathgenmc.cc
More file actions
157 lines (130 loc) · 3.58 KB
/
Copy pathgenmc.cc
File metadata and controls
157 lines (130 loc) · 3.58 KB
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
#include <boost/program_options/options_description.hpp>
#include <boost/program_options/parsers.hpp>
#include <boost/program_options/variables_map.hpp>
#include <boost/tokenizer.hpp>
#include <boost/token_functions.hpp>
#include <exception>
#include <set>
#include "semantic.h"
#include "config.h"
using namespace boost::program_options;
PFSA read_mc(string filename, string TYPE__)
{
connx aut;
pitilde pit, Xpit;
map < state, map < symbol, double > > pitilde_map;
CONFIG modfile(filename);
modfile.set_map<state,symbol,state>(aut,"CONNX");
modfile.set_map<state,symbol,double>(pitilde_map,"PITILDE");
PFSA *G;
state c_state=0;
for ( map < state, map < symbol,
double > >::iterator iti=pitilde_map.begin();
iti != pitilde_map.end();
iti++)
{
vector <double> vec_tmp;
for (map <symbol, double>::iterator itj=iti->second.begin();
itj != iti->second.end();
itj++)
vec_tmp.push_back(itj->second);
pit[c_state++] = vec_tmp;
}
if(TYPE__=="XPFSA")
{
pitilde pit2;
for (state j=0; j < (int)aut.size();++j)
pit2[j]= vector <double> (aut[0].size(),1.0/(aut[0].size()+0.0));
G = new PFSA(pit2,aut);
}
else
G = new PFSA (pit,aut);
G->set_Xpit(pit);
return *G;
};
//-----------------------------------
//-----------------------------------
symbol_list_& nextstatew(symbol_list_& statew,unsigned int alphabet)
{
if(statew.back()==symbol (alphabet-1))
{
statew.push_back(symbol(0));
statew.erase(statew.begin());
}
else
statew.back()=statew.back()+1;
return statew;
}
//-----------------------------------
//-----------------------------------
int main(int argc,char* argv[])
{
const string version="Causality Networks v1.0 copyright Ishanu Chattopadhyay 2015";
const string EMPTY_ARG_MESSAGE="Exiting. Type -h or --help for usage";
string configfile="config.cfg";
vector <double> partition;
unsigned int len=1000;
string DATA_DIR="across";
string DATA_TYPE="continuous";
unsigned int depth=2;
unsigned int alphabet=2;
options_description desc( "Usage: ");
desc.add_options()
("help,h", "print help message.")
("version,V", "print version number")
("datalen,x",value< unsigned int >(), "data length maximum for input sequence")
("alphabet,a",value<unsigned int>(&alphabet), "alphabet size")
("depth,d",value<unsigned int>(&depth), "depth");
positional_options_description p;
variables_map vm;
if (argc == 1)
cout <<"empty arg, type -h or --help" << endl;
try
{
store(command_line_parser(argc, argv)
.options(desc)
.run(), vm);
notify(vm);
}
catch (std::exception &e)
{
cout << endl << e.what()
<< endl << desc << endl;
}
if (vm.count("help"))
{
cout << desc << endl;
return 1;
}
if (vm.count("version"))
{
cout << version << endl;
return 1;
}
if (vm.count("datalen"))
len=vm["datalen"].as<unsigned int>();
unsigned int numstates=pow(alphabet,depth);
symbol_list_ statew(depth,symbol (0));
map<symbol_list_,state> Q;
unsigned int count=0;
Q[statew]=count;
for(unsigned int i=1;i<numstates;++i)
Q[nextstatew(statew,alphabet)]=++count;
connx aut;
map<symbol,state> row;
state thisstate=0;
for(state state_i=0;state_i<numstates;++state_i)
{
if(thisstate==numstates)
thisstate=0;
for(unsigned int j=0;j<alphabet;++j)
row[symbol(j)]=thisstate++;
aut[state_i]=row;
}
for(unsigned int i=0;i<aut.size();++i)
{
for(symbol s(0);s<alphabet;++s)
cout << aut[i][s] << " ";
cout << endl;
}
}