/*
 * Copyright 2008 Novamente LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package relex.stats;

/**
 * This class provides a simple OpenCog-like TruthValue object.
 * It is similar to, but not the same as, OpenCog TV objects.
 * Perhaps someday, it should be refectored to resemble OpenCog
 * more.
 *
 * Copyright (C) 2008 Linas Vepstas <linas@linas.org> 
 */
public class SimpleTruthValue implements TruthValue
{
	private int count;
	private double sum;
	private double sum_squared;

	public SimpleTruthValue()
	{
		count = 0;
		sum = 0.0;
		sum_squared = 0.0;
	}

	public double getMean()
	{
		if (count <= 0) return 0; 
		return sum/count;
	}

	public double getCount()
	{
		return count;
	}

	public double getConfidence()
	{
		if (count <= 0) return 0.0;

		// XXX FIXME
		// A total hack, right now -- the invese RMS value.
		double rms = (sum_squared - sum*sum/count) / count;
		return 1.0/rms;
	}
}


@@ -1421,12 +1421,159 @@
 /rms;%0A%09%7D
+%0A%0A%09public void increment(double val)%0A%09%7B%0A%09%09count ++;%0A%09%09sum += val;%0A%09%09sum_squared += val*val;%0A%09%7D%0A%0A%09public void setCount(int cnt)%0A%09%7B%0A%09%09count = cnt;%0A%09%7D
 %0A%7D%0A%0A

add incemenet, set count methods.