All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.github.evenjn.guess.benchmark.BlindMapleTrainer Maven / Gradle / Ivy

There is a newer version: 0.6.0
Show newest version
/**
 *
 * Copyright 2016 Marco Trevisan
 *
 * 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 org.github.evenjn.guess.benchmark;

import java.util.function.Function;

import org.github.evenjn.guess.Trainer;
import org.github.evenjn.knit.KnittingCursable;
import org.github.evenjn.knit.KnittingTuple;
import org.github.evenjn.numeric.FrequencyDistribution;
import org.github.evenjn.yarn.Cursable;
import org.github.evenjn.yarn.Di;
import org.github.evenjn.yarn.ProgressSpawner;
import org.github.evenjn.yarn.Tuple;

public class BlindMapleTrainer implements
		Trainer, Tuple> {

	public BlindMapleTrainer(
			Cursable above_alphabet,
			Cursable below_alphabet) {
	}

	@Override
	public Function, Tuple> train(
			ProgressSpawner progress_spawner,
			Cursable, Tuple>> data ) {
		FrequencyDistribution fd = new FrequencyDistribution<>( );
		KnittingCursable.wrap( data )
		.flatmapCursable( d -> KnittingTuple.wrap( d.back( ) ).asCursable( ) )
		.tap( fd ).consume( );
		O mostFrequent = fd.getMostFrequent( );
						

		return x -> new Tuple( ) {

			@Override
			public O get( int index ) {
				x.get( index );
				return mostFrequent;
			}

			@Override
			public int size( ) {
				return x.size( );
			}
		};
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy