happyr / normal-distribution-bundle
用于计算正态分布及相关内容的工具包
0.5.0
2020-09-15 16:06 UTC
Requires
- php: ^7.2
- symfony/config: ^4.4 || ^5.1
- symfony/dependency-injection: ^4.4 || ^5.1
- symfony/http-kernel: ^4.4 || ^5.1
Requires (Dev)
- doctrine/doctrine-bundle: ^1.12 || ^2.0.9
- doctrine/orm: ^2.7
- nyholm/nsa: ^1.1
- nyholm/symfony-bundle-test: ^1.6
- symfony/phpunit-bridge: ^4.4 || ^5.1
README
用于计算分布和一些与这些分布相关的统计重要值的工具包。
API
此工具包提供三个服务,以帮助您处理分布。每个服务和函数都有注释,描述了如何使用它们以及为什么使用它们。以下是一个简要概述。
计算器
当您想计算正态分布时,请使用此服务。此服务有两个函数 normalDistribution
和 standardDistribution
。后者计算单位正态分布,其中 meanValue = 0
且 standardDistribution = 1
。
两个函数的输入都是一个值数组,如 array(3,6,2,6,4,2,3,6,8, ... );
分布管理器
此服务构建任何类型的分布,并将一些数据保存到数据库中。此服务的公共函数有 addDistribution
、getPercentile
和 createValueFrequencyArray
。
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