评论排序算法

发布时间: 2014-04-26热度: 2594

20140426160347.jpg

代码

#include 
#include 
#include
double pnorm(double qn)
{
    const double b[] =
    {
        1.570796288, 0.03706987906, -0.8364353589e-3,
        -0.2250947176e-3, 0.6841218299e-5, 0.5824238515e-5,
        -0.104527497e-5, 0.8360937017e-7, -0.3231081277e-8,
        0.3657763036e-10, 0.6936233982e-12
    };

    double w1, w3;

    if (qn < 0.0 || qn > 1.0 || qn == 0.5)
        return 0.0;

    w1 = qn;

    if (qn > 0.5)
        //return -pnorm(1 - qn);
        w1 = 1.0 - w1;

    w3 = -log(4.0 * w1 * (1.0 - w1));
    w1 = b[0];

    for (int i = 1; i < 11; i++)
    {
        w1 += b[i] * pow(w3, i);
    }

    if (qn > 0.5)
        return sqrt(w1 * w3);

    return -sqrt(w1 * w3);
}

double ci_lower_bound(double pos, int total, float power = 0.10)   //Sum
{
    if (!total) return 0.0;
	if (pos>total) return 1.0;

    double z = pnorm(1.0 - power / 2);
	double phat = pos / total;

    return (phat + z * (z / (2*total) - sqrt((phat*(1 - phat) + z*z / (4*total)) / total)) ) / (1 + z*z / total);
}

int main()
{
    printf("%fn",ci_lower_bound(200, 220));    // 总和和好评
    getchar();
}

VB6

Option Explicit
Private Function pnorm(qn As Double) As Double
Dim b
Dim i As Integer
b = Array(1.570796288, 0.03706987906, -0.0008364353589, -0.0002250947176, 0.000006841218299, 0.000005824238515, -0.00000104527497, 8.360937017E-08, -3.231081277E-09, 3.657763036E-11, 6.936233982E-13)
Dim w1 As Double
Dim w3 As Double
If qn 1# Or qn = 0.5 Then
pnorm = 0#
End If
w1 = qn
If qn > 0.5 Then
w1 = 1 – w1
End If
w3 = -Log(4# * w1 * (1# – w1))
w1 = b(0)
For i = 1 To 10
w1 = b(i) * w3 ^ i + w1
Next i
If qn > 0.5 Then
pnorm = Sqr(w1 * w3)
End If
pnorm = -Sqr(w1 * w3)
End Function
Private Function ci_lower_bound(pos As Double, total As Integer, power As Double) As Double
If power = 0 Then power = 0.1
If total = 0 Then ci_lower_bound = 0#
If pos > total Then ci_lower_bound = 1#
Dim z As Double
Dim phat As Double
z = pnorm(1# – power / 2)
phat = pos / total
ci_lower_bound = (phat + z * (z / (2 * total) – Sqr((phat * (1 – phat) + z * z / (4 * total)) / total))) / (1 + z * z / total)
End Function
Private Sub Form_Click()
MsgBox ci_lower_bound(200, 220, 0)
End Sub

请在下方留下您的评论.加入TG吹水群