* [9fans] virus rate & spline
@ 2003-09-24 13:00 steve.simon
2003-09-24 14:41 ` boyd, rounin
0 siblings, 1 reply; 2+ messages in thread
From: steve.simon @ 2003-09-24 13:00 UTC (permalink / raw)
To: 9fans
[-- Attachment #1: Type: text/plain, Size: 511 bytes --]
Hi,
In a silly mood about I decided to graph
the virus reception rate here (attached).
Its only been running since Friday afternoon
and dips below zero and bounces back due to
a network outage bringing the rate to zero
and spline smooting this into a cubic curve;
its not me sending them out, honest!
In the process ported the V7 spline
command (also attached)
BTW our IT dep have a virus catching firewall which
sends me an email telling me what its done, its these
I am graphing.
-Steve
[-- Attachment #2.1: Type: text/plain, Size: 313 bytes --]
The following attachment had content that we can't
prove to be harmless. To avoid possible automatic
execution, we changed the content headers.
The original header was:
Content-Disposition: attachment; filename=spline.bundle
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit
[-- Attachment #2.2: spline.bundle.suspect --]
[-- Type: application/octet-stream, Size: 8755 bytes --]
# To unbundle, run this file
echo spline.1g
sed 's/.//' >spline.1g <<'//GO.SYSIN DD spline.1g'
-.TH SPLINE 1G
-.SH NAME
-spline \- interpolate smooth curve
-.SH SYNOPSIS
-.B spline
-[-a \fBn\fR] [-k \fBn\fR] [-n \fBn\fR] [-p] [-x \fBlo hi\fR] [file...]
-.SH DESCRIPTION
-.I Spline
-takes pairs of numbers from the standard input as abcissas and ordinates
-of a function.
-It produces a similar set, which
-is approximately equally spaced and
-includes the input set, on the standard output.
-The cubic spline output
-(R. W. Hamming,
-.ft I
-Numerical Methods for Scientists and Engineers,
-.ft R
-2nd ed., 349ff)
-has two continuous derivatives,
-and sufficiently many points to look smooth when plotted, for
-example by
-.IR graph (1).
-.PP
-The following options are recognized,
-each as a separate argument.
-.TP 5
-.B \-a
-Supply abscissas automatically (they are missing from
-the input); spacing is given by the next
-argument, the default is 1.
-.TP 5
-.B \-k
-The constant
-.IR k ""
-used in the boundary value computation
-.IP
-.if n .ig
-.ti +1.5i
-.ds ' \h'-\w'\(fm\(fm'u'
-.EQ
-.nr 99 \n(.s
-.nr 98 \n(.f
-'ps 10
-.ft I
-.ds 11 "y\(fm\(fm
-.nr 11 \w'\*(11'
-.ds 12 "\*'
-.nr 12 \w'\*(12'
-'ps 8
-.ds 13 "\fR0\fP
-.nr 13 \w'\*(13'
-.as 12 \v'18u'\s8\*(13\|\s10\v'-18u'
-'ps 10
-.nr 12 \n(12+\n(13+\w'\s8\|'
-.as 11 "\*(12
-.nr 11 \w'\*(11'
-.ds 12 "\|\|
-.nr 12 \w'\*(12'
-.as 11 "\*(12
-.nr 11 \w'\*(11'
-.ds 12 "\|=\|
-.nr 12 \w'\*(12'
-.as 11 "\*(12
-.nr 11 \w'\*(11'
-.ds 12 "\|\|
-.nr 12 \w'\*(12'
-.as 11 "\*(12
-.nr 11 \w'\*(11'
-.ds 12 "ky\(fm\(fm
-.nr 12 \w'\*(12'
-.as 11 "\*(12
-.nr 11 \w'\*(11'
-.ds 12 "\*'
-.nr 12 \w'\*(12'
-'ps 8
-.ds 13 "\fR1\fP
-.nr 13 \w'\*(13'
-.as 12 \v'18u'\s8\*(13\|\s10\v'-18u'
-'ps 10
-.nr 12 \n(12+\n(13+\w'\s8\|'
-.as 11 "\*(12
-.nr 11 \w'\*(11'
-.ds 12 ",
-.nr 12 \w'\*(12'
-.as 11 "\*(12
-.nr 11 \w'\*(11'
-.ds 12 "\|\|
-.nr 12 \w'\*(12'
-.as 11 "\*(12
-.nr 11 \w'\*(11'
-.ds 12 "\|\|
-.nr 12 \w'\*(12'
-.as 11 "\*(12
-.nr 11 \w'\*(11'
-.ds 12 "\|\|
-.nr 12 \w'\*(12'
-.as 11 "\*(12
-.nr 11 \w'\*(11'
-.ds 12 "y\(fm\(fm
-.nr 12 \w'\*(12'
-.as 11 "\*(12
-.nr 11 \w'\*(11'
-.ds 12 "\*'
-.nr 12 \w'\*(12'
-'ps 8
-.ds 13 "n
-.nr 13 \w'\*(13'
-.as 12 \v'18u'\s8\*(13\|\s10\v'-18u'
-'ps 10
-.nr 12 \n(12+\n(13+\w'\s8\|'
-.as 11 "\*(12
-.nr 11 \w'\*(11'
-.ds 12 "\|\|
-.nr 12 \w'\*(12'
-.as 11 "\*(12
-.nr 11 \w'\*(11'
-.ds 12 "\|=\|
-.nr 12 \w'\*(12'
-.as 11 "\*(12
-.nr 11 \w'\*(11'
-.ds 12 "\|\|
-.nr 12 \w'\*(12'
-.as 11 "\*(12
-.nr 11 \w'\*(11'
-.ds 12 "ky\(fm\(fm
-.nr 12 \w'\*(12'
-.as 11 "\*(12
-.nr 11 \w'\*(11'
-.ds 12 "\*'
-.nr 12 \w'\*(12'
-'ps 8
-.ds 13 "n\|\(mi\|\fR1\fP
-.nr 13 \w'\*(13'
-.as 12 \v'18u'\s8\*(13\|\s10\v'-18u'
-'ps 10
-.nr 12 \n(12+\n(13+\w'\s8\|'
-.as 11 "\*(12
-.nr 11 \w'\*(11'
-.ds 11 \x'0'\fI\*(11\s\n(99\f\n(98
-.ne 78u
-\*(11
-'ps \n(99
-.ft \n(98
-.EN
-..
-.if t .ig
-.ce
-(2nd deriv. at end) = k*(2nd deriv. next to end)
-..
-.IP
-.br
-is set by the next argument.
-By default
-.IR k ""
-= 0.
-.TP 5
-.B \-n
-Space output points
-so that approximately
-.I n
-intervals occur between the lower and upper
-.I x
-limits.
-(Default
-.I n
-= 100.)
-.TP 5
-.B \-p
-Make output periodic, i.e. match
-derivatives at ends.
-First and last input values should normally agree.
-.TP 5
-.B \-x
-Next
-1 (or 2) arguments are lower (and upper)
-.I x
-limits.
-Normally these limits are calculated from the data.
-Automatic abcissas start at lower limit
-(default 0).
-.SH "SEE ALSO"
-graph(1)
-.SH DIAGNOSTICS
-When data is not strictly monotone in
-.I x,
-.I spline
-reproduces the input without interpolating extra points.
-.SH BUGS
-A limit of 1000 input points is enforced silently.
//GO.SYSIN DD spline.1g
echo spline.c
sed 's/.//' >spline.c <<'//GO.SYSIN DD spline.c'
-/* spline.c - curve smoothing ported from edition 7 source */
-#include <u.h>
-#include <libc.h>
-#include <bio.h>
-
-#define NP 1000 /* max # of points read */
-#define INF 1.e37 /* default upper and lower limits */
-
-struct proj {
- int lbf, ubf;
- float a, b, lb, ub, quant, mult, val[NP];
-} x, y;
-
-Biobuf bout;
-float *diag, *r;
-float dx = 1.0;
-float ni = 100.0;
-int n;
-int auta;
-int periodic;
-float konst = 0.0;
-float zero = 0.0;
-
-float rhs(int);
-int spline(void);
-void readin(Biobuf *bp);
-int getlim(struct proj *);
-void usage(void);
-
-float
-rhs(int i)
-{
- int i_;
- double zz;
- i_ = i == n - 1 ? 0 : i;
- zz = (y.val[i] - y.val[i-1]) / (x.val[i] - x.val[i-1]);
- return(6 * ((y.val[i_+1] - y.val[i_]) / (x.val[i+1] - x.val[i]) - zz));
-}
-
-
-int
-spline(void)
-{
- float d, s, u, v, hi, hi1;
- float h;
- float D2yi, D2yi1, D2yn1, x0, x1, yy, a;
- int end;
- float corr;
- int i, j, m;
- if (n < 3)
- return(0);
- if (periodic)
- konst = 0;
- d = 1;
- r[0] = 0;
- s = periodic ? -1 : 0;
- for (i = 0; ++i < n - !periodic; ) { /* triangularize */
- hi = x.val[i] - x.val[i-1];
- hi1 = i == n - 1 ? x.val[1] - x.val[0] :
- x.val[i+1] - x.val[i];
- if (hi1 * hi <= 0)
- return(0);
- u = i == 1 ? zero : u - s * s / d;
- v = i == 1 ? zero : v - s * r[i-1] / d;
- r[i] = rhs(i) - hi * r[i-1] / d;
- s = -hi * s / d;
- a = 2 * (hi + hi1);
- if (i == 1)
- a += konst * hi;
- if (i == n - 2)
- a += konst * hi1;
- diag[i] = d = i == 1 ? a :
- a - hi * hi / d;
- }
- D2yi = D2yn1 = 0;
- for (i = n - !periodic; --i >= 0; ) { /* back substitute */
- end = i == n - 1;
- hi1 = end ? x.val[1] - x.val[0] :
- x.val[i+1] - x.val[i];
- D2yi1 = D2yi;
- if (i > 0) {
- hi = x.val[i] - x.val[i-1];
- corr = end ? 2 * s + u : zero;
- D2yi = (r[i] - hi1 * D2yi1 - s * D2yn1 + end * v) /
- (diag[i] + corr);
- if (end)
- D2yn1 = D2yi;
- if (i > 1) {
- a = 2 * (hi + hi1);
- if (i == 1)
- a += konst * hi;
- if (i == n - 2)
- a += konst * hi1;
- d = diag[i-1];
- s = -s * d / hi;
- }
- } else
- D2yi = D2yn1;
-
- if (!periodic) {
- if (i == 0)
- D2yi = konst * D2yi1;
- if (i == n - 2)
- D2yi1 = konst * D2yi;
- }
- if (end)
- continue;
- m = (hi1 > 0) ? ni : -ni;
- m = 1.001 * m * hi1 / (x.ub - x.lb);
- if (m <= 0)
- m = 1;
- h = hi1 / m;
- for (j = m; j > 0 || i == 0 && j == 0; j--) { /* interpolate */
- x0 = (m - j) * h / hi1;
- x1 = j * h / hi1;
- yy = D2yi * (x0 - x0 * x0 * x0) + D2yi1 * (x1 - x1 * x1 * x1);
- yy = y.val[i] * x0 + y.val[i+1] * x1 - hi1 * hi1 * yy / 6;
- Bprint(&bout, "%f ", x.val[i] + j * h);
- Bprint(&bout, "%f\n", yy);
- }
- }
- return(1);
-}
-
-
-void
-readin(Biobuf *bp)
-{
- char *p, *a[4];
-
- for (n = 0; n < NP && (p = Brdline(bp, '\n')) != nil; n++){
- p[Blinelen(bp)-1] = 0;
- if (tokenize(p, a, nelem(a)) == 0)
- continue;
- if (auta){
- x.val[n] = n * dx * x.lb;
- y.val[n] = atof(a[0]);
- }
- else{
- x.val[n] = atof(a[0]);
- y.val[n] = atof(a[1]);
- }
- }
-}
-
-
-getlim(struct proj *p)
-{
- int i;
- for (i = 0; i < n; i++) {
- if (!p->lbf && p->lb > (p->val[i]))
- p->lb = p->val[i];
- if (!p->ubf && p->ub < (p->val[i]))
- p->ub = p->val[i];
- }
-}
-
-
-void
-main(int argc, char *argv[])
-{
- int i;
- Biobuf *bp, bin;
-
- x.lbf = x.ubf = y.lbf = y.ubf = 0;
- x.lb = INF;
- x.ub = -INF;
- y.lb = INF;
- y.ub = -INF;
-
- Binit(&bin, 0, OREAD);
- Binit(&bout, 1, OWRITE);
-
- ARGBEGIN{
- case 'a':
- auta = 1;
- dx = atof(EARGF(usage()));
- break;
- case 'k':
- konst = atof(EARGF(usage()));
- break;
- case 'n':
- ni = atof(EARGF(usage()));
- break;
- case 'p':
- periodic = 1;
- break;
- case 'x':
- x.lbf = atof(EARGF(usage()));
- x.ubf = atof(EARGF(usage()));
- break;
-
- }ARGEND;
- if (auta && !x.lbf)
- x.lb = 0;
-
- if (argc == 0)
- readin(&bin);
- else
- for(; argc--; argv++){
- if ((bp = Bopen(*argv, OREAD)) == nil){
- fprint(2, "%s: %s cannot open, %r", argv0, *argv);
- continue;
- }
- readin(bp);
- Bterm(bp);
- }
-
- getlim(&x);
- getlim(&y);
-
- if ((diag = malloc((n+1) * sizeof(dx))) == nil)
- sysfatal("no memory");
- if ((r = malloc((n+1) * sizeof(dx))) == nil)
- sysfatal("no memory");
-
- if (spline() == 0)
- for (i = 0; i < n; i++) {
- Bprint(&bout, "%f ", x.val[i]);
- Bprint(&bout, "%f\n", y.val[i]);
- }
- Bflush(&bout);
- Bterm(&bout);
- exits(0);
-}
-
-void
-usage(void)
-{
- fprint(2, "usage: %s [-a n] [-k n] [-n n] [-p] [-x lo hi]\n", argv0);
- exits("usage");
-}
//GO.SYSIN DD spline.c
[-- Attachment #3: virus-rate.gif --]
[-- Type: image/gif, Size: 7925 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [9fans] virus rate & spline
2003-09-24 13:00 [9fans] virus rate & spline steve.simon
@ 2003-09-24 14:41 ` boyd, rounin
0 siblings, 0 replies; 2+ messages in thread
From: boyd, rounin @ 2003-09-24 14:41 UTC (permalink / raw)
To: 9fans
in some failsafe mode i was delivering all the spams into
an audit log style mail file [thanks dave]. in one day it hit 50Mb,
so now i'm just auditing the 822 headers.
it forced me to write the rather crude zero:
http://www.insultant.net/code/plan9/zero
i have my own version of pipeto.sample
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2003-09-24 14:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-24 13:00 [9fans] virus rate & spline steve.simon
2003-09-24 14:41 ` boyd, rounin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).