time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

pareto-test.js (3051B)


      1 var vows = require('vows');
      2 var assert = require('assert');
      3 var suite = vows.describe('jStat.distribution');
      4 
      5 require('../env.js');
      6 
      7 suite.addBatch({
      8   'pareto pdf': {
      9     'topic': function() {
     10       return jStat;
     11     },
     12     // Checked against R's dpareto(x, df) in package VGAM
     13     //   install.packages("VGAM")
     14     //   library("VGAM")
     15     //   options(digits=10)
     16     //   dpareto(c(0, 1, 2), 1, 1)
     17     //   dpareto(c(-1, 1, 4), 1, 2)
     18     //   dpareto(c(1, 2, 10), 2, 2)
     19     'check pdf calculation': function(jStat) {
     20       var tol = 0.0000001;
     21       assert.epsilon(tol, jStat.pareto.pdf(0, 1, 1), 0);
     22       assert.epsilon(tol, jStat.pareto.pdf(1, 1, 1), 1);
     23       assert.epsilon(tol, jStat.pareto.pdf(2, 1, 1), 0.25);
     24 
     25       assert.epsilon(tol, jStat.pareto.pdf(-1, 1, 2), 0);
     26       assert.epsilon(tol, jStat.pareto.pdf(1, 1, 2), 2);
     27       assert.epsilon(tol, jStat.pareto.pdf(4, 1, 2), 0.03125);
     28 
     29       assert.epsilon(tol, jStat.pareto.pdf(1, 2, 2), 0);
     30       assert.epsilon(tol, jStat.pareto.pdf(2, 2, 2), 1);
     31       assert.epsilon(tol, jStat.pareto.pdf(10, 2, 2), 0.008);
     32     }
     33   },
     34   'pareto inv': {
     35     'topic': function() {
     36       return jStat;
     37     },
     38     // Checked against R's qpareto(x, df) in package VGAM
     39     //   install.packages("VGAM")
     40     //   library("VGAM")
     41     //   options(digits=10)
     42     //   qpareto(c(0, 0.5, 1), 1, 1)
     43     //   qpareto(c(0, 0.5, 1), 1, 2)
     44     //   qpareto(c(0, 0.5, 1), 2, 2)
     45     'check inv calculation': function(jStat) {
     46       var tol = 0.0000001;
     47       assert.epsilon(tol, jStat.pareto.inv(0, 1, 1), 1);
     48       assert.epsilon(tol, jStat.pareto.inv(0.5, 1, 1), 2);
     49       assert.equal(jStat.pareto.inv(1, 1, 1), Infinity);
     50 
     51       assert.epsilon(tol, jStat.pareto.inv(0, 1, 2), 1);
     52       assert.epsilon(tol, jStat.pareto.inv(0.5, 1, 2), 1.414213562);
     53       assert.equal(jStat.pareto.inv(1, 1, 2), Infinity);
     54 
     55       assert.epsilon(tol, jStat.pareto.inv(0, 2, 2), 2);
     56       assert.epsilon(tol, jStat.pareto.inv(0.5, 2, 2), 2.828427125);
     57       assert.equal(jStat.pareto.inv(1, 2, 2), Infinity);
     58     }
     59   },
     60   'pareto cdf': {
     61     'topic': function() {
     62       return jStat;
     63     },
     64     // Checked against R's ppareto(q, scale = 1, shape, lower.tail = TRUE, log.p = FALSE) in package VGAM
     65     //   install.packages("VGAM")
     66     //   library("VGAM")
     67     //   options(digits=10)
     68     //   ppareto(c(0, 1, 2), 1, 1)
     69     //   ppareto(c(-1, 1, 4), 1, 2)
     70     //   ppareto(c(1, 2, 10), 2, 2)
     71     'check cdf calculation': function(jStat) {
     72       var tol = 0.0000001;
     73       assert.epsilon(tol, jStat.pareto.cdf(0, 1, 1), 0);
     74       assert.epsilon(tol, jStat.pareto.cdf(1, 1, 1), 0);
     75       assert.epsilon(tol, jStat.pareto.cdf(2, 1, 1), 0.5);
     76 
     77       assert.epsilon(tol, jStat.pareto.cdf(-1, 1, 2), 0);
     78       assert.epsilon(tol, jStat.pareto.cdf(1, 1, 2), 0);
     79       assert.epsilon(tol, jStat.pareto.cdf(4, 1, 2), 0.9375);
     80 
     81       assert.epsilon(tol, jStat.pareto.cdf(1, 2, 2), 0);
     82       assert.epsilon(tol, jStat.pareto.cdf(2, 2, 2), 0);
     83       assert.epsilon(tol, jStat.pareto.cdf(10, 2, 2), 0.96);
     84     }
     85   },
     86 });
     87 
     88 suite.export(module);