??xml version="1.0" encoding="utf-8" standalone="yes"?>久久久亚洲精品蜜桃臀,久久亚洲国产成人精品无码区,久久热这里只有精品在线观看http://www.shnenglu.com/luyulaile/I canzh-cnTue, 01 Jul 2025 00:05:33 GMTTue, 01 Jul 2025 00:05:33 GMT60TSP Java 实现http://www.shnenglu.com/luyulaile/archive/2013/03/31/198982.htmlluisluisSun, 31 Mar 2013 06:39:00 GMThttp://www.shnenglu.com/luyulaile/archive/2013/03/31/198982.htmlhttp://www.shnenglu.com/luyulaile/comments/198982.htmlhttp://www.shnenglu.com/luyulaile/archive/2013/03/31/198982.html#Feedback0http://www.shnenglu.com/luyulaile/comments/commentRss/198982.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/198982.htmlpackage BotClean;

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution2 {

    static class Status{
        int id;//current city
        String action;
        int distance;
        Vector<Integer> unvisited;
        HashSet<Integer> visited;
        public Status(int id)
        {
            this.id=id;
        }
    }


    static class DirtyDot{
        int id;//current city
        int x;
        int y;
        
        public DirtyDot(int id, int x, int y)
        {
            this.id=id;
            this.x=x;
            this.y=y;
        }
    }
/* Head ends here */
    static void next_move(int x, int y, String[] board){
        TSP(board,x,y);
                               
    }

/* Tail starts here */
    public static void main(String[] args) {
        //TSP(null,0,0);
        
        Scanner in = new Scanner(System.in);
        int [] pos = new int[2];
        String board[] = new String[5];
        for(int i=0;i<2;i++) pos[i] = in.nextInt();
        for(int i=0;i<5;i++) board[i] = in.next();
        System.out.println("begin now!");
        next_move(pos[0], pos[1], board);
    }
    

    
    public static void TSP(String[] board, int x, int y) {
        
        String dirty="d";
        HashMap<Integer, DirtyDot> dirtyList=new HashMap<Integer,DirtyDot>();
        int id=1;
        DirtyDot tempDirtyDot2;
        DirtyDot tempDirtyDot=new DirtyDot(id-1,x,y);
        dirtyList.put(id,tempDirtyDot);
        
        for(int i=0;i<board.length;i++)
        {
            if(board[i].contains(dirty))
            {
                int position;
                position=board[i].indexOf(dirty, 0);
                while(position!=-1)
                {
                    tempDirtyDot=new DirtyDot(id,i,position);
                    dirtyList.put(id,tempDirtyDot);                   
                    id++;
                    position=board[i].indexOf(dirty,position+1);
                    System.out.println("position"+position);
                }
            }
        }
        
//        int MAX=id;
//        int dist[][]=new int[MAX][MAX];
//        
//        for(int i=0;i<MAX;i++)
//            for(int j=0;j<MAX;j++)
//               {
//                tempDirtyDot=dirtyList.get(i);
//                tempDirtyDot2=dirtyList.get(j);
//                 dist[i][j]=Math.abs(tempDirtyDot.x-tempDirtyDot2.x)+Math.abs(tempDirtyDot.y-tempDirtyDot2.y);
//               }
        
          int MAX=4;
        
          int dist[][]={{-1,3,6,7},{2,-1,8,6},{7,3,-1,5,},{7,3,7,-1}}; 
        
        Vector<Status> currentStatus=new Vector<Status>();
        Vector<Status> previousStatus;
        /*Initialize current Status Vector*/
        for(int i=1;i<MAX;i++)
        {
            Status status=new Status(i);
            status.distance=dist[i][0];
            status.unvisited=new Vector<Integer>();
            status.visited=new HashSet<Integer>();
            currentStatus.add(status);
        }
        System.out.println("Initialized current Status Vector");
        //System.out.println(currentStatus.size());
        
        for(int j=0;j<MAX-2;j++)
        {
            previousStatus=currentStatus;
            currentStatus=new  Vector<Status>();
            //System.out.println(previousStatus.size());
            for(int i=1;i<MAX;i++)// enumerate each node
            {
                for(int k=0;k<previousStatus.size();k++)
                {
                    Status tempStatus=previousStatus.elementAt(k);
                    if(isContain(tempStatus,i)==false)//gurantee node i is not in tempStatus
                    {
                        Status newStatus=new Status(i);
                        newStatus.distance=tempStatus.distance+dist[i][tempStatus.id];
                        System.out.println("id"+tempStatus.id);
                        newStatus.visited=new HashSet<Integer>(tempStatus.visited);
                        newStatus.unvisited=new Vector<Integer>(tempStatus.unvisited);
                        newStatus.unvisited.add(0,(Integer)(tempStatus.id));
                        newStatus.visited.add(tempStatus.id);
                        currentStatus.add(newStatus);
                        System.out.println(newStatus.unvisited.size());
                        System.out.println(newStatus.distance);
                        
                    }
                }
            }
            //System.out.println(currentStatus.size());
            currentStatus=optimize(currentStatus);//dp process  
            
//System.out.println(currentStatus.size());
        }//end for
        
        Iterator<Status> iterator = currentStatus.iterator();  
   
        Status tempStatus=iterator.next();
        Status shortest=tempStatus;
        int minDistance=dist[0][tempStatus.id]+tempStatus.distance;
        System.out.println("1:"+tempStatus.distance);
        System.out.println("2:"+dist[0][tempStatus.id]);
        
        while (iterator.hasNext()) {  
             tempStatus=iterator.next();  
             int tempDistant=dist[0][tempStatus.id]+tempStatus.distance;
             System.out.println("11:"+tempStatus.distance);
             System.out.println("22:"+dist[0][tempStatus.id]);
             System.out.println("33:"+tempStatus.id);
             
             if(tempDistant<minDistance)
             {
                 minDistance=tempDistant;
                 System.out.println("in loop"+minDistance);
                 //System.out.println(tempStatus.distance);
                 shortest=tempStatus;
             }
          }
        
        System.out.println("distance: "+minDistance);
        System.out.println("size:"+shortest.unvisited.size());
        System.out.print(" 1");
        System.out.print(" "+shortest.id);
        for(int i=0;i<shortest.unvisited.size();i++)
            {
                 int tmp=shortest.unvisited.get(i)+1;
               System.out.print(" "+tmp);
            }
        System.out.println(" 1");
    }
    
    private static Vector<Status> optimize(Vector<Status> cs) {
        Status tempStatus,anotherStatus;
        int j;

        Iterator<Status> iterator = cs.iterator();    
         while (iterator.hasNext()) {  
             tempStatus=iterator.next();  
              for(j=0;j<cs.size();j++)
                {
                      anotherStatus=cs.get(j);
                      if(tempStatus.id==anotherStatus.id&&tempStatus.visited.equals(anotherStatus.visited))
                      {
                          if(tempStatus.distance>anotherStatus.distance)
                          {
                              iterator.remove();
                             break;
                          }
                      }
                }
             
         }    
          return cs;
    
    }

    static boolean isContain(Status sta, int i)
    {
        if(i==sta.id)
            return true;
        else
          return sta.unvisited.contains(i);
     }
    

}



luis 2013-03-31 14:39 发表评论
]]>
动态规?解TSP 旅行商问?l典实现 http://www.shnenglu.com/luyulaile/archive/2013/03/31/198974.htmlluisluisSat, 30 Mar 2013 21:26:00 GMThttp://www.shnenglu.com/luyulaile/archive/2013/03/31/198974.htmlhttp://www.shnenglu.com/luyulaile/comments/198974.htmlhttp://www.shnenglu.com/luyulaile/archive/2013/03/31/198974.html#Feedback0http://www.shnenglu.com/luyulaile/comments/commentRss/198974.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/198974.html原文地址: http://blog.csdn.net/gfaiswl/article/details/4749713

1.问题定义

      TSP问题Q旅行商问题Q是指旅行家要旅行n个城市,要求各个城市l历且仅l历一ơ然后回到出发城市,q要求所走的路程最短?/p>

      假设现在有四个城市,0,1,2,3Q他们之间的代h如图一Q可以存成二l表的Ş?br />

              image        image

                      图一                                                                                               

        现在要从城市0出发Q最后又回到0Q期?Q?Q?都必dƈ且只能经q一ơ,使代h?/p>

2.动态规划可行?/h1>

        设s, s1, s2, …, sp, s是从s出发的一条\径长度最短的单回路,假设从sC一个城市s1已经求出Q则问题转化为求从s1到s的最短\径,昄s1, s2, …, sp, s一定构成一条从s1到s的最短\径,所以TSP问题是构成最优子l构性质的,用动态规划来求解也是合理的?/p>

3.推导动态规划方E?/h1>

        假设从顶点s出发Qod(i, V’)表示从顶点i出发l过V’(是一个点的集?中各个顶点一ơ且仅一ơ,最后回到出发点s的最短\径长度?/p>

        推导Q?分情冉|讨论)

        ①当V’为空集,那么d(i, V’)Q表CZi不经qQ何点回到s了,如上囄 城市3->城市0(0v点城?。此时d(i, V’)=Cis(是 城市i ?城市s 的距??/p>

        ②如果V’不ؓI,那么是对子问题的最优求解。你必须在V’q个城市集合中,试每一个,q求出最优解?/p>

           d(i, V’)=min{Cik +  d(k, V’-{k})}

           注:Cik表示你选择的城市和城市i的距,d(k, V’-{k})是一个子问题?/p>

        lg所qͼTSP问题的动态规划方E就出来了:

         image

4.实例分析

     现在寚w题定义中的例子来说明TSP的求解过E?假设出发城市?0城市)

     image

    ①我们要求的最l结果是d(0,{1,2,3}),它表C,从城?开始,l过{1,2,3}之中的城市ƈ且只有一ơ,求出最短\?

    ②d(0,{1,2,3})是不能一下子求出来的Q那么他的值是怎么得出的呢Q看上图的第二层Q第二层表明了d(0,{1,2,3})所需依赖的倹{那么得出:

       d(0,{1,2,3})=min  {

                                    C01+d(1,{2,3})

                                    C02+d{2,{1,3}}

                                    C03+d{3,{1,2}}

                                  }

     ③d(1,{2,3})Qd(2,{1,3})Qd(3,{1,2})同样也不是一步就能求出来的,它们的解一样需要有依赖Q就比如说d(1,{2,3})

       d(1,{2,3})=min{

                              C12+d(2,{3})                             

                              C13+d(3,{2})

                              }

       d(2,{1,3})Qd(3,{1,2})同样需要这么求?/p>

    ④按照上面的思\Q只有最后一层的Q当当V’为空集时QCis的值才可以求,它的值是直接?/p>

image

q张表里求得的?/p>

     5.~程思\

        d(i, V’)转换成二l表Qd[i][j]

image

        在程序中模拟填表的过E,主要要考虑到jq个参数的表C,它要代表一个集合,可以用二l数l来表示?/p>

   6.源代?/h1>

注:׃本h水^有限Qƈ且主要在q里是体现思\Q所以程序ƈ不是很完善,代码质量也不高,很地方可以写得通用一些,所以这里只是提供一个参考,E序的进一步完善,p者自由发挥?/p>

#include 
#include

int IsIncluded(int x,int array[3])//x是否包含在数l中 

    if((array[0] != x) && (array[1] != x) && (array[2] != x)) 
        return 0; 
    return 1; 

int Left(int k,int array[3],int V[8][3])//实现V'-{k} 的下标检?nbsp;

    int i = 0,index = 0,array_0_count = 0,array_1_count = 0,array_2_count = 0,array_3_count = 0; 
    int V_0_count = 0,V_1_count = 0,V_2_count = 0,V_3_count = 0; 
    int temp[3]; 
    for(i = 0; i < 3; i++) 
        temp[i] = array[i]; 
    for(i = 0; i < 3; i++) 
        if(temp[i] == k) 
            temp[i] = 0;  //相当于去掉kq个城市 
    for(i = 0; i < 3; i++) 
    { 
        if(temp[i] == 0) 
            array_0_count++; 
        else if(temp[i] == 1) 
            array_1_count++; 
        else if(temp[i] == 2) 
            array_2_count++; 
        else 
            array_3_count++; 
    } 
    for(index = 0; index < 8; index++) 
    { 
        for(i=0; i < 3; i++) 
        { 
            if(V[index][i] == 0) 
                V_0_count++; 
            else if(V[index][i] == 1) 
                V_1_count++; 
            else if(V[index][i] == 2) 
                V_2_count++; 
            else 
                V_3_count++; 
        } 
        if((array_0_count == V_0_count) && (array_1_count == V_1_count) 
            && (array_2_count == V_2_count) && (array_3_count == V_3_count)) 
            return index; 
        V_0_count = 0; 
        V_1_count = 0; 
        V_2_count = 0; 
        V_3_count = 0; 
    } 
    return 0; 
}

void TSP(int d[4][8],int c[4][4],int V[8][3],int n) 

    int i = 0,j = 0,k = 0;

    for(i = 1; i < n; i++)//V'为空Ӟl赋| 
        d[i][0] = c[i][0];

    for(j = 1; j < 7; j++)//按列遍历不同集合Q{1},{2},{3},{1,2},{1,3}..... 
    { 
        for(i = 1; i < n; i++)//遍历城市1Q?Q? 
        { 
            if( !IsIncluded(i,V[j]) )//i必须不在集合中,否则属于经q两ơ,不符合题?nbsp;
            { 
                for(k = 0; k < 3; k++)//分别试探集合中的每一点,取最?nbsp;
                { 
                    if((V[j][k] != 0) && ((c[i][V[j][k]] + d[V[j][k]][Left(V[j][k],V[j],V)]) < d[i][j])) 
                        d[i][j] = c[i][V[j][k]] + d[V[j][k]][Left(V[j][k],V[j],V)]; 
                } 
            } 
        }//end of     for(i = 1; i < n; i++)//遍历城市1Q?Q? 
    }//end of for(j = 1; j < ((int)pow(2,n)-1); j++) 
    for(k = 0; k < 3; k++)//分别试探下一步ؓ集合中的M一点,取最?nbsp;
    { 
        if((V[7][k] != 0) && (c[0][V[7][k]] + d[V[7][k]][Left(V[7][k],V[7],V)]) < d[0][7]) 
            d[0][7] = c[0][V[7][k]] + d[V[7][k]][Left(V[7][k],V[7],V)]; 
    } 

void main() 

    int V[8][3]= 
    { 
        0,0,0, 
        0,0,1, 
        0,0,2, 
        0,0,3, 
        0,1,2, 
        0,1,3, 
        0,2,3, 
        1,2,3 
    }; 
    int c[4][4]= 
    { 
        0,3,6,7, 
        5,0,2,3, 
        6,4,0,2, 
        3,7,5,0 
    }; 
    int d[4][8]={0},i=0,j=0;

    for(i=0; i<4; i++) 
        for(j=0; j<8; j++) 
            d[i][j]=1000;   //假设1000为无I大 
    TSP(d,c,V,4); 
    printf("The least road is:%d/n",d[0][7]); 
}



luis 2013-03-31 05:26 发表评论
]]>矩阵乘法的意?/title><link>http://www.shnenglu.com/luyulaile/archive/2012/12/05/196013.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Wed, 05 Dec 2012 10:44:00 GMT</pubDate><guid>http://www.shnenglu.com/luyulaile/archive/2012/12/05/196013.html</guid><wfw:comment>http://www.shnenglu.com/luyulaile/comments/196013.html</wfw:comment><comments>http://www.shnenglu.com/luyulaile/archive/2012/12/05/196013.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/luyulaile/comments/commentRss/196013.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/luyulaile/services/trackbacks/196013.html</trackback:ping><description><![CDATA[<div> <img src="file:///C:\users\yilu\AppData\Tencent\Users\349826924\QQ\WinTemp\RichOle\{NB9CE}[L5OABB`L$N7RJK3.jpg" alt="" /><img src="file:///C:\users\yilu\AppData\Tencent\Users\349826924\QQ\WinTemp\RichOle\{NB9CE}[L5OABB`L$N7RJK3.jpg" alt="" /><img src="http://www.shnenglu.com/images/cppblog_com/luyulaile/未命?2.5.jpg" border="0" alt="" width="893" height="563" /><br />相当于A(B <strong>x</strong>) <br /></div><img src ="http://www.shnenglu.com/luyulaile/aggbug/196013.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/luyulaile/" target="_blank">luis</a> 2012-12-05 18:44 <a href="http://www.shnenglu.com/luyulaile/archive/2012/12/05/196013.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Python extract all comments:提取所有comments,提取c/c++中注释Python脚本http://www.shnenglu.com/luyulaile/archive/2012/12/03/195907.htmlluisluisMon, 03 Dec 2012 00:35:00 GMThttp://www.shnenglu.com/luyulaile/archive/2012/12/03/195907.htmlhttp://www.shnenglu.com/luyulaile/comments/195907.htmlhttp://www.shnenglu.com/luyulaile/archive/2012/12/03/195907.html#Feedback0http://www.shnenglu.com/luyulaile/comments/commentRss/195907.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/195907.html如果 E序中出C“/*”,会有bug

#!/usr/bin/env python

import sys
import re

def comment_finder(text):
    pattern = re.compile( r'//.*?$|/\*.*?\*/', re.DOTALL | re.MULTILINE)
    result = pattern.findall(text)
    return result

def print_command(filename):

    codefile = open(filename,'r')
    commentfile = open(filename+".txt",'w')
    lines=codefile.read()
    codefile.close()
    #the list of comments
    list_of_comments = comment_finder(lines)
    for comment in list_of_comments:
        #print comment[0:2]
        if comment[0:2] == "//":
                comment_to_write = comment[2:]
        else:
            comment_to_write = comment[2:-2]
        if len(comment_to_write)!=0:
            commentfile.write(comment_to_write)
        commentfile.write('\n')
    commentfile.close()

if __name__ == "__main__":
    for filename in sys.argv[1:]:
        print_command(filename)
使用Q?br />
在linux下面 转到当前目录 ./get_comment.py *
或?指定文gcd
./get_comment.py *.c


luis 2012-12-03 08:35 发表评论
]]>
Latex 表格http://www.shnenglu.com/luyulaile/archive/2012/11/22/195518.htmlluisluisWed, 21 Nov 2012 17:07:00 GMThttp://www.shnenglu.com/luyulaile/archive/2012/11/22/195518.htmlhttp://www.shnenglu.com/luyulaile/comments/195518.htmlhttp://www.shnenglu.com/luyulaile/archive/2012/11/22/195518.html#Feedback0http://www.shnenglu.com/luyulaile/comments/commentRss/195518.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/195518.html\begin{tabular}{|c|c|c|c|c|c|}
\hline 
Accuracy & General & test 1 & test 2 & test 3 & test 4\tabularnewline
\hline 

Linear  & 0.8950695  & 0.8817864 & 0.8884132  & 0.8884036  & 0.9217801
\tabularnewline
\hline 

Polynomial Degree=2 & 0.927821  & 0.9118337 & 0.934325 & 0.913003 &
0.9335226\tabularnewline
\hline 
Polynomial Degree=2 & 0.8350725  & 0.8317865 & 0.8285052  & 0.8278306  &
0.852091
\tabularnewline
\hline 
Polynomial Degree=3 & 0.770894 & 0.7539803  & 0.7510282 &  0.7762011 &
0.7821553\tabularnewline
\hline 
Polynomial Degree=4 & 0.7172013 & 0.685079 & 0.6988003 & 0.7329987 &
0.7520278\tabularnewline

\hline 
\end{tabular}


=========================


  • Type one:

%%%%%%%%%%单表?%%%%%%%%%

\begin{tabular}{|c|c|}

\hline

a & b \\\hline

c & d\\

\hline

\end{tabular}

 

  • Type two:

%%%%%%%%%%单表?居中(一)%%%%%%%%%%

\begin{center}

\begin{tabular}{|c|c|}

\hline

a & b \\\hline

c & d\\

\hline

\end{tabular}

\end{center}

 

  • Type three:

%%%%%%%%%%单表?居中Q二Q?%%%%%%%%%

\centering

\begin{tabular}{|c|c|}

\hline

a & b \\\hline

c & d\\

\hline

\end{tabular}

This a Table~??

 

  • Type four:

%%%%%%%%%%单表?居中,标题Q编?固定位置%%%%%%%%%%

\begin{table}[h]

\centering

\caption{table}\label{tab:table}

\begin{tabular}{|c|c|}

\hline

a & b \\\hline

c & d\\

\hline

\end{tabular}

\end{table}

  • Type five:

%%%%%%%%%%一个完整的例子%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%Beginning of Table example%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{table}[ht]

\caption{Review paper} % title of Table

\centering % used for centering table

\begin{tabular}{|c|c|} % centered columns (2 columns)

\hline\hline %inserts double horizontal lines

Item 1 & Item 2 \\ [0.5ex] % inserts table heading

\hline % inserts single horizontal line

a & b \\ % inserting body of the table

c & d \\

e & f \\[1.5ex] % [1.5ex] adds vertical space

\hline %inserts single line

\end{tabular}

\label{table:nonlin} % is used to refer this table in the text

\end{table}

%%%%%%%%%%%%%%%%%% end of the example%%%%%%%%%%%%%%%%%%%%%%%%%



luis 2012-11-22 01:07 发表评论
]]>
Java 字符串比?/title><link>http://www.shnenglu.com/luyulaile/archive/2012/11/22/195517.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Wed, 21 Nov 2012 16:44:00 GMT</pubDate><guid>http://www.shnenglu.com/luyulaile/archive/2012/11/22/195517.html</guid><wfw:comment>http://www.shnenglu.com/luyulaile/comments/195517.html</wfw:comment><comments>http://www.shnenglu.com/luyulaile/archive/2012/11/22/195517.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/luyulaile/comments/commentRss/195517.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/luyulaile/services/trackbacks/195517.html</trackback:ping><description><![CDATA[原文Q?a >http://www.cnblogs.com/tonyqus/archive/2004/12/07/73710.html</a> <span style="color: #393939; font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; background-color: #faf7ef; "></span><br /><span style="color: #393939; font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; background-color: #faf7ef; "><br /><br />熟悉C++的h对于两个字符串比较的代码一定很了解Q?nbsp;</span><br style="margin: 0px; padding: 0px; color: #393939; font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; background-color: #faf7ef; " /><span style="color: #393939; font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; background-color: #faf7ef; ">(string1==string2) </span><br style="margin: 0px; padding: 0px; color: #393939; font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; background-color: #faf7ef; " /><span style="color: #393939; font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; background-color: #faf7ef; ">但在java中,q个代码即在两个字W串完全相同的情况下也会q回false </span><br style="margin: 0px; padding: 0px; color: #393939; font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; background-color: #faf7ef; " /><span style="color: #393939; font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; background-color: #faf7ef; ">Java中必M用string1.equals(string2)来进行判?nbsp;</span><br style="margin: 0px; padding: 0px; color: #393939; font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; background-color: #faf7ef; " /><br style="margin: 0px; padding: 0px; color: #393939; font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; background-color: #faf7ef; " /><strong style="margin: 0px; padding: 0px; color: #393939; font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; background-color: #faf7ef; ">补充</strong> <br style="margin: 0px; padding: 0px; color: #393939; font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; background-color: #faf7ef; " /><span style="color: #393939; font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; background-color: #faf7ef; ">如果Q?nbsp;</span><br style="margin: 0px; padding: 0px; color: #393939; font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; background-color: #faf7ef; " /><span style="color: #393939; font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; background-color: #faf7ef; ">string s1=new String("Hello"); </span><br style="margin: 0px; padding: 0px; color: #393939; font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; background-color: #faf7ef; " /><span style="color: #393939; font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; background-color: #faf7ef; ">string s2=new String("Hello"); </span><br style="margin: 0px; padding: 0px; color: #393939; font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; background-color: #faf7ef; " /><span style="color: #393939; font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; background-color: #faf7ef; ">?s1==s2)=false </span><br style="margin: 0px; padding: 0px; color: #393939; font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; background-color: #faf7ef; " /><br style="margin: 0px; padding: 0px; color: #393939; font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; background-color: #faf7ef; " /><span style="color: #393939; font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; background-color: #faf7ef; ">如果Q?nbsp;</span><br style="margin: 0px; padding: 0px; color: #393939; font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; background-color: #faf7ef; " /><span style="color: #393939; font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; background-color: #faf7ef; ">string s1="Hello"; </span><br style="margin: 0px; padding: 0px; color: #393939; font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; background-color: #faf7ef; " /><span style="color: #393939; font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; background-color: #faf7ef; ">string s2="Hello"; </span><br style="margin: 0px; padding: 0px; color: #393939; font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; background-color: #faf7ef; " /><span style="color: #393939; font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; background-color: #faf7ef; ">?s1==s2)=true; </span><br style="margin: 0px; padding: 0px; color: #393939; font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; background-color: #faf7ef; " /><span style="color: #393939; font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; background-color: #faf7ef; ">因ؓ他们指向的同一个对象?nbsp;</span><br style="margin: 0px; padding: 0px; color: #393939; font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; background-color: #faf7ef; " /><br style="margin: 0px; padding: 0px; color: #393939; font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; background-color: #faf7ef; " /><span style="color: #393939; font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; background-color: #faf7ef; ">如果把其他变量的Dls1和s2Q即使内容相同,׃不是指向同一个对象,也会q回false。所以徏议用equals()Q因为equals比较的才是真正的内容 </span><img src ="http://www.shnenglu.com/luyulaile/aggbug/195517.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/luyulaile/" target="_blank">luis</a> 2012-11-22 00:44 <a href="http://www.shnenglu.com/luyulaile/archive/2012/11/22/195517.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Latex 多个囄http://www.shnenglu.com/luyulaile/archive/2012/11/16/195250.htmlluisluisThu, 15 Nov 2012 19:43:00 GMThttp://www.shnenglu.com/luyulaile/archive/2012/11/16/195250.htmlhttp://www.shnenglu.com/luyulaile/comments/195250.htmlhttp://www.shnenglu.com/luyulaile/archive/2012/11/16/195250.html#Feedback0http://www.shnenglu.com/luyulaile/comments/commentRss/195250.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/195250.html
\usepackage{subfigure}
注意不用?{subfig}
\begin{figure}[ht]
\centering
\subfigure[$\alpha$=0.5,$\gamma$=0.9,$\epsilon$=0.01]{
   \includegraphics[width=4.4in] {2.png}
 }
 \subfigure[$\alpha$=0.7,$\gamma$=0.9,$\epsilon$=0.01]{
   \includegraphics[width=4.4in] {3.png}
 }
 \subfigure[$\alpha$=0.9,$\gamma$=0.9,$\epsilon$=0.01]{
   \includegraphics[width=4.4in] {4.png}
 }
 \subfigure[$\alpha$=0.7,$\gamma$=0.9,$\epsilon$=0.1]{
   \includegraphics[width=4.4in] {5.png}
 }
 \subfigure[$\alpha$=0.7,$\gamma$=0.9,$\epsilon$=0.2]{
   \includegraphics[width=4.4in] {6.png}
 }
 \subfigure[$\alpha$=0.7,$\gamma$=0.6,$\epsilon$=0.01]{
   \includegraphics[width=4.4in] {1.png}
 }
\end{figure}


luis 2012-11-16 03:43 发表评论
]]>
Python W记 pi tan {公?/title><link>http://www.shnenglu.com/luyulaile/archive/2012/11/08/194861.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Thu, 08 Nov 2012 00:21:00 GMT</pubDate><guid>http://www.shnenglu.com/luyulaile/archive/2012/11/08/194861.html</guid><wfw:comment>http://www.shnenglu.com/luyulaile/comments/194861.html</wfw:comment><comments>http://www.shnenglu.com/luyulaile/archive/2012/11/08/194861.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/luyulaile/comments/commentRss/194861.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/luyulaile/services/trackbacks/194861.html</trackback:ping><description><![CDATA[<div style="text-align: justify;"><div>import math<br />def mianji(n,s):</div><div>    temp=1/4*n*(s**2)/math.tan(math.pi/n)</div><div>    return temp</div><div>print mianji(5,7)<br />============<br />使用时math.pi math.tan</div></div><img src ="http://www.shnenglu.com/luyulaile/aggbug/194861.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/luyulaile/" target="_blank">luis</a> 2012-11-08 08:21 <a href="http://www.shnenglu.com/luyulaile/archive/2012/11/08/194861.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Python 生成随机?/title><link>http://www.shnenglu.com/luyulaile/archive/2012/11/08/194859.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Wed, 07 Nov 2012 22:56:00 GMT</pubDate><guid>http://www.shnenglu.com/luyulaile/archive/2012/11/08/194859.html</guid><wfw:comment>http://www.shnenglu.com/luyulaile/comments/194859.html</wfw:comment><comments>http://www.shnenglu.com/luyulaile/archive/2012/11/08/194859.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/luyulaile/comments/commentRss/194859.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/luyulaile/services/trackbacks/194859.html</trackback:ping><description><![CDATA[<blockquote style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 10px; padding-bottom: 1px; border: 0px; vertical-align: baseline; background-color: #eeeeee; quotes: none; color: #000000; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; line-height: 18px; "><p style="margin: 0px 0px 1em; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; clear: both; word-wrap: break-word; "><code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; "><table cellspacing="0" cellpadding="0" style="word-wrap: break-word; empty-cells: show; border-collapse: collapse; table-layout: fixed; width: 1119px; color: #000000; font-family: song, Verdana; font-size: 12px; text-align: start; background-color: #ffffff; "><tbody style="word-wrap: break-word; "><tr style="word-wrap: break-word; "><td id="postmessage_8263409" style="word-wrap: break-word; font-size: 14px; line-height: 1.6em; ">import random<br style="word-wrap: break-word; " /><br style="word-wrap: break-word; " />a=random.randint(0,1001)#q个生成的区间是 [0,1001]<br />a=random.randrange(0,10001)#生成的是区间是[0,1001)<br style="word-wrap: break-word; " /><br style="word-wrap: break-word; " />print a</td></tr></tbody></table><br /><br /><br />random.randrange([start], stop[, step])</code></p><p style="margin: 0px 0px 1em; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; clear: both; word-wrap: break-word; ">Return a randomly selected element from <code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; ">range(start, stop, step)</code>. <strong style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; ">This is equivalent to<code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; ">choice(range(start, stop, step))</code></strong>, but doesn’t actually build a range object.</p></blockquote><p style="margin: 0px 0px 1em; padding: 0px; border: 0px; vertical-align: baseline; background-color: #ffffff; clear: both; word-wrap: break-word; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; line-height: 18px; ">And range(start, stop) returns <code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; ">[start, start+step, ..., stop-1]</code>, not <code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; ">[start, start+step, ..., stop]</code>. As for why... zero-based counting rules and <code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; ">range(n)</code> should return n elements, I suppose. Most useful for getting a random index, I suppose.</p><p style="margin: 0px 0px 1em; padding: 0px; border: 0px; vertical-align: baseline; background-color: #ffffff; clear: both; word-wrap: break-word; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; line-height: 18px; ">While randint is documented as:</p><blockquote style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding-top: 10px; padding-bottom: 1px; border: 0px; vertical-align: baseline; background-color: #eeeeee; quotes: none; color: #000000; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; line-height: 18px; "><p style="margin: 0px 0px 1em; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; clear: both; word-wrap: break-word; "><code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; ">random.randint(a, b)</code></p><p style="margin: 0px 0px 1em; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; clear: both; word-wrap: break-word; ">Return a random integer N such that <code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; ">a <= N <= b</code>. <strong style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; ">Alias for <code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; ">randrange(a, b+1)</code></strong></p></blockquote><p style="margin: 0px 0px 1em; padding: 0px; border: 0px; vertical-align: baseline; background-color: #ffffff; clear: both; word-wrap: break-word; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; line-height: 18px; ">So randint is for when you have the maximum and minimum value for the random number you want.</p><img src ="http://www.shnenglu.com/luyulaile/aggbug/194859.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/luyulaile/" target="_blank">luis</a> 2012-11-08 06:56 <a href="http://www.shnenglu.com/luyulaile/archive/2012/11/08/194859.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Python W记2 //http://www.shnenglu.com/luyulaile/archive/2012/11/08/194858.htmlluisluisWed, 07 Nov 2012 22:43:00 GMThttp://www.shnenglu.com/luyulaile/archive/2012/11/08/194858.htmlhttp://www.shnenglu.com/luyulaile/comments/194858.htmlhttp://www.shnenglu.com/luyulaile/archive/2012/11/08/194858.html#Feedback0http://www.shnenglu.com/luyulaile/comments/commentRss/194858.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/194858.html
s1 = "hello,world" 
如果要写成多行,那么p使用/ (“q行W?#8221;)吧,?nbsp;
s2 = "hello,/ 
world" 
s2与s1是一L。如果你?个双引号的话Q就可以直接写了Q如下: 
s3 = """hello, 
world, 
hahaha."""Q那么s3实际上就?hello,/nworld,/nhahaha.", 注意“/n”

s5 = "Let's go"  
s4 = 'Let/'s go' 

我们也可以把'''  ''' 作ؓ多行注释

str(object) 可以所有{化ؓ字符丌Ӏ?br />

pythonjava描述
or||逻辑?/td>
and&&逻辑?/td>
notQ?/td>逻辑?/td>
<Q?gt;Q?lt;=Q?gt;=Q?=Q?=?lt;><Q?gt;Q?lt;=Q?gt;=Q?=Q?=比较操作
isQis notinstanceofw䆾认证
||位或
&&位与
^^位异?/td>
<<Q?gt;><<Q?gt;>UM
+Q?Q?Q?+Q?Q?Q?加减乘除
%%余数
~~位取?/td>


//q算W? 
10/3==3
120//10==12
121//10==12
122//10==12
130//10==13
10//3.0==3.0

A new operator, //, is the floor division operator. (Yes, we know it 
looks like C++'s comment symbol.) // always performs floor division no 
matter what the types of its operands are, so 1 // 2 is 0 and 1.0 // 
2.0 is also 0.0. 

not ()


luis 2012-11-08 06:43 发表评论
]]>
Latex 多行公式http://www.shnenglu.com/luyulaile/archive/2012/11/06/194700.htmlluisluisMon, 05 Nov 2012 22:29:00 GMThttp://www.shnenglu.com/luyulaile/archive/2012/11/06/194700.htmlhttp://www.shnenglu.com/luyulaile/comments/194700.htmlhttp://www.shnenglu.com/luyulaile/archive/2012/11/06/194700.html#Feedback0http://www.shnenglu.com/luyulaile/comments/commentRss/194700.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/194700.html\newcommand{\parenthnewln}[1]{\right.\\#1&\left.{}}
\begin{equation}
\begin{split}
f(x)=1+&g(x)\\
=1+&\left(x+x^2+\dots
\parenthnewln{+}x^n+\ldots\right)
\end{split}
\end{equation}
得到Q?br />


luis 2012-11-06 06:29 发表评论
]]>
Latex 中插入代?/title><link>http://www.shnenglu.com/luyulaile/archive/2012/10/31/194135.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Wed, 31 Oct 2012 13:30:00 GMT</pubDate><guid>http://www.shnenglu.com/luyulaile/archive/2012/10/31/194135.html</guid><wfw:comment>http://www.shnenglu.com/luyulaile/comments/194135.html</wfw:comment><comments>http://www.shnenglu.com/luyulaile/archive/2012/10/31/194135.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/luyulaile/comments/commentRss/194135.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/luyulaile/services/trackbacks/194135.html</trackback:ping><description><![CDATA[<h2><span id="Typesetting_using_the_algorithm2e_package"><a >http://en.wikibooks.org/wiki/LaTeX/Algorithms_and_Pseudocode</a> <br />Typesetting using the <tt style="font-family: monospace, Courier; ">algorithm2e</tt> package</span></h2><p style="margin: 0.4em 0px 0.5em; line-height: 19.200000762939453px; font-family: sans-serif; font-size: 13px; background-color: #ffffff; ">The <tt style="font-family: monospace, Courier; ">algorithm2e</tt> package (first released 1995, latest updated December 2009 according to the <a rel="nofollow" text"="" target="_blank" style="text-decoration: none; color: #663366; background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAQAAAAnOwc2AAAATklEQVR4XmXKQQqAMAwF0X/7XsSz9CSKiyIIFRFcjMmihmiGbB5fqDCaQJ4j46pzYLUWe+cXZ6OVBhTS0srY2Njp/+XxXXZOLu6EUWAOPX1vnwTBe6qQAAAAAElFTkSuQmCC); padding-right: 13px; background-position: 100% 50%; background-repeat: no-repeat no-repeat; ">v4.01 manual</a>) allows typesetting algorithms with a lot of customization. The package is loaded like</p><div dir="ltr" mw-code="" mw-content-ltr"="" style="font-family: monospace, Courier; direction: ltr; padding: 1em; border: 1px dashed #2f6fab; background-color: #f9f9f9; line-height: 1.1em; font-size: 13px; "><div source-latex"="" style="line-height: normal; font-family: monospace; "><pre style="padding: 0px; border: 0px none white; line-height: 1.2em; font-size: 1em; margin-top: 0px; margin-bottom: 0px; background-image: none; vertical-align: top; "><span style="color: #e02020; ">\</span><span style="color: #800000; ">usepackage</span><span style="color: #e02020; ">[</span><span style="color: #c08020; ">options</span><span style="color: #e02020; ">]{</span><span style="color: #2020c0; ">algorithm2e</span><span style="color: #e02020; ">}</span> </pre></div></div><p style="margin: 0.4em 0px 0.5em; line-height: 19.200000762939453px; font-family: sans-serif; font-size: 13px; background-color: #ffffff; ">and a simple example, taken from the v4.01 manual, is</p><div dir="ltr" mw-code="" mw-content-ltr"="" style="font-family: monospace, Courier; direction: ltr; padding: 1em; border: 1px dashed #2f6fab; background-color: #f9f9f9; line-height: 1.1em; font-size: 13px; "><div source-latex"="" style="line-height: normal; font-family: monospace; "><pre style="padding: 0px; border: 0px none white; line-height: 1.2em; font-size: 1em; margin-top: 0px; margin-bottom: 0px; background-image: none; vertical-align: top; "><div style="background-color: #eeeeee; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all; "><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->\begin{algorithm}[H]<br /> \SetAlgoLined<br /> \KwData{this text}<br /> \KwResult{how to write algorithm with \LaTeX2e }<br /> initialization\;<br /> \While{<span style="color: #0000FF; ">not</span> at end of this document}{<br />  read current\;<br />  \eIf{understand}{<br />   go to next section\;<br />   current section becomes this one\;<br />   }{<br />   go back to the beginning of current section\;<br />  }<br /> }<br /> \caption{How to write algorithms}<br />\end{algorithm}</div></pre></div></div><p style="margin: 0.4em 0px 0.5em; line-height: 19.200000762939453px; font-family: sans-serif; font-size: 13px; background-color: #ffffff; ">which produces <a style="text-decoration: none; color: #0b0080; background-image: none; background-position: initial initial; background-repeat: initial initial; "><img alt="Latex-algorithm2e-if-else.png" src="http://upload.wikimedia.org/wikipedia/commons/thumb/6/6d/Latex-algorithm2e-if-else.png/300px-Latex-algorithm2e-if-else.png" width="300" height="181" srcset="http://upload.wikimedia.org/wikipedia/commons/thumb/6/6d/Latex-algorithm2e-if-else.png/450px-Latex-algorithm2e-if-else.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/6/6d/Latex-algorithm2e-if-else.png/600px-Latex-algorithm2e-if-else.png 2x" style="border: none; vertical-align: middle; margin: 0px; " /></a></p><img src ="http://www.shnenglu.com/luyulaile/aggbug/194135.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/luyulaile/" target="_blank">luis</a> 2012-10-31 21:30 <a href="http://www.shnenglu.com/luyulaile/archive/2012/10/31/194135.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Latex 中插入代?/title><link>http://www.shnenglu.com/luyulaile/archive/2012/10/31/194134.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Wed, 31 Oct 2012 13:25:00 GMT</pubDate><guid>http://www.shnenglu.com/luyulaile/archive/2012/10/31/194134.html</guid><wfw:comment>http://www.shnenglu.com/luyulaile/comments/194134.html</wfw:comment><comments>http://www.shnenglu.com/luyulaile/archive/2012/10/31/194134.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/luyulaile/comments/commentRss/194134.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/luyulaile/services/trackbacks/194134.html</trackback:ping><description><![CDATA[<p style="margin: 0px 0px 1em; padding: 0px; border: 0px; vertical-align: baseline; background-color: #ffffff; clear: both; word-wrap: break-word; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; line-height: 18px; "><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->\usepackage{listings}<br />\usepackage{color}<br /><br />\definecolor{dkgreen}{rgb}{0,0.6,0}<br />\definecolor{gray}{rgb}{0.5,0.5,0.5}<br />\definecolor{mauve}{rgb}{0.58,0,0.82}<br /><br />\lstset{frame=tb,<br />  language=Java,<br />  aboveskip=3mm,<br />  belowskip=3mm,<br />  showstringspaces=false,<br />  columns=flexible,<br />  basicstyle={\small\ttfamily},<br />  numbers=none,<br />  numberstyle=\tiny\color{gray},<br />  keywordstyle=\color{blue},<br />  commentstyle=\color{dkgreen},<br />  stringstyle=\color{mauve},<br />  breaklines=true,<br />  breakatwhitespace=true<br />  tabsize=3<br />}<br />================<br /><br /><p style="margin: 0px 0px 1em; padding: 0px; border: 0px; font-size: 14px; vertical-align: baseline; background-color: #ffffff; clear: both; word-wrap: break-word; ">You can change default language in the middle of document with <code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; ">\lstset{language=Java}</code>.</p><p style="margin: 0px 0px 1em; padding: 0px; border: 0px; font-size: 14px; vertical-align: baseline; background-color: #ffffff; clear: both; word-wrap: break-word; ">Example of usage in the document:</p><div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all; "><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->\begin{lstlisting}<br />// Hello.java<br /><span style="color: #0000FF; ">import</span> javax.swing.JApplet;<br /><span style="color: #0000FF; ">import</span> java.awt.Graphics;<br /><br />public <span style="color: #0000FF; ">class</span> Hello extends JApplet {<br />    public void paintComponent(Graphics g) {<br />        g.drawString(<span style="color: #800000; ">"</span><span style="color: #800000; ">Hello, world!</span><span style="color: #800000; ">"</span>, 65, 95);<br />    }    <br />}</div><pre style="margin-top: 0px; margin-bottom: 10px; padding: 5px; border: 0px; font-size: 14px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; overflow: auto; width: auto; max-height: 600px; "><code style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; "><span style="font-size: 13px; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; ">\end{lstlisting}</span> </code></pre><p style="margin: 0px 0px 1em; padding: 0px; border: 0px; font-size: 14px; vertical-align: baseline; background-color: #ffffff; clear: both; word-wrap: break-word; ">Here's the result:</p></div></p><img src ="http://www.shnenglu.com/luyulaile/aggbug/194134.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/luyulaile/" target="_blank">luis</a> 2012-10-31 21:25 <a href="http://www.shnenglu.com/luyulaile/archive/2012/10/31/194134.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>label switchinghttp://www.shnenglu.com/luyulaile/archive/2012/10/31/194109.htmlluisluisTue, 30 Oct 2012 19:36:00 GMThttp://www.shnenglu.com/luyulaile/archive/2012/10/31/194109.htmlhttp://www.shnenglu.com/luyulaile/comments/194109.htmlhttp://www.shnenglu.com/luyulaile/archive/2012/10/31/194109.html#Feedback0http://www.shnenglu.com/luyulaile/comments/commentRss/194109.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/194109.html比如有两p果: W一个箱子内有两个苹果,label 为a 的概率ؓ30%,为b的概?0%Q第二个子内有四个ҎQlabel为b的概?0%,label 为a的概?0%.
如果我们求所有的Ҏ的重量,只需要将所有的子内的Ҏ取出来求重量卛_?br />但是我们先求label a的箱子苹果的重量Q加上label b的箱子苹果的重量Q可能出Cơ取的是同一个箱子,q就是label switching问题?img src ="http://www.shnenglu.com/luyulaile/aggbug/194109.html" width = "1" height = "1" />

luis 2012-10-31 03:36 发表评论
]]>
Python generate corpus using Dirichlet distributionhttp://www.shnenglu.com/luyulaile/archive/2012/10/28/193960.htmlluisluisSun, 28 Oct 2012 02:13:00 GMThttp://www.shnenglu.com/luyulaile/archive/2012/10/28/193960.htmlhttp://www.shnenglu.com/luyulaile/comments/193960.htmlhttp://www.shnenglu.com/luyulaile/archive/2012/10/28/193960.html#Feedback0http://www.shnenglu.com/luyulaile/comments/commentRss/193960.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/193960.htmlAt first, let's define the sample function:

def sample(dist, num_samples=1):
    """
    Uses the inverse CDF method to return samples drawn from an
    (unnormalized) discrete distribution.

    Arguments:

    dist -- (unnormalized) distribution

    Keyword arguments:

    num_samples -- number of samples to draw
    
"""

    cdf = cumsum(dist)
    r = uniform(size=num_samples) * cdf[-1]

    return cdf.searchsorted(r)
As we can see, the sample function input two parameters, one is dist, which can be an un-normalized distribution, another is the sample we want to draw.

Let's see how to generate corpus for Dirichlet--multinomial unigram language model
def generate_corpus(beta, mean, N):
    """
    Returns a corpus of tokens drawn from a Dirichlet--multinomial
    unigram language model. Each token is an instance of one of V
    unique word types, represented by indices 0, , V - 1.

    Arguments:

    beta -- concentration parameter for the Dirichlet prior
    mean -- V-dimensional mean of the Dirichlet prior
    N -- number of tokens to generate
    
"""

    pass # YOUR CODE GOES HERE
    #print mean
    #print beta 
    #print dot(mean,beta)
    #print dirichlet(mean*beta,size=1)
    temp=sample(dirichlet(beta*array(mean),size=1),N)
    #print temp
    return temp
please keep in mind the dirichlet function is  “from numpy.random.mtrand import dirichlet"
and the parameters it receives are corresponding to beta*array(mean). beta is the concentration factor, and mean is the vector which sum to 1.



another way is to generate corpus is using the property:
P(D'|D,H)= Nv+beta_nv/N+beta
def generate_corpus_collapsed(beta, mean, N):
    """
    Returns a corpus of tokens drawn from a Dirichlet--multinomial
    unigram language model using the 'collapsed' generative process
    (i.e., phi is not explicitly represented). Each token is an
    instance of one of V unique word types.

    Arguments:

    beta -- concentration parameter for the Dirichlet prior
    mean -- V-dimensional mean of the Dirichlet prior
    N -- number of tokens to generate
    
"""

    V = len(mean) # vocabulary size

    corpus = zeros(N, dtype=int) # corpus

    Nv = zeros(V, dtype=int) # counts for each word type

    pass # YOUR CODE GOES HERE
    for n in xrange(N):
        corpus[n]=sample((Nv+beta*array(mean))/(n+beta),1)
        Nv[corpus[n]]+=1;    
    return corpus

Let's see how to generate corpus for Mixture of Dirichlet-multinomial unigram language model 

def generate_corpus(alpha, m, beta, n, D, Nd):
    """
    Returns a grouped corpus drawn from a mixture of
    Dirichlet--multinomial unigram language models.

    Arguments:

    alpha -- concentration parameter for the Dirichlet prior over theta
    m -- T-dimensional mean of the Dirichlet prior over theta
    beta -- concentration parameter for the Dirichlet prior over phis
    n -- V-dimensional mean of the Dirichlet prior over phis
    D -- number of documents to generate
    Nd -- number of tokens to generate per document
    
"""
    corpus = GroupedCorpus()

    pass # YOUR CODE GOES HERE
    #determine the topic the distribution for topic dirichlet(dot(m,alpha),size=1)
    #given the topic, the distribtuion for word dirichlet(dot(n,beta),size=1)
    theta=dirichlet(alpha*array(m),1)
    phis=dirichlet(beta*array(n),len(m))
    for d in range(0,D):
        [t]=sample(theta,1)
        #print groupVcab
        corpus.add(str(d),str(t),[str(x) for x in sample(phis[t,:],Nd)])           
    return corpus
注意是T个topic (group)Q?span style="font-size: 13px; background-color: #eeeeee; ">  phis=dirichlet(beta*array(n),len(m))  产生了T?dirichlet distribution,相同的topic t应该取同一?dirichlet distribution phis[t,:]

luis 2012-10-28 10:13 发表评论
]]>
多维矩阵 求和http://www.shnenglu.com/luyulaile/archive/2012/10/27/193940.htmlluisluisSat, 27 Oct 2012 05:11:00 GMThttp://www.shnenglu.com/luyulaile/archive/2012/10/27/193940.htmlhttp://www.shnenglu.com/luyulaile/comments/193940.htmlhttp://www.shnenglu.com/luyulaile/archive/2012/10/27/193940.html#Feedback0http://www.shnenglu.com/luyulaile/comments/commentRss/193940.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/193940.html>> test3=cat(3,test1,test2)
test3(:,:,1) =
     1     2
     3     4
test3(:,:,2) =
     5     6
     7     8

=======================================
>> sum(test3,1)   %对第一个维度求?/div>
ans(:,:,1) =
     4     6
ans(:,:,2) =
    12    14
>> sum(test3,2)  %对第二个l度求和
ans(:,:,1) =
     3
     7
ans(:,:,2) =
    11
    15

>> sum(test3,3)%相当于对W三个维度上求和
ans =
     6     8
    10    12
>> sum(test3(:))
ans =
    36


luis 2012-10-27 13:11 发表评论
]]>matlab 矩阵合ƈhttp://www.shnenglu.com/luyulaile/archive/2012/10/27/193939.htmlluisluisSat, 27 Oct 2012 04:31:00 GMThttp://www.shnenglu.com/luyulaile/archive/2012/10/27/193939.htmlhttp://www.shnenglu.com/luyulaile/comments/193939.htmlhttp://www.shnenglu.com/luyulaile/archive/2012/10/27/193939.html#Feedback0http://www.shnenglu.com/luyulaile/comments/commentRss/193939.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/193939.html>> test1=[1,2;3,4]
test1 =
     1     2
     3     4
>> test2=[5,6;7,8]
test2 =
     5     6
     7     8
>> test3=[test1,test2]
test3 =
     1     2     5     6
     3     4     7     8
>> test4=[test1;test2]
test4 =
     1     2
     3     4
     5     6
     7     8
===
对于l数相同的矩?/div>
cat(1,A,BQ相当于[A;B]
cat (2, A, B) 相当于[A,B]
cat (3, A, B) 相当于增加维?/div>
当AQB分别Zl矩阉|Q合q之后ؓ三维矩阵QA,BZl矩阵,则在W三l方向上合ƈA,B?/span>

>> cat(1,test1,test2)

ans =

     1     2
     3     4
     5     6
     7     8

>> cat(2,test1,test2)

ans =

     1     2     5     6
     3     4     7     8

>> cat(3,test1,test2)

ans(:,:,1) =

     1     2
     3     4


ans(:,:,2) =

     5     6
     7     8


luis 2012-10-27 12:31 发表评论
]]>强制latex 囄的插入位|?/title><link>http://www.shnenglu.com/luyulaile/archive/2012/10/12/193197.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Fri, 12 Oct 2012 01:25:00 GMT</pubDate><guid>http://www.shnenglu.com/luyulaile/archive/2012/10/12/193197.html</guid><wfw:comment>http://www.shnenglu.com/luyulaile/comments/193197.html</wfw:comment><comments>http://www.shnenglu.com/luyulaile/archive/2012/10/12/193197.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/luyulaile/comments/commentRss/193197.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/luyulaile/services/trackbacks/193197.html</trackback:ping><description><![CDATA[latex 囄l常多出?br /><br /><br />1U方? 忽略学<br />[!hb]<br /><br />2另一U方?br />H 插入当前位置<br /><div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all; "><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><br />\usepackage{float}<br /><br />\begin{figure}[H]<br />foo<br />\end{figure}</div><br />看图Q?img src ="http://www.shnenglu.com/luyulaile/aggbug/193197.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/luyulaile/" target="_blank">luis</a> 2012-10-12 09:25 <a href="http://www.shnenglu.com/luyulaile/archive/2012/10/12/193197.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Latex 常用命ohttp://www.shnenglu.com/luyulaile/archive/2012/10/12/193195.htmlluisluisThu, 11 Oct 2012 21:02:00 GMThttp://www.shnenglu.com/luyulaile/archive/2012/10/12/193195.htmlhttp://www.shnenglu.com/luyulaile/comments/193195.htmlhttp://www.shnenglu.com/luyulaile/archive/2012/10/12/193195.html#Feedback0http://www.shnenglu.com/luyulaile/comments/commentRss/193195.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/193195.html
\overline

^ _

\dfrac{}{}

\frac{}{}

\textbf

\sqrt 开根号

\tilde 斜线
\alpha \Alpha

\hat

\leq <=
\rightarrow ->
\geq >= greater equal
\begin{itemize}
\end{itemize}
\xi
\parell
求导?\delta 

关于title
\documentclass{book}
\title{TITLE}
\author{AUTHOR}
\begin{document}
\maketitle
\end{document}


关于表格

artice的文章结?br />title
 section
subsection
subsubsection

首行~进
\usepackage{indentfirst} 

===itemlize description enumerata的区?==

\begin{itemize}
    \item First level, itemize, first item
    \begin{itemize}
        \item Second level, itemize, first item
        \item Second level, itemize, second item
        \begin{enumerate}
            \item Third level, enumerate, first item
            \item Third level, enumerate, second item
        \end{enumerate}
    \end{itemize}
    \item First level, itemize, second item
\end{itemize}
==

 

主要是:


dQ?br />
   \begin{figure}[ht]
\centering
\includegraphics[width=0.8\textwidth,clip]{image/fig2.png}
\caption{}
\label{fig:11}
 \end{figure}

多个图:
\begin{figure}
  \centering
  \subfigure[Small Box with a Long Caption]{
    \label{fig:subfig:a} %% label for first subfigure
    \includegraphics[width=1.0in]{graphic.eps}}
  \hspace{1in}
  \subfigure[Big Box]{
    \label{fig:subfig:b} %% label for second subfigure
    \includegraphics[width=1.5in]{graphic.eps}}
  \caption{Two Subfigures}
  \label{fig:subfig} %% label for entire figure
\end{figure}


luis 2012-10-12 05:02 发表评论
]]>
Matlab 常用d公式http://www.shnenglu.com/luyulaile/archive/2012/10/12/193194.htmlluisluisThu, 11 Oct 2012 20:31:00 GMThttp://www.shnenglu.com/luyulaile/archive/2012/10/12/193194.htmlhttp://www.shnenglu.com/luyulaile/comments/193194.htmlhttp://www.shnenglu.com/luyulaile/archive/2012/10/12/193194.html#Feedback0http://www.shnenglu.com/luyulaile/comments/commentRss/193194.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/193194.html

http://www.mathworks.com/help/matlab/ref/plot.html 

例子Q?br />
q是丄单的例子个大Ӟ?≤x≤2p区间内,l制曲线y1=2e-0.5x和y2=cos(4πx)Qƈl图形添加图形标注?nbsp;
x=0:pi/100:2*pi;
y1=2*exp(-0.5*x);
y2=cos(4*pi*x);
plot(x,y1,x,y2)
title('x from 0 to 2{\pi}');                %加图形标?nbsp;   
xlabel('Variable X');                       %加X轴说?nbsp;         
ylabel('Variable Y');                       %加Y轴说?nbsp;
text(0.8,1.5,'曲线y1=2e^{-0.5x}');          %在指定位|添加图形说?nbsp;
text(2.5,1.1,'曲线y2=cos(4{\pi}x)'); 
legend('y1','y2')                           %加图?nbsp;
复制代码
 

plot

2-D line plot

Syntax

plot(Y)
plot(X1,Y1,...,Xn,Yn)
plot(X1,Y1,LineSpec,...,Xn,Yn,LineSpec)
plot(...,'PropertyName',PropertyValue,...)
plot(axes_handle,...)
h = plot(...)


   1、设|图U宽?/strong>   set( haxis, 'LineWidth', 1.0 ); ----q是 set函数Q?'LineWidth'是axis的线宽度属性,其值默认ؓ0.5Q这里可以改?.0了?/span>

2、调整坐标u上下?br />set( haxis, 'XLim', [ 2 20 ] );  set( haxis, 'YLim', [ 2 20 ] );---调整坐标轴上下限的。Z_那同理set( haxis, 'ZLim', [ Zmin, %% Zmax ] )
     3、调整坐标u上的标注数字
set( haxis, 'XTick', 2:1:20 );  set( haxis, 'YTick', 2:1:20 );----是调整坐标u上那些标注出来的数字了,2:1:20意思是?开始,每隔1标注一ơ,直到20为止。注意这里的2, 20最好和上面相应的XLim, YLim最大最g致?/tt>

4、MATLAB中提供的U型及颜色属性:

如:plot(x1,y1,'r-'),表示Q用U色实线d囑Ş

 

 

U型

说明

标记W?/p>

说明

颜色

说明

-

实线(默认)

+

加号W?/p>

r

U色

--

双划U?/p>

o

I心?/p>

g

l色

:

虚线

*

星号

b

蓝色

:.

点划U?/p>

.

实心?/p>

c

青绿?/p>

 

 

x

叉号W?/p>

m

z红?/p>

 

 

s

正方?/p>

y

黄色

 

 

d

菱Ş

k

黑色

 

 

^

上三角Ş

w

白色

 

 

v

下三角Ş

 

 

 

 

右三角Ş

 

 

 

 

左三角Ş

 

 

 

 

p

五角?/p>

 

 

 

 

h

六边?/p>

 

 

5、图形标题、u标注、图形说明的讄

囑֐标注可用Qtitle('xx关系?)
axis([0,22,0,3]);---昄范围为:X轴从0-22Q?Y轴从0-3昄?br />xlabel('电压QVQ?)Qylabel('甉|QAQ?) 分别表示在X轴下标示 电压QVQ,Y轴旁标示“甉|QAQ?#8221;

legend('A曲线 ','B曲线','C曲线')  用于说明图中的曲U的说明Q顺序和plot(x1,y1,x2,y2,x3,y3)的曲U???相同卛_?/tt>

 

set(h,'LineWidth',1.5)%讄囄_细

%set(gca,'XTickLabel',{'-4/T','-3/T','-2/T','-1/T','0','1/T','2/T','3/T','4/T',})




scatter

Scatter plot

Syntax

scatter(X,Y,S,C)
scatter(X,Y)
scatter(X,Y,S)
scatter(...,markertype)
scatter(...,'filled')
scatter(...,'PropertyName',propertyvalue)
scatter(axes_handle,...)
h = scatter(...)

 

 



luis 2012-10-12 04:31 发表评论
]]>Matlab 常用function W记http://www.shnenglu.com/luyulaile/archive/2012/10/11/193145.htmlluisluisThu, 11 Oct 2012 00:28:00 GMThttp://www.shnenglu.com/luyulaile/archive/2012/10/11/193145.htmlhttp://www.shnenglu.com/luyulaile/comments/193145.htmlhttp://www.shnenglu.com/luyulaile/archive/2012/10/11/193145.html#Feedback0http://www.shnenglu.com/luyulaile/comments/commentRss/193145.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/193145.htmleye(1) [1]  eye(2) 2*2的单位矩?br />ones(n),  n*n的矩?br />ones(n,m) 或?ones([n,m]) n*m全是1的矩?br />zeros(n) zeros([n,m])  全是0的矩?br />
reshape() 数据一列一列重新分?br />例如Q?br />
 

Reshape a 3-by-4 matrix into a 2-by-6 matrix.

A =     1    4    7    10
2 5 8 11
3 6 9 12

B = reshape(A,2,6)
B = 1 3 5 7 9 11
2 4 6 8 10 12
B = reshape(A,2,[])
B =     1    3    5    7    9   11     
2 4 6 8 10 12


A=rand(3,3);
B=A';%转置
C=inv(B);%求?/span>
D=rank(A);%求矩늚|?/span>
[V E]=eig(A);%求矩늚特征向量V和特征值D 
如果不是斚wQ可以用pinv求伪?/span> 

圆括L作用Q用于取|引用数组中的元素Q?br />
>> A =[1    4    7    10
    2    5    8    11
    3    6    9    12]
A =
     1     4     7    10
     2     5     8    11
     3     6     9    12
A(3)=3
A(10)=10
A(2,3)=5
注意不是Q而是逗号,
A(2,:)=L有的W二?2 5 8 11



ҎL作用Q?br />
Matlab Ҏ?#8220;[ ]”的作?br /> 1定义矩阵Q向量,数组Q?br />                例如 a=[1 2 3;4 5 6] 
2.定义函数的返回参数列表(输出变量宗量Q?br /> 例如 [m,n]=size(a) 如果函数的返回参数只有一个,中括号一般省略。即 [n]=rand(1,2); 可写? n=rand(1,2);


大括L作用{ }
大括P用于cell型的数组的分配或引用?br />比如
 A(2,1) = {[1 2 3; 4 5 6]}, or A{2,2} = ('str') 

分号Q的作用Q?br />

cell?数据cd

如果pZ个数Q那么h(1)=p,是没有问题的?/p>

如果pZ个向量,那么h(1,:)=p是没有问题的?/p>

如果p是一个矩늚话,上面的两U赋值方法都是会有错误的?/p>

那么要如何处理呢Q?/p>

q时qCcell数据cd了。cell的每个单元都可以存储M数据Q比如传递函数等。当Ӟ存储矩阵更是没有问题的了。但是用cell数据cd之前Q要先初始化?/p>

a=cell(n,m)

那么把a初始化ؓ一个n行m列的Icellcd数据?/p>

如何赋值呢Q?/p>

a{1,1}=rand(5)

那么a??列的单元中存储的是一个随机的5×5的方阵了?/p>

那么要用W一个单元中的方阵中的某个值呢Q?/p>

可以如下引用Qa{1,1}(2,3)

可以了Q引用cell单元时要用{},再引用矩늚某个数据p?)了?/p>

cell单元中的每个单元都是独立的,可以分别存储不同大小的矩阉|不同cd的数据?/p>



luis 2012-10-11 08:28 发表评论
]]>
Python I数l?/title><link>http://www.shnenglu.com/luyulaile/archive/2012/09/19/191202.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Wed, 19 Sep 2012 01:47:00 GMT</pubDate><guid>http://www.shnenglu.com/luyulaile/archive/2012/09/19/191202.html</guid><wfw:comment>http://www.shnenglu.com/luyulaile/comments/191202.html</wfw:comment><comments>http://www.shnenglu.com/luyulaile/archive/2012/09/19/191202.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/luyulaile/comments/commentRss/191202.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/luyulaile/services/trackbacks/191202.html</trackback:ping><description><![CDATA[<div>Python array 用法   <br />直接 result=[]</div><div>    for x in range(0,N):</div><div>        temp=beta(b,n)</div><div>        print temp</div><div>        if temp >= n:</div><div>            result.append("Yes")  #直接append</div><div>        else:</div><div>            result.append("No") #直接append</div><div>    return result</div><img src ="http://www.shnenglu.com/luyulaile/aggbug/191202.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/luyulaile/" target="_blank">luis</a> 2012-09-19 09:47 <a href="http://www.shnenglu.com/luyulaile/archive/2012/09/19/191202.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>PythonW记http://www.shnenglu.com/luyulaile/archive/2012/09/09/190021.htmlluisluisSun, 09 Sep 2012 06:47:00 GMThttp://www.shnenglu.com/luyulaile/archive/2012/09/09/190021.htmlhttp://www.shnenglu.com/luyulaile/comments/190021.htmlhttp://www.shnenglu.com/luyulaile/archive/2012/09/09/190021.html#Feedback0http://www.shnenglu.com/luyulaile/comments/commentRss/190021.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/190021.htmlTutorial Q?/span> http://www.tutorialspoint.com/python/python_files_io.htm 

Python IO
输出 print
str = raw_input("Enter your input: "); print "Received input is : ", str


Python只有三种变量cd int, string, float? 
typeof(1.5)
貌似不支持隐式类型{?br />print str(2.5)  ?br />print 2.5 ?br />print '2.5' ?br />
python 定义Ҏ?br />def MethodName(para,para2): #注意q里的冒?br />      if 

python注释
#单行注释
"""  三个双引h多行注释 """

python 引用
include math


Python的str
str(var)cd转换
len(var)
var.upper()
var.lower()
var[2] W三个(注意下标?开始)元素Q类glist
var[:3] 前三个元素,实际上指的是0截止?-1的元?br />var[2:4]下标??-1的所有元?br />
Python的list
exampe=[a,b,c,d,e,f];
len(exampe)
自带sortҎ

Python的dictionary
key -value对应
value可以是一个list
注意Ҏ号[]里面只能使用key
区分 del dict['Name']


del dict['Name']; # remove entry with key 'Name' dict.clear();     # remove all entries in dict del dict ;        # delete entire dictionary
自带的方法:

1cmp(dict1, dict2)
Compares elements of both dict.
2len(dict)
Gives the total length of the dictionary. This would be equal to the number of items in the dictionary.
3str(dict)
Produces a printable string representation of a dictionary
4type(variable)
Returns the type of the passed variable. If passed variable is dictionary then it would return a dictionary type.




Pythoncȝ定义和类Ҏ的定?br />定义cM需要用def class,直接

class ClassName(object):
每个c都?__init__(self,arg):
ҎQ注意是 左右各两个下划线Qd4根下划线
 
cL法都需要包含selfq个参数Q但是用的时候不需要self,见下?br />                  
例如
class Adder(object):
def __init__(self):
self.baseNum = 2
def prnt_num(self):
print self.baseNum
def add_to_base(self, arg):
# Your code here
self.baseNum+=arg
print self.baseNum
objectVar = Adder()
objectVar.prnt_num()
# Your code here
objectVar.add_to_base(3)

Python中的cd量不?self.xxx来引用,但是成员变量可以
Class variables are special because they belong to the 
class; the objects created do not get their own copies of the class variable. Class variables are accessed using the class name and dot notation.
ClassName.classVar
Class variables are created outside of__init__ 
例如Q?br />
class Widget(object):
objID = 0
def __init__(self):
Widget.objID += 1
# Your code here
self.myID=Widget.objID

常犯错误Qindentation is very important  
python indentation error expected an indented block
q有一个错误就?cL法,必须使用 self参数Q即使没有参敎ͼQ?/span>
另外一个常错的地方是 __init__(self,arg) 一定是四根下划U?/span>



不仅要记得留dent q要记得 ~进








luis 2012-09-09 14:47 发表评论
]]>
Latex 大括L?/title><link>http://www.shnenglu.com/luyulaile/archive/2012/08/28/188512.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Tue, 28 Aug 2012 03:35:00 GMT</pubDate><guid>http://www.shnenglu.com/luyulaile/archive/2012/08/28/188512.html</guid><wfw:comment>http://www.shnenglu.com/luyulaile/comments/188512.html</wfw:comment><comments>http://www.shnenglu.com/luyulaile/archive/2012/08/28/188512.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/luyulaile/comments/commentRss/188512.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/luyulaile/services/trackbacks/188512.html</trackback:ping><description><![CDATA[原地址Q?a >http://blog.sina.com.cn/s/blog_5e16f1770100gzud.html</a> <br /><img src="http://www.shnenglu.com/images/cppblog_com/luyulaile/690.jpg" width="299" height="332" alt="" /><br /><br /><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: #323e32; font-family: simsun; background-color: #9caec1; ">演示代码Q?/p><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: #323e32; font-family: simsun; background-color: #9caec1; ">\documentclass{article}<br />\setlength\textwidth{245.0pt}<br />\usepackage{CJK}<br />\usepackage{indentfirst}<br />\usepackage{amsmath}</p><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: #323e32; font-family: simsun; background-color: #9caec1; ">\begin{CJK*}{GBK}{song}<br />\begin{document}<br />Ҏ一Q?/p><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: #323e32; font-family: simsun; background-color: #9caec1; ">$$ f(x)=\left\{<br />\begin{aligned}<br />x & = & \cos(t) \\<br />y & = & \sin(t) \\<br />z & = & \frac xy<br />\end{aligned}<br />\right.<br />$$</p><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: #323e32; font-family: simsun; background-color: #9caec1; "><br />Ҏ二:</p><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: #323e32; font-family: simsun; background-color: #9caec1; ">$$ F^{HLLC}=\left\{<br />\begin{array}{rcl}<br />F_L <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> & <wbr> <wbr> <wbr> <wbr> <wbr> & {0 <wbr> <wbr> <wbr> <wbr> <wbr> < <wbr> <wbr> <wbr> <wbr> <wbr> S_L}\\<br />F^*_L <wbr> <wbr> <wbr> <wbr> & <wbr> <wbr> <wbr> <wbr> <wbr> & {S_L \leq 0 < S_M}\\<br />F^*_R <wbr> <wbr> <wbr> <wbr> & <wbr> <wbr> <wbr> <wbr> <wbr> & {S_M \leq 0 < S_R}\\<br />F_R <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> & <wbr> <wbr> <wbr> <wbr> <wbr> & {S_R \leq 0}<br />\end{array} \right. $$</p><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: #323e32; font-family: simsun; background-color: #9caec1; ">Ҏ?</p><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: #323e32; font-family: simsun; background-color: #9caec1; ">$$f(x)=<br />\begin{cases}<br />0& \text{x=0}\\<br />1& \text{x!=0}<br />\end{cases}$$</p><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: #323e32; font-family: simsun; background-color: #9caec1; ">\end{CJK*}<br />\end{document}</p><br />可以用\text{} 注释文字<img src ="http://www.shnenglu.com/luyulaile/aggbug/188512.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/luyulaile/" target="_blank">luis</a> 2012-08-28 11:35 <a href="http://www.shnenglu.com/luyulaile/archive/2012/08/28/188512.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Dijkstra(q杰斯特?法http://www.shnenglu.com/luyulaile/archive/2012/06/16/179006.htmlluisluisFri, 15 Jun 2012 19:53:00 GMThttp://www.shnenglu.com/luyulaile/archive/2012/06/16/179006.htmlhttp://www.shnenglu.com/luyulaile/comments/179006.htmlhttp://www.shnenglu.com/luyulaile/archive/2012/06/16/179006.html#Feedback0http://www.shnenglu.com/luyulaile/comments/commentRss/179006.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/179006.html Dijkstra(q杰斯特?法是典型的单源最短\径算法,用于计算一个节点到其他所有节点的最短\径。主要特Ҏ以v始点Z心向外层层扩展,直到扩展到终点ؓ止。Dijkstra法是很有代表性的最短\径算法,在很多专业课E中都作为基本内Ҏ详细的介l,如数据结构,图论Q运{学{等。Dijkstra一般的表述通常有两U方式,一U用怹和时标h式,一U是用OPEN, CLOSE表的方式Q这里均采用怹和时标L方式。注意该法要求图中不存在负权边?/span>

问题描述

  在无向图 G=(V,E) 中,假设每条?E[i] 的长度ؓ w[i]Q找到由点 V0 到其余各点的最短\径。(单源最短\?/a>Q?/span> 


 
q杰斯特?/a>(Dijkstra)法思想
  
按\径长度递增ơ序产生最短\径算法:
  把V分成两组Q?/span>
  Q?QSQ已求出最短\径的点的集?/span>
  Q?QV-S=TQ尚未确定最短\径的点集合
  T中顶Ҏ最短\径递增的次序加入到S中,
  保证Q(1Q从源点V0到S中各点的最短\径长度都不大?/span>
  从V0到T中Q何顶点的最短\径长?/span>
  Q?Q每个顶点对应一个距d?/span>
  S中顶点:从V0到此点的最短\径长?/span>
  T中顶点:从V0到此点的只包括S中顶点作中间
  点的最短\径长?/span>
  依据Q可以证明V0到T中顶点Vk的最短\径,或是从V0到Vk?/span>
  直接路径的权|或是从V0lS中顶点到Vk的\径权g?/span>
  Q反证法可证Q?/span>
  求最短\径步?/em>
  法步骤如下Q?/span>
  1. 初时o S={V0},T={其余点}QT中顶点对应的距离?/span>
  若存?lt;V0,Vi>Qd(V0,Vi)?lt;V0,Vi>弧上的权?/span>
  若不存在<V0,Vi>Qd(V0,Vi)?#8733;
  2. 从T中选取一个其距离gؓ最的点W且不在S中,加入S
  3. 对T中顶点的距离D行修改:若加qW作中间顶点,从V0到Vi?/span>
  距离值比不加W的\径要短,则修Ҏ距离?/span>
  重复上述步骤2?Q直到S中包含所有顶点,即S=T为止 

代码Q?源地址Q?span style="color: #008000; font-size: 13px; background-color: #eeeeee; ">www.cnblogs.com/newwy
 

/*********************************
*   最短\?--Dijkstra法实现 
*      HDUQ?544 
*   BLOG:www.cnblogs.com/newwy
*   AUTHOR:Wang Yong
*********************************
*/
#include <iostream>
#define MAX 100
#define INF 1000000000
using namespace std;
 int dijkstra (int mat[][MAX],int n, int s,int f)
 {
     int dis[MAX];
     int mark[MAX];//记录被选中的结?nbsp;
     int i,j,k = 0;
     for(i = 0 ; i < n ; i++)//初始化所有结点,每个l点都没有被选中 
         mark[i] = 0;
    for(i = 0 ; i < n ; i++)//每个结点到startl点weight记录为当前distance 
    {
        dis[i] = mat[s][i];
        //path[i] = s;
    }
    mark[s] = 1;//startl点被选中 
    
//path[s] = 0;
    dis[s] = 0;//startl点的的距离讄? 
    int min ;//讄最短的距离?nbsp;
    for(i = 1 ; i < n; i++)
    {
        min = INF;
        for(j = 0 ; j < n;j++)
        {
            if(mark[j] == 0  && dis[j] < min)//未被选中的结点中Q距L短的被选中 
            {
                min = dis[j] ;
                k = j;
            }
        }
        mark[k] = 1;//标记选中 
        for(j = 0 ; j < n ; j++)
        {
            if( mark[j] == 0  && (dis[j] > (dis[k] + mat[k][j])))//修改剩余l点的最短距?nbsp;
            {
                dis[j] = dis[k] + mat[k][j];
            }
        }
    }
    return dis[f];    
 } 
 int mat[MAX][MAX];
int main()
{
    int n,m;
    while(scanf("%d %d",&n,&m))
    {
        int a,b,dis;
        if(n == 0 || m == 0)
            break;
        int i,j;
        for(i = 0 ; i < n;i++)
            for(j = 0 ; j < n; j++)
                mat[i][j] = INF;
        for(i = 0 ; i < m ;i++)
        {
            scanf("%d %d %d",&a,&b,&dis);
            --a,--b;
            if(dis < mat[a][b] || dis < mat[b][a])
            mat[a][b] = mat[b][a] = dis;
        }
        int ans = dijkstra(mat,n,0,n-1);
        printf("%d\n",ans);
    }
 
}

可用 优先队列优化


其他解释Q?br />
http://blog.csdn.net/jiahui524/article/details/6636913 

luis 2012-06-16 03:53 发表评论
]]>
ձƷþ| ŷ޹Ʒþø| ˾þô߽avӰԺ| ŷպþþƷ| þۺɫHEZYO| þۺϾƷ| þѸƵ| ޾Ʒ97þĻ| þþƷAvӰƬ | þƵ| þþƷ77777| Ʒ99þþþ | 77777ҹþö| þAV| 91þþƷ91þɫ| ƷѾþ| vaĻþ| þøһëƬ| ҰĻþ| ޾Ʒtvþþþ| պŷþþwwwۺ| þҹɫƷ| þþƷһպ| ɫۺϾþþþ| һŮȫƾþƬ | žžþþƷר| þþþþҹƷƷ| Ůþþþþ| þþþֻоƷ| þ99Ƶ| Ʒþþ| ľþþƷww16| ˾þۺӰԺ| þۺɫ֮þۺ| ƷþþĻ| þù׾Ʒǿ| 99reþþƷҳ2020| ˾þþƷһ | ھƷþ| þþþþþ97| 77777ҹþö|