10 2011 档案

摘要:解决这一问题的有效的方法是使用嵌套乘法也叫做Horner方法,这样计算该多项式仅用了4次乘法和4次加分。通常一个d次多项式能够d次乘法和d次加法进行计算。matlab程序如下:%Program 0.1 Nested multiplication%Evaluates polynomial from nested form using Horner's method%Input: degree d of polynomial,% array of d+1 coefficients (constant term first),% x-coordinate x at which... 阅读全文
posted @ 2011-10-29 15:38 lxgeek 阅读(312) 评论(0) 推荐(0) 编辑
摘要:getattr函数,可以得到一个直到运行时才知道名称的函数的应用。>>> li = [ "Larry", "Curly" ]>>> li.pop<built-in method pop of list object at 0xb76b364c>>>> getattr( li, "pop" )<built-in method pop of list object at 0xb76b364c>>>> getattr( li, "app 阅读全文
posted @ 2011-10-29 12:42 lxgeek 阅读(1454) 评论(0) 推荐(0) 编辑
摘要:#include <stdio.h>#include <stdlib.h>voidhello( a, b )int a ;int b ;{ a = 5; b = 6; printf( "a is %d \n b is %d\n", a, b );}intmain(){ hello(); exit( 0 );} 阅读全文
posted @ 2011-10-26 19:17 lxgeek 阅读(228) 评论(0) 推荐(0) 编辑
摘要:贝叶斯学习算法应用于机器学习的有两个原因,第一:贝叶斯学习能够计算显式的假设概率,如朴素贝叶斯分类器。第二:贝叶斯方法为理解机器学习的其他方法提供了手段,如分析FIND-S算法。 贝叶斯法则对与贝叶斯学习至关重要,其形式如下: 贝叶斯法则提供了一种计算假设概率的方法,它基于假设的先验概率、给定假设下观察到不同数据的概率以及观察到的数据本身。其中P(H)用来代表在没有训练数据前假设H拥有的初始概率,因此其通常被称为先验概率(prior probability),它反映了我们所拥有的关于假设H是一正确假设的机会的背景知识。如果没有这一先验知识,那么我们可以简单地将每一候选假设赋予相同的先验... 阅读全文
posted @ 2011-10-26 11:44 lxgeek 阅读(2533) 评论(0) 推荐(0) 编辑
摘要:实现《机器学习》19页的FIND-S算法。验证不同的实例顺序开始于非最特殊假设。#__author__=lx#__date__=2011.10.18#__brief__=FIND-S, from 'machine learning' 19def find_s(): x1 = [ 'sunny', 'warm', 'nurmal', 'strong', 'warm', 'same' , 1 ] x2 = [ 'sunny', 'warm', 'h 阅读全文
posted @ 2011-10-18 16:09 lxgeek 阅读(3361) 评论(0) 推荐(0) 编辑
摘要:/* * author:lx * date: 2011-10-04 * brief: strcpy */#include <stdio.h>#include <stdlib.h>#include <assert.h>void*lx_strcpy( char *p, char *q ){ char *address = q; for ( ; *p != '\0'; p++ ) { assert( *q != '\0' ); *q = *p; ... 阅读全文
posted @ 2011-10-04 14:50 lxgeek 阅读(221) 评论(0) 推荐(0) 编辑
摘要:/* * author:lx * date:2011-10-04 * brief: convent int to string */#include <stdio.h>#include <stdlib.h>voidcon_string( int a ){ int m = 10; char p[6]; int c = 1; char *q = p; while ( a != 0 ) { c = a % m; a = a / ... 阅读全文
posted @ 2011-10-04 14:34 lxgeek 阅读(201) 评论(0) 推荐(0) 编辑
摘要:#__author__=lx#__date__=2011-10-03#__brief__=DFStime = 0d = []f = []color = []p = []def DFS_VISIT( G, i ): color[ i ] = 'gray' global time time += 1 d[i] = time print i+1 for v in G[i]: if color[v-1] == 'white': p[v-1] =... 阅读全文
posted @ 2011-10-03 20:21 lxgeek 阅读(235) 评论(0) 推荐(0) 编辑
摘要:#__author__=lx#__date__=2011-10-03#__brief__=BFSfrom collections import dequedef BFS( G, s ): d = [] color = [] p = [] L = deque() for i in range( len( G ) ): if i != s: color.append( 'white' ) d.append( ... 阅读全文
posted @ 2011-10-03 19:52 lxgeek 阅读(351) 评论(0) 推荐(0) 编辑