haskell - 如何用 2 个值对向量进行拆箱

标签 haskell statistics box haskell-vector

我正在尝试按照给定的 here 进行 wilcoxonMatchedPairTest :

import Data.Vector as V
import Statistics.Test.WilcoxonT

sampleA = [1.0,2.0,3.0,4.0,1.0,2.0,3.0,4]
sampleB = [2.0,4.0,5.0,5.0,3.0,4.0,5.0,6]

main = do
    putStrLn "\nResult of wilcoxonMatchedPairTest: "
    print (wilcoxonMatchedPairTest AGreater (Prelude.zip sampleA sampleB))

但是,我收到以下错误:

rnwilcox.hs:10:50: error:
    • Couldn't match expected type ‘Data.Vector.Unboxed.Base.Vector
                                      (a0, a0)’
                  with actual type ‘[(Double, Double)]’
    • In the second argument of ‘wilcoxonMatchedPairTest’, namely
        ‘(Prelude.zip sampleA sampleB)’
      In the first argument of ‘print’, namely
        ‘(wilcoxonMatchedPairTest AGreater (Prelude.zip sampleA sampleB))’
      In a stmt of a 'do' block:
        print
          (wilcoxonMatchedPairTest AGreater (Prelude.zip sampleA sampleB))

显然,我需要在这里对向量进行拆箱。我尝试使用 # 如下:

(# Prelude.zip sampleA sampleB #)

但是它不起作用。问题出在哪里以及如何解决?感谢您的帮助。

最佳答案

您需要使用 fromList :: Unbox a => [a] -> Vector a 将二元组列表转换为 VectorData.Vector.Unboxed 包中创建这样一个向量:

import Data.Vector.Unboxed as <b>VU</b>
import Statistics.Test.WilcoxonT

main = do
    putStrLn "\nResult of wilcoxonMatchedPairTest: "
    print (wilcoxonMatchedPairTest AGreater (<b>VU.fromList</b> (Prelude.zip sampleA sampleB)))

或者如果您有两个Vector,则可以使用 zip :: (Unbox a, Unbox b) => Vector a -> Vector b -> Vector (a, b)将两个 Vector 压缩为一个 Vector 项目:

import Data.Vector.Unboxed as <b>VU</b>
import Statistics.Test.WilcoxonT

sampleA = VU.fromList [1.0,2.0,3.0,4.0,1.0,2.0,3.0,4]
sampleB = VU.fromList [2.0,4.0,5.0,5.0,3.0,4.0,5.0,6]

main = do
    putStrLn "\nResult of wilcoxonMatchedPairTest: "
    print (wilcoxonMatchedPairTest AGreater (<b>VU.zip</b> sampleA sampleB))

对于给定的示例数据,这给我们:

Prelude VU Statistics.Test.WilcoxonT> main

Result of wilcoxonMatchedPairTest: 
Test {testSignificance = mkPValue 1.0, testStatistics = 36.0, testDistribution = ()}

关于haskell - 如何用 2 个值对向量进行拆箱,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57912625/

相关文章:

box - 文件夹下载 URL Box API

android - 找不到符号 Android React Native

haskell - 如何在 Haskell 中将成功或失败返回给操作系统?

haskell - 如何使用异常处理在 Haskell 中编写 "retryForever"函数?

java - Box Java SDK - 无法下载/删除文件的特​​定版本

PHP MySQL 表帮助

ios - 将 Z 分数转换为百分位数( objective-c )

Haskell 函数将操作递归地应用于参数

haskell - 为什么 1 和 2 在这个不相交的联合中

r - Common Lisp 的统计包