@@ -0,0 +1,1863 @@
+/*%0A * Copyright 2008 Novamente LLC%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage relex.stats;%0A%0Aimport java.lang.Math;%0A%0A/**%0A * This class provides simple historgram (bin count) support.%0A *%0A * Copyright (C) 2008 Linas Vepstas %3Clinas@linas.org%3E %0A */%0Apublic class Histogram implements TruthValue%0A%7B%0A%09private int nbins;%0A%09private double min_value;%0A%09private double max_value;%0A%09private double rate;%0A%09private int%5B%5D bins;%0A%09int underflow;%0A%09int overflow;%0A%0A%09public Histogram(int _nbins, double low, double high)%0A%09%7B%0A%09%09nbins = _nbins;%0A%09%09min_value = low;%0A%09%09max_value = high;%0A%09%09underflow = 0;%0A%09%09overflow = 0;%0A%09%09bins = new int%5Bnbins%5D;%0A%09%09for (int i=0; i%3Cnbins; i++)%0A%09%09%7B%0A%09%09%09bins%5Bi%5D = 0;%0A%09%09%7D%0A%0A%09%09rate = nbins / (max_value - min_value);%0A%09%7D%0A%0A%09public void bin(double value)%0A%09%7B%0A%09%09int b = (int) Math.floor (rate * (value - min_value));%0A%0A%09%09if (b %3C 0)%0A%09%09%7B%0A%09%09%09underflow ++;%0A%09%09%09return;%0A%09%09%7D%0A%09%09if (b %3E= nbins)%0A%09%09%7B%0A%09%09%09overflow ++;%0A%09%09%09return;%0A%09%09%7D%0A%09%09bins%5Bb%5D ++;%0A%09%7D%0A%0A%09public double getCount()%0A%09%7B%0A%09%09int cnt = 0;%0A%09%09for (int i=0; i%3Cnbins; i++)%0A%09%09%7B%0A%09%09%09cnt += bins%5Bi%5D;%0A%09%09%7D%0A%09%09return cnt;%0A%09%7D%0A%0A%09public double getMean()%0A%09%7B%0A%09%09int cnt = 0;%0A%09%09double avg = 0.0;%0A%09%09double delta = 1.0 / rate;%0A%09%09for (int i=0; i%3Cnbins; i++)%0A%09%09%7B%0A%09%09%09avg += delta * (i + 0.5) * bins%5Bi%5D;%0A%09%09%09cnt += bins%5Bi%5D;%0A%09%09%7D%0A%09%09return (avg / ((double) cnt)) + min_value;%0A%09%7D%0A%0A%09public double getConfidence()%0A%09%7B%0A%09%09return 1.0;%0A%09%7D%0A%7D%0A%0A

create a new historgram class.