Debian Codegraph @

src/dr/oldevomodel/substmodel/NewMicrosatelliteModel.java

raw symbols SCIP
1 /*
2 * NewMicrosatelliteModel.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.oldevomodel.substmodel;
27
28 import dr.inference.model.Parameter;
29 import dr.evolution.datatype.Microsatellite;
30 import dr.math.ModifiedBesselFirstKind;
31
32 /**
33 * @author Chieh-Hsi Wu
34 * Implementation of models by Watkins (2007)
35 */
36 public class NewMicrosatelliteModel extends MicrosatelliteModel {
37
38 Parameter biasConst;
39 private boolean normalize;
40 public NewMicrosatelliteModel(Microsatellite msat, FrequencyModel rootFreqModel){
41 this(msat, rootFreqModel, false);
42 biasConst = new Parameter.Default(0.5);
43 }
44 public NewMicrosatelliteModel(Microsatellite msat, FrequencyModel rootFreqModel, boolean normalize){
45 super("NewMicrosatelliteModel", msat, rootFreqModel,null);
46 this.normalize = normalize;
47 biasConst = new Parameter.Default(0.5);
48 double[] stationaryDist = new double[stateCount];
49 for(int i = 0; i < stationaryDist.length;i++){
50 stationaryDist[i] = 1.0/stateCount;
51 }
52 freqModel = new FrequencyModel(dataType, stationaryDist);
53 computeStationaryDistribution();
54 }
55 protected void storeState(){};
56 protected void restoreState(){};
57 public void getTransitionProbabilities(double distance, double[] matrix){
58 int k = 0;
59 double[] rowSums = new double[stateCount];
60 double bCVal = biasConst.getParameterValue(0);
61 for(int i = 0; i < stateCount; i ++){
62 for(int j = 0; j < stateCount; j++){
63 int n = i - j;
64 //matrix[k] = Math.exp(-distance)* Math.pow(bCVal/(1-bCVal),n/2.0)*ModifiedBesselFirstKind.bessi(2*Math.sqrt(bCVal*(1-bCVal))*distance,Math.abs(n));
65 matrix[k] = Math.exp(-distance)*ModifiedBesselFirstKind.bessi(distance,Math.abs(n));
66 rowSums[i] += matrix[k];
67 k++;
68 }
69 //System.out.println(rowSums[i]);
70
71 }
72 if(normalize){
73 k = 0;
74 for(int i = 0; i < stateCount; i ++){
75 for(int j = 0; j < stateCount; j++){
76 matrix[k] = matrix[k]/rowSums[i];
77 k++;
78 }
79 }
80 }
81 }
82
83 public double[] getRowTransitionProbabilities(double distance, int parentState){
84
85 double[] probabilities = new double[stateCount];
86 for(int i = 0; i < probabilities.length;i++){
87 int n = parentState - i;
88 probabilities[i] = Math.exp(-distance)*ModifiedBesselFirstKind.bessi(distance,Math.abs(n));
89 }
90
91 return probabilities;
92 }
93
94 public double[] getColTransitionProbabilities(double distance, int childState){
95 double[] probabilities = new double[stateCount];
96 for(int i = 0; i < probabilities.length;i++){
97 int n = i - childState;
98 probabilities[i] = Math.exp(-distance)*ModifiedBesselFirstKind.bessi(distance,Math.abs(n));
99 }
100 return probabilities;
101 }
102 public double getLogOneTransitionProbabilityEntry(double distance, int parentState, int childState){
103 return Math.log(getOneTransitionProbabilityEntry(distance, parentState, childState));
104 }
105
106 public double getOneTransitionProbabilityEntry(double distance, int parentState, int childState){
107 int n = parentState - childState;
108 double probability = Math.exp(-distance)*ModifiedBesselFirstKind.bessi(distance,Math.abs(n));
109 return probability;
110 }
111 protected void ratesChanged() {};
112 protected void setupRelativeRates(){};
113 public void setupInfinitesimalRates(){};
114 protected void frequenciesChanged() {};
115
116 public static void main(String[] args){
117 Microsatellite msat = new Microsatellite(1,5);
118 NewMicrosatelliteModel nmsatModel = new NewMicrosatelliteModel(msat, null);
119 double[] probs = new double[msat.getStateCount()*msat.getStateCount()];
120 nmsatModel.getTransitionProbabilities(1.0,probs);
121 int k =0;
122 for(int i = 0; i < msat.getStateCount(); i++){
123 for(int j = 0; j < msat.getStateCount(); j++){
124 System.out.print(probs[k++]+" ");
125 }
126 System.out.println();
127 }
128 double[] statDist = nmsatModel.getStationaryDistribution();
129 for(int i = 0; i < statDist.length; i++){
130 System.out.print(statDist[i]+" ");
131 }
132 }
133
134 }