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

com.ociweb.pronghorn.neural.NeuralGraphBuilder Maven / Gradle / Ivy

package com.ociweb.pronghorn.neural;

import com.ociweb.pronghorn.pipe.MessageSchema;
import com.ociweb.pronghorn.pipe.Pipe;
import com.ociweb.pronghorn.pipe.PipeConfig;
import com.ociweb.pronghorn.stage.scheduling.GraphManager;

public class NeuralGraphBuilder {

   //hash each word and ad them each to an input pipe 20is?
   //group stages into single stage with no thread scheudler to do one layer at a time
   //build pipes for both directions and feedback.
	
	
	
	public static > Pipe[][] buildPipeLayer(
			 GraphManager gm, PipeConfig config,
			 Pipe[] prevPipes, int nextNodesCount, StageFactory factory) {
			
		final int thisNodesCount = prevPipes.length;
		
		Pipe[][] fromStages = (Pipe[][])new Pipe[thisNodesCount][nextNodesCount];
		int m = thisNodesCount;
		while (--m>=0) {
			fromStages[m] = new Pipe[nextNodesCount];
		}
		
		Pipe[][] fromStageGroupedByNext = (Pipe[][])new Pipe[nextNodesCount][thisNodesCount];
		int n = nextNodesCount;
		while (--n>=0) {
			fromStageGroupedByNext[n] = Pipe.buildPipes(thisNodesCount, config);
			int p = thisNodesCount;
			while (--p>=0) {
				fromStages[p][n] = fromStageGroupedByNext[n][p];
			}
		}
		
		//inputs are grouped by node1
		
		//create stages that write to inputs and take previous as argument to method
		int p = prevPipes.length;
		while (--p>=0) {			
			factory.newStage(gm, prevPipes[p], fromStages[p]);
			
		}
		
		return fromStageGroupedByNext; //grouped by nodes2
		
		//return Pipe.buildPipes(inputs, pipeConfig);				
	}
	
	public static > Pipe[][] buildPipeLayer(
			GraphManager gm, PipeConfig config, Pipe[][] prev, int nodes2, StageFactory factory) {
		
		int nodes1 = prev.length;
		
		Pipe[][] inputs = (Pipe[][])new Pipe[nodes1][nodes2];
		int m = nodes1;
		while (--m>=0) {
			inputs[m] = new Pipe[nodes2];
		}
		
		Pipe[][] outputs = (Pipe[][])new Pipe[nodes2][nodes1];
		int n = nodes2;
		while (--n>=0) {
			outputs[n] = Pipe.buildPipes(nodes1, config);
			int p = nodes1;
			while (--p>=0) {
				inputs[p][n] = outputs[n][p];
			}
		}
		
		//inputs are grouped by node1
		
		//create stages that write to inputs and take previous as argument to method
		int p = prev.length;
		while (--p>=0) {			
			factory.newStage(gm, prev[p], inputs[p]);
			
		}
		
		return outputs; //grouped by nodes2
		
		//return Pipe.buildPipes(inputs, pipeConfig);				
	}
	
	//NOTE: build inputs with  Pipe.buildPipes
	
	public static > Pipe[] lastPipeLayer(
			           GraphManager gm, Pipe[][] prev, StageFactory factory) {
			
		int p = prev.length;
		Pipe[] outputs = Pipe.buildPipes(p, prev[0][0].config());
		while (--p>=0) {			
			factory.newStage(gm, prev[p], outputs[p]);
		}
		return outputs;
	}

	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy