happyr / normal-distribution-bundle

用于计算正态分布及相关内容的工具包

资助包维护!
Nyholm

安装数: 1,064

依赖关系: 0

建议者: 0

安全性: 0

星标: 0

关注者: 2

分支: 0

开放问题: 0

类型:symfony-bundle

0.5.0 2020-09-15 16:06 UTC

This package is auto-updated.

Last update: 2024-09-16 01:03:52 UTC


README

Latest Version Software License SensioLabsInsight Total Downloads

用于计算分布和一些与这些分布相关的统计重要值的工具包。

API

此工具包提供三个服务,以帮助您处理分布。每个服务和函数都有注释,描述了如何使用它们以及为什么使用它们。以下是一个简要概述。

计算器

当您想计算正态分布时,请使用此服务。此服务有两个函数 normalDistributionstandardDistribution。后者计算单位正态分布,其中 meanValue = 0standardDistribution = 1

两个函数的输入都是一个值数组,如 array(3,6,2,6,4,2,3,6,8, ... );

分布管理器

此服务构建任何类型的分布,并将一些数据保存到数据库中。此服务的公共函数有 addDistributiongetPercentilecreateValueFrequencyArray

DistributionManager::addDistribution 接受一个标识符名称和一个数组作为参数,该数组包含值和频率。数组必须采用形式 ($value => $frequency)。以下是一个示例。

<?php

namespace Acme\DemoBundle\Controller;

use Happyr\NormalDistributionBundle\Service\DistributionManager;

class DemoController
{
    public function testController()
    {
        $manager = $this->get(DistributionManager::class);

        $foo = array(8,6,2,6,4,2,3,6,4,8,2,7);
        $bar = $manager->createValueFrequencyArray($foo);
        /*
            $bar should now look like this:
            $bar = (
                2 => 3,
                3 => 1,
                4 => 2,
                6 => 3,
                7 => 1,
                8 => 2
            )
        */
        $summary = $manager->addDistribution('test_id', $bar);

        //get the percentile for a value
        $percentile = $manager->getPercentile('test_id', 3.5);

        $this->get('doctrine.orm.entity_manager')->flush();

        /* ... */
    }
}

统计助手

当您想从预先计算的正态分布中获取值时,请使用 StatisticsHelper

  • getPercentile:获取给定值的百分位数
  • getZTransform:执行 Z 变换以获取正态分布中给定的标准化值
  • getStanine:获取给定值的斯坦纳值
  • getStanineForPercentile:获取给定百分位数的斯坦纳值。当您的分布不是标准分布时,这非常有用。

安装

使用 Composer 安装!

composer require happyr/normal-distribution-bundle

下载依赖项后,然后在 AppKernel 中注册该工具包。

<?php

// in AppKernel::registerBundles()
$bundles = array(
    // ...
    new Happyr\NormalDistributionBundle\HappyrNormalDistributionBundle(),
    // ...
);

更新数据库

该工具包包含两个实体。您应该使用迁移脚本来更新数据库,或者在纯开发环境中运行以下命令

php app:console doctrine:schema:update --force