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

edu.berkeley.nlp.PCFGLA.smoothing.SmoothAcrossParentSubstateTest Maven / Gradle / Ivy

Go to download

The Berkeley parser analyzes the grammatical structure of natural language using probabilistic context-free grammars (PCFGs).

The newest version!
/**
 * 
 */
package edu.berkeley.nlp.PCFGLA.smoothing;

import java.io.Serializable;


import edu.berkeley.nlp.PCFGLA.BinaryCounterTable;
import edu.berkeley.nlp.PCFGLA.BinaryRule;
import edu.berkeley.nlp.PCFGLA.UnaryCounterTable;
import edu.berkeley.nlp.PCFGLA.UnaryRule;

/**
 * @author leon
 *
 */
public class SmoothAcrossParentSubstateTest{
	
	public SmoothAcrossParentSubstateTest() {
		// CLASS IS BROKEN
	}

	/*
	 * Test method for 'edu.berkeley.nlp.PCFGLA.smoothing.SmoothAcrossParentSubstate.smooth(UnaryCounterTable, BinaryCounterTable)'
	 */
	public void testSmooth() {
		short pState = 1, lState = 2, rState = 3;
		short[] numSubStates = {3,3,3,3};
		double[][] uScores = {{ 1, 0, 0 }, {1, 1, 1}, {0, 0, 1}};
		double[][] targetUScores = 
		{{ 0.75, 0.25, 0.5 }, {0.75, 0.5, 0.75}, {0.5, 0.25, 0.75}};
		double[][][] bScores = {{{1, 0, 0}, {0, 1, 0}, {0,0,1}},
			{{0,1,0},{0,0,0},{0,0,0}},
			{{0,0,0},{0,0,0},{0,0,0}}};
		double[][][] targetBScores = {{{0.5,0.25,0},{0,0.5,0},{0,0,0.5}},
				{{0.25,0.5,0},{0,0.25,0},{0,0,0.25}},
				{{0.25,0.25,0},{0,0.25,0},{0,0,0.25}}};
		
		UnaryRule ur = new UnaryRule(pState,lState,uScores);
		BinaryRule br = new BinaryRule(pState,lState,rState,bScores);
		Smoother sm = new SmoothAcrossParentSubstate(0.5);
		UnaryCounterTable unaryCounter = new UnaryCounterTable(numSubStates);
		unaryCounter.setCount(ur,uScores);
		BinaryCounterTable binaryCounter = new BinaryCounterTable(numSubStates);
		binaryCounter.setCount(br,bScores);
		sm.smooth(unaryCounter,binaryCounter);
		
		double[][] newUScores = unaryCounter.getCount(ur);
		for (int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy