メイン stem.html Last modified: Sep 01, 2009
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;CHARSET=EUC-JP">
<link rel="shortcut icon" href="../favicon.ico">
<title>JavaScript</title>
<script src="io.js">document.write("io.js ファイルが見つかりません??<br>")</script>
<script language="JavaScript">
<!--
var _stem, _leaf, lpw = 100
var TEN = 0, FIVE = 1, TWO = 2, ONE = 3
function compareNumbers(a, b) {
// return a - b
if (a > b) return 1
else if (a == b) return 0
else return -1
}
function truncate(x)
{
return x < 0 ? Math.ceil(x) : Math.floor(x)
}
function info(x, f, minimum, t)
{
var p, work
work = Math.round(x/f*10.0)/10.0
p = (""+work).indexOf(".")
_leaf = (p == -1) ? 0 : (""+work).substring(p+1, p+2)
_stem = truncate(work)-t+(x >= 0 && minimum < 0)
if (_stem == 0 && minimum < 0) {
_stem = 0
}
}
function stem_s(j, base, val, minimum)
{
var work
if (j == 0) {
work = truncate(base+val-(minimum < 0 && val > Math.abs(base)))
if (minimum < 0 && val == Math.abs(base)) {
return "-"+work
}
else {
return work
}
}
else {
return ""
}
}
function out4( minimum, maximum, f, n, nn, ok, class0, t, leaf)
{
var class0_mark
class0_mark = new Array(" ","* ・ ","* t f s e ","*#$&@\\!=:・")
var i, j, k, kk, leafsum, js, je, jstep
printf("★ ステム・アンド・リーフ\n\n ステム N リーフ(丸めた値)\n")
if (f != 1) {
printf(" x %.1f x %.1f\n", f, f/10)
}
else {
printf(" %7s x %g\n", "", f/10)
}
for (i = 0; i <= nn; i++) {
js = 0
je = 10-ok
jstep = ok
if (minimum < 0 && i <= Math.abs(t)) {
js = 10-ok
je = 0
jstep = -ok
}
for (j = js; ; j += jstep) {
if ((js <= je && j > je) || (js > je && j < je)) {
break
}
leafsum = 0
for (kk = 0; kk < ok; kk++) {
leafsum += leaf[i][j+kk]
}
printf("%5s %s%5i ", stem_s(j, t, i, minimum), class0_mark[class0].substring(j, j+1), leafsum)
for (kk = 0; kk < ok; kk++) {
for (k = 1; k <= leaf[i][j+kk]; k++) {
printf("%s", "0123456789".substring(j+kk, j+kk+1))
}
}
printf("\n")
if (j == je) {
break
}
}
}
printf(" 合計 %6i\n\n", n)
printf("最小値 = %g , 最大値 = %g\n\n", minimum, maximum)
}
function clasdef(nn, leaf, stem)
{
var i, j, kk, leafsum, class0
class0 = TEN
for (i = 0; i <= nn; i++) {
if (stem[i] > lpw) {
class0 = FIVE
}
}
if (class0 == FIVE) {
for (i = 0; i <= nn; i++) {
for (j = 0; j <= 9; j += 5) {
leafsum = 0
for (kk = 0; kk <= 4; kk++) {
leafsum += leaf[i][j+kk]
}
if (leafsum > lpw) {
class0 = TWO
}
}
}
}
if (class0 == TWO) {
for (i = 0; i <= nn; i++) {
for (j = 0; j <= 9; j += 2) {
if (leaf[i][j]+leaf[i][j+1] > lpw) {
class0 = ONE
}
}
}
}
return class0
}
function stem(data, n)
{
var class0, DeltaN
var OK2 = 1, NG = 0
var ok, stem, leaf, i1, j1, j, k, l, minimum, maximum, range, f, t, u, nn, x
if (n <= 1) {
printf("有効データ数は %i です。少なくとも 2 個 以上のデータがないと...\n", n)
return
}
else {
ok = OK2
stem = new Array(100)
leaf = new Array(100)
for (i1 = 0; i1 <= 99; i1++) {
stem[i1] = 0
leaf[i1] = new Array(10)
for (j1 = 0; j1 <= 9; j1++) {
leaf[i1][j1] = 0
}
}
minimum = maximum = data[0]
for (j = 1; j < n; j++) {
if ((x = data[j]) < minimum) {
minimum = x
}
if (x > maximum) {
maximum = x
}
}
range = maximum-minimum
f = 1.0
while (range >= 10.0) {
range /= 10.0
f /= 10.0
}
while (range < 1.0) {
range *= 10.0
f *= 10.0
}
while (Math.floor(maximum/f)-Math.floor(minimum/f) > 30) {
f *= 10.0
}
while (Math.floor(maximum/f)-Math.floor(minimum/f) < 3) {
f /= 10.0
}
if (Math.floor(maximum/f)-Math.floor(minimum/f) < 3) {
printf("分布範囲が狭く、ステム・アンド・リーフが作れません。\n")
return
}
else {
t = truncate(minimum/f)
u = truncate(maximum/f)
nn = u-t+(minimum < 0.0)
for (j = 0; j < n; j++) {
info(data[j], f, minimum, t)
k = _stem
l = _leaf
stem[k]++
leaf[k][l]++
if (leaf[k][l] > lpw) {
printf("リーフが大きくなり過ぎ、ステム・アンド・リーフが作れません。\n")
return
}
}
if (ok == OK2) {
DeltaN = new Array(10, 5, 2, 1)
class0 = clasdef(nn, leaf, stem)
out4(minimum, maximum, f, n, nn, DeltaN[class0], class0, t, leaf)
}
}
}
}
function calc(data_string)
{
var data, nc, nc2, i, j, x
x = new Array()
if ((data = getdata(data_string, -1)) == false) return
nc = 0
for (i = 0; i < data.length; i++) {
for (j = 0; j < data[i].length; j++) {
x[nc++] = data[i][j]
}
}
if (nc < 2) {
printf("ケース数が1以下です\n")
sep2(35)
return
}
stem(x, nc)
x.sort(compareNumbers)
nc2 = Math.floor(nc/2)
printf("中央値は %g です。\n", nc % 2 == 1 ? x[nc2] : (x[nc2-1]+x[nc2])/2)
sep2(35)
printf("\n")
}
//-->
</script>
</head>
<body bgcolor="#ffffff">
<font size="+2"><b>ステム・アンド・リーフ</b></font> <a href="src/stem.html"><img src="png/src.png" width=35 height=11 alt="src" align=top></a> Last modified: Jun 01, 2006<hr noshade><p>
<font color="#ff0000" size="+2">以下のプログラムのサポートは終了しました。自己責任でお使い下さい。</font>
<form name=Result>
<script language="JavaScript">
<!--
//-->JavaScript がサポートされていないブラウザですか?
</script>
<input type="button" name="calcurate" value="計算開始" onClick="calc(this.form.data.value)">
<input type="button" name="clear" value="入力欄クリア" onClick="this.form.data.value=''">
<input type="button" name="clear" value="出力欄クリア" onClick="this.form.result.value=''">
<p>
<table><tr>
<td>入力欄<br><textarea name="data" ROWS=20 COLS=15></textarea></td><td>出力欄<br><textarea name="result" ROWS=20 COLS=80></textarea></td>
</tr></table>
</form>
入力欄には,データを<a href="exa/kugirimoji.html">区切り文字</a>で区切って何行でも
<p><hr noshade>
<img src="../gra/button3.png" width=9 height=9 alt="・"> <a href="../lecture/Dosuu/stem-and-leaf.html">手法の解説</a><br>
<img src="../gra/button3.png" width=9 height=9 alt="・"> <A HREF="javascript:history.go(-1)">直前のページへ戻る</A> <img src="../gra/button3.png" width=9 height=9 alt="・"> <a href="../mail.html">E-mail to Shigenobu AOKI</a>
<p><center><IMG SRC="../gra/ume5.png" width=121 height=37 ALT="Made with Macintosh"></center>
</body>
</html>
サブ io.js Last modified: Mar 25, 2004
直前のページへ戻る E-mail to Shigenobu AOKI