Jafar
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
demoLinearLeastSquares.tcl
00001 # $Id$ #
00002 
00003 # Linear Least Squares demo
00004 # simple line fitting: y = a.x + b
00005 
00006 # line parameters
00007 set line_a 2.5
00008 set line_b 11
00009 
00010 set sizeDataSet 100000
00011 
00012 package require jmath
00013 
00014 # random x points in [-100,100]
00015 set random [jmath::new_UniformDistribution -100 100]
00016 
00017 # measure gaussian noise
00018 set noise [jmath::new_NormalDistribution 0.0 1.0]
00019 
00020 # lls class
00021 set lls [::jmath::new_LinearLeastSquares]
00022 $lls setSize 2 $sizeDataSet
00023 
00024 # lls reference to A.x = b
00025 set lls_A [$lls A]
00026 set lls_b [$lls b]
00027 
00028 for {set i 0} {$i < $sizeDataSet} {incr i} {
00029     set x [$random get]
00030     set y [expr $line_a * $x + $line_b + [$noise get]]
00031     # set y [expr $line_a * $x + $line_b]
00032 
00033 #    puts "y: $y - x: $x"
00034 
00035     $lls_A set $i 0 $x
00036     $lls_A set $i 1 1.0
00037 
00038     $lls_b set $i $y
00039 }
00040 
00041 kernel::tic
00042 $lls solve
00043 puts "elapsed: [kernel::toc] ms"
00044 
00045 puts "(a,b) = [jmath::print [$lls x]]"
00046 puts "cov(a,b) = \n [jmath::prettyPrint [$lls xCov]]"
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Wed Oct 15 2014 00:37:21 for Jafar by doxygen 1.7.6.1
LAAS-CNRS