<commit_before>/*
 * Encog Artificial Intelligence Framework v2.x
 * Java Version
 * http://www.heatonresearch.com/encog/
 * http://code.google.com/p/encog-java/
 * 
 * Copyright 2008-2009, Heaton Research Inc., and individual contributors.
 * See the copyright.txt in the distribution for a full listing of 
 * individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */

package org.encog.neural.pattern;

import org.encog.neural.activation.ActivationCompetitive;
import org.encog.neural.activation.ActivationFunction;
import org.encog.neural.networks.BasicNetwork;
import org.encog.neural.networks.layers.BasicLayer;
import org.encog.neural.networks.layers.Layer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Pattern that creates a CPN neural network.
 */
public class CPNPattern implements NeuralNetworkPattern {
	
	public final static String TAG_INSTAR = "INSTAR";
	public final static String TAG_OUTSTAR = "OUTSTAR";
	
	/**
	 * The number of neurons in the instar layer.
	 */
	int instarCount;
	
	/**
	 * The number of neurons in the outstar layer.
	 */
	int outstarCount;
	
	/**
	 * The number of neurons in the hidden layer.
	 */
	int inputCount;
	
	/**
	 * The logging object.
	 */
	private final Logger logger = LoggerFactory.getLogger(this.getClass());

	/**
	 * Not used, will throw an error. CPN networks already have a predefined
	 * hidden layer called the instar layer.
	 */
	public void addHiddenLayer(int count) {
		final String str = 
			"A CPN already has a predefined hidden layer.  No additiona" +
			"specification is needed.";
		if (this.logger.isErrorEnabled()) {
			this.logger.error(str);
		}
		
	}

	/**
	 * Clear any parameters that were set.
	 */
	public void clear() {
		this.inputCount = this.instarCount = this.outstarCount = 0;		
	}

	/**
	 * Generate the network.
	 * @return The generated network.
	 */
	public BasicNetwork generate() {
		
		Layer input,instar,outstar;
		int y = PatternConst.START_Y;
		
		BasicNetwork network = new BasicNetwork();
		network.addLayer(input = new BasicLayer(this.inputCount));
		network.addLayer(instar = new BasicLayer(new ActivationCompetitive(),true,this.instarCount));
		network.addLayer(outstar = new BasicLayer(this.outstarCount));
		network.getStructure().finalizeStructure();
		network.reset();
		
		input.setX(PatternConst.START_X);
		input.setY(y);
		y+=PatternConst.INC_Y;
		
		instar.setX(PatternConst.START_X);
		instar.setY(y);
		y+=PatternConst.INC_Y;<commit_msg>Fixed issue with CPN network pattern<commit_after>/*
 * Encog Artificial Intelligence Framework v2.x
 * Java Version
 * http://www.heatonresearch.com/encog/
 * http://code.google.com/p/encog-java/
 * 
 * Copyright 2008-2009, Heaton Research Inc., and individual contributors.
 * See the copyright.txt in the distribution for a full listing of 
 * individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */

package org.encog.neural.pattern;

import org.encog.neural.activation.ActivationCompetitive;
import org.encog.neural.activation.ActivationFunction;
import org.encog.neural.activation.ActivationLinear;
import org.encog.neural.networks.BasicNetwork;
import org.encog.neural.networks.layers.BasicLayer;
import org.encog.neural.networks.layers.Layer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Pattern that creates a CPN neural network.
 */
public class CPNPattern implements NeuralNetworkPattern {
	
	public final static String TAG_INSTAR = "INSTAR";
	public final static String TAG_OUTSTAR = "OUTSTAR";
	
	/**
	 * The number of neurons in the instar layer.
	 */
	int instarCount;
	
	/**
	 * The number of neurons in the outstar layer.
	 */
	int outstarCount;
	
	/**
	 * The number of neurons in the hidden layer.
	 */
	int inputCount;
	
	/**
	 * The logging object.
	 */
	private final Logger logger = LoggerFactory.getLogger(this.getClass());

	/**
	 * Not used, will throw an error. CPN networks already have a predefined
	 * hidden layer called the instar layer.
	 */
	public void addHiddenLayer(int count) {
		final String str = 
			"A CPN already has a predefined hidden layer.  No additiona" +
			"specification is needed.";
		if (this.logger.isErrorEnabled()) {
			this.logger.error(str);
		}
		
	}

	/**
	 * Clear any parameters that were set.
	 */
	public void clear() {
		this.inputCount = this.instarCount = this.outstarCount = 0;		
	}

	/**
	 * Generate the network.
	 * @return The generated network.
	 */
	public BasicNetwork generate() {
		
		Layer input,instar,outstar;
		int y = PatternConst.START_Y;
		
		BasicNetwork network = new BasicNetwork();
		network.addLayer(input = new BasicLayer(new ActivationLinear(), false, this.inputCount));
		network.addLayer(instar = new BasicLayer(new ActivationCompetitive(), false,this.instarCount));
		network.addLayer(outstar = new BasicLayer(new ActivationLinear(), false, this.outstarCount));
		network.getStructure().finalizeStructure();
		network.reset();
		
		input.setX(PatternConst.START_X);
		input.setY(y);
		y+=PatternConst.INC_Y;
		
		instar.setX(PatternConst.START_X);
		instar.setY(y);
		y+=PatternConst.INC_Y;
{'fraction_non_alphanumeric': 0.09853792263173926, 'fraction_numerical': 0.007614986293024673, 'mean_word_length': 3.8536585365853657, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5553909', 'n_tokens_mistral': 2102, 'n_tokens_neox': 1885, 'n_words': 655}