REBOL [ Title: "Conference" Date: 18-Aug-2009/14:23:38+2:00 File: %present.r Author: ["Carl Sassenrath" "Matt Licholai" "Ladislav Mecir"] Purpose: "Rebol Collaboration Conference presentation." ] content: {Rebol and Technical Subjects ===Contact Look for Ladislav at the REBOL mailing list. ===The presentation Based on: - Carl Sassenrath's Presentation Dialect - Matt Licholai's Quick Plot Dialect - %prob.r library ===Lifetime Question #1: Automobile wheel producer: "Is a dataset consisting of four lifetime measurements sufficiently large for a statistical analysis?" The first question was the hardest one and rather undetermined, but I will try to show you how to eventually find an answer. Task: "Determine the lifetime of automobile wheels production defined as the number of standard loading cycles 99.86% of the production is able to sustain. The measurements are the numbers of standard loading cycles until the desctruction for some randomly picked wheels." ===Instruments INCLUDE is my module manager, that you are using right now. Usage: ; a URL you can use in your search path: lm: http://www.fm.vslib.cz/~ladislav/rebol ; define the Include function do lm/include.r ; add the URL to the path include-path: union include-path reduce [lm] ; let's have a look at the path view layout [text-list 400 data include-path] Now let's use Probability Functions (written by me except for two functions translated from FORTRAN, Jaime Vargas helped to check the License to be OK for public use), an enhanced version of Matt Licholai's Quick Plot etc. include %cfor.r include %map.r include %prob.r include %random.r include %q-plot.r include %normal-density.r include %normal-distrib.r include %normal-quantile.r include %lifetime-density.r include %lifetime-distrib.r include %lifetime-quantile.r include %weibull-density.r include %weibull-distrib.r include %weibull-quantile.r include %normal-param.r include %lognorm-param.r include %lifetime-param.r view layout [text "Quick Plot and Probability functions defined."] ===Normal Distribution To solve the given task we should know the distribution of lifetime of the produced wheels, which is the percentage of the wheels having a given lifetime. The simplest way seems to be to measure the lifetime of a large number of wheels and draw a corresponding plot. That is not what may be called practical, because every measurement takes some time and is pretty expensive. The way out is to pick a typical well known distribution and suppose, that our unknown distribution is (in a sense) similar. One such distribution (surely the most popular) is a the Normal Distribution also known as Gauss' Distribution. view quick-plot [ 600x400 title "Bell-shaped curve" x-data [ ( data: copy [] cfor [x: -5.0] [x <= 5.0] [x: round/to x + 0.2 0.1] [ insert tail data x ] data ) ] line [(map :normal-density data)] x-axis 11 border y-axis 5 border x-grid 11 y-grid 7 ] The probability is the area below the density curve which totals to one. A probability that a random variable having this distribution will not exceed certain X is the area of the left hand tail of the distribution, i.e. area below the density curve not exceeding X. view quick-plot [ 600x400 title "Standard Normal Distribution" x-data [(data)] line [(map :normal-distrib data)] x-axis 11 border y-axis 5 border x-grid 11 y-grid 7 ] The area of the left hand tail summed with the area of the right hand tail is one. ===Parameters Standard Normal distribution has got the Mean equal to 0.0 and the Standard Deviation equal to one. These are called Mu and Sigma, i.e. Mu equals to 0.0 and Sigma to 1.0 Using the NORMAL-DISTRIB function we can find the probability for any given X: x: 0.0 view layout [ text "Type a value" f: field 0.0 [ x: to decimal! f/data inform layout reduce [ 'text "Probability:" 'text mold normal-distrib x ] ] ] and see, that the task is to find a lifetime value, for which the reliability of the production corresponds to three sigma probability for the Standard Normal Distribution. Unfortunately, this characterization is an oxymoron. ===Other distributions This is one of the favorite distributions discovered by Birnbaum and Sanders. Suitable for lifetime of parts sustaining cyclic load. view quick-plot [ 600x400 title "Lifetime Distribution Density Curve" x-data [ ( data: copy [] cfor [x: 0.2] [x <= 5.0] [x: round/to x + 0.2 0.1] [ insert tail data x ] data ) ] line [(map func [x] [lifetime-density/param x 2.4 0.4] data)] x-axis 11 border y-axis 5 border x-grid 11 y-grid 7 ] Lognormal distribution is a distribution of a value whose logarithm has got a normal distribution. view quick-plot [ 600x400 title "Lognormal Distribution Density Curve" x-data [(data)] line [(map func [x] [lognorm-density/param x 0.9 0.2] data)] x-axis 11 border y-axis 5 border x-grid 11 y-grid 7 ] A distribution discovered by Weibull, very popular for lifetime tasks. Suitable for lifetime of devices having many parts that can fail. view quick-plot [ 600x400 title "Weibull Distribution Density Curve" x-data [(data)] line [(map func [x] [weibull-density/scale/shape x 2.7 4.3] data)] x-axis 11 border y-axis 5 border x-grid 11 y-grid 7 ] ===Reliability Reliable wheels will be wheels having at least the computed minimum lifetime, unreliable wheels will be wheels that break sooner. Reliability will be the right hand tail area, while the left hand tail area will be the failure probability. ===Probability Plots life-times: [ 2.12242888175422 3.20588715675779 2.70785494199425 1.88113650740248 2.41587753546555 2.94474964179832 2.04100283975998 2.12009818262645 4.3189714153094 2.91337746338666 2.07920814999726 2.23509599338251 1.96391489019623 1.65764092865628 2.18876284525615 1.33270186286227] ranks: median-ranks 16 view quick-plot [ 600x400 title "Normal Probability Plot of data" x-data [(map :normal-quantile ranks)] line [(map :log-e sort life-times)] x-axis 11 border y-axis 5 border x-grid 11 y-grid 7 ] ===Monte Carlo You can use a simulation to compute out the precision with which you estimated the values. This is a way how to create a simulated dataset: life-times: [] loop 16 [ insert tail life-times random-g func [x] [ lifetime-quantile/param x 2.4 0.4 ] ] lt: map :mold life-times view layout [text-list 400 data lt] ===Functions These functions are available: Random-n - Normally Distributed Random Value Random-g - Generally Distributed Random Value Rand-bytes - Random Bytes from www.random.org Random-u - Uniformly Distributed Random Value Normal-density - Density of the Normal Probability Distribution Normal-quantile - Percent Point Function of the Normal Probability Distribution Normal-distrib - The Normal Probability Distribution Weibull-density - Density of the Weibull Probability Distribution Weibull-distrib - Weibull Probability Distribution Weibull-quantile - Percent Point function of the Weibull Probability Distribution Lifetime-density - Density of the Lifetime Probability Distribution Lifetime-distrib - The Lifetime Probability Distribution Lifetime-quantile - Percent Point function of the Lifetime Probability Distribution Lognorm-density - Density of the Lognormal Probability Distribution Lognorm-distrib - The Lognormal Probability Distribution Lognorm-quantile - Percent Point function of the Lognormal Probability Distribution Mean-ranks - Weibull Mean Ranks for N Random Samples Hazen-ranks - Hazen Ranks for N random Samples Median-ranks - "Almost" Median Ranks for N Random Samples Lifetime-param - Estimate Parameters of a Lifetime Distribution Normal-param - Mean and Sample Standard Deviation Lognorm-param - Estimate Parameters of a Lognormal Distribution } ; end of content ; a URL you can use in your search path: lm: http://www.fm.vslib.cz/~ladislav/rebol ; define the Include function do lm/include.r ; add the URL to the path include-path: union include-path reduce [lm] ; definition of probabilistic functions, q-plot etc. include %prob.r include %q-plot.r include %cfor.r include %map.r code: text: layo: xview: none sections: [] layouts: [] space: charset " ^-" chars: complement charset " ^-^/" rules: [title some parts] title: [text-line (title-line: text)] parts: [ newline | "===" section | "---" subsect | "!" note | example | paragraph ] text-line: [copy text to newline newline] indented: [some space thru newline] paragraph: [copy para some [chars thru newline] (emit txt para)] note: [copy para some [chars thru newline] (emit-note para)] example: [ copy code some [indented | some newline indented] (emit-code code) ] section: [ text-line ( append sections text append/only layouts layo: copy page-template emit h1 text ) newline ] subsect: [text-line (emit h2 text)] emit: func ['style data] [repend layo [style data]] emit-code: func [code] [ remove back tail code repend layo ['code 460x-1 trim/auto code 'show-example] ] emit-note: func [code] [ remove back tail code repend layo ['tnt 460x-1 code] ] show-example: [ if xview [xy: xview/offset unview/only xview] xcode: load/all face/text if not block? xcode [xcode: reduce [xcode]] ;!!! fix load/all intro-blk: copy xcode ;; Here's the mess I added to allow arbitrary code before 'view either xcode: next find xcode 'view [ ; if there is an explicit 'view in the block, ; then break it up and 'do the part of the block up to 'view reduce head clear find intro-blk 'view ; finally feed the part after 'view to the dialect ; to make a face (quick-plot) and then drive ; the properly offset 'view either 'quick-plot = first xcode [ ss: quick-plot second xcode xy ;ss broke up the line ;print probe ss xview: view/new/offset quick-plot second xcode xy ][ xview: view/new/offset do xcode xy ] ][ if here: select xcode 'layout [xcode: here] xview: view/new/offset layout xcode xy ] ] page-template: [ size 500x480 origin 8x8 backdrop white style code tt black silver bold as-is para [origin: margin: 12x8] font [colors: [0.0.0 0.80.0]] style tnt txt maroon bold ] parse/all detab content rules show-page: func [i /local blk last-face][ i: max 1 min length? sections i append clear tl/picked pick sections i show tl if blk: pick layouts this-page: i [ f-box/pane: layout/offset blk 0x0 last-face: last f-box/pane/pane f-box/pane/pane/1/size: f-box/pane/size: max 500x480 add 20x20 add last-face/offset last-face/size update-slider show f-box ] ] update-slider: does [ either object? f-box/pane [ sld/redrag min 1.0 divide sld/size/2 f-box/pane/size/2 sld/action: func[face event] compose [ f-box/pane/offset/2: multiply face/data (subtract 480 f-box/pane/size/2) show f-box ] ][ sld/redrag 1.0 show sld sld/action: none ] sld/data: 0 show sld ] main: layout [ backdrop effect [gradient 1x1 220.220.255 0.0.172] across h2 title-line return space 0 tl: text-list 160x480 bold black white data sections [ show-page index? find sections value ] h: at f-box: info 500x480 at h + 500x0 sld: slider 16x480 at h + 456x-24 across space 4 arrow left keycode [up left] [show-page this-page - 1] arrow right keycode [down right] [show-page this-page + 1] pad -120 txt form system/script/header/date/date ] update-slider show-page 1 xy: main/offset + 480x100 view main