How to use the jstat.jStat.normal function in jstat

To help you get started, we’ve selected a few jstat examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github getguesstimate / guesstimate-app / src / lib / guesstimator / samplers / simulator-worker / simulator / distributions / distributions.js View on Github external
const width = max - min
  const a = 1 + lambda * ((mode - min)/width)
  const b = 1 + lambda * ((max - mode)/width)
  const p = jStat.beta.sample(a, b)
  return min + p*width
}

export const Distributions = {
  beta: jStat.beta.sample,
  centralF: jStat.centralF.sample,
  cauchy: jStat.cauchy.sample,
  chisquare: jStat.chisquare.sample,
  exponential: jStat.exponential.sample,
  invgamma: jStat.invgamma.sample,
  lognormal: jStat.lognormal.sample,
  normal: jStat.normal.sample,
  studentt: jStat.studentt.sample,
  weibull: jStat.weibull.sample,
  uniform: jStat.uniform.sample,
  gamma: jStat.gamma.sample,
  triangular,
  doubleTriangular,
  PERT,
  bernoulli: bernoulli,
  if: bernoulli,
  test: bernoulli,
  binomial: binomial,
  poisson: poisson,
  negBinomial: negBinomial
}
github getguesstimate / guesstimate-app / src / lib / guesstimator / samplers / Function.js View on Github external
import math from 'mathjs'
import {jStat} from 'jstat'
var Finance = require('financejs')
const finance = new Finance()

const jStatDistributions = {
  beta: jStat.beta.sample,
  centralF: jStat.centralF.sample,
  cauchy: jStat.cauchy.sample,
  chisquare: jStat.chisquare.sample,
  exponential: jStat.exponential.sample,
  invgamma: jStat.invgamma.sample,
  lognormal: jStat.lognormal.sample,
  normal: jStat.normal.sample,
  studentt: jStat.studentt.sample,
  weibull: jStat.weibull.sample,
  uniform: jStat.uniform.sample,
  gamma: jStat.gamma.sample
}

const financeFunctions = {
  PV: finance.PV,
  FV: finance.FV,
  NPV: finance.NPV,
  //IRR: finance.IRR, Too slow.
  PP: finance.PP,
  ROI: finance.ROI,
  AM: finance.AM,
  PI: finance.PI,
  DF: finance.DF,
github jonnyboyC / kos-language-server / server / src / generator / generator.ts View on Github external
private draw(dist: Distribution): number {
    switch (dist.tag) {
      case 'constant':
        return dist.value;
      case 'exp':
        const expDraw = jStat.exponential.sample(dist.rate) as number;
        return expDraw > 0 ? expDraw : 0;
      case 'gamma':
        const grammDraw = jStat.gamma.sample(dist.shape, dist.scale) as number;
        return grammDraw > 0 ? grammDraw : 0;
      case 'normal':
        const normalDraw = jStat.normal.sample(dist.mean, dist.std) as number;
        return normalDraw > 0 ? normalDraw : 0;
      default:
        throw new Error('Unsupported distribution');
    }
  }
github TracerBench / tracerbench / packages / cli / src / helpers / statistics / confidence-interval.ts View on Github external
export function confidenceInterval(distributionOne: number[], distributionTwo: number[], interval: number): [number, number] {
  const distributionOneLength = distributionOne.length;
  const distributionTwoLength = distributionTwo.length;

  const lengthsMultiplied = distributionOneLength * distributionTwoLength;
  const sqrtOfSomething = Math.sqrt(lengthsMultiplied * (distributionOneLength + distributionTwoLength + 1) / 12);
  const other = jStat.normal.inv(1 - (1 - interval) / 2, 0, 1) * sqrtOfSomething;
  const ca = Math.floor(distributionOneLength * distributionTwoLength / 2 - other);
  const diffs = cartesianProduct(distributionOne, distributionTwo);
  return [diffs[ca - 1], diffs[(distributionOneLength * distributionTwoLength) - ca]];
}