public double messageFactor2Node(int factor, int node, int value) {
		double best = Double.NEGATIVE_INFINITY;
		double current = 0;

		if (factor == node) {
			return  Math.log(potentials.potential(node, value));
		}
		else if (factor == potentials.chainLength() + node -1) {
			// left factor n' -> f -> n
			for (int v = 1; v <= potentials.numXValues(); v++) {
				current = Math.log(potentials.potential(factor, v, value)) + messageNode2Factor(factor, node-1, v);
				if (current > best) {
					best = current;
					assignments[node-1] = v;
				}
			}
		}
		else if (factor == potentials.chainLength() + node) {
			// left factor n <- f <- n'
			for (int v = 1; v <= potentials.numXValues(); v++) {
				current = Math.log(potentials.potential(factor, value, v)) + messageNode2Factor(factor, node+1, v);
				if (current > best) {
					best = current;
					assignments[node+1] = v;
				}
			}
		}
		else {
			// they are not connected
			throw new RuntimeException("wrong assignment");
		}
		
		return best;
	}