cdf 累积分布函数
分位数图是将x轴与y轴互换的cdf图
概率图的目的是判断一个给定的数据集是否来自一个特定的已知分布。例如,很多统计技术都假设误差或残差服从高斯分布,概率图可用于验证该假设是否成立。
秩序图
帕累托图

箱形图
>(defun describe-paths (location edges)
(apply #'append (mapcar #'describe-path (cdr (assoc location edges)))))
> (find 'y '((5 x) (3 y) (7 z)) :key #'cadr)
(3 Y)
>(defun tweak-text (lst caps lit)
(when lst
(let ((item (car lst))
(rest (cdr lst)))
(cond ((eql item #\space) (cons item (tweak-text rest caps lit)))
((member item '(#\! #\? #\.)) (cons item (tweak-text rest t lit)))
((eql item #\") (cons item (tweak-text rest caps (not lit))))
(lit (cons item (tweak-text rest nil lit)))
(caps (cons (char-upcase item) (tweak-text rest nil lit)))
(t (cons (char-downcase item) (tweak-text rest nil nil)))))))
> (tweak-text '(#\a #\Space #\b) 't 'nil)
(tweak-text '(#\a #\Space #\b) 't 'nil)
> (defun game-print (lst)
(princ (coerce (tweak-text (coerce (string-trim "() "
(prin1-to-string lst))
'list)
t
nil)
'string))
(fresh-line))
> (game-print '(i am a. test "c aNnd d" b))
I am a. Test "c aNnd d" b
> (mapcar (lambda (n) (/ n 2)) '(2 4 6))
(1 2 3)
> (defparameter foo '(1 2 3))把exp中非字母数字类的字符都转换成_
FOO
> (setf (cdddr foo) foo)
#1=(1 2 3 . #1#)
(defun dot-name (exp)
(substitute-if #\_ (complement #'alphanumericp) (prin1-to-string exp)))
(concatenate 'string (subseq s 0 (- *max-label-length* 3)) "...")
(defun edges->dot (edges)调用thunk函数,输出的结果写入fname文件,再执行指定shell命令画图
(mapc (lambda (node)
(mapc (lambda (edge)
(fresh-line)
(princ (dot-name (car node)))
(princ "->")
(princ (dot-name (car edge)))
(princ "[label=\"")
(princ (dot-label (cdr edge)))
(princ "\"];"))
(cdr node)))
edges))
(defun dot->png (fname thunk)
(with-open-file (*standard-output*
fname
:direction :output :if-exists :supersede)
(funcall thunk))
(ext:shell (concatenate 'string "dot -Tpng -O " fname)))
(defparameter *wizard-edges* '((living-room (garden west door)
(attic upstairs ladder))
(garden (living-room east door))
(attic (living-room downstairs ladder))))
(defun uedges->dot (edges)
(maplist (lambda (lst)
(mapc (lambda (edge)
(unless (assoc (car edge) (cdr lst))
(fresh-line)
(princ (dot-name (caar lst)))
(princ "--")
(princ (dot-name (car edge)))
(princ "[label=\"")
(princ (dot-label (cdr edge)))
(princ "\"];")))
(cdar lst)))
edges))
(loop repeat 10
collect 1)
(loop for n from 1 to 10
collect n)
(defun get-connected (node edge-list)
(let ((visited nil))
(labels ((traverse (node)
(unless (member node visited)
(push node visited)
(mapc (lambda (edge)
(traverse (cdr edge)))
(direct-edges node edge-list)))))
(traverse node))
visited))
(defun find-islands (nodes edge-list)
(let ((islands nil))
(labels ((find-island (nodes)
(let* ((connected (get-connected (car nodes) edge-list))
(unconnected (set-difference nodes connected)))
(push connected islands)
(when unconnected
(find-island unconnected)))))
(find-island nodes))
islands))
(defun edges-to-alist (edge-list)
(mapcar (lambda (node1)
(cons node1
(mapcar (lambda (edge)
(list (cdr edge)))
(remove-duplicates (direct-edges node1 edge-list)
:test #'equal))))
(remove-duplicates (mapcar #'car edge-list))))
(defun add-cops (edge-alist edges-with-cops)
(mapcar (lambda (x)
(let ((node1 (car x))
(node1-edges (cdr x)))
(cons node1
` (mapcar (lambda (edge)
(let ((node2 (car edge)))
(if (intersection (edge-pair node1 node2)
edges-with-cops
:test #'equal)
(list node2 'cops)
edge)))
node1-edges))))
edge-alist))
(some #'cdr (cdr (assoc n edge-alist)))mapcan 将map之后的结果都合并成一个列表
> (defun ingredients (order)
(mapcan (lambda (burger)
(case burger
(single '(patty))
(double '(patty patty))
(double-cheese '(patty patty cheese))))
order))
INGREDIENTS
> (ingredients '(single double-cheese double))
'(PATTY PATTY PATTY CHEESE PATTY PATTY)
> (defparameter x (make-array 3))
#(NIL NIL NIL)
> (setf (aref x 1) 'foo)
FOO
> x
#(NIL FOO NIL)
> (aref x 1)
FOO
> (setf foo '(a b c))
(A B C)
> (second foo)
B
> (setf (second foo) 'z)
Z
> foo
(A Z C)
> foo
#(NIL NIL (X Y Z) NIL)
> (setf (car (aref foo 2)) (make-hash-table))
#S(HASH-TABLE)
> (setf (gethash 'zoink (car (aref foo 2))) 5)
5
> foo
#(NIL NIL (#S(HASH-TABLE (ZOINK . 5)) Y Z) NIL)
> (nth 1 '(foo bar baz))
BAR
> (defun foo ()
(values 3 7))
FOO
> (foo)
3 ;
7
> (+ (foo) 5)
8
> (multiple-value-bind (a b) (foo)
(* a b))
21
(defun hash-edges (edge-list)
(let ((tab (make-hash-table)))
(mapc (lambda (x)
(let ((node (car x)))
(push (cdr x) (gethash node tab))))
edge-list)
tab))
> (defstruct person
name
age
waist-size
favorite-color)
PERSON
> (defparameter *bob* (make-person :name "Bob"
:age 35
:waist-size 32
:favorite-color "blue"))
*BOB*
> (person-age *bob*)
35
> (setf (person-age *bob*) 36)
36
> (defparameter *that-guy* #S(person :name "Bob" :age 35 :waist-size 32 :favorite-color "blue"))
> (find-if #'numberp '(a b 5 d))求和
5
> (count #\s "mississippi")
4
> (position #\4 "2kewl4skewl")
5
> (some #'numberp '(a b 5 d))
T
> (every #'numberp '(a b 5 d))
NIL
> (reduce #'+ '(3 4 6 5 2))
20
> (reduce (lambda (best item)
(if (and (evenp item) (> item best))
item
best))
'(7 4 6 5 2)
:initial-value 0)
6
(make-array 5 :initial-contents '(1 2 3 4 5))
> (map 'list
(lambda (x)
(if (eq x #\s)
#\S
x))
"this is a string")
(#\t #\h #\i #\S #\ #\i #\S #\ #\a #\ #\S #\t #\r #\i #\n #\g)
> (subseq "america" 2 6)排序
"eric"
> (sort '(5 8 2 4 9 3 6) #'<)
(2 3 4 5 6 8 9)
> (defun add (a b)
(cond ((and (numberp a) (numberp b)) (+ a b))
((and (listp a) (listp b)) (append a b))))
ADD
> (add 3 4)
7
> (add '(a b) '(c d))
(A B C D)
> (defmethod add ((a number) (b number))
(+ a b))
ADD
> (defmethod add ((a list) (b list))
(append a b))
ADD
chap 11
> (format t "Add onion rings for only ~$ dollars more!" 1.5)~s会保留",而~a会去掉分隔符
Add onion rings for only 1.50 dollars more!
NIL
> (format t "I am printing ~s in the middle of this sentence." "foo")
I am printing "foo" in the middle of this sentence.
> (format t "I am printing ~a in the middle of this sentence." "foo")
I am printing foo in the middle of this sentence.
> (format t "I am printing ~10a within ten spaces of room." "foo")
I am printing foo within ten spaces of room.
> (format t "I am printing ~10@a within ten spaces of room." "foo")
I am printing foo within ten spaces of room.
> (format t "~{I see a ~a... or was it a ~a?~%~}" *animals*)
> (progn (format t "this is on one line ~%")此外还有数值处理,居中、两端对齐等等,用的时候再翻书
(format t "~%this is on another line"))
this is on one line
this is on another line
> (progn (format t "this is on one line ~&")
(format t "~&this is on another line"))
this is on one line
this is on another line
> (with-open-file (my-stream "data.txt" :direction :output)
(print "my data" my-stream))
> (with-open-file (my-stream "data.txt" :direction :input)
(read my-stream))
"my data"
> (defparameter foo (make-string-output-stream))
> (princ "This will go into foo. " foo)
> (princ "This will also go into foo. " foo)
> (get-output-stream-string foo)
"This will go into foo. This will also go into foo. "
> (defparameter my-socket (socket-server 4321)) ;ON THE SERVER
MY-SOCKET
> (defparameter my-stream (socket-accept my-socket)) ;ON THE SERVER
> (defparameter my-stream (socket-connect 4321 "127.0.0.1")) ;ON THE CLIENT
MY-STREAM
> (print "Yo Server!" my-stream) ;ON THE CLIENT
"Yo Server!"
> (read my-stream) ;ON THE SERVER
"Yo Server!"
> (close my-stream)
T
;This function is finally safe to use其中,gensym是为了避免调用的时候也有变量名为g,导致冲突出错
(defmacro split (val yes no)
(let1 g (gensym)
`(let1 ,g ,val
(if ,g
(let ((head (car ,g))
(tail (cdr ,g)))
,yes)
,no))))
hiinc = state.x[ , 'income' ] > median(state.x[ , 'income' ])
stateinc = table(state.region , hinnc)
#f_stateinc 共三列:state.region, hinnc, freq(频数)
f_stateinc = as.data.frame(stateinc)
as.data.frame( table(x) )
tt = table(infert$edu, infert$partity)
addmargins(tt,c(1,2))
sumfun = function(x) c(n=sum(!is.na(x)), mean = mean(x), sd=sd(x))
x = apply(somedata, 2, sumfun)
maxes = apply(somedata,2,max)
final = sweep(somedata,2,maxes,"/")
cweights = aggregate(data$weight,data[c('time','diet')], mean)
cweights = tapply(data$weight, data[c('time', 'diet')], mean)
或
mclick = melt(somedata, measure.var = 'weight')
cast(mclick, diet + time ~ variable, mean)
cast(somedata,region~variable,mean)
cast(somedata,variable~region,mean)
cast(somedata, region~variable, mean, subset=variable %in% c('population', 'life'))
cast(somedata, variable~., c(mean,median,sd))
cast(somedata, region~variable, c(mean,median,sd))
有道理。我一直认为,一个人想要在自己的领域做到世界一流,他的周围必须有非常多的一流人物。
确实。真正做好一件事没有捷径,需要一万小时的专业训练和努力。
试问今日之中国,有多少码农想着做几年技术转管理?早在AT&T,他旧对搜索问题的各个西街进行了仔细的研究,他的那些简单而有效的解决方案,常常是深思熟虑去伪存真的结果。其次,辛格坚持每天要分析一些搜索结果不好的例子,以掌握第一手资料,即使在他成为Google Fellow以后,依旧如此。
用"凑"的方法来解决问题,在中国尤其如此。这样的做法说得不好听,就是山寨。
上了市、有了钱甚至利润成为了在世界上也数得上的公司,做事情依然如此,就让人觉得境界低。
指定某个列默认值建表: test_column varchar(100) NOT NULL DEFAULT ‘’
_ 指定单个任意字符查询:select * from test_table where test_column like ‘_ttt’;
坚持到200页,实在撑不住了,图太多,看的眼花,放弃了。
Storable模块:nfreeze比freeze慢,但是保证可跨系统使用
Fcntl的flock
DB_FILE可以有三种存储形式 HASH、B树、RECNO(文本)
MLDBM 支持将复杂的数据结构写入文件
DBI的PrinterError对应warn,RaiseError对应die
错误消息:$DBI::errstr
quote函数自动转义引号
trace函数指定输出DB操作详情,debug用
dump_results打印执行结果,指定写入文件
bind_param_inout指定输出的参数写入到什么变量
bind_col
$sth->{NUM_OF_FIELDS}返回的列数
$sth->{NAME}->[$i-1] 第i列的名字
AutoCommit如果设为0,在执行一系列操作后,$dbh->commit(); if($@) { $dbh->rollback(); },较稳妥。
ODBC标准化了错误码,支持更多函数操作
DBI PROXY : 转发client的query给db,把db返回的结果转给client,这样中转一下,unix机器就能访问windows access的数据库
连接字符串: concat
条件逻辑: select col_a, case when col_b<100 then 'small' else 'big' end as state from sometable
按某个字段的最后两个字符升序:select col_a,col_b from sometable order by substring(col_b, length(col_b)-2)
重叠结果输出:[SELECT SQL A] union all [SELECT SQL B]
union all不删重复项;union删重复项;除非必要,否则不要用union、distinct
从一个表中取数据导入另一个表:insert into table1(col_a, col_b) select (col_aa, col_bb) from table2 where colcc='somevalue'
出现三次以上部门:select col_a from sometable group by col_a having count(*)>=3
列出索引:show index from emp
正则:select data from sometable where data regexp '[^0-9]' = 0
将同一部门的人名合在一行显示:select dept, group_concat(name order by id, ',') from emp group by dept
滚动结果集,每页五行(limit 5),显示第2页(offset 5):select col_a from sometable order by col_a limit 5 offset 5
前向查找:(?=pattern) (?!pattern)
后向查找:(?<=pattern) (?<!pattern)
正则的debug:
脚本中 use re 'debug';
命令行 perl -Mre=debug script.pl
Regexp::Common 常用正则表达式
use Carp qw/carp croak cluck confess/;
cluck :打印堆栈后继续执行
confess:打印堆栈后停止执行
Hook::LexWrap 封装子程序,在子程序执行前后进行预定义代码
perl -d:SmallProf script.pl
DBI::Profile
perl -d:DProf script.pl
Devel::Profiler、Devel::Cover、Devel::Peek
Perl::Critic
临时修改某个库函数:*Some::Module::bar = sub { ... }
perl 命令行参数 -s ,简单置值(默认设为1),例如:
perl -s script.pl -someval=abc -otherval
$someval="abc"、$otherval=1,二者为全局变量
ConfigReader::Simple、Config::Scoped、AppConfig
IO::Interactive
$! 操作系统或库函数调用得到的错误
$? 最近一次调用wait()得到的错误
$@ 最近一次调用eval()得到的错误
$^E 操作系统特有的错误信息
退出值:my $exit_value= $?>>8;
终止程序的信号值:my $signal=$?&127;
若子程序出现内核转储,则低字节第8位置1:my $core_dump = $?&128;
__LINE__ 当前所在行数
use Fatal; 作用是open失败时自动输出die错误信息
Log4perl
do 每次都重新解析文件,而require和use只解析一次文件。
如果找不到文件,$!;如果找到文件,但是无法读取或解析,$@
YAML、YAML::Tiny、YAML::Syck
Storable、Clone::Any
DBM::Deep
二进制数 my $value = ob 10; # $value=2
Devel::Size、Devel::Peek
vec 将一个字符串当成二进制位向量处理
Tie::Cycle、Tie::Hash::Word::Counter
创建一个模块的发布包:
$ Scriptdist Module.pm
$ make disttest
$ make tardist
$variable = ('a', 'list', 'of', 'strings'); print $variable; # returns 'strings' $count = @variable; # returns 4 for @variable above.