1 /* Copyright (c) 2012 Massachusetts Institute of Technology
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to deal
5 * in the Software without restriction, including without limitation the rights
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 * copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 #include "model/TransitionInfo.h"
26 TransitionInfo::TransitionInfo()
27 : m_number_transitions_00_(0.25), m_number_transitions_01_(0.25),
28 m_number_transitions_11_(0.25), m_frequency_multiplier_(1.0)
33 TransitionInfo::TransitionInfo(double number_transitions_00_
, double number_transitions_01_
,
34 double number_transitions_11_
)
35 : m_number_transitions_00_(number_transitions_00_
), m_number_transitions_01_(number_transitions_01_
),
36 m_number_transitions_11_(number_transitions_11_
)
38 m_frequency_multiplier_
= m_number_transitions_00_
+ 2.0 * m_number_transitions_01_
+ m_number_transitions_11_
;
42 TransitionInfo::~TransitionInfo()
45 void TransitionInfo::update()
47 ASSERT(m_number_transitions_00_
>= 0.0, "[Error] Number of 0->0 transitions (" +
48 (String
)m_number_transitions_00_
+ ") must be >= 0.0!");
49 ASSERT(m_number_transitions_01_
>= 0.0, "[Error] Number of 0->1 transitions (" +
50 (String
)m_number_transitions_01_
+ ") must be >= 0.0!");
51 ASSERT(m_number_transitions_11_
>= 0.0, "[Error] Number of 1->1 transitions (" + (String
)m_number_transitions_11_
+ ") must be >= 0.0!");
53 m_probability_1_
= (m_number_transitions_01_
+ m_number_transitions_11_
) / m_frequency_multiplier_
;
54 m_probability_0_
= 1.0 - m_probability_1_
;
58 TransitionInfo
TransitionInfo::scaleFrequencyMultiplier(double frequency_multiplier_
) const
60 // A short cut if frequency_multiplier_ == m_frequency_multiplier_ to avoid excess calculations
61 if(frequency_multiplier_
== m_frequency_multiplier_
)
63 return TransitionInfo(m_number_transitions_00_
, m_number_transitions_01_
, m_number_transitions_11_
);
65 else if (frequency_multiplier_
> m_frequency_multiplier_
)
67 double freq_ratio
= frequency_multiplier_
/ m_frequency_multiplier_
;
68 double diff_num_trans_01
= m_number_transitions_01_
* (freq_ratio
- 1.0);
69 double norm_num_trans_00
= m_number_transitions_00_
* freq_ratio
+ diff_num_trans_01
;
70 double norm_num_trans_01
= m_number_transitions_01_
;
71 double norm_num_trans_11
= m_number_transitions_11_
* freq_ratio
+ diff_num_trans_01
;
73 return TransitionInfo(norm_num_trans_00
, norm_num_trans_01
, norm_num_trans_11
);
77 ASSERT(false, "[Error] Cannot scale to frequency multiplier (" + (String
) frequency_multiplier_
+
78 ") since current frequency multiplier (" + (String
) m_frequency_multiplier_
+ ") is bigger!");
82 void TransitionInfo::print(std::ostream
& ost_
) const
84 ost_
<< "[" << m_number_transitions_00_
<< ", " << m_number_transitions_01_
<< ", " << m_number_transitions_11_
<< "]";
85 ost_
<< " [" << m_number_transitions_00_
/ m_frequency_multiplier_
;
86 ost_
<< ", " << m_number_transitions_01_
*2.0 / m_frequency_multiplier_
;
87 ost_
<< ", " << m_number_transitions_11_
/ m_frequency_multiplier_
<< "]" << endl
;