- Timestamp:
- May 8, 2015, 1:41:28 PM (9 years ago)
- Branches:
- (u'spielwiese', '2a584933abf2a2d3082034c7586d38bb6de1a30a')
- Children:
- dfb374a725f78f1788adb5fd03badc36ec04c6a0
- Parents:
- 52b3cf72ab7fa42d230232612144a2dd8a99aff0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/LIB/maxlike.lib
r52b3cf7 r8833bf 196 196 static proc is_neg_def(matrix H) 197 197 {//determines whether the given matrix is negative definite 198 198 //returns 1 if it is, 0 if it isnt 199 199 matrix M=H-diag(var(1),ncols(H)); 200 200 poly f=det(M); … … 300 300 } 301 301 302 302 //execute("ring outR =(complex,"+string(prec)+"),(x(1.."+string(n)+")),dp;"); 303 303 ring outR=(complex,prec),x(1..n),dp; 304 304 list MPOINTS = imap(R,L2); … … 379 379 " 380 380 {//as opposed to (get)maxpoints, which first eliminates and then solves, this procedure 381 382 383 381 //solves and then projects 382 //furthermore, it also creates a list of the values the generators of I have at the 383 //points in MPOINTS (that is, a list of the probability distributions) 384 384 matrix H=logHessian(I,u); 385 385 def r=basering; … … 511 511 // VALS, containing the probability distributions at those points. 512 512 "; 513 514 513 if(size(#)==0) { print(MPOINTS); print(display); } 514 return(outR); 515 515 } 516 516 example … … 535 535 ////////////////////////////////////////////////////////////////////////////////////////// 536 536 ////////////////////////////////////////////////////////////////////////////////////////// 537 //Here, we present an example of a data vector for which the likelihood function has more 538 //than one biologically meaningful local maximum. 539 //You can generate DNA sequence data, which has this data vector, using Seq-Gen with the 540 //following input: 541 //Tree: (Taxon1:0.6074796219,Taxon2:4.7911951859,Taxon3:0.5522879636); 542 //Seq-Gen options: -mHKY -l7647 -n1 -z28503 543 //You can find Seq-Gen at http://tree.bio.ed.ac.uk/software/seqgen/ 544 // 545 //- write(":w ThreeTaxonClaw.tree", 546 //- "(Taxon1:0.6074796219,Taxon2:4.7911951859,Taxon3:0.5522879636);"); 547 //- int i=system("sh", 548 //- "seq-gen -mHKY -l7647 -n1 -z28503 -q < ThreeTaxonClaw.tree > ThreeTaxonC 549 //law.dat"); 550 //- intvec u=getintvec("ThreeTaxonClaw.dat"); 551 // 537 552 538 553 /* … … 550 565 6*1/3*(1-mu1)*1/3*(1-mu2)*1/3*(1-mu3); 551 566 ideal I = f1,f2,f3,f4,f5; 552 write(":w ThreeTaxonClaw.tree", 553 "(Taxon1:0.6074796219,Taxon2:4.7911951859,Taxon3:0.5522879636);"); 554 int i=system("sh", 555 "seq-gen -mHKY -l7647 -n1 -z28503 -q < ThreeTaxonClaw.tree > ThreeTaxonClaw.dat"); 556 intvec u=getintvec("ThreeTaxonClaw.dat"); 567 intvec u = 770,2234,1156,2331,1156; 557 568 maxPoints(I,u,50); 558 569 } 570 559 571 560 572 proc bad_seq_gen_example2() … … 616 628 */ 617 629 630 618 631 ////////////////////////////////////////////////////////////////////////////////////////// 619 632 ////////////////////////////////////////////////////////////////////////////////////////// … … 623 636 //These are some of the procedures I used to generate and test examples for my Master 624 637 //thesis. To use the ones incorporating Seq-Gen, you may have to adjust the shell command 625 //with which Singular calls Seq-Gen. Furthermore, as the names of the procedures suggest, 626 //we always use the Jukes-Cantor model. 638 //with which Singular calls Seq-Gen. You can find Seq-Gen at 639 //http://tree.bio.ed.ac.uk/software/seqgen/ 640 //As the names of the procedures suggest, we always use the Jukes-Cantor model. 641 //They also tell you which of them use Seq-Gen. 627 642 628 643 /* … … 687 702 if(1) 688 703 { 689 690 691 692 704 if(is_neg_def(hessi[k]) == 1) 705 { 706 hessi2=hessi2+list(hessi[k]); 707 L2=L2+list(L[k]); 693 708 } 694 709 } … … 725 740 return(c); 726 741 } 742 727 743 print(L2); 728 744 } 745 729 746 730 747 proc getintvec(string linkstr) … … 769 786 for(i=1; i<=size(taxons[1]); i++) 770 787 { 771 if((taxons[1][i] == taxons[2][i]) and (taxons[2][i] == taxons[3][i])) 772 { 773 u[1]=u[1]+1; 774 i++; 775 continue;//continue does not execute the increment statement of the loop 776 } 777 778 if(taxons[1][i] == taxons[2][i]) 779 { 780 u[3]=u[3]+1; 781 i++; 782 continue; 783 } 784 785 if(taxons[1][i] == taxons[3][i]) 786 { 787 u[4]=u[4]+1; 788 i++; 789 continue; 790 } 791 792 if(taxons[2][i] == taxons[3][i]) 793 { 794 u[5]=u[5]+1; 795 i++; 796 continue; 797 } 798 799 u[2]=u[2]+1; 800 } 788 if((taxons[1][i] == taxons[2][i]) and (taxons[2][i] == taxons[3][i])) 789 { 790 u[1]=u[1]+1; 791 i++; 792 continue;//continue does not execute the increment statement of the loop 793 } 794 795 if(taxons[1][i] == taxons[2][i]) 796 { 797 u[3]=u[3]+1; 798 i++; 799 continue; 800 } 801 802 if(taxons[1][i] == taxons[3][i]) 803 { 804 u[4]=u[4]+1; 805 i++; 806 continue; 807 } 808 809 if(taxons[2][i] == taxons[3][i]) 810 { 811 u[5]=u[5]+1; 812 i++; 813 continue; 814 } 815 816 u[2]=u[2]+1; 817 } 818 801 819 return(u); 802 820 } … … 851 869 Iu=likeIdeal(I,u); 852 870 853 854 871 Iu=std(Iu); 855 872 //Iu=groebner(Iu); … … 857 874 if(d != 0) 858 875 { 859 860 861 862 863 864 876 nzd++; 877 display="-*-*-*- not 0-dim. for u= "+string(u)+", i= "+string(i)+" -*-*-*-"; 878 print(display); 879 write(lf,display); 880 i++; 881 continue; 865 882 } 866 883 … … 869 886 if(eatoutput >= 2) 870 887 { 871 888 num++; 872 889 write(lf,writestr+"; number: "+string(eatoutput)); 873 890 display="-*-*-*- Failed for u= "+string(u)+", i= "+string(i)+" -*-*-*-"; … … 904 921 ideal I=f1,f2,f3,f4,f5; 905 922 906 907 923 link lu=":a UsedIntvecsJC69seqgen.txt"; 908 924 link lf=":a FailedJC69seqgen.txt"; 909 925 910 926 string readstr="ThreeTaxonClaw.dat"; … … 922 938 { 923 939 shcmd="seq-gen "; 924 925 926 940 shcmd=shcmd+"-mHKY -l"+string(len)+" -n1 -z"+string(sd); 941 shcmd=shcmd+" -q < ThreeTaxonClaw.tree > ThreeTaxonClaw.dat"; 942 sd++; 927 943 eatoutput=system("sh",shcmd); 928 944 u=getintvec(readstr); … … 932 948 Iu=likeIdeal(I,u); 933 949 934 935 950 Iu=std(Iu); 936 951 //Iu=groebner(Iu); … … 938 953 if(d != 0) 939 954 { 940 nzd++; 941 display="-*-*-*- not 0-dim. for u= "+string(u)+", i= "+string(i)+" -*-*-*-"; 942 print(display); 943 write(lf,display); 944 i++; 945 continue; 946 } 947 955 nzd++; 956 display="-*-*-*- not 0-dim. for u= "+string(u)+", i= "+string(i)+" -*-*-*-"; 957 print(display); 958 write(lf,display); 959 i++; 960 continue; 961 } 948 962 949 963 eatoutput=getguaranteedmaxPoints(Iu,logHessian(I,u),1); … … 951 965 if(eatoutput >= 2) 952 966 { 953 967 num++; 954 968 write(lf,writestr+"; number: "+string(eatoutput)); 955 969 display="-*-*-*- no unique maximum for u= "+ 956 970 string(u)+", i= "+string(i)+" -*-*-*-"; 957 971 print(display); 958 972 display=""; … … 960 974 } 961 975 962 963 976 display="-------------- i = "+string(i)+" --------------"; 964 965 966 967 968 969 977 display=display+newline+"not zero-dimensional in "+string(nzd)+" cases"+newline; 978 display=display+"no unique maximum in "+string(num)+" cases"+newline; 979 print(display); 980 write(lf,display); 981 982 close(lu); 970 983 close(lf); 971 984 972 985 return(nzd,num); 973 986 } 974 987 975 988 proc randclawtree(int a) 976 989 { 977 978 979 980 981 982 983 984 985 986 987 988 990 ring r=(complex,10),x,dp; 991 number n1,n2,n3; 992 int n; 993 int i; 994 for(i=1; i<=a; i++) 995 { 996 n=random(1,1000000); 997 n1=number(n)/1000000; 998 n2=number(random(1,1000000-n))/1000000; 999 n3=1-n1-n2; 1000 print("(Taxon1:"+string(n1)+",Taxon2:"+string(n2)+",Taxon3:"+string(n3)+");"); 1001 } 989 1002 } 990 1003 991 1004 proc checkrandomJC69writebeginning(int r, int a, int sta, int up) 992 1005 { 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1006 string writestr=newline+newline+newline+newline+newline+newline; 1007 writestr=writestr+"*****************************************************"+newline; 1008 writestr=writestr+"starting new loop with the following parameters"+newline; 1009 writestr=writestr+"number of runs: "+string(r)+newline; 1010 writestr=writestr+"number of intvecs per run: "+string(a)+newline; 1011 writestr=writestr+"starting random seed: "+string(sta)+newline; 1012 writestr=writestr+"upper bound for the entries of the intvecs: "+string(up)+newline; 1013 writestr=writestr+"*****************************************************"; 1014 1015 link lu=":a UsedIntvecsJC69rand.txt"; 1016 link lf=":a FailedJC69rand.txt"; 1017 write(lu,writestr); 1005 1018 write(lf,writestr); 1006 1019 close(lu); … … 1010 1023 proc checkrandomJC69writeend(int r, int a, int sta, int up, int s, int t) 1011 1024 { 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1025 writestr=newline+newline+newline; 1026 writestr=writestr+"*****************************************************"+newline; 1027 writestr=writestr+"ending loop with the following parameters"+newline; 1028 writestr=writestr+"number of runs: "+string(r)+newline; 1029 writestr=writestr+"number of intvecs per run: "+string(a)+newline; 1030 writestr=writestr+"starting random seed: "+string(sta)+newline; 1031 writestr=writestr+"upper bound for the entries of the intvecs: "+string(up)+newline; 1032 writestr=writestr+newline+"in the whole loop, there were a total of"+newline; 1033 writestr=writestr+" "+string(s)+" examples with non-zero-dim. likeideal"+newline; 1034 writestr=writestr+" "+string(t)+ 1022 1035 " examples with more than one biol. meaningful local maximum"; 1023 1024 1025 1026 1036 writestr=writestr+newline+"*****************************************************"; 1037 1038 1039 write(lu,writestr); 1027 1040 write(lf,writestr); 1028 1041 close(lu); … … 1034 1047 //r the number of runs, a the number of intvecs per run, sta the starting random 1035 1048 //seed, up the upper bound for the entries of the intvecs 1036 checkrandomJC69writebeginning(r,a,sta,up);1049 checkrandomJC69writebeginning(r,a,sta,up); 1037 1050 1038 1051 int nzd, num, i, s, t; … … 1064 1077 link lf=":a FailedJC69seqgen.txt"; 1065 1078 write(lu,writestr); 1079 write(lf,writestr); 1080 close(lu); 1081 close(lf); 1082 } 1083 1084 1085 proc checkseqgenJC69writeend(int r, int a, int sd, int sta, 1086 int len, int p, int s, int t, intvec ls) 1087 { 1088 writestr=newline+newline+newline; 1089 writestr=writestr+"*****************************************************"+newline; 1090 writestr=writestr+"ending loop with the following parameters"+newline; 1091 writestr=writestr+"number of runs: "+string(r)+newline; 1092 writestr=writestr+"number of intvecs per run: "+string(a)+newline; 1093 writestr=writestr+"starting random seed for seqgen: "+string(sd)+newline; 1094 writestr=writestr+"starting random seed for random: "+string(sta)+newline; 1095 writestr=writestr+"length of the generated sequences: "+string(len)+newline; 1096 writestr=writestr+newline+"in the whole loop, there were a total of"+newline; 1097 writestr=writestr+" "+string(s)+" examples with non-zero-dim. likeideal"+newline; 1098 writestr=writestr+" "+string(t)+ 1099 " examples with more than one biol. meaningful local maximum"; 1100 writestr=writestr+newline+"*****************************************************"; 1101 writestr=writestr+"used lengths:"+newline+string(ls); 1102 writestr=writestr+newline+"*****************************************************"; 1103 1104 write(lu,writestr); 1066 1105 write(lf,writestr); 1067 1106 close(lu); … … 1069 1108 } 1070 1109 1071 1072 proc checkseqgenJC69writeend(int r, int a, int sd, int sta,1073 int len, int p, int s, int t, intvec ls)1074 {1075 writestr=newline+newline+newline;1076 writestr=writestr+"*****************************************************"+newline;1077 writestr=writestr+"ending loop with the following parameters"+newline;1078 writestr=writestr+"number of runs: "+string(r)+newline;1079 writestr=writestr+"number of intvecs per run: "+string(a)+newline;1080 writestr=writestr+"starting random seed for seqgen: "+string(sd)+newline;1081 writestr=writestr+"starting random seed for random: "+string(sta)+newline;1082 writestr=writestr+"length of the generated sequences: "+string(len)+newline;1083 writestr=writestr+newline+"in the whole loop, there were a total of"+newline;1084 writestr=writestr+" "+string(s)+" examples with non-zero-dim. likeideal"+newline;1085 writestr=writestr+" "+string(t)+1086 " examples with more than one biol. meaningful local maximum";1087 writestr=writestr+newline+"*****************************************************";1088 writestr=writestr+"used lengths:"+newline+string(ls);1089 writestr=writestr+newline+"*****************************************************";1090 1091 1092 write(lu,writestr);1093 write(lf,writestr);1094 close(lu);1095 close(lf);1096 }1097 1098 1099 1110 proc checkseqgenJC69loop(int r, int a, int sd, int sta, int len, int p) 1100 1111 { 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1112 //r the number of runs, a the number of intvecs per run, sd the starting random 1113 //seed, len the starting length, p the amount len will increase (on average) 1114 //after each run (via + random(1,2*p-1)) 1115 //sta the random seed for random 1116 1117 checkseqgenJC69writebeginning(r,a,sd,sta,len,p); 1118 1119 system("random",sta); 1120 intvec ls; 1121 int nzd, num, i, s, t; 1122 for(i=1; i<=r; i++) 1123 { 1124 (nzd,num)=checkseqgenJC69run(a,sd,len); 1125 sd++; 1126 ls[i]=len; 1127 len=len+random(1,2*p-1); 1128 s=s+nzd; 1129 t=t+num; 1130 } 1131 1132 checkseqgenJC69writeend(r,a,sd,sta,len,p,s,t,ls); 1122 1133 } 1123 1134 */
Note: See TracChangeset
for help on using the changeset viewer.