├── .gitignore ├── LICENSE ├── README ├── constraint_checker ├── README.md ├── check_fossils.R ├── constraint_table.csv └── phy.tre ├── deps ├── ADOL-C-2.6.3.tgz ├── adol-c_git_saved.tar.gz └── nlopt-2.4.2.tar.gz ├── examples ├── M1155.cppr8s ├── M1155.ind8s ├── M1155.inr8s ├── M1155.log ├── M1155.nex ├── M1155.rates ├── M1155.tre ├── big_test.cppr8s ├── clock.cppr8s ├── clock.nex ├── clock.r8s_out ├── clock.tre ├── comm_mol_rr.tre ├── initial_lf.tre ├── initial_pl.tre ├── nonclock.tre ├── pl4203.chisq ├── pl4203.chisq_r8s ├── pl4203.cppr8s ├── pl4203.ind8s ├── pl4203.inr8s ├── pl4203.log ├── pl4203.nex ├── pl4203.r8s.out_1 ├── pl4203.r8s.out_2 ├── pl4203.tre ├── rosales_rr.tre ├── test.cppr8s ├── test.nex ├── test.r8s.2 ├── test.tre ├── vib.cppr8s ├── vib.nex └── vib.tre ├── src ├── Makefile.in ├── README ├── config.h.in ├── configure ├── configure.ac ├── main.cpp ├── myrad.h ├── myradops.cpp ├── node.cpp ├── node.h ├── node_object.h ├── optim_options.cpp ├── optim_options.h ├── optimize_nlopt.cpp ├── optimize_nlopt.h ├── optimize_tnc.cpp ├── optimize_tnc.h ├── pl_calc_parallel.cpp ├── pl_calc_parallel.h ├── rad.h ├── radops.cpp ├── siman_calc_par.cpp ├── siman_calc_par.h ├── string_node_object.h ├── tnc.c ├── tnc.h ├── tree.cpp ├── tree.h ├── tree_reader.cpp ├── tree_reader.h ├── tree_utils.cpp ├── tree_utils.h ├── utils.cpp ├── utils.h └── vector_node_object.h └── vagrant_instructions /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.d 6 | 7 | # Compiled Dynamic libraries 8 | *.so 9 | *.dylib 10 | 11 | # Compiled Static libraries 12 | *.lai 13 | *.la 14 | *.a 15 | 16 | # Other stuff 17 | .DS_Store 18 | ._* 19 | *~ 20 | Makefile 21 | configure 22 | config.h 23 | config.log 24 | config.status 25 | autom4te.cache 26 | treePL 27 | 28 | # Eclipse stuff 29 | .cproject 30 | .project 31 | .settings 32 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | treePL (/ˈtriːpəl/) is a phylogenetic penalized likelihood program. 2 | 3 | More information on installation can be found on the wiki https://github.com/blackrim/treePL/wiki 4 | 5 | Constraint checking (R) code, along with example data, is available here: https://github.com/blackrim/treePL/tree/master/constraint_checker 6 | -------------------------------------------------------------------------------- /constraint_checker/README.md: -------------------------------------------------------------------------------- 1 | ## Constraint Checking 2 | 3 | ``` 4 | Failed setting feasible start rates/dates after 10 attempts. Aborting. 5 | ``` 6 | The error above is produced when data submitted to a treePL analysis possess some issue(s) that prevents the program from generating some initial rates/dates that can be optimized through penalized likehood. 7 | 8 | From experience dealing with troubleshooting many such issues, one (or more) of the following is invariably the culprit: 9 | 10 | 1. Inconsistent constraints. For example, calibrating a descendant node with a larger minimum age than that specified for one of its ancestral nodes. 11 | 12 | 2. Having multiple (perhaps conflicting) constraints applied to the same node. This almost certainly involves a problem involving the MRCA statement. In trees of many hundreds or thousands of tips, two different pairs of tips can easily have the same MRCA. In a slightly different manner, the relationships in the tree may not coincide exactly with expectations; for example, if a (say) family is not recovered to be monophyletic in the present tree, then selection of a different representative taxon within that expected group may define a different MRCA node. [Aside: the code [here](https://gist.github.com/josephwb/f3d35f8833a07f71002af7726b12652b) may help diagnose the last situation]. 13 | 14 | 3. The tree is unrooted. The meaning of 'ancestral' and 'descendant' nodes is ambiguous when a tree is unrooted. The code below can tell you if your tree is unrooted, but (because taxonomy is not involved) does not know the tree _shoiuld_ be rooted. 15 | 16 | 17 | To help deal with these issues, I've put together some R code that you can use to vet your data. Example data (with built-in issues) is also provided. 18 | 19 | ### How To Use 20 | 21 | Put your data in the present directory; for now we will use the example data provided. In R, set your working directory to the present directory (I'll use my own system path here): 22 | 23 | ``` 24 | setwd("/home/josephwb/Work/Phylogenetics/treePL/constraint_checker"); 25 | ``` 26 | (Yes, I use semicolons in R, and I will never _not_ do so ;)). Next, source the functions file: 27 | ``` 28 | source("check_fossils.R"); 29 | ``` 30 | This will make two functions available: 31 | ``` 32 | check_constraints_consistent(phy, cnstrnts); 33 | ``` 34 | which does the actual constraint checking, and 35 | ``` 36 | writeTreePLConfig(phyname, nsites, ndconstrnts, nthreads=8, writeIt=TRUE); 37 | ``` 38 | which can write out a treePL config file (if desired). 39 | 40 | Let's run it with the example data, shall we? Let us read in our data. First, the tree: 41 | ``` 42 | phy <- read.tree("phy.tre"); 43 | ``` 44 | The tree includes node labels (matches 'Constraint.name' in constraint table, below), which can be visualized in FigTree so the exmaple can be easily followed. 45 | 46 | Now load the csv file containing information on the names, positions, and ages of constraints: 47 | ``` 48 | fossils <- read.csv("constraint_table.csv", stringsAsFactors=FALSE, na.strings=c("", " ", "NA")); 49 | ``` 50 | We can look at the structure of the constraint table by just printing it out: 51 | ``` 52 | fossils; 53 | Constraint.name mrca_L mrca_R Min Max info 54 | 1 Root taxon_1 taxon_39 70.1 86.5 55 | 2 CladeA_crown taxon_1 taxon_14 26.1 31.3 younger than descendant node FossilW 56 | 3 FossilW taxon_5 taxon_14 34.7 52.3 older than ancestral node CladeA_crown 57 | 4 CladeB_crown taxon_15 taxon_25 43.7 57.6 58 | 5 CladeC_stem taxon_15 taxon_39 49.4 56.2 59 | 6 CladeC_crown taxon_26 taxon_39 38.9 43.7 60 | 7 FossilX taxon_26 taxon_38 27.9 34.6 younger than descendant node FossilY 61 | 8 FossilY taxon_26 taxon_35 35.1 37.2 older than ancestral node FossilX 62 | 9 FossilZ taxon_26 taxon_34 27.3 29.2 dates same node as FossilQ but is younger 63 | 10 FossilQ taxon_27 taxon_33 31.9 34.6 dates same node as FossilZ but is older 64 | ``` 65 | The table _must_ contain the columns (in any order): 66 | 'Constraint.name', 'mrca_L', 'mrca_R', 'Min', and 'Max'. 'mrca_L' and 'mrca_R' are two taxa which share a common ancestor at some node in the tree; the 'L' (left) and 'R' (right) are arbitrary, and can be thought of instead as 'tip1' and 'tip2' in any order. The `info` column present in this example is not necessary, and here just explains how introduced issues should be interperted. 67 | 68 | Ok, let's try it out: 69 | ``` 70 | res <- check_constraints_consistent(phy=phy, cnstrnts=fossils); 71 | [1] "Error. The following constraints map to the same node:" 72 | [1] " 'FossilZ' (minage=27.3)." 73 | [1] " 'FossilQ' (minage=31.9)." 74 | [1] "Problem with constraint 'FossilW' (minage = 34.7)." 75 | [1] " Ancestor 'CladeA_crown' has a younger minage (26.1)." 76 | [1] "Problem with constraint 'FossilY' (minage = 35.1)." 77 | [1] " Ancestor 'FossilX' has a younger minage (27.9)." 78 | [1] "Problem with constraint 'FossilQ' (minage = 31.9)." 79 | [1] " Ancestor 'FossilX' has a younger minage (27.9)." 80 | ``` 81 | As can be seen, several issues are found. Let's look at the results: 82 | ``` 83 | res; 84 | constraint node min max rtax ltax keep notes 85 | 1 Root 40 70.1 86.5 taxon_39 taxon_1 TRUE good 86 | 2 CladeA_crown 41 26.1 31.3 taxon_14 taxon_1 FALSE invalidated 87 | 3 FossilW 45 34.7 52.3 taxon_14 taxon_5 TRUE good 88 | 4 CladeB_crown 55 43.7 57.6 taxon_25 taxon_15 TRUE good 89 | 5 CladeC_stem 54 49.4 56.2 taxon_39 taxon_15 TRUE good 90 | 6 CladeC_crown 65 38.9 43.7 taxon_39 taxon_26 TRUE good 91 | 7 FossilX 66 27.9 34.6 taxon_38 taxon_26 FALSE invalidated 92 | 8 FossilY 67 35.1 37.2 taxon_35 taxon_26 TRUE good 93 | 9 FossilZ 68 27.3 29.2 taxon_34 taxon_26 FALSE redundant,younger 94 | 10 FossilQ 68 31.9 34.6 taxon_33 taxon_27 TRUE good 95 | ``` 96 | If you like, you can write the results to file for your records: 97 | ``` 98 | write.csv(res, row.names=FALSE, quote=FALSE, file="fossil_analysis_results.csv"); 99 | ``` 100 | If you are happy with the results, we can clean up the table a bit: 101 | ``` 102 | # prune the invalidated constraints 103 | res <- res[res$keep,]; 104 | # and pitch columns that serve no future purpose 105 | res <- within(res, rm(keep, notes)); 106 | ``` 107 | If desired, you can even write a treePL config file using the updated constraints. *NOTE:* make sure to use variable values that match your data! Below I use made up values for the tree name and number of sites. Note also that some generic default settings are, er, set, so make sure you update these to what is approproriate (e.g., smooth, thorough, log_pen, cvstart, etc.; you can see what those (and other) settings are [here](https://github.com/blackrim/treePL/wiki/Run-Options)). 108 | ``` 109 | writeTreePLConfig(phyname="My_awesome_phylogeny.tre", nsites=131313, ndconstrnts=res, nthreads=8); 110 | ``` 111 | For the example data, the following config file is produced: 112 | ``` 113 | ## Tree Information ## 114 | 115 | treefile = My_awesome_phylogeny.tre 116 | outfile = My_awesome_phylogeny.d8s.tre 117 | cvoutfile = My_awesome_phylogeny.tre.cv.out 118 | 119 | 120 | ## Temporal Calibrations ## 121 | 122 | mrca = Root taxon_39 taxon_1 123 | max = Root 86.5 124 | min = Root 70.1 125 | 126 | mrca = FossilW taxon_14 taxon_5 127 | max = FossilW 52.3 128 | min = FossilW 34.7 129 | 130 | mrca = CladeB_crown taxon_25 taxon_15 131 | max = CladeB_crown 57.6 132 | min = CladeB_crown 43.7 133 | 134 | mrca = CladeC_stem taxon_39 taxon_15 135 | max = CladeC_stem 56.2 136 | min = CladeC_stem 49.4 137 | 138 | mrca = CladeC_crown taxon_39 taxon_26 139 | max = CladeC_crown 43.7 140 | min = CladeC_crown 38.9 141 | 142 | mrca = FossilY taxon_35 taxon_26 143 | max = FossilY 37.2 144 | min = FossilY 35.1 145 | 146 | mrca = FossilQ taxon_33 taxon_27 147 | max = FossilQ 34.6 148 | min = FossilQ 31.9 149 | 150 | 151 | ## Run Settings ## 152 | 153 | # Make sure the settings below match your data! 154 | 155 | numsites = 131313 156 | smooth = 10 157 | thorough 158 | log_pen 159 | nthreads = 8 160 | plsimaniter = 200000 161 | #cv 162 | #randomcv 163 | cvstart = 1000 164 | cvstop = 0.01 165 | prime 166 | ``` -------------------------------------------------------------------------------- /constraint_checker/check_fossils.R: -------------------------------------------------------------------------------- 1 | require(ape); 2 | require(phangorn); 3 | 4 | ## complaints/suggestions to @josephwb phylo.jwb@gmail.com 5 | 6 | # purpose: given a table of fossil constraints and a tree: 7 | # 1. check that fossil ages are consistent with topology (i.e., descendant not older than ancestors) 8 | # 2. check if fossils map to same node (get rid of younger one) 9 | # 3. produce output files for dating (e.g., treePL) 10 | 11 | ## functions are at the top of the file, commands (and example data) are below (commented out) 12 | ## see example commands in the README.md 13 | 14 | ################################################################################ 15 | 16 | # map each constraint in the tree. then check if any ancestors are younger than descendants 17 | # this does not currently check max ages 18 | check_constraints_consistent <- function (phy, cnstrnts) { 19 | 20 | if (!is.rooted(phy)) { 21 | stop("\n\nWARNING: tree is unrooted! Constraint checking is not possible. Stopping.\n\n"); 22 | } 23 | 24 | rtax <- cnstrnts$mrca_R; 25 | ltax <- cnstrnts$mrca_L; 26 | 27 | # map mrcas to nodes in the tree 28 | nds <- NULL; # mrca nodes 29 | for (i in 1:length(cnstrnts[,1])) { 30 | nds <- c(nds, getMRCA(phy, c(ltax[i], rtax[i]))); 31 | } 32 | 33 | # set up df to return 34 | df <- as.data.frame(cbind(constraint=cnstrnts$Constraint.name, node=nds, min=cnstrnts$Min, 35 | max=cnstrnts$Max, rtax=rtax, ltax=ltax), stringsAsFactors=FALSE); 36 | class(df[,2]) <- "numeric"; 37 | class(df[,3]) <- "numeric"; 38 | class(df[,4]) <- "numeric"; 39 | 40 | # decisions and notes. default to accept 41 | keep <- rep(TRUE, length(df[,1])); 42 | notes <- rep("good", length(df[,1])); 43 | 44 | ## error-checking 45 | # first, check for constraints mapping to the same node 46 | if (any(duplicated(nds))) { 47 | d.nds <- as.numeric(names(which(table(nds) > 1))); 48 | for (i in 1:length(d.nds)) { 49 | idx <- which(df$node == d.nds[i]); 50 | i.ages <- df$min[idx]; 51 | print("Error. The following constraints map to the same node:"); 52 | for (j in 1:length(idx)) { 53 | print(paste0(" '", cnstrnts$Constraint.name[idx[j]], "' (minage=", cnstrnts$Min[idx[j]], 54 | ").")); 55 | } 56 | toDrop <- which(i.ages != max(i.ages)); # *** have not considered identical mins yet 57 | keep[idx[toDrop]] <- "FALSE"; 58 | notes[idx[toDrop]] <- "redundant,younger"; 59 | } 60 | } 61 | 62 | # finally, check for consistency (i.e. ancestors are not younger than descendants) 63 | for (i in 1:length(nds)) { 64 | pnds <- Ancestors(phy, df$node[i], "all"); 65 | # throw out nodes without constraints 66 | pnds <- pnds[pnds %in% df$node]; 67 | if (length(pnds) > 0) { 68 | i.age <- df$min[i]; 69 | p.ages <- df$min[match(pnds, df$node)]; 70 | if (any(i.age >= p.ages)) { 71 | print(paste0("Problem with constraint '", df$constraint[i], "' (minage = ", i.age, ").")); 72 | # give details 73 | idx <- which(p.ages <= i.age); 74 | for (ii in 1:length(idx)) { 75 | iidx <- which(df$node == pnds[idx[ii]]); 76 | print(paste0(" Ancestor '", df$constraint[iidx], 77 | "' has a younger minage (", df$min[iidx], ").")); 78 | keep[iidx] <- FALSE; 79 | notes[iidx] <- "invalidated"; 80 | } 81 | } 82 | } 83 | } 84 | 85 | df <- cbind(df, keep, notes); 86 | class(df$keep) <- "logical"; 87 | 88 | if (all(df$keep)) { 89 | print("No issues detected!"); 90 | } 91 | return(df); 92 | } 93 | 94 | # write a treePL config file to pwd for an individual source tree 95 | # ndconstrnts is a dataframe with cols: constraint, node, min, max, rtax, ltax 96 | writeTreePLConfig <- function (phyname, nsites, ndconstrnts, nthreads=8, writeIt=TRUE) { 97 | 98 | treeInfo <- paste( 99 | "## Tree Information ##\n", 100 | paste0("treefile = ", phyname), 101 | paste0("outfile = ", sub(".tre", ".d8s.tre", phyname)), 102 | paste0("cvoutfile = ", phyname, ".cv.out\n"), sep="\n"); 103 | 104 | cals <- "\n\n## Temporal Calibrations ##\n"; 105 | # calibrations 106 | for (j in 1:length(ndconstrnts[,1])) { 107 | # calib name 108 | calName <- as.character(ndconstrnts$constraint[j]); 109 | indiv <- paste0("\nmrca = ", calName, " ", ndconstrnts$rtax[j], " ", ndconstrnts$ltax[j], "\n"); 110 | 111 | # max constraint 112 | indiv <- paste0(indiv, paste0("max = ", calName, " ", ndconstrnts$max[j], "\n")); 113 | 114 | # min constraint 115 | indiv <- paste0(indiv, paste0("min = ", calName, " ", ndconstrnts$min[j], "\n")); 116 | cals <- paste0(cals, indiv); 117 | } 118 | # run conditions 119 | runTreePL <- paste( 120 | "\n\n## Run Settings ##\n", 121 | "# Make sure the settings below match your data!\n", 122 | paste0("numsites = ", nsites), 123 | "smooth = 10", # what is a reasonable general value? 124 | "thorough", 125 | "log_pen", 126 | paste0("nthreads = ", nthreads), 127 | "plsimaniter = 200000", 128 | "#cv", 129 | "#randomcv", 130 | "cvstart = 1000", 131 | "cvstop = 0.01", 132 | "prime", sep="\n"); 133 | 134 | toWrite <- paste0(treeInfo, cals, runTreePL); 135 | print(toWrite); 136 | if (writeIt) { # set to false for development 137 | write(toWrite, file=paste0(sub(".tre", ".treepl.config", phyname))); 138 | } 139 | } 140 | 141 | ################################################################################ 142 | 143 | ### The following commands involving the example data are commented-out so this file can be sourced. 144 | ## The commands can also be found in the README.md 145 | 146 | ## dummy example data 147 | ## tree. includes node labels (matches constraint table, below), which can be visualized in FigTree 148 | #phy <- read.tree("phy.tre"); 149 | 150 | ## constraint data. must minimally have column names (in any order): 151 | ## 'Constraint.name', 'mrca_L', 'mrca_R', 'Min', 'Max' 152 | ## can have extra columns. this example includes 'info' which 153 | #fossils <- read.csv("constraint_table.csv", stringsAsFactors=FALSE, na.strings=c("", " ", "NA")); 154 | 155 | ## let's run it! 156 | #res <- check_constraints_consistent(phy=phy, cnstrnts=fossils); 157 | ## look at the results 158 | #res; 159 | ## write a copy of the results for records 160 | #write.csv(res, row.names=FALSE, quote=FALSE, file="fossil_analysis_results.csv"); 161 | 162 | ## if you are happy with the results, we can prune the invalidated constraints 163 | #res <- res[res$keep,]; 164 | ## and pitch columns that serve no future purpose 165 | #res <- within(res, rm(keep, notes)); 166 | 167 | ## write a treePL config file. make sure to use variable values that match your data! 168 | #writeTreePLConfig(phyname="My_awesome_phylogeny.tre", nsites=131313, ndconstrnts=res, nthreads=8); 169 | -------------------------------------------------------------------------------- /constraint_checker/constraint_table.csv: -------------------------------------------------------------------------------- 1 | Constraint.name,mrca_L,mrca_R,Min,Max,info 2 | Root,taxon_1,taxon_39,70.1,86.5, 3 | CladeA_crown,taxon_1,taxon_14,26.1,31.3,younger than descendant node FossilW 4 | FossilW,taxon_5,taxon_14,34.7,52.3,older than ancestral node CladeA_crown 5 | CladeB_crown,taxon_15,taxon_25,43.7,57.6, 6 | CladeC_stem,taxon_15,taxon_39,49.4,56.2, 7 | CladeC_crown,taxon_26,taxon_39,38.9,43.7, 8 | FossilX,taxon_26,taxon_38,27.9,34.6,younger than descendant node FossilY 9 | FossilY,taxon_26,taxon_35,35.1,37.2,older than ancestral node FossilX 10 | FossilZ,taxon_26,taxon_34,27.3,29.2,dates same node as FossilQ but is younger 11 | FossilQ,taxon_27,taxon_33,31.9,34.6,dates same node as FossilZ but is older 12 | -------------------------------------------------------------------------------- /constraint_checker/phy.tre: -------------------------------------------------------------------------------- 1 | ((((taxon_1:0.8951285032603051,taxon_2:0.8951285032603051):0.8722580757824496,(taxon_3:0.4411472314985434,taxon_4:0.4411472314985434):1.3262393475442114):0.1345131730304563,((((taxon_5:0.0495678240977995,taxon_6:0.0495678240977995):0.6965606377875024,taxon_7:0.7461284618853019):0.3990740653679619,(taxon_8:0.4034552276865715,taxon_9:0.4034552276865715):0.7417472995666923):0.2930232184658559,(taxon_10:1.3498735826387889,(taxon_11:1.3057291716372839,((taxon_12:0.894049080355213,taxon_13:0.894049080355213):0.2720653140214551,taxon_14:1.1661143943766681):0.1396147772606158):0.044144411001505):0.0883521630803308)FossilW:0.4636740063540914)CladeA_crown:0.7271232607617275,(((taxon_15:1.6045020720925285,(taxon_16:0.4391994651765021,taxon_17:0.4391994651765021):1.1653026069160264):0.6779059634373374,(((taxon_18:0.4326145911432153,taxon_19:0.4326145911432153):0.8979756480302583,(taxon_20:1.2297156583296323,(taxon_21:0.5059101456701085,taxon_22:0.5059101456701085):0.7238055126595238):0.1008745808438414):0.2246605460194486,(taxon_23:1.2104417662193678,(taxon_24:0.360107164834838,taxon_25:0.360107164834838):0.8503346013845299):0.3448090189735544):0.7271572503369437)CladeB_crown:0.2407971412635503,(((((taxon_26:0.7434384207553382,taxon_27:0.7434384207553382):0.962070786183291,((taxon_28:0.1244187506919863,taxon_29:0.1244187506919863):1.1047375722310691,((taxon_30:0.4452011150583801,taxon_31:0.4452011150583801):0.4095995207076797,(taxon_32:0.1457498526184207,(taxon_33:0.0490783506061279,taxon_34:0.0490783506061279):0.0966715020122928):0.7090507831476391):0.3743556871569955):0.4763528840155739)FossilZ_Q:0.1221180131780224,taxon_35:1.8276272201166517)FossilY:0.2013671674746954,(taxon_36:0.1315458293886045,(taxon_37:0.1204789990761825,taxon_38:0.1204789990761825):0.0110668303124219):1.8974485582027425)FossilX:0.2298498069681877,taxon_39:2.2588441945595346)CladeC_crown:0.2643609822338815)CladeC_stem:0.1058178360415223)Root; 2 | -------------------------------------------------------------------------------- /deps/ADOL-C-2.6.3.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blackrim/treePL/aa775e79b80749e5383ca2748a2916741699ec41/deps/ADOL-C-2.6.3.tgz -------------------------------------------------------------------------------- /deps/adol-c_git_saved.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blackrim/treePL/aa775e79b80749e5383ca2748a2916741699ec41/deps/adol-c_git_saved.tar.gz -------------------------------------------------------------------------------- /deps/nlopt-2.4.2.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blackrim/treePL/aa775e79b80749e5383ca2748a2916741699ec41/deps/nlopt-2.4.2.tar.gz -------------------------------------------------------------------------------- /examples/M1155.cppr8s: -------------------------------------------------------------------------------- 1 | treefile = M1155.tre 2 | #checkconstraints 3 | #sample = 1 4 | smooth = 1 5 | cv 6 | [randomcv] 7 | numsites = 2256 8 | mrca = xx1 Hypocrea_lutea Gibberella_pulicaris 9 | mrca = xx2 Microascus_cirrosus Petriella_setifera 10 | mrca = xx3 Albertiniella_polyporicola Kionochaeta_ramifera 11 | mrca = xx4 Albertiniella_polyporicola Pleospora_betae 12 | max = xx1 136 13 | min = xx1 136 14 | min = xx2 112 15 | max = xx2 112 16 | min = xx3 250 17 | max = xx3 250 18 | min = xx4 300 19 | max = xx4 300 20 | #collapse 21 | [verbose] 22 | #thorough 23 | #cviter = 3 24 | [paramverbose] 25 | #lfsimaniter = 1000 26 | #plsimaniter = 10000 27 | #pliter = 10 28 | [prime] 29 | opt = 2 30 | optad = 0 31 | moredetailad 32 | optcvad = 2 33 | -------------------------------------------------------------------------------- /examples/M1155.ind8s: -------------------------------------------------------------------------------- 1 | ((((((Albertiniella_polyporicola:143.215695,Cryptendoxyla_hypophloia:143.215695):64.499273,(Camarops_microspora:175.501314,(((Chaetomium_elatum:51.522216,Madurella_mycetomatis:51.522216):25.426888,Lasiosphaeria_ovina:76.949104):26.952802,Sordaria_fimicola:103.901906):71.599408):32.213653):27.920634,((((Apiospora_sinensis:55.947708,Arthrinium_phaeospermum:55.947708):102.764370,(((Graphostroma_platystoma:3.461036,Pestalosphaeria_hansenii:3.461036):83.283022,Microdochium_nivale:86.744058):45.412152,Hyponectria_buxi:132.156210,(Hypoxylon_fragiforme:79.698344,Xylaria_carpophila:79.698344):52.457865):26.555868):12.896898,Diatrype_disciformis:171.608976):49.489433,((Ceratosphaeria_lampadophora:126.043534,(Gaeumannomyces_graminis:55.826580,Magnaporthe_grisea:55.826580):70.216954):84.221943,((((Cryphonectria_parasitica:40.574383,Endothia_gyrosa:40.574383):18.089056,(Diaporthe_phaseolorum:27.602392,Leucostoma_persoonii:27.602392):31.061046):103.951390,(((Phaeoacremonium_griseorubrum:13.888022,Phaeoacremonium_parasiticum:13.888022,Phaeoacremonium_tardicrescens:13.888022):13.572116,Phaeoacremonium_theobromatis:27.460138,Phaeoacremonium_viticola:27.460138,(Togninia_fraxinopennsylvanica:13.962288,Togninia_novaezealandiae:13.962288):13.497850,Togninia_minima:27.460138):24.013084,(Phaeoacremonium_sphinctrophorum_DQ173149:14.615643,Phaeoacremonium_sphinctrophorum_DQ173150:14.615643):36.857580):111.141606):42.264319,((Pleurostoma_ootheca:13.825689,Pleurostomophora_repens:13.825689):35.079851,Pleurostomophora_richardsiae:48.905541):155.973607):5.386330,(Endomyces_scopularum:8.392279,Sporothrix_schenckii:8.392279,Ophiostoma_stenoceras:8.392279):201.873198,(Gnomonia_setacea:36.642325,Gnomoniella_fraxini:36.642325):173.623152):10.832932):14.537193):3.630211,(Calosphaeria_pulchella:81.151436,(Togniniella_acerosa_AY761072:3.245408,Togniniella_acerosa_AY761073:3.245408):77.906028):158.114377):10.734187,((Ceratocystis_fimbriata:165.375355,(Graphium_penicillioides:149.020410,(Microascus_cirrosus:112.000000,(Petriella_setifera:79.173840,Pseudallescheria_boydii:79.173840):32.826160)xx2:37.020410):16.354945):43.153118,(((Chaetopsina_fulva:113.944447,Cordyceps_ophioglossoides:113.944447,(Gibberella_pulicaris:79.044790,Nectria_pseudotrichia:79.044790):34.899657):22.055553,Hypocrea_lutea:136.000000)xx1:52.920011,Sphaerodothis_acrocomiae:188.920011):19.608462):41.471527,(Chaetosphaeria_curvispora:73.634866,Kionochaeta_ramifera:73.634866):176.365134)xx3:31.171354,(Cochliobolus_sativus:72.437873,Pleospora_betae:72.437873):208.733481); 2 | -------------------------------------------------------------------------------- /examples/M1155.inr8s: -------------------------------------------------------------------------------- 1 | ((((((Albertiniella_polyporicola:0.000130,Cryptendoxyla_hypophloia:0.000130):0.000138,(Camarops_microspora:0.000081,(((Chaetomium_elatum:0.000069,Madurella_mycetomatis:0.000017):0.000052,Lasiosphaeria_ovina:0.000052):0.000066,Sordaria_fimicola:0.000098):0.000093):0.000110):0.000159,((((Apiospora_sinensis:0.000032,Arthrinium_phaeospermum:0.000134):0.000108,(((Graphostroma_platystoma:0.000128,Pestalosphaeria_hansenii:0.000128):0.000128,Microdochium_nivale:0.000077):0.000107,Hyponectria_buxi:0.000081,(Hypoxylon_fragiforme:0.000045,Xylaria_carpophila:0.000183):0.000126):0.000117):0.000137,Diatrype_disciformis:0.000124):0.000179,((Ceratosphaeria_lampadophora:0.000042,(Gaeumannomyces_graminis:0.000284,Magnaporthe_grisea:0.000008):0.000207):0.000204,((((Cryphonectria_parasitica:0.000011,Endothia_gyrosa:0.000022):0.000049,(Diaporthe_phaseolorum:0.000144,Leucostoma_persoonii:0.000113):0.000128):0.000124,(((Phaeoacremonium_griseorubrum:0.000032,Phaeoacremonium_parasiticum:0.000032,Phaeoacremonium_tardicrescens:0.000032):0.000033,Phaeoacremonium_theobromatis:0.000016,Phaeoacremonium_viticola:0.000016,(Togninia_fraxinopennsylvanica:0.000032,Togninia_novaezealandiae:0.000032):0.000033,Togninia_minima:0.000016):0.000037,(Phaeoacremonium_sphinctrophorum_DQ173149:0.000150,Phaeoacremonium_sphinctrophorum_DQ173150:0.000031):0.000120):0.000139):0.000199,((Pleurostoma_ootheca:0.000498,Pleurostomophora_repens:0.000036):0.000406,Pleurostomophora_richardsiae:0.000009):0.000484):0.000319,(Endomyces_scopularum:0.000055,Sporothrix_schenckii:0.000055,Ophiostoma_stenoceras:0.000155):0.000114,(Gnomonia_setacea:0.000157,Gnomoniella_fraxini:0.000133):0.000153):0.000234):0.000263):0.000233,(Calosphaeria_pulchella:0.000088,(Togniniella_acerosa_AY761072:0.000137,Togniniella_acerosa_AY761073:0.000137):0.000137):0.000135):0.000236,((Ceratocystis_fimbriata:0.000129,(Graphium_penicillioides:0.000108,(Microascus_cirrosus:0.000107,(Petriella_setifera:0.000073,Pseudallescheria_boydii:0.000011):0.000108)xx2:0.000255):0.000263):0.000311,(((Chaetopsina_fulva:0.000074,Cordyceps_ophioglossoides:0.000035,(Gibberella_pulicaris:0.000073,Nectria_pseudotrichia:0.000090):0.000076):0.000060,Hypocrea_lutea:0.000091)xx1:0.000051,Sphaerodothis_acrocomiae:0.000143):0.000159):0.000303,(Chaetosphaeria_curvispora:0.000085,Kionochaeta_ramifera:0.000180):0.000156)xx3:0.000228,(Cochliobolus_sativus:0.000293,Pleospora_betae:0.000086):0.000229); 2 | 3 | -------------------------------------------------------------------------------- /examples/M1155.log: -------------------------------------------------------------------------------- 1 | Reading tree foo 2 | Executing blformat command... 3 | Branch lengths assumed to be in units of numbers of substitutions per site 4 | Number of sites in sequences set to 2256 5 | All branch lengths multipled by the 2256 sites in the sequence 6 | Branch lengths rounded to nearest integer 7 | (This may not be a good idea when using CALIBRATE on ultrametric user supplied input trees. Use ROUND=NO then) 8 | 6 zero-length branches collapsed 9 | Defining clade name: xx1 10 | Defining clade name: xx2 11 | Defining clade name: xx3 12 | Setting maximum age constraint for taxon xx1 to 136.000000 13 | Setting minimum age constraint for taxon xx2 to 112.000000 14 | Fixing age of xx3 at 250.000000 15 | (The age of this node will no longer be estimated.) 16 | (This command overides any previous age constraints for this node.) 17 | (The total number of fixed ages is now 1) 18 | Using DIVTIME with clock (Langley-Fitch) options to obtain an initial guess at rates for PL search 19 | ********************* WARNING ********************** 20 | 21 | ZERO-LENGTH TERMINAL BRANCHES IN TREE: TN will impose small nonzero bounds on parameters to overcome 22 | 23 | **************************************************** 24 | MinND returned failure in ConstrOpt on initial search (may restart!) 25 | MinND returned failure in ConstrOpt (while retrying) 26 | MinND returned failure in ConstrOpt on initial search (may restart!) 27 | MinND returned failure in ConstrOpt (while retrying) 28 | MinND returned failure in ConstrOpt on initial search (may restart!) 29 | MinND returned failure in ConstrOpt (while retrying) 30 | MinND returned failure in ConstrOpt on initial search (may restart!) 31 | MinND returned failure in ConstrOpt (while retrying) 32 | Could not obtain a clock-based initial rate estimate in PL setup 33 | ********************* WARNING ********************** 34 | 35 | Times and rates unavailable 36 | 37 | **************************************************** 38 | [Printing tree 1] 39 | 40 | [NODE INFORMATION of tree foo] 41 | node 1 () age=537.68 len= 0 42 | node 2 () age=2.8e+02 | anc 1 () age=5.4e+02 | dur=2.5e+02 len=1.6e+02 rate= 0.325 nodeReal= 0 age bounds=[1e+20..250] 43 | node 3 (xx3) age=2.5e+02 | anc 2 () age=2.8e+02 | dur= 35 len= 16 rate= 0.325 nodeReal= 0 age bounds=[250..250] 44 | node 5 () age=2.4e+02 | anc 3 (xx3) age=2.5e+02 | dur= 10 len= 6 rate= 0.325 nodeReal= 0 age bounds=[250..0] 45 | node 6 () age=2.4e+02 | anc 5 () age=2.4e+02 | dur= 3.2 len= 2 rate= 0.325 nodeReal= 0 age bounds=[250..0] 46 | node 7 () age=1.8e+02 | anc 6 () age=2.4e+02 | dur= 56 len= 10 rate= 0.325 nodeReal= 0 age bounds=[250..0] 47 | node 8 () age=1.2e+02 | anc 7 () age=1.8e+02 | dur= 56 len= 20 rate= 0.325 nodeReal= 0 age bounds=[250..0] 48 | node 9 (Albertiniella_polyporicola) age= 0 | anc 8 () age=1.2e+02 | dur=1.2e+02 len= 42 rate= 0.325 nodeReal= 0 age bounds=[0..0] 49 | node 10 (Cryptendoxyla_hypophloia) age= 0 | anc 8 () age=1.2e+02 | dur=1.2e+02 len= 42 rate= 0.325 nodeReal= 0 age bounds=[0..0] 50 | node 11 () age=1.3e+02 | anc 7 () age=1.8e+02 | dur= 54 len= 8 rate= 0.325 nodeReal= 0 age bounds=[250..0] 51 | node 12 (Camarops_microspora) age= 0 | anc 11 () age=1.3e+02 | dur=1.3e+02 len= 32 rate= 0.325 nodeReal= 0 age bounds=[0..0] 52 | node 13 () age= 59 | anc 11 () age=1.3e+02 | dur= 68 len= 15 rate= 0.325 nodeReal= 0 age bounds=[250..0] 53 | node 14 () age= 33 | anc 13 () age= 59 | dur= 26 len= 4 rate= 0.325 nodeReal= 0 age bounds=[250..0] 54 | node 15 () age= 19 | anc 14 () age= 33 | dur= 14 len= 3 rate= 0.325 nodeReal= 0 age bounds=[250..0] 55 | node 16 (Chaetomium_elatum) age= 0 | anc 15 () age= 19 | dur= 19 len= 8 rate= 0.325 nodeReal= 0 age bounds=[0..0] 56 | node 17 (Madurella_mycetomatis) age= 0 | anc 15 () age= 19 | dur= 19 len= 2 rate= 0.325 nodeReal= 0 age bounds=[0..0] 57 | node 18 (Lasiosphaeria_ovina) age= 0 | anc 14 () age= 33 | dur= 33 len= 9 rate= 0.325 nodeReal= 0 age bounds=[0..0] 58 | node 19 (Sordaria_fimicola) age= 0 | anc 13 () age= 59 | dur= 59 len= 23 rate= 0.325 nodeReal= 0 age bounds=[0..0] 59 | node 20 () age=2.2e+02 | anc 6 () age=2.4e+02 | dur= 12 len= 9 rate= 0.325 nodeReal= 0 age bounds=[250..0] 60 | node 21 () age=1.4e+02 | anc 20 () age=2.2e+02 | dur= 83 len= 20 rate= 0.325 nodeReal= 0 age bounds=[250..0] 61 | node 22 () age=1.2e+02 | anc 21 () age=1.4e+02 | dur= 18 len= 4 rate= 0.325 nodeReal= 0 age bounds=[250..0] 62 | node 23 () age= 35 | anc 22 () age=1.2e+02 | dur= 89 len= 25 rate= 0.325 nodeReal= 0 age bounds=[250..0] 63 | node 24 (Apiospora_sinensis) age= 0 | anc 23 () age= 35 | dur= 35 len= 4 rate= 0.325 nodeReal= 0 age bounds=[0..0] 64 | node 25 (Arthrinium_phaeospermum) age= 0 | anc 23 () age= 35 | dur= 35 len= 17 rate= 0.325 nodeReal= 0 age bounds=[0..0] 65 | node 26 () age= 98 | anc 22 () age=1.2e+02 | dur= 26 len= 7 rate= 0.325 nodeReal= 0 age bounds=[250..0] 66 | node 28 () age= 62 | anc 26 () age= 98 | dur= 36 len= 11 rate= 0.325 nodeReal= 0 age bounds=[250..0] 67 | node 29 () age=0.31 | anc 28 () age= 62 | dur= 62 len= 24 rate= 0.325 nodeReal= 0 age bounds=[250..0] 68 | node 30 (Graphostroma_platystoma) age= 0 | anc 29 () age=0.31 | dur=0.31 len= 0 rate= 0.325 nodeReal= 0 age bounds=[0..0] 69 | node 31 (Pestalosphaeria_hansenii) age= 0 | anc 29 () age=0.31 | dur=0.31 len= 0 rate= 0.325 nodeReal= 0 age bounds=[0..0] 70 | node 32 (Microdochium_nivale) age= 0 | anc 28 () age= 62 | dur= 62 len= 15 rate= 0.325 nodeReal= 0 age bounds=[0..0] 71 | node 33 (Hyponectria_buxi) age= 0 | anc 26 () age= 98 | dur= 98 len= 24 rate= 0.325 nodeReal= 0 age bounds=[0..0] 72 | node 34 () age= 59 | anc 26 () age= 98 | dur= 40 len= 15 rate= 0.325 nodeReal= 0 age bounds=[250..0] 73 | node 35 (Hypoxylon_fragiforme) age= 0 | anc 34 () age= 59 | dur= 59 len= 8 rate= 0.325 nodeReal= 0 age bounds=[0..0] 74 | node 36 (Xylaria_carpophila) age= 0 | anc 34 () age= 59 | dur= 59 len= 33 rate= 0.325 nodeReal= 0 age bounds=[0..0] 75 | node 37 (Diatrype_disciformis) age= 0 | anc 21 () age=1.4e+02 | dur=1.4e+02 len= 48 rate= 0.325 nodeReal= 0 age bounds=[0..0] 76 | node 38 () age=2.2e+02 | anc 20 () age=2.2e+02 | dur= 7 len= 6 rate= 0.325 nodeReal= 0 age bounds=[250..0] 77 | node 40 () age=1e+02 | anc 38 () age=2.2e+02 | dur=1.2e+02 len= 39 rate= 0.325 nodeReal= 0 age bounds=[250..0] 78 | node 41 (Ceratosphaeria_lampadophora) age= 0 | anc 40 () age=1e+02 | dur=1e+02 len= 12 rate= 0.325 nodeReal= 0 age bounds=[0..0] 79 | node 42 () age= 41 | anc 40 () age=1e+02 | dur= 61 len= 33 rate= 0.325 nodeReal= 0 age bounds=[250..0] 80 | node 43 (Gaeumannomyces_graminis) age= 0 | anc 42 () age= 41 | dur= 41 len= 36 rate= 0.325 nodeReal= 0 age bounds=[0..0] 81 | node 44 (Magnaporthe_grisea) age= 0 | anc 42 () age= 41 | dur= 41 len= 0 rate= 0.325 nodeReal= 0 age bounds=[0..0] 82 | node 46 () age=2.1e+02 | anc 38 () age=2.2e+02 | dur= 4.4 len= 4 rate= 0.325 nodeReal= 0 age bounds=[250..0] 83 | node 47 () age=1.4e+02 | anc 46 () age=2.1e+02 | dur= 74 len= 19 rate= 0.325 nodeReal= 0 age bounds=[250..0] 84 | node 48 () age= 35 | anc 47 () age=1.4e+02 | dur=1e+02 len= 29 rate= 0.325 nodeReal= 0 age bounds=[250..0] 85 | node 49 () age= 5.1 | anc 48 () age= 35 | dur= 30 len= 2 rate= 0.325 nodeReal= 0 age bounds=[250..0] 86 | node 50 (Cryphonectria_parasitica) age= 0 | anc 49 () age= 5.1 | dur= 5.1 len= 0 rate= 0.325 nodeReal= 0 age bounds=[0..0] 87 | node 51 (Endothia_gyrosa) age= 0 | anc 49 () age= 5.1 | dur= 5.1 len= 2 rate= 0.325 nodeReal= 0 age bounds=[0..0] 88 | node 52 () age= 19 | anc 48 () age= 35 | dur= 17 len= 9 rate= 0.325 nodeReal= 0 age bounds=[250..0] 89 | node 53 (Diaporthe_phaseolorum) age= 0 | anc 52 () age= 19 | dur= 19 len= 9 rate= 0.325 nodeReal= 0 age bounds=[0..0] 90 | node 54 (Leucostoma_persoonii) age= 0 | anc 52 () age= 19 | dur= 19 len= 7 rate= 0.325 nodeReal= 0 age bounds=[0..0] 91 | node 55 () age= 24 | anc 47 () age=1.4e+02 | dur=1.2e+02 len= 35 rate= 0.325 nodeReal= 0 age bounds=[250..0] 92 | node 56 () age= 2.4 | anc 55 () age= 24 | dur= 22 len= 2 rate= 0.325 nodeReal= 0 age bounds=[250..0] 93 | node 59 () age=0.31 | anc 56 () age= 2.4 | dur= 2.1 len= 1 rate= 0.325 nodeReal= 0 age bounds=[250..0] 94 | node 61 (Phaeoacremonium_griseorubrum) age= 0 | anc 59 () age=0.31 | dur=0.31 len= 0 rate= 0.325 nodeReal= 0 age bounds=[0..0] 95 | node 62 (Phaeoacremonium_parasiticum) age= 0 | anc 59 () age=0.31 | dur=0.31 len= 0 rate= 0.325 nodeReal= 0 age bounds=[0..0] 96 | node 63 (Phaeoacremonium_tardicrescens) age= 0 | anc 59 () age=0.31 | dur=0.31 len= 0 rate= 0.325 nodeReal= 0 age bounds=[0..0] 97 | node 65 (Phaeoacremonium_theobromatis) age= 0 | anc 56 () age= 2.4 | dur= 2.4 len= 0 rate= 0.325 nodeReal= 0 age bounds=[0..0] 98 | node 66 (Phaeoacremonium_viticola) age= 0 | anc 56 () age= 2.4 | dur= 2.4 len= 0 rate= 0.325 nodeReal= 0 age bounds=[0..0] 99 | node 67 () age=0.31 | anc 56 () age= 2.4 | dur= 2.1 len= 1 rate= 0.325 nodeReal= 0 age bounds=[250..0] 100 | node 68 (Togninia_fraxinopennsylvanica) age= 0 | anc 67 () age=0.31 | dur=0.31 len= 0 rate= 0.325 nodeReal= 0 age bounds=[0..0] 101 | node 69 (Togninia_novaezealandiae) age= 0 | anc 67 () age=0.31 | dur=0.31 len= 0 rate= 0.325 nodeReal= 0 age bounds=[0..0] 102 | node 70 (Togninia_minima) age= 0 | anc 56 () age= 2.4 | dur= 2.4 len= 1 rate= 0.325 nodeReal= 0 age bounds=[0..0] 103 | node 71 () age= 5.8 | anc 55 () age= 24 | dur= 19 len= 10 rate= 0.325 nodeReal= 0 age bounds=[250..0] 104 | node 72 (Phaeoacremonium_sphinctrophorum_DQ173149) age= 0 | anc 71 () age= 5.8 | dur= 5.8 len= 5 rate= 0.325 nodeReal= 0 age bounds=[0..0] 105 | node 73 (Phaeoacremonium_sphinctrophorum_DQ173150) age= 0 | anc 71 () age= 5.8 | dur= 5.8 len= 0 rate= 0.325 nodeReal= 0 age bounds=[0..0] 106 | node 74 () age= 36 | anc 46 () age=2.1e+02 | dur=1.8e+02 len=1.7e+02 rate= 0.325 nodeReal= 0 age bounds=[250..0] 107 | node 75 () age= 10 | anc 74 () age= 36 | dur= 25 len= 33 rate= 0.325 nodeReal= 0 age bounds=[250..0] 108 | node 76 (Pleurostoma_ootheca) age= 0 | anc 75 () age= 10 | dur= 10 len= 16 rate= 0.325 nodeReal= 0 age bounds=[0..0] 109 | node 77 (Pleurostomophora_repens) age= 0 | anc 75 () age= 10 | dur= 10 len= 1 rate= 0.325 nodeReal= 0 age bounds=[0..0] 110 | node 78 (Pleurostomophora_richardsiae) age= 0 | anc 74 () age= 36 | dur= 36 len= 0 rate= 0.325 nodeReal= 0 age bounds=[0..0] 111 | node 79 () age= 5.6 | anc 38 () age=2.2e+02 | dur=2.1e+02 len= 52 rate= 0.325 nodeReal= 0 age bounds=[250..0] 112 | node 81 (Endomyces_scopularum) age= 0 | anc 79 () age= 5.6 | dur= 5.6 len= 1 rate= 0.325 nodeReal= 0 age bounds=[0..0] 113 | node 82 (Sporothrix_schenckii) age= 0 | anc 79 () age= 5.6 | dur= 5.6 len= 1 rate= 0.325 nodeReal= 0 age bounds=[0..0] 114 | node 83 (Ophiostoma_stenoceras) age= 0 | anc 79 () age= 5.6 | dur= 5.6 len= 3 rate= 0.325 nodeReal= 0 age bounds=[0..0] 115 | node 84 () age= 37 | anc 38 () age=2.2e+02 | dur=1.8e+02 len= 60 rate= 0.325 nodeReal= 0 age bounds=[250..0] 116 | node 85 (Gnomonia_setacea) age= 0 | anc 84 () age= 37 | dur= 37 len= 13 rate= 0.325 nodeReal= 0 age bounds=[0..0] 117 | node 86 (Gnomoniella_fraxini) age= 0 | anc 84 () age= 37 | dur= 37 len= 11 rate= 0.325 nodeReal= 0 age bounds=[0..0] 118 | node 87 () age= 67 | anc 5 () age=2.4e+02 | dur=1.7e+02 len= 48 rate= 0.325 nodeReal= 0 age bounds=[250..0] 119 | node 88 (Calosphaeria_pulchella) age= 0 | anc 87 () age= 67 | dur= 67 len= 16 rate= 0.325 nodeReal= 0 age bounds=[0..0] 120 | node 89 () age=0.31 | anc 87 () age= 67 | dur= 66 len= 24 rate= 0.325 nodeReal= 0 age bounds=[250..0] 121 | node 90 (Togniniella_acerosa_AY761072) age= 0 | anc 89 () age=0.31 | dur=0.31 len= 0 rate= 0.325 nodeReal= 0 age bounds=[0..0] 122 | node 91 (Togniniella_acerosa_AY761073) age= 0 | anc 89 () age=0.31 | dur=0.31 len= 0 rate= 0.325 nodeReal= 0 age bounds=[0..0] 123 | node 92 () age=2e+02 | anc 3 (xx3) age=2.5e+02 | dur= 53 len= 29 rate= 0.325 nodeReal= 0 age bounds=[250..112] 124 | node 93 () age=1.5e+02 | anc 92 () age=2e+02 | dur= 44 len= 31 rate= 0.325 nodeReal= 0 age bounds=[250..112] 125 | node 94 (Ceratocystis_fimbriata) age= 0 | anc 93 () age=1.5e+02 | dur=1.5e+02 len= 48 rate= 0.325 nodeReal= 0 age bounds=[0..0] 126 | node 95 () age=1.4e+02 | anc 93 () age=1.5e+02 | dur= 14 len= 10 rate= 0.325 nodeReal= 0 age bounds=[250..112] 127 | node 96 (Graphium_penicillioides) age= 0 | anc 95 () age=1.4e+02 | dur=1.4e+02 len= 36 rate= 0.325 nodeReal= 0 age bounds=[0..0] 128 | node 97 (xx2) age=1.1e+02 | anc 95 () age=1.4e+02 | dur= 28 len= 22 rate= 0.325 nodeReal= 0 age bounds=[250..112] 129 | node 98 (Microascus_cirrosus) age= 0 | anc 97 (xx2) age=1.1e+02 | dur=1.1e+02 len= 27 rate= 0.325 nodeReal= 0 age bounds=[0..0] 130 | node 99 () age= 35 | anc 97 (xx2) age=1.1e+02 | dur= 77 len= 8 rate= 0.325 nodeReal= 0 age bounds=[250..0] 131 | node 100 (Petriella_setifera) age= 0 | anc 99 () age= 35 | dur= 35 len= 13 rate= 0.325 nodeReal= 0 age bounds=[0..0] 132 | node 101 (Pseudallescheria_boydii) age= 0 | anc 99 () age= 35 | dur= 35 len= 2 rate= 0.325 nodeReal= 0 age bounds=[0..0] 133 | node 102 () age=1.5e+02 | anc 92 () age=2e+02 | dur= 43 len= 7 rate= 0.325 nodeReal= 0 age bounds=[250..0] 134 | node 103 (xx1) age= 91 | anc 102 () age=1.5e+02 | dur= 64 len= 6 rate= 0.325 nodeReal= 0 age bounds=[136..0] 135 | node 104 () age= 64 | anc 103 (xx1) age= 91 | dur= 27 len= 3 rate= 0.325 nodeReal= 0 age bounds=[136..0] 136 | node 106 (Chaetopsina_fulva) age= 0 | anc 104 () age= 64 | dur= 64 len= 19 rate= 0.325 nodeReal= 0 age bounds=[0..0] 137 | node 107 (Cordyceps_ophioglossoides) age= 0 | anc 104 () age= 64 | dur= 64 len= 9 rate= 0.325 nodeReal= 0 age bounds=[0..0] 138 | node 108 () age= 45 | anc 104 () age= 64 | dur= 19 len= 6 rate= 0.325 nodeReal= 0 age bounds=[136..0] 139 | node 109 (Gibberella_pulicaris) age= 0 | anc 108 () age= 45 | dur= 45 len= 13 rate= 0.325 nodeReal= 0 age bounds=[0..0] 140 | node 110 (Nectria_pseudotrichia) age= 0 | anc 108 () age= 45 | dur= 45 len= 16 rate= 0.325 nodeReal= 0 age bounds=[0..0] 141 | node 111 (Hypocrea_lutea) age= 0 | anc 103 (xx1) age= 91 | dur= 91 len= 28 rate= 0.325 nodeReal= 0 age bounds=[0..0] 142 | node 112 (Sphaerodothis_acrocomiae) age= 0 | anc 102 () age=1.5e+02 | dur=1.5e+02 len= 61 rate= 0.325 nodeReal= 0 age bounds=[0..0] 143 | node 113 () age= 66 | anc 3 (xx3) age=2.5e+02 | dur=1.8e+02 len= 62 rate= 0.325 nodeReal= 0 age bounds=[250..0] 144 | node 114 (Chaetosphaeria_curvispora) age= 0 | anc 113 () age= 66 | dur= 66 len= 14 rate= 0.325 nodeReal= 0 age bounds=[0..0] 145 | node 115 (Kionochaeta_ramifera) age= 0 | anc 113 () age= 66 | dur= 66 len= 30 rate= 0.325 nodeReal= 0 age bounds=[0..0] 146 | node 116 () age= 74 | anc 2 () age=2.8e+02 | dur=2.1e+02 len=1.1e+02 rate= 0.325 nodeReal= 0 age bounds=[1e+20..0] 147 | node 117 (Cochliobolus_sativus) age= 0 | anc 116 () age= 74 | dur= 74 len= 48 rate= 0.325 nodeReal= 0 age bounds=[0..0] 148 | node 118 (Pleospora_betae) age= 0 | anc 116 () age= 74 | dur= 74 len= 14 rate= 0.325 nodeReal= 0 age bounds=[0..0] 149 | node 119 (Melanospora_zamiae) age= 0 | anc 1 () age=5.4e+02 | dur=5.4e+02 len= 1 rate= 0.325 nodeReal= 0 age bounds=[0..0] 150 | [Printing tree 1] 151 | 152 | [TREE DESCRIPTION of tree foo] 153 | 154 | tree foo = (((((((Albertiniella_polyporicola:123.688795,Cryptendoxyla_hypophloia:123.688795):56.491937,(Camarops_microspora:126.560125,(((Chaetomium_elatum:18.732288,Madurella_mycetomatis:18.732288):14.371488,Lasiosphaeria_ovina:33.103777):25.718846,Sordaria_fimicola:58.822623):67.737502):53.620607):56.136176,((((Apiospora_sinensis:34.721872,Arthrinium_phaeospermum:34.721872):89.376643,(((Graphostroma_platystoma:0.312500,Pestalosphaeria_hansenii:0.312500):61.908400,Microdochium_nivale:62.220900):36.225308,Hyponectria_buxi:98.446209,(Hypoxylon_fragiforme:58.512103,Xylaria_carpophila:58.512103):39.934106):25.652306):17.582098,Diatrype_disciformis:141.680612):82.917583,((Ceratosphaeria_lampadophora:101.959978,(Gaeumannomyces_graminis:41.385334,Magnaporthe_grisea:41.385334):60.574644):115.595053,((((Cryphonectria_parasitica:5.110660,Endothia_gyrosa:5.110660):30.189630,(Diaporthe_phaseolorum:18.551764,Leucostoma_persoonii:18.551764):16.748527):104.122669,(((Phaeoacremonium_griseorubrum:0.312500,Phaeoacremonium_parasiticum:0.312500,Phaeoacremonium_tardicrescens:0.312500):2.061641,Phaeoacremonium_theobromatis:2.374141,Phaeoacremonium_viticola:2.374141,(Togninia_fraxinopennsylvanica:0.312500,Togninia_novaezealandiae:0.312500):2.061641,Togninia_minima:2.374141):21.992055,(Phaeoacremonium_sphinctrophorum_DQ173149:5.790806,Phaeoacremonium_sphinctrophorum_DQ173150:5.790806):18.575391):115.056763):73.750787,((Pleurostoma_ootheca:10.425466,Pleurostomophora_repens:10.425466):25.277059,Pleurostomophora_richardsiae:35.702526):177.471221):4.381285,(Endomyces_scopularum:5.583486,Sporothrix_schenckii:5.583486,Ophiostoma_stenoceras:5.583486):211.971545,(Gnomonia_setacea:36.553097,Gnomoniella_fraxini:36.553097):181.001935):7.043163):11.718713):3.220354,(Calosphaeria_pulchella:66.567335,(Togniniella_acerosa_AY761072:0.312500,Togniniella_acerosa_AY761073:0.312500):66.254835):172.969926):10.462738,((Ceratocystis_fimbriata:153.628908,(Graphium_penicillioides:139.808034,(Microascus_cirrosus:112.000000,(Petriella_setifera:34.969449,Pseudallescheria_boydii:34.969449):77.030551)xx2:27.808034):13.820874):43.607098,(((Chaetopsina_fulva:63.618684,Cordyceps_ophioglossoides:63.618684,(Gibberella_pulicaris:44.908042,Nectria_pseudotrichia:44.908042):18.710642):27.121463,Hypocrea_lutea:90.740147)xx1:63.764666,Sphaerodothis_acrocomiae:154.504813):42.731193):52.763994,(Chaetosphaeria_curvispora:66.388919,Kionochaeta_ramifera:66.388919):183.611081)xx3:34.718926,(Cochliobolus_sativus:74.015692,Pleospora_betae:74.015692):210.703234):252.960698,Melanospora_zamiae:537.679624); 155 | -------------------------------------------------------------------------------- /examples/M1155.rates: -------------------------------------------------------------------------------- 1 | #nexus 2 | begin trees; 3 | tree foo = (((((((Albertiniella_polyporicola:0.018572,Cryptendoxyla_hypophloia:0.018414):0.008976,(Camarops_microspora:0.013976,(((Chaetomium_elatum:0.003746,Madurella_mycetomatis:0.000987):0.001179,Lasiosphaeria_ovina:0.003922):0.001815,Sordaria_fimicola:0.010232):0.006600):0.003569):0.004556,((((Apiospora_sinensis:0.001963,Arthrinium_phaeospermum:0.007433):0.011031,((((Graphostroma_platystoma:0,Pestalosphaeria_hansenii:0):0.010807,Microdochium_nivale:0.006523):0.004662,Hyponectria_buxi:0.010583):0,(Hypoxylon_fragiforme:0.003729,Xylaria_carpophila:0.014825):0.006720):0.003131):0.001850,Diatrype_disciformis:0.021108):0.008752,(((Ceratosphaeria_lampadophora:0.005454,(Gaeumannomyces_graminis:0.015940,Magnaporthe_grisea:0):0.014493):0.017212,(((((Cryphonectria_parasitica:0,Endothia_gyrosa:0.000973):0.001013,(Diaporthe_phaseolorum:0.004044,Leucostoma_persoonii:0.002925):0.003867):0.012761,((((((Phaeoacremonium_griseorubrum:0,Phaeoacremonium_parasiticum:0):0,Phaeoacremonium_tardicrescens:0):0.000607,(Phaeoacremonium_theobromatis:0,Phaeoacremonium_viticola:0):0):0,(Togninia_fraxinopennsylvanica:0,Togninia_novaezealandiae:0):0.000607):0,Togninia_minima:0.000607):0.000707,(Phaeoacremonium_sphinctrophorum_DQ173149:0.002355,Phaeoacremonium_sphinctrophorum_DQ173150:0):0.004445):0.015686):0.008414,((Pleurostoma_ootheca:0.007161,Pleurostomophora_repens:0.000652):0.014621,Pleurostomophora_richardsiae:0):0.077038):0.001657,((Endomyces_scopularum:0.000588,Sporothrix_schenckii:0.000589):0,Ophiostoma_stenoceras:0.001176):0.023003):0.000162):0,(Gnomonia_setacea:0.005760,Gnomoniella_fraxini:0.005095):0.026543):0.002559):0.003835):0.000698,(Calosphaeria_pulchella:0.007177,(Togniniella_acerosa_AY761072:0,Togniniella_acerosa_AY761073:0):0.010630):0.021316):0.002605,((Ceratocystis_fimbriata:0.021331,(Graphium_penicillioides:0.016057,(Microascus_cirrosus:0.012011,(Petriella_setifera:0.005803,Pseudallescheria_boydii:0.000688):0.003575):0.009722):0.004457):0.013849,((((Chaetopsina_fulva:0.008233,Cordyceps_ophioglossoides:0.004197):0,(Gibberella_pulicaris:0.005818,Nectria_pseudotrichia:0.007032):0.002525):0.001353,Hypocrea_lutea:0.012268):0.002780,Sphaerodothis_acrocomiae:0.027256):0.003028):0.012979):0,(Chaetosphaeria_curvispora:0.006194,Kionochaeta_ramifera:0.013519):0.027447):0.007264,(Cochliobolus_sativus:0.021281,Pleospora_betae:0.006290):0.047965):0.07; 4 | end; 5 | 6 | begin r8s; 7 | blformat lengths=persite nsites=2256 ultrametric=no; 8 | set smoothing=1; 9 | [prune Melanospora_zamiae;] 10 | collapse; 11 | MRCA xx1 Hypocrea_lutea Gibberella_pulicaris; 12 | MRCA xx2 Microascus_cirrosus Petriella_setifera; 13 | MRCA xx3 Albertiniella_polyporicola Kionochaeta_ramifera; 14 | constrain taxon=xx1 max_age=136; 15 | constrain taxon=xx2 min_age=112; 16 | fixage taxon=xx3 age=250; 17 | set num_time_guesses=5; 18 | set num_restarts=4; 19 | divtime method=pl algorithm=tn; 20 | showage; 21 | penalty=additive; 22 | describe plot=node_info; 23 | describe plot=chrono_description; 24 | describe plot=rato_description; 25 | end; 26 | -------------------------------------------------------------------------------- /examples/M1155.tre: -------------------------------------------------------------------------------- 1 | (((((((Albertiniella_polyporicola:0.018572,Cryptendoxyla_hypophloia:0.018414):0.008976,(Camarops_microspora:0.013976,(((Chaetomium_elatum:0.003746,Madurella_mycetomatis:0.000987):0.001179,Lasiosphaeria_ovina:0.003922):0.001815,Sordaria_fimicola:0.010232):0.006600):0.003569):0.004556,((((Apiospora_sinensis:0.001963,Arthrinium_phaeospermum:0.007433):0.011031,((((Graphostroma_platystoma:0,Pestalosphaeria_hansenii:0):0.010807,Microdochium_nivale:0.006523):0.004662,Hyponectria_buxi:0.010583):0,(Hypoxylon_fragiforme:0.003729,Xylaria_carpophila:0.014825):0.006720):0.003131):0.001850,Diatrype_disciformis:0.021108):0.008752,(((Ceratosphaeria_lampadophora:0.005454,(Gaeumannomyces_graminis:0.015940,Magnaporthe_grisea:0):0.014493):0.017212,(((((Cryphonectria_parasitica:0,Endothia_gyrosa:0.000973):0.001013,(Diaporthe_phaseolorum:0.004044,Leucostoma_persoonii:0.002925):0.003867):0.012761,((((((Phaeoacremonium_griseorubrum:0,Phaeoacremonium_parasiticum:0):0,Phaeoacremonium_tardicrescens:0):0.000607,(Phaeoacremonium_theobromatis:0,Phaeoacremonium_viticola:0):0):0,(Togninia_fraxinopennsylvanica:0,Togninia_novaezealandiae:0):0.000607):0,Togninia_minima:0.000607):0.000707,(Phaeoacremonium_sphinctrophorum_DQ173149:0.002355,Phaeoacremonium_sphinctrophorum_DQ173150:0):0.004445):0.015686):0.008414,((Pleurostoma_ootheca:0.007161,Pleurostomophora_repens:0.000652):0.014621,Pleurostomophora_richardsiae:0):0.077038):0.001657,((Endomyces_scopularum:0.000588,Sporothrix_schenckii:0.000589):0,Ophiostoma_stenoceras:0.001176):0.023003):0.000162):0,(Gnomonia_setacea:0.005760,Gnomoniella_fraxini:0.005095):0.026543):0.002559):0.003835):0.000698,(Calosphaeria_pulchella:0.007177,(Togniniella_acerosa_AY761072:0,Togniniella_acerosa_AY761073:0):0.010630):0.021316):0.002605,((Ceratocystis_fimbriata:0.021331,(Graphium_penicillioides:0.016057,(Microascus_cirrosus:0.012011,(Petriella_setifera:0.005803,Pseudallescheria_boydii:0.000688):0.003575):0.009722):0.004457):0.013849,((((Chaetopsina_fulva:0.008233,Cordyceps_ophioglossoides:0.004197):0,(Gibberella_pulicaris:0.005818,Nectria_pseudotrichia:0.007032):0.002525):0.001353,Hypocrea_lutea:0.012268):0.002780,Sphaerodothis_acrocomiae:0.027256):0.003028):0.012979):0,(Chaetosphaeria_curvispora:0.006194,Kionochaeta_ramifera:0.013519):0.027447):0.007264,(Cochliobolus_sativus:0.021281,Pleospora_betae:0.006290):0.047965):0.07; 2 | -------------------------------------------------------------------------------- /examples/big_test.cppr8s: -------------------------------------------------------------------------------- 1 | treefile = comm_mol_rr.tre 2 | mrca = root Raphia_farinifera Oryza_rufipogon 3 | min = root 100 4 | max = root 100 5 | numsites = 20000 6 | smooth = 0.0001 7 | [cv] 8 | [verbose] 9 | [prime] 10 | opt = 5 11 | optad = 3 12 | optcvad = 0 13 | [verbose] 14 | log_pen 15 | -------------------------------------------------------------------------------- /examples/clock.cppr8s: -------------------------------------------------------------------------------- 1 | treefile = clock.tre 2 | numsites=100000 3 | mrca = ingroup t137 t164 4 | min = ingroup 100 5 | max = ingroup 100 6 | smooth = 1000 7 | outfile = 1000.tre 8 | cv 9 | randomcv 10 | cviter = 3 11 | cvsimaniter = 1000 12 | cvstart = 1000 13 | cvstop = 0.0001 14 | cvmultstep = 0.1 15 | [thorough] 16 | [prime] 17 | ftol = 1e-5 18 | opt = 0 19 | optad = 2 20 | moredetailad 21 | optcvad = 4 22 | log_pen 23 | -------------------------------------------------------------------------------- /examples/clock.nex: -------------------------------------------------------------------------------- 1 | #nexus 2 | begin trees; 3 | tree PAUP_4203 = [&R] (((((t137:0.262363131,((((t130:0.006272451932,t132:0.006272451932):0.06521212756,((t65:0.0005268397658,t141:0.0005268397658):0.03830839224,(t196:0.01706146205,t17:0.01706146205):0.02177376996):0.03264934748):0.02162788176,(t199:0.003547017699,t166:0.003547017699):0.08956544356):0.05648377218,((t175:0.002256955518,t52:0.002256955518):0.06808346449,(((((t126:0.00131421003,t114:0.00131421003):0.01275365268,t96:0.01406786271):0.03055443969,((t185:0.01295620783,t51:0.01295620783):0.02587495048,((((t60:0.001459718083,t88:0.001459718083):0.001546374585,t161:0.003006092667):0.01554056853,(t91:0.005244934703,(t3:0.002418230301,t178:0.002418230301):0.002826704402):0.0133017265):0.008749618258,(((t149:0.01209863146,((t26:8.370802444e-05,t19:8.370802444e-05):0.008398203633,t103:0.008481911658):0.0036167198):0.005677010634,(t28:0.003887777986,t39:0.003887777986):0.01388786411):0.002784017729,t46:0.02055965982):0.00673661964):0.01153487884):0.005791144094):0.01992148698,(((t131:0.003703528068,t181:0.003703528068):0.01180201033,(t121:0.002948144368,t50:0.002948144368):0.01255739403):0.02390630946,((((t42:0.001256323584,t123:0.001256323584):0.0008305029317,t155:0.002086826516):0.0035516572,t165:0.005638483716):0.01118811565,((t120:0.002182132432,(t140:0.001212622717,t2:0.001212622717):0.000969509715):0.004636494629,t69:0.006818627061):0.01000797231):0.0225852485):0.02513194151):0.002105391453,t31:0.06664918083):0.003691239179):0.07925581343):0.1127668976):0.01369506797,(((t102:0.02765960537,(t162:0.001566749571,t146:0.001566749571):0.0260928558):0.06074812066,((((t154:0.01120264374,t59:0.01120264374):0.008034981742,t14:0.01923762548):0.05090828141,(((t89:0.001031406788,(t179:0.0002279719576,t23:0.0002279719576):0.0008034348307):0.002485606877,(t34:0.002938750435,(t107:0.0006268937889,t54:0.0006268937889):0.002311856646):0.0005782632308):0.0216176482,((t12:0.0008995335554,t188:0.0008995335554):0.02363160529,((t180:0.006944972327,t108:0.006944972327):0.00318378883,(t133:0.007334971313,(t67:0.007155701175,t47:0.007155701175):0.0001792701387):0.002793789844):0.01440237769):0.0006035230218):0.04501124503):0.01361894211,(t64:0.02359081239,((((t197:0.001309397199,t71:0.001309397199):0.001482561877,t190:0.002791959076):0.001973890136,t63:0.004765849212):0.01859245761,((t111:0.0005636610595,(t101:0.000375084833,t176:0.000375084833):0.0001885762264):0.01435228625,((t92:0.0005364537566,t147:0.0005364537566):0.01188382546,(t77:0.01232006982,(t105:0.009518509431,(t81:0.005525643512,t198:0.005525643512):0.003992865919):0.002801560394):0.0001002093956):0.002495668086):0.008442359512):0.000232505568):0.06017403662):0.004642877024):0.03451704832,((t173:0.001656238493,t183:0.001656238493):0.05333171058,(((t110:0.01472278921,(((t106:0.0007474063923,t27:0.0007474063923):0.00046004175,t113:0.001207448142):0.0004288193125,(t18:0.0003401278989,t72:0.0003401278989):0.001296139556):0.01308652176):0.0236669624,(t1:0.01380246023,(t144:0.002460538625,(t49:0.001005323241,t48:0.001005323241):0.001455215385):0.0113419216):0.02458729139):0.01455870685,((t153:0.0321190802,((((t70:0.001882335968,t138:0.001882335968):0.001472244059,t25:0.003354580027):0.01312574758,t29:0.0164803276):0.006039927773,((t124:0.006058084013,t128:0.006058084013):0.0004925829739,t33:0.006550666986):0.01596958839):0.009598824819):0.01181008413,(((t152:0.006935141921,(t84:0.002406232894,t15:0.002406232894):0.004528909027):0.03410573598,t177:0.0410408779):0.001067275489,((t61:0.002965820287,t76:0.002965820287):0.02629440493,(t193:0.02622099111,(t43:0.006172185022,(t157:0.003230475055,t58:0.003230475055):0.002941709967):0.02004880608):0.003039234107):0.01284792818):0.001821010938):0.009019294135):0.002039490613):0.06793682527):0.1531334246):0.002233948004,((t87:0.04906522231,((t11:0.01563574418,t75:0.01563574418):0.02364391604,(((((t57:0.0009807909034,(t194:0.0008949299043,t148:0.0008949299043):8.586099913e-05):0.001861392978,(t200:0.001441717421,t187:0.001441717421):0.001400466461):0.001357171345,t99:0.004199355226):0.001566562357,(t98:0.001950992004,t10:0.001950992004):0.00381492558):0.03001539742,(t13:0.0021885773,t86:0.0021885773):0.03359273771):0.003498345211):0.009785562088):0.02690091434,(t163:0.01872525229,((t116:0.01464779197,t56:0.01464779197):0.00283128921,t115:0.01747908118):0.001246171107):0.05724088436):0.2023260103):0.3324676908,((t169:0.002802411051,t85:0.002802411051):0.1761485411,(((t168:0.01341863577,((t20:0.007710175644,t74:0.007710175644):0.002553281287,t30:0.01026345693):0.003155178836):0.0008101106658,t184:0.01422874643):0.09348964159,((((t40:0.01463560083,t127:0.01463560083):0.01223545504,t109:0.02687105587):0.04851545256,(t158:8.179056079e-05,t5:8.179056079e-05):0.07530471787):0.02556232612,((t174:0.0009604562832,t37:0.0009604562832):0.05593658119,(t6:0.04390553312,t95:0.04390553312):0.01299150436):0.04405179707):0.006769553476):0.07123256408):0.4318088857):0.5081146259,((((t171:0.004043940093,(t78:0.0008538939207,t62:0.0008538939207):0.003190046172):0.0554269347,((t82:0.008243726062,(t129:0.003190267085,(t45:0.002783733947,t35:0.002783733947):0.0004065331382):0.005053458978):0.009886355653,(t79:0.008692617866,t44:0.008692617866):0.009437463849):0.04134079307):0.1039076875,t142:0.1633785623):0.7454326277,(((t167:0.006277691585,t189:0.006277691585):0.5488778536,(((t118:0.005919988874,t150:0.005919988874):0.1234955162,((t125:0.01527192994,((t90:0.00812152768,t182:0.00812152768):0.002014059422,t22:0.0101355871):0.005136342834):0.01337681453,(t24:0.008517511349,(t195:0.004414951146,t36:0.004414951146):0.004102560203):0.02013123312):0.1007667606):0.2191400545,((((t73:0.002373228209,t160:0.002373228209):0.02579293915,((t117:0.004830074017,t136:0.004830074017):0.0008059735155,(t151:0.0004936456681,t4:0.0004936456681):0.005142401864):0.02253011983):0.02297817557,(t156:0.0303513273,((t21:0.01193339353,(t32:0.001729791094,t104:0.001729791094):0.01020360243):0.005272966001,t38:0.01720635953):0.01314496777):0.02079301562):0.07782184381,(t93:0.001698605874,t66:0.001698605874):0.1272675809):0.2195893728):0.2065999856):0.1342691723,(((t94:0.02069998981,((((t186:0.004575032749,t134:0.004575032749):0.0002919258384,t122:0.004866958588):0.00113290316,t80:0.005999861748):0.01176581555,((t159:0.008441430103,t55:0.008441430103):0.00743559327,(t135:0.006308668873,t143:0.006308668873):0.009568354499):0.001888653923):0.002934312512):0.08684166365,((((t41:0.0006001958992,t191:0.0006001958992):0.007553521153,t53:0.008153717052):0.04930899518,(t145:0.01329981967,(((t112:0.002127820493,t9:0.002127820493):0.003106794346,t8:0.005234614839):0.007417192558,t119:0.0126518074):0.000648012271):0.04416289257):0.03450625203,((t139:0.00179418041,((t170:0.0002514488856,t83:0.0002514488856):0.0008243500481,t192:0.001075798934):0.0007183814763):0.03108766356,(t172:0.01908318907,(t68:0.01727759701,(t100:0.00139626214,t7:0.00139626214):0.01588133487):0.00180559206):0.0137986549):0.0590871203):0.01557268919):0.06049884457,(t16:0.01217984143,(t97:0.001119180658,t164:0.001119180658):0.01106066078):0.1558606566):0.5213842194):0.2193864725):0.2100632738); 4 | end; 5 | 6 | begin r8s; 7 | blformat nsites=100000 lengths=persite; 8 | mrca ingroup = t137 t164; 9 | [collapse;] 10 | fixage taxon=ingroup age=100; 11 | set ftol=1e-7 maxiter=2000; 12 | [set verbose=0; suppresses huge amount of output in CV analyses] 13 | divtime method=pl algorithm=tn cvStart=-7 cvInc=1 cvNum=6 crossv=yes; 14 | set smoothing = .0001; 15 | divtime method=pl; 16 | describe plot=cladogram; 17 | show rates; 18 | end; 19 | -------------------------------------------------------------------------------- /examples/clock.tre: -------------------------------------------------------------------------------- 1 | (((((t137:0.262363131,((((t130:0.006272451932,t132:0.006272451932):0.06521212756,((t65:0.0005268397658,t141:0.0005268397658):0.03830839224,(t196:0.01706146205,t17:0.01706146205):0.02177376996):0.03264934748):0.02162788176,(t199:0.003547017699,t166:0.003547017699):0.08956544356):0.05648377218,((t175:0.002256955518,t52:0.002256955518):0.06808346449,(((((t126:0.00131421003,t114:0.00131421003):0.01275365268,t96:0.01406786271):0.03055443969,((t185:0.01295620783,t51:0.01295620783):0.02587495048,((((t60:0.001459718083,t88:0.001459718083):0.001546374585,t161:0.003006092667):0.01554056853,(t91:0.005244934703,(t3:0.002418230301,t178:0.002418230301):0.002826704402):0.0133017265):0.008749618258,(((t149:0.01209863146,((t26:8.370802444e-05,t19:8.370802444e-05):0.008398203633,t103:0.008481911658):0.0036167198):0.005677010634,(t28:0.003887777986,t39:0.003887777986):0.01388786411):0.002784017729,t46:0.02055965982):0.00673661964):0.01153487884):0.005791144094):0.01992148698,(((t131:0.003703528068,t181:0.003703528068):0.01180201033,(t121:0.002948144368,t50:0.002948144368):0.01255739403):0.02390630946,((((t42:0.001256323584,t123:0.001256323584):0.0008305029317,t155:0.002086826516):0.0035516572,t165:0.005638483716):0.01118811565,((t120:0.002182132432,(t140:0.001212622717,t2:0.001212622717):0.000969509715):0.004636494629,t69:0.006818627061):0.01000797231):0.0225852485):0.02513194151):0.002105391453,t31:0.06664918083):0.003691239179):0.07925581343):0.1127668976):0.01369506797,(((t102:0.02765960537,(t162:0.001566749571,t146:0.001566749571):0.0260928558):0.06074812066,((((t154:0.01120264374,t59:0.01120264374):0.008034981742,t14:0.01923762548):0.05090828141,(((t89:0.001031406788,(t179:0.0002279719576,t23:0.0002279719576):0.0008034348307):0.002485606877,(t34:0.002938750435,(t107:0.0006268937889,t54:0.0006268937889):0.002311856646):0.0005782632308):0.0216176482,((t12:0.0008995335554,t188:0.0008995335554):0.02363160529,((t180:0.006944972327,t108:0.006944972327):0.00318378883,(t133:0.007334971313,(t67:0.007155701175,t47:0.007155701175):0.0001792701387):0.002793789844):0.01440237769):0.0006035230218):0.04501124503):0.01361894211,(t64:0.02359081239,((((t197:0.001309397199,t71:0.001309397199):0.001482561877,t190:0.002791959076):0.001973890136,t63:0.004765849212):0.01859245761,((t111:0.0005636610595,(t101:0.000375084833,t176:0.000375084833):0.0001885762264):0.01435228625,((t92:0.0005364537566,t147:0.0005364537566):0.01188382546,(t77:0.01232006982,(t105:0.009518509431,(t81:0.005525643512,t198:0.005525643512):0.003992865919):0.002801560394):0.0001002093956):0.002495668086):0.008442359512):0.000232505568):0.06017403662):0.004642877024):0.03451704832,((t173:0.001656238493,t183:0.001656238493):0.05333171058,(((t110:0.01472278921,(((t106:0.0007474063923,t27:0.0007474063923):0.00046004175,t113:0.001207448142):0.0004288193125,(t18:0.0003401278989,t72:0.0003401278989):0.001296139556):0.01308652176):0.0236669624,(t1:0.01380246023,(t144:0.002460538625,(t49:0.001005323241,t48:0.001005323241):0.001455215385):0.0113419216):0.02458729139):0.01455870685,((t153:0.0321190802,((((t70:0.001882335968,t138:0.001882335968):0.001472244059,t25:0.003354580027):0.01312574758,t29:0.0164803276):0.006039927773,((t124:0.006058084013,t128:0.006058084013):0.0004925829739,t33:0.006550666986):0.01596958839):0.009598824819):0.01181008413,(((t152:0.006935141921,(t84:0.002406232894,t15:0.002406232894):0.004528909027):0.03410573598,t177:0.0410408779):0.001067275489,((t61:0.002965820287,t76:0.002965820287):0.02629440493,(t193:0.02622099111,(t43:0.006172185022,(t157:0.003230475055,t58:0.003230475055):0.002941709967):0.02004880608):0.003039234107):0.01284792818):0.001821010938):0.009019294135):0.002039490613):0.06793682527):0.1531334246):0.002233948004,((t87:0.04906522231,((t11:0.01563574418,t75:0.01563574418):0.02364391604,(((((t57:0.0009807909034,(t194:0.0008949299043,t148:0.0008949299043):8.586099913e-05):0.001861392978,(t200:0.001441717421,t187:0.001441717421):0.001400466461):0.001357171345,t99:0.004199355226):0.001566562357,(t98:0.001950992004,t10:0.001950992004):0.00381492558):0.03001539742,(t13:0.0021885773,t86:0.0021885773):0.03359273771):0.003498345211):0.009785562088):0.02690091434,(t163:0.01872525229,((t116:0.01464779197,t56:0.01464779197):0.00283128921,t115:0.01747908118):0.001246171107):0.05724088436):0.2023260103):0.3324676908,((t169:0.002802411051,t85:0.002802411051):0.1761485411,(((t168:0.01341863577,((t20:0.007710175644,t74:0.007710175644):0.002553281287,t30:0.01026345693):0.003155178836):0.0008101106658,t184:0.01422874643):0.09348964159,((((t40:0.01463560083,t127:0.01463560083):0.01223545504,t109:0.02687105587):0.04851545256,(t158:8.179056079e-05,t5:8.179056079e-05):0.07530471787):0.02556232612,((t174:0.0009604562832,t37:0.0009604562832):0.05593658119,(t6:0.04390553312,t95:0.04390553312):0.01299150436):0.04405179707):0.006769553476):0.07123256408):0.4318088857):0.5081146259,((((t171:0.004043940093,(t78:0.0008538939207,t62:0.0008538939207):0.003190046172):0.0554269347,((t82:0.008243726062,(t129:0.003190267085,(t45:0.002783733947,t35:0.002783733947):0.0004065331382):0.005053458978):0.009886355653,(t79:0.008692617866,t44:0.008692617866):0.009437463849):0.04134079307):0.1039076875,t142:0.1633785623):0.7454326277,(((t167:0.006277691585,t189:0.006277691585):0.5488778536,(((t118:0.005919988874,t150:0.005919988874):0.1234955162,((t125:0.01527192994,((t90:0.00812152768,t182:0.00812152768):0.002014059422,t22:0.0101355871):0.005136342834):0.01337681453,(t24:0.008517511349,(t195:0.004414951146,t36:0.004414951146):0.004102560203):0.02013123312):0.1007667606):0.2191400545,((((t73:0.002373228209,t160:0.002373228209):0.02579293915,((t117:0.004830074017,t136:0.004830074017):0.0008059735155,(t151:0.0004936456681,t4:0.0004936456681):0.005142401864):0.02253011983):0.02297817557,(t156:0.0303513273,((t21:0.01193339353,(t32:0.001729791094,t104:0.001729791094):0.01020360243):0.005272966001,t38:0.01720635953):0.01314496777):0.02079301562):0.07782184381,(t93:0.001698605874,t66:0.001698605874):0.1272675809):0.2195893728):0.2065999856):0.1342691723,(((t94:0.02069998981,((((t186:0.004575032749,t134:0.004575032749):0.0002919258384,t122:0.004866958588):0.00113290316,t80:0.005999861748):0.01176581555,((t159:0.008441430103,t55:0.008441430103):0.00743559327,(t135:0.006308668873,t143:0.006308668873):0.009568354499):0.001888653923):0.002934312512):0.08684166365,((((t41:0.0006001958992,t191:0.0006001958992):0.007553521153,t53:0.008153717052):0.04930899518,(t145:0.01329981967,(((t112:0.002127820493,t9:0.002127820493):0.003106794346,t8:0.005234614839):0.007417192558,t119:0.0126518074):0.000648012271):0.04416289257):0.03450625203,((t139:0.00179418041,((t170:0.0002514488856,t83:0.0002514488856):0.0008243500481,t192:0.001075798934):0.0007183814763):0.03108766356,(t172:0.01908318907,(t68:0.01727759701,(t100:0.00139626214,t7:0.00139626214):0.01588133487):0.00180559206):0.0137986549):0.0590871203):0.01557268919):0.06049884457,(t16:0.01217984143,(t97:0.001119180658,t164:0.001119180658):0.01106066078):0.1558606566):0.5213842194):0.2193864725):0.2100632738); 2 | -------------------------------------------------------------------------------- /examples/initial_lf.tre: -------------------------------------------------------------------------------- 1 | (((Araucarius_minor:15.1256,(Dendroctonus_ponderosae:11.8787,Hylastes_porculus:11.8787):3.24688):1.56056,Ctonoxylon_flavescens:16.6862):984.233,(((((((Cactophagus_spinolae:4.57486,(Rhodobaenus_cf_nawradii:4.26946,Rhodobaenus_nigrofasciatus:4.26946):0.305392):1.31849,(Metamasius_callizona:5.1872,((Metamasius_hemipterus:2.91533,Metamasius_sp_nr_hemipterus:2.91533):1.7059,(Sphenophorus_coesifrons:2.66255,Sphenophorus_venatus:2.66255):1.95868):0.565968):0.706146):2.61192,Rhabdoscelus_obscurus:8.50526):2.42752,((Scyphophorus_acupunctatus:2.41741,Scyphophorus_yuccae:2.41741):2.7405,Sphenophorus_striatopunctatus:5.15791):5.77486):0.581105,(Diocalandra_frumenti:9.83098,((Sitophilus_granarius:3.29968,((Sitophilus_oryzae:1.99136,Sitophilus_zeamais:1.99136):0.867981,Sitophilus_vateriae:2.85934):0.440345):0.779509,Sitophilus_linearis:4.07919):5.75179):1.6829):2.08353,(Cosmopolites_sordidus:8.54012,(((Dynamis_borassi:4.5432,Rhynchophorus_palmarum:4.5432):0.931484,Rhynchophorus_cruentatus:5.47469):0.847395,Rhynchophorus_phoenicis:6.32208):2.21804):5.05729):986.403,(Mesocordylus_bracteolatus:21.2961,Rhinostomus_barbirostris:21.2961):978.704):0.919303) 2 | -------------------------------------------------------------------------------- /examples/initial_pl.tre: -------------------------------------------------------------------------------- 1 | ((((((Encephal:12.1417,Cycas:12.1417)1:14.2926,Ginkgo:26.4343)2:33.0857,(((Welwitsch:13.3971,Ephedra:13.3971)3:12.1576,Pinus:25.5548)4:16.1734,(Araucaria:20.7012,Torreya:20.7012)5:21.0269)6:17.7918)7:30.0475,((Drimys:39.6047,(Pisum:21.361,Nicotiana:21.361)8:18.2437)9:23.8163,(Zea:31.312,Oryza:31.312)10:32.1089)11:26.1465)12:30.4326,(((Equisetum:20.4757,Adiantum:20.4757)13:14.7219,Angiopter:35.1976)14:14.8024,Psilotum:50)15:70)16:20,Huperzia:140)17 2 | -------------------------------------------------------------------------------- /examples/pl4203.chisq: -------------------------------------------------------------------------------- 1 | 1000 1421.4912 2 | 500 1449.6408 3 | 250 1479.9312 4 | 125 1508.4564 5 | 62.5 1535.2184 6 | 31.25 1561.7357 7 | 15.625 1584.9574 8 | 7.8125 1601.5655 9 | 3.90625 1611.7705 10 | 1.953125 1617.4801 11 | 0.9765625 1620.507 12 | 0.48828125 1622.0657 13 | 0.24414062 1622.8601 14 | 0.12207031 1623.2247 15 | 0.061035156 1623.4432 16 | 0.030517578 1623.487 17 | 0.015258789 1623.485 18 | 0.0076293945 1623.1383 19 | 0.0038146973 1621.9601 20 | 0.0019073486 1622.403 21 | 0.00095367432 1618.3836 22 | 0.00047683716 1611.3749 23 | 0.00023841858 1579.5075 24 | 0.00011920929 1525.2017 25 | 5.9604645e-05 1369.6358 26 | 2.9802322e-05 1218.1786 27 | 1.4901161e-05 1018.9204 28 | 7.4505806e-06 515.13208 29 | 3.7252903e-06 483.01434 30 | 1.8626451e-06 693.8453 31 | -------------------------------------------------------------------------------- /examples/pl4203.chisq_r8s: -------------------------------------------------------------------------------- 1 | 1e-07 23466.26 2 | 1e-06 33459.23 3 | 0.00001 1692.15 4 | 0.0001 1590.62 5 | 0.001 1588.12 6 | 0.01 1587.61 7 | 0.1 1587.33 8 | 1 1584.55 9 | 10 1561.53 10 | 100 1484.81 11 | -------------------------------------------------------------------------------- /examples/pl4203.cppr8s: -------------------------------------------------------------------------------- 1 | treefile = pl4203.tre 2 | numsites=2744 3 | mrca = ingroup Cactophagus_spinolae Rhinostomus_barbirostris 4 | mrca = root Dendroctonus_ponderosae Rhinostomus_barbirostris 5 | min = root 1000 6 | max = root 1000 7 | [max = ingroup 900] 8 | smooth = 0.0001 9 | cv 10 | randomcv 11 | cviter = 2 12 | cvsimaniter = 10 13 | cvstart = 0.0001 14 | cvstop = 100 15 | cvmultstep = 0.1 16 | thorough 17 | cvoutfile = test.cv 18 | nthreads = 4 19 | [prime] 20 | lfiter = 1 21 | opt = 5 22 | optad = 2 23 | moredetailad 24 | optcvad = 2 25 | moredetailcvad 26 | [ind8s = dates.tre] 27 | [inr8s = rates.tre] 28 | -------------------------------------------------------------------------------- /examples/pl4203.ind8s: -------------------------------------------------------------------------------- 1 | (((Araucarius_minor:95.261678,Dendroctonus_ponderosae:95.261678,Hylastes_porculus:95.261678):2.715021,Ctonoxylon_flavescens:97.976700):16.250371,(((((((Cactophagus_spinolae:33.672841,(Rhodobaenus_cf_nawradii:31.553315,Rhodobaenus_nigrofasciatus:31.553315):2.119526):9.346842,(Metamasius_callizona:37.199824,((Metamasius_hemipterus:19.404565,Metamasius_sp_nr_hemipterus:19.404565):12.901453,(Sphenophorus_coesifrons:18.473554,Sphenophorus_venatus:18.473554):13.832464):4.893806):5.819858):20.789569,Rhabdoscelus_obscurus:63.809251):16.824875,((Scyphophorus_acupunctatus:22.046970,Scyphophorus_yuccae:22.046970):20.737745,Sphenophorus_striatopunctatus:42.784715):37.849411):3.130232,(Diocalandra_frumenti:73.654229,((Sitophilus_granarius:27.562737,((Sitophilus_oryzae:14.760106,Sitophilus_zeamais:14.760106):8.187263,Sitophilus_vateriae:22.947369):4.615368):7.004413,Sitophilus_linearis:34.567150):39.087078):10.110130):7.135915,(Cosmopolites_sordidus:67.395036,(((Dynamis_borassi:40.677839,Rhynchophorus_palmarum:40.677839):8.564608,Rhynchophorus_cruentatus:49.242447):5.680288,Rhynchophorus_phoenicis:54.922736):12.472301):23.505237):9.099727,(Mesocordylus_bracteolatus:81.591095,Rhinostomus_barbirostris:81.591095):18.408905)ingroup:14.227071); 2 | -------------------------------------------------------------------------------- /examples/pl4203.inr8s: -------------------------------------------------------------------------------- 1 | (((Araucarius_minor:0.005536,Dendroctonus_ponderosae:0.004820,Hylastes_porculus:0.004438):0.005235,Ctonoxylon_flavescens:0.006982):0.006167,(((((((Cactophagus_spinolae:0.007230,(Rhodobaenus_cf_nawradii:0.004816,Rhodobaenus_nigrofasciatus:0.008246):0.006706):0.007018,(Metamasius_callizona:0.005604,((Metamasius_hemipterus:0.009127,Metamasius_sp_nr_hemipterus:0.007757):0.008248,(Sphenophorus_coesifrons:0.008226,Sphenophorus_venatus:0.006569):0.007456):0.007521):0.006700):0.006907,Rhabdoscelus_obscurus:0.005140):0.006281,((Scyphophorus_acupunctatus:0.007504,Scyphophorus_yuccae:0.002761):0.005764,Sphenophorus_striatopunctatus:0.005707):0.006249):0.006403,(Diocalandra_frumenti:0.006675,((Sitophilus_granarius:0.003967,((Sitophilus_oryzae:0.008123,Sitophilus_zeamais:0.008592):0.007834,Sitophilus_vateriae:0.005066):0.006159):0.005307,Sitophilus_linearis:0.004744):0.005575):0.006308):0.006537,(Cosmopolites_sordidus:0.005970,(((Dynamis_borassi:0.005187,Rhynchophorus_palmarum:0.005859):0.005319,Rhynchophorus_cruentatus:0.003708):0.004812,Rhynchophorus_phoenicis:0.005560):0.005435):0.005954):0.006488,(Mesocordylus_bracteolatus:0.005632,Rhinostomus_barbirostris:0.007450):0.006533)ingroup:0.006455); 2 | -------------------------------------------------------------------------------- /examples/pl4203.log: -------------------------------------------------------------------------------- 1 | Reading tree PAUP_4203 2 | Executing blformat command... 3 | Number of sites in sequences set to 2744 4 | Branch lengths assumed to be in units of numbers of substitutions per site 5 | All branch lengths multipled by the 2744 sites in the sequence 6 | Branch lengths rounded to nearest integer 7 | (This may not be a good idea when using CALIBRATE on ultrametric user supplied input trees. Use ROUND=NO then) 8 | Pruning taxon Apion_sp 9 | Pruning taxon Penestes_sp 10 | Pruning taxon Tanysphyrus_lemnae 11 | ********************* WARNING ********************** 12 | 13 | MRCA COMMAND: Num nodes less than num labels: You probably have misspelled a taxon name! 14 | 15 | **************************************************** 16 | Defining clade name: ingroup 17 | 0 zero-length branches collapsed 18 | Fixing age of ingroup at 1000.000000 19 | (The age of this node will no longer be estimated.) 20 | (This command overides any previous age constraints for this node.) 21 | (The total number of fixed ages is now 1) 22 | [Printing tree 1] 23 | 24 | [TREE DESCRIPTION of tree PAUP_4203] 25 | 26 | tree PAUP_4203 = (((Araucarius_minor:952.324999,(Dendroctonus_ponderosae:809.794042,Hylastes_porculus:809.794042):142.530957):24.655171,Ctonoxylon_flavescens:976.980170):161.436550,(((((((Cactophagus_spinolae:336.886036,(Rhodobaenus_cf_nawradii:315.750364,Rhodobaenus_nigrofasciatus:315.750364):21.135671):92.477561,(Metamasius_callizona:371.076676,((Metamasius_hemipterus:193.596584,Metamasius_sp_nr_hemipterus:193.596584):128.792631,(Sphenophorus_coesifrons:184.208106,Sphenophorus_venatus:184.208106):138.181109):48.687461):58.286921):206.364321,Rhabdoscelus_obscurus:635.727918):167.701975,((Scyphophorus_acupunctatus:214.679208,Scyphophorus_yuccae:214.679208):206.135007,Sphenophorus_striatopunctatus:420.814215):382.615677):31.596612,(Diocalandra_frumenti:732.645386,((Sitophilus_granarius:267.270968,((Sitophilus_oryzae:143.579791,Sitophilus_zeamais:143.579791):79.025571,Sitophilus_vateriae:222.605362):44.665606):69.284221,Sitophilus_linearis:336.555190):396.090197):102.381118):73.137964,(Cosmopolites_sordidus:675.619530,(((Dynamis_borassi:410.273859,Rhynchophorus_palmarum:410.273859):86.019886,Rhynchophorus_cruentatus:496.293745):56.841705,Rhynchophorus_phoenicis:553.135450):122.484080):232.544937):91.835533,(Mesocordylus_bracteolatus:816.744814,Rhinostomus_barbirostris:816.744814):183.255186)ingroup:138.416720); 27 | [Printing tree 1] 28 | 29 | [RATO DESCRIPTION of tree PAUP_4203] 30 | 31 | tree PAUP_4203 = (((Araucarius_minor:0.000554,(Dendroctonus_ponderosae:0.000567,Hylastes_porculus:0.000522):0.000552):0.000576,Ctonoxylon_flavescens:0.000700):0.000622,(((((((Cactophagus_spinolae:0.000722,(Rhodobaenus_cf_nawradii:0.000483,Rhodobaenus_nigrofasciatus:0.000822):0.000672):0.000708,(Metamasius_callizona:0.000563,((Metamasius_hemipterus:0.000913,Metamasius_sp_nr_hemipterus:0.000778):0.000825,(Sphenophorus_coesifrons:0.000823,Sphenophorus_venatus:0.000660):0.000746):0.000754):0.000669):0.000694,Rhabdoscelus_obscurus:0.000516):0.000629,((Scyphophorus_acupunctatus:0.000767,Scyphophorus_yuccae:0.000286):0.000579,Sphenophorus_striatopunctatus:0.000581):0.000618):0.000633,(Diocalandra_frumenti:0.000671,((Sitophilus_granarius:0.000410,((Sitophilus_oryzae:0.000834,Sitophilus_zeamais:0.000881):0.000808,Sitophilus_vateriae:0.000524):0.000634):0.000536,Sitophilus_linearis:0.000488):0.000550):0.000623):0.000637,(Cosmopolites_sordidus:0.000596,(((Dynamis_borassi:0.000514,Rhynchophorus_palmarum:0.000581):0.000529,Rhynchophorus_cruentatus:0.000368):0.000481,Rhynchophorus_phoenicis:0.000552):0.000553):0.000602):0.000642,(Mesocordylus_bracteolatus:0.000563,Rhinostomus_barbirostris:0.000744):0.000656)ingroup:0.000663); 32 | ----------------------------------------------------------------------------------------- 33 | Estimated ages and substitution rates for tree PAUP_4203 34 | 35 | Reconstruction method: Penalized likelihood 36 | Named internal nodes indicated by [*] 37 | Rates are for branches subtending indicated node 38 | Rates are in units of substitutions per site per unit time 39 | 40 | Constraints Rates 41 | Node Fix [Mod] Min Max Age Estimated Local 42 | ----------------------------------------------------------------------------------------- 43 | (5) [0] -- -- 1138.42 44 | (6) [0] -- -- 976.98 6.2170e-04 6.2079e-04 45 | (7) [0] -- -- 952.32 5.7633e-04 5.7646e-04 46 | Araucari * [0] -- -- 0.00 5.5380e-04 5.5373e-04 47 | (9) [0] -- -- 809.79 5.5245e-04 5.5228e-04 48 | Dendroct * [0] -- -- 0.00 5.6698e-04 5.6704e-04 49 | Hylastes * [0] -- -- 0.00 5.2214e-04 5.2203e-04 50 | Ctonoxyl * [0] -- -- 0.00 6.9985e-04 7.0016e-04 51 | [*] ingroup * [0] -- -- 1000.00 6.6251e-04 6.6348e-04 52 | (14) [0] -- -- 908.16 6.4193e-04 6.4287e-04 53 | (15) [0] -- -- 835.03 6.3713e-04 6.3780e-04 54 | (16) [0] -- -- 803.43 6.3279e-04 6.3436e-04 55 | (17) [0] -- -- 635.73 6.2928e-04 6.3020e-04 56 | (18) [0] -- -- 429.36 6.9437e-04 6.9579e-04 57 | (19) [0] -- -- 336.89 7.0787e-04 7.0934e-04 58 | Cactopha * [0] -- -- 0.00 7.2245e-04 7.2262e-04 59 | (21) [0] -- -- 315.75 6.7192e-04 6.7246e-04 60 | Rhodobae * [0] -- -- 0.00 4.8288e-04 4.8129e-04 61 | Rhodobae * [0] -- -- 0.00 8.2194e-04 8.2408e-04 62 | (24) [0] -- -- 371.08 6.6922e-04 6.6900e-04 63 | Metamasi * [0] -- -- 0.00 5.6264e-04 5.6176e-04 64 | (26) [0] -- -- 322.39 7.5415e-04 7.5600e-04 65 | (27) [0] -- -- 193.60 8.2518e-04 8.2624e-04 66 | Metamasi * [0] -- -- 0.00 9.1260e-04 9.1486e-04 67 | Metamasi * [0] -- -- 0.00 7.7847e-04 7.7744e-04 68 | (30) [0] -- -- 184.21 7.4633e-04 7.4637e-04 69 | Sphenoph * [0] -- -- 0.00 8.2310e-04 8.2498e-04 70 | Sphenoph * [0] -- -- 0.00 6.6049e-04 6.5880e-04 71 | Rhabdosc * [0] -- -- 0.00 5.1643e-04 5.1593e-04 72 | (34) [0] -- -- 420.81 6.1762e-04 6.1816e-04 73 | (35) [0] -- -- 214.68 5.7886e-04 5.7988e-04 74 | Scyphoph * [0] -- -- 0.00 7.6700e-04 7.7069e-04 75 | Scyphoph * [0] -- -- 0.00 2.8563e-04 2.8349e-04 76 | Sphenoph * [0] -- -- 0.00 5.8051e-04 5.8023e-04 77 | (39) [0] -- -- 732.65 6.2260e-04 6.2292e-04 78 | Diocalan * [0] -- -- 0.00 6.7078e-04 6.7102e-04 79 | (41) [0] -- -- 336.56 5.5017e-04 5.5020e-04 80 | (42) [0] -- -- 267.27 5.3593e-04 5.3651e-04 81 | Sitophil * [0] -- -- 0.00 4.1012e-04 4.0906e-04 82 | (44) [0] -- -- 222.61 6.3375e-04 6.3641e-04 83 | (45) [0] -- -- 143.58 8.0750e-04 8.1164e-04 84 | Sitophil * [0] -- -- 0.00 8.3421e-04 8.3506e-04 85 | Sitophil * [0] -- -- 0.00 8.8082e-04 8.8329e-04 86 | Sitophil * [0] -- -- 0.00 5.2366e-04 5.2224e-04 87 | Sitophil * [0] -- -- 0.00 4.8777e-04 4.8727e-04 88 | (50) [0] -- -- 675.62 6.0158e-04 6.0178e-04 89 | Cosmopol * [0] -- -- 0.00 5.9553e-04 5.9550e-04 90 | (52) [0] -- -- 553.14 5.5283e-04 5.5341e-04 91 | (53) [0] -- -- 496.29 4.8117e-04 4.8085e-04 92 | (54) [0] -- -- 410.27 5.2919e-04 5.2957e-04 93 | Dynamis_ * [0] -- -- 0.00 5.1441e-04 5.1430e-04 94 | Rhynchop * [0] -- -- 0.00 5.8053e-04 5.8092e-04 95 | Rhynchop * [0] -- -- 0.00 3.6835e-04 3.6789e-04 96 | Rhynchop * [0] -- -- 0.00 5.5212e-04 5.5211e-04 97 | (59) [0] -- -- 816.74 6.5627e-04 6.5626e-04 98 | Mesocord * [0] -- -- 0.00 5.6301e-04 5.6266e-04 99 | Rhinosto * [0] -- -- 0.00 7.4383e-04 7.4426e-04 100 | ----------------------------------------------------------------------------------------- 101 | 102 | Summary of rate variation (substitutions per site per unit time) 103 | Mean = 0.0006281 104 | Std Dev = 0.0001255 105 | Min = 0.0002856 106 | Max = 0.0009126 107 | Range = 0.000627 108 | Ratio = 3.195 109 | -------------------------------------------------------------------------------- /examples/pl4203.nex: -------------------------------------------------------------------------------- 1 | #nexus 2 | begin trees; 3 | tree PAUP_4203 = [&R] (((Araucarius_minor:0.527237,(Dendroctonus_ponderosae:0.459213,Hylastes_porculus:0.422817):0.078654):0.014095,Ctonoxylon_flavescens:0.684218):0.100091,(((((((Cactophagus_spinolae:0.243276,(Rhodobaenus_cf_nawradii:0.151873,Rhodobaenus_nigrofasciatus:0.2601):0.014269):0.065451,(Metamasius_callizona:0.208472,((Metamasius_hemipterus:0.177235,Metamasius_sp_nr_hemipterus:0.150374):0.10626,(Sphenophorus_coesifrons:0.151807,Sphenophorus_venatus:0.121463):0.103086):0.0367):0.038845):0.143412,Rhabdoscelus_obscurus:0.327959):0.105817,((Scyphophorus_acupunctatus:0.165328,Scyphophorus_yuccae:0.060699):0.119636,Sphenophorus_striatopunctatus:0.244268):0.236606):0.019965,(Diocalandra_frumenti:0.491588,((Sitophilus_granarius:0.109277,((Sitophilus_oryzae:0.1198,Sitophilus_zeamais:0.126708):0.064102,Sitophilus_vateriae:0.116119):0.028449):0.03722,Sitophilus_linearis:0.163874):0.218052):0.063816):0.046508,(Cosmopolites_sordidus:0.402212,(((Dynamis_borassi:0.210866,Rhynchophorus_palmarum:0.238278):0.045652,Rhynchophorus_cruentatus:0.182456):0.027441,Rhynchophorus_phoenicis:0.305368):0.067839):0.140024):0.059047,(Mesocordylus_bracteolatus:0.45971,Rhinostomus_barbirostris:0.607998):0.120275):0.091744):0.1; 4 | end; 5 | 6 | begin r8s; 7 | blformat nsites=2744 lengths=persite; 8 | mrca ingroup = Cactophagus_spinolae Rhinostomus_barbirostris; 9 | mrca root = Dendroctonus_ponderosae Rhinostomus_barbirostris; 10 | [collapse;] 11 | fixage taxon=root age=1000; 12 | constrain taxon=ingroup max_age=900; 13 | set ftol=1e-10 maxiter=1000000; 14 | [set verbose=0; suppresses huge amount of output in CV analyses] 15 | [divtime method=pl algorithm=tn cvStart=-4 cvInc=1 cvNum=7 crossv=yes;] 16 | set smoothing = 0.0001; 17 | divtime method=pl; 18 | describe plot=cladogram; 19 | show rates; 20 | penalty=additive; 21 | describe plot=node_info; 22 | describe plot=chrono_description; 23 | describe plot=rato_description; 24 | end; 25 | -------------------------------------------------------------------------------- /examples/pl4203.tre: -------------------------------------------------------------------------------- 1 | (((Araucarius_minor:0.527237,(Dendroctonus_ponderosae:0.459213,Hylastes_porculus:0.422817):0.078654):0.014095,Ctonoxylon_flavescens:0.684218):0.100091,(((((((Cactophagus_spinolae:0.243276,(Rhodobaenus_cf_nawradii:0.151873,Rhodobaenus_nigrofasciatus:0.2601):0.014269):0.065451,(Metamasius_callizona:0.208472,((Metamasius_hemipterus:0.177235,Metamasius_sp_nr_hemipterus:0.150374):0.10626,(Sphenophorus_coesifrons:0.151807,Sphenophorus_venatus:0.121463):0.103086):0.0367):0.038845):0.143412,Rhabdoscelus_obscurus:0.327959):0.105817,((Scyphophorus_acupunctatus:0.165328,Scyphophorus_yuccae:0.060699):0.119636,Sphenophorus_striatopunctatus:0.244268):0.236606):0.019965,(Diocalandra_frumenti:0.491588,((Sitophilus_granarius:0.109277,((Sitophilus_oryzae:0.1198,Sitophilus_zeamais:0.126708):0.064102,Sitophilus_vateriae:0.116119):0.028449):0.03722,Sitophilus_linearis:0.163874):0.218052):0.063816):0.046508,(Cosmopolites_sordidus:0.402212,(((Dynamis_borassi:0.210866,Rhynchophorus_palmarum:0.238278):0.045652,Rhynchophorus_cruentatus:0.182456):0.027441,Rhynchophorus_phoenicis:0.305368):0.067839):0.140024):0.059047,(Mesocordylus_bracteolatus:0.45971,Rhinostomus_barbirostris:0.607998):0.120275):0.091744):0.1; 2 | -------------------------------------------------------------------------------- /examples/test.cppr8s: -------------------------------------------------------------------------------- 1 | treefile = test.tre 2 | outfile = test.tre.out 3 | smooth = 0.1 4 | numsites = 10000 5 | mrca = rt a f 6 | mrca = c1 a b 7 | min = c1 3 8 | max = c1 4 9 | min = rt 10 10 | max = rt 10 11 | [verbose] 12 | [thorough] 13 | [prime] 14 | #cv 15 | #cvstart = 0.1 16 | #cvstop = 0.1 17 | -------------------------------------------------------------------------------- /examples/test.nex: -------------------------------------------------------------------------------- 1 | #nexus 2 | begin trees; 3 | [tree PAUP_4203 = [&R] (((a:0.3,b:0.3):0.2,((c:0.2,d:0.2):0.1,e:0.3):0.2):0.1,(f:0.4,g:0.4):0.2):0.1;] 4 | tree PAUP_4203 = [&R] (((a:0.3,b:0.9):0.2,((c:0.2,d:0.8):0.1,e:0.7):0.2):0.1,(f:0.1,g:0.4):0.2):0.1; 5 | end; 6 | 7 | begin r8s; 8 | blformat nsites=1000 lengths=persite; 9 | mrca nrt = a b; 10 | mrca rt = a f; 11 | [collapse;] 12 | constrain taxon=rt max_age=150; 13 | constrain taxon=nrt min_age=50; 14 | set ftol=1e-10 maxiter=10000; 15 | [set verbose=0; suppresses huge amount of output in CV analyses] 16 | divtime method=pl algorithm=tn cvStart=-7 cvInc=1 cvNum=10 crossv=yes; 17 | set smoothing = 0.001; 18 | divtime method=pl; 19 | describe plot=cladogram; 20 | show rates; 21 | end; 22 | -------------------------------------------------------------------------------- /examples/test.tre: -------------------------------------------------------------------------------- 1 | (((a:0.3,b:0.3):0.2,((c:0.2,d:0.2):0.1,e:0.3):0.2):0.1,(f:0.4,g:0.4):0.2):0.1; 2 | -------------------------------------------------------------------------------- /examples/vib.cppr8s: -------------------------------------------------------------------------------- 1 | treefile = vib.tre 2 | outfile = vib.out 3 | smooth = 1.0 4 | numsites = 10000 5 | mrca = nrt clemensae rigidum 6 | min = nrt 10 7 | max = nrt 10 8 | cv 9 | #randomcv 10 | [verbose] 11 | thorough 12 | [prime] 13 | #cviter = 1 14 | cvstart = 0.001 15 | cvstop = 1000 16 | #randomcviter = 10 17 | #randomcv 18 | opt = 3 19 | moredetail 20 | optad = 1 21 | optcvad = 3 22 | #log_pen 23 | -------------------------------------------------------------------------------- /examples/vib.nex: -------------------------------------------------------------------------------- 1 | #nexus 2 | begin trees; 3 | tree PAUP_4203 = [&R] (clemensae:0.006881748591,(((sympodiale:0.001369860535,(cordifolium:0.00170536862,(furcatum:3.659992372E-4,lantanoides:0.002154394712):0.001767787866):1.411708119E-4):0.002885430742,((cassinoides:0.004029524804,(elatum:0.002501532668,(rufidulum:0.001098455786,(prunifolium:3.652681371E-4,lentago:0.002471233984):4.940500971E-4):5.706348535E-4):0.003913489998):3.737642607E-4,((lepidotulum:0.00208689967,punctatum:0.001602732824):0.005755573389,(macrocephalum:0.003036692438,(utile:0.001655741342,(bitchiuense:7.590337834E-4,(carlesii:3.925465508E-4,(schensianum:9.571318513E-4,((veitchii:1.352112852E-4,(buddleifolium:0.003941511938,rhytidophyllum:3.235417302E-4):1.586940981E-4):6.774933844E-4,(mongolicum:6.971516052E-4,(lantana:7.590337834E-4,(burejaeticum:2.148306713E-4,maculatum:0.001361611439):1.298403709E-4):7.885608102E-4):6.097643706E-4):0.001050828682):3.880046229E-4):2.801634833E-4):1.91960378E-4):5.776654376E-4):0.00198301969):8.363577961E-4):0.00444619413):3.58295719E-4,(((urceolatum:2.379112397E-4,taiwanianum:0.001101010557):0.007503560841,((lutescens:0.002445042549,(colebrookeanum:0.002997906238,plicatum:0.002301599604):7.824989851E-4):0.003813467911,(amplificatum:0.007321451038,((sieboldii:0.002799002429,(odoratissimum:4.00120881E-4,awabuki:2.85806227E-4):0.001765201848):0.001003764303,(farreri:5.907623649E-4,((brachybotryum:8.66575862E-4,suspensum:0.00184905506):5.365237433E-5,((erubescens:4.138293784E-4,subalpinum:4.717636353E-4):7.590337834E-4,(chingii:1.990628155E-4,oliganthum:1.561740178E-4):7.590337834E-4):4.136083849E-4):7.590337834E-4):4.448206077E-4):0.002804278159):0.00149216394):0.0021545487):0.001019244433,(((rigidum:6.240466845E-4,tinus:8.016613591E-4):0.005395755943,((atrocyaneum:1.25524723E-4,calvum:4.387136991E-4):0.002494609511,(cinnamomifolium:0.002121008629,propinquum:0.001979199248):4.081119217E-4):0.003482896631):0.003238673534,(((ellipticum:9.232331033E-4,(bracteatum:3.771070353E-4,(rafinesquianum:2.617275643E-4,molle:4.086594346E-4):2.337838592E-4):6.9082842E-4):0.003090236829,((pubescens:3.177181799E-4,(dentatum:7.590337834E-4,(dasyanthum:5.755210051E-4,(carolinianum:7.590337834E-4,recognitum:4.018345568E-4):5.185067321E-4):7.590337834E-4):7.590337834E-4):7.321134462E-4,((triphyllum:9.723727089E-4,hartwegii:0.001552900236):1.358689023E-4,(caudatum:7.647300153E-4,(stenocalyx:4.67080252E-4,loeseneri:6.253180443E-4):7.590337834E-4):4.382975788E-4):4.984191447E-4):0.002448934489):0.006236243013,(((edule:4.810070769E-4,koreanum:5.257725277E-4):0.002424730168,(trilobum:0.002380381459,(opulus:0.001431202048,sargentii:0.001278275273):0.001659768514):0.002116699063):0.004068072809,((ternatum:0.003026667485,inopinatum:0.004307645912):0.001104824811,((acerifolium:0.001675951471,orientale:0.001589654571):7.112462947E-4,((kansuense:0.002268790891,(cylindricum:0.003660797055,(coriaceum:0.002464409943,hebanthum:0.002125600247):3.875195466E-4):0.001851158503):2.178466966E-4,((ichangense:0.001131949074,(lobophyllum:0.001245907426,flavescens:4.696413848E-4):1.599782382E-4):9.77541361E-4,((hupehense:5.358661276E-4,foetidum:7.30740863E-4):6.955677932E-4,(dilatatum:4.028934461E-4,(wrightii:1.37544681E-4,(japonicum:0.001712416441,(setigerum:7.627454889E-4,(betulifolium:7.590337834E-4,(fordiae:0.002780056524,(erosum:5.657244387E-4,(luzonicum:9.128199441E-4,(melanocarpum:7.590337834E-4,sempervirens:0.001873577):1.278820031E-4):2.531499188E-4):1.400255627E-4):7.590337834E-4):7.590337834E-4):7.590337834E-4):3.074746705E-4):3.9542387E-4):0.002667763161):8.686584836E-4):0.001176110862):7.590337834E-4):5.303989674E-4):0.003789751977):0.001333086438):4.772851642E-4):0.00223504911):5.861448129E-4):0.006881748591):0.001; 4 | end; 5 | 6 | begin r8s; 7 | blformat nsites=10000 lengths=persite; 8 | mrca ingroup = clemensae rigidum; 9 | [collapse;] 10 | fixage taxon=ingroup age=100; 11 | set ftol=1E-4 maxiter=10000; 12 | [divtime method=pl algorithm=tn cvStart=-3 cvInc=1 cvNum=7 crossv=yes;] 13 | set smoothing = .00001; 14 | divtime method=pl; 15 | describe plot=cladogram; 16 | show rates; 17 | end; 18 | -------------------------------------------------------------------------------- /examples/vib.tre: -------------------------------------------------------------------------------- 1 | (clemensae:0.006881748591,(((sympodiale:0.001369860535,(cordifolium:0.00170536862,(furcatum:3.659992372E-4,lantanoides:0.002154394712):0.001767787866):1.411708119E-4):0.002885430742,((cassinoides:0.004029524804,(elatum:0.002501532668,(rufidulum:0.001098455786,(prunifolium:3.652681371E-4,lentago:0.002471233984):4.940500971E-4):5.706348535E-4):0.003913489998):3.737642607E-4,((lepidotulum:0.00208689967,punctatum:0.001602732824):0.005755573389,(macrocephalum:0.003036692438,(utile:0.001655741342,(bitchiuense:7.590337834E-4,(carlesii:3.925465508E-4,(schensianum:9.571318513E-4,((veitchii:1.352112852E-4,(buddleifolium:0.003941511938,rhytidophyllum:3.235417302E-4):1.586940981E-4):6.774933844E-4,(mongolicum:6.971516052E-4,(lantana:7.590337834E-4,(burejaeticum:2.148306713E-4,maculatum:0.001361611439):1.298403709E-4):7.885608102E-4):6.097643706E-4):0.001050828682):3.880046229E-4):2.801634833E-4):1.91960378E-4):5.776654376E-4):0.00198301969):8.363577961E-4):0.00444619413):3.58295719E-4,(((urceolatum:2.379112397E-4,taiwanianum:0.001101010557):0.007503560841,((lutescens:0.002445042549,(colebrookeanum:0.002997906238,plicatum:0.002301599604):7.824989851E-4):0.003813467911,(amplificatum:0.007321451038,((sieboldii:0.002799002429,(odoratissimum:4.00120881E-4,awabuki:2.85806227E-4):0.001765201848):0.001003764303,(farreri:5.907623649E-4,((brachybotryum:8.66575862E-4,suspensum:0.00184905506):5.365237433E-5,((erubescens:4.138293784E-4,subalpinum:4.717636353E-4):7.590337834E-4,(chingii:1.990628155E-4,oliganthum:1.561740178E-4):7.590337834E-4):4.136083849E-4):7.590337834E-4):4.448206077E-4):0.002804278159):0.00149216394):0.0021545487):0.001019244433,(((rigidum:6.240466845E-4,tinus:8.016613591E-4):0.005395755943,((atrocyaneum:1.25524723E-4,calvum:4.387136991E-4):0.002494609511,(cinnamomifolium:0.002121008629,propinquum:0.001979199248):4.081119217E-4):0.003482896631):0.003238673534,(((ellipticum:9.232331033E-4,(bracteatum:3.771070353E-4,(rafinesquianum:2.617275643E-4,molle:4.086594346E-4):2.337838592E-4):6.9082842E-4):0.003090236829,((pubescens:3.177181799E-4,(dentatum:7.590337834E-4,(dasyanthum:5.755210051E-4,(carolinianum:7.590337834E-4,recognitum:4.018345568E-4):5.185067321E-4):7.590337834E-4):7.590337834E-4):7.321134462E-4,((triphyllum:9.723727089E-4,hartwegii:0.001552900236):1.358689023E-4,(caudatum:7.647300153E-4,(stenocalyx:4.67080252E-4,loeseneri:6.253180443E-4):7.590337834E-4):4.382975788E-4):4.984191447E-4):0.002448934489):0.006236243013,(((edule:4.810070769E-4,koreanum:5.257725277E-4):0.002424730168,(trilobum:0.002380381459,(opulus:0.001431202048,sargentii:0.001278275273):0.001659768514):0.002116699063):0.004068072809,((ternatum:0.003026667485,inopinatum:0.004307645912):0.001104824811,((acerifolium:0.001675951471,orientale:0.001589654571):7.112462947E-4,((kansuense:0.002268790891,(cylindricum:0.003660797055,(coriaceum:0.002464409943,hebanthum:0.002125600247):3.875195466E-4):0.001851158503):2.178466966E-4,((ichangense:0.001131949074,(lobophyllum:0.001245907426,flavescens:4.696413848E-4):1.599782382E-4):9.77541361E-4,((hupehense:5.358661276E-4,foetidum:7.30740863E-4):6.955677932E-4,(dilatatum:4.028934461E-4,(wrightii:1.37544681E-4,(japonicum:0.001712416441,(setigerum:7.627454889E-4,(betulifolium:7.590337834E-4,(fordiae:0.002780056524,(erosum:5.657244387E-4,(luzonicum:9.128199441E-4,(melanocarpum:7.590337834E-4,sempervirens:0.001873577):1.278820031E-4):2.531499188E-4):1.400255627E-4):7.590337834E-4):7.590337834E-4):7.590337834E-4):3.074746705E-4):3.9542387E-4):0.002667763161):8.686584836E-4):0.001176110862):7.590337834E-4):5.303989674E-4):0.003789751977):0.001333086438):4.772851642E-4):0.00223504911):5.861448129E-4):0.006881748591):0.001; 2 | -------------------------------------------------------------------------------- /src/Makefile.in: -------------------------------------------------------------------------------- 1 | 2 | #CC := /opt/intel/composer_xe_2011_sp1/bin/icc 3 | #CP := /opt/intel/composer_xe_2011_sp1/bin/icc 4 | #probably need something like this if using intel 5 | #export LD_LIBRARY_PATH=/opt/intel/composer_xe_2011_sp1.6.233/compiler/lib/intel64/:$LD_LIBRARY_PATH 6 | #get some errors with intel with really big trees 7 | CC := @CC@ 8 | CP := @CXX@ -std=c++11 9 | 10 | OPENMP := -fopenmp 11 | #OPENMP := -openmp -parallel 12 | 13 | LIBS := -lm $(OPENMP) -ladolc -lnlopt -L/usr/lib64:/usr/local/lib64 14 | LDFLAGS := -L/usr/local/lib64 -I/usr/local/include 15 | 16 | RM := rm -rf 17 | 18 | SRC_DIR = ./ 19 | 20 | prefix = /usr/bin/ 21 | 22 | CPP_SRCS += \ 23 | ./main.cpp \ 24 | ./node.cpp \ 25 | ./pl_calc_parallel.cpp \ 26 | ./tree.cpp \ 27 | ./tree_reader.cpp \ 28 | ./tree_utils.cpp \ 29 | ./optimize_tnc.cpp \ 30 | ./optimize_nlopt.cpp \ 31 | ./myradops.cpp \ 32 | ./siman_calc_par.cpp \ 33 | ./optim_options.cpp \ 34 | ./utils.cpp 35 | 36 | C_SRCS += \ 37 | ./tnc.c 38 | 39 | OBJS += \ 40 | ./main.o \ 41 | ./node.o \ 42 | ./pl_calc_parallel.o \ 43 | ./tnc.o \ 44 | ./tree.o \ 45 | ./tree_reader.o \ 46 | ./tree_utils.o \ 47 | ./optimize_tnc.o \ 48 | ./optimize_nlopt.o \ 49 | ./myradops.o \ 50 | ./siman_calc_par.o \ 51 | ./optim_options.o \ 52 | ./utils.o 53 | 54 | C_DEPS += \ 55 | ./tnc.d 56 | 57 | CPP_DEPS += \ 58 | ./main.d \ 59 | ./node.d \ 60 | ./pl_calc_parallel.d \ 61 | ./tree.d \ 62 | ./tree_reader.d \ 63 | ./tree_utils.d \ 64 | ./optimize_tnc.d \ 65 | ./optimize_nlopt.d \ 66 | ./myradops.d \ 67 | ./siman_calc_par.d \ 68 | ./optim_options.d \ 69 | ./utils.d 70 | 71 | %.o: %.cpp 72 | $(CP) $(CPPFLAGS) $(LDFLAGS) -O3 -g3 -c -fmessage-length=0 $(OPENMP) -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o $@ $(SRC_DIR)$< 73 | 74 | %.o: %.c 75 | $(CC) $(CFLAGS) $(LDFLAGS) -O3 -g3 -c -fmessage-length=0 $(OPENMP) -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o $@ $< 76 | 77 | all: treePL 78 | 79 | treePL: $(OBJS) 80 | $(CP) $(LDFLAGS) -O3 -g3 -o treePL $(OBJS) $(LIBS) 81 | 82 | clean: 83 | -$(RM) *.d *.o treePL 84 | 85 | distclean: 86 | -$(RM) *.o *.d configure config.log config.h config.status treePL Makefile 87 | 88 | install: 89 | install -m 0755 treePL $(prefix) 90 | 91 | uninstall: 92 | -rm $(prefix)treePL 93 | 94 | -------------------------------------------------------------------------------- /src/README: -------------------------------------------------------------------------------- 1 | For autodiff with adol-c, need to do 2 | 3 | 4 | UBUNTU 11.10 (64 bit) 5 | ----------- 6 | git clone git://gitorious.org/adol-c/adol-c.git 7 | (OR USE THE ARCHIVED ONE) 8 | sudo apt-get install build-essential autoconf libtool 9 | cd adol-c 10 | ./update_versions (JUST ENTER THROUGH ANY LATEX ERRORS) 11 | ./configure --with-openmp-flag=-fopenmp --prefix=/usr 12 | make 13 | sudo make install 14 | export LD_LIBRARY_PATH=/usr/lib64 15 | echo export LD_LIBRARY_PATH=/usr/lib64:$LD_LIBRARY_PATH >> ~/.bashrc 16 | 17 | Ubuntu 13.10 and 14.04 (32 bit) 18 | ------------------------------------ 19 | On Ubuntu 13.10 and 140.04 32-bit, if you have installed adol-c via sudo apt-get, it may be necessary to edit the Makefile produced by configure. 20 | 21 | Particularly, the line: 22 | ``` 23 | LIBS := -lm $(OPENMP) -ladolc -L/usr/lib64 -lnlopt 24 | 25 | ``` 26 | 27 | may need to be edited to: 28 | ``` 29 | LIBS := -lm $(OPENMP) -ladolc -L/usr/lib -lnlopt 30 | ``` 31 | 32 | Otherwise, the error message: 33 | 34 | ``` 35 | ./main.o: In function `ADOLC_OpenMP_NC': 36 | /usr/include/adolc/adolc_openmp.h:46: undefined reference to `ADOLC_parallel_doCopy' 37 | /usr/include/adolc/adolc_openmp.h:47: undefined reference to `beginParallel()' 38 | ./main.o: In function `~ADOLC_OpenMP_NC': 39 | /usr/include/adolc/adolc_openmp.h:50: undefined reference to `endParallel()' 40 | collect2: error: ld returned 1 exit status 41 | make: *** [treePL] Error 1 42 | ``` 43 | 44 | may result. 45 | -------------------------------------------------------------------------------- /src/config.h.in: -------------------------------------------------------------------------------- 1 | /* config.h.in. Generated from configure.ac by autoheader. */ 2 | 3 | /* Define to 1 if you have the header file. */ 4 | #undef HAVE_ADOLC_ADOUBLE_H 5 | 6 | /* Define to 1 if you have the header file. */ 7 | #undef HAVE_FENV_H 8 | 9 | /* Define to 1 if you have the `floor' function. */ 10 | #undef HAVE_FLOOR 11 | 12 | /* Define to 1 if you have the header file. */ 13 | #undef HAVE_INTTYPES_H 14 | 15 | /* Define to 1 if you have the `m' library (-lm). */ 16 | #undef HAVE_LIBM 17 | 18 | /* Define to 1 if your system has a GNU libc compatible `malloc' function, and 19 | to 0 otherwise. */ 20 | #undef HAVE_MALLOC 21 | 22 | /* Define to 1 if you have the header file. */ 23 | #undef HAVE_MEMORY_H 24 | 25 | /* Define to 1 if you have the `pow' function. */ 26 | #undef HAVE_POW 27 | 28 | /* Define to 1 if you have the `sqrt' function. */ 29 | #undef HAVE_SQRT 30 | 31 | /* Define to 1 if stdbool.h conforms to C99. */ 32 | #undef HAVE_STDBOOL_H 33 | 34 | /* Define to 1 if you have the header file. */ 35 | #undef HAVE_STDINT_H 36 | 37 | /* Define to 1 if you have the header file. */ 38 | #undef HAVE_STDLIB_H 39 | 40 | /* Define to 1 if you have the header file. */ 41 | #undef HAVE_STRINGS_H 42 | 43 | /* Define to 1 if you have the header file. */ 44 | #undef HAVE_STRING_H 45 | 46 | /* Define to 1 if you have the header file. */ 47 | #undef HAVE_SYS_STAT_H 48 | 49 | /* Define to 1 if you have the header file. */ 50 | #undef HAVE_SYS_TYPES_H 51 | 52 | /* Define to 1 if you have the header file. */ 53 | #undef HAVE_UNISTD_H 54 | 55 | /* Define to 1 if the system has the type `_Bool'. */ 56 | #undef HAVE__BOOL 57 | 58 | /* Define to the address where bug reports for this package should be sent. */ 59 | #undef PACKAGE_BUGREPORT 60 | 61 | /* Define to the full name of this package. */ 62 | #undef PACKAGE_NAME 63 | 64 | /* Define to the full name and version of this package. */ 65 | #undef PACKAGE_STRING 66 | 67 | /* Define to the one symbol short name of this package. */ 68 | #undef PACKAGE_TARNAME 69 | 70 | /* Define to the home page for this package. */ 71 | #undef PACKAGE_URL 72 | 73 | /* Define to the version of this package. */ 74 | #undef PACKAGE_VERSION 75 | 76 | /* Define to 1 if you have the ANSI C header files. */ 77 | #undef STDC_HEADERS 78 | 79 | /* Define to `__inline__' or `__inline' if that's what the C compiler 80 | calls it, or to nothing if 'inline' is not supported under any name. */ 81 | #ifndef __cplusplus 82 | #undef inline 83 | #endif 84 | 85 | /* Define to rpl_malloc if the replacement function should be used. */ 86 | #undef malloc 87 | 88 | /* Define to `unsigned int' if does not define. */ 89 | #undef size_t 90 | -------------------------------------------------------------------------------- /src/configure.ac: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Process this file with autoconf to produce a configure script. 3 | CXXFLAGS="$CXXFLAGS -std=c++11" 4 | 5 | AC_PREREQ([2.68]) 6 | AC_INIT([treepl], [1.0], [eebsmith@umich.edu]) 7 | AC_CONFIG_SRCDIR([tnc.h]) 8 | AC_CONFIG_HEADERS([config.h]) 9 | 10 | # Checks for programs. 11 | AC_PROG_CXX 12 | AC_PROG_CC 13 | 14 | # Checks for libraries. 15 | have_adolc=no 16 | AC_SEARCH_LIBS([main], [adolc], [have_adolc=yes]) 17 | #if test "x${have_adolc}" = xyes; then 18 | # AC_CHECK_HEADERS([adolc/adouble.h],[],[have_adolc=no]) 19 | #fi 20 | 21 | AC_CHECK_HEADERS([adolc/adouble.h], [], [], 22 | [[#ifdef HAVE_ADOLC 23 | # include 24 | #endif 25 | ]]) 26 | 27 | if test "x${have_adolc}" = xno; then 28 | AC_MSG_WARN([ 29 | -------------------------------------------------------- 30 | The adolc library is helpful for parallel excution of the 31 | cross validation procedure. Failure to have this library 32 | may cause problems for convergence. 33 | In the deps folder, unpack the adolc package, go into the 34 | folder and run 35 | autoreconf -fi 36 | ./configure --with-openmp-flag=-fopenmp --prefix=/usr 37 | make 38 | sudo make install 39 | --------------------------------------------------------]) 40 | fi 41 | 42 | AC_CHECK_LIB([m], [fabs]) 43 | 44 | have_nlopt=no 45 | AC_SEARCH_LIBS([nlopt_create], [nlopt], [have_nlopt=yes]) 46 | 47 | if test "x${have_nlopt}" = xno; then 48 | AC_MSG_ERROR([ 49 | -------------------------------------------------------- 50 | The nlopt library is required for optimization. In the 51 | deps folder, you can unpack nlopt and run 52 | ./configure 53 | make 54 | sudo make install 55 | --------------------------------------------------------]) 56 | fi 57 | 58 | # Checks for header files. 59 | AC_CHECK_HEADERS([fenv.h stdlib.h string.h]) 60 | 61 | # Checks for typedefs, structures, and compiler characteristics. 62 | AC_HEADER_STDBOOL 63 | AC_C_INLINE 64 | AC_TYPE_SIZE_T 65 | 66 | # Checks for library functions. 67 | AC_FUNC_MALLOC 68 | AC_FUNC_STRTOD 69 | AC_CHECK_FUNCS([floor pow sqrt]) 70 | 71 | AC_CONFIG_FILES([Makefile]) 72 | AC_OUTPUT 73 | -------------------------------------------------------------------------------- /src/myrad.h: -------------------------------------------------------------------------------- 1 | // RAD package (Reverse Automatic Differentiation) -- 2 | // a package specialized for function and gradient evaluations. 3 | // Written in 2004 by David M. Gay at Sandia National Labs, Albuquerque, NM. 4 | 5 | #include 6 | #include 7 | 8 | class ADvar; 9 | class ADvari; 10 | class ADvar1; 11 | class ADvar2; 12 | class Derp; 13 | class ADcontext; 14 | 15 | struct ADmemblock { // We get memory in ADmemblock chunks 16 | // and never give it back, but reuse it 17 | // after each ADcontext::Gradcomp() call. 18 | ADmemblock *next; 19 | double memblk[1000]; 20 | }; 21 | 22 | class ADcontext { // A singleton class: one instance in radops.c 23 | ADmemblock *Busy, *Free; 24 | char *Mbase; 25 | size_t Mleft; 26 | ADmemblock First; 27 | void *new_ADmemblock(size_t); 28 | public: 29 | ADcontext(); 30 | void *Memalloc(size_t len); 31 | static void Gradcomp(); 32 | }; 33 | 34 | class Derp { // one derivative-propagation operation 35 | public: 36 | static Derp *LastDerp; 37 | Derp *next; 38 | const double *a; 39 | ADvari *b; 40 | ADvari *c; 41 | Derp(){}; 42 | Derp(ADvari *); 43 | Derp(const double *, ADvari *); 44 | Derp(const double *, ADvari *, ADvari *); 45 | /* c->aval += a * b->aval; */ 46 | }; 47 | 48 | class ADvari { // implementation of an ADvar 49 | public: 50 | double Val; // result of this operation 51 | double aval; // adjoint -- partial of final result w.r.t. this Val 52 | void *operator new(size_t len) { return ADvari::adc.Memalloc(len); } 53 | void operator delete(void*) {} /*Should never be called.*/ 54 | ADvari(double t) { Val = t; aval = 0;} 55 | ADvari() { Val = 0; aval = 0; } 56 | static ADcontext adc; 57 | }; 58 | 59 | class ADvar { // an "active" variable 60 | ADvari *cv; 61 | public: 62 | ADvar() { /*cv = 0;*/ } 63 | ADvar(double); 64 | ADvar(const ADvar &x) { cv = x.cv; } 65 | ADvar(ADvari *x) { cv = x; } 66 | #ifdef RAD_NO_EQ_ALIAS 67 | ADvar& operator=(const ADvar &x); 68 | #else /* allow aliasing v and w after "v = w;" */ 69 | ADvar& operator=(const ADvar &x) { cv = x.cv; return *this; } 70 | #endif 71 | ADvar& operator=(const double); 72 | friend ADvar operator+(const ADvar&); 73 | friend ADvar operator-(const ADvar&); 74 | friend ADvar operator+ (const ADvar&, const ADvar&); 75 | ADvar& operator+=(const ADvar&); 76 | friend ADvar operator+ (const ADvar&, double); 77 | ADvar& operator+=(double); 78 | friend ADvar operator+ (double L, const ADvar &R); 79 | friend ADvar operator- (const ADvar&, const ADvar&); 80 | ADvar& operator-=(const ADvar&); 81 | friend ADvar operator- (const ADvar&, double); 82 | ADvar& operator-=(double); 83 | friend ADvar operator- (double L, const ADvar &R); 84 | friend ADvar operator* (const ADvar&, const ADvar&); 85 | ADvar& operator*=(const ADvar&); 86 | friend ADvar operator* (const ADvar&, double); 87 | ADvar& operator*=(double); 88 | friend ADvar operator* (double L, const ADvar &R); 89 | friend ADvar operator/ (const ADvar&, const ADvar&); 90 | ADvar& operator/=(const ADvar&); 91 | friend ADvar operator/ (const ADvar&, double); 92 | ADvar& operator/=(double); 93 | friend ADvar atan(const ADvar&); 94 | friend ADvar atan2(const ADvar&, const ADvar&); 95 | friend ADvar atan2(double, const ADvar&); 96 | friend ADvar atan2(const ADvar&, double); 97 | friend ADvar cos (const ADvar&); 98 | friend ADvar exp (const ADvar&); 99 | friend ADvar log (const ADvar&); 100 | friend ADvar pow (const ADvar&, const ADvar&); 101 | friend ADvar pow (double, const ADvar&); 102 | friend ADvar pow (const ADvar&, double); 103 | friend ADvar sin (const ADvar&); 104 | friend ADvar sqrt(const ADvar&); 105 | friend ADvar tan (const ADvar&); 106 | friend int operator<(const ADvar&, const ADvar&); 107 | friend int operator<(const ADvar&, double); 108 | friend int operator<(double, const ADvar&); 109 | friend int operator<=(const ADvar&, const ADvar&); 110 | friend int operator<=(const ADvar&, double); 111 | friend int operator<=(double,const ADvar&); 112 | friend int operator==(const ADvar&, const ADvar&); 113 | friend int operator==(const ADvar&, double); 114 | friend int operator==(double, const ADvar&); 115 | friend int operator!=(const ADvar&, const ADvar&); 116 | friend int operator!=(const ADvar&, double); 117 | friend int operator!=(double, const ADvar&); 118 | friend int operator>=(const ADvar&, const ADvar&); 119 | friend int operator>=(const ADvar&, double); 120 | friend int operator>=(double, const ADvar&); 121 | friend int operator>(const ADvar&, const ADvar&); 122 | friend int operator>(const ADvar&, double); 123 | friend int operator>(double, const ADvar&); 124 | 125 | operator ADvari*() { return cv; } 126 | 127 | double val() { return cv->Val; } 128 | double adj() { return cv->aval; } 129 | }; 130 | 131 | class ADvar1: public ADvari { // simplest unary ops 132 | public: 133 | Derp d; 134 | ADvar1(double val1): ADvari(val1) {} 135 | ADvar1(double val1, ADvari *c1): d(c1) { Val = val1; } 136 | ADvar1(double val1, const double *a1, ADvari *c1): d(a1,this,c1) { Val = val1; } 137 | }; 138 | 139 | class ADvar1s: public ADvar1 { // unary ops with partial "a" 140 | public: 141 | double a; 142 | ADvar1s(double val1, double a1, ADvari *c1): ADvar1(val1,&a,c1), a(a1) {} 143 | }; 144 | 145 | 146 | class ADvar2: public ADvari { // basic binary ops 147 | public: 148 | Derp dL, dR; 149 | ADvar2(double val1): ADvari(val1) {} 150 | ADvar2(double val1, ADvari *Lcv, const double *Lc, ADvari *Rcv, const double *Rc): 151 | ADvari(val1) { 152 | dR.next = Derp::LastDerp; 153 | dL.next = &dR; 154 | Derp::LastDerp = &dL; 155 | dL.a = Lc; 156 | dL.c = Lcv; 157 | dR.a = Rc; 158 | dR.c = Rcv; 159 | dL.b = dR.b = this; 160 | } 161 | }; 162 | 163 | class ADvar2q: public ADvar2 { // binary ops with partials "a", "b" 164 | public: 165 | double a, b; 166 | ADvar2q(double val1, double Lp, double Rp, ADvari *Lcv, ADvari *Rcv): 167 | ADvar2(val1), a(Lp), b(Rp) { 168 | dR.next = Derp::LastDerp; 169 | dL.next = &dR; 170 | Derp::LastDerp = &dL; 171 | dL.a = &a; 172 | dL.c = Lcv; 173 | dR.a = &b; 174 | dR.c = Rcv; 175 | dL.b = dR.b = this; 176 | } 177 | }; 178 | 179 | 180 | ADvar operator+ (double L, const ADvar &R); 181 | ADvar operator* (double L, const ADvar &R); 182 | ADvar atan(const ADvar&); 183 | ADvar atan2(const ADvar&, const ADvar&); 184 | ADvar atan2(double, const ADvar&); 185 | ADvar atan2(const ADvar&, double); 186 | ADvar cos (const ADvar&); 187 | ADvar exp (const ADvar&); 188 | ADvar log (const ADvar&); 189 | ADvar pow (const ADvar&, const ADvar&); 190 | ADvar pow (double, const ADvar&); 191 | ADvar pow (const ADvar&, double); 192 | ADvar sin (const ADvar&); 193 | ADvar sqrt(const ADvar&); 194 | ADvar tan (const ADvar&); 195 | 196 | inline ADvar operator+(const ADvar &T) { ADvar rv(T.cv); return rv; } 197 | 198 | inline int operator<(const ADvar &L, const ADvar &R) { return L.cv->Val < R.cv->Val; } 199 | inline int operator<(const ADvar &L, double R) { return L.cv->Val < R; } 200 | inline int operator<(double L, const ADvar &R) { return L < R.cv->Val; } 201 | 202 | inline int operator<=(const ADvar &L, const ADvar &R) { return L.cv->Val <= R.cv->Val; } 203 | inline int operator<=(const ADvar &L, double R) { return L.cv->Val <= R; } 204 | inline int operator<=(double L, const ADvar &R) { return L <= R.cv->Val; } 205 | 206 | inline int operator==(const ADvar &L, const ADvar &R) { return L.cv->Val == R.cv->Val; } 207 | inline int operator==(const ADvar &L, double R) { return L.cv->Val == R; } 208 | inline int operator==(double L, const ADvar &R) { return L == R.cv->Val; } 209 | 210 | inline int operator!=(const ADvar &L, const ADvar &R) { return L.cv->Val != R.cv->Val; } 211 | inline int operator!=(const ADvar &L, double R) { return L.cv->Val != R; } 212 | inline int operator!=(double L, const ADvar &R) { return L != R.cv->Val; } 213 | 214 | inline int operator>=(const ADvar &L, const ADvar &R) { return L.cv->Val >= R.cv->Val; } 215 | inline int operator>=(const ADvar &L, double R) { return L.cv->Val >= R; } 216 | inline int operator>=(double L, const ADvar &R) { return L >= R.cv->Val; } 217 | 218 | inline int operator>(const ADvar &L, const ADvar &R) { return L.cv->Val > R.cv->Val; } 219 | inline int operator>(const ADvar &L, double R) { return L.cv->Val > R; } 220 | inline int operator>(double L, const ADvar &R) { return L > R.cv->Val; } 221 | 222 | inline void *ADcontext::Memalloc(size_t len) { 223 | if (Mleft >= len) 224 | return Mbase + (Mleft -= len); 225 | return new_ADmemblock(len); 226 | } 227 | 228 | inline Derp::Derp(ADvari *c1): c(c1) { 229 | next = LastDerp; 230 | LastDerp = this; 231 | } 232 | 233 | inline Derp::Derp(const double *a1, ADvari *c1): a(a1), c(c1) { 234 | next = LastDerp; 235 | LastDerp = this; 236 | } 237 | 238 | inline Derp::Derp(const double *a1, ADvari *b1, ADvari *c1): a(a1), b(b1), c(c1) { 239 | next = LastDerp; 240 | LastDerp = this; 241 | } 242 | -------------------------------------------------------------------------------- /src/myradops.cpp: -------------------------------------------------------------------------------- 1 | // Support routines for the RAD package (Reverse Automatic Differentiation) -- 2 | // a package specialized for function and gradient evaluations. 3 | // Written in 2004 by David M. Gay at Sandia National Labs, Albuquerque, NM. 4 | 5 | #include "myrad.h" 6 | 7 | Derp *Derp::LastDerp = 0; 8 | 9 | ADcontext ADvari::adc; 10 | 11 | double One = 1., negOne = -1.; 12 | 13 | ADcontext::ADcontext() { 14 | First.next = 0; 15 | Busy = &First; 16 | Free = 0; 17 | Mbase = (char*)First.memblk; 18 | Mleft = sizeof(First.memblk); 19 | } 20 | 21 | void* ADcontext::new_ADmemblock(size_t len){ 22 | ADmemblock *x; 23 | 24 | if (x = Free) 25 | Free = x->next; 26 | else 27 | x = new ADmemblock; 28 | x->next = Busy; 29 | Busy = x; 30 | return (Mbase = (char*)x->memblk) + 31 | (Mleft = sizeof(First.memblk) - len); 32 | } 33 | 34 | void ADcontext::Gradcomp(){ 35 | ADmemblock *mb, *mb0, *mb1, *mbf; 36 | Derp *d = Derp::LastDerp; 37 | d->b->aval = 1; 38 | for(; d; d = d->next) 39 | d->c->aval += *d->a * d->b->aval; 40 | Derp::LastDerp = 0; 41 | mb0 = &ADvari::adc.First; 42 | mbf = ADvari::adc.Free; 43 | for(mb = ADvari::adc.Busy; 44 | mb != mb0; mb = mb1) { 45 | mb1 = mb->next; 46 | mb->next = mbf; 47 | mbf = mb; 48 | } 49 | ADvari::adc.Free = mbf; 50 | ADvari::adc.Busy = mb; 51 | ADvari::adc.Mbase = (char*)ADvari::adc.First.memblk; 52 | ADvari::adc.Mleft = sizeof(ADvari::adc.First.memblk); 53 | } 54 | 55 | ADvar::ADvar(double d){ 56 | ADvari *x = new ADvari(d); 57 | cv = x; 58 | } 59 | 60 | #ifdef RAD_NO_EQ_ALIAS 61 | ADvar& 62 | ADvar::operator=(const ADvar &x) 63 | { cv = new ADvar1(x.cv->Val, &One, x.cv); return *this; } 64 | #endif 65 | 66 | ADvar& 67 | ADvar::operator=(const double d) 68 | { cv = new ADvari(d); return *this; } 69 | 70 | ADvar 71 | operator-(const ADvar &T) { 72 | return ADvar(new ADvar1(-T.cv->Val, &negOne, T.cv)); 73 | } 74 | 75 | ADvar 76 | operator+(const ADvar &L, const ADvar &R) { 77 | ADvari *Lcv = L.cv, *Rcv = R.cv; 78 | return ADvar(new ADvar2(Lcv->Val + Rcv->Val, Lcv, &One, Rcv, &One)); 79 | } 80 | 81 | ADvar& 82 | ADvar::operator+=(const ADvar &R) { 83 | ADvari *Lcv = cv, *Rcv = R.cv; 84 | cv = new ADvar2(Lcv->Val + Rcv->Val, Lcv, &One, Rcv, &One); 85 | return *this; 86 | } 87 | 88 | ADvar 89 | operator+(const ADvar &L, double R) { 90 | ADvari *tcv = L.cv; 91 | return ADvar(new ADvar1(tcv->Val + R, &One, tcv)); 92 | } 93 | 94 | ADvar& 95 | ADvar::operator+=(double R) { 96 | ADvari *tcv = cv; 97 | cv = new ADvar1(tcv->Val + R, &One, tcv); 98 | return *this; 99 | } 100 | 101 | ADvar 102 | operator+(double L, const ADvar &R) { 103 | ADvari *Rcv = R.cv; 104 | return ADvar(new ADvar1(L + Rcv->Val, &One, Rcv)); 105 | } 106 | 107 | ADvar 108 | operator-(const ADvar &L, const ADvar &R) { 109 | ADvari *Lcv = L.cv, *Rcv = R.cv; 110 | return ADvar(new ADvar2(Lcv->Val - Rcv->Val, Lcv, &One, Rcv, &negOne)); 111 | } 112 | 113 | ADvar& 114 | ADvar::operator-=(const ADvar &R) { 115 | ADvari *Lcv = cv, *Rcv = R.cv; 116 | cv = new ADvar2(Lcv->Val - Rcv->Val, Lcv, &One, Rcv, &negOne); 117 | } 118 | 119 | ADvar 120 | operator-(const ADvar &L, double R) { 121 | ADvari *tcv = L.cv; 122 | return ADvar(new ADvar1(tcv->Val - R, &One, tcv)); 123 | } 124 | 125 | ADvar& 126 | ADvar::operator-=(double R) { 127 | ADvari *tcv = cv; 128 | cv = new ADvar1(tcv->Val - R, &One, tcv); 129 | return *this; 130 | } 131 | 132 | ADvar 133 | operator-(double L, const ADvar &R) { 134 | ADvari *Rcv = R.cv; 135 | return ADvar(new ADvar1(L - Rcv->Val, &negOne, Rcv)); 136 | } 137 | 138 | ADvar 139 | operator*(const ADvar &L, const ADvar &R) { 140 | ADvari *Lcv = L.cv, *Rcv = R.cv; 141 | return ADvar(new ADvar2(Lcv->Val * Rcv->Val, Lcv, &Rcv->Val, Rcv, &Lcv->Val)); 142 | } 143 | 144 | ADvar& 145 | ADvar::operator*=(const ADvar &R) { 146 | ADvari *Lcv = cv, *Rcv = R.cv; 147 | cv = new ADvar2(Lcv->Val * Rcv->Val, Lcv, &Rcv->Val, Rcv, &Lcv->Val); 148 | } 149 | 150 | ADvar 151 | operator*(const ADvar &L, double R) { 152 | ADvari *Lcv = L.cv; 153 | return ADvar(new ADvar1s(Lcv->Val * R, R, Lcv)); 154 | } 155 | 156 | ADvar& 157 | ADvar::operator*=(double R) { 158 | ADvari *Lcv = cv; 159 | cv = new ADvar1s(Lcv->Val * R, R, Lcv); 160 | return *this; 161 | } 162 | 163 | ADvar 164 | operator*(double L, const ADvar &R) { 165 | ADvari *Rcv = R.cv; 166 | return ADvar(new ADvar1s(L * Rcv->Val, L, Rcv)); 167 | } 168 | 169 | ADvar 170 | operator/(const ADvar &L, const ADvar &R) { 171 | ADvari *Lcv = L.cv, *Rcv = R.cv; 172 | double Lv = Lcv->Val, Rv = Rcv->Val, pL = 1. / Rv, q = Lv/Rv; 173 | return ADvar(new ADvar2q(q, pL, -q*pL, Lcv, Rcv)); 174 | } 175 | 176 | ADvar& 177 | ADvar::operator/=(const ADvar &R) { 178 | ADvari *Lcv = cv, *Rcv = R.cv; 179 | double Lv = Lcv->Val, Rv = Rcv->Val, pL = 1. / Rv, q = Lv/Rv; 180 | cv = new ADvar2q(q, pL, -q*pL, Lcv, Rcv); 181 | } 182 | 183 | ADvar 184 | operator/(const ADvar &L, double R) { 185 | ADvari *Lcv = L.cv; 186 | return ADvar(new ADvar1s(Lcv->Val / R, 1./R, Lcv)); 187 | } 188 | 189 | ADvar& 190 | ADvar::operator/=(double R) { 191 | ADvari *Lcv = cv; 192 | cv = new ADvar1s(Lcv->Val / R, 1./R, Lcv); 193 | return *this; 194 | } 195 | 196 | ADvar 197 | atan(const ADvar &v) { 198 | ADvari *tcv = v.cv; 199 | double t = tcv->Val; 200 | return ADvar(new ADvar1s(atan(t), 1./(1. + t*t), tcv)); 201 | } 202 | 203 | ADvar 204 | atan2(const ADvar &L, const ADvar &R) { 205 | ADvari *Lcv = L.cv, *Rcv = R.cv; 206 | double x = Lcv->Val, y = Rcv->Val, t = x*x + y*y; 207 | return ADvar(new ADvar2q(atan2(x,y), y/t, -x/t, Lcv, Rcv)); 208 | } 209 | 210 | ADvar 211 | atan2(double x, const ADvar &R) { 212 | ADvari *Rcv = R.cv; 213 | double y = Rcv->Val, t = x*x + y*y; 214 | return ADvar(new ADvar1s(atan2(x,y), -x/t, Rcv)); 215 | } 216 | 217 | ADvar 218 | atan2(const ADvar &L, double y) { 219 | ADvari *Lcv = L.cv; 220 | double x = Lcv->Val, t = x*x + y*y; 221 | return ADvar(new ADvar1s(atan2(x,y), y/t, Lcv)); 222 | } 223 | 224 | ADvar 225 | cos(const ADvar &v) { 226 | ADvari *tcv = v.cv; 227 | return ADvar(new ADvar1s(cos(tcv->Val), -sin(tcv->Val), tcv)); 228 | } 229 | 230 | ADvar 231 | exp(const ADvar &v) { 232 | ADvar1* rcv; 233 | ADvari *tcv = v.cv; 234 | ADvar rv(rcv = new ADvar1(exp(tcv->Val), tcv)); 235 | rcv->d.a = &rcv->Val; 236 | rcv->d.b = rcv; 237 | return rv; 238 | } 239 | 240 | ADvar 241 | log(const ADvar &v) { 242 | ADvari *tcv = v.cv; 243 | double x = tcv->Val; 244 | return ADvar(new ADvar1s(log(x), 1. / x, tcv)); 245 | } 246 | 247 | ADvar 248 | pow(const ADvar &L, const ADvar &R) { 249 | ADvari *Lcv = L.cv, *Rcv = R.cv; 250 | double x = Lcv->Val, y = Rcv->Val, t = pow(x,y); 251 | return ADvar(new ADvar2q(t, y*t/x, t*log(x), Lcv, Rcv)); 252 | } 253 | 254 | ADvar 255 | pow(double x, const ADvar &R) { 256 | ADvari *Rcv = R.cv; 257 | double t = pow(x,Rcv->Val); 258 | return ADvar(new ADvar1s(t, t*log(x), Rcv)); 259 | } 260 | 261 | ADvar 262 | pow(const ADvar &L, double y) { 263 | ADvari *Lcv = L.cv; 264 | double x = Lcv->Val, t = pow(x,y); 265 | return ADvar(new ADvar1s(t, y*t/x, Lcv)); 266 | } 267 | 268 | ADvar 269 | sin(const ADvar &v) { 270 | ADvari *tcv = v.cv; 271 | return ADvar(new ADvar1s(sin(tcv->Val), cos(tcv->Val), tcv)); 272 | } 273 | 274 | ADvar 275 | sqrt(const ADvar &v) { 276 | ADvari *tcv = v.cv; 277 | double t = sqrt(tcv->Val); 278 | return ADvar(new ADvar1s(t, 0.5/t, tcv)); 279 | } 280 | 281 | ADvar 282 | tan(const ADvar &v) { 283 | ADvari *tcv = v.cv; 284 | double t = cos(tcv->Val); 285 | return ADvar(new ADvar1s(tan(tcv->Val), 1./(t*t), tcv)); 286 | } 287 | -------------------------------------------------------------------------------- /src/node.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * node.cpp 3 | * 4 | * Created on: Nov 24, 2009 5 | * Author: smitty 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | #include "node.h" 19 | #include "node_object.h" 20 | #include "string_node_object.h" 21 | 22 | Node::Node():BL(0.0),height(0.0),number(0), name(""), 23 | parent(NULL),children(vector ()),assoc(map()), 24 | comment(""),rate(0), free(false),date(0), min(0), max(0),maxb(false), 25 | minb(false),pen_min(0),pen_max(0),pen_maxb(false),pen_minb(false),char_duration(0),duration(0),order(0),log_fact_char_dur(0){} 26 | 27 | Node::Node(Node * inparent):BL(0.0),height(0.0),number(0), name(""), 28 | parent(inparent),children(vector ()),assoc(map()), 29 | comment(""),rate(0), free(false),date(0), min(0), max(0),maxb(false), 30 | minb(false),pen_min(0),pen_max(0),pen_maxb(false),pen_minb(false),char_duration(0),duration(0),order(0),log_fact_char_dur(0){} 31 | 32 | Node::Node(double bl,int innumber,string inname, Node * inparent) 33 | :BL(bl),height(0.0),number(innumber), name(inname), 34 | parent(inparent),children(vector ()),assoc(map()), 35 | comment(""),rate(0), free(false),date(0), min(0), max(0),maxb(false), 36 | minb(false),pen_min(0),pen_max(0),pen_maxb(false),pen_minb(false),char_duration(0),duration(0),order(0),log_fact_char_dur(0){} 37 | 38 | vector Node::getChildren(){ 39 | return children; 40 | } 41 | 42 | bool Node::isExternal(){ 43 | if(children.size()<1) 44 | return true; 45 | else 46 | return false; 47 | 48 | } 49 | 50 | bool Node::isInternal(){ 51 | if(children.size()>0) 52 | return true; 53 | else 54 | return false; 55 | } 56 | 57 | bool Node::isRoot(){ 58 | if(parent == NULL) 59 | return true; 60 | else 61 | return false; 62 | } 63 | 64 | bool Node::hasParent(){ 65 | if(parent == NULL) 66 | return false; 67 | else 68 | return true; 69 | } 70 | 71 | void Node::setParent(Node & p){ 72 | parent = &p; 73 | } 74 | 75 | int Node::getNumber(){ 76 | return number; 77 | } 78 | 79 | void Node::setNumber(int n){ 80 | number = n; 81 | } 82 | 83 | double Node::getBL(){ 84 | return BL; 85 | } 86 | 87 | void Node::setBL(double bl){ 88 | BL = bl; 89 | } 90 | 91 | double Node::getHeight(){ 92 | return height; 93 | } 94 | 95 | void Node::setHeight(double he){ 96 | height = he; 97 | } 98 | 99 | bool Node::hasChild(Node & test){ 100 | bool ret = false; 101 | for(unsigned int i=0;igetChildCount();i++){ 157 | if(i==0) 158 | ret = ret+"("; 159 | ret = ret+this->getChild(i).getNewick(bl); 160 | if(bl==true){ 161 | std::ostringstream o; 162 | setprecision(10); 163 | o << std::fixed; 164 | o << this->getChild(i).getBL(); 165 | ret = ret +":"+o.str(); 166 | } 167 | if(i == this->getChildCount()-1) 168 | ret =ret +")"; 169 | else 170 | ret = ret+","; 171 | } 172 | if(name.size()>0) 173 | ret = ret + name; 174 | return ret; 175 | } 176 | 177 | /* 178 | * should be returning the stringnodeobjects as the names for internal 179 | * nodes 180 | */ 181 | string Node::getNewick(bool bl,string obj){ 182 | string ret = ""; 183 | for(int i=0;igetChildCount();i++){ 184 | if(i==0) 185 | ret = ret+"("; 186 | ret = ret+this->getChild(i).getNewick(bl,obj); 187 | if(bl==true){ 188 | std::ostringstream o; 189 | setprecision(10); 190 | o << std::fixed; 191 | o << this->getChild(i).getBL(); 192 | ret = ret +":"+o.str(); 193 | } 194 | if(i == this->getChildCount()-1) 195 | ret =ret +")"; 196 | else 197 | ret = ret+","; 198 | } 199 | if(isInternal()==true){ 200 | if (obj == "number"){ 201 | std::ostringstream o; 202 | setprecision(10); 203 | o << std::fixed; 204 | o << number; 205 | ret = ret +o.str(); 206 | }else{ 207 | if(this->getObject(obj)!=NULL){ 208 | std::ostringstream o; 209 | setprecision(10); 210 | o << std::fixed; 211 | o << (*((StringNodeObject*) (this->getObject(obj)))); 212 | ret = ret +o.str(); 213 | } 214 | } 215 | }else{//EXTERNAL 216 | if(name.size()>0) 217 | ret = ret + name; 218 | } 219 | return ret; 220 | } 221 | 222 | void Node::getExternalNodeNames(vector * names){ 223 | names->clear(); 224 | Node * nd = this; 225 | stack stack; 226 | stack.push(nd); 227 | while(stack.empty() == false){ 228 | Node * tnd = stack.top(); 229 | stack.pop(); 230 | if(tnd->getChildCount() == 0){ 231 | names->push_back(tnd->getName()); 232 | } 233 | for(int i=0;igetChildCount();i++){ 234 | stack.push(&tnd->getChild(i)); 235 | } 236 | } 237 | } 238 | 239 | Node * Node::getParent(){ 240 | return parent; 241 | } 242 | 243 | int Node::getChildCount(){ 244 | return children.size(); 245 | } 246 | 247 | void Node::assocObject(string name,NodeObject & obj){ 248 | assoc[name] = obj.clone(); 249 | } 250 | 251 | /* 252 | * use the string ones like this 253 | * StringNodeObject sno("...a node object"); 254 | * tree.getRoot()->assocObject("test",sno); 255 | * cout << *((StringNodeObject*) (tree.getRoot()->getObject("test"))) << endl; 256 | * 257 | * and the vector like 258 | * VectorNodeObject vno; 259 | * vno.push_back(1);vno.push_back(2); 260 | * tree.getRoot()->assocObject("testvno",vno); 261 | * cout << ((VectorNodeObject *) (tree.getRoot()->getObject("testvno")))->at(0) << endl; 262 | */ 263 | 264 | NodeObject * Node::getObject(string name){ 265 | return assoc[name]; 266 | } 267 | 268 | -------------------------------------------------------------------------------- /src/node.h: -------------------------------------------------------------------------------- 1 | /* 2 | * node.h 3 | * 4 | * Created on: Nov 24, 2009 5 | * Author: smitty 6 | */ 7 | 8 | #ifndef NODE_H_ 9 | #define NODE_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | using namespace std; 15 | 16 | 17 | #include "node_object.h" 18 | 19 | class Node{ 20 | private: 21 | double BL;//branch lengths 22 | double height; // could be from tip or from root 23 | int number; 24 | string name; 25 | Node * parent; 26 | vector children; 27 | map assoc; 28 | string comment; 29 | 30 | public: 31 | Node(); 32 | Node(Node * parent); 33 | Node(double bl,int number,string name, Node * parent); 34 | 35 | vector getChildren(); 36 | bool isExternal(); 37 | bool isInternal(); 38 | bool isRoot(); 39 | bool hasParent(); 40 | void setParent(Node & p); 41 | int getNumber(); 42 | void setNumber(int n); 43 | double getBL(); 44 | void setBL(double bl); 45 | double getHeight(); 46 | void setHeight(double he); 47 | bool hasChild(Node & test); 48 | bool addChild(Node & c); 49 | bool removeChild(Node & c); 50 | Node & getChild(int c); 51 | string getName(); 52 | string getComment(); 53 | void setName(string s); 54 | void setComment(string s); 55 | string getNewick(bool bl); 56 | string getNewick(bool bl,string obj); 57 | Node * getParent(); 58 | int getChildCount(); 59 | void assocObject(string name,NodeObject & obj); 60 | NodeObject * getObject(string name); 61 | void getExternalNodeNames(vector * names); 62 | 63 | //ADDED FOR R8S 64 | double rate; 65 | bool free; 66 | double date; 67 | double min; 68 | double max; 69 | bool maxb; 70 | bool minb; 71 | bool pen_minb; 72 | bool pen_maxb; 73 | double pen_max; 74 | double pen_min; 75 | double char_duration; 76 | double duration; 77 | int order; 78 | double log_fact_char_dur; 79 | 80 | }; 81 | 82 | #endif /* NODE_H_ */ 83 | -------------------------------------------------------------------------------- /src/node_object.h: -------------------------------------------------------------------------------- 1 | /* 2 | * node_object.h 3 | * 4 | * Created on: Nov 24, 2009 5 | * Author: smitty 6 | */ 7 | 8 | #ifndef NODE_OBJECT_H_ 9 | #define NODE_OBJECT_H_ 10 | 11 | #include 12 | using namespace std; 13 | 14 | class NodeObject{ 15 | 16 | public: 17 | NodeObject() {} 18 | 19 | virtual ~NodeObject() {} 20 | 21 | public: 22 | virtual NodeObject * clone() const = 0; 23 | }; 24 | 25 | #endif /* NODE_OBJECT_H_ */ 26 | -------------------------------------------------------------------------------- /src/optim_options.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "optim_options.h" 3 | 4 | OptimOptions::OptimOptions(){ 5 | lftemp = 50; 6 | lfcool = 0.999; 7 | lfstoptemp = 0.001; 8 | plstoptemp = 0.0001; 9 | pltemp = 20; 10 | plcool = 0.99975; 11 | lfrtstep = 0.07; 12 | lfdtstep = 0.25; 13 | plrtstep = 0.1; 14 | pldtstep = 0.1; 15 | LARGE =10e+15; 16 | thorough = false; 17 | lfiter = 3; 18 | pliter = 5; 19 | cviter = 3; 20 | lfsimaniter = 15000; 21 | plsimaniter = 15000; 22 | cvsimaniter = 7500; 23 | calcgrad = false; 24 | verbose = false; 25 | 26 | bestopt = 0; //0 = tnc, 1 = lbfgs, 2 = tnewton, 3 = mma 27 | bestadopt = 0; //0 = tnc, 1 = lbfgs, 2 = tnewton, 3 = mma 28 | bestcvopt = 3; //0 = tnc, 1 = lbfgs, 2 = tnewton, 3 = mma, these are all ad 29 | moredetail = false; 30 | moredetailad = false; 31 | moredetailcvad = false; 32 | ftol = 1e-10; 33 | xtol = -1; 34 | maxoptimiters = 10000; 35 | nthreads = 1; 36 | } 37 | 38 | OptimOptions::~OptimOptions(){} 39 | -------------------------------------------------------------------------------- /src/optim_options.h: -------------------------------------------------------------------------------- 1 | #ifndef OPTIM_OPTIONS_H_ 2 | #define OPTIM_OPTIONS_H_ 3 | 4 | /* 5 | * This is just optimization options storage. 6 | * Could be a struct, but oh well 7 | */ 8 | 9 | class OptimOptions{ 10 | public: 11 | OptimOptions(); 12 | double lftemp; 13 | double lfcool; 14 | double lfstoptemp; 15 | double plstoptemp; 16 | double pltemp; 17 | double plcool; 18 | double lfrtstep; 19 | double lfdtstep; 20 | double plrtstep; 21 | double pldtstep; 22 | double LARGE; 23 | bool thorough; 24 | int lfiter; 25 | int pliter; 26 | int cviter; 27 | int lfsimaniter; 28 | int plsimaniter; 29 | int cvsimaniter; 30 | bool calcgrad; 31 | bool verbose; 32 | 33 | int bestopt; //0 = tnc, 1 = lbfgs, 2 = tnewton, 3 = mma 34 | int bestadopt; //0 = tnc, 1 = lbfgs, 2 = tnewton, 3 = mma 35 | int bestcvopt; //0 = tnc, 1 = lbfgs, 2 = tnewton, 3 = mma, these are all ad 36 | bool moredetail; 37 | bool moredetailad; 38 | bool moredetailcvad; 39 | double ftol; 40 | double xtol; 41 | int maxoptimiters; 42 | int nthreads; 43 | ~OptimOptions(); 44 | 45 | }; 46 | 47 | #endif /* OPTIM_OPTIONS_H_ */ 48 | -------------------------------------------------------------------------------- /src/optimize_nlopt.cpp: -------------------------------------------------------------------------------- 1 | #if HAVE_CONFIG_H 2 | #include "config.h" 3 | #endif 4 | #include "optimize_nlopt.h" 5 | #include "pl_calc_parallel.h" 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | typedef struct{ 14 | vector tncparams; 15 | vector tncgrads; 16 | pl_calc_parallel * pl_; 17 | } data_obj_nlopt; 18 | 19 | #define LARGE 1e+15 20 | #define SMALL 1e-20 21 | 22 | double function_plcp_nlopt_ad(unsigned n, const double *x, double *g, void *state){ 23 | data_obj_nlopt *d = (data_obj_nlopt *) state; 24 | for(unsigned int i=0;itncparams.size();i++){ 25 | d->tncparams[i] = x[i]; 26 | } 27 | 28 | double f = d->pl_->calc_function_gradient(&d->tncparams,&d->tncgrads); 29 | // cout << "adf: " << f << endl; 30 | if (isnan(f) || f == std::numeric_limits::infinity()){ 31 | return LARGE; 32 | // cout << "adf: " << f << endl; 33 | } 34 | 35 | int tv = d->tncgrads.size()-1; 36 | for(unsigned int i=0;itncgrads.size();i++){ 37 | g[i] = d->tncgrads[i]; 38 | /* if (g[i] > 1e+40) 39 | g[i] = 1e+40; 40 | if(g[i] < 1e-40) 41 | g[i] = 1e-40;*/ 42 | // cout << "adg: " << g[i] << "\tx: "<< x[i] << endl; 43 | } 44 | return f; 45 | } 46 | 47 | double function_plcp_nlopt(unsigned n, const double *x, double *g, void *state){ 48 | data_obj_nlopt *d = (data_obj_nlopt *) state; 49 | for(unsigned int i=0;itncparams.size();i++){ 50 | d->tncparams[i] = x[i]; 51 | // cout <<"x: " << x[i] << endl; 52 | } 53 | // cout << "here" <pl_->calc_pl(d->tncparams); 55 | // cout << "f: " << f << endl; 56 | if (isnan(f) || f == std::numeric_limits::infinity()){ 57 | cout << "throwing" << endl; 58 | return LARGE; 59 | }else{ 60 | d->pl_->calc_gradient(d->tncparams,&d->tncgrads); 61 | // cout << "f2 " << f2 << endl; 62 | for(unsigned int i=0;itncgrads.size();i++){ 63 | g[i] = d->tncgrads[i]; 64 | /* if (g[i] > 1e+40) 65 | g[i] = 1e+40; 66 | if(g[i] < 1e-40) 67 | g[i] = 1e-40;*/ 68 | // cout << "g: " << g[i] << "\tx: "<< x[i] << endl; 69 | } 70 | } 71 | return f; 72 | } 73 | 74 | double function_plcp_nlopt_nograd(unsigned n, const double *x, double *g, void *state){ 75 | data_obj_nlopt *d = (data_obj_nlopt *) state; 76 | for(unsigned int i=0;itncparams.size();i++){ 77 | d->tncparams[i] = x[i]; 78 | } 79 | double f = d->pl_->calc_pl(d->tncparams); 80 | // cout << "nog: " << f << endl; 81 | if (isnan(f) || f == std::numeric_limits::infinity()){ 82 | cout << "throwing" << endl; 83 | return LARGE; 84 | } 85 | return f; 86 | } 87 | 88 | double function_plcp_nlopt_ad_parallel(unsigned n, const double *x, double *g, void *state){ 89 | data_obj_nlopt *d = (data_obj_nlopt *) state; 90 | for(unsigned int i=0;itncparams.size();i++){ 91 | d->tncparams[i] = x[i]; 92 | } 93 | double f = d->pl_->calc_pl_function_gradient_adolc(&d->tncparams,&d->tncgrads); 94 | // cout << "par: " << f << endl; 95 | if(isnan(f) || f == std::numeric_limits::infinity()) 96 | return LARGE; 97 | for(unsigned int i=0;itncgrads.size();i++){ 98 | g[i] = d->tncgrads[i]; 99 | if (g[i] > 1e+40) 100 | g[i] = 1e+40; 101 | if(g[i] < 1e-40) 102 | g[i] = 1e-40; 103 | } 104 | return f; 105 | } 106 | 107 | /* 108 | * which one for all of these are 109 | * 1 lbfgs 110 | * 2 tnewton 111 | * 3 mma 112 | * (0 refers to tnc in the optimize_tnc) 113 | * more detail does a different scaling of the ftol 114 | */ 115 | 116 | int optimize_plcp_nlopt(double *init_x,pl_calc_parallel *pl_,int numiter, int whichone, bool ad,bool moredetail, double ftol,double xtol){ 117 | //tncplcp = pl_; 118 | double f; 119 | data_obj_nlopt d; 120 | d.tncparams.assign(pl_->numparams,0.0); 121 | d.tncgrads.assign(pl_->numparams,0.0); 122 | double low[pl_->numparams]; 123 | double up[pl_->numparams]; 124 | // double init_v[pl_->numparams]; 125 | 126 | for(int i=0;inumparams;i++){ 127 | // cout << init_x[i] << endl; 128 | low[i] = 0; 129 | up[i] = LARGE; 130 | // init_v.push_back(init_x[i]); 131 | } 132 | // exit(0); 133 | //if((whichone == 3 || whichone == 1) && ad == true){//sometimes works, sometimes doesn't 134 | int fcount = 0; 135 | for(int i=0;irates.size();i++){ 136 | if(pl_->freeparams[fcount] != -1){ 137 | // if (pl_->lf == false) 138 | // low[pl_->freeparams[fcount]] = pl_->minrate; 139 | low[pl_->freeparams[fcount]] = 1e-40; 140 | up[pl_->freeparams[fcount]] = LARGE; 141 | } 142 | fcount += 1; 143 | } 144 | 145 | for(int i=0;inumnodes;i++){ 146 | if(pl_->freeparams[fcount] != -1){ 147 | int curponi = i; 148 | if(pl_->min->at(curponi) != -1) 149 | low[pl_->freeparams[fcount]] = pl_->min->at(curponi); 150 | if(pl_->max->at(curponi) != -1) 151 | up[pl_->freeparams[fcount]] = pl_->max->at(curponi); 152 | } 153 | fcount += 1; 154 | } 155 | 156 | for(int i=0;inumparams;i++){ 157 | if (low[i] == 0) 158 | low[i] = 1e-40; 159 | } 160 | 161 | for(int i=0;inumparams;i++){ 162 | if(low[i] > init_x[i]) 163 | init_x[i] = low[i]; 164 | if(up[i] < init_x[i]) 165 | init_x[i] = up[i]; 166 | // cout << "- " << init_x[i] << " " << low[i] << " " << up[i] << endl; 167 | } 168 | //} 169 | 170 | 171 | double g[pl_->numparams]; 172 | d.pl_ = pl_; 173 | int rc = 0; 174 | 175 | //LN_SBPLX is the fastest of the non deriv 176 | 177 | nlopt_opt opt; 178 | if(whichone == 1){ 179 | opt = nlopt_create(NLOPT_LD_LBFGS, pl_->numparams); 180 | cout << "setting NLOPT: LD_LBFGS " << endl; 181 | }else if(whichone == 2){ 182 | opt = nlopt_create(NLOPT_LD_TNEWTON_PRECOND_RESTART, pl_->numparams); 183 | cout << "setting NLOPT: LD_TNEWTON_PRECOND_RESTART" << endl; 184 | }else if(whichone == 3){ 185 | opt = nlopt_create(NLOPT_LD_MMA, pl_->numparams); 186 | cout << "setting NLOPT: LD_MMA" << endl; 187 | }else if(whichone == 4){ 188 | opt = nlopt_create(NLOPT_LD_VAR2, pl_->numparams); 189 | cout << "setting NLOPT: LD_VAR2 " << endl; 190 | }else if(whichone == 5){ 191 | if(pl_->numparams < 10000){ 192 | opt = nlopt_create(NLOPT_LN_SBPLX, pl_->numparams); 193 | cout << "setting NLOPT : LN_SBPLX " << endl; 194 | }else{ 195 | whichone = 3; 196 | opt = nlopt_create(NLOPT_LD_MMA, pl_->numparams); 197 | cout << "setting NLOPT : NLOPT_LD_MMA " << endl; 198 | cout << "you may want to set the plsimaniter > 100000 " << endl; 199 | } 200 | } 201 | // opt.set_vector_storage(10); 202 | 203 | nlopt_set_lower_bounds(opt,low); 204 | nlopt_set_upper_bounds(opt,up); 205 | nlopt_set_maxeval(opt,numiter); 206 | if (moredetail){ 207 | nlopt_set_ftol_rel(opt,ftol*1e-5); 208 | }else{ 209 | nlopt_set_ftol_rel(opt,ftol); 210 | } 211 | nlopt_set_xtol_rel(opt,xtol); 212 | if(whichone == 5) 213 | nlopt_set_min_objective(opt,function_plcp_nlopt_nograd, (&d)); 214 | else if(ad==false) 215 | nlopt_set_min_objective(opt,function_plcp_nlopt, (&d)); 216 | else 217 | nlopt_set_min_objective(opt,function_plcp_nlopt_ad, (&d)); 218 | try{ 219 | nlopt_result result = nlopt_optimize(opt,init_x, &f); //was init_v 220 | // for(int i=0;inumparams;i++){ 221 | // init_x[i] = init_v[i]; 222 | // } 223 | cout << "result: " << result << endl; 224 | // if (result == -1) 225 | // exit(0); 226 | nlopt_destroy(opt); 227 | return result; 228 | }catch(...){ 229 | cout << "failed line search / last value: " << f << endl; 230 | // for(int i=0;inumparams;i++){ 231 | // init_x[i] = init_v[i]; 232 | // } 233 | nlopt_destroy(opt); 234 | return -1; 235 | } 236 | return rc; 237 | } 238 | 239 | 240 | int optimize_plcp_nlopt_ad_parallel(double *init_x,pl_calc_parallel *pl_,int numiter, int whichone, bool moredetail, double ftol, double xtol){ 241 | //tncplcp = pl_; 242 | double f; 243 | data_obj_nlopt d; 244 | d.tncparams.assign(pl_->numparams,0.0); 245 | d.tncgrads.assign(pl_->numparams,0.0); 246 | double low[pl_->numparams]; 247 | double up[pl_->numparams]; 248 | // vector init_v; 249 | 250 | for(int i=0;inumparams;i++){ 251 | low[i] = 0; 252 | up[i] = LARGE; 253 | // init_v.push_back(init_x[i]); 254 | } 255 | 256 | int fcount = 0; 257 | for(int i=0;irates.size();i++){ 258 | if (pl_->freeparams[fcount] != -1){ 259 | // if (pl_->lf == false) 260 | // low[pl_->freeparams[fcount]] = pl_->minrate; 261 | up[pl_->freeparams[fcount]] = LARGE; 262 | low[pl_->freeparams[fcount]] = 1e-40; 263 | } 264 | fcount += 1; 265 | } 266 | 267 | for(int i=0;inumnodes;i++){ 268 | if(pl_->freeparams[fcount] != -1){ 269 | int curponi = i; 270 | if(pl_->min->at(curponi) != -1) 271 | low[pl_->freeparams[fcount]] = pl_->min->at(curponi); 272 | if(pl_->max->at(curponi) != -1) 273 | up[pl_->freeparams[fcount]] = pl_->max->at(curponi); 274 | } 275 | fcount += 1; 276 | } 277 | 278 | for(int i=0;inumparams;i++){ 279 | if(low[i] == 0) 280 | low[i] = 1e-40; 281 | } 282 | 283 | for(int i=0;inumparams;i++){ 284 | if(low[i] > init_x[i]) 285 | init_x[i] = low[i]; 286 | if(up[i] < init_x[i]) 287 | init_x[i] = up[i]; 288 | // cout << "- " << init_x[i] << " " << low[i] << " " << up[i] << endl; 289 | } 290 | 291 | double g[pl_->numparams]; 292 | d.pl_ = pl_; 293 | int rc = 0; 294 | nlopt_opt opt; 295 | if(whichone == 1){ 296 | opt = nlopt_create(NLOPT_LD_LBFGS, pl_->numparams); 297 | cout << "setting NLOPT parallel : LD_LBFGS " << endl; 298 | }else if(whichone == 2){ 299 | opt = nlopt_create(NLOPT_LD_TNEWTON_PRECOND_RESTART, pl_->numparams); 300 | cout << "setting NLOPT parallel : LD_TNEWTON_PRECOND_RESTART" << endl; 301 | }else if(whichone == 3){ 302 | opt = nlopt_create(NLOPT_LD_MMA, pl_->numparams); 303 | cout << "setting NLOPT parallel : LD_MMA" << endl; 304 | }else if(whichone == 4){ 305 | opt = nlopt_create(NLOPT_LD_VAR2, pl_->numparams); 306 | cout << "setting NLOPT parallel : LD_VAR2 " << endl; 307 | }else if(whichone == 5){ 308 | if(pl_->numparams < 10000){ 309 | opt = nlopt_create(NLOPT_LN_SBPLX, pl_->numparams); 310 | cout << "setting NLOPT parallel : LN_SBPLX " << endl; 311 | }else{ 312 | whichone = 3; 313 | opt = nlopt_create(NLOPT_LD_MMA, pl_->numparams); 314 | cout << "setting NLOPT parallel : LD_MMA " << endl; 315 | cout << "you may want to set the plsimaniter > 100000 " << endl; 316 | } 317 | 318 | } 319 | nlopt_set_lower_bounds(opt,low); 320 | nlopt_set_upper_bounds(opt,up); 321 | nlopt_set_maxeval(opt,numiter); 322 | if(moredetail) 323 | nlopt_set_ftol_rel(opt,ftol*1e-5); 324 | else 325 | nlopt_set_ftol_rel(opt,ftol); 326 | if(whichone == 5){ 327 | nlopt_set_min_objective(opt,function_plcp_nlopt_nograd, (&d)); 328 | }else{ 329 | #if HAVE_LIBADOLC 330 | nlopt_set_min_objective(opt,function_plcp_nlopt_ad_parallel, (&d)); 331 | #else 332 | nlopt_set_min_objective(opt,function_plcp_nlopt, (&d)); 333 | #endif 334 | } 335 | nlopt_set_xtol_rel(opt,xtol); 336 | try{ 337 | nlopt_result result = nlopt_optimize(opt,init_x, &f); 338 | // for(int i=0;inumparams;i++){ 339 | // init_x[i] = init_v[i]; 340 | // } 341 | cout << "result: " << result << endl; 342 | nlopt_destroy(opt); 343 | return result; 344 | }catch(...){ 345 | cout << "failed line search / last value: " << f << endl; 346 | // for(int i=0;inumparams;i++){ 347 | // init_x[i] = init_v[i]; 348 | // } 349 | nlopt_destroy(opt); 350 | return -1; 351 | } 352 | return rc; 353 | } 354 | -------------------------------------------------------------------------------- /src/optimize_nlopt.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef OPTIMIZE_NLOPT_H_ 3 | #define OPTIMIZE_NLOPT_H_ 4 | 5 | #include "pl_calc_parallel.h" 6 | 7 | double function_plcp_nlopt_ad(unsigned n, const double *x, double *g, void *state); 8 | double function_plcp_nlopt(unsigned n, const double *x, double *g, void *state); 9 | double function_plcp_nlopt_nograd(unsigned n, const double *x, double *g, void *state); 10 | double function_plcp_nlopt_ad_parallel(unsigned n, const double *x, double *g, void *state); 11 | int optimize_plcp_nlopt(double * init_x, pl_calc_parallel *pl_, int numiter, int whichone, bool ad, bool moredetail,double ftol,double xtol); 12 | int optimize_plcp_nlopt_ad_parallel(double * init_x, pl_calc_parallel *pl_,int numiter, int whichone, bool moredetail, double ftol,double xtol); 13 | #endif 14 | -------------------------------------------------------------------------------- /src/optimize_tnc.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * optimize_tnc.cpp 3 | * 4 | * Created on: Feb 9, 2010 5 | * Author: smitty 6 | */ 7 | #if HAVE_CONFIG_H 8 | #include "config.h" 9 | #endif 10 | #include "optimize_tnc.h" 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include "tnc.h" 17 | #include "pl_calc_parallel.h" 18 | #include 19 | 20 | using namespace std; 21 | 22 | typedef struct{ 23 | vector tncparams; 24 | vector tncgrads; 25 | pl_calc_parallel * pl_; 26 | } data_obj; 27 | 28 | #define VERBOSE false 29 | 30 | #define LARGE 1e+15 31 | #define SMALL 1e-20 32 | 33 | static int function_plcp_ad(double x[], double *f, double g[], void *state){ 34 | data_obj *d = (data_obj *) state; 35 | if (isnan(x[0])){ 36 | return 1; 37 | } 38 | for(unsigned int i=0;itncparams.size();i++){ 39 | d->tncparams[i] = x[i]; 40 | } 41 | *f = d->pl_->calc_function_gradient(&d->tncparams,&d->tncgrads); 42 | // cout << "*f: " << (*f) << endl; 43 | if (isnan(*f)) 44 | return 1; 45 | 46 | int tv = d->tncgrads.size()-1; 47 | for(unsigned int i=0;itncgrads.size();i++){ 48 | g[i] = d->tncgrads[i]; 49 | if (g[i] > 1e+40) 50 | g[i] = 1e+40; 51 | if(g[i] < 1e-40) 52 | g[i] = 1e-40; 53 | } 54 | return 0; 55 | } 56 | 57 | static int function_plcp_ad_parallel(double x[], double *f, double g[], void *state){ 58 | data_obj *d = (data_obj *) state; 59 | for(unsigned int i=0;itncparams.size();i++){ 60 | d->tncparams[i] = x[i]; 61 | } 62 | *f = d->pl_->calc_pl_function_gradient_adolc(&d->tncparams,&d->tncgrads); 63 | // cout << "(*f) " << (*f) << endl; 64 | int tv = d->tncgrads.size()-1; 65 | for(unsigned int i=0;itncgrads.size();i++){ 66 | g[i] = d->tncgrads[i]; 67 | if (g[i] > 1e+40) 68 | g[i] = 1e+40; 69 | if(g[i] < 1e-40) 70 | g[i] = 1e-40; 71 | } 72 | return 0; 73 | } 74 | 75 | static int function_plcp(double x[], double *f, double g[], void *state){ 76 | data_obj *d = (data_obj *) state; 77 | 78 | for(unsigned int i=0;itncparams.size();i++){ 79 | // cout << x[i] << " "; 80 | d->tncparams[i] = x[i]; 81 | } 82 | // cout << endl; 83 | *f = d->pl_->calc_pl(d->tncparams); 84 | // if (isnan(*f)){ 85 | // cout << "NAN result" << endl; 86 | // return 1; 87 | // } 88 | if (isinf(*f)){ 89 | cout << "INF result" << endl; 90 | return 1; 91 | } 92 | // cout << (*f) << endl; 93 | d->pl_->calc_gradient(d->tncparams,&d->tncgrads); 94 | // cout <<"-"; 95 | for(unsigned int i=0;itncgrads.size();i++){ 96 | g[i] = d->tncgrads[i]; 97 | /* if (g[i] > 1e+40) 98 | g[i] = 1e+40; 99 | if(g[i] < 1e-40) 100 | g[i] = 1e-40;*/ 101 | // cout << g[i] << " "; 102 | } 103 | // cout << endl; 104 | return 0; 105 | } 106 | 107 | int optimize_plcp_tnc(double *init_x,pl_calc_parallel *pl_,int numiter, bool ad,double inftol){ 108 | //tncplcp = pl_; 109 | double f; 110 | data_obj d; 111 | d.tncparams.assign(pl_->numparams,0.0); 112 | d.tncgrads.assign(pl_->numparams,0.0); 113 | double low[pl_->numparams]; 114 | double up[pl_->numparams]; 115 | 116 | for(int i=0;inumparams;i++){ 117 | low[i] = 0; 118 | up[i] = LARGE; 119 | } 120 | int fcount = 0; 121 | for(int i=0;irates.size();i++){ 122 | if(pl_->freeparams[fcount] !=-1){ 123 | // if(pl_->lf == false) 124 | // low[pl_->freeparams[fcount]] = pl_->minrate; 125 | up[pl_->freeparams[fcount]] = LARGE; 126 | low[pl_->freeparams[fcount]] = 1e-40; 127 | } 128 | fcount += 1; 129 | } 130 | 131 | for(int i=0;inumnodes;i++){ 132 | if(pl_->freeparams[fcount] != -1){ 133 | int curponi = i; 134 | if(pl_->min->at(curponi) != -1) 135 | low[pl_->freeparams[fcount]] = pl_->min->at(curponi); 136 | if(pl_->max->at(curponi) != -1) 137 | up[pl_->freeparams[fcount]] = pl_->max->at(curponi); 138 | } 139 | fcount += 1; 140 | } 141 | 142 | for(int i=0;inumparams;i++){ 143 | if (low[i]==0) 144 | low[i] = 1e-40; 145 | // cout << low[i] << " " << up[i] << " " << init_x[i] << endl; 146 | } 147 | 148 | for(int i=0;inumparams;i++){ 149 | if(low[i] > init_x[i]) 150 | init_x[i] = low[i]; 151 | if(up[i] < init_x[i]) 152 | init_x[i] = up[i]; 153 | // cout << "- " << init_x[i] << " " << low[i] << " " << up[i] << endl; 154 | } 155 | 156 | double g[pl_->numparams]; 157 | d.pl_=pl_; 158 | //maxCGit = -1 159 | int rc, maxCGit = -1, maxnfeval = 10000, nfeval; 160 | double eta = -1, stepmx = -1, accuracy = -1, fmin = -1, ftol = inftol, rescale = -1; 161 | if (ad == false){ 162 | rc = tnc(pl_->numparams, init_x, &f, g, function_plcp, (&d), low, up, NULL, TNC_MSG_NONE, 163 | maxCGit, maxnfeval, eta, stepmx, accuracy, fmin, ftol, rescale, &nfeval); 164 | }else{ 165 | rc = tnc(pl_->numparams, init_x, &f, g, function_plcp_ad,(&d), low,up, NULL, TNC_MSG_NONE, 166 | maxCGit, maxnfeval, eta, stepmx, accuracy, fmin, ftol, rescale, &nfeval); 167 | } 168 | 169 | cout << "nfeval: " << nfeval << " rc: " << tnc_rc_string[rc-TNC_MINRC] << endl; 170 | return rc; 171 | } 172 | 173 | int optimize_plcp_tnc_ad_parallel(double *init_x,pl_calc_parallel *pl_,double inftol){ 174 | //tncplcp = pl_; 175 | double f; 176 | data_obj d; 177 | d.tncparams.assign(pl_->numparams,0.0); 178 | d.tncgrads.assign(pl_->numparams,0.0); 179 | double low[pl_->numparams]; 180 | double up[pl_->numparams]; 181 | 182 | for(int i=0;inumparams;i++){ 183 | low[i] = 0; 184 | up[i] = LARGE; 185 | } 186 | 187 | int fcount = 0; 188 | for(int i=0;irates.size();i++){ 189 | if(pl_->freeparams[fcount] != -1){ 190 | // if(pl_->lf == false) 191 | // low[pl_->freeparams[fcount]] = pl_->minrate; 192 | low[pl_->freeparams[fcount]] = 1e-40; 193 | up[pl_->freeparams[fcount]] = LARGE; 194 | } 195 | fcount += 1; 196 | } 197 | 198 | for(int i=0;inumnodes;i++){ 199 | if(pl_->freeparams[fcount] != -1){ 200 | int curponi = i; 201 | if(pl_->min->at(curponi) != -1) 202 | low[pl_->freeparams[fcount]] = pl_->min->at(curponi); 203 | if(pl_->max->at(curponi) != -1) 204 | up[pl_->freeparams[fcount]] = pl_->max->at(curponi); 205 | } 206 | fcount += 1; 207 | } 208 | for(int i=0;inumparams;i++){ 209 | if(low[i] == 0) 210 | low[i] = 1e-40; 211 | } 212 | 213 | for(int i=0;inumparams;i++){ 214 | if(low[i] > init_x[i]) 215 | init_x[i] = low[i]; 216 | if(up[i] < init_x[i]) 217 | init_x[i] = up[i]; 218 | // cout << "- " << init_x[i] << " " << low[i] << " " << up[i] << endl; 219 | } 220 | 221 | double g[pl_->numparams]; 222 | d.pl_=pl_; 223 | //maxCGit = -1 224 | int rc, maxCGit = -1, maxnfeval = 10000, nfeval; 225 | double eta = -1, stepmx = -1, accuracy = -1, fmin = -1, ftol = inftol, rescale = -1; 226 | #if HAVE_LIBADOLC 227 | rc = tnc(pl_->numparams, init_x, &f, g, function_plcp_ad_parallel, (&d), low, up, NULL, TNC_MSG_NONE,maxCGit, maxnfeval, eta, stepmx, accuracy, fmin, ftol, rescale, &nfeval); 228 | #else 229 | rc = tnc(pl_->numparams, init_x, &f, g, function_plcp, (&d), low, up, NULL, TNC_MSG_NONE,maxCGit, maxnfeval, eta, stepmx, accuracy, fmin, ftol, rescale, &nfeval); 230 | #endif 231 | 232 | 233 | cout << "nfeval: " << nfeval << " rc: " << tnc_rc_string[rc-TNC_MINRC] << endl; 234 | return rc; 235 | } 236 | 237 | -------------------------------------------------------------------------------- /src/optimize_tnc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * optimize_tnc.h 3 | * 4 | * Created on: Feb 9, 2010 5 | * Author: smitty 6 | */ 7 | 8 | #ifndef OPTIMIZE_TNC_H_ 9 | #define OPTIMIZE_TNC_H_ 10 | 11 | #include "tnc.h" 12 | #include "pl_calc_parallel.h" 13 | 14 | static tnc_function function_plcp_ad; 15 | static tnc_function function_plcp_ad_parallel; 16 | static tnc_function function_plcp; 17 | int optimize_plcp_tnc_ad_parallel(double *init_x, pl_calc_parallel *pl,double ftol); 18 | int optimize_plcp_tnc(double *init_x, pl_calc_parallel *pl_, int numiter,bool ad,double ftol); 19 | 20 | #endif /* OPTIMIZE_TNC_H_ */ 21 | -------------------------------------------------------------------------------- /src/pl_calc_parallel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * pl_calc_parallel.h 3 | * 4 | * Created on: Feb 2, 2010 5 | * Author: smitty 6 | */ 7 | 8 | #ifndef PL_CALC_PARALLEL_H_ 9 | #define PL_CALC_PARALLEL_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | using namespace std; 16 | 17 | class pl_calc_parallel{ 18 | private: 19 | double calc_log_like(); 20 | double calc_roughness_penalty(); 21 | double set_durations(); 22 | double calc_penalty(); 23 | vector cvnodes; 24 | adouble * adx; 25 | adouble ady; 26 | adouble * advrates_adc; 27 | adouble * advdates_adc; 28 | adouble * advdurations_adc; 29 | int adc_size; 30 | bool log_pen; 31 | 32 | public: 33 | pl_calc_parallel(); 34 | double calc_pl(vector & params); 35 | double calc_function_gradient(vector * params, vector * g); 36 | double calc_lf_function_gradient(vector * params, vector * g); 37 | int calc_lf_function_gradient_adolc_void(int size, double * xp, double * yp, int tape); 38 | double calc_lf_function_gradient_adolc(vector * params, vector * g); 39 | int calc_pl_function_gradient_adolc_void(int size, double * xp, double * yp, int tape); 40 | double calc_pl_function_gradient_adolc(vector * params, vector * g); 41 | double calc_pl_function_gradient(vector * params, vector * g); 42 | void calc_gradient(vector & params, vector * g); 43 | void calc_lf_gradient(vector & params, vector * g); 44 | void calc_pl_gradient(vector & params,vector * g); 45 | void setup_starting_bits(const vector * parents_nds, const vector * child_cnts, 46 | const vector * vfree, const vector * char_dur, 47 | const vector * log_fact_ch, const vector * vmn, 48 | const vector * vmx, const vector * start_dates, 49 | const vector * start_rates, const vector * start_durations); 50 | void set_freeparams(int nump, bool lf, vector * freep, vector * params); 51 | int calc_isum(vector & inc); 52 | void set_log_pen(bool); //set whether log penalty is set 53 | //these should all be hidden but oh well for now 54 | int numparams; 55 | bool cvnodeset; 56 | vector * get_cv_nodes(); 57 | void set_cv_nodes(vector & cvnodes); 58 | vector dates; 59 | vector rates; 60 | vector durations; 61 | vector freeparams; 62 | const vector * free; 63 | const vector * min; 64 | const vector * max; 65 | const vector * pen_min;//just the mins that are calculated in the penalty 66 | const vector * pen_max;//just the maxs that are calculated in the penalty 67 | const vector * parents_nds_ints; 68 | const vector * child_counts; 69 | const vector * char_durations; 70 | const vector * log_fact_char_durations; 71 | const vector< vector > * children_vec; 72 | int numnodes; 73 | int numsites; 74 | double smoothing; 75 | bool lf; 76 | void delete_ad_arrays(); 77 | bool paramverbose; 78 | double minrate; 79 | double ftol; 80 | bool isConstrained; 81 | double penalty_boundary; 82 | }; 83 | 84 | #endif /* PL_CALC_PARALLEL_H_ */ 85 | -------------------------------------------------------------------------------- /src/rad.h: -------------------------------------------------------------------------------- 1 | // RAD package (Reverse Automatic Differentiation) -- 2 | // a package specialized for function and gradient evaluations. 3 | // Written in 2004 by David M. Gay at Sandia National Labs, Albuquerque, NM. 4 | 5 | #include 6 | #include 7 | 8 | class ADvar; 9 | class ADvari; 10 | class ADvar1; 11 | class ADvar2; 12 | class Derp; 13 | 14 | struct 15 | ADmemblock { // We get memory in ADmemblock chunks 16 | // and never give it back, but reuse it 17 | // after each ADcontext::Gradcomp() call. 18 | ADmemblock *next; 19 | double memblk[1000]; 20 | }; 21 | 22 | class 23 | ADcontext { // A singleton class: one instance in radops.c 24 | ADmemblock *Busy, *Free; 25 | char *Mbase; 26 | size_t Mleft; 27 | ADmemblock First; 28 | void *new_ADmemblock(size_t); 29 | public: 30 | ADcontext(); 31 | void *Memalloc(size_t len); 32 | static void Gradcomp(); 33 | }; 34 | 35 | class 36 | Derp { // one derivative-propagation operation 37 | public: 38 | static Derp *LastDerp; 39 | Derp *next; 40 | const double *a; 41 | ADvari *b; 42 | ADvari *c; 43 | Derp(){}; 44 | Derp(ADvari *); 45 | Derp(const double *, ADvari *); 46 | Derp(const double *, ADvari *, ADvari *); 47 | /* c->aval += a * b->aval; */ 48 | }; 49 | 50 | class 51 | ADvari { // implementation of an ADvar 52 | public: 53 | double Val; // result of this operation 54 | double aval; // adjoint -- partial of final result w.r.t. this Val 55 | void *operator new(size_t len) { return ADvari::adc.Memalloc(len); } 56 | void operator delete(void*) {} /*Should never be called.*/ 57 | ADvari(double t) { Val = t; aval = 0; } 58 | ADvari() { Val = 0; aval = 0; } 59 | static ADcontext adc; 60 | }; 61 | 62 | class 63 | ADvar { // an "active" variable 64 | ADvari *cv; 65 | public: 66 | ADvar() { /*cv = 0;*/ } 67 | ADvar(double); 68 | ADvar(const ADvar &x) { cv = x.cv; } 69 | ADvar(ADvari *x) { cv = x; } 70 | #ifdef RAD_NO_EQ_ALIAS 71 | ADvar& operator=(const ADvar &x); 72 | #else /* allow aliasing v and w after "v = w;" */ 73 | ADvar& operator=(const ADvar &x) { cv = x.cv; return *this; } 74 | #endif 75 | ADvar& operator=(const double); 76 | friend ADvar operator+(const ADvar&); 77 | friend ADvar operator-(const ADvar&); 78 | friend ADvar operator+ (const ADvar&, const ADvar&); 79 | ADvar& operator+=(const ADvar&); 80 | friend ADvar operator+ (const ADvar&, double); 81 | ADvar& operator+=(double); 82 | friend ADvar operator+ (double L, const ADvar &R); 83 | friend ADvar operator- (const ADvar&, const ADvar&); 84 | ADvar& operator-=(const ADvar&); 85 | friend ADvar operator- (const ADvar&, double); 86 | ADvar& operator-=(double); 87 | friend ADvar operator- (double L, const ADvar &R); 88 | friend ADvar operator* (const ADvar&, const ADvar&); 89 | ADvar& operator*=(const ADvar&); 90 | friend ADvar operator* (const ADvar&, double); 91 | ADvar& operator*=(double); 92 | friend ADvar operator* (double L, const ADvar &R); 93 | friend ADvar operator/ (const ADvar&, const ADvar&); 94 | ADvar& operator/=(const ADvar&); 95 | friend ADvar operator/ (const ADvar&, double); 96 | ADvar& operator/=(double); 97 | friend ADvar atan(const ADvar&); 98 | friend ADvar atan2(const ADvar&, const ADvar&); 99 | friend ADvar atan2(double, const ADvar&); 100 | friend ADvar atan2(const ADvar&, double); 101 | friend ADvar cos (const ADvar&); 102 | friend ADvar exp (const ADvar&); 103 | friend ADvar log (const ADvar&); 104 | friend ADvar pow (const ADvar&, const ADvar&); 105 | friend ADvar pow (double, const ADvar&); 106 | friend ADvar pow (const ADvar&, double); 107 | friend ADvar sin (const ADvar&); 108 | friend ADvar sqrt(const ADvar&); 109 | friend ADvar tan (const ADvar&); 110 | friend int operator<(const ADvar&, const ADvar&); 111 | friend int operator<(const ADvar&, double); 112 | friend int operator<(double, const ADvar&); 113 | friend int operator<=(const ADvar&, const ADvar&); 114 | friend int operator<=(const ADvar&, double); 115 | friend int operator<=(double,const ADvar&); 116 | friend int operator==(const ADvar&, const ADvar&); 117 | friend int operator==(const ADvar&, double); 118 | friend int operator==(double, const ADvar&); 119 | friend int operator!=(const ADvar&, const ADvar&); 120 | friend int operator!=(const ADvar&, double); 121 | friend int operator!=(double, const ADvar&); 122 | friend int operator>=(const ADvar&, const ADvar&); 123 | friend int operator>=(const ADvar&, double); 124 | friend int operator>=(double, const ADvar&); 125 | friend int operator>(const ADvar&, const ADvar&); 126 | friend int operator>(const ADvar&, double); 127 | friend int operator>(double, const ADvar&); 128 | 129 | operator ADvari*() { return cv; } 130 | 131 | double val() { return cv->Val; } 132 | double adj() { return cv->aval; } 133 | }; 134 | 135 | class 136 | ADvar1: public ADvari { // simplest unary ops 137 | public: 138 | Derp d; 139 | ADvar1(double val1): ADvari(val1) {} 140 | ADvar1(double val1, ADvari *c1): d(c1) { Val = val1; } 141 | ADvar1(double val1, const double *a1, ADvari *c1): d(a1,this,c1) { Val = val1; } 142 | }; 143 | 144 | class 145 | ADvar1s: public ADvar1 { // unary ops with partial "a" 146 | public: 147 | double a; 148 | ADvar1s(double val1, double a1, ADvari *c1): ADvar1(val1,&a,c1), a(a1) {} 149 | }; 150 | 151 | class 152 | ADvar2: public ADvari { // basic binary ops 153 | public: 154 | Derp dL, dR; 155 | ADvar2(double val1): ADvari(val1) {} 156 | ADvar2(double val1, ADvari *Lcv, const double *Lc, ADvari *Rcv, const double *Rc): 157 | ADvari(val1) { 158 | dR.next = Derp::LastDerp; 159 | dL.next = &dR; 160 | Derp::LastDerp = &dL; 161 | dL.a = Lc; 162 | dL.c = Lcv; 163 | dR.a = Rc; 164 | dR.c = Rcv; 165 | dL.b = dR.b = this; 166 | } 167 | }; 168 | 169 | class 170 | ADvar2q: public ADvar2 { // binary ops with partials "a", "b" 171 | public: 172 | double a, b; 173 | ADvar2q(double val1, double Lp, double Rp, ADvari *Lcv, ADvari *Rcv): 174 | ADvar2(val1), a(Lp), b(Rp) { 175 | dR.next = Derp::LastDerp; 176 | dL.next = &dR; 177 | Derp::LastDerp = &dL; 178 | dL.a = &a; 179 | dL.c = Lcv; 180 | dR.a = &b; 181 | dR.c = Rcv; 182 | dL.b = dR.b = this; 183 | } 184 | }; 185 | 186 | 187 | ADvar operator+ (double L, const ADvar &R); 188 | ADvar operator* (double L, const ADvar &R); 189 | ADvar atan(const ADvar&); 190 | ADvar atan2(const ADvar&, const ADvar&); 191 | ADvar atan2(double, const ADvar&); 192 | ADvar atan2(const ADvar&, double); 193 | ADvar cos (const ADvar&); 194 | ADvar exp (const ADvar&); 195 | ADvar log (const ADvar&); 196 | ADvar pow (const ADvar&, const ADvar&); 197 | ADvar pow (double, const ADvar&); 198 | ADvar pow (const ADvar&, double); 199 | ADvar sin (const ADvar&); 200 | ADvar sqrt(const ADvar&); 201 | ADvar tan (const ADvar&); 202 | 203 | inline ADvar operator+(const ADvar &T) { ADvar rv(T.cv); return rv; } 204 | 205 | inline int operator<(const ADvar &L, const ADvar &R) { return L.cv->Val < R.cv->Val; } 206 | inline int operator<(const ADvar &L, double R) { return L.cv->Val < R; } 207 | inline int operator<(double L, const ADvar &R) { return L < R.cv->Val; } 208 | 209 | inline int operator<=(const ADvar &L, const ADvar &R) { return L.cv->Val <= R.cv->Val; } 210 | inline int operator<=(const ADvar &L, double R) { return L.cv->Val <= R; } 211 | inline int operator<=(double L, const ADvar &R) { return L <= R.cv->Val; } 212 | 213 | inline int operator==(const ADvar &L, const ADvar &R) { return L.cv->Val == R.cv->Val; } 214 | inline int operator==(const ADvar &L, double R) { return L.cv->Val == R; } 215 | inline int operator==(double L, const ADvar &R) { return L == R.cv->Val; } 216 | 217 | inline int operator!=(const ADvar &L, const ADvar &R) { return L.cv->Val != R.cv->Val; } 218 | inline int operator!=(const ADvar &L, double R) { return L.cv->Val != R; } 219 | inline int operator!=(double L, const ADvar &R) { return L != R.cv->Val; } 220 | 221 | inline int operator>=(const ADvar &L, const ADvar &R) { return L.cv->Val >= R.cv->Val; } 222 | inline int operator>=(const ADvar &L, double R) { return L.cv->Val >= R; } 223 | inline int operator>=(double L, const ADvar &R) { return L >= R.cv->Val; } 224 | 225 | inline int operator>(const ADvar &L, const ADvar &R) { return L.cv->Val > R.cv->Val; } 226 | inline int operator>(const ADvar &L, double R) { return L.cv->Val > R; } 227 | inline int operator>(double L, const ADvar &R) { return L > R.cv->Val; } 228 | 229 | inline void *ADcontext::Memalloc(size_t len) { 230 | if (Mleft >= len) 231 | return Mbase + (Mleft -= len); 232 | return new_ADmemblock(len); 233 | } 234 | 235 | inline Derp::Derp(ADvari *c1): c(c1) { 236 | next = LastDerp; 237 | LastDerp = this; 238 | } 239 | 240 | inline Derp::Derp(const double *a1, ADvari *c1): a(a1), c(c1) { 241 | next = LastDerp; 242 | LastDerp = this; 243 | } 244 | 245 | inline Derp::Derp(const double *a1, ADvari *b1, ADvari *c1): a(a1), b(b1), c(c1) { 246 | next = LastDerp; 247 | LastDerp = this; 248 | } 249 | -------------------------------------------------------------------------------- /src/radops.cpp: -------------------------------------------------------------------------------- 1 | // Support routines for the RAD package (Reverse Automatic Differentiation) -- 2 | // a package specialized for function and gradient evaluations. 3 | // Written in 2004 by David M. Gay at Sandia National Labs, Albuquerque, NM. 4 | 5 | #include "rad.h" 6 | 7 | Derp *Derp::LastDerp = 0; 8 | ADcontext ADvari::adc; 9 | 10 | double One = 1., negOne = -1.; 11 | 12 | ADcontext::ADcontext() 13 | { 14 | First.next = 0; 15 | Busy = &First; 16 | Free = 0; 17 | Mbase = (char*)First.memblk; 18 | Mleft = sizeof(First.memblk); 19 | } 20 | 21 | void* 22 | ADcontext::new_ADmemblock(size_t len) 23 | { 24 | ADmemblock *x; 25 | 26 | if (x = Free) 27 | Free = x->next; 28 | else 29 | x = new ADmemblock; 30 | x->next = Busy; 31 | Busy = x; 32 | return (Mbase = (char*)x->memblk) + 33 | (Mleft = sizeof(First.memblk) - len); 34 | } 35 | 36 | void 37 | ADcontext::Gradcomp() 38 | { 39 | ADmemblock *mb, *mb0, *mb1, *mbf; 40 | Derp *d = Derp::LastDerp; 41 | d->b->aval = 1; 42 | for(; d; d = d->next) 43 | d->c->aval += *d->a * d->b->aval; 44 | Derp::LastDerp = 0; 45 | mb0 = &ADvari::adc.First; 46 | mbf = ADvari::adc.Free; 47 | for(mb = ADvari::adc.Busy; mb != mb0; mb = mb1) { 48 | mb1 = mb->next; 49 | mb->next = mbf; 50 | mbf = mb; 51 | } 52 | ADvari::adc.Free = mbf; 53 | ADvari::adc.Busy = mb; 54 | ADvari::adc.Mbase = (char*)ADvari::adc.First.memblk; 55 | ADvari::adc.Mleft = sizeof(ADvari::adc.First.memblk); 56 | } 57 | 58 | ADvar::ADvar(double d) 59 | { 60 | ADvari *x = new ADvari(d); 61 | cv = x; 62 | } 63 | 64 | #ifdef RAD_NO_EQ_ALIAS 65 | ADvar& 66 | ADvar::operator=(const ADvar &x) 67 | { cv = new ADvar1(x.cv->Val, &One, x.cv); return *this; } 68 | #endif 69 | 70 | ADvar& 71 | ADvar::operator=(const double d) 72 | { cv = new ADvari(d); return *this; } 73 | 74 | ADvar 75 | operator-(const ADvar &T) { 76 | return ADvar(new ADvar1(-T.cv->Val, &negOne, T.cv)); 77 | } 78 | 79 | ADvar 80 | operator+(const ADvar &L, const ADvar &R) { 81 | ADvari *Lcv = L.cv, *Rcv = R.cv; 82 | return ADvar(new ADvar2(Lcv->Val + Rcv->Val, Lcv, &One, Rcv, &One)); 83 | } 84 | 85 | ADvar& 86 | ADvar::operator+=(const ADvar &R) { 87 | ADvari *Lcv = cv, *Rcv = R.cv; 88 | cv = new ADvar2(Lcv->Val + Rcv->Val, Lcv, &One, Rcv, &One); 89 | return *this; 90 | } 91 | 92 | ADvar 93 | operator+(const ADvar &L, double R) { 94 | ADvari *tcv = L.cv; 95 | return ADvar(new ADvar1(tcv->Val + R, &One, tcv)); 96 | } 97 | 98 | ADvar& 99 | ADvar::operator+=(double R) { 100 | ADvari *tcv = cv; 101 | cv = new ADvar1(tcv->Val + R, &One, tcv); 102 | return *this; 103 | } 104 | 105 | ADvar 106 | operator+(double L, const ADvar &R) { 107 | ADvari *Rcv = R.cv; 108 | return ADvar(new ADvar1(L + Rcv->Val, &One, Rcv)); 109 | } 110 | 111 | ADvar 112 | operator-(const ADvar &L, const ADvar &R) { 113 | ADvari *Lcv = L.cv, *Rcv = R.cv; 114 | return ADvar(new ADvar2(Lcv->Val - Rcv->Val, Lcv, &One, Rcv, &negOne)); 115 | } 116 | 117 | ADvar& 118 | ADvar::operator-=(const ADvar &R) { 119 | ADvari *Lcv = cv, *Rcv = R.cv; 120 | cv = new ADvar2(Lcv->Val - Rcv->Val, Lcv, &One, Rcv, &negOne); 121 | } 122 | 123 | ADvar 124 | operator-(const ADvar &L, double R) { 125 | ADvari *tcv = L.cv; 126 | return ADvar(new ADvar1(tcv->Val - R, &One, tcv)); 127 | } 128 | 129 | ADvar& 130 | ADvar::operator-=(double R) { 131 | ADvari *tcv = cv; 132 | cv = new ADvar1(tcv->Val - R, &One, tcv); 133 | return *this; 134 | } 135 | 136 | ADvar 137 | operator-(double L, const ADvar &R) { 138 | ADvari *Rcv = R.cv; 139 | return ADvar(new ADvar1(L - Rcv->Val, &negOne, Rcv)); 140 | } 141 | 142 | ADvar 143 | operator*(const ADvar &L, const ADvar &R) { 144 | ADvari *Lcv = L.cv, *Rcv = R.cv; 145 | return ADvar(new ADvar2(Lcv->Val * Rcv->Val, Lcv, &Rcv->Val, Rcv, &Lcv->Val)); 146 | } 147 | 148 | ADvar& 149 | ADvar::operator*=(const ADvar &R) { 150 | ADvari *Lcv = cv, *Rcv = R.cv; 151 | cv = new ADvar2(Lcv->Val * Rcv->Val, Lcv, &Rcv->Val, Rcv, &Lcv->Val); 152 | } 153 | 154 | ADvar 155 | operator*(const ADvar &L, double R) { 156 | ADvari *Lcv = L.cv; 157 | return ADvar(new ADvar1s(Lcv->Val * R, R, Lcv)); 158 | } 159 | 160 | ADvar& 161 | ADvar::operator*=(double R) { 162 | ADvari *Lcv = cv; 163 | cv = new ADvar1s(Lcv->Val * R, R, Lcv); 164 | return *this; 165 | } 166 | 167 | ADvar 168 | operator*(double L, const ADvar &R) { 169 | ADvari *Rcv = R.cv; 170 | return ADvar(new ADvar1s(L * Rcv->Val, L, Rcv)); 171 | } 172 | 173 | ADvar 174 | operator/(const ADvar &L, const ADvar &R) { 175 | ADvari *Lcv = L.cv, *Rcv = R.cv; 176 | double Lv = Lcv->Val, Rv = Rcv->Val, pL = 1. / Rv, q = Lv/Rv; 177 | return ADvar(new ADvar2q(q, pL, -q*pL, Lcv, Rcv)); 178 | } 179 | 180 | ADvar& 181 | ADvar::operator/=(const ADvar &R) { 182 | ADvari *Lcv = cv, *Rcv = R.cv; 183 | double Lv = Lcv->Val, Rv = Rcv->Val, pL = 1. / Rv, q = Lv/Rv; 184 | cv = new ADvar2q(q, pL, -q*pL, Lcv, Rcv); 185 | } 186 | 187 | ADvar 188 | operator/(const ADvar &L, double R) { 189 | ADvari *Lcv = L.cv; 190 | return ADvar(new ADvar1s(Lcv->Val / R, 1./R, Lcv)); 191 | } 192 | 193 | ADvar& 194 | ADvar::operator/=(double R) { 195 | ADvari *Lcv = cv; 196 | cv = new ADvar1s(Lcv->Val / R, 1./R, Lcv); 197 | return *this; 198 | } 199 | 200 | ADvar 201 | atan(const ADvar &v) { 202 | ADvari *tcv = v.cv; 203 | double t = tcv->Val; 204 | return ADvar(new ADvar1s(atan(t), 1./(1. + t*t), tcv)); 205 | } 206 | 207 | ADvar 208 | atan2(const ADvar &L, const ADvar &R) { 209 | ADvari *Lcv = L.cv, *Rcv = R.cv; 210 | double x = Lcv->Val, y = Rcv->Val, t = x*x + y*y; 211 | return ADvar(new ADvar2q(atan2(x,y), y/t, -x/t, Lcv, Rcv)); 212 | } 213 | 214 | ADvar 215 | atan2(double x, const ADvar &R) { 216 | ADvari *Rcv = R.cv; 217 | double y = Rcv->Val, t = x*x + y*y; 218 | return ADvar(new ADvar1s(atan2(x,y), -x/t, Rcv)); 219 | } 220 | 221 | ADvar 222 | atan2(const ADvar &L, double y) { 223 | ADvari *Lcv = L.cv; 224 | double x = Lcv->Val, t = x*x + y*y; 225 | return ADvar(new ADvar1s(atan2(x,y), y/t, Lcv)); 226 | } 227 | 228 | ADvar 229 | cos(const ADvar &v) { 230 | ADvari *tcv = v.cv; 231 | return ADvar(new ADvar1s(cos(tcv->Val), -sin(tcv->Val), tcv)); 232 | } 233 | 234 | ADvar 235 | exp(const ADvar &v) { 236 | ADvar1* rcv; 237 | ADvari *tcv = v.cv; 238 | ADvar rv(rcv = new ADvar1(exp(tcv->Val), tcv)); 239 | rcv->d.a = &rcv->Val; 240 | rcv->d.b = rcv; 241 | return rv; 242 | } 243 | 244 | ADvar 245 | log(const ADvar &v) { 246 | ADvari *tcv = v.cv; 247 | double x = tcv->Val; 248 | return ADvar(new ADvar1s(log(x), 1. / x, tcv)); 249 | } 250 | 251 | ADvar 252 | pow(const ADvar &L, const ADvar &R) { 253 | ADvari *Lcv = L.cv, *Rcv = R.cv; 254 | double x = Lcv->Val, y = Rcv->Val, t = pow(x,y); 255 | return ADvar(new ADvar2q(t, y*t/x, t*log(x), Lcv, Rcv)); 256 | } 257 | 258 | ADvar 259 | pow(double x, const ADvar &R) { 260 | ADvari *Rcv = R.cv; 261 | double t = pow(x,Rcv->Val); 262 | return ADvar(new ADvar1s(t, t*log(x), Rcv)); 263 | } 264 | 265 | ADvar 266 | pow(const ADvar &L, double y) { 267 | ADvari *Lcv = L.cv; 268 | double x = Lcv->Val, t = pow(x,y); 269 | return ADvar(new ADvar1s(t, y*t/x, Lcv)); 270 | } 271 | 272 | ADvar 273 | sin(const ADvar &v) { 274 | ADvari *tcv = v.cv; 275 | return ADvar(new ADvar1s(sin(tcv->Val), cos(tcv->Val), tcv)); 276 | } 277 | 278 | ADvar 279 | sqrt(const ADvar &v) { 280 | ADvari *tcv = v.cv; 281 | double t = sqrt(tcv->Val); 282 | return ADvar(new ADvar1s(t, 0.5/t, tcv)); 283 | } 284 | 285 | ADvar 286 | tan(const ADvar &v) { 287 | ADvari *tcv = v.cv; 288 | double t = cos(tcv->Val); 289 | return ADvar(new ADvar1s(tan(tcv->Val), 1./(t*t), tcv)); 290 | } 291 | -------------------------------------------------------------------------------- /src/siman_calc_par.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * siman_calc.cpp 3 | * 4 | * Created on: Feb 22, 2010 5 | * Author: smitty 6 | */ 7 | 8 | #include "siman_calc_par.h" 9 | #include "pl_calc_parallel.h" 10 | #include "optimize_tnc.h" 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #define LARGE 10e+13 19 | 20 | siman_calc_par::siman_calc_par():index_probs(vector()), verbose(false){ 21 | 22 | } 23 | 24 | void siman_calc_par::set_verbose(bool v){ 25 | verbose = v; 26 | } 27 | 28 | void siman_calc_par::set_pl(pl_calc_parallel * pl, double temp, double cl, double rt_step, double dt_step, int inmaxit, double sttemp){ 29 | temperature= temp; 30 | cool = cl; 31 | // if (pl->smoothing <= 1){ 32 | step_size_rt = rt_step; 33 | step_size_dt = dt_step;//0.0001 for 1 34 | // }else{ 35 | // step_size_rt = 0.00001;//0.0025; 36 | // step_size_dt = 0.075;//0.0025; 37 | // } 38 | stop_temp = sttemp; 39 | maxit = inmaxit; 40 | //step_size = 0.0000025; 41 | pl_ = pl; 42 | 43 | date_accepts = 0; 44 | date_trials = 0; 45 | rate_accepts = 0; 46 | rate_trials = 0; 47 | 48 | index_probs.clear(); 49 | /* 50 | * setting up the proportion of choosing particular indices 51 | */ 52 | //make sure that this is correct given the number of cv 53 | int fcount = 0; 54 | if(pl_->lf == true){ 55 | cout << "LF SIM" << endl; 56 | //fcount = pl_->rates.size(); 57 | for(int i=0; i < pl_->numparams;i++){ 58 | if (i == 0){ 59 | index_probs.push_back(0.01); 60 | }else{ 61 | index_probs.push_back(0.99/(pl_->numparams-1)); 62 | } 63 | } 64 | }else{ 65 | for(int i=0;irates.size();i++){ 66 | if(pl_->freeparams[fcount] != -1){ 67 | index_probs.push_back(0.5/(pl_->numnodes-1)); 68 | } 69 | fcount += 1; 70 | } 71 | for(int i=0; i < pl_->dates.size();i++){ 72 | if (pl_->freeparams[fcount] != -1){ 73 | index_probs.push_back(0.5/(pl_->numparams-(pl_->numnodes-1))); 74 | } 75 | fcount += 1; 76 | } 77 | } 78 | } 79 | 80 | void siman_calc_par::optimize(vector &init_params){ 81 | if (index_probs.size() != pl_->numparams){ 82 | cout << "something wrong with the number of params" << endl; 83 | exit(0); 84 | } 85 | cur_values = vector(init_params); 86 | last_print_values = cur_values; 87 | cur_like = pl_->calc_pl(cur_values); 88 | //cout << "start sim like: " << cur_like << endl; 89 | test_values = vector(init_params); 90 | converged = false; 91 | //srand( time(NULL) ); // init the random generator. no - this is done in main. 92 | int ind,iteration = 0;double sa,r,step,test_like; 93 | int same_value = 0; 94 | while (temperature > stop_temp){ 95 | ind = rand() % pl_->numparams;// choose one index to change 96 | //proper way to do this when there are different probs 97 | /* 98 | * get a random double 99 | */ 100 | 101 | double id = rand()/(double)RAND_MAX; 102 | bool kp = true; 103 | unsigned int tid = 0; 104 | double cur = 0; 105 | while(kp){ 106 | // cout << id << " " << index_probs[tid] << " " << tid << " " << cur << endl; 107 | if(id >= cur){ 108 | if((tid + 1) == index_probs.size() ){ 109 | ind = tid; 110 | kp = false; 111 | break; 112 | }else if( id < (cur+index_probs[tid]) ){ 113 | ind = tid; 114 | kp = false; 115 | break; 116 | } 117 | } 118 | cur += index_probs[tid]; 119 | tid += 1; 120 | } 121 | // cout << "index: " << ind << endl; 122 | /* 123 | * end choosing index 124 | */ 125 | int index_type; //0 = rate, 1 = date 126 | double step_size; 127 | if (pl_->lf == true){ 128 | if(ind == 0){ 129 | index_type = 0; 130 | step_size = step_size_rt; 131 | rate_trials += 1; 132 | }else{ 133 | index_type = 1; 134 | step_size = step_size_dt; 135 | date_trials += 1; 136 | } 137 | }else{ 138 | if(ind < pl_->numnodes-1){ 139 | index_type = 0; 140 | step_size = step_size_rt; 141 | rate_trials += 1; 142 | }else{ 143 | index_type = 1; 144 | step_size = step_size_dt; 145 | date_trials += 1; 146 | } 147 | } 148 | 149 | double rna = (rand() / (RAND_MAX + 1.0)); 150 | step = (2 * step_size * rna) - step_size; 151 | 152 | make_step_plcp(step,ind); 153 | 154 | test_like = pl_->calc_pl(test_values); 155 | 156 | // cout << "tl " << iteration << " : " << test_like << endl; 157 | if(test_like >= LARGE){//if the return is inf then just continue without counting an iteration 158 | test_values[ind] = cur_values[ind]; 159 | converged = false; 160 | continue; 161 | } 162 | sa = exp((-cur_like-test_like)/temperature); 163 | if (test_like 0.01){ 165 | same_value = 0; 166 | }else{ 167 | same_value += 1; 168 | } 169 | cur_values[ind] = test_values[ind]; 170 | cur_like = test_like; 171 | if(index_type == 0) { 172 | rate_accepts += 1; 173 | }else{ 174 | date_accepts += 1; 175 | } 176 | } // simulated annealing 177 | else if ((r = (rand()/(RAND_MAX + 1.0))) < sa){ 178 | cur_like = test_like; 179 | cur_values[ind] = test_values[ind]; 180 | }else{ 181 | converged = false; 182 | test_values[ind] = cur_values[ind]; 183 | } 184 | iteration++; 185 | if(iteration % 100 == 0){ 186 | temperature *= cool; // reduce the temperature 187 | } 188 | if(iteration % 100 == 0){ 189 | // cout << date_accepts << " " << date_accepts/float(date_trials) << " " << float(date_trials) << " " << step_size_dt<< " " << step_size_dt * 0.99<< endl; 190 | if((rate_accepts/float(rate_trials)) < 0.15) 191 | step_size_rt *= 0.99; 192 | else 193 | step_size_rt *= 1.01; 194 | if((date_accepts/float(date_trials)) < 0.15) 195 | step_size_dt *= 0.99; 196 | else 197 | step_size_dt *= 1.01; 198 | } 199 | if(iteration % 1000 == 0){ 200 | if(verbose){ 201 | cout << iteration<< " cur_like: " << cur_like << " test_like: "<< test_like<< 202 | " same_value: "<< same_value<< " temp: "<< temperature << " rate_acc: ("<< step_size_rt<< ") " << rate_accepts/float(rate_trials) << 203 | " date_acc: ("<< step_size_dt << ") " << date_accepts/float(date_trials) << " vecdiff: " << calc_difference_between_vecs(cur_values,last_print_values,0,1) << 204 | "," << calc_difference_between_vecs(cur_values,last_print_values,1,cur_values.size()) << endl; 205 | } 206 | last_print_values = cur_values; 207 | } 208 | if(same_value >= 5000){ 209 | if(converged == false){ 210 | if(verbose){ 211 | cout << "converged" << endl; 212 | } 213 | converged = true; 214 | same_value = 0; 215 | } 216 | if((converged == true && same_value >= 5000) || iteration > maxit){ 217 | break; 218 | } 219 | } 220 | if (iteration > maxit){ 221 | break; 222 | } 223 | }// while 224 | for(int i=0;ilf == true && index == 0) || (pl_->lf == false && index < pl_->numnodes-1)){//rate 244 | test_values[index] = (1.+step_size)*test_values[index]; 245 | }else{//date 246 | double mi = -1; 247 | double mx = -1; 248 | int fcount; 249 | if (pl_->lf == true) 250 | fcount = 1; 251 | else 252 | fcount = pl_->numnodes-1;//TODO : make sure this is right with cv 253 | for(int j=0;jnumnodes;j++){ 254 | if((*pl_->get_cv_nodes())[j] == 0 && pl_->freeparams[pl_->numnodes+j] != -1){ 255 | if(index == fcount+j){ 256 | mi = pl_->min->at(j);//nd->min;//pl_->mins[nd]; 257 | mx = pl_->max->at(j);//nd->max;//pl_->maxs[nd]; 258 | } 259 | } 260 | } 261 | double st = (1.+step_size)*test_values[index]; 262 | // double st = (step_size)+cu; 263 | if (mx != -1){ 264 | if(st > mx) 265 | st = mx; 266 | } 267 | if(mi != -1 ){ 268 | if(st < mi) 269 | st = mi; 270 | } 271 | test_values[index] = st; 272 | // cout << index << " " << test_values[index] <<" " << mx << " " << mi << " " << endl; 273 | //exit(0); 274 | }*/ 275 | 276 | } 277 | 278 | 279 | double siman_calc_par::calc_difference_between_vecs(vector & vec1,vector & vec2, int start, int end){ 280 | double ret = 0; 281 | for(int i=start;i & init_params){ 289 | 290 | maxit = 10000; 291 | pl_ = plp; 292 | step_size_rt = 0.0001; 293 | step_size_dt = 0.0001; 294 | date_accepts = 0; 295 | date_trials = 0; 296 | rate_accepts = 0; 297 | rate_trials = 0; 298 | verbose = true; 299 | index_probs.clear(); 300 | ofstream mapspacefile; 301 | mapspacefile.open("mapspace.txt",ios::out); 302 | mapspacefile.precision(10); 303 | /* 304 | * setting up the proportion of choosing particular indices 305 | */ 306 | int fcount = 0; 307 | for(int i=0;irates.size();i++){ 308 | if(pl_->freeparams[fcount] != -1){ 309 | index_probs.push_back(0.5/(pl_->numnodes-1)); 310 | } 311 | fcount += 1; 312 | } 313 | for(int i=0; i < pl_->dates.size();i++){ 314 | if (pl_->freeparams[fcount] != -1){ 315 | index_probs.push_back(0.5/(pl_->numparams-(pl_->numnodes-1))); 316 | } 317 | fcount += 1; 318 | } 319 | 320 | if (index_probs.size() != pl_->numparams){ 321 | cout << "something wrong with the number of params" << endl; 322 | exit(0); 323 | } 324 | cur_values = vector(init_params); 325 | last_print_values = cur_values; 326 | cur_like = pl_->calc_pl(cur_values); 327 | double INLIKE = cur_like; 328 | cout << "start map like: " << cur_like << endl; 329 | test_values = vector(init_params); 330 | //srand( time(NULL) ); // init the random generator. no - this is done in main. 331 | int ind,iteration = 0;double sa,r,step,test_like; 332 | int same_value = 0; 333 | while (iteration < maxit){ 334 | ind = rand() % pl_->numparams;// choose one index to change 335 | //proper way to do this when there are different probs 336 | /* 337 | * get a random double 338 | */ 339 | 340 | double id = rand()/(double)RAND_MAX; 341 | bool kp = true; 342 | unsigned int tid = 0; 343 | double cur = 0; 344 | while(kp){ 345 | if(id >= cur){ 346 | if((tid + 1) == index_probs.size() ){ 347 | ind = tid; 348 | kp = false; 349 | break; 350 | }else if( id < (cur+index_probs[tid]) ){ 351 | ind = tid; 352 | kp = false; 353 | break; 354 | } 355 | } 356 | cur += index_probs[tid]; 357 | tid += 1; 358 | } 359 | /* 360 | * end choosing index 361 | */ 362 | int index_type; //0 = rate, 1 = date 363 | double step_size; 364 | if(ind < pl_->numnodes-1){ 365 | index_type = 0; 366 | step_size = step_size_rt; 367 | rate_trials += 1; 368 | }else{ 369 | index_type = 1; 370 | step_size = step_size_dt; 371 | date_trials += 1; 372 | } 373 | 374 | double rna = (rand() / (RAND_MAX + 1.0)); 375 | step = (2 * step_size * rna) - step_size; 376 | 377 | make_step_plcp(step,ind); 378 | 379 | test_like = pl_->calc_pl(test_values); 380 | 381 | if(test_like >= LARGE){//if the return is inf then just continue without counting an iteration 382 | test_values[ind] = cur_values[ind]; 383 | converged = false; 384 | continue; 385 | } 386 | if ((test_like-2) < cur_like){ 387 | if((cur_like-test_like) > 0.01){ 388 | same_value = 0; 389 | }else{ 390 | same_value += 1; 391 | } 392 | // cur_values[ind] = test_values[ind]; 393 | // cur_like = test_like; 394 | if(index_type == 0){ 395 | rate_accepts += 1; 396 | }else{ 397 | date_accepts += 1; 398 | } 399 | //write to the file 400 | mapspacefile << test_like; 401 | for(int n = 0; n < pl_->dates.size();n++){ 402 | if(pl_->dates[n] != 0){ 403 | mapspacefile << "\t" << pl_->dates[n]; 404 | } 405 | } 406 | mapspacefile << endl; 407 | }else{ 408 | converged = false; 409 | test_values[ind] = cur_values[ind]; 410 | } 411 | iteration++; 412 | if(iteration % 100 == 0){ 413 | // cout << date_accepts << " " << date_accepts/float(date_trials) << " " << float(date_trials) << " " << step_size_dt<< " " << step_size_dt * 0.99<< endl; 414 | if((rate_accepts/float(rate_trials)) < 0.15){ 415 | step_size_rt *= 0.99; 416 | }else{ 417 | step_size_rt *= 1.01; 418 | } 419 | if((date_accepts/float(date_trials)) < 0.15){ 420 | step_size_dt *= 0.99; 421 | }else{ 422 | step_size_dt *= 1.01; 423 | } 424 | } 425 | if(iteration % 1000 == 0){ 426 | if(verbose){ 427 | cout << iteration<< " cur_like: " << cur_like << " test_like: "<< test_like<< 428 | " same_value: "<< same_value << " rate_acc: ("<< step_size_rt<< ") " << rate_accepts/float(rate_trials) << 429 | " date_acc: ("<< step_size_dt << ") " << date_accepts/float(date_trials) << " vecdiff: " << calc_difference_between_vecs(cur_values,last_print_values,0,1) << 430 | "," << calc_difference_between_vecs(cur_values,last_print_values,1,cur_values.size()) << endl; 431 | } 432 | last_print_values = cur_values; 433 | } 434 | }// while 435 | mapspacefile.close(); 436 | for(int i=0;i cur_values; 24 | vector test_values; 25 | vector last_print_values; 26 | void make_step_plcp(double, int); 27 | vector index_probs; //this is to determine which index 28 | int rate_accepts; 29 | int rate_trials; 30 | int date_accepts; 31 | int date_trials; 32 | double rate_accept;double rate_trial; 33 | double date_accept;double date_trial; 34 | bool converged; 35 | double calc_difference_between_vecs(vector &,vector &, int, int); 36 | bool verbose; 37 | double calc_sum_part_d(int, int,int); 38 | 39 | public: 40 | siman_calc_par(); 41 | void set_verbose(bool v); 42 | void set_pl(pl_calc_parallel * plcp,double temp,double cl, double rt_step, double dt_step, int derit, double sttemp); 43 | void optimize(vector & init_params); 44 | void mapspace(pl_calc_parallel * plp,vector & init_params); 45 | }; 46 | 47 | #endif /* SIMAN_CALC_H_ */ 48 | -------------------------------------------------------------------------------- /src/string_node_object.h: -------------------------------------------------------------------------------- 1 | /* 2 | * node_object.h 3 | * 4 | * Created on: Nov 24, 2009 5 | * Author: smitty 6 | */ 7 | 8 | #ifndef STRING_NODE_OBJECT_H_ 9 | #define STRING_NODE_OBJECT_H_ 10 | 11 | #include "node_object.h" 12 | #include 13 | using namespace std; 14 | 15 | class StringNodeObject: public string, public NodeObject{ 16 | public: 17 | StringNodeObject(const char * value): string(value) {} 18 | StringNodeObject(const string & value): string(value) {} 19 | virtual ~StringNodeObject() {} 20 | 21 | public: 22 | 23 | StringNodeObject * clone() const { return new StringNodeObject(*this); } 24 | }; 25 | 26 | #endif /* NODE_OBJECT_H_ */ 27 | -------------------------------------------------------------------------------- /src/tnc.h: -------------------------------------------------------------------------------- 1 | /* tnc : truncated newton bound contrained minimization 2 | using gradient information, in C */ 3 | 4 | /* 5 | * Copyright (c) 2002-2004, Jean-Sebastien Roy (js@jeannot.org) 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the 9 | * "Software"), to deal in the Software without restriction, including 10 | * without limitation the rights to use, copy, modify, merge, publish, 11 | * distribute, sublicense, and/or sell copies of the Software, and to 12 | * permit persons to whom the Software is furnished to do so, subject to 13 | * the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included 16 | * in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | */ 26 | 27 | /* 28 | * This software is a C implementation of TNBC, a truncated newton minimization 29 | * package originally developed by Stephen G. Nash in Fortran. 30 | * 31 | * The original source code can be found at : 32 | * http://iris.gmu.edu/~snash/nash/software/software.html 33 | * 34 | * Copyright for the original TNBC fortran routines: 35 | * 36 | * TRUNCATED-NEWTON METHOD: SUBROUTINES 37 | * WRITTEN BY: STEPHEN G. NASH 38 | * SCHOOL OF INFORMATION TECHNOLOGY & ENGINEERING 39 | * GEORGE MASON UNIVERSITY 40 | * FAIRFAX, VA 22030 41 | */ 42 | 43 | /* $Jeannot: tnc.h,v 1.53 2004/04/18 10:32:30 js Exp $ */ 44 | 45 | #ifndef _TNC_ 46 | #define _TNC_ 47 | 48 | #define TNC_VERSION "1.2.5" 49 | 50 | #ifdef __cplusplus 51 | extern "C" { 52 | #endif 53 | 54 | /* 55 | * Verbosity level 56 | */ 57 | typedef enum { 58 | TNC_MSG_NONE = 0, /* No messages */ 59 | TNC_MSG_ITER = 1, /* One line per iteration */ 60 | TNC_MSG_INFO = 2, /* Informational messages */ 61 | TNC_MSG_VERS = 4, /* Version info */ 62 | TNC_MSG_EXIT = 8, /* Exit reasons */ 63 | 64 | TNC_MSG_ALL = TNC_MSG_ITER | TNC_MSG_INFO 65 | | TNC_MSG_VERS | TNC_MSG_EXIT /* All messages */ 66 | } tnc_message; 67 | 68 | /* 69 | * Possible return values for tnc 70 | */ 71 | typedef enum 72 | { 73 | TNC_MINRC = -3, /* Constant to add to get the rc_string */ 74 | TNC_ENOMEM = -3, /* Memory allocation failed */ 75 | TNC_EINVAL = -2, /* Invalid parameters (n<0) */ 76 | TNC_INFEASIBLE = -1, /* Infeasible (low bound > up bound) */ 77 | TNC_LOCALMINIMUM = 0, /* Local minima reach (|pg| ~= 0) */ 78 | TNC_CONVERGED = 1, /* Converged (|f_n-f_(n-1)| ~= 0) */ 79 | TNC_MAXFUN = 2, /* Max. number of function evaluations reach */ 80 | TNC_LSFAIL = 3, /* Linear search failed */ 81 | TNC_CONSTANT = 4, /* All lower bounds are equal to the upper bounds */ 82 | TNC_NOPROGRESS = 5, /* Unable to progress */ 83 | TNC_USERABORT = 6 /* User requested end of minization */ 84 | } tnc_rc; 85 | 86 | /* 87 | * Return code strings 88 | * use tnc_rc_string[rc - TNC_MINRC] to get the message associated with 89 | * return code rc. 90 | */ 91 | 92 | extern char *tnc_rc_string[10]; 93 | 94 | /* 95 | * A function as required by tnc 96 | * state is a void pointer provided to the function at each call 97 | * 98 | * x : on input, then vector of variables (should not be modified) 99 | * f : on output, the value of the function 100 | * g : on output, the value of the gradient 101 | * state : on input, the value of the state variable as provided to tnc 102 | * 103 | * must returns 0 if no error occurs or 1 to immediately end the minimization. 104 | * 105 | */ 106 | typedef int tnc_function(double x[], double *f, double g[], void *state); 107 | 108 | /* 109 | * tnc : minimize a function with variables subject to bounds, using 110 | * gradient information. 111 | * 112 | * n : number of variables (must be >= 0) 113 | * x : on input, initial estimate ; on output, the solution 114 | * f : on output, the function value at the solution 115 | * g : on output, the gradient value at the solution 116 | * g should be an allocated vector of size n or NULL, 117 | * in which case the gradient value is not returned. 118 | * function : the function to minimize (see tnc_function) 119 | * state : used by function (see tnc_function) 120 | * low, up : the bounds 121 | * set low[i] to -HUGE_VAL to remove the lower bound 122 | * set up[i] to HUGE_VAL to remove the upper bound 123 | * if low == NULL, the lower bounds are removed. 124 | * if up == NULL, the upper bounds are removed. 125 | * scale : scaling factors to apply to each variable 126 | * if NULL, the factors are up-low for interval bounded variables 127 | * and 1+|x] fo the others. 128 | * messages : see the tnc_message enum 129 | * maxCGit : max. number of hessian*vector evaluation per main iteration 130 | * if maxCGit == 0, the direction chosen is -gradient 131 | * if maxCGit < 0, maxCGit is set to max(1,min(50,n/2)) 132 | * maxnfeval : max. number of function evaluation 133 | * eta : severity of the line search. if < 0 or > 1, set to 0.25 134 | * stepmx : maximum step for the line search. may be increased during call 135 | * if too small, will be set to 10.0 136 | * accuracy : relative precision for finite difference calculations 137 | * if <= machine_precision, set to sqrt(machine_precision) 138 | * fmin : minimum function value estimate 139 | * ftol : precision goal for the value of f in the stoping criterion 140 | * relative to the machine precision and the value of f. 141 | * if ftol < 0.0, ftol is set to 0.0 142 | * rescale : Scaling factor (in log10) used to trigger rescaling 143 | * if 0, rescale at each iteration 144 | * if a big value, never rescale 145 | * if < 0, rescale is set to 1.3 146 | * nfeval : on output, the number of function evaluations. 147 | * ignored if nfeval==NULL. 148 | * 149 | * The tnc function returns a code defined in the tnc_rc enum. 150 | * On output, x, f and g may be very slightly out of sync because of scaling. 151 | * 152 | */ 153 | extern int tnc(int n, double x[], double *f, double g[], 154 | tnc_function *function, void *state, 155 | double low[], double up[], double scale[], 156 | int messages, int maxCGit, int maxnfeval, double eta, double stepmx, 157 | double accuracy, double fmin, double ftol, double rescale, int *nfeval); 158 | 159 | #ifdef __cplusplus 160 | } 161 | #endif 162 | 163 | #endif /* _TNC_ */ 164 | -------------------------------------------------------------------------------- /src/tree.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * tree.cpp 3 | * 4 | * Created on: Nov 24, 2009 5 | * Author: smitty 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | using namespace std; 14 | 15 | #include "node.h" 16 | #include "tree.h" 17 | 18 | Tree::Tree():root(NULL),nodes(vector()), internalNodes(vector()), 19 | externalNodes(vector()),internalNodeCount(0),externalNodeCount(0){ 20 | processRoot(); 21 | } 22 | 23 | Tree::Tree(Node * inroot):root(inroot),nodes(vector()), internalNodes(vector()), 24 | externalNodes(vector()),internalNodeCount(0),externalNodeCount(0){ 25 | root = inroot; 26 | processRoot(); 27 | } 28 | 29 | void Tree::addExternalNode(Node * tn){ 30 | externalNodes.push_back(tn); 31 | externalNodeCount = externalNodes.size(); 32 | nodes.push_back(tn); 33 | } 34 | 35 | void Tree::addInternalNode(Node * tn){ 36 | internalNodes.push_back(tn); 37 | internalNodeCount = internalNodes.size(); 38 | nodes.push_back(tn); 39 | } 40 | 41 | 42 | Node * Tree::getExternalNode(int num){ 43 | return externalNodes.at(num); 44 | } 45 | 46 | /* 47 | * could precompute this, check for run time differences 48 | */ 49 | Node * Tree::getExternalNode(string & name){ 50 | Node * ret = NULL; 51 | for(unsigned int i=0;igetName() == name) 53 | ret = externalNodes.at(i); 54 | } 55 | return ret; 56 | } 57 | 58 | Node * Tree::getInternalNode(int num){ 59 | return internalNodes.at(num); 60 | } 61 | 62 | /* 63 | * could precompute this, check for run time differences 64 | */ 65 | Node * Tree::getInternalNode(string & name){ 66 | Node * ret = NULL; 67 | for(unsigned int i=0;igetName() == name) 69 | ret = internalNodes.at(i); 70 | } 71 | return ret; 72 | } 73 | 74 | int Tree::getExternalNodeCount(){ 75 | return externalNodeCount; 76 | } 77 | 78 | int Tree::getInternalNodeCount(){ 79 | return internalNodeCount; 80 | } 81 | 82 | Node * Tree::getNode(int num){ 83 | return nodes.at(num); 84 | } 85 | 86 | Node * Tree::getNodeByNodeNumber(int num){ 87 | for(int i=0;igetNumber() == num){ 89 | return nodes[i]; 90 | } 91 | } 92 | return NULL; 93 | } 94 | 95 | int Tree::getNodeCount(){ 96 | return nodes.size(); 97 | } 98 | 99 | Node * Tree::getRoot(){ 100 | return root; 101 | } 102 | 103 | void Tree::setRoot(Node * inroot){ 104 | root = inroot; 105 | } 106 | 107 | void Tree::unRoot(Node & inroot){ 108 | processRoot(); 109 | if (this->getRoot()->getChildCount() < 3) { 110 | tritomyRoot(&inroot); 111 | } 112 | processRoot(); 113 | 114 | } 115 | 116 | /* 117 | * seems to be working but check for leaks 118 | */ 119 | void Tree::reRoot(Node * inroot){ 120 | processRoot(); 121 | if (this->getRoot()->getChildCount() < 3) { 122 | tritomyRoot(inroot);//not sure if this should actually be the inroot instead of NULL 123 | } 124 | //cout << this->root->getNewick(false) << endl; 125 | if (root == inroot) { 126 | cout << "you asked to root at the current root" << endl; 127 | } else { 128 | Node * tempParent = inroot->getParent(); 129 | Node * newRoot = new Node(tempParent); 130 | newRoot->addChild(*inroot); 131 | inroot->setParent(*newRoot); 132 | tempParent->removeChild(*inroot); 133 | tempParent->addChild(*newRoot); 134 | newRoot->setParent(*tempParent); 135 | newRoot->setBL(inroot->getBL() / 2); 136 | inroot->setBL(inroot->getBL() / 2); 137 | processReRoot(newRoot); 138 | setRoot(newRoot); 139 | processRoot(); 140 | } 141 | } 142 | 143 | /* 144 | * seems to be working now 145 | */ 146 | void Tree::tritomyRoot(Node * toberoot){ 147 | Node * curroot = this->getRoot(); 148 | if (toberoot == NULL) { 149 | if (curroot->getChild(0).isInternal()) { 150 | Node * currootCH = &curroot->getChild(0); 151 | double nbl = currootCH->getBL(); 152 | curroot->getChild(1).setBL(curroot->getChild(1).getBL() + nbl); 153 | curroot->removeChild(*currootCH); 154 | for (int i = 0; i < currootCH->getChildCount(); i++) { 155 | curroot->addChild(currootCH->getChild(i)); 156 | //currootCH.getChild(i).setParent(curroot); 157 | } 158 | } else { 159 | Node * currootCH = &curroot->getChild(1); 160 | double nbl = currootCH->getBL(); 161 | curroot->getChild(0).setBL(curroot->getChild(0).getBL() + nbl); 162 | curroot->removeChild(*currootCH); 163 | for (int i = 0; i < currootCH->getChildCount(); i++) { 164 | curroot->addChild(currootCH->getChild(i)); 165 | //currootCH.getChild(i).setParent(curroot); 166 | } 167 | } 168 | } else { 169 | if (&curroot->getChild(1) == toberoot) { 170 | Node * currootCH = &curroot->getChild(0); 171 | double nbl = currootCH->getBL(); 172 | curroot->getChild(1).setBL(curroot->getChild(1).getBL() + nbl); 173 | curroot->removeChild(*currootCH); 174 | for (int i = 0; i < currootCH->getChildCount(); i++) { 175 | curroot->addChild(currootCH->getChild(i)); 176 | //currootCH.getChild(i).setParent(curroot); 177 | } 178 | } else { 179 | Node * currootCH = &curroot->getChild(1); 180 | double nbl = currootCH->getBL(); 181 | curroot->getChild(0).setBL(curroot->getChild(0).getBL() + nbl); 182 | curroot->removeChild(*currootCH); 183 | for (int i = 0; i < currootCH->getChildCount(); i++) { 184 | curroot->addChild(currootCH->getChild(i)); 185 | //currootCH.getChild(i).setParent(curroot); 186 | } 187 | } 188 | } 189 | } 190 | 191 | Node * Tree::getMRCA(vector innodes){ 192 | Node * mrca = NULL; 193 | if(innodes.size() == 1) 194 | return this->getExternalNode(innodes[0]); 195 | else{ 196 | vector outgroup; 197 | for(unsigned int i=0;igetExternalNode(outgroup.at(0)); 201 | outgroup.erase(outgroup.begin()); 202 | Node * cur2 = NULL; 203 | Node * tempmrca = NULL; 204 | while(outgroup.size()>0){ 205 | cur2 = this->getExternalNode(outgroup.at(0)); 206 | outgroup.erase(outgroup.begin()); 207 | tempmrca = getMRCATraverse(cur1,cur2); 208 | cur1 = tempmrca; 209 | } 210 | mrca = cur1; 211 | } 212 | return mrca; 213 | } 214 | 215 | Node * Tree::getMRCA(vector innodes){ 216 | Node * mrca = NULL; 217 | if(innodes.size() == 1) 218 | return innodes[0]; 219 | else{ 220 | Node * cur1 = innodes.at(0); 221 | innodes.erase(innodes.begin()); 222 | Node * cur2 = NULL; 223 | Node * tempmrca = NULL; 224 | while(innodes.size()>0){ 225 | cur2 = innodes.at(0); 226 | innodes.erase(innodes.begin()); 227 | tempmrca = getMRCATraverse(cur1,cur2); 228 | cur1 = tempmrca; 229 | } 230 | mrca = cur1; 231 | } 232 | return mrca; 233 | } 234 | 235 | void Tree::setHeightFromRootToNodes(){ 236 | setHeightFromRootToNode(*this->root,this->root->getBL()); 237 | } 238 | 239 | 240 | void Tree::setHeightFromRootToNode(Node & inNode, double newHeight) { 241 | if (inNode.isRoot() == false) { 242 | newHeight += inNode.getBL(); 243 | inNode.setHeight(newHeight); 244 | } else { 245 | inNode.setHeight(newHeight); 246 | } 247 | for (int i = 0; i < inNode.getChildCount(); i++) { 248 | setHeightFromRootToNode(inNode.getChild(i), newHeight); 249 | } 250 | } 251 | 252 | /* 253 | * only makes sense for ultrametric trees 254 | */ 255 | void Tree::setHeightFromTipToNodes(){ 256 | for (int i = 0; i < externalNodeCount; i++) { 257 | double curh = 0.0; 258 | Node * cur = this->getExternalNode(i); 259 | cur->setHeight(curh); 260 | while (cur->getParent() != NULL) { 261 | curh += cur->getBL(); 262 | cur = cur->getParent(); 263 | if(cur->getHeight()setHeight(curh); 265 | } 266 | } 267 | } 268 | 269 | /* 270 | * private 271 | */ 272 | void Tree::processRoot(){ 273 | nodes.clear(); 274 | internalNodes.clear(); 275 | externalNodes.clear(); 276 | internalNodeCount = 0; 277 | externalNodeCount = 0; 278 | if (&root == NULL) 279 | return; 280 | postOrderProcessRoot(root); 281 | } 282 | 283 | void Tree::processReRoot(Node * node){ 284 | if (node->isRoot() || node->isExternal()) { 285 | return; 286 | } 287 | if (node->getParent() != NULL) { 288 | processReRoot(node->getParent()); 289 | } 290 | // Exchange branch label, length et cetera 291 | exchangeInfo(node->getParent(), node); 292 | // Rearrange topology 293 | Node * parent = node->getParent(); 294 | node->addChild(*parent); 295 | parent->removeChild(*node); 296 | parent->setParent(*node); 297 | } 298 | 299 | void Tree::exchangeInfo(Node * node1, Node * node2){ 300 | string swaps; 301 | double swapd; 302 | swaps = node1->getName(); 303 | node1->setName(node2->getName()); 304 | node2->setName(swaps); 305 | 306 | swapd = node1->getBL(); 307 | node1->setBL(node2->getBL()); 308 | node2->setBL(swapd); 309 | } 310 | 311 | void Tree::postOrderProcessRoot(Node * node){ 312 | if (node == NULL) 313 | return; 314 | if (node->getChildCount() > 0) { 315 | for (int i = 0; i < node->getChildCount(); i++) { 316 | postOrderProcessRoot(&node->getChild(i)); 317 | } 318 | } 319 | if (node->isExternal()) { 320 | addExternalNode(node); 321 | node->setNumber(externalNodeCount); 322 | } else { 323 | addInternalNode(node); 324 | node->setNumber(internalNodeCount); 325 | } 326 | } 327 | 328 | void Tree::pruneExternalNode(Node * node){ 329 | if(node->isInternal()){ 330 | return; 331 | } 332 | /* 333 | * how this works 334 | * 335 | * get the parent = parent 336 | * get the parent of the parent = mparent 337 | * remove parent from mparent 338 | * add !node from parent to mparent 339 | * 340 | * doesn't yet take care if node.parent == root 341 | * or polytomy 342 | */ 343 | double bl = 0; 344 | Node * parent = node->getParent(); 345 | Node * other = NULL; 346 | for(int i=0;igetChildCount();i++){ 347 | if(&parent->getChild(i) != node){ 348 | other = &parent->getChild(i); 349 | } 350 | } 351 | bl = other->getBL()+parent->getBL(); 352 | Node * mparent = parent->getParent(); 353 | if(mparent != NULL){ 354 | mparent->addChild(*other); 355 | other->setBL(bl); 356 | for(int i=0;igetChildCount();i++){ 357 | if(&mparent->getChild(i)==parent){ 358 | mparent->removeChild(*parent); 359 | break; 360 | } 361 | } 362 | } 363 | delete node; 364 | this->processRoot(); 365 | } 366 | 367 | Node * Tree::getMRCATraverse(Node * curn1,Node * curn2){ 368 | Node * mrca = NULL; 369 | //get path to root for first node 370 | vector path1; 371 | Node * parent = curn1; 372 | path1.push_back(parent); 373 | while (parent != NULL) { 374 | path1.push_back(parent); 375 | if (parent->getParent() != NULL) 376 | parent = parent->getParent(); 377 | else 378 | break; 379 | } 380 | //find first match between this node and the first one 381 | parent = curn2; 382 | bool x = true; 383 | while (x == true) { 384 | for (unsigned int i = 0; i < path1.size(); i++) { 385 | if (parent == path1.at(i)) { 386 | mrca = parent; 387 | x = false; 388 | break; 389 | } 390 | } 391 | parent = parent->getParent(); 392 | } 393 | return mrca; 394 | } 395 | 396 | 397 | /* 398 | * end private 399 | */ 400 | 401 | Tree::~Tree(){ 402 | for(int i=0;i 12 | #include 13 | 14 | using namespace std; 15 | 16 | #include "node.h" 17 | 18 | class Tree{ 19 | private: 20 | Node * root; 21 | vector nodes; 22 | vector internalNodes; 23 | vector externalNodes; 24 | int internalNodeCount; 25 | int externalNodeCount; 26 | 27 | void processReRoot(Node * node); 28 | void exchangeInfo(Node * node1, Node * node2); 29 | void postOrderProcessRoot(Node * node); 30 | Node * getMRCATraverse(Node * curn1,Node * curn2); 31 | void setHeightFromRootToNode(Node & inNode, double newHeight); 32 | double getGreatestDistance(Node * inNode); 33 | 34 | public: 35 | Tree(); 36 | Tree(Node * root); 37 | 38 | void addExternalNode(Node * tn); 39 | void addInternalNode(Node * tn); 40 | void pruneExternalNode(Node * node); 41 | Node * getExternalNode(int num); 42 | Node * getExternalNode(string & name); 43 | Node * getInternalNode(int num); 44 | Node * getInternalNode(string & name); 45 | Node * getNode(int num); 46 | Node * getNodeByNodeNumber(int num); 47 | int getNodeCount(); 48 | int getExternalNodeCount(); 49 | int getInternalNodeCount(); 50 | Node * getRoot(); 51 | void setRoot(Node * inroot); 52 | void unRoot(Node & inroot); 53 | void reRoot(Node * inroot); 54 | void tritomyRoot(Node * toberoot); 55 | Node * getMRCA(vector innodes); 56 | Node * getMRCA(vector innodes); 57 | void processRoot(); 58 | 59 | void setHeightFromRootToNodes(); 60 | void setHeightFromTipToNodes(); 61 | 62 | ~Tree(); 63 | }; 64 | 65 | #endif /* TREE_H_ */ 66 | -------------------------------------------------------------------------------- /src/tree_reader.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * tree_reader.cpp 3 | * 4 | * Created on: Nov 24, 2009 5 | * Author: smitty 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | using namespace std; 15 | 16 | #include "node.h" 17 | #include "tree.h" 18 | #include "tree_reader.h" 19 | 20 | TreeReader::TreeReader(){} 21 | 22 | Tree * TreeReader::readTree(string trees){ 23 | Tree * tree = new Tree(); 24 | string pb = trees; 25 | 26 | // remove any trailing spaces 27 | pb.erase(pb.find_last_not_of(" \n\r\t")+1); 28 | if (pb[pb.size() - 1] != ';') { 29 | cout << "Tree is invalid: missing concluding semicolon. Exiting." << endl; 30 | exit(1); 31 | } 32 | 33 | unsigned int x = 0; 34 | char nextChar = pb.c_str()[x]; 35 | bool start = true; 36 | bool keepGoing = true; 37 | Node * currNode = NULL; 38 | while (keepGoing == true) { 39 | if (nextChar == '(') { 40 | if (start == true) { 41 | Node * root = new Node(); 42 | tree->setRoot(root); 43 | currNode = root; 44 | start = false; 45 | } else { 46 | Node * newNode = new Node(currNode); 47 | currNode->addChild(*newNode); 48 | currNode = newNode; 49 | } 50 | } else if (nextChar == ',') { 51 | currNode = currNode->getParent(); 52 | } else if (nextChar == ')') { 53 | currNode = currNode->getParent(); 54 | x++; 55 | nextChar = pb.c_str()[x]; 56 | string nam = ""; 57 | bool goingName = true; 58 | if (nextChar == ',' || nextChar == ')' || nextChar == ':' 59 | || nextChar == ';'|| nextChar == '[') { 60 | goingName = false; 61 | } 62 | while (goingName == true) { 63 | nam = nam + nextChar; 64 | x++; 65 | nextChar = pb.c_str()[x]; 66 | if (nextChar == ',' || nextChar == ')' || nextChar == ':' 67 | || nextChar == ';'|| nextChar == '[') { 68 | goingName = false; 69 | break; 70 | } 71 | }// work on edge 72 | currNode->setName(nam); 73 | x--; 74 | } else if (nextChar == ';') { 75 | keepGoing = false; 76 | } else if (nextChar == ':') { 77 | x++; 78 | nextChar = pb.c_str()[x]; 79 | string edgeL = ""; 80 | bool goingName = true; 81 | while (goingName == true) { 82 | edgeL = edgeL + nextChar; 83 | x++; 84 | nextChar = pb.c_str()[x]; 85 | if (nextChar == ',' || nextChar == ')' || nextChar == ':' 86 | || nextChar == ';'|| nextChar == '[') { 87 | goingName = false; 88 | break; 89 | } 90 | }// work on edge 91 | double edd = strtod(edgeL.c_str(),NULL); 92 | currNode->setBL(edd); 93 | x--; 94 | } 95 | //note 96 | else if (nextChar == '[') { 97 | x++; 98 | nextChar = pb.c_str()[x]; 99 | string note = ""; 100 | bool goingNote = true; 101 | while (goingNote == true) { 102 | note = note + nextChar; 103 | x++; 104 | nextChar = pb.c_str()[x]; 105 | if (nextChar == ']' ) { 106 | goingNote = false; 107 | break; 108 | } 109 | } 110 | currNode->setComment(note); 111 | } else if (nextChar == ' ') { 112 | 113 | } 114 | // external named node 115 | else { 116 | Node * newNode = new Node(currNode); 117 | currNode->addChild(*newNode); 118 | currNode = newNode; 119 | string nodeName = ""; 120 | bool goingName = true; 121 | while (goingName == true) { 122 | nodeName = nodeName + nextChar; 123 | x++; 124 | nextChar = pb.c_str()[x]; 125 | if (nextChar == ',' || nextChar == ')' || nextChar == ':' || nextChar == '[') { 126 | goingName = false; 127 | break; 128 | } 129 | } 130 | newNode->setName(nodeName); 131 | x--; 132 | } 133 | if (x < pb.length() - 1)//added 134 | x++; 135 | nextChar = pb.c_str()[x]; 136 | } 137 | tree->processRoot(); 138 | return tree; 139 | } 140 | -------------------------------------------------------------------------------- /src/tree_reader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * tree_reader.h 3 | * 4 | * Created on: Nov 24, 2009 5 | * Author: smitty 6 | */ 7 | 8 | #ifndef TREE_READER_H_ 9 | #define TREE_READER_H_ 10 | 11 | #include 12 | #include 13 | 14 | using namespace std; 15 | 16 | #include "node.h" 17 | #include "tree.h" 18 | 19 | class TreeReader{ 20 | public: 21 | TreeReader(); 22 | Tree * readTree(string tree); 23 | }; 24 | 25 | #endif /* TREE_READER_H_ */ 26 | -------------------------------------------------------------------------------- /src/tree_utils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * tree_utils.cpp 3 | * 4 | * Created on: Nov 24, 2009 5 | * Author: smitty 6 | */ 7 | 8 | -------------------------------------------------------------------------------- /src/tree_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * tree_utils.h 3 | * 4 | * Created on: Nov 24, 2009 5 | * Author: smitty 6 | */ 7 | 8 | #ifndef TREE_UTILS_H_ 9 | #define TREE_UTILS_H_ 10 | 11 | 12 | #endif /* TREE_UTILS_H_ */ 13 | -------------------------------------------------------------------------------- /src/utils.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef UTILS_H_ 3 | #define UTILS_H_ 4 | 5 | 6 | #include 7 | #include 8 | #include 9 | #include "pl_calc_parallel.h" 10 | #include "optim_options.h" 11 | #include "tree.h" 12 | 13 | void Tokenize(const string& str, vector& tokens, const string& delimiters); 14 | void TrimSpaces( string& str); 15 | void set_mins_maxs(Tree * tr,map * mins, map * maxs); 16 | double get_start_rate(Tree * tree, vector * durations); 17 | void process_initial_branch_lengths(Tree * tree, bool collapse, bool set1, int numsites); 18 | void apply_node_label_preorder(Tree * tr); 19 | void calc_char_durations(Tree * tr, int numsites); 20 | void setup_date_constraints(Tree * tr, map * inmins, map * inmaxs); 21 | void extract_tree_info(Tree * tr, vector * free, 22 | vector * parent_nds_ints, vector * child_c, vector * char_durations, 23 | vector * log_fact_char_durations, vector * min, 24 | vector * max, vector< vector > * children_vec,vector* pen_min, vector* pen_max); 25 | double logFact(double k); 26 | int generate_param_order_vector(vector * freeparams, bool lf, 27 | vector * cvnodes, vector * free); 28 | void get_feasible_start_dates(Tree * tr, vector * dates, vector * rates, 29 | vector * durations); 30 | int a_feasible_time(Node * node,double timeAnc); 31 | double round(double x); 32 | double myRand(void); 33 | float rand_float_range(float a, float b); 34 | void set_node_order(Tree * tr); 35 | int optimize_best(int whichone, bool ad, double * init_x, pl_calc_parallel * plp, int numiter, bool moredetail,double ftol,double xtol); 36 | int optimize_best_parallel(int whichone, double * init_x, pl_calc_parallel * plp, int numiter, bool moredetail,double ftol,double xtol); 37 | void prime_optimization(pl_calc_parallel & plp, vector & params); 38 | 39 | bool check_possible_cv_nodes(const int cvnode,const vector & samps, const vector & parents); 40 | double get_median(vector & container); 41 | double get_gmean(vector & container); 42 | double get_sum(vector & container); 43 | void process_ind8s_inr8s(string ind8s, string inr8s,vector * params, Tree * intree); 44 | bool optimize_full(pl_calc_parallel & plp, vector * params, const OptimOptions * oopt, bool cv); 45 | void mapspace(pl_calc_parallel &plp, vector * params); 46 | int count_trees (string & treefile); 47 | 48 | istream& getlineSafe(std::istream& is, std::string& t); 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/vector_node_object.h: -------------------------------------------------------------------------------- 1 | /* 2 | * node_object.h 3 | * 4 | * Created on: Nov 24, 2009 5 | * Author: smitty 6 | */ 7 | 8 | #ifndef VECTOR_NODE_OBJECT_H_ 9 | #define VECTOR_NODE_OBJECT_H_ 10 | 11 | #include "node_object.h" 12 | #include 13 | using namespace std; 14 | 15 | template 16 | class VectorNodeObject: public vector, public NodeObject{ 17 | public: 18 | VectorNodeObject(): 19 | vector() {} 20 | 21 | VectorNodeObject(typename vector::size_type num, const T& val = T() ): 22 | vector(num, val) {} 23 | 24 | VectorNodeObject(typename vector::iterator start, typename vector::iterator end): 25 | vector(start, end) {} 26 | 27 | virtual ~VectorNodeObject() {} 28 | 29 | public: 30 | 31 | VectorNodeObject * clone() const { return new VectorNodeObject(*this); } 32 | }; 33 | 34 | #endif /* NODE_OBJECT_H_ */ 35 | -------------------------------------------------------------------------------- /vagrant_instructions: -------------------------------------------------------------------------------- 1 | Install vagrant via vagrantup.com. Vagrant enables the quick, easy 2 | installation of customizeable virtual machines. The default is a 32-bit Ubuntu 3 | 12.04 box. It works really cleanly for developing these machines. I'm 4 | currently figuring out how to share my personal machine (without having to 5 | pay for it). 6 | 7 | ##To start Vagrant: 8 | vagrant init hashicorp/precise32 9 | vagrant up 10 | vagrant ssh 11 | 12 | ##To set up treePL: 13 | 14 | sudo apt-get install git 15 | sudo apt-get install make 16 | sudo apt-get install libtool 17 | sudo apt-get install autoconf 18 | git clone git://github.com/blackrim/treePL.git 19 | cd treePL/ 20 | cd deps/ 21 | tar xvf adol-c_git_saved.tar.gz 22 | tar xvf nlopt-2.2.4.tar.gz 23 | rm *.gz 24 | cd nlopt-2.2.4/ 25 | ./configure 26 | make 27 | sudo make install 28 | cd ../adol-c 29 | autoreconf -fi 30 | sudo ./configure --with-openmp-flag=-fopenmp --prefix=/usr 31 | make 32 | sudo make install 33 | cd ../src 34 | ./configure 35 | sudo make install 36 | 37 | ##To copy files to Vagrant box: 38 | 39 | scp -P 2222 vagrant@localhost:. 40 | 41 | Password is 'vagrant' 42 | 43 | ##Once all your files are in Vagrant 44 | 45 | treePL doesn't play well with Mac/Windows line endings. So, we shall switch them to *nix line endings 46 | 47 | for file in *.txt; do sed -i 's/\r/\n/g' $file; done 48 | 49 | Alter as needed to change all your files to *nix line endings. 50 | 51 | treePL also gets weird about rooting. If you've rerooted your tree in a software that leaves a [&R] tag, this might cause a segmentation fault ... for some reason. 52 | 53 | sed -i 's/\[&R]//g' your_file 54 | 55 | should fix this. 56 | 57 | ###To run treePL 58 | 59 | Place your config file and your tree (if in a separate file) into the treePL directory. Call as such: 60 | 61 | ./treePL treePLmatt 62 | 63 | To call in a loop for multiple trees: 64 | 65 | for file in *.tre ; do cp $file input.txt; ./treePL config ; cp dated.tre $file.tre; done 66 | 67 | In your config file, set treefile = input.txt 68 | 69 | 70 | 71 | 72 | --------------------------------------------------------------------------------