解释披系数函数雄辩的Javascript是如何工作的? [英] Explain how the phi coefficient function works in Eloquent Javascript?

查看:96
本文介绍了解释披系数函数雄辩的Javascript是如何工作的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在读能言善辩的JavaScript - 迄今为止,它已经很好看,但我卡在他的竖起,计算PHI-系数可这一功能。这是code。

有显然很为它有点断章取义,我不能复制/粘贴事事休书,因此,如果有人谁的实际阅读这本书可以解释这对我来说,这将是真棒!

什么是不明白的是,什么是被称为他说,当表[3]或表[0]?据我所知,披系数计算公式:

φ=(n11n00 - n10n01)/(√N1•N0•N•1N•0)

但我不明白(全部)他是如何转化成那个JS。究竟在这个code发生了什么?

 函数披(表){
  收益率(表[3] *表[0] - 表[2] *表[1])/
    的Math.sqrt((表[2] +表[3])*
              (表[0] +表[1])*
              (表[1] +表[3])*
              (表[0] +表[2]));
}


解决方案

尝试以可视化的流程上的每一步,并替代品,像一个公式:

┌──────────────┬──────────────┐
│标签:N00│标签:N10│
│数:76│数:9│
│没有松鼠,没有│松鼠,│
│没有比萨薄饼││
├──────────────┼──────────────┤
│标签:N00│标签:N11│
│数:4│数:1│
│松鼠,松鼠│,│
│没有比萨薄饼││
└──────────────┴──────────────┘

 表= [N00,N01,N10,N11]N00 =表[0] = 76
N01 =表[1] = 4
N10 =表[2] = 9
N11 =表[3] = 1N1•= N10 + N11 =表[2] +表[3] = 9 + 1 = 10
N0 =•N00 + N01 =表[0] +表[1] = 76 + 4 = 80
牛•1 = N01 + N11 =表[1] +表[3] = 4 + 1 = 5
牛•0 = N00 + N10 =表[0] +表[2] = 76 + 9 = 85

  //伪code
披=功能(表){
  回报(N11 N00 * - * N10 N01)/
    的Math.sqrt(N1•* N0•* N•1 * N•0)
}// JavaScript的code
披=功能(表){
  收益率(表[3] *表[0] - 表[2] *表[1])/
    的Math.sqrt((表[2] +表[3])*
              (表[0] +表[1])*
              (表[1] +表[3])*
              (表[0] +表[2]))
}

I'm currently reading Eloquent Javascript - so far, it's been a good read, but I'm stuck on this one function that he's put up, for calculating the phi-coeffcient. This is the code.

There's obviously quite a bit of context for it, and I can't copy/paste everything off the book, so if someone who's actually read the book could explain this to me, it would be awesome!

What is don't get is, what is being referred to when he says "table[3]", or "table[0]"? I understand the phi coefficient formula:

ϕ = (n11n00 - n10n01) / (√ n1•n0•n•1n•0)

But I don't get (at all) how he's translated that into JS. What exactly is happening in this code?

function phi(table) {
  return (table[3] * table[0] - table[2] * table[1]) /
    Math.sqrt((table[2] + table[3]) *
              (table[0] + table[1]) *
              (table[1] + table[3]) *
              (table[0] + table[2]));
}

解决方案

Try to visualize the process on each step, and substitute, like an equation:

┌──────────────┬──────────────┐
│ label: n00   │ label: n10   │
│ count: 76    │ count: 9     │
│ no squirrel, │ no squirrel, │
│ no pizza     │ pizza        │
├──────────────┼──────────────┤
│ label: n00   │ label: n11   │
│ count: 4     │ count: 1     │
│ squirrel,    │ squirrel,    │
│ no pizza     │ pizza        │
└──────────────┴──────────────┘

table = [n00, n01, n10, n11]

n00 = table[0] = 76
n01 = table[1] = 4
n10 = table[2] = 9
n11 = table[3] = 1

n1• = n10 + n11 = table[2] + table[3] = 9  + 1 = 10
n0• = n00 + n01 = table[0] + table[1] = 76 + 4 = 80
n•1 = n01 + n11 = table[1] + table[3] = 4  + 1 = 5
n•0 = n00 + n10 = table[0] + table[2] = 76 + 9 = 85

//pseudo code
phi = function(table) {
  return (n11 * n00 - n10 * n01) /
    Math.sqrt(n1• * n0• * n•1 * n•0)
}

//JavaScript code
phi = function(table) {
  return (table[3] * table[0] - table[2] * table[1]) /
    Math.sqrt((table[2] + table[3]) *
              (table[0] + table[1]) *
              (table[1] + table[3]) *
              (table[0] + table[2]))
}

这篇关于解释披系数函数雄辩的Javascript是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆