Livt packages

Livt.ML

Version 1.6.1

Fixed-size quantized inference, tensor storage, attention, and transformer building blocks for Livt.

Published files (132)

tests/classifier/ClassProjectionTest.lvt

namespace Livt.ML.Tests.Classifier

using Livt.ML.Classifier

/**
 * Exercises ClassProjection with a shared fixture instance. Each scenario establishes the
 * inputs and state it needs.
 */
@Test
component ClassProjectionTest
{
	// Shared fixture instances, signals, and observation state.
	projection: ClassProjection

	/**
	 * Creates the shared fixture instances (ClassProjection). Tests initialize the state
	 * required by their scenario.
	 */
	new()
	{
		projection = new ClassProjection()
	}

	/**
	 * Checks that Project s class0 like vector.
	 */
	@Test
	fn ProjectsClass0LikeVector()
	{
		var input: int[8] = [0, 256, 256, 256, 256, 0, 0, 0]

		projection.Project(input)

		assert projection.GetLogit(ClassProjection.CLASS_0) == 1024
		assert projection.GetLogit(ClassProjection.CLASS_1) == -256
		assert projection.GetLogit(ClassProjection.CLASS_2) == 0
	}

	/**
	 * Checks that Project s class1 like vector.
	 */
	@Test
	fn ProjectsClass1LikeVector()
	{
		var input: int[8] = [0, 0, 0, 0, 0, 0, 256, 0]

		projection.Project(input)

		assert projection.GetLogit(ClassProjection.CLASS_0) == -256
		assert projection.GetLogit(ClassProjection.CLASS_1) == 256
		assert projection.GetLogit(ClassProjection.CLASS_2) == 0
	}

	/**
	 * Checks that Project s class2 like vector.
	 */
	@Test
	fn ProjectsClass2LikeVector()
	{
		var input: int[8] = [0, 0, 0, 0, 0, 256, 0, 0]

		projection.Project(input)

		assert projection.GetLogit(ClassProjection.CLASS_0) == -1024
		assert projection.GetLogit(ClassProjection.CLASS_1) == 0
		assert projection.GetLogit(ClassProjection.CLASS_2) == 1024
		assert projection.GetLogit(3) == 0
	}
}