Intro

ML lang family

statically strongly typed languages

  • fisrt-class functions
  • type inference
  • pattern matching

highlights of ocaml

  • safty: static typing, pattern matching
  • efficiency: high performance
  • expressiveness: functional+type inference+polymorphism

  • package manager: opam

  • debugger
  • profiler
  • REPL: "toplevel"
  • bytecode compiler: ccamlc
  • native compiler: ocamlopt

programming environment fully online: https://try.ocamlpro ...

Recap: Functions and Pattern Matching

case classes

ex: json json objects can be seq, num, str, bool,...

⇒ represented as abstract class and case classes.

pattern matching

→ question: what is the type of the {case(key, value)=>"..."} clause?

it is (JBinding => String) type, which is a shorthand for Function1[JBinding, String ...

6.1 - Other Collections

so far: only seen List. → more (immutable) collections.

vector

List: is linear -- access to head is faster than middle or end element. Vector: better rand access performance.

represented as very shallow trees(32-split at each node)

Vector support similar operations as List (head, tail,map, fold ...

5.1 - More Functions on Lists

already known methods:

xs.head
xs.tail

sublist and ele access:

  • xs.length
  • xs.last
  • xs.init: all elementh except last element
  • xs.take(n): sublist of first n elements
  • xs.drop(n): the rest of list after taking first n elements
  • xs(n ...

R里面的统计函数有很多, 这里只用线性模型lm以及(一维)非参估计最常用的三个smoother: Nadaraya-Watson kernel(NW, ksmooth), Local Polynomial(LP, loess), Smoothing Spline(SS, smooth.spline). 用这三个smoother作为例子, 介绍R里面统计回归的一些用法.

数据的形式是: 

目标是估计函数m(). 例子使用R自带的cars数据集, 它包含两列: 汽车速度speed和刹车距离dist.

> data(cars)
> summary(cars)
     speed           dist       
 Min.   : 4.0   Min.   :  2.00  
 1st Qu.:12.0   1st Qu.: 26.00  
 Median :15 ...