-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLabelMatrix.C
58 lines (45 loc) · 1.4 KB
/
LabelMatrix.C
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
/****************************************************************
LabelMatrix.C
Copyright (C)2014 William H. Majoros ([email protected]).
This is OPEN SOURCE SOFTWARE governed by the Gnu General Public
License (GPL) version 3, as described at www.opensource.org.
****************************************************************/
#include <math.h>
#include <iostream>
#include "LabelMatrix.H"
#include "BOOM/File.H"
using namespace std;
using namespace BOOM;
LabelMatrix::LabelMatrix(const String &filename)
{
load(filename);
}
float LabelMatrix::operator()(GeneModelLabel from,GeneModelLabel to)
{
return M[from][to];
}
void LabelMatrix::load(const String &filename)
{
M.resize(NumGeneModelLabels,NumGeneModelLabels);
File f(filename);
f.getline(); // comment line -- ignore
f.getline(); // header line -- ignore
for(int i=0 ; i<NumGeneModelLabels ; ++i) {
String line=f.getline();
line.trimWhitespace();
if(line.isEmpty()) continue;
Vector<String> &fields=*line.getFields();
if(fields.size()<NumGeneModelLabels+1)
throw filename+" : error parsing matrix";
for(int j=0 ; j<NumGeneModelLabels ; ++j)
M[i][j]=fields[j+1].asFloat();
delete &fields;
}
}
void LabelMatrix::convertToLogs()
{
const int firstDim=M.getFirstDim(), secondDim=M.getSecondDim();
for(int x=0 ; x<firstDim ; ++x)
for(int y=0 ; y<secondDim ; ++y)
M[x][y]=log(M[x][y]);
}