@Override public void updateEdgeMessage(int portNum) { if (portNum < _numParameterEdges) { // Port is a parameter input // Determine sample alpha and beta parameters // NOTE: This case works for either CategoricalUnnormalizedParameters or // CategoricalEnergyParameters factor functions // since the actual parameter value doesn't come into play in determining the message in this // direction GammaParameters outputMsg = (GammaParameters) _outputMsgs[portNum]; // The parameter being updated corresponds to this value int parameterIndex = _factorFunction.getIndexByEdge(portNum); // Start with the ports to variable outputs int count = 0; for (int i = 0; i < _numOutputEdges; i++) { int outputIndex = _outputVariables[i].getCurrentSampleIndex(); if (outputIndex == parameterIndex) count++; } // Include any constant outputs also if (_hasConstantOutputs) count += _constantOutputCounts[parameterIndex]; outputMsg.setAlphaMinusOne(count); // Sample alpha outputMsg.setBeta(0); // Sample beta } else super.updateEdgeMessage(portNum); }
@Override public void createMessages() { super.createMessages(); determineParameterConstantsAndEdges(); // Call this here since initialize may not have been // called yet _outputMsgs = new Object[_numPorts]; for (int port = 0; port < _numParameterEdges; port++) // Only parameter edges _outputMsgs[port] = new GammaParameters(); }
@Override public void initialize() { super.initialize(); // Determine what parameters are constants or edges, and save the state determineParameterConstantsAndEdges(); // Pre-compute statistics associated with any constant output values _constantOutputCounts = null; if (_hasConstantOutputs) { FactorFunction factorFunction = _factor.getFactorFunction(); Object[] constantValues = factorFunction.getConstants(); int[] constantIndices = factorFunction.getConstantIndices(); _constantOutputCounts = new int[_numParameters]; for (int i = 0; i < constantIndices.length; i++) { if (_hasFactorFunctionConstructorConstants || constantIndices[i] >= _numParameters) { int outputValue = FactorFunctionUtilities.toInteger(constantValues[i]); _constantOutputCounts[outputValue]++; // Histogram among constant outputs } } } }
@Override public void moveMessages(ISolverNode other, int thisPortNum, int otherPortNum) { super.moveMessages(other, thisPortNum, otherPortNum); _outputMsgs[thisPortNum] = ((CustomCategoricalUnnormalizedOrEnergyParameters) other)._outputMsgs[otherPortNum]; }