| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: mra.c,v 1.6 2014/03/14 05:03:19 khorben Exp $ */ | | 1 | /* $NetBSD: mra.c,v 1.7 2018/03/10 23:25:59 khorben Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1999 Shin Takemura All rights reserved. | | 4 | * Copyright (c) 1999 Shin Takemura All rights reserved. |
5 | * Copyright (c) 1999 PocketBSD Project. All rights reserved. | | 5 | * Copyright (c) 1999 PocketBSD Project. All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -18,27 +18,27 @@ | | | @@ -18,27 +18,27 @@ |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | | 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
26 | * SUCH DAMAGE. | | 26 | * SUCH DAMAGE. |
27 | * | | 27 | * |
28 | */ | | 28 | */ |
29 | | | 29 | |
30 | #include <sys/cdefs.h> | | 30 | #include <sys/cdefs.h> |
31 | __KERNEL_RCSID(0, "$NetBSD: mra.c,v 1.6 2014/03/14 05:03:19 khorben Exp $"); | | 31 | __KERNEL_RCSID(0, "$NetBSD: mra.c,v 1.7 2018/03/10 23:25:59 khorben Exp $"); |
32 | | | 32 | |
33 | #include <sys/param.h> | | 33 | #include <sys/param.h> |
34 | #include <sys/systm.h> | | 34 | #include <sys/systm.h> |
35 | | | 35 | |
36 | extern int mra_Y_AX1_BX2_C(const int *, int, | | 36 | extern int mra_Y_AX1_BX2_C(const int *, int, |
37 | const int *, int, const int *, int, int, int, | | 37 | const int *, int, const int *, int, int, int, |
38 | int *, int *, int *); | | 38 | int *, int *, int *); |
39 | | | 39 | |
40 | /* | | 40 | /* |
41 | * multiple regression analysis | | 41 | * multiple regression analysis |
42 | * Y = AX1 + BX2 + C | | 42 | * Y = AX1 + BX2 + C |
43 | */ | | 43 | */ |
44 | int | | 44 | int |
| @@ -51,27 +51,27 @@ mra_Y_AX1_BX2_C(const int *y, int ys, | | | @@ -51,27 +51,27 @@ mra_Y_AX1_BX2_C(const int *y, int ys, |
51 | int64_t X1a, X2a, Ya; | | 51 | int64_t X1a, X2a, Ya; |
52 | int64_t X1X1s, X2X2s, X1X2s; | | 52 | int64_t X1X1s, X2X2s, X1X2s; |
53 | int64_t YYs, X1Ys, X2Ys; | | 53 | int64_t YYs, X1Ys, X2Ys; |
54 | int64_t S11, S22, S12; | | 54 | int64_t S11, S22, S12; |
55 | // int64_t SYY; | | 55 | // int64_t SYY; |
56 | int64_t S1Y, S2Y; | | 56 | int64_t S1Y, S2Y; |
57 | int64_t A, B, C, M; | | 57 | int64_t A, B, C, M; |
58 | #define AA(p, s, i) (*((const int *)(((const char *)(p)) + (s) * (i)))) | | 58 | #define AA(p, s, i) (*((const int *)(((const char *)(p)) + (s) * (i)))) |
59 | #define X1(i) AA(x1, x1s, i) | | 59 | #define X1(i) AA(x1, x1s, i) |
60 | #define X2(i) AA(x2, x2s, i) | | 60 | #define X2(i) AA(x2, x2s, i) |
61 | #define Y(i) AA(y, ys, i) | | 61 | #define Y(i) AA(y, ys, i) |
62 | | | 62 | |
63 | /* | | 63 | /* |
64 | * get avarage and sum | | 64 | * get average and sum |
65 | */ | | 65 | */ |
66 | X1a = 0; X2a = 0; Ya = 0; | | 66 | X1a = 0; X2a = 0; Ya = 0; |
67 | X1X1s = 0; X2X2s = 0; X1X2s = 0; | | 67 | X1X1s = 0; X2X2s = 0; X1X2s = 0; |
68 | X1Ys = 0; X2Ys = 0; YYs = 0; | | 68 | X1Ys = 0; X2Ys = 0; YYs = 0; |
69 | for (i = 0; i < n; i++) { | | 69 | for (i = 0; i < n; i++) { |
70 | X1a += X1(i); | | 70 | X1a += X1(i); |
71 | X2a += X2(i); | | 71 | X2a += X2(i); |
72 | Ya += Y(i); | | 72 | Ya += Y(i); |
73 | | | 73 | |
74 | X1X1s += X1(i) * X1(i); | | 74 | X1X1s += X1(i) * X1(i); |
75 | X2X2s += X2(i) * X2(i); | | 75 | X2X2s += X2(i) * X2(i); |
76 | X1X2s += X1(i) * X2(i); | | 76 | X1X2s += X1(i) * X2(i); |
77 | | | 77 | |